summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-05-05 15:31:04 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-05-15 06:21:13 +0000
commit2152a9a43767cdd486fd8c93894f66a05083f53c (patch)
treecbb64fc5680ba724bc317e27f6a20802d5b38502 /catalog-model/src/main/java/org
parente3de4c9d214983d38a7d66e89dae5d4bba170ca3 (diff)
Support for selection of capabilities
Change-Id: Ib1a3e3e1a59fc84c62620932c408e231acf77024 Issue-ID: SDC-3580 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/main/java/org')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java124
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java7
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/OperationException.java42
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapper.java40
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ComponentInstanceCapabilityUpdateModel.java50
5 files changed, 258 insertions, 5 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
index f9e9a46698..416c701582 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
@@ -45,6 +45,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.janusgraph.core.JanusGraphVertex;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
@@ -105,6 +106,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -115,7 +117,9 @@ import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
+import org.openecomp.sdc.common.log.elements.ErrorLogOptionalData;
import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.enums.LogLevel;
import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
import org.openecomp.sdc.common.log.enums.StatusCode;
@@ -957,11 +961,13 @@ public class NodeTemplateOperation extends BaseOperation {
MapListCapabilityDataDefinition allCalculatedCap = new MapListCapabilityDataDefinition();
if (calculatedCapabilities != null) {
calculatedCapabilities.forEach((key1, value1) -> {
- Map<String, ListCapabilityDataDefinition> mapByType = value1.getMapToscaDataDefinition();
- mapByType.forEach((key, value) -> value.getListToscaDataDefinition().forEach(cap -> {
- cap.addToPath(componentInstance.getUniqueId());
- allCalculatedCap.add(key, cap);
- }));
+ final Map<String, ListCapabilityDataDefinition> mapByType = value1.getMapToscaDataDefinition();
+ mapByType.forEach((key, value) -> value.getListToscaDataDefinition().stream()
+ .filter(CapabilityDataDefinition::isExternal)
+ .forEach(cap -> {
+ cap.addToPath(componentInstance.getUniqueId());
+ allCalculatedCap.add(key, cap);
+ }));
});
}
MapListCapabilityDataDefinition allCaps;
@@ -1068,6 +1074,93 @@ public class NodeTemplateOperation extends BaseOperation {
return StorageOperationStatus.OK;
}
+ public CapabilityDataDefinition updateComponentInstanceCapabilities(final String componentId, final String componentInstanceUniqueId,
+ final CapabilityDataDefinition capabilityDataDefinition) {
+
+ final GraphVertex containerVertex = findComponentVertex(componentId).orElse(null);
+ if (containerVertex == null) {
+ throw new OperationException(ActionStatus.COMPONENT_NOT_FOUND, componentId);
+ }
+
+ final Pair<GraphVertex, Map<String, MapListCapabilityDataDefinition>> capabilityVertexAndDataPair =
+ findCapabilityVertex(containerVertex).orElse(null);
+ if (capabilityVertexAndDataPair == null) {
+ throw new OperationException(ActionStatus.CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, capabilityDataDefinition.getName(),
+ capabilityDataDefinition.getOwnerName(), componentId);
+ }
+ final GraphVertex capabilitiesVertex = capabilityVertexAndDataPair.getLeft();
+ final Map<String, MapListCapabilityDataDefinition> capabilityDataMap = capabilityVertexAndDataPair.getRight();
+
+ final CapabilityDataDefinition actualCapabilityDataDefinition =
+ findCapability(capabilityDataMap, componentInstanceUniqueId, capabilityDataDefinition.getType(), capabilityDataDefinition.getUniqueId())
+ .orElse(null);
+ if (actualCapabilityDataDefinition == null) {
+ throw new OperationException(ActionStatus.CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, capabilityDataDefinition.getName(),
+ capabilityDataDefinition.getOwnerName(), componentId);
+ }
+ bindCapabilityDefinition(capabilityDataDefinition, actualCapabilityDataDefinition);
+
+ var storageOperationStatus = updateCapabilityVertex(containerVertex, capabilitiesVertex);
+ if (storageOperationStatus != StorageOperationStatus.OK) {
+ throw new OperationException(ActionStatus.COMPONENT_INSTANCE_CAPABILITY_UPDATE_ERROR, capabilityDataDefinition.getName());
+ }
+ return new CapabilityDataDefinition(actualCapabilityDataDefinition);
+ }
+
+ private void bindCapabilityDefinition(final CapabilityDataDefinition fromCapabilityDefinition,
+ final CapabilityDataDefinition capabilityDefinitionToUpdate) {
+ capabilityDefinitionToUpdate.setExternal(fromCapabilityDefinition.isExternal());
+ }
+
+ private Optional<GraphVertex> findComponentVertex(final String componentId) {
+ final Either<GraphVertex, JanusGraphOperationStatus> componentEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.ParseAll);
+ if (componentEither.isRight()) {
+ final JanusGraphOperationStatus error = componentEither.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_FETCH_CONTAINER_VERTEX_ERROR, componentId, error);
+ if (error == JanusGraphOperationStatus.NOT_FOUND) {
+ return Optional.empty();
+ }
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, NodeTemplateOperation.class.getName(), (ErrorLogOptionalData) null,
+ FAILED_TO_FETCH_CONTAINER_VERTEX_ERROR, componentId, error);
+ throw new OperationException(ActionStatus.COMPONENT_FIND_ERROR, componentId);
+ }
+ return Optional.ofNullable(componentEither.left().value());
+ }
+
+ private Optional<Pair<GraphVertex, Map<String, MapListCapabilityDataDefinition>>> findCapabilityVertex(final GraphVertex containerVertex) {
+
+ final Either<Pair<GraphVertex, Map<String, MapListCapabilityDataDefinition>>, StorageOperationStatus> capabilitiesEither =
+ fetchContainerCalculatedCapability(containerVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES);
+ if (capabilitiesEither.isRight()) {
+ final StorageOperationStatus error = capabilitiesEither.right().value();
+ if (error == StorageOperationStatus.NOT_FOUND) {
+ return Optional.empty();
+ }
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, NodeTemplateOperation.class.getName(), (ErrorLogOptionalData) null,
+ FAILED_TO_FETCH_CONTAINER_VERTEX_ERROR, containerVertex.getUniqueId(), error);
+ throw new OperationException(ActionStatus.COMPONENT_CAPABILITIES_FIND_ERROR, containerVertex.getUniqueId());
+ }
+ return Optional.ofNullable(capabilitiesEither.left().value());
+ }
+
+ private Optional<CapabilityDataDefinition> findCapability(final Map<String, MapListCapabilityDataDefinition> capabilityMap,
+ final String componentInstanceUniqueId,
+ final String capabilityType,
+ final String capabilityUniqueId) {
+ var componentInstanceCapabilitiesMap = capabilityMap.get(componentInstanceUniqueId);
+ if (componentInstanceCapabilitiesMap == null || componentInstanceCapabilitiesMap.isEmpty()) {
+ return Optional.empty();
+ }
+ var listCapabilityDataDefinition = componentInstanceCapabilitiesMap.getMapToscaDataDefinition().get(capabilityType);
+ if (listCapabilityDataDefinition == null || listCapabilityDataDefinition.isEmpty()) {
+ return Optional.empty();
+ }
+
+ return listCapabilityDataDefinition.getListToscaDataDefinition().stream()
+ .filter(e -> e.getUniqueId().equals(capabilityUniqueId))
+ .findFirst();
+ }
+
public StorageOperationStatus updateComponentInstanceRequirement(String componentId, String componentInstanceUniqueId,
RequirementDataDefinition requirementDataDefinition) {
Either<GraphVertex, JanusGraphOperationStatus> containerVEither = janusGraphDao
@@ -1143,6 +1236,27 @@ public class NodeTemplateOperation extends BaseOperation {
return StorageOperationStatus.OK;
}
+ private StorageOperationStatus updateCapabilityVertex(final GraphVertex containerVertex, final GraphVertex capabilitiesVertex) {
+ containerVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, System.currentTimeMillis());
+ final Either<GraphVertex, JanusGraphOperationStatus> updateElement = janusGraphDao.updateVertex(containerVertex);
+ if (updateElement.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update topology template '{}' with new capabilities. Error '{}'.",
+ containerVertex.getUniqueId(), updateElement.right().value());
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateElement.right().value());
+ }
+
+ final Either<GraphVertex, JanusGraphOperationStatus> statusEither =
+ updateOrCopyOnUpdate(capabilitiesVertex, containerVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES);
+ if (statusEither.isRight()) {
+ JanusGraphOperationStatus error = statusEither.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
+ "Failed to update calculated capability for container {} error {}", containerVertex.getUniqueId(), error);
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(error);
+ }
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Updated calculated capability for container '{}'", containerVertex.getUniqueId());
+ return StorageOperationStatus.OK;
+ }
+
private StorageOperationStatus addComponentInstanceToscaDataToNodeTypeContainer(NodeType originNodeType,
ComponentInstanceDataDefinition componentInstance,
GraphVertex updatedContainerVertex) {
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 06e23f04ea..205a48e9b2 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
@@ -112,6 +112,7 @@ import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -2963,6 +2964,12 @@ public class ToscaOperationFacade {
return nodeTemplateOperation.updateComponentInstanceRequirement(containerComponentId, componentInstanceUniqueId, requirementDataDefinition);
}
+ public CapabilityDataDefinition updateComponentInstanceCapability(final String containerComponentId, final String componentInstanceUniqueId,
+ final CapabilityDataDefinition capabilityDataDefinition) {
+
+ return nodeTemplateOperation.updateComponentInstanceCapabilities(containerComponentId, componentInstanceUniqueId, capabilityDataDefinition);
+ }
+
public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, String componentInstanceUniqueId) {
MapInterfaceDataDefinition mapInterfaceDataDefinition = convertComponentInstanceInterfaces(containerComponent, componentInstanceUniqueId);
return topologyTemplateOperation.updateComponentInstanceInterfaces(containerComponent, componentInstanceUniqueId, mapInterfaceDataDefinition);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/OperationException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/OperationException.java
new file mode 100644
index 0000000000..30323af521
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/OperationException.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception;
+
+import lombok.Getter;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.exception.BusinessException;
+
+@Getter
+public class OperationException extends BusinessException {
+
+ private final ActionStatus actionStatus;
+ private final String[] params;
+
+ public OperationException(final String message) {
+ super(message);
+ actionStatus = ActionStatus.GENERAL_ERROR;
+ params = new String[0];
+ }
+
+ public OperationException(final ActionStatus actionStatus, String... params) {
+ this.actionStatus = actionStatus;
+ this.params = params;
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapper.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapper.java
new file mode 100644
index 0000000000..4df93829fa
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapper.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ui.mapper;
+
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.ui.model.ComponentInstanceCapabilityUpdateModel;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CapabilityMapper {
+
+ public CapabilityDefinition mapToCapabilityDefinition(final ComponentInstanceCapabilityUpdateModel capabilityUpdateModel) {
+ var capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setUniqueId(capabilityUpdateModel.getUniqueId());
+ capabilityDefinition.setType(capabilityUpdateModel.getType());
+ capabilityDefinition.setOwnerId(capabilityUpdateModel.getOwnerId());
+ capabilityDefinition.setOwnerName(capabilityUpdateModel.getOwnerName());
+ capabilityDefinition.setName(capabilityUpdateModel.getName());
+ capabilityDefinition.setExternal(capabilityUpdateModel.getExternal());
+ return capabilityDefinition;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ComponentInstanceCapabilityUpdateModel.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ComponentInstanceCapabilityUpdateModel.java
new file mode 100644
index 0000000000..3fd74cd9e2
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ComponentInstanceCapabilityUpdateModel.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ui.model;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import lombok.Data;
+
+/**
+ * Model for the component instance capability update request
+ */
+@Data
+public class ComponentInstanceCapabilityUpdateModel {
+
+ @NotNull
+ @Size(min=1)
+ private String type;
+ @NotNull
+ @Size(min=1)
+ private String name;
+ @NotNull
+ @Size(min=1)
+ private String ownerId;
+ @NotNull
+ @Size(min=1)
+ private String ownerName;
+ @NotNull
+ @Size(min=1)
+ private String uniqueId;
+ @NotNull
+ private Boolean external;
+
+}