diff options
author | Shashank Kumar Shankar <shashank.kumar.shankar@intel.com> | 2018-03-21 16:44:25 -0700 |
---|---|---|
committer | Rob Daugherty <rd472p@att.com> | 2018-03-27 22:03:46 +0000 |
commit | b17f8ec08a3087ccf0a30818b0095ad9520c4192 (patch) | |
tree | 38ea7cca0dd87e713d26dcdce99e4553f14a62d8 /adapters/mso-adapter-utils/src/main/java/org | |
parent | b4473da1a753e63e66f5a9a3b1984fd4736273c2 (diff) |
Update Heat enviroment HPA parameters
[WORK IN PROGRESS]
This patch adds support for updating HPA parameters in Heat templates.
Change-Id: Id37e2d1ec752085bdd6808f03be5e85ac040d0c3
Issue-ID: SO-408
Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org')
-rw-r--r-- | adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java | 412 |
1 files changed, 218 insertions, 194 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 92220f8717..7046096979 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 @@ -22,218 +22,242 @@ 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 = null; - private Set<MsoHeatEnvironmentResource> resources = null; - private StringBuilder rawEntry = null; - private boolean valid = true; - private String errorString = null; - private StringBuilder resourceRegistryEntryRaw = null; - - public MsoHeatEnvironmentEntry() { - super(); - } - - 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 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"); - } + 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 = null; + private StringBuilder resourceRegistryEntryRaw = null; + + public MsoHeatEnvironmentEntry() { + super(); + } + + 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 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; - } - - 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"); - } + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; + } + + 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"); + } // 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 StringBuilder getRawEntry() { - return this.rawEntry; - } - - private StringBuilder getResourceRegistryRawEntry() { - - if (this.rawEntry == null) { - return 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; - } - + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; + } + + public StringBuilder getRawEntry() { + return this.rawEntry; + } + + private StringBuilder getResourceRegistryRawEntry() { + + if (this.rawEntry == null) { + return 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; + } + + public void setHPAParameters(StringBuilder hpasb) { + try { + MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(hpasb.toString().getBytes()); + Set<MsoHeatEnvironmentParameter> hpaParams = yaml.getParameterListFromEnvt(); + for (MsoHeatEnvironmentParameter hpaparam : hpaParams) { + for (MsoHeatEnvironmentParameter param : this.parameters) { + if (param.getName() == hpaparam.getName()) { + param.setValue(hpaparam.getValue()); + } + } + } + } catch (Exception e) { + LOGGER.debug("Exception:", e); + this.errorString = e.getMessage(); + //e.printStackTrace(); + } + } } |