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;
27 import java.util.Map.Entry;
28 import java.util.stream.Collectors;
29 import org.apache.commons.collections.MapUtils;
30 import org.apache.tinkerpop.gremlin.structure.Direction;
31 import org.apache.tinkerpop.gremlin.structure.Edge;
32 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
33 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
34 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
35 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
36 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
37 import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
38 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
41 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
58 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
62 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
63 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
64 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
65 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
66 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
67 import org.openecomp.sdc.be.model.Component;
68 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
69 import org.openecomp.sdc.be.model.ComponentParametersView;
70 import org.openecomp.sdc.be.model.DistributionStatusEnum;
71 import org.openecomp.sdc.be.model.GroupDefinition;
72 import org.openecomp.sdc.be.model.PolicyDefinition;
73 import org.openecomp.sdc.be.model.User;
74 import org.openecomp.sdc.be.model.category.CategoryDefinition;
75 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
76 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
77 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
78 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
79 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
80 import org.openecomp.sdc.be.model.operations.StorageException;
81 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
82 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
83 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
84 import org.openecomp.sdc.common.api.Constants;
85 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
86 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
87 import org.openecomp.sdc.common.log.wrappers.Logger;
88 import org.openecomp.sdc.common.util.ValidationUtils;
89 import org.springframework.beans.factory.annotation.Autowired;
92 @org.springframework.stereotype.Component("topology-template-operation")
93 public class TopologyTemplateOperation extends ToscaElementOperation {
95 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
98 private ArchiveOperation archiveOperation;
100 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
101 topologyTemplate.generateUUID();
103 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
104 String resourceUniqueId = topologyTemplate.getUniqueId();
105 if (resourceUniqueId == null) {
106 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
107 topologyTemplate.setUniqueId(resourceUniqueId);
110 GraphVertex topologyTemplateVertex = new GraphVertex();
111 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
113 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
114 if (createdVertex.isRight()) {
115 JanusGraphOperationStatus status = createdVertex.right().value();
116 log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
117 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
120 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate);
121 if (assosiateCommon != StorageOperationStatus.OK) {
122 return Either.right(assosiateCommon);
125 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
126 if (associateCategory != StorageOperationStatus.OK) {
127 return Either.right(associateCategory);
130 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
131 if (associateInputs != StorageOperationStatus.OK) {
132 return Either.right(associateInputs);
134 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
135 if (associateGroups != StorageOperationStatus.OK) {
136 return Either.right(associateGroups);
138 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
139 if (associatePolicies != StorageOperationStatus.OK) {
140 return Either.right(associatePolicies);
142 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
143 if (associateInstAttr != StorageOperationStatus.OK) {
144 return Either.right(associateInstAttr);
146 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
147 if (associateInstProperties != StorageOperationStatus.OK) {
148 return Either.right(associateInstProperties);
150 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
151 if (associateInstProperties != StorageOperationStatus.OK) {
152 return Either.right(associateInstInputs);
154 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
155 if (associateInstGroups != StorageOperationStatus.OK) {
156 return Either.right(associateInstInputs);
159 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
160 if (associateRequirements != StorageOperationStatus.OK) {
161 return Either.right(associateRequirements);
164 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
165 if (associateCapabilities != StorageOperationStatus.OK) {
166 return Either.right(associateCapabilities);
169 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
170 if (associateArtifacts != StorageOperationStatus.OK) {
171 return Either.right(associateArtifacts);
174 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
175 if (addAdditionalInformation != StorageOperationStatus.OK) {
176 return Either.right(addAdditionalInformation);
178 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
179 if (associateCapProperties != StorageOperationStatus.OK) {
180 return Either.right(associateCapProperties);
183 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
184 if (associateInterfaces != StorageOperationStatus.OK) {
185 return Either.right(associateInterfaces);
188 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
189 if (associateCapProperties != StorageOperationStatus.OK) {
190 return Either.right(associatePathProperties);
192 return Either.left(topologyTemplate);
195 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
196 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
199 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
200 if (policies != null && !policies.isEmpty()) {
201 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
202 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
205 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
206 if (assosiateElementToData.isRight()) {
207 return assosiateElementToData.right().value();
210 return StorageOperationStatus.OK;
213 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
214 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
215 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
218 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
219 TopologyTemplate topologyTemplate) {
220 Map<String, CINodeFilterDataDefinition> nodeFilters =
221 topologyTemplate.getNodeFilterComponents();
222 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
225 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
226 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
227 .getCalculatedCapabilitiesProperties();
228 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
229 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
230 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
231 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
232 if (associateElementToData.isRight()) {
233 return associateElementToData.right().value();
237 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
238 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
239 Either<GraphVertex, StorageOperationStatus> associateElementToData =
240 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
241 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
242 if (associateElementToData.isRight()) {
243 return associateElementToData.right().value();
246 return StorageOperationStatus.OK;
249 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
250 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
251 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
252 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
253 if (assosiateElementToData.isRight()) {
254 return assosiateElementToData.right().value();
257 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
258 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
259 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
260 if (assosiateElementToData.isRight()) {
261 return assosiateElementToData.right().value();
264 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
265 if(MapUtils.isNotEmpty(capabilities)) {
266 Either<GraphVertex, StorageOperationStatus> associateElementToData =
267 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
268 EdgeLabelEnum.CAPABILITIES, capabilities);
269 if (associateElementToData.isRight()) {
270 return associateElementToData.right().value();
273 return StorageOperationStatus.OK;
277 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
278 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
279 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
280 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
281 if (assosiateElementToData.isRight()) {
282 return assosiateElementToData.right().value();
285 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
286 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
287 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
288 if (assosiateElementToData.isRight()) {
289 return assosiateElementToData.right().value();
292 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
293 if(MapUtils.isNotEmpty(requirements)) {
294 Either<GraphVertex, StorageOperationStatus> associateElementToData =
295 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
296 EdgeLabelEnum.REQUIREMENTS, requirements);
297 if (associateElementToData.isRight()) {
298 return associateElementToData.right().value();
301 return StorageOperationStatus.OK;
304 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
305 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
307 if (addInformation != null && !addInformation.isEmpty()) {
308 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
309 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
310 a.setUniqueId(uniqueId);
312 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
313 if (assosiateElementToData.isRight()) {
314 return assosiateElementToData.right().value();
317 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
319 if (instArtifacts != null && !instArtifacts.isEmpty()) {
320 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
321 if (assosiateElementToData.isRight()) {
322 return assosiateElementToData.right().value();
325 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
327 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
328 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
329 if (assosiateElementToData.isRight()) {
330 return assosiateElementToData.right().value();
333 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
334 if(MapUtils.isNotEmpty(requirements)) {
335 Either<GraphVertex, StorageOperationStatus> associateElementToData =
336 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
337 EdgeLabelEnum.REQUIREMENTS, requirements);
338 if (associateElementToData.isRight()) {
339 return associateElementToData.right().value();
342 return StorageOperationStatus.OK;
345 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
347 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
349 if (addInformation != null && !addInformation.isEmpty()) {
350 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
351 if (assosiateElementToData.isRight()) {
352 return assosiateElementToData.right().value();
355 return StorageOperationStatus.OK;
358 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
359 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
360 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
363 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
364 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
365 return associateInstInputsToComponent(nodeTypeVertex, instProps);
368 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
369 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
370 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
374 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
375 if (instProps != null && !instProps.isEmpty()) {
376 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
377 if (assosiateElementToData.isRight()) {
378 return assosiateElementToData.right().value();
381 return StorageOperationStatus.OK;
384 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
385 if (instInputs != null && !instInputs.isEmpty()) {
386 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
387 if (assosiateElementToData.isRight()) {
388 return assosiateElementToData.right().value();
391 return StorageOperationStatus.OK;
394 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
395 if (instGroups != null && !instGroups.isEmpty()) {
396 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
397 if (assosiateElementToData.isRight()) {
398 return assosiateElementToData.right().value();
401 return StorageOperationStatus.OK;
405 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
407 if (instInputs != null && !instInputs.isEmpty()) {
408 instInputs.entrySet().forEach(i -> {
409 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
410 List<String> pathKeys = new ArrayList<>();
411 pathKeys.add(i.getKey());
413 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
414 if (status != StorageOperationStatus.OK) {
420 return StorageOperationStatus.OK;
423 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
425 if (instInputs != null && !instInputs.isEmpty()) {
426 instInputs.entrySet().forEach(i -> {
427 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
428 if (status != StorageOperationStatus.OK) {
434 return StorageOperationStatus.OK;
437 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
438 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
441 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
442 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
445 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
446 if (instProps != null && !instProps.isEmpty()) {
447 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
448 if (assosiateElementToData.isRight()) {
449 return assosiateElementToData.right().value();
452 return StorageOperationStatus.OK;
455 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
456 if (!MapUtils.isEmpty(calcRequirements)) {
457 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
458 if (assosiateElementToData.isRight()) {
459 return assosiateElementToData.right().value();
461 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
462 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
463 if (assosiateElementToData.isRight()) {
464 return assosiateElementToData.right().value();
467 if (!MapUtils.isEmpty(calcCapabilty)) {
468 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
469 if (assosiateElementToData.isRight()) {
470 return assosiateElementToData.right().value();
472 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
473 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
474 if (assosiateElementToData.isRight()) {
475 return assosiateElementToData.right().value();
478 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
479 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
480 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
482 .on(v -> StorageOperationStatus.OK);
484 return StorageOperationStatus.OK;
487 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
488 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
489 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
490 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
493 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
494 if (status == JanusGraphOperationStatus.NOT_FOUND) {
495 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
497 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
500 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
501 Optional<StorageOperationStatus> error = dataMap.entrySet()
503 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
504 .filter(s -> s != StorageOperationStatus.OK)
506 if(error.isPresent()){
507 return Either.right(error.get());
509 return Either.left(dataVertex);
512 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
513 Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
514 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
517 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
518 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
519 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
520 if (assosiateElementToData.isRight()) {
521 return assosiateElementToData.right().value();
524 return StorageOperationStatus.OK;
527 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
528 if (instAttr != null && !instAttr.isEmpty()) {
529 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
530 if (assosiateElementToData.isRight()) {
531 return assosiateElementToData.right().value();
534 return StorageOperationStatus.OK;
537 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
539 if (groups != null && !groups.isEmpty()) {
540 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
541 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
544 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
545 if (assosiateElementToData.isRight()) {
546 return assosiateElementToData.right().value();
549 return StorageOperationStatus.OK;
552 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
553 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
556 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
557 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
558 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
561 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
562 if (inputs != null && !inputs.isEmpty()) {
563 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
565 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
566 if (assosiateElementToData.isRight()) {
567 return assosiateElementToData.right().value();
570 return StorageOperationStatus.OK;
573 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
574 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
575 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
576 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
577 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
579 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
580 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
582 return nodeTypeVertex;
586 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
587 if (topologyTemplate.getResourceType() == null) {
589 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
592 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
596 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
597 String categoryName = topologyTemplate.getCategories().get(0).getName();
598 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
599 if (category.isRight()) {
600 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
601 return StorageOperationStatus.CATEGORY_NOT_FOUND;
603 GraphVertex categoryV = category.left().value();
604 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
605 if (createEdge != JanusGraphOperationStatus.OK) {
606 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
607 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
609 return StorageOperationStatus.OK;
613 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
614 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
616 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
617 if (componentByLabelAndId.isRight()) {
618 return Either.right(componentByLabelAndId.right().value());
620 GraphVertex componentV = componentByLabelAndId.left().value();
622 return getToscaElement(componentV, componentParametersView);
625 // -------------------------------------------------------------
627 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
628 TopologyTemplate toscaElement;
630 toscaElement = convertToTopologyTemplate(componentV);
631 JanusGraphOperationStatus status;
632 if (!componentParametersView.isIgnoreUsers()) {
633 status = setCreatorFromGraph(componentV, toscaElement);
634 if (status != JanusGraphOperationStatus.OK) {
635 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
638 status = setLastModifierFromGraph(componentV, toscaElement);
639 if (status != JanusGraphOperationStatus.OK) {
640 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
643 if (!componentParametersView.isIgnoreCategories()) {
644 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
645 if (status != JanusGraphOperationStatus.OK) {
646 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
650 if (!componentParametersView.isIgnoreArtifacts()) {
651 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
652 if (storageStatus != JanusGraphOperationStatus.OK) {
653 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
656 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
657 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
658 if (status != JanusGraphOperationStatus.OK) {
659 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
662 if (!componentParametersView.isIgnoreComponentInstancesAttributes()) {
663 status = setComponentInstancesAttributesFromGraph(componentV, toscaElement);
664 if (status != JanusGraphOperationStatus.OK) {
665 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
668 if (!componentParametersView.isIgnoreCapabilities()) {
669 status = setCapabilitiesFromGraph(componentV, toscaElement);
670 if (status != JanusGraphOperationStatus.OK) {
671 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
674 if (!componentParametersView.isIgnoreRequirements()) {
675 status = setRequirementsFromGraph(componentV, toscaElement);
676 if (status != JanusGraphOperationStatus.OK) {
677 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
680 if (!componentParametersView.isIgnoreAllVersions()) {
681 status = setAllVersions(componentV, toscaElement);
682 if (status != JanusGraphOperationStatus.OK) {
683 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
686 if (!componentParametersView.isIgnoreAdditionalInformation()) {
687 status = setAdditionalInformationFromGraph(componentV, toscaElement);
688 if (status != JanusGraphOperationStatus.OK) {
689 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
693 if (!componentParametersView.isIgnoreGroups()) {
694 status = setGroupsFromGraph(componentV, toscaElement);
695 if (status != JanusGraphOperationStatus.OK) {
696 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
700 if (!componentParametersView.isIgnorePolicies()) {
701 status = setPoliciesFromGraph(componentV, toscaElement);
702 if (status != JanusGraphOperationStatus.OK) {
703 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
707 if (!componentParametersView.isIgnoreComponentInstances()) {
708 status = setInstGroupsFromGraph(componentV, toscaElement);
710 //Mark all CIs that has archived origins
711 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
713 if (status != JanusGraphOperationStatus.OK) {
714 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
718 if (!componentParametersView.isIgnoreInputs()) {
719 status = setInputsFromGraph(componentV, toscaElement);
720 if (status != JanusGraphOperationStatus.OK) {
721 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
726 if (!componentParametersView.isIgnoreOutputs()) {
727 final JanusGraphOperationStatus storageStatus = setOutputsFromGraph(componentV, toscaElement);
728 if (storageStatus != JanusGraphOperationStatus.OK) {
729 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
733 if (!componentParametersView.isIgnoreProperties()) {
734 status = setPropertiesFromGraph(componentV, toscaElement);
735 if (status != JanusGraphOperationStatus.OK) {
736 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
741 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
742 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
743 if (status != JanusGraphOperationStatus.OK) {
744 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
749 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
750 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
751 if (status != JanusGraphOperationStatus.OK) {
752 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
757 if (!componentParametersView.isIgnoreServicePath()) {
758 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
759 if (status != JanusGraphOperationStatus.OK) {
760 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
765 if (!componentParametersView.isIgnoreNodeFilter()) {
766 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
767 if (status != JanusGraphOperationStatus.OK) {
768 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
773 if (!componentParametersView.isIgnoreSubstitutionFilter()) {
774 status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
775 if (status != JanusGraphOperationStatus.OK) {
776 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
781 if (!componentParametersView.isIgnoreInterfaces()) {
782 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
783 if (storageStatus != JanusGraphOperationStatus.OK) {
784 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
789 if (!componentParametersView.isIgnoreInterfaces()) {
790 JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
791 if (storageStatus != JanusGraphOperationStatus.OK) {
792 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
797 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
798 JanusGraphOperationStatus storageStatus =
799 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
800 if (storageStatus != JanusGraphOperationStatus.OK) {
801 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
805 if (!componentParametersView.isIgnoreDataType()) {
806 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
807 if (storageStatus != JanusGraphOperationStatus.OK) {
808 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
812 return Either.left(toscaElement);
815 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
816 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
817 if (result.isLeft()) {
818 toscaElement.setDataTypes(result.left().value());
820 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
821 return result.right().value();
824 return JanusGraphOperationStatus.OK;
827 private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
828 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
829 if (result.isLeft()) {
830 topologyTemplate.setInterfaces(result.left().value());
832 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
833 return result.right().value();
836 return JanusGraphOperationStatus.OK;
839 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
840 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
841 if (result.isLeft()) {
842 toscaElement.setPolicies(result.left().value());
844 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
845 return result.right().value();
848 return JanusGraphOperationStatus.OK;
851 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
852 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
853 if (result.isLeft()) {
854 topologyTemplate.setInterfaces(result.left().value());
856 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
857 return result.right().value();
860 return JanusGraphOperationStatus.OK;
864 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
865 TopologyTemplate topologyTemplate) {
866 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
867 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
868 if (result.isLeft()) {
869 result.left().value().entrySet().forEach(entry -> topologyTemplate
870 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
872 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
873 return result.right().value();
876 return JanusGraphOperationStatus.OK;
879 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
880 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
881 if (interfaceMap != null && !interfaceMap.isEmpty()) {
882 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
883 if (assosiateElementToData.isRight()) {
884 return assosiateElementToData.right().value();
887 return StorageOperationStatus.OK;
890 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
891 Map<String, CINodeFilterDataDefinition> filterMaps) {
892 if (filterMaps != null && !filterMaps.isEmpty()) {
893 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
894 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
895 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
896 if (assosiateElementToData.isRight()) {
897 return assosiateElementToData.right().value();
900 return StorageOperationStatus.OK;
903 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
904 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
905 if (result.isLeft()) {
906 topologyTemplate.setForwardingPaths(result.left().value());
908 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
909 return result.right().value();
912 return JanusGraphOperationStatus.OK;
916 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
917 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
918 if (result.isLeft()) {
919 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
921 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
922 return result.right().value();
925 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
926 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
927 if (capPropResult.isLeft()) {
928 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
930 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
931 return capPropResult.right().value();
935 return JanusGraphOperationStatus.OK;
938 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
939 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
940 if (result.isLeft()) {
941 toscaElement.setProperties(result.left().value());
943 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
944 return result.right().value();
947 return JanusGraphOperationStatus.OK;
950 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
951 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
952 if (result.isLeft()) {
953 topologyTemplate.setInstGroups(result.left().value());
955 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
956 return result.right().value();
959 return JanusGraphOperationStatus.OK;
962 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
963 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
964 if (result.isLeft()) {
965 topologyTemplate.setInstProperties(result.left().value());
967 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
968 return result.right().value();
971 return JanusGraphOperationStatus.OK;
974 private JanusGraphOperationStatus setComponentInstancesAttributesFromGraph(final GraphVertex componentV,
975 final TopologyTemplate topologyTemplate) {
976 final Either<Map<String, MapAttributesDataDefinition>, JanusGraphOperationStatus> result =
977 getDataFromGraph(componentV, EdgeLabelEnum.INST_ATTRIBUTES);
978 if (result.isLeft()) {
979 topologyTemplate.setInstAttributes(result.left().value());
980 } else if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
981 return result.right().value();
983 return JanusGraphOperationStatus.OK;
986 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
987 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
988 if (result.isLeft()) {
989 topologyTemplate.setInstInputs(result.left().value());
991 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
992 return result.right().value();
995 return JanusGraphOperationStatus.OK;
998 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
999 final TopologyTemplate topologyTemplate) {
1001 final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
1002 getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
1003 if (result.isLeft()) {
1004 topologyTemplate.setNodeFilterComponents(result.left().value());
1006 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1007 return result.right().value();
1010 return JanusGraphOperationStatus.OK;
1013 private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
1014 final TopologyTemplate topologyTemplate) {
1016 final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
1017 getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
1018 if (result.isLeft()) {
1019 topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
1021 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1022 return result.right().value();
1025 return JanusGraphOperationStatus.OK;
1030 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1031 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1032 if (result.isLeft()) {
1033 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1035 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1036 return result.right().value();
1039 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1040 if (result.isLeft()) {
1041 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1043 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1044 return result.right().value();
1047 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
1048 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
1049 if (requirementResult.isLeft()) {
1050 toscaElement.setRequirements(requirementResult.left().value());
1052 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1053 return requirementResult.right().value();
1056 return JanusGraphOperationStatus.OK;
1060 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1061 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1062 if (result.isLeft()) {
1063 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1065 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1066 return result.right().value();
1069 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1070 if (result.isLeft()) {
1071 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1073 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1074 return result.right().value();
1077 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1078 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1079 if (capabilitiesResult.isLeft()) {
1080 toscaElement.setCapabilities(capabilitiesResult.left().value());
1082 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1083 return capabilitiesResult.right().value();
1086 return JanusGraphOperationStatus.OK;
1089 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1090 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1091 if (storageStatus != JanusGraphOperationStatus.OK) {
1092 return storageStatus;
1094 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1095 if (result.isLeft()) {
1096 toscaElement.setServiceApiArtifacts(result.left().value());
1098 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1099 return result.right().value();
1102 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1103 if (resultInstArt.isLeft()) {
1104 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1106 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1107 return resultInstArt.right().value();
1110 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1111 if (instanceArt.isLeft()) {
1112 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1114 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1115 return instanceArt.right().value();
1118 return JanusGraphOperationStatus.OK;
1121 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1122 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1123 if (result.isLeft()) {
1124 toscaElement.setInputs(result.left().value());
1126 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1127 return result.right().value();
1130 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1131 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1132 if (capabilitiesResult.isLeft()) {
1133 toscaElement.setCapabilities(capabilitiesResult.left().value());
1135 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1136 return capabilitiesResult.right().value();
1139 return JanusGraphOperationStatus.OK;
1142 private JanusGraphOperationStatus setOutputsFromGraph(final GraphVertex componentV,
1143 final TopologyTemplate toscaElement) {
1144 final Either<Map<String, AttributeDataDefinition>, JanusGraphOperationStatus> result =
1145 getDataFromGraph(componentV, EdgeLabelEnum.OUTPUTS);
1146 if (result.isLeft()) {
1147 toscaElement.setOutputs(result.left().value());
1149 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1150 return result.right().value();
1153 return JanusGraphOperationStatus.OK;
1156 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1157 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1158 if (result.isLeft()) {
1159 toscaElement.setGroups(result.left().value());
1161 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1162 return result.right().value();
1165 return JanusGraphOperationStatus.OK;
1168 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1169 List<CategoryDefinition> categories = new ArrayList<>();
1171 switch (componentV.getType()) {
1173 return setResourceCategoryFromGraph(componentV, toscaElement);
1175 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1178 log.debug("Not supported component type {} ", componentV.getType());
1181 return JanusGraphOperationStatus.OK;
1184 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1185 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1186 if (childVertex.isRight()) {
1187 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1188 return childVertex.right().value();
1190 GraphVertex categoryV = childVertex.left().value();
1191 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1192 CategoryDefinition category = new CategoryDefinition();
1193 category.setUniqueId(categoryV.getUniqueId());
1194 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1195 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1196 final Boolean useServiceSubstitutionForNestedServices = (Boolean)metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
1197 category.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
1199 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
1200 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1201 category.setIcons(iconsfromJsonCat);
1203 final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {}.getType();
1204 final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
1205 category.setMetadataKeys(metadataKeysfromJsonCat);
1207 categories.add(category);
1208 toscaElement.setCategories(categories);
1210 return JanusGraphOperationStatus.OK;
1213 @SuppressWarnings("unchecked")
1214 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1216 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1218 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1219 topologyTemplate.setCompositions(json);
1221 return topologyTemplate;
1225 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1226 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1227 if (nodeType.isRight()) {
1228 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1231 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1232 if (status != JanusGraphOperationStatus.OK) {
1233 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1235 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1236 if (status != JanusGraphOperationStatus.OK) {
1237 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1238 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1240 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1241 if (status != JanusGraphOperationStatus.OK) {
1242 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1243 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1246 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1247 if (status != JanusGraphOperationStatus.OK) {
1248 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1249 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1252 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1253 if (status != JanusGraphOperationStatus.OK) {
1254 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1255 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1257 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1258 if (status != JanusGraphOperationStatus.OK) {
1259 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1260 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1262 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1263 if (status != JanusGraphOperationStatus.OK) {
1264 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1265 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1267 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1268 if (status != JanusGraphOperationStatus.OK) {
1269 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1270 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1272 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1273 if (status != JanusGraphOperationStatus.OK) {
1274 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1275 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1277 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1278 if (status != JanusGraphOperationStatus.OK) {
1279 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1280 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1282 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1283 if (status != JanusGraphOperationStatus.OK) {
1284 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1285 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1287 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1288 if (status != JanusGraphOperationStatus.OK) {
1289 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1290 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1292 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1293 if (status != JanusGraphOperationStatus.OK) {
1294 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1295 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1297 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1298 if (status != JanusGraphOperationStatus.OK) {
1299 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1300 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1302 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1303 if (status != JanusGraphOperationStatus.OK) {
1304 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1305 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1307 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1308 if (status != JanusGraphOperationStatus.OK) {
1309 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1310 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1312 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1313 if (status != JanusGraphOperationStatus.OK) {
1314 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1315 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1317 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1318 if (status != JanusGraphOperationStatus.OK) {
1319 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1320 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1322 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1323 if (status != JanusGraphOperationStatus.OK) {
1324 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1325 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1327 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1328 if (status != JanusGraphOperationStatus.OK) {
1329 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1330 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1333 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1334 EdgeLabelEnum.REQUIREMENTS);
1335 if (status != JanusGraphOperationStatus.OK) {
1336 log.debug("Failed to disassociate requirements for {} error {}",
1337 toscaElementVertex.getUniqueId(), status);
1338 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1340 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1341 EdgeLabelEnum.CAPABILITIES);
1342 if (status != JanusGraphOperationStatus.OK) {
1343 log.debug("Failed to disassociate capabilities for {} error {}",
1344 toscaElementVertex.getUniqueId(), status);
1345 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1347 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1348 if (status != JanusGraphOperationStatus.OK) {
1349 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1350 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1352 toscaElementVertex.getVertex().remove();
1353 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1358 @SuppressWarnings("unchecked")
1360 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1361 return createTopologyTemplate((TopologyTemplate) toscaElement);
1365 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1366 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1370 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1371 // Product isn't supported now!!
1372 // TODO add for Product
1373 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1374 return validateServiceCategory(toscaElementToUpdate, elementV);
1377 return validateResourceCategory(toscaElementToUpdate, elementV);
1382 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1383 // not relevant now for topology template
1384 return StorageOperationStatus.OK;
1388 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1389 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1392 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1393 StorageOperationStatus status = StorageOperationStatus.OK;
1394 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1395 CategoryDefinition newCategory = newCategoryList.get(0);
1397 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1398 if (childVertex.isRight()) {
1399 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1400 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1403 GraphVertex categoryV = childVertex.left().value();
1404 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1405 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1407 String newCategoryName = newCategory.getName();
1408 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1409 // the category was changed
1410 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1412 if (getCategoryVertex.isRight()) {
1413 return getCategoryVertex.right().value();
1415 GraphVertex newCategoryV = getCategoryVertex.left().value();
1416 status = moveCategoryEdge(elementV, newCategoryV);
1417 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1422 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1424 Either<GraphVertex, StorageOperationStatus> result = null;
1425 String userId = user.getUserId();
1426 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1427 GraphVertex userVertex = null;
1428 GraphVertex serviceVertex = null;
1429 if (getRes.isRight()) {
1430 JanusGraphOperationStatus status = getRes.right().value();
1431 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1432 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1434 if (result == null) {
1435 userVertex = getRes.left().value();
1436 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1437 if (getRes.isRight()) {
1438 JanusGraphOperationStatus status = getRes.right().value();
1439 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
1440 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1443 if (result == null) {
1444 serviceVertex = getRes.left().value();
1445 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1446 if (edgeIterator.hasNext()) {
1447 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1448 edgeIterator.next().remove();
1451 if (result == null) {
1452 JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1453 if (status != JanusGraphOperationStatus.OK) {
1454 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1455 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1458 if (result == null) {
1459 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1460 long lastUpdateDate = System.currentTimeMillis();
1461 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1462 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1463 if (updateRes.isRight()) {
1464 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1467 if (result == null) {
1468 result = Either.left(serviceVertex);
1473 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1474 * @param componentId
1476 * @param capabilityName
1477 * @param capabilityType
1481 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1483 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1484 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1485 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1486 if (componentByLabelAndId.isRight()) {
1487 result = Either.right(componentByLabelAndId.right().value());
1489 if(componentByLabelAndId.isLeft()){
1490 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1491 if (getDataRes.isRight()) {
1492 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1494 mapPropertiesDataDefinition = getDataRes.left().value();
1497 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1498 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1503 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1504 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1507 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1508 String componentInstanceId,
1509 MapInterfaceDataDefinition instanceInterfaces) {
1510 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1511 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1512 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1514 return StorageOperationStatus.OK;
1518 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1519 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1520 instanceId != null &&
1521 mapPropertiesDataDefinition.get(instanceId) != null &&
1522 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1525 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1526 List<ComponentInstanceProperty> capPropsList = null;
1527 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1528 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1529 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1530 if (capMap != null && !capMap.isEmpty()) {
1531 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1536 if(capPropsList == null){
1537 capPropsList = new ArrayList<>();
1539 return capPropsList;
1542 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1543 if (capProp != null) {
1544 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1545 if (path.length < 4) {
1546 log.debug("wrong key format for capabilty, key {}", capProp);
1549 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1554 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1555 fillPolicyDefinition(componentV, policyDefinition, counter);
1556 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1559 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1560 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1563 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1564 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1567 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1568 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1571 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1572 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1575 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1576 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
1579 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1580 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1581 policyDefinition.setName(policyName);
1582 policyDefinition.setInvariantName(policyName);
1583 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1584 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1585 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1586 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1589 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1590 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1591 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1592 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1595 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1596 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1597 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1599 .on(this::throwStorageException);
1600 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1601 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1603 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1604 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1606 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1607 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1608 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1612 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1613 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1614 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1616 .on(this::throwStorageException);
1617 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1618 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1620 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1621 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1623 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1624 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1625 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1629 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1630 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1631 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1632 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1633 if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
1634 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1637 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1639 if(getOriginRes.isRight()){
1640 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1641 throw new StorageException(getOriginRes.right().value());
1643 return getOriginRes.left().value();
1646 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1647 log.debug("#detectToscaType - type: {}", originType);
1648 if(originType == OriginTypeEnum.VFC
1649 || originType == OriginTypeEnum.CP
1650 || originType == OriginTypeEnum.VL
1651 || originType == OriginTypeEnum.Configuration
1652 || originType == OriginTypeEnum.VFCMT){
1653 return ToscaElementTypeEnum.NODE_TYPE;
1655 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1659 private ComponentParametersView getFilter() {
1660 ComponentParametersView filter = new ComponentParametersView();
1661 filter.setIgnoreCapabilities(false);
1662 filter.setIgnoreCapabiltyProperties(false);
1663 filter.setIgnoreRequirements(false);
1666 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1667 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1668 .left().on(this::throwStorageException);
1669 updateCapOwnerId(toscaElement, componentId);
1670 updateReqOwnerId(toscaElement, componentId);
1671 updatePropertiesOwnerId(toscaElement, componentId);
1672 topologyTemplateOperation
1674 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1675 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1676 topologyTemplateOperation
1677 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1678 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1679 topologyTemplateOperation
1680 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1681 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1684 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1685 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1686 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1687 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1691 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1692 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1693 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1694 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1698 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1699 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1700 if(MapUtils.isNotEmpty(properties)) {
1701 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));