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 java.lang.reflect.Type;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.List;
31 import java.util.Map.Entry;
32 import java.util.Optional;
33 import java.util.stream.Collectors;
34 import java.lang.reflect.Type;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.Iterator;
38 import java.util.List;
40 import java.util.Map.Entry;
41 import java.util.Optional;
42 import java.util.stream.Collectors;
43 import org.apache.commons.collections.MapUtils;
44 import org.apache.tinkerpop.gremlin.structure.Direction;
45 import org.apache.tinkerpop.gremlin.structure.Edge;
46 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
47 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
48 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
49 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
50 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
51 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
52 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
58 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
63 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
64 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
65 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
66 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
67 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
68 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
69 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
70 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
71 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
72 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
73 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
74 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
75 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
76 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
77 import org.openecomp.sdc.be.model.Component;
78 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
79 import org.openecomp.sdc.be.model.ComponentParametersView;
80 import org.openecomp.sdc.be.model.DistributionStatusEnum;
81 import org.openecomp.sdc.be.model.GroupDefinition;
82 import org.openecomp.sdc.be.model.PolicyDefinition;
83 import org.openecomp.sdc.be.model.User;
84 import org.openecomp.sdc.be.model.category.CategoryDefinition;
85 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
86 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
87 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
88 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
89 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
90 import org.openecomp.sdc.be.model.operations.StorageException;
91 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
92 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
93 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
94 import org.openecomp.sdc.common.api.Constants;
95 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
96 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
97 import org.openecomp.sdc.common.log.wrappers.Logger;
98 import org.openecomp.sdc.common.util.ValidationUtils;
99 import org.springframework.beans.factory.annotation.Autowired;
102 @org.springframework.stereotype.Component("topology-template-operation")
103 public class TopologyTemplateOperation extends ToscaElementOperation {
105 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
106 private static final String PATH_DELIMITER = ".";
109 private ArchiveOperation archiveOperation;
111 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
112 Either<TopologyTemplate, StorageOperationStatus> result = null;
114 topologyTemplate.generateUUID();
116 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
117 String resourceUniqueId = topologyTemplate.getUniqueId();
118 if (resourceUniqueId == null) {
119 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
120 topologyTemplate.setUniqueId(resourceUniqueId);
123 GraphVertex topologyTemplateVertex = new GraphVertex();
124 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
126 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
127 if (createdVertex.isRight()) {
128 JanusGraphOperationStatus status = createdVertex.right().value();
129 log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
130 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
134 topologyTemplateVertex = createdVertex.left().value();
136 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
137 if (assosiateCommon != StorageOperationStatus.OK) {
138 result = Either.right(assosiateCommon);
142 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
143 if (associateCategory != StorageOperationStatus.OK) {
144 result = Either.right(associateCategory);
148 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
149 if (associateInputs != StorageOperationStatus.OK) {
150 result = Either.right(associateInputs);
153 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
154 if (associateGroups != StorageOperationStatus.OK) {
155 result = Either.right(associateGroups);
158 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
159 if (associatePolicies != StorageOperationStatus.OK) {
160 result = Either.right(associatePolicies);
163 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
164 if (associateInstAttr != StorageOperationStatus.OK) {
165 result = Either.right(associateInstAttr);
168 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
169 if (associateInstProperties != StorageOperationStatus.OK) {
170 result = Either.right(associateInstProperties);
173 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
174 if (associateInstProperties != StorageOperationStatus.OK) {
175 result = Either.right(associateInstInputs);
178 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
179 if (associateInstGroups != StorageOperationStatus.OK) {
180 result = Either.right(associateInstInputs);
184 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
185 if (associateRequirements != StorageOperationStatus.OK) {
186 result = Either.right(associateRequirements);
190 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
191 if (associateCapabilities != StorageOperationStatus.OK) {
192 result = Either.right(associateCapabilities);
196 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
197 if (associateArtifacts != StorageOperationStatus.OK) {
198 result = Either.right(associateArtifacts);
202 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
203 if (addAdditionalInformation != StorageOperationStatus.OK) {
204 result = Either.right(addAdditionalInformation);
207 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
208 if (associateCapProperties != StorageOperationStatus.OK) {
209 result = Either.right(associateCapProperties);
213 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
214 if (associateInterfaces != StorageOperationStatus.OK) {
215 result = Either.right(associateInterfaces);
219 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
220 if (associateCapProperties != StorageOperationStatus.OK) {
221 result = Either.right(associatePathProperties);
226 return Either.left(topologyTemplate);
230 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
231 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
234 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
235 if (policies != null && !policies.isEmpty()) {
236 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
237 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
240 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
241 if (assosiateElementToData.isRight()) {
242 return assosiateElementToData.right().value();
245 return StorageOperationStatus.OK;
248 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
249 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
250 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
253 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
254 TopologyTemplate topologyTemplate) {
255 Map<String, CINodeFilterDataDefinition> nodeFilters =
256 topologyTemplate.getNodeFilterComponents();
257 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
260 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
261 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
262 .getCalculatedCapabilitiesProperties();
263 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
264 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
265 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
266 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
267 if (associateElementToData.isRight()) {
268 return associateElementToData.right().value();
272 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
273 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
274 Either<GraphVertex, StorageOperationStatus> associateElementToData =
275 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
276 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
277 if (associateElementToData.isRight()) {
278 return associateElementToData.right().value();
281 return StorageOperationStatus.OK;
284 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
285 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
286 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
287 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
288 if (assosiateElementToData.isRight()) {
289 return assosiateElementToData.right().value();
292 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
293 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
294 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
295 if (assosiateElementToData.isRight()) {
296 return assosiateElementToData.right().value();
299 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
300 if(MapUtils.isNotEmpty(capabilities)) {
301 Either<GraphVertex, StorageOperationStatus> associateElementToData =
302 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
303 EdgeLabelEnum.CAPABILITIES, capabilities);
304 if (associateElementToData.isRight()) {
305 return associateElementToData.right().value();
308 return StorageOperationStatus.OK;
312 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
313 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
314 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
315 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
316 if (assosiateElementToData.isRight()) {
317 return assosiateElementToData.right().value();
320 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
321 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
322 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
323 if (assosiateElementToData.isRight()) {
324 return assosiateElementToData.right().value();
327 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
328 if(MapUtils.isNotEmpty(requirements)) {
329 Either<GraphVertex, StorageOperationStatus> associateElementToData =
330 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
331 EdgeLabelEnum.REQUIREMENTS, requirements);
332 if (associateElementToData.isRight()) {
333 return associateElementToData.right().value();
336 return StorageOperationStatus.OK;
339 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
340 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
342 if (addInformation != null && !addInformation.isEmpty()) {
343 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
344 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
345 a.setUniqueId(uniqueId);
347 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
348 if (assosiateElementToData.isRight()) {
349 return assosiateElementToData.right().value();
352 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
354 if (instArtifacts != null && !instArtifacts.isEmpty()) {
355 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
356 if (assosiateElementToData.isRight()) {
357 return assosiateElementToData.right().value();
360 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
362 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
363 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
364 if (assosiateElementToData.isRight()) {
365 return assosiateElementToData.right().value();
368 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
369 if(MapUtils.isNotEmpty(requirements)) {
370 Either<GraphVertex, StorageOperationStatus> associateElementToData =
371 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
372 EdgeLabelEnum.REQUIREMENTS, requirements);
373 if (associateElementToData.isRight()) {
374 return associateElementToData.right().value();
377 return StorageOperationStatus.OK;
380 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
382 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
384 if (addInformation != null && !addInformation.isEmpty()) {
385 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
386 if (assosiateElementToData.isRight()) {
387 return assosiateElementToData.right().value();
390 return StorageOperationStatus.OK;
393 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
394 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
395 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
398 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
399 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
400 return associateInstInputsToComponent(nodeTypeVertex, instProps);
403 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
404 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
405 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
409 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
410 if (instProps != null && !instProps.isEmpty()) {
411 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
412 if (assosiateElementToData.isRight()) {
413 return assosiateElementToData.right().value();
416 return StorageOperationStatus.OK;
419 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
420 if (instInputs != null && !instInputs.isEmpty()) {
421 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
422 if (assosiateElementToData.isRight()) {
423 return assosiateElementToData.right().value();
426 return StorageOperationStatus.OK;
429 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
430 if (instGroups != null && !instGroups.isEmpty()) {
431 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
432 if (assosiateElementToData.isRight()) {
433 return assosiateElementToData.right().value();
436 return StorageOperationStatus.OK;
440 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
442 if (instInputs != null && !instInputs.isEmpty()) {
443 instInputs.entrySet().forEach(i -> {
444 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
445 List<String> pathKeys = new ArrayList<>();
446 pathKeys.add(i.getKey());
448 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
449 if (status != StorageOperationStatus.OK) {
455 return StorageOperationStatus.OK;
458 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
460 if (instInputs != null && !instInputs.isEmpty()) {
461 instInputs.entrySet().forEach(i -> {
462 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
463 if (status != StorageOperationStatus.OK) {
469 return StorageOperationStatus.OK;
472 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
473 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
476 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
477 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
480 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
481 if (instProps != null && !instProps.isEmpty()) {
482 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
483 if (assosiateElementToData.isRight()) {
484 return assosiateElementToData.right().value();
487 return StorageOperationStatus.OK;
490 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
491 if (!MapUtils.isEmpty(calcRequirements)) {
492 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
493 if (assosiateElementToData.isRight()) {
494 return assosiateElementToData.right().value();
496 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
497 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
498 if (assosiateElementToData.isRight()) {
499 return assosiateElementToData.right().value();
502 if (!MapUtils.isEmpty(calcCapabilty)) {
503 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
504 if (assosiateElementToData.isRight()) {
505 return assosiateElementToData.right().value();
507 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
508 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
509 if (assosiateElementToData.isRight()) {
510 return assosiateElementToData.right().value();
513 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
514 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
515 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
517 .on(v -> StorageOperationStatus.OK);
519 return StorageOperationStatus.OK;
522 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
523 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
524 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
525 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
528 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
529 if (status == JanusGraphOperationStatus.NOT_FOUND) {
530 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
532 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
535 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
536 Optional<StorageOperationStatus> error = dataMap.entrySet()
538 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
539 .filter(s -> s != StorageOperationStatus.OK)
541 if(error.isPresent()){
542 return Either.right(error.get());
544 return Either.left(dataVertex);
547 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
548 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
549 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
552 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
553 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
554 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
555 if (assosiateElementToData.isRight()) {
556 return assosiateElementToData.right().value();
559 return StorageOperationStatus.OK;
562 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
563 if (instAttr != null && !instAttr.isEmpty()) {
564 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
565 if (assosiateElementToData.isRight()) {
566 return assosiateElementToData.right().value();
569 return StorageOperationStatus.OK;
572 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
574 if (groups != null && !groups.isEmpty()) {
575 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
576 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
579 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
580 if (assosiateElementToData.isRight()) {
581 return assosiateElementToData.right().value();
584 return StorageOperationStatus.OK;
587 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
588 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
591 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
592 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
593 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
596 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
597 if (inputs != null && !inputs.isEmpty()) {
598 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
600 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
601 if (assosiateElementToData.isRight()) {
602 return assosiateElementToData.right().value();
605 return StorageOperationStatus.OK;
608 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
609 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
610 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
611 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
612 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
614 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
615 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
617 return nodeTypeVertex;
621 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
622 if (topologyTemplate.getResourceType() == null) {
624 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
627 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
631 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
632 String categoryName = topologyTemplate.getCategories().get(0).getName();
633 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
634 if (category.isRight()) {
635 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
636 return StorageOperationStatus.CATEGORY_NOT_FOUND;
638 GraphVertex categoryV = category.left().value();
639 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
640 if (createEdge != JanusGraphOperationStatus.OK) {
641 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
642 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
644 return StorageOperationStatus.OK;
648 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
649 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
651 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
652 if (componentByLabelAndId.isRight()) {
653 return Either.right(componentByLabelAndId.right().value());
655 GraphVertex componentV = componentByLabelAndId.left().value();
657 return getToscaElement(componentV, componentParametersView);
660 // -------------------------------------------------------------
662 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
663 TopologyTemplate toscaElement;
665 toscaElement = convertToTopologyTemplate(componentV);
666 JanusGraphOperationStatus status;
667 if (!componentParametersView.isIgnoreUsers()) {
668 status = setCreatorFromGraph(componentV, toscaElement);
669 if (status != JanusGraphOperationStatus.OK) {
670 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
673 status = setLastModifierFromGraph(componentV, toscaElement);
674 if (status != JanusGraphOperationStatus.OK) {
675 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
678 if (!componentParametersView.isIgnoreCategories()) {
679 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
680 if (status != JanusGraphOperationStatus.OK) {
681 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
685 if (!componentParametersView.isIgnoreArtifacts()) {
686 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
687 if (storageStatus != JanusGraphOperationStatus.OK) {
688 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
691 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
692 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
693 if (status != JanusGraphOperationStatus.OK) {
694 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
697 if (!componentParametersView.isIgnoreCapabilities()) {
698 status = setCapabilitiesFromGraph(componentV, toscaElement);
699 if (status != JanusGraphOperationStatus.OK) {
700 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
703 if (!componentParametersView.isIgnoreRequirements()) {
704 status = setRequirementsFromGraph(componentV, toscaElement);
705 if (status != JanusGraphOperationStatus.OK) {
706 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
709 if (!componentParametersView.isIgnoreAllVersions()) {
710 status = setAllVersions(componentV, toscaElement);
711 if (status != JanusGraphOperationStatus.OK) {
712 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
715 if (!componentParametersView.isIgnoreAdditionalInformation()) {
716 status = setAdditionalInformationFromGraph(componentV, toscaElement);
717 if (status != JanusGraphOperationStatus.OK) {
718 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
722 if (!componentParametersView.isIgnoreGroups()) {
723 status = setGroupsFromGraph(componentV, toscaElement);
724 if (status != JanusGraphOperationStatus.OK) {
725 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
729 if (!componentParametersView.isIgnorePolicies()) {
730 status = setPoliciesFromGraph(componentV, toscaElement);
731 if (status != JanusGraphOperationStatus.OK) {
732 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
736 if (!componentParametersView.isIgnoreComponentInstances()) {
737 status = setInstGroupsFromGraph(componentV, toscaElement);
739 //Mark all CIs that has archived origins
740 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
742 if (status != JanusGraphOperationStatus.OK) {
743 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
747 if (!componentParametersView.isIgnoreInputs()) {
748 status = setInputsFromGraph(componentV, toscaElement);
749 if (status != JanusGraphOperationStatus.OK) {
750 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
754 if (!componentParametersView.isIgnoreProperties()) {
755 status = setPropertiesFromGraph(componentV, toscaElement);
756 if (status != JanusGraphOperationStatus.OK) {
757 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
762 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
763 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
764 if (status != JanusGraphOperationStatus.OK) {
765 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
770 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
771 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
772 if (status != JanusGraphOperationStatus.OK) {
773 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
778 if (!componentParametersView.isIgnoreForwardingPath()) {
779 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
780 if (status != JanusGraphOperationStatus.OK) {
781 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
786 if (!componentParametersView.isIgnoreNodeFilter()) {
787 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
788 if (status != JanusGraphOperationStatus.OK) {
789 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
794 if (!componentParametersView.isIgnoreInterfaces()) {
795 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
796 if (storageStatus != JanusGraphOperationStatus.OK) {
797 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
802 if (!componentParametersView.isIgnoreInterfaces()) {
803 JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
804 if (storageStatus != JanusGraphOperationStatus.OK) {
805 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
810 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
811 JanusGraphOperationStatus storageStatus =
812 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
813 if (storageStatus != JanusGraphOperationStatus.OK) {
814 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
818 if (!componentParametersView.isIgnoreDataType()) {
819 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
820 if (storageStatus != JanusGraphOperationStatus.OK) {
821 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
825 return Either.left(toscaElement);
828 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
829 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
830 if (result.isLeft()) {
831 toscaElement.setDataTypes(result.left().value());
833 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
834 return result.right().value();
837 return JanusGraphOperationStatus.OK;
840 private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
841 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
842 if (result.isLeft()) {
843 topologyTemplate.setInterfaces(result.left().value());
845 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
846 return result.right().value();
849 return JanusGraphOperationStatus.OK;
852 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
853 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
854 if (result.isLeft()) {
855 toscaElement.setPolicies(result.left().value());
857 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
858 return result.right().value();
861 return JanusGraphOperationStatus.OK;
864 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
865 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
866 if (result.isLeft()) {
867 topologyTemplate.setInterfaces(result.left().value());
869 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
870 return result.right().value();
873 return JanusGraphOperationStatus.OK;
877 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
878 TopologyTemplate topologyTemplate) {
879 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
880 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
881 if (result.isLeft()) {
882 result.left().value().entrySet().forEach(entry -> topologyTemplate
883 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
885 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
886 return result.right().value();
889 return JanusGraphOperationStatus.OK;
892 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
893 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
894 if (interfaceMap != null && !interfaceMap.isEmpty()) {
895 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
896 if (assosiateElementToData.isRight()) {
897 return assosiateElementToData.right().value();
900 return StorageOperationStatus.OK;
903 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
904 Map<String, CINodeFilterDataDefinition> filterMaps) {
905 if (filterMaps != null && !filterMaps.isEmpty()) {
906 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
907 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
908 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
909 if (assosiateElementToData.isRight()) {
910 return assosiateElementToData.right().value();
913 return StorageOperationStatus.OK;
916 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
917 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
918 if (result.isLeft()) {
919 topologyTemplate.setForwardingPaths(result.left().value());
921 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
922 return result.right().value();
925 return JanusGraphOperationStatus.OK;
929 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
930 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
931 if (result.isLeft()) {
932 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
934 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
935 return result.right().value();
938 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
939 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
940 if (capPropResult.isLeft()) {
941 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
943 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
944 return capPropResult.right().value();
948 return JanusGraphOperationStatus.OK;
951 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
952 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
953 if (result.isLeft()) {
954 toscaElement.setProperties(result.left().value());
956 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
957 return result.right().value();
960 return JanusGraphOperationStatus.OK;
963 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
964 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
965 if (result.isLeft()) {
966 topologyTemplate.setInstGroups(result.left().value());
968 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
969 return result.right().value();
972 return JanusGraphOperationStatus.OK;
975 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
976 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
977 if (result.isLeft()) {
978 topologyTemplate.setInstProperties(result.left().value());
980 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
981 return result.right().value();
984 return JanusGraphOperationStatus.OK;
987 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
988 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
989 if (result.isLeft()) {
990 topologyTemplate.setInstInputs(result.left().value());
992 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
993 return result.right().value();
996 return JanusGraphOperationStatus.OK;
999 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV,
1000 TopologyTemplate topologyTemplate) {
1001 Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
1002 getDataFromGraph(componentV,
1003 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
1004 if (result.isLeft()) {
1005 topologyTemplate.setNodeFilterComponents(result.left().value());
1007 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1008 return result.right().value();
1011 return JanusGraphOperationStatus.OK;
1015 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1016 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1017 if (result.isLeft()) {
1018 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1020 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1021 return result.right().value();
1024 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1025 if (result.isLeft()) {
1026 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1028 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1029 return result.right().value();
1032 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
1033 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
1034 if (requirementResult.isLeft()) {
1035 toscaElement.setRequirements(requirementResult.left().value());
1037 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1038 return requirementResult.right().value();
1041 return JanusGraphOperationStatus.OK;
1045 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1046 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1047 if (result.isLeft()) {
1048 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1050 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1051 return result.right().value();
1054 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1055 if (result.isLeft()) {
1056 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1058 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1059 return result.right().value();
1062 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1063 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1064 if (capabilitiesResult.isLeft()) {
1065 toscaElement.setCapabilities(capabilitiesResult.left().value());
1067 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1068 return capabilitiesResult.right().value();
1071 return JanusGraphOperationStatus.OK;
1074 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1075 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1076 if (storageStatus != JanusGraphOperationStatus.OK) {
1077 return storageStatus;
1079 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1080 if (result.isLeft()) {
1081 toscaElement.setServiceApiArtifacts(result.left().value());
1083 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1084 return result.right().value();
1087 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1088 if (resultInstArt.isLeft()) {
1089 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1091 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1092 return resultInstArt.right().value();
1095 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1096 if (instanceArt.isLeft()) {
1097 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1099 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1100 return instanceArt.right().value();
1103 return JanusGraphOperationStatus.OK;
1106 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1107 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1108 if (result.isLeft()) {
1109 toscaElement.setInputs(result.left().value());
1111 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1112 return result.right().value();
1115 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1116 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1117 if (capabilitiesResult.isLeft()) {
1118 toscaElement.setCapabilities(capabilitiesResult.left().value());
1120 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1121 return capabilitiesResult.right().value();
1124 return JanusGraphOperationStatus.OK;
1127 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1128 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1129 if (result.isLeft()) {
1130 toscaElement.setGroups(result.left().value());
1132 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1133 return result.right().value();
1136 return JanusGraphOperationStatus.OK;
1139 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1140 List<CategoryDefinition> categories = new ArrayList<>();
1142 switch (componentV.getType()) {
1144 return setResourceCategoryFromGraph(componentV, toscaElement);
1146 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1149 log.debug("Not supported component type {} ", componentV.getType());
1152 return JanusGraphOperationStatus.OK;
1155 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1156 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1157 if (childVertex.isRight()) {
1158 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1159 return childVertex.right().value();
1161 GraphVertex categoryV = childVertex.left().value();
1162 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1163 CategoryDefinition category = new CategoryDefinition();
1164 category.setUniqueId(categoryV.getUniqueId());
1165 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1166 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1168 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
1169 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1170 category.setIcons(iconsfromJsonCat);
1171 categories.add(category);
1172 toscaElement.setCategories(categories);
1174 return JanusGraphOperationStatus.OK;
1177 @SuppressWarnings("unchecked")
1178 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1180 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1182 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1183 topologyTemplate.setCompositions(json);
1185 return topologyTemplate;
1189 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1190 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1191 if (nodeType.isRight()) {
1192 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1195 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1196 if (status != JanusGraphOperationStatus.OK) {
1197 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1199 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1200 if (status != JanusGraphOperationStatus.OK) {
1201 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1202 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1204 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1205 if (status != JanusGraphOperationStatus.OK) {
1206 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1207 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1210 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1211 if (status != JanusGraphOperationStatus.OK) {
1212 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1213 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1216 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1217 if (status != JanusGraphOperationStatus.OK) {
1218 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1219 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1221 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1222 if (status != JanusGraphOperationStatus.OK) {
1223 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1224 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1226 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1227 if (status != JanusGraphOperationStatus.OK) {
1228 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1229 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1231 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1232 if (status != JanusGraphOperationStatus.OK) {
1233 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1234 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1236 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1237 if (status != JanusGraphOperationStatus.OK) {
1238 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1239 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1241 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1242 if (status != JanusGraphOperationStatus.OK) {
1243 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1244 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1246 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1247 if (status != JanusGraphOperationStatus.OK) {
1248 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1249 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1251 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1252 if (status != JanusGraphOperationStatus.OK) {
1253 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1254 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1256 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1257 if (status != JanusGraphOperationStatus.OK) {
1258 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1259 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1261 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1262 if (status != JanusGraphOperationStatus.OK) {
1263 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1264 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1266 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1267 if (status != JanusGraphOperationStatus.OK) {
1268 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1269 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1271 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1272 if (status != JanusGraphOperationStatus.OK) {
1273 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1274 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1276 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1277 if (status != JanusGraphOperationStatus.OK) {
1278 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1279 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1281 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1282 if (status != JanusGraphOperationStatus.OK) {
1283 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1284 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1286 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1287 if (status != JanusGraphOperationStatus.OK) {
1288 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1289 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1291 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1292 if (status != JanusGraphOperationStatus.OK) {
1293 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1294 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1297 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1298 EdgeLabelEnum.REQUIREMENTS);
1299 if (status != JanusGraphOperationStatus.OK) {
1300 log.debug("Failed to disassociate requirements for {} error {}",
1301 toscaElementVertex.getUniqueId(), status);
1302 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1304 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1305 EdgeLabelEnum.CAPABILITIES);
1306 if (status != JanusGraphOperationStatus.OK) {
1307 log.debug("Failed to disassociate capabilities for {} error {}",
1308 toscaElementVertex.getUniqueId(), status);
1309 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1311 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1312 if (status != JanusGraphOperationStatus.OK) {
1313 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1314 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1316 toscaElementVertex.getVertex().remove();
1317 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1322 @SuppressWarnings("unchecked")
1324 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1325 return createTopologyTemplate((TopologyTemplate) toscaElement);
1329 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1330 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1334 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1335 // Product isn't supported now!!
1336 // TODO add for Product
1337 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1338 return validateServiceCategory(toscaElementToUpdate, elementV);
1341 return validateResourceCategory(toscaElementToUpdate, elementV);
1346 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1347 // not relevant now for topology template
1348 return StorageOperationStatus.OK;
1352 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1353 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1356 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1357 StorageOperationStatus status = StorageOperationStatus.OK;
1358 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1359 CategoryDefinition newCategory = newCategoryList.get(0);
1361 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1362 if (childVertex.isRight()) {
1363 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1364 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1367 GraphVertex categoryV = childVertex.left().value();
1368 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1369 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1371 String newCategoryName = newCategory.getName();
1372 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1373 // the category was changed
1374 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1376 if (getCategoryVertex.isRight()) {
1377 return getCategoryVertex.right().value();
1379 GraphVertex newCategoryV = getCategoryVertex.left().value();
1380 status = moveCategoryEdge(elementV, newCategoryV);
1381 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1386 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1388 Either<GraphVertex, StorageOperationStatus> result = null;
1389 String userId = user.getUserId();
1390 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1391 GraphVertex userVertex = null;
1392 GraphVertex serviceVertex = null;
1393 if (getRes.isRight()) {
1394 JanusGraphOperationStatus status = getRes.right().value();
1395 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1396 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1398 if (result == null) {
1399 userVertex = getRes.left().value();
1400 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1401 if (getRes.isRight()) {
1402 JanusGraphOperationStatus status = getRes.right().value();
1403 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
1404 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1407 if (result == null) {
1408 serviceVertex = getRes.left().value();
1409 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1410 if (edgeIterator.hasNext()) {
1411 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1412 edgeIterator.next().remove();
1415 if (result == null) {
1416 JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1417 if (status != JanusGraphOperationStatus.OK) {
1418 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1419 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1422 if (result == null) {
1423 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1424 long lastUpdateDate = System.currentTimeMillis();
1425 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1426 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1427 if (updateRes.isRight()) {
1428 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1431 if (result == null) {
1432 result = Either.left(serviceVertex);
1437 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1438 * @param componentId
1440 * @param capabilityName
1441 * @param capabilityType
1445 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1447 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1448 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1449 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1450 if (componentByLabelAndId.isRight()) {
1451 result = Either.right(componentByLabelAndId.right().value());
1453 if(componentByLabelAndId.isLeft()){
1454 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1455 if (getDataRes.isRight()) {
1456 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1458 mapPropertiesDataDefinition = getDataRes.left().value();
1461 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1462 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1467 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1468 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1471 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1472 String componentInstanceId,
1473 MapInterfaceDataDefinition instanceInterfaces) {
1474 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1475 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1476 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1478 return StorageOperationStatus.OK;
1482 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1483 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1484 instanceId != null &&
1485 mapPropertiesDataDefinition.get(instanceId) != null &&
1486 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1489 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1490 List<ComponentInstanceProperty> capPropsList = null;
1491 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1492 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1493 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1494 if (capMap != null && !capMap.isEmpty()) {
1495 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1500 if(capPropsList == null){
1501 capPropsList = new ArrayList<>();
1503 return capPropsList;
1506 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1507 if (capProp != null) {
1508 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1509 if (path.length < 4) {
1510 log.debug("wrong key format for capabilty, key {}", capProp);
1513 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1518 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1519 fillPolicyDefinition(componentV, policyDefinition, counter);
1520 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1523 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1524 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1527 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1528 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1531 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1532 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1535 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1536 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1539 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1540 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
1543 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1544 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1545 policyDefinition.setName(policyName);
1546 policyDefinition.setInvariantName(policyName);
1547 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1548 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1549 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1550 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1553 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1554 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1555 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1556 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1559 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1560 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1561 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1563 .on(this::throwStorageException);
1564 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1565 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1567 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1568 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1570 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1571 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1572 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1576 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1577 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1578 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1580 .on(this::throwStorageException);
1581 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1582 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1584 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1585 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1587 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1588 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1589 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1593 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1594 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1595 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1596 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1597 if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
1598 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1601 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1603 if(getOriginRes.isRight()){
1604 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1605 throw new StorageException(getOriginRes.right().value());
1607 return getOriginRes.left().value();
1610 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1611 log.debug("#detectToscaType - type: {}", originType);
1612 if(originType == OriginTypeEnum.VFC
1613 || originType == OriginTypeEnum.CP
1614 || originType == OriginTypeEnum.VL
1615 || originType == OriginTypeEnum.Configuration
1616 || originType == OriginTypeEnum.VFCMT){
1617 return ToscaElementTypeEnum.NODE_TYPE;
1619 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1623 private ComponentParametersView getFilter() {
1624 ComponentParametersView filter = new ComponentParametersView();
1625 filter.setIgnoreCapabilities(false);
1626 filter.setIgnoreCapabiltyProperties(false);
1627 filter.setIgnoreRequirements(false);
1630 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1631 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1632 .left().on(this::throwStorageException);
1633 updateCapOwnerId(toscaElement, componentId);
1634 updateReqOwnerId(toscaElement, componentId);
1635 updatePropertiesOwnerId(toscaElement, componentId);
1636 topologyTemplateOperation
1638 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1639 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1640 topologyTemplateOperation
1641 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1642 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1643 topologyTemplateOperation
1644 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1645 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1648 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1649 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1650 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1651 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1655 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1656 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1657 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1658 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1662 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1663 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1664 if(MapUtils.isNotEmpty(properties)) {
1665 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));