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 org.apache.commons.collections.MapUtils;
35 import org.apache.tinkerpop.gremlin.structure.Direction;
36 import org.apache.tinkerpop.gremlin.structure.Edge;
37 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
38 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
39 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
40 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
41 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
42 import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
45 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
58 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
59 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
63 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
64 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
65 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
66 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
67 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
68 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
69 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
70 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
71 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
72 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
73 import org.openecomp.sdc.be.model.Component;
74 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
75 import org.openecomp.sdc.be.model.ComponentParametersView;
76 import org.openecomp.sdc.be.model.DistributionStatusEnum;
77 import org.openecomp.sdc.be.model.GroupDefinition;
78 import org.openecomp.sdc.be.model.PolicyDefinition;
79 import org.openecomp.sdc.be.model.User;
80 import org.openecomp.sdc.be.model.category.CategoryDefinition;
81 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
82 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
83 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
84 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
85 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
86 import org.openecomp.sdc.be.model.operations.StorageException;
87 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
88 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
89 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
90 import org.openecomp.sdc.common.api.Constants;
91 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
92 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
93 import org.openecomp.sdc.common.log.wrappers.Logger;
94 import org.openecomp.sdc.common.util.ValidationUtils;
95 import org.springframework.beans.factory.annotation.Autowired;
98 @org.springframework.stereotype.Component("topology-template-operation")
99 public class TopologyTemplateOperation extends ToscaElementOperation {
101 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
102 private static final String PATH_DELIMITER = ".";
105 private ArchiveOperation archiveOperation;
107 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
108 Either<TopologyTemplate, StorageOperationStatus> result = null;
110 topologyTemplate.generateUUID();
112 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
113 String resourceUniqueId = topologyTemplate.getUniqueId();
114 if (resourceUniqueId == null) {
115 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
116 topologyTemplate.setUniqueId(resourceUniqueId);
119 GraphVertex topologyTemplateVertex = new GraphVertex();
120 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
122 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
123 if (createdVertex.isRight()) {
124 JanusGraphOperationStatus status = createdVertex.right().value();
125 log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
126 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
130 topologyTemplateVertex = createdVertex.left().value();
132 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
133 if (assosiateCommon != StorageOperationStatus.OK) {
134 result = Either.right(assosiateCommon);
138 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
139 if (associateCategory != StorageOperationStatus.OK) {
140 result = Either.right(associateCategory);
144 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
145 if (associateInputs != StorageOperationStatus.OK) {
146 result = Either.right(associateInputs);
149 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
150 if (associateGroups != StorageOperationStatus.OK) {
151 result = Either.right(associateGroups);
154 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
155 if (associatePolicies != StorageOperationStatus.OK) {
156 result = Either.right(associatePolicies);
159 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
160 if (associateInstAttr != StorageOperationStatus.OK) {
161 result = Either.right(associateInstAttr);
164 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
165 if (associateInstProperties != StorageOperationStatus.OK) {
166 result = Either.right(associateInstProperties);
169 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
170 if (associateInstProperties != StorageOperationStatus.OK) {
171 result = Either.right(associateInstInputs);
174 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
175 if (associateInstGroups != StorageOperationStatus.OK) {
176 result = Either.right(associateInstInputs);
180 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
181 if (associateRequirements != StorageOperationStatus.OK) {
182 result = Either.right(associateRequirements);
186 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
187 if (associateCapabilities != StorageOperationStatus.OK) {
188 result = Either.right(associateCapabilities);
192 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
193 if (associateArtifacts != StorageOperationStatus.OK) {
194 result = Either.right(associateArtifacts);
198 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
199 if (addAdditionalInformation != StorageOperationStatus.OK) {
200 result = Either.right(addAdditionalInformation);
203 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
204 if (associateCapProperties != StorageOperationStatus.OK) {
205 result = Either.right(associateCapProperties);
209 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
210 if (associateInterfaces != StorageOperationStatus.OK) {
211 result = Either.right(associateInterfaces);
215 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
216 if (associateCapProperties != StorageOperationStatus.OK) {
217 result = Either.right(associatePathProperties);
222 return Either.left(topologyTemplate);
226 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
227 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
230 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
231 if (policies != null && !policies.isEmpty()) {
232 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
233 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
236 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
237 if (assosiateElementToData.isRight()) {
238 return assosiateElementToData.right().value();
241 return StorageOperationStatus.OK;
244 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
245 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
246 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
249 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
250 TopologyTemplate topologyTemplate) {
251 Map<String, CINodeFilterDataDefinition> nodeFilters =
252 topologyTemplate.getNodeFilterComponents();
253 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
256 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
257 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
258 .getCalculatedCapabilitiesProperties();
259 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
260 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
261 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
262 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
263 if (associateElementToData.isRight()) {
264 return associateElementToData.right().value();
268 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
269 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
270 Either<GraphVertex, StorageOperationStatus> associateElementToData =
271 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
272 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
273 if (associateElementToData.isRight()) {
274 return associateElementToData.right().value();
277 return StorageOperationStatus.OK;
280 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
281 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
282 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
283 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
284 if (assosiateElementToData.isRight()) {
285 return assosiateElementToData.right().value();
288 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
289 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
290 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
291 if (assosiateElementToData.isRight()) {
292 return assosiateElementToData.right().value();
295 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
296 if(MapUtils.isNotEmpty(capabilities)) {
297 Either<GraphVertex, StorageOperationStatus> associateElementToData =
298 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
299 EdgeLabelEnum.CAPABILITIES, capabilities);
300 if (associateElementToData.isRight()) {
301 return associateElementToData.right().value();
304 return StorageOperationStatus.OK;
308 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
309 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
310 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
311 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
312 if (assosiateElementToData.isRight()) {
313 return assosiateElementToData.right().value();
316 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
317 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
318 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
319 if (assosiateElementToData.isRight()) {
320 return assosiateElementToData.right().value();
323 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
324 if(MapUtils.isNotEmpty(requirements)) {
325 Either<GraphVertex, StorageOperationStatus> associateElementToData =
326 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
327 EdgeLabelEnum.REQUIREMENTS, requirements);
328 if (associateElementToData.isRight()) {
329 return associateElementToData.right().value();
332 return StorageOperationStatus.OK;
335 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
336 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
338 if (addInformation != null && !addInformation.isEmpty()) {
339 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
340 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
341 a.setUniqueId(uniqueId);
343 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
344 if (assosiateElementToData.isRight()) {
345 return assosiateElementToData.right().value();
348 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
350 if (instArtifacts != null && !instArtifacts.isEmpty()) {
351 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
352 if (assosiateElementToData.isRight()) {
353 return assosiateElementToData.right().value();
356 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
358 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
359 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
360 if (assosiateElementToData.isRight()) {
361 return assosiateElementToData.right().value();
364 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
365 if(MapUtils.isNotEmpty(requirements)) {
366 Either<GraphVertex, StorageOperationStatus> associateElementToData =
367 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
368 EdgeLabelEnum.REQUIREMENTS, requirements);
369 if (associateElementToData.isRight()) {
370 return associateElementToData.right().value();
373 return StorageOperationStatus.OK;
376 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
378 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
380 if (addInformation != null && !addInformation.isEmpty()) {
381 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
382 if (assosiateElementToData.isRight()) {
383 return assosiateElementToData.right().value();
386 return StorageOperationStatus.OK;
389 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
390 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
391 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
394 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
395 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
396 return associateInstInputsToComponent(nodeTypeVertex, instProps);
399 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
400 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
401 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
405 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
406 if (instProps != null && !instProps.isEmpty()) {
407 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
408 if (assosiateElementToData.isRight()) {
409 return assosiateElementToData.right().value();
412 return StorageOperationStatus.OK;
415 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
416 if (instInputs != null && !instInputs.isEmpty()) {
417 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
418 if (assosiateElementToData.isRight()) {
419 return assosiateElementToData.right().value();
422 return StorageOperationStatus.OK;
425 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
426 if (instGroups != null && !instGroups.isEmpty()) {
427 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
428 if (assosiateElementToData.isRight()) {
429 return assosiateElementToData.right().value();
432 return StorageOperationStatus.OK;
436 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
438 if (instInputs != null && !instInputs.isEmpty()) {
439 instInputs.entrySet().forEach(i -> {
440 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
441 List<String> pathKeys = new ArrayList<>();
442 pathKeys.add(i.getKey());
444 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
445 if (status != StorageOperationStatus.OK) {
451 return StorageOperationStatus.OK;
454 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
456 if (instInputs != null && !instInputs.isEmpty()) {
457 instInputs.entrySet().forEach(i -> {
458 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
459 if (status != StorageOperationStatus.OK) {
465 return StorageOperationStatus.OK;
468 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
469 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
472 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
473 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
476 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
477 if (instProps != null && !instProps.isEmpty()) {
478 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
479 if (assosiateElementToData.isRight()) {
480 return assosiateElementToData.right().value();
483 return StorageOperationStatus.OK;
486 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
487 if (!MapUtils.isEmpty(calcRequirements)) {
488 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
489 if (assosiateElementToData.isRight()) {
490 return assosiateElementToData.right().value();
492 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
493 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
494 if (assosiateElementToData.isRight()) {
495 return assosiateElementToData.right().value();
498 if (!MapUtils.isEmpty(calcCapabilty)) {
499 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
500 if (assosiateElementToData.isRight()) {
501 return assosiateElementToData.right().value();
503 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
504 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
505 if (assosiateElementToData.isRight()) {
506 return assosiateElementToData.right().value();
509 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
510 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
511 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
513 .on(v -> StorageOperationStatus.OK);
515 return StorageOperationStatus.OK;
518 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
519 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
520 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
521 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
524 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
525 if (status == JanusGraphOperationStatus.NOT_FOUND) {
526 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
528 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
531 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
532 Optional<StorageOperationStatus> error = dataMap.entrySet()
534 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
535 .filter(s -> s != StorageOperationStatus.OK)
537 if(error.isPresent()){
538 return Either.right(error.get());
540 return Either.left(dataVertex);
543 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
544 Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
545 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
548 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
549 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
550 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
551 if (assosiateElementToData.isRight()) {
552 return assosiateElementToData.right().value();
555 return StorageOperationStatus.OK;
558 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
559 if (instAttr != null && !instAttr.isEmpty()) {
560 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
561 if (assosiateElementToData.isRight()) {
562 return assosiateElementToData.right().value();
565 return StorageOperationStatus.OK;
568 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
570 if (groups != null && !groups.isEmpty()) {
571 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
572 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
575 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
576 if (assosiateElementToData.isRight()) {
577 return assosiateElementToData.right().value();
580 return StorageOperationStatus.OK;
583 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
584 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
587 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
588 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
589 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
592 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
593 if (inputs != null && !inputs.isEmpty()) {
594 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
596 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
597 if (assosiateElementToData.isRight()) {
598 return assosiateElementToData.right().value();
601 return StorageOperationStatus.OK;
604 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
605 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
606 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
607 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
608 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
610 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
611 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
613 return nodeTypeVertex;
617 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
618 if (topologyTemplate.getResourceType() == null) {
620 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
623 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
627 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
628 String categoryName = topologyTemplate.getCategories().get(0).getName();
629 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
630 if (category.isRight()) {
631 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
632 return StorageOperationStatus.CATEGORY_NOT_FOUND;
634 GraphVertex categoryV = category.left().value();
635 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
636 if (createEdge != JanusGraphOperationStatus.OK) {
637 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
638 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
640 return StorageOperationStatus.OK;
644 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
645 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
647 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
648 if (componentByLabelAndId.isRight()) {
649 return Either.right(componentByLabelAndId.right().value());
651 GraphVertex componentV = componentByLabelAndId.left().value();
653 return getToscaElement(componentV, componentParametersView);
656 // -------------------------------------------------------------
658 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
659 TopologyTemplate toscaElement;
661 toscaElement = convertToTopologyTemplate(componentV);
662 JanusGraphOperationStatus status;
663 if (!componentParametersView.isIgnoreUsers()) {
664 status = setCreatorFromGraph(componentV, toscaElement);
665 if (status != JanusGraphOperationStatus.OK) {
666 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
669 status = setLastModifierFromGraph(componentV, toscaElement);
670 if (status != JanusGraphOperationStatus.OK) {
671 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
674 if (!componentParametersView.isIgnoreCategories()) {
675 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
676 if (status != JanusGraphOperationStatus.OK) {
677 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
681 if (!componentParametersView.isIgnoreArtifacts()) {
682 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
683 if (storageStatus != JanusGraphOperationStatus.OK) {
684 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
687 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
688 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
689 if (status != JanusGraphOperationStatus.OK) {
690 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
693 if (!componentParametersView.isIgnoreCapabilities()) {
694 status = setCapabilitiesFromGraph(componentV, toscaElement);
695 if (status != JanusGraphOperationStatus.OK) {
696 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
699 if (!componentParametersView.isIgnoreRequirements()) {
700 status = setRequirementsFromGraph(componentV, toscaElement);
701 if (status != JanusGraphOperationStatus.OK) {
702 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
705 if (!componentParametersView.isIgnoreAllVersions()) {
706 status = setAllVersions(componentV, toscaElement);
707 if (status != JanusGraphOperationStatus.OK) {
708 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
711 if (!componentParametersView.isIgnoreAdditionalInformation()) {
712 status = setAdditionalInformationFromGraph(componentV, toscaElement);
713 if (status != JanusGraphOperationStatus.OK) {
714 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
718 if (!componentParametersView.isIgnoreGroups()) {
719 status = setGroupsFromGraph(componentV, toscaElement);
720 if (status != JanusGraphOperationStatus.OK) {
721 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
725 if (!componentParametersView.isIgnorePolicies()) {
726 status = setPoliciesFromGraph(componentV, toscaElement);
727 if (status != JanusGraphOperationStatus.OK) {
728 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
732 if (!componentParametersView.isIgnoreComponentInstances()) {
733 status = setInstGroupsFromGraph(componentV, toscaElement);
735 //Mark all CIs that has archived origins
736 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
738 if (status != JanusGraphOperationStatus.OK) {
739 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
743 if (!componentParametersView.isIgnoreInputs()) {
744 status = setInputsFromGraph(componentV, toscaElement);
745 if (status != JanusGraphOperationStatus.OK) {
746 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
750 if (!componentParametersView.isIgnoreProperties()) {
751 status = setPropertiesFromGraph(componentV, toscaElement);
752 if (status != JanusGraphOperationStatus.OK) {
753 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
758 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
759 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
760 if (status != JanusGraphOperationStatus.OK) {
761 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
766 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
767 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
768 if (status != JanusGraphOperationStatus.OK) {
769 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
774 if (!componentParametersView.isIgnoreForwardingPath()) {
775 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
776 if (status != JanusGraphOperationStatus.OK) {
777 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
782 if (!componentParametersView.isIgnoreNodeFilter()) {
783 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
784 if (status != JanusGraphOperationStatus.OK) {
785 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
790 if (!componentParametersView.isIgnoreSubstitutionFilter()) {
791 status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
792 if (status != JanusGraphOperationStatus.OK) {
793 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
798 if (!componentParametersView.isIgnoreInterfaces()) {
799 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
800 if (storageStatus != JanusGraphOperationStatus.OK) {
801 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
806 if (!componentParametersView.isIgnoreInterfaces()) {
807 JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
808 if (storageStatus != JanusGraphOperationStatus.OK) {
809 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
814 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
815 JanusGraphOperationStatus storageStatus =
816 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
817 if (storageStatus != JanusGraphOperationStatus.OK) {
818 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
822 if (!componentParametersView.isIgnoreDataType()) {
823 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
824 if (storageStatus != JanusGraphOperationStatus.OK) {
825 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
829 return Either.left(toscaElement);
832 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
833 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
834 if (result.isLeft()) {
835 toscaElement.setDataTypes(result.left().value());
837 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
838 return result.right().value();
841 return JanusGraphOperationStatus.OK;
844 private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
845 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
846 if (result.isLeft()) {
847 topologyTemplate.setInterfaces(result.left().value());
849 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
850 return result.right().value();
853 return JanusGraphOperationStatus.OK;
856 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
857 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
858 if (result.isLeft()) {
859 toscaElement.setPolicies(result.left().value());
861 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
862 return result.right().value();
865 return JanusGraphOperationStatus.OK;
868 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
869 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
870 if (result.isLeft()) {
871 topologyTemplate.setInterfaces(result.left().value());
873 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
874 return result.right().value();
877 return JanusGraphOperationStatus.OK;
881 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
882 TopologyTemplate topologyTemplate) {
883 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
884 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
885 if (result.isLeft()) {
886 result.left().value().entrySet().forEach(entry -> topologyTemplate
887 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
889 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
890 return result.right().value();
893 return JanusGraphOperationStatus.OK;
896 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
897 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
898 if (interfaceMap != null && !interfaceMap.isEmpty()) {
899 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
900 if (assosiateElementToData.isRight()) {
901 return assosiateElementToData.right().value();
904 return StorageOperationStatus.OK;
907 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
908 Map<String, CINodeFilterDataDefinition> filterMaps) {
909 if (filterMaps != null && !filterMaps.isEmpty()) {
910 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
911 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
912 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
913 if (assosiateElementToData.isRight()) {
914 return assosiateElementToData.right().value();
917 return StorageOperationStatus.OK;
920 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
921 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
922 if (result.isLeft()) {
923 topologyTemplate.setForwardingPaths(result.left().value());
925 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
926 return result.right().value();
929 return JanusGraphOperationStatus.OK;
933 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
934 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
935 if (result.isLeft()) {
936 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
938 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
939 return result.right().value();
942 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
943 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
944 if (capPropResult.isLeft()) {
945 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
947 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
948 return capPropResult.right().value();
952 return JanusGraphOperationStatus.OK;
955 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
956 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
957 if (result.isLeft()) {
958 toscaElement.setProperties(result.left().value());
960 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
961 return result.right().value();
964 return JanusGraphOperationStatus.OK;
967 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
968 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
969 if (result.isLeft()) {
970 topologyTemplate.setInstGroups(result.left().value());
972 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
973 return result.right().value();
976 return JanusGraphOperationStatus.OK;
979 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
980 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
981 if (result.isLeft()) {
982 topologyTemplate.setInstProperties(result.left().value());
984 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
985 return result.right().value();
988 return JanusGraphOperationStatus.OK;
991 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
992 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
993 if (result.isLeft()) {
994 topologyTemplate.setInstInputs(result.left().value());
996 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
997 return result.right().value();
1000 return JanusGraphOperationStatus.OK;
1003 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
1004 final TopologyTemplate topologyTemplate) {
1006 final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
1007 getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
1008 if (result.isLeft()) {
1009 topologyTemplate.setNodeFilterComponents(result.left().value());
1011 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1012 return result.right().value();
1015 return JanusGraphOperationStatus.OK;
1018 private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
1019 final TopologyTemplate topologyTemplate) {
1021 final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
1022 getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
1023 if (result.isLeft()) {
1024 topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
1026 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1027 return result.right().value();
1030 return JanusGraphOperationStatus.OK;
1035 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1036 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1037 if (result.isLeft()) {
1038 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1040 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1041 return result.right().value();
1044 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1045 if (result.isLeft()) {
1046 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1048 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1049 return result.right().value();
1052 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
1053 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
1054 if (requirementResult.isLeft()) {
1055 toscaElement.setRequirements(requirementResult.left().value());
1057 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1058 return requirementResult.right().value();
1061 return JanusGraphOperationStatus.OK;
1065 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1066 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1067 if (result.isLeft()) {
1068 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1070 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1071 return result.right().value();
1074 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1075 if (result.isLeft()) {
1076 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1078 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1079 return result.right().value();
1082 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1083 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1084 if (capabilitiesResult.isLeft()) {
1085 toscaElement.setCapabilities(capabilitiesResult.left().value());
1087 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1088 return capabilitiesResult.right().value();
1091 return JanusGraphOperationStatus.OK;
1094 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1095 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1096 if (storageStatus != JanusGraphOperationStatus.OK) {
1097 return storageStatus;
1099 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1100 if (result.isLeft()) {
1101 toscaElement.setServiceApiArtifacts(result.left().value());
1103 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1104 return result.right().value();
1107 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1108 if (resultInstArt.isLeft()) {
1109 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1111 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1112 return resultInstArt.right().value();
1115 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1116 if (instanceArt.isLeft()) {
1117 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1119 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1120 return instanceArt.right().value();
1123 return JanusGraphOperationStatus.OK;
1126 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1127 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1128 if (result.isLeft()) {
1129 toscaElement.setInputs(result.left().value());
1131 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1132 return result.right().value();
1135 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1136 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1137 if (capabilitiesResult.isLeft()) {
1138 toscaElement.setCapabilities(capabilitiesResult.left().value());
1140 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1141 return capabilitiesResult.right().value();
1144 return JanusGraphOperationStatus.OK;
1147 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1148 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1149 if (result.isLeft()) {
1150 toscaElement.setGroups(result.left().value());
1152 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1153 return result.right().value();
1156 return JanusGraphOperationStatus.OK;
1159 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1160 List<CategoryDefinition> categories = new ArrayList<>();
1162 switch (componentV.getType()) {
1164 return setResourceCategoryFromGraph(componentV, toscaElement);
1166 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1169 log.debug("Not supported component type {} ", componentV.getType());
1172 return JanusGraphOperationStatus.OK;
1175 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1176 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1177 if (childVertex.isRight()) {
1178 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1179 return childVertex.right().value();
1181 GraphVertex categoryV = childVertex.left().value();
1182 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1183 CategoryDefinition category = new CategoryDefinition();
1184 category.setUniqueId(categoryV.getUniqueId());
1185 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1186 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1187 final Boolean useServiceSubstitutionForNestedServices = (Boolean)metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
1188 category.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
1190 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
1191 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1192 category.setIcons(iconsfromJsonCat);
1194 final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {}.getType();
1195 final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
1196 category.setMetadataKeys(metadataKeysfromJsonCat);
1198 categories.add(category);
1199 toscaElement.setCategories(categories);
1201 return JanusGraphOperationStatus.OK;
1204 @SuppressWarnings("unchecked")
1205 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1207 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1209 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1210 topologyTemplate.setCompositions(json);
1212 return topologyTemplate;
1216 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1217 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1218 if (nodeType.isRight()) {
1219 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1222 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1223 if (status != JanusGraphOperationStatus.OK) {
1224 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1226 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1227 if (status != JanusGraphOperationStatus.OK) {
1228 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1229 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1231 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1232 if (status != JanusGraphOperationStatus.OK) {
1233 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1234 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1237 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1238 if (status != JanusGraphOperationStatus.OK) {
1239 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1240 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1243 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1244 if (status != JanusGraphOperationStatus.OK) {
1245 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1246 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1248 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1249 if (status != JanusGraphOperationStatus.OK) {
1250 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1251 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1253 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1254 if (status != JanusGraphOperationStatus.OK) {
1255 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1256 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1258 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1259 if (status != JanusGraphOperationStatus.OK) {
1260 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1261 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1263 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1264 if (status != JanusGraphOperationStatus.OK) {
1265 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1266 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1268 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1269 if (status != JanusGraphOperationStatus.OK) {
1270 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1271 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1273 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1274 if (status != JanusGraphOperationStatus.OK) {
1275 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1276 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1278 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1279 if (status != JanusGraphOperationStatus.OK) {
1280 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1281 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1283 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1284 if (status != JanusGraphOperationStatus.OK) {
1285 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1286 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1288 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1289 if (status != JanusGraphOperationStatus.OK) {
1290 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1291 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1293 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1294 if (status != JanusGraphOperationStatus.OK) {
1295 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1296 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1298 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1299 if (status != JanusGraphOperationStatus.OK) {
1300 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1301 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1303 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1304 if (status != JanusGraphOperationStatus.OK) {
1305 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1306 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1308 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1309 if (status != JanusGraphOperationStatus.OK) {
1310 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1311 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1313 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1314 if (status != JanusGraphOperationStatus.OK) {
1315 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1316 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1318 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1319 if (status != JanusGraphOperationStatus.OK) {
1320 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1321 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1324 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1325 EdgeLabelEnum.REQUIREMENTS);
1326 if (status != JanusGraphOperationStatus.OK) {
1327 log.debug("Failed to disassociate requirements for {} error {}",
1328 toscaElementVertex.getUniqueId(), status);
1329 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1331 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1332 EdgeLabelEnum.CAPABILITIES);
1333 if (status != JanusGraphOperationStatus.OK) {
1334 log.debug("Failed to disassociate capabilities for {} error {}",
1335 toscaElementVertex.getUniqueId(), status);
1336 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1338 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1339 if (status != JanusGraphOperationStatus.OK) {
1340 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1341 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1343 toscaElementVertex.getVertex().remove();
1344 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1349 @SuppressWarnings("unchecked")
1351 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1352 return createTopologyTemplate((TopologyTemplate) toscaElement);
1356 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1357 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1361 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1362 // Product isn't supported now!!
1363 // TODO add for Product
1364 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1365 return validateServiceCategory(toscaElementToUpdate, elementV);
1368 return validateResourceCategory(toscaElementToUpdate, elementV);
1373 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1374 // not relevant now for topology template
1375 return StorageOperationStatus.OK;
1379 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1380 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1383 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1384 StorageOperationStatus status = StorageOperationStatus.OK;
1385 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1386 CategoryDefinition newCategory = newCategoryList.get(0);
1388 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1389 if (childVertex.isRight()) {
1390 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1391 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1394 GraphVertex categoryV = childVertex.left().value();
1395 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1396 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1398 String newCategoryName = newCategory.getName();
1399 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1400 // the category was changed
1401 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1403 if (getCategoryVertex.isRight()) {
1404 return getCategoryVertex.right().value();
1406 GraphVertex newCategoryV = getCategoryVertex.left().value();
1407 status = moveCategoryEdge(elementV, newCategoryV);
1408 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1413 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1415 Either<GraphVertex, StorageOperationStatus> result = null;
1416 String userId = user.getUserId();
1417 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1418 GraphVertex userVertex = null;
1419 GraphVertex serviceVertex = null;
1420 if (getRes.isRight()) {
1421 JanusGraphOperationStatus status = getRes.right().value();
1422 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1423 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1425 if (result == null) {
1426 userVertex = getRes.left().value();
1427 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1428 if (getRes.isRight()) {
1429 JanusGraphOperationStatus status = getRes.right().value();
1430 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
1431 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1434 if (result == null) {
1435 serviceVertex = getRes.left().value();
1436 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1437 if (edgeIterator.hasNext()) {
1438 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1439 edgeIterator.next().remove();
1442 if (result == null) {
1443 JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1444 if (status != JanusGraphOperationStatus.OK) {
1445 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1446 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1449 if (result == null) {
1450 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1451 long lastUpdateDate = System.currentTimeMillis();
1452 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1453 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1454 if (updateRes.isRight()) {
1455 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1458 if (result == null) {
1459 result = Either.left(serviceVertex);
1464 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1465 * @param componentId
1467 * @param capabilityName
1468 * @param capabilityType
1472 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1474 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1475 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1476 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1477 if (componentByLabelAndId.isRight()) {
1478 result = Either.right(componentByLabelAndId.right().value());
1480 if(componentByLabelAndId.isLeft()){
1481 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1482 if (getDataRes.isRight()) {
1483 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1485 mapPropertiesDataDefinition = getDataRes.left().value();
1488 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1489 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1494 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1495 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1498 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1499 String componentInstanceId,
1500 MapInterfaceDataDefinition instanceInterfaces) {
1501 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1502 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1503 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1505 return StorageOperationStatus.OK;
1509 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1510 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1511 instanceId != null &&
1512 mapPropertiesDataDefinition.get(instanceId) != null &&
1513 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1516 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1517 List<ComponentInstanceProperty> capPropsList = null;
1518 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1519 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1520 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1521 if (capMap != null && !capMap.isEmpty()) {
1522 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1527 if(capPropsList == null){
1528 capPropsList = new ArrayList<>();
1530 return capPropsList;
1533 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1534 if (capProp != null) {
1535 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1536 if (path.length < 4) {
1537 log.debug("wrong key format for capabilty, key {}", capProp);
1540 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1545 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1546 fillPolicyDefinition(componentV, policyDefinition, counter);
1547 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1550 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1551 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1554 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1555 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1558 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1559 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1562 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1563 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1566 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1567 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
1570 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1571 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1572 policyDefinition.setName(policyName);
1573 policyDefinition.setInvariantName(policyName);
1574 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1575 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1576 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1577 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1580 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1581 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1582 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1583 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1586 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1587 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1588 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1590 .on(this::throwStorageException);
1591 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1592 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1594 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1595 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1597 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1598 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1599 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1603 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1604 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1605 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1607 .on(this::throwStorageException);
1608 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1609 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1611 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1612 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1614 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1615 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1616 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1620 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1621 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1622 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1623 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1624 if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
1625 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1628 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1630 if(getOriginRes.isRight()){
1631 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1632 throw new StorageException(getOriginRes.right().value());
1634 return getOriginRes.left().value();
1637 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1638 log.debug("#detectToscaType - type: {}", originType);
1639 if(originType == OriginTypeEnum.VFC
1640 || originType == OriginTypeEnum.CP
1641 || originType == OriginTypeEnum.VL
1642 || originType == OriginTypeEnum.Configuration
1643 || originType == OriginTypeEnum.VFCMT){
1644 return ToscaElementTypeEnum.NODE_TYPE;
1646 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1650 private ComponentParametersView getFilter() {
1651 ComponentParametersView filter = new ComponentParametersView();
1652 filter.setIgnoreCapabilities(false);
1653 filter.setIgnoreCapabiltyProperties(false);
1654 filter.setIgnoreRequirements(false);
1657 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1658 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1659 .left().on(this::throwStorageException);
1660 updateCapOwnerId(toscaElement, componentId);
1661 updateReqOwnerId(toscaElement, componentId);
1662 updatePropertiesOwnerId(toscaElement, componentId);
1663 topologyTemplateOperation
1665 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1666 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1667 topologyTemplateOperation
1668 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1669 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1670 topologyTemplateOperation
1671 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1672 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1675 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1676 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1677 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1678 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1682 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1683 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1684 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1685 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1689 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1690 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1691 if(MapUtils.isNotEmpty(properties)) {
1692 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));