Config Assign
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAIUpdateTasks.java
index 58c51f6..c2cbdd1 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 
 package org.onap.so.bpmn.infrastructure.aai.tasks;
 
+import java.util.List;
+import java.util.Map;
+
 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
+import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
 import org.onap.so.bpmn.common.BuildingBlockExecution;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
@@ -28,6 +34,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
@@ -43,13 +50,17 @@ import org.onap.so.client.orchestration.AAIVfModuleResources;
 import org.onap.so.client.orchestration.AAIVnfResources;
 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
 import org.onap.so.db.catalog.beans.OrchestrationStatus;
-import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 @Component
 public class AAIUpdateTasks {
-       private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAIUpdateTasks.class);
+       private static final Logger logger = LoggerFactory.getLogger(AAIUpdateTasks.class);
+       private static final String ALACARTE = "aLaCarte";
+       private static final String MULTI_STAGE_DESIGN_OFF = "false";
+       private static final String MULTI_STAGE_DESIGN_ON = "true";
        @Autowired
        private AAIServiceInstanceResources aaiServiceInstanceResources;
        @Autowired
@@ -149,7 +160,9 @@ public class AAIUpdateTasks {
                try {
                        GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
                        String heatStackId = execution.getVariable("heatStackId");
-                       
+                       if (heatStackId == null) {
+                               heatStackId = "";
+                       }                       
                        VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID, execution.getLookupMap().get(ResourceKey.VOLUME_GROUP_ID));
                        CloudRegion cloudRegion = gBBInput.getCloudRegion();
                        volumeGroup.setHeatStackId(heatStackId);
@@ -181,6 +194,27 @@ public class AAIUpdateTasks {
                }
        }
        
