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.elements.MapAttributesDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
44 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
58 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
63 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
64 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
65 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
66 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
67 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
68 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
69 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
70 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
71 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
72 import org.openecomp.sdc.be.model.Component;
73 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
74 import org.openecomp.sdc.be.model.ComponentParametersView;
75 import org.openecomp.sdc.be.model.DistributionStatusEnum;
76 import org.openecomp.sdc.be.model.GroupDefinition;
77 import org.openecomp.sdc.be.model.PolicyDefinition;
78 import org.openecomp.sdc.be.model.User;
79 import org.openecomp.sdc.be.model.category.CategoryDefinition;
80 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
81 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
82 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
83 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
84 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
85 import org.openecomp.sdc.be.model.operations.StorageException;
86 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
87 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
88 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
89 import org.openecomp.sdc.common.api.Constants;
90 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
91 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
92 import org.openecomp.sdc.common.log.wrappers.Logger;
93 import org.openecomp.sdc.common.util.ValidationUtils;
94 import org.springframework.beans.factory.annotation.Autowired;
97 @org.springframework.stereotype.Component("topology-template-operation")
98 public class TopologyTemplateOperation extends ToscaElementOperation {
100 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
101 private static final String PATH_DELIMITER = ".";
104 private ArchiveOperation archiveOperation;
106 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
107 Either<TopologyTemplate, StorageOperationStatus> result = null;
109 topologyTemplate.generateUUID();
111 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
112 String resourceUniqueId = topologyTemplate.getUniqueId();
113 if (resourceUniqueId == null) {
114 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
115 topologyTemplate.setUniqueId(resourceUniqueId);
118 GraphVertex topologyTemplateVertex = new GraphVertex();
119 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
121 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
122 if (createdVertex.isRight()) {
123 JanusGraphOperationStatus status = createdVertex.right().value();
124 log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
125 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
129 topologyTemplateVertex = createdVertex.left().value();
131 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
132 if (assosiateCommon != StorageOperationStatus.OK) {
133 result = Either.right(assosiateCommon);
137 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
138 if (associateCategory != StorageOperationStatus.OK) {
139 result = Either.right(associateCategory);
143 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
144 if (associateInputs != StorageOperationStatus.OK) {
145 result = Either.right(associateInputs);
148 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
149 if (associateGroups != StorageOperationStatus.OK) {
150 result = Either.right(associateGroups);
153 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
154 if (associatePolicies != StorageOperationStatus.OK) {
155 result = Either.right(associatePolicies);
158 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
159 if (associateInstAttr != StorageOperationStatus.OK) {
160 result = Either.right(associateInstAttr);
163 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
164 if (associateInstProperties != StorageOperationStatus.OK) {
165 result = Either.right(associateInstProperties);
168 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
169 if (associateInstProperties != StorageOperationStatus.OK) {
170 result = Either.right(associateInstInputs);
173 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
174 if (associateInstGroups != StorageOperationStatus.OK) {
175 result = Either.right(associateInstInputs);
179 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
180 if (associateRequirements != StorageOperationStatus.OK) {
181 result = Either.right(associateRequirements);
185 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
186 if (associateCapabilities != StorageOperationStatus.OK) {
187 result = Either.right(associateCapabilities);
191 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
192 if (associateArtifacts != StorageOperationStatus.OK) {
193 result = Either.right(associateArtifacts);
197 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
198 if (addAdditionalInformation != StorageOperationStatus.OK) {
199 result = Either.right(addAdditionalInformation);
202 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
203 if (associateCapProperties != StorageOperationStatus.OK) {
204 result = Either.right(associateCapProperties);
208 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
209 if (associateInterfaces != StorageOperationStatus.OK) {
210 result = Either.right(associateInterfaces);
214 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
215 if (associateCapProperties != StorageOperationStatus.OK) {
216 result = Either.right(associatePathProperties);
221 return Either.left(topologyTemplate);
225 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
226 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
229 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
230 if (policies != null && !policies.isEmpty()) {
231 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
232 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
235 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
236 if (assosiateElementToData.isRight()) {
237 return assosiateElementToData.right().value();
240 return StorageOperationStatus.OK;
243 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
244 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
245 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
248 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
249 TopologyTemplate topologyTemplate) {
250 Map<String, CINodeFilterDataDefinition> nodeFilters =
251 topologyTemplate.getNodeFilterComponents();
252 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
255 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
256 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
257 .getCalculatedCapabilitiesProperties();
258 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
259 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
260 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
261 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
262 if (associateElementToData.isRight()) {
263 return associateElementToData.right().value();
267 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
268 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
269 Either<GraphVertex, StorageOperationStatus> associateElementToData =
270 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
271 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
272 if (associateElementToData.isRight()) {
273 return associateElementToData.right().value();
276 return StorageOperationStatus.OK;
279 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
280 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
281 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
282 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
283 if (assosiateElementToData.isRight()) {
284 return assosiateElementToData.right().value();
287 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
288 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
289 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
290 if (assosiateElementToData.isRight()) {
291 return assosiateElementToData.right().value();
294 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
295 if(MapUtils.isNotEmpty(capabilities)) {
296 Either<GraphVertex, StorageOperationStatus> associateElementToData =
297 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
298 EdgeLabelEnum.CAPABILITIES, capabilities);
299 if (associateElementToData.isRight()) {
300 return associateElementToData.right().value();
303 return StorageOperationStatus.OK;
307 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
308 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
309 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
310 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
311 if (assosiateElementToData.isRight()) {
312 return assosiateElementToData.right().value();
315 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
316 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
317 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
318 if (assosiateElementToData.isRight()) {
319 return assosiateElementToData.right().value();
322 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
323 if(MapUtils.isNotEmpty(requirements)) {
324 Either<GraphVertex, StorageOperationStatus> associateElementToData =
325 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
326 EdgeLabelEnum.REQUIREMENTS, requirements);
327 if (associateElementToData.isRight()) {
328 return associateElementToData.right().value();
331 return StorageOperationStatus.OK;
334 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
335 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
337 if (addInformation != null && !addInformation.isEmpty()) {
338 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
339 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
340 a.setUniqueId(uniqueId);
342 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
343 if (assosiateElementToData.isRight()) {
344 return assosiateElementToData.right().value();
347 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
349 if (instArtifacts != null && !instArtifacts.isEmpty()) {
350 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
351 if (assosiateElementToData.isRight()) {
352 return assosiateElementToData.right().value();
355 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
357 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
358 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
359 if (assosiateElementToData.isRight()) {
360 return assosiateElementToData.right().value();
363 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
364 if(MapUtils.isNotEmpty(requirements)) {
365 Either<GraphVertex, StorageOperationStatus> associateElementToData =
366 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
367 EdgeLabelEnum.REQUIREMENTS, requirements);
368 if (associateElementToData.isRight()) {
369 return associateElementToData.right().value();
372 return StorageOperationStatus.OK;
375 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
377 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
379 if (addInformation != null && !addInformation.isEmpty()) {
380 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
381 if (assosiateElementToData.isRight()) {
382 return assosiateElementToData.right().value();
385 return StorageOperationStatus.OK;
388 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
389 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
390 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
393 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
394 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
395 return associateInstInputsToComponent(nodeTypeVertex, instProps);
398 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
399 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
400 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
404 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
405 if (instProps != null && !instProps.isEmpty()) {
406 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
407 if (assosiateElementToData.isRight()) {
408 return assosiateElementToData.right().value();
411 return StorageOperationStatus.OK;
414 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
415 if (instInputs != null && !instInputs.isEmpty()) {
416 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
417 if (assosiateElementToData.isRight()) {
418 return assosiateElementToData.right().value();
421 return StorageOperationStatus.OK;
424 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
425 if (instGroups != null && !instGroups.isEmpty()) {
426 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
427 if (assosiateElementToData.isRight()) {
428 return assosiateElementToData.right().value();
431 return StorageOperationStatus.OK;
435 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
437 if (instInputs != null && !instInputs.isEmpty()) {
438 instInputs.entrySet().forEach(i -> {
439 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
440 List<String> pathKeys = new ArrayList<>();
441 pathKeys.add(i.getKey());
443 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
444 if (status != StorageOperationStatus.OK) {
450 return StorageOperationStatus.OK;
453 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
455 if (instInputs != null && !instInputs.isEmpty()) {
456 instInputs.entrySet().forEach(i -> {
457 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
458 if (status != StorageOperationStatus.OK) {
464 return StorageOperationStatus.OK;
467 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
468 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
471 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
472 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
475 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
476 if (instProps != null && !instProps.isEmpty()) {
477 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
478 if (assosiateElementToData.isRight()) {
479 return assosiateElementToData.right().value();
482 return StorageOperationStatus.OK;
485 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
486 if (!MapUtils.isEmpty(calcRequirements)) {
487 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
488 if (assosiateElementToData.isRight()) {
489 return assosiateElementToData.right().value();
491 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
492 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
493 if (assosiateElementToData.isRight()) {
494 return assosiateElementToData.right().value();
497 if (!MapUtils.isEmpty(calcCapabilty)) {
498 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
499 if (assosiateElementToData.isRight()) {
500 return assosiateElementToData.right().value();
502 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
503 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
504 if (assosiateElementToData.isRight()) {
505 return assosiateElementToData.right().value();
508 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
509 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
510 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
512 .on(v -> StorageOperationStatus.OK);
514 return StorageOperationStatus.OK;
517 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
518 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
519 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
520 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
523 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
524 if (status == JanusGraphOperationStatus.NOT_FOUND) {
525 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
527 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
530 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
531 Optional<StorageOperationStatus> error = dataMap.entrySet()
533 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
534 .filter(s -> s != StorageOperationStatus.OK)
536 if(error.isPresent()){
537 return Either.right(error.get());
539 return Either.left(dataVertex);
542 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
543 Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
544 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
547 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
548 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
549 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
550 if (assosiateElementToData.isRight()) {
551 return assosiateElementToData.right().value();
554 return StorageOperationStatus.OK;
557 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
558 if (instAttr != null && !instAttr.isEmpty()) {
559 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
560 if (assosiateElementToData.isRight()) {
561 return assosiateElementToData.right().value();
564 return StorageOperationStatus.OK;
567 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
569 if (groups != null && !groups.isEmpty()) {
570 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
571 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
574 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
575 if (assosiateElementToData.isRight()) {
576 return assosiateElementToData.right().value();
579 return StorageOperationStatus.OK;
582 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
583 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
586 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
587 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
588 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
591 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
592 if (inputs != null && !inputs.isEmpty()) {
593 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
595 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
596 if (assosiateElementToData.isRight()) {
597 return assosiateElementToData.right().value();
600 return StorageOperationStatus.OK;
603 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
604 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
605 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
606 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
607 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
609 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
610 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
612 return nodeTypeVertex;
616 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
617 if (topologyTemplate.getResourceType() == null) {
619 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
622 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
626 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
627 String categoryName = topologyTemplate.getCategories().get(0).getName();
628 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
629 if (category.isRight()) {
630 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
631 return StorageOperationStatus.CATEGORY_NOT_FOUND;
633 GraphVertex categoryV = category.left().value();
634 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
635 if (createEdge != JanusGraphOperationStatus.OK) {
636 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
637 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
639 return StorageOperationStatus.OK;
643 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
644 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
646 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
647 if (componentByLabelAndId.isRight()) {
648 return Either.right(componentByLabelAndId.right().value());
650 GraphVertex componentV = componentByLabelAndId.left().value();
652 return getToscaElement(componentV, componentParametersView);
655 // -------------------------------------------------------------
657 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
658 TopologyTemplate toscaElement;
660 toscaElement = convertToTopologyTemplate(componentV);
661 JanusGraphOperationStatus status;
662 if (!componentParametersView.isIgnoreUsers()) {
663 status = setCreatorFromGraph(componentV, toscaElement);
664 if (status != JanusGraphOperationStatus.OK) {
665 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
668 status = setLastModifierFromGraph(componentV, toscaElement);
669 if (status != JanusGraphOperationStatus.OK) {
670 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
673 if (!componentParametersView.isIgnoreCategories()) {
674 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
675 if (status != JanusGraphOperationStatus.OK) {
676 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
680 if (!componentParametersView.isIgnoreArtifacts()) {
681 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
682 if (storageStatus != JanusGraphOperationStatus.OK) {
683 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
686 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
687 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
688 if (status != JanusGraphOperationStatus.OK) {
689 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
692 if (!componentParametersView.isIgnoreCapabilities()) {
693 status = setCapabilitiesFromGraph(componentV, toscaElement);
694 if (status != JanusGraphOperationStatus.OK) {
695 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
698 if (!componentParametersView.isIgnoreRequirements()) {
699 status = setRequirementsFromGraph(componentV, toscaElement);
700 if (status != JanusGraphOperationStatus.OK) {
701 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
704 if (!componentParametersView.isIgnoreAllVersions()) {
705 status = setAllVersions(componentV, toscaElement);
706 if (status != JanusGraphOperationStatus.OK) {
707 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
710 if (!componentParametersView.isIgnoreAdditionalInformation()) {
711 status = setAdditionalInformationFromGraph(componentV, toscaElement);
712 if (status != JanusGraphOperationStatus.OK) {
713 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
717 if (!componentParametersView.isIgnoreGroups()) {
718 status = setGroupsFromGraph(componentV, toscaElement);
719 if (status != JanusGraphOperationStatus.OK) {
720 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
724 if (!componentParametersView.isIgnorePolicies()) {
725 status = setPoliciesFromGraph(componentV, toscaElement);
726 if (status != JanusGraphOperationStatus.OK) {
727 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
731 if (!componentParametersView.isIgnoreComponentInstances()) {
732 status = setInstGroupsFromGraph(componentV, toscaElement);
734 //Mark all CIs that has archived origins
735 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
737 if (status != JanusGraphOperationStatus.OK) {
738 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
742 if (!componentParametersView.isIgnoreInputs()) {
743 status = setInputsFromGraph(componentV, toscaElement);
744 if (status != JanusGraphOperationStatus.OK) {
745 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
749 if (!componentParametersView.isIgnoreProperties()) {
750 status = setPropertiesFromGraph(componentV, toscaElement);
751 if (status != JanusGraphOperationStatus.OK) {
752 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
757 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
758 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
759 if (status != JanusGraphOperationStatus.OK) {
760 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
765 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
766 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
767 if (status != JanusGraphOperationStatus.OK) {
768 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
773 if (!componentParametersView.isIgnoreForwardingPath()) {
774 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
775 if (status != JanusGraphOperationStatus.OK) {
776 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
781 if (!componentParametersView.isIgnoreNodeFilter()) {
782 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
783 if (status != JanusGraphOperationStatus.OK) {
784 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
789 if (!componentParametersView.isIgnoreSubstitutionFilter()) {
790 status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
791 if (status != JanusGraphOperationStatus.OK) {
792 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
797 if (!componentParametersView.isIgnoreInterfaces()) {
798 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
799 if (storageStatus != JanusGraphOperationStatus.OK) {
800 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
805 if (!componentParametersView.isIgnoreInterfaces()) {
806 JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
807 if (storageStatus != JanusGraphOperationStatus.OK) {
808 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
813 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
814 JanusGraphOperationStatus storageStatus =
815 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
816 if (storageStatus != JanusGraphOperationStatus.OK) {
817 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
821 if (!componentParametersView.isIgnoreDataType()) {
822 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
823 if (storageStatus != JanusGraphOperationStatus.OK) {
824 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
828 return Either.left(toscaElement);
831 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
832 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
833 if (result.isLeft()) {
834 toscaElement.setDataTypes(result.left().value());
836 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
837 return result.right().value();
840 return JanusGraphOperationStatus.OK;
843 private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
844 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
845 if (result.isLeft()) {
846 topologyTemplate.setInterfaces(result.left().value());
848 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
849 return result.right().value();
852 return JanusGraphOperationStatus.OK;
855 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
856 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
857 if (result.isLeft()) {
858 toscaElement.setPolicies(result.left().value());
860 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
861 return result.right().value();
864 return JanusGraphOperationStatus.OK;
867 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
868 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
869 if (result.isLeft()) {
870 topologyTemplate.setInterfaces(result.left().value());
872 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
873 return result.right().value();
876 return JanusGraphOperationStatus.OK;
880 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
881 TopologyTemplate topologyTemplate) {
882 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
883 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
884 if (result.isLeft()) {
885 result.left().value().entrySet().forEach(entry -> topologyTemplate
886 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
888 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
889 return result.right().value();
892 return JanusGraphOperationStatus.OK;
895 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
896 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
897 if (interfaceMap != null && !interfaceMap.isEmpty()) {
898 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
899 if (assosiateElementToData.isRight()) {
900 return assosiateElementToData.right().value();
903 return StorageOperationStatus.OK;
906 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
907 Map<String, CINodeFilterDataDefinition> filterMaps) {
908 if (filterMaps != null && !filterMaps.isEmpty()) {
909 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
910 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
911 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
912 if (assosiateElementToData.isRight()) {
913 return assosiateElementToData.right().value();
916 return StorageOperationStatus.OK;
919 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
920 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
921 if (result.isLeft()) {
922 topologyTemplate.setForwardingPaths(result.left().value());
924 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
925 return result.right().value();
928 return JanusGraphOperationStatus.OK;
932 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
933 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
934 if (result.isLeft()) {
935 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
937 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
938 return result.right().value();
941 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
942 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
943 if (capPropResult.isLeft()) {
944 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
946 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
947 return capPropResult.right().value();
951 return JanusGraphOperationStatus.OK;
954 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
955 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
956 if (result.isLeft()) {
957 toscaElement.setProperties(result.left().value());
959 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
960 return result.right().value();
963 return JanusGraphOperationStatus.OK;
966 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
967 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
968 if (result.isLeft()) {
969 topologyTemplate.setInstGroups(result.left().value());
971 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
972 return result.right().value();
975 return JanusGraphOperationStatus.OK;
978 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
979 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
980 if (result.isLeft()) {
981 topologyTemplate.setInstProperties(result.left().value());
983 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
984 return result.right().value();
987 return JanusGraphOperationStatus.OK;
990 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
991 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
992 if (result.isLeft()) {
993 topologyTemplate.setInstInputs(result.left().value());
995 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
996 return result.right().value();
999 return JanusGraphOperationStatus.OK;
1002 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
1003 final TopologyTemplate topologyTemplate) {
1005 final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
1006 getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
1007 if (result.isLeft()) {
1008 topologyTemplate.setNodeFilterComponents(result.left().value());
1010 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1011 return result.right().value();
1014 return JanusGraphOperationStatus.OK;
1017 private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
1018 final TopologyTemplate topologyTemplate) {
1020 final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
1021 getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
1022 if (result.isLeft()) {
1023 topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
1025 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1026 return result.right().value();
1029 return JanusGraphOperationStatus.OK;
1034 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1035 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1036 if (result.isLeft()) {
1037 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1039 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1040 return result.right().value();
1043 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1044 if (result.isLeft()) {
1045 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1047 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1048 return result.right().value();
1051 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
1052 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
1053 if (requirementResult.isLeft()) {
1054 toscaElement.setRequirements(requirementResult.left().value());
1056 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1057 return requirementResult.right().value();
1060 return JanusGraphOperationStatus.OK;
1064 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1065 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1066 if (result.isLeft()) {
1067 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1069 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1070 return result.right().value();
1073 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1074 if (result.isLeft()) {
1075 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1077 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1078 return result.right().value();
1081 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1082 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1083 if (capabilitiesResult.isLeft()) {
1084 toscaElement.setCapabilities(capabilitiesResult.left().value());
1086 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1087 return capabilitiesResult.right().value();
1090 return JanusGraphOperationStatus.OK;
1093 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1094 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1095 if (storageStatus != JanusGraphOperationStatus.OK) {
1096 return storageStatus;
1098 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1099 if (result.isLeft()) {
1100 toscaElement.setServiceApiArtifacts(result.left().value());
1102 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1103 return result.right().value();
1106 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1107 if (resultInstArt.isLeft()) {
1108 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1110 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1111 return resultInstArt.right().value();
1114 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1115 if (instanceArt.isLeft()) {
1116 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1118 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1119 return instanceArt.right().value();
1122 return JanusGraphOperationStatus.OK;
1125 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1126 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1127 if (result.isLeft()) {
1128 toscaElement.setInputs(result.left().value());
1130 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1131 return result.right().value();
1134 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1135 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1136 if (capabilitiesResult.isLeft()) {
1137 toscaElement.setCapabilities(capabilitiesResult.left().value());
1139 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1140 return capabilitiesResult.right().value();
1143 return JanusGraphOperationStatus.OK;
1146 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1147 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1148 if (result.isLeft()) {
1149 toscaElement.setGroups(result.left().value());
1151 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1152 return result.right().value();
1155 return JanusGraphOperationStatus.OK;
1158 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1159 List<CategoryDefinition> categories = new ArrayList<>();
1161 switch (componentV.getType()) {
1163 return setResourceCategoryFromGraph(componentV, toscaElement);
1165 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1168 log.debug("Not supported component type {} ", componentV.getType());
1171 return JanusGraphOperationStatus.OK;
1174 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1175 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1176 if (childVertex.isRight()) {
1177 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1178 return childVertex.right().value();
1180 GraphVertex categoryV = childVertex.left().value();
1181 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1182 CategoryDefinition category = new CategoryDefinition();
1183 category.setUniqueId(categoryV.getUniqueId());
1184 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1185 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1186 final Boolean useServiceSubstitutionForNestedServices = (Boolean)metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
1187 category.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
1189 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
1190 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1191 category.setIcons(iconsfromJsonCat);
1192 categories.add(category);
1193 toscaElement.setCategories(categories);
1195 return JanusGraphOperationStatus.OK;
1198 @SuppressWarnings("unchecked")
1199 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1201 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1203 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1204 topologyTemplate.setCompositions(json);
1206 return topologyTemplate;
1210 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1211 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1212 if (nodeType.isRight()) {
1213 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1216 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1217 if (status != JanusGraphOperationStatus.OK) {
1218 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1220 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1221 if (status != JanusGraphOperationStatus.OK) {
1222 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1223 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1225 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1226 if (status != JanusGraphOperationStatus.OK) {
1227 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1228 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1231 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1232 if (status != JanusGraphOperationStatus.OK) {
1233 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1234 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1237 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1238 if (status != JanusGraphOperationStatus.OK) {
1239 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1240 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1242 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1243 if (status != JanusGraphOperationStatus.OK) {
1244 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1245 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1247 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1248 if (status != JanusGraphOperationStatus.OK) {
1249 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1250 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1252 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1253 if (status != JanusGraphOperationStatus.OK) {
1254 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1255 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1257 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1258 if (status != JanusGraphOperationStatus.OK) {
1259 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1260 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1262 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1263 if (status != JanusGraphOperationStatus.OK) {
1264 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1265 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1267 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1268 if (status != JanusGraphOperationStatus.OK) {
1269 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1270 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1272 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1273 if (status != JanusGraphOperationStatus.OK) {
1274 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1275 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1277 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1278 if (status != JanusGraphOperationStatus.OK) {
1279 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1280 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1282 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1283 if (status != JanusGraphOperationStatus.OK) {
1284 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1285 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1287 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1288 if (status != JanusGraphOperationStatus.OK) {
1289 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1290 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1292 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1293 if (status != JanusGraphOperationStatus.OK) {
1294 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1295 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1297 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1298 if (status != JanusGraphOperationStatus.OK) {
1299 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1300 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1302 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1303 if (status != JanusGraphOperationStatus.OK) {
1304 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1305 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1307 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1308 if (status != JanusGraphOperationStatus.OK) {
1309 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1310 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1312 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1313 if (status != JanusGraphOperationStatus.OK) {
1314 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1315 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1318 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1319 EdgeLabelEnum.REQUIREMENTS);
1320 if (status != JanusGraphOperationStatus.OK) {
1321 log.debug("Failed to disassociate requirements for {} error {}",
1322 toscaElementVertex.getUniqueId(), status);
1323 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1325 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1326 EdgeLabelEnum.CAPABILITIES);
1327 if (status != JanusGraphOperationStatus.OK) {
1328 log.debug("Failed to disassociate capabilities for {} error {}",
1329 toscaElementVertex.getUniqueId(), status);
1330 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1332 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1333 if (status != JanusGraphOperationStatus.OK) {
1334 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1335 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1337 toscaElementVertex.getVertex().remove();
1338 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1343 @SuppressWarnings("unchecked")
1345 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1346 return createTopologyTemplate((TopologyTemplate) toscaElement);
1350 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1351 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1355 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1356 // Product isn't supported now!!
1357 // TODO add for Product
1358 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1359 return validateServiceCategory(toscaElementToUpdate, elementV);
1362 return validateResourceCategory(toscaElementToUpdate, elementV);
1367 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1368 // not relevant now for topology template
1369 return StorageOperationStatus.OK;
1373 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1374 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1377 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1378 StorageOperationStatus status = StorageOperationStatus.OK;
1379 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1380 CategoryDefinition newCategory = newCategoryList.get(0);
1382 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1383 if (childVertex.isRight()) {
1384 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1385 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1388 GraphVertex categoryV = childVertex.left().value();
1389 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1390 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1392 String newCategoryName = newCategory.getName();
1393 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1394 // the category was changed
1395 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1397 if (getCategoryVertex.isRight()) {
1398 return getCategoryVertex.right().value();
1400 GraphVertex newCategoryV = getCategoryVertex.left().value();
1401 status = moveCategoryEdge(elementV, newCategoryV);
1402 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1407 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1409 Either<GraphVertex, StorageOperationStatus> result = null;
1410 String userId = user.getUserId();
1411 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1412 GraphVertex userVertex = null;
1413 GraphVertex serviceVertex = null;
1414 if (getRes.isRight()) {
1415 JanusGraphOperationStatus status = getRes.right().value();
1416 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1417 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1419 if (result == null) {
1420 userVertex = getRes.left().value();
1421 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1422 if (getRes.isRight()) {
1423 JanusGraphOperationStatus status = getRes.right().value();
1424 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
1425 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1428 if (result == null) {
1429 serviceVertex = getRes.left().value();
1430 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1431 if (edgeIterator.hasNext()) {
1432 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1433 edgeIterator.next().remove();
1436 if (result == null) {
1437 JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1438 if (status != JanusGraphOperationStatus.OK) {
1439 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1440 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1443 if (result == null) {
1444 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1445 long lastUpdateDate = System.currentTimeMillis();
1446 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1447 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1448 if (updateRes.isRight()) {
1449 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1452 if (result == null) {
1453 result = Either.left(serviceVertex);
1458 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1459 * @param componentId
1461 * @param capabilityName
1462 * @param capabilityType
1466 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1468 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1469 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1470 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1471 if (componentByLabelAndId.isRight()) {
1472 result = Either.right(componentByLabelAndId.right().value());
1474 if(componentByLabelAndId.isLeft()){
1475 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1476 if (getDataRes.isRight()) {
1477 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1479 mapPropertiesDataDefinition = getDataRes.left().value();
1482 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1483 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1488 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1489 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1492 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1493 String componentInstanceId,
1494 MapInterfaceDataDefinition instanceInterfaces) {
1495 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1496 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1497 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1499 return StorageOperationStatus.OK;
1503 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1504 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1505 instanceId != null &&
1506 mapPropertiesDataDefinition.get(instanceId) != null &&
1507 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1510 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1511 List<ComponentInstanceProperty> capPropsList = null;
1512 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1513 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1514 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1515 if (capMap != null && !capMap.isEmpty()) {
1516 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1521 if(capPropsList == null){
1522 capPropsList = new ArrayList<>();
1524 return capPropsList;
1527 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1528 if (capProp != null) {
1529 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1530 if (path.length < 4) {
1531 log.debug("wrong key format for capabilty, key {}", capProp);
1534 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1539 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1540 fillPolicyDefinition(componentV, policyDefinition, counter);
1541 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1544 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1545 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1548 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1549 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1552 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1553 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1556 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1557 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1560 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1561 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
1564 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1565 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1566 policyDefinition.setName(policyName);
1567 policyDefinition.setInvariantName(policyName);
1568 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1569 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1570 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1571 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1574 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1575 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1576 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1577 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1580 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1581 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1582 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1584 .on(this::throwStorageException);
1585 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1586 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1588 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1589 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1591 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1592 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1593 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1597 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1598 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1599 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1601 .on(this::throwStorageException);
1602 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1603 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1605 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1606 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1608 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1609 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1610 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1614 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1615 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1616 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1617 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1618 if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
1619 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1622 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1624 if(getOriginRes.isRight()){
1625 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1626 throw new StorageException(getOriginRes.right().value());
1628 return getOriginRes.left().value();
1631 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1632 log.debug("#detectToscaType - type: {}", originType);
1633 if(originType == OriginTypeEnum.VFC
1634 || originType == OriginTypeEnum.CP
1635 || originType == OriginTypeEnum.VL
1636 || originType == OriginTypeEnum.Configuration
1637 || originType == OriginTypeEnum.VFCMT){
1638 return ToscaElementTypeEnum.NODE_TYPE;
1640 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1644 private ComponentParametersView getFilter() {
1645 ComponentParametersView filter = new ComponentParametersView();
1646 filter.setIgnoreCapabilities(false);
1647 filter.setIgnoreCapabiltyProperties(false);
1648 filter.setIgnoreRequirements(false);
1651 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1652 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1653 .left().on(this::throwStorageException);
1654 updateCapOwnerId(toscaElement, componentId);
1655 updateReqOwnerId(toscaElement, componentId);
1656 updatePropertiesOwnerId(toscaElement, componentId);
1657 topologyTemplateOperation
1659 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1660 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1661 topologyTemplateOperation
1662 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1663 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1664 topologyTemplateOperation
1665 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1666 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1669 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1670 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1671 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1672 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1676 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1677 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1678 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1679 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1683 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1684 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1685 if(MapUtils.isNotEmpty(properties)) {
1686 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));