summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/main
diff options
context:
space:
mode:
authorseshukm <seshu.kumar.m@huawei.com>2017-09-18 11:47:20 +0530
committerseshukm <seshu.kumar.m@huawei.com>2017-09-18 11:47:20 +0530
commit5e2aa1fec3c51e8eb0e6b43285c8414105a51b2f (patch)
tree291e6a39ce0cf6e9b0e60c5645fa816226c3c974 /adapters/mso-adapter-utils/src/main
parent5d8490e4c2aabebe4e34a28bc47a42a17fbfa1f1 (diff)
Fixed Issues In adapter code.
Issue-Id : SO-141 Change-Id: I0e901537013634dfc3f0950921c2ebbc2afa411f Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/main')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java11
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java7
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java61
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java12
4 files changed, 56 insertions, 35 deletions
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<MsoHeatEnvironmentParameter> parameters = null;
private Set<MsoHeatEnvironmentResource> 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<MsoHeatEnvironmentParameter>();
+ this.parameters = new HashSet<>();
}
this.parameters.add(hep);
}
public void addResource(MsoHeatEnvironmentResource her) {
if (this.resources == null) {
- this.resources = new HashSet<MsoHeatEnvironmentResource>();
+ 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 <String, HeatCacheEntry> heatClientCache = new HashMap <String, HeatCacheEntry> ();
+ private static Map <String, HeatCacheEntry> 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 <String, Object> combinedFiles = new HashMap <String, Object> ();
+ Map <String, Object> 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 <Void> request = heatClient.getStacks ().deleteByName (canonicalName);
+ OpenStackRequest <Void> 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 <Stacks> request = heatClient.getStacks ().list ();
Stacks stacks = executeAndRecordOpenstackRequest (request, msoProps);
- List <StackInfo> stackList = new ArrayList <StackInfo> ();
+ List <StackInfo> 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 <StackInfo> ();
+ 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 <String> paramList = new ArrayList <String> ();
+ List <String> 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 <String, Object> updatedParams = new HashMap <String, Object> ();
- List <String> extraParams = new ArrayList <String> ();
+ Map <String, Object> updatedParams = new HashMap <> ();
+ List <String> 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 <String, HeatCacheEntry> ();
+ heatClientCache = new HashMap <> ();
}
public Map<String, Object> queryStackForOutputs(String cloudSiteId,
@@ -1273,7 +1280,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
sb.append("(outputs is empty)");
return sb;
}
- Map<String, Object> outputs = new HashMap<String,Object>();
+ Map<String, Object> 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<String> list = new ArrayList<String>(Arrays.asList(cdl3.split(",")));
+ ArrayList<String> list = new ArrayList<>(Arrays.asList(cdl3.split(",")));
return list;
}
@@ -1441,9 +1448,9 @@ public class MsoHeatUtils extends MsoCommonUtils {
* @return HashMap<String, Object> of the inputs, cleaned and converted
*/
public HashMap<String, Object> convertInputMap(Map<String, String> inputs, HeatTemplate template) {
- HashMap<String, Object> newInputs = new HashMap<String, Object>();
- HashMap<String, HeatTemplateParam> params = new HashMap<String, HeatTemplateParam>();
- HashMap<String, HeatTemplateParam> paramAliases = new HashMap<String, HeatTemplateParam>();
+ HashMap<String, Object> newInputs = new HashMap<>();
+ HashMap<String, HeatTemplateParam> params = new HashMap<>();
+ HashMap<String, HeatTemplateParam> 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<String> 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 <String, Object> yml;
private Yaml yaml = new Yaml ();
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
@@ -65,6 +68,7 @@ public class MsoYamlEditorWithEnvt {
try {
resourceMap = (Map<String,Object>) 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 <MsoHeatEnvironmentResource> getResourceListFromEnvt() {
try {
- Set<MsoHeatEnvironmentResource> resourceList = new HashSet<MsoHeatEnvironmentResource>();
+ Set<MsoHeatEnvironmentResource> resourceList = new HashSet<>();
@SuppressWarnings("unchecked")
Map<String, Object> resourceMap = (Map<String,Object>) yml.get("resource_registry");
Iterator<Entry <String,Object>> 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 <HeatTemplateParam> getParameterList () {
- Set <HeatTemplateParam> paramSet = new HashSet <HeatTemplateParam> ();
+ Set <HeatTemplateParam> paramSet = new HashSet <> ();
@SuppressWarnings("unchecked")
Map <String, Object> resourceMap = (Map <String, Object>) yml.get ("parameters");
Iterator <Entry <String, Object>> 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.