aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2021-06-24 11:19:45 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-15 13:22:58 +0000
commit4f4f7fb796475bb4a332e798c80438b33ce7712a (patch)
tree88b0f7285acfa2e49c5ba3ad3cc4b04bf9c58dc7 /catalog-model/src/main
parent53df976426f8845adf58e8ff9355764343a38549 (diff)
Allow only types from selected model in service creation
Issue-ID: SDC-3629 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I98edb8a1133b2df8d884782f3fb2758b42b94158
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java30
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java83
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java8
6 files changed, 102 insertions, 38 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
index d08d705a2b..bfb6cae3aa 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
@@ -206,6 +206,9 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
}
if (result == null) {
+ result = createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex);
+ }
+ if (result == null) {
status = janusGraphDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>());
if (status != JanusGraphOperationStatus.OK) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
@@ -260,6 +263,33 @@ public abstract class ToscaElementOperation extends BaseOperation {
return result;
}
+ /**
+ * Creates the MODEL in case it exits on the previous version
+ * @param previousToscaElement previous element version
+ * @param nextToscaElement latest element version
+ * @param user user
+ * @param createdToscaElementVertex created tosca element
+ * @return
+ */
+ private Either<GraphVertex, StorageOperationStatus> createModelEdge(final GraphVertex previousToscaElement,
+ final GraphVertex nextToscaElement, GraphVertex user,
+ final GraphVertex createdToscaElementVertex) {
+ Either<GraphVertex, StorageOperationStatus> result = null;
+ final Either<GraphVertex, JanusGraphOperationStatus> modelElementVertexResponse = janusGraphDao
+ .getParentVertex(previousToscaElement, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse);
+ if (modelElementVertexResponse.isLeft()) {
+ final JanusGraphOperationStatus status = janusGraphDao
+ .createEdge(nextToscaElement.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.MODEL, new HashMap<>());
+ if (JanusGraphOperationStatus.OK != status) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
+ FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.MODEL,
+ user.getUniqueId(), nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status);
+ result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ }
+ }
+ return result;
+ }
+
protected JanusGraphOperationStatus setLastModifierFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
Either<GraphVertex, JanusGraphOperationStatus> parentVertex = janusGraphDao
.getParentVertex(componentV, EdgeLabelEnum.LAST_MODIFIER, JsonParseFlagEnum.NoParse);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index 814ac01eac..25bac1642c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -43,7 +43,9 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiPredicate;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
@@ -531,8 +533,12 @@ public class ToscaOperationFacade {
if (vertex.isRight() || Objects.isNull(vertex.left().value())) {
return Optional.empty();
}
+ return getElementModelVertex(model, vertex.left().value());
+ }
+
+ private Optional<GraphVertex> getElementModelVertex(final String model, final GraphVertex vertex) {
final Either<List<GraphVertex>, JanusGraphOperationStatus> nodeModelVertices = janusGraphDao
- .getParentVertices(vertex.left().value(), EdgeLabelEnum.MODEL_ELEMENT, JsonParseFlagEnum.NoParse);
+ .getParentVertices(vertex, EdgeLabelEnum.MODEL_ELEMENT, JsonParseFlagEnum.NoParse);
if (nodeModelVertices.isRight() || Objects.isNull(nodeModelVertices.left().value())) {
return Optional.empty();
}
@@ -1884,7 +1890,8 @@ public class ToscaOperationFacade {
}
private Either<List<Service>, StorageOperationStatus> getLatestVersionNonCheckoutServicesMetadataOnly(Map<GraphPropertyEnum, Object> hasProps,
- Map<GraphPropertyEnum, Object> hasNotProps) {
+ Map<GraphPropertyEnum, Object> hasNotProps,
+ String modelName) {
List<Service> services = new ArrayList<>();
List<LifecycleStateEnum> states = new ArrayList<>();
// include props
@@ -1895,30 +1902,27 @@ public class ToscaOperationFacade {
hasNotProps.put(GraphPropertyEnum.STATE, states);
hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
hasNotProps.put(GraphPropertyEnum.IS_ARCHIVED, true);
- return fetchServicesByCriteria(services, hasProps, hasNotProps);
+ return fetchServicesByCriteria(services, hasProps, hasNotProps, modelName);
}
private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract,
ComponentTypeEnum componentTypeEnum,
String internalComponentType,
- VertexTypeEnum vertexType) {
+ VertexTypeEnum vertexType,
+ String modelName) {
List<Service> services = null;
Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType);
Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao
.getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata);
- if (getRes.isRight()) {
- if (getRes.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) {
- return Either.left(new ArrayList<>());
- } else {
- return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
- }
+ if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) {
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
}
// region -> Fetch non checked-out services
if (internalComponentType != null && internalComponentType.toLowerCase().trim().equals(SERVICE) && VertexTypeEnum.NODE_TYPE == vertexType) {
Either<List<Service>, StorageOperationStatus> result = getLatestVersionNonCheckoutServicesMetadataOnly(
- new EnumMap<>(GraphPropertyEnum.class), new EnumMap<>(GraphPropertyEnum.class));
+ new EnumMap<>(GraphPropertyEnum.class), new EnumMap<>(GraphPropertyEnum.class), modelName);
if (result.isRight()) {
log.debug("Failed to fetch services for");
return Either.right(result.right().value());
@@ -1932,15 +1936,17 @@ public class ToscaOperationFacade {
List<Component> nonAbstractLatestComponents = new ArrayList<>();
ComponentParametersView params = new ComponentParametersView(true);
params.setIgnoreAllVersions(false);
- for (GraphVertex vertexComponent : getRes.left().value()) {
- Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation
- .getLightComponent(vertexComponent, componentTypeEnum, params);
- if (componentRes.isRight()) {
- log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value());
- return Either.right(componentRes.right().value());
- } else {
- Component component = ModelConverter.convertFromToscaElement(componentRes.left().value());
- nonAbstractLatestComponents.add(component);
+ if (getRes.isLeft()) {
+ for (GraphVertex vertexComponent : getVerticesForModel(modelName, getRes.left().value())) {
+ Either<ToscaElement, StorageOperationStatus> componentRes = topologyTemplateOperation
+ .getLightComponent(vertexComponent, componentTypeEnum, params);
+ if (componentRes.isRight()) {
+ log.debug("Failed to fetch light element for {} error {}", vertexComponent.getUniqueId(), componentRes.right().value());
+ return Either.right(componentRes.right().value());
+ } else {
+ Component component = ModelConverter.convertFromToscaElement(componentRes.left().value());
+ nonAbstractLatestComponents.add(component);
+ }
}
}
if (CollectionUtils.isNotEmpty(services)) {
@@ -2034,7 +2040,7 @@ public class ToscaOperationFacade {
private Either<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, ComponentTypeEnum componentTypeEnum,
String internalComponentType) {
Either<List<Component>, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, componentTypeEnum,
- internalComponentType);
+ internalComponentType, null);
if (getToscaElementsRes.isRight()) {
return Either.right(getToscaElementsRes.right().value());
}
@@ -2178,12 +2184,13 @@ public class ToscaOperationFacade {
public Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract,
ComponentTypeEnum componentTypeEnum,
- String internalComponentType) {
+ String internalComponentType,
+ String modelName) {
List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType);
List<Component> result = new ArrayList<>();
for (VertexTypeEnum vertexType : internalVertexTypes) {
Either<List<Component>, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract,
- componentTypeEnum, internalComponentType, vertexType);
+ componentTypeEnum, internalComponentType, vertexType, modelName);
if (listByVertexType.isRight()) {
return listByVertexType;
}
@@ -2533,7 +2540,7 @@ public class ToscaOperationFacade {
for (DistributionStatusEnum state : distStatus) {
propertiesToMatch.put(GraphPropertyEnum.DISTRIBUTION_STATUS, state.name());
Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria = fetchServicesByCriteria(servicesAll, propertiesToMatch,
- propertiesNotToMatch);
+ propertiesNotToMatch, null);
if (fetchServicesByCriteria.isRight()) {
return fetchServicesByCriteria;
} else {
@@ -2542,13 +2549,14 @@ public class ToscaOperationFacade {
}
return Either.left(servicesAll);
} else {
- return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch);
+ return fetchServicesByCriteria(servicesAll, propertiesToMatch, propertiesNotToMatch, null);
}
}
private Either<List<Service>, StorageOperationStatus> fetchServicesByCriteria(List<Service> servicesAll,
Map<GraphPropertyEnum, Object> propertiesToMatch,
- Map<GraphPropertyEnum, Object> propertiesNotToMatch) {
+ Map<GraphPropertyEnum, Object> propertiesNotToMatch,
+ String modelName) {
Either<List<GraphVertex>, JanusGraphOperationStatus> getRes = janusGraphDao
.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll);
if (getRes.isRight()) {
@@ -2559,7 +2567,7 @@ public class ToscaOperationFacade {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value()));
}
} else {
- for (GraphVertex vertex : getRes.left().value()) {
+ for (final GraphVertex vertex : getVerticesForModel(modelName, getRes.left().value())) {
Either<ToscaElement, StorageOperationStatus> getServiceRes = topologyTemplateOperation
.getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true));
if (getServiceRes.isRight()) {
@@ -2574,6 +2582,27 @@ public class ToscaOperationFacade {
return Either.left(servicesAll);
}
+ private List<GraphVertex> getVerticesForModel(final String modelName, final List<GraphVertex> graphVertexList) {
+ final Predicate<? super GraphVertex> filterPredicate =
+ StringUtils.isEmpty(modelName) ? this::vertexNotConnectedToAnyModel
+ : graphVertex -> vertexValidForModel(graphVertex, modelName).isPresent();
+ return StreamSupport.stream(graphVertexList.spliterator(), false).filter(filterPredicate).collect(Collectors.toList());
+ }
+
+ private boolean vertexNotConnectedToAnyModel(final GraphVertex vertex) {
+ return !vertex.getVertex().edges(Direction.OUT, EdgeLabelEnum.MODEL.name()).hasNext();
+ }
+
+ private Optional<GraphVertex> vertexValidForModel(final GraphVertex vertex, final String model) {
+ final Either<List<GraphVertex>, JanusGraphOperationStatus> nodeModelVertices = janusGraphDao
+ .getParentVertices(vertex, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse);
+ if (nodeModelVertices.isRight() || Objects.isNull(nodeModelVertices.left().value())) {
+ return Optional.empty();
+ }
+ return nodeModelVertices.left().value().stream().filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.MODEL).equals(model))
+ .findFirst();
+ }
+
public void rollback() {
janusGraphDao.rollback();
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
index bda3e95e0b..bba124ec0d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
@@ -33,5 +33,5 @@ public interface IPolicyTypeOperation {
Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyType(PolicyTypeDefinition updatedPolicyType,
PolicyTypeDefinition currPolicyType);
- List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes);
+ List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes, String modelName);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
index 542d4cf0c0..488ab78cab 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
@@ -273,13 +273,11 @@ public class GroupTypeOperation implements IGroupTypeOperation {
return janusGraphGenericDao.createRelation(groupTypeData, capabilityData, GraphEdgeLabels.GROUP_TYPE_CAPABILITY, properties);
}
- public List<GroupTypeDefinition> getAllGroupTypes(Set<String> excludedGroupTypes) {
+ public List<GroupTypeDefinition> getAllGroupTypes(Set<String> excludedGroupTypes, String modelName) {
Map<String, Map.Entry<JanusGraphPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(),
excludedGroupTypes);
- List<GroupTypeData> groupTypes = janusGraphGenericDao
- .getByCriteriaWithPredicate(NodeTypeEnum.GroupType, predicateCriteria, GroupTypeData.class).left()
- .on(operationUtils::onJanusGraphOperationFailure);
- return convertGroupTypesToDefinition(groupTypes);
+ return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.GroupType, predicateCriteria, GroupTypeData.class, modelName).left()
+ .map(this::convertGroupTypesToDefinition).left().on(operationUtils::validateJanusGraphOperationFailure);
}
private List<GroupTypeDefinition> convertGroupTypesToDefinition(List<GroupTypeData> groupTypes) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java
index 947b2168b9..c30c39835b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/OperationUtils.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.model.operations.impl;
import fj.data.Either;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
@@ -60,4 +62,11 @@ public class OperationUtils {
janusGraphDao.rollback();
throw new StorageException(status);
}
+
+ public <T> List<T> validateJanusGraphOperationFailure(final JanusGraphOperationStatus status) {
+ if (JanusGraphOperationStatus.NOT_FOUND.equals(status)) {
+ return Collections.emptyList();
+ }
+ return onJanusGraphOperationFailure(status);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
index 2b3695fc13..03b531b3b1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
@@ -18,7 +18,6 @@
* ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.be.model.operations.impl;
-
import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate;
import fj.data.Either;
@@ -95,12 +94,11 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
return updatePolicyTypeOnGraph(updatedPolicyType, currPolicyType);
}
- @Override
- public List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes) {
+ public List<PolicyTypeDefinition> getAllPolicyTypes(Set<String> excludedPolicyTypes, String modelName) {
Map<String, Map.Entry<JanusGraphPredicate, Object>> predicateCriteria = buildNotInPredicate(GraphPropertiesDictionary.TYPE.getProperty(),
excludedPolicyTypes);
- return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.PolicyType, predicateCriteria, PolicyTypeData.class).left()
- .map(this::convertPolicyTypesToDefinition).left().on(operationUtils::onJanusGraphOperationFailure);
+ return janusGraphGenericDao.getByCriteriaWithPredicate(NodeTypeEnum.PolicyType, predicateCriteria, PolicyTypeData.class, modelName).left()
+ .map(this::convertPolicyTypesToDefinition).left().on(operationUtils::validateJanusGraphOperationFailure);
}
private List<PolicyTypeDefinition> convertPolicyTypesToDefinition(List<PolicyTypeData> policiesTypes) {