diff options
author | siddharth0905 <siddharth.singh4@amdocs.com> | 2018-09-20 10:00:37 +0300 |
---|---|---|
committer | vempo <vitaliy.emporopulo@amdocs.com> | 2018-09-25 18:07:44 +0300 |
commit | 2b7766dd6ecf6fc011c917a3e99cf538f8cfd6eb (patch) | |
tree | 3d44b5ef8598cbf479640f0822a0219467e9ff18 /openecomp-be/lib/openecomp-heat-lib/src/main/java/org | |
parent | b8f536584bd539e232f6b22a2d80430055b59e42 (diff) |
Test coverage-Corrections
Increase test coverage
Change-Id: I8268d31486b3410fbe8791c6d8c4eed4b237462c
Issue-ID: SDC-1673
Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src/main/java/org')
30 files changed, 1498 insertions, 1898 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java index 0367d0969e..600917201b 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,102 +20,102 @@ package org.openecomp.sdc.heat.datatypes; -import org.apache.commons.lang.math.NumberUtils; -import org.apache.commons.lang3.ClassUtils; - import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import org.apache.commons.lang.math.NumberUtils; +import org.apache.commons.lang3.ClassUtils; + public enum DefinedHeatParameterTypes { - NUMBER("number"), - STRING("string"), - COMMA_DELIMITED_LIST("comma_delimited_list"), - JSON("json"), - BOOLEAN("boolean"); - - private static Map<String, DefinedHeatParameterTypes> stringToDefinedType = new HashMap<>(); - - static { - stringToDefinedType = new HashMap<>(); - for (DefinedHeatParameterTypes definedHeatParameterType : DefinedHeatParameterTypes.values()) { - stringToDefinedType.put(definedHeatParameterType.type, definedHeatParameterType); + NUMBER("number"), + STRING("string"), + COMMA_DELIMITED_LIST("comma_delimited_list"), + JSON("json"), + BOOLEAN("boolean"); + + private static Map<String, DefinedHeatParameterTypes> stringToDefinedType; + + static { + stringToDefinedType = new HashMap<>(); + for (DefinedHeatParameterTypes definedHeatParameterType : DefinedHeatParameterTypes.values()) { + stringToDefinedType.put(definedHeatParameterType.type, definedHeatParameterType); + } + } + + private String type; + + DefinedHeatParameterTypes(String type) { + this.type = type; } - } - - private String type; - - DefinedHeatParameterTypes(String type) { - this.type = type; - } - - public static DefinedHeatParameterTypes findByHeatResource(String type) { - return stringToDefinedType.get(type); - } - - /** - * Is value is from given type boolean. - * - * @param value the value - * @param parameterType the parameter type - * @return the boolean - */ - public static boolean isValueIsFromGivenType(Object value, String parameterType) { - DefinedHeatParameterTypes definedType = findByHeatResource(parameterType); - - if (Objects.nonNull(definedType)) { - switch (definedType) { - case NUMBER: - return NumberUtils.isNumber(String.valueOf(value)); - - case BOOLEAN: - return HeatBoolean.isValueBoolean(value); - - case COMMA_DELIMITED_LIST: - return isValueCommaDelimitedList(value); - - case JSON: - return isValueJson(value); - - case STRING: - return isValueString(value); - default: - } + + public static DefinedHeatParameterTypes findByHeatResource(String type) { + return stringToDefinedType.get(type); } - return false; - } + /** + * Is value is from given type boolean. + * + * @param value the value + * @param parameterType the parameter type + * @return the boolean + */ + public static boolean isValueIsFromGivenType(Object value, String parameterType) { + DefinedHeatParameterTypes definedType = findByHeatResource(parameterType); + + if (Objects.nonNull(definedType)) { + switch (definedType) { + case NUMBER: + return NumberUtils.isNumber(String.valueOf(value)); + + case BOOLEAN: + return HeatBoolean.isValueBoolean(value); + + case COMMA_DELIMITED_LIST: + return isValueCommaDelimitedList(value); + + case JSON: + return isValueJson(value); + + case STRING: + return isValueString(value); + default: + } + } + + return false; + } - public static boolean isNovaServerEnvValueIsFromRightType(Object value) { - return isValueIsFromGivenType(value, COMMA_DELIMITED_LIST.getType()) - || isValueIsFromGivenType(value, STRING.getType()); - } + public static boolean isNovaServerEnvValueIsFromRightType(Object value) { + return isValueIsFromGivenType(value, COMMA_DELIMITED_LIST.getType()) + || isValueIsFromGivenType(value, STRING.getType()); + } - private static boolean isValueCommaDelimitedList(Object value) { - return value instanceof List - || String.valueOf(value).contains(",") - || isValueIsFromGivenType(value, DefinedHeatParameterTypes.STRING.type); - } + private static boolean isValueCommaDelimitedList(Object value) { + return value instanceof List + || String.valueOf(value).contains(",") + || isValueIsFromGivenType(value, DefinedHeatParameterTypes.STRING.type); + } - private static boolean isValueString(Object value) { - return value instanceof String - || ClassUtils.isPrimitiveOrWrapper(value.getClass()); - } + private static boolean isValueString(Object value) { + return value instanceof String + || ClassUtils.isPrimitiveOrWrapper(value.getClass()); + } - private static boolean isValueJson(Object value) { - return (value instanceof Map) || (value instanceof List); - } + private static boolean isValueJson(Object value) { + return (value instanceof Map) || (value instanceof List); + } - public static boolean isEmptyValueInEnv(Object value) { - return Objects.isNull(value); - } + public static boolean isEmptyValueInEnv(Object value) { + return Objects.isNull(value); + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public void setType(String type) { - this.type = type; - } + public void setType(String type) { + this.type = type; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/HeatBoolean.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/HeatBoolean.java index 5753fa2a27..19fa2d5964 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/HeatBoolean.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/HeatBoolean.java @@ -12,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -*/ + */ package org.openecomp.sdc.heat.datatypes; +import java.util.HashSet; +import java.util.Set; + import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; @@ -23,77 +26,75 @@ import org.openecomp.sdc.heat.services.ErrorCodes; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import java.util.HashSet; -import java.util.Set; - public class HeatBoolean { - private static Set<Object> heatFalse; - private static Set<Object> heatTrue; - private static final Logger LOG = LoggerFactory.getLogger(HeatBoolean.class.getName()); - - private HeatBoolean() { - //Utility classes, which are a collection of static members, are not meant to be instantiated - } - static { + private static Set<Object> heatFalse; + private static Set<Object> heatTrue; + private static final Logger LOG = LoggerFactory.getLogger(HeatBoolean.class.getName()); + private HeatBoolean() { + //Utility classes, which are a collection of static members, are not meant to be instantiated + } - heatFalse = new HashSet<>(); - heatFalse.add("f"); - heatFalse.add(false); - heatFalse.add("false"); - heatFalse.add("off"); - heatFalse.add("n"); - heatFalse.add("no"); - heatFalse.add(0); + static { - heatTrue = new HashSet<>(); - heatTrue.add("t"); - heatTrue.add(true); - heatTrue.add("true"); - heatTrue.add("on"); - heatTrue.add("y"); - heatTrue.add("yes"); - heatTrue.add(1); - } + heatFalse = new HashSet<>(); + heatFalse.add("f"); + heatFalse.add(false); + heatFalse.add("false"); + heatFalse.add("off"); + heatFalse.add("n"); + heatFalse.add("no"); + heatFalse.add(0); - /** - * Eval boolean. - * - * @param value the value - * @return the boolean - */ - public static Boolean eval(Object value) { + heatTrue = new HashSet<>(); + heatTrue.add("t"); + heatTrue.add(true); + heatTrue.add("true"); + heatTrue.add("on"); + heatTrue.add("y"); + heatTrue.add("yes"); + heatTrue.add(1); - if (value instanceof String) { - value = ((String) value).toLowerCase(); - } - if (heatFalse.contains(value)) { - return false; - } else if (heatTrue.contains(value)) { - return true; - } else { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withId(ErrorCodes.INVALID_BOOLEAN) - .withCategory(ErrorCategory.APPLICATION) - .withMessage("Invalid boolean value [" + value + "].").build()); } - } + /** + * Eval boolean. + * + * @param value the value + * @return the boolean + */ + public static Boolean eval(Object value) { + + if (value instanceof String) { + value = ((String) value).toLowerCase(); + } + if (heatFalse.contains(value)) { + return false; + } else if (heatTrue.contains(value)) { + return true; + } else { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withId(ErrorCodes.INVALID_BOOLEAN) + .withCategory(ErrorCategory.APPLICATION) + .withMessage("Invalid boolean value [" + value + "].").build()); + } + + } - /** - * Is value boolean boolean. - * - * @param value the value - * @return the boolean - */ - public static boolean isValueBoolean(Object value) { - try { - eval(value); - return true; - } catch (CoreException ce) { - LOG.error("Failed to evaluate value as boolean: {}", value, ce); - return false; + /** + * Is value boolean boolean. + * + * @param value the value + * @return the boolean + */ + public static boolean isValueBoolean(Object value) { + try { + eval(value); + return true; + } catch (CoreException ce) { + LOG.error("Failed to evaluate value as boolean: {}", value, ce); + return false; + } } - } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/FileData.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/FileData.java index 2bc549c058..35276b4f11 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/FileData.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/FileData.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,15 +20,28 @@ package org.openecomp.sdc.heat.datatypes.manifest; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.function.Predicate; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.collections4.CollectionUtils; + +@Data public class FileData { protected static final Set<Type> heatFileTypes = - new HashSet<>(Arrays.asList(Type.HEAT, Type.HEAT_NET, Type.HEAT_VOL)); + new HashSet<>(Arrays.asList(Type.HEAT, Type.HEAT_NET, Type.HEAT_VOL)); + + @Getter(AccessLevel.NONE) + @Setter(AccessLevel.NONE) private Boolean isBase; private String parentFile; private String file; @@ -40,8 +53,8 @@ public class FileData { } public static boolean isHeatFile(Type type) { - return heatFileTypes.contains(type); - } + return heatFileTypes.contains(type); + } public Boolean getBase() { return isBase; @@ -51,43 +64,11 @@ public class FileData { isBase = base; } - public String getFile() { - return file; - } - - public void setFile(String file) { - this.file = file; - } - - public String getParentFile() { - return parentFile; - } - - public void setParentFile(String parentFile) { - this.parentFile = parentFile; - } - - public Type getType() { - return type; - } - - public void setType(Type type) { - this.type = type; - } - - public List<FileData> getData() { - return data; - } - - public void setData(List<FileData> data) { - this.data = data; - } - /** - * Add file data. - * - * @param data the data - */ + * Add file data. + * + * @param data the data + */ public void addFileData(FileData data) { if (CollectionUtils.isEmpty(this.data)) { this.data = new ArrayList<>(); @@ -95,40 +76,32 @@ public class FileData { this.data.add(data); } + @AllArgsConstructor + @Getter public enum Type { - - HEAT("HEAT"), - HEAT_ENV("HEAT_ENV"), - HEAT_NET("HEAT_NET"), - HEAT_VOL("HEAT_VOL"), - CHEF("CHEF"), - PUPPET("PUPPET"), - SHELL("SHELL"), - YANG("YANG"), - YANG_XML("YANG_XML"), - BPEL("BPEL"), - DG_XML("DG_XML"), - MURANO_PKG("MURANO_PKG"), - VENDOR_LICENSE("VENDOR_LICENSE"), - VF_LICENSE("VF_LICENSE"), - OTHER("OTHER"); + HEAT("HEAT"), + HEAT_ENV("HEAT_ENV"), + HEAT_NET("HEAT_NET"), + HEAT_VOL("HEAT_VOL"), + CHEF("CHEF"), + PUPPET("PUPPET"), + SHELL("SHELL"), + YANG("YANG"), + YANG_XML("YANG_XML"), + BPEL("BPEL"), + DG_XML("DG_XML"), + MURANO_PKG("MURANO_PKG"), + VENDOR_LICENSE("VENDOR_LICENSE"), + VF_LICENSE("VF_LICENSE"), + OTHER("OTHER"); private String displayName; - Type(String displayName) { - this.displayName = displayName; - } - - public String getDisplayName() { - return displayName; - } - public static boolean isArtifact(Type fileType) { - return !Arrays.asList(HEAT,HEAT_ENV, HEAT_VOL).contains(fileType); + return !Arrays.asList(HEAT, HEAT_ENV, HEAT_VOL).contains(fileType); } - public static boolean canBeAssociated(Type fileType) - { + public static boolean canBeAssociated(Type fileType) { return HEAT_VOL == fileType; } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestContent.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestContent.java index d89717125a..107b060094 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestContent.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestContent.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,42 +22,13 @@ package org.openecomp.sdc.heat.datatypes.manifest; import java.util.List; -public class ManifestContent { - - String name; - String description; - String version; - List<FileData> data; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } +import lombok.Data; - public void setDescription(String description) { - this.description = description; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public List<FileData> getData() { - return data; - } +@Data +public class ManifestContent { - public void setData(List<FileData> data) { - this.data = data; - } + private String name; + private String description; + private String version; + private List<FileData> data; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestFile.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestFile.java index 607f52a86d..6a62740bf5 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestFile.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/manifest/ManifestFile.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,24 +20,11 @@ package org.openecomp.sdc.heat.datatypes.manifest; -public class ManifestFile { - - String name; - ManifestContent content; - - public String getName() { - return name; - } +import lombok.Data; - public void setName(String name) { - this.name = name; - } - - public ManifestContent getContent() { - return content; - } +@Data +public class ManifestFile { - public void setContent(ManifestContent content) { - this.content = content; - } + private String name; + private ManifestContent content; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Constraint.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Constraint.java index ebbb064ce9..b3658bf5b1 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Constraint.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Constraint.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,56 +23,35 @@ package org.openecomp.sdc.heat.datatypes.model; import java.util.ArrayList; import java.util.List; -public class Constraint { - private Object[] length; - private Integer[] range; - private List<Object> validValues; - private String pattern; - - public Constraint() { - } - - public Integer[] getRange() { - return range; - } +import lombok.AccessLevel; +import lombok.Data; +import lombok.Setter; - public void setRange(Integer[] inRange) { - this.range = new Integer[]{inRange[0], inRange[1]}; - } - - public List<Object> getValidValues() { - return validValues; - } +@Data +public class Constraint { - public void setValidValues(List<Object> validValues) { - this.validValues = validValues; - } + private Object[] length; + @Setter(AccessLevel.NONE) + private Integer[] range; + private List<Object> validValues; + private String pattern; - /** - * Add valid value. - * - * @param validValue the valid value - */ - public void addValidValue(Object validValue) { - if (this.validValues == null) { - this.validValues = new ArrayList<>(); + public Constraint() { } - validValues.add(validValue); - } - public Object[] getLength() { - return length; - } - - public void setLength(Object[] length) { - this.length = length; - } - - public String getPattern() { - return pattern; - } + public void setRange(Integer[] inRange) { + this.range = new Integer[] {inRange[0], inRange[1]}; + } - public void setPattern(String pattern) { - this.pattern = pattern; - } + /** + * Add valid value. + * + * @param validValue the valid value + */ + public void addValidValue(Object validValue) { + if (this.validValues == null) { + this.validValues = new ArrayList<>(); + } + validValues.add(validValue); + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailResourceTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailResourceTypes.java index 47eaefafec..7538f11593 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailResourceTypes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailResourceTypes.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,45 +25,45 @@ import java.util.Map; import java.util.Objects; public enum ContrailResourceTypes { - ATTACH_POLICY("OS::Contrail::AttachPolicy"), - SERVICE_INSTANCE("OS::Contrail::ServiceInstance"), - SERVICE_TEMPLATE("OS::Contrail::ServiceTemplate"), - NETWORK_POLICY("OS::Contrail::NetworkPolicy"), - VIRTUAL_NETWORK("OS::Contrail::VirtualNetwork"); + ATTACH_POLICY("OS::Contrail::AttachPolicy"), + SERVICE_INSTANCE("OS::Contrail::ServiceInstance"), + SERVICE_TEMPLATE("OS::Contrail::ServiceTemplate"), + NETWORK_POLICY("OS::Contrail::NetworkPolicy"), + VIRTUAL_NETWORK("OS::Contrail::VirtualNetwork"); - private static Map<String, ContrailResourceTypes> stringToContrailResourceTypeMap; + private static Map<String, ContrailResourceTypes> stringToContrailResourceTypeMap; - static { - stringToContrailResourceTypeMap = new HashMap<>(); + static { + stringToContrailResourceTypeMap = new HashMap<>(); - for (ContrailResourceTypes type : ContrailResourceTypes.values()) { - stringToContrailResourceTypeMap.put(type.contrailResourceType, type); + for (ContrailResourceTypes type : ContrailResourceTypes.values()) { + stringToContrailResourceTypeMap.put(type.contrailResourceType, type); + } } - } - private String contrailResourceType; + private String contrailResourceType; - ContrailResourceTypes(String contrailResourceType) { - this.contrailResourceType = contrailResourceType; - } + ContrailResourceTypes(String contrailResourceType) { + this.contrailResourceType = contrailResourceType; + } - /** - * Find by contrail v 2 resource contrail resource types. - * - * @param contrailV2Resource the contrail v 2 resource - * @return the contrail resource types - */ - public static ContrailResourceTypes findByContrailV2Resource(String contrailV2Resource) { - return contrailV2Resource == null ? null - : stringToContrailResourceTypeMap.get(contrailV2Resource); + /** + * Find by contrail v 2 resource contrail resource types. + * + * @param contrailV2Resource the contrail v 2 resource + * @return the contrail resource types + */ + public static ContrailResourceTypes findByContrailV2Resource(String contrailV2Resource) { + return contrailV2Resource == null ? null + : stringToContrailResourceTypeMap.get(contrailV2Resource); - } + } - public static boolean isResourceTypeContrail(String resourceType) { - return Objects.nonNull(findByContrailV2Resource(resourceType)); - } + public static boolean isResourceTypeContrail(String resourceType) { + return Objects.nonNull(findByContrailV2Resource(resourceType)); + } - public String getContrailResourceType() { - return contrailResourceType; - } + public String getContrailResourceType() { + return contrailResourceType; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailV2ResourceTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailV2ResourceTypes.java index ff706093f8..40253ad1be 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailV2ResourceTypes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailV2ResourceTypes.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,36 +25,36 @@ import java.util.Map; import java.util.Objects; public enum ContrailV2ResourceTypes { - NETWROK_IPAM("OS::ContrailV2::NetworkIpam"), - VIRTUAL_NETWORK("OS::ContrailV2::VirtualNetwork"), - NETWORK_POLICY("OS::ContrailV2::NetworkPolicy"), - VIRTUAL_MACHINE_INTERFACE("OS::ContrailV2::VirtualMachineInterface"); + NETWROK_IPAM("OS::ContrailV2::NetworkIpam"), + VIRTUAL_NETWORK("OS::ContrailV2::VirtualNetwork"), + NETWORK_POLICY("OS::ContrailV2::NetworkPolicy"), + VIRTUAL_MACHINE_INTERFACE("OS::ContrailV2::VirtualMachineInterface"); - private static Map<String, ContrailV2ResourceTypes> stringToContrailV2ResourceTypeMap; + private static Map<String, ContrailV2ResourceTypes> stringToContrailV2ResourceTypeMap; - static { - stringToContrailV2ResourceTypeMap = new HashMap<>(); + static { + stringToContrailV2ResourceTypeMap = new HashMap<>(); - for (ContrailV2ResourceTypes type : ContrailV2ResourceTypes.values()) { - stringToContrailV2ResourceTypeMap.put(type.contrailV2ResourceType, type); + for (ContrailV2ResourceTypes type : ContrailV2ResourceTypes.values()) { + stringToContrailV2ResourceTypeMap.put(type.contrailV2ResourceType, type); + } } - } - private String contrailV2ResourceType; + private String contrailV2ResourceType; - ContrailV2ResourceTypes(String contrailV2ResourceType) { - this.contrailV2ResourceType = contrailV2ResourceType; - } + ContrailV2ResourceTypes(String contrailV2ResourceType) { + this.contrailV2ResourceType = contrailV2ResourceType; + } - public static ContrailV2ResourceTypes findByContrailV2Resource(String contrailV2Resource) { - return stringToContrailV2ResourceTypeMap.get(contrailV2Resource); - } + public static ContrailV2ResourceTypes findByContrailV2Resource(String contrailV2Resource) { + return stringToContrailV2ResourceTypeMap.get(contrailV2Resource); + } - public static boolean isResourceTypeContrailV2(String resourceType) { - return Objects.nonNull(findByContrailV2Resource(resourceType)); - } + public static boolean isResourceTypeContrailV2(String resourceType) { + return Objects.nonNull(findByContrailV2Resource(resourceType)); + } - public String getContrailV2ResourceType() { - return contrailV2ResourceType; - } + public String getContrailV2ResourceType() { + return contrailV2ResourceType; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Environment.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Environment.java index b2f45d06d9..db5121b014 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Environment.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Environment.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,14 +22,10 @@ package org.openecomp.sdc.heat.datatypes.model; import java.util.Map; -public class Environment { - Map<String, Object> parameters; +import lombok.Data; - public Map<String, Object> getParameters() { - return parameters; - } +@Data +public class Environment { - public void setParameters(Map<String, Object> parameters) { - this.parameters = parameters; - } + private Map<String, Object> parameters; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplate.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplate.java index 294bb9e47e..3387c43840 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplate.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplate.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,68 +23,16 @@ package org.openecomp.sdc.heat.datatypes.model; import java.util.List; import java.util.Map; -public class HeatOrchestrationTemplate { - String heat_template_version; - String description; - List<ParameterGroup> parameter_groups; - Map<String, Parameter> parameters; - Map<String, Resource> resources; - Map<String, Output> outputs; - Map<String, Object> conditions; - - public String getHeat_template_version() { - return heat_template_version; - } - - public void setHeat_template_version(String heat_template_version) { - this.heat_template_version = heat_template_version; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public List<ParameterGroup> getParameter_groups() { - return parameter_groups; - } - - public void setParameter_groups(List<ParameterGroup> parameter_groups) { - this.parameter_groups = parameter_groups; - } +import lombok.Data; - public Map<String, Parameter> getParameters() { - return parameters; - } - - public void setParameters(Map<String, Parameter> parameters) { - this.parameters = parameters; - } - - public Map<String, Resource> getResources() { - return resources; - } - - public void setResources(Map<String, Resource> resources) { - this.resources = resources; - } - - public Map<String, Output> getOutputs() { - return outputs; - } - - public void setOutputs(Map<String, Output> outputs) { - this.outputs = outputs; - } - - public Map<String, Object> getConditions() { - return conditions; - } +@Data +public class HeatOrchestrationTemplate { - public void setConditions(Map<String, Object> conditions) { - this.conditions = conditions; - } + private String heat_template_version; + private String description; + private List<ParameterGroup> parameter_groups; + private Map<String, Parameter> parameters; + private Map<String, Resource> resources; + private Map<String, Output> outputs; + private Map<String, Object> conditions; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatPseudoParameters.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatPseudoParameters.java index c822a78a93..7ed8203bfe 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatPseudoParameters.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatPseudoParameters.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,39 +23,33 @@ package org.openecomp.sdc.heat.datatypes.model; import java.util.ArrayList; import java.util.List; -public enum HeatPseudoParameters { - OS_STACK_NAME("OS::stack_name"), - OS_STACK_ID("OS::stack_id"), - OS_PROJECT_ID("OS::project_id"); - - private static List<String> pseudoParameterNames; +import lombok.Getter; - static { - pseudoParameterNames = new ArrayList<>(); - for (HeatPseudoParameters parameter : HeatPseudoParameters.values()) { - pseudoParameterNames.add(parameter.getPseudoParameter()); +@Getter +public enum HeatPseudoParameters { + OS_STACK_NAME("OS::stack_name"), + OS_STACK_ID("OS::stack_id"), + OS_PROJECT_ID("OS::project_id"); + + private static List<String> pseudoParameterNames; + private String pseudoParameter; + + static { + pseudoParameterNames = new ArrayList<>(); + for (HeatPseudoParameters parameter : HeatPseudoParameters.values()) { + pseudoParameterNames.add(parameter.getPseudoParameter()); + } } - } - - private String pseudoParameter; - - HeatPseudoParameters(String pseudoParameter) { - this.pseudoParameter = pseudoParameter; - } - public static List<String> getPseudoParameterNames() { - return pseudoParameterNames; - } - - public static void setPseudoParameterNames(List<String> pseudoParameterNames) { - HeatPseudoParameters.pseudoParameterNames = pseudoParameterNames; - } + HeatPseudoParameters(String pseudoParameter) { + this.pseudoParameter = pseudoParameter; + } - public String getPseudoParameter() { - return pseudoParameter; - } + public static List<String> getPseudoParameterNames() { + return pseudoParameterNames; + } - public void setPseudoParameter(String pseudoParameter) { - this.pseudoParameter = pseudoParameter; - } + public static void setPseudoParameterNames(List<String> pseudoParameterNames) { + HeatPseudoParameters.pseudoParameterNames = pseudoParameterNames; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypes.java index b73fe385a6..a9598eb67f 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypes.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,93 +27,85 @@ import java.util.Map; import java.util.Objects; public enum HeatResourcesTypes { - NOVA_SERVER_RESOURCE_TYPE("OS::Nova::Server"), - NOVA_SERVER_GROUP_RESOURCE_TYPE("OS::Nova::ServerGroup"), - NEUTRON_PORT_RESOURCE_TYPE("OS::Neutron::Port"), - CONTRAIL_NETWORK_RULE_RESOURCE_TYPE("OS::Contrail::NetworkPolicy"), - CONTRAIL_NETWORK_ATTACH_RULE_RESOURCE_TYPE("OS::Contrail::AttachPolicy"), - CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::Contrail::VirtualNetwork"), - CINDER_VOLUME_RESOURCE_TYPE("OS::Cinder::Volume"), - CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE("OS::Cinder::VolumeAttachment"), - NEUTRON_NET_RESOURCE_TYPE("OS::Neutron::Net"), - NEUTRON_SUBNET_RESOURCE_TYPE("OS::Neutron::Subnet"), - NEUTRON_SECURITY_GROUP_RESOURCE_TYPE("OS::Neutron::SecurityGroup"), - HEAT_SOFTWARE_CONFIG_TYPE("OS::Heat::SoftwareConfig"), - HEAT_CLOUD_CONFIG_TYPE("OS::Heat::CloudConfig"), - HEAT_MULTIPART_MIME_TYPE("OS::Heat::MultipartMime"), - HEAT_CONTRAIL_NETWORK_IPAM_TYPE("OS::Contrail::NetworkIpam"), - CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::ContrailV2::VirtualNetwork"), - CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE("OS::ContrailV2::VirtualMachineInterface"), - CONTRAIL_SERVICE_TEMPLATE("OS::Contrail::ServiceTemplate"), - CONTRAIL_SERVICE_INSTANCE("OS::Contrail::ServiceInstance"), - CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE("OS::ContrailV2::NetworkPolicy"), - RESOURCE_GROUP_RESOURCE_TYPE("OS::Heat::ResourceGroup"); - - private static Map<String, HeatResourcesTypes> stringToHeatResourceTypeMap; - - static { - stringToHeatResourceTypeMap = new HashMap<>(); - - for (HeatResourcesTypes type : HeatResourcesTypes.values()) { - stringToHeatResourceTypeMap.put(type.heatResource, type); + NOVA_SERVER_RESOURCE_TYPE("OS::Nova::Server"), + NOVA_SERVER_GROUP_RESOURCE_TYPE("OS::Nova::ServerGroup"), + NEUTRON_PORT_RESOURCE_TYPE("OS::Neutron::Port"), + CONTRAIL_NETWORK_RULE_RESOURCE_TYPE("OS::Contrail::NetworkPolicy"), + CONTRAIL_NETWORK_ATTACH_RULE_RESOURCE_TYPE("OS::Contrail::AttachPolicy"), + CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::Contrail::VirtualNetwork"), + CINDER_VOLUME_RESOURCE_TYPE("OS::Cinder::Volume"), + CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE("OS::Cinder::VolumeAttachment"), + NEUTRON_NET_RESOURCE_TYPE("OS::Neutron::Net"), + NEUTRON_SUBNET_RESOURCE_TYPE("OS::Neutron::Subnet"), + NEUTRON_SECURITY_GROUP_RESOURCE_TYPE("OS::Neutron::SecurityGroup"), + HEAT_SOFTWARE_CONFIG_TYPE("OS::Heat::SoftwareConfig"), + HEAT_CLOUD_CONFIG_TYPE("OS::Heat::CloudConfig"), + HEAT_MULTIPART_MIME_TYPE("OS::Heat::MultipartMime"), + HEAT_CONTRAIL_NETWORK_IPAM_TYPE("OS::Contrail::NetworkIpam"), + CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::ContrailV2::VirtualNetwork"), + CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE("OS::ContrailV2::VirtualMachineInterface"), + CONTRAIL_SERVICE_TEMPLATE("OS::Contrail::ServiceTemplate"), + CONTRAIL_SERVICE_INSTANCE("OS::Contrail::ServiceInstance"), + CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE("OS::ContrailV2::NetworkPolicy"), + RESOURCE_GROUP_RESOURCE_TYPE("OS::Heat::ResourceGroup"); + + private static Map<String, HeatResourcesTypes> stringToHeatResourceTypeMap; + private String heatResource; + + static { + stringToHeatResourceTypeMap = new HashMap<>(); + + for (HeatResourcesTypes type : HeatResourcesTypes.values()) { + stringToHeatResourceTypeMap.put(type.heatResource, type); + } } - } - - private String heatResource; - - - HeatResourcesTypes(String heatResource) { - this.heatResource = heatResource; - } - - public static HeatResourcesTypes findByHeatResource(String heatResource) { - return stringToHeatResourceTypeMap.get(heatResource); - } - - public static boolean isResourceTypeValid(String resourceType) { - return Objects.nonNull(findByHeatResource(resourceType)); - } - /** - * Is resource expected to be exposed boolean. - * - * @param resourceType the resource type - * @return the boolean - */ - public static boolean isResourceExpectedToBeExposed(String resourceType) { - //todo - check - return (resourceType.equals(NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource()) - || resourceType.equals(CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource()) - || resourceType.equals(NEUTRON_NET_RESOURCE_TYPE.getHeatResource()) - || resourceType.equals(CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()) - || resourceType.equals(NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource()) - ); - } - - /** - * Gets list for resource type. - * - * @param types the types - * @return the list for resource type - */ - public static Map<HeatResourcesTypes, List<String>> getListForResourceType( - HeatResourcesTypes... types) { - Map<HeatResourcesTypes, List<String>> result = new HashMap<>(); - - for (HeatResourcesTypes type : types) { - result.put(type, new ArrayList<>()); + HeatResourcesTypes(String heatResource) { + this.heatResource = heatResource; } - return result; - } + public static HeatResourcesTypes findByHeatResource(String heatResource) { + return stringToHeatResourceTypeMap.get(heatResource); + } - public String getHeatResource() { + public static boolean isResourceTypeValid(String resourceType) { + return Objects.nonNull(findByHeatResource(resourceType)); + } - return heatResource; - } + /** + * Is resource expected to be exposed boolean. + * + * @param resourceType the resource type + * @return the boolean + */ + public static boolean isResourceExpectedToBeExposed(String resourceType) { + //todo - check + return (resourceType.equals(NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource()) + || resourceType.equals(CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource()) + || resourceType.equals(NEUTRON_NET_RESOURCE_TYPE.getHeatResource()) + || resourceType.equals(CINDER_VOLUME_RESOURCE_TYPE.getHeatResource()) + || resourceType.equals(NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource()) + ); + } - public void setHeatResource(String heatResource) { - this.heatResource = heatResource; - } + /** + * Gets list for resource type. + * + * @param types the types + * @return the list for resource type + */ + public static Map<HeatResourcesTypes, List<String>> getListForResourceType( + HeatResourcesTypes... types) { + Map<HeatResourcesTypes, List<String>> result = new HashMap<>(); + + for (HeatResourcesTypes type : types) { + result.put(type, new ArrayList<>()); + } + + return result; + } + public String getHeatResource() { + return heatResource; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Output.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Output.java index 8222edded2..343205d171 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Output.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Output.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,23 +20,11 @@ package org.openecomp.sdc.heat.datatypes.model; -public class Output { - String description; - Object value; - - public String getDescription() { - return description; - } +import lombok.Data; - public void setDescription(String description) { - this.description = description; - } - - public Object getValue() { - return value; - } +@Data +public class Output { - public void setValue(Object value) { - this.value = value; - } + String description; + Object value; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Parameter.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Parameter.java index d419738942..81372aa68c 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Parameter.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Parameter.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,68 +23,16 @@ package org.openecomp.sdc.heat.datatypes.model; import java.util.List; import java.util.Map; -public class Parameter { - String type; - String label; - String description; - Object _default; - boolean hidden; - List<Map<String, Object>> constraints; - boolean immutable; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } +import lombok.Data; - public Object get_default() { - return _default; - } - - public void set_default(Object _default) { - this._default = _default; - } - - public boolean isHidden() { - return hidden; - } - - public void setHidden(boolean hidden) { - this.hidden = hidden; - } - - public List<Map<String, Object>> getConstraints() { - return constraints; - } - - public void setConstraints(List<Map<String, Object>> constraints) { - this.constraints = constraints; - } - - public boolean isImmutable() { - return immutable; - } +@Data +public class Parameter { - public void setImmutable(boolean immutable) { - this.immutable = immutable; - } + private String type; + private String label; + private String description; + private Object _default; + private boolean hidden; + private List<Map<String, Object>> constraints; + private boolean immutable; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterGroup.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterGroup.java index 8ab066f4a4..4595466436 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterGroup.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterGroup.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,32 +22,12 @@ package org.openecomp.sdc.heat.datatypes.model; import java.util.List; -public class ParameterGroup { - String label; - String description; - List<String> parameters; - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } +import lombok.Data; - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public List<String> getParameters() { - return parameters; - } +@Data +public class ParameterGroup { - public void setParameters(List<String> parameters) { - this.parameters = parameters; - } + private String label; + private String description; + private List<String> parameters; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterType.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterType.java index 37c430ec36..3f6dc9f7ce 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterType.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ParameterType.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,23 +20,18 @@ package org.openecomp.sdc.heat.datatypes.model; -public enum ParameterType { - - STRING("string"), - NUMBER("number"), - JSON("json"), - BOOLEAN("boolean"), - COMMA_DELIMITED_LIST("comma_delimited_list"); - - private String displayName; +import lombok.AllArgsConstructor; +import lombok.Getter; - ParameterType(String displayName) { - this.displayName = displayName; - } - - public String getDisplayName() { - return displayName; - } +@AllArgsConstructor +@Getter +public enum ParameterType { + STRING("string"), + NUMBER("number"), + JSON("json"), + BOOLEAN("boolean"), + COMMA_DELIMITED_LIST("comma_delimited_list"); + private String displayName; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PolicyTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PolicyTypes.java index 3195e61fe5..77a7cd4552 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PolicyTypes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PolicyTypes.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,38 +24,31 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor public enum PolicyTypes { - AFFINITY("affinity"), - ANTI_AFFINITY("anti-affinity"); + AFFINITY("affinity"), + ANTI_AFFINITY("anti-affinity"); - private static Map<String, PolicyTypes> stringToPolicyTypesMap; + private static Map<String, PolicyTypes> stringToPolicyTypesMap; - static { - stringToPolicyTypesMap = new HashMap<>(); - for (PolicyTypes type : PolicyTypes.values()) { - stringToPolicyTypesMap.put(type.policy, type); + static { + stringToPolicyTypesMap = new HashMap<>(); + for (PolicyTypes type : PolicyTypes.values()) { + stringToPolicyTypesMap.put(type.policy, type); + } } - } - - private String policy; - - PolicyTypes(String policy) { - this.policy = policy; - } - public static PolicyTypes findByPolicy(String policy) { - return stringToPolicyTypesMap.get(policy); - } + private String policy; - public static boolean isGivenPolicyValid(String policyToCheck) { - return Objects.nonNull(findByPolicy(policyToCheck)); - } - - public String getPolicy() { - return policy; - } + public static PolicyTypes findByPolicy(String policy) { + return stringToPolicyTypesMap.get(policy); + } - public void setPolicy(String policy) { - this.policy = policy; - } + public static boolean isGivenPolicyValid(String policyToCheck) { + return Objects.nonNull(findByPolicy(policyToCheck)); + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PropertiesMapKeyTypes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PropertiesMapKeyTypes.java index e8d43fc10c..46673c2eaa 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PropertiesMapKeyTypes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/PropertiesMapKeyTypes.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,23 +20,16 @@ package org.openecomp.sdc.heat.datatypes.model; -public enum PropertiesMapKeyTypes { - IMAGE("image"), - FLAVOR("flavor"), - NETWORKS("networks"), - RESOURCE_DEF("resource_def"); - - private String keyMap; +import lombok.AllArgsConstructor; +import lombok.Getter; - PropertiesMapKeyTypes(String keyMap) { - this.keyMap = keyMap; - } - - public String getKeyMap() { - return keyMap; - } +@Getter +@AllArgsConstructor +public enum PropertiesMapKeyTypes { + IMAGE("image"), + FLAVOR("flavor"), + NETWORKS("networks"), + RESOURCE_DEF("resource_def"); - public void setKeyMap(String keyMap) { - this.keyMap = keyMap; - } + private String keyMap; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Resource.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Resource.java index 2c70105da9..4703f43632 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Resource.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/Resource.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,71 +22,27 @@ package org.openecomp.sdc.heat.datatypes.model; import java.util.Map; -public class Resource { - String type; - Map<String, Object> properties; - Object metadata; - Object depends_on; - Object update_policy; - Object deletion_policy; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Map<String, Object> getProperties() { - return properties; - } - - public void setProperties(Map<String, Object> properties) { - this.properties = properties; - } - - public Object getMetadata() { - return metadata; - } - - public void setMetadata(Object metadata) { - this.metadata = metadata; - } +import lombok.Data; - public Object getDepends_on() { - return depends_on; - } - - public void setDepends_on(Object depends_on) { - this.depends_on = depends_on; - } - - public Object getUpdate_policy() { - return update_policy; - } - - public void setUpdate_policy(Object update_policy) { - this.update_policy = update_policy; - } - - public Object getDeletion_policy() { - return deletion_policy; - } - - public void setDeletion_policy(Object deletion_policy) { - this.deletion_policy = deletion_policy; - } +@Data +public class Resource { - @Override - public String toString() { - return "Resource{" - + "type='" + type + '\'' - + ", properties=" + properties - + ", metadata=" + metadata - + ", depends_on=" + depends_on - + ", update_policy='" + update_policy + '\'' - + ", deletion_policy='" + deletion_policy + '\'' - + '}'; - } + private String type; + private Map<String, Object> properties; + private Object metadata; + private Object depends_on; + private Object update_policy; + private Object deletion_policy; + + @Override + public String toString() { + return "Resource{" + + "type='" + type + '\'' + + ", properties=" + properties + + ", metadata=" + metadata + + ", depends_on=" + depends_on + + ", update_policy='" + update_policy + '\'' + + ", deletion_policy='" + deletion_policy + '\'' + + '}'; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceReferenceFunctions.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceReferenceFunctions.java index b36d130597..9c1feb2cc4 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceReferenceFunctions.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceReferenceFunctions.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,25 +20,17 @@ package org.openecomp.sdc.heat.datatypes.model; -public enum ResourceReferenceFunctions { - GET_RESOURCE("get_resource"), - GET_PARAM("get_param"), - GET_ATTR("get_attr"), - GET_FILE("get_file"), - SCHEDULER_HINTS("scheduler_hints"); - - - private String function; +import lombok.AllArgsConstructor; +import lombok.Getter; - ResourceReferenceFunctions(String function) { - this.function = function; - } - - public String getFunction() { - return function; - } +@AllArgsConstructor +@Getter +public enum ResourceReferenceFunctions { + GET_RESOURCE("get_resource"), + GET_PARAM("get_param"), + GET_ATTR("get_attr"), + GET_FILE("get_file"), + SCHEDULER_HINTS("scheduler_hints"); - public void setFunction(String function) { - this.function = function; - } + private String function; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceTypeToMessageString.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceTypeToMessageString.java index d7ede70942..c4a13588a1 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceTypeToMessageString.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ResourceTypeToMessageString.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,32 +24,31 @@ import java.util.HashMap; import java.util.Map; public enum ResourceTypeToMessageString { - SERVER_GROUP(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE, "ServerGroup"), - SECURITY_GROUP(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE, "SecurityGroup"), - NETWORK_POLICY(HeatResourcesTypes.CONTRAIL_NETWORK_RULE_RESOURCE_TYPE, "NetworkPolicy"); + SERVER_GROUP(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE, "ServerGroup"), + SECURITY_GROUP(HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE, "SecurityGroup"), + NETWORK_POLICY(HeatResourcesTypes.CONTRAIL_NETWORK_RULE_RESOURCE_TYPE, "NetworkPolicy"); - private static Map<HeatResourcesTypes, String> resourcesTypesStringMap; + private static Map<HeatResourcesTypes, String> resourcesTypesStringMap; - static { - resourcesTypesStringMap = new HashMap<>(); + static { + resourcesTypesStringMap = new HashMap<>(); - for (ResourceTypeToMessageString resourceTypeToMessageString : ResourceTypeToMessageString - .values()) { - resourcesTypesStringMap - .put(resourceTypeToMessageString.type, resourceTypeToMessageString.messageString); + for (ResourceTypeToMessageString resourceTypeToMessageString : ResourceTypeToMessageString + .values()) { + resourcesTypesStringMap + .put(resourceTypeToMessageString.type, resourceTypeToMessageString.messageString); + } } - } - private String messageString; - private HeatResourcesTypes type; + private String messageString; + private HeatResourcesTypes type; + ResourceTypeToMessageString(HeatResourcesTypes type, String messageString) { + this.type = type; + this.messageString = messageString; + } - ResourceTypeToMessageString(HeatResourcesTypes type, String messgageString) { - this.type = type; - this.messageString = messgageString; - } - - public static String getTypeForMessageFromResourceType(HeatResourcesTypes type) { - return resourcesTypesStringMap.get(type); - } + public static String getTypeForMessageFromResourceType(HeatResourcesTypes type) { + return resourcesTypesStringMap.get(type); + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/Artifact.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/Artifact.java index 95ae4e59c7..9d1fbe3cb3 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/Artifact.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/Artifact.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,85 +20,50 @@ package org.openecomp.sdc.heat.datatypes.structure; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.manifest.FileData; -import java.util.ArrayList; -import java.util.List; - +@Getter +@Setter +@EqualsAndHashCode public class Artifact implements Comparable<Artifact> { - private String fileName; - private FileData.Type type; - private List<ErrorMessage> errors; - - public Artifact(String fileName, FileData.Type type) { - this.fileName = fileName; - this.type = type; - } - - - public String getFileName() { - return fileName; - } - - public void setFileName(String name) { - this.fileName = name; - } + private String fileName; + @Setter(AccessLevel.NONE) + @EqualsAndHashCode.Exclude + private FileData.Type type; - public FileData.Type getType() { - return type; - } + @EqualsAndHashCode.Exclude + private List<ErrorMessage> errors; - public List<ErrorMessage> getErrors() { - return errors; - } - - public void setErrors(List<ErrorMessage> errors) { - this.errors = errors; - } - - /** - * Add error to error list. - * - * @param error the error - */ - public void addErrorToErrorList(ErrorMessage error) { - if (this.errors == null || this.errors.isEmpty()) { - this.errors = new ArrayList<>(); + public Artifact(String fileName, FileData.Type type) { + this.fileName = fileName; + this.type = type; } - this.errors.add(error); - } - - @Override - public int hashCode() { - int result = fileName.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; + /** + * Add error to error list. + * + * @param error the error + */ + public void addErrorToErrorList(ErrorMessage error) { + if (this.errors == null || this.errors.isEmpty()) { + this.errors = new ArrayList<>(); + } + + this.errors.add(error); } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - Artifact artifact = (Artifact) obj; - if (!fileName.equals(artifact.fileName)) { - return false; + @Override + public int compareTo(Artifact artifact) { + return artifact.getFileName().compareTo(this.getFileName()); } - return true; - - } - - @Override - public int compareTo(Artifact artifact) { - return artifact.getFileName().compareTo(this.getFileName()); - } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/HeatStructureTree.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/HeatStructureTree.java index 5313d4d370..8d1b5912df 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/HeatStructureTree.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/HeatStructureTree.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,331 +20,253 @@ package org.openecomp.sdc.heat.datatypes.structure; - -import org.codehaus.jackson.annotate.JsonProperty; -import org.openecomp.sdc.datatypes.error.ErrorMessage; -import org.openecomp.sdc.heat.datatypes.manifest.FileData; - import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet; +import lombok.AccessLevel; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.manifest.FileData; + +@Data public class HeatStructureTree implements Comparable<HeatStructureTree> { - private String fileName; - private FileData.Type type; - private Boolean isBase; - private HeatStructureTree env; - private List<ErrorMessage> errors; - private Set<HeatStructureTree> heat; - private Set<HeatStructureTree> volume; - private Set<HeatStructureTree> network; - private Set<HeatStructureTree> nested; - private Set<HeatStructureTree> other; - private Set<Artifact> artifacts; - - public HeatStructureTree() { - } - - ; - - public HeatStructureTree(String fileName, boolean isBase) { - setBase(isBase); - setFileName(fileName); - } - - /** - * Gets heat structure tree by name. - * - * @param filesSet the files set - * @param filename the filename - * @return the heat structure tree by name - */ - public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet, - String filename) { - for (HeatStructureTree heatStructureTree : filesSet) { - if (heatStructureTree.getFileName().equals(filename)) { - return heatStructureTree; - } - } + private String fileName; + private FileData.Type type; - return null; - } - - public void setType(FileData.Type type) { - this.type = type; - } - - public Boolean getBase() { - return isBase; - } - - public void setBase(Boolean base) { - isBase = base; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String file) { - this.fileName = file; - } - - @JsonProperty(value = "heat") - public Set<HeatStructureTree> getHeat() { - return heat; - } - - public void setHeat(Set<HeatStructureTree> heat) { - this.heat = heat; - } - - public Set<HeatStructureTree> getNested() { - return nested; - } - - public void setNested(Set<HeatStructureTree> nested) { - this.nested = nested; - } - - public Set<Artifact> getArtifacts() { - return artifacts; - } - - public void setArtifacts(Set<Artifact> artifacts) { - this.artifacts = artifacts; - } - - /** - * Add heat structure tree to nested heat list. - * - * @param heatStructureTree the heat structure tree - */ - public void addHeatStructureTreeToNestedHeatList(HeatStructureTree heatStructureTree) { - if (this.nested == null) { - this.nested = new TreeSet<>(); + @Getter(AccessLevel.NONE) + @Setter(AccessLevel.NONE) + private Boolean isBase; + + private HeatStructureTree env; + private List<ErrorMessage> errors; + private Set<HeatStructureTree> heat; + private Set<HeatStructureTree> volume; + private Set<HeatStructureTree> network; + private Set<HeatStructureTree> nested; + private Set<HeatStructureTree> other; + private Set<Artifact> artifacts; + + public HeatStructureTree() { } - if (!findItemInSetByName(this.nested, heatStructureTree)) { - this.nested.add(heatStructureTree); + + public HeatStructureTree(String fileName, boolean isBase) { + this.isBase = isBase; + this.fileName = fileName; } - } - - /** - * Add artifact to artifact list. - * - * @param artifact the artifact - */ - public void addArtifactToArtifactList(Artifact artifact) { - if (this.artifacts == null || this.artifacts.isEmpty()) { - this.artifacts = new TreeSet<>(); + + public Boolean getBase() { + return isBase; } - this.artifacts.add(artifact); - } - - public HeatStructureTree getEnv() { - return env; - } - - public void setEnv(HeatStructureTree env) { - this.env = env; - } - - public Set<HeatStructureTree> getVolume() { - return volume; - } - - public void setVolume(Set<HeatStructureTree> volume) { - this.volume = volume; - } - - public Set<HeatStructureTree> getNetwork() { - return network; - } - - public void setNetwork(Set<HeatStructureTree> network) { - this.network = network; - } - - /** - * Add network to network list. - * - * @param heatStructureTree the heat structure tree - */ - public void addNetworkToNetworkList(HeatStructureTree heatStructureTree) { - if (this.network == null) { - this.network = new TreeSet<>(); + + public void setBase(Boolean isBase) { + this.isBase = isBase; } - if (!findItemInSetByName(this.network, heatStructureTree)) { - this.network.add(heatStructureTree); + + /** + * Gets heat structure tree by name. + * + * @param filesSet the files set + * @param filename the filename + * @return the heat structure tree by name + */ + public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet, + String filename) { + for (HeatStructureTree heatStructureTree : filesSet) { + if (heatStructureTree.getFileName().equals(filename)) { + return heatStructureTree; + } + } + + return null; } - } - - /** - * Add volume file to volume list. - * - * @param heatStructureTree the heat structure tree - */ - public void addVolumeFileToVolumeList(HeatStructureTree heatStructureTree) { - if (this.volume == null) { - this.volume = new TreeSet<>(); + + /** + * Add heat structure tree to nested heat list. + * + * @param heatStructureTree the heat structure tree + */ + public void addHeatStructureTreeToNestedHeatList(HeatStructureTree heatStructureTree) { + if (this.nested == null) { + this.nested = new TreeSet<>(); + } + if (!findItemInSetByName(this.nested, heatStructureTree)) { + this.nested.add(heatStructureTree); + } } - if (!findItemInSetByName(this.volume, heatStructureTree)) { - this.volume.add(heatStructureTree); + + /** + * Add artifact to artifact list. + * + * @param artifact the artifact + */ + public void addArtifactToArtifactList(Artifact artifact) { + if (this.artifacts == null || this.artifacts.isEmpty()) { + this.artifacts = new TreeSet<>(); + } + this.artifacts.add(artifact); } - } - - /** - * Add heat to heat list. - * - * @param heat the heat - */ - public void addHeatToHeatList(HeatStructureTree heat) { - if (this.heat == null) { - this.heat = new TreeSet<>(); + + /** + * Add network to network list. + * + * @param heatStructureTree the heat structure tree + */ + public void addNetworkToNetworkList(HeatStructureTree heatStructureTree) { + if (this.network == null) { + this.network = new TreeSet<>(); + } + if (!findItemInSetByName(this.network, heatStructureTree)) { + this.network.add(heatStructureTree); + } } - this.heat.add(heat); - } - - /** - * Add other to other list. - * - * @param other the other - */ - public void addOtherToOtherList(HeatStructureTree other) { - if (this.other == null) { - this.other = new TreeSet<>(); + /** + * Add volume file to volume list. + * + * @param heatStructureTree the heat structure tree + */ + public void addVolumeFileToVolumeList(HeatStructureTree heatStructureTree) { + if (this.volume == null) { + this.volume = new TreeSet<>(); + } + if (!findItemInSetByName(this.volume, heatStructureTree)) { + this.volume.add(heatStructureTree); + } } - this.other.add(other); - } - - /** - * Find item in set by name boolean. - * - * @param searchSet the search set - * @param toFind the to find - * @return the boolean - */ - public boolean findItemInSetByName(Set<HeatStructureTree> searchSet, HeatStructureTree toFind) { - for (HeatStructureTree heatStructureTree : searchSet) { - if (heatStructureTree.getFileName().equals(toFind.getFileName())) { - return true; - } + /** + * Add heat to heat list. + * + * @param heat the heat + */ + public void addHeatToHeatList(HeatStructureTree heat) { + if (this.heat == null) { + this.heat = new TreeSet<>(); + } + + this.heat.add(heat); + } + /** + * Add other to other list. + * + * @param other the other + */ + public void addOtherToOtherList(HeatStructureTree other) { + if (this.other == null) { + this.other = new TreeSet<>(); + } + + this.other.add(other); } - return false; - } - - /** - * Remove from volume or network. - * - * @param fileNameToRemove the file name to remove - * @param type the type - */ - public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) { - Set<HeatStructureTree> volumeOrNetworkSet = - type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network; - HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove); - - volumeOrNetworkSet.remove(toRemove); - } - - @Override - public int hashCode() { - int result1 = fileName != null ? fileName.hashCode() : 0; - result1 = 31 * result1 + (env != null ? env.hashCode() : 0); - result1 = 31 * result1 + (heat != null ? heat.hashCode() : 0); - result1 = 31 * result1 + (volume != null ? volume.hashCode() : 0); - result1 = 31 * result1 + (network != null ? network.hashCode() : 0); - result1 = 31 * result1 + (artifacts != null ? artifacts.hashCode() : 0); - result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0); - result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0); - - - return result1; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; + /** + * Find item in set by name boolean. + * + * @param searchSet the search set + * @param toFind the to find + * @return the boolean + */ + public boolean findItemInSetByName(Set<HeatStructureTree> searchSet, HeatStructureTree toFind) { + for (HeatStructureTree heatStructureTree : searchSet) { + if (heatStructureTree.getFileName().equals(toFind.getFileName())) { + return true; + } + } + return false; } - if (other == null || getClass() != other.getClass()) { - return false; + + /** + * Remove from volume or network. + * + * @param fileNameToRemove the file name to remove + * @param type the type + */ + public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) { + Set<HeatStructureTree> volumeOrNetworkSet = + type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network; + HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove); + + volumeOrNetworkSet.remove(toRemove); } - HeatStructureTree heatStructureTree = (HeatStructureTree) other; + @Override + public int hashCode() { + int result1 = fileName != null ? fileName.hashCode() : 0; + result1 = 31 * result1 + (env != null ? env.hashCode() : 0); + result1 = 31 * result1 + (heat != null ? heat.hashCode() : 0); + result1 = 31 * result1 + (volume != null ? volume.hashCode() : 0); + result1 = 31 * result1 + (network != null ? network.hashCode() : 0); + result1 = 31 * result1 + (artifacts != null ? artifacts.hashCode() : 0); + result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0); + result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0); - if (fileName != null ? !fileName.equals(heatStructureTree.fileName) - : heatStructureTree.fileName != null) { - return false; - } - if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) { - return false; - } - if (heat != null ? !heat.equals(heatStructureTree.heat) : heatStructureTree.heat != null) { - return false; - } - if (volume != null ? !volume.equals(heatStructureTree.volume) - : heatStructureTree.volume != null) { - return false; - } - if (network != null ? !network.equals(heatStructureTree.network) - : heatStructureTree.network != null) { - return false; - } - if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts) - : heatStructureTree.artifacts != null) { - return false; - } - if (nested != null ? !nested.equals(heatStructureTree.nested) - : heatStructureTree.nested != null) { - return false; - } - if (errors != null ? !errors.equals(heatStructureTree.errors) - : heatStructureTree.errors != null) { - return false; - } - return true; - } - - public List<ErrorMessage> getErrors() { - return errors; - } - - public void setErrors(List<ErrorMessage> errors) { - this.errors = errors; - } - - /** - * Add error to errors list. - * - * @param error the error - */ - public void addErrorToErrorsList(ErrorMessage error) { - if (this.errors == null || this.errors.isEmpty()) { - this.errors = new ArrayList<>(); - } - if (!this.errors.contains(error)) { - this.errors.add(error); + return result1; } - } - public Set<HeatStructureTree> getOther() { - return other; - } + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (other == null || getClass() != other.getClass()) { + return false; + } + + HeatStructureTree heatStructureTree = (HeatStructureTree) other; + + if (fileName != null ? !fileName.equals(heatStructureTree.fileName) + : heatStructureTree.fileName != null) { + return false; + } + if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) { + return false; + } + if (heat != null ? !heat.equals(heatStructureTree.heat) : heatStructureTree.heat != null) { + return false; + } + if (volume != null ? !volume.equals(heatStructureTree.volume) + : heatStructureTree.volume != null) { + return false; + } + if (network != null ? !network.equals(heatStructureTree.network) + : heatStructureTree.network != null) { + return false; + } + if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts) + : heatStructureTree.artifacts != null) { + return false; + } + if (nested != null ? !nested.equals(heatStructureTree.nested) + : heatStructureTree.nested != null) { + return false; + } + + return errors != null ? errors.equals(heatStructureTree.errors) : heatStructureTree.errors == null; + } - public void setOther(Set<HeatStructureTree> other) { - this.other = other; - } + /** + * Add error to errors list. + * + * @param error the error + */ + public void addErrorToErrorsList(ErrorMessage error) { + if (this.errors == null || this.errors.isEmpty()) { + this.errors = new ArrayList<>(); + } + if (!this.errors.contains(error)) { + this.errors.add(error); + } + } - @Override - public int compareTo(HeatStructureTree obj) { - return obj.getFileName().compareTo(this.getFileName()); - } + @Override + public int compareTo(HeatStructureTree obj) { + return obj.getFileName().compareTo(this.getFileName()); + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/ValidationStructureList.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/ValidationStructureList.java index f2acb2810d..27b87b9045 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/ValidationStructureList.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/structure/ValidationStructureList.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,21 +20,14 @@ package org.openecomp.sdc.heat.datatypes.structure; -public class ValidationStructureList { - private HeatStructureTree importStructure; - - public ValidationStructureList() { - } +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; - public ValidationStructureList(HeatStructureTree importStructure) { - this.importStructure = importStructure; - } - - public HeatStructureTree getImportStructure() { - return importStructure; - } +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ValidationStructureList { - public void setImportStructure(HeatStructureTree importStructure) { - this.importStructure = importStructure; - } + private HeatStructureTree importStructure; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatResourceUtil.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatResourceUtil.java index a44b0196d4..4563e686e5 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatResourceUtil.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatResourceUtil.java @@ -21,6 +21,8 @@ import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; public class HeatResourceUtil { @@ -31,9 +33,9 @@ public class HeatResourceUtil { private static final String PORT_RESOURCE_ID_REGEX_PREFIX = WORDS_REGEX + PORT_RESOURCE_ID_REGEX_SUFFIX; private static final String PORT_INT_RESOURCE_ID_REGEX_PREFIX = PORT_RESOURCE_ID_REGEX_PREFIX - + UNDERSCORE + "int_"+ WORDS_REGEX + UNDERSCORE; + + UNDERSCORE + "int_" + WORDS_REGEX + UNDERSCORE; private static final String SUB_INTERFACE_INT_RESOURCE_ID_REGEX_PREFIX = - PORT_RESOURCE_ID_REGEX_PREFIX + UNDERSCORE + "subint_"+ WORDS_REGEX + UNDERSCORE; + PORT_RESOURCE_ID_REGEX_PREFIX + UNDERSCORE + "subint_" + WORDS_REGEX + UNDERSCORE; public static Optional<String> evaluateNetworkRoleFromResourceId(String resourceId, String resourceType) { @@ -56,17 +58,23 @@ public class HeatResourceUtil { } private static Optional<PortType> getPortType(String resourceType) { - if (resourceType.equals( - HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) { + if (HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource() + .equals(resourceType)) { return Optional.of(PortType.VMI); - } else if (resourceType.equals( - HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) { + } else if (HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource().equals(resourceType)) { return Optional.of(PortType.PORT); } return Optional.empty(); } - public static Optional<String> extractNetworkRoleFromSubInterfaceId(String resourceId, + /** + * Extract network role from sub interface id optional. + * + * @param resourceId the resource id + * @param resourceType the resource type + * @return the optional + */ + public static Optional<String> extractNetworkRoleFromSubInterfaceId(String resourceId, String resourceType) { Optional<PortType> portType = getPortType(resourceType); if (portType.isPresent()) { @@ -79,19 +87,13 @@ public class HeatResourceUtil { return Optional.empty(); } + @AllArgsConstructor + @Getter private enum PortType { PORT("port"), VMI("vmi"); private String portTypeName; - - PortType(String portTypeName) { - this.portTypeName = portTypeName; - } - - public String getPortTypeName() { - return portTypeName; - } } private static String getNetworkRole(String portResourceId, String portIdRegex) { diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java index ef09841727..b73c7e8b8b 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatStructureUtil.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,6 +20,12 @@ package org.openecomp.sdc.heat.services; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + import org.apache.commons.collections4.CollectionUtils; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; @@ -27,12 +33,6 @@ import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - /** * Created by TALIO on 2/19/2017. */ @@ -42,77 +42,83 @@ public class HeatStructureUtil { // prevent instantiation } - /** - * Gets referenced values by function name. - * - * @param filename the filename - * @param functionName the function name - * @param propertyValue the property value - * @param globalContext the global context - * @return the referenced values by function name - */ - public static Set<String> getReferencedValuesByFunctionName(String filename, String functionName, - Object propertyValue, - GlobalValidationContext globalContext) { - Set<String> valuesNames = new HashSet<>(); - if (propertyValue instanceof Map) { - Map<String, Object> currPropertyMap = (Map<String, Object>) propertyValue; - if (currPropertyMap.containsKey(functionName)) { - Object getFunctionValue = currPropertyMap.get(functionName); - if (!(getFunctionValue instanceof String) && functionName.equals( - ResourceReferenceFunctions.GET_RESOURCE.getFunction())) { - globalContext.addMessage(filename, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(globalContext.getMessageCode(), - Messages.INVALID_GET_RESOURCE_SYNTAX.getErrorMessage(), - getFunctionValue == null ? "null" : getFunctionValue.toString())); - return valuesNames; - } - if (getFunctionValue instanceof String) { + /** + * Gets referenced values by function name. + * + * @param filename the filename + * @param functionName the function name + * @param propertyValue the property value + * @param globalContext the global context + * @return the referenced values by function name + */ + public static Set<String> getReferencedValuesByFunctionName(String filename, String functionName, + Object propertyValue, + GlobalValidationContext globalContext) { + Set<String> valuesNames = new HashSet<>(); + if (propertyValue instanceof Map) { + Map<String, Object> currPropertyMap = (Map<String, Object>) propertyValue; + if (currPropertyMap.containsKey(functionName)) { + Object getFunctionValue = currPropertyMap.get(functionName); + if (!(getFunctionValue instanceof String) && functionName.equals( + ResourceReferenceFunctions.GET_RESOURCE.getFunction())) { + globalContext.addMessage(filename, ErrorLevel.ERROR, ErrorMessagesFormatBuilder + .getErrorWithParameters(globalContext.getMessageCode(), + Messages.INVALID_GET_RESOURCE_SYNTAX.getErrorMessage(), + getFunctionValue == null ? "null" : getFunctionValue.toString())); + return valuesNames; + } + if (getFunctionValue instanceof String) { - if (functionName.equals(ResourceReferenceFunctions.GET_FILE.getFunction())) { - getFunctionValue = ((String) getFunctionValue).replace("file:///", ""); - } + if (functionName.equals(ResourceReferenceFunctions.GET_FILE.getFunction())) { + getFunctionValue = ((String) getFunctionValue).replace("file:///", ""); + } - valuesNames.add((String) getFunctionValue); - } else if (getFunctionValue instanceof List) { - if (CollectionUtils.isNotEmpty((List) getFunctionValue)) { - if (((List) getFunctionValue).get(0) instanceof String) { - valuesNames.add(((String) ((List) getFunctionValue).get(0)).replace("file:///", "")); + valuesNames.add((String) getFunctionValue); + } else if (getFunctionValue instanceof List) { + if (CollectionUtils.isNotEmpty((List) getFunctionValue)) { + if (((List) getFunctionValue).get(0) instanceof String) { + valuesNames.add(((String) ((List) getFunctionValue).get(0)).replace("file:///", "")); + } else { + valuesNames.addAll(getReferencedValuesByFunctionName(filename, functionName, + ((List) getFunctionValue).get(0), globalContext)); + } + + } + } else { + valuesNames.addAll( + getReferencedValuesByFunctionName(filename, functionName, getFunctionValue, + globalContext)); + } } else { - valuesNames.addAll(getReferencedValuesByFunctionName(filename, functionName, - ((List) getFunctionValue).get(0), globalContext)); + for (Map.Entry<String, Object> nestedPropertyMap : currPropertyMap.entrySet()) { + valuesNames.addAll(getReferencedValuesByFunctionName(filename, functionName, + nestedPropertyMap.getValue(), globalContext)); + } + } + } else if (propertyValue instanceof List) { + List propertyValueArray = (List) propertyValue; + for (Object propValue : propertyValueArray) { + valuesNames.addAll( + getReferencedValuesByFunctionName(filename, functionName, propValue, + globalContext)); } - - } - } else { - valuesNames.addAll( - getReferencedValuesByFunctionName(filename, functionName, getFunctionValue, - globalContext)); - } - } else { - for (Map.Entry<String, Object> nestedPropertyMap : currPropertyMap.entrySet()) { - valuesNames.addAll(getReferencedValuesByFunctionName(filename, functionName, - nestedPropertyMap.getValue(), globalContext)); } - } - } else if (propertyValue instanceof List) { - List propertyValueArray = (List) propertyValue; - for (Object propValue : propertyValueArray) { - valuesNames.addAll( - getReferencedValuesByFunctionName(filename, functionName, propValue, - globalContext)); - } - } - return valuesNames; - } + return valuesNames; + } - public static boolean isNestedResource(String resourceType) { - if(Objects.isNull(resourceType)){ - return false; + /** + * Is nested resource. + * + * @param resourceType the resource type + * @return the boolean + */ + public static boolean isNestedResource(String resourceType) { + if (Objects.isNull(resourceType)) { + return false; + } + return resourceType.endsWith(".yaml") || resourceType.endsWith(".yml"); } - return resourceType.endsWith(".yaml") || resourceType.endsWith(".yml"); - } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/manifest/ManifestUtil.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/manifest/ManifestUtil.java index ef057a9fc9..8c6daac71e 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/manifest/ManifestUtil.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/manifest/ManifestUtil.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,156 +20,151 @@ package org.openecomp.sdc.heat.services.manifest; - -import org.apache.commons.collections4.CollectionUtils; -import org.openecomp.sdc.heat.datatypes.manifest.FileData; -import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; - import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.sdc.heat.datatypes.manifest.FileData; +import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; + public class ManifestUtil { - /** - * Gets file and its env. - * - * @param manifestContent the manifest content - * @return the file and its env - */ - public static Map<String, FileData> getFileAndItsEnv(ManifestContent manifestContent) { - Map<String, FileData> fileEnvMap = new HashMap<>(); - scanFileEnvMap(null, manifestContent.getData(), fileEnvMap); - return fileEnvMap; - } - - - /** - * Scan file env map. - * - * @param fileData the file data - * @param fileDataList the file data list - * @param fileEnvMap the file env map - */ - public static void scanFileEnvMap(FileData fileData, List<FileData> fileDataList, - Map<String, FileData> fileEnvMap) { - - if (CollectionUtils.isEmpty(fileDataList)) { - return; + /** + * Gets file and its env. + * + * @param manifestContent the manifest content + * @return the file and its env + */ + public static Map<String, FileData> getFileAndItsEnv(ManifestContent manifestContent) { + Map<String, FileData> fileEnvMap = new HashMap<>(); + scanFileEnvMap(null, manifestContent.getData(), fileEnvMap); + return fileEnvMap; } - for (FileData childFileData : fileDataList) { - FileData.Type childType = childFileData.getType(); - if (fileData != null) { - if (childType != null && childType.equals(FileData.Type.HEAT_ENV)) { - fileEnvMap.put(fileData.getFile(), childFileData); + + /** + * Scan file env map. + * + * @param fileData the file data + * @param fileDataList the file data list + * @param fileEnvMap the file env map + */ + private static void scanFileEnvMap(FileData fileData, List<FileData> fileDataList, + Map<String, FileData> fileEnvMap) { + + if (CollectionUtils.isEmpty(fileDataList)) { + return; + } + + for (FileData childFileData : fileDataList) { + FileData.Type childType = childFileData.getType(); + if (fileData != null) { + if (childType != null && childType.equals(FileData.Type.HEAT_ENV)) { + fileEnvMap.put(fileData.getFile(), childFileData); + } + } + scanFileEnvMap(childFileData, childFileData.getData(), fileEnvMap); } - } - scanFileEnvMap(childFileData, childFileData.getData(), fileEnvMap); - } - } - - - /** - * Gets file type map. - * - * @param manifestContent the manifest content - * @return the file type map - */ - public static Map<String, FileData.Type> getFileTypeMap(ManifestContent manifestContent) { - Map<String, FileData.Type> fileTypeMap = new HashMap<>(); - scanFileTypeMap(null, manifestContent.getData(), fileTypeMap); - return fileTypeMap; - } - - private static FileData.Type scanFileTypeMap(FileData fileData, List<FileData> data, - Map<String, FileData.Type> fileTypeMap) { - if (fileData != null) { - fileTypeMap.put(fileData.getFile(), fileData.getType()); - } - if (data == null) { - return null; } - for (FileData chileFileData : data) { - FileData.Type type = scanFileTypeMap(chileFileData, chileFileData.getData(), fileTypeMap); - if (type != null) { - return type; - } + + /** + * Gets file type map. + * + * @param manifestContent the manifest content + * @return the file type map + */ + public static Map<String, FileData.Type> getFileTypeMap(ManifestContent manifestContent) { + Map<String, FileData.Type> fileTypeMap = new HashMap<>(); + scanFileTypeMap(null, manifestContent.getData(), fileTypeMap); + return fileTypeMap; } - return null; - } + private static FileData.Type scanFileTypeMap(FileData fileData, List<FileData> data, + Map<String, FileData.Type> fileTypeMap) { + if (fileData != null) { + fileTypeMap.put(fileData.getFile(), fileData.getType()); + } + if (data == null) { + return null; + } - /** - * Gets artifacts. - * - * @param manifestContent the manifest content - * @return the artifacts - */ - public static Set<String> getArtifacts(ManifestContent manifestContent) { - Set<String> artifacts = new HashSet<>(); - scanArtifacts(null, manifestContent.getData(), artifacts); + for (FileData chileFileData : data) { + FileData.Type type = scanFileTypeMap(chileFileData, chileFileData.getData(), fileTypeMap); + if (type != null) { + return type; + } + } + return null; + } - return artifacts; - } + /** + * Gets artifacts. + * + * @param manifestContent the manifest content + * @return the artifacts + */ + public static Set<String> getArtifacts(ManifestContent manifestContent) { + Set<String> artifacts = new HashSet<>(); + scanArtifacts(null, manifestContent.getData(), artifacts); - private static void scanArtifacts(FileData fileData, List<FileData> data, Set<String> artifacts) { - if (fileData != null && fileData.getType() != null) { - if (isArtifact(fileData)) { - artifacts.add(fileData.getFile()); - } + return artifacts; } - if (data == null) { - return; - } + private static void scanArtifacts(FileData fileData, List<FileData> data, Set<String> artifacts) { + if (fileData != null && fileData.getType() != null) { + if (isArtifact(fileData)) { + artifacts.add(fileData.getFile()); + } + } - for (FileData chileFileData : data) { - scanArtifacts(chileFileData, chileFileData.getData(), artifacts); - } - } - - private static boolean isArtifact(FileData fileData) { - if (FileData.Type.valueOf(fileData.getType().name()) != null - && !fileData.getType().equals(FileData.Type.HEAT) - && !fileData.getType().equals(FileData.Type.HEAT_ENV) - && !fileData.getType().equals(FileData.Type.HEAT_NET) - && !fileData.getType().equals(FileData.Type.HEAT_VOL)) { - return true; + if (data == null) { + return; + } + + for (FileData chileFileData : data) { + scanArtifacts(chileFileData, chileFileData.getData(), artifacts); + } } - return false; - } - - /** - * Gets base files. - * - * @param manifestContent the manifest content - * @return the base files - */ - public static Set<String> getBaseFiles(ManifestContent manifestContent) { - Set<String> baseFiles = new HashSet<>(); - scanBase(null, manifestContent.getData(), baseFiles); - return baseFiles; - } - - private static void scanBase(FileData fileData, List<FileData> data, Set<String> baseFiles) { - if (fileData != null && fileData.getBase() != null) { - if (fileData.getBase()) { - baseFiles.add(fileData.getFile()); - } + + private static boolean isArtifact(FileData fileData) { + return FileData.Type.valueOf(fileData.getType().name()) != null + && !fileData.getType().equals(FileData.Type.HEAT) + && !fileData.getType().equals(FileData.Type.HEAT_ENV) + && !fileData.getType().equals(FileData.Type.HEAT_NET) + && !fileData.getType().equals(FileData.Type.HEAT_VOL); } - if (data == null) { - return; + /** + * Gets base files. + * + * @param manifestContent the manifest content + * @return the base files + */ + public static Set<String> getBaseFiles(ManifestContent manifestContent) { + Set<String> baseFiles = new HashSet<>(); + scanBase(null, manifestContent.getData(), baseFiles); + return baseFiles; } - for (FileData chileFileData : data) { - scanBase(chileFileData, chileFileData.getData(), baseFiles); + private static void scanBase(FileData fileData, List<FileData> data, Set<String> baseFiles) { + if (fileData != null && fileData.getBase() != null) { + if (fileData.getBase()) { + baseFiles.add(fileData.getFile()); + } + } + + if (data == null) { + return; + } + + for (FileData chileFileData : data) { + scanBase(chileFileData, chileFileData.getData(), baseFiles); + } } - } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java index e8fe034176..936f02be67 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java @@ -12,10 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -*/ + */ package org.openecomp.sdc.heat.services.tree; +import java.io.InputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; @@ -31,257 +39,247 @@ import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import java.io.InputStream; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - public class HeatTreeManager { - private static final Logger LOGGER = LoggerFactory.getLogger(HeatTreeManager.class); - - - private FileContentHandler heatContentMap = new FileContentHandler(); - private byte[] manifest; - private HeatStructureTree tree = new HeatStructureTree(); - private Map<String, HeatStructureTree> fileTreeRef = new HashMap<>(); - private Map<String, Artifact> artifactRef = new HashMap<>(); - private Map<String, Artifact> candidateOrphanArtifacts = new HashMap<>(); - private Map<String, HeatStructureTree> nestedFiles = new HashMap<>(); - private Map<HeatStructureTree, HeatStructureTree> volumeFileToParent = new HashMap<>(); - private Map<HeatStructureTree, HeatStructureTree> networkFileToParent = new HashMap<>(); - private Set<String> manifestFiles = new HashSet<>(); - - /** - * Add file. - * - * @param fileName the file name - * @param content the content - */ - public void addFile(String fileName, InputStream content) { - if (fileName.equals(SdcCommon.MANIFEST_NAME)) { - manifest = FileUtils.toByteArray(content); - - } else { - heatContentMap.addFile(fileName, content); + private static final Logger LOGGER = LoggerFactory.getLogger(HeatTreeManager.class); + + + private FileContentHandler heatContentMap = new FileContentHandler(); + private byte[] manifest; + private HeatStructureTree tree = new HeatStructureTree(); + private Map<String, HeatStructureTree> fileTreeRef = new HashMap<>(); + private Map<String, Artifact> artifactRef = new HashMap<>(); + private Map<String, Artifact> candidateOrphanArtifacts = new HashMap<>(); + private Map<String, HeatStructureTree> nestedFiles = new HashMap<>(); + private Map<HeatStructureTree, HeatStructureTree> volumeFileToParent = new HashMap<>(); + private Map<HeatStructureTree, HeatStructureTree> networkFileToParent = new HashMap<>(); + private Set<String> manifestFiles = new HashSet<>(); + + /** + * Add file. + * + * @param fileName the file name + * @param content the content + */ + public void addFile(String fileName, InputStream content) { + if (fileName.equals(SdcCommon.MANIFEST_NAME)) { + manifest = FileUtils.toByteArray(content); + + } else { + heatContentMap.addFile(fileName, content); + } + } + + /** + * Create tree. + */ + public void createTree() { + if (manifest == null) { + LOGGER.error("Missing manifest file in the zip."); + return; + } + ManifestContent manifestData = + JsonUtil.json2Object(new String(manifest), ManifestContent.class); + scanTree(null, manifestData.getData()); + addNonNestedVolumeNetworkToTree(volumeFileToParent, nestedFiles.keySet(), true); + addNonNestedVolumeNetworkToTree(networkFileToParent, nestedFiles.keySet(), false); + handleOrphans(); + + tree = fileTreeRef.get(SdcCommon.PARENT); } - } - - /** - * Create tree. - */ - public void createTree() { - if (manifest == null) { - LOGGER.error("Missing manifest file in the zip."); - return; + + private void handleOrphans() { + tree = fileTreeRef.get(SdcCommon.PARENT); + candidateOrphanArtifacts.forEach((key, value) -> tree.addArtifactToArtifactList(value)); + nestedFiles + .values().stream().filter(tree.getHeat()::contains) + .forEach(tree.getHeat()::remove); + + heatContentMap.getFileList().stream().filter(this::isNotInManifestFiles) + .forEach(this::addTreeOther); } - ManifestContent manifestData = - JsonUtil.json2Object(new String(manifest), ManifestContent.class); - scanTree(null, manifestData.getData()); - addNonNestedVolumeNetworkToTree(volumeFileToParent, nestedFiles.keySet(), true); - addNonNestedVolumeNetworkToTree(networkFileToParent, nestedFiles.keySet(), false); - handleOrphans(); - - tree = fileTreeRef.get(SdcCommon.PARENT); - } - - private void handleOrphans() { - tree = fileTreeRef.get(SdcCommon.PARENT); - candidateOrphanArtifacts.entrySet().stream() - .forEach(entry -> tree.addArtifactToArtifactList(entry.getValue())); - nestedFiles - .values().stream().filter(tree.getHeat()::contains) - .forEach(tree.getHeat()::remove); - - heatContentMap.getFileList().stream().filter(this::isNotInManifestFiles) - .forEach(this::addTreeOther); - } - - private boolean isNotInManifestFiles(String fileName) { - return !manifestFiles.contains(fileName); - } - - private void addTreeOther(String fileName) { - if (tree.getOther() == null) { - tree.setOther(new HashSet<>()); + + private boolean isNotInManifestFiles(String fileName) { + return !manifestFiles.contains(fileName); } - HeatStructureTree other = new HeatStructureTree(fileName, false); - fileTreeRef.put(fileName, other); - tree.getOther().add(other); - } + private void addTreeOther(String fileName) { + if (tree.getOther() == null) { + tree.setOther(new HashSet<>()); + } + HeatStructureTree other = new HeatStructureTree(fileName, false); + fileTreeRef.put(fileName, other); + tree.getOther().add(other); + } - private void handleHeatContentReference(HeatStructureTree fileHeatStructureTree, - GlobalValidationContext globalContext) { - String fileName = fileHeatStructureTree.getFileName(); + private void handleHeatContentReference(HeatStructureTree fileHeatStructureTree, + GlobalValidationContext globalContext) { - try (InputStream fileContent = this.heatContentMap.getFileContent(fileName)) { - HeatOrchestrationTemplate hot = - new YamlUtil().yamlToObject(fileContent, HeatOrchestrationTemplate.class); + String fileName = fileHeatStructureTree.getFileName(); + try (InputStream fileContent = this.heatContentMap.getFileContent(fileName)) { + HeatOrchestrationTemplate hot = + new YamlUtil().yamlToObject(fileContent, HeatOrchestrationTemplate.class); - Set<String> nestedSet = HeatTreeManagerUtil.getNestedFiles(fileName, hot, globalContext); - addHeatNestedFiles(fileHeatStructureTree, nestedSet); + Set<String> nestedSet = HeatTreeManagerUtil.getNestedFiles(hot); + addHeatNestedFiles(fileHeatStructureTree, nestedSet); - Set<String> artifactSet = HeatTreeManagerUtil.getArtifactFiles(fileName, hot, globalContext); - addHeatArtifactFiles(fileHeatStructureTree, artifactSet); - } catch (Exception ignore) { - LOGGER.debug("Invalid YAML received. No need to process content reference - ignoring", ignore); - } - } - - - private void addHeatArtifactFiles(HeatStructureTree fileHeatStructureTree, - Set<String> artifactSet) { - Artifact artifact; - for (String artifactName : artifactSet) { - FileData.Type type = - candidateOrphanArtifacts.get(artifactName) != null ? candidateOrphanArtifacts - .get(artifactName).getType() : null; - artifact = new Artifact(artifactName, type); - artifactRef.put(artifactName, artifact); - candidateOrphanArtifacts.remove(artifactName); - fileHeatStructureTree.addArtifactToArtifactList(artifact); - } - } - - - private void addHeatNestedFiles(HeatStructureTree fileHeatStructureTree, Set<String> nestedSet) { - HeatStructureTree childHeatStructureTree; - for (String nestedName : nestedSet) { - childHeatStructureTree = fileTreeRef.get(nestedName); - if (childHeatStructureTree == null) { - childHeatStructureTree = new HeatStructureTree(); - childHeatStructureTree.setFileName(nestedName); - fileTreeRef.put(nestedName, childHeatStructureTree); - } - fileHeatStructureTree.addHeatStructureTreeToNestedHeatList(childHeatStructureTree); - nestedFiles.put(childHeatStructureTree.getFileName(), childHeatStructureTree); + Set<String> artifactSet = HeatTreeManagerUtil.getArtifactFiles(fileName, hot, globalContext); + addHeatArtifactFiles(fileHeatStructureTree, artifactSet); + } catch (Exception exp) { + LOGGER.debug("Invalid YAML received. No need to process content reference - ignoring", exp); + } } - } - - - /** - * Add errors. - * - * @param validationErrors the validation errors - */ - public void addErrors(Map<String, List<ErrorMessage>> validationErrors) { - - validationErrors.entrySet().stream().filter(entry ->{ - return fileTreeRef.get(entry.getKey()) != null; - }).forEach(entry -> entry.getValue().stream().forEach(fileTreeRef.get(entry.getKey())::addErrorToErrorsList)); - - validationErrors.entrySet().stream().filter(entry -> { - return artifactRef.get(entry.getKey()) != null; - }).forEach(entry -> artifactRef.get(entry.getKey()).setErrors(entry.getValue())); - - } - - /** - * Scan tree. - * - * @param parent the parent - * @param data the data - */ - public void scanTree(String parent, List<FileData> data) { - String fileName; - FileData.Type type; - HeatStructureTree parentHeatStructureTree; - HeatStructureTree fileHeatStructureTree; - HeatStructureTree childHeatStructureTree; - Artifact artifact; - if (parent == null) { - parentHeatStructureTree = new HeatStructureTree(); - fileTreeRef.put(SdcCommon.PARENT, parentHeatStructureTree); - } else { - parentHeatStructureTree = fileTreeRef.get(parent); + + + private void addHeatArtifactFiles(HeatStructureTree fileHeatStructureTree, + Set<String> artifactSet) { + Artifact artifact; + for (String artifactName : artifactSet) { + FileData.Type type = + candidateOrphanArtifacts.get(artifactName) != null ? candidateOrphanArtifacts + .get(artifactName).getType() : null; + artifact = new Artifact(artifactName, type); + artifactRef.put(artifactName, artifact); + candidateOrphanArtifacts.remove(artifactName); + fileHeatStructureTree.addArtifactToArtifactList(artifact); + } } - for (FileData fileData : data) { - fileName = fileData.getFile(); - manifestFiles.add(fileName); - type = fileData.getType(); - if (Objects.nonNull(type) && FileData.Type.HEAT.equals(type)) { - fileHeatStructureTree = fileTreeRef.get(fileName); - if (fileHeatStructureTree == null) { - fileHeatStructureTree = new HeatStructureTree(); - fileTreeRef.put(fileName, fileHeatStructureTree); + private void addHeatNestedFiles(HeatStructureTree fileHeatStructureTree, Set<String> nestedSet) { + HeatStructureTree childHeatStructureTree; + for (String nestedName : nestedSet) { + childHeatStructureTree = fileTreeRef.get(nestedName); + if (childHeatStructureTree == null) { + childHeatStructureTree = new HeatStructureTree(); + childHeatStructureTree.setFileName(nestedName); + fileTreeRef.put(nestedName, childHeatStructureTree); + } + fileHeatStructureTree.addHeatStructureTreeToNestedHeatList(childHeatStructureTree); + nestedFiles.put(childHeatStructureTree.getFileName(), childHeatStructureTree); } - fileHeatStructureTree.setFileName(fileName); - fileHeatStructureTree.setBase(fileData.getBase()); - fileHeatStructureTree.setType(type); - handleHeatContentReference(fileHeatStructureTree, null); - parentHeatStructureTree.addHeatToHeatList(fileHeatStructureTree); - if (fileData.getData() != null) { - scanTree(fileName, fileData.getData()); + } + + + /** + * Add errors. + * + * @param validationErrors the validation errors + */ + public void addErrors(Map<String, List<ErrorMessage>> validationErrors) { + + validationErrors.entrySet().stream() + .filter(entry -> fileTreeRef.get(entry.getKey()) != null) + .forEach(entry -> entry.getValue().forEach(fileTreeRef.get(entry.getKey())::addErrorToErrorsList)); + + validationErrors.entrySet().stream() + .filter(entry -> artifactRef.get(entry.getKey()) != null) + .forEach(entry -> artifactRef.get(entry.getKey()).setErrors(entry.getValue())); + + } + + /** + * Scan tree. + * + * @param parent the parent + * @param data the data + */ + public void scanTree(String parent, List<FileData> data) { + String fileName; + FileData.Type type; + HeatStructureTree parentHeatStructureTree; + HeatStructureTree fileHeatStructureTree; + HeatStructureTree childHeatStructureTree; + Artifact artifact; + if (parent == null) { + parentHeatStructureTree = new HeatStructureTree(); + fileTreeRef.put(SdcCommon.PARENT, parentHeatStructureTree); + } else { + parentHeatStructureTree = fileTreeRef.get(parent); } - } else { - childHeatStructureTree = new HeatStructureTree(); - childHeatStructureTree.setFileName(fileName); - childHeatStructureTree.setBase(fileData.getBase()); - childHeatStructureTree.setType(type); - fileTreeRef.put(childHeatStructureTree.getFileName(), childHeatStructureTree); - - if (type == null) { - parentHeatStructureTree.addOtherToOtherList(childHeatStructureTree); - } else if (FileData.Type.HEAT_NET.equals(type)) { - networkFileToParent.put(childHeatStructureTree, parentHeatStructureTree); - if (fileData.getData() != null) { - scanTree(fileName, fileData.getData()); - } - handleHeatContentReference(childHeatStructureTree, null); - - } else if (FileData.Type.HEAT_VOL.equals(type)) { - volumeFileToParent.put(childHeatStructureTree, parentHeatStructureTree); - if (fileData.getData() != null) { - scanTree(fileName, fileData.getData()); - } - handleHeatContentReference(childHeatStructureTree, null); - } else if (FileData.Type.HEAT_ENV.equals(type)) { - if (parentHeatStructureTree != null && parentHeatStructureTree.getFileName() != null) { - parentHeatStructureTree.setEnv(childHeatStructureTree); - } else { - if (parentHeatStructureTree.getOther() == null) { - parentHeatStructureTree.setOther(new HashSet<>()); + + for (FileData fileData : data) { + fileName = fileData.getFile(); + manifestFiles.add(fileName); + type = fileData.getType(); + + if (Objects.nonNull(type) && FileData.Type.HEAT.equals(type)) { + fileHeatStructureTree = fileTreeRef.get(fileName); + if (fileHeatStructureTree == null) { + fileHeatStructureTree = new HeatStructureTree(); + fileTreeRef.put(fileName, fileHeatStructureTree); + } + fileHeatStructureTree.setFileName(fileName); + fileHeatStructureTree.setBase(fileData.getBase()); + fileHeatStructureTree.setType(type); + handleHeatContentReference(fileHeatStructureTree, null); + parentHeatStructureTree.addHeatToHeatList(fileHeatStructureTree); + if (fileData.getData() != null) { + scanTree(fileName, fileData.getData()); + } + } else { + childHeatStructureTree = new HeatStructureTree(); + childHeatStructureTree.setFileName(fileName); + childHeatStructureTree.setBase(fileData.getBase()); + childHeatStructureTree.setType(type); + fileTreeRef.put(childHeatStructureTree.getFileName(), childHeatStructureTree); + + if (type == null) { + parentHeatStructureTree.addOtherToOtherList(childHeatStructureTree); + } else if (FileData.Type.HEAT_NET.equals(type)) { + networkFileToParent.put(childHeatStructureTree, parentHeatStructureTree); + if (fileData.getData() != null) { + scanTree(fileName, fileData.getData()); + } + handleHeatContentReference(childHeatStructureTree, null); + + } else if (FileData.Type.HEAT_VOL.equals(type)) { + volumeFileToParent.put(childHeatStructureTree, parentHeatStructureTree); + if (fileData.getData() != null) { + scanTree(fileName, fileData.getData()); + } + handleHeatContentReference(childHeatStructureTree, null); + } else if (FileData.Type.HEAT_ENV.equals(type)) { + if (parentHeatStructureTree != null && parentHeatStructureTree.getFileName() != null) { + parentHeatStructureTree.setEnv(childHeatStructureTree); + } else { + if (parentHeatStructureTree.getOther() == null) { + parentHeatStructureTree.setOther(new HashSet<>()); + } + parentHeatStructureTree.getOther().add(childHeatStructureTree); + } + } else { + artifact = new Artifact(fileName, type); + if (!artifactRef.keySet().contains(fileName)) { + artifactRef.put(fileName, artifact); + candidateOrphanArtifacts.put(fileName, artifact); + } + } } - parentHeatStructureTree.getOther().add(childHeatStructureTree); - } - } else { - artifact = new Artifact(fileName, type); - if (!artifactRef.keySet().contains(fileName)) { - artifactRef.put(fileName, artifact); - candidateOrphanArtifacts.put(fileName, artifact); - } } - } } - } - - - private void addNonNestedVolumeNetworkToTree( - Map<HeatStructureTree, HeatStructureTree> netVolToParent, Set<String> nestedFileNames, - boolean isVolume) { - for (Map.Entry<HeatStructureTree, HeatStructureTree> entry : netVolToParent.entrySet()) { - HeatStructureTree netOrVolNode = entry.getKey(); - HeatStructureTree parent = entry.getValue(); - if (!nestedFileNames.contains(netOrVolNode.getFileName())) { - if (isVolume) { - parent.addVolumeFileToVolumeList(netOrVolNode); - } else { - parent.addNetworkToNetworkList(netOrVolNode); + + + private void addNonNestedVolumeNetworkToTree( + Map<HeatStructureTree, HeatStructureTree> netVolToParent, Set<String> nestedFileNames, + boolean isVolume) { + for (Map.Entry<HeatStructureTree, HeatStructureTree> entry : netVolToParent.entrySet()) { + HeatStructureTree netOrVolNode = entry.getKey(); + HeatStructureTree parent = entry.getValue(); + if (!nestedFileNames.contains(netOrVolNode.getFileName())) { + if (isVolume) { + parent.addVolumeFileToVolumeList(netOrVolNode); + } else { + parent.addNetworkToNetworkList(netOrVolNode); + } + } } - } } - } - public HeatStructureTree getTree() { - return tree; - } + public HeatStructureTree getTree() { + return tree; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java index 7a2dfc971b..8c6d1354c4 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java @@ -12,11 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -*/ + */ package org.openecomp.sdc.heat.services.tree; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.utilities.file.FileContentHandler; @@ -30,196 +36,185 @@ import org.openecomp.sdc.heat.datatypes.model.PropertiesMapKeyTypes; import org.openecomp.sdc.heat.datatypes.model.Resource; import org.openecomp.sdc.heat.services.HeatStructureUtil; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - public class HeatTreeManagerUtil { - private static final String TYPE = "type"; - private HeatTreeManagerUtil() { - - } - - /** - * Init heat tree manager heat tree manager. - * - * @param fileContentMap the file content map - * @return the heat tree manager - */ - public static HeatTreeManager initHeatTreeManager(FileContentHandler fileContentMap) { - - HeatTreeManager heatTreeManager = new HeatTreeManager(); - fileContentMap.getFileList().stream().forEach( - fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContent(fileName))); - - return heatTreeManager; - } - - /** - * Gets nested files. - * - * @param filename the filename - * @param hot the hot - * @param globalContext the global context - * @return the nested files - */ - public static Set<String> getNestedFiles(String filename, HeatOrchestrationTemplate hot, - GlobalValidationContext globalContext) { - Set<String> nestedFileList = new HashSet<>(); - hot.getResources().values().stream().filter( - resource -> resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml")) - .forEach(resource -> nestedFileList.add(resource.getType())); - - Set<String> resourceDefNestedFiles = getResourceDefNestedFiles(hot); - nestedFileList.addAll(resourceDefNestedFiles); - return nestedFileList; - } - - /** - * Gets artifact files. - * - * @param filename the filename - * @param hot the hot - * @param globalContext the global context - * @return the artifact files - */ - public static Set<String> getArtifactFiles(String filename, HeatOrchestrationTemplate hot, - GlobalValidationContext globalContext) { - Set<String> artifactSet = new HashSet<>(); - Collection<Resource> resourcesValue = - hot.getResources() == null ? null : hot.getResources().values(); - if (CollectionUtils.isNotEmpty(resourcesValue)) { - for (Resource resource : resourcesValue) { - Collection<Object> properties = - resource.getProperties() == null ? null : resource.getProperties().values(); - - artifactSet.addAll(getArtifactsFromPropertiesAndAddInArtifactSet(properties, - filename, globalContext)); - } + private static final String TYPE = "type"; + + private HeatTreeManagerUtil() { + } - return artifactSet; - } - - private static Set<String> getArtifactsFromPropertiesAndAddInArtifactSet(Collection<Object> properties, - String filename, - GlobalValidationContext globalContext ){ - Set<String> artifactSet = new HashSet<>(); - if (CollectionUtils.isNotEmpty(properties)) { - - for (Object property : properties) { - Set<String> artifactNames = - HeatStructureUtil.getReferencedValuesByFunctionName(filename, "get_file", property, - globalContext); - artifactSet.addAll(artifactNames); - } + + /** + * Init heat tree manager heat tree manager. + * + * @param fileContentMap the file content map + * @return the heat tree manager + */ + public static HeatTreeManager initHeatTreeManager(FileContentHandler fileContentMap) { + + HeatTreeManager heatTreeManager = new HeatTreeManager(); + fileContentMap.getFileList().forEach( + fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContent(fileName))); + + return heatTreeManager; } - return artifactSet; - } - - private static Set<String> getResourceDefNestedFiles(HeatOrchestrationTemplate hot) { - Set<String> resourceDefNestedFiles = new HashSet<>(); - hot.getResources() - .entrySet().stream().filter(entry -> entry.getValue().getType() - .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) - .filter(entry -> - getResourceDef(entry.getValue()) != null - && HeatStructureUtil.isNestedResource( - getResourceDef(entry.getValue()) - .getType())) - .forEach(entry -> resourceDefNestedFiles.add( - getResourceDef( entry.getValue()).getType())); - return resourceDefNestedFiles; - } - - /** - * Gets resource def. - * - * @param resource the resource - * @return the resource def - */ - @SuppressWarnings("unchecked") - public static Resource getResourceDef( Resource resource) { - Resource resourceDef = null; - Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null - : (Map<String, Object>) resource.getProperties().get( - PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); - if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) { - Object resourceDefType = resourceDefValueMap.get(TYPE); - if ( resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) { - resourceDef = new Resource(); - resourceDef.setType((String) resourceDefType); - //noinspection unchecked - resourceDef.setProperties((Map<String, Object>) resourceDefValueMap.get("properties")); - } + /** + * Will verify the resource type and if type is of nested will return the nested file name + * + * @param hot Containing all translated data from heat file + * @return the nested files + */ + public static Set<String> getNestedFiles(HeatOrchestrationTemplate hot) { + Set<String> nestedFileList = new HashSet<>(); + hot.getResources().values().stream().filter( + resource -> resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml")) + .forEach(resource -> nestedFileList.add(resource.getType())); + + Set<String> resourceDefNestedFiles = getResourceDefNestedFiles(hot); + nestedFileList.addAll(resourceDefNestedFiles); + return nestedFileList; + } + + /** + * Verify if any artifact present in file whose detail is provided and return Artifact name + * + * @param filename name of file where artifact is too be looked for + * @param hot translated heat data + * @param globalContext the global context + * @return the artifact files name + */ + public static Set<String> getArtifactFiles(String filename, HeatOrchestrationTemplate hot, + GlobalValidationContext globalContext) { + Set<String> artifactSet = new HashSet<>(); + Collection<Resource> resourcesValue = + hot.getResources() == null ? null : hot.getResources().values(); + if (CollectionUtils.isNotEmpty(resourcesValue)) { + for (Resource resource : resourcesValue) { + Collection<Object> properties = + resource.getProperties() == null ? null : resource.getProperties().values(); + + artifactSet.addAll(getArtifactsFromPropertiesAndAddInArtifactSet(properties, + filename, globalContext)); + } + } + return artifactSet; + } + + private static Set<String> getArtifactsFromPropertiesAndAddInArtifactSet(Collection<Object> properties, + String filename, + GlobalValidationContext globalContext) { + Set<String> artifactSet = new HashSet<>(); + if (CollectionUtils.isNotEmpty(properties)) { + + for (Object property : properties) { + Set<String> artifactNames = + HeatStructureUtil.getReferencedValuesByFunctionName(filename, "get_file", property, + globalContext); + artifactSet.addAll(artifactNames); + } + } + + return artifactSet; + } + private static Set<String> getResourceDefNestedFiles(HeatOrchestrationTemplate hot) { + Set<String> resourceDefNestedFiles = new HashSet<>(); + hot.getResources() + .entrySet().stream().filter(entry -> entry.getValue().getType() + .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) + .filter(entry -> + getResourceDef(entry.getValue()) != null + && HeatStructureUtil.isNestedResource( + getResourceDef(entry.getValue()) + .getType())) + .forEach(entry -> resourceDefNestedFiles.add( + getResourceDef(entry.getValue()).getType())); + return resourceDefNestedFiles; } - return resourceDef; - } - - @SuppressWarnings("unchecked") - public static void checkResourceGroupTypeValid(String filename, String resourceName, - Resource resource, - GlobalValidationContext globalContext) { - Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null - : (Map<String, Object>) resource.getProperties().get( - PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); - if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) { - Object resourceDefType = resourceDefValueMap.get(TYPE); - if (Objects.nonNull(resourceDefType) && !(resourceDefType instanceof String) ) { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + + /** + * Gets resource def. + * + * @param resource the resource + * @return the resource def + */ + @SuppressWarnings("unchecked") + public static Resource getResourceDef(Resource resource) { + Resource resourceDef = null; + Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null + : (Map<String, Object>) resource.getProperties().get( + PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); + if (MapUtils.isNotEmpty(resourceDefValueMap)) { + Object resourceDefType = resourceDefValueMap.get(TYPE); + if (resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) { + resourceDef = new Resource(); + resourceDef.setType((String) resourceDefType); + //noinspection unchecked + resourceDef.setProperties((Map<String, Object>) resourceDefValueMap.get("properties")); + } + + } + return resourceDef; + } + + @SuppressWarnings("unchecked") + public static void checkResourceGroupTypeValid(String filename, String resourceName, + Resource resource, + GlobalValidationContext globalContext) { + Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null + : (Map<String, Object>) resource.getProperties().get( + PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); + if (MapUtils.isNotEmpty(resourceDefValueMap)) { + Object resourceDefType = resourceDefValueMap.get(TYPE); + if (Objects.nonNull(resourceDefType) && !(resourceDefType instanceof String)) { + globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder .getErrorWithParameters( globalContext.getMessageCode(), Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), resourceName, resourceDefType.toString())); - } + } + } } - } - - @SuppressWarnings("unchecked") - public static void checkResourceTypeValid(String filename, String resourceName, - Resource resource, - GlobalValidationContext globalContext) { - Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null - : (Map<String, Object>) resource.getProperties().get( - PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); - if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) { - Object resourceDefType = resourceDefValueMap.get(TYPE); - if (Objects.isNull(resourceDefType)) { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + + @SuppressWarnings("unchecked") + public static void checkResourceTypeValid(String filename, String resourceName, + Resource resource, + GlobalValidationContext globalContext) { + Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null + : (Map<String, Object>) resource.getProperties().get(PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); + if (MapUtils.isNotEmpty(resourceDefValueMap)) { + Object resourceDefType = resourceDefValueMap.get(TYPE); + if (Objects.isNull(resourceDefType)) { + globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder .getErrorWithParameters( globalContext.getMessageCode(), Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", resourceName)); - } + } + } } - } - - public static boolean isResourceGroupTypeNested(String resourceDefType) { - return HeatStructureUtil.isNestedResource(resourceDefType); - } - - public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName, - Resource resource, - GlobalValidationContext globalContext) { - //noinspection unchecked - Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null - : (Map<String, Object>) resource.getProperties().get( - PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); - if (resourceDefValueMap != null && MapUtils.isNotEmpty(resourceDefValueMap) ) { - Object resourceDefType = resourceDefValueMap.get(TYPE); - if (resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) { - - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + + public static boolean isResourceGroupTypeNested(String resourceDefType) { + return HeatStructureUtil.isNestedResource(resourceDefType); + } + + public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName, + Resource resource, + GlobalValidationContext globalContext) { + //noinspection unchecked + Map<String, Object> resourceDefValueMap = resource.getProperties() == null ? null + : (Map<String, Object>) resource.getProperties().get(PropertiesMapKeyTypes.RESOURCE_DEF.getKeyMap()); + if (MapUtils.isNotEmpty(resourceDefValueMap)) { + Object resourceDefType = resourceDefValueMap.get(TYPE); + if (resourceDefType instanceof String && isResourceGroupTypeNested((String) resourceDefType)) { + globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder .getErrorWithParameters( globalContext.getMessageCode(), Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), resourceName, resourceDefType.toString())); - return true; - } + return true; + } + } + return false; } - return false; - } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java index c711c72faf..944ab62f9f 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java @@ -1,9 +1,20 @@ -package org.openecomp.sdc.heat.services.tree; +/* + * Copyright © 2017-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +**/ -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.sdc.common.utils.SdcCommon; -import org.openecomp.sdc.datatypes.error.ErrorMessage; -import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +package org.openecomp.sdc.heat.services.tree; import java.io.File; import java.util.HashMap; @@ -12,56 +23,84 @@ import java.util.Map; import java.util.Objects; import java.util.regex.Pattern; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; + +/** + * The type Tosca tree manager. + */ public class ToscaTreeManager { - private FileContentHandler csarContentMap = new FileContentHandler(); - private HeatStructureTree tree = new HeatStructureTree(); - private Map<String, HeatStructureTree> fileTreeRef = new HashMap<>(); + private FileContentHandler csarContentMap = new FileContentHandler(); + private HeatStructureTree tree = new HeatStructureTree(); + private Map<String, HeatStructureTree> fileTreeRef = new HashMap<>(); - public void addFile(String fileName, byte[] content) { - if (!fileName.equals(SdcCommon.CSAR_MANIFEST_NAME)) { - csarContentMap.addFile(fileName, content); - } - } - public void createTree() { - for (Map.Entry<String, byte[]> fileEntry : csarContentMap.getFiles().entrySet()) { - String[] splitFilename = getFullFileNameAsArray(fileEntry.getKey()); - addFileToTree(splitFilename, 0, splitFilename[0], tree); + /** + * Add file. + * + * @param fileName the file name + * @param content the content + */ + public void addFile(String fileName, byte[] content) { + if (!fileName.equals(SdcCommon.CSAR_MANIFEST_NAME)) { + csarContentMap.addFile(fileName, content); + } } - } - private void addFileToTree(String[] splitFilename, int startIndex, String fullFileName, - HeatStructureTree parent) { - fileTreeRef.putIfAbsent(fullFileName, new HeatStructureTree()); - HeatStructureTree heatStructureTree = fileTreeRef.get(fullFileName); - heatStructureTree.setFileName(splitFilename[startIndex]); - if (startIndex < splitFilename.length - 1) { - addFileToTree(splitFilename, startIndex + 1, - getFullFileName(fullFileName, splitFilename[startIndex + 1]), heatStructureTree); + /** + * Create tree. + */ + public void createTree() { + for (Map.Entry<String, byte[]> fileEntry : csarContentMap.getFiles().entrySet()) { + String[] splitFilename = getFullFileNameAsArray(fileEntry.getKey()); + addFileToTree(splitFilename, 0, splitFilename[0], tree); + } } - parent.addHeatStructureTreeToNestedHeatList(heatStructureTree); - } - public void addErrors(Map<String, List<ErrorMessage>> validationErrors) { - validationErrors.entrySet().stream().filter(entry -> - Objects.nonNull(fileTreeRef.get(entry.getKey()))).forEach(entry -> entry.getValue() - .forEach(error -> fileTreeRef.get(entry.getKey()).addErrorToErrorsList(error))); - } + private void addFileToTree(String[] splitFilename, int startIndex, String fullFileName, + HeatStructureTree parent) { + fileTreeRef.putIfAbsent(fullFileName, new HeatStructureTree()); + HeatStructureTree heatStructureTree = fileTreeRef.get(fullFileName); + heatStructureTree.setFileName(splitFilename[startIndex]); + if (startIndex < splitFilename.length - 1) { + addFileToTree(splitFilename, startIndex + 1, + getFullFileName(fullFileName, splitFilename[startIndex + 1]), heatStructureTree); + } + parent.addHeatStructureTreeToNestedHeatList(heatStructureTree); + } - private String getFullFileName(String parentFullName, String fileName) { - return parentFullName + File.separator + fileName; - } + /** + * Add errors. + * + * @param validationErrors the validation errors + */ + public void addErrors(Map<String, List<ErrorMessage>> validationErrors) { + validationErrors.entrySet().stream().filter(entry -> + Objects.nonNull(fileTreeRef.get(entry.getKey()))).forEach(entry -> entry.getValue() + .forEach(error -> fileTreeRef.get(entry.getKey()).addErrorToErrorsList(error))); + } - private String[] getFullFileNameAsArray(String filename) { - if (filename.contains("/")) { - return filename.split("/"); + private String getFullFileName(String parentFullName, String fileName) { + return parentFullName + File.separator + fileName; } - return filename.split(Pattern.quote(File.separator)); - } + private String[] getFullFileNameAsArray(String filename) { + if (filename.contains("/")) { + return filename.split("/"); + } + + return filename.split(Pattern.quote(File.separator)); + } - public HeatStructureTree getTree() { - return tree; - } + /** + * Gets tree. + * + * @return the tree + */ + public HeatStructureTree getTree() { + return tree; + } } |