diff options
author | Rob Daugherty <rd472p@att.com> | 2018-03-14 02:07:32 -0400 |
---|---|---|
committer | Rob Daugherty <rd472p@att.com> | 2018-03-14 04:08:41 -0400 |
commit | 38f720752af4d4aad8c4e467a288d9048659f688 (patch) | |
tree | e81066a8b5c77272e30fb57a64999573c4db4d86 /adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils | |
parent | aee3d223f92a6f250f43e17558a2dfd576ff7294 (diff) |
AT&T 1712 and 1802 release code
This is code from AT&T's 1712 and 1802 releases.
Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04
Issue-ID: SO-425
Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils')
6 files changed, 305 insertions, 80 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 04dbf523d0..92220f8717 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 @@ -21,81 +21,219 @@ package org.openecomp.mso.openstack.utils; + + +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; - private String rawEntry; + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + private Set<MsoHeatEnvironmentParameter> parameters = null; + private Set<MsoHeatEnvironmentResource> resources = null; + private StringBuilder rawEntry = null; private boolean valid = true; - private String errorString; - private String resourceRegistryEntryRaw; - - private MsoHeatEnvironmentEntry(String rawEntry) { - this.rawEntry = rawEntry; + private String errorString = null; + private StringBuilder resourceRegistryEntryRaw = null; + + public MsoHeatEnvironmentEntry() { + super(); } - - private MsoHeatEnvironmentEntry(Set<MsoHeatEnvironmentParameter> parameters, String rawEntry, boolean valid, - String errorString, String resourceRegistryEntryRaw) { - this.parameters = parameters; - this.rawEntry = rawEntry; - this.valid = valid; - this.errorString = errorString; - this.resourceRegistryEntryRaw = resourceRegistryEntryRaw; + + public MsoHeatEnvironmentEntry(StringBuilder sb) { + this(); + this.rawEntry = sb; + this.processRawEntry(); } - + + private void processRawEntry() { + try { + if (this.rawEntry == null || "".equals(this.rawEntry)) + return; + byte[] b = this.rawEntry.toString().getBytes(); + MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(b); + this.parameters = yaml.getParameterListFromEnvt(); + //this.resources = yaml.getResourceListFromEnvt(); + StringBuilder sb = this.getResourceRegistryRawEntry(); + if (sb == null) { + this.resourceRegistryEntryRaw = new StringBuilder(""); + } else { + this.resourceRegistryEntryRaw = sb; + } + } catch (Exception e) { + LOGGER.debug("Exception:", e); + this.valid = false; + this.errorString = e.getMessage(); + //e.printStackTrace(); + } + } + public boolean isValid() { return this.valid; } public String getErrorString() { return this.errorString; } - + + public Set<MsoHeatEnvironmentParameter> getParameters() { + return this.parameters; + } + public Set<MsoHeatEnvironmentResource> getResources() { + return this.resources; + } + public void setParameters(Set<MsoHeatEnvironmentParameter> paramSet) { + if (paramSet == null) { + this.parameters = null; + } else { + this.parameters = paramSet; + } + } + public void setResources(Set<MsoHeatEnvironmentResource> resourceSet) { + if (resourceSet == null) { + this.resources = null; + } else { + this.resources = resourceSet; + } + } + + public void addParameter(MsoHeatEnvironmentParameter hep) { + if (this.parameters == null) { + this.parameters = new HashSet<>(); + } + this.parameters.add(hep); + } + public void addResource(MsoHeatEnvironmentResource her) { + if (this.resources == null) { + this.resources = new HashSet<>(); + } + this.resources.add(her); + } + + public int getNumberOfParameters() { + return this.parameters.size(); + } + public int getNumberOfResources() { + return this.resources.size(); + } + + public boolean hasResources() { + if (this.resources != null && this.resources.size() > 0) { + return true; + } + return false; + } + public boolean hasParameters() { + if (this.parameters != null && this.parameters.size() > 0) { + return true; + } + return false; + } + public boolean containsParameter(String paramName) { + boolean contains = false; if (this.parameters == null || this.parameters.size() < 1) { return false; } if (this.parameters.contains(new MsoHeatEnvironmentParameter(paramName))) { + contains = true; + } + return contains; + } + + public boolean containsParameter(String paramName, String paramAlias) { + if (this.containsParameter(paramName)) { + return true; + } + if (this.containsParameter(paramAlias)) { return true; } return false; } - + @Override public String toString() { return "MsoHeatEnvironmentEntry{" + "parameters=" + parameters + ", resourceRegistryEntryRaw='" + resourceRegistryEntryRaw + '\'' + '}'; } - - public String getRawEntry() { - return rawEntry; + + public StringBuilder toFullStringExcludeNonParams(Set<HeatTemplateParam> params) { + // Basically give back the envt - but exclude the params that aren't in the HeatTemplate + + StringBuilder sb = new StringBuilder(); + ArrayList<String> paramNameList = new ArrayList<String>(params.size()); + for (HeatTemplateParam htp : params) { + paramNameList.add(htp.getParamName()); + } + + if (this.hasParameters()) { + sb.append("parameters:\n"); + for (MsoHeatEnvironmentParameter hep : this.parameters) { + String paramName = hep.getName(); + if (paramNameList.contains(paramName)) { + // This parameter *is* in the Heat Template - so include it: + sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); + // New - 1607 - if any of the params mapped badly - JUST RETURN THE ORIGINAL ENVT! + if (hep.getValue().startsWith("_BAD")) { + return this.rawEntry; + } + } + } + sb.append("\n"); + } +// if (this.hasResources()) { +// sb.append("resource_registry:\n"); +// for (MsoHeatEnvironmentResource her : this.resources) { +// sb.append(" \"" + her.getName() + "\": " + her.getValue() + "\n"); +// } +// } + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; } - private static String getResourceRegistryRawEntry(String rawEntry) { - int indexOf = rawEntry.indexOf("resource_registry:"); - if (indexOf < 0) { - return ""; + public StringBuilder toFullString() { + StringBuilder sb = new StringBuilder(); + + if (this.hasParameters()) { + sb.append("parameters:\n"); + for (MsoHeatEnvironmentParameter hep : this.parameters) { + sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); + } + sb.append("\n"); } - return rawEntry.substring(indexOf); +// if (this.hasResources()) { +// sb.append("resource_registry:\n"); +// for (MsoHeatEnvironmentResource her : this.resources) { +// sb.append(" \"" + her.getName() + "\": " + her.getValue() + "\n"); +// } +// } + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; } - - public static MsoHeatEnvironmentEntry create(String rawEntry) { - if (rawEntry == null || rawEntry.isEmpty()) { - return new MsoHeatEnvironmentEntry(rawEntry); + + public StringBuilder getRawEntry() { + return this.rawEntry; + } + + private StringBuilder getResourceRegistryRawEntry() { + + if (this.rawEntry == null) { + return null; } - try { - Set<MsoHeatEnvironmentParameter> parameters = new MsoYamlEditorWithEnvt(rawEntry.getBytes()) - .getParameterListFromEnvt(); - return new MsoHeatEnvironmentEntry(parameters, rawEntry, true, null, - getResourceRegistryRawEntry(rawEntry)); - } catch (Exception e) { - LOGGER.debug(String.format("An exception occurred during processing the following raw entry: %s", rawEntry), - e); - return new MsoHeatEnvironmentEntry(null, rawEntry, false, e.getMessage(), null); + + StringBuilder sb = new StringBuilder(); + int indexOf = this.rawEntry.indexOf("resource_registry:"); + if (indexOf < 0) { // no resource_registry: + return null; } + sb.append(this.rawEntry.substring(indexOf)); + return sb; } - + } 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 6862492d7e..7dd14d865c 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 @@ -30,10 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.JsonParseException; - import org.openecomp.mso.cloud.CloudConfig; import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudIdentity; @@ -55,6 +51,10 @@ import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound; import org.openecomp.mso.properties.MsoJavaProperties; import org.openecomp.mso.properties.MsoPropertiesException; import org.openecomp.mso.properties.MsoPropertiesFactory; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.base.client.OpenStackConnectException; import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.base.client.OpenStackResponseException; @@ -359,6 +359,21 @@ public class MsoHeatUtils extends MsoCommonUtils { stack.setFiles (heatFiles); } } + + // 1802 - attempt to add better formatted printout of request to openstack + try { + Map<String, Object> inputs = new HashMap<String, Object>(); + for (String key : stackInputs.keySet()) { + Object o = (Object) stackInputs.get(key); + if (o != null) { + inputs.put(key, o); + } + } + LOGGER.debug(this.printStackRequest(tenantId, heatFiles, files, environment, inputs, stackName, heatTemplate, timeoutMinutes, backout, cloudSiteId)); + } catch (Exception e) { + // that's okay - this is a nice-to-have + LOGGER.debug("(had an issue printing nicely formatted request to debuglog) " + e.getMessage()); + } Stack heatStack = null; try { @@ -372,7 +387,7 @@ public class MsoHeatUtils extends MsoCommonUtils { request.header ("X-Auth-User", cloudIdentity.getMsoId ()); request.header ("X-Auth-Key", cloudIdentity.getMsoPass ()); LOGGER.debug ("headers added, about to executeAndRecordOpenstackRequest"); - LOGGER.debug(this.requestToStringBuilder(stack).toString()); + //LOGGER.debug(this.requestToStringBuilder(stack).toString()); // END - try to fix X-Auth-User heatStack = executeAndRecordOpenstackRequest (request, msoProps); } catch (OpenStackResponseException e) { @@ -1416,7 +1431,7 @@ public class MsoHeatUtils extends MsoCommonUtils { * (heat variable type) -> java Object type * string -> String * number -> Integer - * json -> JsonNode + * json -> JsonNode XXX Removed with MSO-1475 / 1802 * comma_delimited_list -> ArrayList * boolean -> Boolean * if any of the conversions should fail, we will default to adding it to the inputs @@ -1506,26 +1521,14 @@ public class MsoHeatUtils extends MsoCommonUtils { newInputs.put(key, integerString); } } else if ("json".equalsIgnoreCase(type)) { + // MSO-1475 - Leave this as a string now String jsonString = inputs.get(key); - JsonNode jsonNode = null; - try { - jsonNode = new ObjectMapper().readTree(jsonString); - } catch (Exception e) { - LOGGER.debug("Unable to convert " + jsonString + " to a JsonNode!!", e); - jsonNode = null; - } - if (jsonNode != null) { - if (alias) - newInputs.put(realName, jsonNode); - else - newInputs.put(key, jsonNode); - } - else { - if (alias) - newInputs.put(realName, jsonString); - else - newInputs.put(key, jsonString); - } + LOGGER.debug("Skipping conversion to jsonNode..."); + if (alias) + newInputs.put(realName, jsonString); + else + newInputs.put(key, jsonString); + //} } else if ("comma_delimited_list".equalsIgnoreCase(type)) { String commaSeparated = inputs.get(key); try { @@ -1559,5 +1562,85 @@ public class MsoHeatUtils extends MsoCommonUtils { } return newInputs; } - + + + /* + * Create a string suitable for being dumped to a debug log that creates a + * pseudo-JSON request dumping what's being sent to Openstack API in the create or update request + */ + + private String printStackRequest(String tenantId, + Map<String, Object> heatFiles, + Map<String, Object> nestedTemplates, + String environment, + Map<String, Object> inputs, + String vfModuleName, + String template, + int timeoutMinutes, + boolean backout, + String cloudSiteId) { + StringBuffer sb = new StringBuffer(); + sb.append("CREATE STACK REQUEST (formatted for readability)\n"); + sb.append("tenant=" + tenantId + ", cloud=" + cloudSiteId); + sb.append("{\n"); + sb.append(" \"stack_name\": \"" + vfModuleName + "\",\n"); + sb.append(" \"disable_rollback\": " + backout + ",\n"); + sb.append(" \"timeout_mins\": " + timeoutMinutes + ",\n"); + sb.append(" \"template\": {\n"); + sb.append(template); + sb.append(" },\n"); + sb.append(" \"environment\": {\n"); + if (environment == null) + sb.append("<none>"); + else + sb.append(environment); + sb.append(" },\n"); + sb.append(" \"files\": {\n"); + int filesCounter = 0; + if (heatFiles != null) { + for (String key : heatFiles.keySet()) { + filesCounter++; + if (filesCounter > 1) { + sb.append(",\n"); + } + sb.append(" \"" + key + "\": {\n"); + sb.append(heatFiles.get(key).toString() + "\n }"); + } + } + if (nestedTemplates != null) { + for (String key : nestedTemplates.keySet()) { + filesCounter++; + if (filesCounter > 1) { + sb.append(",\n"); + } + sb.append(" \"" + key + "\": {\n"); + sb.append(nestedTemplates.get(key).toString() + "\n }"); + } + } + sb.append("\n },\n"); + sb.append(" \"parameters\": {\n"); + int paramCounter = 0; + for (String name : inputs.keySet()) { + paramCounter++; + if (paramCounter > 1) { + sb.append(",\n"); + } + Object o = inputs.get(name); + if (o instanceof java.lang.String) { + sb.append(" \"" + name + "\": \"" + inputs.get(name).toString() + "\""); + } else if (o instanceof Integer) { + sb.append(" \"" + name + "\": " + inputs.get(name).toString() ); + } else if (o instanceof ArrayList) { + sb.append(" \"" + name + "\": " + inputs.get(name).toString() ); + } else if (o instanceof Boolean) { + sb.append(" \"" + name + "\": " + inputs.get(name).toString() ); + } else { + sb.append(" \"" + name + "\": " + "\"(there was an issue trying to dump this value...)\"" ); + } + } + sb.append("\n }\n}\n"); + + return sb.toString(); + } + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java index 75bb00351c..595da58270 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java @@ -26,10 +26,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.ObjectMapper; - import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudSite; import org.openecomp.mso.logger.MessageEnum; @@ -42,12 +38,16 @@ import org.openecomp.mso.openstack.exceptions.MsoStackNotFound; import org.openecomp.mso.properties.MsoJavaProperties; import org.openecomp.mso.properties.MsoPropertiesException; import org.openecomp.mso.properties.MsoPropertiesFactory; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.base.client.OpenStackBaseException; import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.heat.Heat; import com.woorea.openstack.heat.model.Stack; -import com.woorea.openstack.heat.model.UpdateStackParam; import com.woorea.openstack.heat.model.Stack.Output; +import com.woorea.openstack.heat.model.UpdateStackParam; public class MsoHeatUtilsWithUpdate extends MsoHeatUtils { diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java index 3b710032c1..018396d6ec 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java @@ -383,7 +383,9 @@ public class MsoKeystoneUtils extends MsoTenantUtils { // Get the Identity service URL. Throws runtime exception if not found per region. String adminUrl = null; try { - adminUrl = KeystoneUtils.findEndpointURL (access.getServiceCatalog (), "identity", region, "admin"); + // TODO: FOR TESTING!!!! + adminUrl = KeystoneUtils.findEndpointURL (access.getServiceCatalog (), "identity", region, "public"); + adminUrl = adminUrl.replaceFirst("5000", "35357"); } catch (RuntimeException e) { String error = "Identity service not found: region=" + region + ",cloud=" + cloudIdentity.getId (); alarmLogger.sendAlarm ("MsoConfigurationError", MsoAlarmLogger.CRITICAL, error); diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java index e36d46841d..cc9e869608 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java @@ -20,28 +20,30 @@ package org.openecomp.mso.openstack.utils; +import java.lang.reflect.InvocationTargetException; + import org.openecomp.mso.cloud.CloudConfig; import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudIdentity; import org.openecomp.mso.cloud.CloudSite; - -import java.lang.reflect.InvocationTargetException; +import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; public class MsoTenantUtilsFactory { - private CloudConfigFactory cloudConfigFactory= new CloudConfigFactory(); + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private CloudConfigFactory cloudConfigFactory= new CloudConfigFactory(); private CloudConfig cloudConfig; private String msoPropID; - + public MsoTenantUtilsFactory (String msoPropID) { this.msoPropID = msoPropID; } //based on Cloud IdentityServerType returns ORM or KEYSTONE Utils public MsoTenantUtils getTenantUtils(String cloudSiteId) throws MsoCloudSiteNotFound { - // Obtain the cloud site information + // Obtain the cloud site information cloudConfig = cloudConfigFactory.getCloudConfig(); CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow( () -> new MsoCloudSiteNotFound(cloudSiteId)); @@ -50,7 +52,7 @@ public class MsoTenantUtilsFactory { public MsoTenantUtils getTenantUtilsByServerType(String serverType) { - MsoTenantUtils tenantU; + MsoTenantUtils tenantU = null; if (CloudIdentity.IdentityServerType.KEYSTONE.toString().equals(serverType)) { tenantU = new MsoKeystoneUtils (msoPropID); } else { 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 8002087ddd..8704911e26 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 @@ -32,7 +32,7 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.yaml.snakeyaml.Yaml; |