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
257 .getCalculatedCapabilitiesProperties();
258 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
259 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
260 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
261 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
262 if (associateElementToData.isRight()) {
263 return associateElementToData.right().value();
267 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
268 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
269 Either<GraphVertex, StorageOperationStatus> associateElementToData =
270 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
271 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
272 if (associateElementToData.isRight()) {
273 return associateElementToData.right().value();
276 return StorageOperationStatus.OK;
279 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
280 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
281 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
282 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
283 if (assosiateElementToData.isRight()) {
284 return assosiateElementToData.right().value();
287 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
288 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
289 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
290 if (assosiateElementToData.isRight()) {
291 return assosiateElementToData.right().value();
294 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
295 if(MapUtils.isNotEmpty(capabilities)) {
296 Either<GraphVertex, StorageOperationStatus> associateElementToData =
297 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
298 EdgeLabelEnum.CAPABILITIES, capabilities);
299 if (associateElementToData.isRight()) {
300 return associateElementToData.right().value();
303 return StorageOperationStatus.OK;
307 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
308 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
309 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
310 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
311 if (assosiateElementToData.isRight()) {
312 return assosiateElementToData.right().value();
315 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
316 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
317 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
318 if (assosiateElementToData.isRight()) {
319 return assosiateElementToData.right().value();
322 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
323 if(MapUtils.isNotEmpty(requirements)) {
324 Either<GraphVertex, StorageOperationStatus> associateElementToData =
325 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
326 EdgeLabelEnum.REQUIREMENTS, requirements);
327 if (associateElementToData.isRight()) {
328 return associateElementToData.right().value();
331 return StorageOperationStatus.OK;
334 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
335 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
337 if (addInformation != null && !addInformation.isEmpty()) {
338 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
339 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
340 a.setUniqueId(uniqueId);
342 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
343 if (assosiateElementToData.isRight()) {
344 return assosiateElementToData.right().value();
347 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
349 if (instArtifacts != null && !instArtifacts.isEmpty()) {
350 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
351 if (assosiateElementToData.isRight()) {
352 return assosiateElementToData.right().value();
355 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
357 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
358 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
359 if (assosiateElementToData.isRight()) {
360 return assosiateElementToData.right().value();
363 return StorageOperationStatus.OK;
366 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
368 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
370 if (addInformation != null && !addInformation.isEmpty()) {
371 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
372 if (assosiateElementToData.isRight()) {
373 return assosiateElementToData.right().value();
376 return StorageOperationStatus.OK;
379 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
380 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
381 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
384 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
385 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
386 return associateInstInputsToComponent(nodeTypeVertex, instProps);
389 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
390 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
391 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
395 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
396 if (instProps != null && !instProps.isEmpty()) {
397 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
398 if (assosiateElementToData.isRight()) {
399 return assosiateElementToData.right().value();
402 return StorageOperationStatus.OK;
405 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
406 if (instInputs != null && !instInputs.isEmpty()) {
407 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
408 if (assosiateElementToData.isRight()) {
409 return assosiateElementToData.right().value();
412 return StorageOperationStatus.OK;
415 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
416 if (instGroups != null && !instGroups.isEmpty()) {
417 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
418 if (assosiateElementToData.isRight()) {
419 return assosiateElementToData.right().value();
422 return StorageOperationStatus.OK;
426 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
428 if (instInputs != null && !instInputs.isEmpty()) {
429 instInputs.entrySet().forEach(i -> {
430 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
431 List<String> pathKeys = new ArrayList<>();
432 pathKeys.add(i.getKey());
434 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
435 if (status != StorageOperationStatus.OK) {
441 return StorageOperationStatus.OK;
444 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
446 if (instInputs != null && !instInputs.isEmpty()) {
447 instInputs.entrySet().forEach(i -> {
448 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
449 if (status != StorageOperationStatus.OK) {
455 return StorageOperationStatus.OK;
458 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
459 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
462 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
463 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
466 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
467 if (instProps != null && !instProps.isEmpty()) {
468 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
469 if (assosiateElementToData.isRight()) {
470 return assosiateElementToData.right().value();
473 return StorageOperationStatus.OK;
476 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
477 if (calcRequirements != null && !calcRequirements.isEmpty()) {
478 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
479 if (assosiateElementToData.isRight()) {
480 return assosiateElementToData.right().value();
482 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
483 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
484 if (assosiateElementToData.isRight()) {
485 return assosiateElementToData.right().value();
488 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
489 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
490 if (assosiateElementToData.isRight()) {
491 return assosiateElementToData.right().value();
493 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
494 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
495 if (assosiateElementToData.isRight()) {
496 return assosiateElementToData.right().value();
499 if (calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty()) {
500 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
501 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
503 .on(v -> StorageOperationStatus.OK);
505 return StorageOperationStatus.OK;
508 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
509 return titanDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
510 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
511 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
514 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(TitanOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
515 if (status == TitanOperationStatus.NOT_FOUND) {
516 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
518 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
521 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
522 Optional<StorageOperationStatus> error = dataMap.entrySet()
524 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
525 .filter(s -> s != StorageOperationStatus.OK)
527 if (error.isPresent()) {
528 return Either.right(error.get());
530 return Either.left(dataVertex);
533 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
534 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
535 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
538 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
539 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
540 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
541 if (assosiateElementToData.isRight()) {
542 return assosiateElementToData.right().value();
545 return StorageOperationStatus.OK;
548 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
549 if (instAttr != null && !instAttr.isEmpty()) {
550 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
551 if (assosiateElementToData.isRight()) {
552 return assosiateElementToData.right().value();
555 return StorageOperationStatus.OK;
558 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
560 if (groups != null && !groups.isEmpty()) {
561 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
562 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
565 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
566 if (assosiateElementToData.isRight()) {
567 return assosiateElementToData.right().value();
570 return StorageOperationStatus.OK;
573 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
574 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
577 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
578 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
579 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
582 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
583 if (inputs != null && !inputs.isEmpty()) {
584 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
586 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
587 if (assosiateElementToData.isRight()) {
588 return assosiateElementToData.right().value();
591 return StorageOperationStatus.OK;
594 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
595 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
596 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
597 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
598 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
600 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
601 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
603 return nodeTypeVertex;
607 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
608 if (topologyTemplate.getResourceType() == null) {
610 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
613 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
617 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
618 String categoryName = topologyTemplate.getCategories().get(0).getName();
619 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
620 if (category.isRight()) {
621 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
622 return StorageOperationStatus.CATEGORY_NOT_FOUND;
624 GraphVertex categoryV = category.left().value();
625 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
626 if (createEdge != TitanOperationStatus.OK) {
627 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
628 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
630 return StorageOperationStatus.OK;
634 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
635 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
637 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
638 if (componentByLabelAndId.isRight()) {
639 return Either.right(componentByLabelAndId.right().value());
641 GraphVertex componentV = componentByLabelAndId.left().value();
643 return getToscaElement(componentV, componentParametersView);
646 // -------------------------------------------------------------
648 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
649 TopologyTemplate toscaElement;
651 toscaElement = convertToTopologyTemplate(componentV);
652 TitanOperationStatus status;
653 if (!componentParametersView.isIgnoreUsers()) {
654 status = setCreatorFromGraph(componentV, toscaElement);
655 if (status != TitanOperationStatus.OK) {
656 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
659 status = setLastModifierFromGraph(componentV, toscaElement);
660 if (status != TitanOperationStatus.OK) {
661 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
664 if (!componentParametersView.isIgnoreCategories()) {
665 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
666 if (status != TitanOperationStatus.OK) {
667 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
671 if (!componentParametersView.isIgnoreArtifacts()) {
672 TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
673 if (storageStatus != TitanOperationStatus.OK) {
674 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
677 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
678 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
679 if (status != TitanOperationStatus.OK) {
680 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
683 if (!componentParametersView.isIgnoreCapabilities()) {
684 status = setCapabilitiesFromGraph(componentV, toscaElement);
685 if (status != TitanOperationStatus.OK) {
686 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
689 if (!componentParametersView.isIgnoreRequirements()) {
690 status = setRequirementsFromGraph(componentV, toscaElement);
691 if (status != TitanOperationStatus.OK) {
692 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
695 if (!componentParametersView.isIgnoreAllVersions()) {
696 status = setAllVersions(componentV, toscaElement);
697 if (status != TitanOperationStatus.OK) {
698 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
701 if (!componentParametersView.isIgnoreAdditionalInformation()) {
702 status = setAdditionalInformationFromGraph(componentV, toscaElement);
703 if (status != TitanOperationStatus.OK) {
704 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
708 if (!componentParametersView.isIgnoreGroups()) {
709 status = setGroupsFromGraph(componentV, toscaElement);
710 if (status != TitanOperationStatus.OK) {
711 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
715 if (!componentParametersView.isIgnorePolicies()) {
716 status = setPoliciesFromGraph(componentV, toscaElement);
717 if (status != TitanOperationStatus.OK) {
718 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
722 if (!componentParametersView.isIgnoreComponentInstances()) {
723 status = setInstGroupsFromGraph(componentV, toscaElement);
725 //Mark all CIs that has archived origins
726 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
728 if (status != TitanOperationStatus.OK) {
729 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
733 if (!componentParametersView.isIgnoreInputs()) {
734 status = setInputsFromGraph(componentV, toscaElement);
735 if (status != TitanOperationStatus.OK) {
736 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
740 if (!componentParametersView.isIgnoreProperties()) {
741 status = setPropertiesFromGraph(componentV, toscaElement);
742 if (status != TitanOperationStatus.OK) {
743 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
748 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
749 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
750 if (status != TitanOperationStatus.OK) {
751 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
756 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
757 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
758 if (status != TitanOperationStatus.OK) {
759 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
764 if (!componentParametersView.isIgnoreForwardingPath()) {
765 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
766 if (status != TitanOperationStatus.OK) {
767 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
772 if (!componentParametersView.isIgnoreNodeFilter()) {
773 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
774 if (status != TitanOperationStatus.OK) {
775 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
780 if (!componentParametersView.isIgnoreInterfaces()) {
781 TitanOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
782 if (storageStatus != TitanOperationStatus.OK) {
783 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
788 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
789 TitanOperationStatus storageStatus =
790 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
791 if (storageStatus != TitanOperationStatus.OK) {
792 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
796 if (!componentParametersView.isIgnoreDataType()) {
797 TitanOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
798 if (storageStatus != TitanOperationStatus.OK) {
799 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
803 return Either.left(toscaElement);
806 private TitanOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
807 Either<Map<String, DataTypeDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
808 if (result.isLeft()) {
809 toscaElement.setDataTypes(result.left().value());
811 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
812 return result.right().value();
815 return TitanOperationStatus.OK;
818 private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
819 Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
820 if (result.isLeft()) {
821 toscaElement.setPolicies(result.left().value());
823 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
824 return result.right().value();
827 return TitanOperationStatus.OK;
830 private TitanOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
831 Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
832 if (result.isLeft()) {
833 topologyTemplate.setInterfaces(result.left().value());
835 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
836 return result.right().value();
839 return TitanOperationStatus.OK;
843 private TitanOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
844 TopologyTemplate topologyTemplate) {
845 Either<Map<String, MapInterfaceDataDefinition>, TitanOperationStatus> result =
846 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
847 if (result.isLeft()) {
848 result.left().value().entrySet().forEach(entry -> topologyTemplate
849 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
851 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
852 return result.right().value();
855 return TitanOperationStatus.OK;
858 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
859 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
860 if (interfaceMap != null && !interfaceMap.isEmpty()) {
861 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
862 if (assosiateElementToData.isRight()) {
863 return assosiateElementToData.right().value();
866 return StorageOperationStatus.OK;
869 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
870 Map<String, CINodeFilterDataDefinition> filterMaps) {
871 if (filterMaps != null && !filterMaps.isEmpty()) {
872 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
873 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
874 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
875 if (assosiateElementToData.isRight()) {
876 return assosiateElementToData.right().value();
879 return StorageOperationStatus.OK;
882 private TitanOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
883 Either<Map<String, ForwardingPathDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
884 if (result.isLeft()) {
885 topologyTemplate.setForwardingPaths(result.left().value());
887 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
888 return result.right().value();
891 return TitanOperationStatus.OK;
895 private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
896 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
897 if (result.isLeft()) {
898 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
900 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
901 return result.right().value();
904 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> capPropResult =
905 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
906 if (capPropResult.isLeft()) {
907 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
909 if (capPropResult.right().value() != TitanOperationStatus.NOT_FOUND) {
910 return capPropResult.right().value();
914 return TitanOperationStatus.OK;
917 private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
918 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
919 if (result.isLeft()) {
920 toscaElement.setProperties(result.left().value());
922 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
923 return result.right().value();
926 return TitanOperationStatus.OK;
929 private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
930 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
931 if (result.isLeft()) {
932 topologyTemplate.setInstGroups(result.left().value());
934 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
935 return result.right().value();
938 return TitanOperationStatus.OK;
941 private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
942 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
943 if (result.isLeft()) {
944 topologyTemplate.setInstProperties(result.left().value());
946 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
947 return result.right().value();
950 return TitanOperationStatus.OK;
953 private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
954 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
955 if (result.isLeft()) {
956 topologyTemplate.setInstInputs(result.left().value());
958 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
959 return result.right().value();
962 return TitanOperationStatus.OK;
965 private TitanOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
966 TopologyTemplate topologyTemplate) {
967 Either<Map<String, CINodeFilterDataDefinition>, TitanOperationStatus> result =
968 getDataFromGraph(componentV,
969 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
970 if (result.isLeft()) {
971 topologyTemplate.setNodeFilterComponents(result.left().value());
973 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
974 return result.right().value();
977 return TitanOperationStatus.OK;
981 protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
982 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
983 if (result.isLeft()) {
984 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
986 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
987 return result.right().value();
990 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
991 if (result.isLeft()) {
992 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
994 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
995 return result.right().value();
998 Either<Map<String, ListRequirementDataDefinition>, TitanOperationStatus> requirementResult =
999 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
1000 if (requirementResult.isLeft()) {
1001 toscaElement.setRequirements(requirementResult.left().value());
1003 if (requirementResult.right().value() != TitanOperationStatus.NOT_FOUND) {
1004 return requirementResult.right().value();
1007 return TitanOperationStatus.OK;
1011 protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1012 Either<Map<String, MapListCapabilityDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1013 if (result.isLeft()) {
1014 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1016 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1017 return result.right().value();
1020 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1021 if (result.isLeft()) {
1022 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1024 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1025 return result.right().value();
1028 Either<Map<String, ListCapabilityDataDefinition>, TitanOperationStatus> capabilitiesResult =
1029 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1030 if (capabilitiesResult.isLeft()) {
1031 toscaElement.setCapabilities(capabilitiesResult.left().value());
1033 if (capabilitiesResult.right().value() != TitanOperationStatus.NOT_FOUND) {
1034 return capabilitiesResult.right().value();
1037 return TitanOperationStatus.OK;
1040 private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1041 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1042 if (storageStatus != TitanOperationStatus.OK) {
1043 return storageStatus;
1045 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1046 if (result.isLeft()) {
1047 toscaElement.setServiceApiArtifacts(result.left().value());
1049 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1050 return result.right().value();
1053 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1054 if (resultInstArt.isLeft()) {
1055 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1057 if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
1058 return resultInstArt.right().value();
1061 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1062 if (instanceArt.isLeft()) {
1063 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1065 if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
1066 return instanceArt.right().value();
1069 return TitanOperationStatus.OK;
1072 private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1073 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1074 if (result.isLeft()) {
1075 toscaElement.setInputs(result.left().value());
1077 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1078 return result.right().value();
1081 return TitanOperationStatus.OK;
1084 private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1085 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1086 if (result.isLeft()) {
1087 toscaElement.setGroups(result.left().value());
1089 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
1090 return result.right().value();
1093 return TitanOperationStatus.OK;
1096 private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1097 List<CategoryDefinition> categories = new ArrayList<>();
1099 switch (componentV.getType()) {
1101 return setResourceCategoryFromGraph(componentV, toscaElement);
1103 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1106 log.debug("Not supported component type {} ", componentV.getType());
1109 return TitanOperationStatus.OK;
1112 private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1113 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1114 if (childVertex.isRight()) {
1115 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1116 return childVertex.right().value();
1118 GraphVertex categoryV = childVertex.left().value();
1119 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1120 CategoryDefinition category = new CategoryDefinition();
1121 category.setUniqueId(categoryV.getUniqueId());
1122 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1123 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1125 Type listTypeCat = new TypeToken<List<String>>() {
1127 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1128 category.setIcons(iconsfromJsonCat);
1129 categories.add(category);
1130 toscaElement.setCategories(categories);
1132 return TitanOperationStatus.OK;
1135 @SuppressWarnings("unchecked")
1136 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1138 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1140 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1141 topologyTemplate.setCompositions(json);
1143 return topologyTemplate;
1147 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1148 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1149 if (nodeType.isRight()) {
1150 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1153 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1154 if (status != TitanOperationStatus.OK) {
1155 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1157 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1158 if (status != TitanOperationStatus.OK) {
1159 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1160 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1162 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1163 if (status != TitanOperationStatus.OK) {
1164 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1165 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1168 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1169 if (status != TitanOperationStatus.OK) {
1170 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1171 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1174 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1175 if (status != TitanOperationStatus.OK) {
1176 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1177 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1179 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1180 if (status != TitanOperationStatus.OK) {
1181 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1182 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1184 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1185 if (status != TitanOperationStatus.OK) {
1186 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1187 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1189 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1190 if (status != TitanOperationStatus.OK) {
1191 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1192 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1194 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1195 if (status != TitanOperationStatus.OK) {
1196 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1197 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1199 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1200 if (status != TitanOperationStatus.OK) {
1201 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1202 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1204 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1205 if (status != TitanOperationStatus.OK) {
1206 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1207 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1209 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1210 if (status != TitanOperationStatus.OK) {
1211 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1212 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1214 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1215 if (status != TitanOperationStatus.OK) {
1216 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1217 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1219 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1220 if (status != TitanOperationStatus.OK) {
1221 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1222 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1224 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1225 if (status != TitanOperationStatus.OK) {
1226 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1227 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1229 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1230 if (status != TitanOperationStatus.OK) {
1231 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1232 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1234 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1235 if (status != TitanOperationStatus.OK) {
1236 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1237 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1239 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1240 if (status != TitanOperationStatus.OK) {
1241 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1242 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1244 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1245 if (status != TitanOperationStatus.OK) {
1246 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1247 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1249 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1250 if (status != TitanOperationStatus.OK) {
1251 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1252 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1255 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1256 EdgeLabelEnum.REQUIREMENTS);
1257 if (status != TitanOperationStatus.OK) {
1258 log.debug("Failed to disassociate requirements for {} error {}",
1259 toscaElementVertex.getUniqueId(), status);
1260 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1262 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1263 EdgeLabelEnum.CAPABILITIES);
1264 if (status != TitanOperationStatus.OK) {
1265 log.debug("Failed to disassociate capabilities for {} error {}",
1266 toscaElementVertex.getUniqueId(), status);
1267 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1269 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1270 if (status != TitanOperationStatus.OK) {
1271 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1272 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1274 toscaElementVertex.getVertex().remove();
1275 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1280 @SuppressWarnings("unchecked")
1282 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1283 return createTopologyTemplate((TopologyTemplate) toscaElement);
1287 protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1288 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1292 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1293 // Product isn't supported now!!
1294 // TODO add for Product
1295 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1296 return validateServiceCategory(toscaElementToUpdate, elementV);
1299 return validateResourceCategory(toscaElementToUpdate, elementV);
1304 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1305 // not relevant now for topology template
1306 return StorageOperationStatus.OK;
1310 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1311 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1314 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1315 StorageOperationStatus status = StorageOperationStatus.OK;
1316 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1317 CategoryDefinition newCategory = newCategoryList.get(0);
1319 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1320 if (childVertex.isRight()) {
1321 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1322 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1325 GraphVertex categoryV = childVertex.left().value();
1326 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1327 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1329 String newCategoryName = newCategory.getName();
1330 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1331 // the category was changed
1332 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1334 if (getCategoryVertex.isRight()) {
1335 return getCategoryVertex.right().value();
1337 GraphVertex newCategoryV = getCategoryVertex.left().value();
1338 status = moveCategoryEdge(elementV, newCategoryV);
1339 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1344 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1346 Either<GraphVertex, StorageOperationStatus> result = null;
1347 String userId = user.getUserId();
1348 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
1349 GraphVertex userVertex = null;
1350 GraphVertex serviceVertex = null;
1351 if (getRes.isRight()) {
1352 TitanOperationStatus status = getRes.right().value();
1353 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1354 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1356 if (result == null) {
1357 userVertex = getRes.left().value();
1358 getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1359 if (getRes.isRight()) {
1360 TitanOperationStatus status = getRes.right().value();
1361 log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status);
1362 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1365 if (result == null) {
1366 serviceVertex = getRes.left().value();
1367 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1368 if (edgeIterator.hasNext()) {
1369 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1370 edgeIterator.next().remove();
1373 if (result == null) {
1374 TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1375 if (status != TitanOperationStatus.OK) {
1376 log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1377 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1380 if (result == null) {
1381 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1382 long lastUpdateDate = System.currentTimeMillis();
1383 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1384 Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1385 if (updateRes.isRight()) {
1386 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1389 if (result == null) {
1390 result = Either.left(serviceVertex);
1396 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1398 * @param componentId
1400 * @param capabilityName
1401 * @param capabilityType
1405 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1407 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1408 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1409 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1410 if (componentByLabelAndId.isRight()) {
1411 result = Either.right(componentByLabelAndId.right().value());
1413 if (componentByLabelAndId.isLeft()) {
1414 Either<Map<String, MapCapabilityProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1415 if (getDataRes.isRight()) {
1416 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
1418 mapPropertiesDataDefinition = getDataRes.left().value();
1421 if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
1422 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1427 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1428 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1431 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1432 String componentInstanceId,
1433 MapInterfaceDataDefinition instanceInterfaces) {
1434 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1435 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1436 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1438 return StorageOperationStatus.OK;
1442 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1443 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1444 mapPropertiesDataDefinition.get(instanceId) != null &&
1445 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1448 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1449 List<ComponentInstanceProperty> capPropsList = null;
1450 for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
1451 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1452 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1453 if (capMap != null && !capMap.isEmpty()) {
1454 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1459 if (capPropsList == null) {
1460 capPropsList = new ArrayList<>();
1462 return capPropsList;
1465 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1466 if (capProp != null) {
1467 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
1468 if (path.length < 4) {
1469 log.debug("wrong key format for capabilty, key {}", capProp);
1472 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1477 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1478 fillPolicyDefinition(componentV, policyDefinition, counter);
1479 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1482 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1483 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1486 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1487 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1490 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1491 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1494 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1495 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1498 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1499 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.NAME);
1502 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1503 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1504 policyDefinition.setName(policyName);
1505 policyDefinition.setInvariantName(policyName);
1506 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1507 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1508 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1509 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1512 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1513 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1514 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1515 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1518 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1519 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1520 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1522 .on(this::throwStorageException);
1523 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1524 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1526 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1527 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1529 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1530 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1531 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1535 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1536 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1537 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1539 .on(this::throwStorageException);
1540 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1541 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1543 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1544 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1546 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1547 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1548 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1552 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1553 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1554 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1555 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1556 if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
1557 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1560 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1562 if (getOriginRes.isRight()) {
1563 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1564 throw new StorageException(getOriginRes.right().value());
1566 return getOriginRes.left().value();
1569 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1570 log.debug("#detectToscaType - type: {}", originType);
1571 if (nodeTypeSet.contains(originType)){
1572 return ToscaElementTypeEnum.NODE_TYPE;
1574 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1578 private ComponentParametersView getFilter() {
1579 ComponentParametersView filter = new ComponentParametersView();
1580 filter.setIgnoreCapabilities(false);
1581 filter.setIgnoreCapabiltyProperties(false);
1582 filter.setIgnoreRequirements(false);
1585 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1586 GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1587 .left().on(this::throwStorageException);
1588 updateCapOwnerId(toscaElement, componentId);
1589 updateReqOwnerId(toscaElement, componentId);
1590 updatePropertiesOwnerId(toscaElement, componentId);
1591 topologyTemplateOperation
1593 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1594 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1595 topologyTemplateOperation
1596 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1597 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1598 topologyTemplateOperation
1599 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1600 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1603 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1604 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1605 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1606 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1610 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1611 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1612 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1613 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1617 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1618 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1619 if(MapUtils.isNotEmpty(properties)) {
1620 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));