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=========================================================
21 package org.openecomp.sdc.be.model.jsontitan.operations;
23 import com.google.gson.reflect.TypeToken;
24 import fj.data.Either;
25 import java.lang.reflect.Type;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.Iterator;
31 import java.util.List;
33 import java.util.Map.Entry;
34 import java.util.Optional;
36 import java.util.stream.Collectors;
37 import org.apache.commons.collections.MapUtils;
38 import org.apache.tinkerpop.gremlin.structure.Direction;
39 import org.apache.tinkerpop.gremlin.structure.Edge;
40 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
41 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
42 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
43 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
44 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
45 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
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.MapListCapabilityDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
63 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
64 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
65 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
66 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
67 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
68 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
69 import org.openecomp.sdc.be.model.Component;
70 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
71 import org.openecomp.sdc.be.model.ComponentParametersView;
72 import org.openecomp.sdc.be.model.DistributionStatusEnum;
73 import org.openecomp.sdc.be.model.GroupDefinition;
74 import org.openecomp.sdc.be.model.PolicyDefinition;
75 import org.openecomp.sdc.be.model.User;
76 import org.openecomp.sdc.be.model.category.CategoryDefinition;
77 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
78 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
79 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
80 import org.openecomp.sdc.be.model.jsontitan.utils.CapabilityRequirementNameResolver;
81 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
82 import org.openecomp.sdc.be.model.operations.StorageException;
83 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
84 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
85 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
86 import org.openecomp.sdc.common.api.Constants;
87 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
88 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
89 import org.openecomp.sdc.common.log.wrappers.Logger;
90 import org.openecomp.sdc.common.util.ValidationUtils;
91 import org.springframework.beans.factory.annotation.Autowired;
93 @org.springframework.stereotype.Component("topology-template-operation")
94 public class TopologyTemplateOperation extends ToscaElementOperation {
96 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
97 private Set<OriginTypeEnum> nodeTypeSet = new HashSet<>(Arrays.asList(OriginTypeEnum.VFC, OriginTypeEnum.CP, OriginTypeEnum.VL, OriginTypeEnum.Configuration, OriginTypeEnum.VFCMT));
100 private ArchiveOperation archiveOperation;
102 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
103 Either<TopologyTemplate, StorageOperationStatus> result = null;
105 topologyTemplate.generateUUID();
107 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
108 String resourceUniqueId = topologyTemplate.getUniqueId();
109 if (resourceUniqueId == null) {
110 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
111 topologyTemplate.setUniqueId(resourceUniqueId);
114 GraphVertex topologyTemplateVertex = new GraphVertex();
115 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
117 Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
118 if (createdVertex.isRight()) {
119 TitanOperationStatus status = createdVertex.right().value();
120 log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
121 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
125 topologyTemplateVertex = createdVertex.left().value();
127 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
128 if (assosiateCommon != StorageOperationStatus.OK) {
129 result = Either.right(assosiateCommon);
133 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
134 if (associateCategory != StorageOperationStatus.OK) {
135 result = Either.right(associateCategory);
139 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
140 if (associateInputs != StorageOperationStatus.OK) {
141 result = Either.right(associateInputs);
144 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
145 if (associateGroups != StorageOperationStatus.OK) {
146 result = Either.right(associateGroups);
149 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
150 if (associatePolicies != StorageOperationStatus.OK) {
151 result = Either.right(associatePolicies);
154 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
155 if (associateInstAttr != StorageOperationStatus.OK) {
156 result = Either.right(associateInstAttr);
159 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
160 if (associateInstProperties != StorageOperationStatus.OK) {
161 result = Either.right(associateInstProperties);
164 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
165 if (associateInstProperties != StorageOperationStatus.OK) {
166 result = Either.right(associateInstInputs);
169 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
170 if (associateInstGroups != StorageOperationStatus.OK) {
171 result = Either.right(associateInstInputs);
175 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
176 if (associateRequirements != StorageOperationStatus.OK) {
177 result = Either.right(associateRequirements);
181 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
182 if (associateCapabilities != StorageOperationStatus.OK) {
183 result = Either.right(associateCapabilities);
187 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
188 if (associateArtifacts != StorageOperationStatus.OK) {
189 result = Either.right(associateArtifacts);
193 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
194 if (addAdditionalInformation != StorageOperationStatus.OK) {
195 result = Either.right(addAdditionalInformation);
198 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
199 if (associateCapProperties != StorageOperationStatus.OK) {
200 result = Either.right(associateCapProperties);
204 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
205 if (associateInterfaces != StorageOperationStatus.OK) {
206 result = Either.right(associateInterfaces);
210 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
211 if (associateCapProperties != StorageOperationStatus.OK) {
212 result = Either.right(associatePathProperties);
217 return Either.left(topologyTemplate);
221 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
222 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
225 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
226 if (policies != null && !policies.isEmpty()) {
227 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
228 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
231 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
232 if (assosiateElementToData.isRight()) {
233 return assosiateElementToData.right().value();
236 return StorageOperationStatus.OK;
239 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
240 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
241 return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths);
244 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
245 TopologyTemplate topologyTemplate) {
246 Map<String, CINodeFilterDataDefinition> nodeFilters =
247 topologyTemplate.getNodeFilterComponents();
248 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
251 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
252 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
253 if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
254 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
255 if (assosiateElementToData.isRight()) {
256 return assosiateElementToData.right().value();
259 return StorageOperationStatus.OK;
262 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
263 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
264 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
265 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
266 if (assosiateElementToData.isRight()) {
267 return assosiateElementToData.right().value();
270 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
271 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
272 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
273 if (assosiateElementToData.isRight()) {
274 return assosiateElementToData.right().value();
277 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
278 if(MapUtils.isNotEmpty(capabilities)) {
279 Either<GraphVertex, StorageOperationStatus> associateElementToData =
280 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
281 EdgeLabelEnum.CAPABILITIES, capabilities);
282 if (associateElementToData.isRight()) {
283 return associateElementToData.right().value();
286 return StorageOperationStatus.OK;
290 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
291 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
292 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
293 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
294 if (assosiateElementToData.isRight()) {
295 return assosiateElementToData.right().value();
298 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
299 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
300 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
301 if (assosiateElementToData.isRight()) {
302 return assosiateElementToData.right().value();
305 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
306 if(MapUtils.isNotEmpty(requirements)) {
307 Either<GraphVertex, StorageOperationStatus> associateElementToData =
308 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
309 EdgeLabelEnum.REQUIREMENTS, requirements);
310 if (associateElementToData.isRight()) {
311 return associateElementToData.right().value();
314 return StorageOperationStatus.OK;
317 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
318 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
320 if (addInformation != null && !addInformation.isEmpty()) {
321 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
322 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
323 a.setUniqueId(uniqueId);
325 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
326 if (assosiateElementToData.isRight()) {
327 return assosiateElementToData.right().value();
330 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
332 if (instArtifacts != null && !instArtifacts.isEmpty()) {
333 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
334 if (assosiateElementToData.isRight()) {
335 return assosiateElementToData.right().value();
338 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
340 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
341 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
342 if (assosiateElementToData.isRight()) {
343 return assosiateElementToData.right().value();
346 return StorageOperationStatus.OK;
349 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
351 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
353 if (addInformation != null && !addInformation.isEmpty()) {
354 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
355 if (assosiateElementToData.isRight()) {
356 return assosiateElementToData.right().value();
359 return StorageOperationStatus.OK;
362 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
363 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
364 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
367 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
368 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
369 return associateInstInputsToComponent(nodeTypeVertex, instProps);
372 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
373 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
374 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
378 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
379 if (instProps != null && !instProps.isEmpty()) {
380 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
381 if (assosiateElementToData.isRight()) {
382 return assosiateElementToData.right().value();
385 return StorageOperationStatus.OK;
388 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
389 if (instInputs != null && !instInputs.isEmpty()) {
390 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
391 if (assosiateElementToData.isRight()) {
392 return assosiateElementToData.right().value();
395 return StorageOperationStatus.OK;
398 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
399 if (instGroups != null && !instGroups.isEmpty()) {
400 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
401 if (assosiateElementToData.isRight()) {
402 return assosiateElementToData.right().value();
405 return StorageOperationStatus.OK;
409 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
411 if (instInputs != null && !instInputs.isEmpty()) {
412 instInputs.entrySet().forEach(i -> {
413 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
414 List<String> pathKeys = new ArrayList<>();
415 pathKeys.add(i.getKey());
417 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
418 if (status != StorageOperationStatus.OK) {
424 return StorageOperationStatus.OK;
427 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
429 if (instInputs != null && !instInputs.isEmpty()) {
430 instInputs.entrySet().forEach(i -> {
431 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
432 if (status != StorageOperationStatus.OK) {
438 return StorageOperationStatus.OK;
441 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
442 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
445 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
446 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
449 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
450 if (instProps != null && !instProps.isEmpty()) {
451 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
452 if (assosiateElementToData.isRight()) {
453 return assosiateElementToData.right().value();
456 return StorageOperationStatus.OK;
459 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
460 if (calcRequirements != null && !calcRequirements.isEmpty()) {
461 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
462 if (assosiateElementToData.isRight()) {
463 return assosiateElementToData.right().value();
465 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
466 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
467 if (assosiateElementToData.isRight()) {
468 return assosiateElementToData.right().value();
471 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
472 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
473 if (assosiateElementToData.isRight()) {
474 return assosiateElementToData.right().value();
476 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
477 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
478 if (assosiateElementToData.isRight()) {
479 return assosiateElementToData.right().value();
482 if (calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty()) {
483 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
484 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
486 .on(v -> StorageOperationStatus.OK);
488 return StorageOperationStatus.OK;
491 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
492 return titanDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
493 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
494 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
497 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(TitanOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
498 if (status == TitanOperationStatus.NOT_FOUND) {
499 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
501 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
504 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
505 Optional<StorageOperationStatus> error = dataMap.entrySet()
507 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
508 .filter(s -> s != StorageOperationStatus.OK)
510 if (error.isPresent()) {
511 return Either.right(error.get());
513 return Either.left(dataVertex);
516 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
517 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
518 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
521 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
522 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
523 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
524 if (assosiateElementToData.isRight()) {
525 return assosiateElementToData.right().value();
528 return StorageOperationStatus.OK;
531 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
532 if (instAttr != null && !instAttr.isEmpty()) {
533 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
534 if (assosiateElementToData.isRight()) {
535 return assosiateElementToData.right().value();
538 return StorageOperationStatus.OK;
541 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
543 if (groups != null && !groups.isEmpty()) {
544 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
545 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
548 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
549 if (assosiateElementToData.isRight()) {
550 return assosiateElementToData.right().value();
553 return StorageOperationStatus.OK;
556 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
557 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
560 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
561 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
562 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
565 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
566 if (inputs != null && !inputs.isEmpty()) {
567 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
569 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
570 if (assosiateElementToData.isRight()) {
571 return assosiateElementToData.right().value();
574 return StorageOperationStatus.OK;
577 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
578 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
579 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
580 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
581 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
583 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
584 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
586 return nodeTypeVertex;
590 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
591 if (topologyTemplate.getResourceType() == null) {
593 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
596 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
600 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
601 String categoryName = topologyTemplate.getCategories().get(0).getName();
602 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
603 if (category.isRight()) {
604 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
605 return StorageOperationStatus.CATEGORY_NOT_FOUND;
607 GraphVertex categoryV = category.left().value();
608 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
609 if (createEdge != TitanOperationStatus.OK) {
610 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
611 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
613 return StorageOperationStatus.OK;
617 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
618 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
620 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
621 if (componentByLabelAndId.isRight()) {
622 return Either.right(componentByLabelAndId.right().value());
624 GraphVertex componentV = componentByLabelAndId.left().value();
626 return getToscaElement(componentV, componentParametersView);
629 // -------------------------------------------------------------
631 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
632 TopologyTemplate toscaElement;
634 toscaElement = convertToTopologyTemplate(componentV);
635 TitanOperationStatus status;
636 if (!componentParametersView.isIgnoreUsers()) {
637 status = setCreatorFromGraph(componentV, toscaElement);
638 if (status != TitanOperationStatus.OK) {
639 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
642 status = setLastModifierFromGraph(componentV, toscaElement);
643 if (status != TitanOperationStatus.OK) {
644 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
647 if (!componentParametersView.isIgnoreCategories()) {
648 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
649 if (status != TitanOperationStatus.OK) {
650 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
654 if (!componentParametersView.isIgnoreArtifacts()) {
655 TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
656 if (storageStatus != TitanOperationStatus.OK) {
657 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
660 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
661 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
662 if (status != TitanOperationStatus.OK) {
663 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
666 if (!componentParametersView.isIgnoreCapabilities()) {
667 status = setCapabilitiesFromGraph(componentV, toscaElement);
668 if (status != TitanOperationStatus.OK) {
669 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
672 if (!componentParametersView.isIgnoreRequirements()) {
673 status = setRequirementsFromGraph(componentV, toscaElement);
674 if (status != TitanOperationStatus.OK) {
675 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
678 if (!componentParametersView.isIgnoreAllVersions()) {
679 status = setAllVersions(componentV, toscaElement);
680 if (status != TitanOperationStatus.OK) {
681 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
684 if (!componentParametersView.isIgnoreAdditionalInformation()) {
685 status = setAdditionalInformationFromGraph(componentV, toscaElement);
686 if (status != TitanOperationStatus.OK) {
687 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
691 if (!componentParametersView.isIgnoreGroups()) {
692 status = setGroupsFromGraph(componentV, toscaElement);
693 if (status != TitanOperationStatus.OK) {
694 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
698 if (!componentParametersView.isIgnorePolicies()) {
699 status = setPoliciesFromGraph(componentV, toscaElement);
700 if (status != TitanOperationStatus.OK) {
701 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
705 if (!componentParametersView.isIgnoreComponentInstances()) {
706 status = setInstGroupsFromGraph(componentV, toscaElement);
708 //Mark all CIs that has archived origins
709 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
711 if (status != TitanOperationStatus.OK) {
712 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
716 if (!componentParametersView.isIgnoreInputs()) {
717 status = setInputsFromGraph(componentV, toscaElement);
718 if (status != TitanOperationStatus.OK) {
719 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
723 if (!componentParametersView.isIgnoreProperties()) {
724 status = setPropertiesFromGraph(componentV, toscaElement);
725 if (status != TitanOperationStatus.OK) {
726 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
731 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
732 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
733 if (status != TitanOperationStatus.OK) {
734 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
739 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
740 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
741 if (status != TitanOperationStatus.OK) {
742 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
747 if (!componentParametersView.isIgnoreForwardingPath()) {
748 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
749 if (status != TitanOperationStatus.OK) {
750 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
755 if (!componentParametersView.isIgnoreNodeFilter()) {
756 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
757 if (status != TitanOperationStatus.OK) {
758 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
763 if (!componentParametersView.isIgnoreInterfaces()) {
764 TitanOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
765 if (storageStatus != TitanOperationStatus.OK) {
766 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
771 return Either.left(toscaElement);
774 private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
775 Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
776 if (result.isLeft()) {
777 toscaElement.setPolicies(result.left().value());
779 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
780 return result.right().value();
783 return TitanOperationStatus.OK;
786 private TitanOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
787 Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
788 if (result.isLeft()) {
789 topologyTemplate.setInterfaces(result.left().value());
791 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
792 return result.right().value();
795 return TitanOperationStatus.OK;
798 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
799 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
800 if (interfaceMap != null && !interfaceMap.isEmpty()) {
801 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
802 if (assosiateElementToData.isRight()) {
803 return assosiateElementToData.right().value();
806 return StorageOperationStatus.OK;
809 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
810 Map<String, CINodeFilterDataDefinition> filterMaps) {
811 if (filterMaps != null && !filterMaps.isEmpty()) {
812 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
813 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
814 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
815 if (assosiateElementToData.isRight()) {
816 return assosiateElementToData.right().value();
819 return StorageOperationStatus.OK;
822 private TitanOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
823 Either<Map<String, ForwardingPathDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
824 if (result.isLeft()) {
825 topologyTemplate.setForwardingPaths(result.left().value());
827 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
828 return result.right().value();
831 return TitanOperationStatus.OK;
835 private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
836 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
837 if (result.isLeft()) {
838 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
840 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
841 return result.right().value();
844 return TitanOperationStatus.OK;
847 private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
848 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
849 if (result.isLeft()) {
850 toscaElement.setProperties(result.left().value());
852 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
853 return result.right().value();
856 return TitanOperationStatus.OK;
859 private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
860 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
861 if (result.isLeft()) {
862 topologyTemplate.setInstGroups(result.left().value());
864 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
865 return result.right().value();
868 return TitanOperationStatus.OK;
871 private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
872 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
873 if (result.isLeft()) {
874 topologyTemplate.setInstProperties(result.left().value());
876 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
877 return result.right().value();
880 return TitanOperationStatus.OK;
883 private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
884 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
885 if (result.isLeft()) {
886 topologyTemplate.setInstInputs(result.left().value());
888 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
889 return result.right().value();
892 return TitanOperationStatus.OK;
895 private TitanOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
896 TopologyTemplate topologyTemplate) {
897 Either<Map<String, CINodeFilterDataDefinition>, TitanOperationStatus> result =
898 getDataFromGraph(componentV,
899 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
900 if (result.isLeft()) {
901 topologyTemplate.setNodeFilterComponents(result.left().value());
903 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
904 return result.right().value();
907 return TitanOperationStatus.OK;
911 protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
912 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
913 if (result.isLeft()) {
914 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
916 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
917 return result.right().value();
920 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
921 if (result.isLeft()) {
922 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
924 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
925 return result.right().value();
928 Either<Map<String, ListRequirementDataDefinition>, TitanOperationStatus> requirementResult =
929 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
930 if (requirementResult.isLeft()) {
931 toscaElement.setRequirements(requirementResult.left().value());
933 if (requirementResult.right().value() != TitanOperationStatus.NOT_FOUND) {
934 return requirementResult.right().value();
937 return TitanOperationStatus.OK;
941 protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
942 Either<Map<String, MapListCapabilityDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
943 if (result.isLeft()) {
944 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
946 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
947 return result.right().value();
950 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
951 if (result.isLeft()) {
952 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
954 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
955 return result.right().value();
958 Either<Map<String, ListCapabilityDataDefinition>, TitanOperationStatus> capabilitiesResult =
959 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
960 if (capabilitiesResult.isLeft()) {
961 toscaElement.setCapabilities(capabilitiesResult.left().value());
963 if (capabilitiesResult.right().value() != TitanOperationStatus.NOT_FOUND) {
964 return capabilitiesResult.right().value();
967 return TitanOperationStatus.OK;
970 private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
971 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
972 if (storageStatus != TitanOperationStatus.OK) {
973 return storageStatus;
975 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
976 if (result.isLeft()) {
977 toscaElement.setServiceApiArtifacts(result.left().value());
979 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
980 return result.right().value();
983 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
984 if (resultInstArt.isLeft()) {
985 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
987 if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
988 return resultInstArt.right().value();
991 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
992 if (instanceArt.isLeft()) {
993 toscaElement.setInstanceArtifacts(instanceArt.left().value());
995 if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
996 return instanceArt.right().value();
999 return TitanOperationStatus.OK;
1002 private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1003 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1004 if (result.isLeft()) {
1005 toscaElement.setInputs(result.left().value());
1007 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1008 return result.right().value();
1011 return TitanOperationStatus.OK;
1014 private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1015 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1016 if (result.isLeft()) {
1017 toscaElement.setGroups(result.left().value());
1019 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1020 return result.right().value();
1023 return TitanOperationStatus.OK;
1026 private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1027 List<CategoryDefinition> categories = new ArrayList<>();
1029 switch (componentV.getType()) {
1031 return setResourceCategoryFromGraph(componentV, toscaElement);
1033 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1036 log.debug("Not supported component type {} ", componentV.getType());
1039 return TitanOperationStatus.OK;
1042 private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1043 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1044 if (childVertex.isRight()) {
1045 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1046 return childVertex.right().value();
1048 GraphVertex categoryV = childVertex.left().value();
1049 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1050 CategoryDefinition category = new CategoryDefinition();
1051 category.setUniqueId(categoryV.getUniqueId());
1052 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1053 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1055 Type listTypeCat = new TypeToken<List<String>>() {
1057 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1058 category.setIcons(iconsfromJsonCat);
1059 categories.add(category);
1060 toscaElement.setCategories(categories);
1062 return TitanOperationStatus.OK;
1065 @SuppressWarnings("unchecked")
1066 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1068 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1070 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1071 topologyTemplate.setCompositions(json);
1073 return topologyTemplate;
1077 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1078 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1079 if (nodeType.isRight()) {
1080 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1083 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1084 if (status != TitanOperationStatus.OK) {
1085 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1087 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1088 if (status != TitanOperationStatus.OK) {
1089 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1090 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1092 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1093 if (status != TitanOperationStatus.OK) {
1094 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1095 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1098 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1099 if (status != TitanOperationStatus.OK) {
1100 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1101 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1104 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1105 if (status != TitanOperationStatus.OK) {
1106 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1107 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1109 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1110 if (status != TitanOperationStatus.OK) {
1111 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1112 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1114 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1115 if (status != TitanOperationStatus.OK) {
1116 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1117 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1119 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1120 if (status != TitanOperationStatus.OK) {
1121 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1122 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1124 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1125 if (status != TitanOperationStatus.OK) {
1126 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1127 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1129 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1130 if (status != TitanOperationStatus.OK) {
1131 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1132 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1134 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1135 if (status != TitanOperationStatus.OK) {
1136 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1137 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1139 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1140 if (status != TitanOperationStatus.OK) {
1141 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1142 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1144 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1145 if (status != TitanOperationStatus.OK) {
1146 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1147 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1149 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1150 if (status != TitanOperationStatus.OK) {
1151 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1152 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1154 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1155 if (status != TitanOperationStatus.OK) {
1156 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1157 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1159 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1160 if (status != TitanOperationStatus.OK) {
1161 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1162 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1164 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1165 if (status != TitanOperationStatus.OK) {
1166 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1167 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1169 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1170 if (status != TitanOperationStatus.OK) {
1171 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1172 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1174 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1175 if (status != TitanOperationStatus.OK) {
1176 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1177 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1180 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1181 EdgeLabelEnum.REQUIREMENTS);
1182 if (status != TitanOperationStatus.OK) {
1183 log.debug("Failed to disassociate requirements for {} error {}",
1184 toscaElementVertex.getUniqueId(), status);
1185 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1187 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1188 EdgeLabelEnum.CAPABILITIES);
1189 if (status != TitanOperationStatus.OK) {
1190 log.debug("Failed to disassociate capabilities for {} error {}",
1191 toscaElementVertex.getUniqueId(), status);
1192 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1195 toscaElementVertex.getVertex().remove();
1196 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1201 @SuppressWarnings("unchecked")
1203 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1204 return createTopologyTemplate((TopologyTemplate) toscaElement);
1208 protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1209 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1213 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1214 // Product isn't supported now!!
1215 // TODO add for Product
1216 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1217 return validateServiceCategory(toscaElementToUpdate, elementV);
1220 return validateResourceCategory(toscaElementToUpdate, elementV);
1225 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1226 // not relevant now for topology template
1227 return StorageOperationStatus.OK;
1231 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1232 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1235 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1236 StorageOperationStatus status = StorageOperationStatus.OK;
1237 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1238 CategoryDefinition newCategory = newCategoryList.get(0);
1240 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1241 if (childVertex.isRight()) {
1242 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1243 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1246 GraphVertex categoryV = childVertex.left().value();
1247 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1248 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1250 String newCategoryName = newCategory.getName();
1251 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1252 // the category was changed
1253 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1255 if (getCategoryVertex.isRight()) {
1256 return getCategoryVertex.right().value();
1258 GraphVertex newCategoryV = getCategoryVertex.left().value();
1259 status = moveCategoryEdge(elementV, newCategoryV);
1260 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1265 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1267 Either<GraphVertex, StorageOperationStatus> result = null;
1268 String userId = user.getUserId();
1269 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
1270 GraphVertex userVertex = null;
1271 GraphVertex serviceVertex = null;
1272 if (getRes.isRight()) {
1273 TitanOperationStatus status = getRes.right().value();
1274 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1275 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1277 if (result == null) {
1278 userVertex = getRes.left().value();
1279 getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1280 if (getRes.isRight()) {
1281 TitanOperationStatus status = getRes.right().value();
1282 log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status);
1283 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1286 if (result == null) {
1287 serviceVertex = getRes.left().value();
1288 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1289 if (edgeIterator.hasNext()) {
1290 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1291 edgeIterator.next().remove();
1294 if (result == null) {
1295 TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1296 if (status != TitanOperationStatus.OK) {
1297 log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1298 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1301 if (result == null) {
1302 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1303 long lastUpdateDate = System.currentTimeMillis();
1304 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1305 Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1306 if (updateRes.isRight()) {
1307 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1310 if (result == null) {
1311 result = Either.left(serviceVertex);
1317 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1319 * @param componentId
1321 * @param capabilityName
1322 * @param capabilityType
1326 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1328 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1329 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1330 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1331 if (componentByLabelAndId.isRight()) {
1332 result = Either.right(componentByLabelAndId.right().value());
1334 if (componentByLabelAndId.isLeft()) {
1335 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1336 if (getDataRes.isRight()) {
1337 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
1339 mapPropertiesDataDefinition = getDataRes.left().value();
1342 if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
1343 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1348 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1349 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1353 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1354 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1355 mapPropertiesDataDefinition.get(instanceId) != null &&
1356 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1359 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1360 List<ComponentInstanceProperty> capPropsList = null;
1361 for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
1362 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1363 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1364 if (capMap != null && !capMap.isEmpty()) {
1365 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1370 if (capPropsList == null) {
1371 capPropsList = new ArrayList<>();
1373 return capPropsList;
1376 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1377 if (capProp != null) {
1378 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
1379 if (path.length < 4) {
1380 log.debug("wrong key format for capabilty, key {}", capProp);
1383 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1388 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1389 fillPolicyDefinition(componentV, policyDefinition, counter);
1390 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1393 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1394 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1397 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1398 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1401 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1402 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1405 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1406 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1409 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1410 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.NAME);
1413 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1414 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1415 policyDefinition.setName(policyName);
1416 policyDefinition.setInvariantName(policyName);
1417 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1418 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1419 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1420 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1423 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1424 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1425 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1426 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1429 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1430 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1431 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1433 .on(this::throwStorageException);
1434 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1435 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1437 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1438 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1440 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1441 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1442 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1446 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1447 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1448 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1450 .on(this::throwStorageException);
1451 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1452 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1454 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1455 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1457 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1458 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1459 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1463 private GraphVertex throwStorageException(TitanOperationStatus status) {
1464 throw new StorageException(status);
1467 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1468 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1469 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1470 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1471 if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
1472 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1475 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1477 if (getOriginRes.isRight()) {
1478 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1479 throw new StorageException(getOriginRes.right().value());
1481 return getOriginRes.left().value();
1484 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1485 log.debug("#detectToscaType - type: {}", originType);
1486 if (nodeTypeSet.contains(originType)){
1487 return ToscaElementTypeEnum.NODE_TYPE;
1489 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1493 private ComponentParametersView getFilter() {
1494 ComponentParametersView filter = new ComponentParametersView();
1495 filter.setIgnoreCapabilities(false);
1496 filter.setIgnoreCapabiltyProperties(false);
1497 filter.setIgnoreRequirements(false);
1500 public void updateCapReqOwnerId(String componentId, TopologyTemplate toscaElement) {
1501 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1502 .left().on(this::throwStorageException);
1503 updateCapOwnerId(toscaElement, componentId);
1504 updateReqOwnerId(toscaElement, componentId);
1505 topologyTemplateOperation
1507 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1508 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1509 topologyTemplateOperation
1510 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1511 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1514 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1515 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1516 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1517 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1521 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1522 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1523 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1524 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));