Merge "Reorder modifiers"
[so.git] / adapters / mso-network-adapter / src / main / java / org / openecomp / mso / adapters / network / MsoNetworkAdapterImpl.java
index e5e6c85..7f0f988 100644 (file)
@@ -71,6 +71,12 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
        MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory();
 
        CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
+       
+       protected MsoNeutronUtils neutron;
+    
+       protected MsoHeatUtils heat;
+    
+       protected MsoHeatUtilsWithUpdate heatWithUpdate;
 
        private static final String AIC3_NW_PROPERTY= "org.openecomp.mso.adapters.network.aic3nw";
        private static final String AIC3_NW="OS::ContrailV2::VirtualNetwork";
@@ -85,7 +91,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
     private static final String NEUTRON_MODE = "NEUTRON";
     private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
     private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
-    protected CloudConfig cloudConfig;
 
     /**
      * Health Check web method. Does nothing but return to show the adapter is deployed.
@@ -111,7 +116,10 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
     public MsoNetworkAdapterImpl(MsoPropertiesFactory msoPropFactory,CloudConfigFactory cloudConfigFact) {
        this.msoPropertiesFactory = msoPropFactory;
        this.cloudConfigFactory=cloudConfigFact;
-       cloudConfig = cloudConfigFactory.getCloudConfig ();
+       neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
+       heat = new MsoHeatUtils(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory, cloudConfigFactory);
+       heatWithUpdate = new MsoHeatUtilsWithUpdate(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
+                       cloudConfigFactory);
     }
 
     @Override
@@ -226,7 +234,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
      * the orchestration fails on a subsequent operation.
      */
 
