From b29c5c244b23bbf549bc4e7637019e28ed48b0c4 Mon Sep 17 00:00:00 2001 From: Ester Rotstein Date: Tue, 20 Jun 2017 09:42:36 +0300 Subject: [SDC-36] support get nt by sdc type Change-Id: I0e514827ea7e9a420438a20c369e0b6a9967c66a Signed-off-by: Ester Rotstein --- .../sdc/tosca/parser/api/ISdcCsarHelper.java | 18 +++++++++++ .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 36 ++++++++++++++-------- .../openecomp/sdc/tosca/parser/impl/SdcTypes.java | 27 ++++++++++++++++ .../org/openecomp/sdc/tosca/parser/impl/Types.java | 32 ------------------- 4 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java delete mode 100644 src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java index 0317595..eeb23b4 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.lang3.tuple.Pair; +import org.openecomp.sdc.tosca.parser.impl.SdcTypes; import org.openecomp.sdc.toscaparser.api.Group; import org.openecomp.sdc.toscaparser.api.NodeTemplate; import org.openecomp.sdc.toscaparser.api.elements.Metadata; @@ -333,4 +334,21 @@ public interface ISdcCsarHelper { * @return customization UUID of a node template. */ public String getNodeTemplateCustomizationUuid(NodeTemplate nt); + + /** + * Get all node templates by sdcType for parent Node Template. + * + * @param parentNodeTemplate - parent node template + * @param sdcType - the SDC type of the node. + * @return node templates of this SDC type. + */ + List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType); + + /** + * Get all node templates by sdcType for this CSAR service. + * + * @param sdcType - the SDC type of the node. + * @return service node templates of this SDC type. + */ + List getServiceNodeTemplateBySdcType(SdcTypes sdcType); } diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index 612b896..1c4b71b 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -142,14 +142,14 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @Override //Sunny flow - covered with UT public List getServiceVlList() { - List serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL); + List serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL); return serviceVlList; } @Override //Sunny flow - covered with UT public List getServiceVfList() { - List serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF); + List serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF); return serviceVfList; } @@ -205,7 +205,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { List serviceVfList = getServiceVfList(); NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId); - return getNodeTemplateBySdcType(vfInstance, Types.TYPE_VFC); + return getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC); } @Override @@ -417,7 +417,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { log.debug("getCpListByVf vf list is null"); return cpList; } - cpList = getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP); + cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP); if (cpList == null || cpList.size() == 0) log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId); return cpList; @@ -551,24 +551,23 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return res; } - /************************************* helper functions ***********************************/ - private List getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType) { - if (nodeTemplate == null) { + public List getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType) { + if (parentNodeTemplate == null) { log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty"); return new ArrayList<>(); } - if (GeneralUtility.isEmptyString(sdcType)) { + if (sdcType == null) { log.error("getNodeTemplateBySdcType - sdcType is null or empty"); return new ArrayList<>(); } - SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate(); + SubstitutionMappings substitutionMappings = parentNodeTemplate.getSubMappingToscaTemplate(); if (substitutionMappings != null) { List nodeTemplates = substitutionMappings.getNodeTemplates(); if (nodeTemplates != null && nodeTemplates.size() > 0) - return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); + return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); else log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist"); } else @@ -577,8 +576,19 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return new ArrayList<>(); } - private List getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType) { - if (GeneralUtility.isEmptyString(sdcType)) { + public List getServiceNodeTemplateBySdcType(SdcTypes sdcType) { + if (sdcType == null) { + log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty"); + return new ArrayList<>(); + } + + TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); + return getNodeTemplateBySdcType(topologyTemplate, sdcType); + } + + /************************************* helper functions ***********************************/ + private List getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, SdcTypes sdcType) { + if (sdcType == null) { log.error("getNodeTemplateBySdcType - sdcType is null or empty"); return new ArrayList<>(); } @@ -591,7 +601,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { List nodeTemplates = topologyTemplate.getNodeTemplates(); if (nodeTemplates != null && nodeTemplates.size() > 0) - return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); + return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist"); return new ArrayList<>(); diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java new file mode 100644 index 0000000..5b68aea --- /dev/null +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * sdc-distribution-client + * ================================================================================ + * 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.tosca.parser.impl; + +public enum SdcTypes { + + CP, VL, VF, VFC, PNF, SERVICE + +} diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java deleted file mode 100644 index 9e71476..0000000 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * sdc-distribution-client - * ================================================================================ - * 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.tosca.parser.impl; - -public class Types { - public static String TYPE_VFMODULE = "org.openecomp.groups.VfModule"; - - // types found under metadata, type property - public static String TYPE_CP = "CP"; - public static String TYPE_VL = "VL"; - public static String TYPE_VF = "VF"; - public static String TYPE_VFC = "VFC"; - public static String TYPE_SERVICE = "Service"; -} -- cgit 1.2.3-korg