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 org.apache.commons.collections.MapUtils;
26 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
27 import org.apache.tinkerpop.gremlin.structure.Direction;
28 import org.apache.tinkerpop.gremlin.structure.Edge;
29 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
30 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
31 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
32 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
33 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
34 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
38 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
47 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
55 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
56 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
57 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
58 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
59 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
60 import org.openecomp.sdc.be.model.Component;
61 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
62 import org.openecomp.sdc.be.model.ComponentParametersView;
63 import org.openecomp.sdc.be.model.DistributionStatusEnum;
64 import org.openecomp.sdc.be.model.GroupDefinition;
65 import org.openecomp.sdc.be.model.PolicyDefinition;
66 import org.openecomp.sdc.be.model.User;
67 import org.openecomp.sdc.be.model.category.CategoryDefinition;
68 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
69 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
70 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
71 import org.openecomp.sdc.be.model.jsontitan.utils.CapabilityRequirementNameResolver;
72 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
73 import org.openecomp.sdc.be.model.operations.StorageException;
74 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
75 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
76 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
77 import org.openecomp.sdc.common.api.Constants;
78 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
79 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
80 import org.openecomp.sdc.common.log.wrappers.Logger;
81 import org.openecomp.sdc.common.util.ValidationUtils;
82 import org.springframework.beans.factory.annotation.Autowired;
84 import java.lang.reflect.Type;
85 import java.util.ArrayList;
86 import java.util.Arrays;
87 import java.util.HashMap;
88 import java.util.HashSet;
89 import java.util.Iterator;
90 import java.util.List;
92 import java.util.Map.Entry;
93 import java.util.Optional;
95 import java.util.stream.Collectors;
97 @org.springframework.stereotype.Component("topology-template-operation")
98 public class TopologyTemplateOperation extends ToscaElementOperation {
100 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
101 private Set<OriginTypeEnum> nodeTypeSet = new HashSet<>(Arrays.asList(OriginTypeEnum.VFC, OriginTypeEnum.CP, OriginTypeEnum.VL, OriginTypeEnum.Configuration, OriginTypeEnum.VFCMT));
104 private ArchiveOperation archiveOperation;
106 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
107 Either<TopologyTemplate, StorageOperationStatus> result = null;
109 topologyTemplate.generateUUID();
111 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
112 String resourceUniqueId = topologyTemplate.getUniqueId();
113 if (resourceUniqueId == null) {
114 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
115 topologyTemplate.setUniqueId(resourceUniqueId);
118 GraphVertex topologyTemplateVertex = new GraphVertex();
119 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
121 Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
122 if (createdVertex.isRight()) {
123 TitanOperationStatus status = createdVertex.right().value();
124 log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
125 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
129 topologyTemplateVertex = createdVertex.left().value();
131 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
132 if (assosiateCommon != StorageOperationStatus.OK) {
133 result = Either.right(assosiateCommon);
137 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
138 if (associateCategory != StorageOperationStatus.OK) {
139 result = Either.right(associateCategory);
143 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
144 if (associateInputs != StorageOperationStatus.OK) {
145 result = Either.right(associateInputs);
148 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
149 if (associateGroups != StorageOperationStatus.OK) {
150 result = Either.right(associateGroups);
153 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
154 if (associatePolicies != StorageOperationStatus.OK) {
155 result = Either.right(associatePolicies);
158 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
159 if (associateInstAttr != StorageOperationStatus.OK) {
160 result = Either.right(associateInstAttr);
163 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
164 if (associateInstProperties != StorageOperationStatus.OK) {
165 result = Either.right(associateInstProperties);
168 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
169 if (associateInstProperties != StorageOperationStatus.OK) {
170 result = Either.right(associateInstInputs);
173 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
174 if (associateInstGroups != StorageOperationStatus.OK) {
175 result = Either.right(associateInstInputs);
179 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
180 if (associateRequirements != StorageOperationStatus.OK) {
181 result = Either.right(associateRequirements);
185 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
186 if (associateCapabilities != StorageOperationStatus.OK) {
187 result = Either.right(associateCapabilities);
191 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
192 if (associateArtifacts != StorageOperationStatus.OK) {
193 result = Either.right(associateArtifacts);
197 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
198 if (addAdditionalInformation != StorageOperationStatus.OK) {
199 result = Either.right(addAdditionalInformation);
202 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
203 if (associateCapProperties != StorageOperationStatus.OK) {
204 result = Either.right(associateCapProperties);
208 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
209 if (associateInterfaces != StorageOperationStatus.OK) {
210 result = Either.right(associateInterfaces);
214 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
215 if (associateCapProperties != StorageOperationStatus.OK) {
216 result = Either.right(associatePathProperties);
221 return Either.left(topologyTemplate);
225 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
226 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
229 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
230 if (policies != null && !policies.isEmpty()) {
231 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
232 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
235 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
236 if (assosiateElementToData.isRight()) {
237 return assosiateElementToData.right().value();
240 return StorageOperationStatus.OK;
243 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
244 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
245 return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths);
248 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
249 TopologyTemplate topologyTemplate) {
250 Map<String, CINodeFilterDataDefinition> nodeFilters =
251 topologyTemplate.getNodeFilterComponents();
252 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
255 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
256 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
257 if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
258 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
259 if (assosiateElementToData.isRight()) {
260 return assosiateElementToData.right().value();
263 return StorageOperationStatus.OK;
266 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
267 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
268 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
269 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
270 if (assosiateElementToData.isRight()) {
271 return assosiateElementToData.right().value();
274 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
275 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
276 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
277 if (assosiateElementToData.isRight()) {
278 return assosiateElementToData.right().value();
281 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
282 if(MapUtils.isNotEmpty(capabilities)) {
283 Either<GraphVertex, StorageOperationStatus> associateElementToData =
284 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
285 EdgeLabelEnum.CAPABILITIES, capabilities);
286 if (associateElementToData.isRight()) {
287 return associateElementToData.right().value();
290 return StorageOperationStatus.OK;
294 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
295 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
296 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
297 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
298 if (assosiateElementToData.isRight()) {
299 return assosiateElementToData.right().value();
302 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
303 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
304 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
305 if (assosiateElementToData.isRight()) {
306 return assosiateElementToData.right().value();
309 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
310 if(MapUtils.isNotEmpty(requirements)) {
311 Either<GraphVertex, StorageOperationStatus> associateElementToData =
312 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
313 EdgeLabelEnum.REQUIREMENTS, requirements);
314 if (associateElementToData.isRight()) {
315 return associateElementToData.right().value();
318 return StorageOperationStatus.OK;
321 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
322 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
324 if (addInformation != null && !addInformation.isEmpty()) {
325 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
326 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
327 a.setUniqueId(uniqueId);
329 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
330 if (assosiateElementToData.isRight()) {
331 return assosiateElementToData.right().value();
334 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
336 if (instArtifacts != null && !instArtifacts.isEmpty()) {
337 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
338 if (assosiateElementToData.isRight()) {
339 return assosiateElementToData.right().value();
342 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
344 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
345 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
346 if (assosiateElementToData.isRight()) {
347 return assosiateElementToData.right().value();
350 return StorageOperationStatus.OK;
353 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
355 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
357 if (addInformation != null && !addInformation.isEmpty()) {
358 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
359 if (assosiateElementToData.isRight()) {
360 return assosiateElementToData.right().value();
363 return StorageOperationStatus.OK;
366 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
367 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
368 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
371 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
372 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
373 return associateInstInputsToComponent(nodeTypeVertex, instProps);
376 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
377 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
378 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
382 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
383 if (instProps != null && !instProps.isEmpty()) {
384 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
385 if (assosiateElementToData.isRight()) {
386 return assosiateElementToData.right().value();
389 return StorageOperationStatus.OK;
392 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
393 if (instInputs != null && !instInputs.isEmpty()) {
394 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
395 if (assosiateElementToData.isRight()) {
396 return assosiateElementToData.right().value();
399 return StorageOperationStatus.OK;
402 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
403 if (instGroups != null && !instGroups.isEmpty()) {
404 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
405 if (assosiateElementToData.isRight()) {
406 return assosiateElementToData.right().value();
409 return StorageOperationStatus.OK;
413 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
415 if (instInputs != null && !instInputs.isEmpty()) {
416 instInputs.entrySet().forEach(i -> {
417 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
418 List<String> pathKeys = new ArrayList<>();
419 pathKeys.add(i.getKey());
421 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
422 if (status != StorageOperationStatus.OK) {
428 return StorageOperationStatus.OK;
431 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
433 if (instInputs != null && !instInputs.isEmpty()) {
434 instInputs.entrySet().forEach(i -> {
435 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
436 if (status != StorageOperationStatus.OK) {
442 return StorageOperationStatus.OK;
445 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
446 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
449 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
450 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
453 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
454 if (instProps != null && !instProps.isEmpty()) {
455 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
456 if (assosiateElementToData.isRight()) {
457 return assosiateElementToData.right().value();
460 return StorageOperationStatus.OK;
463 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
464 if (calcRequirements != null && !calcRequirements.isEmpty()) {
465 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
466 if (assosiateElementToData.isRight()) {
467 return assosiateElementToData.right().value();
469 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
470 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
471 if (assosiateElementToData.isRight()) {
472 return assosiateElementToData.right().value();
475 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
476 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
477 if (assosiateElementToData.isRight()) {
478 return assosiateElementToData.right().value();
480 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
481 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
482 if (assosiateElementToData.isRight()) {
483 return assosiateElementToData.right().value();
486 if (calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty()) {
487 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
488 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
490 .on(v -> StorageOperationStatus.OK);
492 return StorageOperationStatus.OK;
495 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
496 return titanDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
497 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
498 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
501 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(TitanOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
502 if (status == TitanOperationStatus.NOT_FOUND) {
503 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
505 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
508 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
509 Optional<StorageOperationStatus> error = dataMap.entrySet()
511 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
512 .filter(s -> s != StorageOperationStatus.OK)
514 if (error.isPresent()) {
515 return Either.right(error.get());
517 return Either.left(dataVertex);
520 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
521 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
522 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
525 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
526 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
527 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
528 if (assosiateElementToData.isRight()) {
529 return assosiateElementToData.right().value();
532 return StorageOperationStatus.OK;
535 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
536 if (instAttr != null && !instAttr.isEmpty()) {
537 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
538 if (assosiateElementToData.isRight()) {
539 return assosiateElementToData.right().value();
542 return StorageOperationStatus.OK;
545 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
547 if (groups != null && !groups.isEmpty()) {
548 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
549 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
552 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
553 if (assosiateElementToData.isRight()) {
554 return assosiateElementToData.right().value();
557 return StorageOperationStatus.OK;
560 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
561 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
564 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
565 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
566 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
569 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
570 if (inputs != null && !inputs.isEmpty()) {
571 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
573 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
574 if (assosiateElementToData.isRight()) {
575 return assosiateElementToData.right().value();
578 return StorageOperationStatus.OK;
581 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
582 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
583 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
584 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
585 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
587 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
588 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
590 return nodeTypeVertex;
594 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
595 if (topologyTemplate.getResourceType() == null) {
597 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
600 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
604 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
605 String categoryName = topologyTemplate.getCategories().get(0).getName();
606 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
607 if (category.isRight()) {
608 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
609 return StorageOperationStatus.CATEGORY_NOT_FOUND;
611 GraphVertex categoryV = category.left().value();
612 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
613 if (createEdge != TitanOperationStatus.OK) {
614 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
615 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
617 return StorageOperationStatus.OK;
621 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
622 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
624 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
625 if (componentByLabelAndId.isRight()) {
626 return Either.right(componentByLabelAndId.right().value());
628 GraphVertex componentV = componentByLabelAndId.left().value();
630 return getToscaElement(componentV, componentParametersView);
633 // -------------------------------------------------------------
635 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
636 TopologyTemplate toscaElement;
638 toscaElement = convertToTopologyTemplate(componentV);
639 TitanOperationStatus status;
640 if (!componentParametersView.isIgnoreUsers()) {
641 status = setCreatorFromGraph(componentV, toscaElement);
642 if (status != TitanOperationStatus.OK) {
643 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
646 status = setLastModifierFromGraph(componentV, toscaElement);
647 if (status != TitanOperationStatus.OK) {
648 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
651 if (!componentParametersView.isIgnoreCategories()) {
652 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
653 if (status != TitanOperationStatus.OK) {
654 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
658 if (!componentParametersView.isIgnoreArtifacts()) {
659 TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
660 if (storageStatus != TitanOperationStatus.OK) {
661 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
664 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
665 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
666 if (status != TitanOperationStatus.OK) {
667 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
670 if (!componentParametersView.isIgnoreCapabilities()) {
671 status = setCapabilitiesFromGraph(componentV, toscaElement);
672 if (status != TitanOperationStatus.OK) {
673 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
676 if (!componentParametersView.isIgnoreRequirements()) {
677 status = setRequirementsFromGraph(componentV, toscaElement);
678 if (status != TitanOperationStatus.OK) {
679 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
682 if (!componentParametersView.isIgnoreAllVersions()) {
683 status = setAllVersions(componentV, toscaElement);
684 if (status != TitanOperationStatus.OK) {
685 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
688 if (!componentParametersView.isIgnoreAdditionalInformation()) {
689 status = setAdditionalInformationFromGraph(componentV, toscaElement);
690 if (status != TitanOperationStatus.OK) {
691 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
695 if (!componentParametersView.isIgnoreGroups()) {
696 status = setGroupsFromGraph(componentV, toscaElement);
697 if (status != TitanOperationStatus.OK) {
698 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
702 if (!componentParametersView.isIgnorePolicies()) {
703 status = setPoliciesFromGraph(componentV, toscaElement);
704 if (status != TitanOperationStatus.OK) {
705 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
709 if (!componentParametersView.isIgnoreComponentInstances()) {
710 status = setInstGroupsFromGraph(componentV, toscaElement);
712 //Mark all CIs that has archived origins
713 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
715 if (status != TitanOperationStatus.OK) {
716 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
720 if (!componentParametersView.isIgnoreInputs()) {
721 status = setInputsFromGraph(componentV, toscaElement);
722 if (status != TitanOperationStatus.OK) {
723 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
727 if (!componentParametersView.isIgnoreProperties()) {
728 status = setPropertiesFromGraph(componentV, toscaElement);
729 if (status != TitanOperationStatus.OK) {
730 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
735 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
736 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
737 if (status != TitanOperationStatus.OK) {
738 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
743 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
744 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
745 if (status != TitanOperationStatus.OK) {
746 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
751 if (!componentParametersView.isIgnoreForwardingPath()) {
752 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
753 if (status != TitanOperationStatus.OK) {
754 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
759 if (!componentParametersView.isIgnoreNodeFilter()) {
760 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
761 if (status != TitanOperationStatus.OK) {
762 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
767 if (!componentParametersView.isIgnoreInterfaces()) {
768 TitanOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
769 if (storageStatus != TitanOperationStatus.OK) {
770 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
775 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
776 TitanOperationStatus storageStatus =
777 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
778 if (storageStatus != TitanOperationStatus.OK) {
779 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
783 if (!componentParametersView.isIgnoreDataType()) {
784 TitanOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
785 if (storageStatus != TitanOperationStatus.OK) {
786 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
790 return Either.left(toscaElement);
793 private TitanOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
794 Either<Map<String, DataTypeDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
795 if (result.isLeft()) {
796 toscaElement.setDataTypes(result.left().value());
798 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
799 return result.right().value();
802 return TitanOperationStatus.OK;
805 private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
806 Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
807 if (result.isLeft()) {
808 toscaElement.setPolicies(result.left().value());
810 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
811 return result.right().value();
814 return TitanOperationStatus.OK;
817 private TitanOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
818 Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
819 if (result.isLeft()) {
820 topologyTemplate.setInterfaces(result.left().value());
822 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
823 return result.right().value();
826 return TitanOperationStatus.OK;
830 private TitanOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
831 TopologyTemplate topologyTemplate) {
832 Either<Map<String, MapInterfaceDataDefinition>, TitanOperationStatus> result =
833 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
834 if (result.isLeft()) {
835 result.left().value().entrySet().forEach(entry -> topologyTemplate
836 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
838 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
839 return result.right().value();
842 return TitanOperationStatus.OK;
845 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
846 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
847 if (interfaceMap != null && !interfaceMap.isEmpty()) {
848 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
849 if (assosiateElementToData.isRight()) {
850 return assosiateElementToData.right().value();
853 return StorageOperationStatus.OK;
856 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
857 Map<String, CINodeFilterDataDefinition> filterMaps) {
858 if (filterMaps != null && !filterMaps.isEmpty()) {
859 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
860 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
861 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
862 if (assosiateElementToData.isRight()) {
863 return assosiateElementToData.right().value();
866 return StorageOperationStatus.OK;
869 private TitanOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
870 Either<Map<String, ForwardingPathDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
871 if (result.isLeft()) {
872 topologyTemplate.setForwardingPaths(result.left().value());
874 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
875 return result.right().value();
878 return TitanOperationStatus.OK;
882 private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
883 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
884 if (result.isLeft()) {
885 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
887 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
888 return result.right().value();
891 return TitanOperationStatus.OK;
894 private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
895 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
896 if (result.isLeft()) {
897 toscaElement.setProperties(result.left().value());
899 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
900 return result.right().value();
903 return TitanOperationStatus.OK;
906 private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
907 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
908 if (result.isLeft()) {
909 topologyTemplate.setInstGroups(result.left().value());
911 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
912 return result.right().value();
915 return TitanOperationStatus.OK;
918 private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
919 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
920 if (result.isLeft()) {
921 topologyTemplate.setInstProperties(result.left().value());
923 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
924 return result.right().value();
927 return TitanOperationStatus.OK;
930 private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
931 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
932 if (result.isLeft()) {
933 topologyTemplate.setInstInputs(result.left().value());
935 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
936 return result.right().value();
939 return TitanOperationStatus.OK;
942 private TitanOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
943 TopologyTemplate topologyTemplate) {
944 Either<Map<String, CINodeFilterDataDefinition>, TitanOperationStatus> result =
945 getDataFromGraph(componentV,
946 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
947 if (result.isLeft()) {
948 topologyTemplate.setNodeFilterComponents(result.left().value());
950 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
951 return result.right().value();
954 return TitanOperationStatus.OK;
958 protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
959 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
960 if (result.isLeft()) {
961 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
963 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
964 return result.right().value();
967 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
968 if (result.isLeft()) {
969 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
971 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
972 return result.right().value();
975 Either<Map<String, ListRequirementDataDefinition>, TitanOperationStatus> requirementResult =
976 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
977 if (requirementResult.isLeft()) {
978 toscaElement.setRequirements(requirementResult.left().value());
980 if (requirementResult.right().value() != TitanOperationStatus.NOT_FOUND) {
981 return requirementResult.right().value();
984 return TitanOperationStatus.OK;
988 protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
989 Either<Map<String, MapListCapabilityDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
990 if (result.isLeft()) {
991 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
993 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
994 return result.right().value();
997 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
998 if (result.isLeft()) {
999 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1001 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1002 return result.right().value();
1005 Either<Map<String, ListCapabilityDataDefinition>, TitanOperationStatus> capabilitiesResult =
1006 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1007 if (capabilitiesResult.isLeft()) {
1008 toscaElement.setCapabilities(capabilitiesResult.left().value());
1010 if (capabilitiesResult.right().value() != TitanOperationStatus.NOT_FOUND) {
1011 return capabilitiesResult.right().value();
1014 return TitanOperationStatus.OK;
1017 private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1018 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1019 if (storageStatus != TitanOperationStatus.OK) {
1020 return storageStatus;
1022 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1023 if (result.isLeft()) {
1024 toscaElement.setServiceApiArtifacts(result.left().value());
1026 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1027 return result.right().value();
1030 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1031 if (resultInstArt.isLeft()) {
1032 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1034 if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
1035 return resultInstArt.right().value();
1038 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1039 if (instanceArt.isLeft()) {
1040 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1042 if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
1043 return instanceArt.right().value();
1046 return TitanOperationStatus.OK;
1049 private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1050 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1051 if (result.isLeft()) {
1052 toscaElement.setInputs(result.left().value());
1054 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1055 return result.right().value();
1058 return TitanOperationStatus.OK;
1061 private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1062 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1063 if (result.isLeft()) {
1064 toscaElement.setGroups(result.left().value());
1066 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1067 return result.right().value();
1070 return TitanOperationStatus.OK;
1073 private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1074 List<CategoryDefinition> categories = new ArrayList<>();
1076 switch (componentV.getType()) {
1078 return setResourceCategoryFromGraph(componentV, toscaElement);
1080 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1083 log.debug("Not supported component type {} ", componentV.getType());
1086 return TitanOperationStatus.OK;
1089 private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1090 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1091 if (childVertex.isRight()) {
1092 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1093 return childVertex.right().value();
1095 GraphVertex categoryV = childVertex.left().value();
1096 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1097 CategoryDefinition category = new CategoryDefinition();
1098 category.setUniqueId(categoryV.getUniqueId());
1099 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1100 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1102 Type listTypeCat = new TypeToken<List<String>>() {
1104 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1105 category.setIcons(iconsfromJsonCat);
1106 categories.add(category);
1107 toscaElement.setCategories(categories);
1109 return TitanOperationStatus.OK;
1112 @SuppressWarnings("unchecked")
1113 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1115 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1117 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1118 topologyTemplate.setCompositions(json);
1120 return topologyTemplate;
1124 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1125 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1126 if (nodeType.isRight()) {
1127 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1130 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1131 if (status != TitanOperationStatus.OK) {
1132 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1134 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1135 if (status != TitanOperationStatus.OK) {
1136 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1137 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1139 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1140 if (status != TitanOperationStatus.OK) {
1141 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1142 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1145 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1146 if (status != TitanOperationStatus.OK) {
1147 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1148 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1151 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1152 if (status != TitanOperationStatus.OK) {
1153 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1154 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1156 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1157 if (status != TitanOperationStatus.OK) {
1158 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1159 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1161 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1162 if (status != TitanOperationStatus.OK) {
1163 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1164 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1166 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1167 if (status != TitanOperationStatus.OK) {
1168 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1169 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1171 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1172 if (status != TitanOperationStatus.OK) {
1173 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1174 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1176 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1177 if (status != TitanOperationStatus.OK) {
1178 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1179 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1181 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1182 if (status != TitanOperationStatus.OK) {
1183 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1184 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1186 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1187 if (status != TitanOperationStatus.OK) {
1188 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1189 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1191 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1192 if (status != TitanOperationStatus.OK) {
1193 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1194 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1196 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1197 if (status != TitanOperationStatus.OK) {
1198 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1199 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1201 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1202 if (status != TitanOperationStatus.OK) {
1203 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1204 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1206 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1207 if (status != TitanOperationStatus.OK) {
1208 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1209 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1211 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1212 if (status != TitanOperationStatus.OK) {
1213 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1214 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1216 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1217 if (status != TitanOperationStatus.OK) {
1218 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1219 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1221 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1222 if (status != TitanOperationStatus.OK) {
1223 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1224 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1227 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1228 EdgeLabelEnum.REQUIREMENTS);
1229 if (status != TitanOperationStatus.OK) {
1230 log.debug("Failed to disassociate requirements for {} error {}",
1231 toscaElementVertex.getUniqueId(), status);
1232 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1234 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1235 EdgeLabelEnum.CAPABILITIES);
1236 if (status != TitanOperationStatus.OK) {
1237 log.debug("Failed to disassociate capabilities for {} error {}",
1238 toscaElementVertex.getUniqueId(), status);
1239 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1241 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1242 if (status != TitanOperationStatus.OK) {
1243 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1244 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1246 toscaElementVertex.getVertex().remove();
1247 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1252 @SuppressWarnings("unchecked")
1254 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1255 return createTopologyTemplate((TopologyTemplate) toscaElement);
1259 protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1260 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1264 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1265 // Product isn't supported now!!
1266 // TODO add for Product
1267 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1268 return validateServiceCategory(toscaElementToUpdate, elementV);
1271 return validateResourceCategory(toscaElementToUpdate, elementV);
1276 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1277 // not relevant now for topology template
1278 return StorageOperationStatus.OK;
1282 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1283 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1286 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1287 StorageOperationStatus status = StorageOperationStatus.OK;
1288 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1289 CategoryDefinition newCategory = newCategoryList.get(0);
1291 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1292 if (childVertex.isRight()) {
1293 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1294 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1297 GraphVertex categoryV = childVertex.left().value();
1298 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1299 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1301 String newCategoryName = newCategory.getName();
1302 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1303 // the category was changed
1304 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1306 if (getCategoryVertex.isRight()) {
1307 return getCategoryVertex.right().value();
1309 GraphVertex newCategoryV = getCategoryVertex.left().value();
1310 status = moveCategoryEdge(elementV, newCategoryV);
1311 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1316 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1318 Either<GraphVertex, StorageOperationStatus> result = null;
1319 String userId = user.getUserId();
1320 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
1321 GraphVertex userVertex = null;
1322 GraphVertex serviceVertex = null;
1323 if (getRes.isRight()) {
1324 TitanOperationStatus status = getRes.right().value();
1325 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1326 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1328 if (result == null) {
1329 userVertex = getRes.left().value();
1330 getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1331 if (getRes.isRight()) {
1332 TitanOperationStatus status = getRes.right().value();
1333 log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status);
1334 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1337 if (result == null) {
1338 serviceVertex = getRes.left().value();
1339 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1340 if (edgeIterator.hasNext()) {
1341 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1342 edgeIterator.next().remove();
1345 if (result == null) {
1346 TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1347 if (status != TitanOperationStatus.OK) {
1348 log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1349 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1352 if (result == null) {
1353 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1354 long lastUpdateDate = System.currentTimeMillis();
1355 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1356 Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1357 if (updateRes.isRight()) {
1358 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1361 if (result == null) {
1362 result = Either.left(serviceVertex);
1368 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1370 * @param componentId
1372 * @param capabilityName
1373 * @param capabilityType
1377 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1379 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1380 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1381 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1382 if (componentByLabelAndId.isRight()) {
1383 result = Either.right(componentByLabelAndId.right().value());
1385 if (componentByLabelAndId.isLeft()) {
1386 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1387 if (getDataRes.isRight()) {
1388 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
1390 mapPropertiesDataDefinition = getDataRes.left().value();
1393 if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
1394 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1399 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1400 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1403 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1404 String componentInstanceId,
1405 MapInterfaceDataDefinition instanceInterfaces) {
1406 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1407 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1408 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1410 return StorageOperationStatus.OK;
1414 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1415 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1416 mapPropertiesDataDefinition.get(instanceId) != null &&
1417 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1420 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1421 List<ComponentInstanceProperty> capPropsList = null;
1422 for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
1423 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1424 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1425 if (capMap != null && !capMap.isEmpty()) {
1426 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1431 if (capPropsList == null) {
1432 capPropsList = new ArrayList<>();
1434 return capPropsList;
1437 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1438 if (capProp != null) {
1439 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
1440 if (path.length < 4) {
1441 log.debug("wrong key format for capabilty, key {}", capProp);
1444 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1449 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1450 fillPolicyDefinition(componentV, policyDefinition, counter);
1451 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1454 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1455 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1458 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1459 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1462 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1463 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1466 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1467 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1470 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1471 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.NAME);
1474 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1475 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1476 policyDefinition.setName(policyName);
1477 policyDefinition.setInvariantName(policyName);
1478 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1479 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1480 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1481 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1484 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1485 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1486 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1487 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1490 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1491 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1492 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1494 .on(this::throwStorageException);
1495 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1496 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1498 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1499 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1501 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1502 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1503 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1507 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1508 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1509 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1511 .on(this::throwStorageException);
1512 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1513 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1515 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1516 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1518 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1519 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1520 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1524 private GraphVertex throwStorageException(TitanOperationStatus status) {
1525 throw new StorageException(status);
1528 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1529 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1530 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1531 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1532 if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
1533 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1536 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1538 if (getOriginRes.isRight()) {
1539 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1540 throw new StorageException(getOriginRes.right().value());
1542 return getOriginRes.left().value();
1545 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1546 log.debug("#detectToscaType - type: {}", originType);
1547 if (nodeTypeSet.contains(originType)){
1548 return ToscaElementTypeEnum.NODE_TYPE;
1550 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1554 private ComponentParametersView getFilter() {
1555 ComponentParametersView filter = new ComponentParametersView();
1556 filter.setIgnoreCapabilities(false);
1557 filter.setIgnoreCapabiltyProperties(false);
1558 filter.setIgnoreRequirements(false);
1561 public void updateCapReqOwnerId(String componentId, TopologyTemplate toscaElement) {
1562 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1563 .left().on(this::throwStorageException);
1564 updateCapOwnerId(toscaElement, componentId);
1565 updateReqOwnerId(toscaElement, componentId);
1566 topologyTemplateOperation
1568 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1569 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1570 topologyTemplateOperation
1571 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1572 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1575 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1576 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1577 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1578 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1582 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1583 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1584 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1585 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));