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.MapAttributesDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
40 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
58 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
61 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
62 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
63 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
64 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
65 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
66 import org.openecomp.sdc.be.model.Component;
67 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
68 import org.openecomp.sdc.be.model.ComponentParametersView;
69 import org.openecomp.sdc.be.model.DistributionStatusEnum;
70 import org.openecomp.sdc.be.model.GroupDefinition;
71 import org.openecomp.sdc.be.model.PolicyDefinition;
72 import org.openecomp.sdc.be.model.User;
73 import org.openecomp.sdc.be.model.category.CategoryDefinition;
74 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
75 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
76 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
77 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
78 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
79 import org.openecomp.sdc.be.model.operations.StorageException;
80 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
81 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
82 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
83 import org.openecomp.sdc.common.api.Constants;
84 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
85 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
86 import org.openecomp.sdc.common.log.wrappers.Logger;
87 import org.openecomp.sdc.common.util.ValidationUtils;
88 import org.springframework.beans.factory.annotation.Autowired;
91 @org.springframework.stereotype.Component("topology-template-operation")
92 public class TopologyTemplateOperation extends ToscaElementOperation {
94 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
97 private ArchiveOperation archiveOperation;
99 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
100 topologyTemplate.generateUUID();
102 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
103 String resourceUniqueId = topologyTemplate.getUniqueId();
104 if (resourceUniqueId == null) {
105 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
106 topologyTemplate.setUniqueId(resourceUniqueId);
109 GraphVertex topologyTemplateVertex = new GraphVertex();
110 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
112 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
113 if (createdVertex.isRight()) {
114 JanusGraphOperationStatus status = createdVertex.right().value();
115 log.debug( "Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
116 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
119 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate);
120 if (assosiateCommon != StorageOperationStatus.OK) {
121 return Either.right(assosiateCommon);
124 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
125 if (associateCategory != StorageOperationStatus.OK) {
126 return Either.right(associateCategory);
129 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
130 if (associateInputs != StorageOperationStatus.OK) {
131 return Either.right(associateInputs);
133 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
134 if (associateGroups != StorageOperationStatus.OK) {
135 return Either.right(associateGroups);
137 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
138 if (associatePolicies != StorageOperationStatus.OK) {
139 return Either.right(associatePolicies);
141 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
142 if (associateInstAttr != StorageOperationStatus.OK) {
143 return Either.right(associateInstAttr);
145 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
146 if (associateInstProperties != StorageOperationStatus.OK) {
147 return Either.right(associateInstProperties);
149 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
150 if (associateInstProperties != StorageOperationStatus.OK) {
151 return Either.right(associateInstInputs);
153 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
154 if (associateInstGroups != StorageOperationStatus.OK) {
155 return Either.right(associateInstInputs);
158 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
159 if (associateRequirements != StorageOperationStatus.OK) {
160 return Either.right(associateRequirements);
163 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
164 if (associateCapabilities != StorageOperationStatus.OK) {
165 return Either.right(associateCapabilities);
168 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
169 if (associateArtifacts != StorageOperationStatus.OK) {
170 return Either.right(associateArtifacts);
173 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
174 if (addAdditionalInformation != StorageOperationStatus.OK) {
175 return Either.right(addAdditionalInformation);
177 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
178 if (associateCapProperties != StorageOperationStatus.OK) {
179 return Either.right(associateCapProperties);
182 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
183 if (associateInterfaces != StorageOperationStatus.OK) {
184 return Either.right(associateInterfaces);
187 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
188 if (associateCapProperties != StorageOperationStatus.OK) {
189 return Either.right(associatePathProperties);
191 return Either.left(topologyTemplate);
194 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
195 return associatePoliciesToComponent(nodeTypeVertex, topologyTemplate.getPolicies());
198 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, Map<String, PolicyDataDefinition> policies) {
199 if (policies != null && !policies.isEmpty()) {
200 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
201 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
204 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES, EdgeLabelEnum.POLICIES, policies);
205 if (assosiateElementToData.isRight()) {
206 return assosiateElementToData.right().value();
209 return StorageOperationStatus.OK;
212 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
213 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
214 return associateForwardingPathToComponent(topologyTemplateVertex,forwardingPaths);
217 private StorageOperationStatus associateNodeFilterToResource(GraphVertex topologyTemplateVertex,
218 TopologyTemplate topologyTemplate) {
219 Map<String, CINodeFilterDataDefinition> nodeFilters =
220 topologyTemplate.getNodeFilterComponents();
221 return associateNodeFiltersToComponent(topologyTemplateVertex, nodeFilters);
224 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
225 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate
226 .getCalculatedCapabilitiesProperties();
227 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
228 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData
229 (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
230 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
231 if (associateElementToData.isRight()) {
232 return associateElementToData.right().value();
236 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
237 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
238 Either<GraphVertex, StorageOperationStatus> associateElementToData =
239 associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
240 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
241 if (associateElementToData.isRight()) {
242 return associateElementToData.right().value();
245 return StorageOperationStatus.OK;
248 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
249 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
250 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
251 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
252 if (assosiateElementToData.isRight()) {
253 return assosiateElementToData.right().value();
256 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
257 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
258 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullfilledCapabilities);
259 if (assosiateElementToData.isRight()) {
260 return assosiateElementToData.right().value();
263 Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities();
264 if(MapUtils.isNotEmpty(capabilities)) {
265 Either<GraphVertex, StorageOperationStatus> associateElementToData =
266 associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
267 EdgeLabelEnum.CAPABILITIES, capabilities);
268 if (associateElementToData.isRight()) {
269 return associateElementToData.right().value();
272 return StorageOperationStatus.OK;
276 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
277 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
278 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
279 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
280 if (assosiateElementToData.isRight()) {
281 return assosiateElementToData.right().value();
284 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
285 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
286 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullfilledRequirements);
287 if (assosiateElementToData.isRight()) {
288 return assosiateElementToData.right().value();
291 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
292 if(MapUtils.isNotEmpty(requirements)) {
293 Either<GraphVertex, StorageOperationStatus> associateElementToData =
294 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
295 EdgeLabelEnum.REQUIREMENTS, requirements);
296 if (associateElementToData.isRight()) {
297 return associateElementToData.right().value();
300 return StorageOperationStatus.OK;
303 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
304 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
306 if (addInformation != null && !addInformation.isEmpty()) {
307 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
308 String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
309 a.setUniqueId(uniqueId);
311 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.SERVICE_API_ARTIFACTS, EdgeLabelEnum.SERVICE_API_ARTIFACTS, addInformation);
312 if (assosiateElementToData.isRight()) {
313 return assosiateElementToData.right().value();
316 Map<String, MapArtifactDataDefinition> instArtifacts = topologyTemplate.getInstDeploymentArtifacts();
318 if (instArtifacts != null && !instArtifacts.isEmpty()) {
319 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts);
320 if (assosiateElementToData.isRight()) {
321 return assosiateElementToData.right().value();
324 Map<String, MapArtifactDataDefinition> instInfoArtifacts = topologyTemplate.getInstanceArtifacts();
326 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
327 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS, instInfoArtifacts);
328 if (assosiateElementToData.isRight()) {
329 return assosiateElementToData.right().value();
332 Map<String, ListRequirementDataDefinition> requirements = topologyTemplate.getRequirements();
333 if(MapUtils.isNotEmpty(requirements)) {
334 Either<GraphVertex, StorageOperationStatus> associateElementToData =
335 associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
336 EdgeLabelEnum.REQUIREMENTS, requirements);
337 if (associateElementToData.isRight()) {
338 return associateElementToData.right().value();
341 return StorageOperationStatus.OK;
344 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
346 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
348 if (addInformation != null && !addInformation.isEmpty()) {
349 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
350 if (assosiateElementToData.isRight()) {
351 return assosiateElementToData.right().value();
354 return StorageOperationStatus.OK;
357 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
358 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
359 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
362 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
363 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
364 return associateInstInputsToComponent(nodeTypeVertex, instProps);
367 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
368 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
369 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
373 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
374 if (instProps != null && !instProps.isEmpty()) {
375 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
376 if (assosiateElementToData.isRight()) {
377 return assosiateElementToData.right().value();
380 return StorageOperationStatus.OK;
383 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
384 if (instInputs != null && !instInputs.isEmpty()) {
385 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS, EdgeLabelEnum.INST_INPUTS, instInputs);
386 if (assosiateElementToData.isRight()) {
387 return assosiateElementToData.right().value();
390 return StorageOperationStatus.OK;
393 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
394 if (instGroups != null && !instGroups.isEmpty()) {
395 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS, EdgeLabelEnum.INST_GROUPS, instGroups);
396 if (assosiateElementToData.isRight()) {
397 return assosiateElementToData.right().value();
400 return StorageOperationStatus.OK;
404 public StorageOperationStatus deleteInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
406 if (instInputs != null && !instInputs.isEmpty()) {
407 instInputs.entrySet().forEach(i -> {
408 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
409 List<String> pathKeys = new ArrayList<>();
410 pathKeys.add(i.getKey());
412 StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS, uniqueKeys, pathKeys, JsonPresentationFields.NAME);
413 if (status != StorageOperationStatus.OK) {
419 return StorageOperationStatus.OK;
422 public StorageOperationStatus addInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
424 if (instInputs != null && !instInputs.isEmpty()) {
425 instInputs.entrySet().forEach(i -> {
426 StorageOperationStatus status = addToscaDataDeepElementsBlockToToscaElement(nodeTypeVertex, EdgeLabelEnum.INST_PROPERTIES, VertexTypeEnum.INST_PROPERTIES, i.getValue(), i.getKey());
427 if (status != StorageOperationStatus.OK) {
433 return StorageOperationStatus.OK;
436 public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
437 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
440 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
441 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
444 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
445 if (instProps != null && !instProps.isEmpty()) {
446 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
447 if (assosiateElementToData.isRight()) {
448 return assosiateElementToData.right().value();
451 return StorageOperationStatus.OK;
454 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex, Map<String, MapListRequirementDataDefinition> calcRequirements, Map<String, MapListCapabilityDataDefinition> calcCapabilty, Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
455 if (!MapUtils.isEmpty(calcRequirements)) {
456 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
457 if (assosiateElementToData.isRight()) {
458 return assosiateElementToData.right().value();
460 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
461 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS, EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
462 if (assosiateElementToData.isRight()) {
463 return assosiateElementToData.right().value();
466 if (!MapUtils.isEmpty(calcCapabilty)) {
467 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAPABILITIES ,EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
468 if (assosiateElementToData.isRight()) {
469 return assosiateElementToData.right().value();
471 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
472 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES, EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
473 if (assosiateElementToData.isRight()) {
474 return assosiateElementToData.right().value();
477 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)){
478 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
479 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapabilitiesProperties)
481 .on(v -> StorageOperationStatus.OK);
483 return StorageOperationStatus.OK;
486 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap){
487 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
488 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
489 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
492 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, ? extends ToscaDataDefinition> dataMap) {
493 if (status == JanusGraphOperationStatus.NOT_FOUND) {
494 return associateElementToData(nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap);
496 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
499 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> addElementsToComponent(GraphVertex nodeTypeVertex, GraphVertex dataVertex, VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum, Map<String, T> dataMap) {
500 Optional<StorageOperationStatus> error = dataMap.entrySet()
502 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
503 .filter(s -> s != StorageOperationStatus.OK)
505 if(error.isPresent()){
506 return Either.right(error.get());
508 return Either.left(dataVertex);
511 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
512 Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
513 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
516 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex, Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
517 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
518 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
519 if (assosiateElementToData.isRight()) {
520 return assosiateElementToData.right().value();
523 return StorageOperationStatus.OK;
526 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
527 if (instAttr != null && !instAttr.isEmpty()) {
528 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
529 if (assosiateElementToData.isRight()) {
530 return assosiateElementToData.right().value();
533 return StorageOperationStatus.OK;
536 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
538 if (groups != null && !groups.isEmpty()) {
539 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
540 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
543 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS, EdgeLabelEnum.GROUPS, groups);
544 if (assosiateElementToData.isRight()) {
545 return assosiateElementToData.right().value();
548 return StorageOperationStatus.OK;
551 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
552 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
555 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
556 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
557 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
560 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
561 if (inputs != null && !inputs.isEmpty()) {
562 inputs.values().stream().filter(e -> e.getUniqueId() == null).forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
564 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS, EdgeLabelEnum.INPUTS, inputs);
565 if (assosiateElementToData.isRight()) {
566 return assosiateElementToData.right().value();
569 return StorageOperationStatus.OK;
572 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
573 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
574 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
575 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
576 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
578 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
579 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
581 return nodeTypeVertex;
585 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
586 if (topologyTemplate.getResourceType() == null) {
588 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
591 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
595 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
596 String categoryName = topologyTemplate.getCategories().get(0).getName();
597 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
598 if (category.isRight()) {
599 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
600 return StorageOperationStatus.CATEGORY_NOT_FOUND;
602 GraphVertex categoryV = category.left().value();
603 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
604 if (createEdge != JanusGraphOperationStatus.OK) {
605 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName, categoryV.getUniqueId());
606 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
608 return StorageOperationStatus.OK;
612 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
613 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
615 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, parseFlag);
616 if (componentByLabelAndId.isRight()) {
617 return Either.right(componentByLabelAndId.right().value());
619 GraphVertex componentV = componentByLabelAndId.left().value();
621 return getToscaElement(componentV, componentParametersView);
624 // -------------------------------------------------------------
626 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
627 TopologyTemplate toscaElement;
629 toscaElement = convertToTopologyTemplate(componentV);
630 JanusGraphOperationStatus status;
631 if (!componentParametersView.isIgnoreUsers()) {
632 status = setCreatorFromGraph(componentV, toscaElement);
633 if (status != JanusGraphOperationStatus.OK) {
634 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
637 status = setLastModifierFromGraph(componentV, toscaElement);
638 if (status != JanusGraphOperationStatus.OK) {
639 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
642 if (!componentParametersView.isIgnoreCategories()) {
643 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
644 if (status != JanusGraphOperationStatus.OK) {
645 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
649 if (!componentParametersView.isIgnoreArtifacts()) {
650 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
651 if (storageStatus != JanusGraphOperationStatus.OK) {
652 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
655 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
656 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
657 if (status != JanusGraphOperationStatus.OK) {
658 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
661 if (!componentParametersView.isIgnoreComponentInstancesAttributes()) {
662 status = setComponentInstancesAttributesFromGraph(componentV, toscaElement);
663 if (status != JanusGraphOperationStatus.OK) {
664 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
667 if (!componentParametersView.isIgnoreCapabilities()) {
668 status = setCapabilitiesFromGraph(componentV, toscaElement);
669 if (status != JanusGraphOperationStatus.OK) {
670 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
673 if (!componentParametersView.isIgnoreRequirements()) {
674 status = setRequirementsFromGraph(componentV, toscaElement);
675 if (status != JanusGraphOperationStatus.OK) {
676 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
679 if (!componentParametersView.isIgnoreAllVersions()) {
680 status = setAllVersions(componentV, toscaElement);
681 if (status != JanusGraphOperationStatus.OK) {
682 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
685 if (!componentParametersView.isIgnoreAdditionalInformation()) {
686 status = setAdditionalInformationFromGraph(componentV, toscaElement);
687 if (status != JanusGraphOperationStatus.OK) {
688 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
692 if (!componentParametersView.isIgnoreGroups()) {
693 status = setGroupsFromGraph(componentV, toscaElement);
694 if (status != JanusGraphOperationStatus.OK) {
695 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
699 if (!componentParametersView.isIgnorePolicies()) {
700 status = setPoliciesFromGraph(componentV, toscaElement);
701 if (status != JanusGraphOperationStatus.OK) {
702 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
706 if (!componentParametersView.isIgnoreComponentInstances()) {
707 status = setInstGroupsFromGraph(componentV, toscaElement);
709 //Mark all CIs that has archived origins
710 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
712 if (status != JanusGraphOperationStatus.OK) {
713 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
717 if (!componentParametersView.isIgnoreInputs()) {
718 status = setInputsFromGraph(componentV, toscaElement);
719 if (status != JanusGraphOperationStatus.OK) {
720 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
724 if (!componentParametersView.isIgnoreProperties()) {
725 status = setPropertiesFromGraph(componentV, toscaElement);
726 if (status != JanusGraphOperationStatus.OK) {
727 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
732 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
733 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
734 if (status != JanusGraphOperationStatus.OK) {
735 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
740 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
741 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
742 if (status != JanusGraphOperationStatus.OK) {
743 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
748 if (!componentParametersView.isIgnoreServicePath()) {
749 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
750 if (status != JanusGraphOperationStatus.OK) {
751 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
756 if (!componentParametersView.isIgnoreNodeFilter()) {
757 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
758 if (status != JanusGraphOperationStatus.OK) {
759 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
764 if (!componentParametersView.isIgnoreSubstitutionFilter()) {
765 status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
766 if (status != JanusGraphOperationStatus.OK) {
767 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
772 if (!componentParametersView.isIgnoreInterfaces()) {
773 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
774 if (storageStatus != JanusGraphOperationStatus.OK) {
775 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
780 if (!componentParametersView.isIgnoreInterfaces()) {
781 JanusGraphOperationStatus storageStatus = setInterfcesFromGraph(componentV, toscaElement);
782 if (storageStatus != JanusGraphOperationStatus.OK) {
783 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
788 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
789 JanusGraphOperationStatus storageStatus =
790 setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
791 if (storageStatus != JanusGraphOperationStatus.OK) {
792 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
796 if (!componentParametersView.isIgnoreDataType()) {
797 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
798 if (storageStatus != JanusGraphOperationStatus.OK) {
799 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
803 return Either.left(toscaElement);
806 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
807 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
808 if (result.isLeft()) {
809 toscaElement.setDataTypes(result.left().value());
811 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
812 return result.right().value();
815 return JanusGraphOperationStatus.OK;
818 private JanusGraphOperationStatus setInterfcesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
819 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
820 if (result.isLeft()) {
821 topologyTemplate.setInterfaces(result.left().value());
823 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
824 return result.right().value();
827 return JanusGraphOperationStatus.OK;
830 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
831 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
832 if (result.isLeft()) {
833 toscaElement.setPolicies(result.left().value());
835 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
836 return result.right().value();
839 return JanusGraphOperationStatus.OK;
842 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
843 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
844 if (result.isLeft()) {
845 topologyTemplate.setInterfaces(result.left().value());
847 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
848 return result.right().value();
851 return JanusGraphOperationStatus.OK;
855 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV,
856 TopologyTemplate topologyTemplate) {
857 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result =
858 getDataFromGraph(componentV, EdgeLabelEnum.INST_INTERFACES);
859 if (result.isLeft()) {
860 result.left().value().entrySet().forEach(entry -> topologyTemplate
861 .addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
863 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
864 return result.right().value();
867 return JanusGraphOperationStatus.OK;
870 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
871 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
872 if (interfaceMap != null && !interfaceMap.isEmpty()) {
873 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
874 if (assosiateElementToData.isRight()) {
875 return assosiateElementToData.right().value();
878 return StorageOperationStatus.OK;
881 public StorageOperationStatus associateNodeFiltersToComponent(GraphVertex nodeTypeVertex,
882 Map<String, CINodeFilterDataDefinition> filterMaps) {
883 if (filterMaps != null && !filterMaps.isEmpty()) {
884 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData
885 (nodeTypeVertex, VertexTypeEnum.NODE_FILTER_TEMPLATE,
886 EdgeLabelEnum.NODE_FILTER_TEMPLATE, filterMaps);
887 if (assosiateElementToData.isRight()) {
888 return assosiateElementToData.right().value();
891 return StorageOperationStatus.OK;
894 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
895 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.FORWARDING_PATH);
896 if (result.isLeft()) {
897 topologyTemplate.setForwardingPaths(result.left().value());
899 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
900 return result.right().value();
903 return JanusGraphOperationStatus.OK;
907 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
908 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
909 if (result.isLeft()) {
910 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
912 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
913 return result.right().value();
916 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult =
917 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
918 if (capPropResult.isLeft()) {
919 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
921 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
922 return capPropResult.right().value();
926 return JanusGraphOperationStatus.OK;
929 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
930 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
931 if (result.isLeft()) {
932 toscaElement.setProperties(result.left().value());
934 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
935 return result.right().value();
938 return JanusGraphOperationStatus.OK;
941 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
942 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
943 if (result.isLeft()) {
944 topologyTemplate.setInstGroups(result.left().value());
946 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
947 return result.right().value();
950 return JanusGraphOperationStatus.OK;
953 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
954 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_PROPERTIES);
955 if (result.isLeft()) {
956 topologyTemplate.setInstProperties(result.left().value());
958 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
959 return result.right().value();
962 return JanusGraphOperationStatus.OK;
965 private JanusGraphOperationStatus setComponentInstancesAttributesFromGraph(final GraphVertex componentV,
966 final TopologyTemplate topologyTemplate) {
967 final Either<Map<String, MapAttributesDataDefinition>, JanusGraphOperationStatus> result =
968 getDataFromGraph(componentV, EdgeLabelEnum.INST_ATTRIBUTES);
969 if (result.isLeft()) {
970 topologyTemplate.setInstAttributes(result.left().value());
971 } else if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
972 return result.right().value();
974 return JanusGraphOperationStatus.OK;
977 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
978 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
979 if (result.isLeft()) {
980 topologyTemplate.setInstInputs(result.left().value());
982 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
983 return result.right().value();
986 return JanusGraphOperationStatus.OK;
989 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV,
990 final TopologyTemplate topologyTemplate) {
992 final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result =
993 getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
994 if (result.isLeft()) {
995 topologyTemplate.setNodeFilterComponents(result.left().value());
997 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
998 return result.right().value();
1001 return JanusGraphOperationStatus.OK;
1004 private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV,
1005 final TopologyTemplate topologyTemplate) {
1007 final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result =
1008 getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
1009 if (result.isLeft()) {
1010 topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value());
1012 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1013 return result.right().value();
1016 return JanusGraphOperationStatus.OK;
1021 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1022 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1023 if (result.isLeft()) {
1024 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1026 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1027 return result.right().value();
1030 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1031 if (result.isLeft()) {
1032 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1034 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1035 return result.right().value();
1038 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult =
1039 getDataFromGraph(componentV, EdgeLabelEnum.REQUIREMENTS);
1040 if (requirementResult.isLeft()) {
1041 toscaElement.setRequirements(requirementResult.left().value());
1043 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1044 return requirementResult.right().value();
1047 return JanusGraphOperationStatus.OK;
1051 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1052 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1053 if (result.isLeft()) {
1054 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1056 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1057 return result.right().value();
1060 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1061 if (result.isLeft()) {
1062 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1064 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1065 return result.right().value();
1068 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1069 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1070 if (capabilitiesResult.isLeft()) {
1071 toscaElement.setCapabilities(capabilitiesResult.left().value());
1073 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1074 return capabilitiesResult.right().value();
1077 return JanusGraphOperationStatus.OK;
1080 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1081 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1082 if (storageStatus != JanusGraphOperationStatus.OK) {
1083 return storageStatus;
1085 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1086 if (result.isLeft()) {
1087 toscaElement.setServiceApiArtifacts(result.left().value());
1089 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1090 return result.right().value();
1093 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1094 if (resultInstArt.isLeft()) {
1095 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1097 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1098 return resultInstArt.right().value();
1101 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1102 if (instanceArt.isLeft()) {
1103 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1105 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1106 return instanceArt.right().value();
1109 return JanusGraphOperationStatus.OK;
1112 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1113 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1114 if (result.isLeft()) {
1115 toscaElement.setInputs(result.left().value());
1117 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1118 return result.right().value();
1121 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult =
1122 getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES);
1123 if (capabilitiesResult.isLeft()) {
1124 toscaElement.setCapabilities(capabilitiesResult.left().value());
1126 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1127 return capabilitiesResult.right().value();
1130 return JanusGraphOperationStatus.OK;
1133 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1134 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1135 if (result.isLeft()) {
1136 toscaElement.setGroups(result.left().value());
1138 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1139 return result.right().value();
1142 return JanusGraphOperationStatus.OK;
1145 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1146 List<CategoryDefinition> categories = new ArrayList<>();
1148 switch (componentV.getType()) {
1150 return setResourceCategoryFromGraph(componentV, toscaElement);
1152 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1155 log.debug("Not supported component type {} ", componentV.getType());
1158 return JanusGraphOperationStatus.OK;
1161 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement, List<CategoryDefinition> categories) {
1162 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1163 if (childVertex.isRight()) {
1164 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(), childVertex.right().value());
1165 return childVertex.right().value();
1167 GraphVertex categoryV = childVertex.left().value();
1168 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1169 CategoryDefinition category = new CategoryDefinition();
1170 category.setUniqueId(categoryV.getUniqueId());
1171 category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
1172 category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
1173 final Boolean useServiceSubstitutionForNestedServices = (Boolean)metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
1174 category.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
1176 Type listTypeCat = new TypeToken<List<String>>() {}.getType();
1177 List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1178 category.setIcons(iconsfromJsonCat);
1180 final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {}.getType();
1181 final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
1182 category.setMetadataKeys(metadataKeysfromJsonCat);
1184 categories.add(category);
1185 toscaElement.setCategories(categories);
1187 return JanusGraphOperationStatus.OK;
1190 @SuppressWarnings("unchecked")
1191 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1193 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1195 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1196 topologyTemplate.setCompositions(json);
1198 return topologyTemplate;
1202 public Either<ToscaElement, StorageOperationStatus> deleteToscaElement(GraphVertex toscaElementVertex) {
1203 Either<ToscaElement, StorageOperationStatus> nodeType = getToscaElement(toscaElementVertex, new ComponentParametersView());
1204 if (nodeType.isRight()) {
1205 log.debug("Failed to fetch tosca element {} error {}", toscaElementVertex.getUniqueId(), nodeType.right().value());
1208 JanusGraphOperationStatus status = disassociateAndDeleteCommonElements(toscaElementVertex);
1209 if (status != JanusGraphOperationStatus.OK) {
1210 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1212 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_ATTRIBUTES);
1213 if (status != JanusGraphOperationStatus.OK) {
1214 log.debug("Failed to disassociate instances attributes for {} error {}", toscaElementVertex.getUniqueId(), status);
1215 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1217 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_PROPERTIES);
1218 if (status != JanusGraphOperationStatus.OK) {
1219 log.debug("Failed to disassociate instances properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1220 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1223 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1224 if (status != JanusGraphOperationStatus.OK) {
1225 log.debug("Failed to disassociate instances inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1226 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1229 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1230 if (status != JanusGraphOperationStatus.OK) {
1231 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1232 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1234 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1235 if (status != JanusGraphOperationStatus.OK) {
1236 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1237 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1239 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1240 if (status != JanusGraphOperationStatus.OK) {
1241 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1242 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1244 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1245 if (status != JanusGraphOperationStatus.OK) {
1246 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1247 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1249 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INPUTS);
1250 if (status != JanusGraphOperationStatus.OK) {
1251 log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1252 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1254 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES);
1255 if (status != JanusGraphOperationStatus.OK) {
1256 log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1257 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1259 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES);
1260 if (status != JanusGraphOperationStatus.OK) {
1261 log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status);
1262 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1264 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1265 if (status != JanusGraphOperationStatus.OK) {
1266 log.debug("Failed to disassociate fullfilled capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1267 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1269 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1270 if (status != JanusGraphOperationStatus.OK) {
1271 log.debug("Failed to disassociate calculated capabiliites properties for {} error {}", toscaElementVertex.getUniqueId(), status);
1272 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1274 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1275 if (status != JanusGraphOperationStatus.OK) {
1276 log.debug("Failed to disassociate calculated requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1277 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1279 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1280 if (status != JanusGraphOperationStatus.OK) {
1281 log.debug("Failed to disassociate full filled requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1282 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1284 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1285 if (status != JanusGraphOperationStatus.OK) {
1286 log.debug("Failed to disassociate instance artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1287 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1289 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1290 if (status != JanusGraphOperationStatus.OK) {
1291 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1292 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1294 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.FORWARDING_PATH);
1295 if (status != JanusGraphOperationStatus.OK) {
1296 log.debug("Failed to disassociate service api artifacts for {} error {}", toscaElementVertex.getUniqueId(), status);
1297 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1299 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INTERFACE);
1300 if (status != JanusGraphOperationStatus.OK) {
1301 log.debug("Failed to disassociate interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1302 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1304 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INSTANCE_ARTIFACTS);
1305 if (status != JanusGraphOperationStatus.OK) {
1306 log.debug("Failed to disassociate instance artifact for {} error {}", toscaElementVertex.getUniqueId(), status);
1307 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1310 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1311 EdgeLabelEnum.REQUIREMENTS);
1312 if (status != JanusGraphOperationStatus.OK) {
1313 log.debug("Failed to disassociate requirements for {} error {}",
1314 toscaElementVertex.getUniqueId(), status);
1315 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1317 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT,
1318 EdgeLabelEnum.CAPABILITIES);
1319 if (status != JanusGraphOperationStatus.OK) {
1320 log.debug("Failed to disassociate capabilities for {} error {}",
1321 toscaElementVertex.getUniqueId(), status);
1322 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1324 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1325 if (status != JanusGraphOperationStatus.OK) {
1326 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1327 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1329 toscaElementVertex.getVertex().remove();
1330 log.trace("Tosca element vertex for {} was removed", toscaElementVertex.getUniqueId());
1335 @SuppressWarnings("unchecked")
1337 public Either<TopologyTemplate, StorageOperationStatus> createToscaElement(ToscaElement toscaElement) {
1338 return createTopologyTemplate((TopologyTemplate) toscaElement);
1342 protected <T extends ToscaElement> JanusGraphOperationStatus setCategoriesFromGraph(GraphVertex vertexComponent, T toscaElement) {
1343 return setTopologyTempalteCategoriesFromGraph(vertexComponent, toscaElement);
1347 protected <T extends ToscaElement> StorageOperationStatus validateCategories(T toscaElementToUpdate, GraphVertex elementV) {
1348 // Product isn't supported now!!
1349 // TODO add for Product
1350 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1351 return validateServiceCategory(toscaElementToUpdate, elementV);
1354 return validateResourceCategory(toscaElementToUpdate, elementV);
1359 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1360 // not relevant now for topology template
1361 return StorageOperationStatus.OK;
1365 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1366 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1369 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1370 StorageOperationStatus status = StorageOperationStatus.OK;
1371 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1372 CategoryDefinition newCategory = newCategoryList.get(0);
1374 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao.getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1375 if (childVertex.isRight()) {
1376 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(), childVertex.right().value());
1377 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1380 GraphVertex categoryV = childVertex.left().value();
1381 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1382 String categoryNameCurrent = (String) metadataProperties.get(GraphPropertyEnum.NAME);
1384 String newCategoryName = newCategory.getName();
1385 if (newCategoryName != null && !newCategoryName.equals(categoryNameCurrent)) {
1386 // the category was changed
1387 Either<GraphVertex, StorageOperationStatus> getCategoryVertex = categoryOperation.getCategory(newCategoryName, VertexTypeEnum.SERVICE_CATEGORY);
1389 if (getCategoryVertex.isRight()) {
1390 return getCategoryVertex.right().value();
1392 GraphVertex newCategoryV = getCategoryVertex.left().value();
1393 status = moveCategoryEdge(elementV, newCategoryV);
1394 log.debug("Going to update the category of the resource from {} to {}. status is {}", categoryNameCurrent, newCategory, status);
1399 public Either<GraphVertex, StorageOperationStatus> updateDistributionStatus(String uniqueId, User user, DistributionStatusEnum distributionStatus) {
1401 Either<GraphVertex, StorageOperationStatus> result = null;
1402 String userId = user.getUserId();
1403 Either<GraphVertex, JanusGraphOperationStatus> getRes = findUserVertex(userId);
1404 GraphVertex userVertex = null;
1405 GraphVertex serviceVertex = null;
1406 if (getRes.isRight()) {
1407 JanusGraphOperationStatus status = getRes.right().value();
1408 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Cannot find user {} in the graph. status is {}", userId, status);
1409 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1411 if (result == null) {
1412 userVertex = getRes.left().value();
1413 getRes = janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.ParseMetadata);
1414 if (getRes.isRight()) {
1415 JanusGraphOperationStatus status = getRes.right().value();
1416 log.debug( "Cannot find service {} in the graph. status is {}", uniqueId, status);
1417 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1420 if (result == null) {
1421 serviceVertex = getRes.left().value();
1422 Iterator<Edge> edgeIterator = serviceVertex.getVertex().edges(Direction.IN, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER.name());
1423 if (edgeIterator.hasNext()) {
1424 log.debug("Remove existing edge from user to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1425 edgeIterator.next().remove();
1428 if (result == null) {
1429 JanusGraphOperationStatus status = janusGraphDao.createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1430 if (status != JanusGraphOperationStatus.OK) {
1431 log.debug( "Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1432 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1435 if (result == null) {
1436 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1437 long lastUpdateDate = System.currentTimeMillis();
1438 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1439 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1440 if (updateRes.isRight()) {
1441 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1444 if (result == null) {
1445 result = Either.left(serviceVertex);
1450 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1451 * @param componentId
1453 * @param capabilityName
1454 * @param capabilityType
1458 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityName, String capabilityType, String ownerId) {
1460 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1461 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1462 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1463 if (componentByLabelAndId.isRight()) {
1464 result = Either.right(componentByLabelAndId.right().value());
1466 if(componentByLabelAndId.isLeft()){
1467 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1468 if (getDataRes.isRight()) {
1469 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1471 mapPropertiesDataDefinition = getDataRes.left().value();
1474 if(isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)){
1475 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId, mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1480 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId, MapCapabilityProperty instanceProperties) {
1481 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instanceProperties, componentInstanceId);
1484 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent,
1485 String componentInstanceId,
1486 MapInterfaceDataDefinition instanceInterfaces) {
1487 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1488 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(),
1489 EdgeLabelEnum.INST_INTERFACES, instanceInterfaces, componentInstanceId);
1491 return StorageOperationStatus.OK;
1495 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1496 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) &&
1497 instanceId != null &&
1498 mapPropertiesDataDefinition.get(instanceId) != null &&
1499 MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1502 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType, String ownerId, Map<String, MapPropertiesDataDefinition> propertiesMap) {
1503 List<ComponentInstanceProperty> capPropsList = null;
1504 for(Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()){
1505 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1506 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1507 if (capMap != null && !capMap.isEmpty()) {
1508 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1513 if(capPropsList == null){
1514 capPropsList = new ArrayList<>();
1516 return capPropsList;
1519 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId, Entry<String, MapPropertiesDataDefinition> capProp) {
1520 if (capProp != null) {
1521 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM );
1522 if (path.length < 4) {
1523 log.debug("wrong key format for capabilty, key {}", capProp);
1526 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0].equals(instanceId);
1531 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1532 fillPolicyDefinition(componentV, policyDefinition, counter);
1533 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1536 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1537 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1540 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1541 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition, JsonPresentationFields.UNIQUE_ID);
1544 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1545 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions, JsonPresentationFields.UNIQUE_ID);
1548 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1549 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
1552 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1553 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition, JsonPresentationFields.CI_INVARIANT_NAME);
1556 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1557 String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME), policyDefinition.getPolicyTypeName(), counter);
1558 policyDefinition.setName(policyName);
1559 policyDefinition.setInvariantName(policyName);
1560 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1561 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1562 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1563 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1566 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
1567 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
1568 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
1569 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
1572 void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1573 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1574 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1576 .on(this::throwStorageException);
1577 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1578 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1580 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1581 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1583 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1584 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1585 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1589 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1590 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())){
1591 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1593 .on(this::throwStorageException);
1594 if(MapUtils.isNotEmpty(toscaElement.getComponentInstances())){
1595 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(), this::getOriginToscaElement));
1597 if(MapUtils.isNotEmpty(toscaElement.getGroups())){
1598 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver.updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1600 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES, toscaElement.getCalculatedCapabilities());
1601 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS, toscaElement.getCalculatedRequirements());
1602 topologyTemplateOperation.updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, toscaElement.getCalculatedCapabilitiesProperties());
1606 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1607 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1608 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1609 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1610 if(elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE){
1611 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1614 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1616 if(getOriginRes.isRight()){
1617 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1618 throw new StorageException(getOriginRes.right().value());
1620 return getOriginRes.left().value();
1623 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1624 log.debug("#detectToscaType - type: {}", originType);
1625 if(originType == OriginTypeEnum.VFC
1626 || originType == OriginTypeEnum.CP
1627 || originType == OriginTypeEnum.VL
1628 || originType == OriginTypeEnum.Configuration
1629 || originType == OriginTypeEnum.VFCMT){
1630 return ToscaElementTypeEnum.NODE_TYPE;
1632 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1636 private ComponentParametersView getFilter() {
1637 ComponentParametersView filter = new ComponentParametersView();
1638 filter.setIgnoreCapabilities(false);
1639 filter.setIgnoreCapabiltyProperties(false);
1640 filter.setIgnoreRequirements(false);
1643 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1644 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse)
1645 .left().on(this::throwStorageException);
1646 updateCapOwnerId(toscaElement, componentId);
1647 updateReqOwnerId(toscaElement, componentId);
1648 updatePropertiesOwnerId(toscaElement, componentId);
1649 topologyTemplateOperation
1651 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES,
1652 VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1653 topologyTemplateOperation
1654 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS,
1655 VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1656 topologyTemplateOperation
1657 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES,
1658 VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1661 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1662 if(MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1663 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1664 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1668 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1669 if(MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1670 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1671 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1675 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1676 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1677 if(MapUtils.isNotEmpty(properties)) {
1678 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));