summaryrefslogtreecommitdiffstats
path: root/catalog-model
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
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')
-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
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java197
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapperTest.java60
7 files changed, 479 insertions, 41 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;
+
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
index cf4d6b22bf..5a02c5752f 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationTest.java
@@ -29,12 +29,29 @@
*/
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import com.google.common.collect.Lists;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraphVertex;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -43,46 +60,48 @@ import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
+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.JanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
-import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
+import org.openecomp.sdc.be.model.ComponentInstanceOutput;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.RelationshipImpl;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+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.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.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import static org.codehaus.groovy.runtime.DefaultGroovyMethods.any;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.anyList;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@ExtendWith(MockitoExtension.class)
@TestInstance(Lifecycle.PER_CLASS)
class NodeTemplateOperationTest extends ModelTestBase {
@@ -205,10 +224,8 @@ class NodeTemplateOperationTest extends ModelTestBase {
@Test
void testGetDefaultHeatTimeout() {
- Integer result;
-
- // default test
- result = NodeTemplateOperation.getDefaultHeatTimeout();
+ assertEquals(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatArtifactDeploymentTimeout().getDefaultMinutes(),
+ NodeTemplateOperation.getDefaultHeatTimeout());
}
@Test
@@ -234,13 +251,8 @@ class NodeTemplateOperationTest extends ModelTestBase {
}
@Test
- void testCreateCapPropertyKey() throws Exception {
- String key = "";
- String instanceId = "";
- String result;
-
- // default test
- result = NodeTemplateOperation.createCapPropertyKey(key, instanceId);
+ void testCreateCapPropertyKey() {
+ assertEquals("instanceId#instanceId#key", NodeTemplateOperation.createCapPropertyKey("key", "instanceId"));
}
@Test
@@ -438,6 +450,119 @@ class NodeTemplateOperationTest extends ModelTestBase {
eq(componentInstanceOutputList), ArgumentMatchers.anyList(), eq(JsonPresentationFields.NAME));
}
+ @Test
+ void updateComponentInstanceCapabilitiesSuccessTest() {
+ final var capabilityUniqueId = "capabilityUniqueId";
+ final var capabilityType = "capabilityType";
+ final var componentInstanceId = "componentInstanceId";
+
+ final var nodeTemplateOperation = spy(operation);
+ final var capabilityDefinitionDatabase = new CapabilityDataDefinition();
+ capabilityDefinitionDatabase.setUniqueId(capabilityUniqueId);
+ capabilityDefinitionDatabase.setType(capabilityType);
+ capabilityDefinitionDatabase.setExternal(false);
+ final var capabilityDefinitionToUpdate = new CapabilityDataDefinition();
+ capabilityDefinitionToUpdate.setUniqueId(capabilityUniqueId);
+ capabilityDefinitionToUpdate.setType(capabilityType);
+ capabilityDefinitionToUpdate.setExternal(true);
+ final Map<String, MapListCapabilityDataDefinition> capabilityByInstanceMap = new HashMap<>();
+ var mapListCapabilityDataDefinition = new MapListCapabilityDataDefinition();
+ mapListCapabilityDataDefinition.add(capabilityDefinitionDatabase.getType(), capabilityDefinitionDatabase);
+ capabilityByInstanceMap.put(componentInstanceId, mapListCapabilityDataDefinition);
+
+ final GraphVertex componentVertex = Mockito.mock(GraphVertex.class);
+ final GraphVertex capabilitiesVertex = Mockito.mock(GraphVertex.class);
+ doReturn(capabilityByInstanceMap).when(capabilitiesVertex).getJson();
+ when(janusGraphDao.getVertexById(COMPONENT_ID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(componentVertex));
+ when(janusGraphDao.getChildVertex(componentVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES, JsonParseFlagEnum.ParseJson))
+ .thenReturn(Either.left(capabilitiesVertex));
+ when(janusGraphDao.updateVertex(componentVertex)).thenReturn(Either.left(componentVertex));
+ doReturn(Either.left(capabilitiesVertex))
+ .when(nodeTemplateOperation).updateOrCopyOnUpdate(capabilitiesVertex, componentVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES);
+ final CapabilityDataDefinition actualCapabilityDataDefinition = nodeTemplateOperation
+ .updateComponentInstanceCapabilities(COMPONENT_ID, componentInstanceId, capabilityDefinitionToUpdate);
+ assertTrue(actualCapabilityDataDefinition.isExternal());
+ }
+
+ @Test
+ void updateComponentInstanceCapabilitiesTest_capabilityNotFound() {
+ final var componentInstanceId = "componentInstanceId";
+ var capabilityDataDefinition = new CapabilityDataDefinition();
+ capabilityDataDefinition.setType("aCapabilityType");
+ final GraphVertex componentVertex = Mockito.mock(GraphVertex.class);
+ final GraphVertex calculatedCapabilityVertex = Mockito.mock(GraphVertex.class);
+ //no capabilities found
+ when(janusGraphDao.getVertexById(COMPONENT_ID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(componentVertex));
+ when(janusGraphDao.getChildVertex(componentVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES, JsonParseFlagEnum.ParseJson))
+ .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ OperationException actualException = assertThrows(OperationException.class, () ->
+ operation.updateComponentInstanceCapabilities(COMPONENT_ID, componentInstanceId, capabilityDataDefinition));
+ assertEquals(ActionStatus.CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, actualException.getActionStatus());
+ assertEquals(actualException.getParams().length, 3);
+ assertEquals(capabilityDataDefinition.getName(), actualException.getParams()[0]);
+ assertEquals(capabilityDataDefinition.getOwnerName(), actualException.getParams()[1]);
+ assertEquals(COMPONENT_ID, actualException.getParams()[2]);
+
+ //found capabilities, but not for the provided instance id
+ when(janusGraphDao.getChildVertex(componentVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES, JsonParseFlagEnum.ParseJson))
+ .thenReturn(Either.left(calculatedCapabilityVertex));
+ actualException = assertThrows(OperationException.class, () ->
+ operation.updateComponentInstanceCapabilities(COMPONENT_ID, "componentInstanceId", capabilityDataDefinition));
+ assertEquals(ActionStatus.CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, actualException.getActionStatus());
+ assertEquals(actualException.getParams().length, 3);
+ assertEquals(capabilityDataDefinition.getName(), actualException.getParams()[0]);
+ assertEquals(capabilityDataDefinition.getOwnerName(), actualException.getParams()[1]);
+ assertEquals(COMPONENT_ID, actualException.getParams()[2]);
+
+ //found capabilities for the instance id, but not with the provided capability type
+ final Map<String, MapListCapabilityDataDefinition> capabilityByInstanceMap = new HashMap<>();
+ var mapListCapabilityDataDefinition = new MapListCapabilityDataDefinition();
+ mapListCapabilityDataDefinition.add("anotherCapabilityType", new CapabilityDataDefinition());
+ capabilityByInstanceMap.put(componentInstanceId, mapListCapabilityDataDefinition);
+ doReturn(capabilityByInstanceMap).when(calculatedCapabilityVertex).getJson();
+ actualException = assertThrows(OperationException.class, () ->
+ operation.updateComponentInstanceCapabilities(COMPONENT_ID, "componentInstanceId", capabilityDataDefinition));
+ assertEquals(ActionStatus.CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, actualException.getActionStatus());
+ assertEquals(actualException.getParams().length, 3);
+ assertEquals(capabilityDataDefinition.getName(), actualException.getParams()[0]);
+ assertEquals(capabilityDataDefinition.getOwnerName(), actualException.getParams()[1]);
+ assertEquals(COMPONENT_ID, actualException.getParams()[2]);
+ }
+
+ @Test
+ void updateComponentInstanceCapabilitiesTest_capabilityFindError() {
+ final GraphVertex componentVertex = Mockito.mock(GraphVertex.class);
+ when(componentVertex.getUniqueId()).thenReturn(COMPONENT_ID);
+ when(janusGraphDao.getVertexById(COMPONENT_ID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(componentVertex));
+ when(janusGraphDao.getChildVertex(componentVertex, EdgeLabelEnum.CALCULATED_CAPABILITIES, JsonParseFlagEnum.ParseJson))
+ .thenReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR));
+ final OperationException actualException = assertThrows(OperationException.class, () ->
+ operation.updateComponentInstanceCapabilities(COMPONENT_ID, "componentInstanceId", new CapabilityDataDefinition()));
+ assertEquals(ActionStatus.COMPONENT_CAPABILITIES_FIND_ERROR, actualException.getActionStatus());
+ assertEquals(actualException.getParams().length, 1);
+ assertEquals(COMPONENT_ID, actualException.getParams()[0]);
+ }
+
+ @Test
+ void updateComponentInstanceCapabilitiesTest_componentNotFound() {
+ when(janusGraphDao.getVertexById(COMPONENT_ID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+ final OperationException actualException = assertThrows(OperationException.class, () ->
+ operation.updateComponentInstanceCapabilities(COMPONENT_ID, "componentInstanceId", new CapabilityDataDefinition()));
+ assertEquals(ActionStatus.COMPONENT_NOT_FOUND, actualException.getActionStatus());
+ assertEquals(actualException.getParams().length, 1);
+ assertEquals(COMPONENT_ID, actualException.getParams()[0]);
+ }
+
+ @Test
+ void updateComponentInstanceCapabilitiesTest_componentFindError() {
+ when(janusGraphDao.getVertexById(COMPONENT_ID, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(JanusGraphOperationStatus.GENERAL_ERROR));
+ final OperationException actualException = assertThrows(OperationException.class, () ->
+ operation.updateComponentInstanceCapabilities(COMPONENT_ID, "componentInstanceId", new CapabilityDataDefinition()));
+ assertEquals(ActionStatus.COMPONENT_FIND_ERROR, actualException.getActionStatus());
+ assertEquals(actualException.getParams().length, 1);
+ assertEquals(COMPONENT_ID, actualException.getParams()[0]);
+ }
+
private ComponentInstance createCompInstance() {
ComponentInstance componentInstance = new ComponentInstance();
String id = "id";
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapperTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapperTest.java
new file mode 100644
index 0000000000..6e147281b8
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/ui/mapper/CapabilityMapperTest.java
@@ -0,0 +1,60 @@
+/*
+ * ============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 static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.ui.model.ComponentInstanceCapabilityUpdateModel;
+
+class CapabilityMapperTest {
+
+ private CapabilityMapper capabilityMapper;
+
+ @BeforeEach
+ void beforeEach() {
+ capabilityMapper = new CapabilityMapper();
+ }
+
+ @Test
+ void mapToCapabilityDefinitionTest() {
+ final ComponentInstanceCapabilityUpdateModel capabilityUpdateModel = new ComponentInstanceCapabilityUpdateModel();
+ capabilityUpdateModel.setUniqueId("uniqueId");
+ capabilityUpdateModel.setName("name");
+ capabilityUpdateModel.setExternal(true);
+ capabilityUpdateModel.setOwnerId("ownerId");
+ capabilityUpdateModel.setType("type");
+ capabilityUpdateModel.setOwnerName("ownerName");
+ final CapabilityDefinition capabilityDefinition = capabilityMapper.mapToCapabilityDefinition(capabilityUpdateModel);
+ assertCapabilityDefinition(capabilityDefinition, capabilityUpdateModel);
+ }
+
+ private void assertCapabilityDefinition(final CapabilityDefinition actualCapabilityDefinition,
+ final ComponentInstanceCapabilityUpdateModel expectedCapabilityDefinition) {
+ assertEquals(expectedCapabilityDefinition.getUniqueId(), actualCapabilityDefinition.getUniqueId());
+ assertEquals(expectedCapabilityDefinition.getName(), actualCapabilityDefinition.getName());
+ assertEquals(expectedCapabilityDefinition.getOwnerId(), actualCapabilityDefinition.getOwnerId());
+ assertEquals(expectedCapabilityDefinition.getOwnerName(), actualCapabilityDefinition.getOwnerName());
+ assertEquals(expectedCapabilityDefinition.getType(), actualCapabilityDefinition.getType());
+ assertEquals(expectedCapabilityDefinition.getExternal(), actualCapabilityDefinition.isExternal());
+ }
+} \ No newline at end of file