summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2020-04-06 15:44:56 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-07 08:14:26 +0000
commitf8bc4f94da584d5861827df7ee2107c33f514a55 (patch)
tree4f16ccc40d1ecfce5b6d1e85ce731f9f1eb3d45d /catalog-model/src/main
parenta36531c38fe1a9234b8dbeaed5505cf3ca48de26 (diff)
Support configuring of tosca type for categories
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-2877 Change-Id: I3160c5089979757628f31a44b01836236563b770
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java86
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java78
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java21
3 files changed, 100 insertions, 85 deletions
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 bf1dfef243..63194752fc 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
@@ -311,20 +311,18 @@ public abstract class Component implements PropertiesOwner {
public Map<String, ArtifactDefinition> safeGetComponentInstanceDeploymentArtifacts(String componentInstanceId) {
return getComponentInstanceById(componentInstanceId).map(ComponentInstance::safeGetDeploymentArtifacts)
- .orElse(emptyMap());
+ .orElse(emptyMap());
}
public Map<String, ArtifactDefinition> safeGetComponentInstanceInformationalArtifacts(String componentInstanceId) {
return getComponentInstanceById(componentInstanceId).map(ComponentInstance::safeGetInformationalArtifacts)
- .orElse(emptyMap());
+ .orElse(emptyMap());
}
public List<ArtifactDefinition> safeGetComponentInstanceHeatArtifacts(String componentInstanceId) {
- return safeGetComponentInstanceDeploymentArtifacts(componentInstanceId)
- .values()
- .stream()
- .filter(artifact -> ArtifactTypeEnum.HEAT_ENV.getType().equals(artifact.getArtifactType()))
- .collect(Collectors.toList());
+ return safeGetComponentInstanceDeploymentArtifacts(componentInstanceId).values().stream()
+ .filter(artifact -> ArtifactTypeEnum.HEAT_ENV.getType().equals(artifact.getArtifactType()))
+ .collect(Collectors.toList());
}
public Map<String, List<ComponentInstanceProperty>> safeGetComponentInstancesProperties() {
@@ -336,13 +334,10 @@ public abstract class Component implements PropertiesOwner {
}
private Map<String, List<ComponentInstanceProperty>> findUiComponentInstancesProperties() {
- List<String> instancesFromUi = componentInstances.stream()
- .filter(i -> !i.isCreatedFromCsar())
- .map(ComponentInstance::getUniqueId)
- .collect(Collectors.toList());
- return componentInstancesProperties.entrySet().stream()
- .filter(e -> instancesFromUi.contains(e.getKey()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ List<String> instancesFromUi = componentInstances.stream().filter(i -> !i.isCreatedFromCsar())
+ .map(ComponentInstance::getUniqueId).collect(Collectors.toList());
+ return componentInstancesProperties.entrySet().stream().filter(e -> instancesFromUi.contains(e.getKey()))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
public Map<String, List<ComponentInstanceInput>> safeGetComponentInstancesInputs() {
@@ -354,13 +349,10 @@ public abstract class Component implements PropertiesOwner {
}
private Map<String, List<ComponentInstanceInput>> findUiComponentInstancesInputs() {
- List<String> instancesFromUi = componentInstances.stream()
- .filter(i -> !i.isCreatedFromCsar())
- .map(ComponentInstance::getUniqueId)
- .collect(Collectors.toList());
- return componentInstancesInputs.entrySet().stream()
- .filter(e -> instancesFromUi.contains(e.getKey()))
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ List<String> instancesFromUi = componentInstances.stream().filter(i -> !i.isCreatedFromCsar())
+ .map(ComponentInstance::getUniqueId).collect(Collectors.toList());
+ return componentInstancesInputs.entrySet().stream().filter(e -> instancesFromUi.contains(e.getKey()))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
public List<ComponentInstanceProperty> safeGetComponentInstanceProperties(String cmptInstacneId) {
@@ -458,9 +450,7 @@ public abstract class Component implements PropertiesOwner {
if (groups == null) {
return Optional.empty();
}
- return groups.stream()
- .filter(predicate)
- .findAny();
+ return groups.stream().filter(predicate).findAny();
}
public void addGroups(List<GroupDefinition> groupsToAdd) {
@@ -483,8 +473,7 @@ public abstract class Component implements PropertiesOwner {
this.properties = new ArrayList<>();
}
- this.properties.add(propertyDefinition);
- ;
+ this.properties.add(propertyDefinition);;
}
public void addCategory(String category, String subCategory) {
@@ -565,21 +554,16 @@ public abstract class Component implements PropertiesOwner {
if (isEmpty(groups)) {
return emptyMap();
}
- return groups.stream()
- .filter(gr -> Objects.nonNull(gr.getProperties()))
- .collect(toMap(GroupDataDefinition::getUniqueId,
- GroupDataDefinition::getProperties));
+ return groups.stream().filter(gr -> Objects.nonNull(gr.getProperties()))
+ .collect(toMap(GroupDataDefinition::getUniqueId, GroupDataDefinition::getProperties));
}
public Map<String, List<PropertyDataDefinition>> safeGetPolicyProperties() {
if (isEmpty(policies)) {
return emptyMap();
}
- return policies.values()
- .stream()
- .filter(policy -> Objects.nonNull(policy.getProperties()))
- .collect(toMap(PolicyDataDefinition::getUniqueId,
- PolicyDataDefinition::getProperties));
+ return policies.values().stream().filter(policy -> Objects.nonNull(policy.getProperties()))
+ .collect(toMap(PolicyDataDefinition::getUniqueId, PolicyDataDefinition::getProperties));
}
public List<ComponentInstanceInput> safeGetComponentInstanceInputsByName(String cmptInstanceName) {
@@ -587,12 +571,10 @@ public abstract class Component implements PropertiesOwner {
if (this.componentInstancesInputs == null) {
return emptyPropsList;
}
- return this.componentInstances.stream()
- .filter(ci -> ci.getName().equals(cmptInstanceName))
- .map(ComponentInstance::getUniqueId)
- .map(instanceId -> safeGetComponentInstanceEntity(instanceId, this.componentInstancesInputs))
- .findAny()
- .orElse(emptyPropsList);
+ return this.componentInstances.stream().filter(ci -> ci.getName().equals(cmptInstanceName))
+ .map(ComponentInstance::getUniqueId)
+ .map(instanceId -> safeGetComponentInstanceEntity(instanceId, this.componentInstancesInputs)).findAny()
+ .orElse(emptyPropsList);
}
private <T> List<T> safeGetComponentInstanceEntity(String cmptInstanceId, Map<String, List<T>> instanceEntities) {
@@ -604,17 +586,17 @@ public abstract class Component implements PropertiesOwner {
return cmptInstanceProps == null ? emptyPropsList : cmptInstanceProps;
}
-
public void setSpecificComponetTypeArtifacts(Map<String, ArtifactDefinition> specificComponentTypeArtifacts) {
// Implement where needed
}
public String fetchGenericTypeToscaNameFromConfig() {
- // Implement where needed
- return ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getGenericAssetNodeTypes()
- .get(this.assetType());
+ return ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes()
+ .get(this.assetType());
+ }
+
+ protected <A> Optional<A> getHeadOption(List<A> list) {
+ return list == null || list.isEmpty() ? Optional.empty() : Optional.ofNullable(list.get(0));
}
public String assetType() {
@@ -661,18 +643,14 @@ public abstract class Component implements PropertiesOwner {
if (policies == null) {
return emptyList();
}
- return policies.values().stream()
- .filter(policyPredicate)
- .collect(Collectors.toList());
+ return policies.values().stream().filter(policyPredicate).collect(Collectors.toList());
}
public List<GroupDefinition> resolveGroupsByMember(String instanceId) {
if (groups == null) {
return emptyList();
}
- return groups.stream()
- .filter(group -> group.containsInstanceAsMember(instanceId))
- .collect(Collectors.toList());
+ return groups.stream().filter(group -> group.containsInstanceAsMember(instanceId)).collect(Collectors.toList());
}
public String getActualComponentType() {
@@ -703,7 +681,7 @@ public abstract class Component implements PropertiesOwner {
componentMetadataDefinition.getMetadataDataDefinition().setVspArchived(vspArchived);
}
- //supportability log method return map of component metadata teddy.h
+ // supportability log method return map of component metadata teddy.h
public Map<String, String> getComponentMetadataForSupportLog() {
Map<String, String> componentMetadata = new HashMap<>();
componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, this.getName());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
index 2c7dc57a52..44d6eff4fb 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java
@@ -28,11 +28,14 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
+
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
@Getter
@Setter
@@ -60,32 +63,31 @@ public class Resource extends Component {
public Resource() {
super(new ResourceMetadataDefinition());
- this.getComponentMetadataDefinition().getMetadataDataDefinition()
- .setComponentType(ComponentTypeEnum.RESOURCE);
+ this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE);
}
public Resource(ComponentMetadataDefinition componentMetadataDefinition) {
super(componentMetadataDefinition);
if (this.getComponentMetadataDefinition().getMetadataDataDefinition() == null) {
- this.getComponentMetadataDefinition().componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
+ this.getComponentMetadataDefinition().componentMetadataDataDefinition =
+ new ResourceMetadataDataDefinition();
}
this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE);
}
public Boolean isAbstract() {
- return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition()
- .getMetadataDataDefinition())
- .isAbstract();
+ return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
+ .isAbstract();
}
public void setAbstract(Boolean isAbstract) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setAbstract(isAbstract);
+ .setAbstract(isAbstract);
}
public String getCost() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getCost();
+ .getCost();
}
public void setCost(String cost) {
@@ -94,74 +96,91 @@ public class Resource extends Component {
public String getLicenseType() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getLicenseType();
+ .getLicenseType();
}
public void setLicenseType(String licenseType) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setLicenseType(licenseType);
+ .setLicenseType(licenseType);
}
public String getToscaResourceName() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getToscaResourceName();
+ .getToscaResourceName();
}
public void setToscaResourceName(String toscaResourceName) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setToscaResourceName(toscaResourceName);
+ .setToscaResourceName(toscaResourceName);
}
public ResourceTypeEnum getResourceType() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getResourceType();
+ .getResourceType();
}
public void setResourceType(ResourceTypeEnum resourceType) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setResourceType(resourceType);
+ .setResourceType(resourceType);
}
public String getVendorName() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getVendorName();
+ .getVendorName();
}
public void setVendorName(String vendorName) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setVendorName(vendorName);
+ .setVendorName(vendorName);
}
public String getVendorRelease() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getVendorRelease();
+ .getVendorRelease();
}
public void setVendorRelease(String vendorRelease) {
((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .setVendorRelease(vendorRelease);
+ .setVendorRelease(vendorRelease);
}
public String getResourceVendorModelNumber() {
return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
- .getResourceVendorModelNumber();
+ .getResourceVendorModelNumber();
}
public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
- ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()).
- setResourceVendorModelNumber(resourceVendorModelNumber);
+ ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
+ .setResourceVendorModelNumber(resourceVendorModelNumber);
}
@Override
public String fetchGenericTypeToscaNameFromConfig() {
+ return fetchToscaNameFromConfigBasedOnCategory().orElse(fetchToscaNameFromConfigBasedOnAssetType());
+ }
+
+ public String fetchToscaNameFromConfigBasedOnAssetType() {
String result = super.fetchGenericTypeToscaNameFromConfig();
if (null == result) {
result = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes()
- .get(ResourceTypeEnum.VFC.getValue());
+ .get(ResourceTypeEnum.VFC.getValue());
}
return result;
}
+ private Optional<String> fetchToscaNameFromConfigBasedOnCategory() {
+ return getHeadOption(this.getCategories()).flatMap(category -> getHeadOption(category.getSubcategories()).map(
+ subCategory -> fetchToscaNameFromConfigBasedOnCategory(category.getName(), subCategory.getName())));
+ }
+
+ private String fetchToscaNameFromConfigBasedOnCategory(final String resourceCategory,
+ final String resourceSubCategory) {
+ return Optional
+ .ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getResourceNodeTypes())
+ .map(categoryNames -> categoryNames.get(resourceCategory))
+ .map(subCategoryNames -> subCategoryNames.get(resourceSubCategory)).orElse(null);
+ }
+
@Override
public String assetType() {
return this.getResourceType().name();
@@ -174,21 +193,22 @@ public class Resource extends Component {
@Override
public boolean deriveFromGeneric() {
- return this.shouldGenerateInputs() || (derivedFrom != null && derivedFrom
- .contains(fetchGenericTypeToscaNameFromConfig()));
+ return this.shouldGenerateInputs()
+ || (derivedFrom != null && derivedFrom.contains(fetchGenericTypeToscaNameFromConfig()));
}
public Map<String, List<RequirementCapabilityRelDef>> groupRelationsFromCsarByInstanceName(Resource resource) {
List<RequirementCapabilityRelDef> componentInstanceRelationsFromCsar = resource.getComponentInstancesRelations()
- .stream().filter(r -> !r.isOriginUI()).collect(Collectors.toList());
- Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId = MapUtil
- .groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode);
- return MapUtil
- .convertMapKeys(relationsByInstanceId, instId -> getInstanceInvariantNameFromInstanceId(resource, instId));
+ .stream().filter(r -> !r.isOriginUI()).collect(Collectors.toList());
+ Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId =
+ MapUtil.groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode);
+ return MapUtil.convertMapKeys(relationsByInstanceId,
+ instId -> getInstanceInvariantNameFromInstanceId(resource, instId));
}
private String getInstanceInvariantNameFromInstanceId(Resource resource, String instId) {
Optional<ComponentInstance> componentInstanceById = resource.getComponentInstanceById(instId);
return componentInstanceById.isPresent() ? componentInstanceById.get().getInvariantName() : null;
}
+
}
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 3040f6bb6c..3e33fd490c 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
@@ -22,16 +22,20 @@ package org.openecomp.sdc.be.model;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
+
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.InstantiationTypes;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
@Getter
@@ -51,8 +55,8 @@ public class Service extends Component {
public Service(ComponentMetadataDefinition serviceMetadataDefinition) {
super(serviceMetadataDefinition);
- ComponentMetadataDataDefinition metadataDataDefinition = this.getComponentMetadataDefinition()
- .getMetadataDataDefinition();
+ ComponentMetadataDataDefinition metadataDataDefinition =
+ this.getComponentMetadataDefinition().getMetadataDataDefinition();
if (metadataDataDefinition != null) {
metadataDataDefinition.setComponentType(ComponentTypeEnum.SERVICE);
}
@@ -158,6 +162,19 @@ public class Service extends Component {
}
@Override
+ public String fetchGenericTypeToscaNameFromConfig() {
+ return getHeadOption(this.getCategories())
+ .map(category -> fetchToscaNameFromConfigBasedOnService(category.getName()))
+ .orElse(super.fetchGenericTypeToscaNameFromConfig());
+ }
+
+ private String fetchToscaNameFromConfigBasedOnService(final String serviceCategory) {
+ return Optional
+ .ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes())
+ .map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null);
+ }
+
+ @Override
public void setSpecificComponetTypeArtifacts(Map<String, ArtifactDefinition> specificComponentTypeArtifacts) {
setServiceApiArtifacts(specificComponentTypeArtifacts);
}