Merge "Enhanced List Level flow with backward support"
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / adapters / network / MsoNetworkAdapterImpl.java
index 029da43..d9f47f5 100644 (file)
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.Optional;
 import javax.jws.WebService;
 import javax.xml.ws.Holder;
+import org.onap.so.logger.LoggingAnchor;
 import org.onap.so.adapters.network.beans.ContrailPolicyRef;
 import org.onap.so.adapters.network.beans.ContrailPolicyRefSeq;
 import org.onap.so.adapters.network.beans.ContrailSubnet;
@@ -205,7 +206,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             String error = String.format(
                     "Configuration Error. Stack %s in %s/%s: CloudSite does not exist in MSO Configuration",
                     networkName, cloudSiteId, tenantId);
-            logger.error("{} {} {}", MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
             // Set the detailed error as the Exception 'message'
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
@@ -240,8 +241,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 if (failIfExists != null && failIfExists) {
                     String error = String.format("Create Nework: Network %s already exists in %s/%s with ID %s",
                             networkName, cloudSiteId, tenantId, netInfo.getId());
-                    logger.error("{} {} {}", MessageEnum.RA_NETWORK_ALREADY_EXIST, ErrorCode.DataError.getValue(),
-                            error);
+                    logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_ALREADY_EXIST,
+                            ErrorCode.DataError.getValue(), error);
                     throw new NetworkException(error, MsoExceptionCategory.USERDATA);
                 } else {
                     // Populate the outputs from the existing network.
@@ -285,7 +286,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             HeatTemplate heatTemplate = networkResource.getHeatTemplate();
             if (heatTemplate == null) {
                 String error = String.format("Network error - undefined Heat Template. Network Type = %s", networkType);
-                logger.error("{} {} {}", MessageEnum.RA_PARAM_NOT_FOUND, ErrorCode.DataError.getValue(), error);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_PARAM_NOT_FOUND, ErrorCode.DataError.getValue(),
+                        error);
                 throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
             }
 
@@ -322,8 +324,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 if (failIfExists != null && failIfExists) {
                     String error = String.format("CreateNetwork: Stack %s already exists in %s/%s as %s", networkName,
                             cloudSiteId, tenantId, heatStack.getCanonicalName());
-                    logger.error("{} {} {}", MessageEnum.RA_NETWORK_ALREADY_EXIST, ErrorCode.DataError.getValue(),
-                            error);
+                    logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_ALREADY_EXIST,
+                            ErrorCode.DataError.getValue(), error);
                     throw new NetworkException(error, MsoExceptionCategory.USERDATA);
                 } else {
                     // Populate the outputs from the existing stack.
@@ -371,7 +373,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 stackParams = heat.validateStackParams(stackParams, heatTemplate);
             } catch (IllegalArgumentException e) {
                 String error = "Create Network: Configuration Error: " + e.getMessage();
-                logger.error("{} {} {} ", MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error, e);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error, e);
                 // Input parameters were not valid
                 throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
             }
@@ -537,7 +539,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             String error = String.format(
                     "UpdateNetwork: Configuration Error. Stack %s in %s/%s: CloudSite does not exist in MSO Configuration",
                     networkName, cloudSiteId, tenantId);
-            logger.error("{} {} {}", MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
             // Set the detailed error as the Exception 'message'
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
@@ -569,8 +571,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             if (netInfo == null) {
                 String error = String.format("Update Nework: Network %s does not exist in %s/%s", networkId,
                         cloudSiteId, tenantId);
-                logger.error("{} {} {}", MessageEnum.RA_NETWORK_NOT_FOUND, ErrorCode.BusinessProcesssError.getValue(),
-                        error);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_NOT_FOUND,
+                        ErrorCode.BusinessProcesssError.getValue(), error);
                 // Does not exist. Throw an exception (can't update a non-existent network)
                 throw new NetworkException(error, MsoExceptionCategory.USERDATA);
             }
