diff options
Diffstat (limited to 'catalog-be/src')
13 files changed, 141 insertions, 50 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java index 2ab68e8db1..eefe47f69c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java @@ -592,7 +592,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { resource.setDeploymentArtifacts(createdArtifactsMap); if (groupName != null && !groupName.isEmpty()) { Either<GroupDefinition, ResponseFormat> groupDefinitionEither = buildGroupDefinition(createdArtifacts, heatGroups, groupTemplateInfo, - groupName, artifactsGroup, artifactsUUIDGroup); + groupName, artifactsGroup, artifactsUUIDGroup, resource.getModel()); if (groupDefinitionEither.isRight()) { return Either.right(groupDefinitionEither.right().value()); } @@ -611,7 +611,8 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { private Either<GroupDefinition, ResponseFormat> buildGroupDefinition(List<ArtifactDefinition> createdArtifacts, List<GroupDefinition> heatGroups, ArtifactTemplateInfo groupTemplateInfo, String groupName, - Set<String> artifactsGroup, Set<String> artifactsUUIDGroup) { + Set<String> artifactsGroup, Set<String> artifactsUUIDGroup, + String model) { Map<String, String> members = new HashMap<>(); associateMembersToArtifacts(createdArtifacts, null, heatGroups, artifactsGroup, members); List<String> artifactsList = new ArrayList<>(artifactsGroup); @@ -630,7 +631,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { prop.setValue(Boolean.toString(groupTemplateInfo.isBase())); properties.add(prop); Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation - .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true); + .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, model); if (getLatestGroupTypeRes.isRight()) { return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value()))); } @@ -1197,7 +1198,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { createdArtifacts.addAll(createdNewArtifacts); createdArtifacts.addAll(artifactsFromResource); Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation - .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true); + .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, resource.getModel()); if (getLatestGroupTypeRes.isRight()) { return Either .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value()))); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index e04a4011cc..5d4549406c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -135,9 +135,9 @@ public class YamlTemplateParsingHandler { findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName)); parsedToscaYamlInfo.setInputs(getInputs(mappedToscaTemplate)); parsedToscaYamlInfo.setInstances(getInstances(fileName, mappedToscaTemplate, createdNodesToscaResourceNames)); - parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate)); + parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate, component.getModel())); if (component instanceof Resource) { - parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate)); + parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate, component.getModel())); } log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName); return parsedToscaYamlInfo; @@ -176,15 +176,15 @@ public class YamlTemplateParsingHandler { return inputs; } - private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson) { + private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson, String model) { Map<String, Object> foundPolicies = findFirstToscaMapElement(toscaJson, POLICIES).left().on(err -> logPoliciesNotFound(fileName)); if (MapUtils.isNotEmpty(foundPolicies)) { - return foundPolicies.entrySet().stream().map(this::createPolicy).collect(Collectors.toMap(PolicyDefinition::getName, p -> p)); + return foundPolicies.entrySet().stream().map(policyToCreate -> createPolicy(policyToCreate, model)).collect(Collectors.toMap(PolicyDefinition::getName, p -> p)); } return Collections.emptyMap(); } - private PolicyDefinition createPolicy(Map.Entry<String, Object> policyNameValue) { + private PolicyDefinition createPolicy(Map.Entry<String, Object> policyNameValue, String model) { PolicyDefinition emptyPolicyDef = new PolicyDefinition(); String policyName = policyNameValue.getKey(); emptyPolicyDef.setName(policyName); @@ -192,7 +192,7 @@ public class YamlTemplateParsingHandler { // There's no need to null test in conjunction with an instanceof test. null is not an instanceof anything, so a null check is redundant. if (policyNameValue.getValue() instanceof Map) { Map<String, Object> policyTemplateJsonMap = (Map<String, Object>) policyNameValue.getValue(); - validateAndFillPolicy(emptyPolicyDef, policyTemplateJsonMap); + validateAndFillPolicy(emptyPolicyDef, policyTemplateJsonMap, model); } else { rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE); } @@ -208,7 +208,7 @@ public class YamlTemplateParsingHandler { return Collections.emptyMap(); } - private void validateAndFillPolicy(PolicyDefinition emptyPolicyDefinition, Map<String, Object> policyTemplateJsonMap) { + private void validateAndFillPolicy(PolicyDefinition emptyPolicyDefinition, Map<String, Object> policyTemplateJsonMap, String model) { String policyTypeName = (String) policyTemplateJsonMap.get(TYPE.getElementName()); if (StringUtils.isEmpty(policyTypeName)) { log.debug("#validateAndFillPolicy - The 'type' member is not found under policy {}", emptyPolicyDefinition.getName()); @@ -217,13 +217,13 @@ public class YamlTemplateParsingHandler { emptyPolicyDefinition.setType(policyTypeName); // set policy targets emptyPolicyDefinition.setTargets(validateFillPolicyTargets(policyTemplateJsonMap)); - PolicyTypeDefinition policyTypeDefinition = validateGetPolicyTypeDefinition(policyTypeName); + PolicyTypeDefinition policyTypeDefinition = validateGetPolicyTypeDefinition(policyTypeName, model); // set policy properties emptyPolicyDefinition.setProperties(validateFillPolicyProperties(policyTypeDefinition, policyTemplateJsonMap)); } - private PolicyTypeDefinition validateGetPolicyTypeDefinition(String policyType) { - PolicyTypeDefinition policyTypeDefinition = policyTypeBusinessLogic.getLatestPolicyTypeByType(policyType); + private PolicyTypeDefinition validateGetPolicyTypeDefinition(String policyType, String modelName) { + PolicyTypeDefinition policyTypeDefinition = policyTypeBusinessLogic.getLatestPolicyTypeByType(policyType, modelName); if (policyTypeDefinition == null) { log.debug("#validateAndFillPolicy - The policy type {} not found", policyType); rollbackWithException(ActionStatus.POLICY_TYPE_IS_INVALID, policyType); @@ -293,10 +293,10 @@ public class YamlTemplateParsingHandler { } @SuppressWarnings("unchecked") - private Map<String, GroupDefinition> getGroups(String fileName, Map<String, Object> toscaJson) { + private Map<String, GroupDefinition> getGroups(String fileName, Map<String, Object> toscaJson, String model) { Map<String, Object> foundGroups = findFirstToscaMapElement(toscaJson, GROUPS).left().on(err -> logGroupsNotFound(fileName)); if (MapUtils.isNotEmpty(foundGroups) && matcheKey(foundGroups)) { - Map<String, GroupDefinition> groups = foundGroups.entrySet().stream().map(this::createGroup) + Map<String, GroupDefinition> groups = foundGroups.entrySet().stream().map(groupToCreate -> createGroup(groupToCreate, model)) .collect(Collectors.toMap(GroupDefinition::getName, g -> g)); Map<String, Object> substitutionMappings = getSubstitutionMappings(toscaJson); if (capabilitiesSubstitutionMappingsExist(substitutionMappings)) { @@ -343,13 +343,13 @@ public class YamlTemplateParsingHandler { return substitutionMappings != null && substitutionMappings.containsKey(CAPABILITIES.getElementName()); } - private GroupDefinition createGroup(Map.Entry<String, Object> groupNameValue) { + private GroupDefinition createGroup(Map.Entry<String, Object> groupNameValue, String model) { GroupDefinition group = new GroupDefinition(); group.setName(groupNameValue.getKey()); try { if (groupNameValue.getValue() instanceof Map) { Map<String, Object> groupTemplateJsonMap = (Map<String, Object>) groupNameValue.getValue(); - validateAndFillGroup(group, groupTemplateJsonMap); + validateAndFillGroup(group, groupTemplateJsonMap, model); validateUpdateGroupProperties(group, groupTemplateJsonMap); validateUpdateGroupCapabilities(group, groupTemplateJsonMap); } else { @@ -443,14 +443,14 @@ public class YamlTemplateParsingHandler { } } - private void validateAndFillGroup(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap) { + private void validateAndFillGroup(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap, String model) { String type = (String) groupTemplateJsonMap.get(TYPE.getElementName()); if (StringUtils.isEmpty(type)) { log.debug("#validateAndFillGroup - The 'type' member is not found under group {}", groupInfo.getName()); rollbackWithException(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupInfo.getName()); } groupInfo.setType(type); - GroupTypeDefinition groupType = groupTypeBusinessLogic.getLatestGroupTypeByType(type); + GroupTypeDefinition groupType = groupTypeBusinessLogic.getLatestGroupTypeByType(type, model); if (groupType == null) { log.debug("#validateAndFillGroup - The group type {} not found", groupInfo.getName()); rollbackWithException(ActionStatus.GROUP_TYPE_IS_INVALID, type); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java index b4e1594a41..9a77aad0b2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java @@ -340,6 +340,95 @@ public class CommonImportManager { } } + protected <T> Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> createElementTypesWithVersionByDao(List<T> elementTypesToCreate, + Function<T, Either<ActionStatus, ResponseFormat>> validator, + Function<T, ImmutablePair<ElementTypeEnum, String>> elementInfoGetter, + BiFunction<String, String, Either<T, StorageOperationStatus>> elementFetcher, + Function<T, Either<T, StorageOperationStatus>> elementAdder, + BiFunction<T, T, Either<T, StorageOperationStatus>> elementUpgrader, + String modelName) { + + List<ImmutablePair<T, Boolean>> createdElementTypes = new ArrayList<>(); + + Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> eitherResult = Either.left(createdElementTypes); + Iterator<T> elementTypeItr = elementTypesToCreate.iterator(); + + try { + while (elementTypeItr.hasNext()) { + T elementType = elementTypeItr.next(); + eitherResult = handleTypeByDao(elementType, validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader, modelName) + .left() + .map(elem -> append(createdElementTypes, elem)); + + if (eitherResult.isRight()) { + break; + } + + if (!elementTypeItr.hasNext()) { + log.info("all {} were created successfully!!!", elementType); + } + } + } catch (Exception e) { + eitherResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); + throw e; + } finally { + if (eitherResult.isLeft()) { + propertyOperation.getJanusGraphGenericDao().commit(); + } else { + propertyOperation.getJanusGraphGenericDao().rollback(); + } + } + + return eitherResult; + } + + private <T> Either<ImmutablePair<T, Boolean>, ResponseFormat> handleTypeByDao(T elementType, + Function<T, Either<ActionStatus, ResponseFormat>> validator, + Function<T, ImmutablePair<ElementTypeEnum, String>> elementInfoGetter, + BiFunction<String, String, Either<T, StorageOperationStatus>> elementFetcher, + Function<T, Either<T, StorageOperationStatus>> elementAdder, + BiFunction<T, T, Either<T, StorageOperationStatus>> elementUpgrader, + String modelName) { + + final ImmutablePair<ElementTypeEnum, String> elementInfo = elementInfoGetter.apply(elementType); + ElementTypeEnum elementTypeEnum = elementInfo.left; + String elementName = elementInfo.right; + + Either<ActionStatus, ResponseFormat> validateElementType = validator.apply(elementType); + if (validateElementType.isRight()) { + ResponseFormat responseFormat = validateElementType.right().value(); + log.debug("Failed in validation of element type: {}. Response is {}", elementType, responseFormat.getFormattedMessage()); + return Either.right(responseFormat); + } + + log.info("send {} : {} to dao for create", elementTypeEnum, elementName); + + Either<T, StorageOperationStatus> findElementType = elementFetcher.apply(elementName, modelName); + if (findElementType.isRight()) { + StorageOperationStatus status = findElementType.right().value(); + log.debug("searched {} finished with result:{}", elementTypeEnum, status); + if (status != StorageOperationStatus.NOT_FOUND) { + ResponseFormat responseFormat = getResponseFormatForElementType(convertFromStorageResponseForElementType(status, elementTypeEnum), + elementTypeEnum, elementType); + return Either.right(responseFormat); + } else { + return addElementType(elementType, elementAdder, elementTypeEnum, elementName); + } + } else { + + if (elementUpgrader != null) { + return updateElementType(elementType, elementUpgrader, elementTypeEnum, elementName, findElementType.left().value()); + + } else { + // mshitrit Once GroupType Versions are supported add + // code here + log.debug("{} : {} already exists.", elementTypeEnum, elementName); + return Either.left(new ImmutablePair<>(elementType, false)); + } + + } + } + private <T> Either<ImmutablePair<T, Boolean>, ResponseFormat> addElementType(T elementType, Function<T, Either<T, StorageOperationStatus>> elementAdder, ElementTypeEnum elementTypeEnum, String elementName) { @@ -384,7 +473,7 @@ public class CommonImportManager { public <T extends ToscaTypeDataDefinition> Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> createElementTypes( ToscaTypeImportData toscaTypeImportData, BiFunction<String, String, Either<List<T>, ActionStatus>> elementTypeFromYmlCreater, - Function<List<T>, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater, String modelName) { + BiFunction<List<T>, String, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater, String modelName) { Either<List<T>, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(toscaTypeImportData.getToscaTypesYml(), modelName); return elementTypes .right() @@ -392,7 +481,7 @@ public class CommonImportManager { .left() .map(toscaTypes -> enrichTypesWithNonToscaMetadata(toscaTypes, toscaTypeImportData.getToscaTypeMetadata())) .left() - .bind(elementTypeDaoCreater::apply); + .bind(elementTypeList -> elementTypeDaoCreater.apply(elementTypeList, modelName)); } public <T extends ToscaDataDefinition> List<ImmutablePair<T, Boolean>> createElementTypes(String toscaTypesYml, 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 45d6b74f8d..0d85675c45 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 @@ -948,7 +948,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { public GroupDefinition createGroup(String componentId, ComponentTypeEnum componentTypeEnum, String groupType, String userId) { Component component = accessValidations.validateUserCanWorkOnComponent(componentId, componentTypeEnum, userId, CREATE_GROUP); validateGroupTypePerComponent(groupType, component); - GroupTypeDefinition groupTypeDefinition = groupTypeOperation.getLatestGroupTypeByType(groupType, false).left() + GroupTypeDefinition groupTypeDefinition = groupTypeOperation.getLatestGroupTypeByType(groupType, component.getModel(), false).left() .on(se -> onGroupTypeNotFound(component)); boolean hasExistingGroups = CollectionUtils.isNotEmpty(component.getGroups()); GroupDefinition groupDefinition = new GroupDefinition(); @@ -1240,7 +1240,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { if (StringUtils.isEmpty(groupType)) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupDefinitionName)); } - Either<GroupTypeDefinition, StorageOperationStatus> getGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType, true); + Either<GroupTypeDefinition, StorageOperationStatus> getGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType, component.getModel(), true); if (getGroupType.isRight()) { StorageOperationStatus status = getGroupType.right().value(); if (status == StorageOperationStatus.NOT_FOUND) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java index 823612e4e1..5ee62c0b19 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java @@ -69,8 +69,8 @@ public class GroupTypeBusinessLogic { } } - public GroupTypeDefinition getLatestGroupTypeByType(String groupTypeName) { - return groupTypeOperation.getLatestGroupTypeByType(groupTypeName, true).left().on(e -> failOnGetGroupType(e, groupTypeName)); + public GroupTypeDefinition getLatestGroupTypeByType(String groupTypeName, String modelName) { + return groupTypeOperation.getLatestGroupTypeByType(groupTypeName, modelName).left().on(e -> failOnGetGroupType(e, groupTypeName)); } public Set<String> getExcludedGroupTypes(String internalComponentType) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java index 8015685403..4983c0160f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java @@ -77,11 +77,11 @@ public class GroupTypeImportManager { } private Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> upsertGroupTypesByDao( - List<GroupTypeDefinition> groupTypesToCreate) { - return commonImportManager.createElementTypesByDao(groupTypesToCreate, this::validateGroupType, + List<GroupTypeDefinition> groupTypesToCreate, String modelName) { + return commonImportManager.createElementTypesWithVersionByDao(groupTypesToCreate, this::validateGroupType, groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, UniqueIdBuilder.buildGroupTypeUid(groupType.getModel(), groupType.getType(), groupType.getVersion(), NodeTypeEnum.GroupType.getName()).toLowerCase()), groupTypeOperation::getLatestGroupTypeByType, - groupTypeOperation::addGroupType, this::updateGroupType); + groupTypeOperation::addGroupType, this::updateGroupType, modelName); } private Either<GroupTypeDefinition, StorageOperationStatus> updateGroupType(GroupTypeDefinition newGroupType, GroupTypeDefinition oldGroupType) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java index 8c18d07495..f8aab3def1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java @@ -554,7 +554,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic { } private PolicyTypeDefinition validatePolicyTypeOnCreatePolicy(String policyTypeName, Component component) { - Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyTypeByType = policyTypeOperation.getLatestPolicyTypeByType(policyTypeName); + Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyTypeByType = policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, component.getModel()); if (latestPolicyTypeByType.isRight()) { throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(latestPolicyTypeByType.right().value())); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java index 99b56e7330..1e0a55fd07 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java @@ -60,8 +60,8 @@ public class PolicyTypeBusinessLogic { return getPolicyTypes(excludedPolicyTypes, modelName); } - public PolicyTypeDefinition getLatestPolicyTypeByType(String policyTypeName) { - return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName).left().on(e -> failOnPolicyType(e, policyTypeName)); + public PolicyTypeDefinition getLatestPolicyTypeByType(String policyTypeName, String modelName) { + return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, modelName).left().on(e -> failOnPolicyType(e, policyTypeName)); } public Set<String> getExcludedPolicyTypes(String internalComponentType) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java index 48519d9abe..d10680db0d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java @@ -77,11 +77,11 @@ public class PolicyTypeImportManager { } private Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> upsertPolicyTypesByDao( - List<PolicyTypeDefinition> policyTypesToCreate) { - return commonImportManager.createElementTypesByDao(policyTypesToCreate, this::validatePolicyType, + List<PolicyTypeDefinition> policyTypesToCreate, String modelName) { + return commonImportManager.createElementTypesWithVersionByDao(policyTypesToCreate, this::validatePolicyType, policyType -> new ImmutablePair<>(ElementTypeEnum.POLICY_TYPE, UniqueIdBuilder.buildPolicyTypeUid(policyType.getModel(), policyType.getType(), policyType.getVersion(), NodeTypeEnum.PolicyType.getName()).toLowerCase()), policyTypeOperation::getLatestPolicyTypeByType, - policyTypeOperation::addPolicyType, this::updatePolicyType); + policyTypeOperation::addPolicyType, this::updatePolicyType, modelName); } private Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyType(PolicyTypeDefinition newPolicyType, @@ -108,7 +108,7 @@ public class PolicyTypeImportManager { boolean isValid = toscaOperationFacade.getLatestByToscaResourceName(targetId).isLeft(); if (!isValid) { // check if it is a groupType final Either<GroupTypeDefinition, StorageOperationStatus> groupTypeFound = groupTypeOperation - .getLatestGroupTypeByType(targetId, false); + .getLatestGroupTypeByType(targetId, policyType.getModel(), false); isValid = groupTypeFound.isLeft() && !groupTypeFound.left().value().isEmpty(); } if (!isValid) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java index ebc5702913..2520e44aca 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java @@ -147,7 +147,7 @@ class GroupBusinessLogicTest { GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); Map<String, DataTypeDefinition> map = new HashMap<>(); when(dataTypeCache.getAll()).thenReturn(Either.left(map)); - when(groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true)).thenReturn(Either.left(groupTypeDefinition)); + when(groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, null, true)).thenReturn(Either.left(groupTypeDefinition)); when(groupsOperation.createGroups(any(Component.class), anyMap())).thenReturn(Either.left(groupDefinitions)); when(groupsOperation.addCalculatedCapabilitiesWithProperties(anyString(), anyMap(), anyMap())).thenReturn(StorageOperationStatus.OK); result = test.createGroups(component, groupDefinitions, true); @@ -213,9 +213,9 @@ class GroupBusinessLogicTest { List<PropertyDefinition> properties = asList( buildProperty("network_collection_type", "l3-network", "network collection type, defined with default value")); groupTypeDefinition.setProperties(properties); - when(groupTypeOperation.getLatestGroupTypeByType(grpType, false)).thenReturn(Either.left(groupTypeDefinition)); + when(groupTypeOperation.getLatestGroupTypeByType(grpType, component.getModel(), false)).thenReturn(Either.left(groupTypeDefinition)); when(toscaOperationFacade.canAddGroups(componentId)).thenReturn(true); - when(groupTypeOperation.getLatestGroupTypeByType(grpType, true)).thenReturn(Either.left(groupTypeDefinition)); + when(groupTypeOperation.getLatestGroupTypeByType(grpType, component.getModel(), true)).thenReturn(Either.left(groupTypeDefinition)); when(propertyOperation.checkInnerType(any(PropertyDefinition.class))).thenReturn(Either.left("ok")); when(propertyOperation.validateAndUpdatePropertyValue("string", null, "ok", map)).thenReturn(Either.left(component)); when(groupsOperation.addGroups(any(Resource.class), any())).thenReturn(Either.left(groupDefList)); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java index c759c15094..627c536720 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java @@ -172,7 +172,7 @@ public class PolicyBusinessLogicTest { @Test public void createPolicySuccessTest(){ stubValidateAndLockSuccess(CREATE_POLICY); - when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither); + when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither); when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither); stubUnlockAndCommit(); PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true); @@ -201,7 +201,7 @@ public class PolicyBusinessLogicTest { newResource.setPolicies(policies); newResource.setComponentInstances(instanceList); - when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither); + when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither); when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy)); when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(Either.left(newResource)); when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(Either.left(policy)); @@ -249,7 +249,7 @@ public class PolicyBusinessLogicTest { public void createPolicyPolicyTypeFailureTest(){ stubValidateAndLockSuccess(CREATE_POLICY); Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND); - when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeFailed); + when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeFailed); when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND); stubUnlockAndRollback(); businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true); @@ -258,7 +258,7 @@ public class PolicyBusinessLogicTest { @Test(expected = ComponentException.class) public void createPolicyComponentTypeFailureTest(){ stubValidateAndLockSuccess(CREATE_POLICY); - when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither); + when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither); Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST); when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes); when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java index d3a27a8615..7391d91309 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java @@ -122,9 +122,9 @@ public class PolicyTypeBusinessLogicTest { @Test public void getLatestPolicyTypeByTypeTest() { PolicyTypeDefinition policyTypeDefinition = new PolicyTypeBuilder().setType("org.openecomp.policies.placement.Antilocate").build(); - when(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate")).thenReturn( + when(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate", null)).thenReturn( Either.left(policyTypeDefinition)); - assertThat(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate")) - .isEqualTo(Either.left(testInstance.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate"))); + assertThat(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate", null)) + .isEqualTo(Either.left(testInstance.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate", null))); } }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java index ac64e06917..69367e962c 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java @@ -66,6 +66,7 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS; @@ -266,9 +267,9 @@ public class YamlTemplateParsingHandlerTest { } private void stubGetGroupType() { - when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE))).thenReturn(VfcInstanceGroupType); - when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE))).thenReturn(heatGroupType); - when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE))).thenReturn(rootGroupType); + when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE), any())).thenReturn(VfcInstanceGroupType); + when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType); + when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE), any())).thenReturn(rootGroupType); } private static GroupTypeDefinition buildRootGroupType() { @@ -366,7 +367,7 @@ public class YamlTemplateParsingHandlerTest { } private void stubGetPolicyType () { - when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE))).thenReturn( + when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any())).thenReturn( OPENECOMP_POLICY_TYPE); } |