2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
22 import com.google.gson.reflect.TypeToken;
23 import fj.data.Either;
24 import java.lang.reflect.Type;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
30 import java.util.Map.Entry;
31 import java.util.Optional;
32 import java.util.stream.Collectors;
33 import org.apache.commons.collections.MapUtils;
34 import org.apache.tinkerpop.gremlin.structure.Direction;
35 import org.apache.tinkerpop.gremlin.structure.Edge;
36 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
37 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
38 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
39 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
40 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
41 import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
57 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
58 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
63 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
64 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
65 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
66 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
67 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
68 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
69 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
70 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
71 import org.openecomp.sdc.be.model.Component;
72 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
73 import org.openecomp.sdc.be.model.ComponentParametersView;
74 import org.openecomp.sdc.be.model.DistributionStatusEnum;
75 import org.openecomp.sdc.be.model.GroupDefinition;
76 import org.openecomp.sdc.be.model.PolicyDefinition;
77 import org.openecomp.sdc.be.model.User;
78 import org.openecomp.sdc.be.model.category.CategoryDefinition;
79 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
80 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
81 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
82 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
83 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
84 import org.openecomp.sdc.be.model.operations.StorageException;
85 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
86 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
87 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
88 import org.openecomp.sdc.common.api.Constants;
89 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
90 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
91 import org.openecomp.sdc.common.log.elements.ErrorLogOptionalData;
92 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
93 import org.openecomp.sdc.common.log.wrappers.Logger;
94 import org.openecomp.sdc.common.util.ValidationUtils;
95 import org.springframework.beans.factory.annotation.Autowired;
97 @org.springframework.stereotype.Component("topology-template-operation")
98 public class TopologyTemplateOperation extends ToscaElementOperation {
100 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
102 private ArchiveOperation archiveOperation;
104 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
105 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
106 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
107 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
110 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
111 topologyTemplate.generateUUID();
112 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
113 String resourceUniqueId = topologyTemplate.getUniqueId();
114 if (resourceUniqueId == null) {
115 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
116 topologyTemplate.setUniqueId(resourceUniqueId);
118 GraphVertex topologyTemplateVertex = new GraphVertex();
119 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
120 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
121 if (createdVertex.isRight()) {
122 JanusGraphOperationStatus status = createdVertex.right().value();
123 log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
124 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
126 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate);
127 if (assosiateCommon != StorageOperationStatus.OK) {
128 return Either.right(assosiateCommon);
130 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
131 if (associateCategory != StorageOperationStatus.OK) {
132 return Either.right(associateCategory);
134 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
135 if (associateInputs != StorageOperationStatus.OK) {
136 return Either.right(associateInputs);
138 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
139 if (associateGroups != StorageOperationStatus.OK) {
140 return Either.right(associateGroups);
142 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
143 if (associatePolicies != StorageOperationStatus.OK) {
144 return Either.right(associatePolicies);
146 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
147 if (associateInstAttr != StorageOperationStatus.OK) {
148 return Either.right(associateInstAttr);
150 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
151 if (associateInstProperties != StorageOperationStatus.OK) {
152 return Either.right(associateInstProperties);
154 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
155 if (associateInstProperties != StorageOperationStatus.OK) {
156 return Either.right(associateInstInputs);
158 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
159 if (associateInstGroups != StorageOperationStatus.OK) {
160 return Either.right(associateInstInputs);
162 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
163 if (associateRequirements != StorageOperationStatus.OK) {
164 return Either.right(associateRequirements);
166 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
167 if (associateCapabilities != StorageOperationStatus.OK) {
168 return Either.right(associateCapabilities);
170 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
171 if (associateArtifacts != StorageOperationStatus.OK) {
172 return Either.right(associateArtifacts);
174 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
175 if (addAdditionalInformation != StorageOperationStatus.OK) {
176 return Either.right(addAdditionalInformation);
178 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
179 if (associateCapProperties != StorageOperationStatus.OK) {
180 return Either.right(associateCapProperties);
182 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
183 if (associateInterfaces != StorageOperationStatus.OK) {
184 return Either.right(associateInterfaces);
186 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
187 if (associateCapProperties != StorageOperationStatus.OK) {
188 return Either.right(associatePathProperties);
190 final StorageOperationStatus associateServiceToModel = associateComponentToModel(topologyTemplateVertex, topologyTemplate,
191 EdgeLabelEnum.MODEL);
192 if (associateServiceToModel != StorageOperationStatus.OK) {
193 return Either.right(associateServiceToModel);
195 return Either.left(topologyTemplate);
198 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
199 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
202 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
203 if (policies != null && !policies.isEmpty()) {
204 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
205 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
208 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES,
209 EdgeLabelEnum.POLICIES, policies);
210 if (assosiateElementToData.isRight()) {
211 return assosiateElementToData.right().value();
214 return StorageOperationStatus.OK;
217 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
218 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
219 return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths);
222 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
223 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
224 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
225 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(topologyTemplateVertex,
226 VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
227 if (associateElementToData.isRight()) {
228 return associateElementToData.right().value();
231 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
232 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
233 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(topologyTemplateVertex,
234 VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
235 if (associateElementToData.isRight()) {
236 return associateElementToData.right().value();
239 return StorageOperationStatus.OK;
242 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
243 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
244 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
245 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
246 VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
247 if (assosiateElementToData.isRight()) {
248 return assosiateElementToData.right().value();
251 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
252 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
253 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
254 VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
255 if (assosiateElementToData.isRight()) {
256 return assosiateElementToData.right().value();
259 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
260 if (MapUtils.isNotEmpty(capabilities)) {
261 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
262 EdgeLabelEnum.CAPABILITIES, capabilities);
263 if (associateElementToData.isRight()) {
264 return associateElementToData.right().value();
267 return StorageOperationStatus.OK;
270 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
271 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
272 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
273 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
274 VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
275 if (assosiateElementToData.isRight()) {
276 return assosiateElementToData.right().value();
279 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
280 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
281 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
282 VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
283 if (assosiateElementToData.isRight()) {
284 return assosiateElementToData.right().value();
287 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
288 if (MapUtils.isNotEmpty(requirements)) {
289 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
290 EdgeLabelEnum.REQUIREMENTS, requirements);
291 if (associateElementToData.isRight()) {
292 return associateElementToData.right().value();
295 return StorageOperationStatus.OK;
298 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
299 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
300 if (addInformation != null && !addInformation.isEmpty()) {
301 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
302 String uniqueId = UniqueIdBuilder
303 .buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
304 a.setUniqueId(uniqueId);
306 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
307 VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
308 if (assosiateElementToData.isRight()) {
309 return assosiateElementToData.right().value();
312 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
313 if (instArtifacts != null && !instArtifacts.isEmpty()) {
314 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
315 VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
316 if (assosiateElementToData.isRight()) {
317 return assosiateElementToData.right().value();
320 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
321 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
322 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
323 VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
324 if (assosiateElementToData.isRight()) {
325 return assosiateElementToData.right().value();
328 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
329 if (MapUtils.isNotEmpty(requirements)) {
330 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
331 EdgeLabelEnum.REQUIREMENTS, requirements);
332 if (associateElementToData.isRight()) {
333 return associateElementToData.right().value();
336 return StorageOperationStatus.OK;
339 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
340 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
341 if (addInformation != null && !addInformation.isEmpty()) {
342 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
343 VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
344 if (assosiateElementToData.isRight()) {
345 return assosiateElementToData.right().value();
348 return StorageOperationStatus.OK;
351 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
352 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
353 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
356 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
357 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
358 return associateInstInputsToComponent(nodeTypeVertex, instProps);
361 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
362 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
363 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
366 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
367 if (instProps != null && !instProps.isEmpty()) {
368 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
369 VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
370 if (assosiateElementToData.isRight()) {
371 return assosiateElementToData.right().value();
374 return StorageOperationStatus.OK;
377 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
378 if (instInputs != null && !instInputs.isEmpty()) {
379 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS,
380 EdgeLabelEnum.INST_INPUTS, instInputs);
381 if (assosiateElementToData.isRight()) {
382 return assosiateElementToData.right().value();
385 return StorageOperationStatus.OK;
388 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
389 if (instGroups != null && !instGroups.isEmpty()) {
390 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS,
391 EdgeLabelEnum.INST_GROUPS, instGroups);
392 if (assosiateElementToData.isRight()) {
393 return assosiateElementToData.right().value();
396 return StorageOperationStatus.OK;
399 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
400 if (instInputs != null && !instInputs.isEmpty()) {
401 instInputs.entrySet().forEach(i -> {
402 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
403 List<String> pathKeys = new ArrayList<>();
404 pathKeys.add(i.getKey());
405 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS,
406 uniqueKeys, pathKeys, JsonPresentationFields.NAME);
407 if (status != StorageOperationStatus.OK) {
412 return StorageOperationStatus.OK;
415 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
416 if (instInputs != null && !instInputs.isEmpty()) {
417 instInputs.entrySet().forEach(i -> {
418 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES,
419 VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
420 if (status != StorageOperationStatus.OK) {
425 return StorageOperationStatus.OK;
428 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex,
429 Map<String, MapArtifactDataDefinition> instArtifacts) {
430 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS,
431 EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
434 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex,
435 Map<String, MapArtifactDataDefinition> instArtifacts) {
436 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS,
437 EdgeLabelEnum.INSTANCE_ARTIFACTS);
440 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps,
441 VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
442 if (instProps != null && !instProps.isEmpty()) {
443 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel,
445 if (assosiateElementToData.isRight()) {
446 return assosiateElementToData.right().value();
449 return StorageOperationStatus.OK;
452 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex,
453 Map<String, MapListRequirementDataDefinition> calcRequirements,
454 Map<String, MapListCapabilityDataDefinition> calcCapabilty,
455 Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
456 if (!MapUtils.isEmpty(calcRequirements)) {
457 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex,
458 VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
459 if (assosiateElementToData.isRight()) {
460 return assosiateElementToData.right().value();
462 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
463 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS,
464 EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
465 if (assosiateElementToData.isRight()) {
466 return assosiateElementToData.right().value();
469 if (!MapUtils.isEmpty(calcCapabilty)) {
470 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex,
471 VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
472 if (assosiateElementToData.isRight()) {
473 return assosiateElementToData.right().value();
475 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
476 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES,
477 EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
478 if (assosiateElementToData.isRight()) {
479 return assosiateElementToData.right().value();
482 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)) {
483 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES,
484 calculatedCapabilitiesProperties).right().on(v -> StorageOperationStatus.OK);
486 return StorageOperationStatus.OK;
489 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex,
490 VertexTypeEnum vertexTypeEnum,
491 EdgeLabelEnum edgeLabelEnum,
492 Map<String, T> dataMap) {
493 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
494 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
495 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
498 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex,
499 VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum,
500 Map<String, ? extends ToscaDataDefinition> dataMap) {
501 if (status == JanusGraphOperationStatus.NOT_FOUND) {
502 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
504 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
507 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex,
508 GraphVertex dataVertex,
509 VertexTypeEnum vertexTypeEnum,
510 EdgeLabelEnum edgeLabelEnum,
511 Map<String, T> dataMap) {
512 Optional<StorageOperationStatus> error = dataMap.entrySet().stream()
513 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
514 .filter(s -> s != StorageOperationStatus.OK).findFirst();
515 if (error.isPresent()) {
516 return Either.right(error.get());
518 return Either.left(dataVertex);
521 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
522 Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
523 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
526 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex,
527 Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
528 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
529 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
530 VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
531 if (assosiateElementToData.isRight()) {
532 return assosiateElementToData.right().value();
535 return StorageOperationStatus.OK;
538 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
539 if (instAttr != null && !instAttr.isEmpty()) {
540 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
541 VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
542 if (assosiateElementToData.isRight()) {
543 return assosiateElementToData.right().value();
546 return StorageOperationStatus.OK;
549 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
550 if (groups != null && !groups.isEmpty()) {
551 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
552 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
555 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS,
556 EdgeLabelEnum.GROUPS, groups);
557 if (assosiateElementToData.isRight()) {
558 return assosiateElementToData.right().value();
561 return StorageOperationStatus.OK;
564 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
565 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
568 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
569 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
570 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
573 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
574 if (inputs != null && !inputs.isEmpty()) {
575 inputs.values().stream().filter(e -> e.getUniqueId() == null)
576 .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
577 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS,
578 EdgeLabelEnum.INPUTS, inputs);
579 if (assosiateElementToData.isRight()) {
580 return assosiateElementToData.right().value();
583 return StorageOperationStatus.OK;
586 public StorageOperationStatus associateOutputsToComponent(final GraphVertex nodeTypeVertex,
587 final Map<String, ? extends AttributeDataDefinition> outputs,
589 if (MapUtils.isNotEmpty(outputs)) {
590 outputs.values().stream().filter(e -> e.getUniqueId() == null)
591 .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
592 final Either<GraphVertex, StorageOperationStatus> associateElementToData
593 = associateElementToData(nodeTypeVertex, VertexTypeEnum.OUTPUTS, EdgeLabelEnum.OUTPUTS, outputs);
594 if (associateElementToData.isRight()) {
595 return associateElementToData.right().value();
598 return StorageOperationStatus.OK;
601 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
602 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
603 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
604 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
605 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
607 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
608 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_VERSION_UUID,
609 topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_VERSION_ID));
610 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS,
611 topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
612 return nodeTypeVertex;
615 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
616 if (topologyTemplate.getResourceType() == null) {
618 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
621 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
625 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
626 String categoryName = topologyTemplate.getCategories().get(0).getName();
627 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName,
628 VertexTypeEnum.SERVICE_CATEGORY);
629 if (category.isRight()) {
630 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
631 return StorageOperationStatus.CATEGORY_NOT_FOUND;
633 GraphVertex categoryV = category.left().value();
634 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
635 if (createEdge != JanusGraphOperationStatus.OK) {
636 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName,
637 categoryV.getUniqueId());
638 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
640 return StorageOperationStatus.OK;
644 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
645 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
646 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE,
648 if (componentByLabelAndId.isRight()) {
649 return Either.right(componentByLabelAndId.right().value());
651 GraphVertex componentV = componentByLabelAndId.left().value();
652 return getToscaElement(componentV, componentParametersView);
655 // -------------------------------------------------------------
656 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
657 TopologyTemplate toscaElement;
658 toscaElement = convertToTopologyTemplate(componentV);
659 JanusGraphOperationStatus status;
660 if (!componentParametersView.isIgnoreUsers()) {
661 status = setCreatorFromGraph(componentV, toscaElement);
662 if (status != JanusGraphOperationStatus.OK) {
663 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
665 status = setLastModifierFromGraph(componentV, toscaElement);
666 if (status != JanusGraphOperationStatus.OK) {
667 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
670 if (!componentParametersView.isIgnoreCategories()) {
671 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
672 if (status != JanusGraphOperationStatus.OK) {
673 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
676 if (!componentParametersView.isIgnoreArtifacts()) {
677 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
678 if (storageStatus != JanusGraphOperationStatus.OK) {
679 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
682 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
683 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
684 if (status != JanusGraphOperationStatus.OK) {
685 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
688 if (!componentParametersView.isIgnoreComponentInstancesAttributes()) {
689 status = setComponentInstancesAttributesFromGraph(componentV, toscaElement);
690 if (status != JanusGraphOperationStatus.OK) {
691 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
694 if (!componentParametersView.isIgnoreCapabilities()) {
695 status = setCapabilitiesFromGraph(componentV, toscaElement);
696 if (status != JanusGraphOperationStatus.OK) {
697 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
700 if (!componentParametersView.isIgnoreRequirements()) {
701 status = setRequirementsFromGraph(componentV, toscaElement);
702 if (status != JanusGraphOperationStatus.OK) {
703 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
706 if (!componentParametersView.isIgnoreAllVersions()) {
707 status = setAllVersions(componentV, toscaElement);
708 if (status != JanusGraphOperationStatus.OK) {
709 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
712 if (!componentParametersView.isIgnoreAdditionalInformation()) {
713 status = setAdditionalInformationFromGraph(componentV, toscaElement);
714 if (status != JanusGraphOperationStatus.OK) {
715 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
718 if (!componentParametersView.isIgnoreGroups()) {
719 status = setGroupsFromGraph(componentV, toscaElement);
720 if (status != JanusGraphOperationStatus.OK) {
721 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
724 if (!componentParametersView.isIgnorePolicies()) {
725 status = setPoliciesFromGraph(componentV, toscaElement);
726 if (status != JanusGraphOperationStatus.OK) {
727 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
730 if (!componentParametersView.isIgnoreComponentInstances()) {
731 status = setInstGroupsFromGraph(componentV, toscaElement);
732 //Mark all CIs that has archived origins
733 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
734 if (status != JanusGraphOperationStatus.OK) {
735 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
738 if (!componentParametersView.isIgnoreInputs()) {
739 status = setInputsFromGraph(componentV, toscaElement);
740 if (status != JanusGraphOperationStatus.OK) {
741 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
744 if (!componentParametersView.isIgnoreOutputs()) {
745 final JanusGraphOperationStatus storageStatus = setOutputsFromGraph(componentV, toscaElement);
746 if (storageStatus != JanusGraphOperationStatus.OK) {
747 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
750 if (!componentParametersView.isIgnoreProperties()) {
751 status = setPropertiesFromGraph(componentV, toscaElement);
752 if (status != JanusGraphOperationStatus.OK) {
753 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
756 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
757 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
758 if (status != JanusGraphOperationStatus.OK) {
759 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
762 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
763 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
764 if (status != JanusGraphOperationStatus.OK) {
765 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
768 if (!componentParametersView.isIgnoreServicePath()) {
769 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
770 if (status != JanusGraphOperationStatus.OK) {
771 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
774 if (!componentParametersView.isIgnoreNodeFilter()) {
775 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
776 if (status != JanusGraphOperationStatus.OK) {
777 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
780 if (!componentParametersView.isIgnoreSubstitutionFilter()) {
781 status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
782 if (status != JanusGraphOperationStatus.OK) {
783 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
786 if (!componentParametersView.isIgnoreInterfaces()) {
787 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
788 if (storageStatus != JanusGraphOperationStatus.OK) {
789 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
792 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
793 JanusGraphOperationStatus storageStatus = setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
794 if (storageStatus != JanusGraphOperationStatus.OK) {
795 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
798 if (!componentParametersView.isIgnoreDataType()) {
799 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
800 if (storageStatus != JanusGraphOperationStatus.OK) {
801 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
804 return Either.left(toscaElement);
807 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
808 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
809 if (result.isLeft()) {
810 toscaElement.setDataTypes(result.left().value());
812 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
813 return result.right().value();
816 return JanusGraphOperationStatus.OK;
819 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
820 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
821 if (result.isLeft()) {
822 toscaElement.setPolicies(result.left().value());
824 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
825 return result.right().value();
828 return JanusGraphOperationStatus.OK;
831 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
832 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
833 if (result.isLeft()) {
834 topologyTemplate.setInterfaces(result.left().value());
836 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
837 return result.right().value();
840 return JanusGraphOperationStatus.OK;
843 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
844 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
845 EdgeLabelEnum.INST_INTERFACES);
846 if (result.isLeft()) {
847 result.left().value().entrySet().forEach(entry -> topologyTemplate.addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
849 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
850 return result.right().value();
853 return JanusGraphOperationStatus.OK;
856 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
857 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
858 if (interfaceMap != null && !interfaceMap.isEmpty()) {
859 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex,
860 VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
861 if (assosiateElementToData.isRight()) {
862 return assosiateElementToData.right().value();
865 return StorageOperationStatus.OK;
868 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
869 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
870 EdgeLabelEnum.FORWARDING_PATH);
871 if (result.isLeft()) {
872 topologyTemplate.setForwardingPaths(result.left().value());
874 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
875 return result.right().value();
878 return JanusGraphOperationStatus.OK;
881 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
882 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
883 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
884 if (result.isLeft()) {
885 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
887 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
888 return result.right().value();
891 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult = getDataFromGraph(componentV,
892 EdgeLabelEnum.CAPABILITIES_PROPERTIES);
893 if (capPropResult.isLeft()) {
894 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
896 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
897 return capPropResult.right().value();
900 return JanusGraphOperationStatus.OK;
903 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
904 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
905 if (result.isLeft()) {
906 toscaElement.setProperties(result.left().value());
908 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
909 return result.right().value();
912 return JanusGraphOperationStatus.OK;
915 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
916 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
917 if (result.isLeft()) {
918 topologyTemplate.setInstGroups(result.left().value());
920 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
921 return result.right().value();
924 return JanusGraphOperationStatus.OK;
927 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
928 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
929 EdgeLabelEnum.INST_PROPERTIES);
930 if (result.isLeft()) {
931 topologyTemplate.setInstProperties(result.left().value());
933 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
934 return result.right().value();
937 return JanusGraphOperationStatus.OK;
940 private JanusGraphOperationStatus setComponentInstancesAttributesFromGraph(final GraphVertex componentV,
941 final TopologyTemplate topologyTemplate) {
942 final Either<Map<String, MapAttributesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
943 EdgeLabelEnum.INST_ATTRIBUTES);
944 if (result.isLeft()) {
945 topologyTemplate.setInstAttributes(result.left().value());
946 } else if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
947 return result.right().value();
949 return JanusGraphOperationStatus.OK;
952 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
953 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
954 if (result.isLeft()) {
955 topologyTemplate.setInstInputs(result.left().value());
957 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
958 return result.right().value();
961 return JanusGraphOperationStatus.OK;
964 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) {
965 final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
966 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
967 if (result.isLeft()) {
968 topologyTemplate.setNodeFilterComponents(result.left().value());
970 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
971 return result.right().value();
974 return JanusGraphOperationStatus.OK;
977 private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) {
978 final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
979 EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
980 if (result.isLeft()) {
981 final Map<String, SubstitutionFilterDataDefinition> filters = result.left().value();
982 if (MapUtils.isEmpty(filters)) {
983 return JanusGraphOperationStatus.OK;
985 if (filters.values().size() > 1) {
986 log.error(EcompLoggerErrorCode.DATA_ERROR, TopologyTemplateOperation.class.getName(),
987 (ErrorLogOptionalData) null, "Only a single substitution filter is expected, but got '{}'", filters.values().size());
988 return JanusGraphOperationStatus.GENERAL_ERROR;
990 topologyTemplate.setSubstitutionFilters(new SubstitutionFilterDataDefinition(filters.values().iterator().next()));
992 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
993 return result.right().value();
996 return JanusGraphOperationStatus.OK;
1000 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1001 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
1002 EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1003 if (result.isLeft()) {
1004 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1006 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1007 return result.right().value();
1010 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1011 if (result.isLeft()) {
1012 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1014 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1015 return result.right().value();
1018 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult = getDataFromGraph(componentV,
1019 EdgeLabelEnum.REQUIREMENTS);
1020 if (requirementResult.isLeft()) {
1021 toscaElement.setRequirements(requirementResult.left().value());
1023 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1024 return requirementResult.right().value();
1027 return JanusGraphOperationStatus.OK;
1030 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1031 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
1032 EdgeLabelEnum.CALCULATED_CAPABILITIES);
1033 if (result.isLeft()) {
1034 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1036 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1037 return result.right().value();
1040 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1041 if (result.isLeft()) {
1042 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1044 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1045 return result.right().value();
1048 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV,
1049 EdgeLabelEnum.CAPABILITIES);
1050 if (capabilitiesResult.isLeft()) {
1051 toscaElement.setCapabilities(capabilitiesResult.left().value());
1053 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1054 return capabilitiesResult.right().value();
1057 return JanusGraphOperationStatus.OK;
1060 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1061 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1062 if (storageStatus != JanusGraphOperationStatus.OK) {
1063 return storageStatus;
1065 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
1066 EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1067 if (result.isLeft()) {
1068 toscaElement.setServiceApiArtifacts(result.left().value());
1070 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1071 return result.right().value();
1074 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV,
1075 EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1076 if (resultInstArt.isLeft()) {
1077 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1079 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1080 return resultInstArt.right().value();
1083 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV,
1084 EdgeLabelEnum.INSTANCE_ARTIFACTS);
1085 if (instanceArt.isLeft()) {
1086 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1088 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1089 return instanceArt.right().value();
1092 return JanusGraphOperationStatus.OK;
1095 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1096 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1097 if (result.isLeft()) {
1098 toscaElement.setInputs(result.left().value());
1100 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1101 return result.right().value();
1104 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV,
1105 EdgeLabelEnum.CAPABILITIES);
1106 if (capabilitiesResult.isLeft()) {
1107 toscaElement.setCapabilities(capabilitiesResult.left().value());
1109 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1110 return capabilitiesResult.right().value();
1113 return JanusGraphOperationStatus.OK;
1116 private JanusGraphOperationStatus setOutputsFromGraph(final GraphVertex componentV, final TopologyTemplate toscaElement) {
1117 final Either<Map<String, AttributeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.OUTPUTS);
1118 if (result.isLeft()) {
1119 toscaElement.setOutputs(result.left().value());
1121 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1122 return result.right().value();
1125 return JanusGraphOperationStatus.OK;
1128 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1129 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1130 if (result.isLeft()) {
1131 toscaElement.setGroups(result.left().value());
1133 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1134 return result.right().value();
1137 return JanusGraphOperationStatus.OK;
1140 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1141 List<CategoryDefinition> categories = new ArrayList<>();
1142 switch (componentV.getType()) {
1144 return setResourceCategoryFromGraph(componentV, toscaElement);
1146 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1148 log.debug("Not supported component type {} ", componentV.getType());
1151 return JanusGraphOperationStatus.OK;
1154 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement,
1155 List<CategoryDefinition> categories) {
1156 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao
1157 .getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1158 if (childVertex.isRight()) {
1159 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(),
1160 childVertex.right().value());
1161 return childVertex.right().value();
1163 GraphVertex categoryV = childVertex.left().value();
1164 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1165 CategoryDefinition category = new CategoryDefinition();
1166 category.setUniqueId(categoryV.getUniqueId());
1167 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1168 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1169 final Boolean useServiceSubstitutionForNestedServices = (Boolean) metadataProperties
1170 .get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
1171 category.setUseServiceSubstitutionForNestedServices(
1172 useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
1173 Type listTypeCat = new TypeToken<List<String>>() {
1175 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1176 category.setIcons(iconsfromJsonCat);
1177 category.setModels((getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.MODEL.getProperty()), listTypeCat)));
1178 final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {
1180 final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson()
1181 .fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
1182 category.setMetadataKeys(metadataKeysfromJsonCat);
1183 categories.add(category);
1184 toscaElement.setCategories(categories);
1185 return JanusGraphOperationStatus.OK;
1188 @SuppressWarnings("unchecked")
1189 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1190 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1191 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1192 topologyTemplate.setCompositions(json);
1193 return topologyTemplate;
1197 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1198 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1199 if (nodeType.isRight()) {
1200 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1203 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1204 if (status != JanusGraphOperationStatus.OK) {
1205 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1207 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1208 if (status != JanusGraphOperationStatus.OK) {
1209 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1210 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1212 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1213 if (status != JanusGraphOperationStatus.OK) {
1214 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1215 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1217 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1218 if (status != JanusGraphOperationStatus.OK) {
1219 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1220 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1222 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1223 if (status != JanusGraphOperationStatus.OK) {
1224 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1225 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1227 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1228 if (status != JanusGraphOperationStatus.OK) {
1229 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1230 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1232 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1233 if (status != JanusGraphOperationStatus.OK) {
1234 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1235 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1237 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1238 if (status != JanusGraphOperationStatus.OK) {
1239 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1240 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1242 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1243 if (status != JanusGraphOperationStatus.OK) {
1244 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1245 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1247 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1248 if (status != JanusGraphOperationStatus.OK) {
1249 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1250 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1252 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1253 if (status != JanusGraphOperationStatus.OK) {
1254 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1255 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1257 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1258 if (status != JanusGraphOperationStatus.OK) {
1259 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1260 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1262 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1263 if (status != JanusGraphOperationStatus.OK) {
1264 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1265 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1267 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1268 if (status != JanusGraphOperationStatus.OK) {
1269 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1270 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1272 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1273 if (status != JanusGraphOperationStatus.OK) {
1274 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1275 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1277 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1278 if (status != JanusGraphOperationStatus.OK) {
1279 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1280 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1282 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1283 if (status != JanusGraphOperationStatus.OK) {
1284 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1285 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1287 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1288 if (status != JanusGraphOperationStatus.OK) {
1289 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1290 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1292 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1293 if (status != JanusGraphOperationStatus.OK) {
1294 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1295 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1297 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1298 if (status != JanusGraphOperationStatus.OK) {
1299 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1300 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1302 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.REQUIREMENTS);
1303 if (status != JanusGraphOperationStatus.OK) {
1304 log.debug("Failed to disassociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1305 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1307 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES);
1308 if (status != JanusGraphOperationStatus.OK) {
1309 log.debug("Failed to disassociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1310 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1312 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1313 if (status != JanusGraphOperationStatus.OK) {
1314 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1315 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1317 toscaElementVertex.getVertex().remove();
1318 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1322 @SuppressWarnings("unchecked")
1324 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1325 return createTopologyTemplate((TopologyTemplate) toscaElement);
1329 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1330 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1334 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1335 // Product isn't supported now!!
1337 // TODO add for Product
1338 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1339 return validateServiceCategory(toscaElementToUpdate, elementV);
1342 return validateResourceCategory(toscaElementToUpdate, elementV);
1347 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1348 // not relevant now for topology template
1349 return StorageOperationStatus.OK;
1353 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1354 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1357 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1358 StorageOperationStatus status = StorageOperationStatus.OK;
1359 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1360 CategoryDefinition newCategory = newCategoryList.get(0);
1361 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao
1362 .getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1363 if (childVertex.isRight()) {
1364 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(),
1365 childVertex.right().value());
1366 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1368 GraphVertex categoryV = childVertex.left().value();
1369 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1370 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1371 String newCategoryName = newCategory.getName();
1372 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1373 // the category was changed
1374 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation
1375 .getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1376 if (getCategoryVertex.isRight()) {
1377 return getCategoryVertex.right().value();
1379 GraphVertex newCategoryV = getCategoryVertex.left().value();
1380 status = moveCategoryEdge(elementV, newCategoryV);
1381 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1386 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user,
1387 DistributionStatusEnum distributionStatus) {
1388 Either<GraphVertex, StorageOperationStatus> result = null;
1389 String userId = user.getUserId();
1390 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1391 GraphVertex userVertex = null;
1392 GraphVertex serviceVertex = null;
1393 if (getRes.isRight()) {
1394 JanusGraphOperationStatus status = getRes.right().value();
1395 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1396 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1398 if (result == null) {
1399 userVertex = getRes.left().value();
1400 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1401 if (getRes.isRight()) {
1402 JanusGraphOperationStatus status = getRes.right().value();
1403 log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status);
1404 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1407 if (result == null) {
1408 serviceVertex = getRes.left().value();
1409 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1410 if (edgeIterator.hasNext()) {
1411 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId,
1412 EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1413 edgeIterator.next().remove();
1416 if (result == null) {
1417 JanusGraphOperationStatus status = janusGraphDao
1418 .createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1419 if (status != JanusGraphOperationStatus.OK) {
1420 log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId,
1421 EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1422 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1425 if (result == null) {
1426 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1427 long lastUpdateDate = System.currentTimeMillis();
1428 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1429 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1430 if (updateRes.isRight()) {
1431 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1434 if (result == null) {
1435 result = Either.left(serviceVertex);
1441 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1443 * @param componentId
1445 * @param capabilityName
1446 * @param capabilityType
1450 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId,
1452 String capabilityName,
1453 String capabilityType,
1455 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1456 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1457 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId,
1458 ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1459 if (componentByLabelAndId.isRight()) {
1460 result = Either.right(componentByLabelAndId.right().value());
1462 if (componentByLabelAndId.isLeft()) {
1463 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(),
1464 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1465 if (getDataRes.isRight()) {
1466 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1468 mapPropertiesDataDefinition = getDataRes.left().value();
1471 if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
1472 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId,
1473 mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1478 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId,
1479 MapCapabilityProperty instanceProperties) {
1480 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES,
1481 instanceProperties, componentInstanceId);
1484 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, String componentInstanceId,
1485 MapInterfaceDataDefinition instanceInterfaces) {
1486 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1487 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INTERFACES, instanceInterfaces,
1488 componentInstanceId);
1490 return StorageOperationStatus.OK;
1494 public StorageOperationStatus updateComponentInterfaces(final String componentId, final MapInterfaceDataDefinition instanceInterfaces,
1495 final String componentInterfaceUpdatedKey) {
1496 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1497 return updateToscaDataDeepElementsBlockToToscaElement(componentId, EdgeLabelEnum.INTERFACE_ARTIFACTS, instanceInterfaces,
1498 componentInterfaceUpdatedKey);
1500 return StorageOperationStatus.OK;
1503 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1504 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) && instanceId != null && mapPropertiesDataDefinition.get(instanceId) != null
1505 && MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1508 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType,
1510 Map<String, MapPropertiesDataDefinition> propertiesMap) {
1511 List<ComponentInstanceProperty> capPropsList = null;
1512 for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
1513 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1514 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1515 if (capMap != null && !capMap.isEmpty()) {
1516 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1521 if (capPropsList == null) {
1522 capPropsList = new ArrayList<>();
1524 return capPropsList;
1527 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId,
1528 Entry<String, MapPropertiesDataDefinition> capProp) {
1529 if (capProp != null) {
1530 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
1531 if (path.length < 4) {
1532 log.debug("wrong key format for capabilty, key {}", capProp);
1535 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0]
1536 .equals(instanceId);
1541 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1542 fillPolicyDefinition(componentV, policyDefinition, counter);
1543 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition,
1544 JsonPresentationFields.UNIQUE_ID);
1547 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1548 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1551 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1552 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition,
1553 JsonPresentationFields.UNIQUE_ID);
1556 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1557 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions,
1558 JsonPresentationFields.UNIQUE_ID);
1561 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1562 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1565 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1566 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition,
1567 JsonPresentationFields.CI_INVARIANT_NAME);
1570 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1571 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME),
1572 policyDefinition.getPolicyTypeName(), counter);
1573 policyDefinition.setName(policyName);
1574 policyDefinition.setInvariantName(policyName);
1575 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1576 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1577 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1578 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1581 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1582 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1583 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException);
1584 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1585 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver
1586 .revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1588 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1589 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver
1590 .revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1592 topologyTemplateOperation
1593 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,
1594 toscaElement.getCalculatedCapabilities());
1595 topologyTemplateOperation
1596 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,
1597 toscaElement.getCalculatedRequirements());
1598 topologyTemplateOperation
1599 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
1600 toscaElement.getCalculatedCapabilitiesProperties());
1604 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1605 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1606 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException);
1607 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1608 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver
1609 .updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(),
1610 this::getOriginToscaElement));
1612 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1613 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver
1614 .updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1616 topologyTemplateOperation
1617 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,
1618 toscaElement.getCalculatedCapabilities());
1619 topologyTemplateOperation
1620 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,
1621 toscaElement.getCalculatedRequirements());
1622 topologyTemplateOperation
1623 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
1624 toscaElement.getCalculatedCapabilitiesProperties());
1628 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1629 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1630 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1631 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1632 if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
1633 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1635 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1637 if (getOriginRes.isRight()) {
1638 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1639 throw new StorageException(getOriginRes.right().value());
1641 return getOriginRes.left().value();
1644 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1645 log.debug("#detectToscaType - type: {}", originType);
1646 if (originType == OriginTypeEnum.VFC || originType == OriginTypeEnum.CP || originType == OriginTypeEnum.VL
1647 || originType == OriginTypeEnum.Configuration || originType == OriginTypeEnum.VFCMT) {
1648 return ToscaElementTypeEnum.NODE_TYPE;
1650 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1654 private ComponentParametersView getFilter() {
1655 ComponentParametersView filter = new ComponentParametersView();
1656 filter.setIgnoreCapabilities(false);
1657 filter.setIgnoreCapabiltyProperties(false);
1658 filter.setIgnoreRequirements(false);
1662 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1663 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException);
1664 updateCapOwnerId(toscaElement, componentId);
1665 updateReqOwnerId(toscaElement, componentId);
1666 updatePropertiesOwnerId(toscaElement, componentId);
1667 topologyTemplateOperation
1668 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1669 topologyTemplateOperation
1670 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS, VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1671 topologyTemplateOperation
1672 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1675 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1676 if (MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1677 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1678 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1682 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1683 if (MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1684 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1685 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1689 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1690 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1691 if (MapUtils.isNotEmpty(properties)) {
1692 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));