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.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.enums.ComponentTypeEnum;
66 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
67 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
68 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
69 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
70 import org.openecomp.sdc.be.model.Component;
71 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
72 import org.openecomp.sdc.be.model.ComponentParametersView;
73 import org.openecomp.sdc.be.model.DistributionStatusEnum;
74 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.jsontitan.datamodel.TopologyTemplate;
80 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
81 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
82 import org.openecomp.sdc.be.model.jsontitan.utils.CapabilityRequirementNameResolver;
83 import org.openecomp.sdc.be.model.jsontitan.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.wrappers.Logger;
92 import org.openecomp.sdc.common.util.ValidationUtils;
93 import org.springframework.beans.factory.annotation.Autowired;
95 @org.springframework.stereotype.Component("topology-template-operation")
96 public class TopologyTemplateOperation extends ToscaElementOperation {
98 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
99 private Set<OriginTypeEnum> nodeTypeSet = new HashSet<>(Arrays.asList(OriginTypeEnum.VFC, OriginTypeEnum.CP, OriginTypeEnum.VL, OriginTypeEnum.Configuration, OriginTypeEnum.VFCMT));
102 private ArchiveOperation archiveOperation;
104 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
105 Either<TopologyTemplate, StorageOperationStatus> result = null;
107 topologyTemplate.generateUUID();
109 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
110 String resourceUniqueId = topologyTemplate.getUniqueId();
111 if (resourceUniqueId == null) {
112 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
113 topologyTemplate.setUniqueId(resourceUniqueId);
116 GraphVertex topologyTemplateVertex = new GraphVertex();
117 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
119 Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
120 if (createdVertex.isRight()) {
121 TitanOperationStatus status = createdVertex.right().value();
122 log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
123 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
127 topologyTemplateVertex = createdVertex.left().value();
129 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
130 if (assosiateCommon != StorageOperationStatus.OK) {
131 result = Either.right(assosiateCommon);
135 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
136 if (associateCategory != StorageOperationStatus.OK) {
137 result = Either.right(associateCategory);
141 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
142 if (associateInputs != StorageOperationStatus.OK) {
143 result = Either.right(associateInputs);
146 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
147 if (associateGroups != StorageOperationStatus.OK) {
148 result = Either.right(associateGroups);
151 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
152 if (associatePolicies != StorageOperationStatus.OK) {
153 result = Either.right(associatePolicies);
156 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
157 if (associateInstAttr != StorageOperationStatus.OK) {
158 result = Either.right(associateInstAttr);
161 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
162 if (associateInstProperties != StorageOperationStatus.OK) {
163 result = Either.right(associateInstProperties);
166 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
167 if (associateInstProperties != StorageOperationStatus.OK) {
168 result = Either.right(associateInstInputs);
171 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
172 if (associateInstGroups != StorageOperationStatus.OK) {
173 result = Either.right(associateInstInputs);
177 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
178 if (associateRequirements != StorageOperationStatus.OK) {
179 result = Either.right(associateRequirements);
183 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
184 if (associateCapabilities != StorageOperationStatus.OK) {
185 result = Either.right(associateCapabilities);
189 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
190 if (associateArtifacts != StorageOperationStatus.OK) {
191 result = Either.right(associateArtifacts);
195 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
196 if (addAdditionalInformation != StorageOperationStatus.OK) {
197 result = Either.right(addAdditionalInformation);
200 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
201 if (associateCapProperties != StorageOperationStatus.OK) {
202 result = Either.right(associateCapProperties);
206 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
207 if (associateInterfaces != StorageOperationStatus.OK) {
208 result = Either.right(associateInterfaces);
212 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
213 if (associateCapProperties != StorageOperationStatus.OK) {
214 result = Either.right(associatePathProperties);
219 return Either.left(topologyTemplate);
223 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
224 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
227 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
228 if (policies != null && !policies.isEmpty()) {
229 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
230 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
233 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
234 if (assosiateElementToData.isRight()) {
235 return assosiateElementToData.right().value();
238 return StorageOperationStatus.OK;
241 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
242 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
243 return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths);
246 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
247 TopologyTemplate topologyTemplate) {
248 Map<String, CINodeFilterDataDefinition> nodeFilters =
249 topologyTemplate.getNodeFilterComponents();
250 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
253 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
254 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
255 if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
256 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
257 if (assosiateElementToData.isRight()) {
258 return assosiateElementToData.right().value();
261 return StorageOperationStatus.OK;
264 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
265 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
266 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
267 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
268 if (assosiateElementToData.isRight()) {
269 return assosiateElementToData.right().value();
272 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
273 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
274 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
275 if (assosiateElementToData.isRight()) {
276 return assosiateElementToData.right().value();
279 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
280 if(MapUtils.isNotEmpty(capabilities)) {
281 Either<GraphVertex, StorageOperationStatus> associateElementToData =
282 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
283 EdgeLabelEnum.CAPABILITIES, capabilities);
284 if (associateElementToData.isRight()) {
285 return associateElementToData.right().value();
288 return StorageOperationStatus.OK;
292 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
293 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
294 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
295 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
296 if (assosiateElementToData.isRight()) {
297 return assosiateElementToData.right().value();
300 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
301 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
302 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
303 if (assosiateElementToData.isRight()) {
304 return assosiateElementToData.right().value();
307 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
308 if(MapUtils.isNotEmpty(requirements)) {
309 Either<GraphVertex, StorageOperationStatus> associateElementToData =
310 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
311 EdgeLabelEnum.REQUIREMENTS, requirements);
312 if (associateElementToData.isRight()) {
313 return associateElementToData.right().value();
316 return StorageOperationStatus.OK;
319 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
320 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
322 if (addInformation != null && !addInformation.isEmpty()) {
323 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
324 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
325 a.setUniqueId(uniqueId);
327 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
328 if (assosiateElementToData.isRight()) {
329 return assosiateElementToData.right().value();
332 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
334 if (instArtifacts != null && !instArtifacts.isEmpty()) {
335 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
336 if (assosiateElementToData.isRight()) {
337 return assosiateElementToData.right().value();
340 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
342 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
343 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
344 if (assosiateElementToData.isRight()) {
345 return assosiateElementToData.right().value();
348 return StorageOperationStatus.OK;
351 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
353 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
355 if (addInformation != null && !addInformation.isEmpty()) {
356 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
357 if (assosiateElementToData.isRight()) {
358 return assosiateElementToData.right().value();
361 return StorageOperationStatus.OK;
364 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
365 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
366 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
369 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
370 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
371 return associateInstInputsToComponent(nodeTypeVertex, instProps);
374 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
375 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
376 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
380 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
381 if (instProps != null && !instProps.isEmpty()) {
382 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
383 if (assosiateElementToData.isRight()) {
384 return assosiateElementToData.right().value();
387 return StorageOperationStatus.OK;
390 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
391 if (instInputs != null && !instInputs.isEmpty()) {
392 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
393 if (assosiateElementToData.isRight()) {
394 return assosiateElementToData.right().value();
397 return StorageOperationStatus.OK;
400 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
401 if (instGroups != null && !instGroups.isEmpty()) {
402 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
403 if (assosiateElementToData.isRight()) {
404 return assosiateElementToData.right().value();
407 return StorageOperationStatus.OK;
411 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
413 if (instInputs != null && !instInputs.isEmpty()) {
414 instInputs.entrySet().forEach(i -> {
415 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
416 List<String> pathKeys = new ArrayList<>();
417 pathKeys.add(i.getKey());
419 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
420 if (status != StorageOperationStatus.OK) {
426 return StorageOperationStatus.OK;
429 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
431 if (instInputs != null && !instInputs.isEmpty()) {
432 instInputs.entrySet().forEach(i -> {
433 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
434 if (status != StorageOperationStatus.OK) {
440 return StorageOperationStatus.OK;
443 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
444 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
447 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
448 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
451 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
452 if (instProps != null && !instProps.isEmpty()) {
453 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
454 if (assosiateElementToData.isRight()) {
455 return assosiateElementToData.right().value();
458 return StorageOperationStatus.OK;
461 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
462 if (calcRequirements != null && !calcRequirements.isEmpty()) {
463 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
464 if (assosiateElementToData.isRight()) {
465 return assosiateElementToData.right().value();
467 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
468 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
469 if (assosiateElementToData.isRight()) {
470 return assosiateElementToData.right().value();
473 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
474 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
475 if (assosiateElementToData.isRight()) {
476 return assosiateElementToData.right().value();
478 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
479 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
480 if (assosiateElementToData.isRight()) {
481 return assosiateElementToData.right().value();
484 if (calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty()) {
485 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
486 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
488 .on(v -> StorageOperationStatus.OK);
490 return StorageOperationStatus.OK;
493 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
494 return titanDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
495 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
496 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
499 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(TitanOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
500 if (status == TitanOperationStatus.NOT_FOUND) {
501 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
503 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
506 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
507 Optional<StorageOperationStatus> error = dataMap.entrySet()
509 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
510 .filter(s -> s != StorageOperationStatus.OK)
512 if (error.isPresent()) {
513 return Either.right(error.get());
515 return Either.left(dataVertex);
518 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
519 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
520 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
523 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
524 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
525 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
526 if (assosiateElementToData.isRight()) {
527 return assosiateElementToData.right().value();
530 return StorageOperationStatus.OK;
533 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
534 if (instAttr != null && !instAttr.isEmpty()) {
535 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
536 if (assosiateElementToData.isRight()) {
537 return assosiateElementToData.right().value();
540 return StorageOperationStatus.OK;
543 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
545 if (groups != null && !groups.isEmpty()) {
546 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
547 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
550 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
551 if (assosiateElementToData.isRight()) {
552 return assosiateElementToData.right().value();
555 return StorageOperationStatus.OK;
558 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
559 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
562 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
563 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
564 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
567 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
568 if (inputs != null && !inputs.isEmpty()) {
569 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
571 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
572 if (assosiateElementToData.isRight()) {
573 return assosiateElementToData.right().value();
576 return StorageOperationStatus.OK;
579 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
580 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
581 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
582 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
583 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
585 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
586 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
588 return nodeTypeVertex;
592 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
593 if (topologyTemplate.getResourceType() == null) {
595 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
598 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
602 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
603 String categoryName = topologyTemplate.getCategories().get(0).getName();
604 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
605 if (category.isRight()) {
606 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
607 return StorageOperationStatus.CATEGORY_NOT_FOUND;
609 GraphVertex categoryV = category.left().value();
610 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
611 if (createEdge != TitanOperationStatus.OK) {
612 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
613 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
615 return StorageOperationStatus.OK;
619 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
620 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
622 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
623 if (componentByLabelAndId.isRight()) {
624 return Either.right(componentByLabelAndId.right().value());
626 GraphVertex componentV = componentByLabelAndId.left().value();
628 return getToscaElement(componentV, componentParametersView);
631 // -------------------------------------------------------------
633 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
634 TopologyTemplate toscaElement;
636 toscaElement = convertToTopologyTemplate(componentV);
637 TitanOperationStatus status;
638 if (!componentParametersView.isIgnoreUsers()) {
639 status = setCreatorFromGraph(componentV, toscaElement);
640 if (status != TitanOperationStatus.OK) {
641 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
644 status = setLastModifierFromGraph(componentV, toscaElement);
645 if (status != TitanOperationStatus.OK) {
646 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
649 if (!componentParametersView.isIgnoreCategories()) {
650 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
651 if (status != TitanOperationStatus.OK) {
652 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
656 if (!componentParametersView.isIgnoreArtifacts()) {
657 TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
658 if (storageStatus != TitanOperationStatus.OK) {
659 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
662 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
663 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
664 if (status != TitanOperationStatus.OK) {
665 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
668 if (!componentParametersView.isIgnoreCapabilities()) {
669 status = setCapabilitiesFromGraph(componentV, toscaElement);
670 if (status != TitanOperationStatus.OK) {
671 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
674 if (!componentParametersView.isIgnoreRequirements()) {
675 status = setRequirementsFromGraph(componentV, toscaElement);
676 if (status != TitanOperationStatus.OK) {
677 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
680 if (!componentParametersView.isIgnoreAllVersions()) {
681 status = setAllVersions(componentV, toscaElement);
682 if (status != TitanOperationStatus.OK) {
683 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
686 if (!componentParametersView.isIgnoreAdditionalInformation()) {
687 status = setAdditionalInformationFromGraph(componentV, toscaElement);
688 if (status != TitanOperationStatus.OK) {
689 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
693 if (!componentParametersView.isIgnoreGroups()) {
694 status = setGroupsFromGraph(componentV, toscaElement);
695 if (status != TitanOperationStatus.OK) {
696 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
700 if (!componentParametersView.isIgnorePolicies()) {
701 status = setPoliciesFromGraph(componentV, toscaElement);
702 if (status != TitanOperationStatus.OK) {
703 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
707 if (!componentParametersView.isIgnoreComponentInstances()) {
708 status = setInstGroupsFromGraph(componentV, toscaElement);
710 //Mark all CIs that has archived origins
711 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
713 if (status != TitanOperationStatus.OK) {
714 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
718 if (!componentParametersView.isIgnoreInputs()) {
719 status = setInputsFromGraph(componentV, toscaElement);
720 if (status != TitanOperationStatus.OK) {
721 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
725 if (!componentParametersView.isIgnoreProperties()) {
726 status = setPropertiesFromGraph(componentV, toscaElement);
727 if (status != TitanOperationStatus.OK) {
728 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
733 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
734 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
735 if (status != TitanOperationStatus.OK) {
736 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
741 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
742 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
743 if (status != TitanOperationStatus.OK) {
744 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
749 if (!componentParametersView.isIgnoreForwardingPath()) {
750 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
751 if (status != TitanOperationStatus.OK) {
752 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
757 if (!componentParametersView.isIgnoreNodeFilter()) {
758 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
759 if (status != TitanOperationStatus.OK) {
760 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
765 if (!componentParametersView.isIgnoreInterfaces()) {
766 TitanOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
767 if (storageStatus != TitanOperationStatus.OK) {
768 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
773 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
774 TitanOperationStatus storageStatus =
775 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
776 if (storageStatus != TitanOperationStatus.OK) {
777 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
780 return Either.left(toscaElement);
783 private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
784 Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
785 if (result.isLeft()) {
786 toscaElement.setPolicies(result.left().value());
788 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
789 return result.right().value();
792 return TitanOperationStatus.OK;
795 private TitanOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
796 Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
797 if (result.isLeft()) {
798 topologyTemplate.setInterfaces(result.left().value());
800 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
801 return result.right().value();
804 return TitanOperationStatus.OK;
808 private TitanOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
809 TopologyTemplate topologyTemplate) {
810 Either<Map<String, MapInterfaceDataDefinition>, TitanOperationStatus> result =
811 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
812 if (result.isLeft()) {
813 result.left().value().entrySet().forEach(entry -> topologyTemplate
814 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
816 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
817 return result.right().value();
820 return TitanOperationStatus.OK;
823 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
824 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
825 if (interfaceMap != null && !interfaceMap.isEmpty()) {
826 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
827 if (assosiateElementToData.isRight()) {
828 return assosiateElementToData.right().value();
831 return StorageOperationStatus.OK;
834 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
835 Map<String, CINodeFilterDataDefinition> filterMaps) {
836 if (filterMaps != null && !filterMaps.isEmpty()) {
837 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
838 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
839 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
840 if (assosiateElementToData.isRight()) {
841 return assosiateElementToData.right().value();
844 return StorageOperationStatus.OK;
847 private TitanOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
848 Either<Map<String, ForwardingPathDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
849 if (result.isLeft()) {
850 topologyTemplate.setForwardingPaths(result.left().value());
852 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
853 return result.right().value();
856 return TitanOperationStatus.OK;
860 private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
861 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
862 if (result.isLeft()) {
863 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
865 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
866 return result.right().value();
869 return TitanOperationStatus.OK;
872 private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
873 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
874 if (result.isLeft()) {
875 toscaElement.setProperties(result.left().value());
877 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
878 return result.right().value();
881 return TitanOperationStatus.OK;
884 private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
885 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
886 if (result.isLeft()) {
887 topologyTemplate.setInstGroups(result.left().value());
889 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
890 return result.right().value();
893 return TitanOperationStatus.OK;
896 private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
897 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
898 if (result.isLeft()) {
899 topologyTemplate.setInstProperties(result.left().value());
901 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
902 return result.right().value();
905 return TitanOperationStatus.OK;
908 private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
909 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
910 if (result.isLeft()) {
911 topologyTemplate.setInstInputs(result.left().value());
913 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
914 return result.right().value();
917 return TitanOperationStatus.OK;
920 private TitanOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
921 TopologyTemplate topologyTemplate) {
922 Either<Map<String, CINodeFilterDataDefinition>, TitanOperationStatus> result =
923 getDataFromGraph(componentV,
924 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
925 if (result.isLeft()) {
926 topologyTemplate.setNodeFilterComponents(result.left().value());
928 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
929 return result.right().value();
932 return TitanOperationStatus.OK;
936 protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
937 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
938 if (result.isLeft()) {
939 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
941 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
942 return result.right().value();
945 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
946 if (result.isLeft()) {
947 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
949 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
950 return result.right().value();
953 Either<Map<String, ListRequirementDataDefinition>, TitanOperationStatus> requirementResult =
954 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
955 if (requirementResult.isLeft()) {
956 toscaElement.setRequirements(requirementResult.left().value());
958 if (requirementResult.right().value() != TitanOperationStatus.NOT_FOUND) {
959 return requirementResult.right().value();
962 return TitanOperationStatus.OK;
966 protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
967 Either<Map<String, MapListCapabilityDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
968 if (result.isLeft()) {
969 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
971 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
972 return result.right().value();
975 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
976 if (result.isLeft()) {
977 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
979 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
980 return result.right().value();
983 Either<Map<String, ListCapabilityDataDefinition>, TitanOperationStatus> capabilitiesResult =
984 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
985 if (capabilitiesResult.isLeft()) {
986 toscaElement.setCapabilities(capabilitiesResult.left().value());
988 if (capabilitiesResult.right().value() != TitanOperationStatus.NOT_FOUND) {
989 return capabilitiesResult.right().value();
992 return TitanOperationStatus.OK;
995 private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
996 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
997 if (storageStatus != TitanOperationStatus.OK) {
998 return storageStatus;
1000 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1001 if (result.isLeft()) {
1002 toscaElement.setServiceApiArtifacts(result.left().value());
1004 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1005 return result.right().value();
1008 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1009 if (resultInstArt.isLeft()) {
1010 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1012 if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
1013 return resultInstArt.right().value();
1016 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1017 if (instanceArt.isLeft()) {
1018 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1020 if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
1021 return instanceArt.right().value();
1024 return TitanOperationStatus.OK;
1027 private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1028 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1029 if (result.isLeft()) {
1030 toscaElement.setInputs(result.left().value());
1032 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1033 return result.right().value();
1036 return TitanOperationStatus.OK;
1039 private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1040 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1041 if (result.isLeft()) {
1042 toscaElement.setGroups(result.left().value());
1044 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1045 return result.right().value();
1048 return TitanOperationStatus.OK;
1051 private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1052 List<CategoryDefinition> categories = new ArrayList<>();
1054 switch (componentV.getType()) {
1056 return setResourceCategoryFromGraph(componentV, toscaElement);
1058 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1061 log.debug("Not supported component type {} ", componentV.getType());
1064 return TitanOperationStatus.OK;
1067 private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1068 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1069 if (childVertex.isRight()) {
1070 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1071 return childVertex.right().value();
1073 GraphVertex categoryV = childVertex.left().value();
1074 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1075 CategoryDefinition category = new CategoryDefinition();
1076 category.setUniqueId(categoryV.getUniqueId());
1077 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1078 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1080 Type listTypeCat = new TypeToken<List<String>>() {
1082 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1083 category.setIcons(iconsfromJsonCat);
1084 categories.add(category);
1085 toscaElement.setCategories(categories);
1087 return TitanOperationStatus.OK;
1090 @SuppressWarnings("unchecked")
1091 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1093 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1095 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1096 topologyTemplate.setCompositions(json);
1098 return topologyTemplate;
1102 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1103 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1104 if (nodeType.isRight()) {
1105 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1108 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1109 if (status != TitanOperationStatus.OK) {
1110 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1112 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1113 if (status != TitanOperationStatus.OK) {
1114 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1115 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1117 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1118 if (status != TitanOperationStatus.OK) {
1119 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1120 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1123 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1124 if (status != TitanOperationStatus.OK) {
1125 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1126 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1129 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1130 if (status != TitanOperationStatus.OK) {
1131 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1132 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1134 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1135 if (status != TitanOperationStatus.OK) {
1136 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1137 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1139 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1140 if (status != TitanOperationStatus.OK) {
1141 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1142 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1144 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1145 if (status != TitanOperationStatus.OK) {
1146 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1147 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1149 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1150 if (status != TitanOperationStatus.OK) {
1151 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1152 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1154 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1155 if (status != TitanOperationStatus.OK) {
1156 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1157 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1159 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1160 if (status != TitanOperationStatus.OK) {
1161 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1162 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1164 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1165 if (status != TitanOperationStatus.OK) {
1166 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1167 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1169 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1170 if (status != TitanOperationStatus.OK) {
1171 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1172 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1174 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1175 if (status != TitanOperationStatus.OK) {
1176 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1177 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1179 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1180 if (status != TitanOperationStatus.OK) {
1181 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1182 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1184 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1185 if (status != TitanOperationStatus.OK) {
1186 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1187 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1189 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1190 if (status != TitanOperationStatus.OK) {
1191 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1192 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1194 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1195 if (status != TitanOperationStatus.OK) {
1196 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1197 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1199 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1200 if (status != TitanOperationStatus.OK) {
1201 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1202 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1205 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1206 EdgeLabelEnum.REQUIREMENTS);
1207 if (status != TitanOperationStatus.OK) {
1208 log.debug("Failed to disassociate requirements for {} error {}",
1209 toscaElementVertex.getUniqueId(), status);
1210 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1212 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1213 EdgeLabelEnum.CAPABILITIES);
1214 if (status != TitanOperationStatus.OK) {
1215 log.debug("Failed to disassociate capabilities for {} error {}",
1216 toscaElementVertex.getUniqueId(), status);
1217 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1219 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1220 if (status != TitanOperationStatus.OK) {
1221 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1222 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1224 toscaElementVertex.getVertex().remove();
1225 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1230 @SuppressWarnings("unchecked")
1232 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1233 return createTopologyTemplate((TopologyTemplate) toscaElement);
1237 protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1238 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1242 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1243 // Product isn't supported now!!
1244 // TODO add for Product
1245 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1246 return validateServiceCategory(toscaElementToUpdate, elementV);
1249 return validateResourceCategory(toscaElementToUpdate, elementV);
1254 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1255 // not relevant now for topology template
1256 return StorageOperationStatus.OK;
1260 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1261 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1264 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1265 StorageOperationStatus status = StorageOperationStatus.OK;
1266 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1267 CategoryDefinition newCategory = newCategoryList.get(0);
1269 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1270 if (childVertex.isRight()) {
1271 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1272 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1275 GraphVertex categoryV = childVertex.left().value();
1276 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1277 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1279 String newCategoryName = newCategory.getName();
1280 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1281 // the category was changed
1282 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1284 if (getCategoryVertex.isRight()) {
1285 return getCategoryVertex.right().value();
1287 GraphVertex newCategoryV = getCategoryVertex.left().value();
1288 status = moveCategoryEdge(elementV, newCategoryV);
1289 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1294 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1296 Either<GraphVertex, StorageOperationStatus> result = null;
1297 String userId = user.getUserId();
1298 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
1299 GraphVertex userVertex = null;
1300 GraphVertex serviceVertex = null;
1301 if (getRes.isRight()) {
1302 TitanOperationStatus status = getRes.right().value();
1303 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1304 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1306 if (result == null) {
1307 userVertex = getRes.left().value();
1308 getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1309 if (getRes.isRight()) {
1310 TitanOperationStatus status = getRes.right().value();
1311 log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status);
1312 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1315 if (result == null) {
1316 serviceVertex = getRes.left().value();
1317 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1318 if (edgeIterator.hasNext()) {
1319 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1320 edgeIterator.next().remove();
1323 if (result == null) {
1324 TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1325 if (status != TitanOperationStatus.OK) {
1326 log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1327 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1330 if (result == null) {
1331 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1332 long lastUpdateDate = System.currentTimeMillis();
1333 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1334 Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1335 if (updateRes.isRight()) {
1336 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1339 if (result == null) {
1340 result = Either.left(serviceVertex);
1346 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1348 * @param componentId
1350 * @param capabilityName
1351 * @param capabilityType
1355 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1357 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1358 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1359 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1360 if (componentByLabelAndId.isRight()) {
1361 result = Either.right(componentByLabelAndId.right().value());
1363 if (componentByLabelAndId.isLeft()) {
1364 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1365 if (getDataRes.isRight()) {
1366 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
1368 mapPropertiesDataDefinition = getDataRes.left().value();
1371 if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
1372 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1377 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1378 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1381 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1382 String componentInstanceId,
1383 MapInterfaceDataDefinition instanceInterfaces) {
1384 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1385 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1386 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1388 return StorageOperationStatus.OK;
1392 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1393 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1394 mapPropertiesDataDefinition.get(instanceId) != null &&
1395 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1398 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1399 List<ComponentInstanceProperty> capPropsList = null;
1400 for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
1401 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1402 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1403 if (capMap != null && !capMap.isEmpty()) {
1404 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1409 if (capPropsList == null) {
1410 capPropsList = new ArrayList<>();
1412 return capPropsList;
1415 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1416 if (capProp != null) {
1417 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
1418 if (path.length < 4) {
1419 log.debug("wrong key format for capabilty, key {}", capProp);
1422 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1427 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1428 fillPolicyDefinition(componentV, policyDefinition, counter);
1429 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1432 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1433 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1436 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1437 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1440 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1441 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1444 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1445 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1448 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1449 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.NAME);
1452 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1453 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1454 policyDefinition.setName(policyName);
1455 policyDefinition.setInvariantName(policyName);
1456 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1457 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1458 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1459 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1462 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1463 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1464 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1465 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1468 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1469 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1470 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1472 .on(this::throwStorageException);
1473 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1474 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1476 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1477 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1479 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1480 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1481 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1485 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1486 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1487 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1489 .on(this::throwStorageException);
1490 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1491 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1493 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1494 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1496 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1497 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1498 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1502 private GraphVertex throwStorageException(TitanOperationStatus status) {
1503 throw new StorageException(status);
1506 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1507 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1508 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1509 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1510 if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
1511 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1514 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1516 if (getOriginRes.isRight()) {
1517 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1518 throw new StorageException(getOriginRes.right().value());
1520 return getOriginRes.left().value();
1523 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1524 log.debug("#detectToscaType - type: {}", originType);
1525 if (nodeTypeSet.contains(originType)){
1526 return ToscaElementTypeEnum.NODE_TYPE;
1528 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1532 private ComponentParametersView getFilter() {
1533 ComponentParametersView filter = new ComponentParametersView();
1534 filter.setIgnoreCapabilities(false);
1535 filter.setIgnoreCapabiltyProperties(false);
1536 filter.setIgnoreRequirements(false);
1539 public void updateCapReqOwnerId(String componentId, TopologyTemplate toscaElement) {
1540 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1541 .left().on(this::throwStorageException);
1542 updateCapOwnerId(toscaElement, componentId);
1543 updateReqOwnerId(toscaElement, componentId);
1544 topologyTemplateOperation
1546 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1547 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1548 topologyTemplateOperation
1549 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1550 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1553 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1554 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1555 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1556 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1560 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1561 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1562 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1563 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));