+       public void updateOrchestrationStatusAssignedOrPendingActivationVfModule(BuildingBlockExecution execution) {
+               try {
+                       VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
+                       vfModule.setHeatStackId("");
+                       GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
+                       String multiStageDesign = MULTI_STAGE_DESIGN_OFF;
+                       if (vnf.getModelInfoGenericVnf() != null) {
+                               multiStageDesign = vnf.getModelInfoGenericVnf().getMultiStageDesign();
+                       }
+                       boolean aLaCarte = (boolean) execution.getVariable(ALACARTE);
+                       if (aLaCarte && multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) {
+                               aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule,vnf,OrchestrationStatus.PENDING_ACTIVATION);
+                       }
+                       else {
+                               aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule,vnf,OrchestrationStatus.ASSIGNED);
+                       }
+               } catch (Exception ex) {                        
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+               }
+       }
+       
        public void updateOrchestrationStatusCreatedVfModule(BuildingBlockExecution execution) {                
                try {
                        VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
@@ -209,22 +243,7 @@ public class AAIUpdateTasks {
         * @throws BBObjectNotFoundException 
         */
        public void updateOrchestrationStatusAssignedNetwork(BuildingBlockExecution execution) {
-               execution.setVariable("aaiNetworkAssignRollback", false);
-               try {
-                       L3Network l3network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
-                       L3Network copiedl3network = l3network.shallowCopyId();
-
-
-                       l3network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
-                       l3network.setHeatStackId("");
-
-                       copiedl3network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
-                       copiedl3network.setHeatStackId("");
-                       aaiNetworkResources.updateNetwork(copiedl3network);
-                       execution.setVariable("aaiNetworkAssignRollback", true);
-               } catch (Exception ex) {
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
-               }
+               updateNetwork(execution, OrchestrationStatus.ASSIGNED);
        }
        
        /**
@@ -233,18 +252,7 @@ public class AAIUpdateTasks {
         * @throws BBObjectNotFoundException 
         */
        public void updateOrchestrationStatusActiveNetwork(BuildingBlockExecution execution) {
-               execution.setVariable("aaiNetworkActivateRollback", false);
-               try {
-                       L3Network l3network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
-                       L3Network copiedl3network = l3network.shallowCopyId();
-
-                       copiedl3network.setOrchestrationStatus(OrchestrationStatus.ACTIVE);
-                       l3network.setOrchestrationStatus(OrchestrationStatus.ACTIVE);
-                       aaiNetworkResources.updateNetwork(copiedl3network);
-                       execution.setVariable("aaiNetworkActivateRollback", true);
-               } catch (Exception ex) {
-                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
-               }
+               updateNetwork(execution, OrchestrationStatus.ACTIVE);
        }
        
        /**
@@ -253,20 +261,35 @@ public class AAIUpdateTasks {
         * @throws BBObjectNotFoundException 
         */
        public void updateOrchestrationStatusCreatedNetwork(BuildingBlockExecution execution) {
-               execution.setVariable("aaiNetworkActivateRollback", false);
+               updateNetwork(execution, OrchestrationStatus.CREATED);
+       }
+       
+       protected void updateNetwork(BuildingBlockExecution execution, OrchestrationStatus status) {
                try {
-                       L3Network l3network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
-                       L3Network copiedl3network = l3network.shallowCopyId();
-
-                       copiedl3network.setOrchestrationStatus(OrchestrationStatus.CREATED);
-                       l3network.setOrchestrationStatus(OrchestrationStatus.CREATED);
-                       aaiNetworkResources.updateNetwork(copiedl3network);
-                       execution.setVariable("aaiNetworkActivateRollback", true);
+                       L3Network l3Network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
+                       updateNetworkAAI(l3Network, status);
                } catch (Exception ex) {
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
                }
        }
        
+       protected void updateNetworkAAI(L3Network l3Network, OrchestrationStatus status) {
+               L3Network copiedl3Network = l3Network.shallowCopyId();
+
+               copiedl3Network.setOrchestrationStatus(status);
+               l3Network.setOrchestrationStatus(status);
+               aaiNetworkResources.updateNetwork(copiedl3Network);
+               
+               List<Subnet> subnets = l3Network.getSubnets();
+               if (subnets != null){
+                       for (Subnet subnet : subnets){
+                               Subnet copiedSubnet = subnet.shallowCopyId();
+                               copiedSubnet.setOrchestrationStatus(status);
+                               aaiNetworkResources.updateSubnet(copiedl3Network, copiedSubnet);
+                       }
+               }
+       }
+       
        /**
         * BPMN access method to update status of L3Network Collection to Active in AAI
         * @param execution
@@ -303,6 +326,9 @@ public class AAIUpdateTasks {
        public void updateHeatStackIdVfModule(BuildingBlockExecution execution) {               
                try {
                        String heatStackId = execution.getVariable("heatStackId");
+                       if (heatStackId == null) {
+                               heatStackId = "";
+                       }
                        VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
                        GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
                        vfModule.setHeatStackId(heatStackId);
@@ -313,7 +339,7 @@ public class AAIUpdateTasks {
        }
        
        /**
-        * BPMN access method to update L3Network after it was created in AIC
+        * BPMN access method to update L3Network after it was created in cloud
         * @param execution
         * @throws Exception
         */
@@ -336,12 +362,52 @@ public class AAIUpdateTasks {
                        copiedl3network.setNeutronNetworkId(response.getNeutronNetworkId());
 
                        aaiNetworkResources.updateNetwork(copiedl3network);
+                       
+                       Map<String, String> subnetMap = response.getSubnetMap();
+                       List<Subnet> subnets = l3network.getSubnets();
+                       if (subnets != null && subnetMap != null){
+                               for (Subnet subnet: subnets){
+                                       Subnet copiedSubnet = subnet.shallowCopyId();
+                                       copiedSubnet.setNeutronSubnetId(subnetMap.get(copiedSubnet.getSubnetId()));
+                                       copiedSubnet.setOrchestrationStatus(OrchestrationStatus.CREATED);
+                                       aaiNetworkResources.updateSubnet(copiedl3network, copiedSubnet);
+                               }
+                       }
+                       
                        execution.setVariable("aaiNetworkActivateRollback", true);
                } catch (Exception ex) {
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
                }
        }
        
+       /**
+        * BPMN access method to update L3Network after it was updated in cloud
+        * @param execution
+        * @throws Exception
+        */
+       public void updateNetworkUpdated(BuildingBlockExecution execution) throws Exception {
+               L3Network l3network =  extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
+               L3Network copiedl3network = l3network.shallowCopyId();
+               UpdateNetworkResponse response = execution.getVariable("updateNetworkResponse");
+               try {
+                       copiedl3network.setNeutronNetworkId(response.getNeutronNetworkId());
+                       aaiNetworkResources.updateNetwork(copiedl3network);
+                       
+                       Map<String, String> subnetMap = response.getSubnetMap();
+                       List<Subnet> subnets = l3network.getSubnets();
+                       if (subnets != null && subnetMap != null){
+                               for (Subnet subnet: subnets){
+                                       Subnet copiedSubnet = subnet.shallowCopyId();
+                                       copiedSubnet.setNeutronSubnetId(subnetMap.get(copiedSubnet.getSubnetId()));
+                                       copiedSubnet.setOrchestrationStatus(OrchestrationStatus.CREATED);
+                                       aaiNetworkResources.updateSubnet(copiedl3network, copiedSubnet);
+                               }
+                       }
+               } catch (Exception ex) {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+               }
+       }
+       
        public void updateObjectNetwork(BuildingBlockExecution execution) {
                try {
                        L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID));
@@ -415,4 +481,61 @@ public class AAIUpdateTasks {
                        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
                }
        }
-}
\ No newline at end of file
+       
+       public void updateIpv4OamAddressVnf(BuildingBlockExecution execution) {
+               try {
+                       String ipv4OamAddress = execution.getVariable("oamManagementV4Address");
+                       if (ipv4OamAddress != null) {
+                               GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
+                               GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
+                       
+                               genericVnf.setIpv4OamAddress(ipv4OamAddress);   
+                               copiedGenericVnf.setIpv4OamAddress(ipv4OamAddress);             
+
+                               aaiVnfResources.updateObjectVnf(copiedGenericVnf);
+                       }
+               } catch(Exception ex) {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+               }
+       }
+       
+       public void updateManagementV6AddressVnf(BuildingBlockExecution execution) {
+               try {
+                       String managementV6Address = execution.getVariable("oamManagementV6Address");
+                       if (managementV6Address != null) {
+                               GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
+                               GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
+                       
+                               genericVnf.setManagementV6Address(managementV6Address); 
+                               copiedGenericVnf.setManagementV6Address(managementV6Address);           
+
+                               aaiVnfResources.updateObjectVnf(copiedGenericVnf);
+                       }
+               } catch(Exception ex) {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+               }
+       }
+       
+       public void updateContrailServiceInstanceFqdnVfModule(BuildingBlockExecution execution) {               
+               try {
+                       String contrailServiceInstanceFqdn = execution.getVariable("contrailServiceInstanceFqdn");
+                       if (contrailServiceInstanceFqdn != null) {
+                               VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID));
+                               GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
+                               vfModule.setContrailServiceInstanceFqdn(contrailServiceInstanceFqdn);
+                               aaiVfModuleResources.updateContrailServiceInstanceFqdnVfModule(vfModule, vnf);
+                       }
+               } catch (Exception ex) {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+               }
+       }
+       
+       public void updateOrchestrationStatusConfigAssignedVnf(BuildingBlockExecution execution) {
+               try {
+                       GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
+                       aaiVnfResources.updateOrchestrationStatusVnf(vnf, OrchestrationStatus.CONFIGASSIGNED);
+               } catch (Exception ex) {
+                       exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+               }
+       }
+}