diff options
author | andre.schmid <andre.schmid@est.tech> | 2021-10-13 16:01:51 +0100 |
---|---|---|
committer | andre.schmid <andre.schmid@est.tech> | 2021-10-21 17:07:40 +0100 |
commit | 68eed7997aab4aa4f785085303aab61cf8e16a31 (patch) | |
tree | 119f4857936e217a063ce5342134b2ce11a6f3c6 /catalog-model/src/main/java | |
parent | cef866edcf8a14ede6762297dd9ab04b1f3d0375 (diff) |
Make Service base type optional
Issue-ID: SDC-3759
Change-Id: I8adf112966ee9303fc965a74cec7203274acd735
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/main/java')
5 files changed, 100 insertions, 19 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java index 5c88101b2f..584edad022 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/BaseType.java @@ -33,7 +33,7 @@ public class BaseType { @Setter private String toscaResourceName; - private List<Semver> versions = new ArrayList<>(); + private final List<Semver> versions = new ArrayList<>(); public BaseType(final String toscaResourceName) { this.toscaResourceName = toscaResourceName; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java index e0ca719005..1c0cfc4c5d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java @@ -638,6 +638,11 @@ public abstract class Component implements PropertiesOwner { } public void setDerivedFromGenericInfo(Resource genericType) { + if (genericType == null) { + derivedFromGenericType = null; + derivedFromGenericVersion = null; + return; + } derivedFromGenericType = genericType.getToscaResourceName(); derivedFromGenericVersion = genericType.getVersion(); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java index a06f737c83..bc8efb528d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java @@ -19,16 +19,15 @@ */ package org.openecomp.sdc.be.model; -import static java.util.Optional.ofNullable; - import java.util.HashMap; -import java.util.List; import java.util.Map; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.config.CategoryBaseTypeConfig; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition; @@ -143,7 +142,7 @@ public class Service extends Component { } private ServiceMetadataDataDefinition getServiceMetadataDefinition() { - return (ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition(); + return getMetadataDefinition(); } public String getServiceFunction() { @@ -167,9 +166,18 @@ public class Service extends Component { } private String fetchToscaNameFromConfigBasedOnService(final String serviceCategory) { - final Map<String, List<String>> serviceNodeTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); - final List<String> stringList = ofNullable(serviceNodeTypes).map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null); - return stringList != null ? stringList.get(0) : null; + final Map<String, CategoryBaseTypeConfig> serviceNodeTypesConfig = + ConfigurationManager.getConfigurationManager().getConfiguration().getServiceBaseNodeTypes(); + if (serviceNodeTypesConfig == null) { + return null; + } + + final CategoryBaseTypeConfig categoryBaseTypeConfig = serviceNodeTypesConfig.get(serviceCategory); + if (categoryBaseTypeConfig == null || CollectionUtils.isEmpty(categoryBaseTypeConfig.getBaseTypes())) { + return null; + } + + return categoryBaseTypeConfig.getBaseTypes().get(0); } @Override @@ -182,14 +190,22 @@ public class Service extends Component { } public void setAbstract(Boolean isAbstract) { - ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setIsAbstract(isAbstract); + getMetadataDefinition().setIsAbstract(isAbstract); } public void setVendorName(String vendorName) { - ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setVendorName(vendorName); + getMetadataDefinition().setVendorName(vendorName); } public void setVendorRelease(String vendorRelease) { - ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).setVendorRelease(vendorRelease); + getMetadataDefinition().setVendorRelease(vendorRelease); + } + + public boolean isSubstituteCandidate() { + return getDerivedFromGenericType() != null; + } + + private ServiceMetadataDataDefinition getMetadataDefinition() { + return (ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition(); } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java index 7457ed727e..ebc563268e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java @@ -86,7 +86,15 @@ public interface IElementOperation { Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction); - List<BaseType> getBaseTypes(String categoryName, String modelName); + List<BaseType> getServiceBaseTypes(String categoryName, String modelName); + + /** + * Checks if a category requires a base type. + * + * @param categoryName the category name + * @return {@code true} if a base type is required, {@code false} otherwise. + */ + boolean isBaseTypeRequired(String categoryName); Either<CategoryDefinition, ActionStatus> getCategory(NodeTypeEnum nodeType, String categoryId); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java index b98f8d9dea..127d778f73 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java @@ -21,19 +21,24 @@ package org.openecomp.sdc.be.model.operations.impl; import fj.data.Either; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphVertex; import org.openecomp.sdc.be.config.ArtifactConfigManager; import org.openecomp.sdc.be.config.ArtifactConfiguration; +import org.openecomp.sdc.be.config.CategoryBaseTypeConfig; import org.openecomp.sdc.be.config.Configuration; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -382,13 +387,18 @@ public class ElementOperation implements IElementOperation { } @Override - public List<BaseType> getBaseTypes(final String categoryName, final String modelName) { - final ArrayList<BaseType> baseTypes = new ArrayList<>(); - final Map<String, List<String>> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); - final List<String> categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName); - final String generalBaseType = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes().get("Service"); - final List<String> baseToscaResourceNames = categorySpecificBaseType == null ? List.of(generalBaseType) : categorySpecificBaseType; + public List<BaseType> getServiceBaseTypes(final String categoryName, final String modelName) { + + final CategoryBaseTypeConfig categoryBaseTypeConfig = getCategoryBaseTypeConfig(categoryName).orElse(null); + final List<String> baseToscaResourceNames; + if (categoryBaseTypeConfig == null) { + final String generalBaseType = getConfiguration().getGenericAssetNodeTypes().get("Service"); + baseToscaResourceNames = List.of(generalBaseType); + } else { + baseToscaResourceNames = getCategoryBaseTypes(categoryName); + } + final ArrayList<BaseType> baseTypes = new ArrayList<>(); baseToscaResourceNames.forEach(baseToscaResourceName -> { final Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class); props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName); @@ -413,6 +423,48 @@ public class ElementOperation implements IElementOperation { return baseTypes; } + private Configuration getConfiguration() { + return ConfigurationManager.getConfigurationManager().getConfiguration(); + } + + @Override + public boolean isBaseTypeRequired(final String categoryName) { + final Map<String, CategoryBaseTypeConfig> categoriesSpecificBaseTypeMap = getConfiguration().getServiceBaseNodeTypes(); + if (MapUtils.isEmpty(categoriesSpecificBaseTypeMap)) { + return true; + } + + final CategoryBaseTypeConfig categoryBaseTypeConfig = categoriesSpecificBaseTypeMap.get(categoryName); + if (categoryBaseTypeConfig == null) { + return true; + } + + return categoryBaseTypeConfig.isRequired(); + } + + private List<String> getCategoryBaseTypes(final String categoryName) { + final Optional<CategoryBaseTypeConfig> categoryBaseTypeConfigOptional = getCategoryBaseTypeConfig(categoryName); + if (categoryBaseTypeConfigOptional.isEmpty()) { + return Collections.emptyList(); + } + + final CategoryBaseTypeConfig categoryBaseTypeConfig = categoryBaseTypeConfigOptional.get(); + if (CollectionUtils.isEmpty(categoryBaseTypeConfig.getBaseTypes())) { + return Collections.emptyList(); + } + + return categoryBaseTypeConfig.getBaseTypes(); + } + + private Optional<CategoryBaseTypeConfig> getCategoryBaseTypeConfig(final String categoryName) { + final Map<String, CategoryBaseTypeConfig> categoriesSpecificBaseTypes = getConfiguration().getServiceBaseNodeTypes(); + if (categoriesSpecificBaseTypes == null) { + return Optional.empty(); + } + + return Optional.ofNullable(categoriesSpecificBaseTypes.get(categoryName)); + } + private Map<String, List<String>> addTypesDerivedFromVertex(final Map<String, List<String>> types, final GraphVertex vertex) { final Either<List<GraphVertex>, JanusGraphOperationStatus> derivedFromVertex = janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll); @@ -900,7 +952,7 @@ public class ElementOperation implements IElementOperation { @Override public Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> getDefaultHeatTimeout() { - return Either.left(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatArtifactDeploymentTimeout()); + return Either.left(getConfiguration().getHeatArtifactDeploymentTimeout()); } @Override |