summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java138
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java189
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java130
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java62
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java56
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java31
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java361
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java282
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java2019
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java140
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java55
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java14
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java44
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java36
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java60
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java71
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java63
-rw-r--r--catalog-be/src/main/resources/config/SDC.zipbin30057 -> 29275 bytes
-rw-r--r--catalog-be/src/main/resources/config/configuration.yaml27
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml518
-rw-r--r--catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml53
-rw-r--r--catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zipbin5277 -> 5408 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types.zipbin72549 -> 0 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.yml11
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.zipbin0 -> 320 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.yml20
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.zipbin790 -> 780 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.yml10
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.zipbin0 -> 714 bytes
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.json21
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.yml10
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.zipbin0 -> 759 bytes
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py7
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json7
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py110
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py5
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py47
-rw-r--r--catalog-be/src/main/webapp/WEB-INF/web.xml1
53 files changed, 2959 insertions, 1803 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 cb04cfcdc9..77900efd82 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
@@ -340,10 +340,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private boolean artifactGenerationRequired(org.openecomp.sdc.be.model.Component component, ArtifactDefinition artifactInfo) {
boolean needGenerate;
needGenerate = artifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA && (component.getLifecycleState() == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || component.getLifecycleState() == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- needGenerate = needGenerate || (ComponentTypeEnum.RESOURCE == component.getComponentType() && artifactInfo.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType()));
+ needGenerate = needGenerate || (ComponentTypeEnum.RESOURCE == component.getComponentType() && (artifactInfo.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType()) || isAbstractVfcEmptyCsar((Resource) component, artifactInfo)));
return needGenerate;
}
+ private boolean isAbstractVfcEmptyCsar(Resource resource, ArtifactDefinition artifactInfo) {
+ return resource.isAbstract() && artifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA && artifactInfo.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType()) && StringUtils.isEmpty(artifactInfo.getArtifactChecksum());
+ }
+
public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateAndSaveToscaArtifact(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest,
boolean shouldLock, boolean inTransaction, boolean fetchTemplatesFromDB) {
@@ -798,13 +802,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(artifactResult.left().value());
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleCreate(String parentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, User user, ComponentTypeEnum componentType,
+ private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleCreate(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, User user, ComponentTypeEnum componentType,
org.openecomp.sdc.be.model.Component parent, String origMd5, String originData, String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
String artifactId = null;
// step 11
- Either<byte[], ResponseFormat> payloadEither = validateInput(parentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceType, operationName, inTransaction);
+ Either<byte[], ResponseFormat> payloadEither = validateInput(componentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceType, operationName, inTransaction);
if (payloadEither.isRight()) {
return Either.right(payloadEither.right().value());
}
@@ -814,14 +818,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (shouldLock) {
Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Upload Artifact - lock ");
if (lockComponent.isRight()) {
- handleAuditing(auditingAction, parent, parentId, user, null, null, null, lockComponent.right().value(), componentType, null);
+ handleAuditing(auditingAction, parent, componentId, user, null, null, null, lockComponent.right().value(), componentType, null);
return Either.right(lockComponent.right().value());
}
}
Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
try {
- resultOp = createArtifact(parent, parentId, artifactInfo, decodedPayload, user, componentType, auditingAction, interfaceType, operationName);
+ resultOp = createArtifact(parent, componentId, artifactInfo, decodedPayload, user, componentType, auditingAction, interfaceType, operationName);
return resultOp;
} finally {
if (shouldLock) {
@@ -872,28 +876,28 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return lockComponentAndUpdateArtifact(parentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, decodedPayload, interfaceType, operationName, shouldLock, inTransaction);
}
- private Either<byte[], ResponseFormat> validateInput(String parentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
+ private Either<byte[], ResponseFormat> validateInput(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
org.openecomp.sdc.be.model.Component parent, String origMd5, String originData, String interfaceType, String operationName, boolean inTransaction) {
// Md5 validations
Either<Boolean, ResponseFormat> validateMd5 = validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
if (validateMd5.isRight()) {
ResponseFormat responseFormat = validateMd5.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
return Either.right(responseFormat);
}
// step 11
- Either<ArtifactDefinition, ResponseFormat> validateResult = validateInput(parentId, artifactInfo, operation, artifactId, user, interfaceType, operationName, componentType, parent, inTransaction);
+ Either<ArtifactDefinition, ResponseFormat> validateResult = validateInput(componentId, artifactInfo, operation, artifactId, user, interfaceType, operationName, componentType, parent, inTransaction);
if (validateResult.isRight()) {
ResponseFormat responseFormat = validateResult.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
return Either.right(validateResult.right().value());
}
Either<byte[], ResponseFormat> payloadEither = handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
if (payloadEither.isRight()) {
ResponseFormat responseFormat = payloadEither.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
log.debug("Error during handle payload");
return Either.right(responseFormat);
}
@@ -903,7 +907,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers = validateAndConvertHeatParamers(artifactInfo, artifactInfo.getArtifactType());
if (validateAndConvertHeatParamers.isRight()) {
ResponseFormat responseFormat = validateAndConvertHeatParamers.right().value();
- handleAuditing(auditingAction, parent, parentId, user, artifactInfo, null, artifactId, responseFormat, componentType, null);
+ handleAuditing(auditingAction, parent, componentId, user, artifactInfo, null, artifactId, responseFormat, componentType, null);
log.debug("Error during handle payload");
return Either.right(responseFormat);
}
@@ -1025,9 +1029,16 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(true);
}
- private Either<ArtifactDefinition, ResponseFormat> validateInput(String parentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, String artifactId, User user, String interfaceName, String operationName,
+ private Either<ArtifactDefinition, ResponseFormat> validateInput(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, String artifactId, User user, String interfaceName, String operationName,
ComponentTypeEnum componentType, Component parentComponent, boolean inTransaction) {
+ Either<ArtifactDefinition, ResponseFormat> artifactById = findArtifactOnParentComponent(parentComponent, componentType, componentId, operation, artifactId);
+ if (artifactById.isRight()) {
+ return Either.right(artifactById.right().value());
+ }
+ ArtifactDefinition currentArtifactInfo = artifactById.left().value();
+
+ ignoreUnupdateableFieldsInUpdate(operation, artifactInfo, currentArtifactInfo);
Either<Boolean, ResponseFormat> validateInformationalArtifactRes = validateInformationalArtifact(artifactInfo, parentComponent);
if (validateInformationalArtifactRes.isRight()) {
return Either.right(validateInformationalArtifactRes.right().value());
@@ -1036,16 +1047,11 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (validateAndSetArtifactname.isRight()) {
return Either.right(validateAndSetArtifactname.right().value());
}
- Either<ArtifactDefinition, ResponseFormat> artifactById = findArtifactOnParentComponent(parentComponent, componentType, parentId, operation, artifactId);
- if (artifactById.isRight()) {
- return Either.right(artifactById.right().value());
- }
- ArtifactDefinition currentArtifactInfo = artifactById.left().value();
if (operationName != null && interfaceName != null) {
operationName = operationName.toLowerCase();
interfaceName = interfaceName.toLowerCase();
}
- Either<ActionStatus, ResponseFormat> logicalNameStatus = handleArtifactLabel(parentId, operation, artifactId, artifactInfo, interfaceName, operationName, currentArtifactInfo, componentType, inTransaction);
+ Either<ActionStatus, ResponseFormat> logicalNameStatus = handleArtifactLabel(componentId, parentComponent, operation, artifactId, artifactInfo, interfaceName, operationName, currentArtifactInfo, componentType);
if (logicalNameStatus.isRight()) {
return Either.right(logicalNameStatus.right().value());
}
@@ -1058,7 +1064,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
checkCreateFields(user, artifactInfo, (operationName != null ? ArtifactGroupTypeEnum.LIFE_CYCLE : ArtifactGroupTypeEnum.INFORMATIONAL));
}
- composeArtifactId(parentId, artifactId, artifactInfo, interfaceName, operationName);
+ composeArtifactId(componentId, artifactId, artifactInfo, interfaceName, operationName);
if (currentArtifactInfo != null) {
artifactInfo.setMandatory(currentArtifactInfo.getMandatory());
}
@@ -1077,7 +1083,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
boolean isCreate = operation.getArtifactOperationEnum() == ArtifactOperationEnum.Create;
if (isDeploymentArtifact(artifactInfo)) {
- Either<Boolean, ResponseFormat> deploymentValidationResult = validateDeploymentArtifact(parentComponent, parentId, user.getUserId(), isCreate, artifactInfo, currentArtifactInfo, parentType);
+ Either<Boolean, ResponseFormat> deploymentValidationResult = validateDeploymentArtifact(parentComponent, componentId, user.getUserId(), isCreate, artifactInfo, currentArtifactInfo, parentType);
if (deploymentValidationResult.isRight()) {
return Either.right(deploymentValidationResult.right().value());
}
@@ -1135,6 +1141,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(artifactInfo);
}
+ private void ignoreUnupdateableFieldsInUpdate(ArtifactOperationInfo operation, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifactInfo) {
+ if(operation.getArtifactOperationEnum().equals(ArtifactOperationEnum.Update)){
+ artifactInfo.setArtifactType(currentArtifactInfo.getArtifactType());
+ artifactInfo.setArtifactGroupType(currentArtifactInfo.getArtifactGroupType());
+ artifactInfo.setArtifactLabel(currentArtifactInfo.getArtifactLabel());
+ }
+ }
+
private Either<ArtifactDefinition, ResponseFormat> findArtifactOnParentComponent(Component parentComponent, ComponentTypeEnum componentType, String parentId, ArtifactOperationInfo operation, String artifactId) {
Either<ArtifactDefinition, ResponseFormat> result = null;
@@ -1474,13 +1488,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private void resetMandatoryArtifactFields(ArtifactDefinition fetchedArtifact) {
if (fetchedArtifact != null) {
log.debug("Going to reset mandatory artifact {} fields. ", fetchedArtifact.getUniqueId());
- fetchedArtifact.setEsId("");
- fetchedArtifact.setArtifactName("");
- fetchedArtifact.setDescription("");
- fetchedArtifact.setApiUrl("");
- fetchedArtifact.setArtifactChecksum("");
+ fetchedArtifact.setEsId(null);
+ fetchedArtifact.setArtifactName(null);
+ fetchedArtifact.setDescription(null);
+ fetchedArtifact.setApiUrl(null);
+ fetchedArtifact.setArtifactChecksum(null);
nodeTemplateOperation.setDefaultArtifactTimeout(fetchedArtifact.getArtifactGroupType(), fetchedArtifact);
- fetchedArtifact.setArtifactUUID("");
+ fetchedArtifact.setArtifactUUID(null);
long time = System.currentTimeMillis();
fetchedArtifact.setPayloadUpdateDate(time);
fetchedArtifact.setHeatParameters(null);
@@ -1540,10 +1554,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(currentArtifactInfo);
}
- private Either<ActionStatus, ResponseFormat> handleArtifactLabel(String componentId, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo, String interfaceName, String operationName,
- ArtifactDefinition currentArtifactInfo, ComponentTypeEnum componentType, boolean inTransaction) {
- String artifactLabel = artifactInfo.getArtifactLabel();
+ private Either<ActionStatus, ResponseFormat> handleArtifactLabel(String componentId, Component parentComponent, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo, String interfaceName, String operationName,
+ ArtifactDefinition currentArtifactInfo, ComponentTypeEnum componentType) {
+ String artifactLabel = artifactInfo.getArtifactLabel();
if (operationName == null && (artifactInfo.getArtifactLabel() == null || artifactInfo.getArtifactLabel().isEmpty())) {
BeEcompErrorManager.getInstance().logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
log.debug("missing artifact logical name for component {}", componentId);
@@ -1584,27 +1598,25 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
log.debug("Invalid lenght form Artifact label : {}", artifactLabel);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, ARTIFACT_LABEL, String.valueOf(ValidationUtils.ARTIFACT_LABEL_LENGTH)));
}
- if (!validateLabelUniqueness(componentId, artifactLabel, componentType)) {
+ if (!validateLabelUniqueness(componentId, parentComponent, artifactLabel, componentType)) {
log.debug("Non unique Artifact label : {}", artifactLabel);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST, artifactLabel));
}
}
artifactInfo.setArtifactLabel(artifactLabel);
- if (currentArtifactInfo != null && !currentArtifactInfo.getArtifactLabel().equals(artifactInfo.getArtifactLabel())) {
- log.info("Logical artifact's name cannot be changed {}", artifactId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED));
- }
return Either.left(ActionStatus.OK);
}
- private boolean validateLabelUniqueness(String parentId, String artifactLabel, ComponentTypeEnum componentType) {
+ private boolean validateLabelUniqueness(String componentId, Component parentComponent, String artifactLabel, ComponentTypeEnum componentType) {
boolean isUnique = true;
- if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifacts;
+ if (componentType.equals(ComponentTypeEnum.RESOURCE_INSTANCE)) {
+ artifacts = artifactToscaOperation.getAllInstanceArtifacts(parentComponent.getUniqueId(), componentId);
} else {
+ artifacts = artifactToscaOperation.getArtifacts(componentId);
}
- // Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifacts = artifactOperation.getArtifacts(parentId, parentType, inTransaction);
- Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifacts = artifactToscaOperation.getArtifacts(parentId);
+
if (artifacts.isLeft()) {
for (String label : artifacts.left().value().keySet()) {
if (label.equals(artifactLabel)) {
@@ -1614,7 +1626,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
- Either<Map<String, InterfaceDefinition>, StorageOperationStatus> allInterfacesOfResource = interfaceLifecycleOperation.getAllInterfacesOfResource(parentId, true, true);
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> allInterfacesOfResource = interfaceLifecycleOperation.getAllInterfacesOfResource(componentId, true, true);
if (allInterfacesOfResource.isLeft()) {
for (InterfaceDefinition interace : allInterfacesOfResource.left().value().values()) {
for (Operation operation : interace.getOperationsMap().values()) {
@@ -2749,8 +2761,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
} else if (ArtifactTypeEnum.YANG_XML.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.VNF_CATALOG.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.VF_LICENSE.getType().equalsIgnoreCase(artifactType)
|| ArtifactTypeEnum.VENDOR_LICENSE.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.getType().equalsIgnoreCase(artifactType)
- || ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().equalsIgnoreCase(artifactType)) {
- isValidPayload = validateYangPayload(decodedPayload, artifactType);
+ || ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().equalsIgnoreCase(artifactType) || ArtifactTypeEnum.UCPE_LAYER_2_CONFIGURATION.getType().equalsIgnoreCase(artifactType)) {
+ isValidPayload = validateXmlPayload(decodedPayload, artifactType);
// else
// if(ArtifactTypeEnum.APPC_CONFIG.getType().equalsIgnoreCase(artifactType)
// || ){
@@ -2760,7 +2772,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String fileExtension = GeneralUtility.getFilenameExtension(artifactFileName).toLowerCase();
switch (fileExtension) {
case "xml":
- isValidPayload = validateYangPayload(decodedPayload, artifactType);
+ isValidPayload = validateXmlPayload(decodedPayload, artifactType);
break;
case "json":
isValidPayload = validateJsonPayload(decodedPayload, artifactType);
@@ -2824,7 +2836,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return res;
}
- private Either<Boolean, ResponseFormat> validateYangPayload(byte[] payload, String artifactType) {
+ private Either<Boolean, ResponseFormat> validateXmlPayload(byte[] payload, String artifactType) {
boolean isXmlValid = isValidXml(payload);
if (!isXmlValid) {
ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.INVALID_XML, artifactType);
@@ -3515,11 +3527,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private String generateHeatEnvPayload(ArtifactDefinition artifactDefinition) {
List<HeatParameterDefinition> heatParameters = artifactDefinition.getListHeatParameters();
- heatParameters.sort(Comparator.comparing(e -> e.getName()));
StringBuilder sb = new StringBuilder();
sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader());
sb.append("parameters:\n");
if (heatParameters != null) {
+ heatParameters.sort(Comparator.comparing(e -> e.getName()));
+
List<HeatParameterDefinition> empltyHeatValues = new ArrayList<>();
for (HeatParameterDefinition heatParameterDefinition : heatParameters) {
@@ -3885,7 +3898,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* currently getArtifactById does not retrieve heatParameters Either<ArtifactDefinition, StorageOperationStatus> artifactRes = artifactOperation.getArtifactById(artifactId, false); ArtifactDefinition currArtifact = artifactRes.left().value();
*/
String currentHeatId = currHeatArtifact.getUniqueId();
-
+
String esArtifactId = currHeatArtifact.getEsId();
Either<ESArtifactData, CassandraOperationStatus> artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
if (artifactfromES.isRight()) {
@@ -3898,8 +3911,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
ESArtifactData esArtifactData = artifactfromES.left().value();
byte[] data = esArtifactData.getDataAsArray();
-
-
+
+
ArtifactDefinition updatedHeatArt = currHeatArtifact;
List<HeatParameterDefinition> updatedHeatEnvParams = artifactEnvInfo.getListHeatParameters();
@@ -3948,7 +3961,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (!updatedHeatArt.getDuplicated() || esArtifactData.getId() == null)
esArtifactData.setId(updatedHeatArt.getEsId());
res = saveArtifacts(esArtifactData, parent.getUniqueId(), false);
-
+
if (res) {
log.debug("Artifact saved into ES - {}", updatedHeatArt.getUniqueId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
@@ -3963,7 +3976,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
resultOp = Either.right(responseFormat);
// return resultOp;
}
-
+
insideEither = Either.left(updatedHeatArt);
}
}
@@ -3975,13 +3988,17 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
updateHeatEnvArtifact = artifactToscaOperation.updateHeatEnvPlaceholder(artifactEnvInfo, componentId, componentType.getNodeType());
}
- if ( needToUpdateGroup && updateHeatEnvArtifact.isLeft() ){
+ if (needToUpdateGroup && updateHeatEnvArtifact.isLeft()) {
ActionStatus result = updateGroupForHeat(currHeatArtifact, updatedHeatArt, artifactEnvInfo, updateHeatEnvArtifact.left().value(), parent, componentType);
- if ( result != ActionStatus.OK ){
+ if (result != ActionStatus.OK) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(result);
return Either.right(responseFormat);
}
}
+
+ if (updatedHeatEnvParams.isEmpty()) {
+ return getResponseAndAuditInvalidEmptyHeatEnvFile(auditingAction, parent, parent.getUniqueId(), user, currHeatArtifact, artifactId, componentType);
+ }
resultOp = Either.left(insideEither);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
handleAuditing(auditingAction, parent, parent.getUniqueId(), user, currHeatArtifact, null, artifactId, responseFormat, componentType, "");
@@ -3989,6 +4006,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
+ private Either<Either<ArtifactDefinition,Operation>,ResponseFormat> getResponseAndAuditInvalidEmptyHeatEnvFile(AuditingActionEnum auditingAction, Component parent, String uniqueId, User user, ArtifactDefinition currHeatArtifact, String artifactId, ComponentTypeEnum componentType) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML);
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, currHeatArtifact, null, artifactId, responseFormat, componentType, "");
+ return Either.right(responseFormat);
+ }
+
+
private StorageOperationStatus generateCustomizationUUIDOnGroupInstance(ComponentInstance ri, String artifactId, String componentId) {
StorageOperationStatus error = StorageOperationStatus.OK;
log.debug("Need to re-generate customization UUID for group instance on component instance {}", ri.getUniqueId());
@@ -4091,7 +4115,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Component component = getComponentByUuid(componentType, componentUuid, errorWrapper);
if (errorWrapper.isEmpty()) {
auditAdditionalParam.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, component.getName());
- downloadedArtifact = downloadArtifact(component.getDeploymentArtifacts(), artifactUUID, errorWrapper, component.getName());
+ downloadedArtifact = downloadArtifact(component.getAllArtifacts(), artifactUUID, errorWrapper, component.getName());
}
if (errorWrapper.isEmpty()) {
result = Either.left(downloadedArtifact);
@@ -4270,7 +4294,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Component component = null;
String componentId = null;
String artifactId = null;
- ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinitionForUpdate(data, ArtifactDefinition.class);
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
@@ -4732,17 +4756,17 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
byte[] downloadedArtifact = null;
Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = null;
- List<ArtifactDefinition> deploymentArtifacts = null;
+ List<ArtifactDefinition> artifactsList = null;
ArtifactDefinition deploymentArtifact = null;
if (artifacts != null && !artifacts.isEmpty()) {
- deploymentArtifacts = artifacts.values().stream().filter(art -> art.getArtifactUUID() != null && art.getArtifactUUID().equals(artifactUUID)).collect(Collectors.toList());
+ artifactsList = artifacts.values().stream().filter(art -> art.getArtifactUUID() != null && art.getArtifactUUID().equals(artifactUUID)).collect(Collectors.toList());
}
- if (deploymentArtifacts == null || deploymentArtifacts.isEmpty()) {
+ if (artifactsList == null || artifactsList.isEmpty()) {
log.debug("Deployment artifact with uuid {} was not found for component {}", artifactUUID, componentName);
errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactUUID));
}
if (errorWrapper.isEmpty()) {
- deploymentArtifact = deploymentArtifacts.get(0);
+ deploymentArtifact = artifactsList.get(0);
downloadArtifactEither = downloadArtifact(deploymentArtifact);
if (downloadArtifactEither.isRight()) {
log.debug("Failed to download artifact {}. ", deploymentArtifact.getArtifactName());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index df8460ca96..1d153e0a5d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -47,6 +47,7 @@ import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.be.model.IComplexDefaultValue;
+import org.openecomp.sdc.be.model.IPropertyInputCommon;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
@@ -391,11 +392,10 @@ public abstract class BaseBusinessLogic {
}
protected Either<Boolean, ResponseFormat> validatePropertyDefaultValue(IComplexDefaultValue property, Map<String, DataTypeDefinition> dataTypes) {
- log.debug("validate property");
String type = null;
String innerType = null;
if (!propertyOperation.isPropertyTypeValid(property)) {
- log.info("Invalid type for property");
+ log.info("Invalid type for property {} type {}", property.getName(), property.getType());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
return Either.right(responseFormat);
}
@@ -404,13 +404,13 @@ public abstract class BaseBusinessLogic {
ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, dataTypes);
innerType = propertyInnerTypeValid.getLeft();
if (!propertyInnerTypeValid.getRight().booleanValue()) {
- log.info("Invalid inner type for property");
+ log.info("Invalid inner type for property {} type {}", property.getName(), property.getType() );
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
return Either.right(responseFormat);
}
}
if (!propertyOperation.isPropertyDefaultValueValid(property, dataTypes)) {
- log.info("Invalid default value for property");
+ log.info("Invalid default value for property {} type {}", property.getName(), property.getType() );
ResponseFormat responseFormat;
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType, property.getDefaultValue());
@@ -568,7 +568,7 @@ public abstract class BaseBusinessLogic {
return Arrays.asList(enumValues).contains(enumFound);
}
- protected Either<String, StorageOperationStatus> validatePropValueBeforeCreate(ComponentInstanceProperty property, String value, boolean isValidate, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
+ protected Either<String, StorageOperationStatus> validatePropValueBeforeCreate(IPropertyInputCommon property, String value, boolean isValidate, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
String propertyType = property.getType();
ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
@@ -603,7 +603,7 @@ public abstract class BaseBusinessLogic {
}
ImmutablePair<String, Boolean> pair = validateAndUpdateRules(propertyType, property.getRules(), innerType, allDataTypes, isValidate);
- log.debug("After validateAndUpdateRules. pair = {}", pair);
+ log.trace("After validateAndUpdateRules. pair = {}", pair);
if (pair.getRight() != null && pair.getRight() == false) {
BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(), property.getName(), propertyType);
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java
new file mode 100644
index 0000000000..237ec6d5fe
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java
@@ -0,0 +1,189 @@
+package org.openecomp.sdc.be.components.impl;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.annotation.PostConstruct;
+
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.cassandra.schema.SdcSchemaUtils;
+import org.openecomp.sdc.be.dao.cassandra.schema.Table;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.KeyspaceMetadata;
+import com.datastax.driver.core.Metadata;
+import com.datastax.driver.core.Session;
+
+@Component("cassandra-health-check")
+public class CassandraHealthCheck {
+
+
+ private static Logger log = LoggerFactory.getLogger(CassandraHealthCheck.class.getName());
+
+ private String localDataCenterName = null;
+
+ private Set<String> sdcKeyspaces = new HashSet<String>();
+
+ private int HC_FormulaNumber;
+
+ @PostConstruct
+ private void init() {
+
+ //Initialize local data center name - this field must be filled by DevOps
+ localDataCenterName = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig().getLocalDataCenter();
+
+ if (GeneralUtility.isEmptyString(localDataCenterName)) {
+ log.error("localDataCenter Name in configuration.yaml is missing.");
+ return;
+ }
+
+ //Collect all SDC keyspaces
+ for (Table table : Table.values()) {
+ sdcKeyspaces.add(table.getTableDescription().getKeyspace());
+ }
+
+ String titanCfgFile = ConfigurationManager.getConfigurationManager().getConfiguration().getTitanCfgFile();
+ Properties prop = new Properties();
+ InputStream titanProp = null;
+ try {
+ //load a properties file
+ titanProp = new FileInputStream(titanCfgFile);
+ prop.load(titanProp);
+ //Add titan keyspace
+ String titanKeyspace = prop.getProperty("storage.cassandra.keyspace");
+ if (!GeneralUtility.isEmptyString(titanKeyspace)) {
+ sdcKeyspaces.add(titanKeyspace);
+ }
+ } catch (Exception e) {
+ log.error("Failed to open titen.properties file , url is : {}", titanCfgFile);
+ }
+
+ log.info("All sdc keyspaces are : {}", sdcKeyspaces);
+
+ //Calculate the Formula of Health Check
+ Cluster cluster = null;
+ try {
+
+ log.info("creating cluster for Cassandra Health Check.");
+ //Create cluster from nodes in cassandra configuration
+ cluster = SdcSchemaUtils.createCluster();
+ if (cluster == null) {
+ log.error("Failure create cassandra cluster.");
+ return;
+ }
+
+ Metadata metadata = cluster.getMetadata();
+
+ if (metadata == null) {
+ log.error("Failure get cassandra metadata.");
+ return;
+ }
+
+ log.info("Cluster Metadata: {}", metadata.toString());
+ List<KeyspaceMetadata> keyspaces = metadata.getKeyspaces();
+ List<Integer> replactionFactorList = new ArrayList<Integer>();
+
+ //Collect the keyspaces Replication Factor of current localDataCenter
+ for (KeyspaceMetadata keyspace : keyspaces) {
+
+ if (sdcKeyspaces.contains(keyspace.getName())) {
+
+ log.info("keyspace : {} , replication: {}", keyspace.getName(), keyspace.getReplication());
+ Map<String, String> replicationOptions = keyspace.getReplication();
+
+ //In 1 site with one data center
+ if (replicationOptions.containsKey("replication_factor")) {
+ replactionFactorList.add(Integer.parseInt(replicationOptions.get("replication_factor")));
+ }
+ //In multiple sites with some data center
+ else if (replicationOptions.containsKey(localDataCenterName)) {
+ replactionFactorList.add(Integer.parseInt(replicationOptions.get(localDataCenterName)));
+ }
+ }
+ }
+
+ if (replactionFactorList.size() == 0) {
+ log.error("Replication factor NOT found in all keyspaces");
+ return;
+ }
+
+ int maxReplicationFactor = Collections.max(replactionFactorList);
+ log.info("maxReplication Factor is: {}", maxReplicationFactor);
+
+ int localQuorum = maxReplicationFactor/2 + 1;
+ log.info("localQuorum is: {}", localQuorum);
+
+ HC_FormulaNumber = maxReplicationFactor - localQuorum;
+
+ log.info("Health Check formula : Replication Factor – Local_Quorum = {}", HC_FormulaNumber);
+
+
+ } catch (Exception e) {
+ log.error("create cassandra cluster failed with exception.", e);
+ } finally {
+ if (cluster != null) {
+ cluster.close();
+ }
+ }
+
+ }
+
+ public boolean getCassandraStatus() {
+
+ if (GeneralUtility.isEmptyString(localDataCenterName)) {
+ log.error("localDataCenter Name in configuration.yaml is missing.");
+ return false;
+ }
+
+ Cluster cluster = null;
+ Session session = null;
+ try {
+ log.info("creating cluster for Cassandra for monitoring.");
+ cluster = SdcSchemaUtils.createCluster();
+ if (cluster == null) {
+ log.error("Failure create cassandra cluster.");
+ return false;
+ }
+ session = cluster.connect();
+ Metadata metadata = cluster.getMetadata();
+
+ if (metadata == null) {
+ log.error("Failure get cassandra metadata.");
+ return false;
+ }
+
+ log.info("The number of cassandra nodes is:{}", metadata.getAllHosts().size());
+
+ //Count the number of data center nodes that are down
+ Long downHostsNumber = metadata.getAllHosts().stream()
+ .filter(x -> x.getDatacenter().equals(localDataCenterName) && !x.isUp()).count();
+
+ log.info("The cassandra down nodes number is {}", downHostsNumber.toString());
+ return (HC_FormulaNumber >= downHostsNumber);
+
+ } catch (Exception e) {
+ log.error("create cassandra cluster failed with exception.", e);
+ return false;
+ } finally {
+ if (session != null) {
+ session.close();
+ }
+ if (cluster != null) {
+ cluster.close();
+ }
+ }
+ }
+}
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 5ee5c88f69..21f7b3ab7c 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
@@ -69,7 +69,6 @@ import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.utils.CommonBeUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.config.EcompErrorName;
import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -183,11 +182,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return Either.right(errorResponse);
}
- description = ValidationUtils.removeNoneUtf8Chars(description);
- description = ValidationUtils.normaliseWhitespace(description);
- description = ValidationUtils.stripOctets(description);
- description = ValidationUtils.removeHtmlTagsOnly(description);
-
+ description = cleanUpText(description);
Either<Boolean, ResponseFormat> validatDescription = validateComponentDescription(description, type);
if (validatDescription.isRight()) {
ResponseFormat responseFormat = validatDescription.right().value();
@@ -666,19 +661,25 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
toscaArtifact = generateToscaRes.left().value().left().value();
component.getToscaArtifacts().put(toscaArtifact.getArtifactLabel(), toscaArtifact);
- toscaArtifact = component.getToscaArtifacts().values().stream()
- .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType()))
- .findAny().get();
- generateToscaRes = saveToscaArtifactPayload(toscaArtifact, component, user, isInCertificationRequest, shouldLock, inTransaction, true);
- }
- if (generateToscaRes.isRight()) {
- return generateToscaRes;
+ if(!isAbstractResource(component)){
+ toscaArtifact = component.getToscaArtifacts().values().stream()
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType()))
+ .findAny().get();
+ generateToscaRes = saveToscaArtifactPayload(toscaArtifact, component, user, isInCertificationRequest, shouldLock, inTransaction, true);
+ if (generateToscaRes.isRight()) {
+ return generateToscaRes;
+ }
+ toscaArtifact = generateToscaRes.left().value().left().value();
+ component.getToscaArtifacts().put(toscaArtifact.getArtifactLabel(), toscaArtifact);
+ }
}
- ArtifactDefinition toscaArtifact = generateToscaRes.left().value().left().value();
- component.getToscaArtifacts().put(toscaArtifact.getArtifactLabel(), toscaArtifact);
return generateToscaRes;
}
+ private boolean isAbstractResource(Component component) {
+ return component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource)component).isAbstract();
+ }
+
public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> saveToscaArtifactPayload(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest, boolean shouldLock,
boolean inTransaction, boolean fetchTemplatesFromDB) {
return artifactsBusinessLogic.generateAndSaveToscaArtifact(artifactDefinition, component, user, isInCertificationRequest, shouldLock, inTransaction, fetchTemplatesFromDB);
@@ -735,11 +736,11 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
}
- public Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Component currentComponent, Component updatedComponent, AuditingActionEnum audatingAction) {
+ public Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Component currentComponent, Component updatedComponent, AuditingActionEnum auditingAction) {
String descriptionUpdated = updatedComponent.getDescription();
String descriptionCurrent = currentComponent.getDescription();
if (descriptionUpdated != null && !descriptionCurrent.equals(descriptionUpdated)) {
- Either<Boolean, ResponseFormat> validateDescriptionResponse = validateDescriptionAndCleanup(user, updatedComponent, audatingAction);
+ Either<Boolean, ResponseFormat> validateDescriptionResponse = validateDescriptionAndCleanup(user, updatedComponent, auditingAction);
if (validateDescriptionResponse.isRight()) {
ResponseFormat errorRespons = validateDescriptionResponse.right().value();
return Either.right(errorRespons);
@@ -816,85 +817,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return Either.left(deleteMarkedElements.left().value());
}
- private Either<String, ResponseFormat> deleteMarkedComponent(String componentToDelete, ComponentTypeEnum componentType) {
-
- Either<String, ResponseFormat> result = null;
- NodeTypeEnum compNodeType = componentType.getNodeType();
- StorageOperationStatus lockResult = graphLockOperation.lockComponent(componentToDelete, compNodeType);
- if (!lockResult.equals(StorageOperationStatus.OK)) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, "Delete marked component");
- log.debug("Failed to lock component {} error - {}", componentToDelete, lockResult);
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- return result;
- }
- try {
-
- // check if resource has relations
- Either<Boolean, StorageOperationStatus> isResourceInUse = toscaOperationFacade.isComponentInUse(componentToDelete);
- if (isResourceInUse.isRight()) {
- log.info("deleteMarkedResource - failed to find relations to resource. id = {}, type = {}, error = {}", componentToDelete, componentType, isResourceInUse.right().value().name());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- result = Either.right(responseFormat);
- return result;
- }
-
- if (isResourceInUse.isLeft() && isResourceInUse.left().value() == false) {
-
- // delete resource and its artifacts in one transaction
- Either<List<ArtifactDefinition>, StorageOperationStatus> artifactsRes = getComponentArtifactsForDelete(componentToDelete, compNodeType, true);
- if (artifactsRes.isRight() && !artifactsRes.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
- log.info("failed to check artifacts for component node. id = {}, type = {}, error = {}", componentToDelete, componentType, artifactsRes.right().value().name());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- result = Either.right(responseFormat);
- return result;
- }
- List<ArtifactDefinition> artifactsToDelete = new ArrayList<>();
- if (artifactsRes.isLeft()) {
- artifactsToDelete = artifactsRes.left().value();
- }
-
- Either<Component, StorageOperationStatus> deleteComponentRes = toscaOperationFacade.deleteToscaComponent(componentToDelete);
- if (deleteComponentRes.isRight()) {
- log.info("failed to delete component. id = {}, type = {}, error = {}", componentToDelete, componentType, deleteComponentRes.right().value().name());
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteComponentRes.right().value());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete);
- result = Either.right(responseFormat);
- } else {
- log.trace("component was deleted, id = {}, type = {}", componentToDelete, componentType);
- // delete related artifacts
- StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(artifactsToDelete);
- if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete);
- result = Either.right(responseFormat);
- return result;
- }
- log.debug("component and all its artifacts were deleted, id = {}, type = {}", componentToDelete, componentType);
- result = Either.left(componentToDelete);
- }
- } else {
- // resource in use
- log.debug("componentis marked for delete but still in use, id = {}, type = {}", componentToDelete, componentType);
- ActionStatus actionStatus = ActionStatus.RESTRICTED_OPERATION;
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentToDelete);
- result = Either.right(responseFormat);
- return result;
- }
- } finally {
- if (result == null || result.isRight()) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "delete marked component");
- log.debug("operation failed. do rollback");
- titanDao.rollback();
- } else {
- log.debug("operation success. do commit");
- titanDao.commit();
- }
- graphLockOperation.unlockComponent(componentToDelete, compNodeType);
- }
-
- return result;
- }
-
public Either<List<ArtifactDefinition>, StorageOperationStatus> getComponentArtifactsForDelete(String parentId, NodeTypeEnum parentType, boolean inTransacton) {
List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifactsResponse = artifactToscaOperation.getArtifacts(parentId);
@@ -977,8 +899,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
protected <T extends Component> Either<Resource, ResponseFormat> fetchAndSetDerivedFromGenericType(T component){
-
- String genericTypeToscaName = component.fetchGenericTypeToscaNameFromConfig();
+ String genericTypeToscaName = null;
+ if(component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource)component).getResourceType() == ResourceTypeEnum.CVFC && CollectionUtils.isNotEmpty(((Resource)component).getDerivedFrom())){
+ genericTypeToscaName = ((Resource)component).getDerivedFrom().get(0);
+ } else {
+ genericTypeToscaName = component.fetchGenericTypeToscaNameFromConfig();
+ }
if(null == genericTypeToscaName)
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
Either<Resource, StorageOperationStatus> findLatestGeneric = toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(genericTypeToscaName);
@@ -1237,6 +1163,14 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
return isMatchingType;
}
+
+ protected String cleanUpText(String text){
+ text = ValidationUtils.removeNoneUtf8Chars(text);
+ text = ValidationUtils.normaliseWhitespace(text);
+ text = ValidationUtils.stripOctets(text);
+ text = ValidationUtils.removeHtmlTagsOnly(text);
+ return text;
+ }
}
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 643b35d17b..56cd91d754 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
@@ -58,10 +58,12 @@ 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.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
@@ -72,6 +74,7 @@ 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;
@@ -142,9 +145,9 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
containerComponent = validateComponentExists.left().value();
}
- Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances = validateAllowedToContainCompInstances(containerComponent);
- if (validateAllowedToContainCompInstances.isRight()) {
- return Either.right(validateAllowedToContainCompInstances.right().value());
+ if (ToscaUtils.isAtomicType(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()));
}
Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
@@ -201,9 +204,9 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
- Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances = validateAllowedToContainCompInstances(containerComponent);
- if (validateAllowedToContainCompInstances.isRight()) {
- return Either.right(validateAllowedToContainCompInstances.right().value());
+ if (ToscaUtils.isAtomicType(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()));
}
Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
@@ -383,14 +386,14 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
StorageOperationStatus artStatus = toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, finalDeploymentArtifacts);
if ( artStatus != StorageOperationStatus.OK){
log.debug("Failed to add instance deployment artifacts for instance {} in conatiner {} error {}", componentInstance.getUniqueId(), containerComponent.getUniqueId(), artStatus);
- return Either.left(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false));
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)));
}
StorageOperationStatus result = toscaOperationFacade
.addGroupInstancesToComponentInstance(containerComponent, componentInstance, filteredGroups, groupInstancesArtifacts);
if (result != StorageOperationStatus.OK) {
log.debug("failed to update group instance for component instance {}", componentInstance.getUniqueId());
- return Either.left(componentsUtils.convertFromStorageResponse(result));
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result)));
}
componentInstance.setDeploymentArtifacts(finalDeploymentArtifacts);
return Either.left(ActionStatus.OK);
@@ -620,6 +623,7 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Optional<ComponentInstance> componentInstanceOptional = null;
Either<ImmutablePair<Component, String>, StorageOperationStatus> updateRes = null;
ComponentInstance oldComponentInstance = null;
+ boolean isNameChanged = false;
if (resultOp == null) {
componentInstanceOptional = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(componentInstance.getUniqueId())).findFirst();
@@ -631,6 +635,9 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (resultOp == null) {
oldComponentInstance = componentInstanceOptional.get();
String newInstanceName = componentInstance.getName();
+ if ( oldComponentInstance!=null && oldComponentInstance.getName() != null
+ && !oldComponentInstance.getName().equals( newInstanceName ) )
+ isNameChanged = true;
Boolean isUniqueName = validateInstanceNameUniquenessUponUpdate(containerComponent, oldComponentInstance, newInstanceName);
if (!isUniqueName) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", oldComponentInstance.getName(), newInstanceName);
@@ -643,6 +650,14 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata of component instance {} belonging to container component {}. Status is {}. ", componentInstance.getName(), containerComponent.getName(),
updateRes.right().value());
resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(updateRes.right().value(), true), "", null));
+ }else{
+ //region - Update instance Groups
+ if ( isNameChanged ){
+ Either result = toscaOperationFacade.cleanAndAddGroupInstancesToComponentInstance( containerComponent ,oldComponentInstance ,componentInstanceId );
+ if ( result.isRight() )
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to rename group instances for container {}. error {} ", componentInstanceId ,result.right().value() );
+ }
+ //endregion
}
}
if (resultOp == null) {
@@ -662,11 +677,29 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
return resultOp;
}
+ /**
+ * @param oldPrefix- The normalized old vf name
+ * @param newNormailzedPrefix- The normalized new vf name
+ * @param qualifiedGroupInstanceName- old Group Instance Name
+ **/
+ //modify group names
+ private String getNewGroupName( String oldPrefix ,String newNormailzedPrefix , String qualifiedGroupInstanceName){
+ if (qualifiedGroupInstanceName == null){
+ log.info("CANNOT change group name ");
+ return null;
+ }
+ if (qualifiedGroupInstanceName.startsWith(oldPrefix) || qualifiedGroupInstanceName.startsWith(ValidationUtils.normalizeComponentInstanceName(oldPrefix)))
+ return qualifiedGroupInstanceName.replaceFirst(oldPrefix, newNormailzedPrefix);
+ return qualifiedGroupInstanceName;
+ }
private ComponentInstance updateComponentInstanceMetadata(ComponentInstance oldComponentInstance, ComponentInstance newComponentInstance) {
oldComponentInstance.setName(newComponentInstance.getName());
oldComponentInstance.setModificationTime(System.currentTimeMillis());
oldComponentInstance.setCustomizationUUID(UUID.randomUUID().toString());
+ if ( oldComponentInstance.getGroupInstances() != null )
+ oldComponentInstance.getGroupInstances().forEach( group ->
+ group.setName( getNewGroupName( oldComponentInstance.getNormalizedName() , ValidationUtils.normalizeComponentInstanceName( newComponentInstance.getName() ) , group.getName() ) ) );
return oldComponentInstance;
}
@@ -748,6 +781,17 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
resultOp = Either.right(componentsUtils.getResponseFormat(status, componentInstanceId));
}
}
+ if(resultOp.isLeft() && CollectionUtils.isNotEmpty(containerComponent.getInputs())){
+ List<InputDefinition> inputsToDelete = containerComponent.getInputs().stream().filter(i -> i.getInstanceUniqueId() != null && i.getInstanceUniqueId().equals(componentInstanceId)).collect(Collectors.toList());
+ if(CollectionUtils.isNotEmpty(inputsToDelete)){
+ StorageOperationStatus deleteInputsRes =
+ toscaOperationFacade.deleteComponentInstanceInputsFromTopologyTemplate(containerComponent, containerComponent.getComponentType(), inputsToDelete);
+ if(deleteInputsRes != StorageOperationStatus.OK){
+ log.debug("Failed to delete inputs of the component instance {} from container component. ", componentInstanceId);
+ resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteInputsRes, containerComponentType), componentInstanceId));
+ }
+ }
+ }
return resultOp;
}
@@ -1696,8 +1740,6 @@ public abstract class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
- protected abstract Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent);
-
protected abstract NodeTypeEnum getNodeTypeOfComponentInstanceOrigin();
protected abstract ComponentTypeEnum getComponentTypeOfComponentInstance();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
index 669b84f229..7214d011e0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java
@@ -20,19 +20,10 @@
package org.openecomp.sdc.be.components.impl;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
+import com.thinkaurelius.titan.core.TitanGraph;
+import fj.data.Either;
import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
@@ -47,24 +38,10 @@ import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
import org.openecomp.sdc.be.datamodel.utils.NodeTypeConvertUtils;
import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
+import org.openecomp.sdc.be.datatypes.enums.*;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.ArtifactType;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.DistributionStatusEnum;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Product;
-import org.openecomp.sdc.be.model.PropertyScope;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.ResourceMetadataDefinition;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.Tag;
-import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.GroupingDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
@@ -87,9 +64,10 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.thinkaurelius.titan.core.TitanGraph;
-
-import fj.data.Either;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
@org.springframework.stereotype.Component("elementsBusinessLogic")
public class ElementBusinessLogic extends BaseBusinessLogic {
@@ -1003,16 +981,16 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return elementOperation.getDefaultHeatTimeout();
}
- public Either<Map<String, List<? extends Component>>, ResponseFormat> getCatalogComponents(String userId) {
+ public Either<Map<String, List<? extends Component>>, ResponseFormat> getCatalogComponents(String userId, List<OriginTypeEnum> excludeTypes) {
Either<User, ResponseFormat> resp = validateUserExists(userId, "get Catalog Components", false);
if (resp.isRight()) {
return Either.right(resp.right().value());
}
Map<String, List<? extends Component>> resMap = new HashMap<>();
- Either<List<Resource>, StorageOperationStatus> resResources = toscaOperationFacade.getCatalogComponents(ComponentTypeEnum.RESOURCE, true);
+ Either<List<Resource>, StorageOperationStatus> resResources = toscaOperationFacade.getCatalogComponents(ComponentTypeEnum.RESOURCE,excludeTypes, true);
if (resResources.isLeft()) {
- Either<List<Service>, StorageOperationStatus> resServices = toscaOperationFacade.getCatalogComponents(ComponentTypeEnum.SERVICE, true);
+ Either<List<Service>, StorageOperationStatus> resServices = toscaOperationFacade.getCatalogComponents(ComponentTypeEnum.SERVICE,excludeTypes, true);
if (resServices.isLeft()) {
// Either<List<Product>, StorageOperationStatus> resProducts = productOperation.getProductCatalogData(false);
// if (resProducts.isLeft()) {
@@ -1041,7 +1019,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
if (filters == null || filters.isEmpty()) {
- Either<List<Component>, StorageOperationStatus> componentsList = toscaOperationFacade.getCatalogComponents(assetTypeEnum, false);
+ Either<List<Component>, StorageOperationStatus> componentsList = toscaOperationFacade.getCatalogComponents(assetTypeEnum,null, false);
if(componentsList.isRight()) {
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentsList.right().value())));
}
@@ -1134,15 +1112,15 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not allowed for this API");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
-
+
Either<List<Component>, StorageOperationStatus> componentsListByUuid = toscaOperationFacade.getComponentListByUuid(uuid, additionalPropertiesToMatch);
if(componentsListByUuid.isRight()) {
- log.debug("getCatalogComponentsByUuidAndAssetType: Service fetching failed");
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(componentsListByUuid.right().value(), ComponentTypeEnum.SERVICE);
+ log.debug("getCatalogComponentsByUuidAndAssetType: " + assetTypeEnum.getValue()+ " fetching failed");
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(componentsListByUuid.right().value(), assetTypeEnum);
return Either.right(componentsUtils.getResponseFormat(actionStatus, uuid));
}
-
- log.debug("getCatalogComponentsByUuidAndAssetType: " + assetTypeEnum.getValue() + "Service fetching successful");
+
+ log.debug("getCatalogComponentsByUuidAndAssetType: " + assetTypeEnum.getValue() + assetTypeEnum.getValue() + "fetching successful");
return Either.left(componentsListByUuid.left().value());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
index f298b0f203..a3d590374f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
@@ -359,7 +359,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
* @param inTransaction
* @return
*/
- public Either<GroupDefinition, ResponseFormat> validateAndUpdateGroupMetadata(String componentId, User user, ComponentTypeEnum componentType, GroupDefinition updatedGroup, boolean inTransaction) {
+ public Either<GroupDefinition, ResponseFormat> validateAndUpdateGroupMetadata(String componentId, User user, ComponentTypeEnum componentType, GroupDefinition updatedGroup, boolean inTransaction , boolean shouldLock) {
Either<GroupDefinition, ResponseFormat> result = null;
try {
@@ -396,10 +396,12 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
return result;
}
GroupDefinition currentGroup = currentGroupOpt.get();
- Either<Boolean, ResponseFormat> lockResult = lockComponent(componentId, component, "Update GroupDefinition Metadata");
- if (lockResult.isRight()) {
- result = Either.right(lockResult.right().value());
- return result;
+ if ( shouldLock ){
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(componentId, component, "Update GroupDefinition Metadata");
+ if (lockResult.isRight()) {
+ result = Either.right(lockResult.right().value());
+ return result;
+ }
}
// Validate group type is vfModule
if (!currentGroup.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
@@ -417,7 +419,8 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
} else {
titanDao.rollback();
}
- graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
+ if( shouldLock )
+ graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
}
}
@@ -734,7 +737,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
String nameUpdated = groupUpdate.getName();
String nameCurrent = currentGroup.getName();
if (!nameCurrent.equals(nameUpdated)) {
- Either<Boolean, ResponseFormat> validatNameResponse = validateGroupName(currentGroup.getName(), groupUpdate.getName());
+ Either<Boolean, ResponseFormat> validatNameResponse = validateGroupName(currentGroup.getName(), groupUpdate.getName() ,true);
if (validatNameResponse.isRight()) {
ResponseFormat errorRespons = validatNameResponse.right().value();
return Either.right(errorRespons);
@@ -752,7 +755,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
* @param groupUpdateName
* @return
*/
- private Either<Boolean, ResponseFormat> validateGroupName(String currentGroupName, String groupUpdateName) {
+ private Either<Boolean, ResponseFormat> validateGroupName(String currentGroupName, String groupUpdateName , boolean isforceNameModification) {
try {
// Check if the group name is in old format.
if (Pattern.compile(Constants.MODULE_OLD_NAME_PATTERN).matcher(groupUpdateName).matches()) {
@@ -771,14 +774,16 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
String[] split2 = groupUpdateName.split("\\.\\.");
String groupUpdateResourceName = split2[0];
String groupUpdateCounter = split2[2];
+ if (!isforceNameModification){ //if not forced ,allow name prefix&suffix validation [no changes]
+ if (!currentResourceName.equals(groupUpdateResourceName)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME_MODIFICATION, currentResourceName));
+ }
- if (!currentResourceName.equals(groupUpdateResourceName)) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME_MODIFICATION, currentResourceName));
+ if (!currentCounter.equals(groupUpdateCounter)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME_MODIFICATION, currentCounter));
+ }
}
- if (!currentCounter.equals(groupUpdateCounter)) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_VF_MODULE_NAME_MODIFICATION, currentCounter));
- }
}
return Either.left(true);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java
index e535214d70..8a8937740f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/HealthCheckBusinessLogic.java
@@ -20,7 +20,10 @@
package org.openecomp.sdc.be.components.impl;
+import java.io.IOException;
+import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -34,16 +37,23 @@ import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
-import javax.servlet.ServletContext;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth;
import org.openecomp.sdc.be.components.distribution.engine.UebHealthCheckCall;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.IEsHealthCheckDao;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
-import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector;
-import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.api.HealthCheckInfo;
import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckComponent;
import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
@@ -52,7 +62,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import org.springframework.web.context.WebApplicationContext;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
@Component("healthCheckBusinessLogic")
public class HealthCheckBusinessLogic {
@@ -62,6 +74,7 @@ public class HealthCheckBusinessLogic {
private static Logger healthLogger = LoggerFactory.getLogger(BE_HEALTH_LOG_CONTEXT);
private static final String BE_HEALTH_CHECK_STR = "beHealthCheck";
+ private static final String COMPONENT_CHANGED_MESSAGE = "BE Component %s state changed from %s to %s";
@Resource
private TitanGenericDao titanGenericDao;
@@ -72,15 +85,16 @@ public class HealthCheckBusinessLogic {
@Resource
private DistributionEngineClusterHealth distributionEngineClusterHealth;
+ @Resource
+ private CassandraHealthCheck cassandraHealthCheck;
+
@Autowired
private SwitchoverDetector switchoverDetector;
private static Logger log = LoggerFactory.getLogger(HealthCheckBusinessLogic.class.getName());
- private volatile List<HealthCheckInfo> lastBeHealthCheckInfos = null;
+ private volatile List<HealthCheckInfo> prevBeHealthCheckInfos = null;
- // private static volatile HealthCheckBusinessLogic instance;
- //
public HealthCheckBusinessLogic() {
}
@@ -99,9 +113,9 @@ public class HealthCheckBusinessLogic {
@PostConstruct
public void init() {
- lastBeHealthCheckInfos = getBeHealthCheckInfos();
+ prevBeHealthCheckInfos = getBeHealthCheckInfos();
- log.debug("After initializing lastBeHealthCheckInfos: {}", lastBeHealthCheckInfos);
+ log.debug("After initializing prevBeHealthCheckInfos: {}", prevBeHealthCheckInfos);
healthCheckScheduledTask = new HealthCheckScheduledTask();
@@ -111,115 +125,9 @@ public class HealthCheckBusinessLogic {
}
- //
- // public static HealthCheckBusinessLogic getInstance(){
- //// if (instance == null){
- //// instance = init();
- //// }
- // return instance;
- // }
-
- // private synchronized static HealthCheckBusinessLogic init() {
- // if (instance == null){
- // instance = new HealthCheckBusinessLogic();
- // }
- // return instance;
- // }
-
- private List<HealthCheckInfo> getBeHealthCheckInfos(ServletContext servletContext) {
-
- List<HealthCheckInfo> healthCheckInfos = new ArrayList<HealthCheckInfo>();
-
- // BE
- getBeHealthCheck(servletContext, healthCheckInfos);
-
- // ES
- getEsHealthCheck(servletContext, healthCheckInfos);
-
- // Titan
- getTitanHealthCheck(servletContext, healthCheckInfos);
-
- // Distribution Engine
- getDistributionEngineCheck(servletContext, healthCheckInfos);
-
- return healthCheckInfos;
- }
-
- private List<HealthCheckInfo> getBeHealthCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
- String appVersion = ExternalConfiguration.getAppVersion();
- String description = "OK";
- healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.BE, HealthCheckStatus.UP, appVersion, description));
- return healthCheckInfos;
- }
-
- public List<HealthCheckInfo> getTitanHealthCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
- // Titan health check and version
- TitanGenericDao titanStatusDao = (TitanGenericDao) getDao(servletContext, TitanGenericDao.class);
- String description;
- boolean isTitanUp;
-
- try {
- isTitanUp = titanStatusDao.isGraphOpen();
- } catch (Exception e) {
- description = "Titan error: " + e.getMessage();
- healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, description));
- return healthCheckInfos;
- }
- if (isTitanUp) {
- description = "OK";
- healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.UP, null, description));
- } else {
- description = "Titan graph is down";
- healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, description));
- }
- return healthCheckInfos;
- }
-
- public List<HealthCheckInfo> getEsHealthCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
-
- // ES health check and version
- IEsHealthCheckDao esStatusDao = (IEsHealthCheckDao) getDao(servletContext, IEsHealthCheckDao.class);
- HealthCheckStatus healthCheckStatus;
- String description;
-
- try {
- healthCheckStatus = esStatusDao.getClusterHealthStatus();
- } catch (Exception e) {
- healthCheckStatus = HealthCheckStatus.DOWN;
- description = "ES cluster error: " + e.getMessage();
- healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ES, healthCheckStatus, null, description));
- return healthCheckInfos;
- }
- if (healthCheckStatus.equals(HealthCheckStatus.DOWN)) {
- description = "ES cluster is down";
- } else {
- description = "OK";
- }
- healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ES, healthCheckStatus, null, description));
- return healthCheckInfos;
- }
-
- public Object getDao(ServletContext servletContext, Class<?> clazz) {
- WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
-
- WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(servletContext);
-
- return webApplicationContext.getBean(clazz);
- }
-
- private void getDistributionEngineCheck(ServletContext servletContext, List<HealthCheckInfo> healthCheckInfos) {
-
- DistributionEngineClusterHealth deDao = (DistributionEngineClusterHealth) getDao(servletContext, DistributionEngineClusterHealth.class);
- HealthCheckInfo healthCheckInfo = deDao.getHealthCheckInfo();
+ public boolean isDistributionEngineUp() {
- healthCheckInfos.add(healthCheckInfo);
-
- }
-
- public boolean isDistributionEngineUp(ServletContext servletContext) {
-
- DistributionEngineClusterHealth deDao = (DistributionEngineClusterHealth) getDao(servletContext, DistributionEngineClusterHealth.class);
- HealthCheckInfo healthCheckInfo = deDao.getHealthCheckInfo();
+ HealthCheckInfo healthCheckInfo = distributionEngineClusterHealth.getHealthCheckInfo();
if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckStatus.DOWN)) {
return false;
}
@@ -228,7 +136,7 @@ public class HealthCheckBusinessLogic {
public List<HealthCheckInfo> getBeHealthCheckInfosStatus() {
- return lastBeHealthCheckInfos;
+ return prevBeHealthCheckInfos;
}
@@ -241,8 +149,8 @@ public class HealthCheckBusinessLogic {
// BE
getBeHealthCheck(healthCheckInfos);
- // ES
- getEsHealthCheck(healthCheckInfos);
+ /*// ES
+ getEsHealthCheck(healthCheckInfos);*/
// Titan
getTitanHealthCheck(healthCheckInfos);
@@ -250,6 +158,12 @@ public class HealthCheckBusinessLogic {
// Distribution Engine
getDistributionEngineCheck(healthCheckInfos);
+ //Cassandra
+ getCassandraHealthCheck(healthCheckInfos);
+
+ // Amdocs
+ getAmdocsHealthCheck(healthCheckInfos);
+
return healthCheckInfos;
}
@@ -260,7 +174,8 @@ public class HealthCheckBusinessLogic {
return healthCheckInfos;
}
- public List<HealthCheckInfo> getEsHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ //Removed from aggregate HC - TDP 293490
+/* private List<HealthCheckInfo> getEsHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
// ES health check and version
HealthCheckStatus healthCheckStatus;
@@ -282,7 +197,7 @@ public class HealthCheckBusinessLogic {
healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ES, healthCheckStatus, null, description));
return healthCheckInfos;
}
-
+*/
public List<HealthCheckInfo> getTitanHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
// Titan health check and version
String description;
@@ -305,6 +220,28 @@ public class HealthCheckBusinessLogic {
return healthCheckInfos;
}
+ private List<HealthCheckInfo> getCassandraHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+
+ String description;
+ boolean isCassandraUp;
+
+ try {
+ isCassandraUp = cassandraHealthCheck.getCassandraStatus();
+ } catch (Exception e) {
+ isCassandraUp = false;
+ description = "Cassandra error: " + e.getMessage();
+ }
+ if (isCassandraUp) {
+ description = "OK";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.CASSANDRA, HealthCheckStatus.UP, null, description));
+ } else {
+ description = "Cassandra is down";
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.CASSANDRA, HealthCheckStatus.DOWN, null, description));
+ }
+ return healthCheckInfos;
+
+ }
+
private void getDistributionEngineCheck(List<HealthCheckInfo> healthCheckInfos) {
HealthCheckInfo healthCheckInfo = distributionEngineClusterHealth.getHealthCheckInfo();
@@ -313,6 +250,76 @@ public class HealthCheckBusinessLogic {
}
+ private List<HealthCheckInfo> getAmdocsHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ HealthCheckStatus healthCheckStatus;
+ String description;
+ Map<String, Object> amdocsHC = null;
+ String version = null;
+ List<HealthCheckInfo> componentsInfo = null;
+ CloseableHttpClient httpClient = getHttpClient();
+ String amdocsHealtchCheckUrl = buildHealthCheckUrl();
+ HttpGet httpGet = new HttpGet(amdocsHealtchCheckUrl);
+ CloseableHttpResponse beResponse;
+ int beStatus;
+ try {
+ beResponse = httpClient.execute(httpGet);
+ beStatus = beResponse.getStatusLine().getStatusCode();
+
+ HttpEntity entity = beResponse.getEntity();
+ String beJsonResponse = EntityUtils.toString(entity);
+ Gson gson = new Gson();
+ amdocsHC = gson.fromJson(beJsonResponse, Map.class);
+ version = amdocsHC.get("sdcVersion") != null ? amdocsHC.get("sdcVersion").toString() : null;
+ Object object = amdocsHC.get("componentsInfo");
+ Type listType = new TypeToken<List<HealthCheckInfo>>(){}.getType();
+ componentsInfo = gson.fromJson(object.toString(), listType);
+
+ if (beStatus != HttpStatus.SC_OK) {
+ healthCheckStatus = HealthCheckStatus.DOWN;
+ StringBuilder sb = new StringBuilder();
+ componentsInfo.forEach(x -> {
+ if (x.getHealthCheckStatus()==HealthCheckStatus.DOWN){
+ sb.append("Component "+x.getHealthCheckComponent().name()+" is Down,");
+ }
+ });
+ //Removing the last comma
+ description = sb.length()>0
+ ? sb.substring(0, sb.length()-1)
+ : "Onboarding is Down, specific reason unknown";//No Amdocs inner component returned DOWN, but the status of Amdocs HC is still DOWN.
+ } else {
+ healthCheckStatus = HealthCheckStatus.UP;
+ description = "OK";
+
+
+ }
+
+ } catch (Exception e) {
+ healthCheckStatus = HealthCheckStatus.DOWN;
+ description = "Onboarding unexpected response: " + e.getMessage();
+ } finally {
+ if (httpClient != null) {
+ try {
+ httpClient.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.ON_BOARDING, healthCheckStatus, version, description, componentsInfo));
+ return healthCheckInfos;
+ }
+
+ private CloseableHttpClient getHttpClient() {
+ int timeout = 3000;
+ RequestConfig.Builder requestBuilder = RequestConfig.custom();
+ requestBuilder.setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout);
+
+ HttpClientBuilder builder = HttpClientBuilder.create();
+ builder.setDefaultRequestConfig(requestBuilder.build());
+ return builder.build();
+ }
+
@PreDestroy
private void destroy() {
@@ -340,101 +347,127 @@ public class HealthCheckBusinessLogic {
healthLogger.trace("Executing BE Health Check Task");
- List<HealthCheckInfo> beHealthCheckInfos = getBeHealthCheckInfos();
- boolean healthStatus = getAggregateBeStatus(beHealthCheckInfos);
+ List<HealthCheckInfo> currentBeHealthCheckInfos = getBeHealthCheckInfos();
+ boolean healthStatus = getAggregateBeStatus(currentBeHealthCheckInfos);
+
+ boolean prevHealthStatus = getAggregateBeStatus(prevBeHealthCheckInfos);
- boolean lastHealthStatus = getAggregateBeStatus(lastBeHealthCheckInfos);
+ boolean anyStatusChanged = anyStatusChanged(currentBeHealthCheckInfos, prevBeHealthCheckInfos);
- if (lastHealthStatus != healthStatus) {
+ if (prevHealthStatus != healthStatus || anyStatusChanged) {
log.trace("BE Health State Changed to {}. Issuing alarm / recovery alarm...", healthStatus);
- lastBeHealthCheckInfos = beHealthCheckInfos;
+ prevBeHealthCheckInfos = currentBeHealthCheckInfos;
logAlarm(healthStatus);
+ }
- } else {
- // check if we need to update the status's list in case one of
- // the statuses was changed
- if (true == anyStatusChanged(beHealthCheckInfos, lastBeHealthCheckInfos)) {
- lastBeHealthCheckInfos = beHealthCheckInfos;
- }
+ }
- }
+ private boolean getAggregateBeStatus(List<HealthCheckInfo> beHealthCheckInfos) {
+
+ boolean status = true;
+ for (HealthCheckInfo healthCheckInfo : beHealthCheckInfos) {
+ if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckStatus.DOWN) && healthCheckInfo.getHealthCheckComponent() != HealthCheckComponent.DE) {
+ status = false;
+ break;
+ }
+ }
+ return status;
}
}
- private void logAlarm(boolean lastHealthState) {
- if (lastHealthState == true) {
+ private void logAlarm(boolean prevHealthState) {
+ if (prevHealthState) {
BeEcompErrorManager.getInstance().logBeHealthCheckRecovery(BE_HEALTH_CHECK_STR);
} else {
BeEcompErrorManager.getInstance().logBeHealthCheckError(BE_HEALTH_CHECK_STR);
}
}
- private boolean getAggregateBeStatus(List<HealthCheckInfo> beHealthCheckInfos) {
-
- boolean status = true;
-
- for (HealthCheckInfo healthCheckInfo : beHealthCheckInfos) {
- if (healthCheckInfo.getHealthCheckStatus().equals(HealthCheckStatus.DOWN) && healthCheckInfo.getHealthCheckComponent() != HealthCheckComponent.DE) {
- status = false;
- break;
- }
- }
- return status;
+ private void logAlarm(String componentChangedMsg) {
+ BeEcompErrorManager.getInstance().logBeHealthCheckRecovery(componentChangedMsg);
}
+
public String getSiteMode() {
return switchoverDetector.getSiteMode();
}
- public boolean anyStatusChanged(List<HealthCheckInfo> beHealthCheckInfos, List<HealthCheckInfo> lastBeHealthCheckInfos) {
+ public boolean anyStatusChanged(List<HealthCheckInfo> beHealthCheckInfos, List<HealthCheckInfo> prevBeHealthCheckInfos) {
boolean result = false;
- if (beHealthCheckInfos != null && lastBeHealthCheckInfos != null) {
+ if (beHealthCheckInfos != null && prevBeHealthCheckInfos != null) {
Map<HealthCheckComponent, HealthCheckStatus> currentValues = beHealthCheckInfos.stream().collect(Collectors.toMap(p -> p.getHealthCheckComponent(), p -> p.getHealthCheckStatus()));
- Map<HealthCheckComponent, HealthCheckStatus> lastValues = lastBeHealthCheckInfos.stream().collect(Collectors.toMap(p -> p.getHealthCheckComponent(), p -> p.getHealthCheckStatus()));
+ Map<HealthCheckComponent, HealthCheckStatus> prevValues = prevBeHealthCheckInfos.stream().collect(Collectors.toMap(p -> p.getHealthCheckComponent(), p -> p.getHealthCheckStatus()));
- if (currentValues != null && lastValues != null) {
+ if (currentValues != null && prevValues != null) {
int currentSize = currentValues.size();
- int lastSize = lastValues.size();
+ int prevSize = prevValues.size();
+
+ if (currentSize != prevSize) {
+
+ result = true; //extra/missing component
+
+ Map<HealthCheckComponent, HealthCheckStatus> notPresent = null;
+ if (currentValues.keySet().containsAll(prevValues.keySet())) {
+ notPresent = new HashMap<>(currentValues);
+ notPresent.keySet().removeAll(prevValues.keySet());
+ } else {
+ notPresent = new HashMap<>(prevValues);
+ notPresent.keySet().removeAll(currentValues.keySet());
+ }
+
+ for (HealthCheckComponent component : notPresent.keySet()) {
+ logAlarm(String.format(COMPONENT_CHANGED_MESSAGE, component, prevValues.get(component), currentValues.get(component)));
+ }
+ // HealthCheckComponent changedComponent = notPresent.keySet().iterator().next();
- if (currentSize != lastSize) {
- result = true;
} else {
for (Entry<HealthCheckComponent, HealthCheckStatus> entry : currentValues.entrySet()) {
HealthCheckComponent key = entry.getKey();
HealthCheckStatus value = entry.getValue();
- if (false == lastValues.containsKey(key)) {
- result = true;
+ if (!prevValues.containsKey(key)) {
+ result = true; //component missing
+ logAlarm(String.format(COMPONENT_CHANGED_MESSAGE, key, prevValues.get(key), currentValues.get(key)));
break;
}
- HealthCheckStatus lastHealthCheckStatus = lastValues.get(key);
+ HealthCheckStatus prevHealthCheckStatus = prevValues.get(key);
- if (value != lastHealthCheckStatus) {
- result = true;
+ if (value != prevHealthCheckStatus) {
+ result = true; //component status changed
+ logAlarm(String.format(COMPONENT_CHANGED_MESSAGE, key, prevValues.get(key), currentValues.get(key)));
break;
}
}
}
- } else if (currentValues == null && lastValues == null) {
- result = false;
- } else {
- result = true;
}
- } else if (beHealthCheckInfos == null && lastBeHealthCheckInfos == null) {
+ } else if (beHealthCheckInfos == null && prevBeHealthCheckInfos == null) {
result = false;
} else {
+ logAlarm(String.format(COMPONENT_CHANGED_MESSAGE, "", prevBeHealthCheckInfos == null ? "null" : "true", prevBeHealthCheckInfos == null ? "true" : "null"));
result = true;
}
return result;
}
+
+ private String buildHealthCheckUrl() {
+
+ Configuration.OnboardingConfig onboardingConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getOnboarding();
+
+ String protocol = onboardingConfig.getProtocol();
+ String host = onboardingConfig.getHost();
+ Integer port = onboardingConfig.getPort();
+ String uri = onboardingConfig.getHealthCheckUri();
+
+ return protocol + "://" + host + ":" + port + uri;
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index cded9ee706..838cd53458 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -104,9 +104,11 @@ public final class ImportUtils {
public static final String DEFAULT_ICON = "defaulticon";
public static final String INNER_VFC_DESCRIPTION = "Not reusable inner VFC";
public static final String USER_DEFINED_RESOURCE_NAMESPACE_PREFIX = "org.openecomp.resource.";
- public static final List<String> TOSCA_DEFINITION_VERSIONS = Arrays.asList(new String[] { "tosca_simple_yaml_1_0_0", "tosca_simple_profile_for_nfv_1_0_0", "tosca_simple_yaml_1_0" });
- public static final List<String> TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(new String[] { ".yml", ".yaml", ".csar" });
+ public static final String TOSCA_SIMPLE_YAML_PREFIX = "tosca_simple_yaml_";
+ public static final List<String> TOSCA_DEFINITION_VERSIONS = Arrays.asList(TOSCA_SIMPLE_YAML_PREFIX + "1_0_0", TOSCA_SIMPLE_YAML_PREFIX + "1_1_0", "tosca_simple_profile_for_nfv_1_0_0", TOSCA_SIMPLE_YAML_PREFIX + "1_0", TOSCA_SIMPLE_YAML_PREFIX + "1_1");
+ public static final List<String> TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(".yml", ".yaml", ".csar");
public static final String UI_JSON_PAYLOAD_NAME = "payloadName";
+ public static final String CVFC_DESCRIPTION = "Complex node type that is used as nested type in VF";
}
public enum ResultStatusEnum {
@@ -133,6 +135,7 @@ public final class ImportUtils {
PARAMETERS("parameters"),
// Import Validations
TOSCA_VERSION("tosca_definitions_version"), TOPOLOGY_TEMPLATE("topology_template"), NODE_TYPES("node_types"), OCCURRENCES("occurrences"), NODE_TEMPLATES("node_templates"), GROUPS("groups"), INPUTS("inputs"),
+ SUBSTITUTION_MAPPINGS("substitution_mappings"), NODE_TYPE("node_type"),
// Attributes
ATTRIBUTES("attributes"), LABEL("label"), HIDDEN("hidden"), IMMUTABLE("immutable"), GET_INPUT("get_input");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
index 4f4ad7f838..f85e25e5fb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
@@ -46,6 +46,7 @@ import org.openecomp.sdc.be.model.ComponentInstancePropInput;
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.IComponentInstanceConnectedElement;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.User;
@@ -443,57 +444,26 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
//////////////////////////////////////////////////////////////////////////////////////////////////////
List<InputDefinition> resList = new ArrayList<InputDefinition>();
- Map<String, List<InputDefinition>> newInputsMap = componentInstInputsMapUi.getComponentInstanceInputsMap();
+ Map<String, List<ComponentInstancePropInput>> newInputsMap = componentInstInputsMapUi.getComponentInstanceInputsMap();
List<ComponentInstance> ciList = component.getComponentInstances();
if (newInputsMap != null && !newInputsMap.isEmpty()) {
- int index = 0;
- for (Entry<String, List<InputDefinition>> entry : newInputsMap.entrySet()) {
-
- String compInstId = entry.getKey();
-
- Optional<ComponentInstance> op = ciList.stream().filter(ci -> ci.getUniqueId().equals(compInstId)).findAny();
- if(!op.isPresent()){
- ActionStatus actionStatus = ActionStatus.INVALID_CONTENT;
- log.debug("Failed to find component instance {} under component {}", compInstId, componentId);
- result = Either.right(componentsUtils.getResponseFormat(actionStatus));
- return result;
- }
- ComponentInstance ci = op.get();
- String compInstname = ci.getNormalizedName();
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> origComponentEither = getOriginComponent(ci, origComponentMap);
- if(origComponentEither.isRight()){
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(origComponentEither.right().value());
- log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
- result = Either.right(componentsUtils.getResponseFormat(actionStatus));
- return result;
- }
- org.openecomp.sdc.be.model.Component origComponent = origComponentEither.left().value();
-
- List<InputDefinition> inputs = entry.getValue();
-
- if (inputs != null && !inputs.isEmpty()) {
-
- for (InputDefinition input : inputs) {
-
- StorageOperationStatus status = addInputsToComponent(componentId, inputsToCreate, inputsValueToCreateMap, allDataTypes.left().value(), resList, index, compInstId, compInstname, origComponent, input);
- if(status != StorageOperationStatus.OK ){
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(status);
- log.debug("Failed to create inputs value under component {}, error: {}", componentId, actionStatus.name());
- result = Either.right(componentsUtils.getResponseFormat(actionStatus));
- return result;
- }
+
+ result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, inputsValueToCreateMap, dataTypes, resList, newInputsMap, true);
- }
- }
-
+ if (result.isRight()) {
+ log.debug("Failed to create inputs of resource for id {} error {}", component.getUniqueId(), result.right().value());
+ return result;
}
+ resList = result.left().value();
+
+
}
Map<String, List<ComponentInstancePropInput>> newInputsPropsMap = componentInstInputsMapUi.getComponentInstanceProperties();
if (newInputsPropsMap != null && !newInputsPropsMap.isEmpty()) {
- result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, dataTypes, resList, newInputsPropsMap);
+ result = createInputsFromProperty(component, origComponentMap, inputsToCreate, propertiesToCreateMap, inputsValueToCreateMap, dataTypes, resList, newInputsPropsMap, false);
if (result.isRight()) {
log.debug("Failed to create inputs of resource for id {} error {}", component.getUniqueId(), result.right().value());
@@ -705,42 +675,38 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
Either<List<InputDefinition>, ResponseFormat> result = Either.left(resList);
List<InputDefinition> resourceProperties = component.getInputs();
- if(inputs != null && !inputs.isEmpty()){
- Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
- if (allDataTypes.isRight()) {
- return Either.right(allDataTypes.right().value());
- }
-
- Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+ Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
+ if (allDataTypes.isRight()) {
+ return Either.right(allDataTypes.right().value());
+ }
- for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
- String inputName = inputDefinition.getKey();
- inputDefinition.getValue().setName(inputName);
+ Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
- Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
- if(preparedInputEither.isRight()){
- return Either.right(preparedInputEither.right().value());
- }
+ for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
+ String inputName = inputDefinition.getKey();
+ inputDefinition.getValue().setName(inputName);
- }
- if (resourceProperties != null) {
- Map<String, InputDefinition> generatedInputs = resourceProperties.stream().collect(Collectors.toMap(i -> i.getName(), i -> i));
- Either<Map<String, InputDefinition>, String> mergeEither = ToscaDataDefinition.mergeDataMaps(generatedInputs, inputs);
- if(mergeEither.isRight()){
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, mergeEither.right().value()));
- }
- inputs = mergeEither.left().value();
+ Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
+ if(preparedInputEither.isRight()){
+ return Either.right(preparedInputEither.right().value());
}
- Either<List<InputDefinition>, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
- if(assotiateInputsEither.isRight()){
- log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
+ }
+ if (resourceProperties != null) {
+ Map<String, InputDefinition> generatedInputs = resourceProperties.stream().collect(Collectors.toMap(i -> i.getName(), i -> i));
+ Either<Map<String, InputDefinition>, String> mergeEither = ToscaDataDefinition.mergeDataMaps(generatedInputs, inputs);
+ if(mergeEither.isRight()){
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, mergeEither.right().value()));
}
- result = Either.left(assotiateInputsEither.left().value());
-
+ inputs = mergeEither.left().value();
}
+ Either<List<InputDefinition>, StorageOperationStatus> assotiateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
+ if(assotiateInputsEither.isRight()){
+ log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), assotiateInputsEither.right().value());
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(assotiateInputsEither.right().value())));
+ }
+ result = Either.left(assotiateInputsEither.left().value());
return result;
}
@@ -891,29 +857,22 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
List<ComponentInstanceInput> inputsValue= getComponentInstanceInputsByInputId(component, inputId);
- Map<String, List<ComponentInstanceInput>> insInputsMatToDelete = new HashMap<>();
-
+
if(inputsValue != null && !inputsValue.isEmpty()){
for(ComponentInstanceInput inputValue: inputsValue){
- inputValue.setValue(inputValue.getDefaultValue());
- List<GetInputValueDataDefinition> getInputsValues = inputValue.getGetInputValues();
- if(getInputsValues != null && !getInputsValues.isEmpty()){
- Optional<GetInputValueDataDefinition> op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny();
- if(op.isPresent()){
- getInputsValues.remove(op.get());
- }
- }
- inputValue.setGetInputValues(getInputsValues);
- List<ComponentInstanceInput> inputList = null;
- String ciId = inputValue.getComponentInstanceId();
- status = toscaOperationFacade.updateComponentInstanceInput(component, ciId, inputValue);
+ String compInstId = inputValue.getComponentInstanceId();
+ prepareValueBeforeDelete(compInstId, inputForDelete, inputValue, inputValue.getPath());
+
+ status = toscaOperationFacade.updateComponentInstanceInput(component, compInstId, inputValue);
if(status != StorageOperationStatus.OK){
- log.debug("Component id: {} delete component instance input id: {} failed", componentId, inputId);
+ log.debug("Component id: {} update component instance property {} id: {} failed", componentId, inputValue.getUniqueId(), inputId);
deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), component.getName()));
return deleteEither;
}
+
}
+
}
// US848813 delete service input that relates to VL / CP property
@@ -923,42 +882,9 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
//propertyList = propertyValueStatus.left().value();
for(ComponentInstanceProperty propertyValue: propertiesValue){
- String value = propertyValue.getValue();
- Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(value);
-
- resetInputName(mappedToscaTemplate, inputForDelete.getName());
-
- value = "";
- if(!mappedToscaTemplate.isEmpty()){
- Either result = cleanNestedMap(mappedToscaTemplate , true);
- Map modifiedMappedToscaTemplate = mappedToscaTemplate;
- if (result.isLeft())
- modifiedMappedToscaTemplate = (Map)result.left().value();
- else
- Log.warn("Map cleanup failed -> " +result.right().value().toString()); //continue, don't break operation
- value = gson.toJson(modifiedMappedToscaTemplate);
- }
- propertyValue.setValue(value);
String compInstId = propertyValue.getComponentInstanceId();
- propertyValue.setRules(null);
- List<GetInputValueDataDefinition> getInputsValues = propertyValue.getGetInputValues();
- if(getInputsValues != null && !getInputsValues.isEmpty()){
- Optional<GetInputValueDataDefinition> op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny();
- if(op.isPresent()){
- getInputsValues.remove(op.get());
- }
- }
- propertyValue.setGetInputValues(getInputsValues);
-
- Either<String, TitanOperationStatus> findDefaultValue = propertyOperation.findDefaultValueFromSecondPosition(propertyValue.getPath(), propertyValue.getUniqueId(), propertyValue.getDefaultValue());
- if (findDefaultValue.isRight()) {
- deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value()))));
- return deleteEither;
-
- }
- String defaultValue = findDefaultValue.left().value();
- propertyValue.setDefaultValue(defaultValue);
- log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue);
+ prepareValueBeforeDelete(compInstId, inputForDelete, propertyValue, propertyValue.getPath());
+
status = toscaOperationFacade.updateComponentInstanceProperty(component, compInstId, propertyValue);
if(status != StorageOperationStatus.OK){
log.debug("Component id: {} update component instance property {} id: {} failed", componentId, propertyValue.getUniqueId(), inputId);
@@ -984,6 +910,47 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
}
+ private Either<InputDefinition, ResponseFormat> prepareValueBeforeDelete(String compInstId, InputDefinition inputForDelete, PropertyDefinition inputValue, List<String> pathOfComponentInstances) {
+ Either<InputDefinition, ResponseFormat> deleteEither = Either.left(inputForDelete);
+ String value = inputValue.getValue();
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(value);
+
+ resetInputName(mappedToscaTemplate, inputForDelete.getName());
+
+ value = "";
+ if(!mappedToscaTemplate.isEmpty()){
+ Either result = cleanNestedMap(mappedToscaTemplate , true);
+ Map modifiedMappedToscaTemplate = mappedToscaTemplate;
+ if (result.isLeft())
+ modifiedMappedToscaTemplate = (Map)result.left().value();
+ else
+ Log.warn("Map cleanup failed -> " +result.right().value().toString()); //continue, don't break operation
+ value = gson.toJson(modifiedMappedToscaTemplate);
+ }
+ inputValue.setValue(value);
+
+
+ List<GetInputValueDataDefinition> getInputsValues = inputValue.getGetInputValues();
+ if(getInputsValues != null && !getInputsValues.isEmpty()){
+ Optional<GetInputValueDataDefinition> op = getInputsValues.stream().filter(gi -> gi.getInputId().equals(inputForDelete.getUniqueId())).findAny();
+ if(op.isPresent()){
+ getInputsValues.remove(op.get());
+ }
+ }
+ inputValue.setGetInputValues(getInputsValues);
+
+ Either<String, TitanOperationStatus> findDefaultValue = propertyOperation.findDefaultValueFromSecondPosition(pathOfComponentInstances, inputValue.getUniqueId(), inputValue.getDefaultValue());
+ if (findDefaultValue.isRight()) {
+ deleteEither = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value()))));
+ return deleteEither;
+
+ }
+ String defaultValue = findDefaultValue.left().value();
+ inputValue.setDefaultValue(defaultValue);
+ log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue);
+ return deleteEither;
+ }
+
private Either<InputDefinition, ResponseFormat> prepareAndValidateInputBeforeCreate(InputDefinition newInputDefinition, Map<String, DataTypeDefinition> dataTypes) {
@@ -1196,7 +1163,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
- private Either<List<InputDefinition>, ResponseFormat> createInputsFromProperty(org.openecomp.sdc.be.model.Component component, Map<String, org.openecomp.sdc.be.model.Component> origComponentMap, Map<String, InputDefinition> inputsToCreate, Map<String, List<ComponentInstanceProperty>> propertiesToCreateMap, Map<String, DataTypeDefinition> dataTypes, List<InputDefinition> resList, Map<String, List<ComponentInstancePropInput>> newInputsPropsMap) {
+ private Either<List<InputDefinition>, ResponseFormat> createInputsFromProperty(org.openecomp.sdc.be.model.Component component, Map<String, org.openecomp.sdc.be.model.Component> origComponentMap, Map<String, InputDefinition> inputsToCreate, Map<String, List<ComponentInstanceProperty>> propertiesToCreateMap, Map<String, List<ComponentInstanceInput>> inputsValueToCreateMap, Map<String, DataTypeDefinition> dataTypes, List<InputDefinition> resList, Map<String, List<ComponentInstancePropInput>> newInputsPropsMap, boolean isInputValue) {
List<ComponentInstance> ciList = component.getComponentInstances();
String componentId = component.getUniqueId();
for (Entry<String, List<ComponentInstancePropInput>> entry : newInputsPropsMap.entrySet()) {
@@ -1206,7 +1173,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
propertiesToCreate = propertiesToCreateMap.get(compInstId);
}else{
propertiesToCreate = new ArrayList<>();
- }
+ }
+
+ List<ComponentInstanceInput> inputsValueToCreate = null;
+ if(propertiesToCreateMap.containsKey(compInstId)){
+ inputsValueToCreate = inputsValueToCreateMap.get(compInstId);
+ }else{
+ inputsValueToCreate = new ArrayList<>();
+ }
List<ComponentInstancePropInput> properties = entry.getValue();
@@ -1238,7 +1212,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
propInput.setOwnerId(null);
propInput.setParentUniqueId(null);
- Either<InputDefinition, StorageOperationStatus> createInputRes = createInputForComponentInstance(component, origComponent,ci, inputsToCreate, propertiesToCreate, dataTypes, inputName, propInput);
+ Either<InputDefinition, StorageOperationStatus> createInputRes = createInputForComponentInstance(component, origComponent,ci, inputsToCreate, propertiesToCreate, inputsValueToCreate, dataTypes, inputName, propInput, isInputValue);
if (createInputRes.isRight()) {
log.debug("Failed to create input of resource instance for id {} error {}", compInstId, createInputRes.right().value());
@@ -1249,14 +1223,19 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
resList.add(createInputRes.left().value());
}
- propertiesToCreateMap.put(compInstId, propertiesToCreate);
+ if(! isInputValue){
+ propertiesToCreateMap.put(compInstId, propertiesToCreate);
+ }
+ else{
+ inputsValueToCreateMap.put(compInstId, inputsValueToCreate);
+ }
}
}
return Either.left(resList);
}
- private Either<InputDefinition, StorageOperationStatus> createInputForComponentInstance(org.openecomp.sdc.be.model.Component component,org.openecomp.sdc.be.model.Component orignComponent, ComponentInstance ci, Map<String, InputDefinition> inputsToCreate, List<ComponentInstanceProperty> propertiesToCreate, Map<String, DataTypeDefinition> dataTypes, String inputName, ComponentInstancePropInput propInput) {
+ private Either<InputDefinition, StorageOperationStatus> createInputForComponentInstance(org.openecomp.sdc.be.model.Component component,org.openecomp.sdc.be.model.Component orignComponent, ComponentInstance ci, Map<String, InputDefinition> inputsToCreate, List<ComponentInstanceProperty> propertiesToCreate, List<ComponentInstanceInput> inputsValueToCreate, Map<String, DataTypeDefinition> dataTypes, String inputName, ComponentInstancePropInput propInput, boolean isInputValue) {
String propertiesName = propInput.getPropertiesName() ;
PropertyDefinition selectedProp = propInput.getInput();
String[] parsedPropNames = propInput.getParsedPropNames();
@@ -1270,14 +1249,22 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
InputDefinition input = null;
- ComponentInstanceProperty prop = propInput;
+ PropertyDefinition prop = propInput;
- if(CollectionUtils.isNotEmpty(propertiesToCreate)){
+ if(CollectionUtils.isNotEmpty(propertiesToCreate) && !isInputValue){
Optional<ComponentInstanceProperty> propOpt = propertiesToCreate.stream().filter(p -> p.getName().equals(propInput.getName())).findFirst();
if(propOpt.isPresent()){
prop = propOpt.get();
}
+ }else{
+ if(CollectionUtils.isNotEmpty(inputsValueToCreate) && isInputValue){
+ Optional<ComponentInstanceInput> propOpt = inputsValueToCreate.stream().filter(p -> p.getName().equals(propInput.getName())).findFirst();
+ if(propOpt.isPresent()){
+ prop = propOpt.get();
+ }
+ }
}
+
boolean complexProperty = false;
if(propertiesName != null && !propertiesName.isEmpty() && selectedProp != null){
complexProperty = true;
@@ -1317,7 +1304,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
if(!complexProperty){
jobject.put(GET_INPUT, input.getName());
prop.setValue(jobject.toJSONString());
- prop.setRules(null);
+
}else{
Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
@@ -1325,18 +1312,19 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
String json = gson.toJson(mappedToscaTemplate);
prop.setValue(json);
- prop.setRules(null);
+
}
}else{
jobject.put(GET_INPUT, input.getName());
prop.setValue(jobject.toJSONString());
- prop.setRules(null);
+
}
}
- prop.setComponentInstanceId(ci.getUniqueId());
- prop.setComponentInstanceName(ci.getName());
+
+ ((IComponentInstanceConnectedElement)prop).setComponentInstanceId(ci.getUniqueId());
+ ((IComponentInstanceConnectedElement)prop).setComponentInstanceName(ci.getName());
if(CollectionUtils.isEmpty(prop.getGetInputValues())){
prop.setGetInputValues(new ArrayList<>());
@@ -1348,17 +1336,31 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
getInputValueDataDefinition.setInputName(input.getName());
getInputValues.add(getInputValueDataDefinition);
- if(!propertiesToCreate.contains(prop)){
- propertiesToCreate.add(prop);
+ if(!isInputValue){
+ if(!propertiesToCreate.contains(prop)){
+ propertiesToCreate.add((ComponentInstanceProperty)prop);
+ }
+
+ inputsToCreate.put(input.getName(), input);
+ List<ComponentInstanceProperty> propertiesList = input.getProperties();
+ if(propertiesList == null)
+ propertiesList = new ArrayList<>(); // adding the property with the new value for UI
+ propertiesList.add((ComponentInstanceProperty)prop);
+ input.setProperties(propertiesList);
+ }else{
+ ComponentInstanceInput inputValue = new ComponentInstanceInput(prop);
+ if(!inputsValueToCreate.contains(inputValue)){
+ inputsValueToCreate.add(inputValue);;
+ }
+
+ inputsToCreate.put(input.getName(), input);
+ List<ComponentInstanceInput> inputsValueList = input.getInputs();
+ if(inputsValueList == null)
+ inputsValueList = new ArrayList<>(); // adding the property with the new value for UI
+ inputsValueList.add(inputValue);
+ input.setInputs(inputsValueList);
}
- inputsToCreate.put(input.getName(), input);
- List<ComponentInstanceProperty> propertiesList = input.getProperties();
- if(propertiesList == null)
- propertiesList = new ArrayList<>(); // adding the property with the new value for UI
- propertiesList.add(prop);
- input.setProperties(propertiesList);
-
return Either.left(input);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java
index ab0969358c..7a7148a6a1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductComponentInstanceBusinessLogic.java
@@ -30,10 +30,6 @@ import fj.data.Either;
@Component("productComponentInstanceBusinessLogic")
public class ProductComponentInstanceBusinessLogic extends ComponentInstanceBusinessLogic {
- @Override
- protected Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent) {
- return Either.left(true);
- }
@Override
protected NodeTypeEnum getNodeTypeOfComponentInstanceOrigin() {
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 cc4a6d9c71..0aa4a6f006 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
@@ -23,7 +23,6 @@ package org.openecomp.sdc.be.components.impl;
import static org.openecomp.sdc.be.tosca.CsarUtils.ARTIFACTS_PATH;
import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -46,6 +45,7 @@ import javax.servlet.ServletContext;
import org.apache.commons.codec.binary.Base64;
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.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
@@ -79,6 +79,7 @@ import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
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;
@@ -86,10 +87,12 @@ import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.CsarInfo;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.PropertyDefinition;
@@ -111,13 +114,11 @@ import org.openecomp.sdc.be.model.heat.HeatParameterType;
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;
-import org.openecomp.sdc.be.model.operations.api.IHeatParametersOperation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
-import org.openecomp.sdc.be.model.operations.impl.InputsOperation;
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;
@@ -125,6 +126,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.servlets.RepresentationUtils;
import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
+import org.openecomp.sdc.be.tosca.ToscaUtils;
import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.be.user.Role;
@@ -133,7 +135,6 @@ import org.openecomp.sdc.be.utils.CommonBeUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.config.EcompErrorName;
import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
import org.openecomp.sdc.common.datastructure.FunctionalInterfaces;
import org.openecomp.sdc.common.datastructure.Wrapper;
@@ -203,18 +204,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
@Autowired
private InputsBusinessLogic inputsBusinessLogic;
- @javax.annotation.Resource
- private InputsOperation inputOperation;
-
- // @Autowired
- // private GroupOperation groupOperation;
-
- @Autowired
- private IHeatParametersOperation heatParametersOperation;
-
- // @Autowired
- // private IArtifactOperation artifactOperation;
-
@Autowired
private CompositionBusinessLogic compositionBusinessLogic;
@@ -290,8 +279,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
* the method returns a list of all the resources that are certified, the returned resources are only abstract or only none abstract according to the given param
*
* @param getAbstract
- * @param userId
- * TODO
+ * @param userId TODO
* @return
*/
public Either<List<Resource>, ResponseFormat> getAllCertifiedResources(boolean getAbstract, HighestFilterEnum highestFilter, String userId) {
@@ -301,16 +289,16 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
Boolean isHighest = null;
switch (highestFilter) {
- case ALL:
- break;
- case HIGHEST_ONLY:
- isHighest = true;
- break;
- case NON_HIGHEST_ONLY:
- isHighest = false;
- break;
- default:
- break;
+ case ALL:
+ break;
+ case HIGHEST_ONLY:
+ isHighest = true;
+ break;
+ case NON_HIGHEST_ONLY:
+ isHighest = false;
+ break;
+ default:
+ break;
}
Either<List<Resource>, StorageOperationStatus> getResponse = toscaOperationFacade.getAllCertifiedResources(getAbstract, isHighest);
@@ -489,7 +477,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<Resource, ResponseFormat> updateResourceFromCsar(Resource oldRresource, Resource newRresource, User user, AuditingActionEnum updateResource, boolean inTransaction, Either<Map<String, byte[]>, StorageOperationStatus> csarUIPayload,
- String csarUUID) {
+ String csarUUID) {
// check state
if (LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.equals(oldRresource.getLifecycleState())) {
@@ -500,7 +488,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
String lockedResourceId = oldRresource.getUniqueId();
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
Either<Map<String, byte[]>, StorageOperationStatus> csar = null;
if (csarUIPayload != null && csarUIPayload.left() != null && csarUIPayload.left().value() != null) {
@@ -536,30 +523,68 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(lockResult.right().value());
}
- Either<Resource, ResponseFormat> result = null;
String yamlFileName = toscaYamlCsarStatus.left().value().getKey();
- Either<Map<String, Resource>, ResponseFormat> parseNodeTypeInfoYamlEither = null;
- try {
+ String yamlFileContents = toscaYamlCsarStatus.left().value().getValue();
+ CsarInfo csarInfo = new CsarInfo(newRresource.getName(), user, csarUUID, csar.left().value(), true);
+ Map<String, NodeTypeInfo> nodeTypesInfo = extractNodeTypesInfo(csar.left().value(), yamlFileContents);
+ Either<Resource, ResponseFormat> result =null;
+
+ Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo.getCsar(), csarInfo.getCsarUUID(), yamlFileName, oldRresource, csarInfo.getModifier());
+ if (findNodeTypesArtifactsToHandleRes.isRight()) {
+ log.debug("failed to find node types for update with artifacts during import csar {}. ", csarInfo.getCsarUUID());
+ result = Either.right(findNodeTypesArtifactsToHandleRes.right().value());
+ return result;
+ }
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes.left().value();
+ try{
+ result = updateResourceFromYaml(oldRresource, newRresource, updateResource, createdArtifacts, isUpdateYaml, yamlFileName, yamlFileContents, csarInfo, nodeTypesInfo, nodeTypesArtifactsToHandle, null);
+
+ } finally {
+ if (result == null || result.isRight()) {
+ log.warn("operation failed. do rollback");
+ titanDao.rollback();
+ if (!createdArtifacts.isEmpty()) {
+ StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts);
+ if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
+ result = Either.right(componentsUtils.getResponseFormat(actionStatus, oldRresource.getName()));
+ }
+ log.debug("component and all its artifacts were deleted, id = {}", oldRresource.getName());
+ }
+ } else {
+ log.debug("operation success. do commit");
+ titanDao.commit();
+ }
+ log.debug("unlock resource {}", lockedResourceId);
+ graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
+ }
+ return result;
+
+ }
+
+ private Either<Resource, ResponseFormat> updateResourceFromYaml(Resource oldRresource, Resource newRresource, AuditingActionEnum updateResource, List<ArtifactDefinition> createdArtifacts,
+ boolean isUpdateYaml, String yamlFileName, String yamlFileContent, CsarInfo csarInfo, Map<String, NodeTypeInfo> nodeTypesInfo,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle, String nodeName) {
+ Either<Resource, ResponseFormat> result = null;
+ Either<Map<String, Resource>, ResponseFormat> parseNodeTypeInfoYamlEither;
+ boolean inTransaction = true;
+ boolean shouldLock = false;
+
Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> prepareForUpdate = null;
Resource preparedResource = null;
- Either<ParsedToscaYamlInfo, ResponseFormat> uploadComponentInstanceInfoMap = parseResourceInfoFromYaml(yamlFileName, newRresource, toscaYamlCsarStatus.left().value().getValue(), user);
+ Either<ParsedToscaYamlInfo, ResponseFormat> uploadComponentInstanceInfoMap = parseResourceInfoFromYaml(yamlFileName, newRresource, yamlFileContent, csarInfo.getModifier(), csarInfo.getCreatedNodesToscaResourceNames(), nodeTypesInfo, nodeName);
if (uploadComponentInstanceInfoMap.isRight()) {
ResponseFormat responseFormat = uploadComponentInstanceInfoMap.right().value();
- componentsUtils.auditResource(responseFormat, user, newRresource, "", "", updateResource, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), newRresource, "", "", updateResource, null);
result = Either.right(responseFormat);
return result;
}
+
Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.left().value().getInstances();
- Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(csar.left().value(), csarUUID, yamlFileName, oldRresource, user, true, instances);
- if (findNodeTypesArtifactsToHandleRes.isRight()) {
- log.debug("failed to find node types for update with artifacts during import csar {}. ", csarUUID);
- result = Either.right(findNodeTypesArtifactsToHandleRes.right().value());
- return result;
- }
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes.left().value();
+
if (isUpdateYaml || !nodeTypesArtifactsToHandle.isEmpty()) {
- prepareForUpdate = updateExistingResourceByImport(newRresource, oldRresource, user, true, false);
+ prepareForUpdate = updateExistingResourceByImport(newRresource, oldRresource, csarInfo.getModifier(), inTransaction, shouldLock);
if (prepareForUpdate.isRight()) {
log.debug("Failed to prepare resource for update : {}", prepareForUpdate.right().value());
result = Either.right(prepareForUpdate.right().value());
@@ -567,39 +592,38 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
preparedResource = prepareForUpdate.left().value().left;
- String yamlFileContents = toscaYamlCsarStatus.left().value().getValue();
- log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContents);
+ log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContent);
- parseNodeTypeInfoYamlEither = this.handleNodeTypes(yamlFileName, preparedResource, user, yamlFileContents, csar.left().value(), false, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts);
+ parseNodeTypeInfoYamlEither = this.handleNodeTypes(yamlFileName, preparedResource, yamlFileContent, shouldLock, nodeTypesArtifactsToHandle, createdArtifacts, nodeTypesInfo, csarInfo, nodeName);
if (parseNodeTypeInfoYamlEither.isRight()) {
ResponseFormat responseFormat = parseNodeTypeInfoYamlEither.right().value();
- componentsUtils.auditResource(responseFormat, user, preparedResource, "", "", updateResource, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource, "", "", updateResource, null);
result = Either.right(responseFormat);
return result;
}
Map<String, InputDefinition> inputs = uploadComponentInstanceInfoMap.left().value().getInputs();
- Either<Resource, ResponseFormat> createInputsOnResource = createInputsOnResource(preparedResource, user, inputs, true);
+ Either<Resource, ResponseFormat> createInputsOnResource = createInputsOnResource(preparedResource, csarInfo.getModifier(), inputs, inTransaction);
if (createInputsOnResource.isRight()) {
log.debug("failed to create resource inputs status is {}", createInputsOnResource.right().value());
ResponseFormat responseFormat = createInputsOnResource.right().value();
- componentsUtils.auditResource(createInputsOnResource.right().value(), user, preparedResource, "", "", updateResource, null);
+ componentsUtils.auditResource(createInputsOnResource.right().value(), csarInfo.getModifier(), preparedResource, "", "", updateResource, null);
result = Either.right(responseFormat);
return result;
}
preparedResource = createInputsOnResource.left().value();
- Either<Resource, ResponseFormat> createResourcesInstancesEither = createResourceInstances(user, yamlFileName, preparedResource, instances, true, false, parseNodeTypeInfoYamlEither.left().value());
+ Either<Resource, ResponseFormat> createResourcesInstancesEither = createResourceInstances(csarInfo.getModifier(), yamlFileName, preparedResource, instances, inTransaction, shouldLock, csarInfo.getCreatedNodes());
if (createResourcesInstancesEither.isRight()) {
log.debug("failed to create resource instances status is {}", createResourcesInstancesEither.right().value());
ResponseFormat responseFormat = createResourcesInstancesEither.right().value();
- componentsUtils.auditResource(createResourcesInstancesEither.right().value(), user, preparedResource, "", "", updateResource, null);
+ componentsUtils.auditResource(createResourcesInstancesEither.right().value(), csarInfo.getModifier(), preparedResource, "", "", updateResource, null);
result = Either.right(responseFormat);
return result;
}
preparedResource = createResourcesInstancesEither.left().value();
-
- createResourcesInstancesEither = createResourceInstancesRelations(user, yamlFileName, preparedResource, instances, true, false);
+
+ createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances, inTransaction, shouldLock);
if (createResourcesInstancesEither.isRight()) {
log.debug("failed to create relation between resource instances status is {}", createResourcesInstancesEither.right().value());
result = Either.right(createResourcesInstancesEither.right().value());
@@ -621,7 +645,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
} else {
groups = uploadComponentInstanceInfoMap.left().value().getGroups();
}
- Either<Resource, ResponseFormat> updatedGroupsOnResource = updateGroupsOnResource(preparedResource, user, groups);
+ Either<Resource, ResponseFormat> updatedGroupsOnResource = updateGroupsOnResource(preparedResource, csarInfo.getModifier(), groups);
if (updatedGroupsOnResource.isRight()) {
return updatedGroupsOnResource;
@@ -629,7 +653,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
preparedResource = updatedGroupsOnResource.left().value();
} else {
- Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(oldRresource.getUniqueId(), newRresource, user, oldRresource, false, true);
+ Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(oldRresource.getUniqueId(), newRresource, csarInfo.getModifier(), oldRresource, shouldLock, inTransaction);
if (dataModelResponse.isRight()) {
log.debug("failed to update resource metadata {}", dataModelResponse.right().value());
result = Either.right(dataModelResponse.right().value());
@@ -638,44 +662,32 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
preparedResource = dataModelResponse.left().value();
}
- Either<Resource, ResponseFormat> createdCsarArtifactsEither = handleCsarArtifacts(preparedResource, user, csarUUID, csar.left().value(), createdArtifacts,
- artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update), false, true);
- if (createdCsarArtifactsEither.isRight()) {
-
- return createdCsarArtifactsEither;
+ if(preparedResource.getResourceType() == ResourceTypeEnum.CVFC){
+ if(nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null && !nodeTypesArtifactsToHandle.get(nodeName).isEmpty()){
+ Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes =
+ handleNodeTypeArtifacts(preparedResource, nodeTypesArtifactsToHandle.get(nodeName), createdArtifacts, csarInfo.getModifier(), inTransaction, true);
+ if(handleNodeTypeArtifactsRes.isRight()){
+ return Either.right(handleNodeTypeArtifactsRes.right().value());
+ }
+ }
+ } else {
+ Either<Resource, ResponseFormat> createdCsarArtifactsEither = handleVfCsarArtifacts(preparedResource, csarInfo, createdArtifacts,
+ artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update), shouldLock, inTransaction);
+ log.trace("************* Finished to add artifacts from yaml {}", yamlFileName);
+ if (createdCsarArtifactsEither.isRight()) {
+ return createdCsarArtifactsEither;
+ }
+ preparedResource = createdCsarArtifactsEither.left().value();
}
- preparedResource = createdCsarArtifactsEither.left().value();
- Either<List<ComponentInstance>, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, user.getUserId());
+ Either<List<ComponentInstance>, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, csarInfo.getModifier().getUserId());
result = eitherSetPosition.isRight() ? Either.right(eitherSetPosition.right().value()) : Either.left(preparedResource);
return result;
- } finally {
- if (result == null || result.isRight()) {
- log.warn("operation failed. do rollback");
- titanDao.rollback();
- if (!createdArtifacts.isEmpty() || !nodeTypesNewCreatedArtifacts.isEmpty()) {
- createdArtifacts.addAll(nodeTypesNewCreatedArtifacts);
- StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts);
- if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, oldRresource.getName());
- }
- log.debug("component and all its artifacts were deleted, id = {}", oldRresource.getName());
- }
- } else {
- log.debug("operation success. do commit");
- titanDao.commit();
- }
- log.debug("unlock resource {}", lockedResourceId);
- graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
- }
-
}
- private Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(Map<String, byte[]> csar, String csarUUID, String yamlFileName, Resource oldResource, User user,
- boolean inTransaction, Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap) {
+ private Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(Map<String, NodeTypeInfo> nodeTypesInfo, Map<String, byte[]> csar, String csarUUID, String yamlFileName, Resource oldResource, User user) {
Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts = CsarUtils.extractVfcsArtifactsFromCsar(csar);
Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
@@ -683,14 +695,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
try {
nodeTypesArtifactsToHandleRes = Either.left(nodeTypesArtifactsToHandle);
- List<ImmutablePair<ImmutablePair<String, List<String>>, String>> extractedVfcToscaNames = extractVfcToscaNames(csar, yamlFileName, oldResource.getSystemName(), uploadComponentInstanceInfoMap);
- validateNodeTypeIdentifiers(extractedVfcsArtifacts, extractedVfcToscaNames);
+ Map<String, String> extractedVfcToscaNames = extractVfcToscaNames(nodeTypesInfo, yamlFileName, oldResource.getSystemName());
Either<EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>, ResponseFormat> curNodeTypeArtifactsToHandleRes = null;
EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> curNodeTypeArtifactsToHandle = null;
log.debug("Going to fetch node types for resource with name {} during import csar with UUID {}. ", oldResource.getName(), csarUUID);
- for (ImmutablePair<ImmutablePair<String, List<String>>, String> currVfcToscaNameEntry : extractedVfcToscaNames) {
+ for (Entry<String, String> currVfcToscaNameEntry : extractedVfcToscaNames.entrySet()) {
String currVfcToscaName = currVfcToscaNameEntry.getValue();
+ String currNamespace = currVfcToscaNameEntry.getKey();
log.debug("Going to fetch node type with tosca name {}. ", currVfcToscaName);
Either<Resource, StorageOperationStatus> curVfcRes = toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName);
@@ -706,10 +718,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
if (!MapUtils.isEmpty(extractedVfcsArtifacts)) {
List<ArtifactDefinition> currArtifacts = new ArrayList<>();
- for (String currNamespace : currVfcToscaNameEntry.getKey().getValue()) {
- if (extractedVfcsArtifacts.containsKey(currNamespace)) {
- handleAndAddExtractedVfcsArtifacts(currArtifacts, extractedVfcsArtifacts.get(currNamespace));
- }
+ if (extractedVfcsArtifacts.containsKey(currNamespace)) {
+ handleAndAddExtractedVfcsArtifacts(currArtifacts, extractedVfcsArtifacts.get(currNamespace));
}
curNodeTypeArtifactsToHandleRes = findNodeTypeArtifactsToHandle(curNodeType, currArtifacts);
if (curNodeTypeArtifactsToHandleRes.isRight()) {
@@ -731,7 +741,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
if (MapUtils.isNotEmpty(curNodeTypeArtifactsToHandle)) {
- nodeTypesArtifactsToHandle.put(currVfcToscaNameEntry.getKey().getKey(), curNodeTypeArtifactsToHandle);
+ nodeTypesArtifactsToHandle.put(currVfcToscaNameEntry.getKey(), curNodeTypeArtifactsToHandle);
}
}
} catch (Exception e) {
@@ -742,22 +752,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return nodeTypesArtifactsToHandleRes;
}
- private void validateNodeTypeIdentifiers(Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts, List<ImmutablePair<ImmutablePair<String, List<String>>, String>> extractedVfcToscaNames) {
- if (extractedVfcsArtifacts != null) {
- List<String> validIdentifiers = new ArrayList<>();
- if (extractedVfcToscaNames != null) {
- extractedVfcToscaNames.stream().forEach(pair -> {
- validIdentifiers.addAll(pair.getKey().getValue());
- validIdentifiers.add(pair.getKey().getKey());
- });
- }
- for (String curIdentifier : extractedVfcsArtifacts.keySet()) {
- if (validIdentifiers != null && !validIdentifiers.contains(curIdentifier))
- log.warn("Warning - VFC identification {} provided in the Artifacts folder of the CSAR is not valid. ", curIdentifier);
- }
- }
- }
-
private Either<EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>, ResponseFormat> findNodeTypeArtifactsToHandle(Resource curNodeType, List<ArtifactDefinition> extractedArtifacts) {
Either<EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>, ResponseFormat> nodeTypeArtifactsToHandleRes = null;
@@ -869,8 +863,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
* @param inTransaction
* @return
*/
- public Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> vfcsNewCreatedArtifacts,
- User user, boolean inTransaction) {
+ public Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> createdArtifacts,
+ User user, boolean inTransaction, boolean ignoreLifecycleState) {
Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRequestRes;
Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = null;
Either<Resource, ResponseFormat> changeStateResponse;
@@ -888,14 +882,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
List<ArtifactDefinition> curArtifactsToHandle = curOperationEntry.getValue();
if (curArtifactsToHandle != null && !curArtifactsToHandle.isEmpty()) {
log.debug("************* Going to {} artifact to vfc {}", curOperation.name(), nodeTypeResource.getName());
- handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic.handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user, vfcsNewCreatedArtifacts,
- artifactsBusinessLogic.new ArtifactOperationInfo(false, false, curOperation), false, inTransaction);
+ handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic.handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user, createdArtifacts,
+ artifactsBusinessLogic.new ArtifactOperationInfo(false, ignoreLifecycleState, curOperation), false, inTransaction);
if (handleNodeTypeArtifactsRequestRes.isRight()) {
handleNodeTypeArtifactsRes = Either.right(handleNodeTypeArtifactsRequestRes.right().value());
break;
}
if (curOperation == ArtifactOperationEnum.Create) {
- vfcsNewCreatedArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value());
+ createdArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value());
}
handledNodeTypeArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value());
}
@@ -911,93 +905,30 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return handleNodeTypeArtifactsRes;
}
- @SuppressWarnings("unchecked")
- private List<ImmutablePair<ImmutablePair<String, List<String>>, String>> extractVfcToscaNames(Map<String, byte[]> csar, String yamlFileName, String vfResourceName, Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap) {
- List<ImmutablePair<ImmutablePair<String, List<String>>, String>> vfcToscaNames = new ArrayList<>();
- Map<String, Object> nodeTypes;
- if (csar != null) {
- nodeTypes = new HashMap<>();
- putNodeTypesFromYaml(csar, yamlFileName, nodeTypes);
- putNodeTypesFromYaml(csar, Constants.GLOBAL_SUBSTITUTION_TYPES_SERVICE_TEMPLATE, nodeTypes);
- putNodeTypesFromYaml(csar, Constants.ABSTRACT_SUBSTITUTE_GLOBAL_TYPES_SERVICE_TEMPLATE, nodeTypes);
- Map<String,String> nestedServiceTemplatesMap = new HashMap<>();
- for(UploadComponentInstanceInfo ci : uploadComponentInstanceInfoMap.values()){
- if(ci.getProperties() != null && ci.getProperties().containsKey("service_template_filter")){
- String tempName = CsarUtils.DEFINITIONS_PATH + ((Map<String, String>)ci.getProperties().get("service_template_filter").get(0).getValue()).get("substitute_service_template");
- putNodeTypesFromYaml(csar,tempName, nodeTypes);
- nestedServiceTemplatesMap.put(ci.getType(), tempName);
- }
- }
-
- if (!nodeTypes.isEmpty()) {
- Iterator<Entry<String, Object>> nodesNameEntry = nodeTypes.entrySet().iterator();
- while (nodesNameEntry.hasNext()) {
- Entry<String, Object> nodeType = nodesNameEntry.next();
- addVfcToscaNameFindSubstitutes(csar, vfResourceName, vfcToscaNames, nodeType.getKey(), nestedServiceTemplatesMap);
- }
+ private Map<String, String> extractVfcToscaNames(Map<String, NodeTypeInfo> nodeTypesInfo, String yamlFileName, String vfResourceName) {
+ Map<String, String> vfcToscaNames = new HashMap<>();
+
+ Map<String, Object> nodes = extractAllNodes(nodeTypesInfo);
+ if (!nodes.isEmpty()) {
+ Iterator<Entry<String, Object>> nodesNameEntry = nodes.entrySet().iterator();
+ while (nodesNameEntry.hasNext()) {
+ Entry<String, Object> nodeType = nodesNameEntry.next();
+ String toscaResourceName = buildNestedToscaResourceName(ResourceTypeEnum.VFC.name(), vfResourceName, nodeType.getKey());
+ vfcToscaNames.put(nodeType.getKey(), toscaResourceName);
}
}
return vfcToscaNames;
}
- @SuppressWarnings("unchecked")
- private void putNodeTypesFromYaml(Map<String, byte[]> csar, String yamlFileName, Map<String, Object> nodeTypes) {
-
- if (csar.containsKey(yamlFileName)) {
- Map<String, Object> mappedToscaTemplate;
- Either<Map<String, Object>, ResultStatusEnum> eitherNodeTypes;
- mappedToscaTemplate = (Map<String, Object>) new Yaml().load(new String(csar.get(yamlFileName), StandardCharsets.UTF_8));
- eitherNodeTypes = ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES);
+ private Map<String, Object> extractAllNodes(Map<String, NodeTypeInfo> nodeTypesInfo) {
+ Map<String, Object> nodes = new HashMap<>();
+ for(NodeTypeInfo nodeTypeInfo: nodeTypesInfo.values()){
+ Either<Map<String, Object>, ResultStatusEnum> eitherNodeTypes = ImportUtils.findFirstToscaMapElement(nodeTypeInfo.getMappedToscaTemplate(), ToscaTagNamesEnum.NODE_TYPES);
if (eitherNodeTypes.isLeft()) {
- nodeTypes.putAll(eitherNodeTypes.left().value());
- }
- }
- }
-
- private void addVfcToscaNameFindSubstitutes(Map<String, byte[]> csar, String vfResourceName, List<ImmutablePair<ImmutablePair<String, List<String>>, String>> vfcToscaNames, String nodeTypeFullName, Map<String, String> nestedServiceTemplatesMap) {
-
- String toscaResourceName = buildNestedVfcToscaResourceName(vfResourceName, nodeTypeFullName);
- String nodeTypeTemplateYamlName =null;
- if(nestedServiceTemplatesMap.containsKey(nodeTypeFullName)){
- nodeTypeTemplateYamlName = nestedServiceTemplatesMap.get(nodeTypeFullName);
- }
- List<String> relatedVfcsToscaNameSpaces = new ArrayList<>();
- relatedVfcsToscaNameSpaces.add(buildNestedVfcToscaNamespace(nodeTypeFullName));
- if (nodeTypeTemplateYamlName!=null && csar.containsKey(nodeTypeTemplateYamlName)) {
- addSubstituteToscaNamespacesRecursively(csar, nodeTypeTemplateYamlName, relatedVfcsToscaNameSpaces, nestedServiceTemplatesMap);
- }
- ImmutablePair<String, List<String>> toscaNameSpacesHierarchy = new ImmutablePair<>(nodeTypeFullName, relatedVfcsToscaNameSpaces);
- vfcToscaNames.add(new ImmutablePair<>(toscaNameSpacesHierarchy, toscaResourceName));
- }
-
- private void addSubstituteToscaNamespacesRecursively(Map<String, byte[]> csar, String yamlFileName, List<String> toscaNameSpaces, Map<String, String> nestedServiceTemplatesMap) {
-
- Map<String, Object> nodeTypes = new HashMap<>();
-
- if (csar.containsKey(yamlFileName)) {
- putNodeTypesFromYaml(csar, yamlFileName, nodeTypes);
- }
- if (!nodeTypes.isEmpty()) {
- Iterator<Entry<String, Object>> nodesNameEntry = nodeTypes.entrySet().iterator();
- while (nodesNameEntry.hasNext()) {
- Entry<String, Object> nodeType = nodesNameEntry.next();
- String nodeTypeFullName = nodeType.getKey();
- String toscaNameSpace = buildNestedVfcToscaNamespace(nodeTypeFullName);
- if (toscaNameSpaces.contains(toscaNameSpace)) {
- break;
- }
- toscaNameSpaces.add(toscaNameSpace);
-
- String nodeTypeTemplateYamlName =null;
- if(nestedServiceTemplatesMap.containsKey(nodeTypeFullName)){
- nodeTypeTemplateYamlName = nestedServiceTemplatesMap.get(nodeTypeFullName);
- }
-
- if (nodeTypeTemplateYamlName!=null && csar.containsKey(nodeTypeTemplateYamlName)) {
- addSubstituteToscaNamespacesRecursively(csar, nodeTypeTemplateYamlName, toscaNameSpaces, nestedServiceTemplatesMap);
- }
+ nodes.putAll(eitherNodeTypes.left().value());
}
}
+ return nodes;
}
public Either<Resource, ResponseFormat> createResourceFromCsar(Resource resource, User user, Either<Map<String, byte[]>, StorageOperationStatus> csarUIPayload, String csarUUID) {
@@ -1024,7 +955,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
String yamlFileName = toscaYamlCsarStatus.left().value().getKey();
String yamlFileContents = toscaYamlCsarStatus.left().value().getValue();
log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContents);
- Either<Resource, ResponseFormat> createResourceFromYaml = createResourceFromYaml(resource, user, yamlFileContents, yamlFileName, csar.left().value(), csarUUID);
+
+ Map<String, NodeTypeInfo> nodeTypesInfo = extractNodeTypesInfo(csar.left().value(), yamlFileContents);
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = findNodeTypeArtifactsToCreate(csar.left().value(), resource);
+ CsarInfo csarInfo = new CsarInfo(resource.getName(), user, csarUUID, csar.left().value(), false);
+ Either<Resource, ResponseFormat> createResourceFromYaml = createResourceFromYaml(resource, yamlFileContents, yamlFileName, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, true, false, null);
if (createResourceFromYaml.isRight()) {
log.debug("Couldn't create resource from YAML");
return Either.right(createResourceFromYaml.right().value());
@@ -1035,6 +970,80 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(vfResource);
}
+ @SuppressWarnings("unchecked")
+ private Map<String, NodeTypeInfo> extractNodeTypesInfo(Map<String, byte[]> csar, String yamlFileContent) {
+ Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
+ List<Entry<String, byte[]>> globalSubstitutes = new ArrayList<>();
+ for (Map.Entry<String, byte[]> entry : csar.entrySet()) {
+ if (Pattern.compile(CsarUtils.SERVICE_TEMPLATE_PATH_PATTERN).matcher(entry.getKey()).matches()) {
+ if (!isGlobalSubstitute(entry.getKey())) {
+ String yamlFileContents = new String(entry.getValue());
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(yamlFileContents);
+ Either<Object, ResultStatusEnum> substitutionMappingsEither = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS, ToscaElementTypeEnum.MAP);
+ if (substitutionMappingsEither.isLeft()) {
+ Map<String, Object> substitutionMappings = (Map<String, Object>) substitutionMappingsEither.left().value();
+ if (substitutionMappings.containsKey(ToscaTagNamesEnum.NODE_TYPE.getElementName())) {
+ NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
+ nodeTypeInfo.setType((String) substitutionMappings.get(ToscaTagNamesEnum.NODE_TYPE.getElementName()));
+ nodeTypeInfo.setTemplateFileName(entry.getKey());
+ nodeTypeInfo.setMappedToscaTemplate(mappedToscaTemplate);
+ nodeTypesInfo.put(nodeTypeInfo.getType(), nodeTypeInfo);
+ }
+ }
+ } else {
+ globalSubstitutes.add(entry);
+ }
+ }
+ }
+ if (CollectionUtils.isNotEmpty(globalSubstitutes)) {
+ for (Map.Entry<String, byte[]> entry : globalSubstitutes) {
+ String yamlFileContents = new String(entry.getValue());
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(yamlFileContents);
+ Either<Object, ResultStatusEnum> nodeTypesEither = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP);
+ if (nodeTypesEither.isLeft()) {
+ Map<String, Object> nodeTypes = (Map<String, Object>) nodeTypesEither.left().value();
+ for (Entry<String, Object> nodeType : nodeTypes.entrySet()) {
+ Map<String, Object> nodeTypeMap = (Map<String, Object>) nodeType.getValue();
+ if (nodeTypeMap.containsKey(ToscaTagNamesEnum.DERIVED_FROM.getElementName())) {
+ if (nodeTypesInfo.containsKey(nodeType.getKey())) {
+ NodeTypeInfo nodeTypeInfo = nodeTypesInfo.get(nodeType.getKey());
+ List<String> derivedFrom = new ArrayList<>();
+ derivedFrom.add((String) nodeTypeMap.get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()));
+ nodeTypeInfo.setDerivedFrom(derivedFrom);
+ }
+ }
+ }
+ }
+ }
+ }
+ markNestedVfc(yamlFileContent, nodeTypesInfo);
+ return nodeTypesInfo;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void markNestedVfc(String yamlFileContent, Map<String, NodeTypeInfo> nodeTypesInfo) {
+ Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(yamlFileContent);
+ Either<Object, ResultStatusEnum> nodeTemplatesEither = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP);
+ if (nodeTemplatesEither.isLeft()) {
+ Map<String, Object> nodeTemplates = (Map<String, Object>) nodeTemplatesEither.left().value();
+ for (Entry<String, Object> nodeTemplateEntry : nodeTemplates.entrySet()) {
+ Map<String, Object> nodeTemplate = (Map<String, Object>) nodeTemplateEntry.getValue();
+ if (nodeTemplate.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
+ String type = (String) nodeTemplate.get(ToscaTagNamesEnum.TYPE.getElementName());
+ if (nodeTypesInfo.containsKey(type)) {
+ NodeTypeInfo nodeTypeInfo = nodeTypesInfo.get(type);
+ nodeTypeInfo.setNested(true);
+ }
+ }
+ }
+ }
+ }
+
+ private boolean isGlobalSubstitute(String fileName) {
+ return fileName.equalsIgnoreCase(Constants.GLOBAL_SUBSTITUTION_TYPES_SERVICE_TEMPLATE) || fileName.equalsIgnoreCase(Constants.ABSTRACT_SUBSTITUTE_GLOBAL_TYPES_SERVICE_TEMPLATE);
+ }
+
private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Resource resource, User user, String csarUUID, Either<Map<String, byte[]>, StorageOperationStatus> csar) {
if (csar.isRight()) {
StorageOperationStatus value = csar.right().value();
@@ -1079,36 +1088,41 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (validateRes.isRight()) {
return Either.right(validateRes.right().value());
}
- // VF "derivedFrom" should be null (or ignored)
- if (!resource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ // VF / PNF "derivedFrom" should be null (or ignored)
+ if (ToscaUtils.isAtomicType(resource)) {
Either<Boolean, ResponseFormat> validateDerivedFromNotEmpty = validateDerivedFromNotEmpty(user, resource, AuditingActionEnum.CREATE_RESOURCE);
if (validateDerivedFromNotEmpty.isRight()) {
return Either.right(validateDerivedFromNotEmpty.right().value());
}
}
- return validateResourceBeforeCreate(resource, user, AuditingActionEnum.CREATE_RESOURCE, inTransaction);
+ return validateResourceBeforeCreate(resource, user, AuditingActionEnum.CREATE_RESOURCE, inTransaction, null);
}
-
- public Either<Resource, ResponseFormat> createResourceFromYaml(Resource resource, User user, String topologyTemplateYaml, String yamlName, Map<String, byte[]> csar, String csarUUID) {
+//resource, yamlFileContents, yamlFileName, nodeTypesInfo,csarInfo, nodeTypesArtifactsToCreate, true, false, null
+ private Either<Resource, ResponseFormat> createResourceFromYaml(Resource resource, String topologyTemplateYaml, String yamlName,
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ boolean shouldLock, boolean inTransaction, String nodeName) {
List<ArtifactDefinition> createdArtifacts = new ArrayList<ArtifactDefinition>();
log.trace("************* createResourceFromYaml before parse yaml ");
- Either<ParsedToscaYamlInfo, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceInfoFromYaml(yamlName, resource, topologyTemplateYaml, user);
+ Either<ParsedToscaYamlInfo, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceInfoFromYaml(yamlName, resource, topologyTemplateYaml, csarInfo.getModifier(), csarInfo.getCreatedNodesToscaResourceNames(), nodeTypesInfo, nodeName);
if (parseResourceInfoFromYamlEither.isRight()) {
ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value();
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
return Either.right(responseFormat);
}
log.trace("************* createResourceFromYaml after parse yaml ");
ParsedToscaYamlInfo parsedToscaYamlInfo = parseResourceInfoFromYamlEither.left().value();
log.debug("The parsed tosca yaml info is {}", parsedToscaYamlInfo);
log.trace("************* createResourceFromYaml before create ");
- Either<Resource, ResponseFormat> createdResourceResponse = createResourceAndRIsFromYaml(yamlName, resource, user, parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false, csarUUID, csar, createdArtifacts, topologyTemplateYaml);
+ Either<Resource, ResponseFormat> createdResourceResponse = createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo,
+ AuditingActionEnum.IMPORT_RESOURCE, false, createdArtifacts, topologyTemplateYaml,
+ nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName);
log.trace("************* createResourceFromYaml after create ");
if (createdResourceResponse.isRight()) {
ResponseFormat responseFormat = createdResourceResponse.right().value();
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
return Either.right(responseFormat);
}
@@ -1116,47 +1130,160 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- public Either<Map<String, Resource>, ResponseFormat> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, String resourceYml, User user, boolean needLock,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) {
-
- Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(resourceYml);
+ public Either<Map<String, Resource>, ResponseFormat> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, String resourceYml, Map<String, Object> mappedToscaTemplate, boolean needLock,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo) {
Either<String, ResultStatusEnum> tosca_version = ImportUtils.findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.TOSCA_VERSION);
if (tosca_version.isRight()) {
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
return Either.right(responseFormat);
}
-
Either<Map<String, Object>, ResultStatusEnum> eitherNodeTypes = ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPES);
-
- Map<String, Resource> nodeTypesResources = new HashMap<>();
- Either<Map<String, Resource>, ResponseFormat> result = Either.left(nodeTypesResources);
-
+ Either<Map<String, Resource>, ResponseFormat> result = Either.left(csarInfo.getCreatedNodes());
Map<String, Object> mapToConvert = new HashMap<String, Object>();
mapToConvert.put(ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), tosca_version.left().value());
-
+ Resource vfcCreated = null;
if (eitherNodeTypes.isLeft()) {
-
Iterator<Entry<String, Object>> nodesNameValue = eitherNodeTypes.left().value().entrySet().iterator();
-
while (nodesNameValue.hasNext()) {
-
Entry<String, Object> nodeType = nodesNameValue.next();
Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = nodeTypesArtifactsToHandle == null || nodeTypesArtifactsToHandle.isEmpty() ? null : nodeTypesArtifactsToHandle.get(nodeType.getKey());
- log.trace("************* Going to create node {}", nodeType.getKey());
- Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> resourceCreated = this.createNodeTypeResourceFromYaml(yamlName, nodeType, user, mapToConvert, resource, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts);
- log.trace("************* finished to create node {}", nodeType.getKey());
- if (resourceCreated.isRight()) {
- return Either.right(resourceCreated.right().value());
- }
- Resource vfcCreated = resourceCreated.left().value().getLeft();
- nodeTypesResources.put(nodeType.getKey(), vfcCreated);
+ if (nodeTypesInfo.containsKey(nodeType.getKey())) {
+ log.trace("************* Going to handle nested vfc {}", nodeType.getKey());
+ Either<Resource, ResponseFormat> handleNeatedVfcYaml = handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeType.getKey());
+ log.trace("************* Finished to handle nested vfc {}", nodeType.getKey());
+ if (handleNeatedVfcYaml.isRight()) {
+ return Either.right(handleNeatedVfcYaml.right().value());
+ }
+ vfcCreated = handleNeatedVfcYaml.left().value();
+ } else if(csarInfo.getCreatedNodesToscaResourceNames()!= null && !csarInfo.getCreatedNodesToscaResourceNames().containsKey(nodeType.getKey())){
+ log.trace("************* Going to create node {}", nodeType.getKey());
+ Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> resourceCreated = this.createNodeTypeResourceFromYaml(yamlName, nodeType, csarInfo.getModifier(), mapToConvert, resource, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, true, csarInfo);
+ log.debug("************* Finished to create node {}", nodeType.getKey());
+
+ if (resourceCreated.isRight()) {
+ return Either.right(resourceCreated.right().value());
+ }
+ vfcCreated = resourceCreated.left().value().getLeft();
+ csarInfo.getCreatedNodesToscaResourceNames().put(nodeType.getKey(),vfcCreated.getToscaResourceName());
+ }
+ if (vfcCreated != null) {
+ csarInfo.getCreatedNodes().put(nodeType.getKey(), vfcCreated);
+ }
mapToConvert.remove(ToscaTagNamesEnum.NODE_TYPES.getElementName());
+ }
+ }
+ return result;
+ }
+
+ private Either<Resource, ResponseFormat> handleNestedVfc(Resource resource, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
+ List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo, String nodeName) {
+ Either<Resource, ResponseFormat> handleNestedVfcRes = Either.left(resource);
+ String yamlName = nodesInfo.get(nodeName).getTemplateFileName();
+ String yamlContent = new String(csarInfo.getCsar().get(yamlName));
+ Map<String, Object> nestedVfcJsonMap = nodesInfo.get(nodeName).getMappedToscaTemplate();
+
+ log.debug("************* Going to create node types from yaml {}", yamlName);
+ Either<Map<String, Resource>, ResponseFormat> createNodeTypesRes = createResourcesFromYamlNodeTypesList(yamlName, resource, yamlContent,
+ nestedVfcJsonMap, false, nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo);
+ if (createNodeTypesRes.isRight()) {
+ log.debug("Failed to create node types from yaml {}. Status is {}", yamlName, createNodeTypesRes.right().value());
+ return Either.right(createNodeTypesRes.right().value());
+ }
+ log.debug("************* Finished to create node types from yaml {}", yamlName);
+
+ if (nestedVfcJsonMap.containsKey(ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) {
+ log.debug("************* Going to handle complex VFC from yaml {}", yamlName);
+ handleNestedVfcRes = handleComplexVfc(resource, nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName, yamlContent);
+ }
+ return handleNestedVfcRes;
+ }
+
+ private Either<Resource, ResponseFormat> handleComplexVfc(Resource resource, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle, List<ArtifactDefinition> createdArtifacts,
+ Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo, String nodeName, String yamlName, String yamlContent) {
+
+ Either<Resource, ResponseFormat> result = null;
+ Resource oldComplexVfc = null;
+ Resource newComplexVfc = null;
+
+ Either<Resource, ResponseFormat> buildCvfcRes = buildValidComplexVfc(resource, csarInfo, nodeName, nodesInfo);
+ if(buildCvfcRes.isRight()){
+ log.debug("Failed to validate complex VFC for node {}. ", nodeName);
+ result = buildCvfcRes;
+ }
+ if(result == null){
+ newComplexVfc = buildCvfcRes.left().value();
+ if(csarInfo.isUpdate()){
+ Either<Resource, StorageOperationStatus> oldComplexVfcRes = toscaOperationFacade.getLatestByToscaResourceName(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));
+ } else if(oldComplexVfcRes.isLeft()){
+ oldComplexVfc = oldComplexVfcRes.left().value();
+ }
+ }
+ }
+ if(result == null){
+ result = handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName, yamlContent, oldComplexVfc, newComplexVfc);
+ }
+ if(result.isLeft()){
+ newComplexVfc = result.left().value();
+ csarInfo.getCreatedNodesToscaResourceNames().put(nodeName, newComplexVfc.getToscaResourceName());
+ LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction("certification on import", LifecycleChanceActionEnum.CREATE_FROM_CSAR);
+ log.debug("Going to certify cvfc {}. ", newComplexVfc.getName());
+ result = propagateStateToCertified(csarInfo.getModifier(), newComplexVfc, lifecycleChangeInfo, true, false, true);
+ if (result.isRight()) {
+ log.debug("Failed to certify complex VFC resource {}. ", newComplexVfc.getName());
+ }
+ }
+ if(result.isLeft()){
+ csarInfo.getCreatedNodes().put(nodeName, result.left().value());
+ csarInfo.getCvfcToCreateQueue().remove();
+ }
+ return result;
+ }
+
+ private Either<Resource, ResponseFormat> handleComplexVfc(Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle, List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo,
+ CsarInfo csarInfo, String nodeName, String yamlName, String yamlContent, Resource oldComplexVfc, Resource newComplexVfc) {
+
+ Either<Resource, ResponseFormat> handleComplexVfcRes;
+ Map<String, NodeTypeInfo> newNodeTypesInfo = nodesInfo.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().getUnmarkedCopy()));
+ markNestedVfc(yamlContent, newNodeTypesInfo);
+ if(oldComplexVfc == null){
+ handleComplexVfcRes = createResourceFromYaml(newComplexVfc, yamlContent, yamlName, newNodeTypesInfo, csarInfo, nodesArtifactsToHandle, false, true, nodeName);
+ if (handleComplexVfcRes.isRight()) {
+ log.debug("Failed to create resource {} from YAML {}. ", newComplexVfc.getName(), yamlName);
+ }
+ } else {
+ handleComplexVfcRes = updateResourceFromYaml(oldComplexVfc, newComplexVfc, AuditingActionEnum.UPDATE_RESOURCE_METADATA, createdArtifacts, true, yamlContent, yamlName, csarInfo, newNodeTypesInfo, nodesArtifactsToHandle, nodeName);
+ if (handleComplexVfcRes.isRight()) {
+ log.debug("Failed to update resource {} from YAML {}. ", oldComplexVfc.getName(), yamlName);
}
}
+ return handleComplexVfcRes;
+ }
+ private Either<Resource, ResponseFormat> buildValidComplexVfc(Resource resource, CsarInfo csarInfo, String nodeName, Map<String, NodeTypeInfo> nodesInfo) {
+
+ Either<Resource, ResponseFormat> result = null;
+ Resource complexVfc = buildComplexVfcMetadata(resource, csarInfo, nodeName, nodesInfo);
+ log.debug("************* Going to validate complex VFC from yaml {}", complexVfc.getName());
+
+ if(!csarInfo.getCvfcToCreateQueue().contains(nodeName)){
+ csarInfo.getCvfcToCreateQueue().add(nodeName);
+ } else {
+ log.debug("Failed to validate complex VFC {}. Loop detected, VSP {}. ", complexVfc.getName(), csarInfo.getVfResourceName());
+ result = Either.right(componentsUtils.getResponseFormat(ActionStatus.CFVC_LOOP_DETECTED, csarInfo.getVfResourceName(), complexVfc.getName()));
+ }
+ if(result == null){
+ result = validateResourceBeforeCreate(complexVfc, csarInfo.getModifier(), AuditingActionEnum.IMPORT_RESOURCE, true, csarInfo);
+ if(result.isRight()){
+ log.debug("Failed to validate complex VFC {}. ", complexVfc.getName());
+ }
+ }
return result;
}
@@ -1168,40 +1295,35 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createNodeTypeResourceFromYaml(String yamlName, Entry<String, Object> nodeNameValue, User user, Map<String, Object> mapToConvert, Resource resourceVf, boolean needLock,
- Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) {
+ Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo) {
Either<UploadResourceInfo, ResponseFormat> resourceMetaData = fillResourceMetadata(yamlName, resourceVf, nodeNameValue.getKey(), user);
if (resourceMetaData.isRight()) {
return Either.right(resourceMetaData.right().value());
}
+ String singleVfcYaml = buildNodeTypeYaml(nodeNameValue, mapToConvert, resourceMetaData.left().value().getResourceType(), csarInfo.getVfResourceName());
+
+ Either<User, ResponseFormat> eitherCreator = validateUser(user, "CheckIn Resource", resourceVf, AuditingActionEnum.CHECKIN_RESOURCE, true);
+ if (eitherCreator.isRight()) {
+ return Either.right(eitherCreator.right().value());
+ }
+ user = eitherCreator.left().value();
+
+ return this.createResourceFromNodeType(singleVfcYaml, resourceMetaData.left().value(), user, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo);
+ }
+ private String buildNodeTypeYaml(Entry<String, Object> nodeNameValue, Map<String, Object> mapToConvert, String nodeResourceType, String csarVfName) {
// We need to create a Yaml from each node_types in order to create
// resource from each node type using import normative flow.
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
- Map<String, Object> singleVfc = new HashMap<>();
-
- String actualName = this.getNodeTypeActualName(nodeNameValue.getKey());
- if (!actualName.startsWith(Constants.ABSTRACT)) {
- actualName = "." + Constants.ABSTRACT + actualName;
- }
-
- // Setting tosca name
- String toscaResourceName = ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + resourceMetaData.left().value().getResourceType().toLowerCase() + '.' + resourceVf.getSystemName() + actualName;
- singleVfc.put(toscaResourceName, nodeNameValue.getValue());
- mapToConvert.put(ToscaTagNamesEnum.NODE_TYPES.getElementName(), singleVfc);
-
- String singleVfcYaml = yaml.dumpAsMap(mapToConvert);
-
- Either<User, ResponseFormat> eitherCreator = validateUser(user, "CheckIn Resource", resourceVf, AuditingActionEnum.CHECKIN_RESOURCE, true);
- if (eitherCreator.isRight()) {
- return Either.right(eitherCreator.right().value());
- }
- user = eitherCreator.left().value();
+ Map<String, Object> node = new HashMap<>();
+ node.put(buildNestedToscaResourceName(nodeResourceType, csarVfName, nodeNameValue.getKey()), nodeNameValue.getValue());
+ mapToConvert.put(ToscaTagNamesEnum.NODE_TYPES.getElementName(), node);
- return this.createResourceFromNodeType(singleVfcYaml, resourceMetaData.left().value(), user, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts);
+ return yaml.dumpAsMap(mapToConvert);
}
public Either<Boolean, ResponseFormat> validateResourceCreationFromNodeType(Resource resource, User creator) {
@@ -1214,25 +1336,25 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResourceFromNodeType(String nodeTypeYaml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction, boolean needLock,
- Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) {
+ Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo) {
LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction("certification on import", LifecycleChanceActionEnum.CREATE_FROM_CSAR);
Function<Resource, Either<Boolean, ResponseFormat>> validator = (resource) -> this.validateResourceCreationFromNodeType(resource, creator);
- return this.resourceImportManager.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts);
+ return this.resourceImportManager.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo);
}
- private Either<UploadResourceInfo, ResponseFormat> fillResourceMetadata(String yamlName, Resource resourceVf, String nodeTypeName, User user) {
+ private Either<UploadResourceInfo, ResponseFormat> fillResourceMetadata(String yamlName, Resource resourceVf, String nodeName, User user) {
UploadResourceInfo resourceMetaData = new UploadResourceInfo();
// validate nodetype name prefix
- if (!nodeTypeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) {
- log.debug("invalid nodeTypeName:{} does not start with {}.", nodeTypeName, Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeTypeName);
+ if (!nodeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) {
+ log.debug("invalid nodeName:{} does not start with {}.", nodeName, Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeName);
return Either.right(responseFormat);
}
- String actualName = this.getNodeTypeActualName(nodeTypeName);
- String namePrefix = nodeTypeName.replace(actualName, "");
+ String actualName = this.getNodeTypeActualName(nodeName);
+ String namePrefix = nodeName.replace(actualName, "");
String resourceType = namePrefix.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
// if we import from csar, the node_type name can be
@@ -1244,7 +1366,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// validating type
if (!ResourceTypeEnum.containsName(resourceType.toUpperCase())) {
log.debug("invalid resourceType:{} the type is not one of the valide types:{}.", resourceType.toUpperCase(), ResourceTypeEnum.values());
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeTypeName);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeName);
return Either.right(responseFormat);
}
@@ -1279,20 +1401,68 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(resourceMetaData);
}
- private Either<Resource, ResponseFormat> createResourceAndRIsFromYaml(String yamlName, Resource resource, User user, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative, String csarUUID,
- Map<String, byte[]> csar, List<ArtifactDefinition> createdArtifacts, String topologyTemplateYaml) {
+ private Resource buildComplexVfcMetadata(Resource resourceVf, CsarInfo csarInfo, String nodeName, Map<String, NodeTypeInfo> nodesInfo) {
+ Resource cvfc = new Resource();
+ NodeTypeInfo nodeTypeInfo = nodesInfo.get(nodeName);
+ cvfc.setName(buildCvfcName(csarInfo.getVfResourceName(), nodeName));
+ cvfc.setNormalizedName(ValidationUtils.normaliseComponentName(cvfc.getName()));
+ cvfc.setSystemName(ValidationUtils.convertToSystemName(cvfc.getName()));
+ cvfc.setResourceType(ResourceTypeEnum.CVFC);
+ cvfc.setAbstract(true);
+ cvfc.setDerivedFrom(nodeTypeInfo.getDerivedFrom());
+ cvfc.setDescription(ImportUtils.Constants.CVFC_DESCRIPTION);
+ cvfc.setIcon(ImportUtils.Constants.DEFAULT_ICON);
+ cvfc.setContactId(csarInfo.getModifier().getUserId());
+ cvfc.setCreatorUserId(csarInfo.getModifier().getUserId());
+ cvfc.setVendorName(resourceVf.getVendorName());
+ cvfc.setVendorRelease(resourceVf.getVendorRelease());
+ cvfc.setResourceVendorModelNumber(resourceVf.getResourceVendorModelNumber());
+ cvfc.setToscaResourceName(buildNestedToscaResourceName(ResourceTypeEnum.VFC.name(), csarInfo.getVfResourceName(), nodeName));
+ cvfc.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
+
+ List<String> tags = new ArrayList<>();
+ tags.add(cvfc.getName());
+ cvfc.setTags(tags);
+
+ CategoryDefinition category = new CategoryDefinition();
+ category.setName(ImportUtils.Constants.ABSTRACT_CATEGORY_NAME);
+ SubCategoryDefinition subCategory = new SubCategoryDefinition();
+ subCategory.setName(ImportUtils.Constants.ABSTRACT_SUBCATEGORY);
+ category.addSubCategory(subCategory);
+ List<CategoryDefinition> categories = new ArrayList<>();
+ categories.add(category);
+ cvfc.setCategories(categories);
+
+ cvfc.setVersion(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION);
+ cvfc.setLifecycleState(ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE_NOT_CERTIFIED_CHECKOUT);
+ cvfc.setHighestVersion(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION);
+
+ return cvfc;
+ }
+
+ private String buildCvfcName(String resourceVfName, String nodeName) {
+ String nameWithouNamespacePrefix = nodeName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ String[] findTypes = nameWithouNamespacePrefix.split("\\.");
+ String resourceType = findTypes[0];
+ return resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1);
+ }
+
+ private Either<Resource, ResponseFormat> createResourceAndRIsFromYaml(String yamlName, Resource resource, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative,
+ List<ArtifactDefinition> createdArtifacts, String topologyTemplateYaml, Map<String, NodeTypeInfo> nodeTypesInfo,
+ CsarInfo csarInfo, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ boolean shouldLock, boolean inTransaction, String nodeName) {
boolean result = true;
- boolean inTransaction = true;
- Map<String, Resource> createdVfcs = new HashMap<>();
List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
- Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource, "Create Resource");
- if (lockResult.isRight()) {
- ResponseFormat responseFormat = lockResult.right().value();
- return Either.right(responseFormat);
- }
- log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
+ if (shouldLock) {
+ Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource, "Create Resource");
+ if (lockResult.isRight()) {
+ ResponseFormat responseFormat = lockResult.right().value();
+ return Either.right(responseFormat);
+ }
+ log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
+ }
try {
log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
Either<Resource, ResponseFormat> genericResourceEither = fetchAndSetDerivedFromGenericType(resource);
@@ -1300,7 +1470,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
result = false;
return genericResourceEither;
}
- Either<Resource, ResponseFormat> createResourcesEither = createResourceTransaction(resource, user, isNormative, inTransaction);
+ Either<Resource, ResponseFormat> createResourcesEither = createResourceTransaction(resource, csarInfo.getModifier(), isNormative, inTransaction);
log.trace("************* createResourceFromYaml after full create resource {}", yamlName);
if (createResourcesEither.isRight()) {
result = false;
@@ -1313,7 +1483,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
generateInputsFromGenericTypeProperties(resource, genericResourceEither.left().value());
Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
- Either<Resource, ResponseFormat> createInputsOnResource = createInputsOnResource(resource, user, inputs, inTransaction);
+ Either<Resource, ResponseFormat> createInputsOnResource = createInputsOnResource(resource, csarInfo.getModifier(), inputs, inTransaction);
if (createInputsOnResource.isRight()) {
result = false;
return createInputsOnResource;
@@ -1323,7 +1493,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
- createResourcesEither = createRIAndRelationsFromYaml(yamlName, resource, user, uploadComponentInstanceInfoMap, actionEnum, topologyTemplateYaml, csar, csarUUID, nodeTypesNewCreatedArtifacts, createdVfcs);
+
+ createResourcesEither = createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap, actionEnum, topologyTemplateYaml,
+ nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName);
log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
if (createResourcesEither.isRight()) {
result = false;
@@ -1346,7 +1518,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
} else {
groups = parsedToscaYamlInfo.getGroups();
}
- Either<Resource, ResponseFormat> createGroupsOnResource = createGroupsOnResource(resource, user, groups);
+ Either<Resource, ResponseFormat> createGroupsOnResource = createGroupsOnResource(resource, csarInfo.getModifier(), groups);
if (createGroupsOnResource.isRight()) {
result = false;
return createGroupsOnResource;
@@ -1355,43 +1527,54 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
log.trace("************* Finished to add groups from yaml {}", yamlName);
log.trace("************* Going to add artifacts from yaml {}", yamlName);
- Either<Resource, ResponseFormat> createdCsarArtifactsEither = this.handleCsarArtifacts(resource, user, csarUUID, csar, createdArtifacts, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create), false,
- inTransaction);
- log.trace("************* Finished to add artifacts from yaml {}", yamlName);
- if (createdCsarArtifactsEither.isRight()) {
- result = false;
- return createdCsarArtifactsEither;
- }
- resource = createdCsarArtifactsEither.left().value();
+ if(resource.getResourceType() == ResourceTypeEnum.CVFC){
+ if(nodeTypesArtifactsToCreate.containsKey(nodeName) && nodeTypesArtifactsToCreate.get(nodeName) !=null && !nodeTypesArtifactsToCreate.get(nodeName).isEmpty()){
+ Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes =
+ handleNodeTypeArtifacts(resource, nodeTypesArtifactsToCreate.get(nodeName), nodeTypesNewCreatedArtifacts, csarInfo.getModifier(), true, false);
+ if(handleNodeTypeArtifactsRes.isRight()){
+ return Either.right(handleNodeTypeArtifactsRes.right().value());
+ }
+ }
+ } else {
+ Either<Resource, ResponseFormat> createdCsarArtifactsEither = this.handleVfCsarArtifacts(resource, csarInfo, createdArtifacts, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create), false,
+ inTransaction);
+ log.trace("************* Finished to add artifacts from yaml {}", yamlName);
+ if (createdCsarArtifactsEither.isRight()) {
+ result = false;
+ return createdCsarArtifactsEither;
+ }
+ resource = createdCsarArtifactsEither.left().value();
+ }
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
- componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", actionEnum, null);
ASDCKpiApi.countCreatedResourcesKPI();
return Either.left(resource);
} finally {
- if (!result) {
- log.warn("operation failed. do rollback");
- titanDao.rollback();
- if (!createdArtifacts.isEmpty() || !nodeTypesNewCreatedArtifacts.isEmpty()) {
- createdArtifacts.addAll(nodeTypesNewCreatedArtifacts);
- StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts);
- if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, resource.getName());
+ if (!inTransaction) {
+ if (!result) {
+ log.warn("operation failed. do rollback");
+ titanDao.rollback();
+ if (!createdArtifacts.isEmpty() || !nodeTypesNewCreatedArtifacts.isEmpty()) {
+ createdArtifacts.addAll(nodeTypesNewCreatedArtifacts);
+ StorageOperationStatus deleteFromEsRes = artifactsBusinessLogic.deleteAllComponentArtifactsIfNotOnGraph(createdArtifacts);
+ if (!deleteFromEsRes.equals(StorageOperationStatus.OK)) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteFromEsRes);
+ return Either.right(componentsUtils.getResponseFormat(actionStatus, resource.getName()));
+ }
+ log.debug("component and all its artifacts were deleted, id = {}", resource.getName());
}
- log.debug("component and all its artifacts were deleted, id = {}", resource.getName());
- }
- } else {
- log.debug("operation success. do commit");
- titanDao.commit();
+ } else {
+ log.debug("operation success. do commit");
+ titanDao.commit();
+ }
+ }
+ if (shouldLock) {
+ graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(), NodeTypeEnum.Resource);
}
-
- graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(), NodeTypeEnum.Resource);
-
}
-
}
private Either<Resource, ResponseFormat> createGroupsOnResource(Resource resource, User user, Map<String, GroupDefinition> groups) {
@@ -1493,11 +1676,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<Resource, ResponseFormat> createInputsOnResource(Resource resource, User user, Map<String, InputDefinition> inputs, boolean inTransaction) {
- if (inputs != null && false == inputs.isEmpty()) {
+ List<InputDefinition> resourceProperties = resource.getInputs();
+ if ( (inputs != null && false == inputs.isEmpty()) || (resourceProperties != null && false == resourceProperties.isEmpty()) ) {
- Either<List<InputDefinition>, ResponseFormat> createGroups = inputsBusinessLogic.createInputsInGraph(inputs, resource, user, inTransaction);
- if (createGroups.isRight()) {
- return Either.right(createGroups.right().value());
+ Either<List<InputDefinition>, ResponseFormat> createInputs = inputsBusinessLogic.createInputsInGraph(inputs, resource, user, inTransaction);
+ if (createInputs.isRight()) {
+ return Either.right(createInputs.right().value());
}
} else {
return Either.left(resource);
@@ -1618,12 +1802,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// Filtered Members Of Current Group containing only members which
// are groups
List<String> currGroupFilteredMembers = currGroupMembers.stream().
- // Keep Only Elements of type group and not Resource Instances
- filter(innerGroupName -> allGroups.containsKey(innerGroupName)).
+ // Keep Only Elements of type group and not Resource Instances
+ filter(innerGroupName -> allGroups.containsKey(innerGroupName)).
// Add Filtered Elements to main Set
- peek(innerGroupName -> allGroupMembers.add(innerGroupName)).
+ peek(innerGroupName -> allGroupMembers.add(innerGroupName)).
// Collect results
- collect(Collectors.toList());
+ collect(Collectors.toList());
// Recursively call the method for all the filtered group members
for (String innerGroupName : currGroupFilteredMembers) {
@@ -1649,35 +1833,33 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (!stop) {
final Set<String> allMembers = allGroups.get(groupName).getMembers().keySet();
Set<String> membersOfTypeGroup = allMembers.stream().
- // Filter In Only Group members
- filter(innerGroupName -> allGroups.containsKey(innerGroupName)).
+ // Filter In Only Group members
+ filter(innerGroupName -> allGroups.containsKey(innerGroupName)).
// Collect
- collect(Collectors.toSet());
+ collect(Collectors.toSet());
stop = allGroupMembers.containsAll(membersOfTypeGroup);
}
return stop;
}
- private Either<Resource, ResponseFormat> createRIAndRelationsFromYaml(String yamlName, Resource resource, User user, Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap, AuditingActionEnum actionEnum,
- String topologyTemplateYaml, Map<String, byte[]> csar, String csarUUID, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, Resource> createdVfcs) {
+ private Either<Resource, ResponseFormat> createRIAndRelationsFromYaml(String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap, AuditingActionEnum actionEnum,
+ String topologyTemplateYaml, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ String nodeName) {
Either<Resource, ResponseFormat> result;
Either<Resource, ResponseFormat> createResourcesInstancesEither;
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = findNodeTypeArtifactsToCreate(csar, yamlName, resource, uploadComponentInstanceInfoMap);
-
log.debug("************* Going to create all nodes {}", yamlName);
- Either<Map<String, Resource>, ResponseFormat> createdResourcesFromdNodeTypeMap = this.handleNodeTypes(yamlName, resource, user, topologyTemplateYaml, csar, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts);
+ 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());
}
- createdVfcs.putAll(createdResourcesFromdNodeTypeMap.left().value());
-
log.debug("************* Going to create all resource instances {}", yamlName);
- createResourcesInstancesEither = createResourceInstances(user, yamlName, resource, uploadComponentInstanceInfoMap, true, false, createdResourcesFromdNodeTypeMap.left().value());
+ createResourcesInstancesEither = createResourceInstances(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false, csarInfo.getCreatedNodes());
log.debug("************* Finished to create all resource instances {}", yamlName);
if (createResourcesInstancesEither.isRight()) {
@@ -1687,7 +1869,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
resource = createResourcesInstancesEither.left().value();
log.debug("************* Going to create all relations {}", yamlName);
- createResourcesInstancesEither = createResourceInstancesRelations(user, yamlName, resource, uploadComponentInstanceInfoMap, true, false);
+ createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false);
log.debug("************* Finished to create all relations {}", yamlName);
@@ -1700,44 +1882,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
log.debug("************* Going to create positions {}", yamlName);
- Either<List<ComponentInstance>, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(resource, user.getUserId());
+ Either<List<ComponentInstance>, ResponseFormat> eitherSetPosition = compositionBusinessLogic.setPositionsForComponentInstances(resource, csarInfo.getModifier().getUserId());
log.debug("************* Finished to set positions {}", yamlName);
result = eitherSetPosition.isRight() ? Either.right(eitherSetPosition.right().value()) : Either.left(resource);
return result;
}
- private Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> findNodeTypeArtifactsToCreate(Map<String, byte[]> csar, String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap) {
+ private Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> findNodeTypeArtifactsToCreate(Map<String, byte[]> csar, Resource resource) {
Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts = CsarUtils.extractVfcsArtifactsFromCsar(csar);
- List<ImmutablePair<ImmutablePair<String, List<String>>, String>> extractedVfcToscaNames = extractVfcToscaNames(csar, yamlName, resource.getSystemName(), uploadComponentInstanceInfoMap);
- validateNodeTypeIdentifiers(extractedVfcsArtifacts, extractedVfcToscaNames);
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = null;
- if (!extractedVfcsArtifacts.isEmpty() && !extractedVfcToscaNames.isEmpty()) {
- for (ImmutablePair<ImmutablePair<String, List<String>>, String> currToscaNamePair : extractedVfcToscaNames) {
- EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> curNodeTypeArtifacts = null;
- String currVfcToscaNamespace = currToscaNamePair.getKey().getKey();
- List<String> relatedVfcs = currToscaNamePair.getKey().getValue();
- List<ArtifactDefinition> currArtifactList = null;
-
- for (String currSubstitute : relatedVfcs) {
- if (extractedVfcsArtifacts.containsKey(currSubstitute)) {
- if (MapUtils.isEmpty(curNodeTypeArtifacts)) {
- curNodeTypeArtifacts = new EnumMap<>(ArtifactOperationEnum.class);
- currArtifactList = new ArrayList<>();
- curNodeTypeArtifacts.put(ArtifactOperationEnum.Create, currArtifactList);
- } else {
- currArtifactList = curNodeTypeArtifacts.get(ArtifactOperationEnum.Create);
- }
- handleAndAddExtractedVfcsArtifacts(currArtifactList, extractedVfcsArtifacts.get(currSubstitute));
- }
- }
-
- if (nodeTypesArtifactsToHandle == null) {
- nodeTypesArtifactsToHandle = new HashMap<>();
- }
- nodeTypesArtifactsToHandle.put(currVfcToscaNamespace, curNodeTypeArtifacts);
- }
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
+ for (Map.Entry<String, List<ArtifactDefinition>> currArts : extractedVfcsArtifacts.entrySet()) {
+ EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> artifactsToCreate = new EnumMap<>(ArtifactOperationEnum.class);
+ artifactsToCreate.put(ArtifactOperationEnum.Create, currArts.getValue());
+ nodeTypesArtifactsToHandle.put(currArts.getKey(), artifactsToCreate);
}
return nodeTypesArtifactsToHandle;
}
@@ -1754,47 +1913,51 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- private Either<Map<String, Resource>, ResponseFormat> handleNodeTypes(String yamlName, Resource resource, User user, String topologyTemplateYaml, Map<String, byte[]> csar, boolean needLock,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) {
-
- Map<String, Resource> createdResourcesFromdNodeTypeMap = new HashMap<>();
- Either<Map<String, Resource>, ResponseFormat> result = Either.left(createdResourcesFromdNodeTypeMap);
+ @SuppressWarnings("unchecked")
+ private Either<Map<String, Resource>, ResponseFormat> handleNodeTypes(String yamlName, Resource resource, String topologyTemplateYaml, boolean needLock,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, String nodeName) {
- String yamlFileName = Constants.GLOBAL_SUBSTITUTION_TYPES_SERVICE_TEMPLATE;
+ Either<Map<String, Resource>, ResponseFormat> result = Either.left(csarInfo.getCreatedNodes());
+ for (Entry<String, NodeTypeInfo> nodeTypeEntry : nodeTypesInfo.entrySet()) {
+ if (nodeTypeEntry.getValue().isNested()) {
- if (csar != null && csar.containsKey(yamlFileName)) {
- byte[] yamlFileBytes = csar.get(yamlFileName);
- String globalTypesYaml = new String(yamlFileBytes, StandardCharsets.UTF_8);
- Either<Map<String, Resource>, ResponseFormat> createdNodeTypesFromGlobalTypesTemplateEither = this.createResourcesFromYamlNodeTypesList(yamlFileName, resource, globalTypesYaml, user, needLock, nodeTypesArtifactsToHandle,
- nodeTypesNewCreatedArtifacts);
- if (createdNodeTypesFromGlobalTypesTemplateEither.isRight()) {
- ResponseFormat responseFormat = createdNodeTypesFromGlobalTypesTemplateEither.right().value();
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
- return Either.right(responseFormat);
+ Either<Resource, ResponseFormat> createResourceFromYaml = handleNestedVfc(resource, nodeTypesArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypeEntry.getKey());
+ log.trace("************* finished to create node {}", nodeTypeEntry.getKey());
+ if (createResourceFromYaml.isRight()) {
+ return Either.right(createResourceFromYaml.right().value());
+ }
}
- createdResourcesFromdNodeTypeMap.putAll(createdNodeTypesFromGlobalTypesTemplateEither.left().value());
}
-
- Either<Map<String, Resource>, ResponseFormat> createdNodeTypeFromMainTemplateEither = createResourcesFromYamlNodeTypesList(yamlName, resource, topologyTemplateYaml, user, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts);
+
+ Map<String, Object> mappedToscaTemplate = null;
+ if(StringUtils.isNotEmpty(nodeName) && MapUtils.isNotEmpty(nodeTypesInfo) && nodeTypesInfo.containsKey(nodeName)){
+ mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate();
+ }
+ if(MapUtils.isEmpty(mappedToscaTemplate)){
+ mappedToscaTemplate = (Map<String, Object>) new Yaml().load(topologyTemplateYaml);
+ }
+
+ Either<Map<String, Resource>, ResponseFormat> createdNodeTypeFromMainTemplateEither = createResourcesFromYamlNodeTypesList(yamlName, resource, topologyTemplateYaml, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo);
if (createdNodeTypeFromMainTemplateEither.isRight()) {
ResponseFormat responseFormat = createdNodeTypeFromMainTemplateEither.right().value();
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
return Either.right(responseFormat);
}
- createdResourcesFromdNodeTypeMap.putAll(createdNodeTypeFromMainTemplateEither.left().value());
-
// add the created node types to the cache although they are not in the
// graph.
- createdResourcesFromdNodeTypeMap.values().stream().forEach(p -> cacheManagerOperation.storeComponentInCache(p, NodeTypeEnum.Resource));
+ csarInfo.getCreatedNodes().values().stream().forEach(p -> cacheManagerOperation.storeComponentInCache(p, NodeTypeEnum.Resource));
return result;
}
- private Either<Resource, ResponseFormat> handleCsarArtifacts(Resource resource, User user, String csarUUID, Map<String, byte[]> csar, List<ArtifactDefinition> createdArtifacts, ArtifactOperationInfo artifactOperation, boolean shouldLock,
- boolean inTransaction) {
+ private Either<Resource, ResponseFormat> handleVfCsarArtifacts(Resource resource, CsarInfo csarInfo, List<ArtifactDefinition> createdArtifacts, ArtifactOperationInfo artifactOperation, boolean shouldLock,
+ boolean inTransaction) {
- if (csar != null) {
+ if (csarInfo.getCsar() != null) {
String vendorLicenseModelId = null;
String vfLicenseModelId = null;
@@ -1811,26 +1974,26 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
// Specific Behavior for license artifacts
- createOrUpdateSingleNonMetaArtifact(resource, user, csarUUID, csar, CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL, Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
+ createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL, Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME, Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId, artifactOperation, null, shouldLock, inTransaction);
- createOrUpdateSingleNonMetaArtifact(resource, user, csarUUID, csar, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
+ createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
Constants.VF_LICENSE_LABEL, Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, shouldLock, inTransaction);
- Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarUUID, csar, resource, user, createdArtifacts, shouldLock, inTransaction, artifactOperation);
+ Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation);
if (eitherCreateResult.isRight()) {
return Either.right(eitherCreateResult.right().value());
}
- Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(csar, csarUUID, componentsUtils);
+ Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils);
if (artifacsMetaCsarStatus.isLeft()) {
String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey();
String artifactsContents = artifacsMetaCsarStatus.left().value().getValue();
Either<Resource, ResponseFormat> createArtifactsFromCsar = Either.left(resource);
if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.Create)
- createArtifactsFromCsar = createResourceArtifactsFromCsar(csarUUID, csar, resource, user, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
+ createArtifactsFromCsar = createResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
else
- createArtifactsFromCsar = updateResourceArtifactsFromCsar(csarUUID, csar, resource, user, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
+ createArtifactsFromCsar = updateResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
if (createArtifactsFromCsar.isRight()) {
log.debug("Couldn't create artifacts from artifacts.meta");
return Either.right(createArtifactsFromCsar.right().value());
@@ -1849,7 +2012,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
* Either.right(componentsUtils.getResponseFormat(actionStatus)); } } }
*/
for (String artifactId : artifactsToDelete) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE,
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, csarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE,
resource, null, null, shouldLock, inTransaction);
if (handleDelete.isRight()) {
log.debug("Couldn't delete artifact {}", artifactId);
@@ -1870,18 +2033,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(resource);
}
- private Either<Boolean, ResponseFormat> createOrUpdateSingleNonMetaArtifact(Resource resource, User user, String csarUUID, Map<String, byte[]> csar, String artifactPath, String artifactFileName, String artifactType,
- ArtifactGroupTypeEnum artifactGroupType, String artifactLabel, String artifactDisplayName, String artifactDescription, String artifactId, ArtifactOperationInfo operation, List<ArtifactDefinition> createdArtifacts, boolean shouldLock,
- boolean inTransaction) {
+ private Either<Boolean, ResponseFormat> createOrUpdateSingleNonMetaArtifact(Resource resource, CsarInfo csarInfo, String artifactPath, String artifactFileName, String artifactType,
+ ArtifactGroupTypeEnum artifactGroupType, String artifactLabel, String artifactDisplayName, String artifactDescription, String artifactId, ArtifactOperationInfo operation, List<ArtifactDefinition> createdArtifacts, boolean shouldLock,
+ boolean inTransaction) {
byte[] artifactFileBytes = null;
- if (csar.containsKey(artifactPath)) {
- artifactFileBytes = csar.get(artifactPath);
+ if (csarInfo.getCsar().containsKey(artifactPath)) {
+ artifactFileBytes = csarInfo.getCsar().get(artifactPath);
}
Either<Boolean, ResponseFormat> result = Either.left(true);
if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.Update || operation.getArtifactOperationEnum() == ArtifactOperationEnum.Delete) {
if (artifactId != null && !artifactId.isEmpty() && artifactFileBytes == null) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, null,
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, csarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, null,
null, shouldLock, inTransaction);
if (handleDelete.isRight()) {
result = Either.right(handleDelete.right().value());
@@ -1896,10 +2059,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
if (artifactFileBytes != null) {
Map<String, Object> vendorLicenseModelJson = buildJsonForUpdateArtifact(artifactId, artifactFileName, artifactType, artifactGroupType, artifactLabel, artifactDisplayName, artifactDescription, artifactFileBytes, null);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts = createOrUpdateCsarArtifactFromJson(resource, user, vendorLicenseModelJson, operation, shouldLock, inTransaction);
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts = createOrUpdateCsarArtifactFromJson(resource, csarInfo.getModifier(), vendorLicenseModelJson, operation, shouldLock, inTransaction);
addNonMetaCreatedArtifactsToSupportRollback(operation, createdArtifacts, eitherNonMetaArtifacts);
if (eitherNonMetaArtifacts.isRight()) {
- BeEcompErrorManager.getInstance().logInternalFlowError("UploadLicenseArtifact", "Failed to upload license artifact: " + artifactFileName + "With csar uuid: " + csarUUID, ErrorSeverity.WARNING);
+ BeEcompErrorManager.getInstance().logInternalFlowError("UploadLicenseArtifact", "Failed to upload license artifact: " + artifactFileName + "With csar uuid: " + csarInfo.getCsarUUID(), ErrorSeverity.WARNING);
return Either.right(eitherNonMetaArtifacts.right().value());
}
}
@@ -1930,13 +2093,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(uploadArtifactToService.left().value());
}
- public Either<Resource, ResponseFormat> updateResourceArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdNewArtifacts,
- boolean shouldLock, boolean inTransaction) {
+ public Either<Resource, ResponseFormat> updateResourceArtifactsFromCsar(CsarInfo csarInfo, Resource resource, String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdNewArtifacts,
+ boolean shouldLock, boolean inTransaction) {
- Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, user);
+ Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, csarInfo.getModifier());
if (parseResourceInfoFromYamlEither.isRight()) {
ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value();
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
return Either.right(responseFormat);
}
@@ -1960,7 +2123,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
}
- return createResourceArtifacts(csarUUID, csar, resource, user, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdNewArtifacts, shouldLock, inTransaction);
+ return createResourceArtifacts(csarInfo, resource, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdNewArtifacts, shouldLock, inTransaction);
}
// find master in group
@@ -1990,13 +2153,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Set<ArtifactDefinition> artifactsToDelete = new HashSet<ArtifactDefinition>();
Map<String, List<ArtifactDefinition>> groupToDelete = new HashMap<String, List<ArtifactDefinition>>();
- Map<String, List<String>> dissocArtifactFromGroup = new HashMap<String, List<String>>();
Set<ArtifactTemplateInfo> jsonMasterArtifacts = parsedGroup.keySet();
Map<GroupDefinition, MergedArtifactInfo> mergedgroup = mergeGroupInUpdateFlow(groupArtifact, parsedGroup, artifactsToDelete, groupToDelete, jsonMasterArtifacts, createdDeplymentArtifactsAfterDelete);
// Set<String> deletedArtifactsName = new HashSet<String>();
- Either<List<ArtifactDefinition>, ResponseFormat> deletedArtifactsEither = deleteArtifactsInUpdateCsarFlow(resource, user, shouldLock, inTransaction, artifactsToDelete, groupToDelete);
+ Either<List<ArtifactDefinition>, ResponseFormat> deletedArtifactsEither = deleteArtifactsInUpdateCsarFlow(resource, csarInfo.getModifier(), shouldLock, inTransaction, artifactsToDelete, groupToDelete);
if (deletedArtifactsEither.isRight()) {
log.debug("Failed to delete artifacts. Status is {} ", deletedArtifactsEither.right().value());
@@ -2023,8 +2185,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
////////////// dissociate, associate or create
////////////// artifacts////////////////////////////
- Either<Resource, ResponseFormat> assDissotiateEither = associateAndDissociateArtifactsToGroup(csarUUID, csar, resource, user, createdNewArtifacts, labelCounter, shouldLock, inTransaction, createdDeplymentArtifactsAfterDelete,
- mergedgroup, deletedArtifacts);
+ Either<Resource, ResponseFormat> assDissotiateEither = associateAndDissociateArtifactsToGroup(csarInfo, resource, createdNewArtifacts, labelCounter, shouldLock, inTransaction, createdDeplymentArtifactsAfterDelete,
+ mergedgroup, deletedArtifacts);
if (assDissotiateEither.isRight()) {
log.debug("Failed to delete artifacts. Status is {} ", assDissotiateEither.right().value());
@@ -2042,7 +2204,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
groups = resource.getGroups();
- List<GroupDefinition> groupToUpdate = new ArrayList<>();
+
// update vfModule names
Set<GroupDefinition> groupForAssociateWithMembers = mergedgroup.keySet();
if (groups != null && !groups.isEmpty()) {
@@ -2056,30 +2218,22 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
;
for (GroupDefinition updatedGroupDef : groupForAssociateWithMembers) {
- GroupDefinition group = null;
- Optional<GroupDefinition> opGr = groups.stream().filter(p -> p.getUniqueId().equals(updatedGroupDef.getUniqueId())).findAny();
- if (opGr.isPresent()) {
- group = opGr.get();
- groupToUpdate.add(group);
- }
- if (group != null) {
- Map<String, String> members = new HashMap<String, String>();
- Set<String> artifactsGroup = new HashSet<String>();
- artifactsGroup.addAll(group.getArtifacts());
- associateMembersToArtifacts(createdNewArtifacts, createdDeplymentArtifactsAfterDelete, heatGroups, artifactsGroup, members);
- if (!members.isEmpty()) {
- group.setMembers(members);
- }
+ if (updatedGroupDef.getMembers() != null && !updatedGroupDef.getMembers().isEmpty()) {
+ updatedGroupDef.getMembers().clear();
}
+ Map<String, String> members = new HashMap<String, String>();
+ Set<String> artifactsGroup = new HashSet<String>();
+ artifactsGroup.addAll(updatedGroupDef.getArtifacts());
+ associateMembersToArtifacts(createdNewArtifacts, createdDeplymentArtifactsAfterDelete, heatGroups, artifactsGroup, members);
+ if (!members.isEmpty()) {
+ updatedGroupDef.setMembers(members);
+
+ }
+
}
- /*
- * if (!groupToUpdate.isEmpty()) { Either<List<GroupDefinition>, ResponseFormat> assotiateGroupEither = groupBusinessLogic.associateMembersToGroup(resource.getUniqueId(), user.getUserId(), ComponentTypeEnum.RESOURCE, groupToUpdate, false,
- * true); if (assotiateGroupEither.isRight()) { log.debug("Failed to associate artifacts to groups. Status is {} ", assotiateGroupEither.right().value()); return Either.right(assotiateGroupEither.right().value());
- *
- * } }
- */
+
}
@@ -2111,7 +2265,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (validateGroupNamesRes.isRight()) {
return Either.right(validateGroupNamesRes.right().value());
}
- Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, newArtifactsGroup, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter, shouldLock, inTransaction);
+ Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, resource, newArtifactsGroup, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter, shouldLock, inTransaction);
if (resStatus.isRight())
return resStatus;
}
@@ -2142,7 +2296,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<List<ArtifactDefinition>, ResponseFormat> deleteArtifactsInUpdateCsarFlow(Resource resource, User user, boolean shouldLock, boolean inTransaction, Set<ArtifactDefinition> artifactsToDelete,
- Map<String, List<ArtifactDefinition>> groupToDelete) {
+ Map<String, List<ArtifactDefinition>> groupToDelete) {
List<ArtifactDefinition> deletedArtifacts = new ArrayList<ArtifactDefinition>();
String resourceId = resource.getUniqueId();
if (!artifactsToDelete.isEmpty()) {
@@ -2159,9 +2313,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
* deletedArtifacts.add(removeArifactFromGraph.left().value());
*/
- }
-
- else {
+ } else {
Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resourceId, artifact.getUniqueId(), user, AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource,
null, null, shouldLock, inTransaction);
if (handleDelete.isRight()) {
@@ -2194,8 +2346,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(deletedArtifacts);
}
- private Either<Resource, ResponseFormat> associateAndDissociateArtifactsToGroup(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, List<ArtifactDefinition> createdNewArtifacts, int labelCounter, boolean shouldLock,
- boolean inTransaction, List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete, Map<GroupDefinition, MergedArtifactInfo> mergedgroup, List<ArtifactDefinition> deletedArtifacts) {
+ private Either<Resource, ResponseFormat> associateAndDissociateArtifactsToGroup(CsarInfo csarInfo, Resource resource, List<ArtifactDefinition> createdNewArtifacts, int labelCounter, boolean shouldLock,
+ boolean inTransaction, List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete, Map<GroupDefinition, MergedArtifactInfo> mergedgroup, List<ArtifactDefinition> deletedArtifacts) {
Map<GroupDefinition, List<ArtifactTemplateInfo>> artifactsToAssotiate = new HashMap<GroupDefinition, List<ArtifactTemplateInfo>>();
Map<GroupDefinition, List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>> artifactsToUpdateMap = new HashMap<GroupDefinition, List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>>();
Either<Resource, ResponseFormat> resEither = Either.left(resource);
@@ -2212,7 +2364,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
List<ArtifactTemplateInfo> newArtifactsInGroup = entry.getValue().getListToAssociateArtifactToGroup();
if (newArtifactsInGroup != null && !newArtifactsInGroup.isEmpty())
artifactsToAssotiate.put(entry.getKey(), newArtifactsInGroup);
-
List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>> artifactsToUpdate = entry.getValue().getListToUpdateArtifactInGroup();
if (artifactsToUpdate != null && !artifactsToUpdate.isEmpty())
@@ -2224,11 +2375,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
for (Entry<GroupDefinition, List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>> artifactsToUpdateEntry : artifactsToUpdateMap.entrySet()) {
List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>> artifactsToUpdateList = artifactsToUpdateEntry.getValue();
GroupDefinition groupToUpdate = artifactsToUpdateEntry.getKey();
-
+
for (ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo> artifact : artifactsToUpdateList) {
String prevUUID = artifact.getKey().getArtifactUUID();
String prevId = artifact.getKey().getUniqueId();
- Either<ArtifactDefinition, ResponseFormat> updateArtifactEither = updateDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifact.getKey(), artifact.getValue(), updatedArtifacts,
+ Either<ArtifactDefinition, ResponseFormat> updateArtifactEither = updateDeploymentArtifactsFromCsar(csarInfo, resource, artifact.getKey(), artifact.getValue(), updatedArtifacts,
artifact.getRight().getRelatedArtifactsInfo(), shouldLock, inTransaction);
if (updateArtifactEither.isRight()) {
log.debug("failed to update artifacts. status is {}", updateArtifactEither.right().value());
@@ -2236,7 +2387,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return resEither;
}
ArtifactDefinition artAfterUpdate = updateArtifactEither.left().value();
- if ( !prevUUID.equals(artAfterUpdate.getArtifactUUID()) || !prevId.equals(artAfterUpdate.getUniqueId()) ){
+ if (!prevUUID.equals(artAfterUpdate.getArtifactUUID()) || !prevId.equals(artAfterUpdate.getUniqueId())) {
groupToUpdate.getArtifacts().remove(prevId);
groupToUpdate.getArtifactsUuid().remove(prevUUID);
groupToUpdate.getArtifacts().add(artAfterUpdate.getUniqueId());
@@ -2246,11 +2397,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
- List<GroupDefinition> associateArtifactGroup = new ArrayList<GroupDefinition>();
-
for (Entry<GroupDefinition, List<ArtifactTemplateInfo>> associateEntry : artifactsToAssotiate.entrySet()) {
List<ArtifactTemplateInfo> associatedArtifact = associateEntry.getValue();
Set<String> arifactsUids = new HashSet<String>();
+ Set<String> arifactsUuids = new HashSet<String>();
for (ArtifactTemplateInfo artifactTemplate : associatedArtifact) { // try
// to
// find
@@ -2261,6 +2411,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
for (ArtifactDefinition createdArtifact : createdDeplymentArtifactsAfterDelete) {
if (artifactTemplate.getFileName().equalsIgnoreCase(createdArtifact.getArtifactName())) {
arifactsUids.add(createdArtifact.getUniqueId());
+ arifactsUuids.add(createdArtifact.getUniqueId());
isCreate = false;
String heatEnvId = checkAndGetHeatEnvId(createdArtifact);
if (!heatEnvId.isEmpty()) {
@@ -2280,6 +2431,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
for (ArtifactDefinition createdNewArtifact : createdNewArtifacts) {
if (artifactTemplate.getFileName().equalsIgnoreCase(createdNewArtifact.getArtifactName())) {
arifactsUids.add(createdNewArtifact.getUniqueId());
+ arifactsUuids.add(createdNewArtifact.getUniqueId());
isCreate = false;
String heatEnvId = checkAndGetHeatEnvId(createdNewArtifact);
if (!heatEnvId.isEmpty()) {
@@ -2291,17 +2443,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
if (isCreate) {
- Either<ArtifactDefinition, ResponseFormat> createArtifactEither = createDeploymentArtifact(csarUUID, csar, resource, user, ARTIFACTS_PATH, artifactTemplate, createdNewArtifacts, labelCounter, shouldLock, inTransaction);
+ Either<ArtifactDefinition, ResponseFormat> createArtifactEither = createDeploymentArtifact(csarInfo, resource, ARTIFACTS_PATH, artifactTemplate, createdNewArtifacts, labelCounter, shouldLock, inTransaction);
if (createArtifactEither.isRight()) {
resEither = Either.right(createArtifactEither.right().value());
return resEither;
}
ArtifactDefinition createdArtifact = createArtifactEither.left().value();
arifactsUids.add(createdArtifact.getUniqueId());
+ arifactsUuids.add(createdArtifact.getUniqueId());
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(createdArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_VOL) {
Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(createdArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, resource.getUniqueId(), NodeTypeEnum.Resource,
- resource.getName(), user, resource, null);
+ resource.getName(), csarInfo.getModifier(), resource, null);
if (createHeatEnvPlaceHolder.isRight()) {
return Either.right(createHeatEnvPlaceHolder.right().value());
}
@@ -2314,11 +2467,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (arifactsUids.size() > 0) {
List<String> artifactsToAssociate = new ArrayList<String>();
artifactsToAssociate.addAll(arifactsUids);
- GroupDefinition assotiateGroup = new GroupDefinition();
- assotiateGroup.setUniqueId(associateEntry.getKey().getUniqueId());
- assotiateGroup.setArtifacts(artifactsToAssociate);
- associateArtifactGroup.add(assotiateGroup);
-
+ GroupDefinition assotiateGroup = associateEntry.getKey();
+ assotiateGroup.getArtifacts().addAll(arifactsUids);
+ assotiateGroup.getArtifactsUuid().addAll(arifactsUuids);
}
}
@@ -2354,7 +2505,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Map<GroupDefinition, MergedArtifactInfo> mergeGroupInUpdateFlow(Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact, Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup,
- Set<ArtifactDefinition> artifactsToDelete, Map<String, List<ArtifactDefinition>> groupToDelete, Set<ArtifactTemplateInfo> jsonMasterArtifacts, List<ArtifactDefinition> createdDeplymentArtifacts) {
+ Set<ArtifactDefinition> artifactsToDelete, Map<String, List<ArtifactDefinition>> groupToDelete, Set<ArtifactTemplateInfo> jsonMasterArtifacts, List<ArtifactDefinition> createdDeplymentArtifacts) {
Map<GroupDefinition, MergedArtifactInfo> mergedgroup = new HashMap<GroupDefinition, MergedArtifactInfo>();
for (Entry<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupListEntry : groupArtifact.entrySet()) {
Map<ArtifactDefinition, List<ArtifactDefinition>> createdArtifactMap = groupListEntry.getValue();
@@ -2365,21 +2516,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
for (ArtifactDefinition artToDelete : listToDelete) {
findArtifactToDelete(parsedGroup, artifactsToDelete, groupListEntry.getKey().getUniqueId(), artToDelete, createdDeplymentArtifacts);
}
- if(artifactsToDelete != null && !artifactsToDelete.isEmpty()){
+ if (artifactsToDelete != null && !artifactsToDelete.isEmpty()) {
GroupDefinition group = groupListEntry.getKey();
- for(ArtifactDefinition artifactDefinition: artifactsToDelete){
+ for (ArtifactDefinition artifactDefinition : artifactsToDelete) {
if (CollectionUtils.isNotEmpty(group.getArtifacts()) && group.getArtifacts().contains(artifactDefinition.getUniqueId())) {
group.getArtifacts().remove(artifactDefinition.getUniqueId());
-
+
}
if (CollectionUtils.isNotEmpty(group.getArtifactsUuid()) && group.getArtifactsUuid().contains(artifactDefinition.getArtifactUUID())) {
group.getArtifactsUuid().remove(artifactDefinition.getArtifactUUID());
-
+
}
}
-
+
}
-
+
for (ArtifactTemplateInfo jsonMasterArtifact : jsonMasterArtifacts) {
if (maserArtifact.getArtifactName().equalsIgnoreCase(jsonMasterArtifact.getFileName())) {
MergedArtifactInfo mergedGroup = new MergedArtifactInfo();
@@ -2400,34 +2551,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return mergedgroup;
}
- private Set<String> findArtifactsNotInGroupToDelete(List<GroupDefinition> groups, List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete) {
- Set<String> artifactNotInGroupSet = new HashSet<String>();
- for (ArtifactDefinition artifact : createdDeplymentArtifactsAfterDelete) {
- boolean needToDelete = true;
- if (artifact.getArtifactName().equalsIgnoreCase(Constants.VENDOR_LICENSE_MODEL) || artifact.getArtifactName().equalsIgnoreCase(Constants.VF_LICENSE_MODEL))
- continue;
- if (groups != null) {
- for (GroupDefinition group : groups) {
- List<String> groupArtifactIds = group.getArtifacts();
- if (groupArtifactIds == null || groupArtifactIds.isEmpty()) {
- continue;
- }
- for (String groupArtifactid : groupArtifactIds) {
- if (groupArtifactid.equalsIgnoreCase(artifact.getUniqueId()))
- needToDelete = false;
-
- }
-
- }
- }
- if (needToDelete)
- artifactNotInGroupSet.add(artifact.getUniqueId());
- }
- return artifactNotInGroupSet;
- }
-
private void findArtifactToDelete(Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Set<ArtifactDefinition> artifactsToDelete, String deleteGroupId, ArtifactDefinition artifact,
- List<ArtifactDefinition> createdDeplymentArtifacts) {
+ List<ArtifactDefinition> createdDeplymentArtifacts) {
boolean isNeedToDeleteArtifact = true;
String artifactType = artifact.getArtifactType();
ArtifactDefinition generatedFromArt = null;
@@ -2492,20 +2617,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
- public Either<Resource, ResponseFormat> createResourceArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdArtifacts,
- boolean shouldLock, boolean inTransaction) {
+ public Either<Resource, ResponseFormat> createResourceArtifactsFromCsar(CsarInfo csarInfo, Resource resource, String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdArtifacts,
+ boolean shouldLock, boolean inTransaction) {
log.debug("parseResourceArtifactsInfoFromFile start");
- Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, user);
+ Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceInfoFromYamlEither = parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName, csarInfo.getModifier());
if (parseResourceInfoFromYamlEither.isRight()) {
ResponseFormat responseFormat = parseResourceInfoFromYamlEither.right().value();
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
return Either.right(responseFormat);
}
log.debug("parseResourceArtifactsInfoFromFile end");
log.debug("createResourceArtifacts start");
- Either<Resource, ResponseFormat> respStatus = createResourceArtifacts(csarUUID, csar, resource, user, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdArtifacts, shouldLock, inTransaction);
+ Either<Resource, ResponseFormat> respStatus = createResourceArtifacts(csarInfo, resource, parseResourceInfoFromYamlEither.left().value(), AuditingActionEnum.CREATE_RESOURCE, createdArtifacts, shouldLock, inTransaction);
if (respStatus.isRight()) {
return respStatus;
}
@@ -2523,8 +2648,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, List<ArtifactTemplateInfo> artifactsTemplateList,
- List<ArtifactDefinition> createdNewArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter, boolean shouldLock, boolean inTransaction) {
+ private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, List<ArtifactTemplateInfo> artifactsTemplateList,
+ List<ArtifactDefinition> createdNewArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter, boolean shouldLock, boolean inTransaction) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
List<GroupDefinition> createdGroups = resource.getGroups();
List<GroupDefinition> heatGroups = null;
@@ -2538,7 +2663,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Set<String> artifactsGroup = new HashSet<String>();
Set<String> artifactsUUIDGroup = new HashSet<String>();
- resStatus = createDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter, shouldLock, inTransaction);
+ resStatus = createDeploymentArtifactsFromCsar(csarInfo, resource, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter, shouldLock, inTransaction);
if (resStatus.isRight())
return resStatus;
@@ -2562,7 +2687,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
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);
@@ -2590,15 +2715,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
resource = component.left().value();
- Either<List<GroupDefinition>, ResponseFormat> addGroups = groupBusinessLogic.addGroups(resource, user, ComponentTypeEnum.RESOURCE, needToAdd);
+ Either<List<GroupDefinition>, ResponseFormat> addGroups = groupBusinessLogic.addGroups(resource, csarInfo.getModifier(), ComponentTypeEnum.RESOURCE, needToAdd);
if (addGroups.isRight())
return Either.right(addGroups.right().value());
return resStatus;
}
- private Either<Resource, ResponseFormat> createDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, Set<String> artifactsGroup, Set<String> artifactsUUIDGroup,
- ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter, boolean shoudLock, boolean inTransaction) {
+ private Either<Resource, ResponseFormat> createDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, Set<String> artifactsGroup, Set<String> artifactsUUIDGroup,
+ ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter, boolean shoudLock, boolean inTransaction) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
String artifactFileName = artifactTemplateInfo.getFileName();
String artifactUid = "";
@@ -2646,7 +2771,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// if not exist need to create
if (!alreadyExist) {
- Either<ArtifactDefinition, ResponseFormat> newArtifactEither = createDeploymentArtifact(csarUUID, csar, resource, user, ARTIFACTS_PATH, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
+ Either<ArtifactDefinition, ResponseFormat> newArtifactEither = createDeploymentArtifact(csarInfo, resource, ARTIFACTS_PATH, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
if (newArtifactEither.isRight()) {
resStatus = Either.right(newArtifactEither.right().value());
return resStatus;
@@ -2657,7 +2782,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_VOL) {
Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, resource.getUniqueId(), NodeTypeEnum.Resource,
- resource.getName(), user, resource, null);
+ resource.getName(), csarInfo.getModifier(), resource, null);
if (createHeatEnvPlaceHolder.isRight()) {
return Either.right(createHeatEnvPlaceHolder.right().value());
}
@@ -2674,7 +2799,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
List<ArtifactTemplateInfo> relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo();
if (relatedArtifacts != null) {
for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) {
- resStatus = createDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, artifactsFromResource, labelCounter, shoudLock, inTransaction);
+ resStatus = createDeploymentArtifactsFromCsar(csarInfo, resource, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, artifactsFromResource, labelCounter, shoudLock, inTransaction);
if (resStatus.isRight())
return resStatus;
}
@@ -2682,8 +2807,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return resStatus;
}
- private Either<Resource, ResponseFormat> createResourceArtifacts(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, Map<String, List<ArtifactTemplateInfo>> artifactsMap, AuditingActionEnum createResource,
- List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction) {
+ private Either<Resource, ResponseFormat> createResourceArtifacts(CsarInfo csarInfo, Resource resource, Map<String, List<ArtifactTemplateInfo>> artifactsMap, AuditingActionEnum createResource,
+ List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
@@ -2691,7 +2816,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
for (List<ArtifactTemplateInfo> groupTemplateList : arifactsCollection) {
if (groupTemplateList != null) {
- resStatus = createGroupDeploymentArtifactsFromCsar(csarUUID, csar, resource, user, groupTemplateList, createdArtifacts, 0, shouldLock, inTransaction);
+ resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, resource, groupTemplateList, createdArtifacts, 0, shouldLock, inTransaction);
if (resStatus.isRight())
return resStatus;
}
@@ -2701,8 +2826,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- private Either<Resource, ResponseFormat> createOrUpdateNonMetaArtifacts(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction,
- ArtifactOperationInfo artifactOperation) {
+ private Either<Resource, ResponseFormat> createOrUpdateNonMetaArtifacts(CsarInfo csarInfo, Resource resource, List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction, ArtifactOperationInfo artifactOperation) {
Either<Resource, ResponseFormat> resStatus = null;
Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
@@ -2710,7 +2834,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
try {
List<NonMetaArtifactInfo> artifactPathAndNameList =
// Stream of file paths contained in csar
- csar.entrySet().stream()
+ csarInfo.getCsar().entrySet().stream()
// Filter in only VF artifact path location
.filter(e -> Pattern.compile(VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN).matcher(e.getKey()).matches())
// Validate and add warnings
@@ -2722,13 +2846,19 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// collect to List
.collect(Collectors.toList());
+ Either<Boolean, String> responseFormatEither = validateArtifactNames(artifactPathAndNameList);
+ if (responseFormatEither.isRight()) {
+ return Either.right(getComponentsUtils().getResponseFormatByArtifactId(ActionStatus.ARTIFACT_NAME_INVALID, responseFormatEither.right().value()));
+ }
+
+
EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> vfCsarArtifactsToHandle = null;
if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.Create) {
vfCsarArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList);
} else {
- Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, user);
+ Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, csarInfo.getModifier());
if (findVfCsarArtifactsToHandleRes.isRight()) {
resStatus = Either.right(findVfCsarArtifactsToHandleRes.right().value());
@@ -2744,15 +2874,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// Stream of artifacts to be created
currArtifactOperationPair.getValue().stream()
// create each artifact
- .map(e -> createOrUpdateSingleNonMetaArtifact(resource, user, csarUUID, csar, e.getPath(), e.getArtifactName(), e.getArtifactType().getType(), e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(),
+ .map(e -> createOrUpdateSingleNonMetaArtifact(resource, csarInfo, e.getPath(), e.getArtifactName(), e.getArtifactType().getType(), e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(),
CsarUtils.ARTIFACT_CREATED_FROM_CSAR, e.getArtifactUniqueId(), artifactsBusinessLogic.new ArtifactOperationInfo(false, false, currArtifactOperationPair.getKey()), createdArtifacts, shouldLock,
inTransaction))
// filter in only error
.filter(e -> e.isRight()).
// Convert the error from either to ResponseFormat
- map(e -> e.right().value()).
+ map(e -> e.right().value()).
// Check if an error occurred
- findAny();
+ findAny();
// Error found on artifact Creation
if (optionalCreateInDBError.isPresent()) {
resStatus = Either.right(optionalCreateInDBError.get());
@@ -2772,6 +2902,17 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return resStatus;
}
+ private Either<Boolean, String> validateArtifactNames(List<NonMetaArtifactInfo> artifactPathAndNameList) {
+ Pattern englishNumbersAndUnderScoresOnly = Pattern.compile(CsarUtils.VALID_ENGLISH_ARTIFACT_NAME);
+ for (NonMetaArtifactInfo nonMetaArtifactInfo : artifactPathAndNameList) {
+ if (!englishNumbersAndUnderScoresOnly.matcher(nonMetaArtifactInfo.getDisplayName()).matches()) {
+ return Either.right(nonMetaArtifactInfo.getArtifactName());
+ }
+ }
+ return Either.left(true);
+ }
+
+
private Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandle(Resource resource, List<NonMetaArtifactInfo> artifactPathAndNameList, User user) {
List<ArtifactDefinition> existingArtifacts = new ArrayList<>();
@@ -2816,8 +2957,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
- private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, List<ArtifactTemplateInfo> artifactsTemplateList, List<ArtifactDefinition> createdArtifacts,
- int labelCounter, boolean shouldLock, boolean inTransaction) {
+ private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, List<ArtifactTemplateInfo> artifactsTemplateList, List<ArtifactDefinition> createdArtifacts,
+ int labelCounter, boolean shouldLock, boolean inTransaction) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
List<GroupDefinition> createdGroups = resource.getGroups();
List<GroupDefinition> heatGroups = null;
@@ -2840,7 +2981,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Set<String> artifactsUUIDGroup = new HashSet<String>();
log.debug("createDeploymentArtifactsFromCsar start");
- resStatus = createDeploymentArtifactFromCsar(csarUUID, ARTIFACTS_PATH, csar, resource, user, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdArtifacts, labelCounter, shouldLock, inTransaction);
+ resStatus = createDeploymentArtifactFromCsar(csarInfo, ARTIFACTS_PATH, resource, artifactsGroup, artifactsUUIDGroup, groupTemplateInfo, createdArtifacts, labelCounter, shouldLock, inTransaction);
log.debug("createDeploymentArtifactsFromCsar end");
if (resStatus.isRight())
return resStatus;
@@ -2895,7 +3036,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
- Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.addGroups(component.left().value(), user, ComponentTypeEnum.RESOURCE, needToCreate);
+ Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.addGroups(component.left().value(), csarInfo.getModifier(), ComponentTypeEnum.RESOURCE, needToCreate);
if (createGroups.isRight()) {
return Either.right(createGroups.right().value());
}
@@ -2980,7 +3121,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
String heatFileNAme = prop.getValue();
if (null == heatFileNAme || heatFileNAme.isEmpty())
continue;
- List<ArtifactDefinition> artifacts = new ArrayList();
+ List<ArtifactDefinition> artifacts = new ArrayList<ArtifactDefinition>();
for (String artifactId : artifactsGroup) {
Optional<ArtifactDefinition> opArt = createdArtifacts.stream().filter(p -> p.getUniqueId().equals(artifactId)).findAny();
if (opArt.isPresent()) {
@@ -3004,8 +3145,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
- private Either<Resource, ResponseFormat> createDeploymentArtifactFromCsar(String csarUUID, String artifactPath, Map<String, byte[]> csar, Resource resource, User user, Set<String> artifactsGroup, Set<String> artifactsUUIDGroup,
- ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> createdArtifacts, int labelCounter, boolean shoudLock, boolean inTransaction) {
+ private Either<Resource, ResponseFormat> createDeploymentArtifactFromCsar(CsarInfo csarInfo, String artifactPath, Resource resource, Set<String> artifactsGroup, Set<String> artifactsUUIDGroup,
+ ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> createdArtifacts, int labelCounter, boolean shoudLock, boolean inTransaction) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
String artifactFileName = artifactTemplateInfo.getFileName();
String artifactUid = "";
@@ -3031,7 +3172,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// if not exist need to create
if (!alreadyExist) {
- Either<ArtifactDefinition, ResponseFormat> newArtifactEither = createDeploymentArtifact(csarUUID, csar, resource, user, artifactPath, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
+ Either<ArtifactDefinition, ResponseFormat> newArtifactEither = createDeploymentArtifact(csarInfo, resource, artifactPath, artifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
if (newArtifactEither.isRight()) {
resStatus = Either.right(newArtifactEither.right().value());
return resStatus;
@@ -3043,7 +3184,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_VOL) {
Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, resource.getUniqueId(), NodeTypeEnum.Resource,
- resource.getName(), user, resource, null);
+ resource.getName(), csarInfo.getModifier(), resource, null);
if (createHeatEnvPlaceHolder.isRight()) {
return Either.right(createHeatEnvPlaceHolder.right().value());
}
@@ -3060,7 +3201,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
List<ArtifactTemplateInfo> relatedArtifacts = artifactTemplateInfo.getRelatedArtifactsInfo();
if (relatedArtifacts != null) {
for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) {
- resStatus = createDeploymentArtifactFromCsar(csarUUID, artifactPath, csar, resource, user, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
+ resStatus = createDeploymentArtifactFromCsar(csarInfo, artifactPath, resource, artifactsGroup, artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, labelCounter, shoudLock, inTransaction);
if (resStatus.isRight())
return resStatus;
}
@@ -3077,10 +3218,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return artifactEnvUid;
}
- private Either<ArtifactDefinition, ResponseFormat> createDeploymentArtifact(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, String artifactPath, ArtifactTemplateInfo artifactTemplateInfo,
- List<ArtifactDefinition> createdArtifacts, int labelCounter, boolean shoudLock, boolean inTransaction) {
+ private Either<ArtifactDefinition, ResponseFormat> createDeploymentArtifact(CsarInfo csarInfo, Resource resource, String artifactPath, ArtifactTemplateInfo artifactTemplateInfo,
+ List<ArtifactDefinition> createdArtifacts, int labelCounter, boolean shoudLock, boolean inTransaction) {
final String artifactFileName = artifactTemplateInfo.getFileName();
- Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarUUID, csar, artifactPath + artifactFileName, artifactFileName, componentsUtils);
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), artifactPath + artifactFileName, artifactFileName, componentsUtils);
if (artifactContententStatus.isRight()) {
return Either.right(artifactContententStatus.right().value());
}
@@ -3088,7 +3229,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Map<String, Object> json = buildJsonForArtifact(artifactTemplateInfo, artifactContententStatus.left().value().getValue(), labelCounter);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, user, json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create),
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, csarInfo.getModifier(), json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create),
shoudLock, inTransaction);
if (uploadArtifactToService.isRight())
@@ -3097,7 +3238,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value();
if (currentInfo.getHeatParameters() != null) {
- Either<ArtifactDefinition, ResponseFormat> updateEnvEither = updateHeatParamsFromCsar(resource, csarUUID, csar, artifactTemplateInfo, currentInfo, false);
+ Either<ArtifactDefinition, ResponseFormat> updateEnvEither = updateHeatParamsFromCsar(resource, csarInfo, artifactTemplateInfo, currentInfo, false);
if (updateEnvEither.isRight()) {
log.debug("failed to update parameters to artifact {}", artifactFileName);
return Either.right(updateEnvEither.right().value());
@@ -3113,39 +3254,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- private Either<ArtifactDefinition, ResponseFormat> createInformationalArtifact(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, ArtifactTemplateInfo artifactTemplateInfo, int labelCounter, boolean shoudLock,
- boolean inTransaction) {
- final String artifactFileName = artifactTemplateInfo.getFileName();
- String artifactPath = CsarUtils.ARTIFACTS_PATH + CsarUtils.INFORMATIONAL_ARTIFACTS + artifactFileName;
- Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarUUID, csar, artifactPath, artifactFileName, componentsUtils);
- if (artifactContententStatus.isRight())
- return Either.right(artifactContententStatus.right().value());
-
- Map<String, Object> json = buildJsonForArtifact(artifactTemplateInfo, artifactContententStatus.left().value().getValue(), labelCounter);
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, user, json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Create),
- shoudLock, inTransaction);
-
- if (uploadArtifactToService.isRight())
- return Either.right(uploadArtifactToService.right().value());
-
- ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value();
-
- return Either.left(currentInfo);
-
- }
-
- private Either<ArtifactDefinition, ResponseFormat> updateDeploymentArtifactsFromCsar(String csarUUID, Map<String, byte[]> csar, Resource resource, User user, ArtifactDefinition oldArtifact, ArtifactTemplateInfo artifactTemplateInfo,
- List<ArtifactDefinition> updatedArtifacts, List<ArtifactTemplateInfo> updatedRequiredArtifacts, boolean shouldLock, boolean inTransaction) {
+ private Either<ArtifactDefinition, ResponseFormat> updateDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource, ArtifactDefinition oldArtifact, ArtifactTemplateInfo artifactTemplateInfo,
+ List<ArtifactDefinition> updatedArtifacts, List<ArtifactTemplateInfo> updatedRequiredArtifacts, boolean shouldLock, boolean inTransaction) {
Either<ArtifactDefinition, ResponseFormat> resStatus = null;
String artifactFileName = artifactTemplateInfo.getFileName();
- String artifactUid = "";
// check if artifacts already exist
for (ArtifactDefinition updatedArtifact : updatedArtifacts) {
if (updatedArtifact.getArtifactName().equals(artifactFileName)) {
- artifactUid = updatedArtifact.getUniqueId();
if (!updatedArtifact.getArtifactType().equalsIgnoreCase(artifactTemplateInfo.getType())) {
log.debug("Artifact with name {} and type {} already updated with type {}", artifactFileName, artifactTemplateInfo.getType(), updatedArtifact.getArtifactType());
BeEcompErrorManager.getInstance().logInternalDataError("Artifact file is not in expected formatr, fileName " + artifactFileName, "Artifact internals are invalid", ErrorSeverity.ERROR);
@@ -3158,7 +3275,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarUUID, csar, CsarUtils.ARTIFACTS_PATH + artifactFileName, artifactFileName, componentsUtils);
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils.getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), CsarUtils.ARTIFACTS_PATH + artifactFileName, artifactFileName, componentsUtils);
if (artifactContententStatus.isRight()) {
resStatus = Either.right(artifactContententStatus.right().value());
return resStatus;
@@ -3167,7 +3284,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Map<String, Object> json = buildJsonForUpdateArtifact(oldArtifact.getUniqueId(), artifactFileName, oldArtifact.getArtifactType(), ArtifactGroupTypeEnum.DEPLOYMENT, oldArtifact.getArtifactLabel(), oldArtifact.getArtifactDisplayName(),
oldArtifact.getDescription(), artifactContententStatus.left().value().getRight(), updatedRequiredArtifacts);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, user, json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update),
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(resource, csarInfo.getModifier(), json, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.Update),
shouldLock, inTransaction);
if (uploadArtifactToService.isRight()) {
@@ -3176,7 +3293,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value();
- Either<ArtifactDefinition, ResponseFormat> updateEnvEither = updateHeatParamsFromCsar(resource, csarUUID, csar, artifactTemplateInfo, currentInfo, true);
+ Either<ArtifactDefinition, ResponseFormat> updateEnvEither = updateHeatParamsFromCsar(resource, csarInfo, artifactTemplateInfo, currentInfo, true);
if (updateEnvEither.isRight()) {
log.debug("failed to update parameters to artifact {}", artifactFileName);
resStatus = Either.right(updateEnvEither.right().value());
@@ -3184,7 +3301,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
// TODO evg update env time ( must be separate US for this!!!!)
- artifactUid = updateEnvEither.left().value().getUniqueId();
updatedArtifacts.add(updateEnvEither.left().value());
resStatus = Either.left(updateEnvEither.left().value());
@@ -3192,11 +3308,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- private Either<ArtifactDefinition, ResponseFormat> updateHeatParamsFromCsar(Resource resource, String csarUUID, Map<String, byte[]> csar, ArtifactTemplateInfo artifactTemplateInfo, ArtifactDefinition currentInfo, boolean isUpdateEnv) {
+ private Either<ArtifactDefinition, ResponseFormat> updateHeatParamsFromCsar(Resource resource, CsarInfo csarInfo, ArtifactTemplateInfo artifactTemplateInfo, ArtifactDefinition currentInfo, boolean isUpdateEnv) {
Either<ArtifactDefinition, ResponseFormat> resStatus = Either.left(currentInfo);
if (artifactTemplateInfo.getEnv() != null && !artifactTemplateInfo.getEnv().isEmpty()) {
- Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactparamsStatus = CsarValidationUtils.getArtifactsContent(csarUUID, csar, CsarUtils.ARTIFACTS_PATH + artifactTemplateInfo.getEnv(), artifactTemplateInfo.getEnv(),
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactparamsStatus = CsarValidationUtils.getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), CsarUtils.ARTIFACTS_PATH + artifactTemplateInfo.getEnv(), artifactTemplateInfo.getEnv(),
componentsUtils);
if (artifactparamsStatus.isRight()) {
resStatus = Either.right(artifactparamsStatus.right().value());
@@ -3308,7 +3424,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Map<String, Object> buildJsonForUpdateArtifact(String artifactId, String artifactName, String artifactType, ArtifactGroupTypeEnum artifactGroupType, String label, String displayName, String description, byte[] artifactContentent,
- List<ArtifactTemplateInfo> updatedRequiredArtifacts) {
+ List<ArtifactTemplateInfo> updatedRequiredArtifacts) {
Map<String, Object> json = new HashMap<String, Object>();
if (artifactId != null && !artifactId.isEmpty())
@@ -3335,6 +3451,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return json;
}
+ @SuppressWarnings({ "unchecked", "static-access" })
private Either<Map<String, List<ArtifactTemplateInfo>>, ResponseFormat> parseResourceArtifactsInfoFromFile(Resource resource, String artifactsMetaFile, String artifactFileName, User user) {
try {
@@ -3434,7 +3551,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (allDataTypes.isRight()) {
TitanOperationStatus status = allDataTypes.right().value();
BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName));
}
@@ -3446,6 +3563,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Map<String, Resource> originCompMap = new HashMap<>();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
+ Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
+
for (Entry<String, UploadComponentInstanceInfo> entry : uploadResInstancesMap.entrySet()) {
UploadComponentInstanceInfo uploadComponentInstanceInfo = entry.getValue();
ComponentInstance currentCompInstance = null;
@@ -3466,31 +3585,72 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
String resourceInstanceId = currentCompInstance.getUniqueId();
Resource originResource = null;
if (!originCompMap.containsKey(currentCompInstance.getComponentUid())) {
- Either<Resource, StorageOperationStatus> getPropertyRes = toscaOperationFacade.getToscaFullElement(currentCompInstance.getComponentUid());
- if (getPropertyRes.isRight()) {
- log.debug("failed to find properties of resource {} status is {}", currentCompInstance.getComponentUid(), getPropertyRes);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getPropertyRes.right().value()), yamlName);
+ Either<Resource, StorageOperationStatus> getOriginResourceRes = toscaOperationFacade.getToscaFullElement(currentCompInstance.getComponentUid());
+ if (getOriginResourceRes.isRight()) {
+ log.debug("failed to fetch resource with uniqueId {} and tosca component name {} status is {}", currentCompInstance.getComponentUid(), currentCompInstance.getToscaComponentName(), getOriginResourceRes);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getOriginResourceRes.right().value()), yamlName);
return Either.right(responseFormat);
}
- originResource = getPropertyRes.left().value();
+ originResource = getOriginResourceRes.left().value();
originCompMap.put(originResource.getUniqueId(), originResource);
} 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 (originResource.getCapabilities() != null && !originResource.getCapabilities().isEmpty()) {
+ Map<String, List<CapabilityDefinition>> originCapabilities ;
+ if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilitiesNamesToUpdate()) && resource.getResourceType() == ResourceTypeEnum.CVFC) {
+ 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);
+ });
+ for (List<CapabilityDefinition> capabilities : originCapabilities.values()) {
+ capabilities.stream().filter(c -> uploadComponentInstanceInfo.getCapabilitiesNamesToUpdate().containsKey(c.getName())).forEach(c -> c.setName(uploadComponentInstanceInfo.getCapabilitiesNamesToUpdate().get(c.getName())));
+ }
+ }else{
+ originCapabilities = originResource.getCapabilities();
+ }
+ instCapabilties.put(currentCompInstance, originCapabilities);
+ }
+ if (originResource.getRequirements() != null && !originResource.getRequirements().isEmpty()) {
+ Map<String, List<RequirementDefinition>> originRequirements;
+ if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getRequirementsNamesToUpdate()) && resource.getResourceType() == ResourceTypeEnum.CVFC) {
+ originRequirements = new HashMap<>();
+ originResource.getRequirements().entrySet().stream().forEach(e ->{
+ List<RequirementDefinition> list = e.getValue().stream().map(l -> new RequirementDefinition(l)).collect(Collectors.toList());
+ originRequirements.put(e.getKey(), list);
+ });
+ for (List<RequirementDefinition> requirements : originRequirements.values()) {
+ requirements.stream().filter(r -> uploadComponentInstanceInfo.getRequirementsNamesToUpdate().containsKey(r.getName())).forEach(r -> r.setName(uploadComponentInstanceInfo.getRequirementsNamesToUpdate().get(r.getName())));
+ }
+ }else{
+ originRequirements = originResource.getRequirements();
+ }
+ instRequirements.put(currentCompInstance, originRequirements);
+ }
if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts().isEmpty())
instArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts());
if (originResource.getAttributes() != null && !originResource.getAttributes().isEmpty())
instAttributes.put(resourceInstanceId, originResource.getAttributes());
-
- ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, yamlName, instProperties, allDataTypes.left().value());
- if (addPropertiesValueToRiRes.getStatus() != 200) {
- return Either.right(addPropertiesValueToRiRes);
+ if (originResource.getResourceType() != ResourceTypeEnum.CVFC) {
+ ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, yamlName, instProperties, allDataTypes.left().value());
+ if (addPropertiesValueToRiRes.getStatus() != 200) {
+ 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);
+ }
}
-
}
Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addPropToInst = toscaOperationFacade.associateComponentInstancePropertiesToComponent(instProperties, resource.getUniqueId());
@@ -3499,7 +3659,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addPropToInst.right().value()), yamlName);
return Either.right(responseFormat);
}
-
+ if (instInputs != null && !instInputs.isEmpty()) {
+ Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addInputToInst = toscaOperationFacade.associateComponentInstanceInputsToComponent(instInputs, resource.getUniqueId());
+ if (addInputToInst.isRight()) {
+ log.debug("failed to associate inputs value of resource {} status is {}", resource.getUniqueId(), addInputToInst.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addInputToInst.right().value()), yamlName);
+ return Either.right(responseFormat);
+ }
+ }
StorageOperationStatus addArtToInst = toscaOperationFacade.associateArtifactToInstances(instArtifacts, resource.getUniqueId(), user);
if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst);
@@ -3585,8 +3752,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private ResponseFormat addRelationToRI(String yamlName, Resource resource, UploadComponentInstanceInfo nodesInfoValue, List<RequirementCapabilityRelDef> relations) {
List<ComponentInstance> componentInstancesList = resource.getComponentInstances();
- long totalCreateRel = 0;
- long totalCreatePropVal = 0;
UploadComponentInstanceInfo uploadComponentInstanceInfo = nodesInfoValue;
@@ -3609,95 +3774,188 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
String resourceInstanceId = currentCompInstance.getUniqueId();
- log.debug("************* addPropertyValuesToRi start");
- long startAddProperty = System.currentTimeMillis();
- log.debug("************* addPropertyValuesToRi end");
- totalCreatePropVal += (System.currentTimeMillis() - startAddProperty);
Map<String, List<UploadReqInfo>> regMap = uploadComponentInstanceInfo.getRequirements();
- if (regMap == null) {
+
+ if (regMap != null) {
+ Iterator<Entry<String, List<UploadReqInfo>>> nodesRegValue = regMap.entrySet().iterator();
+
+ while (nodesRegValue.hasNext()) {
+ Entry<String, List<UploadReqInfo>> nodesRegInfoEntry = nodesRegValue.next();
+
+ List<UploadReqInfo> uploadRegInfoList = nodesRegInfoEntry.getValue();
+ for (UploadReqInfo uploadRegInfo : uploadRegInfoList) {
+ log.debug("Going to create relation {}", uploadRegInfo.getName());
+ String regName = uploadRegInfo.getName();
+ RequirementCapabilityRelDef regCapRelDef = new RequirementCapabilityRelDef();
+ regCapRelDef.setFromNode(resourceInstanceId);
+ log.debug("try to find available requirement {} ", regName);
+ Either<RequirementDefinition, ResponseFormat> eitherReqStatus = findAviableRequiremen(regName, yamlName, uploadComponentInstanceInfo, currentCompInstance, uploadRegInfo.getCapabilityName());
+ if (eitherReqStatus.isRight()) {
+ log.debug("failed to find available requirement {} status is {}", regName, eitherReqStatus.right().value());
+ return eitherReqStatus.right().value();
+ }
+
+ RequirementDefinition validReq = eitherReqStatus.left().value();
+ List<RequirementAndRelationshipPair> reqAndRelationshipPairList = regCapRelDef.getRelationships();
+ if (reqAndRelationshipPairList == null)
+ reqAndRelationshipPairList = new ArrayList<RequirementAndRelationshipPair>();
+ RequirementAndRelationshipPair reqAndRelationshipPair = new RequirementAndRelationshipPair();
+ reqAndRelationshipPair.setRequirement(regName);
+ reqAndRelationshipPair.setRequirementOwnerId(validReq.getOwnerId());
+ reqAndRelationshipPair.setRequirementUid(validReq.getUniqueId());
+ RelationshipImpl relationship = new RelationshipImpl();
+ relationship.setType(validReq.getCapability());
+ reqAndRelationshipPair.setRelationships(relationship);
+
+ ComponentInstance currentCapCompInstance = null;
+ for (ComponentInstance compInstance : componentInstancesList) {
+ if (compInstance.getName().equals(uploadRegInfo.getNode())) {
+ currentCapCompInstance = compInstance;
+ break;
+ }
+ }
+
+ if (currentCapCompInstance == null) {
+ log.debug("The component instance with name {} not found on resource {} ", uploadRegInfo.getNode(), resource.getUniqueId());
+ BeEcompErrorManager.getInstance().logInternalDataError("component instance with name " + uploadRegInfo.getNode() + " in resource {} ", resource.getUniqueId(), ErrorSeverity.ERROR);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ return responseFormat;
+ }
+ regCapRelDef.setToNode(currentCapCompInstance.getUniqueId());
+ log.debug("try to find aviable Capability req name is {} ", validReq.getName());
+ CapabilityDefinition aviableCapForRel = findAvailableCapabilityByTypeOrName(validReq, currentCapCompInstance, uploadRegInfo);
+ if (aviableCapForRel == null) {
+ log.debug("aviable capability was not found. req name is {} component instance is {}", validReq.getName(), currentCapCompInstance.getUniqueId());
+ BeEcompErrorManager.getInstance().logInternalDataError("aviable capability was not found. req name is " + validReq.getName() + " component instance is " + currentCapCompInstance.getUniqueId(), resource.getUniqueId(),
+ ErrorSeverity.ERROR);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ return responseFormat;
+ }
+ reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
+ reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
+ reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
+ reqAndRelationshipPairList.add(reqAndRelationshipPair);
+ regCapRelDef.setRelationships(reqAndRelationshipPairList);
+ relations.add(regCapRelDef);
+ }
+ }
+ } else if (resource.getResourceType() != ResourceTypeEnum.CVFC) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK, yamlName);
return responseFormat;
}
- Iterator<Entry<String, List<UploadReqInfo>>> nodesRegValue = regMap.entrySet().iterator();
-
- long startAddRelation = System.currentTimeMillis();
-
- while (nodesRegValue.hasNext()) {
- Entry<String, List<UploadReqInfo>> nodesRegInfoEntry = nodesRegValue.next();
-
- List<UploadReqInfo> uploadRegInfoList = nodesRegInfoEntry.getValue();
- for (UploadReqInfo uploadRegInfo : uploadRegInfoList) {
- log.debug("Going to create relation {}", uploadRegInfo.getName());
- String regName = uploadRegInfo.getName();
- String nodeCapName = uploadRegInfo.getNode();
- RequirementCapabilityRelDef regCapRelDef = new RequirementCapabilityRelDef();
- regCapRelDef.setFromNode(resourceInstanceId);
- log.debug("try to find available requirement {} ", regName);
- Either<RequirementDefinition, ResponseFormat> eitherReqStatus = findAviableRequiremen(regName, yamlName, uploadComponentInstanceInfo, currentCompInstance, uploadRegInfo.getCapabilityName());
- if (eitherReqStatus.isRight()) {
- log.debug("failed to find available requirement {} status is {}", regName, eitherReqStatus.right().value());
- return eitherReqStatus.right().value();
- }
-
- RequirementDefinition validReq = eitherReqStatus.left().value();
- List<RequirementAndRelationshipPair> reqAndRelationshipPairList = regCapRelDef.getRelationships();
- if (reqAndRelationshipPairList == null)
- reqAndRelationshipPairList = new ArrayList<RequirementAndRelationshipPair>();
- RequirementAndRelationshipPair reqAndRelationshipPair = new RequirementAndRelationshipPair();
- reqAndRelationshipPair.setRequirement(regName);
- reqAndRelationshipPair.setRequirementOwnerId(validReq.getOwnerId());
- reqAndRelationshipPair.setRequirementUid(validReq.getUniqueId());
- RelationshipImpl relationship = new RelationshipImpl();
- relationship.setType(validReq.getCapability());
- reqAndRelationshipPair.setRelationships(relationship);
-
- ComponentInstance currentCapCompInstance = null;
- for (ComponentInstance compInstance : componentInstancesList) {
- if (compInstance.getName().equals(uploadRegInfo.getNode())) {
- currentCapCompInstance = compInstance;
- break;
- }
+ return componentsUtils.getResponseFormat(ActionStatus.OK);
+ }
+
+ private ResponseFormat addInputsValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo, Resource resource, Resource originResource, ComponentInstance currentCompInstance, String yamlName,
+ Map<String, List<ComponentInstanceInput>> instInputs, Map<String, DataTypeDefinition> allDataTypes) {
+ Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
+ if (propMap != null && propMap.size() > 0) {
+ Map<String, InputDefinition> currPropertiesMap = new HashMap<String, InputDefinition>();
+
+ List<InputDefinition> listFromMap = originResource.getInputs();
+ if (listFromMap == null || listFromMap.isEmpty()) {
+ log.debug("failed to find properties ");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND);
+ return responseFormat;
+ }
+ for (InputDefinition prop : listFromMap) {
+ String propName = prop.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ currPropertiesMap.put(propName, prop);
}
+ }
+ List<ComponentInstanceInput> instPropList = new ArrayList<>();
+ for (List<UploadPropInfo> propertyList : propMap.values()) {
- if (currentCapCompInstance == null) {
- log.debug("component instance with name {} in resource {} ", uploadRegInfo.getNode(), resource.getUniqueId());
- BeEcompErrorManager.getInstance().logInternalDataError("component instance with name " + uploadRegInfo.getNode() + " in resource {} ", resource.getUniqueId(), ErrorSeverity.ERROR);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ UploadPropInfo propertyInfo = propertyList.get(0);
+ String propName = propertyInfo.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ log.debug("failed to find property {} ", propName);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, propName);
return responseFormat;
}
- regCapRelDef.setToNode(currentCapCompInstance.getUniqueId());
- log.debug("try to find aviable Capability req name is {} ", validReq.getName());
- CapabilityDefinition aviableCapForRel = findAvailableCapabilityByTypeOrName(validReq, currentCapCompInstance, uploadRegInfo);
- if (aviableCapForRel == null) {
- log.debug("aviable capability was not found. req name is {} component instance is {}", validReq.getName(), currentCapCompInstance.getUniqueId());
- BeEcompErrorManager.getInstance().logInternalDataError("aviable capability was not found. req name is " + validReq.getName() + " component instance is " + currentCapCompInstance.getUniqueId(), resource.getUniqueId(),
- ErrorSeverity.ERROR);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- return responseFormat;
+ InputDefinition curPropertyDef = currPropertiesMap.get(propName);
+ ComponentInstanceInput property = null;
+
+ 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(), curPropertyDef.getType());
+ } else
+ value = ImportUtils.getPropertyJsonStringValue(propertyInfo.getValue(), ToscaTagNamesEnum.GET_INPUT.getElementName());
}
- reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
- reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
- reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
- reqAndRelationshipPairList.add(reqAndRelationshipPair);
- regCapRelDef.setRelationships(reqAndRelationshipPairList);
- relations.add(regCapRelDef);
+ String innerType = null;
+ property = new ComponentInstanceInput(curPropertyDef, value, null);
- }
+ Either<String, StorageOperationStatus> validatevalueEiter = validatePropValueBeforeCreate(property, value, isValidate, innerType, allDataTypes);
+ if (validatevalueEiter.isRight()) {
+ return componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(validatevalueEiter.right().value()));
+ }
- }
- totalCreateRel += (System.currentTimeMillis() - startAddRelation);
+ // String uniqueId = UniqueIdBuilder.buildResourceInstancePropertyValueUid(currentCompInstance.getComponentUid(), index++);
+ // property.setUniqueId(uniqueId);
+ property.setValue(validatevalueEiter.left().value());
+
+ if (getInputs != null && !getInputs.isEmpty()) {
+ List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
+ for (GetInputValueDataDefinition getInput : getInputs) {
+ List<InputDefinition> inputs = resource.getInputs();
+ if (inputs == null || inputs.isEmpty()) {
+ log.debug("Failed to add property {} to resource instance {}. Inputs list is empty ", property, currentCompInstance.getUniqueId());
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ }
+
+ Optional<InputDefinition> optional = inputs.stream().filter(p -> p.getName().equals(getInput.getInputName())).findAny();
+ if (!optional.isPresent()) {
+ log.debug("Failed to find input {} ", getInput.getInputName());
+ // @@TODO error message
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ }
+ InputDefinition input = optional.get();
+ getInput.setInputId(input.getUniqueId());
+ getInputValues.add(getInput);
+ GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
+ if (getInputIndex != null) {
+ optional = inputs.stream().filter(p -> p.getName().equals(getInputIndex.getInputName())).findAny();
+ if (!optional.isPresent()) {
+ log.debug("Failed to find input {} ", getInputIndex.getInputName());
+ // @@TODO error message
+ return componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ }
+ InputDefinition inputIndex = optional.get();
+ getInputIndex.setInputId(inputIndex.getUniqueId());
+ getInputValues.add(getInputIndex);
+ }
+ }
+ property.setGetInputValues(getInputValues);
+ }
+ instPropList.add(property);
+ // delete overriden property
+ currPropertiesMap.remove(property.getName());
+ }
+ // add rest of properties
+ if (!currPropertiesMap.isEmpty()) {
+ for (InputDefinition value : currPropertiesMap.values()) {
+ instPropList.add(new ComponentInstanceInput(value));
+ }
+ }
+ instInputs.put(currentCompInstance.getUniqueId(), instPropList);
+ }
return componentsUtils.getResponseFormat(ActionStatus.OK);
}
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>();
- int index = 0;
List<PropertyDefinition> listFromMap = originResource.getProperties();
if (listFromMap == null || listFromMap.isEmpty()) {
log.debug("failed to find properties ");
@@ -3845,14 +4103,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return cap;
}
- private RequirementAndRelationshipPair getReqRelPair(CapabilityDefinition cap) {
- RequirementAndRelationshipPair relationPair = new RequirementAndRelationshipPair();
- relationPair.setCapabilityUid(cap.getUniqueId());
- relationPair.setCapability(cap.getName());
- relationPair.setCapabilityOwnerId(cap.getOwnerId());
- return relationPair;
- }
-
private CapabilityDefinition findAviableCapability(RequirementDefinition validReq, ComponentInstance currentCapCompInstance) {
CapabilityDefinition aviableCapForRel = null;
Map<String, List<CapabilityDefinition>> capMap = currentCapCompInstance.getCapabilities();
@@ -3955,9 +4205,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
@SuppressWarnings("unchecked")
- public Either<ParsedToscaYamlInfo, ResponseFormat> parseResourceInfoFromYaml(String yamlFileName, Resource resource, String resourceYml, User user) {
+ public Either<ParsedToscaYamlInfo, ResponseFormat> parseResourceInfoFromYaml(String yamlFileName, Resource resource, String resourceYml, User user, Map<String, String> createdNodesToscaResourceNames, Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName) {
- Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(resourceYml);
+ Map<String, Object> mappedToscaTemplate;
+ if(nodeTypesInfo != null && nodeName != null && nodeTypesInfo.containsKey(nodeName)){
+ mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate();
+ }
+ else {
+ mappedToscaTemplate = (Map<String, Object>) new Yaml().load(resourceYml);
+ }
Either<Object, ResultStatusEnum> toscaElementEither = ImportUtils.findToscaElement(mappedToscaTemplate, ToscaTagNamesEnum.TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL);
if (toscaElementEither.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
@@ -3970,7 +4226,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(responseFormat);
}
- Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> uploadResInstancesEither = createResourcesInstanceInfoFromYaml(yamlFileName, mappedToscaTemplate, resource);
+ Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> uploadResInstancesEither = createResourcesInstanceInfoFromYaml(yamlFileName, mappedToscaTemplate, resource, createdNodesToscaResourceNames);
if (uploadResInstancesEither.isRight()) {
ResponseFormat responseFormat = uploadResInstancesEither.right().value();
return Either.right(responseFormat);
@@ -3991,7 +4247,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<Resource, ResponseFormat> createResourceInstances(User user, String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, boolean inTransaction, boolean needLock,
- Map<String, Resource> nodeTypeNamespaceMap) {
+ Map<String, Resource> nodeNamespaceMap) {
Either<Resource, ResponseFormat> eitherResource = null;
log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
@@ -4002,8 +4258,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
Map<String, Resource> existingnodeTypeMap = new HashMap<>();
- if (nodeTypeNamespaceMap != null && !nodeTypeNamespaceMap.isEmpty()) {
- nodeTypeNamespaceMap.entrySet().stream().forEach(x -> existingnodeTypeMap.put(x.getValue().getToscaResourceName(), x.getValue()));
+ if (nodeNamespaceMap != null && !nodeNamespaceMap.isEmpty()) {
+ nodeNamespaceMap.entrySet().stream().forEach(x -> existingnodeTypeMap.put(x.getValue().getToscaResourceName(), x.getValue()));
}
Iterator<Entry<String, UploadComponentInstanceInfo>> nodesInfoValue = uploadResInstancesMap.entrySet().iterator();
@@ -4016,8 +4272,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// updating type if the type is node type name - we need to take the
// updated name
log.debug("*************Going to create resource instances {}", uploadComponentInstanceInfo.getName());
- if (nodeTypeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
- uploadComponentInstanceInfo.setType(nodeTypeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
+ if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ uploadComponentInstanceInfo.setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
}
eitherResource = validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, existingnodeTypeMap);
@@ -4093,11 +4349,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(eitherGerResource.left().value());
}
- private Either<Resource, ResponseFormat> validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo, Map<String, Resource> nodeTypeNamespaceMap) {
+ private Either<Resource, ResponseFormat> validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo, Map<String, Resource> nodeNamespaceMap) {
log.debug("validateResourceInstanceBeforeCreate - going to validate resource instance with name {} and type before create", uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
Resource refResource = null;
- if (nodeTypeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
- refResource = nodeTypeNamespaceMap.get(uploadComponentInstanceInfo.getType());
+ if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType());
} else {
Either<Resource, StorageOperationStatus> findResourceEither = toscaOperationFacade.getLatestCertifiedNodeTypeByToscaResourceName(uploadComponentInstanceInfo.getType());
if (findResourceEither.isRight()) {
@@ -4106,7 +4362,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(responseFormat);
}
refResource = findResourceEither.left().value();
- nodeTypeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
+ nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
}
String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState();
if (componentState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
@@ -4114,32 +4370,36 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE, refResource.getComponentType().getValue(), refResource.getName(), componentState);
return Either.right(responseFormat);
}
- ResourceTypeEnum resourceTypeEnum = refResource.getResourceType();
- if (resourceTypeEnum == ResourceTypeEnum.VF) {
- log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", resourceTypeEnum);
+
+ if (!ToscaUtils.isAtomicType(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);
}
return Either.left(refResource);
}
- private Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> createResourcesInstanceInfoFromYaml(String yamlFileName, Map<String, Object> toscaJson, Resource resource) {
+ private Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> createResourcesInstanceInfoFromYaml(String yamlFileName, Map<String, Object> toscaJson, Resource resource, Map<String, String> createdNodesToscaResourceNames) {
Map<String, UploadComponentInstanceInfo> moduleComponentInstances = new HashMap<String, UploadComponentInstanceInfo>();
+ Map<String, Object> substitutionMappings = null;
Either<Map<String, UploadComponentInstanceInfo>, ResponseFormat> result = Either.left(moduleComponentInstances);
Either<Map<String, Object>, ResultStatusEnum> eitherNodesTemlates = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.NODE_TEMPLATES);
+ Either<Map<String, Object>, ResultStatusEnum> eitherSubstitutionMappings = ImportUtils.findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS);
+ if (eitherSubstitutionMappings.isLeft()) {
+ substitutionMappings = eitherSubstitutionMappings.left().value();
+ }
if (eitherNodesTemlates.isLeft()) {
Map<String, Object> jsonNodeTemplates = eitherNodesTemlates.left().value();
Iterator<Entry<String, Object>> nodesNameValue = jsonNodeTemplates.entrySet().iterator();
while (nodesNameValue.hasNext()) {
Entry<String, Object> nodeNameValue = nodesNameValue.next();
- Either<UploadComponentInstanceInfo, ResponseFormat> eitherNode = createModuleComponentInstanceInfo(nodeNameValue.getValue());
+ Either<UploadComponentInstanceInfo, ResponseFormat> eitherNode = createModuleComponentInstanceInfo(nodeNameValue, substitutionMappings, createdNodesToscaResourceNames);
if (eitherNode.isRight()) {
log.info("error when creating node template:{}, for resource:{}", nodeNameValue.getKey(), resource.getName());
return Either.right(eitherNode.right().value());
} else {
UploadComponentInstanceInfo uploadComponentInstanceInfo = eitherNode.left().value();
- uploadComponentInstanceInfo.setName(nodeNameValue.getKey());
moduleComponentInstances.put(nodeNameValue.getKey(), uploadComponentInstanceInfo);
}
@@ -4154,20 +4414,25 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
- private Either<UploadComponentInstanceInfo, ResponseFormat> createModuleComponentInstanceInfo(Object nodeTemplateJson) {
+ @SuppressWarnings("unchecked")
+ private Either<UploadComponentInstanceInfo, ResponseFormat> createModuleComponentInstanceInfo(Entry<String, Object> nodeTemplateJsonEntry, Map<String, Object> substitutionMappings, Map<String, String> createdNodesToscaResourceNames) {
UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
Either<UploadComponentInstanceInfo, ResponseFormat> result = Either.left(nodeTemplateInfo);
-
+ nodeTemplateInfo.setName(nodeTemplateJsonEntry.getKey());
try {
- if (nodeTemplateJson instanceof String) {
- String nodeTemplateJsonString = (String) nodeTemplateJson;
+ if (nodeTemplateJsonEntry.getValue() instanceof String) {
+ String nodeTemplateJsonString = (String) nodeTemplateJsonEntry.getValue();
nodeTemplateInfo.setType(nodeTemplateJsonString);
- } else if (nodeTemplateJson instanceof Map) {
- Map<String, Object> nodeTemplateJsonMap = (Map<String, Object>) nodeTemplateJson;
+ } else if (nodeTemplateJsonEntry.getValue() instanceof Map) {
+ Map<String, Object> nodeTemplateJsonMap = (Map<String, Object>) nodeTemplateJsonEntry.getValue();
// Type
if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.TYPE.getElementName())) {
- nodeTemplateInfo.setType((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName()));
+ String toscaResourceType = (String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.TYPE.getElementName());
+ if (createdNodesToscaResourceNames.containsKey(toscaResourceType)) {
+ toscaResourceType = createdNodesToscaResourceNames.get(toscaResourceType);
+ }
+ nodeTemplateInfo.setType(toscaResourceType);
}
if (nodeTemplateJsonMap.containsKey(ToscaTagNamesEnum.REQUIREMENTS.getElementName())) {
@@ -4195,13 +4460,30 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
nodeTemplateInfo.setProperties(regResponse.left().value());
}
}
+ if (substitutionMappings != null) {
+ if (substitutionMappings.containsKey(ToscaTagNamesEnum.CAPABILITIES.getElementName())) {
+ Either<Map<String, String>, ResponseFormat> getCapNamesToUpdateRes = getNamesToUpdate(nodeTemplateInfo, (Map<String, List<String>>) substitutionMappings.get(ToscaTagNamesEnum.CAPABILITIES.getElementName()));
+ if (getCapNamesToUpdateRes.isRight())
+ return Either.right(getCapNamesToUpdateRes.right().value());
+ if (getCapNamesToUpdateRes.left().value().size() > 0) {
+ nodeTemplateInfo.setCapabilitiesNamesToUpdate(getCapNamesToUpdateRes.left().value());
+ }
+ }
+ if (substitutionMappings.containsKey(ToscaTagNamesEnum.REQUIREMENTS.getElementName())) {
+ Either<Map<String, String>, ResponseFormat> getReqNamesToUpdateRes = getNamesToUpdate(nodeTemplateInfo, (Map<String, List<String>>) substitutionMappings.get(ToscaTagNamesEnum.REQUIREMENTS.getElementName()));
+ if (getReqNamesToUpdateRes.isRight())
+ return Either.right(getReqNamesToUpdateRes.right().value());
+ if (getReqNamesToUpdateRes.left().value().size() > 0) {
+ nodeTemplateInfo.setRequirementsNamesToUpdate(getReqNamesToUpdateRes.left().value());
+ }
+ }
+ }
} else {
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
}
} catch (Exception e) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Import Resource - create capability");
BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create capability");
log.debug("error when creating capability, message:{}", e.getMessage(), e);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
@@ -4210,6 +4492,19 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
+ private Either<Map<String, String>, ResponseFormat> getNamesToUpdate(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, List<String>> elements) {
+ Either<Map<String, String>, ResponseFormat> response;
+ try {
+ Map<String, String> namesToUpdate = elements.entrySet().stream().filter(e -> e.getValue().get(0).equalsIgnoreCase(nodeTemplateInfo.getName())).collect(Collectors.toMap(e -> e.getValue().get(1), e -> e.getKey()));
+ response = Either.left(namesToUpdate);
+ } catch (Exception e) {
+ log.debug("The exception {} occured upon adding names to update for instance {} . ", e.getMessage(), nodeTemplateInfo.getName());
+ response = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return response;
+ }
+
+ @SuppressWarnings("unchecked")
private Either<Map<String, List<UploadPropInfo>>, ResponseFormat> createPropModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadPropInfo>> moduleProp = new HashMap<String, List<UploadPropInfo>>();
Either<Map<String, List<UploadPropInfo>>, ResponseFormat> response = Either.left(moduleProp);
@@ -4222,21 +4517,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Object propValue = jsonPropObj.getValue();
if (valueContainsPattern(STR_REPLACE_PATTERN, propValue)) {
- log.debug("Ignore property value {}.", propName);
+ log.trace("Ignore property value {}.", propName);
continue;
}
if (valueContainsPattern(TOKEN_PATTERN, propValue)) {
- log.debug("Ignore property value {}.", propName);
+ log.trace("Ignore property value {}.", propName);
continue;
}
if (valueContainsPattern(GET_PROPERTY_PATTERN, propValue)) {
- log.debug("Ignore property value {}.", propName);
+ log.trace("Ignore property value {}.", propName);
continue;
}
if (valueContainsPattern(CONCAT_PATTERN, propValue)) {
- log.debug("Ignore property value {}.", propName);
+ log.trace("Ignore property value {}.", propName);
continue;
}
@@ -4283,6 +4578,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return response;
}
+ @SuppressWarnings("unchecked")
private void createInputPropList(UploadPropInfo propertyDef, List<Object> propValueList) {
for (Object objValue : propValueList) {
@@ -4316,6 +4612,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
+ @SuppressWarnings("unchecked")
private void createGetInputModuleFromMap(String propName, Map<String, Object> propValue, UploadPropInfo propertyDef) {
if (propValue.containsKey(ToscaTagNamesEnum.GET_INPUT.getElementName())) {
@@ -4399,7 +4696,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
log.debug("valueContainsToken value is {}", propValue);
boolean result = false;
if (propValue != null) {
- log.debug("valueContainspattern value is {}", propValue.getClass());
+ log.trace("valueContainspattern value is {}", propValue.getClass());
Matcher matcher = pattern.matcher(propValue.toString());
result = matcher.find();
}
@@ -4408,6 +4705,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
+ @SuppressWarnings("unchecked")
private Either<Map<String, List<UploadCapInfo>>, ResponseFormat> createCapModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadCapInfo>> moduleCap = new HashMap<String, List<UploadCapInfo>>();
Either<Map<String, List<UploadCapInfo>>, ResponseFormat> response = Either.left(moduleCap);
@@ -4433,15 +4731,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
list.add(requirementDef);
moduleCap.put(capName, list);
}
-
}
}
-
}
-
return response;
}
+ @SuppressWarnings("unchecked")
private Either<Map<String, List<UploadReqInfo>>, ResponseFormat> createReqModuleFromYaml(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<String, List<UploadReqInfo>>();
Either<Map<String, List<UploadReqInfo>>, ResponseFormat> response = Either.left(moduleRequirements);
@@ -4467,14 +4763,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
list.add(requirementDef);
moduleRequirements.put(requirementName, list);
}
-
}
}
-
}
return response;
}
+ @SuppressWarnings("unchecked")
private Either<UploadCapInfo, ResponseFormat> createModuleNodeTemplateCap(Object capObject) {
UploadCapInfo capTemplateInfo = new UploadCapInfo();
Either<UploadCapInfo, ResponseFormat> result = Either.left(capTemplateInfo);
@@ -4509,10 +4804,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
}
-
return result;
}
+ @SuppressWarnings("unchecked")
private Either<UploadReqInfo, ResponseFormat> createModuleNodeTemplateReg(Object regObject) {
UploadReqInfo regTemplateInfo = new UploadReqInfo();
@@ -4532,33 +4827,31 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
regTemplateInfo.setCapabilityName((String) nodeTemplateJsonMap.get(ToscaTagNamesEnum.CAPABILITY.getElementName()));
}
}
-
return result;
}
- public Either<Resource, ResponseFormat> propagateStateToCertified(User user, Resource resource, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ public Either<Resource, ResponseFormat> propagateStateToCertified(User user, Resource resource, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock, boolean forceCertificationAllowed) {
+
Either<Resource, ResponseFormat> result = null;
-
- // resource updated with checkout. certify the resource
- if (resource.getLifecycleState().equals(LifecycleStateEnum.CERTIFIED)) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherPopulated = populateToscaArtifacts(resource, user, false, inTransaction, needLock);
- result = eitherPopulated.isLeft() ? Either.left(resource) : Either.right(eitherPopulated.right().value());
- return result;
- }
try {
- result = lifecycleBusinessLogic.changeState(resource.getUniqueId(), user, LifeCycleTransitionEnum.CERTIFICATION_REQUEST, lifecycleChangeInfo, inTransaction, needLock);
- if (result.isLeft()) {
+ if(resource.getLifecycleState() != LifecycleStateEnum.CERTIFIED && forceCertificationAllowed){
+ result = nodeForceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock);
+ if(result.isRight()){
+ return result;
+ }
resource = result.left().value();
- result = lifecycleBusinessLogic.changeState(resource.getUniqueId(), user, LifeCycleTransitionEnum.START_CERTIFICATION, lifecycleChangeInfo, inTransaction, needLock);
}
- if (result.isLeft()) {
- resource = result.left().value();
- result = lifecycleBusinessLogic.changeState(resource.getUniqueId(), user, LifeCycleTransitionEnum.CERTIFY, lifecycleChangeInfo, inTransaction, needLock);
+ if (resource.getLifecycleState() == LifecycleStateEnum.CERTIFIED) {
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherPopulated = populateToscaArtifacts(resource, user, false, inTransaction, needLock);
+ result = eitherPopulated.isLeft() ? Either.left(resource) : Either.right(eitherPopulated.right().value());
+ return result;
}
- return result;
+ return nodeFullCertification(resource.getUniqueId(), user, lifecycleChangeInfo, inTransaction, needLock);
+ } catch (Exception e) {
+ log.debug("The exception {} has occured upon certification of resource {}. ", e.getMessage(), resource.getName());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
if (result == null || result.isRight()) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Change LifecycleState - Certify");
BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
if (inTransaction == false) {
log.debug("operation failed. do rollback");
@@ -4571,6 +4864,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
+ private Either<Resource, ResponseFormat> nodeFullCertification(String uniqueId, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ Either<Resource, ResponseFormat> result = lifecycleBusinessLogic.changeState(uniqueId, user, LifeCycleTransitionEnum.CERTIFICATION_REQUEST, lifecycleChangeInfo, inTransaction, needLock);
+ if (result.isLeft()) {
+ result = lifecycleBusinessLogic.changeState(uniqueId, user, LifeCycleTransitionEnum.START_CERTIFICATION, lifecycleChangeInfo, inTransaction, needLock);
+ }
+ if (result.isLeft()) {
+ result = lifecycleBusinessLogic.changeState(uniqueId, user, LifeCycleTransitionEnum.CERTIFY, lifecycleChangeInfo, inTransaction, needLock);
+ }
+ return result;
+ }
+
+ private Either<Resource, ResponseFormat> nodeForceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ return lifecycleBusinessLogic.forceResourceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock);
+ }
+
/*
* /**
*
@@ -4581,7 +4889,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
* createOrUpdateResourceByImport(resource, user, isNormative, false, needLock); }
*/
- public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock) {
+ public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock, CsarInfo csarInfo) {
// check if resource already exist
Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resource.getName());
@@ -4592,11 +4900,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Either<Resource, StorageOperationStatus> latestByToscaName = toscaOperationFacade.getLatestByToscaResourceName(resource.getToscaResourceName());
if (latestByToscaName.isRight() && latestByToscaName.right().value().equals(StorageOperationStatus.NOT_FOUND))
- result = createResourceByImport(resource, user, isNormative, isInTransaction);
+ result = createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo);
else {
StorageOperationStatus status = latestByName.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "Create / Update resource by import", resource.getName());
BeEcompErrorManager.getInstance().logBeComponentMissingError("Create / Update resource by import", ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
log.debug("resource already exist {}. status={}", resource.getName(), status);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_ALREADY_EXISTS);
@@ -4614,7 +4921,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// error
else {
StorageOperationStatus status = latestByName.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "Create / Update resource by import", resource.getName());
log.debug("failed to get latest version of resource {}. status={}", resource.getName(), status);
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(latestByName.right().value()), resource);
componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
@@ -4624,9 +4930,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
- private Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction) {
+ private Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createResourceByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, CsarInfo csarInfo) {
log.debug("resource with name {} does not exist. create new resource", resource.getName());
- Either<Resource, ResponseFormat> response = validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isInTransaction);
+ Either<Resource, ResponseFormat> response = validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isInTransaction, csarInfo);
if (response.isRight()) {
return Either.right(response.right().value());
}
@@ -4726,7 +5032,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
} finally {
if (result == null || result.isRight()) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeSystemError, "Change LifecycleState - Certify");
BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
log.debug("operation failed. do rollback");
titanDao.rollback();
@@ -4764,6 +5069,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
newResource.setVendorRelease(oldResource.getVendorRelease());
}
+ if (newResource.getResourceVendorModelNumber() == null) {
+ newResource.setResourceVendorModelNumber(oldResource.getResourceVendorModelNumber());
+ }
+
if (newResource.getContactId() == null) {
newResource.setContactId(oldResource.getContactId());
}
@@ -4785,7 +5094,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
- public Either<Resource, ResponseFormat> validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction) {
+ public Either<Resource, ResponseFormat> validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction, CsarInfo csarInfo) {
Either<Boolean, ResponseFormat> eitherValidation = validateResourceFieldsBeforeCreate(user, resource, actionEnum, inTransaction);
if (eitherValidation.isRight()) {
@@ -4808,12 +5117,19 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resource.setCreatorUserId(user.getUserId());
resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
resource.setContactId(resource.getContactId().toLowerCase());
- if (resource.getResourceType().equals(ResourceTypeEnum.VF)) {
- resource.setToscaResourceName(CommonBeUtils.generateToscaResourceName(ResourceTypeEnum.VF.name(), resource.getSystemName()));
+ if (StringUtils.isEmpty(resource.getToscaResourceName()) && !ToscaUtils.isAtomicType(resource)) {
+ String resourceSystemName;
+ if(csarInfo != null && StringUtils.isNotEmpty(csarInfo.getVfResourceName())){
+ resourceSystemName = ValidationUtils.convertToSystemName(csarInfo.getVfResourceName());
+ } else {
+ resourceSystemName = resource.getSystemName();
+ }
+ resource.setToscaResourceName(CommonBeUtils.generateToscaResourceName(resource.getResourceType().name().toLowerCase(), resourceSystemName));
}
// Generate invariant UUID - must be here and not in operation since it
// should stay constant during clone
+ // TODO
String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
resource.setInvariantUUID(invariantUUID);
@@ -4842,10 +5158,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Either<InterfaceDefinition, StorageOperationStatus> eitherCapTypeFound = interfaceTypeOperation.getInterface(intType);
if (eitherCapTypeFound.isRight()) {
if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeInterfaceMissingError, "Create Resource - validateLifecycleTypesCreate", intType);
BeEcompErrorManager.getInstance().logBeGraphObjectMissingError("Create Resource - validateLifecycleTypesCreate", "Interface", intType);
log.debug("Lifecycle Type: {} is required by resource: {} but does not exist in the DB", intType, resource.getName());
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateLifecycleTypesCreate");
BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateLifecycleTypesCreate");
log.debug("request to data model failed with error: {}", eitherCapTypeFound.right().value().name());
}
@@ -4878,7 +5192,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (resource.getRequirements() != null && resource.getRequirements().size() > 0) {
log.debug("validate capability Types Exist - requirements section");
for (String type : resource.getRequirements().keySet()) {
- eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource, resource.getRequirements().get(type) , actionEnum, eitherResult, type, inTransaction);
+ eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource, resource.getRequirements().get(type), actionEnum, eitherResult, type, inTransaction);
if (eitherResult.isRight()) {
return Either.right(eitherResult.right().value());
}
@@ -4888,24 +5202,22 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return eitherResult;
}
- //@param typeObject- the object to which the validation is done
- private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user, ICapabilityTypeOperation capabilityTypeOperation, Resource resource, List validationObjects , AuditingActionEnum actionEnum, Either<Boolean, ResponseFormat> eitherResult, String type,
- boolean inTransaction) {
+ // @param typeObject- the object to which the validation is done
+ private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user, ICapabilityTypeOperation capabilityTypeOperation, Resource resource, List<?> validationObjects, AuditingActionEnum actionEnum, Either<Boolean, ResponseFormat> eitherResult, String type,
+ boolean inTransaction) {
Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(type, inTransaction);
if (eitherCapTypeFound.isRight()) {
if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeCapabilityTypeMissingError, "Create Resource - validateCapabilityTypesCreate", type);
BeEcompErrorManager.getInstance().logBeGraphObjectMissingError("Create Resource - validateCapabilityTypesCreate", "Capability Type", type);
log.debug("Capability Type: {} is required by resource: {} but does not exist in the DB", type, resource.getName());
BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateCapabilityTypesCreate");
}
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateCapabilityTypesCreate");
log.debug("Trying to get capability type {} failed with error: {}", type, eitherCapTypeFound.right().value().name());
- ResponseFormat errorResponse =null;
- if (type!=null)
+ ResponseFormat errorResponse = null;
+ if (type != null)
errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, type);
else
- errorResponse = componentsUtils.getResponseFormatByElement(ActionStatus.MISSING_CAPABILITY_TYPE, validationObjects );
+ errorResponse = componentsUtils.getResponseFormatByElement(ActionStatus.MISSING_CAPABILITY_TYPE, validationObjects);
eitherResult = Either.right(errorResponse);
componentsUtils.auditResource(errorResponse, user, resource, "", "", actionEnum, null);
}
@@ -4913,16 +5225,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user, ICapabilityTypeOperation capabilityTypeOperation, Resource resource, AuditingActionEnum actionEnum, Either<Boolean, ResponseFormat> eitherResult,
- Entry<String, List<CapabilityDefinition>> typeEntry, boolean inTransaction) {
+ Entry<String, List<CapabilityDefinition>> typeEntry, boolean inTransaction) {
Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(typeEntry.getKey(), inTransaction);
if (eitherCapTypeFound.isRight()) {
if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeCapabilityTypeMissingError, "Create Resource - validateCapabilityTypesCreate", typeEntry.getKey());
BeEcompErrorManager.getInstance().logBeGraphObjectMissingError("Create Resource - validateCapabilityTypesCreate", "Capability Type", typeEntry.getKey());
log.debug("Capability Type: {} is required by resource: {} but does not exist in the DB", typeEntry.getKey(), resource.getName());
BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateCapabilityTypesCreate");
}
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateCapabilityTypesCreate");
log.debug("Trying to get capability type {} failed with error: {}", typeEntry.getKey(), eitherCapTypeFound.right().value().name());
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, typeEntry.getKey());
eitherResult = Either.right(errorResponse);
@@ -4985,8 +5295,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Either<Resource, ResponseFormat> respStatus = createResourceTransaction(resource, user, isNormative, inTransaction);
if (respStatus.isLeft()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
- componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, additionalParams);
+ auditCreateResource(user, respStatus.left().value(), actionEnum, additionalParams);
ASDCKpiApi.countCreatedResourcesKPI();
} else
componentsUtils.auditResource(respStatus.right().value(), user, resource, "", "", actionEnum, additionalParams);
@@ -4999,6 +5308,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
+ private void auditCreateResource(User user, Resource persistedResource, AuditingActionEnum actionEnum, EnumMap<AuditingFieldsKeysEnum, Object> additionalParams) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditResource(responseFormat, user, persistedResource, "", "", actionEnum, additionalParams);
+ }
+
private Either<Resource, ResponseFormat> createResourceTransaction(Resource resource, User user, boolean isNormative, boolean inTransaction) {
// validate resource name uniqueness
log.debug("validate resource name");
@@ -5026,7 +5340,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setVersion(INITIAL_VERSION);
resource.setHighestVersion(true);
- resource.setAbstract(false);
+ if (resource.getResourceType() != null && resource.getResourceType() != ResourceTypeEnum.CVFC)
+ resource.setAbstract(false);
}
Either<Resource, StorageOperationStatus> createToscaElement = toscaOperationFacade.createToscaComponent(resource);
@@ -5090,6 +5405,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resource.setDeploymentArtifacts(artifactMap);
}
+ @SuppressWarnings("unchecked")
private void setInformationalArtifactsPlaceHolder(Resource resource, User user) {
Map<String, ArtifactDefinition> artifactMap = resource.getArtifacts();
if (artifactMap == null) {
@@ -5097,6 +5413,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
String resourceUniqueId = resource.getUniqueId();
List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager().getConfiguration().getExcludeResourceCategory();
+ List<String> exludeResourceType = ConfigurationManager.getConfigurationManager().getConfiguration().getExcludeResourceType();
Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getInformationalResourceArtifacts();
List<CategoryDefinition> categories = resource.getCategories();
boolean isCreateArtifact = true;
@@ -5110,6 +5427,16 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
+ if (isCreateArtifact && exludeResourceType != null) {
+ String resourceType = resource.getResourceType().name();
+ for (String type : exludeResourceType) {
+ if (type.equalsIgnoreCase(resourceType)) {
+ isCreateArtifact = false;
+ break;
+ }
+ }
+
+ }
if (informationalResourceArtifacts != null && isCreateArtifact) {
Set<String> keys = informationalResourceArtifacts.keySet();
@@ -5273,14 +5600,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
/**
* updateResourceMetadata
*
- * @param user
- * - modifier data (userId)
- * @param inTransaction
- * TODO
- * @param resourceIdToUpdate
- * - the resource identifier
+ * @param user - modifier data (userId)
+ * @param inTransaction TODO
+ * @param resourceIdToUpdate - the resource identifier
* @param newResource
- *
* @return Either<Resource, responseFormat>
*/
public Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource, Resource currentResource, User user, boolean inTransaction) {
@@ -5315,7 +5638,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// lock resource
StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceIdToUpdate, NodeTypeEnum.Resource);
if (!lockResult.equals(StorageOperationStatus.OK)) {
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeFailedLockObjectError, "Upload Artifact - lock " + resourceIdToUpdate + ": " + NodeTypeEnum.Resource);
BeEcompErrorManager.getInstance().logBeFailedLockObjectError("Upload Artifact - lock ", NodeTypeEnum.Resource.getName(), resourceIdToUpdate);
log.debug("Failed to lock resource: {}, error - {}", resourceIdToUpdate, lockResult);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockResult));
@@ -5331,7 +5653,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 (!currentResource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ if (ToscaUtils.isAtomicType(currentResource)) {
Either<Boolean, ResponseFormat> derivedFromNotEmptyEither = validateDerivedFromNotEmpty(null, newResource, null);
if (derivedFromNotEmptyEither.isRight()) {
log.debug("for updated resource {}, derived from field is empty", newResource.getName());
@@ -5373,7 +5695,54 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
+ private Either<List<GroupDefinition>,Boolean> updateComponentGroupName(String replacePattern , String with ,List<GroupDefinition> oldGroup){
+ if ( oldGroup==null || with==null || replacePattern==null || with.isEmpty() || replacePattern.isEmpty()){
+ if (log.isInfoEnabled())
+ log.info("cannot update group name , invalid args -> replacePattern:{} , with:{} , oldGroup:{}" , replacePattern, with, oldGroup == null ? null : " < size : "+oldGroup.size()+" >" );
+ return Either.right(false);
+ }
+ List<GroupDefinition> list = oldGroup.stream().map( group -> new GroupDefinition(group)).collect(Collectors.toList());
+ for ( GroupDefinition group : list) {
+ if ( group!=null && group.isSamePrefix( replacePattern ) ){
+ String prefix = group.getName().substring( 0, replacePattern.length() );
+ String newGroupName = group.getName().replaceFirst(prefix , with);
+ group.setName(newGroupName);
+ //String newUid = group.getUniqueId().replaceFirst(prefix , with); //removing this will also change the unique id
+ //group.setUniqueId(newUid);
+ }
+ }
+ return Either.left(list);
+ }
+
+ private boolean isComponentNameChanged(Resource newResource,Resource oldResource){
+ if (newResource!=null && oldResource!=null){ //TODO - must protect all chain against null , use optional
+ String futureName = newResource.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ String oldName = oldResource.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
+ return !oldName.equals(futureName);
+ }
+ return false;
+ }
+
private Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource, User user, Resource currentResource, boolean shouldLock, boolean inTransaction) {
+ //region -> Update groups name for newResource
+ if ( isComponentNameChanged( currentResource , newResource) ){
+ String replacePattern = Optional.ofNullable( //get currentResource name from metadata
+ Optional.ofNullable( Optional.ofNullable( currentResource )
+ .orElse(null).getComponentMetadataDefinition() )
+ .orElse(null).getMetadataDataDefinition() )
+ .orElse(null).getName();
+ String with = Optional.ofNullable( //get newResource name from metadata
+ Optional.ofNullable( Optional.ofNullable( newResource )
+ .orElse(null).getComponentMetadataDefinition() )
+ .orElse(null).getMetadataDataDefinition() )
+ .orElse(null).getName();
+ if ( with != null && replacePattern != null ){
+ Either<List<GroupDefinition>,Boolean> result = updateComponentGroupName( replacePattern , with ,currentResource.getGroups());
+ if (result.isLeft())
+ newResource.setGroups( (List<GroupDefinition>)result.left().value() );
+ }
+ }
+ //endregion
Either<Boolean, ResponseFormat> validateResourceFields = validateResourceFieldsBeforeUpdate(currentResource, newResource, inTransaction);
if (validateResourceFields.isRight()) {
@@ -5395,6 +5764,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
log.debug("send resource {} to dao for update", newResource.getUniqueId());
+ if (newResource!=null && newResource.getGroups()!=null){
+ for ( GroupDefinition group : newResource.getGroups() ){
+ if (newResource.getComponentMetadataDefinition()!=null && newResource.getComponentMetadataDefinition().getMetadataDataDefinition()!=null)
+ groupBusinessLogic.validateAndUpdateGroupMetadata(
+ newResource.getComponentMetadataDefinition().getMetadataDataDefinition().getUniqueId() ,
+ user,
+ ComponentTypeEnum.RESOURCE_INSTANCE,
+ group,
+ true ,
+ false) ;
+ }
+ }
Either<Resource, StorageOperationStatus> dataModelResponse = toscaOperationFacade.updateToscaElement(newResource);
if (dataModelResponse.isRight()) {
@@ -5410,12 +5791,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
/**
* validateResourceFieldsBeforeCreate
*
- * @param user
- * - modifier data (userId)
- * @param dataModel
- * - IResourceOperation for resource crud
- * @param resource
- * - Resource object to validate
+ * @param user - modifier data (userId)
+ * @param dataModel - IResourceOperation for resource crud
+ * @param resource - Resource object to validate
* @return Either<Boolean, ErrorResponse>
*/
private Either<Boolean, ResponseFormat> validateResourceFieldsBeforeCreate(User user, Resource resource, AuditingActionEnum actionEnum, boolean inTransaction) {
@@ -5449,7 +5827,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return eitherValidation;
}
- // validate vendor name & release
+ // validate vendor name & release & model number
log.debug("validate vendor name");
eitherValidation = validateVendorName(user, resource, actionEnum);
if (eitherValidation.isRight()) {
@@ -5462,6 +5840,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return eitherValidation;
}
+ log.debug("validate resource vendor model number");
+ eitherValidation = validateResourceVendorModelNumber(user, resource, actionEnum);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
// validate contact info
/*
* log.debug("validate contact info"); eitherValidation = validateContactIdContactId(user, resource, actionEnum); if (eitherValidation.isRight()) { return eitherValidation; }
@@ -5483,7 +5867,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
// validate template (derived from)
log.debug("validate derived from");
- if (resource.getResourceType().equals(ResourceTypeEnum.VF)) {
+ if (!ToscaUtils.isAtomicType(resource) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
resource.setDerivedFrom(null);
}
eitherValidation = validateDerivedFromExist(user, resource, actionEnum);
@@ -5519,8 +5903,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
/**
* validateResourceFieldsBeforeUpdate
*
- * @param currentResource
- * - Resource object to validate
+ * @param currentResource - Resource object to validate
* @return Either<Boolean, ErrorResponse>
*/
private Either<Boolean, ResponseFormat> validateResourceFieldsBeforeUpdate(Resource currentResource, Resource updateInfoResource, boolean inTransaction) {
@@ -5559,6 +5942,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return eitherValidation;
}
+ log.debug("validate resource vendor model number before update");
+ eitherValidation = validateResourceVendorModelNumber(currentResource, updateInfoResource);
+ if (eitherValidation.isRight()) {
+ return eitherValidation;
+ }
+
+
log.debug("validate vendor release before update");
eitherValidation = validateVendorReleaseName(null, updateInfoResource, null);
if (eitherValidation.isRight()) {
@@ -5763,6 +6153,19 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(true);
}
+ private Either<Boolean, ResponseFormat> validateResourceVendorModelNumber(Resource currentResource, Resource updateInfoResource) {
+ String updatedResourceVendorModelNumber = updateInfoResource.getResourceVendorModelNumber();
+ String currentResourceVendorModelNumber = currentResource.getResourceVendorModelNumber();
+ if (!currentResourceVendorModelNumber.equals(updatedResourceVendorModelNumber)) {
+ Either<Boolean, ResponseFormat> validateResourceVendorModelNumber = validateResourceVendorModelNumber(null, updateInfoResource, null);
+ if (validateResourceVendorModelNumber.isRight()) {
+ ResponseFormat errorResponse = validateResourceVendorModelNumber.right().value();
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
+
private Either<Boolean, ResponseFormat> validateCategory(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified, boolean inTransaction) {
Either<Boolean, ResponseFormat> validateCategoryName = validateCategory(null, updateInfoResource, null, inTransaction);
if (validateCategoryName.isRight()) {
@@ -5834,16 +6237,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade.validateToscaResourceNameExists(templateName);
if (dataModelResponse.isRight()) {
StorageOperationStatus storageStatus = dataModelResponse.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeDaoSystemError, "Create Resource - validateDerivedFromExist");
BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateDerivedFromExist");
log.debug("request to data model failed with error: {}", storageStatus.name());
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus), resource);
log.trace("audit before sending response");
componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
return Either.right(responseFormat);
- }
-
- else if (!dataModelResponse.left().value()) {
+ } else if (!dataModelResponse.left().value()) {
log.info("resource template with name: {}, does not exists", templateName);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
@@ -5958,7 +6358,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.right(responseFormat);
}
if (subcategories.size() > 1) {
- log.debug("Must be only one sub ategory for resource");
+ log.debug("Must be only one sub category for resource");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
return Either.right(responseFormat);
}
@@ -6071,6 +6471,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
+ private Either<Boolean, ResponseFormat> validateResourceVendorModelNumber(User user, Resource resource, AuditingActionEnum actionEnum) {
+ String resourceVendorModelNumber = resource.getResourceVendorModelNumber();
+ Either<Boolean, ResponseFormat> validateResourceVendorModelNumber = validateResourceVendorModelNumber(resourceVendorModelNumber);
+ if (validateResourceVendorModelNumber.isRight()) {
+ ResponseFormat responseFormat = validateResourceVendorModelNumber.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, "", "", actionEnum, null);
+ }
+ return validateResourceVendorModelNumber;
+
+ }
+
+
private Either<Boolean, ResponseFormat> validateVendorName(String vendorName) {
if (vendorName != null) {
if (!ValidationUtils.validateVendorNameLength(vendorName)) {
@@ -6091,6 +6503,26 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
+ private Either<Boolean, ResponseFormat> validateResourceVendorModelNumber(String resourceVendorModelNumber) {
+ if (resourceVendorModelNumber.equals("")) {
+ return Either.left(true);
+ } else {
+ if (!ValidationUtils.validateResourceVendorModelNumberLength(resourceVendorModelNumber)) {
+ log.info("resource vendor model number exceeds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
+ return Either.right(errorResponse);
+ }
+ // resource vendor model number is currently validated as vendor name
+ if (!ValidationUtils.validateVendorName(resourceVendorModelNumber)) {
+ log.info("resource vendor model number is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+ }
+
+
/*
* private Either<Boolean, ResponseFormat> validateDescriptionAndCleanup(User user, Resource resource, AuditingActionEnum actionEnum) { String description = resource.getDescription(); if (!ValidationUtils.validateStringNotEmpty(description)) {
* log.debug("Resource description is empty"); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus. COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue()); componentsUtils.auditResource(errorResponse,
@@ -6355,7 +6787,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (inputs.isRight()) {
String message = "Failed when creating inputs: for resource:" + resource.getName();
BeEcompErrorManager.getInstance().logInternalFlowError("ImportResource", message, ErrorSeverity.INFO);
- Map<String, InputDefinition> resultMap = new HashMap();
+ Map<String, InputDefinition> resultMap = new HashMap<>();
return Either.left(resultMap);
}
@@ -6365,6 +6797,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
+ @SuppressWarnings("unchecked")
private Either<GroupDefinition, ResponseFormat> createGroupInfo(String groupName, Object groupTemplateJson) {
GroupDefinition groupInfo = new GroupDefinition();
@@ -6428,6 +6861,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return result;
}
+ @SuppressWarnings("unchecked")
private Either<List<GroupProperty>, ResponseFormat> createPropertiesValueModuleFromYaml(Object properties, String groupName, String groupType) {
List<GroupProperty> result = new ArrayList<>();
@@ -6568,7 +7002,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
private Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> organizeVfCsarArtifactsByArtifactOperation(List<NonMetaArtifactInfo> artifactPathAndNameList, List<ArtifactDefinition> existingArtifactsToHandle,
- Resource resource, User user) {
+ Resource resource, User user) {
EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> nodeTypeArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
@@ -6631,22 +7065,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return nodeTypeArtifactsToHandleRes;
}
- private String buildNestedVfcToscaNamespace(String nodeTypeFullName) {
-
- String actualName = this.getNodeTypeActualName(nodeTypeFullName);
- return ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + ResourceTypeEnum.VFC.name().toLowerCase() + actualName;
-
- }
- private String buildNestedVfcToscaResourceName(String vfResourceName, String nodeTypeFullName) {
- String toscaResourceName;
- String nameWithouNamespacePrefix = getNodeTypeActualName(nodeTypeFullName);
- if (nameWithouNamespacePrefix.startsWith(Constants.ABSTRACT)) {
- toscaResourceName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + ResourceTypeEnum.VFC.name().toLowerCase() + '.' + vfResourceName + '.' + nameWithouNamespacePrefix;
+ private String buildNestedToscaResourceName(String nodeResourceType, String vfResourceName, String nodeTypeFullName) {
+ StringBuilder toscaResourceName = new StringBuilder(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
+ String nameWithouNamespacePrefix = nodeTypeFullName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ String[] findTypes = nameWithouNamespacePrefix.split("\\.");
+ String resourceType = findTypes[0];
+ String actualName = nameWithouNamespacePrefix.substring(resourceType.length());
+
+ if (actualName.startsWith(Constants.ABSTRACT)) {
+ toscaResourceName.append(resourceType.toLowerCase()).append('.').append(ValidationUtils.convertToSystemName(vfResourceName));
} else {
- toscaResourceName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + ResourceTypeEnum.VFC.name().toLowerCase() + '.' + vfResourceName + '.' + Constants.ABSTRACT + nameWithouNamespacePrefix;
+ toscaResourceName.append(nodeResourceType.toLowerCase()).append('.').append(ValidationUtils.convertToSystemName(vfResourceName)).append('.').append(Constants.ABSTRACT);
}
- return toscaResourceName;
+ return toscaResourceName.append(actualName.toLowerCase()).toString();
}
public ICacheMangerOperation getCacheManagerOperation() {
@@ -6658,85 +7090,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
///////////////////////////////////////// DataModel refactoring/////////////////////////////////////////////
-
- /*
- * /**
- *
- * @deprecated Use {@link #createOrUpdateResourceByImport(Resource,User,boolean, boolean,boolean)} instead
- */
- /*
- * public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResourceByImport(Resource resource, User user, AuditingActionEnum auditingEnum, boolean isNormative, boolean needLock) { return
- * createOrUpdateResourceByImport(resource, user, isNormative, false, needLock); }
- */
-
- public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateNodeTypeByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock) {
-
- // check if resource already exist
- Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resource.getName());
- Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> result = null;
-
- // create
- if (latestByName.isRight() && latestByName.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
-
- Either<Resource, StorageOperationStatus> latestByToscaName = toscaOperationFacade.getLatestByToscaResourceName(resource.getToscaResourceName());
- if (latestByToscaName.isRight() && latestByToscaName.right().value().equals(StorageOperationStatus.NOT_FOUND))
- result = createNodeTypeByImport(resource, user, isNormative, isInTransaction);
-
- else {
- StorageOperationStatus status = latestByName.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "Create / Update resource by import", resource.getName());
- BeEcompErrorManager.getInstance().logBeComponentMissingError("Create / Update resource by import", ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
- log.debug("resource already exist {}. status={}", resource.getName(), status);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_ALREADY_EXISTS);
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
- result = Either.right(responseFormat);
- }
-
- }
-
- // update
- else if (latestByName.isLeft()) {
- // result = updateExistingNodeTypeByImport(resource, latestByName.left().value(), user, isNormative, needLock);
- }
-
- // error
- else {
- StorageOperationStatus status = latestByName.right().value();
- BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeResourceMissingError, "Create / Update resource by import", resource.getName());
- log.debug("failed to get latest version of resource {}. status={}", resource.getName(), status);
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(latestByName.right().value()), resource);
- componentsUtils.auditResource(responseFormat, user, resource, "", "", AuditingActionEnum.IMPORT_RESOURCE, null);
- result = Either.right(responseFormat);
- }
- return result;
-
- }
-
- private Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createNodeTypeByImport(Resource resource, User user, boolean isNormative, boolean isInTransaction) {
- log.debug("resource with name {} does not exist. create new resource", resource.getName());
- Either<Resource, ResponseFormat> response = validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isInTransaction);
- if (response.isRight()) {
- return Either.right(response.right().value());
- }
-
- Either<Resource, ResponseFormat> createResponse = createResourceByDao(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isNormative, isInTransaction, null);
- if (createResponse.isRight()) {
- return Either.right(createResponse.right().value());
- } else {
- ImmutablePair<Resource, ActionStatus> resourcePair = new ImmutablePair<>(createResponse.left().value(), ActionStatus.CREATED);
- ASDCKpiApi.countImportResourcesKPI();
- return Either.left(resourcePair);
-
- }
- }
-
+ @Override
public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String resourceId, List<String> dataParamsToReturn) {
ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn);
Either<Resource, StorageOperationStatus> resourceResultEither = toscaOperationFacade.getToscaElement(resourceId, paramsToRetuen);
if (resourceResultEither.isRight()) {
- if(resourceResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ if (resourceResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
log.debug("Failed to found resource with id {} ", resourceId);
Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceId));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index b157b635b4..ac6183db00 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -36,6 +36,7 @@ import java.util.stream.Collectors;
import javax.servlet.ServletContext;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.auditing.api.IAuditingManager;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
@@ -55,6 +56,7 @@ import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.CsarInfo;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.PropertyDefinition;
@@ -124,7 +126,7 @@ public class ResourceImportManager {
lifecycleChangeInfo.setUserRemarks("certification on import");
Function<Resource, Either<Boolean, ResponseFormat>> validator = (resource) -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
- return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null);
+ return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null);
}
public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
@@ -133,18 +135,18 @@ public class ResourceImportManager {
lifecycleChangeInfo.setUserRemarks("certification on import");
Function<Resource, Either<Boolean, ResponseFormat>> validator = (resource) -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
- return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null);
+ return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null);
}
public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function<Resource, Either<Boolean, ResponseFormat>> validationFunction,
- LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) {
+ LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo) {
Resource resource = new Resource();
ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
String latestCertifiedResourceId = null;
try {
- boolean shouldBeCertified = nodeTypeArtifactsToHandle == null || nodeTypeArtifactsToHandle.isEmpty() ? true : false;
+ boolean shouldBeCertified = nodeTypeArtifactsToHandle == null || nodeTypeArtifactsToHandle.isEmpty();
setConstantMetaData(resource, shouldBeCertified);
setMetaDataFromJson(resourceMetaData, resource);
@@ -166,20 +168,20 @@ public class ResourceImportManager {
}
}
- response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock);
+ response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo);
Either<Resource, ResponseFormat> changeStateResponse;
if (response.isLeft()) {
resource = response.left().value().left;
if(nodeTypeArtifactsToHandle !=null && !nodeTypeArtifactsToHandle.isEmpty()){
Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes =
- resourceBusinessLogic.handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction);
+ resourceBusinessLogic.handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction, false);
if(handleNodeTypeArtifactsRes.isRight()){
return Either.right(handleNodeTypeArtifactsRes.right().value());
}
}
latestCertifiedResourceId = getLatestCertifiedResourceId(resource);
- changeStateResponse = resourceBusinessLogic.propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock);
+ changeStateResponse = resourceBusinessLogic.propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock, forceCertificationAllowed);
if (changeStateResponse.isRight()) {
response = Either.right(changeStateResponse.right().value());
} else {
@@ -254,7 +256,7 @@ public class ResourceImportManager {
Either<Boolean, ResponseFormat> validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource);
if (validatePropertiesTypes.isLeft()) {
- response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true);
+ response = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true, null);
} else {
ResponseFormat validationErrorResponse = validatePropertiesTypes.right().value();
auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
@@ -270,14 +272,14 @@ public class ResourceImportManager {
}
- private Either<Boolean, ResponseFormat> populateResourceFromYaml(String resourceYml, Resource resource, boolean inTransaction) {
+ Either<Boolean, ResponseFormat> populateResourceFromYaml(String resourceYml, Resource resource, boolean inTransaction) {
@SuppressWarnings("unchecked")
Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
Map<String, Object> toscaJsonAll = (Map<String, Object>) new Yaml().load(resourceYml);
Map<String, Object> toscaJson = toscaJsonAll;
// Checks if exist and builds the node_types map
- if (toscaJsonAll.containsKey(ToscaTagNamesEnum.NODE_TYPES.getElementName())) {
+ if (toscaJsonAll.containsKey(ToscaTagNamesEnum.NODE_TYPES.getElementName()) && resource.getResourceType()!=ResourceTypeEnum.CVFC) {
toscaJson = new HashMap<String, Object>();
toscaJson.put(ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(ToscaTagNamesEnum.NODE_TYPES.getElementName()));
}
@@ -287,7 +289,8 @@ public class ResourceImportManager {
return Either.right(setDerivedFrom.right().value());
}
Resource parentResource = setDerivedFrom.left().value();
- setToscaResourceName(toscaJson, resource);
+ if(StringUtils.isEmpty(resource.getToscaResourceName()))
+ setToscaResourceName(toscaJson, resource);
setAttributes(toscaJson, resource);
eitherResult = setCapabilities(toscaJson, resource, parentResource);
if (eitherResult.isRight())
@@ -721,7 +724,7 @@ public class ResourceImportManager {
capabilityDefinition.setProperties(capabilityProperties);
}
}
- } else {
+ } else if (!(capabilityJson instanceof List)) {
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index bc1c6e5910..ae7ae31ed9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -447,14 +447,12 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return componentsFieldsValidation;
}
- // validate service name uniqueness
log.debug("validate service name uniqueness");
Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, service, actionEnum);
if (serviceNameUniquenessValidation.isRight()) {
return serviceNameUniquenessValidation;
}
- // validate category
log.debug("validate category");
Either<Boolean, ResponseFormat> categoryValidation = validateServiceCategory(user, service, actionEnum);
if (categoryValidation.isRight()) {
@@ -462,12 +460,23 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
// validate project name (ProjectCode) - mandatory in service
-
log.debug("validate projectName");
Either<Boolean, ResponseFormat> projectCodeValidation = validateProjectCode(user, service, actionEnum);
if (projectCodeValidation.isRight()) {
return projectCodeValidation;
}
+
+ log.debug("validate service type");
+ Either<Boolean, ResponseFormat> serviceTypeValidation = validateServiceTypeAndCleanup(user, service, actionEnum);
+ if (serviceTypeValidation.isRight()) {
+ return serviceTypeValidation;
+ }
+
+ log.debug("validate service role");
+ Either<Boolean, ResponseFormat> serviceRoleValidation = validateServiceRoleAndCleanup(user, service, actionEnum);
+ if (serviceRoleValidation.isRight()) {
+ return serviceRoleValidation;
+ }
return Either.left(true);
@@ -704,6 +713,18 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (!uuidCurrent.equals(uuidUpdated)) {
log.info("update srvice: recived request to update uuid to {} the field is not updatable ignoring.", uuidUpdated);
}
+
+ response = validateAndUpdateServiceType(user, currentService, serviceUpdate, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
+
+ response = validateAndUpdateServiceRole(user, currentService, serviceUpdate, null);
+ if (response.isRight()) {
+ ResponseFormat errorResponse = response.right().value();
+ return Either.right(errorResponse);
+ }
String currentInvariantUuid = currentService.getInvariantUUID();
String updatedInvariantUuid = serviceUpdate.getInvariantUUID();
@@ -821,18 +842,18 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validateAndUpdateServiceName(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
+ private Either<Boolean, ResponseFormat> validateAndUpdateServiceName(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum auditingAction) {
String serviceNameUpdated = serviceUpdate.getName();
String serviceNameCurrent = currentService.getName();
if (!serviceNameCurrent.equals(serviceNameUpdated)) {
if (!hasBeenCertified) {
- Either<Boolean, ResponseFormat> validatServiceNameResponse = validateComponentName(user, serviceUpdate, audatingAction);
+ Either<Boolean, ResponseFormat> validatServiceNameResponse = validateComponentName(user, serviceUpdate, auditingAction);
if (validatServiceNameResponse.isRight()) {
ResponseFormat errorRespons = validatServiceNameResponse.right().value();
return Either.right(errorRespons);
}
- Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, serviceUpdate, audatingAction);
+ Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, serviceUpdate, auditingAction);
if (serviceNameUniquenessValidation.isRight()) {
return serviceNameUniquenessValidation;
}
@@ -848,6 +869,111 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
return Either.left(true);
}
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateServiceType(User user, Service currentService, Service updatedService, AuditingActionEnum auditingAction) {
+ String updatedServiceType = updatedService.getServiceType();
+ String currentServiceType = currentService.getServiceType();
+ if (!currentServiceType.equals(updatedServiceType)) {
+ Either<Boolean, ResponseFormat> validateServiceType = validateServiceTypeAndCleanup(user, updatedService , auditingAction);
+ if (validateServiceType.isRight()) {
+ ResponseFormat errorResponse = validateServiceType.right().value();
+ componentsUtils.auditComponentAdmin(errorResponse, user, updatedService, "", "", auditingAction, ComponentTypeEnum.SERVICE);
+ return Either.right(errorResponse);
+ }
+ currentService.setServiceType(updatedServiceType);
+ }
+ return Either.left(true);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateServiceTypeAndCleanup(User user, Component component, AuditingActionEnum actionEnum) {
+ String serviceType = ((Service)component).getServiceType();
+ if (serviceType != null){
+ serviceType = cleanUpText(serviceType);
+ Either<Boolean, ResponseFormat> validateServiceType = validateServiceType(serviceType);
+ if (validateServiceType.isRight()) {
+ ResponseFormat responseFormat = validateServiceType.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", actionEnum, ComponentTypeEnum.SERVICE);
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
+ } else {
+ return Either.left(false);
+ }
+ }
+
+
+ private Either<Boolean, ResponseFormat> validateServiceType(String serviceType) {
+ if (serviceType.equals("")){
+ return Either.left(true);
+ } else {
+ if (!ValidationUtils.validateServiceTypeLength(serviceType)) {
+ log.info("service type exceeds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_TYPE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_TYPE_MAX_LENGTH);
+ return Either.right(errorResponse);
+ }
+
+ if (!ValidationUtils.validateIsEnglish(serviceType)) {
+ log.info("service type is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_SERVICE_TYPE);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+ }
+
+ private Either<Boolean, ResponseFormat> validateAndUpdateServiceRole(User user, Service currentService, Service updatedService, AuditingActionEnum auditingAction) {
+ String updatedServiceRole = updatedService.getServiceRole();
+ String currentServiceRole = currentService.getServiceRole();
+ if (!currentServiceRole.equals(updatedServiceRole)) {
+ Either<Boolean, ResponseFormat> validateServiceRole = validateServiceRoleAndCleanup(user, updatedService , auditingAction);
+ if (validateServiceRole.isRight()) {
+ ResponseFormat errorResponse = validateServiceRole.right().value();
+ componentsUtils.auditComponentAdmin(errorResponse, user, updatedService, "", "", auditingAction, ComponentTypeEnum.SERVICE);
+ return Either.right(errorResponse);
+ }
+ currentService.setServiceRole(updatedServiceRole);
+ }
+ return Either.left(true);
+ }
+
+ protected Either<Boolean, ResponseFormat> validateServiceRoleAndCleanup(User user, Component component, AuditingActionEnum actionEnum) {
+ String serviceRole = ((Service)component).getServiceRole();
+ if (serviceRole != null){
+ serviceRole = cleanUpText(serviceRole);
+
+ Either<Boolean, ResponseFormat> validateServiceRole = validateServiceRole(serviceRole);
+ if (validateServiceRole.isRight()) {
+ ResponseFormat responseFormat = validateServiceRole.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, "", "", actionEnum, ComponentTypeEnum.SERVICE);
+ return Either.right(responseFormat);
+ }
+ return Either.left(true);
+ } else {
+ return Either.left(false);
+ }
+ }
+
+
+ private Either<Boolean, ResponseFormat> validateServiceRole(String serviceRole) {
+ if (serviceRole.equals("")){
+ return Either.left(true);
+ } else {
+ if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
+ log.info("service role exceeds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_ROLE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_ROLE_MAX_LENGTH);
+ return Either.right(errorResponse);
+ }
+
+ if (!ValidationUtils.validateIsEnglish(serviceRole)) {
+ log.info("service role is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_SERVICE_ROLE);
+ return Either.right(errorResponse);
+ }
+ return Either.left(true);
+ }
+ }
+
+
private Either<Boolean, ResponseFormat> validateAndUpdateCategory(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
List<CategoryDefinition> categoryUpdated = serviceUpdate.getCategories();
@@ -1225,7 +1351,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
// DE194021
ServletContext servletContext = request.getSession().getServletContext();
- boolean isDistributionEngineUp = getHealthCheckBL(servletContext).isDistributionEngineUp(request.getSession().getServletContext()); // DE
+ boolean isDistributionEngineUp = getHealthCheckBL(servletContext).isDistributionEngineUp(); // DE
if (!isDistributionEngineUp) {
BeEcompErrorManager.getInstance().logBeSystemError("Distribution Engine is DOWN");
log.debug("Distribution Engine is DOWN");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java
index 9586be81ea..11ffcd9329 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceComponentInstanceBusinessLogic.java
@@ -31,10 +31,6 @@ import fj.data.Either;
@Component("serviceComponentInstanceBusinessLogic")
public class ServiceComponentInstanceBusinessLogic extends ComponentInstanceBusinessLogic {
- @Override
- protected Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent) {
- return Either.left(true);
- }
@Override
protected NodeTypeEnum getNodeTypeOfComponentInstanceOrigin() {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java
index 61a5af5b74..5a93ecf182 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/VFComponentInstanceBusinessLogic.java
@@ -25,6 +25,7 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.tosca.ToscaUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,17 +39,6 @@ public class VFComponentInstanceBusinessLogic extends ComponentInstanceBusinessL
private static Logger log = LoggerFactory.getLogger(VFComponentInstanceBusinessLogic.class.getName());
@Override
- protected Either<Boolean, ResponseFormat> validateAllowedToContainCompInstances(org.openecomp.sdc.be.model.Component containerComponent) {
- Resource resource = (Resource) containerComponent;
- ResourceTypeEnum resourceType = resource.getResourceType();
- if (ResourceTypeEnum.VF != resourceType) {
- log.debug("Cannot attach resource instances to container resource of type {}", resourceType);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, resourceType.getValue()));
- }
- return Either.left(true);
- }
-
- @Override
protected NodeTypeEnum getNodeTypeOfComponentInstanceOrigin() {
return NodeTypeEnum.Resource;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java
index 042af54383..b18c4d0985 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java
@@ -55,6 +55,7 @@ import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
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;
@@ -66,6 +67,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.tosca.ToscaError;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.be.tosca.ToscaRepresentation;
+import org.openecomp.sdc.be.tosca.ToscaUtils;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.util.ValidationUtils;
@@ -196,7 +198,7 @@ public class CertificationRequestTransition extends LifeCycleTransition {
ResponseFormat responseFormat;
Either<? extends Component, ResponseFormat> result = null;
try{
- if (componentType == ComponentTypeEnum.SERVICE || (componentType == ComponentTypeEnum.RESOURCE && ((Resource) component).getResourceType() == ResourceTypeEnum.VF)) {
+ if (component.getToscaType().equals(ToscaElementTypeEnum.TopologyTemplate.getValue())) {
Either<Boolean, ResponseFormat> statusCert = validateAllResourceInstanceCertified(component);
if (statusCert.isRight()) {
@@ -270,7 +272,10 @@ public class CertificationRequestTransition extends LifeCycleTransition {
// occurrences in the future
Map<String, List<String>> reqName2Ids = new HashMap<>();
Map<String, List<String>> capName2Ids = new HashMap<>();
- parseRelationsForReqCapVerification(component, reqName2Ids, capName2Ids);
+// Either<Boolean, ResponseFormat> parseRelationsForReqCapVerificationRes = parseRelationsForReqCapVerification(component, reqName2Ids, capName2Ids);
+// if(parseRelationsForReqCapVerificationRes.isRight()){
+// return parseRelationsForReqCapVerificationRes;
+// }
Map<String, Set<String>> requirementsToFulfillBeforeCert = configurationManager.getConfiguration().getRequirementsToFulfillBeforeCert();
Map<String, Set<String>> capabilitiesToConsumeBeforeCert = configurationManager.getConfiguration().getCapabilitiesToConsumeBeforeCert();
for (ComponentInstance compInst : componentInstances) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
index 8e89a6bf31..dfe04f919d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
@@ -32,6 +32,7 @@ import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
@@ -46,13 +47,14 @@ import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
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.ICacheMangerOperation;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CapabilityOperation;
-import org.openecomp.sdc.be.model.operations.impl.ComponentOperation;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.common.api.Constants;
@@ -204,9 +206,9 @@ public class LifecycleBusinessLogic {
String resourceCurrVersion = component.getVersion();
LifecycleStateEnum resourceCurrState = component.getLifecycleState();
- log.info("lock component {}", componentId);
// lock resource
if (inTransaction == false && needLock) {
+ log.info("lock component {}", componentId);
Either<Boolean, ResponseFormat> eitherLockResource = lockComponent(componentType, component);
if (eitherLockResource.isRight()) {
errorResponse = eitherLockResource.right().value();
@@ -214,8 +216,8 @@ public class LifecycleBusinessLogic {
log.error("lock component {} failed", componentId);
return Either.right(errorResponse);
}
+ log.info("after lock component {}", componentId);
}
- log.info("after lock component {}", componentId);
try {
Either<String, ResponseFormat> commentValidationResult = validateComment(changeInfo, transitionEnum);
if (commentValidationResult.isRight()) {
@@ -463,4 +465,51 @@ public class LifecycleBusinessLogic {
return Either.left(latestComponent);
}
+ public Either<Resource, ResponseFormat> forceResourceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ Either<Resource, ResponseFormat> result = null;
+ Either<ToscaElement, StorageOperationStatus> certifyResourceRes = null;
+ if(lifecycleChangeInfo.getAction() != LifecycleChanceActionEnum.CREATE_FROM_CSAR){
+ log.debug("Force certification is not allowed for the action {}. ", lifecycleChangeInfo.getAction().name());
+ result = Either.right(componentUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ }
+ // lock resource
+ if(result == null && !inTransaction && needLock){
+ log.info("lock component {}", resource.getUniqueId());
+ Either<Boolean, ResponseFormat> eitherLockResource = lockComponent(resource.getComponentType(), resource);
+ if (eitherLockResource.isRight()) {
+ log.error("lock component {} failed", resource.getUniqueId());
+ result = Either.right(eitherLockResource.right().value());
+ }
+ log.info("after lock component {}", resource.getUniqueId());
+ }
+ try{
+ if(result == null){
+ certifyResourceRes = lifecycleOperation.forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId(), resource.getVersion());
+ if (certifyResourceRes.isRight()) {
+ StorageOperationStatus status = certifyResourceRes.right().value();
+ log.debug("Failed to perform a force certification of resource {}. The status is {}. ", resource.getName(), status);
+ result = Either.right(componentUtils.getResponseFormatByResource(componentUtils.convertFromStorageResponse(status), resource));
+ }
+ }
+ if(result == null){
+ result = Either.left(ModelConverter.convertFromToscaElement(certifyResourceRes.left().value()));
+ }
+ } finally {
+ log.info("unlock component {}", resource.getUniqueId());
+ if (!inTransaction) {
+ if(result.isLeft()){
+ titanDao.commit();
+ } else{
+ titanDao.rollback();
+ }
+ if(needLock){
+ NodeTypeEnum nodeType = resource.getComponentType().getNodeType();
+ log.info("During change state, another component {} has been created/updated", resource.getUniqueId());
+ graphLockOperation.unlockComponent(resource.getUniqueId(), nodeType);
+ }
+ }
+ }
+ return result;
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
index c3708d4017..f96e226d26 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
@@ -126,10 +126,11 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
Response response = null;
ResponseFormat responseFormat = null;
String query = request.getQueryString();
- String requestURI = request.getRequestURI();
+ String requestURI = request.getRequestURI().endsWith("/")?
+ removeDuplicateSlashSeparator(request.getRequestURI()): request.getRequestURI();
String url = request.getMethod() + " " + requestURI;
log.debug("Start handle request of {}", url);
-
+
AuditingActionEnum auditingActionEnum = query == null ? AuditingActionEnum.GET_ASSET_LIST : AuditingActionEnum.GET_FILTERED_ASSET_LIST;
EnumMap<AuditingFieldsKeysEnum, Object> additionalParam = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
@@ -162,7 +163,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
}
if (resourceType != null) {
ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.getTypeIgnoreCase(resourceType);
- if( resourceTypeEnum == null ){
+ if (resourceTypeEnum == null) {
log.debug("getAssetList: Asset Fetching Failed. Invalid resource type was received");
responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, additionalParam);
@@ -370,4 +371,11 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
return response;
}
}
+
+
+ private String removeDuplicateSlashSeparator(String requestUri) {
+ return requestUri.substring(0, requestUri.length()-1);
+ }
+
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
index 529d2aba4d..40a5322afa 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
@@ -269,7 +269,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
@ApiOperation(value = "Change Resource lifecycle State", httpMethod = "POST")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Resource state changed", response = AssetMetadata.class),
- @ApiResponse(code = 400, message = "Missing X-ECOMP-InstanceID HTTP header - POL5001"),
+ @ApiResponse(code = 400, message = "Missing X-ECOMP-InstanceID HTTP header - POL5001"),
@ApiResponse(code = 401, message = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
@ApiResponse(code = 403, message = "ECOMP component is not authorized - POL5003"),
@ApiResponse(code = 404, message = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
index 6b16e71e82..55ad44db0c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
@@ -102,7 +102,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
- private synchronized void initLog(Logger log) {
+ protected synchronized void initLog(Logger log) {
if (this.log == null) {
this.log = log;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
index 92bc31f123..dff6cddbbb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
@@ -120,7 +120,7 @@ public class ComponentServlet extends BeGenericServlet {
@Path("/{componentType}/{componentId}/requirmentsCapabilities")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Get Component Requirments And Capabilities", httpMethod = "GET", notes = "Returns Requirments And Capabilities according to componentId", response = Resource.class)
+ @ApiOperation(value = "Get Component Requirments And Capabilities", httpMethod = "GET", notes = "Returns Requirements And Capabilities according to componentId", response = Resource.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
public Response getRequirementAndCapabilities(@PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
index da64dc58fb..4b2ff89ef8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
@@ -20,26 +20,8 @@
package org.openecomp.sdc.be.servlets;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
import org.openecomp.sdc.be.components.clean.ComponentsCleanBusinessLogic;
import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -47,13 +29,9 @@ import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.info.ArtifactTypesInfo;
-import org.openecomp.sdc.be.model.ArtifactType;
-import org.openecomp.sdc.be.model.Category;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.PropertyScope;
-import org.openecomp.sdc.be.model.Tag;
-import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.GroupingDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
@@ -65,14 +43,20 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.jcabi.aspects.Loggable;
+import javax.inject.Singleton;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import fj.data.Either;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.*;
@Path("/v1/")
@@ -552,14 +536,14 @@ public class ElementServlet extends BeGenericServlet {
@ApiOperation(value = "Retrieve catalog resources and services", httpMethod = "GET", notes = "Retrieve catalog resources and services", response = User.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Returns resources and services Ok"), @ApiResponse(code = 404, message = "No resources and services were found"), @ApiResponse(code = 404, message = "User not found"),
@ApiResponse(code = 500, message = "Internal Server Error") })
- public Response getCatalogComponents(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ public Response getCatalogComponents(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) {
Response res = null;
try {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("Start handle request of {}", url);
- Either<Map<String, List<? extends Component>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId);
+ Either<Map<String, List<? extends Component>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId, excludeTypes);
if (catalogData.isRight()) {
log.debug("failed to get catalog data");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
index 04081bac30..f7e7ae2da1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
@@ -153,7 +153,7 @@ public class GroupServlet extends AbstractValidationsServlet {
// Update GroupDefinition
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
Either<GroupDefinition, ResponseFormat> actionResponse = businessLogic
- .validateAndUpdateGroupMetadata(componentId, user, componentTypeEnum, updatedGroup, true);
+ .validateAndUpdateGroupMetadata(componentId, user, componentTypeEnum, updatedGroup, true ,true);
if (actionResponse.isRight()) {
log.debug("failed to update GroupDefinition");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
index 5eed7eeb0d..98e966e6eb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
@@ -44,6 +44,42 @@ public class RepresentationUtils {
private static Logger log = LoggerFactory.getLogger(RepresentationUtils.class.getName());
+ public static ArtifactDefinition convertJsonToArtifactDefinitionForUpdate(String content, Class<ArtifactDefinition> clazz) {
+
+ JsonObject jsonElement = new JsonObject();
+ ArtifactDefinition resourceInfo = null;
+
+ try {
+ Gson gson = new Gson();
+ jsonElement = gson.fromJson(content, jsonElement.getClass());
+ String payload = null;
+ jsonElement.remove(Constants.ARTIFACT_GROUP_TYPE_FIELD);
+ //in update the group type is ignored but this spagheti code makes it too complex to remove this field.
+ jsonElement.addProperty(Constants.ARTIFACT_GROUP_TYPE_FIELD, ArtifactGroupTypeEnum.INFORMATIONAL.getType());
+ JsonElement artifactPayload = jsonElement.get(Constants.ARTIFACT_PAYLOAD_DATA);
+ if (artifactPayload != null && !artifactPayload.isJsonNull()) {
+ payload = artifactPayload.getAsString();
+ }
+ jsonElement.remove(Constants.ARTIFACT_PAYLOAD_DATA);
+ String json = gson.toJson(jsonElement);
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(Feature.FAIL_ON_EMPTY_BEANS, false);
+ mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
+
+ resourceInfo = mapper.readValue(json, clazz);
+ resourceInfo.setPayloadData(payload);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeArtifactInformationInvalidError, "Artifact Upload / Update");
+ BeEcompErrorManager.getInstance().logBeArtifactInformationInvalidError("Artifact Upload / Update");
+ log.debug("Failed to convert the content {} to object.", content.substring(0, Math.min(50, content.length())), e);
+ }
+
+ return resourceInfo;
+ }
+
+
public static class ResourceRep {
}
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 fb87e34de7..b70dae68e8 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
@@ -75,8 +75,10 @@ import org.openecomp.sdc.be.model.operations.impl.LifecycleOperation;
import org.openecomp.sdc.be.resources.data.ESArtifactData;
import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
+import org.openecomp.sdc.be.utils.CommonBeUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ValidationUtils;
@@ -146,9 +148,14 @@ public class CsarUtils {
"([\\w\\_\\-\\.\\s]+)(/)" +
// Artifact Type
"([\\w\\_\\-\\.\\s]+)(/)" +
- // Artifact File Name
- "([\\w\\_\\-\\.\\s]+)";
- public static final String ARTIFACT_CREATED_FROM_CSAR = "Artifact created from csar";
+ // Artifact Any File Name
+ ".+";
+ public static final String VALID_ENGLISH_ARTIFACT_NAME = "([\\w\\_\\-\\.\\s]+)";
+ public static final String SERVICE_TEMPLATE_PATH_PATTERN = Constants.SERVICE_TEMPLATES_CONTAINING_FOLDER +
+ // Service Template File Name
+ "([\\w\\_\\-\\.\\s]+)";
+
+ public static final String ARTIFACT_CREATED_FROM_CSAR = "Artifact created from csar";
public CsarUtils() {
if(SDC_VERSION != null && !SDC_VERSION.isEmpty()){
@@ -281,8 +288,8 @@ public class CsarUtils {
dependencies = dependenciesRes.left().value().getDependencies();
}
- //UID <cassandraId,filename,component>
- Map<String, ImmutableTriple<String,String, Component>> innerComponentsCache = new HashMap<>();
+ //UID <cassandraId,filename,component>
+ Map<String, ImmutableTriple<String,String, Component>> innerComponentsCache = new HashMap<>();
if (dependencies != null && !dependencies.isEmpty()) {
for (Triple<String, String, Component> d : dependencies) {
@@ -295,18 +302,16 @@ public class CsarUtils {
return Either.right(responseFormat);
}
- //fill innerComponentsCache
- fileName = d.getLeft();
- innerComponentsCache.put(childComponent.getUniqueId(),
- new ImmutableTriple<String, String, Component>(cassandraId, fileName, childComponent));
- insertInnerComponentsToCache(innerComponentsCache, childComponent);
-
- byte[] content = entryData.left().value();
- generatorInputs.add(new ImmutablePair<Component, byte[]>(childComponent, content));
- }
+ //fill innerComponentsCache
+ fileName = d.getLeft();
+ addComponentToCache(innerComponentsCache, cassandraId, fileName, childComponent);
+ addInnerComponentsToCache(innerComponentsCache, childComponent);
- //add inner components to CSAR
-
+ byte[] content = entryData.left().value();
+ generatorInputs.add(new ImmutablePair<Component, byte[]>(childComponent, content));
+ }
+
+ //add inner components to CSAR
for (Entry<String, ImmutableTriple<String, String, Component>> innerComponentTripleEntry : innerComponentsCache.entrySet()) {
ImmutableTriple<String, String, Component> innerComponentTriple = innerComponentTripleEntry.getValue();
@@ -418,7 +423,7 @@ public class CsarUtils {
}
- private void insertInnerComponentsToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache,
+ private void addInnerComponentsToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache,
Component childComponent) {
List<ComponentInstance> instances = childComponent.getComponentInstances();
@@ -438,19 +443,32 @@ public class CsarUtils {
ArtifactDefinition childArtifactDefinition = childToscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
if (childArtifactDefinition != null) {
//add to cache
- componentCache.put(ci.getComponentUid(),
- new ImmutableTriple<String, String, Component>(childArtifactDefinition.getEsId(),
- childArtifactDefinition.getArtifactName(), componentRI));
+ addComponentToCache(componentCache, childArtifactDefinition.getEsId(), childArtifactDefinition.getArtifactName(), componentRI);
}
//if not atomic - insert inner components as well
if(!ToscaUtils.isAtomicType(componentRI)) {
- insertInnerComponentsToCache(componentCache, componentRI);
+ addInnerComponentsToCache(componentCache, componentRI);
}
}
});
}
}
+
+ private void addComponentToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache,
+ String id, String fileName, Component component) {
+
+ ImmutableTriple<String, String, Component> cachedComponent = componentCache.get(component.getInvariantUUID());
+ if (cachedComponent == null || CommonBeUtils.compareAsdcComponentVersions(component.getVersion(), cachedComponent.getRight().getVersion())) {
+ componentCache.put(component.getInvariantUUID(),
+ new ImmutableTriple<String, String, Component>(id, fileName, component));
+
+ if(cachedComponent != null) {
+ //overwriting component with newer version
+ log.warn("Overwriting component invariantID {} of version {} with a newer version {}", id, cachedComponent.getRight().getVersion(), component.getVersion());
+ }
+ }
+ }
private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(Component component, ZipOutputStream zip, String fileName) {
try {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
index 0804ef1ed4..b8414367aa 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -100,7 +100,7 @@ public class PropertyConvertor {
eschema.setDescription(schema.getProperty().getDescription());
prop.setEntry_schema(eschema);
}
- log.debug("try to convert property {} from type {} with default value {}", property.getName(), property.getType(), property.getDefaultValue());
+ log.trace("try to convert property {} from type {} with default value [{}]", property.getName(), property.getType(), property.getDefaultValue());
prop.setDefaultp(convertToToscaObject(property.getType(), property.getName(), property.getDefaultValue(), innerType, dataTypes));
prop.setType(property.getType());
prop.setDescription(property.getDescription());
@@ -112,45 +112,46 @@ public class PropertyConvertor {
}
public Object convertToToscaObject(String propertyType, String propertyName, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
- log.debug("try to convert propertyType {} , value {}, innerType {}", propertyType, value, innerType);
+ log.trace("try to convert propertyType {} , value [{}], innerType {}", propertyType, value, innerType);
if (value == null) {
value = getDataTypeDefaultValue(propertyName, dataTypes.get(propertyType));
if(StringUtils.isEmpty(value)){
return null;
}
- }
-
- ToscaMapValueConverter mapConverterInst = ToscaMapValueConverter.getInstance();
- ToscaValueConverter innerConverter = null;
- Boolean isScalar = true;
-
- ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
- if (type == null) {
- log.debug("isn't prederfined type, get from all data types");
- DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
- if (innerType == null) {
- innerType = propertyType;
- }
-
- if ((type = mapConverterInst.isScalarType(dataTypeDefinition)) != null) {
- log.debug("This is scalar type. get suitable converter for type {}", type);
- innerConverter = type.getValueConverter();
- } else {
- isScalar = false;
- }
- } else {
- ToscaPropertyType typeIfScalar = ToscaPropertyType.getTypeIfScalar(type.getType());
- if (typeIfScalar == null) {
- isScalar = false;
- }
- innerConverter = type.getValueConverter();
- if (ToscaPropertyType.STRING.equals(type) && value.startsWith("/")) {
- return innerConverter.convertToToscaValue(value, innerType, dataTypes);
- }
}
- JsonElement jsonElement = null;
try {
+ ToscaMapValueConverter mapConverterInst = ToscaMapValueConverter.getInstance();
+ ToscaValueConverter innerConverter = null;
+ Boolean isScalar = true;
+
+ ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
+ if (type == null) {
+ log.trace("isn't prederfined type, get from all data types");
+ DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
+ if (innerType == null) {
+ innerType = propertyType;
+ }
+
+ if ((type = mapConverterInst.isScalarType(dataTypeDefinition)) != null) {
+ log.trace("This is scalar type. get suitable converter for type {}", type);
+ innerConverter = type.getValueConverter();
+ } else {
+ isScalar = false;
+ }
+ } else {
+ ToscaPropertyType typeIfScalar = ToscaPropertyType.getTypeIfScalar(type.getType());
+ if (typeIfScalar == null) {
+ isScalar = false;
+ }
+
+ innerConverter = type.getValueConverter();
+ if (ToscaPropertyType.STRING.equals(type) && value.startsWith("/")) {
+ return innerConverter.convertToToscaValue(value, innerType, dataTypes);
+ }
+ }
+ JsonElement jsonElement = null;
+
StringReader reader = new StringReader(value);
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
@@ -162,11 +163,11 @@ public class PropertyConvertor {
}
if (jsonElement.isJsonPrimitive() && isScalar) {
- log.debug("It's well defined type. convert it");
+ log.trace("It's well defined type. convert it");
ToscaValueConverter converter = type.getValueConverter();
return converter.convertToToscaValue(value, innerType, dataTypes);
} else {
- log.debug("It's data type or inputs in primitive type. convert as map");
+ log.trace("It's data type or inputs in primitive type. convert as map");
Object convertedValue;
if (innerConverter != null && (ToscaPropertyType.MAP.equals(type) || ToscaPropertyType.LIST.equals(type))) {
convertedValue = innerConverter.convertToToscaValue(value, innerType, dataTypes);
@@ -185,7 +186,7 @@ public class PropertyConvertor {
return convertedValue;
}
- } catch (JsonSyntaxException e) {
+ } catch (Exception e) {
log.debug("convertToToscaValue failed to parse json value :", e);
return null;
}
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 d6f87967ca..f802d0f412 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
@@ -94,7 +94,7 @@ public class ToscaExportHandler {
private static Logger log = LoggerFactory.getLogger(ToscaExportHandler.class.getName());
- public static final String TOSCA_VERSION = "tosca_simple_yaml_1_0";
+ public static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
public static final String SERVICE_NODE_TYPE_PREFIX = "org.openecomp.service.";
public static final String IMPORTS_FILE_KEY = "file";
public static final String TOSCA_TEMPLATE_NAME = "-template.yml";
@@ -333,10 +333,13 @@ public class ToscaExportHandler {
toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
toscaMetadata.setResourceVendor(resource.getVendorName());
toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
-
+ toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber());
break;
case SERVICE:
+ Service service = (Service) component;
toscaMetadata.setType(component.getComponentType().getValue());
+ toscaMetadata.setServiceType(service.getServiceType());
+ toscaMetadata.setServiceRole(service.getServiceRole());
if (!isInstance) {
// DE268546
toscaMetadata.setServiceEcompNaming(((Service)component).isEcompGeneratedNaming());
@@ -747,8 +750,9 @@ public class ToscaExportHandler {
toscaMetadata = new VfModuleToscaMetadata();
Map<String, Object> properties = fillGroupProperties(props.get());
-
- properties.put(VF_MODULE_DESC_KEY, description.get());
+ 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);
}
toscaMetadata.setName(groupName.get());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
index 6573313dbb..604a52083b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
@@ -32,6 +32,9 @@ public class ToscaMetadata implements IToscaMetadata {
private String subcategory;
private String resourceVendor;
private String resourceVendorRelease;
+ private String resourceVendorModelNumber;
+ private String serviceType;
+ private String serviceRole;
private Boolean serviceEcompNaming;
private Boolean ecompGeneratedNaming;
private String namingPolicy;
@@ -110,6 +113,30 @@ public class ToscaMetadata implements IToscaMetadata {
public void setResourceVendorRelease(String resourceVendorRelease) {
this.resourceVendorRelease = resourceVendorRelease;
}
+
+ public String getResourceVendorModelNumber() {
+ return resourceVendorModelNumber;
+ }
+
+ public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
+ this.resourceVendorModelNumber = resourceVendorModelNumber;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getServiceRole() {
+ return serviceRole;
+ }
+
+ public void setServiceRole(String serviceRole) {
+ this.serviceRole = serviceRole;
+ }
public Boolean isEcompGeneratedNaming() {
return ecompGeneratedNaming;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
index 0641524038..7485a8dc43 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
@@ -20,68 +20,54 @@
package org.openecomp.sdc.common.transaction.mngr;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import fj.P;
+import fj.data.Either;
+import fj.data.HashMap;
+import fj.data.List;
import org.openecomp.sdc.common.transaction.api.RollbackHandler;
import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-import fj.data.Either;
-
public class RollbackManager {
- private Map<DBTypeEnum, RollbackHandler> rollBackHandlersMap;
- private Integer transactionId;
- private String userId, actionType;
+ private final HashMap<DBTypeEnum, RollbackHandler> rollbackHandlersMap;
+ private final Integer transactionId;
+ private final String userId;
+ private final String actionType;
- RollbackManager(Integer transactionId, String userId, String actionType, List<RollbackHandler> roleBackHandlers) {
+ RollbackManager(Integer transactionId, String userId, String actionType, Iterable<RollbackHandler> rollbackHandlers) {
this.transactionId = transactionId;
this.userId = userId;
this.actionType = actionType;
- rollBackHandlersMap = new HashMap<>();
- for (RollbackHandler handler : roleBackHandlers) {
- rollBackHandlersMap.put(handler.getDBType(), handler);
- }
-
+ this.rollbackHandlersMap = HashMap.from(List.iterableList(rollbackHandlers).map(i -> P.p(i.getDBType(), i)));
}
public DBActionCodeEnum transactionRollback() {
- DBActionCodeEnum rollbackResult = DBActionCodeEnum.SUCCESS;
- Iterator<RollbackHandler> handlersItr = rollBackHandlersMap.values().iterator();
- while (handlersItr.hasNext()) {
- RollbackHandler handler = handlersItr.next();
- DBActionCodeEnum rollbackCode = handler.doRollback();
- if (rollbackCode == DBActionCodeEnum.FAIL_GENERAL) {
- rollbackResult = DBActionCodeEnum.FAIL_GENERAL;
- }
- }
-
- return rollbackResult;
+ List<DBActionCodeEnum> results = rollbackHandlersMap.values().map(RollbackHandler::doRollback);
+ boolean failure = results.exists(r -> r == DBActionCodeEnum.FAIL_GENERAL);
+ return failure ? DBActionCodeEnum.FAIL_GENERAL : DBActionCodeEnum.SUCCESS;
}
protected Either<RollbackHandler, MethodActivationStatusEnum> addRollbackHandler(RollbackHandler rollbackHandler) {
Either<RollbackHandler, MethodActivationStatusEnum> result;
- if (rollBackHandlersMap.containsKey(rollbackHandler.getDBType())) {
+ if (rollbackHandlersMap.contains(rollbackHandler.getDBType())) {
result = Either.right(MethodActivationStatusEnum.NOT_ALLOWED);
} else {
- rollBackHandlersMap.put(rollbackHandler.getDBType(), rollbackHandler);
+ rollbackHandlersMap.set(rollbackHandler.getDBType(), rollbackHandler);
result = Either.left(rollbackHandler);
}
return result;
}
- protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(DBTypeEnum dbType) {
+ protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(final DBTypeEnum dbType) {
- final DBTypeEnum dbTypeFinal = dbType;
RollbackHandler rollbackHandler = new RollbackHandler(transactionId, userId, actionType) {
@Override
public DBTypeEnum getDBType() {
- return dbTypeFinal;
+ return dbType;
}
@Override
@@ -89,19 +75,12 @@ public class RollbackManager {
return true;
}
};
- Either<RollbackHandler, MethodActivationStatusEnum> result = addRollbackHandler(rollbackHandler);
-
- return result;
+ return addRollbackHandler(rollbackHandler);
}
protected Either<RollbackHandler, MethodActivationStatusEnum> getRollbackHandler(DBTypeEnum dbType) {
- Either<RollbackHandler, MethodActivationStatusEnum> result;
- if (rollBackHandlersMap.containsKey(dbType)) {
- result = Either.left(rollBackHandlersMap.get(dbType));
- } else {
- result = Either.right(MethodActivationStatusEnum.NOT_FOUND);
- }
- return result;
+ // need to swap here because the uses of Either in SDC appears to be opposite of convention
+ // by convention left is failure; in SDC right is failure
+ return rollbackHandlersMap.get(dbType).toEither(MethodActivationStatusEnum.NOT_FOUND).swap();
}
-
}
diff --git a/catalog-be/src/main/resources/config/SDC.zip b/catalog-be/src/main/resources/config/SDC.zip
index 674f6f86b4..6df1b13f2b 100644
--- a/catalog-be/src/main/resources/config/SDC.zip
+++ b/catalog-be/src/main/resources/config/SDC.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/config/configuration.yaml b/catalog-be/src/main/resources/config/configuration.yaml
index c9ebfd2e9f..5242652188 100644
--- a/catalog-be/src/main/resources/config/configuration.yaml
+++ b/catalog-be/src/main/resources/config/configuration.yaml
@@ -23,7 +23,7 @@ beSslPort: 8443
version: 1.0
released: 2012-11-30
-toscaConformanceLevel: 3.0
+toscaConformanceLevel: 4.0
minToscaConformanceLevel: 3.0
titanCfgFile: /home/vagrant/catalog-be/config/catalog-be/titan.properties
@@ -41,7 +41,6 @@ esReconnectIntervalInSeconds: 3
uebHealthCheckReconnectIntervalInSeconds: 15
uebHealthCheckReadTimeout: 4
-
# Protocols
protocols:
- http
@@ -75,7 +74,7 @@ neo4j:
cassandraConfig:
cassandraHosts: ['localhost']
- localDataCenter:
+ localDataCenter: datacenter1
reconnectTimeout : 30000
authenticate: false
username: koko
@@ -87,6 +86,7 @@ cassandraConfig:
- { name: sdcaudit, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
- { name: sdcartifact, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
- { name: sdccomponent, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
+ - { name: sdcrepository, replicationStrategy: SimpleStrategy, replicationInfo: ['1']}
#Application-specific settings of ES
elasticSearch:
@@ -147,6 +147,7 @@ resourceTypes: &allResourceTypes
- VF
- VFCMT
- Abstract
+ - CVFC
# validForResourceTypes usage
# validForResourceTypes:
@@ -195,6 +196,8 @@ toscaArtifacts:
#Informational artifacts placeHolder
excludeResourceCategory:
- Generic
+excludeResourceType:
+ - PNF
informationalResourceArtifacts:
features:
displayName: Features
@@ -303,6 +306,10 @@ serviceDeploymentArtifacts:
MODEL_QUERY_SPEC:
acceptedTypes:
- xml
+ UCPE_LAYER_2_CONFIGURATION:
+ acceptedTypes:
+ - xml
+
#AAI Artifacts
AAI_SERVICE_MODEL:
acceptedTypes:
@@ -500,7 +507,15 @@ resourceInformationalArtifacts:
validForResourceTypes: *allResourceTypes
OTHER:
acceptedTypes:
- validForResourceTypes: *allResourceTypes
+ validForResourceTypes:
+ - VFC
+ - CVFC
+ - CP
+ - VL
+ - VF
+ - VFCMT
+ - Abstract
+ - PNF
SNMP_POLL:
acceptedTypes:
validForResourceTypes: *allResourceTypes
@@ -512,6 +527,7 @@ resourceInformationalArtifacts:
validForResourceTypes:
- VF
- VFC
+ - CVFC
resourceInformationalDeployedArtifacts:
@@ -538,6 +554,7 @@ onboarding:
host: localhost
port: 8080
downloadCsarUri: "/onboarding-api/v1.0/vendor-software-products/packages"
+ healthCheckUri: "/onboarding-api/v1.0/healthcheck"
switchoverDetector:
gBeFqdn: AIO-BE.ecomp.idns.cip.com
@@ -597,5 +614,7 @@ vfModuleProperties:
genericAssetNodeTypes:
VFC: org.openecomp.resource.abstract.nodes.VFC
+ CVFC: org.openecomp.resource.abstract.nodes.VFC
VF : org.openecomp.resource.abstract.nodes.VF
+ PNF: org.openecomp.resource.abstract.nodes.PNF
Service: org.openecomp.resource.abstract.nodes.service
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index 4985ab552a..62bd7206ba 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -12,103 +12,103 @@ errors:
code: 204,
message: "No Content"
}
-#--------POL4050-----------------------------
+#--------POL4050-----------------------------
NOT_ALLOWED: {
code: 405,
message: "Error: Method not allowed.",
messageId: "POL4050"
}
-#--------POL5000-----------------------------
+#--------POL5000-----------------------------
GENERAL_ERROR: {
code: 500,
message: "Error: Internal Server Error. Please try again later.",
messageId: "POL5000"
}
-#---------POL5001------------------------------
+#---------POL5001------------------------------
MISSING_X_ECOMP_INSTANCE_ID: {
code: 400 ,
message: "Error: Missing 'X-ECOMP-InstanceID' HTTP header.",
messageId: "POL5001"
}
-#---------POL5002------------------------------
+#---------POL5002------------------------------
AUTH_REQUIRED: {
code: 401 ,
message: "Error: Authentication is required to use the API.",
messageId: "POL5002"
}
-#---------POL5003------------------------------
+#---------POL5003------------------------------
AUTH_FAILED: {
code: 403 ,
message: "Error: Not authorized to use the API.",
messageId: "POL5003"
}
-#---------POL5004------------------------------
+#---------POL5004------------------------------
MISSING_USER_ID: {
code: 400 ,
message: "Error: Missing 'USER_ID' HTTP header.",
messageId: "POL5004"
}
-#---------SVC4000-----------------------------
+#---------SVC4000-----------------------------
INVALID_CONTENT: {
code: 400,
message: "Error: Invalid content.",
messageId: "SVC4000"
}
-#---------SVC4002-----------------------------
+#---------SVC4002-----------------------------
MISSING_INFORMATION: {
code: 403,
message: "Error: Missing information.",
messageId: "SVC4002"
}
-#---------SVC4003------------------------------
-# %1 - Users's ID
+#---------SVC4003------------------------------
+# %1 - Users's ID
USER_NOT_FOUND: {
code: 404,
message: "Error: User '%1' was not found.",
messageId: "SVC4003"
}
-#---------SVC4004-----------------------------
-# %1 - Users's email address
+#---------SVC4004-----------------------------
+# %1 - Users's email address
INVALID_EMAIL_ADDRESS: {
code: 400,
message: "Error: Invalid email address '%1'.",
messageId: "SVC4004"
}
-#---------SVC4005------------------------------
+#---------SVC4005------------------------------
# %1 - role
INVALID_ROLE: {
code: 400,
message: "Error: Invalid role '%1'.",
messageId: "SVC4005"
}
-#---------SVC4006------------------------------
-# %1 - Users's USER_ID
+#---------SVC4006------------------------------
+# %1 - Users's USER_ID
USER_ALREADY_EXIST: {
code: 409,
message: "Error: User with '%1' ID already exists.",
messageId: "SVC4006"
}
-#---------SVC4007------------------------------
+#---------SVC4007------------------------------
DELETE_USER_ADMIN_CONFLICT: {
code: 409,
message: "Error: An administrator can only be deleted by another administrator.",
messageId: "SVC4007"
}
-#---------SVC4008-----------------------------
-# %1 - Users's userId
+#---------SVC4008-----------------------------
+# %1 - Users's userId
INVALID_USER_ID: {
code: 400,
message: "Error: Invalid userId '%1'.",
messageId: "SVC4008"
}
-#---------SVC4049------------------------------
+#---------SVC4049------------------------------
# %1 - service/resource
COMPONENT_MISSING_CONTACT: {
code: 400,
message: "Error: Invalid Content. Missing %1 contact.",
messageId: "SVC4049"
- }
-#---------SVC4050-----------------------------
+ }
+#---------SVC4050-----------------------------
# %1 - Service/Resource/Additional parameter
# %2 - service/resource/label name
COMPONENT_NAME_ALREADY_EXIST: {
@@ -116,90 +116,90 @@ errors:
message: "Error: %1 with name '%2' already exists.",
messageId: "SVC4050"
}
-#---------SVC4051------------------------------
-# %1 - resource/service
+#---------SVC4051------------------------------
+# %1 - resource/service
COMPONENT_MISSING_CATEGORY: {
code: 400,
message: "Error: Invalid Content. Missing %1 category.",
messageId: "SVC4051"
}
-#---------SVC4052------------------------------
+#---------SVC4052------------------------------
COMPONENT_MISSING_TAGS: {
code: 400,
message: "Error: Invalid Content. At least one tag has to be specified.",
messageId: "SVC4052"
}
-#---------SVC4053------------------------------
+#---------SVC4053------------------------------
# %1 - service/resource
COMPONENT_MISSING_DESCRIPTION: {
code: 400,
message: "Error: Invalid Content. Missing %1 description.",
messageId: "SVC4053"
}
-#---------SVC4054------------------------------
+#---------SVC4054------------------------------
# %1 - resource/service
COMPONENT_INVALID_CATEGORY: {
code: 400,
message: "Error: Invalid Content. Invalid %1 category.",
messageId: "SVC4054"
}
-#---------SVC4055------------------------------
+#---------SVC4055------------------------------
MISSING_VENDOR_NAME: {
code: 400,
message: "Error: Invalid Content. Missing vendor name.",
messageId: "SVC4055"
}
-#---------SVC4056------------------------------
+#---------SVC4056------------------------------
MISSING_VENDOR_RELEASE: {
code: 400,
message: "Error: Invalid Content. Missing vendor release.",
messageId: "SVC4056"
}
-#---------SVC4057------------------------------
+#---------SVC4057------------------------------
MISSING_DERIVED_FROM_TEMPLATE: {
code: 400,
message: "Error: Invalid Content. Missing derived from template specification.",
messageId: "SVC4057"
}
-#---------SVC4058------------------------------
+#---------SVC4058------------------------------
# %1 - service/resource
COMPONENT_MISSING_ICON: {
code: 400,
message: "Error: Invalid Content. Missing %1 icon.",
messageId: "SVC4058"
}
-#---------SVC4059------------------------------
+#---------SVC4059------------------------------
# %1 - service/resource
COMPONENT_INVALID_ICON: {
code: 400,
message: "Error: Invalid Content. Invalid %1 icon.",
messageId: "SVC4059"
}
-#---------SVC4060------------------------------
+#---------SVC4060------------------------------
PARENT_RESOURCE_NOT_FOUND: {
code: 400,
message: "Error: Invalid Content. Derived from resource template was not found.",
messageId: "SVC4060"
}
-#---------SVC4061------------------------------
+#---------SVC4061------------------------------
MULTIPLE_PARENT_RESOURCE_FOUND: {
code: 400,
message: "Error: Invalid Content. Multiple derived from resource template is not allowed.",
messageId: "SVC4061"
}
-#---------SVC4062------------------------------
+#---------SVC4062------------------------------
# %1 - service/resource
MISSING_COMPONENT_NAME: {
code: 400,
message: "Error: Invalid Content. Missing %1 name.",
messageId: "SVC4062"
}
-#---------SVC4063------------------------------
+#---------SVC4063------------------------------
#%1  -  resource/service name
RESOURCE_NOT_FOUND: {
code: 404,
@@ -207,51 +207,51 @@ errors:
messageId: "SVC4063"
}
-#---------SVC4064------------------------------
+#---------SVC4064------------------------------
# %1 - Service/Resource/Property
COMPONENT_INVALID_DESCRIPTION: {
code: 400,
message: "Error: Invalid Content. %1 description contains non-english characters.",
messageId: "SVC4064"
}
-#---------SVC4065------------------------------
+#---------SVC4065------------------------------
# %1 - Service/Resource/Property
-# %2 - max resource/service name length
+# %2 - max resource/service name length
COMPONENT_DESCRIPTION_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 description exceeds limit of %2 characters.",
messageId: "SVC4065"
}
-#---------SVC4066------------------------------
-# %1 - max length
+#---------SVC4066------------------------------
+# %1 - max length
COMPONENT_TAGS_EXCEED_LIMIT: {
code: 400,
message: "Error: Invalid Content. Tags overall length exceeds limit of %1 characters.",
messageId: "SVC4066"
}
#---------SVC4067------------------------------
-# %1 - max length
+# %1 - max length
VENDOR_NAME_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Vendor name exceeds limit of %1 characters.",
messageId: "SVC4067"
}
#---------SVC4068------------------------------
-# %1 - max length
+# %1 - max length
VENDOR_RELEASE_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Vendor release exceeds limit of %1 characters.",
messageId: "SVC4068"
}
-#---------SVC4069------------------------------
+#---------SVC4069------------------------------
# %1 - Service/Resource/Product
COMPONENT_INVALID_CONTACT: {
code: 400,
message: "Error: Invalid Content. %1 Contact Id should be in format 'mnnnnnn' or 'aannna' or 'aannnn', where m=m ,a=a-zA-Z and n=0-9",
messageId: "SVC4069"
}
-#---------SVC4070------------------------------
+#---------SVC4070------------------------------
# %1 - Service/Resource
INVALID_COMPONENT_NAME: {
code: 400,
@@ -259,27 +259,27 @@ errors:
messageId: "SVC4070"
}
-#---------SVC4071------------------------------
+#---------SVC4071------------------------------
INVALID_VENDOR_NAME: {
code: 400,
message: 'Error: Invalid Content. Vendor name is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
messageId: "SVC4071"
}
-#---------SVC4072------------------------------
+#---------SVC4072------------------------------
INVALID_VENDOR_RELEASE: {
code: 400,
message: 'Error: Invalid Content. Vendor release is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
messageId: "SVC4072"
}
-#---------SVC4073------------------------------
+#---------SVC4073------------------------------
# %1 - Service/Resource
-# %2 - max resource/service name
+# %2 - max resource/service name
COMPONENT_NAME_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 name exceeds limit of %2 characters.",
messageId: "SVC4073"
}
-#---------SVC4080------------------------------
+#---------SVC4080------------------------------
# %1 - resource/service name
# %2 - resource/service
# %3 - First name of last modifier
@@ -290,7 +290,7 @@ errors:
message: "Error: Requested '%1' %2 is locked for modification by %3 %4(%5).",
messageId: "SVC4080"
}
-#---------SVC4081-----------------------------
+#---------SVC4081-----------------------------
# %1 - resource/service name
# %2 - resource/service
# %3 - First name of last modifier
@@ -302,7 +302,7 @@ errors:
messageId: "SVC4081"
}
-#-----------SVC4082---------------------------
+#-----------SVC4082---------------------------
# %1 - resource/service name
# %2 - resource/service
# %3 - First name of last modifier
@@ -392,7 +392,7 @@ errors:
}
#-----------SVC4102---------------------------
-# %1 - capability type name
+# %1 - capability type name
CAPABILITY_TYPE_ALREADY_EXIST: {
code: 409,
message: "Error: Capability Type with name '%1' already exists.",
@@ -405,7 +405,7 @@ errors:
messageId: "SVC4114"
}
#-----------SVC4115---------------------------
-# %1 - capability type name
+# %1 - capability type name
MISSING_CAPABILITY_TYPE: {
code: 400,
message: "Error: Invalid Content. Missing Capability Type '%1'.",
@@ -483,7 +483,7 @@ errors:
message: "Error: Artifact '%1' already exists.",
messageId: "SVC4125"
}
-#---------SVC4126------------------------------
+#---------SVC4126------------------------------
# %1 - resource/service/product/...
# %2 - field (tag, vendor name...)
INVALID_FIELD_FORMAT: {
@@ -518,7 +518,7 @@ errors:
#-----------SVC4131---------------------------
# %1-resource/service
# %2-srtifact/artifacts
-# %3-semicolomn separated list of artifact
+# %3-semicolomn separated list of artifact
COMPONENT_MISSING_MANDATORY_ARTIFACTS: {
code: 403,
message: "Error: Missing mandatory informational %1 %2: [%3].",
@@ -545,60 +545,60 @@ errors:
message: "Error: Invalid Content. Missing interface life-cycle type.",
messageId: "SVC4134"
}
-#---------SVC4135------------------------------
+#---------SVC4135------------------------------
SERVICE_CATEGORY_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Service category cannot be changed once the service is certified.",
messageId: "SVC4135"
}
-#---------SVC4136------------------------------
-# %1 - distribution environment name
+#---------SVC4136------------------------------
+# %1 - distribution environment name
DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE: {
code: 500,
message: "Error: Requested distribution environment '%1' is not available.",
messageId: "SVC4136"
}
-#---------SVC4137------------------------------
-# %1 - distribution environment name
+#---------SVC4137------------------------------
+# %1 - distribution environment name
DISTRIBUTION_ENVIRONMENT_NOT_FOUND: {
code: 400,
message: "Error: Requested distribution environment '%1' was not found.",
messageId: "SVC4137"
}
-#---------SVC4138------------------------------
+#---------SVC4138------------------------------
DISTRIBUTION_ENVIRONMENT_INVALID: {
code: 400,
message: "Error: Invalid distribution environment.",
messageId: "SVC4138"
}
-#---------SVC4139------------------------------
+#---------SVC4139------------------------------
# %1 - service name
DISTRIBUTION_ARTIFACT_NOT_FOUND: {
code: 409,
message: "Error: Service '%1' cannot be distributed due to missing deployment artifacts.",
messageId: "SVC4139"
}
-#---------SVC4200------------------------------
+#---------SVC4200------------------------------
# %1 - Service/Resource
-# %2 - max icon name length
+# %2 - max icon name length
COMPONENT_ICON_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 icon name exceeds limit of %2 characters.",
messageId: "SVC4200"
}
-#---------SVC4300------------------------------
+#---------SVC4300------------------------------
RESTRICTED_ACCESS: {
code: 403,
message: "Error: Restricted access.",
messageId: "SVC4300"
}
-#---------SVC4301------------------------------
+#---------SVC4301------------------------------
RESTRICTED_OPERATION: {
code: 409,
message: "Error: Restricted operation.",
messageId: "SVC4301"
}
-#---------SVC4500------------------------------
+#---------SVC4500------------------------------
MISSING_BODY: {
code: 400 ,
message: "Error: Missing request body.",
@@ -610,7 +610,7 @@ errors:
message: "Error: Invalid Content. Missing mandatory parameter 'apiPublicKey'." ,
messageId: "SVC4501"
}
-#---------SVC4502------------------------------
+#---------SVC4502------------------------------
DISTRIBUTION_ENV_DOES_NOT_EXIST: {
code: 400 ,
message: "Error: Invalid Body : Missing mandatory parameter 'distrEnvName'." ,
@@ -624,7 +624,7 @@ errors:
messageId: "SVC4503"
}
-#---------SVC4504------------------------------
+#---------SVC4504------------------------------
# %1 - Service/Resource
# %2 - service/resource version
COMPONENT_VERSION_NOT_FOUND: {
@@ -634,103 +634,103 @@ errors:
}
#-----------SVC4505---------------------------
#%1-artifact name
-
+
ARTIFACT_NOT_FOUND: {
code: 404,
message: "Error: Artifact '%1' was not found.",
messageId: "SVC4505"
}
-#---------SVC4506------------------------------
+#---------SVC4506------------------------------
MISSING_ENV_NAME: {
code: 400 ,
message: "Error: Invalid Content. Missing mandatory parameter 'distrEnvName'.",
messageId: "SVC4506"
}
-#---------SVC4507------------------------------
+#---------SVC4507------------------------------
COMPONENT_INVALID_TAGS_NO_COMP_NAME: {
code: 400,
message: "Error: Invalid Content. One of the tags should be the component name.",
messageId: "SVC4507"
}
-
-#---------SVC4508------------------------------
+
+#---------SVC4508------------------------------
SERVICE_NAME_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Service name cannot be changed once the service is certified.",
messageId: "SVC4508"
}
-#---------SVC4509------------------------------
+#---------SVC4509------------------------------
SERVICE_ICON_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Icon cannot be changed once the service is certified.",
messageId: "SVC4509"
}
-#---------SVC4510------------------------------
+#---------SVC4510------------------------------
# %1 - icon name max length
SERVICE_ICON_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Icon name exceeds limit of %1 characters.",
messageId: "SVC4510"
}
-#---------SVC4511------------------------------
+#---------SVC4511------------------------------
DISTRIBUTION_REQUESTED_NOT_FOUND: {
code: 404,
message: "Error: Requested distribution was not found.",
messageId: "SVC4511"
}
-#---------SVC4512------------------------------
+#---------SVC4512------------------------------
# %1 - Distribution ID
DISTRIBUTION_REQUESTED_FAILED: {
code: 403,
message: "Error: Requested distribution '%1' failed.",
messageId: "SVC4512"
}
-#---------SVC4513------------------------------
+#---------SVC4513------------------------------
RESOURCE_CATEGORY_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Resource category cannot be changed once the resource is certified.",
messageId: "SVC4513"
}
-#---------SVC4514------------------------------
+#---------SVC4514------------------------------
RESOURCE_NAME_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Resource name cannot be changed once the resource is certified.",
messageId: "SVC4514"
}
-#---------SVC4515------------------------------
+#---------SVC4515------------------------------
RESOURCE_ICON_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Icon cannot be changed once the resource is certified.",
messageId: "SVC4515"
}
-#---------SVC4516------------------------------
+#---------SVC4516------------------------------
RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Vendor name cannot be changed once the resource is certified.",
messageId: "SVC4516"
}
-#---------SVC4517------------------------------
+#---------SVC4517------------------------------
RESOURCE_DERIVED_FROM_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Derived from resource template cannot be changed once the resource is certified.",
messageId: "SVC4517"
}
-#---------SVC4518------------------------------
-# %1 - max length
+#---------SVC4518------------------------------
+# %1 - max length
COMPONENT_SINGLE_TAG_EXCEED_LIMIT: {
code: 400,
message: "Error: Invalid Content. Single tag exceeds limit of %1 characters.",
messageId: "SVC4518"
}
-#---------SVC4519------------------------------
+#---------SVC4519------------------------------
INVALID_DEFAULT_VALUE: {
code: 400,
message: "Error: mismatch in data-type occurred for property %1. data type is %2 and default value found is %3.",
messageId: "SVC4519"
}
-#---------SVC4520------------------------------
-# %1 - service or resource
+#---------SVC4520------------------------------
+# %1 - service or resource
ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED: {
code: 409,
message: "Error: Maximal number of additional %1 parameters was reached.",
@@ -742,7 +742,7 @@ errors:
message: "Error: Invalid Content. The Additional information label and value cannot be empty.",
messageId: "SVC4521"
}
-#---------SVC4522------------------------------
+#---------SVC4522------------------------------
# %1 - label/value
# %2 - Maximal length of %1
ADDITIONAL_INFORMATION_EXCEEDS_LIMIT: {
@@ -762,32 +762,32 @@ errors:
message: "Error: Requested additional information was not found.",
messageId: "SVC4524"
}
-#---------SVC4525------------------------------
+#---------SVC4525------------------------------
ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS: {
code: 400,
message: 'Error: Invalid Content. Additional information contains non-english characters.',
messageId: "SVC4525"
}
-#---------SVC4526------------------------------
+#---------SVC4526------------------------------
RESOURCE_INSTANCE_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' resource instance was not found.",
messageId: "SVC4526"
}
-#---------SVC4527------------------------------
+#---------SVC4527------------------------------
ASDC_VERSION_NOT_FOUND: {
code: 500,
message: 'Error: ASDC version cannot be displayed.',
messageId: "SVC4527"
}
-#---------SVC4528------------------------------
+#---------SVC4528------------------------------
# %1-artifact url/artifact label/artifact description/VNF Service Indicator
MISSING_DATA: {
code: 400,
message: "Error: Invalid content. Missing %1.",
messageId: "SVC4528"
}
-#---------SVC4529------------------------------
+#---------SVC4529------------------------------
# %1-artifact url/artifact label/artifact description/artifact name
# %2 - Maximal length of %1
EXCEEDS_LIMIT: {
@@ -795,51 +795,51 @@ errors:
message: "Error: Invalid Content. %1 exceeds limit of %2 characters.",
messageId: "SVC4529"
}
-#---------SVC4530------------------------------
+#---------SVC4530------------------------------
ARTIFACT_INVALID_TIMEOUT: {
code: 400,
message: "Error: Invalid Content. Artifact Timeout should be set to valid positive non-zero number of minutes.",
messageId: "SVC4530"
}
-#---------SVC4531------------------------------
+#---------SVC4531------------------------------
SERVICE_IS_VNF_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: VNF Indicator cannot be updated for certified service.",
messageId: "SVC4531"
}
- #---------SVC4532------------------------------
+ #---------SVC4532------------------------------
RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE: {
code: 404,
message: "Error: Requested '%1' resource instance was not found on the service '%2.",
messageId: "SVC4532"
}
- #---------SVC4533------------------------------
- # %1 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"/"YANG_XML"
+ #---------SVC4533------------------------------
+ # %1 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"/"YANG_XML"
WRONG_ARTIFACT_FILE_EXTENSION: {
code: 400,
message: "Error: Invalid file extension for %1 artifact type.",
messageId: "SVC4533"
}
-#---------SVC4534------------------------------
-# %1 - "HEAT"/"HEAT_ENV"
+#---------SVC4534------------------------------
+# %1 - "HEAT"/"HEAT_ENV"
INVALID_YAML: {
code: 400,
message: "Error: Uploaded YAML file for %1 artifact is invalid.",
messageId: "SVC4534"
}
-#---------SVC4535------------------------------
-# %1 - "HEAT"
+#---------SVC4535------------------------------
+# %1 - "HEAT"
INVALID_DEPLOYMENT_ARTIFACT_HEAT: {
code: 400,
message: "Error: Invalid %1 artifact.",
messageId: "SVC4535"
}
-#---------SVC4536------------------------------
+#---------SVC4536------------------------------
# %1 - "Resource"/"Service"
-# %2 - resource/service name
-# %3 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"
+# %2 - resource/service name
+# %3 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"
# %4 - "HEAT"/"HEAT_ENV"/"MURANO_PKG
DEPLOYMENT_ARTIFACT_OF_TYPE_ALREADY_EXISTS: {
code: 400,
@@ -847,80 +847,80 @@ errors:
messageId: "SVC4536"
}
-#---------SVC4537------------------------------
+#---------SVC4537------------------------------
MISSING_HEAT: {
code: 400,
message: "Error: Missing HEAT artifact. HEAT_ENV artifact cannot be uploaded without corresponding HEAT template.",
messageId: "SVC4537"
}
-#---------SVC4538------------------------------
+#---------SVC4538------------------------------
MISMATCH_HEAT_VS_HEAT_ENV: {
code: 400,
message: "Error: Invalid artifact content. Parameter's set in HEAT_ENV '%1' artifact doesn't match the parameters in HEAT '%2' artifact.",
messageId: "SVC4538"
}
-#---------SVC4539------------------------------
+#---------SVC4539------------------------------
INVALID_RESOURCE_PAYLOAD: {
code: 400,
message: "Error: Invalid resource payload.",
messageId: "SVC4539"
}
-#---------SVC4540------------------------------
+#---------SVC4540------------------------------
INVALID_TOSCA_FILE_EXTENSION: {
code: 400,
message: "Error: Invalid file extension for TOSCA template.",
messageId: "SVC4540"
}
-#---------SVC4541------------------------------
+#---------SVC4541------------------------------
INVALID_YAML_FILE: {
code: 400,
message: "Error: Invalid YAML file.",
messageId: "SVC4541"
}
-#---------SVC4542------------------------------
+#---------SVC4542------------------------------
INVALID_TOSCA_TEMPLATE: {
code: 400,
message: "Error: Invalid TOSCA template.",
messageId: "SVC4542"
}
-#---------SVC4543------------------------------
+#---------SVC4543------------------------------
NOT_RESOURCE_TOSCA_TEMPLATE: {
code: 400,
message: "Error: Imported Service TOSCA template.",
messageId: "SVC4543"
}
-#---------SVC4544------------------------------
+#---------SVC4544------------------------------
NOT_SINGLE_RESOURCE: {
code: 400,
message: "Error: Imported TOSCA template should contain one resource definition.",
messageId: "SVC4544"
}
-#---------SVC4545------------------------------
+#---------SVC4545------------------------------
INVALID_RESOURCE_NAMESPACE: {
code: 400,
message: "Error: Invalid resource namespace.",
messageId: "SVC4545"
}
-#---------SVC4546------------------------------
+#---------SVC4546------------------------------
RESOURCE_ALREADY_EXISTS: {
code: 400,
message: "Error: Imported resource already exists in ASDC Catalog.",
messageId: "SVC4546"
}
-#---------SVC4549------------------------------
+#---------SVC4549------------------------------
INVALID_RESOURCE_CHECKSUM: {
code: 400,
message: "Error: Invalid resource checksum.",
messageId: "SVC4549"
}
-#---------SVC4550------------------------------
+#---------SVC4550------------------------------
#%1  -  Consumer salt
INVALID_LENGTH: {
code: 400,
message: "Error: Invalid %1 length.",
messageId: "SVC4550"
}
- #---------SVC4551------------------------------
+ #---------SVC4551------------------------------
#%1  -  ECOMP User name
ECOMP_USER_NOT_FOUND: {
code: 404,
@@ -934,13 +934,13 @@ errors:
messageId: "SVC4552"
}
#---------SVC4553-----------------------------
- #%1  -  Consumer name / Consumer password/ Consumer salt
+ #%1  -  Consumer name / Consumer password/ Consumer salt
INVALID_CONTENT_PARAM: {
code: 400,
message: "Error: %1 is invalid.",
messageId: "SVC4553"
}
- #---------SVC4554------------------------------
+ #---------SVC4554------------------------------
# %1 - "Resource"/"Service"
COMPONENT_ARTIFACT_NOT_FOUND: {
code: 404,
@@ -954,7 +954,7 @@ errors:
message: "Error: Requested '%1' service is not ready for certification. Service has to have at least one deployment artifact.",
messageId: "SVC4554"
}
-#---------SVC4555------------------------------
+#---------SVC4555------------------------------
#%1 - "Resource"/"Service"/"Product"
#%2 - "category"
COMPONENT_ELEMENT_INVALID_NAME_LENGTH: {
@@ -962,7 +962,7 @@ errors:
message: "Error: Invalid %1 %2 name length.",
messageId: "SVC4555"
}
-#---------SVC4556------------------------------
+#---------SVC4556------------------------------
#%1 - "Resource"/"Service"/"Product"
#%2 - "category"
COMPONENT_ELEMENT_INVALID_NAME_FORMAT: {
@@ -970,7 +970,7 @@ errors:
message: "Error: Invalid %1 %2 name format.",
messageId: "SVC4556"
}
-#---------SVC4557------------------------------
+#---------SVC4557------------------------------
#%1 - "Resource"/"Service"/"Product"
#%2 - "category name"
COMPONENT_CATEGORY_ALREADY_EXISTS: {
@@ -1001,7 +1001,7 @@ errors:
code: 403,
message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource. Please use one of available validated resource versions.",
messageId: "SVC4560"
- }
+ }
#---------SVC4561------------------------------
# %1 - "resource"/"product"
# %2 - "category"
@@ -1029,108 +1029,108 @@ errors:
message: "Error: %1 grouping '%2' already exists under '%3' sub-category.",
messageId: "SVC4563"
}
-#---------SVC4564------------------------------
+#---------SVC4564------------------------------
# %1 - product name
PRODUCT_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' product was not found.",
messageId: "SVC4564"
}
-#---------SVC4565------------------------------
-# %1 - "HEAT"
-# %2 - parameter type ("string" , "boolean" , "number")
+#---------SVC4565------------------------------
+# %1 - "HEAT"
+# %2 - parameter type ("string" , "boolean" , "number")
# %3 - parameter name
INVALID_HEAT_PARAMETER_VALUE: {
code: 400,
message: "Error: Invalid %1 artifact. Invalid %2 value set for '%3' parameter.",
messageId: "SVC4565"
}
-#---------SVC4566------------------------------
-# %1 - "HEAT"
-# %2 - parameter type ("string" , "boolean" , "number")
+#---------SVC4566------------------------------
+# %1 - "HEAT"
+# %2 - parameter type ("string" , "boolean" , "number")
INVALID_HEAT_PARAMETER_TYPE: {
code: 400,
message: "Error: Invalid %1 artifact. Unsupported '%2' parameter type.",
messageId: "SVC4566"
}
-#---------SVC4567------------------------------
-# %1 - "YANG_XML"
+#---------SVC4567------------------------------
+# %1 - "YANG_XML"
INVALID_XML: {
code: 400,
message: "Error: Uploaded XML file for %1 artifact is invalid.",
messageId: "SVC4567"
}
-#---------SVC4567------------------------------
-# %1 - "User Name and UserId"
+#---------SVC4567------------------------------
+# %1 - "User Name and UserId"
# %2 -"checked-out"/"in-certification"
CANNOT_DELETE_USER_WITH_ACTIVE_ELEMENTS: {
code: 409,
message: "Error: User cannot be deleted. User '%1' has %2 projects.",
messageId: "SVC4567"
}
-#---------SVC4568------------------------------
-# %1 - "User Name and UserId"
+#---------SVC4568------------------------------
+# %1 - "User Name and UserId"
# %2 -"checked-out"/"in-certification"
CANNOT_UPDATE_USER_WITH_ACTIVE_ELEMENTS: {
code: 409,
message: "Error: Role cannot be changed. User '%1' has %2 projects.",
messageId: "SVC4568"
}
-#---------SVC4570------------------------------
+#---------SVC4570------------------------------
UPDATE_USER_ADMIN_CONFLICT: {
code: 409,
message: "Error: An administrator is not allowed to change his/her role.",
messageId: "SVC4570"
}
-#---------SVC4571------------------------------
+#---------SVC4571------------------------------
SERVICE_CANNOT_CONTAIN_SUBCATEGORY: {
code: 400,
message: "Error: Sub category cannot be defined for service",
messageId: "SVC4571"
}
-#---------SVC4572------------------------------
+#---------SVC4572------------------------------
# %1 - "Resource"/"Service"
COMPONENT_TOO_MUCH_CATEGORIES: {
code: 400,
message: "Error: %1 must have only 1 category",
messageId: "SVC4572"
}
-#---------SVC4574------------------------------
+#---------SVC4574------------------------------
RESOURCE_TOO_MUCH_SUBCATEGORIES: {
code: 400,
message: "Error: Resource must have only 1 sub category",
messageId: "SVC4574"
}
-#---------SVC4575------------------------------
+#---------SVC4575------------------------------
COMPONENT_MISSING_SUBCATEGORY: {
code: 400,
message: "Error: Missing sub category",
messageId: "SVC4575"
}
- #---------SVC4576------------------------------
+ #---------SVC4576------------------------------
# %1 - "component type"
UNSUPPORTED_ERROR: {
code: 400,
message: "Error : Requested component type %1 is unsupported.",
messageId: "SVC4576"
}
- #---------SVC4577------------------------------
+ #---------SVC4577------------------------------
# %1 - "resource type"
RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES: {
code: 409,
message: "Error : Resource of type %1 cannot contain resource instances.",
messageId: "SVC4577"
}
-#---------SVC4578------------------------------
+#---------SVC4578------------------------------
# %1 - "Resource"/"Service"
-# %2 - resource/service name
-# %3 - "artifact name"
+# %2 - resource/service name
+# %3 - "artifact name"
DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS: {
code: 400,
message: "Error: %1 '%2' already has a deployment artifact named '%3'.",
messageId: "SVC4578"
}
-#---------SVC4579------------------------------
+#---------SVC4579------------------------------
# %1 - "Category"/"Sub-Category"/"Group"
# %2 - category/sub-category/grouping name.
INVALID_GROUP_ASSOCIATION: {
@@ -1138,27 +1138,27 @@ errors:
message: "Error: Invalid group association. %1 '%2' was not found.",
messageId: "SVC4579"
}
-#---------SVC4580------------------------------
+#---------SVC4580------------------------------
EMPTY_PRODUCT_CONTACTS_LIST: {
code: 400,
message: "Error: Invalid content. At least one Product Contact has to be specified.",
messageId: "SVC4580"
}
-#---------SVC4581------------------------------
+#---------SVC4581------------------------------
# %1 - UserId
INVALID_PRODUCT_CONTACT: {
code: 400,
message: "Error: Invalid content. User '%1' cannot be set as Product Contact.",
messageId: "SVC4581"
}
-#---------SVC4582------------------------------
+#---------SVC4582------------------------------
# %1 - Product
# %2 - "abbreviated"/"full"
MISSING_ONE_OF_COMPONENT_NAMES: {
code: 400,
message: "Error: Invalid content. Missing %1 %2 name.",
messageId: "SVC4582"
- }
+ }
#---------SVC4583------------------------------
# %1 - "Icon"
# %2 - "resource"/"service"/"product"
@@ -1168,10 +1168,10 @@ errors:
messageId: "SVC4583"
}
#---------SVC4584------------------------------
-# %1 - service/VF name
+# %1 - service/VF name
# %2 - "service" /"VF"
# %3 - resource instance origin type
-# %4 - resource instance name
+# %4 - resource instance name
# %5 - requirement/capability
# %6 - requirement/capability name
# %7 - "fulfilled" (for req)/"consumed (for cap)"
@@ -1180,57 +1180,57 @@ errors:
message: "Error: Requested '%1' %2 is not ready for certification. %3 '%4' has to have %5 '%6' %7.",
messageId: "SVC4584"
}
-#---------SVC4585------------------------------
+#---------SVC4585------------------------------
INVALID_OCCURRENCES: {
code: 400,
message: "Error: Invalid occurrences format.",
messageId: "SVC4585"
}
-#---------SVC4586------------------------------
-#---------SVC4586------------------------------
+#---------SVC4586------------------------------
+#---------SVC4586------------------------------
INVALID_SERVICE_API_URL: {
code: 400,
message: 'Error: Invalid Service API URL. Please check whether your URL has a valid domain extension and does not contain the following characters - #?&@%+;,=$<>~^`\[]{}|"*!',
messageId: "SVC4586"
}
-#---------SVC4587------------------------------
-# %1 - Data type name
+#---------SVC4587------------------------------
+# %1 - Data type name
DATA_TYPE_ALREADY_EXIST: {
code: 409,
message: 'Error: Data type %1 already exists.',
messageId: "SVC4587"
}
-#---------SVC4588------------------------------
-# %1 - Data type name
+#---------SVC4588------------------------------
+# %1 - Data type name
DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM: {
code: 400,
message: 'Error: Invalid Data type %1. Data type must have either a valid derived from declaration or at least one valid property',
messageId: "SVC4588"
}
-#---------SVC4589------------------------------
-# %1 - Data type name
+#---------SVC4589------------------------------
+# %1 - Data type name
DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY: {
code: 400,
message: "Error: Invalid Data type %1. 'properties' parameter cannot be empty if provided.",
messageId: "SVC4589"
}
-#---------SVC4590------------------------------
-# %1 - Property type name
+#---------SVC4590------------------------------
+# %1 - Property type name
# %2 - Property name
INVALID_PROPERTY_TYPE: {
code: 400,
message: "Error: Invalid Property type %1 in property %2.",
messageId: "SVC4590"
}
-#---------SVC4591------------------------------
+#---------SVC4591------------------------------
# %1 - Property inner type
-# %2 - Property name
+# %2 - Property name
INVALID_PROPERTY_INNER_TYPE: {
code: 400,
message: "Error: Invalid property inner type %1, in property %2",
messageId: "SVC4591"
}
-#---------SVC4592------------------------------
+#---------SVC4592------------------------------
# %1 - component instance name
# %2 - "resource instance"/"service instance"
COMPONENT_INSTANCE_NOT_FOUND: {
@@ -1238,11 +1238,11 @@ errors:
message: "Error: Requested '%1' %2 was not found.",
messageId: "SVC4592"
}
-#---------SVC4593------------------------------
+#---------SVC4593------------------------------
# %1 - component instance name
# %2 - "resource instance"/"service instance"
# %3 - "resource/"service"/"product"
-# %4 - container name
+# %4 - container name
COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER: {
code: 404,
message: "Error: Requested '%1' %2 was not found on the %3 '%4'.",
@@ -1259,20 +1259,20 @@ errors:
#---------SVC4595------------------------------
#%1 - requirement / capability
#%2 - requirement name
-#%3 - parent containing the requirement
+#%3 - parent containing the requirement
IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED: {
code: 400,
message: "Error: Imported TOSCA template contains %1 '%2' that is already defined by derived template %3.",
messageId: "SVC4595"
}
-#---------SVC4596------------------------------
+#---------SVC4596------------------------------
# %1 - Data type name
DATA_TYPE_DERIVED_IS_MISSING: {
code: 400,
message: "Error: Invalid Content. The ancestor data type %1 cannot be found in the system.",
messageId: "SVC4596"
}
-#---------SVC4597------------------------------
+#---------SVC4597------------------------------
# %1 - Data type name
# %2 - Property names
DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR: {
@@ -1280,14 +1280,14 @@ errors:
message: "Error: Invalid Content. The data type %1 contains properties named %2 which are already defined in one of its ancestors.",
messageId: "SVC4597"
}
-#---------SVC4598------------------------------
+#---------SVC4598------------------------------
# %1 - Data type name
DATA_TYPE_DUPLICATE_PROPERTY: {
code: 400,
message: "Error: Invalid Content. The data type %1 contains duplicate property.",
messageId: "SVC4598"
}
-#---------SVC4599------------------------------
+#---------SVC4599------------------------------
# %1 - Data type name
# %2 - Property names
DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE: {
@@ -1295,14 +1295,14 @@ errors:
message: "Error: Invalid Content. The data type %1 contains properties %2 which their type is this data type.",
messageId: "SVC4599"
}
-#---------SVC4600------------------------------
+#---------SVC4600------------------------------
# %1 - Data type name
DATA_TYPE_CANNOT_HAVE_PROPERTIES: {
code: 400,
message: "Error: Invalid Content. The data type %1 cannot have properties since it is of type scalar",
messageId: "SVC4600"
}
-#---------SVC4601------------------------------
+#---------SVC4601------------------------------
NOT_TOPOLOGY_TOSCA_TEMPLATE: {
code: 400,
message: "Error: TOSCA yaml file %1 cannot be modeled to VF as it does not contain 'topology_template.",
@@ -1317,7 +1317,7 @@ errors:
message: "Error: TOSCA yaml file '%1' contains node_template '%2' of type '%3' that does not represent existing VFC/CP/VL",
messageId: "SVC4602"
}
-#---------SVC4603------------------------------
+#---------SVC4603------------------------------
# %1 - component type
# %2 - component name
# %3 - state
@@ -1326,21 +1326,21 @@ errors:
message: "Error: Component instance of %1 can not be created because the component '%2' is in an illegal state %3.",
messageId: "SVC4603"
}
-#---------SVC4604------------------------------
+#---------SVC4604------------------------------
# %1 - csar file name
CSAR_INVALID: {
code: 400,
message: "Error: TOSCA CSAR '%1' is invalid. 'TOSCA-Metadata/Tosca.meta' file must be provided.",
messageId: "SVC4604"
}
-#---------SVC4605------------------------------
+#---------SVC4605------------------------------
# %1 - csar file name
CSAR_INVALID_FORMAT: {
code: 400,
message: "Error: TOSCA CSAR '%1' is invalid. Invalid 'TOSCA-Metadata/Tosca.meta' file format.",
messageId: "SVC4605"
}
-#---------SVC4606------------------------------
+#---------SVC4606------------------------------
# %1 - property name
# %2 - property type
# %3 - property innerType
@@ -1350,14 +1350,14 @@ errors:
message: "Error: Invalid default value of property %1. Data type is %2 with inner type %3 and default value found is %4.",
messageId: "SVC4606"
}
-#---------SVC4607------------------------------
+#---------SVC4607------------------------------
# %1 - csar file name
CSAR_NOT_FOUND: {
code: 400,
message: "Error: TOSCA CSAR '%1' is not found.",
messageId: "SVC4607"
}
-#---------SVC4608------------------------------
+#---------SVC4608------------------------------
# %1 - artifact name
# %2 - component type
# %3 - actual component type
@@ -1367,14 +1367,14 @@ errors:
messageId: "SVC4608"
}
-#---------SVC4609------------------------------
-# %1 - "INVALID_JSON"
+#---------SVC4609------------------------------
+# %1 - "INVALID_JSON"
INVALID_JSON: {
code: 400,
message: "Error: Uploaded JSON file for %1 artifact is invalid.",
messageId: "SVC4609"
}
-#---------SVC4610------------------------------
+#---------SVC4610------------------------------
# %1 - csar file name
# %2 - missing file name
YAML_NOT_FOUND_IN_CSAR: {
@@ -1382,21 +1382,21 @@ errors:
message: "Error - TOSCA CSAR %1 is invalid. TOSCA-Metadata/Tosca.meta refers to file %2 that is not provided.",
messageId: "SVC4610"
}
-#---------SVC4611------------------------------
+#---------SVC4611------------------------------
# %1 - group name
GROUP_MEMBER_EMPTY: {
code: 400,
message: "Error: Invalid Content. Group %1 member list was provided but does not have values",
messageId: "SVC4611"
}
-#---------SVC4612------------------------------
-# %1 - group name
+#---------SVC4612------------------------------
+# %1 - group name
GROUP_TYPE_ALREADY_EXIST: {
code: 409,
message: 'Error: Group type %1 already exists.',
messageId: "SVC4612"
}
-#---------SVC4613------------------------------
+#---------SVC4613------------------------------
# %1 - group name
# %2 - VF name(component name)
# %3 - actual component type [VF]
@@ -1404,15 +1404,15 @@ errors:
code: 409,
message: "Error: Group with name '%1' already exists in %2 %3.",
messageId: "SVC4613"
- }
-#---------SVC4614------------------------------
+ }
+#---------SVC4614------------------------------
# %1 - group type
GROUP_TYPE_IS_INVALID: {
code: 400,
message: "Error: Invalid content. Group type %1 does not exist",
messageId: "SVC4614"
}
-#---------SVC4615------------------------------
+#---------SVC4615------------------------------
# %1 - group name
GROUP_MISSING_GROUP_TYPE: {
code: 400,
@@ -1428,7 +1428,7 @@ errors:
code: 400,
message: "Error: Member '%1' listed in group '%2' is not part of '%3' %4.",
messageId: "SVC4616"
- }
+ }
#---------SVC4617------------------------------
# %1 - member name
# %2 - group name
@@ -1438,7 +1438,7 @@ errors:
message: "Error: member %1 listed in group %2 is not part of allowed members of group type %3.",
messageId: "SVC4617"
}
-#---------SVC4618------------------------------
+#---------SVC4618------------------------------
# %1 - missing file name
# %2 - csar file name
ARTIFACT_NOT_FOUND_IN_CSAR: {
@@ -1446,7 +1446,7 @@ errors:
message: "Error: artifact %1 is defined in CSAR %2 manifest but is not provided",
messageId: "SVC4618"
}
-#---------SVC4619------------------------------
+#---------SVC4619------------------------------
# %1 - artifact name
# %2 - artifact type
# %3 - existing artifact type
@@ -1455,23 +1455,23 @@ errors:
message: "Error: artifact %1 in type %2 already exists in type %3.",
messageId: "SVC4619"
}
-#---------SVC4620------------------------------
+#---------SVC4620------------------------------
FAILED_RETRIVE_ARTIFACTS_TYPES: {
code: 400,
message: "Error: Failed to retrieve list of suported artifact types.",
messageId: "SVC4620"
}
-#---------SVC4621------------------------------
+#---------SVC4621------------------------------
# %1 - artifact name
-# %2 - master
+# %2 - master
ARTIFACT_ALRADY_EXIST_IN_MASTER_IN_CSAR: {
code: 400,
message: "Error: artifact %1 already exists in master %2 .",
messageId: "SVC4621"
}
-#---------SVC4622------------------------------
+#---------SVC4622------------------------------
# %1 - artifact name
-# %2 - artifact type
+# %2 - artifact type
# %3 - master name
# %4 - master type
ARTIFACT_NOT_VALID_IN_MASTER: {
@@ -1479,9 +1479,9 @@ errors:
message: "Error: artifact %1 in type %2 can not be exists under master %3 in type %4.",
messageId: "SVC4622"
}
-#---------SVC4623------------------------------
+#---------SVC4623------------------------------
# %1 - artifact name
-# %2 - artifact type
+# %2 - artifact type
# %3 - env name
# %4 - existing env
ARTIFACT_NOT_VALID_ENV: {
@@ -1489,7 +1489,7 @@ errors:
message: "Error: Artifact %1 in type %2 with env %3 already exists with another env %4",
messageId: "SVC4623"
}
-#---------SVC4624------------------------------
+#---------SVC4624------------------------------
# %1 - groups names
# %2 - VF name
# %3 - component type [VF ]
@@ -1498,14 +1498,14 @@ errors:
message: "Error: Invalid Content. The groups '%1' cannot be found under %2 %3.",
messageId: "SVC4624"
}
-#---------SVC4625------------------------------
+#---------SVC4625------------------------------
# %1 - groups name
GROUP_ARTIFACT_ALREADY_ASSOCIATED: {
code: 400,
message: "Error: Invalid Content. Artifact already associated to group '%1'.",
messageId: "SVC4625"
}
-#---------SVC4626------------------------------
+#---------SVC4626------------------------------
# %1 - groups name
GROUP_ARTIFACT_ALREADY_DISSOCIATED: {
code: 400,
@@ -1521,7 +1521,7 @@ errors:
message: "Error: property %1 listed in group %2 is not exist in group type %3.",
messageId: "SVC4627"
}
-#---------SVC4628------------------------------
+#---------SVC4628------------------------------
# %1 - csarUUID
# %2 - VF name
VSP_ALREADY_EXISTS: {
@@ -1529,14 +1529,14 @@ errors:
message: "Error: The VSP with UUID %1 was already imported for VF %2. Please select another or update the existing VF.",
messageId: "SVC4628"
}
-#---------SVC4629------------------------------
+#---------SVC4629------------------------------
# %1 - VF name
MISSING_CSAR_UUID: {
code: 400,
message: "Error: The Csar UUID or payload name is missing for VF %1.",
messageId: "SVC4629"
}
-#---------SVC4630------------------------------
+#---------SVC4630------------------------------
# %1 - VF name
# %2 - new csarUUID
# %3 - old csarUUID
@@ -1545,8 +1545,8 @@ errors:
message: "Error: Resource %1 cannot be updated using CsarUUID %2 since the resource is linked to a different VSP with csarUUID %3.",
messageId: "SVC4630"
}
-#---------SVC4631------------------------------
-# %1 - policy name
+#---------SVC4631------------------------------
+# %1 - policy name
POLICY_TYPE_ALREADY_EXIST: {
code: 409,
message: "Error: Policy type %1 already exists.",
@@ -1593,7 +1593,7 @@ errors:
code: 404,
message: "Error: Requested '%1' attribute was not found.",
messageId: "SVC4637"
- }
+ }
#-----------SVC4638---------------------------
#%1 - attribute name
ATTRIBUTE_ALREADY_EXIST: {
@@ -1661,7 +1661,7 @@ errors:
message: "Error: Invalid Content. VF Module name '%1' contains invalid characters",
messageId: "SVC4646"
}
-
+
#---------SVC4647------------------------------
# %1 - "modifiedName"
INVALID_VF_MODULE_NAME_MODIFICATION: {
@@ -1699,23 +1699,23 @@ errors:
message: "Error: Once resource is certified, derived_from can be changed only to a sibling",
messageId: "SVC4651"
}
-#---------SVC4652------------------------------
+#---------SVC4652------------------------------
# %1 - resource/service
COMPONENT_INVALID_SUBCATEGORY: {
code: 400,
message: "Error: Invalid Content. Invalid %1 sub category.",
messageId: "SVC4652"
}
-#---------SVC4653------------------------------
-# %1 - group instance uniqueId
+#---------SVC4653------------------------------
+# %1 - group instance uniqueId
# %2 - service uniqueId
GROUP_INSTANCE_NOT_FOUND_ON_COMPONENT_INSTANCE: {
code: 404,
message: "Error: Requested group instance %1 was not found on component %2.",
messageId: "SVC4653"
}
-#---------SVC4654------------------------------
-# %1 - group property name
+#---------SVC4654------------------------------
+# %1 - group property name
# %2 - valid min limit value
# %3 - valid max limit value
INVALID_GROUP_MIN_MAX_INSTANCES_PROPERTY_VALUE: {
@@ -1723,8 +1723,8 @@ errors:
message: "Error: Value of %1 must be not higher than %2, and not lower than %3.",
messageId: "SVC4654"
}
-#---------SVC4655------------------------------
-# %1 - group property name
+#---------SVC4655------------------------------
+# %1 - group property name
# %2 - valid min limit value
# %3 - valid max limit value
INVALID_GROUP_INITIAL_COUNT_PROPERTY_VALUE: {
@@ -1732,15 +1732,15 @@ errors:
message: "Error: Value of %1 must be between %2 and %3.",
messageId: "SVC4655"
}
-#---------SVC4656------------------------------
-# %1 - group property name
+#---------SVC4656------------------------------
+# %1 - group property name
# %2 - lower/higher
# %3 - valid max/min value
INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER: {
code: 400,
message: "Error: Value of %1 must be %2 or equals to %3.",
messageId: "SVC4656"
- }
+ }
#---------SVC4657------------------------------
# %1 - certificationRequest / startTesting
RESOURCE_VFCMT_LIFECYCLE_STATE_NOT_VALID: {
@@ -1752,7 +1752,7 @@ errors:
# %1 – asset type [service / resource ]
# %2 – main asset uuid
# %3 – not found asset type [service / resource]
-# %4 – not found asset name
+# %4 – not found asset name
ASSET_NOT_FOUND_DURING_CSAR_CREATION: {
code: 400,
message: "Error: CSAR packaging failed for %1 %2. %3 %4 was not found",
@@ -1761,7 +1761,7 @@ errors:
#---------SVC4659------------------------------
# %1 – asset type [service / resource ]
# %2 – main asset uuid
-# %3 – Artifact name
+# %3 – Artifact name
# %4 – Artifact uuid
ARTIFACT_PAYLOAD_NOT_FOUND_DURING_CSAR_CREATION: {
code: 400,
@@ -1777,18 +1777,78 @@ errors:
messageId: "SVC4660"
}
#---------SVC4661------------------------------
-# %1 - version
-# %2 - conformance level
+# %1 - assetType
+# %2 - matching generic node type name
TOSCA_SCHEMA_FILES_NOT_FOUND: {
code: 400,
message: "Error: CSAR packaging failed. TOSCA schema files for SDC-Version: %1 and Conformance-Level %2 were not found",
messageId: "SVC4661"
}
-#---------SVC4662------------------------------
+#---------SVC4662------------------------------
# %1 - file name
# %2 - parser error
TOSCA_PARSE_ERROR: {
code: 400,
message: "Error: Invalid TOSCA template in file %1. %2",
messageId: "SVC4662"
+ }
+#---------SVC4663------------------------------
+# %1 - max length
+ RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Resource vendor model number exceeds limit of %1 characters.",
+ messageId: "SVC4663"
+ }
+#---------SVC4664------------------------------
+ INVALID_RESOURCE_VENDOR_MODEL_NUMBER: {
+ code: 400,
+ message: 'Error: Invalid Content. Resource vendor model number is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4664"
+ }
+#---------SVC4665------------------------------
+# %1 - max length
+ SERVICE_TYPE_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Service type exceeds limit of %1 characters.",
+ messageId: "SVC4665"
+ }
+#---------SVC4666------------------------------
+ INVALID_SERVICE_TYPE: {
+ code: 400,
+ message: 'Error: Invalid Content. Serivce type is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4666"
+ }
+#---------SVC4667------------------------------
+# %1 - max length
+ SERVICE_ROLE_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Service role exceeds limit of %1 characters.",
+ messageId: "SVC4667"
+ }
+#---------SVC4668------------------------------
+ INVALID_SERVICE_ROLE: {
+ code: 400,
+ message: 'Error: Invalid Content. Service role is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4668"
+ }
+
+#---------SVC4669-----------------------------
+ INVALID_RESOURCE_TYPE: {
+ code: 400,
+ message: "Error: Invalid resource type.",
+ messageId: "SVC4669"
+ }
+#---------SVC4670------------------------------
+ ARTIFACT_NAME_INVALID: {
+ code: 400,
+ message: "Error: Artifact name is invalid.",
+ messageId: "SVC4670"
+ }
+#---------SVC4671------------------------------
+# %1 - VSP name
+# %2 - VFC name
+ CFVC_LOOP_DETECTED: {
+ code: 400,
+ message: 'Error: VSP %1 cannot be imported. The VSP contains internal loop in VFC %2',
+ messageId: "SVC4671"
} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml
index 63d70c699e..da15414d9d 100644
--- a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml
+++ b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml
@@ -1196,4 +1196,57 @@ org.openecomp.datatypes.Naming:
type: string
required: false
+# NFoD
+org.openecomp.datatypes.flavors.ComputeFlavor:
+ derived_from: tosca.datatypes.Root
+ properties:
+ num_cpus:
+ type: integer
+ disk_size:
+ type: scalar-unit.size
+ mem_size:
+ type: scalar-unit.size
+
+org.openecomp.datatypes.flavors.LicenseFlavor:
+ derived_from: tosca.datatypes.Root
+ properties:
+ feature_group_uuid:
+ type: string
+
+org.openecomp.datatypes.flavors.VendorInfo:
+ derived_from: tosca.datatypes.Root
+ properties:
+ manufacturer_reference_number:
+ type: string
+ vendor_model:
+ type: string
+
+org.openecomp.datatypes.flavors.DeploymentFlavor:
+ derived_from: tosca.datatypes.Root
+ properties:
+ sp_part_number:
+ type: string
+ vendor_info:
+ type: org.openecomp.datatypes.flavors.VendorInfo
+ compute_flavor:
+ type: org.openecomp.datatypes.flavors.ComputeFlavor
+ license_flavor:
+ type: org.openecomp.datatypes.flavors.LicenseFlavor
+ required: false
+
+
+org.openecomp.datatypes.ImageInfo:
+ derived_from: tosca.datatypes.Root
+ properties:
+ software_version:
+ type: string
+ file_name:
+ type: string
+ file_hash:
+ type: string
+ description: checksum/signature
+ file_hash_type:
+ type: string
+ required: false
+ default: md5
diff --git a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zip b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zip
index 9c5964df1d..08d4bfc3a5 100644
--- a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zip
+++ b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types.zip b/catalog-be/src/main/resources/import/tosca/heat-types.zip
deleted file mode 100644
index ebb5afd09d..0000000000
--- a/catalog-be/src/main/resources/import/tosca/heat-types.zip
+++ /dev/null
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.json b/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.json
new file mode 100644
index 0000000000..cfa11dc3c7
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "Generic_PNF.yml",
+ "contactId": "jh0003",
+ "name": "Generic_PNF",
+ "description": "Represents a generic PNF.",
+ "resourceIconPath": "defaulticon",
+ "resourceType": "ABSTRACT",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "Generic_PNF"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.yml b/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.yml
new file mode 100644
index 0000000000..db3fc7cd3e
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.yml
@@ -0,0 +1,11 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resource.abstract.nodes.PNF:
+ derived_from: tosca.nodes.Root
+ properties:
+ nf_function:
+ type: string
+ nf_role:
+ type: string
+ nf_type:
+ type: string \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.zip b/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.zip
new file mode 100644
index 0000000000..fc5d706514
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/Generic_PNF/Generic_PNF.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.yml b/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.yml
index e73cafe100..9160a9ba22 100644
--- a/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.yml
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.yml
@@ -37,16 +37,16 @@ node_types:
subnetpoolid:
type: string
requirements:
- virtualLink:
- capability: tosca.capabilities.network.Linkable
- relationship: tosca.relationships.network.LinksTo
- virtualBinding:
- capability: tosca.capabilities.network.Bindable
- relationship: tosca.relationships.network.BindsTo
- external_virtualLink:
- capability: tosca.capabilities.network.Linkable
- relationship: tosca.relationships.network.LinksTo
- node: org.openecomp.resource.vl.VL
+ - virtualLink:
+ capability: tosca.capabilities.network.Linkable
+ relationship: tosca.relationships.network.LinksTo
+ - virtualBinding:
+ capability: tosca.capabilities.network.Bindable
+ relationship: tosca.relationships.network.BindsTo
+ - external_virtualLink:
+ capability: tosca.capabilities.network.Linkable
+ relationship: tosca.relationships.network.LinksTo
+ node: org.openecomp.resource.vl.VL
capabilities:
internal_connectionPoint:
type: tosca.capabilities.Node
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.zip b/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.zip
index a26c323819..5e18a2474a 100644
--- a/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.zip
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/extCp/extCp.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.json b/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.json
new file mode 100644
index 0000000000..1d27562aae
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "multiFlavorVFC.yml",
+ "contactId": "jh0003",
+ "name": "multiFlavorVFC",
+ "description": "Represents a generic multi flavor VFC.",
+ "resourceIconPath": "defaulticon",
+ "resourceType": "VFC",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "multiFlavorVFC"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.yml b/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.yml
new file mode 100644
index 0000000000..2df111d1c5
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.yml
@@ -0,0 +1,10 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resource.abstract.nodes.MultiFlavorVFC:
+ derived_from: org.openecomp.resource.abstract.nodes.VFC
+ properties:
+ images:
+ type: map
+ entry_schema:
+ type: org.openecomp.datatypes.ImageInfo
+ required: false
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.zip b/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.zip
new file mode 100644
index 0000000000..d73488d0c0
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/multiFlavorVFC/multiFlavorVFC.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.json b/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.json
new file mode 100644
index 0000000000..2a955ab955
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.json
@@ -0,0 +1,21 @@
+{
+ "payloadName": "vnfConfiguration.yml",
+ "contactId": "jh0003",
+ "name": "vnfConfiguration",
+ "description": "Configuration parameters for VNF",
+ "resourceIconPath": "vnfconfiguration",
+ "resourceType": "VFC",
+ "categories": [
+ {
+ "name": "Generic",
+ "subcategories": [
+ {
+ "name": "Abstract"
+ }
+ ]
+ }
+],
+ "tags": [
+ "vnfConfiguration"
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.yml b/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.yml
new file mode 100644
index 0000000000..4ee624615a
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.yml
@@ -0,0 +1,10 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+node_types:
+ org.openecomp.resource.abstract.nodes.VnfConfiguration:
+ derived_from: tosca.nodes.Root
+ properties:
+ allowed_flavors:
+ description: a collection of all flavor valuesets available for a given VFC
+ type: map
+ entry_schema:
+ type: org.openecomp.datatypes.flavors.DeploymentFlavor
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.zip b/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.zip
new file mode 100644
index 0000000000..03a7d535f2
--- /dev/null
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/vnfConfiguration/vnfConfiguration.zip
Binary files differ
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
index f65aefacf1..e7eaa8610b 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
@@ -37,7 +37,8 @@ def importHeatTypes(beHost, bePort, adminUser, fileDir, updateversion):
"eline",
"abstractSubstitute",
"Generic_VFC",
- "Generic_VF",
+ "Generic_VF",
+ "Generic_PNF",
"Generic_Service",
"contrailNetworkRules",
"contrailPort",
@@ -48,7 +49,9 @@ def importHeatTypes(beHost, bePort, adminUser, fileDir, updateversion):
"contrailCompute",
"contrailV2VirtualMachineInterface",
"subInterface",
- "contrailV2VLANSubInterface"
+ "contrailV2VLANSubInterface",
+ "multiFlavorVFC",
+ "vnfConfiguration"
]
responseCodes = [200, 201]
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json b/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json
new file mode 100644
index 0000000000..1ef72856a4
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json
@@ -0,0 +1,7 @@
+{
+ "heat": [
+ "Generic_PNF"
+ ],
+ "normative": [
+ ]
+} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py
new file mode 100644
index 0000000000..75afe33eba
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatAndNormativeTypes.py
@@ -0,0 +1,110 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importCommon import *
+from importNormativeTypes import *
+import importCommon
+import json
+
+
+################################################################################################################################################
+# #
+# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file #
+# #
+# activation : #
+# python upgradeHeatAndNormativeTypes.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): #
+# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+def upgradeTypesPerConfigFile(beHost, bePort, adminUser, baseDir, updateversion):
+ responseCodes = [200, 201]
+ if (updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+ with open("typesToUpgrade.json", 'r') as stream:
+ try:
+ types = json.load(stream)
+ heatTypes = types["heat"]
+ debug(heatTypes)
+ normativeTypes = types["normative"]
+ debug(normativeTypes)
+ heatFileDir = baseDir + "heat-types/"
+ debug(heatFileDir)
+ normativeFileDir = baseDir + "normative-types/"
+ debug(normativeFileDir)
+ results = []
+ for heatType in heatTypes:
+ result = createNormativeType(beHost, bePort, adminUser, heatFileDir, heatType.encode('ascii', 'ignore'), updateversion)
+ results.append(result)
+ if (result[1] == None or result[1] not in responseCodes):
+ print "Failed creating heat type " + heatType + ". " + str(result[1])
+ for normativeType in normativeTypes:
+ result = createNormativeType(beHost, bePort, adminUser, normativeFileDir, normativeType.encode('ascii', 'ignore'), updateversion)
+ results.append(result)
+ if (result[1] == None or result[1] not in responseCodes):
+ print "Failed creating normative type " + normativeType + ". " + str(result[1])
+ return results
+ except yaml.YAMLError as exc:
+ print(exc)
+
+
+
+def main(argv):
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ updateversion = 'true'
+
+ try:
+ opts, args = getopt.getopt(argv, "i:p:u:v:h:", ["ip=", "port=", "user=", "updateversion="])
+ except getopt.GetoptError:
+ usage()
+ errorAndExit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ # print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-v", "--updateversion"):
+ if (arg.lower() == "false" or arg.lower() == "no"):
+ updateversion = 'false'
+
+ print 'be host =', beHost, ', be port =', bePort, ', user =', adminUser
+
+ if (beHost == None):
+ usage()
+ sys.exit(3)
+
+ results = upgradeTypesPerConfigFile(beHost, bePort, adminUser, "../../../import/tosca/", updateversion)
+
+ print "-----------------------------"
+ for result in results:
+ print "{0:20} | {1:6}".format(result[0], result[1])
+ print "-----------------------------"
+
+ responseCodes = [200, 201]
+
+ if (updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
+ if (len(failedNormatives) > 0):
+ errorAndExit(1, None)
+ else:
+ errorAndExit(0, None)
+
+
+if __name__ == "__main__":
+ main(sys.argv[1:]) \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py
index 7c0746fb55..7315ec0635 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeHeatTypes1707.py
@@ -26,7 +26,8 @@ def upgradeHeatTypes1707(beHost, bePort, adminUser, fileDir, updateversion):
"extVl",
"extCp",
"Generic_VFC",
- "Generic_VF",
+ "Generic_VF",
+ "Generic_PNF",
"Generic_Service",
"globalPort",
"globalNetwork",
@@ -37,6 +38,8 @@ def upgradeHeatTypes1707(beHost, bePort, adminUser, fileDir, updateversion):
"contrailVirtualNetwork",
"neutronNet",
"neutronPort",
+ "multiFlavorVFC",
+ "vnfConfiguration"
]
responseCodes = [200, 201]
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
index 488d4d739d..085467e09a 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py
@@ -5,23 +5,28 @@ import json
import copy
import time
from importCategoryTypes import importCategories
-from upgradeHeatTypes1707 import upgradeHeatTypes1707
+from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile
from importDataTypes import importDataTypes
+from importPolicyTypes import importPolicyTypes
+from importGroupTypes import importGroupTypes
+from importNormativeCapabilities import importNormativeCapabilities
+from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
+
from importCommon import *
import importCommon
#################################################################################################################################################################################################
-# #
+# #
# Upgrades the normative types #
-# #
+# #
# activation : #
# python upgradeNormative.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>] #
# #
-# #
+# #
# shortest activation (be host = localhost, be port = 8080, user = jh0003): # # #
# python upgradeNormative.py #
-# #
+# #
#################################################################################################################################################################################################
def usage():
@@ -32,7 +37,7 @@ def handleResults(results, updateversion):
for result in results:
printNameAndReturnCode(result[0], result[1])
printFrameLine()
-
+
failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results)
if (len(failedResults) > 0):
errorAndExit(1, None)
@@ -40,23 +45,23 @@ def handleResults(results, updateversion):
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
- beHost = 'localhost'
+ beHost = 'localhost'
bePort = '8080'
adminUser = 'jh0003'
debugf = None
updateversion = 'true'
- importCommon.debugFlag = False
+ importCommon.debugFlag = False
try:
opts, args = getopt.getopt(argv,"i:p:u:d:h",["ip=","port=","user=","debug="])
except getopt.GetoptError:
usage()
errorAndExit(2, 'Invalid input')
-
+
for opt, arg in opts:
#print opt, arg
if opt == '-h':
- usage()
+ usage()
sys.exit(3)
elif opt in ("-i", "--ip"):
beHost = arg
@@ -73,13 +78,13 @@ def main(argv):
if (debugf != None):
print 'set debug mode to ' + str(debugf)
importCommon.debugFlag = debugf
-
+
if ( beHost == None ):
usage()
sys.exit(3)
print sys.argv[0]
- pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
+ pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))
debug("path dir =" + pathdir)
baseFileLocation = pathdir + "/../../../import/tosca/"
@@ -90,15 +95,25 @@ def main(argv):
fileLocation = baseFileLocation + "data-types/"
importDataTypes(beHost, bePort, adminUser, False, fileLocation)
+ fileLocation = baseFileLocation + "policy-types/"
+ importPolicyTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "group-types/"
+ importGroupTypes(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "capability-types/"
+ importNormativeCapabilities(beHost, bePort, adminUser, False, fileLocation)
+
+ fileLocation = baseFileLocation + "interface-lifecycle-types/"
+ importNormativeInterfaceLifecycleType(beHost, bePort, adminUser, False, fileLocation)
+
print 'sleep until data type cache is updated'
time.sleep( 70 )
- fileLocation = baseFileLocation + "heat-types/"
- resultsHeat = upgradeHeatTypes1707(beHost, bePort, adminUser, fileLocation, updateversion)
+ resultsHeat = upgradeTypesPerConfigFile(beHost, bePort, adminUser, baseFileLocation, updateversion)
handleResults(resultsHeat, 'false')
- errorAndExit(0, None)
+ errorAndExit(0, None)
if __name__ == "__main__":
main(sys.argv[1:])
-
diff --git a/catalog-be/src/main/webapp/WEB-INF/web.xml b/catalog-be/src/main/webapp/WEB-INF/web.xml
index 9b7a55a4dd..889b1fac60 100644
--- a/catalog-be/src/main/webapp/WEB-INF/web.xml
+++ b/catalog-be/src/main/webapp/WEB-INF/web.xml
@@ -77,7 +77,6 @@
<servlet-mapping>
<servlet-name>jerseyDistribution</servlet-name>
<url-pattern>/sdc/*</url-pattern>
- <url-pattern>/asdc/*</url-pattern>
</servlet-mapping>
<servlet>