From 5e2aa1fec3c51e8eb0e6b43285c8414105a51b2f Mon Sep 17 00:00:00 2001 From: seshukm Date: Mon, 18 Sep 2017 11:47:20 +0530 Subject: Fixed Issues In adapter code. Issue-Id : SO-141 Change-Id: I0e901537013634dfc3f0950921c2ebbc2afa411f Signed-off-by: seshukm --- .../openstack/utils/MsoHeatEnvironmentEntry.java | 11 ++-- .../utils/MsoHeatEnvironmentResource.java | 7 ++- .../mso/openstack/utils/MsoHeatUtils.java | 61 ++++++++++++---------- .../mso/openstack/utils/MsoYamlEditorWithEnvt.java | 12 +++-- 4 files changed, 56 insertions(+), 35 deletions(-) (limited to 'adapters/mso-adapter-utils/src/main/java/org/openecomp') diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java index fd252b634a..3aa77c2c7a 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java @@ -3,6 +3,7 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +27,12 @@ import java.util.HashSet; import java.util.ArrayList; import java.util.Set; import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; +import org.openecomp.mso.logger.MsoLogger; public class MsoHeatEnvironmentEntry { + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private Set parameters = null; private Set resources = null; private StringBuilder rawEntry = null; @@ -48,7 +52,7 @@ public class MsoHeatEnvironmentEntry { private void processRawEntry() { try { - if (this.rawEntry == null || this.rawEntry.equals("")) + if (this.rawEntry == null || "".equals(this.rawEntry)) return; byte[] b = this.rawEntry.toString().getBytes(); MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(b); @@ -61,6 +65,7 @@ public class MsoHeatEnvironmentEntry { this.resourceRegistryEntryRaw = sb; } } catch (Exception e) { + LOGGER.debug("Exception:", e); this.valid = false; this.errorString = e.getMessage(); //e.printStackTrace(); @@ -97,13 +102,13 @@ public class MsoHeatEnvironmentEntry { public void addParameter(MsoHeatEnvironmentParameter hep) { if (this.parameters == null) { - this.parameters = new HashSet(); + this.parameters = new HashSet<>(); } this.parameters.add(hep); } public void addResource(MsoHeatEnvironmentResource her) { if (this.resources == null) { - this.resources = new HashSet(); + this.resources = new HashSet<>(); } this.resources.add(her); } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java index f5dffc3297..31e2fca4c1 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java @@ -3,6 +3,7 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +21,12 @@ package org.openecomp.mso.openstack.utils; - +import org.openecomp.mso.logger.MsoLogger; public class MsoHeatEnvironmentResource { + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private String name; private String value; @@ -77,7 +80,7 @@ public class MsoHeatEnvironmentResource { try { result = this.name.hashCode(); } catch (Exception e) { - // in case it's null - return zero + LOGGER.debug("Exception:", e); } return result; } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java index 8073c953e9..fad0c2368b 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java @@ -91,12 +91,12 @@ public class MsoHeatUtils extends MsoCommonUtils { // token will be used until it expires. // // The cache key is "tenantId:cloudId" - private static Map heatClientCache = new HashMap (); + private static Map heatClientCache = new HashMap <> (); // Fetch cloud configuration each time (may be cached in CloudConfig class) protected CloudConfig cloudConfig; - private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); protected MsoJavaProperties msoProps = null; @@ -343,7 +343,7 @@ public class MsoHeatUtils extends MsoCommonUtils { if (haveFiles && haveHeatFiles) { // Let's do this here - not in the bean LOGGER.debug ("Found files AND heatFiles - combine and add!"); - Map combinedFiles = new HashMap (); + Map combinedFiles = new HashMap <> (); for (String keyString : files.keySet ()) { combinedFiles.put (keyString, files.get (keyString)); } @@ -584,7 +584,7 @@ public class MsoHeatUtils extends MsoCommonUtils { } } // end while !deleted - StringBuilder errorContextMessage = null; + StringBuilder errorContextMessage; if (createTimedOut) { errorContextMessage = new StringBuilder("Stack Creation Timeout"); } else { @@ -737,7 +737,14 @@ public class MsoHeatUtils extends MsoCommonUtils { String canonicalName = heatStack.getStackName () + "/" + heatStack.getId (); try { - OpenStackRequest request = heatClient.getStacks ().deleteByName (canonicalName); + OpenStackRequest request = null; + if(null != heatClient) { + request = heatClient.getStacks ().deleteByName (canonicalName); + } + else { + LOGGER.debug ("Heat Client is NULL" ); + } + executeAndRecordOpenstackRequest (request, msoProps); } catch (OpenStackResponseException e) { if (e.getStatus () == 404) { @@ -845,7 +852,7 @@ public class MsoHeatUtils extends MsoCommonUtils { OpenStackRequest request = heatClient.getStacks ().list (); Stacks stacks = executeAndRecordOpenstackRequest (request, msoProps); - List stackList = new ArrayList (); + List stackList = new ArrayList <> (); // Not sure if returns an empty list or null if no stacks exist if (stacks != null) { @@ -859,7 +866,7 @@ public class MsoHeatUtils extends MsoCommonUtils { if (e.getStatus () == 404) { // Not sure if this can happen, but return an empty list LOGGER.debug ("queryAllStacks - stack not found: "); - return new ArrayList (); + return new ArrayList <> (); } else { // Convert the OpenStackResponseException to an MsoOpenstackException throw heatExceptionToMsoException (e, QUERY_ALL_STACKS); @@ -891,7 +898,7 @@ public class MsoHeatUtils extends MsoCommonUtils { HeatTemplate heatTemplate) throws IllegalArgumentException { // Check that required parameters have been supplied for this template type String missingParams = null; - List paramList = new ArrayList (); + List paramList = new ArrayList <> (); // TODO: Enhance DB to support defaults for Heat Template parameters @@ -913,8 +920,8 @@ public class MsoHeatUtils extends MsoCommonUtils { } // Remove any extraneous parameters (don't throw an error) - Map updatedParams = new HashMap (); - List extraParams = new ArrayList (); + Map updatedParams = new HashMap <> (); + List extraParams = new ArrayList <> (); for (String key : inputParams.keySet ()) { if (!paramList.contains (key)) { // This is not a valid parameter for this template @@ -1139,7 +1146,7 @@ public class MsoHeatUtils extends MsoCommonUtils { * This may be useful if cached credentials get out of sync. */ public static void heatCacheReset () { - heatClientCache = new HashMap (); + heatClientCache = new HashMap <> (); } public Map queryStackForOutputs(String cloudSiteId, @@ -1273,7 +1280,7 @@ public class MsoHeatUtils extends MsoCommonUtils { sb.append("(outputs is empty)"); return sb; } - Map outputs = new HashMap(); + Map outputs = new HashMap<>(); for (Output outputItem : outputList) { outputs.put(outputItem.getOutputKey(), outputItem.getOutputValue()); } @@ -1419,7 +1426,7 @@ public class MsoHeatUtils extends MsoCommonUtils { } else { cdl3 = cdl2; } - ArrayList list = new ArrayList(Arrays.asList(cdl3.split(","))); + ArrayList list = new ArrayList<>(Arrays.asList(cdl3.split(","))); return list; } @@ -1441,9 +1448,9 @@ public class MsoHeatUtils extends MsoCommonUtils { * @return HashMap of the inputs, cleaned and converted */ public HashMap convertInputMap(Map inputs, HeatTemplate template) { - HashMap newInputs = new HashMap(); - HashMap params = new HashMap(); - HashMap paramAliases = new HashMap(); + HashMap newInputs = new HashMap<>(); + HashMap params = new HashMap<>(); + HashMap paramAliases = new HashMap<>(); if (inputs == null) { LOGGER.debug("convertInputMap - inputs is null - nothing to do here"); @@ -1462,7 +1469,7 @@ public class MsoHeatUtils extends MsoCommonUtils { for (HeatTemplateParam htp : template.getParameters()) { LOGGER.debug("Adding " + htp.getParamName()); params.put(htp.getParamName(), htp); - if (htp.getParamAlias() != null && !htp.getParamAlias().equals("")) { + if (htp.getParamAlias() != null && !"".equals(htp.getParamAlias())) { LOGGER.debug("\tFound ALIAS " + htp.getParamName() + "->" + htp.getParamAlias()); paramAliases.put(htp.getParamAlias(), htp); } @@ -1485,20 +1492,20 @@ public class MsoHeatUtils extends MsoCommonUtils { } } String type = params.get(key).getParamType(); - if (type == null || type.equals("")) { + if (type == null || "".equals(type)) { LOGGER.debug("**PARAM_TYPE is null/empty for " + key + ", will default to string"); type = "string"; } LOGGER.debug("Parameter: " + key + " is of type " + type); - if (type.equalsIgnoreCase("string")) { + if ("string".equalsIgnoreCase(type)) { // Easiest! String str = inputs.get(key); if (alias) newInputs.put(realName, str); else newInputs.put(key, str); - } else if (type.equalsIgnoreCase("number")) { - String integerString = inputs.get(key).toString(); + } else if ("number".equalsIgnoreCase(type)) { + String integerString = inputs.get(key); Integer anInteger = null; try { anInteger = Integer.parseInt(integerString); @@ -1518,8 +1525,8 @@ public class MsoHeatUtils extends MsoCommonUtils { else newInputs.put(key, integerString); } - } else if (type.equalsIgnoreCase("json")) { - String jsonString = inputs.get(key).toString(); + } else if ("json".equalsIgnoreCase(type)) { + String jsonString = inputs.get(key); JsonNode jsonNode = null; try { jsonNode = new ObjectMapper().readTree(jsonString); @@ -1539,8 +1546,8 @@ public class MsoHeatUtils extends MsoCommonUtils { else newInputs.put(key, jsonString); } - } else if (type.equalsIgnoreCase("comma_delimited_list")) { - String commaSeparated = inputs.get(key).toString(); + } else if ("comma_delimited_list".equalsIgnoreCase(type)) { + String commaSeparated = inputs.get(key); try { ArrayList anArrayList = this.convertCdlToArrayList(commaSeparated); if (alias) @@ -1554,8 +1561,8 @@ public class MsoHeatUtils extends MsoCommonUtils { else newInputs.put(key, commaSeparated); } - } else if (type.equalsIgnoreCase("boolean")) { - String booleanString = inputs.get(key).toString(); + } else if ("boolean".equalsIgnoreCase(type)) { + String booleanString = inputs.get(key); Boolean aBool = new Boolean(booleanString); if (alias) newInputs.put(realName, aBool); diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java index 4e715fa06e..bd649e867f 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java @@ -36,9 +36,12 @@ import java.util.LinkedHashMap; import org.yaml.snakeyaml.Yaml; +import org.openecomp.mso.logger.MsoLogger; public class MsoYamlEditorWithEnvt { + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private Map yml; private Yaml yaml = new Yaml (); private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); @@ -65,6 +68,7 @@ public class MsoYamlEditorWithEnvt { try { resourceMap = (Map) yml.get("parameters"); } catch (Exception e) { + LOGGER.debug("Exception:", e); return paramSet; } if (resourceMap == null) { @@ -90,6 +94,7 @@ public class MsoYamlEditorWithEnvt { try { value = JSON_MAPPER.writeValueAsString(obj); } catch (Exception e) { + LOGGER.debug("Exception:", e); value = "_BAD_JSON_MAPPING"; } } else { @@ -104,7 +109,7 @@ public class MsoYamlEditorWithEnvt { } public synchronized Set getResourceListFromEnvt() { try { - Set resourceList = new HashSet(); + Set resourceList = new HashSet<>(); @SuppressWarnings("unchecked") Map resourceMap = (Map) yml.get("resource_registry"); Iterator> it = resourceMap.entrySet().iterator(); @@ -118,12 +123,12 @@ public class MsoYamlEditorWithEnvt { } return resourceList; } catch (Exception e) { - + LOGGER.debug("Exception:", e); } return null; } public synchronized Set getParameterList () { - Set paramSet = new HashSet (); + Set paramSet = new HashSet <> (); @SuppressWarnings("unchecked") Map resourceMap = (Map ) yml.get ("parameters"); Iterator > it = resourceMap.entrySet ().iterator (); @@ -137,6 +142,7 @@ public class MsoYamlEditorWithEnvt { try { value = resourceEntry.get ("default"); } catch (java.lang.ClassCastException cce) { + LOGGER.debug("Exception:", cce); // This exception only - the value is an integer. For what we're doing // here - we don't care - so set value to something - and it will // get marked as not being required - which is correct. -- cgit 1.2.3-korg