aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-11-12 02:07:27 +0200
committerMichael Lando <ml636r@att.com>2017-11-12 02:07:27 +0200
commit88e37209870c269747d9dff49ab1169cb6399654 (patch)
treee6a2c61ffe0c1cad63a82ec32e108a68be1c7a60
parent38c1e4c4ef5c948dd6cbf35c059bc302c1788fee (diff)
fix capabilities
Change-Id: Iff0448a083627b881affcacbf12b5fb5baebe294 Issue-Id: SDC-533 Signed-off-by: Michael Lando <ml636r@att.com>
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java7
-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.java519
-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.java435
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java352
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java56
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java149
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java62
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java36
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaDataDefinition.java10
-rw-r--r--sdc-os-chef/pom.xml1
-rw-r--r--sdc-os-chef/scripts/docker_sanity_run.sh122
-rw-r--r--sdc-os-chef/scripts/sanity_run.sh117
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vPCRF.csar (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vPCRF_aligned_fixed.csar)bin3836 -> 3836 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW.csarbin0 -> 3907 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW_fixed.csarbin3887 -> 0 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcMmeVf.csar (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/resource-ZteEpcMmeVf-csar_fix.csar)bin4790 -> 4790 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcSpgwVf.csar (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcSpgwVf-csar.csar)bin2804 -> 2804 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/cscf_si.csar (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/cscf_si_fixed.csar)bin50982 -> 50982 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ntas.csarbin61134 -> 0 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF.csar (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_aligned.csar)bin4290 -> 4290 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_v3.0.csarbin44851 -> 44977 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vSBC.csar (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vSBC_aligned.csar)bin3771 -> 3771 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vfw.zip (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/base_vfw.zip)bin3522 -> 3522 bytes
-rw-r--r--sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vvg.zip (renamed from sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/base_vvg.zip)bin944 -> 944 bytes
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/ComponentBaseTest.java2
-rw-r--r--test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java2
30 files changed, 1425 insertions, 485 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 1ee3bc61c8..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 {
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 08d377c7db..b664efebcb 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());
@@ -1110,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());
@@ -1236,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));
@@ -1873,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;
@@ -1899,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());
@@ -1991,7 +2012,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (eitherCreateResult.isRight()) {
return Either.right(eitherCreateResult.right().value());
}
- resource = eitherCreateResult.left().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()) {
@@ -1999,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);
@@ -2079,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());
@@ -2145,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
@@ -2675,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();
@@ -2863,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 {
@@ -2900,9 +2937,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
if (resStatus == null) {
- Either<Resource, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(resource.getUniqueId());
- resStatus = toscaElement.bimap(resourceResponse -> resourceResponse,
- storageResponse -> componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageResponse), resource));
+ resStatus = Either.left(resource);
}
} catch (Exception e) {
resStatus = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
@@ -2996,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();
@@ -3503,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());
@@ -3609,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())
@@ -3625,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);
@@ -3731,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 (propertyInfo.getValue() != null) {
+ 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) {
@@ -3770,7 +3851,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
if(updateRes == null){
- updateRes = toscaOperationFacade.getToscaElement( resource.getUniqueId());
+ updateRes = Either.left(resource);
}
return updateRes;
}
@@ -4017,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);
@@ -4111,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);
}
@@ -4271,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;
@@ -4324,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);
@@ -4339,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());
}
@@ -4362,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());
@@ -4372,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);
}
@@ -4424,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);
}
@@ -4456,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);
}
@@ -4795,57 +4876,6 @@ 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<>();
- 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());
- }
- }
- }
- }
- 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<Map<String, List<UploadReqInfo>>, ResponseFormat> createReqModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<String, List<UploadReqInfo>>();
@@ -4876,9 +4906,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
return response;
}
-
- private Either<UploadReqInfo, ResponseFormat> addModuleNodeTemplateReq(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, List<UploadReqInfo>> moduleRequirements, Object requirementJson, String requirementName) {
+ 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);
@@ -4897,6 +4927,56 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
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());
+ }
+ }
+ }
+ }
+ 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();
@@ -5109,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());
@@ -5245,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());
@@ -5414,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);
@@ -5783,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());
@@ -5997,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);
@@ -6216,6 +6299,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
*
* return Either.left(true); }
*/
+
private boolean isResourceNameEquals(Resource currentResource, Resource updateInfoResource) {
String resourceNameUpdated = updateInfoResource.getName();
String resourceNameCurrent = currentResource.getName();
@@ -6248,7 +6332,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
currentResource.setNormalizedName(ValidationUtils.normaliseComponentName(resourceNameUpdated));
currentResource.setSystemName(ValidationUtils.convertToSystemName(resourceNameUpdated));
- } else if(currentResource.getResourceType() != ResourceTypeEnum.CVFC) {
+ } else {
log.info("Resource name: {}, cannot be updated once the resource has been certified once.", resourceNameUpdated);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
return Either.right(errorResponse);
@@ -7278,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..0c93ee83cf 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
@@ -1,5 +1,4 @@
/*-
-
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
@@ -22,11 +21,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 +38,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 +56,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 +90,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 +105,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 +118,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 +144,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 +372,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 +492,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 fda199052e..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;
@@ -275,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);
}
@@ -332,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);
}
}
@@ -453,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..e65c4b5001 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,211 @@ 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(componentInstance, originComponent, component.getComponentInstances(), rel, toscaRequirements)).findFirst().isPresent();
+ }
+ return result;
+ }
+
+ private boolean addRequirement(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){
+ 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;
+ }
- private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component, SubstitutionMapping substitutionMapping, Map<String, DataTypeDefinition> dataTypes) {
- Map<String, String[]> toscaCapabilities = capabiltyRequirementConvertor.convertSubstitutionMappingCapabilities(component, dataTypes);
-
- 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();
+ }
- 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 +1066,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 +1098,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;
+ }
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java
index d986d77450..e530144fe0 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTypeOperation.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
import fj.data.Either;
+import java.util.stream.Collectors;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -58,8 +59,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
@org.springframework.stereotype.Component("node-type-operation")
@@ -757,25 +760,49 @@ public class NodeTypeOperation extends ToscaElementOperation {
return DaoStatusConverter.convertTitanStatusToStorageStatus(error);
}
// must be only one
- GraphVertex newDerived = getParentResources.left().value().get(0);
- derivedResources.add(newDerived);
- StorageOperationStatus updateStatus = updateDataFromNewDerived(derivedResources, nodeTypeV, (NodeType)toscaElementToUpdate);
- if (updateStatus != StorageOperationStatus.OK) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update data for {} from new derived {} ", nodeTypeV.getUniqueId(), newDerived.getUniqueId(), updateStatus);
- return updateStatus;
- }
+ GraphVertex newDerivedV = getParentResources.left().value().get(0);
+ return updateDerived(toscaElementToUpdate, nodeTypeV, firstDerivedInChain, newDerivedV, false);
+ }
+ }
+ return StorageOperationStatus.OK;
+ }
- Either<Edge, TitanOperationStatus> deleteEdge = titanDao.deleteEdge(nodeTypeV, firstDerivedInChain, EdgeLabelEnum.DERIVED_FROM);
- if (deleteEdge.isRight()) {
- TitanOperationStatus deleteError = deleteEdge.right().value();
- log.debug("Failed to disassociate element {} from derived {} , error {}", nodeTypeV.getUniqueId(), firstDerivedInChain.getUniqueId(), deleteError);
- return DaoStatusConverter.convertTitanStatusToStorageStatus(deleteError);
- }
+ /**
+ *
+ * @param toscaElementToUpdate
+ * @param nodeTypeV
+ * @param preDerivedV
+ * @param newDerivedV
+ * @param mergeValues
+ * @return
+ */
+ protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex nodeTypeV, GraphVertex preDerivedV, GraphVertex newDerivedV, boolean mergeValues) {
+ Set<String> preDerivedChainIdList = new HashSet();
+ preDerivedChainIdList.add(preDerivedV.getUniqueId());
+ Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(preDerivedV, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.NoParse);
+ while (childVertex.isLeft()) {
+ GraphVertex currentChield = childVertex.left().value();
+ preDerivedChainIdList.add(currentChield.getUniqueId());
+ childVertex = titanDao.getChildVertex(currentChield, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.NoParse);
+ }
- titanDao.createEdge(nodeTypeV, newDerived, EdgeLabelEnum.DERIVED_FROM, new HashMap<>());
- }
+ List<GraphVertex> derivedResources = new ArrayList<>();
+ derivedResources.add(newDerivedV);
+ StorageOperationStatus updateStatus = updateDataFromNewDerived(derivedResources, nodeTypeV, (NodeType) toscaElementToUpdate, mergeValues, preDerivedChainIdList);
+ if (updateStatus != StorageOperationStatus.OK) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update data for {} from new derived {} ", nodeTypeV.getUniqueId(), newDerivedV.getUniqueId(), updateStatus);
+ return updateStatus;
+ }
+
+ Either<Edge, TitanOperationStatus> deleteEdge = titanDao.deleteEdge(nodeTypeV, preDerivedV, EdgeLabelEnum.DERIVED_FROM);
+ if (deleteEdge.isRight()) {
+ TitanOperationStatus deleteError = deleteEdge.right().value();
+ log.debug("Failed to disassociate element {} from derived {} , error {}", nodeTypeV.getUniqueId(), preDerivedV.getUniqueId(), deleteError);
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(deleteError);
}
+ titanDao.createEdge(nodeTypeV, newDerivedV, EdgeLabelEnum.DERIVED_FROM, new HashMap<>());
+
return StorageOperationStatus.OK;
}
@@ -800,20 +827,20 @@ public class NodeTypeOperation extends ToscaElementOperation {
}
- private StorageOperationStatus updateDataFromNewDerived(List<GraphVertex> newDerived, GraphVertex nodeTypeV, NodeType nodeToUpdate) {
+ private StorageOperationStatus updateDataFromNewDerived(List<GraphVertex> newDerived, GraphVertex nodeTypeV, NodeType nodeToUpdate, boolean mergeValues, Set<String> preDerivedChainIdList) {
EnumSet<EdgeLabelEnum> edgeLabels = EnumSet.of(EdgeLabelEnum.CAPABILITIES, EdgeLabelEnum.REQUIREMENTS, EdgeLabelEnum.PROPERTIES, EdgeLabelEnum.ATTRIBUTES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.ADDITIONAL_INFORMATION);
StorageOperationStatus status = null;
- for (EdgeLabelEnum edge : edgeLabels){
- status = updateDataByType(newDerived, nodeTypeV, edge, nodeToUpdate);
+ for (EdgeLabelEnum edge : edgeLabels) {
+ status = updateDataByType(newDerived, nodeTypeV, edge, nodeToUpdate, mergeValues, preDerivedChainIdList);
if (status != StorageOperationStatus.OK) {
break;
}
}
return status;
-
+
}
- private <T extends ToscaDataDefinition> StorageOperationStatus updateDataByType(List<GraphVertex> newDerivedList, GraphVertex nodeTypeV, EdgeLabelEnum label, NodeType nodeElement) {
+ private <T extends ToscaDataDefinition> StorageOperationStatus updateDataByType(List<GraphVertex> newDerivedList, GraphVertex nodeTypeV, EdgeLabelEnum label, NodeType nodeElement, boolean mergeValues, Set<String> preDerivedChainIdList) {
log.debug("Update data from derived for element {} type {}", nodeTypeV.getUniqueId(), label);
Either<GraphVertex, TitanOperationStatus> dataFromGraph = getDataVertex(nodeTypeV, label);
if (dataFromGraph.isRight()) {
@@ -824,9 +851,23 @@ public class NodeTypeOperation extends ToscaElementOperation {
GraphVertex dataV = dataFromGraph.left().value();
Map<String, T> mapFromGraph = (Map<String, T>) dataV.getJson();
- mapFromGraph.entrySet().removeIf(e -> e.getValue().getOwnerId() != null);
+ Map<String, T> valuesFrmPrev = null;
+ if (isSimpleHierarchy(label)) {
+ if (mergeValues) {
+ valuesFrmPrev = mapFromGraph.entrySet().stream().filter(e -> e.getValue().getOwnerId() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ }
+ mapFromGraph.entrySet().removeIf(e -> preDerivedChainIdList.contains(e.getValue().getOwnerId()));
+ } else {
+ final Map<String, T> valuesFrmPrevFinal = new HashMap<>();
+ mapFromGraph.entrySet().stream().forEach(e -> {
+ T value = e.getValue();
+ value = ToscaDataDefinition.removeAndCollectByOwnerId(value, preDerivedChainIdList);
+ valuesFrmPrevFinal.put(e.getKey(), value);
+ });
+ valuesFrmPrev = valuesFrmPrevFinal;
+ mapFromGraph.entrySet().removeIf(e->e.getValue().isEmpty());
+ }
-
Either<Map<String, T>, StorageOperationStatus> dataFromDerived = getDataFromDerived(newDerivedList, label);
if (dataFromDerived.isRight()) {
return dataFromDerived.right().value();
@@ -845,10 +886,74 @@ public class NodeTypeOperation extends ToscaElementOperation {
}
return StorageOperationStatus.OK;
}
+
+ private boolean isSimpleHierarchy(EdgeLabelEnum label) {
+ switch (label) {
+ case PROPERTIES:
+ case ATTRIBUTES:
+ case ADDITIONAL_INFORMATION:
+ case ARTIFACTS:
+ case GROUPS:
+ case INPUTS:
+ return true;
+ default:
+ return false;
+ }
+ }
+
@Override
public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
fillMetadata(elementV, (NodeType) toscaElementToUpdate);
}
+ public Either<ToscaElement, StorageOperationStatus> shouldUpdateDerivedVersion(ToscaElement toscaElementToUpdate, GraphVertex nodeTypeV) {
+ NodeType nodeType = (NodeType) toscaElementToUpdate;
+
+ Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(nodeTypeV, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.NoParse);
+ if (childVertex.isRight()) {
+ TitanOperationStatus getchildError = childVertex.right().value();
+ if (getchildError == TitanOperationStatus.NOT_FOUND) {
+ log.debug("derived resource for element {} not found", nodeTypeV.getUniqueId());
+ return Either.right(StorageOperationStatus.OK);
+ }
+
+ log.debug("Failed to fetch derived resource for element {} error {}", nodeTypeV.getUniqueId(), getchildError);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getchildError));
+ }
+ GraphVertex firstDerivedInChain = childVertex.left().value();
+
+ String currentVersion = (String) firstDerivedInChain.getMetadataProperty(GraphPropertyEnum.VERSION);
+
+ Map<GraphPropertyEnum, Object> props = new HashMap<>();
+ props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, nodeType.getDerivedFrom().get(0));
+ props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ Map<GraphPropertyEnum, Object> propsHasNot = new HashMap<>();
+ propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
+ Either<List<GraphVertex>, TitanOperationStatus> byCriteria = titanDao.getByCriteria(VertexTypeEnum.NODE_TYPE, props, propsHasNot, JsonParseFlagEnum.NoParse);
+ if (byCriteria.isRight()) {
+ log.debug("Failed to fetch derived by props {} error {}", props, byCriteria.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(byCriteria.right().value()));
+ }
+ List<GraphVertex> lastDerived = byCriteria.left().value();
+ // now supported only one derived!!! Change in future!(Evg)
+ GraphVertex derivedFromHighest = lastDerived.get(0);
+ String highestVersion = (String) derivedFromHighest.getMetadataProperty(GraphPropertyEnum.VERSION);
+ if (!highestVersion.equals(currentVersion)) {
+
+ // need to update to latest version of derived from
+ StorageOperationStatus updateDerived = updateDerived(toscaElementToUpdate, nodeTypeV, firstDerivedInChain, derivedFromHighest, true);
+
+ if (updateDerived != StorageOperationStatus.OK) {
+ log.debug("Failed to update {} to highest derived {} from error {}", nodeTypeV.getUniqueId(), derivedFromHighest.getUniqueId(), updateDerived);
+ return Either.right(updateDerived);
+ }
+ return getToscaElement(nodeTypeV.getUniqueId(), new ComponentParametersView());
+ }
+ // no version changes
+ return Either.right(StorageOperationStatus.OK);
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
index b11036df49..394231938a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
@@ -275,8 +275,11 @@ public class ToscaOperationFacade {
public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
-
}
+
+ public <T extends Component> Either<T, StorageOperationStatus> getFullLatestComponentByToscaResourceName(String toscaResourceName) {
+ return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, JsonParseFlagEnum.ParseAll);
+ }
public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) {
return getLatestByName(GraphPropertyEnum.NAME, resourceName);
@@ -536,6 +539,39 @@ public class ToscaOperationFacade {
return getToscaElementByOperation(highestResource);
}
+ private <T extends Component> Either<T, StorageOperationStatus> getLatestByName(GraphPropertyEnum property, String nodeName, JsonParseFlagEnum parseFlag) {
+ Either<T, StorageOperationStatus> result;
+
+ Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class);
+
+ propertiesToMatch.put(property, nodeName);
+ propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+
+ propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
+
+ Either<List<GraphVertex>, TitanOperationStatus> highestResources = titanDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag);
+ if (highestResources.isRight()) {
+ TitanOperationStatus status = highestResources.right().value();
+ log.debug("failed to find resource with name {}. status={} ", nodeName, status);
+ result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ return result;
+ }
+
+ List<GraphVertex> resources = highestResources.left().value();
+ double version = 0.0;
+ GraphVertex highestResource = null;
+ for (GraphVertex vertex : resources) {
+ Object versionObj = vertex.getMetadataProperty(GraphPropertyEnum.VERSION);
+ double resourceVersion = Double.valueOf((String) versionObj);
+ if (resourceVersion > version) {
+ version = resourceVersion;
+ highestResource = vertex;
+ }
+ }
+ return getToscaElementByOperation(highestResource);
+ }
+
public <T extends Component> Either<List<T>, StorageOperationStatus> getBySystemName(ComponentTypeEnum componentType, String systemName) {
Either<List<T>, StorageOperationStatus> result = null;
@@ -2216,4 +2252,28 @@ public class ToscaOperationFacade {
return status;
}
+ public Either<Component, StorageOperationStatus> shouldUpgradeToLatestDerived(Resource clonedResource) {
+ String componentId = clonedResource.getUniqueId();
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+
+ }
+ GraphVertex nodeTypeV = getVertexEither.left().value();
+
+ ToscaElement toscaElementToUpdate = ModelConverter.convertToToscaElement(clonedResource);
+
+ Either<ToscaElement, StorageOperationStatus> shouldUpdateDerivedVersion = nodeTypeOperation.shouldUpdateDerivedVersion(toscaElementToUpdate, nodeTypeV);
+ if ( shouldUpdateDerivedVersion.isRight() && StorageOperationStatus.OK != shouldUpdateDerivedVersion.right().value() ){
+ log.debug("Failed to update derived version for node type {} derived {}, error: {}", componentId, clonedResource.getDerivedFrom().get(0), shouldUpdateDerivedVersion.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+ }
+ if ( shouldUpdateDerivedVersion.isLeft() ){
+ return Either.left(ModelConverter.convertFromToscaElement(shouldUpdateDerivedVersion.left().value()));
+ }
+ return Either.left(clonedResource);
+ }
+
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
index 03a5f41d55..973b0ce069 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
@@ -94,6 +94,22 @@ public class ModelConverter {
return null;
}
}
+
+ public static boolean isAtomicComponent(Component component) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ if (!componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ return false;
+ }
+ Resource resource = (Resource) component;
+ ResourceTypeEnum resType = resource.getResourceType();
+ return isAtomicComponent(resType);
+ }
+
+ public static boolean isAtomicComponent(ResourceTypeEnum resourceType) {
+ if (resourceType == null || resourceType == ResourceTypeEnum.VF || resourceType == ResourceTypeEnum.PNF || resourceType == ResourceTypeEnum.CVFC)
+ return false;
+ return true;
+ }
// **********************************************************
public static VertexTypeEnum getVertexType(Component component) {
@@ -117,11 +133,7 @@ public class ModelConverter {
return vertexType;
}
- public static boolean isAtomicComponent(ResourceTypeEnum resourceType) {
- if (resourceType == null || resourceType == ResourceTypeEnum.VF || resourceType == ResourceTypeEnum.PNF || resourceType == ResourceTypeEnum.CVFC)
- return false;
- return true;
- }
+
private static Service convertToService(ToscaElement toscaElement) {
Service service = new Service();
@@ -303,6 +315,7 @@ public class ModelConverter {
relationshipPair.setCapabilityOwnerId(relation.getCapabilityOwnerId());
relationshipPair.setCapabilityUid(relation.getCapabilityId());
+ relationshipPair.setCapability(relation.getCapability());
relationshipPair.setRequirementOwnerId(relation.getRequirementOwnerId());
relationshipPair.setRequirementUid(relation.getRequirementId());
relationshipPair.setRequirement(relation.getRequirement());
@@ -991,18 +1004,7 @@ public class ModelConverter {
toscaElement.setMetadataValue(JsonPresentationFields.CONTACT_ID, component.getContactId());
}
- public static boolean isAtomicComponent(Component component) {
- ComponentTypeEnum componentType = component.getComponentType();
- if (!componentType.equals(ComponentTypeEnum.RESOURCE)) {
- return false;
- }
- Resource resource = (Resource) component;
- ResourceTypeEnum resType = resource.getResourceType();
- if (resType == ResourceTypeEnum.VFC || resType == ResourceTypeEnum.VFCMT || resType == ResourceTypeEnum.VL || resType == ResourceTypeEnum.CP || resType == ResourceTypeEnum.ABSTRACT) {
- return true;
- }
- return false;
- }
+
private static void setComponentInstancesToComponent(TopologyTemplate topologyTemplate, Component component) {
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaDataDefinition.java
index df73adaa4a..b8d164e4aa 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaDataDefinition.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.stream.Collectors;
import org.codehaus.jackson.annotate.JsonCreator;
@@ -104,4 +105,13 @@ public abstract class ToscaDataDefinition {
public boolean findUidMatch(String uid){
return uid.equals(getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID));
}
+ public <T extends ToscaDataDefinition> T removeByOwnerId(Set<String> ownerIdList) {
+ return (T) this;
+ }
+ public static <T extends ToscaDataDefinition> T removeAndCollectByOwnerId(T complexStructure, Set<String> ownerIdList) {
+ return complexStructure.removeByOwnerId(ownerIdList);
+ }
+ public boolean isEmpty(){
+ return false;
+ }
}
diff --git a/sdc-os-chef/pom.xml b/sdc-os-chef/pom.xml
index 896a75e503..04c2a9355f 100644
--- a/sdc-os-chef/pom.xml
+++ b/sdc-os-chef/pom.xml
@@ -259,6 +259,7 @@
</resources>
</configuration>
</execution>
+
<execution>
<id>copy-resources-test-apis-ci</id>
<phase>validate</phase>
diff --git a/sdc-os-chef/scripts/docker_sanity_run.sh b/sdc-os-chef/scripts/docker_sanity_run.sh
new file mode 100644
index 0000000000..339b538f7a
--- /dev/null
+++ b/sdc-os-chef/scripts/docker_sanity_run.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+
+
+function usage {
+ echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -s|--skipTests <Run-without-sanityDocker>] [ -h|--help ]"
+}
+
+
+function cleanup {
+ echo "performing old dockers cleanup"
+ docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'`
+ for X in ${docker_ids}
+ do
+ docker rm -f ${X}
+ done
+}
+
+
+function dir_perms {
+ mkdir -p /data/logs/BE/SDC/SDC-BE
+ mkdir -p /data/logs/FE/SDC/SDC-FE
+ chmod -R 777 /data/logs
+}
+
+function monitor_docker {
+
+echo monitor $1 Docker
+sleep 10
+TIME_OUT=800
+INTERVAL=20
+TIME=0
+while [ "$TIME" -lt "$TIME_OUT" ]; do
+
+MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
+echo MATCH is -- $MATCH
+
+if [ -n "$MATCH" ]
+ then
+ echo DOCKER start finished in $TIME seconds
+ break
+ fi
+
+ echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
+ sleep $INTERVAL
+ TIME=$(($TIME+$INTERVAL))
+done
+
+if [ "$TIME" -ge "$TIME_OUT" ]
+ then
+ echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
+fi
+
+
+}
+
+
+RELEASE=latest
+LOCAL=false
+SKIPTESTS=false
+DEBUG_PORT="--publish 4000:4000"
+
+[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
+[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release
+[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
+[ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=ecomp-nexus:${PORT}
+
+while test $# -gt 0; do
+ case $1 in
+ -r | --release )
+ shift
+ RELEASE=$1
+ ;;
+ -e | --environment )
+ shift
+ DEP_ENV=$1
+ ;;
+ -p | --port )
+ shift
+ PORT=$1
+ ;;
+ -l | --local )
+ shift
+ LOCAL=true
+ ;;
+ -s | --skipTests )
+ shift
+ SKIPTESTS=true
+ ;;
+ -h | --help )
+ usage
+ exit
+ ;;
+ * )
+ usage
+ exit 1
+ esac
+done
+
+[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
+
+
+
+
+export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
+export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp'
+
+if [ ${LOCAL} = true ]; then
+ PREFIX='openecomp'
+fi
+
+echo ""
+
+
+# sanityDocker
+echo "docker run sdc-frontend..."
+if [ ${SKIPTESTS} = false ]; then
+echo "Triger sanity docker, please wait..."
+ if [ ${LOCAL} = false ]; then
+ docker pull ${PREFIX}/sdc-sanity:${RELEASE}
+ fi
+ docker run --detach --name sdc-sanity --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 1.2g --memory-swap=1.2g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/sdc-sanity/target:/var/lib/tests/target --volume /data/logs/sdc-sanity/ExtentReport:/var/lib/tests/ExtentReport --volume /data/environments:/root/chef-solo/environments --publish 8849:8849 --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE}
+fi
diff --git a/sdc-os-chef/scripts/sanity_run.sh b/sdc-os-chef/scripts/sanity_run.sh
new file mode 100644
index 0000000000..17d1642c73
--- /dev/null
+++ b/sdc-os-chef/scripts/sanity_run.sh
@@ -0,0 +1,117 @@
+#!/bin/bash
+
+
+function usage {
+ echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -s|--skipTests <Run-without-sanityDocker>] [ -h|--help ]"
+}
+
+
+function cleanup {
+ echo "performing old dockers cleanup"
+ docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc-sanity|sdc-sanity|Exit" | awk '{print $1}'`
+ for X in ${docker_ids}
+ do
+ docker rm -f ${X}
+ done
+}
+
+
+function dir_perms {
+ mkdir -p /data/logs/BE/SDC/SDC-BE
+ mkdir -p /data/logs/FE/SDC/SDC-FE
+ chmod -R 777 /data/logs
+}
+
+function monitor_docker {
+
+echo monitor $1 Docker
+sleep 5
+TIME_OUT=900
+INTERVAL=20
+TIME=0
+while [ "$TIME" -lt "$TIME_OUT" ]; do
+
+MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
+echo MATCH is -- $MATCH
+
+if [ -n "$MATCH" ]
+ then
+ echo DOCKER start finished in $TIME seconds
+ break
+ fi
+
+ echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
+ sleep $INTERVAL
+ TIME=$(($TIME+$INTERVAL))
+done
+
+if [ "$TIME" -ge "$TIME_OUT" ]
+ then
+ echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
+fi
+
+
+}
+
+
+RELEASE=latest
+LOCAL=false
+SKIPTESTS=false
+DEBUG_PORT="--publish 4000:4000"
+
+[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
+[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release
+[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
+[ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=ecomp-nexus:${PORT}
+
+while [ "$1" != "" ]; do
+ case $1 in
+ -r | --release )
+ shift
+ RELEASE=${1}
+ ;;
+ -e | --environment )
+ shift
+ DEP_ENV=${1}
+ ;;
+ -p | --port )
+ shift
+ PORT=${1}
+ ;;
+ -l | --local )
+ shift
+ LOCAL=true
+ ;;
+ -s | --skipTests )
+ shift
+ SKIPTESTS=true
+ ;;
+ -h | --help )
+ usage
+ exit
+ ;;
+ * )
+ usage
+ exit 1
+ esac
+ shift
+done
+
+[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
+
+export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'`
+export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp'
+
+if [ ${LOCAL} = true ]; then
+ PREFIX='openecomp'
+fi
+
+## sanityDocker
+echo "docker run sdc-sanity..."
+if [ ${SKIPTESTS} = false ]; then
+echo "Triger sanity docker, please wait..."
+ if [ ${LOCAL} = false ]; then
+ docker pull ${PREFIX}/sdc-sanity:${RELEASE}
+ fi
+ docker run --detach --name sdc-sanity --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 1g --memory-swap=1g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/sdc-sanity/target:/var/lib/tests/target --volume /data/logs/sdc-sanity/ExtentReport:/var/lib/tests/ExtentReport --volume /data/logs/sdc-sanity/outputCsar:/var/lib/tests/outputCsar --volume /data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE}
+fi \ No newline at end of file
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vPCRF_aligned_fixed.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vPCRF.csar
index 6f997bcf98..6f997bcf98 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vPCRF_aligned_fixed.csar
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vPCRF.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW.csar
new file mode 100644
index 0000000000..e7eed4b7c6
--- /dev/null
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW_fixed.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW_fixed.csar
deleted file mode 100644
index fa83c17d20..0000000000
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/Huawei_vSPGW_fixed.csar
+++ /dev/null
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/resource-ZteEpcMmeVf-csar_fix.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcMmeVf.csar
index bf0e775102..bf0e775102 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/resource-ZteEpcMmeVf-csar_fix.csar
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcMmeVf.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcSpgwVf-csar.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcSpgwVf.csar
index 0eacd74655..0eacd74655 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcSpgwVf-csar.csar
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ZteEpcSpgwVf.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/cscf_si_fixed.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/cscf_si.csar
index bc8397a86e..da19f0dd29 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/cscf_si_fixed.csar
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/cscf_si.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ntas.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ntas.csar
deleted file mode 100644
index 6b6f7c4d8c..0000000000
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/ntas.csar
+++ /dev/null
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_aligned.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF.csar
index 347b8bcced..347b8bcced 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_aligned.csar
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_v3.0.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_v3.0.csar
index 1c52cca12d..094810a3f7 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_v3.0.csar
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vCSCF_v3.0.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vSBC_aligned.csar b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vSBC.csar
index ee60eed872..ee60eed872 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vSBC_aligned.csar
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vSBC.csar
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/base_vfw.zip b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vfw.zip
index b8273defea..b8273defea 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/base_vfw.zip
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vfw.zip
Binary files differ
diff --git a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/base_vvg.zip b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vvg.zip
index dc9ef5d823..dc9ef5d823 100644
--- a/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/base_vvg.zip
+++ b/sdc-os-chef/sdc-sanity/chef-repo/cookbooks/sdc-sanity/files/default/Files/VNFs/vvg.zip
Binary files differ
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/ComponentBaseTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/ComponentBaseTest.java
index 9af3b6bc05..67091f3898 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/ComponentBaseTest.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/api/ComponentBaseTest.java
@@ -116,7 +116,7 @@ public abstract class ComponentBaseTest {
config = Utils.getConfig();
myContext=context;
ExtentManager.initReporter(getReportFolder(), REPORT_FILE_NAME, context);
- AtomicOperationUtils.createDefaultConsumer(true);
+// AtomicOperationUtils.createDefaultConsumer(true);
openTitanLogic();
performClean();
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java
index 95953838c9..6828a5ef2a 100644
--- a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java
+++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/utils/rest/ResponseParser.java
@@ -187,7 +187,7 @@ public class ResponseParser {
Resource resource = null;
try {
// TODO Andrey L. uncomment line below in case to ignore on unknown properties, not recommended
-// mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
resource = mapper.readValue(response, Resource.class);
logger.debug(resource.toString());