diff options
author | AviZi <avi.ziv@amdocs.com> | 2017-06-09 02:39:56 +0300 |
---|---|---|
committer | AviZi <avi.ziv@amdocs.com> | 2017-06-09 02:39:56 +0300 |
commit | 280f8015d06af1f41a3ef12e8300801c7a5e0d54 (patch) | |
tree | 9c1d3978c04cd28068f02073038c936bb49ca9e0 /openecomp-be/lib/openecomp-heat-lib | |
parent | fd3821dad11780d33c5373d74c957c442489945e (diff) |
[SDC-29] Amdocs OnBoard 1707 initial commit.
Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370
Signed-off-by: AviZi <avi.ziv@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib')
22 files changed, 555 insertions, 532 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/pom.xml b/openecomp-be/lib/openecomp-heat-lib/pom.xml index f04b243dbe..2d79b5ab22 100644 --- a/openecomp-be/lib/openecomp-heat-lib/pom.xml +++ b/openecomp-be/lib/openecomp-heat-lib/pom.xml @@ -2,26 +2,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <groupId>org.openecomp.core</groupId> + <name>openecomp-heat-lib</name> + <artifactId>openecomp-heat-lib</artifactId> <parent> <artifactId>openecomp-sdc-lib</artifactId> <groupId>org.openecomp.sdc</groupId> <version>1.1.0-SNAPSHOT</version> + <relativePath>..</relativePath> </parent> - <artifactId>openecomp-heat-lib</artifactId> - - <name>openecomp-heat-lib</name> - <dependencies> <dependency> - <groupId>org.yaml</groupId> - <artifactId>snakeyaml</artifactId> - <version>1.17</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.openecomp.sdc</groupId> + <groupId>org.openecomp.core</groupId> <artifactId>openecomp-utilities-lib</artifactId> <version>${project.version}</version> </dependency> @@ -31,19 +25,19 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.openecomp.sdc</groupId> + <groupId>org.openecomp.core</groupId> <artifactId>openecomp-common-lib</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> - <version>1.1.2</version> + <version>${logback.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>RELEASE</version> + <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> @@ -53,7 +47,4 @@ </dependency> </dependencies> - - - -</project>
\ No newline at end of file +</project> diff --git a/openecomp-be/lib/openecomp-heat-lib/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-heat-lib/pom.xml.versionsBackup new file mode 100644 index 0000000000..f434a8e24c --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/pom.xml.versionsBackup @@ -0,0 +1,50 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.openecomp.core</groupId> + <name>openecomp-heat-lib</name> + <dependencies> + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-utilities-lib</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-datatypes-lib</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-common-lib</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>RELEASE</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-validation-api</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + </dependencies> + + <artifactId>openecomp-heat-lib</artifactId> + + <parent> + <artifactId>openecomp-sdc-lib</artifactId> + <groupId>org.openecomp.sdc</groupId> + <version>1.0-SNAPSHOT</version> + </parent> + + +</project>
\ No newline at end of file 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 62364e7a11..d4b6a88ba9 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 @@ -33,7 +33,6 @@ public enum DefinedHeatParameterTypes { COMMA_DELIMITED_LIST("comma_delimited_list"), JSON("json"), BOOLEAN("boolean"); - // TODO : ASK SEGEV ABOUT STRING private static Map<String, DefinedHeatParameterTypes> stringToDefinedType = new HashMap<>(); @@ -80,11 +79,8 @@ public enum DefinedHeatParameterTypes { return (value instanceof Map) || (value instanceof List); case STRING: - //return value instanceof String; return true; - default: - // 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 728b714868..dd487603e1 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 @@ -20,6 +20,9 @@ package org.openecomp.sdc.heat.datatypes.manifest; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -75,6 +78,18 @@ public class FileData { this.data = data; } + /** + * Add file data. + * + * @param data the data + */ + public void addFileData(FileData data) { + if (CollectionUtils.isEmpty(this.data)) { + this.data = new ArrayList<>(); + } + this.data.add(data); + } + public enum Type { HEAT("HEAT"), @@ -103,5 +118,10 @@ public class FileData { return displayName; } + public static boolean isArtifact(Type fileType) + { + return !Arrays.asList(HEAT,HEAT_ENV, HEAT_VOL).contains(fileType); + } + } } 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 8aad825055..ebbb064ce9 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 @@ -26,7 +26,7 @@ import java.util.List; public class Constraint { private Object[] length; private Integer[] range; - private List<Object> valid_values; + private List<Object> validValues; private String pattern; public Constraint() { @@ -40,12 +40,12 @@ public class Constraint { this.range = new Integer[]{inRange[0], inRange[1]}; } - public List<Object> getValid_values() { - return valid_values; + public List<Object> getValidValues() { + return validValues; } - public void setValid_values(List<Object> validValues) { - this.valid_values = validValues; + public void setValidValues(List<Object> validValues) { + this.validValues = validValues; } /** @@ -54,10 +54,10 @@ public class Constraint { * @param validValue the valid value */ public void addValidValue(Object validValue) { - if (this.valid_values == null) { - this.valid_values = new ArrayList<>(); + if (this.validValues == null) { + this.validValues = new ArrayList<>(); } - valid_values.add(validValue); + validValues.add(validValue); } public Object[] getLength() { 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 new file mode 100644 index 0000000000..47eaefafec --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailResourceTypes.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.heat.datatypes.model; + +import java.util.HashMap; +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"); + + private static Map<String, ContrailResourceTypes> stringToContrailResourceTypeMap; + + static { + stringToContrailResourceTypeMap = new HashMap<>(); + + for (ContrailResourceTypes type : ContrailResourceTypes.values()) { + stringToContrailResourceTypeMap.put(type.contrailResourceType, type); + } + } + + private String 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); + + } + + public static boolean isResourceTypeContrail(String resourceType) { + return Objects.nonNull(findByContrailV2Resource(resourceType)); + } + + 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 new file mode 100644 index 0000000000..ff706093f8 --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/ContrailV2ResourceTypes.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.heat.datatypes.model; + +import java.util.HashMap; +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"); + + private static Map<String, ContrailV2ResourceTypes> stringToContrailV2ResourceTypeMap; + + static { + stringToContrailV2ResourceTypeMap = new HashMap<>(); + + for (ContrailV2ResourceTypes type : ContrailV2ResourceTypes.values()) { + stringToContrailV2ResourceTypeMap.put(type.contrailV2ResourceType, type); + } + } + + private String contrailV2ResourceType; + + ContrailV2ResourceTypes(String contrailV2ResourceType) { + this.contrailV2ResourceType = contrailV2ResourceType; + } + + public static ContrailV2ResourceTypes findByContrailV2Resource(String contrailV2Resource) { + return stringToContrailV2ResourceTypeMap.get(contrailV2Resource); + } + + public static boolean isResourceTypeContrailV2(String resourceType) { + return Objects.nonNull(findByContrailV2Resource(resourceType)); + } + + public String getContrailV2ResourceType() { + return contrailV2ResourceType; + } +} diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/GroupTypeValues.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/GroupTypeValues.java deleted file mode 100644 index 84259b1807..0000000000 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/model/GroupTypeValues.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.heat.datatypes.model; - -import java.util.ArrayList; -import java.util.List; - -public enum GroupTypeValues { - EXCLUSIVITY("exclusivity"), - AFFINITY("affinity"), - DIVERSITY("diversity"); - - private static List<String> groupTypeAsStrings; - - static { - groupTypeAsStrings = new ArrayList<>(); - for (GroupTypeValues attGroupTypeValue : GroupTypeValues.values()) { - groupTypeAsStrings.add(attGroupTypeValue.groupTypeValue); - } - } - - private String groupTypeValue; - - GroupTypeValues(String groupTypeValue) { - this.groupTypeValue = groupTypeValue; - } - - public static boolean isGroupTypeValid(String groupType) { - return groupTypeAsStrings.contains(groupType); - } -} 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 4170d35d7a..294bb9e47e 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 @@ -36,8 +36,8 @@ public class HeatOrchestrationTemplate { return heat_template_version; } - public void setHeat_template_version(String heatTemplateVersion) { - this.heat_template_version = heatTemplateVersion; + public void setHeat_template_version(String heat_template_version) { + this.heat_template_version = heat_template_version; } public String getDescription() { @@ -52,8 +52,8 @@ public class HeatOrchestrationTemplate { return parameter_groups; } - public void setParameter_groups(List<ParameterGroup> parameterGroups) { - this.parameter_groups = parameterGroups; + public void setParameter_groups(List<ParameterGroup> parameter_groups) { + this.parameter_groups = parameter_groups; } public Map<String, Parameter> getParameters() { 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 d4adfe7d32..b73fe385a6 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 @@ -26,93 +26,27 @@ import java.util.List; import java.util.Map; import java.util.Objects; -/** - * The enum Heat resources types. - */ public enum HeatResourcesTypes { - /** - * Nova server resource type heat resources types. - */ NOVA_SERVER_RESOURCE_TYPE("OS::Nova::Server"), - /** - * Nova server group resource type heat resources types. - */ NOVA_SERVER_GROUP_RESOURCE_TYPE("OS::Nova::ServerGroup"), - /** - * Neutron port resource type heat resources types. - */ NEUTRON_PORT_RESOURCE_TYPE("OS::Neutron::Port"), - /** - * Contrail network rule resource type heat resources types. - */ CONTRAIL_NETWORK_RULE_RESOURCE_TYPE("OS::Contrail::NetworkPolicy"), - /** - * Contrail network attach rule resource type heat resources types. - */ CONTRAIL_NETWORK_ATTACH_RULE_RESOURCE_TYPE("OS::Contrail::AttachPolicy"), - /** - * Contrail virtual network resource type heat resources types. - */ CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::Contrail::VirtualNetwork"), - /** - * Cinder volume resource type heat resources types. - */ CINDER_VOLUME_RESOURCE_TYPE("OS::Cinder::Volume"), - /** - * Cinder volume attachment resource type heat resources types. - */ CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE("OS::Cinder::VolumeAttachment"), - /** - * Neutron net resource type heat resources types. - */ NEUTRON_NET_RESOURCE_TYPE("OS::Neutron::Net"), - /** - * Neutron subnet resource type heat resources types. - */ NEUTRON_SUBNET_RESOURCE_TYPE("OS::Neutron::Subnet"), - /** - * Neutron security group resource type heat resources types. - */ NEUTRON_SECURITY_GROUP_RESOURCE_TYPE("OS::Neutron::SecurityGroup"), - /** - * Heat software config type heat resources types. - */ HEAT_SOFTWARE_CONFIG_TYPE("OS::Heat::SoftwareConfig"), - /** - * Heat cloud config type heat resources types. - */ HEAT_CLOUD_CONFIG_TYPE("OS::Heat::CloudConfig"), - /** - * Heat multipart mime type heat resources types. - */ HEAT_MULTIPART_MIME_TYPE("OS::Heat::MultipartMime"), - /** - * Heat contrail network ipam type heat resources types. - */ HEAT_CONTRAIL_NETWORK_IPAM_TYPE("OS::Contrail::NetworkIpam"), - /** - * Contrail v 2 virtual network resource type heat resources types. - */ CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::ContrailV2::VirtualNetwork"), - /** - * Contrail v 2 virtual machine interface resource type heat resources types. - */ CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE("OS::ContrailV2::VirtualMachineInterface"), - /** - * Contrail service template heat resources types. - */ CONTRAIL_SERVICE_TEMPLATE("OS::Contrail::ServiceTemplate"), - /** - * Contrail service instance heat resources types. - */ CONTRAIL_SERVICE_INSTANCE("OS::Contrail::ServiceInstance"), - /** - * Contrail v 2 network rule resource type heat resources types. - */ CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE("OS::ContrailV2::NetworkPolicy"), - /** - * Resource group resource type heat resources types. - */ RESOURCE_GROUP_RESOURCE_TYPE("OS::Heat::ResourceGroup"); private static Map<String, HeatResourcesTypes> stringToHeatResourceTypeMap; @@ -132,22 +66,10 @@ public enum HeatResourcesTypes { this.heatResource = heatResource; } - /** - * Find by heat resource heat resources types. - * - * @param heatResource the heat resource - * @return the heat resources types - */ public static HeatResourcesTypes findByHeatResource(String heatResource) { return stringToHeatResourceTypeMap.get(heatResource); } - /** - * Is resource type valid boolean. - * - * @param resourceType the resource type - * @return the boolean - */ public static boolean isResourceTypeValid(String resourceType) { return Objects.nonNull(findByHeatResource(resourceType)); } @@ -159,6 +81,7 @@ public enum HeatResourcesTypes { * @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()) @@ -184,21 +107,11 @@ public enum HeatResourcesTypes { return result; } - /** - * Gets heat resource. - * - * @return the heat resource - */ public String getHeatResource() { return heatResource; } - /** - * Sets heat resource. - * - * @param heatResource the heat resource - */ public void setHeatResource(String heatResource) { this.heatResource = heatResource; } 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 63681cc80c..d419738942 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 @@ -60,8 +60,8 @@ public class Parameter { return _default; } - public void set_default(Object defaultValue) { - this._default = defaultValue; + public void set_default(Object _default) { + this._default = _default; } public boolean isHidden() { 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 f4c3cd91cb..2c70105da9 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 @@ -58,24 +58,24 @@ public class Resource { return depends_on; } - public void setDepends_on(Object dependsOn) { - this.depends_on = dependsOn; + public void setDepends_on(Object depends_on) { + this.depends_on = depends_on; } public Object getUpdate_policy() { return update_policy; } - public void setUpdate_policy(Object updatePolicy) { - this.update_policy = updatePolicy; + public void setUpdate_policy(Object update_policy) { + this.update_policy = update_policy; } public Object getDeletion_policy() { return deletion_policy; } - public void setDeletion_policy(Object deletionPolicy) { - this.deletion_policy = deletionPolicy; + public void setDeletion_policy(Object deletion_policy) { + this.deletion_policy = deletion_policy; } @Override 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 b5c263f545..95ae4e59c7 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 @@ -73,6 +73,11 @@ public class Artifact implements Comparable<Artifact> { this.errors.add(error); } + @Override + public int hashCode() { + int result = fileName.hashCode(); + return result; + } @Override public boolean equals(Object obj) { @@ -93,12 +98,6 @@ public class Artifact implements Comparable<Artifact> { } @Override - public int hashCode() { - int result = fileName.hashCode(); - return result; - } - - @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 c86425fd43..5313d4d370 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 @@ -30,9 +30,6 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; -/** - * The type Heat structure tree. - */ public class HeatStructureTree implements Comparable<HeatStructureTree> { private String fileName; @@ -40,27 +37,18 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { private Boolean isBase; private HeatStructureTree env; private List<ErrorMessage> errors; - private Set<HeatStructureTree> HEAT; + private Set<HeatStructureTree> heat; private Set<HeatStructureTree> volume; private Set<HeatStructureTree> network; private Set<HeatStructureTree> nested; private Set<HeatStructureTree> other; private Set<Artifact> artifacts; - /** - * Instantiates a new Heat structure tree. - */ public HeatStructureTree() { } ; - /** - * Instantiates a new Heat structure tree. - * - * @param fileName the file name - * @param isBase the is base - */ public HeatStructureTree(String fileName, boolean isBase) { setBase(isBase); setFileName(fileName); @@ -84,102 +72,47 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { return null; } - /** - * Sets type. - * - * @param type the type - */ public void setType(FileData.Type type) { this.type = type; } - /** - * Gets base. - * - * @return the base - */ public Boolean getBase() { return isBase; } - /** - * Sets base. - * - * @param base the base - */ public void setBase(Boolean base) { isBase = base; } - /** - * Gets file name. - * - * @return the file name - */ public String getFileName() { return fileName; } - /** - * Sets file name. - * - * @param file the file - */ public void setFileName(String file) { this.fileName = file; } - /** - * Gets heat. - * - * @return the heat - */ - @JsonProperty(value = "HEAT") - public Set<HeatStructureTree> getHEAT() { - return HEAT; + @JsonProperty(value = "heat") + public Set<HeatStructureTree> getHeat() { + return heat; } - /** - * Sets heat. - * - * @param heat the heat - */ - public void setHEAT(Set<HeatStructureTree> heat) { - this.HEAT = heat; + public void setHeat(Set<HeatStructureTree> heat) { + this.heat = heat; } - /** - * Gets nested. - * - * @return the nested - */ public Set<HeatStructureTree> getNested() { return nested; } - /** - * Sets nested. - * - * @param nested the nested - */ public void setNested(Set<HeatStructureTree> nested) { this.nested = nested; } - /** - * Gets artifacts. - * - * @return the artifacts - */ public Set<Artifact> getArtifacts() { return artifacts; } - /** - * Sets artifacts. - * - * @param artifacts the artifacts - */ public void setArtifacts(Set<Artifact> artifacts) { this.artifacts = artifacts; } @@ -210,56 +143,26 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { this.artifacts.add(artifact); } - /** - * Gets env. - * - * @return the env - */ public HeatStructureTree getEnv() { return env; } - /** - * Sets env. - * - * @param env the env - */ public void setEnv(HeatStructureTree env) { this.env = env; } - /** - * Gets volume. - * - * @return the volume - */ public Set<HeatStructureTree> getVolume() { return volume; } - /** - * Sets volume. - * - * @param volume the volume - */ public void setVolume(Set<HeatStructureTree> volume) { this.volume = volume; } - /** - * Gets network. - * - * @return the network - */ public Set<HeatStructureTree> getNetwork() { return network; } - /** - * Sets network. - * - * @param network the network - */ public void setNetwork(Set<HeatStructureTree> network) { this.network = network; } @@ -297,12 +200,12 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { * * @param heat the heat */ - public void addHeatToHEATList(HeatStructureTree heat) { - if (this.HEAT == null) { - this.HEAT = new TreeSet<>(); + public void addHeatToHeatList(HeatStructureTree heat) { + if (this.heat == null) { + this.heat = new TreeSet<>(); } - this.HEAT.add(heat); + this.heat.add(heat); } /** @@ -351,6 +254,21 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { } @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; @@ -368,7 +286,7 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) { return false; } - if (HEAT != null ? !HEAT.equals(heatStructureTree.HEAT) : heatStructureTree.HEAT != null) { + if (heat != null ? !heat.equals(heatStructureTree.heat) : heatStructureTree.heat != null) { return false; } if (volume != null ? !volume.equals(heatStructureTree.volume) @@ -395,35 +313,10 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { return true; } - @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; - } - - /** - * Gets errors. - * - * @return the errors - */ public List<ErrorMessage> getErrors() { return errors; } - /** - * Sets errors. - * - * @param errors the errors - */ public void setErrors(List<ErrorMessage> errors) { this.errors = errors; } @@ -442,26 +335,16 @@ public class HeatStructureTree implements Comparable<HeatStructureTree> { } } - /** - * Gets other. - * - * @return the other - */ public Set<HeatStructureTree> getOther() { return other; } - /** - * Sets other. - * - * @param other the other - */ public void setOther(Set<HeatStructureTree> other) { this.other = other; } @Override - public int compareTo(HeatStructureTree heatStructureTree) { - return heatStructureTree.getFileName().compareTo(this.getFileName()); + 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/services/ErrorCodes.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/ErrorCodes.java index c48d732e63..e239d225e8 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/ErrorCodes.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/ErrorCodes.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.heat.services; + public class ErrorCodes { public static final String INVALID_BOOLEAN = "INVALID_BOOLEAN"; } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatConstants.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatConstants.java index e2afe89a06..91f36a17d1 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatConstants.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/HeatConstants.java @@ -21,7 +21,7 @@ package org.openecomp.sdc.heat.services; public class HeatConstants { - public static final String GET_ATT_FROM_RESOURCE_GROUP_PREFIX = "resource."; + public static final String GET_ATTR_FROM_RESOURCE_GROUP_PREFIX = "resource."; public static final String RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE = "%index%"; public static final String INDEX_PROPERTY_NAME = "index_var"; @@ -30,5 +30,30 @@ public class HeatConstants { public static final String VOLUME_ID_PROPERTY_NAME = "volume_id"; public static final String RESOURCE_DEF_PROPERTY_NAME = "resource_def"; public static final String SCALE_OUT_PROPERTY_NAME = "scale_out"; + public static final String INTERFACE_LIST_PROPERTY_NAME = "interface_list"; + public static final String VIRTUAL_NETWORK_PROPERTY_NAME = "virtual_network"; + public static final String VMI_SUB_INTERFACE_VLAN_TAG_PROPERTY_NAME + = "virtual_machine_interface_properties_sub_interface_vlan_tag"; + public static final String VMI_PROPERTIES_PROPERTY_NAME = "virtual_machine_interface_properties"; + public static final String VMI_REFS_PROPERTY_NAME = "virtual_machine_interface_refs"; + public static final String VMI_MAC_ADDRESSES = "virtual_machine_interface_mac_addresses"; + public static final String VMI_MAC_ADDRESSES_MAC_ADDRESSES = + "virtual_machine_interface_mac_addresses#virtual_machine_interface_mac_addresses_mac_address"; + public static final String VIRTUAL_NETWORK_REFS_PROPERTY_NAME = "virtual_network_refs"; + public static final String READ_ONLY_PROPERTY_NAME = "read_only"; + public static final String VOL_ID_PROPERTY_NAME = "volume_id"; + public static final String CONFIG_DRIVE_PROPERTY_NAME = "config_drive"; + public static final String AVAILABILITY_ZONE_ENABLE_PROPERTY_NAME = "availability_zone_enable"; + public static final String ORDERED_INTERFACES_PROPERTY_NAME = "ordered_interfaces"; + public static final String SHARED_IP_LIST_PROPERTY_NAME = "shared_ip_list"; + public static final String STATIC_ROUTES_LIST_PROPERTY_NAME = "static_routes_list"; + public static final String SERVICE_INTERFCAE_TYPE_LIST_PROPERTY_NAME = + "service_interface_type_list"; + public static final String PORT_SECURITY_ENABLED_PROPERTY_NAME = "port_security_enabled"; + public static final String SHARED_PROPERTY_NAME = "shared"; + public static final String ADMIN_STATE_UP_PROPERTY_NAME = "admin_state_up"; + + public static final String CONTRAIL_RESOURCE_PREFIX = "OS::Contrail::"; + public static final String CONTRAIL_V2_RESOURCE_PREFIX = "OS::ContrailV2::"; } 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 a216b224af..cd217a50ef 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 @@ -21,18 +21,13 @@ package org.openecomp.sdc.heat.services; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; -import org.openecomp.core.validation.errors.Messages; import org.openecomp.core.validation.types.GlobalValidationContext; +import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorLevel; -import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; -import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; -import org.openecomp.sdc.heat.datatypes.model.PropertiesMapKeyTypes; -import org.openecomp.sdc.heat.datatypes.model.Resource; import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; -import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -40,151 +35,11 @@ import java.util.Objects; import java.util.Set; /** - * The type Heat structure util. + * Created by TALIO on 2/19/2017. */ public class HeatStructureUtil { /** - * 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<>(); - Set<String> resourceDefNestedFiles; - hot.getResources().values().stream().filter( - resource -> (resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml"))) - .forEach(resource -> nestedFileList.add(resource.getType())); - - resourceDefNestedFiles = getResourceDefNestedFiles(filename, hot, globalContext); - nestedFileList.addAll(resourceDefNestedFiles); - - return nestedFileList; - } - - - private static Set<String> getResourceDefNestedFiles(String filename, - HeatOrchestrationTemplate hot, - GlobalValidationContext globalContext) { - Set<String> resourceDefNestedFiles = new HashSet<>(); - hot.getResources() - .entrySet() - .stream() - .filter(entry -> entry.getValue().getType() - .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) - .filter(entry -> - getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext) != null - && isNestedResource( - getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext) - .getType())) - .forEach(entry -> resourceDefNestedFiles.add( - getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext).getType())); - - return resourceDefNestedFiles; - } - - - /** - * Gets resource def. - * - * @param filename the filename - * @param resourceName the resource name - * @param resource the resource - * @param globalContext the global context - * @return the resource def - */ - @SuppressWarnings("unchecked") - public static Resource getResourceDef(String filename, String resourceName, Resource resource, - GlobalValidationContext globalContext) { - 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 (Objects.nonNull(resourceDefType)) { - if (resourceDefType instanceof String) { - boolean isNested = - checkIfResourceGroupTypeIsNested(filename, resourceName, (String) resourceDefType, - globalContext); - if (isNested) { - resourceDef = new Resource(); - resourceDef.setType((String) resourceDefType); - //noinspection unchecked - resourceDef.setProperties((Map<String, Object>) resourceDefValueMap.get("properties")); - } - } else { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), - resourceName, resourceDefType.toString())); - } - } else { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", - resourceName)); - } - - } - return resourceDef; - } - - - /** - * Check if resource group type is nested boolean. - * - * @param filename the filename - * @param resourceName the resource name - * @param resourceDefType the resource def type - * @param globalContext the global context - * @return the boolean - */ - public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName, - String resourceDefType, - GlobalValidationContext globalContext) { - if (!HeatStructureUtil.isNestedResource(resourceDefType)) { - globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), - resourceName, resourceDefType)); - return false; - } - return true; - } - - /** - * 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(); - if (CollectionUtils.isNotEmpty(properties)) { - for (Object property : properties) { - Set<String> artifactNames = - getReferencedValuesByFunctionName(filename, "get_file", property, globalContext); - artifactSet.addAll(artifactNames); - } - } - } - } - return artifactSet; - } - - /** * Gets referenced values by function name. * * @param filename the filename @@ -194,18 +49,19 @@ public class HeatStructureUtil { * @return the referenced values by function name */ public static Set<String> getReferencedValuesByFunctionName(String filename, String functionName, - Object propertyValue, - GlobalValidationContext globalContext) { + 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())) { + if (!(getFunctionValue instanceof String) && functionName.equals( + ResourceReferenceFunctions.GET_RESOURCE.getFunction())) { globalContext.addMessage(filename, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_GET_RESOURCE_SYNTAX.getErrorMessage(), - getFunctionValue == null ? "null" : getFunctionValue.toString())); + .getErrorWithParameters(Messages.INVALID_GET_RESOURCE_SYNTAX.getErrorMessage(), + getFunctionValue == null ? "null" : getFunctionValue.toString()), + LoggerTragetServiceName.VALIDATE_GET_RESOURCE, "Invalid get_resource syntax"); return valuesNames; } if (getFunctionValue instanceof String) { @@ -238,9 +94,9 @@ public class HeatStructureUtil { } } else if (propertyValue instanceof List) { List propertyValueArray = (List) propertyValue; - for (Object propertyValueArrayInstance : propertyValueArray) { + for (Object propValue : propertyValueArray) { valuesNames.addAll( - getReferencedValuesByFunctionName(filename, functionName, propertyValueArrayInstance, + getReferencedValuesByFunctionName(filename, functionName, propValue, globalContext)); } } @@ -249,13 +105,11 @@ public class HeatStructureUtil { } - /** - * Is nested resource boolean. - * - * @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"); } + } 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 09378cebf4..af2a71d42c 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 @@ -20,6 +20,7 @@ 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; @@ -31,9 +32,6 @@ import java.util.Map; import java.util.Set; -/** - * The type Manifest util. - */ public class ManifestUtil { @@ -59,6 +57,7 @@ public class ManifestUtil { */ public static void scanFileEnvMap(FileData fileData, List<FileData> fileDataList, Map<String, FileData> fileEnvMap) { + if (CollectionUtils.isEmpty(fileDataList)) { return; } @@ -165,6 +164,7 @@ public class ManifestUtil { baseFiles.add(fileData.getFile()); } } + if (data == null) { return; } 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 71c532dbd3..02278acf3f 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 @@ -25,31 +25,28 @@ import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.core.utilities.yaml.YamlUtil; import org.openecomp.core.validation.types.GlobalValidationContext; -import org.openecomp.sdc.common.utils.AsdcCommon; +import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.heat.datatypes.manifest.FileData; import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; import org.openecomp.sdc.heat.datatypes.structure.Artifact; import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; -import org.openecomp.sdc.heat.services.HeatStructureUtil; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +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; -/** - * The type Heat tree manager. - */ + public class HeatTreeManager { - private static Logger logger = LoggerFactory.getLogger(HeatTreeManager.class); + private static Logger logger = (Logger) LoggerFactory.getLogger(HeatTreeManager.class); private FileContentHandler heatContentMap = new FileContentHandler(); @@ -70,7 +67,7 @@ public class HeatTreeManager { * @param content the content */ public void addFile(String fileName, InputStream content) { - if (fileName.equals(AsdcCommon.MANIFEST_NAME)) { + if (fileName.equals(SdcCommon.MANIFEST_NAME)) { manifest = FileUtils.toByteArray(content); } else { @@ -93,18 +90,16 @@ public class HeatTreeManager { addNonNestedVolumeNetworkToTree(networkFileToParent, nestedFiles.keySet(), false); handleOrphans(); - tree = fileTreeRef.get(AsdcCommon.PARENT); + tree = fileTreeRef.get(SdcCommon.PARENT); } private void handleOrphans() { - tree = fileTreeRef.get(AsdcCommon.PARENT); + tree = fileTreeRef.get(SdcCommon.PARENT); candidateOrphanArtifacts.entrySet().stream() .forEach(entry -> tree.addArtifactToArtifactList(entry.getValue())); nestedFiles - .values() - .stream() - .filter(heatStructureTree -> tree.getHEAT().contains(heatStructureTree)) - .forEach(heatStructureTree -> tree.getHEAT().remove(heatStructureTree)); + .values().stream().filter(heatStructureTree -> tree.getHeat().contains(heatStructureTree)) + .forEach(heatStructureTree -> tree.getHeat().remove(heatStructureTree)); heatContentMap.getFileList().stream().filter(fileName -> !manifestFiles.contains(fileName)) .forEach(fileName -> addTreeOther(fileName)); @@ -132,14 +127,15 @@ public class HeatTreeManager { HeatOrchestrationTemplate hot = new YamlUtil().yamlToObject(fileContent, HeatOrchestrationTemplate.class); - Set<String> nestedSet = HeatStructureUtil.getNestedFiles(filename, hot, globalContext); + Set<String> nestedSet = HeatTreeManagerUtil.getNestedFiles(filename, hot, globalContext); addHeatNestedFiles(fileHeatStructureTree, nestedSet); - Set<String> artifactSet = HeatStructureUtil.getArtifactFiles(filename, hot, globalContext); + Set<String> artifactSet = HeatTreeManagerUtil.getArtifactFiles(filename, hot, globalContext); addHeatArtifactFiles(fileHeatStructureTree, artifactSet); } catch (Exception ignore) { /* invalid yaml no need to process reference */ } } + private void addHeatArtifactFiles(HeatStructureTree fileHeatStructureTree, Set<String> artifactSet) { Artifact artifact; @@ -203,7 +199,7 @@ public class HeatTreeManager { Artifact artifact; if (parent == null) { parentHeatStructureTree = new HeatStructureTree(); - fileTreeRef.put(AsdcCommon.PARENT, parentHeatStructureTree); + fileTreeRef.put(SdcCommon.PARENT, parentHeatStructureTree); } else { parentHeatStructureTree = fileTreeRef.get(parent); } @@ -213,7 +209,7 @@ public class HeatTreeManager { manifestFiles.add(fileName); type = fileData.getType(); - if (FileData.Type.HEAT.equals(type)) { + if (Objects.nonNull(type) && FileData.Type.HEAT.equals(type)) { fileHeatStructureTree = fileTreeRef.get(fileName); if (fileHeatStructureTree == null) { fileHeatStructureTree = new HeatStructureTree(); @@ -223,7 +219,7 @@ public class HeatTreeManager { fileHeatStructureTree.setBase(fileData.getBase()); fileHeatStructureTree.setType(type); handleHeatContentReference(null, fileHeatStructureTree, null); - parentHeatStructureTree.addHeatToHEATList(fileHeatStructureTree); + parentHeatStructureTree.addHeatToHeatList(fileHeatStructureTree); if (fileData.getData() != null) { scanTree(fileName, fileData.getData()); } @@ -237,14 +233,14 @@ public class HeatTreeManager { if (type == null) { parentHeatStructureTree.addOtherToOtherList(childHeatStructureTree); } else if (FileData.Type.HEAT_NET.equals(type)) { - // parentHeatStructureTree.addNetworkToNetworkList(childHeatStructureTree); + //parentHeatStructureTree.addNetworkToNetworkList(childHeatStructureTree); networkFileToParent.put(childHeatStructureTree, parentHeatStructureTree); if (fileData.getData() != null) { scanTree(fileName, fileData.getData()); } } else if (FileData.Type.HEAT_VOL.equals(type)) { - // parentHeatStructureTree.addVolumeFileToVolumeList(childHeatStructureTree); + //parentHeatStructureTree.addVolumeFileToVolumeList(childHeatStructureTree); volumeFileToParent.put(childHeatStructureTree, parentHeatStructureTree); if (fileData.getData() != null) { scanTree(fileName, fileData.getData()); @@ -287,11 +283,6 @@ public class HeatTreeManager { } - /** - * Gets tree. - * - * @return the 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 dac7cdbbcb..b8df50b87c 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 @@ -20,12 +20,31 @@ package org.openecomp.sdc.heat.services.tree; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; +import org.openecomp.core.validation.types.GlobalValidationContext; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; +import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; +import org.openecomp.sdc.heat.datatypes.model.PropertiesMapKeyTypes; +import org.openecomp.sdc.heat.datatypes.model.Resource; +import org.openecomp.sdc.heat.services.HeatStructureUtil; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; -/** - * The type Heat tree manager util. - */ public class HeatTreeManagerUtil { + + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + /** * Init heat tree manager heat tree manager. * @@ -40,4 +59,165 @@ public class HeatTreeManagerUtil { 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) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + Set<String> nestedFileList = new HashSet<>(); + Set<String> resourceDefNestedFiles; + hot.getResources().values().stream().filter( + resource -> (resource.getType().endsWith(".yaml") || resource.getType().endsWith(".yml"))) + .forEach(resource -> nestedFileList.add(resource.getType())); + + resourceDefNestedFiles = getResourceDefNestedFiles(filename, hot, globalContext); + nestedFileList.addAll(resourceDefNestedFiles); + + mdcDataDebugMessage.debugExitMessage(null, null); + 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) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + 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(); + if (CollectionUtils.isNotEmpty(properties)) { + for (Object property : properties) { + Set<String> artifactNames = + HeatStructureUtil.getReferencedValuesByFunctionName(filename, "get_file", property, + globalContext); + artifactSet.addAll(artifactNames); + } + } + } + } + + mdcDataDebugMessage.debugExitMessage(null, null); + return artifactSet; + } + + private static Set<String> getResourceDefNestedFiles(String filename, + HeatOrchestrationTemplate hot, + GlobalValidationContext globalContext) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + Set<String> resourceDefNestedFiles = new HashSet<>(); + hot.getResources() + .entrySet().stream().filter(entry -> entry.getValue().getType() + .equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) + .filter(entry -> + getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext) != null + && HeatStructureUtil.isNestedResource( + getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext) + .getType())) + .forEach(entry -> resourceDefNestedFiles.add( + getResourceDef(filename, entry.getKey(), entry.getValue(), globalContext).getType())); + + mdcDataDebugMessage.debugExitMessage(null, null); + return resourceDefNestedFiles; + } + + /** + * Gets resource def. + * + * @param filename the filename + * @param resourceName the resource name + * @param resource the resource + * @param globalContext the global context + * @return the resource def + */ + @SuppressWarnings("unchecked") + public static Resource getResourceDef(String filename, String resourceName, Resource resource, + GlobalValidationContext globalContext) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + 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 (Objects.nonNull(resourceDefType)) { + if (resourceDefType instanceof String) { + boolean isNested = + checkIfResourceGroupTypeIsNested(filename, resourceName, (String) resourceDefType, + globalContext); + if (isNested) { + resourceDef = new Resource(); + resourceDef.setType((String) resourceDefType); + //noinspection unchecked + resourceDef.setProperties((Map<String, Object>) resourceDefValueMap.get("properties")); + } + } else { + globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters(Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), + resourceName, resourceDefType.toString()), + LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE, "Invalid resource group type"); + } + } else { + globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters(Messages.INVALID_RESOURCE_TYPE.getErrorMessage(), "null", + resourceName), LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE, + "Invalid resource type"); + } + + } + + mdcDataDebugMessage.debugExitMessage(null, null); + return resourceDef; + } + + /** + * Check if resource group type is nested boolean. + * + * @param filename the filename + * @param resourceName the resource name + * @param resourceDefType the resource def type + * @param globalContext the global context + * @return the boolean + */ + public static boolean checkIfResourceGroupTypeIsNested(String filename, String resourceName, + String resourceDefType, + GlobalValidationContext globalContext) { + if (!HeatStructureUtil.isNestedResource(resourceDefType)) { + globalContext.addMessage(filename, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters(Messages.INVALID_RESOURCE_GROUP_TYPE.getErrorMessage(), + resourceName, resourceDefType), + LoggerTragetServiceName.VALIDATE_RESOURCE_GROUP_TYPE, + "Invalid resource group type"); + return false; + } + return true; + } } diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java index 2c0cf0b1aa..ee2fb6cab7 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java @@ -1,7 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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. + * ============LICENSE_END========================================================= + */ + package org.openecomp.sdc.heat.datatypes.model; -import org.openecomp.core.utilities.yaml.YamlUtil; import org.junit.Test; +import org.openecomp.core.utilities.yaml.YamlUtil; import java.io.InputStream; @@ -35,4 +55,4 @@ public class EnvironmentTest { } } } -}
\ No newline at end of file +} diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java index 09c83ca217..73cc6811ff 100644 --- a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java +++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java @@ -1,8 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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. + * ============LICENSE_END========================================================= + */ + package org.openecomp.sdc.heat.datatypes.model; -import org.openecomp.core.utilities.yaml.YamlUtil; import org.junit.Assert; import org.junit.Test; +import org.openecomp.core.utilities.yaml.YamlUtil; import java.io.InputStream; import java.util.ArrayList; @@ -115,8 +135,8 @@ public class HeatOrchestrationTemplateTest { List<Object> validValues = new ArrayList<>(); validValues.add("abc"); validValues.add("def"); - constraint.setValid_values(validValues); + constraint.setValidValues(validValues); constraints.add(constraint); return constraints; } -}
\ No newline at end of file +} |