fix artifact provisioning 98/398/1
authorSerban Jora <sj2381@att.com>
Mon, 8 Jan 2018 19:50:49 +0000 (14:50 -0500)
committerSerban Jora <sj2381@att.com>
Mon, 8 Jan 2018 19:50:56 +0000 (14:50 -0500)
Change-Id: Id99fd782ce1d80044e98b5eb6501e3e8046e370f
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/FederationClient.java

index 5673ace..abc688b 100644 (file)
@@ -36,6 +36,8 @@ import org.acumos.federation.gateway.service.impl.Clients;
 import org.acumos.federation.gateway.service.impl.FederationClient;
 import org.acumos.federation.gateway.util.Utils;
 
+import org.acumos.nexus.client.data.UploadArtifactInfo;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.BeanInitializationException;
 //import org.springframework.scheduling.annotation.Scheduled;
@@ -242,7 +244,11 @@ public class PeerGateway {
                        }
                }
                
-               private MLPArtifact createMLPArtifact(MLPArtifact mlpArtifact, ICommonDataServiceRestClient cdsClient) {
+               private MLPArtifact createMLPArtifact(
+                               String theSolutionId,
+                               String theRevisionId,
+                               MLPArtifact mlpArtifact,
+                               ICommonDataServiceRestClient cdsClient) {
                        MLPArtifact artifact = new MLPArtifact();
                        artifact.setArtifactId(mlpArtifact.getArtifactId());
                        artifact.setArtifactTypeCode(mlpArtifact.getArtifactTypeCode());
@@ -257,6 +263,7 @@ public class PeerGateway {
                        artifact.setVersion(mlpArtifact.getVersion());
                        try {
                                cdsClient.createArtifact(artifact);
+                               cdsClient.addSolutionRevisionArtifact(theSolutionId, theRevisionId, mlpArtifact.getArtifactId());
                                return artifact;
                        }
                        catch (HttpStatusCodeException restx) {
@@ -384,10 +391,23 @@ public class PeerGateway {
                                for(MLPArtifact artifact : acumosArtifacts) {
                                        MLPArtifact mlpArtifact = cdsClient.getArtifact(artifact.getArtifactId());
                                        if(mlpArtifact == null) {
-                                               createMLPArtifact(mlpArtifact, cdsClient);
-                                       } else {
-                                               updateMLPArtifact(artifact, mlpArtifact, cdsClient);
+                                               mlpArtifact = createMLPArtifact(
+                                                                                                               theSolution.getSolutionId(),
+                                                                                                               mlpSolutionRevision.getRevisionId(),
+                                                                                                               artifact,
+                                                                                                               cdsClient);
+                                       }
+                                       else {
+                                               mlpArtifact = updateMLPArtifact(artifact, mlpArtifact, cdsClient);
                                        }
+
+                                       if (mlpArtifact == null) {
+                                               //not transactional .. hard to recover from, we'll re-attempt
+                                               //next time we process the enclosing solution/revision (should be
+                                               //marked accordingly)
+                                               continue;
+                                       }
+
                                        //artifacts file download and push it to nexus
                                        Resource artifactContent = null;
                                        try {
@@ -398,17 +418,37 @@ public class PeerGateway {
                                                logger.warn(EELFLoggerDelegate.debugLogger, "Failed to retrieve acumos artifact content", x);
                                        }
 
+                                       UploadArtifactInfo uploadInfo = null;
                                        if (artifactContent != null) {
                                                try {
-                                                       PeerGateway.this.clients.getNexusClient().uploadArtifact("", "", "", "", 0, artifactContent.getInputStream());
+                                                       uploadInfo = 
+                                                               PeerGateway.this.clients.getNexusClient()
+                                                                       .uploadArtifact(
+                                                                                       PeerGateway.this.env.getProperty("nexus.groupId"),
+                                                                                       mlpArtifact.getName(), /* probably wrong */
+                                                                                       mlpArtifact.getVersion(),
+                                                                                       "", /* should receive this from peer */
+                                                                                       artifactContent.contentLength(),
+                                                                                       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);
+                                       if (uploadInfo != null) {
+                                               //update artifact with local repo reference
+                                               mlpArtifact.setUri(uploadInfo.getArtifactMvnPath());
+                                               try {
+                                                       cdsClient.updateArtifact(mlpArtifact);
+                                               }
+                                               catch (HttpStatusCodeException restx) {
+                                                       logger.error(EELFLoggerDelegate.debugLogger, "updateArtifact CDS call failed. CDS message is " + restx.getResponseBodyAsString(),  restx);
+                                               }
+                                               catch (Exception x) {
+                                                       logger.error(EELFLoggerDelegate.debugLogger, "updateArtifact unexpected failure",  x);
+                                               }
+                                       }
                                }
                                
                        }
index 794fc7a..ec2e2a1 100644 (file)
@@ -197,7 +197,9 @@ public class CatalogServiceImpl
                        
                        //Plain Old Java. Sprint 3 will use try resource handling
                        if(inputStream != null) {
-                               streamResource = new InputStreamResource(inputStream);
+                               streamResource = new InputStreamResource(inputStream
+                                                                                                                                                                                                /*, some_description
+                                                                                                                                                                                                       */);
                        }
                        if(byteArrayOutputStream != null) {
                                byteArrayOutputStream.close();
index 0d8910d..f6a8b85 100644 (file)
@@ -223,7 +223,13 @@ public class FederationClient extends AbstractClient {
                finally {
                        logger.info(EELFLoggerDelegate.debugLogger, uri + " response " + response);
                }
-               return response == null ? null : response.getBody();
+
+               if (response == null) {
+                       return null;
+               }
+               else {
+                       return response.getBody();
+               }
        }
 
 }