diff options
author | Steve Smokowski <ss835w@att.com> | 2019-06-17 12:53:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-06-17 12:53:57 +0000 |
commit | 984f8da49f06c1563b4496572c54147014aa94bb (patch) | |
tree | 88ea740352011c3ebe498c85fd284b3b8797dc47 /adapters | |
parent | 7eb82a8cd009b4b677d348cf16333ca7699c3274 (diff) | |
parent | 2acb045495ff733e0cd42ced507cf6bfbb99a3b7 (diff) |
Merge "Fix sonar issues in mso-openstack-adapters"
Diffstat (limited to 'adapters')
-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 98cfa9d410..96e5db7ce7 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 @@ -176,10 +176,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 { @@ -190,6 +186,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 @@ -215,7 +212,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { logger.debug("VNF {} not found", vnfName); } - return; } @@ -241,7 +237,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(LoggingAnchor.THREE, MessageEnum.RA_ROLLBACK_NULL.toString(), OPENSTACK, "rollbackVnf"); @@ -267,7 +262,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. @@ -290,7 +284,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { logger.debug(error); throw new VnfException(me); } - return; } @@ -318,37 +311,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); } } } @@ -364,18 +358,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) { @@ -386,12 +379,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) { @@ -400,9 +392,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]"; } @@ -411,44 +403,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); } } } @@ -504,8 +496,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()) { @@ -587,7 +577,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()); } @@ -622,7 +612,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) { @@ -716,7 +705,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); @@ -765,7 +753,6 @@ public class MsoVnfCloudifyAdapterImpl implements MsoVnfAdapter { } if (baseVfModuleId != null) { - long subStartTime2 = System.currentTimeMillis(); DeploymentInfo baseDeployment = null; try { baseDeployment = cloudifyUtils.queryDeployment(cloudSiteId, tenantId, baseVfModuleId); @@ -843,21 +830,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()); @@ -893,18 +880,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()); } } } @@ -948,7 +935,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); } @@ -996,7 +983,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()); @@ -1039,7 +1026,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. @@ -1073,11 +1059,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()); } @@ -1091,15 +1077,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 @@ -1124,7 +1108,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) { |