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.tinkerpop.gremlin.structure.Direction;
27 import org.apache.tinkerpop.gremlin.structure.Edge;
28 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
29 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
30 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
31 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
32 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
33 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
38 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
42 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
48 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
49 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
50 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
51 import org.openecomp.sdc.be.model.Component;
52 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
53 import org.openecomp.sdc.be.model.ComponentParametersView;
54 import org.openecomp.sdc.be.model.DistributionStatusEnum;
55 import org.openecomp.sdc.be.model.PolicyDefinition;
56 import org.openecomp.sdc.be.model.User;
57 import org.openecomp.sdc.be.model.category.CategoryDefinition;
58 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
59 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
60 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
61 import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
62 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
63 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
64 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
65 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
66 import org.openecomp.sdc.common.api.Constants;
67 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
68 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
72 import java.lang.reflect.Type;
73 import java.util.ArrayList;
74 import java.util.HashMap;
75 import java.util.Iterator;
76 import java.util.List;
78 import java.util.Map.Entry;
79 import java.util.stream.Collectors;
81 @org.springframework.stereotype.Component("topology-template-operation")
82 public class TopologyTemplateOperation extends ToscaElementOperation {
84 private static Logger log = LoggerFactory.getLogger(TopologyTemplateOperation.class.getName());
87 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId) {
88 return super.getToscaElement(uniqueId);
91 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
92 Either<TopologyTemplate, StorageOperationStatus> result = null;
94 topologyTemplate.generateUUID();
96 topologyTemplate = (TopologyTemplate) getResourceMetaDataFromResource(topologyTemplate);
97 String resourceUniqueId = topologyTemplate.getUniqueId();
98 if (resourceUniqueId == null) {
99 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
100 topologyTemplate.setUniqueId(resourceUniqueId);
103 GraphVertex topologyTemplateVertex = new GraphVertex();
104 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
106 Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
107 if (createdVertex.isRight()) {
108 TitanOperationStatus status = createdVertex.right().value();
109 log.error("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
110 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
114 topologyTemplateVertex = createdVertex.left().value();
116 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
117 if (assosiateCommon != StorageOperationStatus.OK) {
118 result = Either.right(assosiateCommon);
122 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
123 if (associateCategory != StorageOperationStatus.OK) {
124 result = Either.right(associateCategory);
128 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
129 if (associateInputs != StorageOperationStatus.OK) {
130 result = Either.right(associateInputs);
133 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
134 if (associateGroups != StorageOperationStatus.OK) {
135 result = Either.right(associateGroups);
138 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
139 if (associatePolicies != StorageOperationStatus.OK) {
140 result = Either.right(associatePolicies);
143 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
144 if (associateInstAttr != StorageOperationStatus.OK) {
145 result = Either.right(associateInstAttr);
148 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
149 if (associateInstProperties != StorageOperationStatus.OK) {
150 result = Either.right(associateInstProperties);
153 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
154 if (associateInstProperties != StorageOperationStatus.OK) {
155 result = Either.right(associateInstInputs);
158 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
159 if (associateInstGroups != StorageOperationStatus.OK) {
160 result = Either.right(associateInstInputs);
164 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
165 if (associateRequirements != StorageOperationStatus.OK) {
166 result = Either.right(associateRequirements);
170 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
171 if (associateCapabilities != StorageOperationStatus.OK) {
172 result = Either.right(associateCapabilities);
176 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
177 if (associateArtifacts != StorageOperationStatus.OK) {
178 result = Either.right(associateArtifacts);
182 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
183 if (addAdditionalInformation != StorageOperationStatus.OK) {
184 result = Either.right(addAdditionalInformation);
187 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
188 if (associateCapProperties != StorageOperationStatus.OK) {
189 result = Either.right(associateCapProperties);
193 StorageOperationStatus associateInterfaces = associateInterfacesToResource(topologyTemplateVertex, topologyTemplate);
194 if (associateInterfaces != StorageOperationStatus.OK) {
195 result = Either.right(associateInterfaces);
199 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
200 if (associateCapProperties != StorageOperationStatus.OK) {
201 result = Either.right(associatePathProperties);
206 return Either.left(topologyTemplate);
210 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
211 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
214 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
215 if (policies != null && !policies.isEmpty()) {
216 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
217 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
220 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
221 if (assosiateElementToData.isRight()) {
222 return assosiateElementToData.right().value();
225 return StorageOperationStatus.OK;
228 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
229 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
230 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
233 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
234 Map<String, MapCapabiltyProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
235 if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
236 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
237 if (assosiateElementToData.isRight()) {
238 return assosiateElementToData.right().value();
241 return StorageOperationStatus.OK;
244 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
245 Map<String, MapListCapabiltyDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
246 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
247 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
248 if (assosiateElementToData.isRight()) {
249 return assosiateElementToData.right().value();
252 Map<String, MapListCapabiltyDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
253 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
254 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
255 if (assosiateElementToData.isRight()) {
256 return assosiateElementToData.right().value();
259 return StorageOperationStatus.OK;
263 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
264 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
265 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
266 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
267 if (assosiateElementToData.isRight()) {
268 return assosiateElementToData.right().value();
271 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
272 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
273 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
274 if (assosiateElementToData.isRight()) {
275 return assosiateElementToData.right().value();
278 return StorageOperationStatus.OK;
281 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
282 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
284 if (addInformation != null && !addInformation.isEmpty()) {
285 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
286 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
287 a.setUniqueId(uniqueId);
289 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
290 if (assosiateElementToData.isRight()) {
291 return assosiateElementToData.right().value();
294 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
296 if (instArtifacts != null && !instArtifacts.isEmpty()) {
297 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
298 if (assosiateElementToData.isRight()) {
299 return assosiateElementToData.right().value();
302 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
304 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
305 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
306 if (assosiateElementToData.isRight()) {
307 return assosiateElementToData.right().value();
310 return StorageOperationStatus.OK;
313 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
315 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
317 if (addInformation != null && !addInformation.isEmpty()) {
318 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
319 if (assosiateElementToData.isRight()) {
320 return assosiateElementToData.right().value();
323 return StorageOperationStatus.OK;
326 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
327 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
328 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
331 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
332 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
333 return associateInstInputsToComponent(nodeTypeVertex, instProps);
336 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
337 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
338 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
342 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
343 if (instProps != null && !instProps.isEmpty()) {
344 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
345 if (assosiateElementToData.isRight()) {
346 return assosiateElementToData.right().value();
349 return StorageOperationStatus.OK;
352 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
353 if (instInputs != null && !instInputs.isEmpty()) {
354 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
355 if (assosiateElementToData.isRight()) {
356 return assosiateElementToData.right().value();
359 return StorageOperationStatus.OK;
362 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
363 if (instGroups != null && !instGroups.isEmpty()) {
364 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
365 if (assosiateElementToData.isRight()) {
366 return assosiateElementToData.right().value();
369 return StorageOperationStatus.OK;
373 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
375 if (instInputs != null && !instInputs.isEmpty()) {
376 instInputs.entrySet().forEach(i -> {
377 List<String> uniqueKeys = new ArrayList<String>(i.getValue().getMapToscaDataDefinition().keySet());
378 List<String> pathKeys = new ArrayList<String>();
379 pathKeys.add(i.getKey());
381 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
382 if (status != StorageOperationStatus.OK) {
388 return StorageOperationStatus.OK;
391 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
393 if (instInputs != null && !instInputs.isEmpty()) {
394 instInputs.entrySet().forEach(i -> {
395 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
396 if (status != StorageOperationStatus.OK) {
402 return StorageOperationStatus.OK;
405 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
406 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
409 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
410 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
413 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
414 if (instProps != null && !instProps.isEmpty()) {
415 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
416 if (assosiateElementToData.isRight()) {
417 return assosiateElementToData.right().value();
420 return StorageOperationStatus.OK;
423 public StorageOperationStatus associateCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabiltyDataDefinition> calcCapabilty, Map<String, MapCapabiltyProperty> calculatedCapabilitiesProperties) {
424 if (calcRequirements != null && !calcRequirements.isEmpty()) {
425 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
426 if (assosiateElementToData.isRight()) {
427 return assosiateElementToData.right().value();
429 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
430 assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
431 if (assosiateElementToData.isRight()) {
432 return assosiateElementToData.right().value();
435 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
436 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
437 if (assosiateElementToData.isRight()) {
438 return assosiateElementToData.right().value();
440 Map<String, MapListCapabiltyDataDefinition> fullFilled = new HashMap<>();
441 assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
442 if (assosiateElementToData.isRight()) {
443 return assosiateElementToData.right().value();
446 if ( calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty() ){
447 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties);
448 if (assosiateElementToData.isRight()) {
449 return assosiateElementToData.right().value();
452 return StorageOperationStatus.OK;
455 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
456 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
457 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
460 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
461 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
462 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
463 if (assosiateElementToData.isRight()) {
464 return assosiateElementToData.right().value();
467 return StorageOperationStatus.OK;
470 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
471 if (instAttr != null && !instAttr.isEmpty()) {
472 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
473 if (assosiateElementToData.isRight()) {
474 return assosiateElementToData.right().value();
477 return StorageOperationStatus.OK;
480 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
482 if (groups != null && !groups.isEmpty()) {
483 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
484 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
487 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
488 if (assosiateElementToData.isRight()) {
489 return assosiateElementToData.right().value();
492 return StorageOperationStatus.OK;
495 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
496 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
499 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
500 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
501 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
504 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
505 if (inputs != null && !inputs.isEmpty()) {
506 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
508 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
509 if (assosiateElementToData.isRight()) {
510 return assosiateElementToData.right().value();
513 return StorageOperationStatus.OK;
516 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
517 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
518 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
519 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
520 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
522 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
523 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
525 return nodeTypeVertex;
529 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
530 if (topologyTemplate.getResourceType() == null) {
532 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
535 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
539 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
540 String categoryName = topologyTemplate.getCategories().get(0).getName();
541 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
542 if (category.isRight()) {
543 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
544 return StorageOperationStatus.CATEGORY_NOT_FOUND;
546 GraphVertex categoryV = category.left().value();
547 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
548 if (createEdge != TitanOperationStatus.OK) {
549 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
550 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
552 return StorageOperationStatus.OK;
556 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
557 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
559 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TopologyTemplate, parseFlag);
560 if (componentByLabelAndId.isRight()) {
561 return Either.right(componentByLabelAndId.right().value());
563 GraphVertex componentV = componentByLabelAndId.left().value();
565 return getToscaElement(componentV, componentParametersView);
568 // -------------------------------------------------------------
570 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
571 TopologyTemplate toscaElement;
573 toscaElement = convertToTopologyTemplate(componentV);
574 TitanOperationStatus status;
575 if (!componentParametersView.isIgnoreUsers()) {
576 status = setCreatorFromGraph(componentV, toscaElement);
577 if (status != TitanOperationStatus.OK) {
578 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
581 status = setLastModifierFromGraph(componentV, toscaElement);
582 if (status != TitanOperationStatus.OK) {
583 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
586 if (!componentParametersView.isIgnoreCategories()) {
587 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
588 if (status != TitanOperationStatus.OK) {
589 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
593 if (!componentParametersView.isIgnoreArtifacts()) {
594 TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
595 if (storageStatus != TitanOperationStatus.OK) {
596 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
599 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
600 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
601 if (status != TitanOperationStatus.OK) {
602 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
605 if (!componentParametersView.isIgnoreCapabilities()) {
606 status = setCapabilitiesFromGraph(componentV, toscaElement);
607 if (status != TitanOperationStatus.OK) {
608 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
611 if (!componentParametersView.isIgnoreRequirements()) {
612 status = setRequirementsFromGraph(componentV, toscaElement);
613 if (status != TitanOperationStatus.OK) {
614 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
617 if (!componentParametersView.isIgnoreAllVersions()) {
618 status = setAllVersions(componentV, toscaElement);
619 if (status != TitanOperationStatus.OK) {
620 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
623 if (!componentParametersView.isIgnoreAdditionalInformation()) {
624 status = setAdditionalInformationFromGraph(componentV, toscaElement);
625 if (status != TitanOperationStatus.OK) {
626 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
630 if (!componentParametersView.isIgnoreGroups()) {
631 status = setGroupsFromGraph(componentV, toscaElement);
632 if (status != TitanOperationStatus.OK) {
633 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
637 if (!componentParametersView.isIgnorePolicies()) {
638 status = setPoliciesFromGraph(componentV, toscaElement);
639 if (status != TitanOperationStatus.OK) {
640 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
644 if (!componentParametersView.isIgnoreComponentInstances()) {
645 status = setInstGroupsFromGraph(componentV, toscaElement);
646 if (status != TitanOperationStatus.OK) {
647 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
651 if (!componentParametersView.isIgnoreInputs()) {
652 status = setInputsFromGraph(componentV, toscaElement);
653 if (status != TitanOperationStatus.OK) {
654 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
658 if (!componentParametersView.isIgnoreProperties()) {
659 status = setPropertiesFromGraph(componentV, toscaElement);
660 if (status != TitanOperationStatus.OK) {
661 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
666 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
667 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
668 if (status != TitanOperationStatus.OK) {
669 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
674 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
675 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
676 if (status != TitanOperationStatus.OK) {
677 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
682 if (!componentParametersView.isIgnoreForwardingPath()) {
683 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
684 if (status != TitanOperationStatus.OK) {
685 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
689 if (!componentParametersView.isIgnoreInterfaces()) {
690 TitanOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
691 if (storageStatus != TitanOperationStatus.OK) {
692 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
696 return Either.left(toscaElement);
699 private TitanOperationStatus setInterfcesFromGraph(GraphVertex componentV,
700 TopologyTemplate topologyTemplate) {
701 Either<Map<String, InterfaceDataDefinition>, TitanOperationStatus> result = getDataFromGraph
703 EdgeLabelEnum.INTERFACE_ARTIFACTS);
704 if (result.isLeft()) {
705 topologyTemplate.setInterfaces(result.left().value());
707 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
708 return result.right().value();
711 return TitanOperationStatus.OK;
714 private StorageOperationStatus associateInterfacesToResource(GraphVertex topologyTemplateVertex,
715 TopologyTemplate topologyTemplate) {
716 Map<String, InterfaceDataDefinition> interfaces = topologyTemplate.getInterfaces();
717 return associateInterfacesToComponent(topologyTemplateVertex,interfaces);
720 public StorageOperationStatus associateInterfacesToComponent(GraphVertex nodeTypeVertex,
721 Map<String, InterfaceDataDefinition>
723 if (interfaceMap != null && !interfaceMap.isEmpty()) {
724 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData
725 (nodeTypeVertex, VertexTypeEnum.INTERFACE_ARTIFACTS, EdgeLabelEnum.INTERFACE_ARTIFACTS, interfaceMap);
726 if (assosiateElementToData.isRight()) {
727 return assosiateElementToData.right().value();
730 return StorageOperationStatus.OK;
734 private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
735 Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
736 if (result.isLeft()) {
737 toscaElement.setPolicies(result.left().value());
739 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
740 return result.right().value();
743 return TitanOperationStatus.OK;
746 private TitanOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
747 Either<Map<String, ForwardingPathDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
748 if (result.isLeft()) {
749 topologyTemplate.setForwardingPaths(result.left().value());
751 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
752 return result.right().value();
755 return TitanOperationStatus.OK;
759 private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
760 Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
761 if (result.isLeft()) {
762 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
764 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
765 return result.right().value();
768 return TitanOperationStatus.OK;
771 private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
772 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
773 if (result.isLeft()) {
774 toscaElement.setProperties(result.left().value());
776 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
777 return result.right().value();
780 return TitanOperationStatus.OK;
783 private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
784 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
785 if (result.isLeft()) {
786 topologyTemplate.setInstGroups(result.left().value());
788 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
789 return result.right().value();
792 return TitanOperationStatus.OK;
795 private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
796 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
797 if (result.isLeft()) {
798 topologyTemplate.setInstProperties(result.left().value());
800 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
801 return result.right().value();
804 return TitanOperationStatus.OK;
807 private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
808 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
809 if (result.isLeft()) {
810 topologyTemplate.setInstInputs(result.left().value());
812 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
813 return result.right().value();
816 return TitanOperationStatus.OK;
820 protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
821 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
822 if (result.isLeft()) {
823 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
825 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
826 return result.right().value();
829 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
830 if (result.isLeft()) {
831 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
833 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
834 return result.right().value();
837 return TitanOperationStatus.OK;
841 protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
842 Either<Map<String, MapListCapabiltyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
843 if (result.isLeft()) {
844 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
846 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
847 return result.right().value();
850 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
851 if (result.isLeft()) {
852 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
854 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
855 return result.right().value();
858 return TitanOperationStatus.OK;
861 private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
862 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
863 if (storageStatus != TitanOperationStatus.OK) {
864 return storageStatus;
866 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
867 if (result.isLeft()) {
868 toscaElement.setServiceApiArtifacts(result.left().value());
870 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
871 return result.right().value();
874 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
875 if (resultInstArt.isLeft()) {
876 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
878 if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
879 return resultInstArt.right().value();
882 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
883 if (instanceArt.isLeft()) {
884 toscaElement.setInstanceArtifacts(instanceArt.left().value());
886 if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
887 return instanceArt.right().value();
890 return TitanOperationStatus.OK;
893 private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
894 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
895 if (result.isLeft()) {
896 toscaElement.setInputs(result.left().value());
898 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
899 return result.right().value();
902 return TitanOperationStatus.OK;
905 private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
906 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
907 if (result.isLeft()) {
908 toscaElement.setGroups(result.left().value());
910 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
911 return result.right().value();
914 return TitanOperationStatus.OK;
917 private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
918 List<CategoryDefinition> categories = new ArrayList<>();
920 switch (componentV.getType()) {
922 return setResourceCategoryFromGraph(componentV, toscaElement);
924 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
927 log.debug("Not supported component type {} ", componentV.getType());
930 return TitanOperationStatus.OK;
933 private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
934 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
935 if (childVertex.isRight()) {
936 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
937 return childVertex.right().value();
939 GraphVertex categoryV = childVertex.left().value();
940 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
941 CategoryDefinition category = new CategoryDefinition();
942 category.setUniqueId(categoryV.getUniqueId());
943 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
944 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
946 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
947 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
948 category.setIcons(iconsfromJsonCat);
949 categories.add(category);
950 toscaElement.setCategories(categories);
952 return TitanOperationStatus.OK;
955 @SuppressWarnings("unchecked")
956 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
958 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
960 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
961 topologyTemplate.setCompositions(json);
963 return topologyTemplate;
967 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
968 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
969 if (nodeType.isRight()) {
970 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
973 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
974 if (status != TitanOperationStatus.OK) {
975 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
977 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
978 if (status != TitanOperationStatus.OK) {
979 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
980 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
982 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
983 if (status != TitanOperationStatus.OK) {
984 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
985 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
988 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
989 if (status != TitanOperationStatus.OK) {
990 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
991 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
994 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
995 if (status != TitanOperationStatus.OK) {
996 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
997 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
999 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1000 if (status != TitanOperationStatus.OK) {
1001 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1002 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1004 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1005 if (status != TitanOperationStatus.OK) {
1006 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1007 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1009 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1010 if (status != TitanOperationStatus.OK) {
1011 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1012 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1014 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1015 if (status != TitanOperationStatus.OK) {
1016 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1017 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1019 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1020 if (status != TitanOperationStatus.OK) {
1021 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1022 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1024 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1025 if (status != TitanOperationStatus.OK) {
1026 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1027 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1029 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1030 if (status != TitanOperationStatus.OK) {
1031 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1032 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1034 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1035 if (status != TitanOperationStatus.OK) {
1036 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1037 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1039 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1040 if (status != TitanOperationStatus.OK) {
1041 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1042 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1044 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1045 if (status != TitanOperationStatus.OK) {
1046 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1047 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1049 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1050 if (status != TitanOperationStatus.OK) {
1051 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1052 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1055 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1056 toscaElementVertex.getVertex().remove();
1057 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1062 @SuppressWarnings("unchecked")
1064 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1065 return createTopologyTemplate((TopologyTemplate) toscaElement);
1069 protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1070 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1074 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1075 // Product isn't supported now!!
1076 // TODO add for Product
1077 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1078 return validateServiceCategory(toscaElementToUpdate, elementV);
1081 return validateResourceCategory(toscaElementToUpdate, elementV);
1086 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1087 // not relevant now for topology template
1088 return StorageOperationStatus.OK;
1092 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1093 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1096 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1097 StorageOperationStatus status = StorageOperationStatus.OK;
1098 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1099 CategoryDefinition newCategory = newCategoryList.get(0);
1101 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1102 if (childVertex.isRight()) {
1103 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1104 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
1107 GraphVertex categoryV = childVertex.left().value();
1108 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1109 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1111 String newCategoryName = newCategory.getName();
1112 if (newCategoryName != null && false == newCategoryName.equals(categoryNameCurrent)) {
1113 // the category was changed
1114 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1116 if (getCategoryVertex.isRight()) {
1117 return getCategoryVertex.right().value();
1119 GraphVertex newCategoryV = getCategoryVertex.left().value();
1120 status = moveCategoryEdge(elementV, newCategoryV);
1121 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1126 public Either<List<GraphVertex>, TitanOperationStatus> getAllNotDeletedElements() {
1127 Map<GraphPropertyEnum, Object> propsHasNot = new HashMap<>();
1128 propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
1130 Either<List<GraphVertex>, TitanOperationStatus> byCriteria = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, propsHasNot, JsonParseFlagEnum.ParseJson);
1131 if (byCriteria.isRight()) {
1132 log.debug("Failed to fetch all non marked topology templates , propsHasNot {}, error {}", propsHasNot, byCriteria.right().value());
1133 return Either.right(byCriteria.right().value());
1135 return Either.left(byCriteria.left().value());
1138 @SuppressWarnings("unchecked")
1139 public boolean isInUse(GraphVertex elementV, List<GraphVertex> allNonDeleted) {
1140 for (GraphVertex containerV : allNonDeleted) {
1141 Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
1142 if (composition != null) {
1143 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
1144 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
1145 for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
1146 if (ci.getComponentUid().equals(elementV.getUniqueId())) {
1147 log.debug("The resource {} failed to delete cause in use as component instance UniqueID = {} in {} with UniqueID {}", elementV.getUniqueId(), ci.getUniqueId(), containerV.getType(), containerV.getUniqueId());
1159 @SuppressWarnings("unchecked")
1160 public boolean isInUse(String componentId, List<GraphVertex> allNonDeleted) {
1161 for (GraphVertex containerV : allNonDeleted) {
1162 Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
1163 if (composition != null) {
1164 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
1165 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
1166 for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
1167 if (ci.getComponentUid().equals(componentId)) {
1179 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1181 Either<GraphVertex, StorageOperationStatus> result = null;
1182 String userId = user.getUserId();
1183 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
1184 GraphVertex userVertex = null;
1185 GraphVertex serviceVertex = null;
1186 if (getRes.isRight()) {
1187 TitanOperationStatus status = getRes.right().value();
1188 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1189 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1191 if (result == null) {
1192 userVertex = getRes.left().value();
1193 getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1194 if (getRes.isRight()) {
1195 TitanOperationStatus status = getRes.right().value();
1196 log.error("Cannot find service {} in the graph. status is {}", uniqueId, status);
1197 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1200 if (result == null) {
1201 serviceVertex = getRes.left().value();
1202 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1203 if (edgeIterator.hasNext()) {
1204 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1205 edgeIterator.next().remove();
1208 if (result == null) {
1209 TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1210 if (status != TitanOperationStatus.OK) {
1211 log.error("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1212 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1215 if (result == null) {
1216 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1217 long lastUpdateDate = System.currentTimeMillis();
1218 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1219 Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1220 if (updateRes.isRight()) {
1221 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1224 if (result == null) {
1225 result = Either.left(serviceVertex);
1230 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1231 * @param componentId
1233 * @param capabilityName
1234 * @param capabilityType
1238 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1240 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1241 Map<String, MapCapabiltyProperty> mapPropertiesDataDefinition = null;
1242 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TopologyTemplate, JsonParseFlagEnum.NoParse);
1243 if (componentByLabelAndId.isRight()) {
1244 result = Either.right(componentByLabelAndId.right().value());
1246 if(componentByLabelAndId.isLeft()){
1247 Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1248 if (getDataRes.isRight()) {
1249 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getDataRes.right().value()));
1251 mapPropertiesDataDefinition = getDataRes.left().value();
1254 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1255 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1260 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabiltyProperty instanceProperties) {
1261 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1265 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabiltyProperty> mapPropertiesDataDefinition) {
1266 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1267 mapPropertiesDataDefinition.get(instanceId) != null &&
1268 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1271 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1272 List<ComponentInstanceProperty> capPropsList = null;
1273 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1274 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1275 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1276 if (capMap != null && !capMap.isEmpty()) {
1277 capPropsList = capMap.values().stream().map(o -> new ComponentInstanceProperty(o)).collect(Collectors.toList());
1282 if(capPropsList == null){
1283 capPropsList = new ArrayList<>();
1285 return capPropsList;
1288 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1289 if (capProp != null) {
1290 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1291 if (path.length < 4) {
1292 log.debug("wrong key format for capabilty, key {}", capProp);
1295 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1300 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1301 fillPolicyDefinition(componentV, policyDefinition, counter);
1302 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1305 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1306 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1309 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1310 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1313 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1314 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1317 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1318 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1319 policyDefinition.setName(policyName);
1320 policyDefinition.setInvariantName(policyName);
1321 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1322 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1323 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1324 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1327 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1328 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1329 return componentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;