fixes cds solution handling 97/397/1
authorSerban Jora <sj2381@att.com>
Mon, 8 Jan 2018 16:31:54 +0000 (11:31 -0500)
committerSerban Jora <sj2381@att.com>
Mon, 8 Jan 2018 16:32:08 +0000 (11:32 -0500)
Change-Id: I435362aa296c5d784e575e12d329285a4153c455
Signed-off-by: Serban Jora <sj2381@att.com>
gateway/src/main/java/org/acumos/federation/gateway/adapter/PeerGateway.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/CatalogServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/Clients.java

index bea0038..5673ace 100644 (file)
@@ -164,15 +164,19 @@ public class PeerGateway {
                                        }
                                        
                                        //Verify if MLPSolution is not same
-                                       if(mlpSolution != null && !isSameMLPSolution(acumosSolution, mlpSolution)) {
+                                       if(mlpSolution != null &&
+                                                isSameMLPSolution(acumosSolution, mlpSolution)) {
                                                //if already exists locally then loop through next
                                                mlpSolution = updateMLPSolution(acumosSolution, mlpSolution, cdsClient);
                                                
-                                       } else {
+                                       } 
+                                       else {
                                                mlpSolution = createMLPSolution(acumosSolution, cdsClient);
                                        }
-                                       updateMLPSolutionArtifacts(mlpSolution, cdsClient);
-                                       //ONAP.this.asdc.checkinResource(UUID.fromString(sdcAsset.getString("artifactUUID")), ONAP.this.asdcOperator, "solution imported " + " the acumos revision number ");
+
+                                       if (mlpSolution != null) {      
+                                               updateMLPSolutionArtifacts(mlpSolution, cdsClient);
+                                       }
                                }
                                catch (Exception x) {
                                        logger.warn(EELFLoggerDelegate.debugLogger, "Mapping of acumos solution failed for: " + acumosSolution + ": " + x);
@@ -294,7 +298,7 @@ public class PeerGateway {
                }
                
                private MLPSolution updateMLPSolution(MLPSolution peerMLPSolution, MLPSolution localMLPSolution, ICommonDataServiceRestClient cdsClient) {
-                       logger.info(EELFLoggerDelegate.debugLogger, "Updating Local MLP Solutino for peer solution " + peerMLPSolution);
+                       logger.info(EELFLoggerDelegate.debugLogger, "Updating Local MLP Solution for peer solution " + peerMLPSolution);
                        localMLPSolution.setSolutionId(peerMLPSolution.getSolutionId());
                        localMLPSolution.setName(peerMLPSolution.getName());
                        localMLPSolution.setDescription(peerMLPSolution.getDescription());
@@ -372,7 +376,7 @@ public class PeerGateway {
                        
                        MLPSolutionRevision mlpSolutionRevision = cdsClient.getSolutionRevision(theSolution.getSolutionId(), acumosRevisions.get(acumosRevisions.size()-1).getRevisionId());
                        if(mlpSolutionRevision == null && !Utils.isEmptyList(acumosArtifacts)) {
-                               //If SolutinoRevision is null, we need to create a Solution Revision in Local Acumos
+                               //If SolutionRevision is null, we need to create a Solution Revision in Local Acumos
                                mlpSolutionRevision = createMLPSolutionRevision(acumosRevisions.get(acumosRevisions.size()-1), cdsClient);
                        } 
                        
@@ -388,11 +392,23 @@ public class PeerGateway {
                                        Resource artifactContent = null;
                                        try {
                                                artifactContent = fedClient.downloadArtifact(artifact.getArtifactId());
-                                               logger.warn(EELFLoggerDelegate.debugLogger, "Received artifact content: " + new BufferedReader(new InputStreamReader(artifactContent.getInputStream())).lines().collect(Collectors.joining("\n")));
+                                               //logger.warn(EELFLoggerDelegate.debugLogger, "Received artifact content: " + new BufferedReader(new InputStreamReader(artifactContent.getInputStream())).lines().collect(Collectors.joining("\n")));
                                        }
                                        catch (Exception x) {
                                                logger.warn(EELFLoggerDelegate.debugLogger, "Failed to retrieve acumos artifact content", x);
                                        }
+
+                                       if (artifactContent != null) {
+                                               try {
+                                                       PeerGateway.this.clients.getNexusClient().uploadArtifact("", "", "", "", 0, artifactContent.getInputStream());
+                                               }
+                                               catch (Exception x) {
+                                                       logger.warn(EELFLoggerDelegate.debugLogger, "Failed to push artifact content to local Nexus repo", x);
+                                               }
+                                       }
+
+                                       //update artifact with local repo
+                                       //updateMLPArtifact(artifact, mlpArtifact, cdsClient);
                                }
                                
                        }
index 7276a7c..794fc7a 100644 (file)
@@ -49,7 +49,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.context.annotation.Conditional;
 
 import org.acumos.nexus.client.NexusArtifactClient;
-import org.acumos.nexus.client.RepositoryLocation;
 
 import org.acumos.cds.AccessTypeCode;
 import org.acumos.cds.ValidationStatusCode;
@@ -191,17 +190,7 @@ public class CatalogServiceImpl
                        ICommonDataServiceRestClient cdsClient = getClient();
                        MLPArtifact mlpArtifact = cdsClient.getArtifact(theArtifactId);
                        
-                       String path = Utils.getTempFolderPath(mlpArtifact.getName(), mlpArtifact.getVersion(), env.getProperty("nexus.tempFolder", ""));
-                       
-                       RepositoryLocation repositoryLocation = new RepositoryLocation();
-                       repositoryLocation.setId("1");
-                       repositoryLocation.setUrl(env.getProperty("nexus.url"));
-                       repositoryLocation.setUsername(env.getProperty("nexus.username"));
-                       repositoryLocation.setPassword(env.getProperty("nexus.password"));
-                       repositoryLocation.setProxy(env.getProperty("nexus.proxy"));
-                       
-                       // if you need a proxy to access the Nexus
-                       NexusArtifactClient artifactClient = new NexusArtifactClient(repositoryLocation);
+                       NexusArtifactClient artifactClient = this.clients.getNexusClient();
                        
                        byteArrayOutputStream = artifactClient.getArtifact(mlpArtifact.getUri());
                        InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
@@ -213,7 +202,6 @@ public class CatalogServiceImpl
                        if(byteArrayOutputStream != null) {
                                byteArrayOutputStream.close();
                        }
-                       Utils.deletetTempFiles(path);
                        
                } catch (Exception e) {
                        log.error(EELFLoggerDelegate.errorLogger, "getSolutionRevisionArtifactiContent", e);
index a1cea86..652a151 100644 (file)
@@ -34,6 +34,10 @@ import org.acumos.federation.gateway.config.EELFLoggerDelegate;
 import org.acumos.cds.client.CommonDataServiceRestClientImpl;
 import org.acumos.cds.client.ICommonDataServiceRestClient;
 
+import org.acumos.nexus.client.NexusArtifactClient;
+import org.acumos.nexus.client.RepositoryLocation;
+
+
 /**
  * Unique entry point for building clients: peer access clients, cds clients
  */
@@ -70,4 +74,17 @@ public class Clients implements ApplicationContextAware {
                                                                        thePeerURI,
                   (HttpClient)this.appCtx.getBean("federationClient"));
        }
+
+       public NexusArtifactClient getNexusClient() {
+
+               RepositoryLocation repositoryLocation = new RepositoryLocation();
+               repositoryLocation.setId("1");
+               repositoryLocation.setUrl(this.env.getProperty("nexus.url"));
+               repositoryLocation.setUsername(this.env.getProperty("nexus.username"));
+               repositoryLocation.setPassword(this.env.getProperty("nexus.password"));
+               repositoryLocation.setProxy(this.env.getProperty("nexus.proxy"));
+                       
+               // if you need a proxy to access the Nexus
+               return new NexusArtifactClient(repositoryLocation);
+       }
 }