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.jsonjanusgraph.operations;
23 import com.google.gson.reflect.TypeToken;
24 import fj.data.Either;
25 import org.apache.commons.collections.MapUtils;
26 import org.apache.tinkerpop.gremlin.structure.Direction;
27 import org.apache.tinkerpop.gremlin.structure.Edge;
28 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
29 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
30 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
31 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
32 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
33 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
38 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
46 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
54 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
55 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
56 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
57 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
58 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
59 import org.openecomp.sdc.be.model.Component;
60 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
61 import org.openecomp.sdc.be.model.ComponentParametersView;
62 import org.openecomp.sdc.be.model.DistributionStatusEnum;
63 import org.openecomp.sdc.be.model.GroupDefinition;
64 import org.openecomp.sdc.be.model.PolicyDefinition;
65 import org.openecomp.sdc.be.model.User;
66 import org.openecomp.sdc.be.model.category.CategoryDefinition;
67 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
68 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
69 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
70 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
71 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
72 import org.openecomp.sdc.be.model.operations.StorageException;
73 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
74 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
75 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
76 import org.openecomp.sdc.common.api.Constants;
77 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
78 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
79 import org.openecomp.sdc.common.log.wrappers.Logger;
80 import org.openecomp.sdc.common.util.ValidationUtils;
81 import org.springframework.beans.factory.annotation.Autowired;
83 import java.lang.reflect.Type;
84 import java.util.ArrayList;
85 import java.util.Arrays;
86 import java.util.HashMap;
87 import java.util.HashSet;
88 import java.util.Iterator;
89 import java.util.List;
91 import java.util.Map.Entry;
92 import java.util.Optional;
94 import java.util.stream.Collectors;
96 @org.springframework.stereotype.Component("topology-template-operation")
97 public class TopologyTemplateOperation extends ToscaElementOperation {
99 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
100 private Set<OriginTypeEnum> nodeTypeSet = new HashSet<>(Arrays.asList(OriginTypeEnum.VFC, OriginTypeEnum.CP, OriginTypeEnum.VL, OriginTypeEnum.Configuration, OriginTypeEnum.VFCMT));
103 private ArchiveOperation archiveOperation;
105 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
106 Either<TopologyTemplate, StorageOperationStatus> result = null;
108 topologyTemplate.generateUUID();
110 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
111 String resourceUniqueId = topologyTemplate.getUniqueId();
112 if (resourceUniqueId == null) {
113 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
114 topologyTemplate.setUniqueId(resourceUniqueId);
117 GraphVertex topologyTemplateVertex = new GraphVertex();
118 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
120 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
121 if (createdVertex.isRight()) {
122 JanusGraphOperationStatus status = createdVertex.right().value();
123 log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
124 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
128 topologyTemplateVertex = createdVertex.left().value();
130 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
131 if (assosiateCommon != StorageOperationStatus.OK) {
132 result = Either.right(assosiateCommon);
136 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
137 if (associateCategory != StorageOperationStatus.OK) {
138 result = Either.right(associateCategory);
142 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
143 if (associateInputs != StorageOperationStatus.OK) {
144 result = Either.right(associateInputs);
147 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
148 if (associateGroups != StorageOperationStatus.OK) {
149 result = Either.right(associateGroups);
152 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
153 if (associatePolicies != StorageOperationStatus.OK) {
154 result = Either.right(associatePolicies);
157 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
158 if (associateInstAttr != StorageOperationStatus.OK) {
159 result = Either.right(associateInstAttr);
162 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
163 if (associateInstProperties != StorageOperationStatus.OK) {
164 result = Either.right(associateInstProperties);
167 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
168 if (associateInstProperties != StorageOperationStatus.OK) {
169 result = Either.right(associateInstInputs);
172 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
173 if (associateInstGroups != StorageOperationStatus.OK) {
174 result = Either.right(associateInstInputs);
178 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
179 if (associateRequirements != StorageOperationStatus.OK) {
180 result = Either.right(associateRequirements);
184 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
185 if (associateCapabilities != StorageOperationStatus.OK) {
186 result = Either.right(associateCapabilities);
190 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
191 if (associateArtifacts != StorageOperationStatus.OK) {
192 result = Either.right(associateArtifacts);
196 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
197 if (addAdditionalInformation != StorageOperationStatus.OK) {
198 result = Either.right(addAdditionalInformation);
201 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
202 if (associateCapProperties != StorageOperationStatus.OK) {
203 result = Either.right(associateCapProperties);
207 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
208 if (associateInterfaces != StorageOperationStatus.OK) {
209 result = Either.right(associateInterfaces);
213 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
214 if (associateCapProperties != StorageOperationStatus.OK) {
215 result = Either.right(associatePathProperties);
220 return Either.left(topologyTemplate);
224 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
225 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
228 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
229 if (policies != null && !policies.isEmpty()) {
230 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
231 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
234 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
235 if (assosiateElementToData.isRight()) {
236 return assosiateElementToData.right().value();
239 return StorageOperationStatus.OK;
242 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
243 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
244 return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths);
247 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
248 TopologyTemplate topologyTemplate) {
249 Map<String, CINodeFilterDataDefinition> nodeFilters =
250 topologyTemplate.getNodeFilterComponents();
251 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
254 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
255 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
256 .getCalculatedCapabilitiesProperties();
257 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
258 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
259 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
260 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
261 if (associateElementToData.isRight()) {
262 return associateElementToData.right().value();
266 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
267 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
268 Either<GraphVertex, StorageOperationStatus> associateElementToData =
269 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
270 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
271 if (associateElementToData.isRight()) {
272 return associateElementToData.right().value();
275 return StorageOperationStatus.OK;
278 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
279 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
280 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
281 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
282 if (assosiateElementToData.isRight()) {
283 return assosiateElementToData.right().value();
286 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
287 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
288 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
289 if (assosiateElementToData.isRight()) {
290 return assosiateElementToData.right().value();
293 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
294 if(MapUtils.isNotEmpty(capabilities)) {
295 Either<GraphVertex, StorageOperationStatus> associateElementToData =
296 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
297 EdgeLabelEnum.CAPABILITIES, capabilities);
298 if (associateElementToData.isRight()) {
299 return associateElementToData.right().value();
302 return StorageOperationStatus.OK;
306 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
307 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
308 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
309 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
310 if (assosiateElementToData.isRight()) {
311 return assosiateElementToData.right().value();
314 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
315 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
316 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
317 if (assosiateElementToData.isRight()) {
318 return assosiateElementToData.right().value();
321 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
322 if(MapUtils.isNotEmpty(requirements)) {
323 Either<GraphVertex, StorageOperationStatus> associateElementToData =
324 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
325 EdgeLabelEnum.REQUIREMENTS, requirements);
326 if (associateElementToData.isRight()) {
327 return associateElementToData.right().value();
330 return StorageOperationStatus.OK;
333 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
334 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
336 if (addInformation != null && !addInformation.isEmpty()) {
337 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
338 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
339 a.setUniqueId(uniqueId);
341 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
342 if (assosiateElementToData.isRight()) {
343 return assosiateElementToData.right().value();
346 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
348 if (instArtifacts != null && !instArtifacts.isEmpty()) {
349 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
350 if (assosiateElementToData.isRight()) {
351 return assosiateElementToData.right().value();
354 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
356 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
357 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
358 if (assosiateElementToData.isRight()) {
359 return assosiateElementToData.right().value();
362 return StorageOperationStatus.OK;
365 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
367 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
369 if (addInformation != null && !addInformation.isEmpty()) {
370 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
371 if (assosiateElementToData.isRight()) {
372 return assosiateElementToData.right().value();
375 return StorageOperationStatus.OK;
378 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
379 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
380 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
383 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
384 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
385 return associateInstInputsToComponent(nodeTypeVertex, instProps);
388 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
389 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
390 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
394 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
395 if (instProps != null && !instProps.isEmpty()) {
396 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
397 if (assosiateElementToData.isRight()) {
398 return assosiateElementToData.right().value();
401 return StorageOperationStatus.OK;
404 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
405 if (instInputs != null && !instInputs.isEmpty()) {
406 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
407 if (assosiateElementToData.isRight()) {
408 return assosiateElementToData.right().value();
411 return StorageOperationStatus.OK;
414 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
415 if (instGroups != null && !instGroups.isEmpty()) {
416 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
417 if (assosiateElementToData.isRight()) {
418 return assosiateElementToData.right().value();
421 return StorageOperationStatus.OK;
425 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
427 if (instInputs != null && !instInputs.isEmpty()) {
428 instInputs.entrySet().forEach(i -> {
429 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
430 List<String> pathKeys = new ArrayList<>();
431 pathKeys.add(i.getKey());
433 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
434 if (status != StorageOperationStatus.OK) {
440 return StorageOperationStatus.OK;
443 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
445 if (instInputs != null && !instInputs.isEmpty()) {
446 instInputs.entrySet().forEach(i -> {
447 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
448 if (status != StorageOperationStatus.OK) {
454 return StorageOperationStatus.OK;
457 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
458 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
461 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
462 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
465 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
466 if (instProps != null && !instProps.isEmpty()) {
467 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
468 if (assosiateElementToData.isRight()) {
469 return assosiateElementToData.right().value();
472 return StorageOperationStatus.OK;
475 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
476 if (calcRequirements != null && !calcRequirements.isEmpty()) {
477 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
478 if (assosiateElementToData.isRight()) {
479 return assosiateElementToData.right().value();
481 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
482 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
483 if (assosiateElementToData.isRight()) {
484 return assosiateElementToData.right().value();
487 if (calcCapabilty != null && !calcCapabilty.isEmpty()) {
488 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
489 if (assosiateElementToData.isRight()) {
490 return assosiateElementToData.right().value();
492 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
493 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
494 if (assosiateElementToData.isRight()) {
495 return assosiateElementToData.right().value();
498 if (calculatedCapabilitiesProperties != null && !calculatedCapabilitiesProperties.isEmpty()) {
499 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
500 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
502 .on(v -> StorageOperationStatus.OK);
504 return StorageOperationStatus.OK;
507 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
508 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
509 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
510 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
513 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
514 if (status == JanusGraphOperationStatus.NOT_FOUND) {
515 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
517 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
520 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
521 Optional<StorageOperationStatus> error = dataMap.entrySet()
523 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
524 .filter(s -> s != StorageOperationStatus.OK)
526 if (error.isPresent()) {
527 return Either.right(error.get());
529 return Either.left(dataVertex);
532 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
533 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
534 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
537 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
538 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
539 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
540 if (assosiateElementToData.isRight()) {
541 return assosiateElementToData.right().value();
544 return StorageOperationStatus.OK;
547 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
548 if (instAttr != null && !instAttr.isEmpty()) {
549 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
550 if (assosiateElementToData.isRight()) {
551 return assosiateElementToData.right().value();
554 return StorageOperationStatus.OK;
557 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
559 if (groups != null && !groups.isEmpty()) {
560 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
561 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
564 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
565 if (assosiateElementToData.isRight()) {
566 return assosiateElementToData.right().value();
569 return StorageOperationStatus.OK;
572 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
573 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
576 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
577 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
578 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
581 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
582 if (inputs != null && !inputs.isEmpty()) {
583 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
585 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
586 if (assosiateElementToData.isRight()) {
587 return assosiateElementToData.right().value();
590 return StorageOperationStatus.OK;
593 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
594 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
595 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
596 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
597 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
599 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
600 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
602 return nodeTypeVertex;
606 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
607 if (topologyTemplate.getResourceType() == null) {
609 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
612 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
616 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
617 String categoryName = topologyTemplate.getCategories().get(0).getName();
618 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
619 if (category.isRight()) {
620 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
621 return StorageOperationStatus.CATEGORY_NOT_FOUND;
623 GraphVertex categoryV = category.left().value();
624 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
625 if (createEdge != JanusGraphOperationStatus.OK) {
626 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
627 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
629 return StorageOperationStatus.OK;
633 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
634 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
636 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
637 if (componentByLabelAndId.isRight()) {
638 return Either.right(componentByLabelAndId.right().value());
640 GraphVertex componentV = componentByLabelAndId.left().value();
642 return getToscaElement(componentV, componentParametersView);
645 // -------------------------------------------------------------
647 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
648 TopologyTemplate toscaElement;
650 toscaElement = convertToTopologyTemplate(componentV);
651 JanusGraphOperationStatus status;
652 if (!componentParametersView.isIgnoreUsers()) {
653 status = setCreatorFromGraph(componentV, toscaElement);
654 if (status != JanusGraphOperationStatus.OK) {
655 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
658 status = setLastModifierFromGraph(componentV, toscaElement);
659 if (status != JanusGraphOperationStatus.OK) {
660 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
663 if (!componentParametersView.isIgnoreCategories()) {
664 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
665 if (status != JanusGraphOperationStatus.OK) {
666 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
670 if (!componentParametersView.isIgnoreArtifacts()) {
671 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
672 if (storageStatus != JanusGraphOperationStatus.OK) {
673 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
676 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
677 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
678 if (status != JanusGraphOperationStatus.OK) {
679 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
682 if (!componentParametersView.isIgnoreCapabilities()) {
683 status = setCapabilitiesFromGraph(componentV, toscaElement);
684 if (status != JanusGraphOperationStatus.OK) {
685 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
688 if (!componentParametersView.isIgnoreRequirements()) {
689 status = setRequirementsFromGraph(componentV, toscaElement);
690 if (status != JanusGraphOperationStatus.OK) {
691 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
694 if (!componentParametersView.isIgnoreAllVersions()) {
695 status = setAllVersions(componentV, toscaElement);
696 if (status != JanusGraphOperationStatus.OK) {
697 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
700 if (!componentParametersView.isIgnoreAdditionalInformation()) {
701 status = setAdditionalInformationFromGraph(componentV, toscaElement);
702 if (status != JanusGraphOperationStatus.OK) {
703 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
707 if (!componentParametersView.isIgnoreGroups()) {
708 status = setGroupsFromGraph(componentV, toscaElement);
709 if (status != JanusGraphOperationStatus.OK) {
710 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
714 if (!componentParametersView.isIgnorePolicies()) {
715 status = setPoliciesFromGraph(componentV, toscaElement);
716 if (status != JanusGraphOperationStatus.OK) {
717 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
721 if (!componentParametersView.isIgnoreComponentInstances()) {
722 status = setInstGroupsFromGraph(componentV, toscaElement);
724 //Mark all CIs that has archived origins
725 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
727 if (status != JanusGraphOperationStatus.OK) {
728 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
732 if (!componentParametersView.isIgnoreInputs()) {
733 status = setInputsFromGraph(componentV, toscaElement);
734 if (status != JanusGraphOperationStatus.OK) {
735 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
739 if (!componentParametersView.isIgnoreProperties()) {
740 status = setPropertiesFromGraph(componentV, toscaElement);
741 if (status != JanusGraphOperationStatus.OK) {
742 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
747 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
748 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
749 if (status != JanusGraphOperationStatus.OK) {
750 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
755 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
756 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
757 if (status != JanusGraphOperationStatus.OK) {
758 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
763 if (!componentParametersView.isIgnoreForwardingPath()) {
764 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
765 if (status != JanusGraphOperationStatus.OK) {
766 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
771 if (!componentParametersView.isIgnoreNodeFilter()) {
772 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
773 if (status != JanusGraphOperationStatus.OK) {
774 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
779 if (!componentParametersView.isIgnoreInterfaces()) {
780 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
781 if (storageStatus != JanusGraphOperationStatus.OK) {
782 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
787 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
788 JanusGraphOperationStatus storageStatus =
789 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
790 if (storageStatus != JanusGraphOperationStatus.OK) {
791 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
795 if (!componentParametersView.isIgnoreDataType()) {
796 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
797 if (storageStatus != JanusGraphOperationStatus.OK) {
798 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
802 return Either.left(toscaElement);
805 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
806 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
807 if (result.isLeft()) {
808 toscaElement.setDataTypes(result.left().value());
810 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
811 return result.right().value();
814 return JanusGraphOperationStatus.OK;
817 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
818 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
819 if (result.isLeft()) {
820 toscaElement.setPolicies(result.left().value());
822 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
823 return result.right().value();
826 return JanusGraphOperationStatus.OK;
829 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
830 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
831 if (result.isLeft()) {
832 topologyTemplate.setInterfaces(result.left().value());
834 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
835 return result.right().value();
838 return JanusGraphOperationStatus.OK;
842 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
843 TopologyTemplate topologyTemplate) {
844 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
845 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
846 if (result.isLeft()) {
847 result.left().value().entrySet().forEach(entry -> topologyTemplate
848 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
850 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
851 return result.right().value();
854 return JanusGraphOperationStatus.OK;
857 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
858 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
859 if (interfaceMap != null && !interfaceMap.isEmpty()) {
860 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
861 if (assosiateElementToData.isRight()) {
862 return assosiateElementToData.right().value();
865 return StorageOperationStatus.OK;
868 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
869 Map<String, CINodeFilterDataDefinition> filterMaps) {
870 if (filterMaps != null && !filterMaps.isEmpty()) {
871 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
872 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
873 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
874 if (assosiateElementToData.isRight()) {
875 return assosiateElementToData.right().value();
878 return StorageOperationStatus.OK;
881 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
882 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
883 if (result.isLeft()) {
884 topologyTemplate.setForwardingPaths(result.left().value());
886 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
887 return result.right().value();
890 return JanusGraphOperationStatus.OK;
894 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
895 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
896 if (result.isLeft()) {
897 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
899 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
900 return result.right().value();
903 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
904 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
905 if (capPropResult.isLeft()) {
906 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
908 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
909 return capPropResult.right().value();
913 return JanusGraphOperationStatus.OK;
916 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
917 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
918 if (result.isLeft()) {
919 toscaElement.setProperties(result.left().value());
921 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
922 return result.right().value();
925 return JanusGraphOperationStatus.OK;
928 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
929 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
930 if (result.isLeft()) {
931 topologyTemplate.setInstGroups(result.left().value());
933 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
934 return result.right().value();
937 return JanusGraphOperationStatus.OK;
940 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
941 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
942 if (result.isLeft()) {
943 topologyTemplate.setInstProperties(result.left().value());
945 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
946 return result.right().value();
949 return JanusGraphOperationStatus.OK;
952 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
953 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
954 if (result.isLeft()) {
955 topologyTemplate.setInstInputs(result.left().value());
957 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
958 return result.right().value();
961 return JanusGraphOperationStatus.OK;
964 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
965 TopologyTemplate topologyTemplate) {
966 Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
967 getDataFromGraph(componentV,
968 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
969 if (result.isLeft()) {
970 topologyTemplate.setNodeFilterComponents(result.left().value());
972 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
973 return result.right().value();
976 return JanusGraphOperationStatus.OK;
980 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
981 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
982 if (result.isLeft()) {
983 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
985 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
986 return result.right().value();
989 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
990 if (result.isLeft()) {
991 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
993 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
994 return result.right().value();
997 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
998 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
999 if (requirementResult.isLeft()) {
1000 toscaElement.setRequirements(requirementResult.left().value());
1002 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1003 return requirementResult.right().value();
1006 return JanusGraphOperationStatus.OK;
1010 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1011 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1012 if (result.isLeft()) {
1013 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1015 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1016 return result.right().value();
1019 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1020 if (result.isLeft()) {
1021 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1023 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1024 return result.right().value();
1027 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1028 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1029 if (capabilitiesResult.isLeft()) {
1030 toscaElement.setCapabilities(capabilitiesResult.left().value());
1032 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1033 return capabilitiesResult.right().value();
1036 return JanusGraphOperationStatus.OK;
1039 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1040 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1041 if (storageStatus != JanusGraphOperationStatus.OK) {
1042 return storageStatus;
1044 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1045 if (result.isLeft()) {
1046 toscaElement.setServiceApiArtifacts(result.left().value());
1048 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1049 return result.right().value();
1052 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1053 if (resultInstArt.isLeft()) {
1054 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1056 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1057 return resultInstArt.right().value();
1060 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1061 if (instanceArt.isLeft()) {
1062 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1064 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1065 return instanceArt.right().value();
1068 return JanusGraphOperationStatus.OK;
1071 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1072 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1073 if (result.isLeft()) {
1074 toscaElement.setInputs(result.left().value());
1076 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1077 return result.right().value();
1080 return JanusGraphOperationStatus.OK;
1083 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1084 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1085 if (result.isLeft()) {
1086 toscaElement.setGroups(result.left().value());
1088 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1089 return result.right().value();
1092 return JanusGraphOperationStatus.OK;
1095 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1096 List<CategoryDefinition> categories = new ArrayList<>();
1098 switch (componentV.getType()) {
1100 return setResourceCategoryFromGraph(componentV, toscaElement);
1102 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1105 log.debug("Not supported component type {} ", componentV.getType());
1108 return JanusGraphOperationStatus.OK;
1111 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1112 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1113 if (childVertex.isRight()) {
1114 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1115 return childVertex.right().value();
1117 GraphVertex categoryV = childVertex.left().value();
1118 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1119 CategoryDefinition category = new CategoryDefinition();
1120 category.setUniqueId(categoryV.getUniqueId());
1121 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1122 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1124 Type listTypeCat = new TypeToken<List<String>>() {
1126 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1127 category.setIcons(iconsfromJsonCat);
1128 categories.add(category);
1129 toscaElement.setCategories(categories);
1131 return JanusGraphOperationStatus.OK;
1134 @SuppressWarnings("unchecked")
1135 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1137 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1139 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1140 topologyTemplate.setCompositions(json);
1142 return topologyTemplate;
1146 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1147 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1148 if (nodeType.isRight()) {
1149 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1152 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1153 if (status != JanusGraphOperationStatus.OK) {
1154 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1156 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1157 if (status != JanusGraphOperationStatus.OK) {
1158 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1159 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1161 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1162 if (status != JanusGraphOperationStatus.OK) {
1163 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1164 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1167 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1168 if (status != JanusGraphOperationStatus.OK) {
1169 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1170 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1173 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1174 if (status != JanusGraphOperationStatus.OK) {
1175 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1176 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1178 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1179 if (status != JanusGraphOperationStatus.OK) {
1180 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1181 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1183 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1184 if (status != JanusGraphOperationStatus.OK) {
1185 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1186 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1188 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1189 if (status != JanusGraphOperationStatus.OK) {
1190 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1191 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1193 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1194 if (status != JanusGraphOperationStatus.OK) {
1195 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1196 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1198 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1199 if (status != JanusGraphOperationStatus.OK) {
1200 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1201 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1203 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1204 if (status != JanusGraphOperationStatus.OK) {
1205 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1206 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1208 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1209 if (status != JanusGraphOperationStatus.OK) {
1210 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1211 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1213 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1214 if (status != JanusGraphOperationStatus.OK) {
1215 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1216 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1218 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1219 if (status != JanusGraphOperationStatus.OK) {
1220 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1221 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1223 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1224 if (status != JanusGraphOperationStatus.OK) {
1225 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1226 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1228 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1229 if (status != JanusGraphOperationStatus.OK) {
1230 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1231 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1233 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1234 if (status != JanusGraphOperationStatus.OK) {
1235 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1236 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1238 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1239 if (status != JanusGraphOperationStatus.OK) {
1240 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1241 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1243 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1244 if (status != JanusGraphOperationStatus.OK) {
1245 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1246 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1248 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1249 if (status != JanusGraphOperationStatus.OK) {
1250 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1251 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1254 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1255 EdgeLabelEnum.REQUIREMENTS);
1256 if (status != JanusGraphOperationStatus.OK) {
1257 log.debug("Failed to disassociate requirements for {} error {}",
1258 toscaElementVertex.getUniqueId(), status);
1259 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1261 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1262 EdgeLabelEnum.CAPABILITIES);
1263 if (status != JanusGraphOperationStatus.OK) {
1264 log.debug("Failed to disassociate capabilities for {} error {}",
1265 toscaElementVertex.getUniqueId(), status);
1266 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1268 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1269 if (status != JanusGraphOperationStatus.OK) {
1270 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1271 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1273 toscaElementVertex.getVertex().remove();
1274 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1279 @SuppressWarnings("unchecked")
1281 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1282 return createTopologyTemplate((TopologyTemplate) toscaElement);
1286 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1287 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1291 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1292 // Product isn't supported now!!
1293 // TODO add for Product
1294 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1295 return validateServiceCategory(toscaElementToUpdate, elementV);
1298 return validateResourceCategory(toscaElementToUpdate, elementV);
1303 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1304 // not relevant now for topology template
1305 return StorageOperationStatus.OK;
1309 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1310 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1313 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1314 StorageOperationStatus status = StorageOperationStatus.OK;
1315 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1316 CategoryDefinition newCategory = newCategoryList.get(0);
1318 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1319 if (childVertex.isRight()) {
1320 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1321 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1324 GraphVertex categoryV = childVertex.left().value();
1325 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1326 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1328 String newCategoryName = newCategory.getName();
1329 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1330 // the category was changed
1331 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1333 if (getCategoryVertex.isRight()) {
1334 return getCategoryVertex.right().value();
1336 GraphVertex newCategoryV = getCategoryVertex.left().value();
1337 status = moveCategoryEdge(elementV, newCategoryV);
1338 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1343 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1345 Either<GraphVertex, StorageOperationStatus> result = null;
1346 String userId = user.getUserId();
1347 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1348 GraphVertex userVertex = null;
1349 GraphVertex serviceVertex = null;
1350 if (getRes.isRight()) {
1351 JanusGraphOperationStatus status = getRes.right().value();
1352 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1353 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1355 if (result == null) {
1356 userVertex = getRes.left().value();
1357 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1358 if (getRes.isRight()) {
1359 JanusGraphOperationStatus status = getRes.right().value();
1360 log.debug("Cannot find service {} in the graph. status is {}", uniqueId, status);
1361 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1364 if (result == null) {
1365 serviceVertex = getRes.left().value();
1366 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1367 if (edgeIterator.hasNext()) {
1368 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1369 edgeIterator.next().remove();
1372 if (result == null) {
1373 JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1374 if (status != JanusGraphOperationStatus.OK) {
1375 log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1376 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1379 if (result == null) {
1380 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1381 long lastUpdateDate = System.currentTimeMillis();
1382 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1383 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1384 if (updateRes.isRight()) {
1385 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1388 if (result == null) {
1389 result = Either.left(serviceVertex);
1395 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1397 * @param componentId
1399 * @param capabilityName
1400 * @param capabilityType
1404 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1406 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1407 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1408 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1409 if (componentByLabelAndId.isRight()) {
1410 result = Either.right(componentByLabelAndId.right().value());
1412 if (componentByLabelAndId.isLeft()) {
1413 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1414 if (getDataRes.isRight()) {
1415 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1417 mapPropertiesDataDefinition = getDataRes.left().value();
1420 if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
1421 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1426 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1427 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1430 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1431 String componentInstanceId,
1432 MapInterfaceDataDefinition instanceInterfaces) {
1433 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1434 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1435 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1437 return StorageOperationStatus.OK;
1441 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1442 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1443 mapPropertiesDataDefinition.get(instanceId) != null &&
1444 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1447 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1448 List<ComponentInstanceProperty> capPropsList = null;
1449 for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
1450 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1451 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1452 if (capMap != null && !capMap.isEmpty()) {
1453 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1458 if (capPropsList == null) {
1459 capPropsList = new ArrayList<>();
1461 return capPropsList;
1464 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1465 if (capProp != null) {
1466 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
1467 if (path.length < 4) {
1468 log.debug("wrong key format for capabilty, key {}", capProp);
1471 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1476 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1477 fillPolicyDefinition(componentV, policyDefinition, counter);
1478 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1481 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1482 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1485 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1486 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1489 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1490 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1493 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1494 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1497 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1498 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.NAME);
1501 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1502 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1503 policyDefinition.setName(policyName);
1504 policyDefinition.setInvariantName(policyName);
1505 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1506 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1507 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1508 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1511 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1512 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1513 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1514 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1517 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1518 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1519 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1521 .on(this::throwStorageException);
1522 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1523 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1525 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1526 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1528 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1529 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1530 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1534 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1535 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1536 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1538 .on(this::throwStorageException);
1539 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1540 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1542 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1543 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1545 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1546 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1547 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1551 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1552 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1553 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1554 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1555 if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
1556 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1559 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1561 if (getOriginRes.isRight()) {
1562 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1563 throw new StorageException(getOriginRes.right().value());
1565 return getOriginRes.left().value();
1568 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1569 log.debug("#detectToscaType - type: {}", originType);
1570 if (nodeTypeSet.contains(originType)){
1571 return ToscaElementTypeEnum.NODE_TYPE;
1573 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1577 private ComponentParametersView getFilter() {
1578 ComponentParametersView filter = new ComponentParametersView();
1579 filter.setIgnoreCapabilities(false);
1580 filter.setIgnoreCapabiltyProperties(false);
1581 filter.setIgnoreRequirements(false);
1584 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1585 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1586 .left().on(this::throwStorageException);
1587 updateCapOwnerId(toscaElement, componentId);
1588 updateReqOwnerId(toscaElement, componentId);
1589 updatePropertiesOwnerId(toscaElement, componentId);
1590 topologyTemplateOperation
1592 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1593 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1594 topologyTemplateOperation
1595 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1596 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1597 topologyTemplateOperation
1598 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1599 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1602 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1603 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1604 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1605 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1609 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1610 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1611 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1612 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1616 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1617 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1618 if(MapUtils.isNotEmpty(properties)) {
1619 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));