-    private void createNetwork (String cloudSiteId,
+    protected void createNetwork (String cloudSiteId,
                                String tenantId,
                                String networkType,
                                String modelCustomizationUuid,
@@ -272,7 +280,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         // If the tenant doesn’t exist, the Heat calls will fail anyway (when the HeatUtils try to obtain a token).
         // So this is just catching that error in a bit more obvious way up front.
 
-        cloudConfig = cloudConfigFactory.getCloudConfig ();
+        CloudConfig cloudConfig = getCloudConfigFactory().getCloudConfig ();
         Optional<CloudSite> cloudSiteOpt = cloudConfig.getCloudSite(cloudSiteId);
         if (!cloudSiteOpt.isPresent())
         {
@@ -306,9 +314,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
 
             if (NEUTRON_MODE.equals(mode)) {
 
-                // Use an MsoNeutronUtils for all neutron commands
-                MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
-
                 // See if the Network already exists (by name)
                 NetworkInfo netInfo = null;
                 long queryNetworkStarttime = System.currentTimeMillis();
@@ -406,10 +411,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 LOGGER.debug("Network " + networkName + " created, id = " + netInfo.getId());
             } else if ("HEAT".equals(mode)) {
 
-                // Use an MsoHeatUtils for all Heat commands
-                MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
-                    cloudConfigFactory);
-
                 //HeatTemplate heatTemplate = db.getHeatTemplate (networkResource.getTemplateId ());
                 HeatTemplate heatTemplate = db
                     .getHeatTemplateByArtifactUuidRegularQuery(networkResource.getHeatTemplateArtifactUUID());
@@ -826,7 +827,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         networkRollback.setTenantId (tenantId);
         networkRollback.setMsoRequest (msoRequest);
 
-        cloudConfig = cloudConfigFactory.getCloudConfig ();
+        CloudConfig cloudConfig = getCloudConfigFactory().getCloudConfig ();
         Optional<CloudSite> cloudSiteOpt = cloudConfig.getCloudSite (cloudSiteId);
         if (!cloudSiteOpt.isPresent()) {
                   String error = "UpdateNetwork: Configuration Error. Stack " + networkName + " in "
@@ -857,9 +858,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             String mode = networkResource.getOrchestrationMode();
             NetworkType neutronNetworkType = NetworkType.valueOf(networkResource.getNeutronNetworkType());
 
-            // Use an MsoNeutronUtils for all Neutron commands
-            MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
-
             if (NEUTRON_MODE.equals(mode)) {
 
                 // Verify that the Network exists
@@ -943,16 +941,12 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 LOGGER.debug("Network " + networkId + " updated, id = " + netInfo.getId());
             } else if ("HEAT".equals(mode)) {
 
-                // Use an MsoHeatUtils for all Heat commands
-                MsoHeatUtilsWithUpdate heat = new MsoHeatUtilsWithUpdate(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
-                    cloudConfigFactory);
-
                 // First, look up to see that the Network already exists.
                 // For Heat-based orchestration, the networkId is the network Stack ID.
                 StackInfo heatStack = null;
                 long queryStackStarttime = System.currentTimeMillis();
                 try {
-                    heatStack = heat.queryStack(cloudSiteId, tenantId, networkName);
+                    heatStack = heatWithUpdate.queryStack(cloudSiteId, tenantId, networkName);
                     LOGGER.recordMetricEvent(queryStackStarttime, MsoLogger.StatusCode.COMPLETE,
                         MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack",
                         "QueryStack", null);
@@ -1056,7 +1050,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 // Validate (and update) the input parameters against the DB definition
                 // Shouldn't happen unless DB config is wrong, since all networks use same inputs
                 try {
-                    stackParams = heat.validateStackParams(stackParams, heatTemplate);
+                    stackParams = heatWithUpdate.validateStackParams(stackParams, heatTemplate);
                 } catch (IllegalArgumentException e) {
                     String error = "UpdateNetwork: Configuration Error: Network Type=" + networkType;
                     LOGGER.error(MessageEnum.RA_CONFIG_EXC, "Network Type=" + networkType, "OpenStack", "",
@@ -1138,7 +1132,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 // Ignore MsoStackNotFound exception because we already checked.
                 long updateStackStarttime = System.currentTimeMillis();
                 try {
-                    heatStack = heat.updateStack(cloudSiteId,
+                    heatStack = heatWithUpdate.updateStack(cloudSiteId,
                         tenantId,
                         networkId,
                         template,
@@ -1202,7 +1196,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         return;
     }
 
-    private NetworkResource networkCheck (CatalogDatabase db,
+    protected NetworkResource networkCheck (CatalogDatabase db,
                                           long startTime,
                                           String networkType,
                                           String modelCustomizationUuid,
@@ -1388,7 +1382,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             throw new NetworkException (error, MsoExceptionCategory.USERDATA);
         }
 
-        cloudConfig = cloudConfigFactory.getCloudConfig();
+        CloudConfig cloudConfig = getCloudConfigFactory().getCloudConfig();
         Optional<CloudSite> cloudSiteOpt = cloudConfig.getCloudSite(cloudSiteId);
         if (!cloudSiteOpt.isPresent())
         {
@@ -1404,10 +1398,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                throw new NetworkException (error, MsoExceptionCategory.USERDATA);
         }
 
-        // Use MsoNeutronUtils for all NEUTRON commands
-        MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_NETWORK_ADAPTER,msoPropertiesFactory,cloudConfigFactory);
-        MsoNeutronUtils neutron = new MsoNeutronUtils (MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
-
         String mode;
         String neutronId;
         // Try Heat first, since networks may be named the same as the Heat stack
@@ -1582,9 +1572,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             }
 
             if (NEUTRON_MODE.equals(mode)) {
-
-                // Use MsoNeutronUtils for all NEUTRON commands
-                MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
                 long deleteNetworkStarttime = System.currentTimeMillis();
                 try {
                     // The deleteNetwork function in MsoNeutronUtils returns success if the network
@@ -1613,9 +1600,6 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 }
             } else { // DEFAULT to ("HEAT".equals (mode))
                 long deleteStackStarttime = System.currentTimeMillis();
-                // Use MsoHeatUtils for all HEAT commands
-                MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
-                    cloudConfigFactory);
 
                 try {
                     // The deleteStack function in MsoHeatUtils returns NOTFOUND if the stack was not found or if the stack was deleted.
@@ -1660,6 +1644,10 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         return CatalogDatabase.getInstance();
     }
 
+    public CloudConfigFactory getCloudConfigFactory() {
+        return cloudConfigFactory;
+    }
+
     /**
      * This web service endpoint will rollback a previous Create VNF operation.
      * A rollback object is returned to the client in a successful creation
@@ -1717,7 +1705,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 // Rolling back a newly created network, so delete it.
                 if (NEUTRON_MODE.equals(mode)) {
                     // Use MsoNeutronUtils for all NEUTRON commands
-                    MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, cloudConfigFactory);
+                    MsoNeutronUtils neutron = new MsoNeutronUtils(MSO_PROP_NETWORK_ADAPTER, getCloudConfigFactory());
                     long deleteNetworkStarttime = System.currentTimeMillis();
                     try {
                         // The deleteNetwork function in MsoNeutronUtils returns success if the network
@@ -1748,7 +1736,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 } else { // DEFAULT to if ("HEAT".equals (mode))
                     // Use MsoHeatUtils for all HEAT commands
                     MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_NETWORK_ADAPTER, msoPropertiesFactory,
-                        cloudConfigFactory);
+                        getCloudConfigFactory());
                     long deleteStackStarttime = System.currentTimeMillis();
                     try {
                         // The deleteStack function in MsoHeatUtils returns success if the stack
@@ -1807,7 +1795,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         return missing.toString ();
     }
 
-    private Map <String, Object> populateNetworkParams (NetworkType neutronNetworkType,
+    protected Map <String, Object> populateNetworkParams (NetworkType neutronNetworkType,
                                                         String networkName,
                                                         String physicalNetwork,
                                                         List <Integer> vlans,