diff options
author | franciscovila <javier.paradela.vila@est.tech> | 2022-07-26 14:49:32 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-08-15 11:24:12 +0000 |
commit | ebffd13f0100839fecf5dbcd5c83856c193d8109 (patch) | |
tree | 600f5d2340124af6834121b666b01d6b73922c4f /catalog-model/src/main | |
parent | cc764ab040ec1c278d8619d2d92be638d8f585e8 (diff) |
Service Import - Node Template Interface Definitions
Add Node Template Interface Definitions when
importing a service
Issue-ID: SDC-4113
Signed-off-by: franciscovila <javier.paradela.vila@est.tech>
Change-Id: I28bcb120ebd25b0baa4e62404d3fe38ce3a3706f
Diffstat (limited to 'catalog-model/src/main')
4 files changed, 159 insertions, 26 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java index ef9f1f17e8..5aad2fb91d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java @@ -19,11 +19,12 @@ */ package org.openecomp.sdc.be.model; +import lombok.Getter; +import lombok.Setter; + import java.util.Collection; import java.util.List; import java.util.Map; -import lombok.Getter; -import lombok.Setter; import org.openecomp.sdc.be.ui.model.OperationUi; @Getter @@ -40,6 +41,7 @@ public class UploadComponentInstanceInfo { private Map<String, String> capabilitiesNamesToUpdate; private Map<String, String> requirementsNamesToUpdate; private Collection<String> directives; + private Map<String, UploadInterfaceInfo> interfaces; private UploadNodeFilterInfo uploadNodeFilterInfo; private Map<String, List<OperationUi>> operations; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadInterfaceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadInterfaceInfo.java new file mode 100644 index 0000000000..1a05ace4f1 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadInterfaceInfo.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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; + +import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; +import java.util.HashMap; +import java.util.Map; + +public class UploadInterfaceInfo extends UploadInfo { + private Object value; + private String description; + private String type; + private Map<String, OperationDataDefinition> operations; + + public Map<String, OperationDataDefinition> getOperations() { + if (operations == null) { + operations = new HashMap<>(); + } + return operations; + } + + public void setOperations(Map<String, OperationDataDefinition> operations) { + this.operations = operations; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java index dcd801168a..91176a9ecb 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java @@ -385,6 +385,23 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return StorageOperationStatus.OK; } + public StorageOperationStatus associateInstInterfacesToComponent( + GraphVertex nodeTypeVertex, + Map<String, MapInterfaceDataDefinition> instInterfaces + ) { + if (instInterfaces != null && !instInterfaces.isEmpty()) { + Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData( + nodeTypeVertex, + VertexTypeEnum.INST_INTERFACES, + EdgeLabelEnum.INST_INTERFACES, + instInterfaces); + if (associateElementToData.isRight()) { + return associateElementToData.right().value(); + } + } + return StorageOperationStatus.OK; + } + public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) { if (instGroups != null && !instGroups.isEmpty()) { Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, 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 8c08a3d040..b35ae1ec8c 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 @@ -19,33 +19,9 @@ */ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; -import static java.util.Objects.requireNonNull; -import static org.apache.commons.collections.CollectionUtils.isEmpty; -import static org.apache.commons.collections.CollectionUtils.isNotEmpty; -import static org.janusgraph.core.attribute.Text.REGEX; - import com.vdurmont.semver4j.Semver; import com.vdurmont.semver4j.Semver.SemverType; import fj.data.Either; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.TreeSet; -import java.util.function.BiPredicate; -import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -68,6 +44,8 @@ import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; @@ -77,6 +55,7 @@ import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -113,6 +92,7 @@ import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.UploadInterfaceInfo; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.catalog.CatalogComponent; import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData; @@ -134,6 +114,31 @@ import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.ValidationUtils; import org.springframework.beans.factory.annotation.Autowired; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.BiPredicate; +import java.util.stream.Collectors; + +import static java.util.Objects.requireNonNull; +import static org.apache.commons.collections.CollectionUtils.isEmpty; +import static org.apache.commons.collections.CollectionUtils.isNotEmpty; +import static org.janusgraph.core.attribute.Text.REGEX; + @org.springframework.stereotype.Component("tosca-operation-facade") public class ToscaOperationFacade { @@ -1665,6 +1670,48 @@ public class ToscaOperationFacade { return Either.right(status); } + public Either<Map<String, MapInterfaceDataDefinition>, StorageOperationStatus> associateComponentInstanceInterfacesToComponent( + Map<String, Map<String, InterfaceDefinition>> instInterfaces, + String componentId + ) { + Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById( + componentId, + JsonParseFlagEnum.NoParse + ); + if (getVertexEither.isRight()) { + log.debug( + COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, + componentId, + getVertexEither.right().value() + ); + return Either.right( + DaoStatusConverter.convertJanusGraphStatusToStorageStatus( + getVertexEither.right().value() + ) + ); + } + GraphVertex vertex = getVertexEither.left().value(); + Map<String, MapInterfaceDataDefinition> instInterfacesMap = new HashMap<>(); + if (instInterfaces != null) { + MapInterfaceDataDefinition interfacesMap = new MapInterfaceDataDefinition(); + for (Map.Entry<String, Map<String, InterfaceDefinition>> entryInstances : instInterfaces.entrySet()) { + Map<String, InterfaceDataDefinition> incomingInterfacesMap = entryInstances.getValue().entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); + interfacesMap.setMapToscaDataDefinition(incomingInterfacesMap); + instInterfacesMap.put(entryInstances.getKey(), interfacesMap); + } + } + StorageOperationStatus status = topologyTemplateOperation.associateInstInterfacesToComponent( + vertex, + instInterfacesMap + ); + if (StorageOperationStatus.OK == status) { + log.debug(COMPONENT_CREATED_SUCCESSFULLY); + return Either.left(instInterfacesMap); + } + return Either.right(status); + } + public Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addComponentInstanceInputsToComponent( Component containerComponent, Map<String, List<ComponentInstanceInput>> instProperties) { requireNonNull(instProperties); |