[SDC-DIST] Upgrade asdc-controller to use client version 2.0.0
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / client / ASDCController.java
index c9d4f4d..8e3c5f4 100644 (file)
@@ -39,7 +39,7 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Paths;
 import java.util.List;
 import java.util.Optional;
-import org.onap.so.logger.LoggingAnchor;
+import org.onap.logging.filter.base.ErrorCode;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.onap.sdc.api.IDistributionClient;
 import org.onap.sdc.api.consumer.IDistributionStatusMessage;
@@ -50,6 +50,8 @@ import org.onap.sdc.api.notification.IResourceInstance;
 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
 import org.onap.sdc.api.results.IDistributionClientResult;
 import org.onap.sdc.impl.DistributionClientFactory;
+import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
 import org.onap.sdc.utils.DistributionActionResultEnum;
 import org.onap.sdc.utils.DistributionStatusEnum;
 import org.onap.so.asdc.activity.DeployActivitySpecs;
@@ -67,11 +69,12 @@ import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
 import org.onap.so.asdc.tenantIsolation.DistributionStatus;
 import org.onap.so.asdc.tenantIsolation.WatchdogDistribution;
 import org.onap.so.asdc.util.ASDCNotificationLogging;
+import org.onap.so.asdc.util.ZipParser;
 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
-import org.onap.so.logger.ErrorCode;
+import org.onap.so.logger.LoggingAnchor;
 import org.onap.so.logger.MessageEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -144,6 +147,10 @@ public class ASDCController {
         this.controllerName = controllerConfigName;
     }
 
+    public ASDCConfiguration getASDCConfiguration() {
+        return asdcConfig;
+    }
+
     public int getNbOfNotificationsOngoing() {
         return nbOfNotificationsOngoing;
     }
@@ -737,6 +744,7 @@ public class ASDCController {
 
     protected void processResourceNotification(INotificationData iNotif) {
         // For each artifact, create a structure describing the VFModule in a ordered flat level
+        ResourceStructure resourceStructure = null;
         String msoConfigPath = getMsoConfigPath();
         ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath);
         DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK;
@@ -748,8 +756,14 @@ public class ASDCController {
             if (isCsarAlreadyDeployed(iNotif, toscaResourceStructure)) {
                 return;
             }
+            // process NsstResource
+            this.processNsstNotification(iNotif, toscaResourceStructure);
+
+            if (iNotif.getResources().isEmpty()) {
+                logger.error("Service Model contains no resources.");
+                return;
+            }
 
-            ResourceStructure resourceStructure = null;
             for (IResourceInstance resource : iNotif.getResources()) {
 
                 String resourceType = resource.getResourceType();
@@ -914,6 +928,23 @@ public class ASDCController {
                             "processCsarServiceArtifacts", ErrorCode.BusinessProcessError.getValue(),
                             "Exception in processCsarServiceArtifacts", e);
                 }
+            } else if (artifact.getArtifactType().equals(ASDCConfiguration.OTHER)) {
+                try {
+                    IDistributionClientDownloadResult resultArtifact =
+                            this.downloadTheArtifact(artifact, iNotif.getDistributionID());
+
+                    writeArtifactToFile(artifact, resultArtifact);
+
+                    toscaResourceStructure.setToscaArtifact(artifact);
+
+                    toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion());
+
+                } catch (ASDCDownloadException e) {
+                    logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(),
+                            "Exception caught during processCsarServiceArtifacts", "ASDC",
+                            "processCsarServiceArtifacts", ErrorCode.BusinessProcessError.getValue(),
+                            "Exception in processCsarServiceArtifacts", e);
+                }
             }
 
 
@@ -926,7 +957,7 @@ public class ASDCController {
      */
     public String getAddress() {
         if (asdcConfig != null) {
-            return asdcConfig.getAsdcAddress();
+            return asdcConfig.getSdcAddress();
         }
         return UNKNOWN;
     }
@@ -940,4 +971,44 @@ public class ASDCController {
         }
         return UNKNOWN;
     }
+
+    private void processNsstNotification(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
+        Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
+        try {
+            String category = serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
+            boolean isNeedInital = (category.contains("NSST") || category.equalsIgnoreCase("TN Network Requirement"))
+                    && iNotif.getResources().isEmpty();
+            if (isNeedInital) {
+                String artifactContent = null;
+                List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
+                Optional<IArtifactInfo> artifactOpt = serviceArtifacts.stream()
+                        .filter(e -> e.getArtifactType().equalsIgnoreCase("WORKFLOW")).findFirst();
+                if (artifactOpt.isPresent()) {
+                    IArtifactInfo artifactInfo = artifactOpt.get();
+                    logger.debug("Ready to parse this serviceArtifactUUID:  " + artifactInfo.getArtifactUUID());
+                    String filePath = Paths.get(getMsoConfigPath(), "ASDC", artifactInfo.getArtifactVersion(),
+                            artifactInfo.getArtifactName()).normalize().toString();
+                    ZipParser zipParserInstance = ZipParser.getInstance();
+                    artifactContent = zipParserInstance.parseJsonForZip(filePath);
+                    logger.debug(
+                            "serviceArtifact parsing success! serviceArtifactUUID: " + artifactInfo.getArtifactUUID());
+
+                    ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance());
+                    resourceStructure.setResourceType(ResourceType.OTHER);
+                    toscaInstaller.installNsstService(toscaResourceStructure, (VfResourceStructure) resourceStructure,
+                            artifactContent);
+                } else {
+                    logger.debug("serviceArtifact is null");
+                    toscaInstaller.installNsstService(toscaResourceStructure, null, null);
+                }
+
+            }
+
+        } catch (IOException e) {
+            logger.error("serviceArtifact parse failure for service uuid:  "
+                    + serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
+        } catch (Exception e) {
+            logger.error("error NSST process resource failure ", e);
+        }
+    }
 }