1 package org.openecomp.sdc.be.model.jsontitan.operations;
3 import java.lang.reflect.Type;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.Iterator;
10 import org.apache.tinkerpop.gremlin.structure.Direction;
11 import org.apache.tinkerpop.gremlin.structure.Edge;
12 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
13 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
14 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
15 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
16 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
17 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
18 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
19 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
20 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
21 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
22 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
23 import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
24 import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
25 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
26 import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
27 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
28 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
29 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
30 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
31 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
32 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
33 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
34 import org.openecomp.sdc.be.model.ComponentParametersView;
35 import org.openecomp.sdc.be.model.DistributionStatusEnum;
36 import org.openecomp.sdc.be.model.User;
37 import org.openecomp.sdc.be.model.category.CategoryDefinition;
38 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
39 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
40 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
41 import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
42 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
43 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
44 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
45 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
46 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
50 import com.google.gson.reflect.TypeToken;
52 import fj.data.Either;
54 @org.springframework.stereotype.Component("topology-template-operation")
55 public class TopologyTemplateOperation extends ToscaElementOperation {
56 private static Logger log = LoggerFactory.getLogger(TopologyTemplateOperation.class.getName());
58 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
59 Either<TopologyTemplate, StorageOperationStatus> result = null;
61 topologyTemplate.generateUUID();
63 topologyTemplate = (TopologyTemplate) getResourceMetaDataFromResource(topologyTemplate);
64 String resourceUniqueId = topologyTemplate.getUniqueId();
65 if (resourceUniqueId == null) {
66 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
67 topologyTemplate.setUniqueId(resourceUniqueId);
70 GraphVertex topologyTemplateVertex = new GraphVertex();
71 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
73 Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
74 if (createdVertex.isRight()) {
75 TitanOperationStatus status = createdVertex.right().value();
76 log.error("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
77 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
81 topologyTemplateVertex = createdVertex.left().value();
83 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
84 if (assosiateCommon != StorageOperationStatus.OK) {
85 result = Either.right(assosiateCommon);
89 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
90 if (associateCategory != StorageOperationStatus.OK) {
91 result = Either.right(associateCategory);
95 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
96 if (associateInputs != StorageOperationStatus.OK) {
97 result = Either.right(associateInputs);
100 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
101 if (associateGroups != StorageOperationStatus.OK) {
102 result = Either.right(associateGroups);
105 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
106 if (associateInstAttr != StorageOperationStatus.OK) {
107 result = Either.right(associateInstAttr);
110 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
111 if (associateInstProperties != StorageOperationStatus.OK) {
112 result = Either.right(associateInstProperties);
115 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
116 if (associateInstProperties != StorageOperationStatus.OK) {
117 result = Either.right(associateInstInputs);
120 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
121 if (associateRequirements != StorageOperationStatus.OK) {
122 result = Either.right(associateRequirements);
126 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
127 if (associateCapabilities != StorageOperationStatus.OK) {
128 result = Either.right(associateCapabilities);
132 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
133 if (associateArtifacts != StorageOperationStatus.OK) {
134 result = Either.right(associateArtifacts);
138 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
139 if (addAdditionalInformation != StorageOperationStatus.OK) {
140 result = Either.right(addAdditionalInformation);
143 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
144 if (associateCapProperties != StorageOperationStatus.OK) {
145 result = Either.right(associateCapProperties);
148 return Either.left(topologyTemplate);
152 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
153 Map<String, MapCapabiltyProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
154 if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
155 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
156 if (assosiateElementToData.isRight()) {
157 return assosiateElementToData.right().value();
160 return StorageOperationStatus.OK;
163 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
164 Map<String, MapListCapabiltyDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
165 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
166 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
167 if (assosiateElementToData.isRight()) {
168 return assosiateElementToData.right().value();
171 Map<String, MapListCapabiltyDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
172 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
173 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
174 if (assosiateElementToData.isRight()) {
175 return assosiateElementToData.right().value();
178 return StorageOperationStatus.OK;
182 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
183 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
184 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
185 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
186 if (assosiateElementToData.isRight()) {
187 return assosiateElementToData.right().value();
190 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
191 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
192 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
193 if (assosiateElementToData.isRight()) {
194 return assosiateElementToData.right().value();
197 return StorageOperationStatus.OK;
200 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
201 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
203 if (addInformation != null && !addInformation.isEmpty()) {
204 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
205 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
206 a.setUniqueId(uniqueId);
208 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
209 if (assosiateElementToData.isRight()) {
210 return assosiateElementToData.right().value();
213 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
215 if (instArtifacts != null && !instArtifacts.isEmpty()) {
216 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
217 if (assosiateElementToData.isRight()) {
218 return assosiateElementToData.right().value();
221 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
223 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
224 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
225 if (assosiateElementToData.isRight()) {
226 return assosiateElementToData.right().value();
229 return StorageOperationStatus.OK;
232 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
234 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
236 if (addInformation != null && !addInformation.isEmpty()) {
237 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
238 if (assosiateElementToData.isRight()) {
239 return assosiateElementToData.right().value();
242 return StorageOperationStatus.OK;
245 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
246 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
247 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
250 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
251 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
252 return associateInstInputsToComponent(nodeTypeVertex, instProps);
255 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
256 if (instProps != null && !instProps.isEmpty()) {
257 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
258 if (assosiateElementToData.isRight()) {
259 return assosiateElementToData.right().value();
262 return StorageOperationStatus.OK;
265 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
266 if (instInputs != null && !instInputs.isEmpty()) {
267 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
268 if (assosiateElementToData.isRight()) {
269 return assosiateElementToData.right().value();
272 return StorageOperationStatus.OK;
275 public StorageOperationStatus addInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
277 if (instInputs != null && !instInputs.isEmpty()) {
278 instInputs.entrySet().forEach(i -> {
279 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, i.getValue(), i.getKey());
280 if (status != StorageOperationStatus.OK) {
286 return StorageOperationStatus.OK;
289 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
291 if (instInputs != null && !instInputs.isEmpty()) {
292 instInputs.entrySet().forEach(i -> {
293 List<String> uniqueKeys = new ArrayList<String>(i.getValue().getMapToscaDataDefinition().keySet());
294 List<String> pathKeys = new ArrayList<String>();
295 pathKeys.add(i.getKey());
297 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
298 if (status != StorageOperationStatus.OK) {
304 return StorageOperationStatus.OK;
307 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
309 if (instInputs != null && !instInputs.isEmpty()) {
310 instInputs.entrySet().forEach(i -> {
311 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
312 if (status != StorageOperationStatus.OK) {
318 return StorageOperationStatus.OK;
321 public StorageOperationStatus associateInstArtifactToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps) {
322 if (instProps != null && !instProps.isEmpty()) {
323 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instProps);
324 if (assosiateElementToData.isRight()) {
325 return assosiateElementToData.right().value();
328 return StorageOperationStatus.OK;
331 public StorageOperationStatus associateCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabiltyDataDefinition> calcCapabilty, Map<String, MapCapabiltyProperty> calculatedCapabilitiesProperties) {
332 if (calcRequirements != null && !calcRequirements.isEmpty()) {
333 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
334 if (assosiateElementToData.isRight()) {
335 return assosiateElementToData.right().value();
337 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
338 assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
339 if (assosiateElementToData.isRight()) {
340 return assosiateElementToData.right().value();
343 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
344 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
345 if (assosiateElementToData.isRight()) {
346 return assosiateElementToData.right().value();
348 Map<String, MapListCapabiltyDataDefinition> fullFilled = new HashMap<>();
349 assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
350 if (assosiateElementToData.isRight()) {
351 return assosiateElementToData.right().value();
354 if ( calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty() ){
355 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties);
356 if (assosiateElementToData.isRight()) {
357 return assosiateElementToData.right().value();
360 return StorageOperationStatus.OK;
363 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
364 Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
365 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
368 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
369 if (instAttr != null && !instAttr.isEmpty()) {
370 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
371 if (assosiateElementToData.isRight()) {
372 return assosiateElementToData.right().value();
375 return StorageOperationStatus.OK;
378 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
380 if (groups != null && !groups.isEmpty()) {
381 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
382 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
385 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
386 if (assosiateElementToData.isRight()) {
387 return assosiateElementToData.right().value();
390 return StorageOperationStatus.OK;
393 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
394 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
397 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
398 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
399 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
402 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
403 if (inputs != null && !inputs.isEmpty()) {
404 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
406 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
407 if (assosiateElementToData.isRight()) {
408 return assosiateElementToData.right().value();
411 return StorageOperationStatus.OK;
414 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
415 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
416 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
417 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
418 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
420 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
421 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
423 return nodeTypeVertex;
427 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
428 if (topologyTemplate.getResourceType() == null) {
430 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
433 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
437 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
438 String categoryName = topologyTemplate.getCategories().get(0).getName();
439 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
440 if (category.isRight()) {
441 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
442 return StorageOperationStatus.CATEGORY_NOT_FOUND;
444 GraphVertex categoryV = category.left().value();
445 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
446 if (createEdge != TitanOperationStatus.OK) {
447 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
448 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
450 return StorageOperationStatus.OK;
454 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
455 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
457 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TopologyTemplate, parseFlag);
458 if (componentByLabelAndId.isRight()) {
459 return Either.right(componentByLabelAndId.right().value());
461 GraphVertex componentV = componentByLabelAndId.left().value();
463 return getToscaElement(componentV, componentParametersView);
466 // -------------------------------------------------------------
468 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
469 TopologyTemplate toscaElement;
471 toscaElement = convertToTopologyTemplate(componentV);
472 TitanOperationStatus status = null;
473 if (false == componentParametersView.isIgnoreUsers()) {
474 status = setCreatorFromGraph(componentV, toscaElement);
475 if (status != TitanOperationStatus.OK) {
476 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
479 status = setLastModifierFromGraph(componentV, toscaElement);
480 if (status != TitanOperationStatus.OK) {
481 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
484 if (false == componentParametersView.isIgnoreCategories()) {
485 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
486 if (status != TitanOperationStatus.OK) {
487 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
491 if (false == componentParametersView.isIgnoreArtifacts()) {
492 TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
493 if (storageStatus != TitanOperationStatus.OK) {
494 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
497 if (false == componentParametersView.isIgnoreComponentInstancesProperties()) {
498 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
499 if (status != TitanOperationStatus.OK) {
500 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
503 if (false == componentParametersView.isIgnoreCapabilities()) {
504 status = setCapabilitiesFromGraph(componentV, toscaElement);
505 if (status != TitanOperationStatus.OK) {
506 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
509 if (false == componentParametersView.isIgnoreRequirements()) {
510 status = setRequirementsFromGraph(componentV, toscaElement);
511 if (status != TitanOperationStatus.OK) {
512 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
515 if (false == componentParametersView.isIgnoreAllVersions()) {
516 status = setAllVersions(componentV, toscaElement);
517 if (status != TitanOperationStatus.OK) {
518 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
521 if (false == componentParametersView.isIgnoreAdditionalInformation()) {
522 status = setAdditionalInformationFromGraph(componentV, toscaElement);
523 if (status != TitanOperationStatus.OK) {
524 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
528 if (false == componentParametersView.isIgnoreGroups()) {
529 status = setGroupsFromGraph(componentV, toscaElement);
530 if (status != TitanOperationStatus.OK) {
531 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
535 if (false == componentParametersView.isIgnoreComponentInstances()) {
536 status = setInstGroupsFromGraph(componentV, toscaElement);
537 if (status != TitanOperationStatus.OK) {
538 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
542 if (false == componentParametersView.isIgnoreInputs()) {
543 status = setInputsFromGraph(componentV, toscaElement);
544 if (status != TitanOperationStatus.OK) {
545 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
549 if (false == componentParametersView.isIgnoreProperties()) {
550 status = setPropertiesFromGraph(componentV, toscaElement);
551 if (status != TitanOperationStatus.OK) {
552 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
557 if (false == componentParametersView.isIgnoreComponentInstancesInputs()) {
558 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
559 if (status != TitanOperationStatus.OK) {
560 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
565 if (false == componentParametersView.isIgnoreCapabiltyProperties()) {
566 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
567 if (status != TitanOperationStatus.OK) {
568 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
572 return Either.left(toscaElement);
575 private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
576 Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
577 if (result.isLeft()) {
578 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
580 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
581 return result.right().value();
584 return TitanOperationStatus.OK;
587 private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
588 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
589 if (result.isLeft()) {
590 toscaElement.setProperties(result.left().value());
592 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
593 return result.right().value();
596 return TitanOperationStatus.OK;
599 private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
600 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
601 if (result.isLeft()) {
602 topologyTemplate.setInstGroups(result.left().value());
604 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
605 return result.right().value();
608 return TitanOperationStatus.OK;
611 private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
612 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
613 if (result.isLeft()) {
614 topologyTemplate.setInstProperties(result.left().value());
616 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
617 return result.right().value();
620 return TitanOperationStatus.OK;
623 private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
624 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
625 if (result.isLeft()) {
626 topologyTemplate.setInstInputs(result.left().value());
628 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
629 return result.right().value();
632 return TitanOperationStatus.OK;
636 protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
637 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
638 if (result.isLeft()) {
639 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
641 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
642 return result.right().value();
645 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
646 if (result.isLeft()) {
647 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
649 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
650 return result.right().value();
653 return TitanOperationStatus.OK;
657 protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
658 Either<Map<String, MapListCapabiltyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
659 if (result.isLeft()) {
660 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
662 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
663 return result.right().value();
666 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
667 if (result.isLeft()) {
668 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
670 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
671 return result.right().value();
674 return TitanOperationStatus.OK;
677 private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
678 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
679 if (storageStatus != TitanOperationStatus.OK) {
680 return storageStatus;
682 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
683 if (result.isLeft()) {
684 toscaElement.setServiceApiArtifacts(result.left().value());
686 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
687 return result.right().value();
690 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
691 if (resultInstArt.isLeft()) {
692 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
694 if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
695 return resultInstArt.right().value();
698 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
699 if (instanceArt.isLeft()) {
700 toscaElement.setInstanceArtifacts(instanceArt.left().value());
702 if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
703 return instanceArt.right().value();
706 return TitanOperationStatus.OK;
709 private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
710 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
711 if (result.isLeft()) {
712 toscaElement.setInputs(result.left().value());
714 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
715 return result.right().value();
718 return TitanOperationStatus.OK;
721 private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
722 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
723 if (result.isLeft()) {
724 toscaElement.setGroups(result.left().value());
726 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
727 return result.right().value();
730 return TitanOperationStatus.OK;
733 private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
734 List<CategoryDefinition> categories = new ArrayList<>();
736 switch (componentV.getType()) {
738 return setResourceCategoryFromGraph(componentV, toscaElement);
740 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
743 log.debug("Not supported component type {} ", componentV.getType());
746 return TitanOperationStatus.OK;
749 private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
750 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
751 if (childVertex.isRight()) {
752 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
753 return childVertex.right().value();
755 GraphVertex categoryV = childVertex.left().value();
756 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
757 CategoryDefinition category = new CategoryDefinition();
758 category.setUniqueId((String) metadataProperties.get(GraphPropertyEnum.UNIQUE_ID));
759 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
760 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
762 Type listTypeCat = new TypeToken<List<String>>() {
764 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
765 category.setIcons(iconsfromJsonCat);
766 categories.add(category);
767 toscaElement.setCategories(categories);
769 return TitanOperationStatus.OK;
772 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
774 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
776 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
777 topologyTemplate.setCompositions(json);
779 return topologyTemplate;
783 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
784 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
785 if (nodeType.isRight()) {
786 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
789 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
790 if (status != TitanOperationStatus.OK) {
791 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
793 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
794 if (status != TitanOperationStatus.OK) {
795 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
796 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
798 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
799 if (status != TitanOperationStatus.OK) {
800 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
801 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
804 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
805 if (status != TitanOperationStatus.OK) {
806 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
807 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
810 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
811 if (status != TitanOperationStatus.OK) {
812 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
813 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
815 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
816 if (status != TitanOperationStatus.OK) {
817 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
818 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
820 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
821 if (status != TitanOperationStatus.OK) {
822 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
823 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
825 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
826 if (status != TitanOperationStatus.OK) {
827 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
828 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
830 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
831 if (status != TitanOperationStatus.OK) {
832 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
833 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
835 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
836 if (status != TitanOperationStatus.OK) {
837 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
838 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
840 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
841 if (status != TitanOperationStatus.OK) {
842 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
843 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
845 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
846 if (status != TitanOperationStatus.OK) {
847 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
848 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
850 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
851 if (status != TitanOperationStatus.OK) {
852 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
853 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
855 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
856 if (status != TitanOperationStatus.OK) {
857 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
858 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
860 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
861 if (status != TitanOperationStatus.OK) {
862 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
863 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
865 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
866 toscaElementVertex.getVertex().remove();
867 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
872 @SuppressWarnings("unchecked")
874 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
875 return createTopologyTemplate((TopologyTemplate) toscaElement);
879 protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
880 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
884 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
885 // Product isn't supported now!!
886 // TODO add for Product
887 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
888 return validateServiceCategory(toscaElementToUpdate, elementV);
891 return validateResourceCategory(toscaElementToUpdate, elementV);
896 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
897 // not relevant now for topology template
898 return StorageOperationStatus.OK;
902 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
903 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
906 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
907 StorageOperationStatus status = StorageOperationStatus.OK;
908 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
909 CategoryDefinition newCategory = newCategoryList.get(0);
911 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
912 if (childVertex.isRight()) {
913 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
914 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
917 GraphVertex categoryV = childVertex.left().value();
918 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
919 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
921 String newCategoryName = newCategory.getName();
922 if (newCategoryName != null && false == newCategoryName.equals(categoryNameCurrent)) {
923 // the category was changed
924 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
926 if (getCategoryVertex.isRight()) {
927 return getCategoryVertex.right().value();
929 GraphVertex newCategoryV = getCategoryVertex.left().value();
930 status = moveCategoryEdge(elementV, newCategoryV);
931 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
936 public Either<List<GraphVertex>, TitanOperationStatus> getAllNotDeletedElements() {
937 Map<GraphPropertyEnum, Object> propsHasNot = new HashMap<>();
938 propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
940 Either<List<GraphVertex>, TitanOperationStatus> byCriteria = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, propsHasNot, JsonParseFlagEnum.ParseJson);
941 if (byCriteria.isRight()) {
942 log.debug("Failed to fetch all non marked topology templates , propsHasNot {}, error {}", propsHasNot, byCriteria.right().value());
943 return Either.right(byCriteria.right().value());
945 return Either.left(byCriteria.left().value());
948 public boolean isInUse(GraphVertex elementV, List<GraphVertex> allNonDeleted) {
949 for (GraphVertex containerV : allNonDeleted) {
950 Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
951 if (composition != null) {
952 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
953 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
954 for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
955 if (ci.getComponentUid().equals(elementV.getUniqueId())) {
967 public boolean isInUse(String componentId, List<GraphVertex> allNonDeleted) {
968 for (GraphVertex containerV : allNonDeleted) {
969 Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
970 if (composition != null) {
971 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
972 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
973 for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
974 if (ci.getComponentUid().equals(componentId)) {
986 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
988 Either<GraphVertex, StorageOperationStatus> result = null;
989 String userId = user.getUserId();
990 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
991 GraphVertex userVertex = null;
992 GraphVertex serviceVertex = null;
993 if (getRes.isRight()) {
994 TitanOperationStatus status = getRes.right().value();
995 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
996 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
998 if (result == null) {
999 userVertex = getRes.left().value();
1000 getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1001 if (getRes.isRight()) {
1002 TitanOperationStatus status = getRes.right().value();
1003 log.error("Cannot find service {} in the graph. status is {}", uniqueId, status);
1004 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1007 if (result == null) {
1008 serviceVertex = getRes.left().value();
1009 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1010 if (edgeIterator.hasNext()) {
1011 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1012 edgeIterator.next().remove();
1015 if (result == null) {
1016 TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1017 if (status != TitanOperationStatus.OK) {
1018 log.error("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1019 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1022 if (result == null) {
1023 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1024 long lastUpdateDate = System.currentTimeMillis();
1025 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1026 Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1027 if (updateRes.isRight()) {
1028 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1031 if (result == null) {
1032 result = Either.left(serviceVertex);