summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorYuli Shlosberg <ys9693@att.com>2017-11-26 19:05:23 +0200
committerMichael Lando <ml636r@att.com>2017-11-27 08:49:27 +0000
commit0566f581c0f310384f42838c388f57234ed1d60e (patch)
treedd782da7ebd4ce591876865a564b9c1f65eb5e66 /catalog-be/src/main/java/org
parent4d8033eeb036943c05b3a5752b8f4cd4d705272f (diff)
sync 1.1.0 to master
Change-Id: I6e040f039895dd2ced55f95824473946b226fb5d Issue-ID: SDC-707 Signed-off-by: Yuli Shlosberg <ys9693@att.com>
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java561
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java434
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java372
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java56
9 files changed, 1040 insertions, 436 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index 74bb55b63d..b7344e9911 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -191,7 +191,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
public static enum ArtifactOperationEnum {
- Create(), Update(), Delete(), Download();
+ Create(), Update(), Delete(), Download(), Link();
+
+ public static boolean isCreateOrLink(ArtifactOperationEnum operation) {
+ return (operation.equals(Create) || operation.equals(Link));
+
+ }
}
public class ArtifactOperationInfo {
@@ -3648,12 +3653,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ESArtifactData, CassandraOperationStatus> artifactfromES;
ESArtifactData esArtifactData;
if (esArtifactId != null && !esArtifactId.isEmpty() && artifactDefinition.getPayloadData() == null) {
+ log.debug("Try to fetch artifact from cassandra with id : {}", esArtifactId);
artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
if (artifactfromES.isRight()) {
CassandraOperationStatus resourceUploadStatus = artifactfromES.right().value();
StorageOperationStatus storageResponse = DaoStatusConverter.convertCassandraStatusToStorageStatus(resourceUploadStatus);
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageResponse);
- log.debug("Error when getting artifact from ES, error: {}", actionStatus.name());
+ log.debug("Error when getting artifact from ES, error: {} esid : {}", actionStatus.name(), esArtifactId);
return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, artifactDefinition.getArtifactDisplayName()));
}
esArtifactData = artifactfromES.left().value();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
index a34bf00a7a..108e03c274 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
@@ -1178,6 +1178,11 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return text;
}
+ public Either<Component, ActionStatus> shouldUpgradeToLatestDerived(Component clonedComponent) {
+ //general implementation. Must be error for service, VF . In ResourceBuisnessLogic exist override
+ return Either.right(ActionStatus.GENERAL_ERROR);
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index 6dc83bfc2b..66d8668fea 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -32,7 +32,6 @@ import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -42,15 +41,12 @@ import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
@@ -60,26 +56,20 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.GroupInstance;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
-import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
-import org.openecomp.sdc.be.resources.data.PropertyValueData;
-import org.openecomp.sdc.be.tosca.ToscaUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
@@ -150,7 +140,7 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
containerComponent = validateComponentExists.left().value();
}
- if (ToscaUtils.isAtomicType(containerComponent)) {
+ if (ModelConverter.isAtomicComponent(containerComponent)) {
log.debug("Cannot attach resource instances to container resource of type {}", containerComponent.assetType());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType()));
}
@@ -209,7 +199,7 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
- if (ToscaUtils.isAtomicType(containerComponent)) {
+ if (ModelConverter.isAtomicComponent(containerComponent)) {
log.debug("Cannot attach resource instances to container resource of type {}", containerComponent.assetType());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType()));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 0ae546479a..1ab7ffb007 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -111,6 +111,7 @@ import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.ICacheMangerOperation;
import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
@@ -595,6 +596,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContent);
+ Either<Resource, ResponseFormat> genericResourceEither = handleResourceGenericType(preparedResource);
+ if (genericResourceEither.isRight()) {
+ log.debug("failed to get resource generic type. status is {}", genericResourceEither.right().value());
+ ResponseFormat responseFormat = genericResourceEither.right().value();
+ componentsUtils.auditResource(genericResourceEither.right().value(), csarInfo.getModifier(), preparedResource, "", "", updateResource, null);
+ return Either.right(responseFormat);
+ }
+
parseNodeTypeInfoYamlEither = this.handleNodeTypes(yamlFileName, preparedResource, yamlFileContent, shouldLock, nodeTypesArtifactsToHandle, createdArtifacts, nodeTypesInfo, csarInfo, nodeName);
if (parseNodeTypeInfoYamlEither.isRight()) {
ResponseFormat responseFormat = parseNodeTypeInfoYamlEither.right().value();
@@ -687,6 +696,17 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
+ private Either<Resource, ResponseFormat> handleResourceGenericType(Resource resource) {
+ Either<Resource, ResponseFormat> genericResourceEither = fetchAndSetDerivedFromGenericType(resource);
+ if (genericResourceEither.isRight()) {
+ return genericResourceEither;
+ }
+ if (resource.shouldGenerateInputs()) {
+ generateInputsFromGenericTypeProperties(resource, genericResourceEither.left().value());
+ }
+ return genericResourceEither;
+ }
+
private Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Resource oldResource) {
Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts = CsarUtils.extractVfcsArtifactsFromCsar(csarInfo.getCsar());
@@ -888,7 +908,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
handleNodeTypeArtifactsRes = Either.right(handleNodeTypeArtifactsRequestRes.right().value());
break;
}
- if (curOperation == ArtifactOperationEnum.Create) {
+ if (ArtifactOperationEnum.isCreateOrLink(curOperation)) {
createdArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value());
}
handledNodeTypeArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value());
@@ -917,6 +937,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
vfcToscaNames.put(nodeType.getKey(), toscaResourceName);
}
}
+ for(NodeTypeInfo cvfc : nodeTypesInfo.values()){
+ vfcToscaNames.put(cvfc.getType(), buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), vfResourceName, cvfc.getType()));
+ }
return vfcToscaNames;
}
@@ -1107,7 +1130,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(validateRes.right().value());
}
// VF / PNF "derivedFrom" should be null (or ignored)
- if (ToscaUtils.isAtomicType(resource)) {
+ if (ModelConverter.isAtomicComponent(resource)) {
Either<Boolean, ResponseFormat> validateDerivedFromNotEmpty = validateDerivedFromNotEmpty(user, resource, AuditingActionEnum.CREATE_RESOURCE);
if (validateDerivedFromNotEmpty.isRight()) {
return Either.right(validateDerivedFromNotEmpty.right().value());
@@ -1233,7 +1256,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
if(result == null){
newComplexVfc = buildCvfcRes.left().value();
- Either<Resource, StorageOperationStatus> oldComplexVfcRes = toscaOperationFacade.getLatestByToscaResourceName(newComplexVfc.getToscaResourceName());
+ Either<Resource, StorageOperationStatus> oldComplexVfcRes = toscaOperationFacade.getFullLatestComponentByToscaResourceName(newComplexVfc.getToscaResourceName());
if(oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() != StorageOperationStatus.NOT_FOUND){
log.debug("Failed to fetch previous complex VFC by tosca resource name {}. Status is {}. ", newComplexVfc.getToscaResourceName(), oldComplexVfcRes.right().value());
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
@@ -1461,7 +1484,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
String nameWithouNamespacePrefix = nodeName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
String[] findTypes = nameWithouNamespacePrefix.split("\\.");
String resourceType = findTypes[0];
- return resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1) + "Cvfc";
+ String resourceName = resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1);
+ return addCvfcSuffixToResourceName(resourceName);
}
private Either<Resource, ResponseFormat> createResourceAndRIsFromYaml(String yamlName, Resource resource, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative,
@@ -1869,25 +1893,27 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
log.debug("************* Going to create all nodes {}", yamlName);
Either<Map<String, Resource>, ResponseFormat> createdResourcesFromdNodeTypeMap = this.handleNodeTypes(yamlName, resource, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeName);
+ log.debug("************* Finished to create all nodes {}", yamlName);
if (createdResourcesFromdNodeTypeMap.isRight()) {
log.debug("failed to resources from node types status is {}", createdResourcesFromdNodeTypeMap.right().value());
return Either.right(createdResourcesFromdNodeTypeMap.right().value());
}
- log.debug("************* Finished to create all nodes {}", yamlName);
log.debug("************* Going to create all resource instances {}", yamlName);
createResourcesInstancesEither = createResourceInstances(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false, csarInfo.getCreatedNodes());
+ log.debug("************* Finished to create all resource instances {}", yamlName);
if (createResourcesInstancesEither.isRight()) {
log.debug("failed to create resource instances status is {}", createResourcesInstancesEither.right().value());
result = createResourcesInstancesEither;
return createResourcesInstancesEither;
}
- log.debug("************* Finished to create all resource instances for {}", yamlName);
resource = createResourcesInstancesEither.left().value();
log.debug("************* Going to create all relations {}", yamlName);
createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap);
+ log.debug("************* Finished to create all relations {}", yamlName);
+
if (createResourcesInstancesEither.isRight()) {
log.debug("failed to create relation between resource instances status is {}", createResourcesInstancesEither.right().value());
result = createResourcesInstancesEither;
@@ -1895,7 +1921,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
} else {
resource = createResourcesInstancesEither.left().value();
}
- log.debug("************* Finished to create all relations {}", yamlName);
log.debug("************* Going to create positions {}", yamlName);
Either<List<ComponentInstance>, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(resource, csarInfo.getModifier().getUserId());
@@ -1987,6 +2012,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (eitherCreateResult.isRight()) {
return Either.right(eitherCreateResult.right().value());
}
+ Either<Resource, StorageOperationStatus> eitherGerResource = toscaOperationFacade.getToscaElement(resource.getUniqueId());
+ if (eitherGerResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+
+ return Either.right(responseFormat);
+
+ }
+ resource = eitherGerResource.left().value();
Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils);
if (artifacsMetaCsarStatus.isLeft()) {
@@ -1994,7 +2027,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey();
String artifactsContents = artifacsMetaCsarStatus.left().value().getValue();
Either<Resource, ResponseFormat> createArtifactsFromCsar = Either.left(resource);
- if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.Create)
+ if (ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum()))
createArtifactsFromCsar = createResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
else
createArtifactsFromCsar = updateResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
@@ -2074,7 +2107,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private void addNonMetaCreatedArtifactsToSupportRollback(ArtifactOperationInfo operation, List<ArtifactDefinition> createdArtifacts, Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts) {
- if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.Create && createdArtifacts != null && eitherNonMetaArtifacts.isLeft()) {
+ if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum()) && createdArtifacts != null && eitherNonMetaArtifacts.isLeft()) {
Either<ArtifactDefinition, Operation> eitherResult = eitherNonMetaArtifacts.left().value();
if (eitherResult.isLeft()) {
createdArtifacts.add(eitherResult.left().value());
@@ -2140,16 +2173,27 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup = new HashMap<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>();
for (List<ArtifactTemplateInfo> parsedGroupTemplateList : parsedArifactsCollection) {
+
for (ArtifactTemplateInfo parsedGroupTemplate : parsedGroupTemplateList) {
- parsedGroupTemplate.setGroupName("");
- Set<ArtifactTemplateInfo> parsedArtifactsNames = new HashSet<ArtifactTemplateInfo>();
- parsedArtifactsNames.add(parsedGroupTemplate);
- List<ArtifactTemplateInfo> relatedGroupTemplateList = parsedGroupTemplate.getRelatedArtifactsInfo();
- if (relatedGroupTemplateList != null && !relatedGroupTemplateList.isEmpty()) {
- createArtifactsGroupSet(parsedGroupTemplateList, parsedArtifactsNames);
+ if(parsedGroupTemplate.getGroupName() != null){
+ parsedGroupTemplate.setGroupName("");
+ Set<ArtifactTemplateInfo> parsedArtifactsNames = new HashSet<ArtifactTemplateInfo>();
+ parsedArtifactsNames.add(parsedGroupTemplate);
+ List<ArtifactTemplateInfo> relatedGroupTemplateList = parsedGroupTemplate.getRelatedArtifactsInfo();
+ if (relatedGroupTemplateList != null && !relatedGroupTemplateList.isEmpty()) {
+ createArtifactsGroupSet(parsedGroupTemplateList, parsedArtifactsNames);
+ }
+ parsedGroup.put(parsedGroupTemplate, parsedArtifactsNames);
+ }else{
+ List<ArtifactTemplateInfo> arrtifacts = new ArrayList<ArtifactTemplateInfo>();
+ arrtifacts.add(parsedGroupTemplate);
+ Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, resource, arrtifacts, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter, shouldLock, inTransaction);
+ if (resStatus.isRight())
+ return resStatus;
+
}
- parsedGroup.put(parsedGroupTemplate, parsedArtifactsNames);
}
+
}
///////////////////////////////// find artifacts to
@@ -2670,42 +2714,40 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resStatus = createDeploymentArtifactsFromCsar(csarInfo, resource, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter, shouldLock, inTransaction);
if (resStatus.isRight())
return resStatus;
-
- Map<String, String> members = new HashMap<String, String>();
- associateMembersToArtifacts(createdNewArtifacts, artifactsFromResource, heatGroups, artifactsGroup, members);
-
- List<String> artifactsList = new ArrayList<String>(artifactsGroup);
- List<String> artifactsUUIDList = new ArrayList<String>(artifactsUUIDGroup);
-
- GroupDefinition groupDefinition = new GroupDefinition();
- groupDefinition.setName(groupName);
- groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
- groupDefinition.setArtifacts(artifactsList);
- groupDefinition.setArtifactsUuid(artifactsUUIDList);
-
- if (!members.isEmpty())
- groupDefinition.setMembers(members);
-
- List<GroupProperty> properties = new ArrayList<GroupProperty>();
- GroupProperty prop = new GroupProperty();
- prop.setName(Constants.IS_BASE);
- prop.setValue(Boolean.toString(groupTemplateInfo.isBase()));
- properties.add(prop);
-
- List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- createdArtifacts.addAll(createdNewArtifacts);
- createdArtifacts.addAll(artifactsFromResource);
- Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true);
- if (getLatestGroupTypeRes.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value())));
+ if(groupName != null && !groupName.isEmpty()){
+ Map<String, String> members = new HashMap<String, String>();
+ associateMembersToArtifacts(createdNewArtifacts, artifactsFromResource, heatGroups, artifactsGroup, members);
+
+ List<String> artifactsList = new ArrayList<String>(artifactsGroup);
+ List<String> artifactsUUIDList = new ArrayList<String>(artifactsUUIDGroup);
+
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName(groupName);
+ groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
+ groupDefinition.setArtifacts(artifactsList);
+ groupDefinition.setArtifactsUuid(artifactsUUIDList);
+
+ if (!members.isEmpty())
+ groupDefinition.setMembers(members);
+
+ List<GroupProperty> properties = new ArrayList<GroupProperty>();
+ GroupProperty prop = new GroupProperty();
+ prop.setName(Constants.IS_BASE);
+ prop.setValue(Boolean.toString(groupTemplateInfo.isBase()));
+ properties.add(prop);
+
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ createdArtifacts.addAll(createdNewArtifacts);
+ createdArtifacts.addAll(artifactsFromResource);
+ Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true);
+ if (getLatestGroupTypeRes.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value())));
+ }
+ properties = createVfModuleAdditionalProperties(groupTemplateInfo.isBase(), groupName, properties, createdArtifacts, artifactsList, getLatestGroupTypeRes.left().value());
+ groupDefinition.convertFromGroupProperties(properties);
+
+ needToAdd.add(groupDefinition);
}
- properties = createVfModuleAdditionalProperties(groupTemplateInfo.isBase(), groupName, properties, createdArtifacts, artifactsList, getLatestGroupTypeRes.left().value());
- groupDefinition.convertFromGroupProperties(properties);
-
- // Either<GroupDefinition, ResponseFormat> createGroup = groupBusinessLogic.createGroup(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, groupDefinition, inTransaction);
- // if (createGroup.isRight())
- // return Either.right(createGroup.right().value());
- needToAdd.add(groupDefinition);
}
ComponentParametersView componentParametersView = new ComponentParametersView();
componentParametersView.disableAll();
@@ -2858,7 +2900,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> vfCsarArtifactsToHandle = null;
- if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.Create) {
+ if (ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
vfCsarArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList);
} else {
@@ -2989,42 +3031,36 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
log.debug("createDeploymentArtifactsFromCsar end");
if (resStatus.isRight())
return resStatus;
-
- Map<String, String> members = new HashMap<String, String>();
- associateMembersToArtifacts(createdArtifacts, null, heatGroups, artifactsGroup, members);
-
- List<String> artifactsList = new ArrayList<String>(artifactsGroup);
- List<String> artifactsUUIDList = new ArrayList<String>(artifactsUUIDGroup);
-
- GroupDefinition groupDefinition = new GroupDefinition();
- groupDefinition.setName(groupName);
- groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
- groupDefinition.setArtifacts(artifactsList);
- groupDefinition.setArtifactsUuid(artifactsUUIDList);
-
- if (!members.isEmpty())
- groupDefinition.setMembers(members);
- List<GroupProperty> properties = new ArrayList<GroupProperty>();
- GroupProperty prop = new GroupProperty();
- prop.setName(Constants.IS_BASE);
- prop.setValue(Boolean.toString(groupTemplateInfo.isBase()));
- properties.add(prop);
- Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true);
- if (getLatestGroupTypeRes.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value())));
+ if(groupName != null && !groupName.isEmpty()){
+ Map<String, String> members = new HashMap<String, String>();
+ associateMembersToArtifacts(createdArtifacts, null, heatGroups, artifactsGroup, members);
+
+ List<String> artifactsList = new ArrayList<String>(artifactsGroup);
+ List<String> artifactsUUIDList = new ArrayList<String>(artifactsUUIDGroup);
+
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName(groupName);
+ groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
+ groupDefinition.setArtifacts(artifactsList);
+ groupDefinition.setArtifactsUuid(artifactsUUIDList);
+
+ if (!members.isEmpty())
+ groupDefinition.setMembers(members);
+ List<GroupProperty> properties = new ArrayList<GroupProperty>();
+ GroupProperty prop = new GroupProperty();
+ prop.setName(Constants.IS_BASE);
+ prop.setValue(Boolean.toString(groupTemplateInfo.isBase()));
+ properties.add(prop);
+ Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true);
+ if (getLatestGroupTypeRes.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value())));
+ }
+ properties = createVfModuleAdditionalProperties(groupTemplateInfo.isBase(), groupName, properties, createdArtifacts, artifactsList, getLatestGroupTypeRes.left().value());
+ groupDefinition.convertFromGroupProperties(properties);
+ log.debug("createGroup start");
+
+ needToCreate.add(groupDefinition);
}
- properties = createVfModuleAdditionalProperties(groupTemplateInfo.isBase(), groupName, properties, createdArtifacts, artifactsList, getLatestGroupTypeRes.left().value());
- groupDefinition.convertFromGroupProperties(properties);
- log.debug("createGroup start");
-
- // Since in these groups we handle only artifacts, then no need to
- // fetch component instances
-
- // Either<GroupDefinition, ResponseFormat> createGroup = groupBusinessLogic.createGroup(comp, user, ComponentTypeEnum.RESOURCE, groupDefinition, inTransaction);
- // log.debug("createGroup end");
- // if (createGroup.isRight())
- // return Either.right(createGroup.right().value());
- needToCreate.add(groupDefinition);
}
ComponentParametersView componentParametersView = new ComponentParametersView();
@@ -3496,7 +3532,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
}
- allGroups.addAll(artifactTemplateInfoList);
+ if(!artifactsTypeKey.equalsIgnoreCase(ArtifactTemplateInfo.CSAR_ARTIFACT))
+ allGroups.addAll(artifactTemplateInfoList);
artifactsMap.put(artifactsTypeKey, artifactTemplateInfoList);
}
int counter = groupBusinessLogic.getNextVfModuleNameCounter(resource.getGroups());
@@ -3602,10 +3639,40 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
} else {
originResource = originCompMap.get(currentCompInstance.getComponentUid());
}
- if (originResource.getCapabilities() != null && !originResource.getCapabilities().isEmpty())
- instCapabilties.put(currentCompInstance, originResource.getCapabilities());
if (originResource.getRequirements() != null && !originResource.getRequirements().isEmpty())
instRequirements.put(currentCompInstance, originResource.getRequirements());
+ if (MapUtils.isNotEmpty(originResource.getCapabilities())) {
+ Map<String, List<CapabilityDefinition>> originCapabilities ;
+ if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilities())) {
+ originCapabilities = new HashMap<>();
+ originResource.getCapabilities().entrySet().stream().forEach(e ->{
+ List<CapabilityDefinition> list = e.getValue().stream().map(l -> new CapabilityDefinition(l)).collect(Collectors.toList());
+ originCapabilities.put(e.getKey(), list);
+ });
+ Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>();
+ for(List<UploadCapInfo> capabilities : uploadComponentInstanceInfo.getCapabilities().values()){
+ for(UploadCapInfo capability :capabilities){
+ if(CollectionUtils.isNotEmpty(capability.getProperties())){
+ newPropertiesMap.put(capability.getName(), capability.getProperties().stream().collect(Collectors.toMap(p->p.getName(), p->p)));
+ }
+ }
+ }
+ for (List<CapabilityDefinition> capabilities : originCapabilities.values()) {
+ List<CapabilityDefinition> filteredCapabilities = capabilities.stream().filter(c -> newPropertiesMap.containsKey(c.getName())).collect(Collectors.toList());
+ for(CapabilityDefinition cap : filteredCapabilities){
+ Either<Boolean, ResponseFormat> updateRes = updatePropertyValues(cap.getProperties(),newPropertiesMap.get(cap.getName()), allDataTypes.left().value());
+ if(updateRes.isRight()){
+ log.debug("Failed to update capability properties of capability {} . Status is {}. ", cap.getName(), updateRes.right().value());
+ return Either.right(updateRes.right().value());
+ }
+ }
+ }
+ }
+ else{
+ originCapabilities = originResource.getCapabilities();
+ }
+ instCapabilties.put(currentCompInstance, originCapabilities);
+ }
if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts().isEmpty())
instDeploymentArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts());
if (originResource.getArtifacts() != null && !originResource.getArtifacts().isEmpty())
@@ -3618,14 +3685,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(addPropertiesValueToRiRes);
}
} else {
- Either<Resource, ResponseFormat> genericResourceEither = fetchAndSetDerivedFromGenericType(originResource);
- if (genericResourceEither.isRight()) {
- return genericResourceEither;
- }
- log.trace("************* Going to add inputs from from original resource {} to resource instance. ", originResource.getName());
- if (originResource.shouldGenerateInputs())
- generateInputsFromGenericTypeProperties(originResource, genericResourceEither.left().value());
-
ResponseFormat addInputValueToRiRes = addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, yamlName, instInputs, allDataTypes.left().value());
if (addInputValueToRiRes.getStatus() != 200) {
return Either.right(addInputValueToRiRes);
@@ -3724,25 +3783,54 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(responseFormat);
}
+ if(resource.getResourceType() == ResourceTypeEnum.CVFC){
+ eitherGetResource = toscaOperationFacade.getToscaFullElement(resource.getUniqueId());
+ if (eitherGetResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource);
+ return Either.right(responseFormat);
+ }
+ eitherGetResource = updateCalculatedCapReqWithSubstitutionMappings(eitherGetResource.left().value(), uploadResInstancesMap);
+ if (eitherGetResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource);
+ return Either.right(responseFormat);
+ }
+ }
+
log.debug("************* in create relations, getResource start");
-
eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId());
log.debug("************* in create relations, getResource end");
if (eitherGetResource.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource);
-
return Either.right(responseFormat);
-
}
- resource = eitherGetResource.left().value();
- if(resource.getResourceType() == ResourceTypeEnum.CVFC){
- eitherGetResource = updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap);
- if (eitherGetResource.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource);
- return Either.right(responseFormat);
+ return Either.left(eitherGetResource.left().value());
+ }
+
+ private Either<Boolean, ResponseFormat> updatePropertyValues(List<ComponentInstanceProperty> properties, Map<String, UploadPropInfo> newProperties, Map<String, DataTypeDefinition> allDataTypes) {
+ for(ComponentInstanceProperty property : properties){
+ Either<String, StorageOperationStatus> updateRes = updatePropertyValue(property ,newProperties.get(property.getName()), allDataTypes);
+ if(updateRes.isRight()){
+ log.debug("Failed to update capability property {} . Status is {}. ", property.getName(), updateRes.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateRes.right().value())));
}
}
- return Either.left(eitherGetResource.left().value());
+ return Either.left(true);
+ }
+
+ private Either<String, StorageOperationStatus> updatePropertyValue(ComponentInstanceProperty property, UploadPropInfo propertyInfo, Map<String, DataTypeDefinition> allDataTypes) {
+ String value = null;
+ List<GetInputValueDataDefinition> getInputs = null;
+ boolean isValidate = true;
+ if (null != propertyInfo && null != propertyInfo.getValue()) {
+ getInputs = propertyInfo.getGet_input();
+ isValidate = getInputs == null || getInputs.isEmpty();
+ if (isValidate) {
+ value = ImportUtils.getPropertyJsonStringValue(propertyInfo.getValue(), property.getType());
+ } else
+ value = ImportUtils.getPropertyJsonStringValue(propertyInfo.getValue(), ToscaTagNamesEnum.GET_INPUT.getElementName());
+ }
+ property.setValue(value);
+ return validatePropValueBeforeCreate(property, value, isValidate, null, allDataTypes);
}
private Either<Resource, StorageOperationStatus> updateCalculatedCapReqWithSubstitutionMappings(Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
@@ -3763,7 +3851,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
if(updateRes == null){
- updateRes = toscaOperationFacade.getToscaElement( resource.getUniqueId());
+ updateRes = Either.left(resource);
}
return updateRes;
}
@@ -4010,25 +4098,28 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private ResponseFormat addPropertyValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo, Resource resource, Resource originResource, ComponentInstance currentCompInstance, String yamlName,
- Map<String, List<ComponentInstanceProperty>> instProperties, Map<String, DataTypeDefinition> allDataTypes) {
+ Map<String, List<ComponentInstanceProperty>> instProperties, Map<String, DataTypeDefinition> allDataTypes) {
Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
- if (propMap != null && propMap.size() > 0) {
- Map<String, PropertyDefinition> currPropertiesMap = new HashMap<String, PropertyDefinition>();
+ Map<String, PropertyDefinition> currPropertiesMap = new HashMap<String, PropertyDefinition>();
- List<PropertyDefinition> listFromMap = originResource.getProperties();
- if (listFromMap == null || listFromMap.isEmpty()) {
- log.debug("failed to find properties ");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND);
- return responseFormat;
- }
- for (PropertyDefinition prop : listFromMap) {
- String propName = prop.getName();
- if (!currPropertiesMap.containsKey(propName)) {
- currPropertiesMap.put(propName, prop);
- }
+ List<PropertyDefinition> listFromMap = originResource.getProperties();
+ if ((propMap != null && !propMap.isEmpty()) && (listFromMap == null || listFromMap.isEmpty())) {
+ log.debug("failed to find properties ");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND);
+ return responseFormat;
+ }
+ if(listFromMap == null || listFromMap.isEmpty()){
+ return componentsUtils.getResponseFormat(ActionStatus.OK);
+ }
+ for (PropertyDefinition prop : listFromMap) {
+ String propName = prop.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ currPropertiesMap.put(propName, prop);
}
- List<ComponentInstanceProperty> instPropList = new ArrayList<>();
+ }
+ List<ComponentInstanceProperty> instPropList = new ArrayList<>();
+ if (propMap != null && propMap.size() > 0) {
for (List<UploadPropInfo> propertyList : propMap.values()) {
UploadPropInfo propertyInfo = propertyList.get(0);
@@ -4104,14 +4195,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// delete overriden property
currPropertiesMap.remove(property.getName());
}
- // add rest of properties
- if (!currPropertiesMap.isEmpty()) {
- for (PropertyDefinition value : currPropertiesMap.values()) {
- instPropList.add(new ComponentInstanceProperty(value));
- }
+ }
+ // add rest of properties
+ if (!currPropertiesMap.isEmpty()) {
+ for (PropertyDefinition value : currPropertiesMap.values()) {
+ instPropList.add(new ComponentInstanceProperty(value));
}
- instProperties.put(currentCompInstance.getUniqueId(), instPropList);
}
+ instProperties.put(currentCompInstance.getUniqueId(), instPropList);
return componentsUtils.getResponseFormat(ActionStatus.OK);
}
@@ -4264,6 +4355,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(validRegDef);
}
+ @SuppressWarnings("unchecked")
public Either<ParsedToscaYamlInfo, ResponseFormat> parseResourceInfoFromYaml(String yamlFileName, Resource resource, String resourceYml, Map<String, String> createdNodesToscaResourceNames, Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName) {
Map<String, Object> mappedToscaTemplate;
@@ -4317,7 +4409,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Map<String, Resource> nodeNamespaceMap) {
Either<Resource, ResponseFormat> eitherResource = null;
- log.debug("{} - going to create resource instanse from CSAR", yamlName);
+ log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
if (uploadResInstancesMap == null || uploadResInstancesMap.isEmpty()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
@@ -4332,13 +4424,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Iterator<Entry<String, UploadComponentInstanceInfo>> nodesInfoValue = uploadResInstancesMap.entrySet().iterator();
Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
while (nodesInfoValue.hasNext()) {
- log.debug("*************Going to create resource instances from {}", yamlName);
+ log.debug("*************Going to create resource instances {}", yamlName);
Entry<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoEntry = nodesInfoValue.next();
UploadComponentInstanceInfo uploadComponentInstanceInfo = uploadComponentInstanceInfoEntry.getValue();
// updating type if the type is node type name - we need to take the
// updated name
- log.debug("*************Going to create resource instance {}", uploadComponentInstanceInfo.getName());
+ log.debug("*************Going to create resource instances {}", uploadComponentInstanceInfo.getName());
if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
uploadComponentInstanceInfo.setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
}
@@ -4355,7 +4447,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ComponentTypeEnum containerComponentType = resource.getComponentType();
NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
- //************
+
if (containerNodeType.equals(NodeTypeEnum.Resource) && MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilities()) && MapUtils.isNotEmpty(refResource.getCapabilities())) {
setCapabilityNamesTypes(refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities());
Either<Map<String, List<CapabilityDefinition>>, ResponseFormat> getValidComponentInstanceCapabilitiesRes = getValidComponentInstanceCapabilities(refResource.getUniqueId(), refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities());
@@ -4365,9 +4457,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
componentInstance.setCapabilities(getValidComponentInstanceCapabilitiesRes.left().value());
}
}
- //***********************
if (!existingnodeTypeMap.containsKey(uploadComponentInstanceInfo.getType())) {
- log.debug("createResourceInstances - not found latest version for resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ log.debug("createResourceInstances - not found lates version for resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
return Either.right(responseFormat);
}
@@ -4417,30 +4508,28 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(eitherGerResource.left().value());
}
-
+
private void setCapabilityNamesTypes(Map<String, List<CapabilityDefinition>> originCapabilities, Map<String, List<UploadCapInfo>> uploadedCapabilities) {
for(Entry<String, List<UploadCapInfo>> currEntry : uploadedCapabilities.entrySet()){
if(originCapabilities.containsKey(currEntry.getKey())){
currEntry.getValue().stream().forEach(cap -> cap.setType(currEntry.getKey()));
}
}
-
for(Map.Entry<String, List<CapabilityDefinition>> capabilities : originCapabilities.entrySet()){
capabilities.getValue().stream().forEach(cap -> {if(uploadedCapabilities.containsKey(cap.getName())){uploadedCapabilities.get(cap.getName()).stream().forEach(c -> {c.setName(cap.getName());c.setType(cap.getType());});};});
- }
+ }
+
}
-
-
private Either<Resource, ResponseFormat> validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo, Map<String, Resource> nodeNamespaceMap) {
- log.debug("going to validate resource instance with name {} and type {} before create", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ log.debug("validateResourceInstanceBeforeCreate - going to validate resource instance with name {} and type before create", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
Resource refResource = null;
if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType());
} else {
Either<Resource, StorageOperationStatus> findResourceEither = toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(uploadComponentInstanceInfo.getType());
if (findResourceEither.isRight()) {
- log.debug("not found lates version for resource instance with name {} and type {}", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ log.debug("validateResourceInstanceBeforeCreate - not found lates version for resource instance with name {} and type ", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(findResourceEither.right().value()));
return Either.right(responseFormat);
}
@@ -4449,17 +4538,16 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState();
if (componentState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
- log.debug("component instance of component {} can not be created because the component is in an illegal state {}.", refResource.getName(), componentState);
+ log.debug("validateResourceInstanceBeforeCreate - component instance of component {} can not be created because the component is in an illegal state {}.", refResource.getName(), componentState);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE, refResource.getComponentType().getValue(), refResource.getName(), componentState);
return Either.right(responseFormat);
}
- if (!ToscaUtils.isAtomicType(refResource) && refResource.getResourceType() != ResourceTypeEnum.CVFC) {
- log.debug("ref resource type is {}", refResource.getResourceType());
+ if (!ModelConverter.isAtomicComponent(refResource) && refResource.getResourceType() != ResourceTypeEnum.CVFC) {
+ log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", refResource.getResourceType());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
return Either.right(responseFormat);
}
- log.debug("validate resource instance with name {} and type {} before create, successful",uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
return Either.left(refResource);
}
@@ -4788,32 +4876,30 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
-
@SuppressWarnings("unchecked")
- private Either<Map<String, List<UploadCapInfo>>, ResponseFormat> createCapModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
- Map<String, List<UploadCapInfo>> moduleCap = new HashMap<String, List<UploadCapInfo>>();
- Either<Map<String, List<UploadCapInfo>>, ResponseFormat> response = Either.left(moduleCap);
- Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ToscaTagNamesEnum.CAPABILITIES);
- if (toscaRequirements.isLeft()) {
- List<Object> jsonCapabilities = toscaRequirements.left().value();
-
- for (Object jsonCapObj : jsonCapabilities) {
- // Requirement
- Map<String, Object> capJsonWrapper = (Map<String, Object>) jsonCapObj;
- String capName = capJsonWrapper.keySet().iterator().next();
- Either<UploadCapInfo, ResponseFormat> eitherCap = createModuleNodeTemplateCap(capJsonWrapper.get(capName));
+ private Either<Map<String, List<UploadReqInfo>>, ResponseFormat> createReqModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
+ Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<String, List<UploadReqInfo>>();
+ Either<Map<String, List<UploadReqInfo>>, ResponseFormat> response = Either.left(moduleRequirements);
+ Either<List<Object>, ResultStatusEnum> requirementsListRes = ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ToscaTagNamesEnum.REQUIREMENTS);
+
+ if (requirementsListRes.isLeft()) {
+ for (Object jsonReqObj : requirementsListRes.left().value()) {
+ String reqName = ((Map<String, Object>) jsonReqObj).keySet().iterator().next();
+ Object reqJson = ((Map<String, Object>) jsonReqObj).get(reqName);
+ Either<UploadReqInfo, ResponseFormat> eitherCap = addModuleNodeTemplateReq(nodeTemplateInfo, moduleRequirements, reqJson, reqName);
if (eitherCap.isRight()) {
- log.info("error when creating Requirement:{}, for node:{}", capName, nodeTemplateInfo);
return Either.right(eitherCap.right().value());
- } else {
- UploadCapInfo requirementDef = eitherCap.left().value();
- requirementDef.setName(capName);
- if (moduleCap.containsKey(capName)) {
- moduleCap.get(capName).add(requirementDef);
- } else {
- List<UploadCapInfo> list = new ArrayList<UploadCapInfo>();
- list.add(requirementDef);
- moduleCap.put(capName, list);
+ }
+ }
+ } else {
+ Either<Map<String,Object>, ResultStatusEnum> requirementsMapRes = ImportUtils.findFirstToscaMapElement(nodeTemplateJsonMap, ToscaTagNamesEnum.REQUIREMENTS);
+ if (requirementsMapRes.isLeft()) {
+ for (Map.Entry<String, Object> entry: requirementsMapRes.left().value().entrySet()) {
+ String reqName = entry.getKey();
+ Object reqJson = entry.getValue();
+ Either<UploadReqInfo, ResponseFormat> eitherCap = addModuleNodeTemplateReq(nodeTemplateInfo, moduleRequirements, reqJson, reqName);
+ if (eitherCap.isRight()) {
+ return Either.right(eitherCap.right().value());
}
}
}
@@ -4821,31 +4907,49 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return response;
}
- @SuppressWarnings("unchecked")
- private Either<Map<String, List<UploadReqInfo>>, ResponseFormat> createReqModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
- Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<String, List<UploadReqInfo>>();
- Either<Map<String, List<UploadReqInfo>>, ResponseFormat> response = Either.left(moduleRequirements);
- Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ToscaTagNamesEnum.REQUIREMENTS);
- if (toscaRequirements.isLeft()) {
- List<Object> jsonRequirements = toscaRequirements.left().value();
-
- for (Object jsonRequirementObj : jsonRequirements) {
- // Requirement
- Map<String, Object> requirementJsonWrapper = (Map<String, Object>) jsonRequirementObj;
- String requirementName = requirementJsonWrapper.keySet().iterator().next();
- Either<UploadReqInfo, ResponseFormat> eitherRequirement = createModuleNodeTemplateReg(requirementJsonWrapper.get(requirementName));
- if (eitherRequirement.isRight()) {
- log.info("error when creating Requirement:{}, for node:{}", requirementName, nodeTemplateInfo);
- return Either.right(eitherRequirement.right().value());
- } else {
- UploadReqInfo requirementDef = eitherRequirement.left().value();
- requirementDef.setName(requirementName);
- if (moduleRequirements.containsKey(requirementName)) {
- moduleRequirements.get(requirementName).add(requirementDef);
- } else {
- List<UploadReqInfo> list = new ArrayList<UploadReqInfo>();
- list.add(requirementDef);
- moduleRequirements.put(requirementName, list);
+ private Either<UploadReqInfo, ResponseFormat> addModuleNodeTemplateReq(UploadComponentInstanceInfo nodeTemplateInfo,Map<String, List<UploadReqInfo>> moduleRequirements, Object requirementJson, String requirementName) {
+
+ Either<UploadReqInfo, ResponseFormat> eitherRequirement = createModuleNodeTemplateReg(requirementJson);
+ if (eitherRequirement.isRight()) {
+ log.info("error when creating Requirement:{}, for node:{}", requirementName, nodeTemplateInfo);
+ return Either.right(eitherRequirement.right().value());
+ } else {
+ UploadReqInfo requirementDef = eitherRequirement.left().value();
+ requirementDef.setName(requirementName);
+ if (moduleRequirements.containsKey(requirementName)) {
+ moduleRequirements.get(requirementName).add(requirementDef);
+ } else {
+ List<UploadReqInfo> list = new ArrayList<UploadReqInfo>();
+ list.add(requirementDef);
+ moduleRequirements.put(requirementName, list);
+ }
+ }
+ return Either.left(eitherRequirement.left().value());
+ }
+
+ @SuppressWarnings("unchecked")
+ private Either<Map<String, List<UploadCapInfo>>, ResponseFormat> createCapModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
+ Map<String, List<UploadCapInfo>> moduleCap = new HashMap<>();
+ Either<Map<String, List<UploadCapInfo>>, ResponseFormat> response = Either.left(moduleCap);
+ Either<List<Object>, ResultStatusEnum> capabilitiesListRes = ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ToscaTagNamesEnum.CAPABILITIES);
+ if (capabilitiesListRes.isLeft()) {
+ for (Object jsonCapObj : capabilitiesListRes.left().value()) {
+ String key = ((Map<String, Object>) jsonCapObj).keySet().iterator().next();
+ Object capJson = ((Map<String, Object>) jsonCapObj).get(key);
+ Either<UploadCapInfo, ResponseFormat> eitherCap = addModuleNodeTemplateCap(nodeTemplateInfo, moduleCap, capJson, key);
+ if (eitherCap.isRight()) {
+ return Either.right(eitherCap.right().value());
+ }
+ }
+ } else {
+ Either<Map<String,Object>, ResultStatusEnum> capabilitiesMapRes = ImportUtils.findFirstToscaMapElement(nodeTemplateJsonMap, ToscaTagNamesEnum.CAPABILITIES);
+ if (capabilitiesMapRes.isLeft()) {
+ for (Map.Entry<String, Object> entry: capabilitiesMapRes.left().value().entrySet()) {
+ String capName = entry.getKey();
+ Object capJson = entry.getValue();
+ Either<UploadCapInfo, ResponseFormat> eitherCap = addModuleNodeTemplateCap(nodeTemplateInfo, moduleCap, capJson, capName);
+ if (eitherCap.isRight()) {
+ return Either.right(eitherCap.right().value());
}
}
}
@@ -4853,6 +4957,26 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return response;
}
+ private Either<UploadCapInfo, ResponseFormat> addModuleNodeTemplateCap(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, List<UploadCapInfo>> moduleCap, Object capJson, String key) {
+
+ Either<UploadCapInfo, ResponseFormat> eitherCap = createModuleNodeTemplateCap(capJson);
+ if (eitherCap.isRight()) {
+ log.info("error when creating Capability:{}, for node:{}", key, nodeTemplateInfo);
+ return Either.right(eitherCap.right().value());
+ } else {
+ UploadCapInfo capabilityDef = eitherCap.left().value();
+ capabilityDef.setKey(key);
+ if (moduleCap.containsKey(key)) {
+ moduleCap.get(key).add(capabilityDef);
+ } else {
+ List<UploadCapInfo> list = new ArrayList<UploadCapInfo>();
+ list.add(capabilityDef);
+ moduleCap.put(key, list);
+ }
+ }
+ return Either.left( eitherCap.left().value());
+ }
+
@SuppressWarnings("unchecked")
private Either<UploadCapInfo, ResponseFormat> createModuleNodeTemplateCap(Object capObject) {
UploadCapInfo capTemplateInfo = new UploadCapInfo();
@@ -5065,6 +5189,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
result = Either.right(validateFieldsResponse.right().value());
return result;
}
+
+ validateFieldsResponse = validateCapabilityTypesCreate(user, getCapabilityTypeOperation(), newResource, AuditingActionEnum.IMPORT_RESOURCE, inTransaction);
+ if (validateFieldsResponse.isRight()) {
+ return Either.right(validateFieldsResponse.right().value());
+ }
// contact info normalization
newResource.setContactId(newResource.getContactId().toLowerCase());
@@ -5201,7 +5330,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resource.setCreatorUserId(user.getUserId());
resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
resource.setContactId(resource.getContactId().toLowerCase());
- if (StringUtils.isEmpty(resource.getToscaResourceName()) && !ToscaUtils.isAtomicType(resource)) {
+ if (StringUtils.isEmpty(resource.getToscaResourceName()) && !ModelConverter.isAtomicComponent(resource)) {
String resourceSystemName;
if(csarInfo != null && StringUtils.isNotEmpty(csarInfo.getVfResourceName())){
resourceSystemName = ValidationUtils.convertToSystemName(csarInfo.getVfResourceName());
@@ -5370,11 +5499,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
try {
if (resource.deriveFromGeneric()) {
- Either<Resource, ResponseFormat> genericResourceEither = fetchAndSetDerivedFromGenericType(resource);
+ Either<Resource, ResponseFormat> genericResourceEither = handleResourceGenericType(resource);
if (genericResourceEither.isRight())
return genericResourceEither;
- if (resource.shouldGenerateInputs())
- generateInputsFromGenericTypeProperties(resource, genericResourceEither.left().value());
}
Either<Resource, ResponseFormat> respStatus = createResourceTransaction(resource, user, isNormative, inTransaction);
@@ -5739,7 +5866,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// list
// This code is not called from import resources, because of root
// VF "derivedFrom" should be null (or ignored)
- if (ToscaUtils.isAtomicType(currentResource)) {
+ if (ModelConverter.isAtomicComponent(currentResource)) {
Either<Boolean, ResponseFormat> derivedFromNotEmptyEither = validateDerivedFromNotEmpty(null, newResource, null);
if (derivedFromNotEmptyEither.isRight()) {
log.debug("for updated resource {}, derived from field is empty", newResource.getName());
@@ -5953,7 +6080,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// validate template (derived from)
log.debug("validate derived from");
- if (!ToscaUtils.isAtomicType(resource) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
+ if (!ModelConverter.isAtomicComponent(resource) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
resource.setDerivedFrom(null);
}
eitherValidation = validateDerivedFromExist(user, resource, actionEnum);
@@ -6173,10 +6300,23 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
* return Either.left(true); }
*/
- private Either<Boolean, ResponseFormat> validateResourceName(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
+ private boolean isResourceNameEquals(Resource currentResource, Resource updateInfoResource) {
String resourceNameUpdated = updateInfoResource.getName();
String resourceNameCurrent = currentResource.getName();
- if (!resourceNameCurrent.equals(resourceNameUpdated)) {
+ if (resourceNameCurrent.equals(resourceNameUpdated))
+ return true;
+ // In case of CVFC type we should support the case of old VF with CVFC instances that were created without the "Cvfc" suffix
+ return (currentResource.getResourceType().equals(ResourceTypeEnum.CVFC)
+ && resourceNameUpdated.equals(addCvfcSuffixToResourceName(resourceNameCurrent)));
+ }
+
+ private String addCvfcSuffixToResourceName(String resourceName) {
+ return resourceName+"Cvfc";
+ }
+
+ private Either<Boolean, ResponseFormat> validateResourceName(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
+ String resourceNameUpdated = updateInfoResource.getName();
+ if (!isResourceNameEquals(currentResource, updateInfoResource)) {
if (!hasBeenCertified) {
Either<Boolean, ResponseFormat> validateResourceNameResponse = validateComponentName(null, updateInfoResource, null);
if (validateResourceNameResponse.isRight()) {
@@ -7222,5 +7362,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
UiComponentDataTransfer dataTransfer = UiComponentDataConverter.getUiDataTransferFromResourceByParams(resource, dataParamsToReturn);
return Either.left(dataTransfer);
}
+ @Override
+ public Either<Component, ActionStatus> shouldUpgradeToLatestDerived(Component clonedComponent) {
+ Resource resource = (Resource) clonedComponent;
+ if (ModelConverter.isAtomicComponent(resource.getResourceType())) {
+ Either<Component, StorageOperationStatus> shouldUpgradeToLatestDerived = toscaOperationFacade.shouldUpgradeToLatestDerived(resource);
+ if (shouldUpgradeToLatestDerived.isRight()) {
+ return Either.right(componentsUtils.convertFromStorageResponse(shouldUpgradeToLatestDerived.right().value()));
+ }
+ return Either.left(shouldUpgradeToLatestDerived.left().value());
+ } else {
+ return super.shouldUpgradeToLatestDerived(clonedComponent);
+ }
+ }
+
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
index fa051a9e3d..0f1bf4603d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
@@ -49,11 +49,11 @@ public class ArtifactTemplateInfo {
public static final String ENV = "env";
public static final String IS_BASE = "isBase";
- private static final String CSAR_HEAT = "HEAT";
- private static final String CSAR_ARTIFACT = "artifacts";
- private static final String CSAR_NETWORK = "network";
- private static final String CSAR_VOLUME = "volume";
- private static final String CSAR_NESTED = "nested";
+ public static final String CSAR_HEAT = "HEAT";
+ public static final String CSAR_ARTIFACT = "artifacts";
+ public static final String CSAR_NETWORK = "network";
+ public static final String CSAR_VOLUME = "volume";
+ public static final String CSAR_NESTED = "nested";
private static final Object DESC = "description";
private static Logger log = LoggerFactory.getLogger(ArtifactTemplateInfo.class.getName());
String type;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java
index 649f083903..41268188f9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java
@@ -22,11 +22,16 @@
package org.openecomp.sdc.be.tosca;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
@@ -34,9 +39,14 @@ import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.tosca.ToscaUtils.SubstituitionEntry;
import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
import org.openecomp.sdc.be.tosca.model.ToscaCapability;
import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
@@ -47,14 +57,29 @@ import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import fj.data.Either;
-
+/**
+ * Allows to convert requirements\capabilities of a component to requirements\capabilities of a substitution mappings section of a tosca template
+ *
+ */
+@org.springframework.stereotype.Component("capabilty-requirement-convertor")
+@Scope(value = "singleton")
public class CapabiltyRequirementConvertor {
+
+ private static final String NO_CAPABILITIES = "No Capabilities for node type";
private static CapabiltyRequirementConvertor instance;
- public final static String PATH_DELIMITER = ".";
+ private static Logger logger = LoggerFactory.getLogger(CapabiltyRequirementConvertor.class.getName());
+ public static final String PATH_DELIMITER = ".";
+
+ @Autowired
+ private ToscaOperationFacade toscaOperationFacade;
protected CapabiltyRequirementConvertor() {
@@ -66,9 +91,13 @@ public class CapabiltyRequirementConvertor {
}
return instance;
}
-
- private static Logger log = LoggerFactory.getLogger(CapabiltyRequirementConvertor.class.getName());
-
+ /**
+ * Allows to convert capabilities of a component to capabilities of a substitution mappings section of a tosca template
+ * @param componentInstance
+ * @param dataTypes
+ * @param nodeTemplate
+ * @return
+ */
public Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceCapabilties(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, ToscaNodeTemplate nodeTemplate) {
Map<String, List<CapabilityDefinition>> capabilitiesInst = componentInstance.getCapabilities();
@@ -77,12 +106,10 @@ public class CapabiltyRequirementConvertor {
capabilitiesInst.entrySet().forEach(e -> {
List<CapabilityDefinition> capList = e.getValue();
if (capList != null && !capList.isEmpty()) {
- capList.forEach(c -> {
- convertOverridenProperties(componentInstance, dataTypes, capabilties, c);
- });
+ capList.forEach(c -> convertOverridenProperties(componentInstance, dataTypes, capabilties, c));
}
});
- if (capabilties != null && !capabilties.isEmpty()) {
+ if (MapUtils.isNotEmpty(capabilties)) {
nodeTemplate.setCapabilities(capabilties);
}
}
@@ -92,15 +119,16 @@ public class CapabiltyRequirementConvertor {
private void convertOverridenProperties(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, Map<String, ToscaTemplateCapability> capabilties, CapabilityDefinition c) {
List<ComponentInstanceProperty> properties = c.getProperties();
if (properties != null && !properties.isEmpty()) {
- properties.stream().filter(p -> (p.getValueUniqueUid() != null)).forEach(p -> {
- convertOverridenProperty(componentInstance, dataTypes, capabilties, c, p);
- });
+ properties
+ .stream()
+ .filter(p -> p.getValue() != null || p.getDefaultValue() != null)
+ .forEach(p -> convertOverridenProperty(componentInstance, dataTypes, capabilties, c, p));
}
}
private void convertOverridenProperty(ComponentInstance componentInstance, Map<String, DataTypeDefinition> dataTypes, Map<String, ToscaTemplateCapability> capabilties, CapabilityDefinition c, ComponentInstanceProperty p) {
- if (log.isDebugEnabled()) {
- log.debug("Exist overriden property {} for capabity {} with value {}", p.getName(), c.getName(), p.getValue());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Exist overriden property {} for capabity {} with value {}", p.getName(), c.getName(), p.getValue());
}
ToscaTemplateCapability toscaTemplateCapability = capabilties.get(c.getName());
if (toscaTemplateCapability == null) {
@@ -117,109 +145,224 @@ public class CapabiltyRequirementConvertor {
}
private Object convertInstanceProperty(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance, ComponentInstanceProperty prop) {
- log.debug("Convert property {} for instance {}", prop.getName(), componentInstance.getUniqueId());
+ logger.debug("Convert property {} for instance {}", prop.getName(), componentInstance.getUniqueId());
String propertyType = prop.getType();
String innerType = null;
if (prop.getSchema() != null && prop.getSchema().getProperty() != null) {
innerType = prop.getSchema().getProperty().getType();
}
- Object convertedValue = PropertyConvertor.getInstance().convertToToscaObject(propertyType, prop.getValue(), innerType, dataTypes);
- return convertedValue;
+ String propValue = prop.getValue() == null ? prop.getDefaultValue() : prop.getValue();
+ return PropertyConvertor.getInstance().convertToToscaObject(propertyType, propValue, innerType, dataTypes);
}
-
+ /**
+ * Allows to convert requirements of a node type to tosca template requirements representation
+ * @param component
+ * @param nodeType
+ * @return
+ */
public Either<ToscaNodeType, ToscaError> convertRequirements(Component component, ToscaNodeType nodeType) {
List<Map<String, ToscaRequirement>> toscaRequirements = convertRequirementsAsList(component);
if (!toscaRequirements.isEmpty()) {
nodeType.setRequirements(toscaRequirements);
}
- log.debug("Finish convert Requirements for node type");
+ logger.debug("Finish convert Requirements for node type");
return Either.left(nodeType);
}
- public Either<SubstitutionMapping, ToscaError> convertSubstitutionMappingRequirements(Component component, SubstitutionMapping substitutionMapping) {
- Map<String, String[]> toscaRequirements = convertSubstitutionMappingRequirementsAsMap(component);
- if (!toscaRequirements.isEmpty()) {
- substitutionMapping.setRequirements(toscaRequirements);
+ /**
+ * Allows to convert component requirements to the tosca template substitution mappings requirements
+ * @param componentsCache
+ * @param component
+ * @param substitutionMappings
+ * @return
+ */
+ public Either<SubstitutionMapping, ToscaError> convertSubstitutionMappingRequirements(Map<String,Component> componentsCache, Component component, SubstitutionMapping substitutionMappings) {
+ Either<SubstitutionMapping, ToscaError> result = Either.left(substitutionMappings);
+ Either<Map<String, String[]>, ToscaError> toscaRequirementsRes = convertSubstitutionMappingRequirementsAsMap(componentsCache, component);
+ if(toscaRequirementsRes.isRight()){
+ result = Either.right(toscaRequirementsRes.right().value());
+ logger.error("Failed convert requirements for the component {}. ", component.getName());
+ } else if (MapUtils.isNotEmpty(toscaRequirementsRes.left().value())) {
+ substitutionMappings.setRequirements(toscaRequirementsRes.left().value());
+ result = Either.left(substitutionMappings);
+ logger.debug("Finish convert requirements for the component {}. ", component.getName());
}
- log.debug("Finish convert Requirements for node type");
-
- return Either.left(substitutionMapping);
+ return result;
}
private List<Map<String, ToscaRequirement>> convertRequirementsAsList(Component component) {
Map<String, List<RequirementDefinition>> requirements = component.getRequirements();
List<Map<String, ToscaRequirement>> toscaRequirements = new ArrayList<>();
if (requirements != null) {
- boolean isNodeType = ToscaUtils.isAtomicType(component);
for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
- entry.getValue().stream().filter(r -> (!isNodeType || (isNodeType && component.getUniqueId().equals(r.getOwnerId())) || (isNodeType && r.getOwnerId() == null))).forEach(r -> {
- ImmutablePair<String, ToscaRequirement> pair = convertRequirement(component, isNodeType, r);
+ entry.getValue().stream().filter(r -> filter(component, r.getOwnerId())).forEach(r -> {
+ ImmutablePair<String, ToscaRequirement> pair = convertRequirement(component, ModelConverter.isAtomicComponent(component), r);
Map<String, ToscaRequirement> requirement = new HashMap<>();
requirement.put(pair.left, pair.right);
toscaRequirements.add(requirement);
});
-
- log.debug("Finish convert Requirements for node type");
+ logger.debug("Finish convert Requirements for node type");
}
} else {
- log.debug("No Requirements for node type");
+ logger.debug("No Requirements for node type");
}
return toscaRequirements;
}
- private String getSubPathByFirstDelimiterAppearance(String path) {
- return path.substring(path.indexOf(PATH_DELIMITER) + 1);
+ private boolean filter(Component component, String ownerId) {
+ return !ModelConverter.isAtomicComponent(component) || isNodeTypeOwner(component, ownerId) || (ModelConverter.isAtomicComponent(component) && ownerId == null);
+ }
+
+ private boolean isNodeTypeOwner(Component component, String ownerId) {
+ return ModelConverter.isAtomicComponent(component) && component.getUniqueId().equals(ownerId);
}
private String getSubPathByLastDelimiterAppearance(String path) {
return path.substring(path.lastIndexOf(PATH_DELIMITER) + 1);
}
-
- //This function calls on Substitution Mapping region - the component is always non-atomic
- private Map<String, String[]> convertSubstitutionMappingRequirementsAsMap(Component component) {
+
+ private Either<Map<String, String[]>, ToscaError> convertSubstitutionMappingRequirementsAsMap(Map<String, Component> componentsCache, Component component) {
Map<String, List<RequirementDefinition>> requirements = component.getRequirements();
- Map<String, String[]> toscaRequirements = new HashMap<>();
+ Either<Map<String, String[]>, ToscaError> result;
if (requirements != null) {
- for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
- entry.getValue().stream().forEach(r -> {
- String fullReqName;
- String sourceCapName;
- if(ToscaUtils.isComplexVfc(component)){
- fullReqName = r.getName();
- sourceCapName = r.getParentName();
- } else {
- fullReqName = getRequirementPath(r);
- sourceCapName = getSubPathByFirstDelimiterAppearance(fullReqName);
- }
- log.debug("the requirement {} belongs to resource {} ", fullReqName, component.getUniqueId());
- if(sourceCapName!= null){
- toscaRequirements.put(fullReqName, new String[]{r.getOwnerName(), sourceCapName});
- }
- });
- log.debug("Finish convert Requirements for node type");
- }
+ result = buildAddSubstitutionMappingsRequirements(componentsCache, component, requirements);
} else {
- log.debug("No Requirements for node type");
+ result = Either.left(Maps.newHashMap());
+ logger.debug("No requirements for substitution mappings section of a tosca template of the component {}. ", component.getName());
}
- return toscaRequirements;
+ return result;
}
- private String getRequirementPath(RequirementDefinition r) {
- List<String> pathArray = Lists.reverse(r.getPath().stream()
- .map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path)))
- .collect(Collectors.toList()));
- return new StringBuilder().append(String.join(PATH_DELIMITER, pathArray)).append(PATH_DELIMITER).append(r.getName()).toString();
+ private Either<Map<String, String[]>, ToscaError> buildAddSubstitutionMappingsRequirements(Map<String, Component> componentsCache, Component component, Map<String, List<RequirementDefinition>> requirements) {
+
+ Map<String, String[]> toscaRequirements = new HashMap<>();
+ Either<Map<String, String[]>, ToscaError> result = null;
+ for (Map.Entry<String, List<RequirementDefinition>> entry : requirements.entrySet()) {
+ Optional<RequirementDefinition> failedToAddRequirement = entry.getValue()
+ .stream()
+ .filter(r->!addEntry(componentsCache, toscaRequirements, component, r.getName(), r.getParentName(), r.getPath()))
+ .findAny();
+ if(failedToAddRequirement.isPresent()){
+ logger.error("Failed to convert requirement {} for substitution mappings section of a tosca template of the component {}. ",
+ failedToAddRequirement.get().getName(), component.getName());
+ result = Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
+ }
+ logger.debug("Finish convert requirements for the component {}. ", component.getName());
+ }
+ if(result == null){
+ result = Either.left(toscaRequirements);
+ }
+ return result;
+ }
+
+ private Either<Map<String, String[]>, ToscaError> buildAddSubstitutionMappingsCapabilities(Map<String, Component> componentsCache, Component component, Map<String, List<CapabilityDefinition>> capabilities) {
+ Map<String, String[]> toscaRequirements = new HashMap<>();
+ Either<Map<String, String[]>, ToscaError> result = null;
+ for (Map.Entry<String, List<CapabilityDefinition>> entry : capabilities.entrySet()) {
+ Optional<CapabilityDefinition> failedToAddRequirement = entry.getValue()
+ .stream()
+ .filter(c->!addEntry(componentsCache, toscaRequirements, component, c.getName(), c.getParentName(), c.getPath()))
+ .findAny();
+ if(failedToAddRequirement.isPresent()){
+ logger.error("Failed to convert capalility {} for substitution mappings section of a tosca template of the component {}. ",
+ failedToAddRequirement.get().getName(), component.getName());
+ result = Either.right(ToscaError.NODE_TYPE_CAPABILITY_ERROR);
+ }
+ logger.debug("Finish convert capalilities for the component {}. ", component.getName());
+ }
+ if(result == null){
+ result = Either.left(toscaRequirements);
+ }
+ return result;
}
+ private boolean addEntry(Map<String,Component> componentsCache, Map<String, String[]> capReqMap, Component component, String name, String parentName, List<String> path){
+
+ SubstituitionEntry entry = new SubstituitionEntry(name, parentName, "");
+
+ if(shouldBuildSubstitutionName(component, path) && !buildSubstitutedNamePerInstance(componentsCache, component, name, path, entry)){
+ return false;
+ }
+ logger.debug("The requirement/capability {} belongs to the component {} ", entry.getFullName(), component.getUniqueId());
+ if (entry.getSourceName() != null) {
+ addEntry(capReqMap, component, path, entry);
+ }
+ logger.debug("Finish convert the requirement/capability {} for the component {}. ", entry.getFullName(), component.getName());
+ return true;
+
+ }
+
+ private boolean shouldBuildSubstitutionName(Component component, List<String> path) {
+ return !ToscaUtils.isComplexVfc(component) && CollectionUtils.isNotEmpty(path) && path.iterator().hasNext();
+ }
+
+ private boolean buildSubstitutedNamePerInstance(Map<String, Component> componentsCache, Component component, String name, List<String> path, SubstituitionEntry entry) {
+ Optional<ComponentInstance> ci = component.getComponentInstances().stream().filter(c->c.getUniqueId().equals(Iterables.getLast(path))).findFirst();
+ if(ci.isPresent()){
+ Either<String, Boolean> buildSubstitutedName = buildSubstitutedName(componentsCache, name, path, ci.get());
+ if(buildSubstitutedName.isRight()){
+ return false;
+ }
+ entry.setFullName(ci.get().getNormalizedName() + '.' + buildSubstitutedName.left().value());
+ entry.setSourceName(buildSubstitutedName.left().value());
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ private void addEntry(Map<String, String[]> toscaRequirements, Component component, List<String> capPath, SubstituitionEntry entry) {
+ Optional<ComponentInstance> findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(Iterables.getLast(capPath))).findFirst();
+ if (findFirst.isPresent()) {
+ entry.setOwner(findFirst.get().getNormalizedName());
+ }
+ toscaRequirements.put(entry.getFullName(), new String[] { entry.getOwner(), entry.getSourceName() });
+ }
+
+ private Either<String, Boolean> buildSubstitutedName(Map<String, Component> componentsCache, String name, List<String> path, ComponentInstance instance) {
+
+ Either<String, Boolean> result = null;
+ Either<Component, Boolean> getOriginRes = getOriginComponent(componentsCache, instance);
+ if(getOriginRes.isRight()){
+ logger.debug("Failed to build substituted name for the capability/requirement {}. Failed to get an origin component with uniqueId {}", name, instance.getComponentUid());
+ result = Either.right(false);
+ }
+ if(result == null){
+ result = buildSubstitutedName(componentsCache, getOriginRes.left().value(), Lists.newArrayList(path.subList(0, path.size()-1)), name);
+ }
+ return result;
+ }
+
+ private String getRequirementPath(Component component, RequirementDefinition r) {
+
+ // Evg : for the last in path take real instance name and not "decrypt" unique id. ( instance name can be change and not equal to id..)
+ // dirty quick fix. must be changed as capability redesign
+ List<String> capPath = r.getPath();
+ String lastInPath = capPath.get(capPath.size() - 1);
+ Optional<ComponentInstance> findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst();
+ if (findFirst.isPresent()) {
+ String lastInPathName = findFirst.get().getNormalizedName();
+
+ if (capPath.size() > 1) {
+ List<String> pathArray = Lists.reverse(capPath.stream().map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))).collect(Collectors.toList()));
+
+ return new StringBuilder().append(lastInPathName).append(PATH_DELIMITER).append(String.join(PATH_DELIMITER, pathArray.subList(1, pathArray.size() ))).append(PATH_DELIMITER).append(r.getName()).toString();
+ }else{
+ return new StringBuilder().append(lastInPathName).append(PATH_DELIMITER).append(r.getName()).toString();
+ }
+ }
+ return "";
+ }
+
private ImmutablePair<String, ToscaRequirement> convertRequirement(Component component, boolean isNodeType, RequirementDefinition r) {
String name = r.getName();
if (!isNodeType) {
- name = getRequirementPath(r);
+ name = getRequirementPath(component, r);
}
- log.debug("the requirement {} belongs to resource {} ", name, component.getUniqueId());
+ logger.debug("the requirement {} belongs to resource {} ", name, component.getUniqueId());
ToscaRequirement toscaRequirement = new ToscaRequirement();
List<Object> occurences = new ArrayList<>();
@@ -230,78 +373,101 @@ public class CapabiltyRequirementConvertor {
occurences.add(Integer.valueOf(r.getMaxOccurrences()));
}
toscaRequirement.setOccurrences(occurences);
- // toscaRequirement.setOccurrences(createOcurrencesRange(requirementDefinition.getMinOccurrences(),
- // requirementDefinition.getMaxOccurrences()));
toscaRequirement.setNode(r.getNode());
toscaRequirement.setCapability(r.getCapability());
toscaRequirement.setRelationship(r.getRelationship());
- ImmutablePair<String, ToscaRequirement> pair = new ImmutablePair<String, ToscaRequirement>(name, toscaRequirement);
- return pair;
+ return new ImmutablePair<>(name, toscaRequirement);
}
+ /**
+ * Allows to convert capabilities of a node type to tosca template capabilities
+ * @param component
+ * @param dataTypes
+ * @return
+ */
public Map<String, ToscaCapability> convertCapabilities(Component component, Map<String, DataTypeDefinition> dataTypes) {
Map<String, List<CapabilityDefinition>> capabilities = component.getCapabilities();
Map<String, ToscaCapability> toscaCapabilities = new HashMap<>();
if (capabilities != null) {
- boolean isNodeType = ToscaUtils.isAtomicType(component);
+ boolean isNodeType = ModelConverter.isAtomicComponent(component);
for (Map.Entry<String, List<CapabilityDefinition>> entry : capabilities.entrySet()) {
- entry.getValue().stream().filter(c -> (!isNodeType || (isNodeType && component.getUniqueId().equals(c.getOwnerId())) || (isNodeType && c.getOwnerId() == null) )).forEach(c -> {
- convertCapabilty(component, toscaCapabilities, isNodeType, c, dataTypes);
-
- });
+ entry.getValue().stream().filter(c -> filter(component, c.getOwnerId())).forEach(c -> convertCapabilty(component, toscaCapabilities, isNodeType, c, dataTypes));
}
} else {
- log.debug("No Capabilities for node type");
+ logger.debug(NO_CAPABILITIES);
}
return toscaCapabilities;
}
-
- //This function calls on Substitution Mapping region - the component is always non-atomic
- public Map<String, String[]> convertSubstitutionMappingCapabilities(Component component, Map<String, DataTypeDefinition> dataTypes) {
- Map<String, List<CapabilityDefinition>> capabilities = component.getCapabilities();
- Map<String, String[]> toscaCapabilities = new HashMap<>();
+
+ /**
+ * Allows to convert capabilities of a server proxy node type to tosca template capabilities
+ * @param component
+ * @param proxyComponent
+ * @param instanceProxy
+ * @param dataTypes
+ * @return
+ */
+ public Map<String, ToscaCapability> convertProxyCapabilities(Component component, Component proxyComponent, ComponentInstance instanceProxy, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, List<CapabilityDefinition>> capabilities = instanceProxy.getCapabilities();
+ Map<String, ToscaCapability> toscaCapabilities = new HashMap<>();
if (capabilities != null) {
+ boolean isNodeType = ModelConverter.isAtomicComponent(component);
for (Map.Entry<String, List<CapabilityDefinition>> entry : capabilities.entrySet()) {
- entry.getValue().stream().forEach(c -> {
- String fullCapName;
- String sourceReqName;
- if(ToscaUtils.isComplexVfc(component)){
- fullCapName = c.getName();
- sourceReqName = c.getParentName();
- } else {
- fullCapName = getCapabilityPath(c);
- sourceReqName = getSubPathByFirstDelimiterAppearance(fullCapName);
- }
- log.debug("the capabilty {} belongs to resource {} ", fullCapName, component.getUniqueId());
- if(sourceReqName!= null){
- toscaCapabilities.put(fullCapName, new String[]{c.getOwnerName(), sourceReqName});
- }
- });
+ entry.getValue().stream().forEach(c -> convertCapabilty(proxyComponent, toscaCapabilities, isNodeType, c, dataTypes));
}
} else {
- log.debug("No Capabilities for node type");
+ logger.debug(NO_CAPABILITIES);
}
return toscaCapabilities;
}
-
- private String getCapabilityPath(CapabilityDefinition c) {
- List<String> pathArray = Lists.reverse(c.getPath().stream()
- .map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path)))
- .collect(Collectors.toList()));
- return new StringBuilder().append(String.join(PATH_DELIMITER, pathArray)).append(PATH_DELIMITER).append(c.getName()).toString();
+
+ /**
+ * Allows to convert component capabilities to the tosca template substitution mappings capabilities
+ * @param componentsCache
+ * @param component
+ * @return
+ */
+ public Either<Map<String, String[]>, ToscaError> convertSubstitutionMappingCapabilities(Map<String, Component> componentsCache, Component component) {
+ Map<String, List<CapabilityDefinition>> capabilities = component.getCapabilities();
+ Either<Map<String, String[]>, ToscaError> res = null;
+ if (capabilities != null) {
+ res = buildAddSubstitutionMappingsCapabilities(componentsCache, component, capabilities);
+ } else {
+ logger.debug(NO_CAPABILITIES);
+ res = Either.left(new HashMap<>());
+ }
+ return res;
}
-
-
+ private String getCapabilityPath(CapabilityDefinition c, Component component) {
+ // Evg : for the last in path take real instance name and not "decrypt" unique id. ( instance name can be change and not equal to id..)
+ // dirty quick fix. must be changed as capability redesign
+ List<String> capPath = c.getPath();
+ String lastInPath = capPath.get(capPath.size() - 1);
+ Optional<ComponentInstance> findFirst = component.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(lastInPath)).findFirst();
+ if (findFirst.isPresent()) {
+ String lastInPathName = findFirst.get().getNormalizedName();
+
+ if (capPath.size() > 1) {
+ List<String> pathArray = Lists.reverse(capPath.stream().map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))).collect(Collectors.toList()));
+
+ return new StringBuilder().append(lastInPathName).append(PATH_DELIMITER).append(String.join(PATH_DELIMITER, pathArray.subList(1, pathArray.size() ))).append(PATH_DELIMITER).append(c.getName()).toString();
+ }else{
+ return new StringBuilder().append(lastInPathName).append(PATH_DELIMITER).append(c.getName()).toString();
+ }
+ }
+ return "";
+ }
+
private void convertCapabilty(Component component, Map<String, ToscaCapability> toscaCapabilities, boolean isNodeType, CapabilityDefinition c, Map<String, DataTypeDefinition> dataTypes) {
String name = c.getName();
if (!isNodeType) {
- name = getCapabilityPath(c);
+ name = getCapabilityPath(c, component);
}
- log.debug("the capabilty {} belongs to resource {} ", name, component.getUniqueId());
+ logger.debug("the capabilty {} belongs to resource {} ", name, component.getUniqueId());
ToscaCapability toscaCapability = new ToscaCapability();
toscaCapability.setDescription(c.getDescription());
toscaCapability.setType(c.getType());
@@ -327,5 +493,61 @@ public class CapabiltyRequirementConvertor {
}
toscaCapabilities.put(name, toscaCapability);
}
+
+ Either<String, Boolean> buildSubstitutedName(Map<String, Component> originComponents, Component originComponent, List<String> path, String name) {
+ StringBuilder substitutedName = new StringBuilder();
+ boolean nameBuiltSuccessfully = true;
+ Either<String, Boolean> result;
+ if(CollectionUtils.isNotEmpty(path) && !ToscaUtils.isComplexVfc(originComponent)){
+ Collections.reverse(path);
+ Iterator<String> instanceIdIter = path.iterator();
+ nameBuiltSuccessfully = appendNameRecursively(originComponents, originComponent, instanceIdIter, substitutedName);
+ }
+ if(nameBuiltSuccessfully){
+ result = Either.left(substitutedName.append(name).toString());
+ } else {
+ result = Either.right(nameBuiltSuccessfully);
+ }
+ return result;
+ }
+
+ private boolean appendNameRecursively(Map<String, Component> originComponents, Component originComponent, Iterator<String> instanceIdIter, StringBuilder substitutedName) {
+ if(CollectionUtils.isNotEmpty(originComponent.getComponentInstances()) && instanceIdIter.hasNext()){
+ String instanceId = instanceIdIter.next();
+ Optional<ComponentInstance> instanceOpt = originComponent.getComponentInstances().stream().filter(i -> i.getUniqueId().equals(instanceId)).findFirst();
+ if(!instanceOpt.isPresent()){
+ logger.debug("Failed to find an instance with uniqueId {} on a component with uniqueId {}", instanceId, originComponent.getUniqueId());
+ return false;
+ }
+ Either<Component, Boolean> getOriginRes = getOriginComponent(originComponents, instanceOpt.get());
+ if(getOriginRes.isRight()){
+ return false;
+ }
+ appendNameRecursively(originComponents, getOriginRes.left().value(), instanceIdIter, substitutedName);
+ substitutedName.append(instanceOpt.get().getNormalizedName()).append('.');
+ return true;
+ }
+ return true;
+ }
+
+ private Either<Component, Boolean> getOriginComponent(Map<String, Component> originComponents, ComponentInstance instance) {
+ Either<Component, Boolean> result;
+ Either<Component, StorageOperationStatus> getOriginRes;
+ if(originComponents.containsKey(instance.getComponentUid())){
+ result = Either.left(originComponents.get(instance.getComponentUid()));
+ } else {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstances(false);
+ getOriginRes = toscaOperationFacade.getToscaElement(instance.getComponentUid(), filter);
+ if(getOriginRes.isRight()){
+ logger.debug("Failed to get an origin component with uniqueId {}", instance.getComponentUid());
+ result = Either.right(false);
+ } else {
+ result = Either.left(getOriginRes.left().value());
+ originComponents.put(getOriginRes.left().value().getUniqueId(), getOriginRes.left().value());
+ }
+ }
+ return result;
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index a0cc347e09..2f4a385f69 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -52,6 +52,7 @@ import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.resources.data.ESArtifactData;
@@ -146,7 +147,8 @@ public class CsarUtils {
ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX +
"([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
"([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
- "([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN;
+ "([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
+ "([\\d\\w\\_\\-\\.\\s]+)";
public static final String VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN = ARTIFACTS + DEL_PATTERN+
// Artifact Group (i.e Deployment/Informational)
@@ -274,7 +276,7 @@ public class CsarUtils {
zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + fileName));
zip.write(mainYaml);
//US798487 - Abstraction of complex types
- if (!ToscaUtils.isAtomicType(component)){
+ if (!ModelConverter.isAtomicComponent(component)){
log.debug("Component {} is complex - generating abstract type for it..", component.getName());
writeComponentInterface(component, zip, fileName);
}
@@ -331,7 +333,7 @@ public class CsarUtils {
zip.write(content);
// add component interface to zip
- if (!ToscaUtils.isAtomicType(innerComponent)) {
+ if (!ModelConverter.isAtomicComponent(innerComponent)) {
writeComponentInterface(innerComponent, zip, icFileName);
}
}
@@ -452,7 +454,7 @@ public class CsarUtils {
}
//if not atomic - insert inner components as well
- if(!ToscaUtils.isAtomicType(componentRI)) {
+ if(!ModelConverter.isAtomicComponent(componentRI)) {
addInnerComponentsToCache(componentCache, componentRI);
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 8e0c312f1a..1f29eb2113 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
@@ -42,10 +43,29 @@ import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.converters.ToscaValueBaseConverter;
import org.openecomp.sdc.be.tosca.model.IToscaMetadata;
@@ -87,10 +107,10 @@ public class ToscaExportHandler {
@Autowired
private ToscaOperationFacade toscaOperationFacade;
-
- private CapabiltyRequirementConvertor capabiltyRequirementConvertor = CapabiltyRequirementConvertor.getInstance();
+ @Autowired
+ private CapabiltyRequirementConvertor capabiltyRequirementConvertor;
private PropertyConvertor propertyConvertor = PropertyConvertor.getInstance();
-
+ Map<String,Component> originComponents = new HashMap<>();
private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName());
@@ -105,9 +125,9 @@ public class ToscaExportHandler {
public static final String VOLUME_GROUP_KEY = "volume_group";
public static final String VF_MODULE_TYPE_BASE = "Base";
public static final String VF_MODULE_TYPE_EXPANSION = "Expansion";
- public static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultImports();
-
-
+ private static final String FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION = "convertToToscaTemplate - failed to get Default Imports section from configuration";
+ private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
+ protected static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS = ConfigurationManager.getConfigurationManager().getConfiguration().getDefaultImports();
public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
@@ -122,15 +142,16 @@ public class ToscaExportHandler {
}
public Either<ToscaRepresentation, ToscaError> exportComponentInterface(Component component) {
- if(null == DEFAULT_IMPORTS) {
- log.debug("convertToToscaTemplate - failed to get Default Imports section from configuration");
+ if (null == DEFAULT_IMPORTS) {
+ log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
}
ToscaTemplate toscaTemplate = new ToscaTemplate(TOSCA_VERSION);
toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS));
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(component, toscaTemplate, nodeTypes);
+ Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertInterfaceNodeType(component, toscaTemplate,
+ nodeTypes);
if (toscaTemplateRes.isRight()) {
return Either.right(toscaTemplateRes.right().value());
}
@@ -179,8 +200,8 @@ public class ToscaExportHandler {
}
private Either<ToscaTemplate, ToscaError> convertToToscaTemplate(Component component) {
- if(null == DEFAULT_IMPORTS) {
- log.debug("convertToToscaTemplate - failed to get Default Imports section from configuration");
+ if (null == DEFAULT_IMPORTS) {
+ log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
}
@@ -190,7 +211,7 @@ public class ToscaExportHandler {
toscaTemplate.setMetadata(convertMetadata(component));
toscaTemplate.setImports(new ArrayList<>(DEFAULT_IMPORTS));
Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
- if (ToscaUtils.isAtomicType(component)) {
+ if (ModelConverter.isAtomicComponent(component)) {
log.trace("convert component as node type");
return convertNodeType(component, toscaTemplate, nodeTypes);
} else {
@@ -208,6 +229,15 @@ public class ToscaExportHandler {
return Either.right(importsRes.right().value());
}
toscaNode = importsRes.left().value().left;
+ /*Either<Map<String, ToscaNodeType>, ToscaError> nodeTypesMapEither = createProxyNodeTypes(component);
+ if (nodeTypesMapEither.isRight()) {
+ log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
+ nodeTypesMapEither.right().value());
+ return Either.right(nodeTypesMapEither.right().value());
+ }
+ Map<String, ToscaNodeType> nodeTypesMap = nodeTypesMapEither.left().value();
+ if (nodeTypesMap != null && !nodeTypesMap.isEmpty())
+ toscaNode.setNode_types(nodeTypesMap);*/
Map<String, Component> componentCache = importsRes.left().value().right;
Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
@@ -240,9 +270,9 @@ public class ToscaExportHandler {
topologyTemplate.setNode_templates(nodeTemplates.left().value());
}
- Map<String, ToscaGroupTemplate> groupsMap = null;
+ Map<String, ToscaGroupTemplate> groupsMap;
if (groups != null && !groups.isEmpty()) {
- groupsMap = new HashMap<String, ToscaGroupTemplate>();
+ groupsMap = new HashMap<>();
for (GroupDefinition group : groups) {
ToscaGroupTemplate toscaGroup = convertGroup(group);
groupsMap.put(group.getName(), toscaGroup);
@@ -252,7 +282,7 @@ public class ToscaExportHandler {
topologyTemplate.addGroups(groupsMap);
}
SubstitutionMapping substitutionMapping = new SubstitutionMapping();
- String toscaResourceName = null;
+ String toscaResourceName;
switch (component.getComponentType()) {
case RESOURCE:
toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
@@ -263,19 +293,19 @@ public class ToscaExportHandler {
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
break;
default:
- log.debug("Not supported component type {}", component.getComponentType());
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
}
substitutionMapping.setNode_type(toscaResourceName);
- Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping,
- dataTypes);
+ Either<SubstitutionMapping, ToscaError> capabilities = convertCapabilities(component, substitutionMapping);
if (capabilities.isRight()) {
return Either.right(capabilities.right().value());
}
substitutionMapping = capabilities.left().value();
- Either<SubstitutionMapping, ToscaError> requirements = capabiltyRequirementConvertor.convertSubstitutionMappingRequirements(component, substitutionMapping);
+ Either<SubstitutionMapping, ToscaError> requirements = capabiltyRequirementConvertor
+ .convertSubstitutionMappingRequirements(originComponents, component, substitutionMapping);
if (requirements.isRight()) {
return Either.right(requirements.right().value());
}
@@ -356,19 +386,19 @@ public class ToscaExportHandler {
private Either<ImmutablePair<ToscaTemplate, Map<String, Component>>, ToscaError> fillImports(Component component,
ToscaTemplate toscaTemplate) {
- if(null == DEFAULT_IMPORTS) {
- log.debug("convertToToscaTemplate - failed to get Default Imports section from configuration");
+ if (null == DEFAULT_IMPORTS) {
+ log.debug(FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION);
return Either.right(ToscaError.GENERAL_ERROR);
}
Map<String, Component> componentCache = new HashMap<>();
- if (!ToscaUtils.isAtomicType(component)) {
+ if (!ModelConverter.isAtomicComponent(component)) {
List<ComponentInstance> componentInstances = component.getComponentInstances();
if (componentInstances != null && !componentInstances.isEmpty()) {
- List<Map<String, Map<String, String>>> additionalImports =
- toscaTemplate.getImports() == null ? new ArrayList<>(DEFAULT_IMPORTS) : new ArrayList<>(toscaTemplate.getImports());
+ List<Map<String, Map<String, String>>> additionalImports = toscaTemplate.getImports() == null
+ ? new ArrayList<>(DEFAULT_IMPORTS) : new ArrayList<>(toscaTemplate.getImports());
List<Triple<String, String, Component>> dependecies = new ArrayList<>();
@@ -386,9 +416,8 @@ public class ToscaExportHandler {
importsListMember.put(keyNameBuilder.toString(), interfaceFiles);
additionalImports.add(importsListMember);
- componentInstances.forEach(ci -> {
- createDependency(componentCache, additionalImports, dependecies, ci);
- });
+ componentInstances.forEach(ci -> createDependency(componentCache, additionalImports, dependecies, ci));
+ originComponents.putAll(componentCache);
toscaTemplate.setDependencies(dependecies);
toscaTemplate.setImports(additionalImports);
}
@@ -407,7 +436,8 @@ public class ToscaExportHandler {
Component componentRI = componentCache.get(ci.getComponentUid());
if (componentRI == null) {
// all resource must be only once!
- Either<Component, StorageOperationStatus> resource = toscaOperationFacade.getToscaFullElement(ci.getComponentUid());
+ Either<Component, StorageOperationStatus> resource = toscaOperationFacade
+ .getToscaFullElement(ci.getComponentUid());
if (resource.isRight()) {
log.debug("Failed to fetch resource with id {} for instance {}");
}
@@ -429,7 +459,7 @@ public class ToscaExportHandler {
dependecies.add(new ImmutableTriple<String, String, Component>(artifactName,
artifactDefinition.getEsId(), fetchedComponent));
- if(!ToscaUtils.isAtomicType(componentRI)) {
+ if (!ModelConverter.isAtomicComponent(componentRI)) {
importsListMember = new HashMap<>();
Map<String, String> interfaceFiles = new HashMap<>();
interfaceFiles.put(IMPORTS_FILE_KEY, getInterfaceFilename(artifactName));
@@ -442,8 +472,7 @@ public class ToscaExportHandler {
}
public static String getInterfaceFilename(String artifactName) {
- String interfaceFileName = artifactName.substring(0, artifactName.lastIndexOf('.')) + ToscaExportHandler.TOSCA_INTERFACE_NAME;
- return interfaceFileName;
+ return artifactName.substring(0, artifactName.lastIndexOf('.')) + ToscaExportHandler.TOSCA_INTERFACE_NAME;
}
private Either<ToscaTemplate, ToscaError> convertNodeType(Component component, ToscaTemplate toscaNode,
@@ -466,7 +495,7 @@ public class ToscaExportHandler {
toscaNodeType = properties.left().value();
log.debug("Properties converted for {}", component.getUniqueId());
- //Extracted to method for code reuse
+ // Extracted to method for code reuse
return convertReqCapAndTypeName(component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
}
@@ -496,7 +525,7 @@ public class ToscaExportHandler {
}
}
- //Extracted to method for code reuse
+ // Extracted to method for code reuse
return convertReqCapAndTypeName(component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
}
@@ -510,15 +539,13 @@ public class ToscaExportHandler {
toscaNodeType = capabilities.left().value();
log.debug("Capabilities converted for {}", component.getUniqueId());
- Either<ToscaNodeType, ToscaError> requirements = capabiltyRequirementConvertor.convertRequirements(component,
- toscaNodeType);
+ Either<ToscaNodeType, ToscaError> requirements = capabiltyRequirementConvertor.convertRequirements(component, toscaNodeType);
if (requirements.isRight()) {
return Either.right(requirements.right().value());
}
toscaNodeType = requirements.left().value();
log.debug("Requirements converted for {}", component.getUniqueId());
-
String toscaResourceName;
switch (component.getComponentType()) {
case RESOURCE:
@@ -530,7 +557,7 @@ public class ToscaExportHandler {
+ component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
break;
default:
- log.debug("Not supported component type {}", component.getComponentType());
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
}
@@ -558,7 +585,8 @@ public class ToscaExportHandler {
nodeTemplate.setType(componentInstance.getToscaComponentName());
Either<ToscaNodeTemplate, ToscaError> requirements = convertComponentInstanceRequirements(component,
- componentInstance, component.getComponentInstancesRelations(), nodeTemplate, componentCache.get(componentInstance.getComponentUid()));
+ componentInstance, component.getComponentInstancesRelations(), nodeTemplate,
+ componentCache.get(componentInstance.getComponentUid()));
if (requirements.isRight()) {
convertNodeTemplatesRes = Either.right(requirements.right().value());
break;
@@ -634,8 +662,9 @@ public class ToscaExportHandler {
List<ComponentInstanceInput> instanceInputsList = componentInstancesInputs.get(instanceUniqueId);
if (instanceInputsList != null) {
instanceInputsList.forEach(input -> {
-
- Supplier<String> supplier = () -> input.getValue() != null && !input.getValue().isEmpty()? input.getValue(): input.getDefaultValue();
+
+ Supplier<String> supplier = () -> input.getValue() != null && !input.getValue().isEmpty()
+ ? input.getValue() : input.getDefaultValue();
convertAndAddValue(dataTypes, componentInstance, props, input, supplier);
});
}
@@ -724,7 +753,8 @@ public class ToscaExportHandler {
Supplier<String> supplGroupType = () -> groupInstance.getType();
Supplier<String> supplDescription = () -> groupInstance.getDescription();
- Supplier<List<? extends GroupProperty>> supplProperties = () -> groupInstance.convertToGroupInstancesProperties();
+ Supplier<List<? extends GroupProperty>> supplProperties = () -> groupInstance
+ .convertToGroupInstancesProperties();
Supplier<String> supplgroupName = () -> groupInstance.getGroupName();
Supplier<String> supplInvariantUUID = () -> groupInstance.getInvariantUUID();
Supplier<String> supplGroupUUID = () -> groupInstance.getGroupUUID();
@@ -751,7 +781,8 @@ public class ToscaExportHandler {
toscaMetadata = new VfModuleToscaMetadata();
Map<String, Object> properties = fillGroupProperties(props.get());
- if(!properties.containsKey(VF_MODULE_DESC_KEY) || StringUtils.isEmpty((String) properties.get(VF_MODULE_DESC_KEY))){
+ if (!properties.containsKey(VF_MODULE_DESC_KEY)
+ || StringUtils.isEmpty((String) properties.get(VF_MODULE_DESC_KEY))) {
properties.put(VF_MODULE_DESC_KEY, description.get());
}
toscaGroup.setProperties(properties);
@@ -765,7 +796,7 @@ public class ToscaExportHandler {
private Map<String, Object> fillGroupProperties(List<? extends GroupProperty> groupProps) {
Map<String, Object> properties = new HashMap<>();
- if(groupProps != null){
+ if (groupProps != null) {
for (GroupProperty gp : groupProps) {
if (gp.getName().equals(Constants.IS_BASE)) {
Boolean isBase = Boolean.parseBoolean(gp.getValue());
@@ -800,72 +831,233 @@ public class ToscaExportHandler {
private ToscaNodeType createNodeType(Component component) {
ToscaNodeType toscaNodeType = new ToscaNodeType();
- if (ToscaUtils.isAtomicType(component)){
- if (((Resource) component).getDerivedFrom() != null){
+ if (ModelConverter.isAtomicComponent(component)) {
+ if (((Resource) component).getDerivedFrom() != null) {
toscaNodeType.setDerived_from(((Resource) component).getDerivedFrom().get(0));
}
- toscaNodeType.setDescription(component.getDescription()); // or name??
+ toscaNodeType.setDescription(component.getDescription()); // or
+ // name??
} else {
- String derivedFrom = null != component.getDerivedFromGenericType()? component.getDerivedFromGenericType() : "tosca.nodes.Root";
+ String derivedFrom = null != component.getDerivedFromGenericType() ? component.getDerivedFromGenericType()
+ : "tosca.nodes.Root";
toscaNodeType.setDerived_from(derivedFrom);
}
return toscaNodeType;
}
- //TODO save the capability(type or name) info on relation data
- private Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceRequirements(Component component,
- ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations,
- ToscaNodeTemplate nodeTypeTemplate, Component originComponent) {
+ /*private Either<Map<String, ToscaNodeType>, ToscaError> createProxyNodeTypes(Component container) {
- List<ComponentInstance> instancesList = component.getComponentInstances();
- List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
- Map<String, List<RequirementDefinition>> reqMap = originComponent.getRequirements();
+ Map<String, ToscaNodeType> nodeTypesMap = null;
+ Either<Map<String, ToscaNodeType>, ToscaError> res = Either.left(nodeTypesMap);
- relations.stream().filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).forEach(rel -> {
- ComponentInstance toComponentInstance = instancesList.stream()
- .filter(i -> rel.getToNode().equals(i.getUniqueId())).findFirst().orElse(null);
- if (toComponentInstance == null) {
- log.debug("Failed to find relation between node {} to node {}", componentInstance.getName(),
- rel.getToNode());
- return;
- }
- RequirementAndRelationshipPair reqAndRelationshipPair = rel.getRelationships().get(0);
- ToscaTemplateRequirement toscaRequirement = new ToscaTemplateRequirement();
- toscaRequirement.setNode(toComponentInstance.getName());
- Optional<RequirementDefinition> findAny = reqMap.values().stream().flatMap(e -> e.stream())
- .filter(e -> e.getName().equals(reqAndRelationshipPair.getRequirement())).findAny();
- if (findAny.isPresent()) {
- RequirementDefinition reqDefinition = findAny.get();
- toscaRequirement.setCapability(reqDefinition.getCapability());
- toscaRequirement.setRelationship(reqDefinition.getRelationship());
- } else {
- // reqMap represents calculated requirements! if not found there, export data directly from the relation definition
- log.debug("Failed to find requirement {} definition for node {}", reqAndRelationshipPair.getRequirement(), componentInstance.getName());
- return;
+ List<ComponentInstance> componetInstances = container.getComponentInstances();
+
+ if (componetInstances == null || componetInstances.isEmpty())
+ return res;
+ Map<String, ComponentInstance> serviceProxyInstanceList = new HashMap<>();
+ List<ComponentInstance> proxyInst = componetInstances.stream().filter(p -> p.getOriginType().name().equals(OriginTypeEnum.ServiceProxy.name())).collect(Collectors.toList());
+ if(proxyInst != null && !proxyInst.isEmpty()){
+ for(ComponentInstance inst: proxyInst){
+ serviceProxyInstanceList.put(inst.getToscaComponentName(), inst);
}
- Map<String, ToscaTemplateRequirement> toscaReqMap = new HashMap<>();
- toscaReqMap.put(reqAndRelationshipPair.getRequirement(), toscaRequirement);
- toscaRequirements.add(toscaReqMap);
+ }
+
+ if (serviceProxyInstanceList.isEmpty())
+ return res;
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreCapabilities(false);
+ filter.setIgnoreComponentInstances(false);
+ Either<Resource, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade
+ .getLatestByName("serviceProxy");
+ if (serviceProxyOrigin.isRight()) {
+ log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
+ serviceProxyOrigin.right().value());
+ return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
+ }
+ Component origComponent = serviceProxyOrigin.left().value();
+
+ nodeTypesMap = new HashMap<>();
+ for (Entry<String, ComponentInstance> entryProxy : serviceProxyInstanceList.entrySet()) {
+ Component serviceComponent = null;
+ ComponentParametersView componentParametersView = new ComponentParametersView();
+ componentParametersView.disableAll();
+ componentParametersView.setIgnoreCategories(false);
+ Either<Component, StorageOperationStatus> service = toscaOperationFacade
+ .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
+ if (service.isRight()) {
+ log.debug("Failed to fetch resource with id {} for instance {}");
+ } else
+ serviceComponent = service.left().value();
+
+ ToscaNodeType toscaNodeType = createProxyNodeType(origComponent, serviceComponent, entryProxy.getValue());
+ nodeTypesMap.put(entryProxy.getKey(), toscaNodeType);
+ }
+
+ return Either.left(nodeTypesMap);
+ }*/
+
+ private ToscaNodeType createProxyNodeType(Component origComponent, Component proxyComponent,
+ ComponentInstance instance) {
+ ToscaNodeType toscaNodeType = new ToscaNodeType();
+ String derivedFrom = ((Resource) origComponent).getToscaResourceName();
+
+ toscaNodeType.setDerived_from(derivedFrom);
+ Either<Map<String, DataTypeDefinition>, TitanOperationStatus> dataTypesEither = dataTypeCache.getAll();
+ if (dataTypesEither.isRight()) {
+ log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value());
+ }
+ Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
+ Map<String, ToscaCapability> capabilities = this.capabiltyRequirementConvertor
+ .convertProxyCapabilities(origComponent, proxyComponent, instance, dataTypes);
+
+ toscaNodeType.setCapabilities(capabilities);
- });
+ return toscaNodeType;
+ }
+ private Either<ToscaNodeTemplate, ToscaError> convertComponentInstanceRequirements(Component component,
+ ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations,
+ ToscaNodeTemplate nodeTypeTemplate, Component originComponent) {
+
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>();
+ if(!addRequirements(component, componentInstance, relations, originComponent, toscaRequirements)){
+ log.debug("Failed to convert component instance requirements for the component instance {}. ", componentInstance.getName());
+ return Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
+ }
if (!toscaRequirements.isEmpty()) {
nodeTypeTemplate.setRequirements(toscaRequirements);
}
- log.debug("Finish convert Requirements for node type");
+ log.debug("Finished to convert requirements for the node type {} ", componentInstance.getName());
return Either.left(nodeTypeTemplate);
}
+ private boolean addRequirements(Component component, ComponentInstance componentInstance, List<RequirementCapabilityRelDef> relations, Component originComponent,
+ List<Map<String, ToscaTemplateRequirement>> toscaRequirements) {
+ boolean result;
+ List<RequirementCapabilityRelDef> filteredRelations = relations.stream().filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).collect(Collectors.toList());
+ if(CollectionUtils.isEmpty(filteredRelations)){
+ result = true;
+ } else {
+ result = !filteredRelations.stream().filter(rel -> !addRequirement(component,componentInstance, originComponent, component.getComponentInstances(), rel, toscaRequirements)).findFirst().isPresent();
+ }
+ return result;
+ }
+
+ private boolean addRequirement(Component component,ComponentInstance fromInstance, Component originComponent, List<ComponentInstance> instancesList, RequirementCapabilityRelDef rel, List<Map<String, ToscaTemplateRequirement>> toscaRequirements){
+
+ boolean result = true;
+ Map<String,Component> originComponents = new HashMap<>();
+ Map<String, List<RequirementDefinition>> reqMap = originComponent.getRequirements();
+ RequirementAndRelationshipPair reqAndRelationshipPair = rel.getRelationships().get(0);
+ Either<Component, StorageOperationStatus> getOriginRes = null;
+ Optional<RequirementDefinition> reqOpt = null;
+ Component toOriginComponent = null;
+ Optional<CapabilityDefinition> cap = null;
+ Either<String, Boolean> buildCapNameRes = null;
+ Either<String, Boolean> buildReqNameRes = null;
+
+ ComponentInstance toInstance = instancesList.stream().filter(i -> rel.getToNode().equals(i.getUniqueId())).findFirst().orElse(null);
+ if (toInstance == null) {
+ log.debug("Failed to find a relation from the node {} to the node {}", fromInstance.getName(), rel.getToNode());
+ result = false;
+ }
+ if(result){
- private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component, SubstitutionMapping substitutionMapping, Map<String, DataTypeDefinition> dataTypes) {
- Map<String, String[]> toscaCapabilities = capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(component, dataTypes);
+ if(component.getComponentType().equals(ComponentTypeEnum.SERVICE)) {
+ reqOpt = findRequirement(reqMap, reqAndRelationshipPair);
+ }
+ else {
+ reqOpt = findRequirement(reqMap, reqAndRelationshipPair.getRequirementUid());
+ }
+ if(!reqOpt.isPresent()){
+ log.debug("Failed to find a requirement with uniqueId {} on a component with uniqueId {}", reqAndRelationshipPair.getRequirementUid(), originComponent.getUniqueId());
+ result = false;
+ }
+ }
+ if(result){
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstances(false);
+ filter.setIgnoreCapabilities(false);
+ getOriginRes = toscaOperationFacade.getToscaElement(toInstance.getComponentUid(), filter);
+ if(getOriginRes.isRight()){
+ log.debug("Failed to build substituted name for the requirement {}. Failed to get an origin component with uniqueId {}", reqOpt.get().getName(), toInstance.getComponentUid());
+ result = false;
+ }
+ }
+ if(result){
+ toOriginComponent = getOriginRes.left().value();
+ cap = toOriginComponent.getCapabilities().get(reqOpt.get().getCapability()).stream().filter(c -> c.getName().equals(reqAndRelationshipPair.getCapability())).findFirst();
+ if(!cap.isPresent()){
+ log.debug("Failed to find a capability with name {} on a component with uniqueId {}", reqAndRelationshipPair.getCapability(), originComponent.getUniqueId());
+ result = false;
+ }
+ }
+ if(result){
+ buildCapNameRes = capabiltyRequirementConvertor.buildSubstitutedName(originComponents, toOriginComponent, cap.get().getPath(), reqAndRelationshipPair.getCapability());
+ if(buildCapNameRes.isRight()){
+ log.debug("Failed to build a substituted capability name for the capability with name {} on a component with uniqueId {}", reqAndRelationshipPair.getCapability(), originComponent.getUniqueId());
+ result = false;
+ }
+ }
+ if(result){
+ buildReqNameRes = capabiltyRequirementConvertor.buildSubstitutedName(originComponents, originComponent, reqOpt.get().getPath(), reqAndRelationshipPair.getRequirement());
+ if(buildReqNameRes.isRight()){
+ log.debug("Failed to build a substituted requirement name for the requirement with name {} on a component with uniqueId {}", reqAndRelationshipPair.getRequirement(), originComponent.getUniqueId());
+ result = false;
+ }
+ }
+ if(result){
+ ToscaTemplateRequirement toscaRequirement = new ToscaTemplateRequirement();
+ Map<String, ToscaTemplateRequirement> toscaReqMap = new HashMap<>();
+ toscaRequirement.setNode(toInstance.getName());
+ toscaRequirement.setCapability(buildCapNameRes.left().value());
+ toscaReqMap.put(buildReqNameRes.left().value(), toscaRequirement);
+ toscaRequirements.add(toscaReqMap);
+ }
+ return result;
+ }
- if (!toscaCapabilities.isEmpty()) {
- substitutionMapping.setCapabilities(toscaCapabilities);
+ private Optional<RequirementDefinition> findRequirement(Map<String, List<RequirementDefinition>> reqMap, String reqId) {
+ for(List<RequirementDefinition> reqList: reqMap.values()){
+ Optional<RequirementDefinition> reqOpt = reqList.stream().filter(r -> r.getUniqueId().equals(reqId)).findFirst();
+ if(reqOpt.isPresent()){
+ return reqOpt;
+ }
}
- log.debug("Finish convert Capabilities for node type");
+ return Optional.empty();
+ }
+
+ private Optional<RequirementDefinition> findRequirement(Map<String, List<RequirementDefinition>> reqMap, RequirementAndRelationshipPair reqAndRelationshipPair) {
+ for(List<RequirementDefinition> reqList: reqMap.values()){
+ Optional<RequirementDefinition> reqOpt = reqList.stream().filter(r ->
+ isRequirmentBelongTo(reqAndRelationshipPair, r))
+ .findFirst();
+ if(reqOpt.isPresent()){
+ return reqOpt;
+ }
+ }
+ return Optional.empty();
+ }
+
+ private boolean isRequirmentBelongTo(RequirementAndRelationshipPair reqAndRelationshipPair, RequirementDefinition r) {
+ return StringUtils.isNotEmpty(r.getOwnerId()) && r.getOwnerId().equals(reqAndRelationshipPair.getRequirementOwnerId())
+ && StringUtils.isNotEmpty(r.getName()) && r.getName().equals(reqAndRelationshipPair.getRequirement());
+ }
- return Either.left(substitutionMapping);
+ private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component, SubstitutionMapping substitutionMappings) {
+
+ Either<SubstitutionMapping, ToscaError> result = Either.left(substitutionMappings);;
+ Either<Map<String, String[]>, ToscaError> toscaCapabilitiesRes = capabiltyRequirementConvertor
+ .convertSubstitutionMappingCapabilities(originComponents, component);
+ if(toscaCapabilitiesRes.isRight()){
+ result = Either.right(toscaCapabilitiesRes.right().value());
+ log.error("Failed convert capabilities for the component {}. ", component.getName());
+ } else if (MapUtils.isNotEmpty(toscaCapabilitiesRes.left().value())) {
+ substitutionMappings.setCapabilities(toscaCapabilitiesRes.left().value());
+ log.debug("Finish convert capabilities for the component {}. ", component.getName());
+ }
+ log.debug("Finished to convert capabilities for the component {}. ", component.getName());
+ return result;
}
private Either<ToscaNodeType, ToscaError> convertCapabilities(Component component, ToscaNodeType nodeType,
@@ -896,12 +1088,12 @@ public class ToscaExportHandler {
return null;
} else {
// skip not relevant for Tosca property
- if (property.getName().equals("dependencies")) {
+ if ("dependencies".equals(property.getName())) {
return null;
}
NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
- return property.getName().equals("_defaultp_")
+ return "_defaultp_".equals(property.getName())
? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
}
}
@@ -928,7 +1120,7 @@ public class ToscaExportHandler {
protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess)
throws IntrospectionException {
Collection<Property> fields = getPropertiesMap(type, BeanAccess.FIELD).values();
- return new LinkedHashSet<Property>(fields);
+ return new LinkedHashSet<>(fields);
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
index 24586d9ea0..0c54e7229e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
@@ -34,17 +34,6 @@ import org.openecomp.sdc.be.model.Component;
public class ToscaUtils {
- public static boolean isAtomicType(Component component) {
- ComponentTypeEnum componentType = component.getComponentType();
- if (ComponentTypeEnum.RESOURCE.equals(componentType)) {
- ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
- if (ResourceTypeEnum.CP == resourceType || ResourceTypeEnum.VL == resourceType || ResourceTypeEnum.VFC == resourceType || ResourceTypeEnum.VFCMT == resourceType || ResourceTypeEnum.ABSTRACT == resourceType) {
- return true;
- }
- }
- return false;
- }
-
public static boolean isComplexVfc(Component component) {
if (ComponentTypeEnum.RESOURCE == component.getComponentType()) {
ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
@@ -55,7 +44,7 @@ public class ToscaUtils {
return false;
}
- public static Map<String, Object> objectToMap(Object objectToConvert, Class clazz) throws IllegalArgumentException, IllegalAccessException {
+ public static Map<String, Object> objectToMap(Object objectToConvert, Class<?> clazz) throws IllegalArgumentException, IllegalAccessException {
Map<String, Object> map = new HashMap<>();
List<Field> fields = new ArrayList<>();
@@ -76,4 +65,47 @@ public class ToscaUtils {
}
return fields;
}
+
+ public static class SubstituitionEntry{
+
+ private String fullName = "";
+ private String sourceName = "";
+ private String owner = "";
+
+ public SubstituitionEntry() {}
+
+ public SubstituitionEntry(String fullName, String sourceName, String owner) {
+ if(fullName != null)
+ this.fullName = fullName;
+ if(sourceName != null)
+ this.sourceName = sourceName;
+ if(owner != null)
+ this.owner = owner;
+ }
+
+ public String getFullName() {
+ return fullName;
+ }
+
+ public void setFullName(String fullName) {
+ this.fullName = fullName;
+ }
+
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ public void setSourceName(String sourceName) {
+ this.sourceName = sourceName;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+ }
+
}