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.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.MapCapabilityProperty;
55 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
58 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
63 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
64 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
65 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
66 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
67 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
68 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
69 import org.openecomp.sdc.be.model.Component;
70 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
71 import org.openecomp.sdc.be.model.ComponentParametersView;
72 import org.openecomp.sdc.be.model.DistributionStatusEnum;
73 import org.openecomp.sdc.be.model.GroupDefinition;
74 import org.openecomp.sdc.be.model.PolicyDefinition;
75 import org.openecomp.sdc.be.model.User;
76 import org.openecomp.sdc.be.model.category.CategoryDefinition;
77 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
78 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
79 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
80 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
81 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
82 import org.openecomp.sdc.be.model.operations.StorageException;
83 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
84 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
85 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
86 import org.openecomp.sdc.common.api.Constants;
87 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
88 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
89 import org.openecomp.sdc.common.log.wrappers.Logger;
90 import org.openecomp.sdc.common.util.ValidationUtils;
91 import org.springframework.beans.factory.annotation.Autowired;
94 @org.springframework.stereotype.Component("topology-template-operation")
95 public class TopologyTemplateOperation extends ToscaElementOperation {
97 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
98 private static final String PATH_DELIMITER = ".";
101 private ArchiveOperation archiveOperation;
103 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
104 Either<TopologyTemplate, StorageOperationStatus> result = null;
106 topologyTemplate.generateUUID();
108 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
109 String resourceUniqueId = topologyTemplate.getUniqueId();
110 if (resourceUniqueId == null) {
111 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
112 topologyTemplate.setUniqueId(resourceUniqueId);
115 GraphVertex topologyTemplateVertex = new GraphVertex();
116 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
118 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
119 if (createdVertex.isRight()) {
120 JanusGraphOperationStatus status = createdVertex.right().value();
121 log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
122 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
126 topologyTemplateVertex = createdVertex.left().value();
128 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate, null);
129 if (assosiateCommon != StorageOperationStatus.OK) {
130 result = Either.right(assosiateCommon);
134 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
135 if (associateCategory != StorageOperationStatus.OK) {
136 result = Either.right(associateCategory);
140 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
141 if (associateInputs != StorageOperationStatus.OK) {
142 result = Either.right(associateInputs);
145 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
146 if (associateGroups != StorageOperationStatus.OK) {
147 result = Either.right(associateGroups);
150 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
151 if (associatePolicies != StorageOperationStatus.OK) {
152 result = Either.right(associatePolicies);
155 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
156 if (associateInstAttr != StorageOperationStatus.OK) {
157 result = Either.right(associateInstAttr);
160 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
161 if (associateInstProperties != StorageOperationStatus.OK) {
162 result = Either.right(associateInstProperties);
165 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
166 if (associateInstProperties != StorageOperationStatus.OK) {
167 result = Either.right(associateInstInputs);
170 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
171 if (associateInstGroups != StorageOperationStatus.OK) {
172 result = Either.right(associateInstInputs);
176 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
177 if (associateRequirements != StorageOperationStatus.OK) {
178 result = Either.right(associateRequirements);
182 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
183 if (associateCapabilities != StorageOperationStatus.OK) {
184 result = Either.right(associateCapabilities);
188 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
189 if (associateArtifacts != StorageOperationStatus.OK) {
190 result = Either.right(associateArtifacts);
194 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
195 if (addAdditionalInformation != StorageOperationStatus.OK) {
196 result = Either.right(addAdditionalInformation);
199 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
200 if (associateCapProperties != StorageOperationStatus.OK) {
201 result = Either.right(associateCapProperties);
205 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
206 if (associateInterfaces != StorageOperationStatus.OK) {
207 result = Either.right(associateInterfaces);
211 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
212 if (associateCapProperties != StorageOperationStatus.OK) {
213 result = Either.right(associatePathProperties);
218 return Either.left(topologyTemplate);
222 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
223 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
226 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
227 if (policies != null && !policies.isEmpty()) {
228 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
229 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
232 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
233 if (assosiateElementToData.isRight()) {
234 return assosiateElementToData.right().value();
237 return StorageOperationStatus.OK;
240 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
241 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
242 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
245 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
246 TopologyTemplate topologyTemplate) {
247 Map<String, CINodeFilterDataDefinition> nodeFilters =
248 topologyTemplate.getNodeFilterComponents();
249 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
252 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
253 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
254 .getCalculatedCapabilitiesProperties();
255 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
256 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
257 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
258 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
259 if (associateElementToData.isRight()) {
260 return associateElementToData.right().value();
264 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
265 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
266 Either<GraphVertex, StorageOperationStatus> associateElementToData =
267 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
268 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
269 if (associateElementToData.isRight()) {
270 return associateElementToData.right().value();
273 return StorageOperationStatus.OK;
276 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
277 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
278 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
279 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
280 if (assosiateElementToData.isRight()) {
281 return assosiateElementToData.right().value();
284 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
285 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
286 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
287 if (assosiateElementToData.isRight()) {
288 return assosiateElementToData.right().value();
291 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
292 if(MapUtils.isNotEmpty(capabilities)) {
293 Either<GraphVertex, StorageOperationStatus> associateElementToData =
294 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
295 EdgeLabelEnum.CAPABILITIES, capabilities);
296 if (associateElementToData.isRight()) {
297 return associateElementToData.right().value();
300 return StorageOperationStatus.OK;
304 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
305 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
306 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
307 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
308 if (assosiateElementToData.isRight()) {
309 return assosiateElementToData.right().value();
312 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
313 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
314 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
315 if (assosiateElementToData.isRight()) {
316 return assosiateElementToData.right().value();
319 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
320 if(MapUtils.isNotEmpty(requirements)) {
321 Either<GraphVertex, StorageOperationStatus> associateElementToData =
322 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
323 EdgeLabelEnum.REQUIREMENTS, requirements);
324 if (associateElementToData.isRight()) {
325 return associateElementToData.right().value();
328 return StorageOperationStatus.OK;
331 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
332 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
334 if (addInformation != null && !addInformation.isEmpty()) {
335 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
336 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
337 a.setUniqueId(uniqueId);
339 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
340 if (assosiateElementToData.isRight()) {
341 return assosiateElementToData.right().value();
344 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
346 if (instArtifacts != null && !instArtifacts.isEmpty()) {
347 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
348 if (assosiateElementToData.isRight()) {
349 return assosiateElementToData.right().value();
352 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
354 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
355 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
356 if (assosiateElementToData.isRight()) {
357 return assosiateElementToData.right().value();
360 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
361 if(MapUtils.isNotEmpty(requirements)) {
362 Either<GraphVertex, StorageOperationStatus> associateElementToData =
363 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
364 EdgeLabelEnum.REQUIREMENTS, requirements);
365 if (associateElementToData.isRight()) {
366 return associateElementToData.right().value();
369 return StorageOperationStatus.OK;
372 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
374 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
376 if (addInformation != null && !addInformation.isEmpty()) {
377 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
378 if (assosiateElementToData.isRight()) {
379 return assosiateElementToData.right().value();
382 return StorageOperationStatus.OK;
385 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
386 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
387 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
390 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
391 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
392 return associateInstInputsToComponent(nodeTypeVertex, instProps);
395 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
396 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
397 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
401 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
402 if (instProps != null && !instProps.isEmpty()) {
403 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
404 if (assosiateElementToData.isRight()) {
405 return assosiateElementToData.right().value();
408 return StorageOperationStatus.OK;
411 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
412 if (instInputs != null && !instInputs.isEmpty()) {
413 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
414 if (assosiateElementToData.isRight()) {
415 return assosiateElementToData.right().value();
418 return StorageOperationStatus.OK;
421 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
422 if (instGroups != null && !instGroups.isEmpty()) {
423 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
424 if (assosiateElementToData.isRight()) {
425 return assosiateElementToData.right().value();
428 return StorageOperationStatus.OK;
432 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
434 if (instInputs != null && !instInputs.isEmpty()) {
435 instInputs.entrySet().forEach(i -> {
436 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
437 List<String> pathKeys = new ArrayList<>();
438 pathKeys.add(i.getKey());
440 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
441 if (status != StorageOperationStatus.OK) {
447 return StorageOperationStatus.OK;
450 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
452 if (instInputs != null && !instInputs.isEmpty()) {
453 instInputs.entrySet().forEach(i -> {
454 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
455 if (status != StorageOperationStatus.OK) {
461 return StorageOperationStatus.OK;
464 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
465 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
468 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
469 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
472 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
473 if (instProps != null && !instProps.isEmpty()) {
474 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
475 if (assosiateElementToData.isRight()) {
476 return assosiateElementToData.right().value();
479 return StorageOperationStatus.OK;
482 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
483 if (!MapUtils.isEmpty(calcRequirements)) {
484 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
485 if (assosiateElementToData.isRight()) {
486 return assosiateElementToData.right().value();
488 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
489 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
490 if (assosiateElementToData.isRight()) {
491 return assosiateElementToData.right().value();
494 if (!MapUtils.isEmpty(calcCapabilty)) {
495 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
496 if (assosiateElementToData.isRight()) {
497 return assosiateElementToData.right().value();
499 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
500 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
501 if (assosiateElementToData.isRight()) {
502 return assosiateElementToData.right().value();
505 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
506 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
507 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
509 .on(v -> StorageOperationStatus.OK);
511 return StorageOperationStatus.OK;
514 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
515 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
516 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
517 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
520 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
521 if (status == JanusGraphOperationStatus.NOT_FOUND) {
522 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
524 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
527 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
528 Optional<StorageOperationStatus> error = dataMap.entrySet()
530 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
531 .filter(s -> s != StorageOperationStatus.OK)
533 if(error.isPresent()){
534 return Either.right(error.get());
536 return Either.left(dataVertex);
539 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
540 Map<String, MapPropertiesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
541 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
544 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
545 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
546 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
547 if (assosiateElementToData.isRight()) {
548 return assosiateElementToData.right().value();
551 return StorageOperationStatus.OK;
554 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instAttr) {
555 if (instAttr != null && !instAttr.isEmpty()) {
556 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
557 if (assosiateElementToData.isRight()) {
558 return assosiateElementToData.right().value();
561 return StorageOperationStatus.OK;
564 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
566 if (groups != null && !groups.isEmpty()) {
567 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
568 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
571 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
572 if (assosiateElementToData.isRight()) {
573 return assosiateElementToData.right().value();
576 return StorageOperationStatus.OK;
579 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
580 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
583 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
584 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
585 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
588 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
589 if (inputs != null && !inputs.isEmpty()) {
590 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
592 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
593 if (assosiateElementToData.isRight()) {
594 return assosiateElementToData.right().value();
597 return StorageOperationStatus.OK;
600 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
601 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
602 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
603 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
604 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
606 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
607 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
609 return nodeTypeVertex;
613 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
614 if (topologyTemplate.getResourceType() == null) {
616 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
619 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
623 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
624 String categoryName = topologyTemplate.getCategories().get(0).getName();
625 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
626 if (category.isRight()) {
627 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
628 return StorageOperationStatus.CATEGORY_NOT_FOUND;
630 GraphVertex categoryV = category.left().value();
631 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
632 if (createEdge != JanusGraphOperationStatus.OK) {
633 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
634 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
636 return StorageOperationStatus.OK;
640 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
641 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
643 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
644 if (componentByLabelAndId.isRight()) {
645 return Either.right(componentByLabelAndId.right().value());
647 GraphVertex componentV = componentByLabelAndId.left().value();
649 return getToscaElement(componentV, componentParametersView);
652 // -------------------------------------------------------------
654 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
655 TopologyTemplate toscaElement;
657 toscaElement = convertToTopologyTemplate(componentV);
658 JanusGraphOperationStatus status;
659 if (!componentParametersView.isIgnoreUsers()) {
660 status = setCreatorFromGraph(componentV, toscaElement);
661 if (status != JanusGraphOperationStatus.OK) {
662 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
665 status = setLastModifierFromGraph(componentV, toscaElement);
666 if (status != JanusGraphOperationStatus.OK) {
667 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
670 if (!componentParametersView.isIgnoreCategories()) {
671 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
672 if (status != JanusGraphOperationStatus.OK) {
673 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
677 if (!componentParametersView.isIgnoreArtifacts()) {
678 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
679 if (storageStatus != JanusGraphOperationStatus.OK) {
680 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
683 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
684 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
685 if (status != JanusGraphOperationStatus.OK) {
686 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
689 if (!componentParametersView.isIgnoreCapabilities()) {
690 status = setCapabilitiesFromGraph(componentV, toscaElement);
691 if (status != JanusGraphOperationStatus.OK) {
692 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
695 if (!componentParametersView.isIgnoreRequirements()) {
696 status = setRequirementsFromGraph(componentV, toscaElement);
697 if (status != JanusGraphOperationStatus.OK) {
698 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
701 if (!componentParametersView.isIgnoreAllVersions()) {
702 status = setAllVersions(componentV, toscaElement);
703 if (status != JanusGraphOperationStatus.OK) {
704 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
707 if (!componentParametersView.isIgnoreAdditionalInformation()) {
708 status = setAdditionalInformationFromGraph(componentV, toscaElement);
709 if (status != JanusGraphOperationStatus.OK) {
710 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
714 if (!componentParametersView.isIgnoreGroups()) {
715 status = setGroupsFromGraph(componentV, toscaElement);
716 if (status != JanusGraphOperationStatus.OK) {
717 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
721 if (!componentParametersView.isIgnorePolicies()) {
722 status = setPoliciesFromGraph(componentV, toscaElement);
723 if (status != JanusGraphOperationStatus.OK) {
724 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
728 if (!componentParametersView.isIgnoreComponentInstances()) {
729 status = setInstGroupsFromGraph(componentV, toscaElement);
731 //Mark all CIs that has archived origins
732 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
734 if (status != JanusGraphOperationStatus.OK) {
735 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
739 if (!componentParametersView.isIgnoreInputs()) {
740 status = setInputsFromGraph(componentV, toscaElement);
741 if (status != JanusGraphOperationStatus.OK) {
742 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
746 if (!componentParametersView.isIgnoreProperties()) {
747 status = setPropertiesFromGraph(componentV, toscaElement);
748 if (status != JanusGraphOperationStatus.OK) {
749 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
754 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
755 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
756 if (status != JanusGraphOperationStatus.OK) {
757 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
762 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
763 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
764 if (status != JanusGraphOperationStatus.OK) {
765 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
770 if (!componentParametersView.isIgnoreForwardingPath()) {
771 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
772 if (status != JanusGraphOperationStatus.OK) {
773 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
778 if (!componentParametersView.isIgnoreNodeFilter()) {
779 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
780 if (status != JanusGraphOperationStatus.OK) {
781 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
786 if (!componentParametersView.isIgnoreSubstitutionFilter()) {
787 status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
788 if (status != JanusGraphOperationStatus.OK) {
789 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
794 if (!componentParametersView.isIgnoreInterfaces()) {
795 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
796 if (storageStatus != JanusGraphOperationStatus.OK) {
797 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
802 if (!componentParametersView.isIgnoreInterfaces()) {
803 JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
804 if (storageStatus != JanusGraphOperationStatus.OK) {
805 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
810 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
811 JanusGraphOperationStatus storageStatus =
812 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
813 if (storageStatus != JanusGraphOperationStatus.OK) {
814 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
818 if (!componentParametersView.isIgnoreDataType()) {
819 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
820 if (storageStatus != JanusGraphOperationStatus.OK) {
821 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
825 return Either.left(toscaElement);
828 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
829 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
830 if (result.isLeft()) {
831 toscaElement.setDataTypes(result.left().value());
833 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
834 return result.right().value();
837 return JanusGraphOperationStatus.OK;
840 private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
841 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
842 if (result.isLeft()) {
843 topologyTemplate.setInterfaces(result.left().value());
845 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
846 return result.right().value();
849 return JanusGraphOperationStatus.OK;
852 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
853 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
854 if (result.isLeft()) {
855 toscaElement.setPolicies(result.left().value());
857 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
858 return result.right().value();
861 return JanusGraphOperationStatus.OK;
864 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
865 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
866 if (result.isLeft()) {
867 topologyTemplate.setInterfaces(result.left().value());
869 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
870 return result.right().value();
873 return JanusGraphOperationStatus.OK;
877 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
878 TopologyTemplate topologyTemplate) {
879 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
880 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
881 if (result.isLeft()) {
882 result.left().value().entrySet().forEach(entry -> topologyTemplate
883 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
885 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
886 return result.right().value();
889 return JanusGraphOperationStatus.OK;
892 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
893 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
894 if (interfaceMap != null && !interfaceMap.isEmpty()) {
895 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
896 if (assosiateElementToData.isRight()) {
897 return assosiateElementToData.right().value();
900 return StorageOperationStatus.OK;
903 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
904 Map<String, CINodeFilterDataDefinition> filterMaps) {
905 if (filterMaps != null && !filterMaps.isEmpty()) {
906 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
907 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
908 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
909 if (assosiateElementToData.isRight()) {
910 return assosiateElementToData.right().value();
913 return StorageOperationStatus.OK;
916 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
917 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
918 if (result.isLeft()) {
919 topologyTemplate.setForwardingPaths(result.left().value());
921 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
922 return result.right().value();
925 return JanusGraphOperationStatus.OK;
929 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
930 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
931 if (result.isLeft()) {
932 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
934 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
935 return result.right().value();
938 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
939 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
940 if (capPropResult.isLeft()) {
941 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
943 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
944 return capPropResult.right().value();
948 return JanusGraphOperationStatus.OK;
951 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
952 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
953 if (result.isLeft()) {
954 toscaElement.setProperties(result.left().value());
956 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
957 return result.right().value();
960 return JanusGraphOperationStatus.OK;
963 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
964 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
965 if (result.isLeft()) {
966 topologyTemplate.setInstGroups(result.left().value());
968 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
969 return result.right().value();
972 return JanusGraphOperationStatus.OK;
975 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
976 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
977 if (result.isLeft()) {
978 topologyTemplate.setInstProperties(result.left().value());
980 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
981 return result.right().value();
984 return JanusGraphOperationStatus.OK;
987 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
988 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
989 if (result.isLeft()) {
990 topologyTemplate.setInstInputs(result.left().value());
992 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
993 return result.right().value();
996 return JanusGraphOperationStatus.OK;
999 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
1000 final TopologyTemplate topologyTemplate) {
1002 final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
1003 getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
1004 if (result.isLeft()) {
1005 topologyTemplate.setNodeFilterComponents(result.left().value());
1007 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1008 return result.right().value();
1011 return JanusGraphOperationStatus.OK;
1014 private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
1015 final TopologyTemplate topologyTemplate) {
1017 final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
1018 getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
1019 if (result.isLeft()) {
1020 topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
1022 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1023 return result.right().value();
1026 return JanusGraphOperationStatus.OK;
1031 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1032 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1033 if (result.isLeft()) {
1034 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1036 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1037 return result.right().value();
1040 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1041 if (result.isLeft()) {
1042 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1044 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1045 return result.right().value();
1048 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
1049 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
1050 if (requirementResult.isLeft()) {
1051 toscaElement.setRequirements(requirementResult.left().value());
1053 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1054 return requirementResult.right().value();
1057 return JanusGraphOperationStatus.OK;
1061 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1062 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1063 if (result.isLeft()) {
1064 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1066 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1067 return result.right().value();
1070 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1071 if (result.isLeft()) {
1072 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1074 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1075 return result.right().value();
1078 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1079 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1080 if (capabilitiesResult.isLeft()) {
1081 toscaElement.setCapabilities(capabilitiesResult.left().value());
1083 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1084 return capabilitiesResult.right().value();
1087 return JanusGraphOperationStatus.OK;
1090 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1091 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1092 if (storageStatus != JanusGraphOperationStatus.OK) {
1093 return storageStatus;
1095 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1096 if (result.isLeft()) {
1097 toscaElement.setServiceApiArtifacts(result.left().value());
1099 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1100 return result.right().value();
1103 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1104 if (resultInstArt.isLeft()) {
1105 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1107 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1108 return resultInstArt.right().value();
1111 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1112 if (instanceArt.isLeft()) {
1113 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1115 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1116 return instanceArt.right().value();
1119 return JanusGraphOperationStatus.OK;
1122 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1123 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1124 if (result.isLeft()) {
1125 toscaElement.setInputs(result.left().value());
1127 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1128 return result.right().value();
1131 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1132 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1133 if (capabilitiesResult.isLeft()) {
1134 toscaElement.setCapabilities(capabilitiesResult.left().value());
1136 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1137 return capabilitiesResult.right().value();
1140 return JanusGraphOperationStatus.OK;
1143 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1144 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1145 if (result.isLeft()) {
1146 toscaElement.setGroups(result.left().value());
1148 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1149 return result.right().value();
1152 return JanusGraphOperationStatus.OK;
1155 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1156 List<CategoryDefinition> categories = new ArrayList<>();
1158 switch (componentV.getType()) {
1160 return setResourceCategoryFromGraph(componentV, toscaElement);
1162 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1165 log.debug("Not supported component type {} ", componentV.getType());
1168 return JanusGraphOperationStatus.OK;
1171 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1172 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1173 if (childVertex.isRight()) {
1174 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1175 return childVertex.right().value();
1177 GraphVertex categoryV = childVertex.left().value();
1178 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1179 CategoryDefinition category = new CategoryDefinition();
1180 category.setUniqueId(categoryV.getUniqueId());
1181 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1182 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1184 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
1185 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1186 category.setIcons(iconsfromJsonCat);
1187 categories.add(category);
1188 toscaElement.setCategories(categories);
1190 return JanusGraphOperationStatus.OK;
1193 @SuppressWarnings("unchecked")
1194 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1196 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1198 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1199 topologyTemplate.setCompositions(json);
1201 return topologyTemplate;
1205 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1206 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1207 if (nodeType.isRight()) {
1208 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1211 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1212 if (status != JanusGraphOperationStatus.OK) {
1213 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1215 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1216 if (status != JanusGraphOperationStatus.OK) {
1217 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1218 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1220 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1221 if (status != JanusGraphOperationStatus.OK) {
1222 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1223 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1226 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1227 if (status != JanusGraphOperationStatus.OK) {
1228 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1229 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1232 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1233 if (status != JanusGraphOperationStatus.OK) {
1234 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1235 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1237 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1238 if (status != JanusGraphOperationStatus.OK) {
1239 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1240 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1242 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1243 if (status != JanusGraphOperationStatus.OK) {
1244 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1245 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1247 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1248 if (status != JanusGraphOperationStatus.OK) {
1249 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1250 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1252 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1253 if (status != JanusGraphOperationStatus.OK) {
1254 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1255 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1257 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1258 if (status != JanusGraphOperationStatus.OK) {
1259 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1260 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1262 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1263 if (status != JanusGraphOperationStatus.OK) {
1264 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1265 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1267 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1268 if (status != JanusGraphOperationStatus.OK) {
1269 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1270 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1272 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1273 if (status != JanusGraphOperationStatus.OK) {
1274 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1275 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1277 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1278 if (status != JanusGraphOperationStatus.OK) {
1279 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1280 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1282 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1283 if (status != JanusGraphOperationStatus.OK) {
1284 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1285 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1287 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1288 if (status != JanusGraphOperationStatus.OK) {
1289 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1290 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1292 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1293 if (status != JanusGraphOperationStatus.OK) {
1294 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1295 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1297 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
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.INTERFACE);
1303 if (status != JanusGraphOperationStatus.OK) {
1304 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1305 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1307 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1308 if (status != JanusGraphOperationStatus.OK) {
1309 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1310 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1313 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1314 EdgeLabelEnum.REQUIREMENTS);
1315 if (status != JanusGraphOperationStatus.OK) {
1316 log.debug("Failed to disassociate requirements for {} error {}",
1317 toscaElementVertex.getUniqueId(), status);
1318 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1320 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1321 EdgeLabelEnum.CAPABILITIES);
1322 if (status != JanusGraphOperationStatus.OK) {
1323 log.debug("Failed to disassociate capabilities for {} error {}",
1324 toscaElementVertex.getUniqueId(), status);
1325 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1327 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1328 if (status != JanusGraphOperationStatus.OK) {
1329 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1330 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1332 toscaElementVertex.getVertex().remove();
1333 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1338 @SuppressWarnings("unchecked")
1340 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1341 return createTopologyTemplate((TopologyTemplate) toscaElement);
1345 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1346 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1350 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1351 // Product isn't supported now!!
1352 // TODO add for Product
1353 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1354 return validateServiceCategory(toscaElementToUpdate, elementV);
1357 return validateResourceCategory(toscaElementToUpdate, elementV);
1362 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1363 // not relevant now for topology template
1364 return StorageOperationStatus.OK;
1368 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1369 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1372 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1373 StorageOperationStatus status = StorageOperationStatus.OK;
1374 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1375 CategoryDefinition newCategory = newCategoryList.get(0);
1377 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1378 if (childVertex.isRight()) {
1379 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1380 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1383 GraphVertex categoryV = childVertex.left().value();
1384 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1385 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1387 String newCategoryName = newCategory.getName();
1388 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1389 // the category was changed
1390 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1392 if (getCategoryVertex.isRight()) {
1393 return getCategoryVertex.right().value();
1395 GraphVertex newCategoryV = getCategoryVertex.left().value();
1396 status = moveCategoryEdge(elementV, newCategoryV);
1397 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1402 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1404 Either<GraphVertex, StorageOperationStatus> result = null;
1405 String userId = user.getUserId();
1406 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1407 GraphVertex userVertex = null;
1408 GraphVertex serviceVertex = null;
1409 if (getRes.isRight()) {
1410 JanusGraphOperationStatus status = getRes.right().value();
1411 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1412 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1414 if (result == null) {
1415 userVertex = getRes.left().value();
1416 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1417 if (getRes.isRight()) {
1418 JanusGraphOperationStatus status = getRes.right().value();
1419 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
1420 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1423 if (result == null) {
1424 serviceVertex = getRes.left().value();
1425 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1426 if (edgeIterator.hasNext()) {
1427 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1428 edgeIterator.next().remove();
1431 if (result == null) {
1432 JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1433 if (status != JanusGraphOperationStatus.OK) {
1434 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1435 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1438 if (result == null) {
1439 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1440 long lastUpdateDate = System.currentTimeMillis();
1441 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1442 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1443 if (updateRes.isRight()) {
1444 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1447 if (result == null) {
1448 result = Either.left(serviceVertex);
1453 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1454 * @param componentId
1456 * @param capabilityName
1457 * @param capabilityType
1461 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1463 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1464 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1465 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1466 if (componentByLabelAndId.isRight()) {
1467 result = Either.right(componentByLabelAndId.right().value());
1469 if(componentByLabelAndId.isLeft()){
1470 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1471 if (getDataRes.isRight()) {
1472 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1474 mapPropertiesDataDefinition = getDataRes.left().value();
1477 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1478 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1483 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1484 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1487 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1488 String componentInstanceId,
1489 MapInterfaceDataDefinition instanceInterfaces) {
1490 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1491 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1492 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1494 return StorageOperationStatus.OK;
1498 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1499 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1500 instanceId != null &&
1501 mapPropertiesDataDefinition.get(instanceId) != null &&
1502 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1505 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1506 List<ComponentInstanceProperty> capPropsList = null;
1507 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1508 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1509 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1510 if (capMap != null && !capMap.isEmpty()) {
1511 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1516 if(capPropsList == null){
1517 capPropsList = new ArrayList<>();
1519 return capPropsList;
1522 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1523 if (capProp != null) {
1524 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1525 if (path.length < 4) {
1526 log.debug("wrong key format for capabilty, key {}", capProp);
1529 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1534 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1535 fillPolicyDefinition(componentV, policyDefinition, counter);
1536 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1539 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1540 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1543 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1544 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1547 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1548 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1551 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1552 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1555 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1556 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
1559 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1560 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1561 policyDefinition.setName(policyName);
1562 policyDefinition.setInvariantName(policyName);
1563 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1564 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1565 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1566 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1569 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1570 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1571 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1572 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1575 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1576 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1577 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1579 .on(this::throwStorageException);
1580 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1581 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1583 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1584 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1586 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1587 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1588 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1592 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1593 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1594 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1596 .on(this::throwStorageException);
1597 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1598 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1600 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1601 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1603 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1604 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1605 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1609 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1610 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1611 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1612 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1613 if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
1614 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1617 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1619 if(getOriginRes.isRight()){
1620 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1621 throw new StorageException(getOriginRes.right().value());
1623 return getOriginRes.left().value();
1626 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1627 log.debug("#detectToscaType - type: {}", originType);
1628 if(originType == OriginTypeEnum.VFC
1629 || originType == OriginTypeEnum.CP
1630 || originType == OriginTypeEnum.VL
1631 || originType == OriginTypeEnum.Configuration
1632 || originType == OriginTypeEnum.VFCMT){
1633 return ToscaElementTypeEnum.NODE_TYPE;
1635 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1639 private ComponentParametersView getFilter() {
1640 ComponentParametersView filter = new ComponentParametersView();
1641 filter.setIgnoreCapabilities(false);
1642 filter.setIgnoreCapabiltyProperties(false);
1643 filter.setIgnoreRequirements(false);
1646 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1647 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1648 .left().on(this::throwStorageException);
1649 updateCapOwnerId(toscaElement, componentId);
1650 updateReqOwnerId(toscaElement, componentId);
1651 updatePropertiesOwnerId(toscaElement, componentId);
1652 topologyTemplateOperation
1654 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1655 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1656 topologyTemplateOperation
1657 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1658 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1659 topologyTemplateOperation
1660 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1661 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1664 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1665 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1666 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1667 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1671 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1672 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1673 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1674 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1678 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1679 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1680 if(MapUtils.isNotEmpty(properties)) {
1681 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));