diff options
Diffstat (limited to 'adapters/mso-openstack-adapters/src/main')
-rw-r--r-- | adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java | 141 |
1 files changed, 62 insertions, 79 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java index d092b49d8c..344daa83bc 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImpl.java @@ -174,10 +174,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { Holder<Map<String, String>> outputs) throws VnfException { logger.debug("Querying VNF {} in {}", vnfName, cloudSiteId + "/" + tenantId); - // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); - long subStartTime = System.currentTimeMillis(); - DeploymentInfo deployment = null; try { @@ -188,6 +184,7 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { deployment = null; } catch (MsoException me) { // Failed to query the Deployment due to a cloudify exception. + logger.debug("Failed to query the Deployment due to a cloudify exception"); // Convert to a generic VnfException me.addContext("QueryVNF"); String error = "Query VNF (Cloudify): " + vnfName + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId @@ -213,7 +210,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { logger.debug("VNF {} not found", vnfName); } - return; } @@ -239,7 +235,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { */ @Override public void rollbackVnf(VnfRollback rollback) throws VnfException { - long startTime = System.currentTimeMillis(); // rollback may be null (e.g. if stack already existed when Create was called) if (rollback == null) { logger.info("{} {} {}", MessageEnum.RA_ROLLBACK_NULL.toString(), OPENSTACK, "rollbackVnf"); @@ -265,7 +260,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { // The possible outcomes of deleteStack are a StackInfo object with status // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException // could be thrown. - long subStartTime = System.currentTimeMillis(); try { // KLUDGE - Cloudify requires Tenant Name for Openstack. We have the ID. // Go directly to Keystone until APIs could be updated to supply the name. @@ -288,7 +282,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { logger.debug(error); throw new VnfException(me); } - return; } @@ -316,37 +309,38 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } private Map<String, String> copyStringOutputs(Map<String, Object> stackOutputs) { - Map<String, String> stringOutputs = new HashMap<String, String>(); - for (String key : stackOutputs.keySet()) { - if (stackOutputs.get(key) instanceof String) { - stringOutputs.put(key, (String) stackOutputs.get(key)); - } else if (stackOutputs.get(key) instanceof Integer) { + Map<String, String> stringOutputs = new HashMap<>(); + for (Map.Entry<String, Object> entry : stackOutputs.entrySet()) { + if (entry.getValue() instanceof String) { + stringOutputs.put(entry.getKey(), (String) entry.getValue()); + } else if (entry.getValue() instanceof Integer) { try { - String str = "" + stackOutputs.get(key); - stringOutputs.put(key, str); + String str = "" + entry.getValue(); + stringOutputs.put(entry.getKey(), str); } catch (Exception e) { - logger.debug("Unable to add " + key + " to outputs"); + logger.error("Unable to add " + entry.getKey() + " to outputs", e); } - } else if (stackOutputs.get(key) instanceof JsonNode) { + } else if (entry.getValue() instanceof JsonNode) { try { - String str = this.convertNode((JsonNode) stackOutputs.get(key)); - stringOutputs.put(key, str); + String str = this.convertNode((JsonNode) entry.getValue()); + stringOutputs.put(entry.getKey(), str); } catch (Exception e) { - logger.debug("Unable to add " + key + " to outputs - exception converting JsonNode"); + logger.error("Unable to add " + entry.getKey() + " to outputs - exception converting JsonNode", e); } - } else if (stackOutputs.get(key) instanceof java.util.LinkedHashMap) { + } else if (entry.getValue() instanceof java.util.LinkedHashMap) { try { - String str = JSON_MAPPER.writeValueAsString(stackOutputs.get(key)); - stringOutputs.put(key, str); + String str = JSON_MAPPER.writeValueAsString(entry.getValue()); + stringOutputs.put(entry.getKey(), str); } catch (Exception e) { - logger.debug("Unable to add " + key + " to outputs - exception converting LinkedHashMap"); + logger.error("Unable to add " + entry.getKey() + " to outputs - exception converting LinkedHashMap", + e); } } else { try { - String str = stackOutputs.get(key).toString(); - stringOutputs.put(key, str); + String str = entry.getValue().toString(); + stringOutputs.put(entry.getKey(), str); } catch (Exception e) { - logger.debug("Unable to add " + key + " to outputs - unable to call .toString() " + e.getMessage()); + logger.error("Unable to add " + entry.getKey() + " to outputs - unable to call .toString() ", e); } } } @@ -362,18 +356,17 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } else if (inputs.size() < 1) { sb.append("\tEMPTY"); } else { - for (String str : inputs.keySet()) { + for (Map.Entry<String, Object> entry : inputs.entrySet()) { String outputString; try { - outputString = inputs.get(str).toString(); + outputString = entry.getValue().toString(); } catch (Exception e) { - outputString = "Unable to call toString() on the value for " + str; + outputString = "Unable to call toString() on the value for " + entry.getKey(); } - sb.append("\t\nitem " + i++ + ": '" + str + "'='" + outputString + "'"); + sb.append("\t\nitem " + i++ + ": '" + entry.getKey() + "'='" + outputString + "'"); } } logger.debug(sb.toString()); - return; } private void sendMapToDebug(Map<String, Object> inputs) { @@ -384,12 +377,11 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } else if (inputs.size() < 1) { sb.append("\tEMPTY"); } else { - for (String str : inputs.keySet()) { - sb.append("\titem " + i++ + ": " + str + "=" + inputs.get(str)); + for (Map.Entry<String, Object> entry : inputs.entrySet()) { + sb.append("\titem " + i++ + ": " + entry.getKey() + "=" + entry.getValue()); } } logger.debug(sb.toString()); - return; } private String convertNode(final JsonNode node) { @@ -398,9 +390,9 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { final String json = JSON_MAPPER.writeValueAsString(obj); return json; } catch (JsonParseException jpe) { - logger.debug("Error converting json to string " + jpe.getMessage()); + logger.error("Error converting json to string ", jpe); } catch (Exception e) { - logger.debug("Error converting json to string " + e.getMessage()); + logger.error("Error converting json to string ", e); } return "[Error converting json to string]"; } @@ -409,44 +401,44 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { if (objectMap == null) { return null; } - Map<String, String> stringMap = new HashMap<String, String>(); - for (String key : objectMap.keySet()) { - if (!stringMap.containsKey(key)) { - Object obj = objectMap.get(key); + Map<String, String> stringMap = new HashMap<>(); + for (Map.Entry<String, Object> entry : objectMap.entrySet()) { + if (!stringMap.containsKey(entry.getKey())) { + Object obj = entry.getValue(); if (obj instanceof String) { - stringMap.put(key, (String) objectMap.get(key)); + stringMap.put(entry.getKey(), (String) entry.getValue()); } else if (obj instanceof JsonNode) { // This is a bit of mess - but I think it's the least impacting // let's convert it BACK to a string - then it will get converted back later try { String str = this.convertNode((JsonNode) obj); - stringMap.put(key, str); + stringMap.put(entry.getKey(), str); } catch (Exception e) { - logger.debug("DANGER WILL ROBINSON: unable to convert value for JsonNode " + key); + logger.error("DANGER WILL ROBINSON: unable to convert value for JsonNode " + entry.getKey(), e); // okay in this instance - only string values (fqdn) are expected to be needed } } else if (obj instanceof java.util.LinkedHashMap) { logger.debug("LinkedHashMap - this is showing up as a LinkedHashMap instead of JsonNode"); try { String str = JSON_MAPPER.writeValueAsString(obj); - stringMap.put(key, str); + stringMap.put(entry.getKey(), str); } catch (Exception e) { - logger.debug("DANGER WILL ROBINSON: unable to convert value for LinkedHashMap " + key); + logger.error( + "DANGER WILL ROBINSON: unable to convert value for LinkedHashMap " + entry.getKey(), e); } } else if (obj instanceof Integer) { try { String str = "" + obj; - stringMap.put(key, str); + stringMap.put(entry.getKey(), str); } catch (Exception e) { - logger.debug("DANGER WILL ROBINSON: unable to convert value for Integer " + key); + logger.error("DANGER WILL ROBINSON: unable to convert value for Integer " + entry.getKey(), e); } } else { try { String str = obj.toString(); - stringMap.put(key, str); + stringMap.put(entry.getKey(), str); } catch (Exception e) { - logger.debug( - "DANGER WILL ROBINSON: unable to convert value " + key + " (" + e.getMessage() + ")"); + logger.error("DANGER WILL ROBINSON: unable to convert value " + entry.getKey(), e); } } } @@ -502,8 +494,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { String volumeGroupId, String baseVfModuleId, String modelCustomizationUuid, Map<String, Object> inputs, Boolean failIfExists, Boolean backout, Boolean enableBridge, MsoRequest msoRequest, Holder<String> vnfId, Holder<Map<String, String>> outputs, Holder<VnfRollback> rollback) throws VnfException { - // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); // Require a model customization ID. Every VF Module definition must have one. if (modelCustomizationUuid == null || modelCustomizationUuid.isEmpty()) { @@ -585,7 +575,7 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { vnfResource = vfmc.getVfModule().getVnfResources(); } catch (Exception e) { - logger.debug("unhandled exception in create VF - [Query]" + e.getMessage()); + logger.error("unhandled exception in create VF - [Query]", e); throw new VnfException("Exception during create VF " + e.getMessage()); } @@ -620,7 +610,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { // First, look up to see if the VF already exists. - long subStartTime1 = System.currentTimeMillis(); try { cloudifyDeployment = cloudifyUtils.queryDeployment(cloudSiteId, tenantId, vfModuleName); } catch (MsoException me) { @@ -714,7 +703,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { // If a Volume Group was provided, query its outputs for inclusion in Module input parameters if (volumeGroupId != null) { - long subStartTime2 = System.currentTimeMillis(); DeploymentInfo volumeDeployment = null; try { volumeDeployment = cloudifyUtils.queryDeployment(cloudSiteId, tenantId, volumeGroupId); @@ -763,7 +751,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } if (baseVfModuleId != null) { - long subStartTime2 = System.currentTimeMillis(); DeploymentInfo baseDeployment = null; try { baseDeployment = cloudifyUtils.queryDeployment(cloudSiteId, tenantId, baseVfModuleId); @@ -839,21 +826,21 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { try { // All variables converted to their native object types - HashMap<String, Object> goldenInputs = new HashMap<String, Object>(); - List<String> extraInputs = new ArrayList<String>(); + HashMap<String, Object> goldenInputs = new HashMap<>(); + List<String> extraInputs = new ArrayList<>(); // NOTE: SKIP THIS FOR CLOUDIFY for now. Just use what was passed in. // This whole section needs to be rewritten. Boolean skipInputChecks = false; if (skipInputChecks) { - goldenInputs = new HashMap<String, Object>(); - for (String key : inputs.keySet()) { - goldenInputs.put(key, inputs.get(key)); + goldenInputs = new HashMap<>(); + for (Map.Entry<String, Object> entry : inputs.entrySet()) { + goldenInputs.put(entry.getKey(), entry.getValue()); } } else { // Build maps for the parameters (including aliases) to simplify checks - HashMap<String, HeatTemplateParam> params = new HashMap<String, HeatTemplateParam>(); + HashMap<String, HeatTemplateParam> params = new HashMap<>(); Set<HeatTemplateParam> paramSet = heatTemplate.getParameters(); logger.debug("paramSet has {} entries", paramSet.size()); @@ -889,18 +876,18 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { // Next add in Volume Group Outputs if there are any. Copy directly without conversions. if (volumeGroupOutputs != null && !volumeGroupOutputs.isEmpty()) { - for (String key : volumeGroupOutputs.keySet()) { - if (params.containsKey(key) && !goldenInputs.containsKey(key)) { - goldenInputs.put(key, volumeGroupOutputs.get(key)); + for (Map.Entry<String, Object> entry : volumeGroupOutputs.entrySet()) { + if (params.containsKey(entry.getKey()) && !goldenInputs.containsKey(entry.getKey())) { + goldenInputs.put(entry.getKey(), entry.getValue()); } } } // Next add in Base Module Outputs if there are any. Copy directly without conversions. if (baseModuleOutputs != null && !baseModuleOutputs.isEmpty()) { - for (String key : baseModuleOutputs.keySet()) { - if (params.containsKey(key) && !goldenInputs.containsKey(key)) { - goldenInputs.put(key, baseModuleOutputs.get(key)); + for (Map.Entry<String, Object> entry : baseModuleOutputs.entrySet()) { + if (params.containsKey(entry.getKey()) && !goldenInputs.containsKey(entry.getKey())) { + goldenInputs.put(entry.getKey(), entry.getValue()); } } } @@ -944,7 +931,7 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } } catch (Exception e) { // No problem - default is true - logger.debug("An exception occured trying to get property {}", + logger.error("An exception occured trying to get property {}", MsoVnfCloudifyAdapterImpl.CHECK_REQD_PARAMS, e); } @@ -992,7 +979,7 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { if (!cloudifyUtils.isBlueprintLoaded(cloudSiteId, blueprintId)) { logger.debug("Blueprint " + blueprintId + " is not loaded. Will upload it now."); - Map<String, byte[]> blueprintFiles = new HashMap<String, byte[]>(); + Map<String, byte[]> blueprintFiles = new HashMap<>(); blueprintFiles.put(blueprintName, blueprint.getBytes()); @@ -1036,7 +1023,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { // Ignore MsoTenantNotFound and MsoStackAlreadyExists exceptions // because we already checked for those. - long createDeploymentStarttime = System.currentTimeMillis(); try { // KLUDGE - Cloudify requires Tenant Name for Openstack. We have the ID. // Go directly to Keystone until APIs could be updated to supply the name. @@ -1070,11 +1056,11 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { // npe.addContext ("CreateVNF"); throw new VnfException("NullPointerException during cloudify.createAndInstallDeployment"); } catch (Exception e) { - logger.debug("unhandled exception at cloudify.createAndInstallDeployment"); + logger.error("unhandled exception at cloudify.createAndInstallDeployment", e); throw new VnfException("Exception during cloudify.createAndInstallDeployment! " + e.getMessage()); } } catch (Exception e) { - logger.debug("unhandled exception in create VF"); + logger.error("unhandled exception in create VF", e); throw new VnfException("Exception during create VF " + e.getMessage()); } @@ -1088,15 +1074,13 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { rollback.value = vfRollback; - logger.debug("VF Module successfully created", vfModuleName); - return; + logger.debug("VF Module successfully created {}", vfModuleName); + } public void deleteVfModule(String cloudSiteId, String cloudOwner, String tenantId, String vnfName, MsoRequest msoRequest, Holder<Map<String, String>> outputs) throws VnfException { logger.debug("Deleting VF " + vnfName + " in " + cloudOwner + "/" + cloudSiteId + "/" + tenantId); - // Will capture execution time for metrics - long startTime = System.currentTimeMillis(); // 1702 capture the output parameters on a delete // so we'll need to query first @@ -1121,7 +1105,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { // The possible outcomes of deleteStack are a StackInfo object with status // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException // could be thrown. - long subStartTime = System.currentTimeMillis(); try { cloudifyUtils.uninstallAndDeleteDeployment(cloudSiteId, tenantId, vnfName, 5); } catch (MsoException me) { |