@@ -613,7 +615,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             if (heatStack == null || (heatStack.getStatus() == HeatStatus.NOTFOUND)) {
                 String error = String.format("UpdateNetwork: Stack %s does not exist in %s/%s", networkName,
                         cloudSiteId, tenantId);
-                logger.error("{} {} {}", MessageEnum.RA_NETWORK_NOT_FOUND, ErrorCode.DataError.getValue(), error);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_NOT_FOUND, ErrorCode.DataError.getValue(),
+                        error);
                 // Network stack does not exist. Return an error
                 throw new NetworkException(error, MsoExceptionCategory.USERDATA);
             }
@@ -644,7 +647,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             HeatTemplate heatTemplate = networkResource.getHeatTemplate();
             if (heatTemplate == null) {
                 String error = "Network error - undefined Heat Template. Network Type=" + networkType;
-                logger.error("{} {} {}", MessageEnum.RA_PARAM_NOT_FOUND, ErrorCode.DataError.getValue(), error);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_PARAM_NOT_FOUND, ErrorCode.DataError.getValue(),
+                        error);
                 throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
             }
 
@@ -672,7 +676,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 stackParams = heat.validateStackParams(stackParams, heatTemplate);
             } catch (IllegalArgumentException e) {
                 String error = "UpdateNetwork: Configuration Error: Network Type=" + networkType;
-                logger.error("{} {} {} ", MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
                 throw new NetworkException(error, MsoExceptionCategory.INTERNAL, e);
             }
 
@@ -802,7 +806,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             String error = String.format(
                     "Create/UpdateNetwork: Unable to get network resource with NetworkType: %s or ModelCustomizationUUID:%s",
                     networkType, modelCustomizationUuid);
-            logger.error("{} {} {} ", MessageEnum.RA_UNKOWN_PARAM, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_UNKOWN_PARAM, ErrorCode.DataError.getValue(), error);
 
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
@@ -814,8 +818,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         // All Networks are orchestrated via HEAT or Neutron
         if (!("HEAT".equals(mode) || NEUTRON_MODE.equals(mode))) {
             String error = "CreateNetwork: Configuration Error: Network Type = " + networkType;
-            logger.error("{} {} {}", MessageEnum.RA_NETWORK_ORCHE_MODE_NOT_SUPPORT, ErrorCode.DataError.getValue(),
-                    error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_NETWORK_ORCHE_MODE_NOT_SUPPORT,
+                    ErrorCode.DataError.getValue(), error);
             throw new NetworkException(error, MsoExceptionCategory.INTERNAL);
         }
 
@@ -836,7 +840,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                     "Network Type:%s Version_Min:%s Version_Max:%s not supported on Cloud:%s with AIC_Version:%s",
                     networkType, networkType, networkResource.getAicVersionMin(), networkResource.getAicVersionMax(),
                     cloudSiteId, cloudSite.getCloudVersion());
