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 java.lang.reflect.Type;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.List;
29 import java.util.Optional;
30 import java.util.Map.Entry;
32 import org.apache.tinkerpop.gremlin.structure.Direction;
33 import org.apache.tinkerpop.gremlin.structure.Edge;
34 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
35 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
36 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
37 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
38 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
39 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.MapCapabiltyProperty;
46 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.MapListCapabiltyDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
51 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
52 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
53 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
54 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
55 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
56 import org.openecomp.sdc.be.model.ComponentParametersView;
57 import org.openecomp.sdc.be.model.DistributionStatusEnum;
58 import org.openecomp.sdc.be.model.User;
59 import org.openecomp.sdc.be.model.category.CategoryDefinition;
60 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
61 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
62 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
63 import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
64 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
65 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
66 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
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 com.google.gson.reflect.TypeToken;
74 import fj.data.Either;
76 @org.springframework.stereotype.Component("topology-template-operation")
77 public class TopologyTemplateOperation extends ToscaElementOperation {
78 private static Logger log = LoggerFactory.getLogger(TopologyTemplateOperation.class.getName());
80 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
81 Either<TopologyTemplate, StorageOperationStatus> result = null;
83 topologyTemplate.generateUUID();
85 topologyTemplate = (TopologyTemplate) getResourceMetaDataFromResource(topologyTemplate);
86 String resourceUniqueId = topologyTemplate.getUniqueId();
87 if (resourceUniqueId == null) {
88 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
89 topologyTemplate.setUniqueId(resourceUniqueId);
92 GraphVertex topologyTemplateVertex = new GraphVertex();
93 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
95 Either<GraphVertex, TitanOperationStatus> createdVertex = titanDao.createVertex(topologyTemplateVertex);
96 if (createdVertex.isRight()) {
97 TitanOperationStatus status = createdVertex.right().value();
98 log.error("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
99 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
103 topologyTemplateVertex = createdVertex.left().value();
105 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
106 if (assosiateCommon != StorageOperationStatus.OK) {
107 result = Either.right(assosiateCommon);
111 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
112 if (associateCategory != StorageOperationStatus.OK) {
113 result = Either.right(associateCategory);
117 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
118 if (associateInputs != StorageOperationStatus.OK) {
119 result = Either.right(associateInputs);
122 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
123 if (associateGroups != StorageOperationStatus.OK) {
124 result = Either.right(associateGroups);
127 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
128 if (associateInstAttr != StorageOperationStatus.OK) {
129 result = Either.right(associateInstAttr);
132 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
133 if (associateInstProperties != StorageOperationStatus.OK) {
134 result = Either.right(associateInstProperties);
137 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
138 if (associateInstProperties != StorageOperationStatus.OK) {
139 result = Either.right(associateInstInputs);
142 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
143 if (associateInstGroups != StorageOperationStatus.OK) {
144 result = Either.right(associateInstInputs);
148 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
149 if (associateRequirements != StorageOperationStatus.OK) {
150 result = Either.right(associateRequirements);
154 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
155 if (associateCapabilities != StorageOperationStatus.OK) {
156 result = Either.right(associateCapabilities);
160 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
161 if (associateArtifacts != StorageOperationStatus.OK) {
162 result = Either.right(associateArtifacts);
166 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
167 if (addAdditionalInformation != StorageOperationStatus.OK) {
168 result = Either.right(addAdditionalInformation);
171 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
172 if (associateCapProperties != StorageOperationStatus.OK) {
173 result = Either.right(associateCapProperties);
176 return Either.left(topologyTemplate);
180 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
181 Map<String, MapCapabiltyProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
182 if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) {
183 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
184 if (assosiateElementToData.isRight()) {
185 return assosiateElementToData.right().value();
188 return StorageOperationStatus.OK;
191 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
192 Map<String, MapListCapabiltyDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
193 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
194 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
195 if (assosiateElementToData.isRight()) {
196 return assosiateElementToData.right().value();
199 Map<String, MapListCapabiltyDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
200 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
201 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
202 if (assosiateElementToData.isRight()) {
203 return assosiateElementToData.right().value();
206 return StorageOperationStatus.OK;
210 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
211 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
212 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
213 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
214 if (assosiateElementToData.isRight()) {
215 return assosiateElementToData.right().value();
218 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
219 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
220 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
221 if (assosiateElementToData.isRight()) {
222 return assosiateElementToData.right().value();
225 return StorageOperationStatus.OK;
228 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
229 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
231 if (addInformation != null && !addInformation.isEmpty()) {
232 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
233 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
234 a.setUniqueId(uniqueId);
236 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
237 if (assosiateElementToData.isRight()) {
238 return assosiateElementToData.right().value();
241 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
243 if (instArtifacts != null && !instArtifacts.isEmpty()) {
244 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
245 if (assosiateElementToData.isRight()) {
246 return assosiateElementToData.right().value();
249 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
251 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
252 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
253 if (assosiateElementToData.isRight()) {
254 return assosiateElementToData.right().value();
257 return StorageOperationStatus.OK;
260 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
262 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
264 if (addInformation != null && !addInformation.isEmpty()) {
265 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
266 if (assosiateElementToData.isRight()) {
267 return assosiateElementToData.right().value();
270 return StorageOperationStatus.OK;
273 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
274 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
275 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
278 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
279 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
280 return associateInstInputsToComponent(nodeTypeVertex, instProps);
283 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
284 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
285 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
289 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
290 if (instProps != null && !instProps.isEmpty()) {
291 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
292 if (assosiateElementToData.isRight()) {
293 return assosiateElementToData.right().value();
296 return StorageOperationStatus.OK;
299 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
300 if (instInputs != null && !instInputs.isEmpty()) {
301 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
302 if (assosiateElementToData.isRight()) {
303 return assosiateElementToData.right().value();
306 return StorageOperationStatus.OK;
309 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
310 if (instGroups != null && !instGroups.isEmpty()) {
311 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
312 if (assosiateElementToData.isRight()) {
313 return assosiateElementToData.right().value();
316 return StorageOperationStatus.OK;
320 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
322 if (instInputs != null && !instInputs.isEmpty()) {
323 instInputs.entrySet().forEach(i -> {
324 List<String> uniqueKeys = new ArrayList<String>(i.getValue().getMapToscaDataDefinition().keySet());
325 List<String> pathKeys = new ArrayList<String>();
326 pathKeys.add(i.getKey());
328 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
329 if (status != StorageOperationStatus.OK) {
335 return StorageOperationStatus.OK;
338 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
340 if (instInputs != null && !instInputs.isEmpty()) {
341 instInputs.entrySet().forEach(i -> {
342 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
343 if (status != StorageOperationStatus.OK) {
349 return StorageOperationStatus.OK;
352 public StorageOperationStatus associateInstArtifactToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps) {
353 if (instProps != null && !instProps.isEmpty()) {
354 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instProps);
355 if (assosiateElementToData.isRight()) {
356 return assosiateElementToData.right().value();
359 return StorageOperationStatus.OK;
362 public StorageOperationStatus associateCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabiltyDataDefinition> calcCapabilty, Map<String, MapCapabiltyProperty> calculatedCapabilitiesProperties) {
363 if (calcRequirements != null && !calcRequirements.isEmpty()) {
364 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
365 if (assosiateElementToData.isRight()) {
366 return assosiateElementToData.right().value();
368 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
369 assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
370 if (assosiateElementToData.isRight()) {
371 return assosiateElementToData.right().value();
374 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
375 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
376 if (assosiateElementToData.isRight()) {
377 return assosiateElementToData.right().value();
379 Map<String, MapListCapabiltyDataDefinition> fullFilled = new HashMap<>();
380 assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
381 if (assosiateElementToData.isRight()) {
382 return assosiateElementToData.right().value();
385 if ( calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty() ){
386 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties);
387 if (assosiateElementToData.isRight()) {
388 return assosiateElementToData.right().value();
391 return StorageOperationStatus.OK;
394 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
395 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
396 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
399 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
400 if (instAttr != null && !instAttr.isEmpty()) {
401 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
402 if (assosiateElementToData.isRight()) {
403 return assosiateElementToData.right().value();
406 return StorageOperationStatus.OK;
409 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
411 if (groups != null && !groups.isEmpty()) {
412 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
413 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
416 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
417 if (assosiateElementToData.isRight()) {
418 return assosiateElementToData.right().value();
421 return StorageOperationStatus.OK;
424 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
425 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
428 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
429 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
430 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
433 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
434 if (inputs != null && !inputs.isEmpty()) {
435 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
437 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
438 if (assosiateElementToData.isRight()) {
439 return assosiateElementToData.right().value();
442 return StorageOperationStatus.OK;
445 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
446 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
447 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
448 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
449 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
451 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
452 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
454 return nodeTypeVertex;
458 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
459 if (topologyTemplate.getResourceType() == null) {
461 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
464 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
468 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
469 String categoryName = topologyTemplate.getCategories().get(0).getName();
470 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
471 if (category.isRight()) {
472 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
473 return StorageOperationStatus.CATEGORY_NOT_FOUND;
475 GraphVertex categoryV = category.left().value();
476 TitanOperationStatus createEdge = titanDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
477 if (createEdge != TitanOperationStatus.OK) {
478 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
479 return DaoStatusConverter.convertTitanStatusToStorageStatus(createEdge);
481 return StorageOperationStatus.OK;
485 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
486 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
488 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TopologyTemplate, parseFlag);
489 if (componentByLabelAndId.isRight()) {
490 return Either.right(componentByLabelAndId.right().value());
492 GraphVertex componentV = componentByLabelAndId.left().value();
494 return getToscaElement(componentV, componentParametersView);
497 // -------------------------------------------------------------
499 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
500 TopologyTemplate toscaElement;
502 toscaElement = convertToTopologyTemplate(componentV);
503 TitanOperationStatus status = null;
504 if (false == componentParametersView.isIgnoreUsers()) {
505 status = setCreatorFromGraph(componentV, toscaElement);
506 if (status != TitanOperationStatus.OK) {
507 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
510 status = setLastModifierFromGraph(componentV, toscaElement);
511 if (status != TitanOperationStatus.OK) {
512 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
515 if (false == componentParametersView.isIgnoreCategories()) {
516 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
517 if (status != TitanOperationStatus.OK) {
518 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
522 if (false == componentParametersView.isIgnoreArtifacts()) {
523 TitanOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
524 if (storageStatus != TitanOperationStatus.OK) {
525 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
528 if (false == componentParametersView.isIgnoreComponentInstancesProperties()) {
529 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
530 if (status != TitanOperationStatus.OK) {
531 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
534 if (false == componentParametersView.isIgnoreCapabilities()) {
535 status = setCapabilitiesFromGraph(componentV, toscaElement);
536 if (status != TitanOperationStatus.OK) {
537 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
540 if (false == componentParametersView.isIgnoreRequirements()) {
541 status = setRequirementsFromGraph(componentV, toscaElement);
542 if (status != TitanOperationStatus.OK) {
543 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
546 if (false == componentParametersView.isIgnoreAllVersions()) {
547 status = setAllVersions(componentV, toscaElement);
548 if (status != TitanOperationStatus.OK) {
549 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
552 if (false == componentParametersView.isIgnoreAdditionalInformation()) {
553 status = setAdditionalInformationFromGraph(componentV, toscaElement);
554 if (status != TitanOperationStatus.OK) {
555 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
559 if (false == componentParametersView.isIgnoreGroups()) {
560 status = setGroupsFromGraph(componentV, toscaElement);
561 if (status != TitanOperationStatus.OK) {
562 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
566 if (false == componentParametersView.isIgnoreComponentInstances()) {
567 status = setInstGroupsFromGraph(componentV, toscaElement);
568 if (status != TitanOperationStatus.OK) {
569 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
573 if (false == componentParametersView.isIgnoreInputs()) {
574 status = setInputsFromGraph(componentV, toscaElement);
575 if (status != TitanOperationStatus.OK) {
576 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
580 if (false == componentParametersView.isIgnoreProperties()) {
581 status = setPropertiesFromGraph(componentV, toscaElement);
582 if (status != TitanOperationStatus.OK) {
583 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
588 if (false == componentParametersView.isIgnoreComponentInstancesInputs()) {
589 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
590 if (status != TitanOperationStatus.OK) {
591 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
596 if (false == componentParametersView.isIgnoreCapabiltyProperties()) {
597 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
598 if (status != TitanOperationStatus.OK) {
599 return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
603 return Either.left(toscaElement);
606 private TitanOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
607 Either<Map<String, MapCapabiltyProperty>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
608 if (result.isLeft()) {
609 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
611 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
612 return result.right().value();
615 return TitanOperationStatus.OK;
618 private TitanOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
619 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
620 if (result.isLeft()) {
621 toscaElement.setProperties(result.left().value());
623 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
624 return result.right().value();
627 return TitanOperationStatus.OK;
630 private TitanOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
631 Either<Map<String, MapGroupsDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
632 if (result.isLeft()) {
633 topologyTemplate.setInstGroups(result.left().value());
635 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
636 return result.right().value();
639 return TitanOperationStatus.OK;
642 private TitanOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
643 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
644 if (result.isLeft()) {
645 topologyTemplate.setInstProperties(result.left().value());
647 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
648 return result.right().value();
651 return TitanOperationStatus.OK;
654 private TitanOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
655 Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
656 if (result.isLeft()) {
657 topologyTemplate.setInstInputs(result.left().value());
659 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
660 return result.right().value();
663 return TitanOperationStatus.OK;
667 protected <T extends ToscaElement> TitanOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
668 Either<Map<String, MapListRequirementDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
669 if (result.isLeft()) {
670 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
672 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
673 return result.right().value();
676 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
677 if (result.isLeft()) {
678 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
680 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
681 return result.right().value();
684 return TitanOperationStatus.OK;
688 protected <T extends ToscaElement> TitanOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
689 Either<Map<String, MapListCapabiltyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
690 if (result.isLeft()) {
691 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
693 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
694 return result.right().value();
697 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
698 if (result.isLeft()) {
699 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
701 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
702 return result.right().value();
705 return TitanOperationStatus.OK;
708 private TitanOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
709 TitanOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
710 if (storageStatus != TitanOperationStatus.OK) {
711 return storageStatus;
713 Either<Map<String, ArtifactDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
714 if (result.isLeft()) {
715 toscaElement.setServiceApiArtifacts(result.left().value());
717 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
718 return result.right().value();
721 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
722 if (resultInstArt.isLeft()) {
723 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
725 if (resultInstArt.right().value() != TitanOperationStatus.NOT_FOUND) {
726 return resultInstArt.right().value();
729 Either<Map<String, MapArtifactDataDefinition>, TitanOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
730 if (instanceArt.isLeft()) {
731 toscaElement.setInstanceArtifacts(instanceArt.left().value());
733 if (instanceArt.right().value() != TitanOperationStatus.NOT_FOUND) {
734 return instanceArt.right().value();
737 return TitanOperationStatus.OK;
740 private TitanOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
741 Either<Map<String, PropertyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
742 if (result.isLeft()) {
743 toscaElement.setInputs(result.left().value());
745 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
746 return result.right().value();
749 return TitanOperationStatus.OK;
752 private TitanOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
753 Either<Map<String, GroupDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
754 if (result.isLeft()) {
755 toscaElement.setGroups(result.left().value());
757 if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
758 return result.right().value();
761 return TitanOperationStatus.OK;
764 private TitanOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
765 List<CategoryDefinition> categories = new ArrayList<>();
767 switch (componentV.getType()) {
769 return setResourceCategoryFromGraph(componentV, toscaElement);
771 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
774 log.debug("Not supported component type {} ", componentV.getType());
777 return TitanOperationStatus.OK;
780 private TitanOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
781 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
782 if (childVertex.isRight()) {
783 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
784 return childVertex.right().value();
786 GraphVertex categoryV = childVertex.left().value();
787 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
788 CategoryDefinition category = new CategoryDefinition();
789 category.setUniqueId(categoryV.getUniqueId());
790 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
791 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
793 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
794 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
795 category.setIcons(iconsfromJsonCat);
796 categories.add(category);
797 toscaElement.setCategories(categories);
799 return TitanOperationStatus.OK;
802 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
804 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
806 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
807 topologyTemplate.setCompositions(json);
809 return topologyTemplate;
813 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
814 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
815 if (nodeType.isRight()) {
816 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
819 TitanOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
820 if (status != TitanOperationStatus.OK) {
821 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
823 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
824 if (status != TitanOperationStatus.OK) {
825 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
826 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
828 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
829 if (status != TitanOperationStatus.OK) {
830 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
831 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
834 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
835 if (status != TitanOperationStatus.OK) {
836 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
837 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
840 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
841 if (status != TitanOperationStatus.OK) {
842 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
843 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
845 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
846 if (status != TitanOperationStatus.OK) {
847 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
848 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
850 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
851 if (status != TitanOperationStatus.OK) {
852 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
853 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
855 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
856 if (status != TitanOperationStatus.OK) {
857 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
858 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
860 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
861 if (status != TitanOperationStatus.OK) {
862 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
863 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
865 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
866 if (status != TitanOperationStatus.OK) {
867 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
868 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
870 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
871 if (status != TitanOperationStatus.OK) {
872 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
873 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
875 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
876 if (status != TitanOperationStatus.OK) {
877 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
878 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
880 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
881 if (status != TitanOperationStatus.OK) {
882 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
883 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
885 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
886 if (status != TitanOperationStatus.OK) {
887 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
888 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
890 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
891 if (status != TitanOperationStatus.OK) {
892 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
893 Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
895 status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
896 toscaElementVertex.getVertex().remove();
897 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
902 @SuppressWarnings("unchecked")
904 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
905 return createTopologyTemplate((TopologyTemplate) toscaElement);
909 protected <T extends ToscaElement> TitanOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
910 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
914 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
915 // Product isn't supported now!!
916 // TODO add for Product
917 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
918 return validateServiceCategory(toscaElementToUpdate, elementV);
921 return validateResourceCategory(toscaElementToUpdate, elementV);
926 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
927 // not relevant now for topology template
928 return StorageOperationStatus.OK;
932 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
933 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
936 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
937 StorageOperationStatus status = StorageOperationStatus.OK;
938 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
939 CategoryDefinition newCategory = newCategoryList.get(0);
941 Either<GraphVertex, TitanOperationStatus> childVertex = titanDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
942 if (childVertex.isRight()) {
943 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
944 return DaoStatusConverter.convertTitanStatusToStorageStatus(childVertex.right().value());
947 GraphVertex categoryV = childVertex.left().value();
948 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
949 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
951 String newCategoryName = newCategory.getName();
952 if (newCategoryName != null && false == newCategoryName.equals(categoryNameCurrent)) {
953 // the category was changed
954 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
956 if (getCategoryVertex.isRight()) {
957 return getCategoryVertex.right().value();
959 GraphVertex newCategoryV = getCategoryVertex.left().value();
960 status = moveCategoryEdge(elementV, newCategoryV);
961 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
966 public Either<List<GraphVertex>, TitanOperationStatus> getAllNotDeletedElements() {
967 Map<GraphPropertyEnum, Object> propsHasNot = new HashMap<>();
968 propsHasNot.put(GraphPropertyEnum.IS_DELETED, true);
970 Either<List<GraphVertex>, TitanOperationStatus> byCriteria = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, null, propsHasNot, JsonParseFlagEnum.ParseJson);
971 if (byCriteria.isRight()) {
972 log.debug("Failed to fetch all non marked topology templates , propsHasNot {}, error {}", propsHasNot, byCriteria.right().value());
973 return Either.right(byCriteria.right().value());
975 return Either.left(byCriteria.left().value());
978 public boolean isInUse(GraphVertex elementV, List<GraphVertex> allNonDeleted) {
979 for (GraphVertex containerV : allNonDeleted) {
980 Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
981 if (composition != null) {
982 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
983 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
984 for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
985 if (ci.getComponentUid().equals(elementV.getUniqueId())) {
986 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());
998 public boolean isInUse(String componentId, List<GraphVertex> allNonDeleted) {
999 for (GraphVertex containerV : allNonDeleted) {
1000 Map<String, CompositionDataDefinition> composition = (Map<String, CompositionDataDefinition>) containerV.getJson();
1001 if (composition != null) {
1002 CompositionDataDefinition instances = composition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
1003 if (instances != null && instances.getComponentInstances() != null && !instances.getComponentInstances().isEmpty()) {
1004 for (ComponentInstanceDataDefinition ci : instances.getComponentInstances().values()) {
1005 if (ci.getComponentUid().equals(componentId)) {
1017 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1019 Either<GraphVertex, StorageOperationStatus> result = null;
1020 String userId = user.getUserId();
1021 Either<GraphVertex, TitanOperationStatus> getRes = findUserVertex(userId);
1022 GraphVertex userVertex = null;
1023 GraphVertex serviceVertex = null;
1024 if (getRes.isRight()) {
1025 TitanOperationStatus status = getRes.right().value();
1026 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1027 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1029 if (result == null) {
1030 userVertex = getRes.left().value();
1031 getRes = titanDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1032 if (getRes.isRight()) {
1033 TitanOperationStatus status = getRes.right().value();
1034 log.error("Cannot find service {} in the graph. status is {}", uniqueId, status);
1035 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1038 if (result == null) {
1039 serviceVertex = getRes.left().value();
1040 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1041 if (edgeIterator.hasNext()) {
1042 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1043 edgeIterator.next().remove();
1046 if (result == null) {
1047 TitanOperationStatus status = titanDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1048 if (status != TitanOperationStatus.OK) {
1049 log.error("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1050 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
1053 if (result == null) {
1054 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1055 long lastUpdateDate = System.currentTimeMillis();
1056 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1057 Either<GraphVertex, TitanOperationStatus> updateRes = titanDao.updateVertex(serviceVertex);
1058 if (updateRes.isRight()) {
1059 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateRes.right().value()));
1062 if (result == null) {
1063 result = Either.left(serviceVertex);