-            logger.error("{} {} {} ", MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
 
@@ -845,7 +849,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 validateNetworkParams(neutronNetworkType, networkName, physicalNetworkName, vlans, routeTargets);
         if (!missing.isEmpty()) {
             String error = "Create Network: Missing parameters: " + missing;
-            logger.error("{} {} {}", MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
 
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
@@ -890,7 +894,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 || commonUtils.isNullOrEmpty(networkNameOrId)) {
 
             String error = "Missing mandatory parameter cloudSiteId, tenantId or networkId";
-            logger.error("{} {} {}", MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
 
@@ -899,7 +903,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             String error = String.format(
                     "Configuration Error. Stack %s in %s/%s: CloudSite does not exist in MSO Configuration",
                     networkNameOrId, cloudSiteId, tenantId);
-            logger.error("{} {} {}", MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_CONFIG_EXC, ErrorCode.DataError.getValue(), error);
             // Set the detailed error as the Exception 'message'
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
@@ -958,7 +962,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             if (netInfo != null) {
                 // Found. Populate the output elements
                 networkExists.value = Boolean.TRUE;
-                if ("HEAT".equals(mode)) {
+                if ("HEAT".equals(mode) && heatStack != null) {
                     networkId.value = heatStack.getCanonicalName();
                 } else {
                     networkId.value = netInfo.getId();
@@ -1017,7 +1021,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         if (commonUtils.isNullOrEmpty(cloudSiteId) || commonUtils.isNullOrEmpty(tenantId)
                 || commonUtils.isNullOrEmpty(networkId)) {
             String error = "Missing mandatory parameter cloudSiteId, tenantId or networkId";
-            logger.error("{} {} {} ", MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
             throw new NetworkException(error, MsoExceptionCategory.USERDATA);
         }
 
@@ -1290,15 +1294,23 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
         // Resource Property
         List<ContrailPolicyRef> prlist = new ArrayList<>();
         int index = 1;
-        for (String pf : pFqdns) {
-            if (!commonUtils.isNullOrEmpty(pf)) {
-                ContrailPolicyRef pr = new ContrailPolicyRef();
-                ContrailPolicyRefSeq refSeq = new ContrailPolicyRefSeq(String.valueOf(index), "0");
-                pr.setSeq(refSeq);
-                index++;
-                logger.debug("Contrail PolicyRefs Data:{}", pr);
-                prlist.add(pr);
+
+        if (pFqdns != null) {
+            for (String pf : pFqdns) {
+                if (!commonUtils.isNullOrEmpty(pf)) {
+                    ContrailPolicyRef pr = new ContrailPolicyRef();
+                    ContrailPolicyRefSeq refSeq = new ContrailPolicyRefSeq(String.valueOf(index), "0");
+                    pr.setSeq(refSeq);
+                    index++;
+                    logger.debug("Contrail PolicyRefs Data:{}", pr);
+                    prlist.add(pr);
+                }
             }
+        } else {
+            String error = "Null pFqdns at start of mergePolicyRefs";
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.BusinessProcesssError.getValue(),
+                    error);
+            throw new MsoAdapterException(error);
         }
 
         JsonNode node = null;
@@ -1309,8 +1321,8 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             logger.debug("Json PolicyRefs Data:{}", jsonString);
         } catch (Exception e) {
             String error = "Error creating JsonNode for policyRefs Data";
-            logger.error("{} {} {} ", MessageEnum.RA_MARSHING_ERROR, ErrorCode.BusinessProcesssError.getValue(), error,
-                    e);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.BusinessProcesssError.getValue(),
+                    error, e);
             throw new MsoAdapterException(error);
         }
         // update parameters
@@ -1386,7 +1398,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
             logger.debug("Json Subnet List:{}", jsonString);
         } catch (Exception e) {
             String error = "Error creating JsonNode from input subnets";
-            logger.error("{} {} {} ", MessageEnum.RA_MARSHING_ERROR, ErrorCode.DataError.getValue(), error, e);
+            logger.error(LoggingAnchor.THREE, MessageEnum.RA_MARSHING_ERROR, ErrorCode.DataError.getValue(), error, e);
             throw new MsoAdapterException(error);
         }
         // update parameters
@@ -1432,7 +1444,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 curR = curR.replace("%subnetId%", subnet.getSubnetId());
             } else {
                 String error = "Missing Required AAI SubnetId for subnet in HEAT Template";
-                logger.error("{} {} {} ", MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
                 throw new MsoAdapterException(error);
             }
 
@@ -1446,7 +1458,7 @@ public class MsoNetworkAdapterImpl implements MsoNetworkAdapter {
                 curR = curR.replace("%cidr%", subnet.getCidr());
             } else {
                 String error = "Missing Required cidr for subnet in HEAT Template";
-                logger.error("{} {} {} ", MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
+                logger.error(LoggingAnchor.THREE, MessageEnum.RA_MISSING_PARAM, ErrorCode.DataError.getValue(), error);
                 throw new MsoAdapterException(error);
             }