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=========================================================
20 package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
22 import com.google.gson.reflect.TypeToken;
23 import fj.data.Either;
24 import java.lang.reflect.Type;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
30 import java.util.Map.Entry;
31 import java.util.Optional;
32 import java.util.stream.Collectors;
33 import org.apache.commons.collections.MapUtils;
34 import org.apache.commons.lang3.StringUtils;
35 import org.apache.tinkerpop.gremlin.structure.Direction;
36 import org.apache.tinkerpop.gremlin.structure.Edge;
37 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
38 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
39 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
40 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
41 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
42 import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
50 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
51 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.MapAttributesDataDefinition;
57 import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
58 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
59 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
60 import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
61 import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
62 import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition;
63 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
64 import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
65 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
66 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
67 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
68 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
69 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
70 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
71 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
72 import org.openecomp.sdc.be.model.Component;
73 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
74 import org.openecomp.sdc.be.model.ComponentParametersView;
75 import org.openecomp.sdc.be.model.DistributionStatusEnum;
76 import org.openecomp.sdc.be.model.GroupDefinition;
77 import org.openecomp.sdc.be.model.PolicyDefinition;
78 import org.openecomp.sdc.be.model.User;
79 import org.openecomp.sdc.be.model.category.CategoryDefinition;
80 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
81 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
82 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
83 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.CapabilityRequirementNameResolver;
84 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
85 import org.openecomp.sdc.be.model.operations.StorageException;
86 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
87 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
88 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
89 import org.openecomp.sdc.common.api.Constants;
90 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
91 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
92 import org.openecomp.sdc.common.log.elements.ErrorLogOptionalData;
93 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
94 import org.openecomp.sdc.common.log.wrappers.Logger;
95 import org.openecomp.sdc.common.util.ValidationUtils;
96 import org.springframework.beans.factory.annotation.Autowired;
98 @org.springframework.stereotype.Component("topology-template-operation")
99 public class TopologyTemplateOperation extends ToscaElementOperation {
101 private static final Logger log = Logger.getLogger(TopologyTemplateOperation.class);
103 private ArchiveOperation archiveOperation;
105 public static String buildSubComponentName(String componentName, String subComponentTypeName, int counter) {
106 String normalizedComponentName = ValidationUtils.normalizeComponentInstanceName(componentName);
107 String typeSuffix = subComponentTypeName.substring(subComponentTypeName.lastIndexOf('.') + 1, subComponentTypeName.length());
108 return normalizedComponentName + Constants.GROUP_POLICY_NAME_DELIMETER + typeSuffix + Constants.GROUP_POLICY_NAME_DELIMETER + counter;
111 public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
112 if (topologyTemplate.getUUID() == null) {
113 topologyTemplate.generateUUID();
115 topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
116 String resourceUniqueId = topologyTemplate.getUniqueId();
117 if (resourceUniqueId == null) {
118 resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
119 topologyTemplate.setUniqueId(resourceUniqueId);
121 GraphVertex topologyTemplateVertex = new GraphVertex();
122 topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
123 Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
124 if (createdVertex.isRight()) {
125 JanusGraphOperationStatus status = createdVertex.right().value();
126 log.debug("Error returned after creating topology template data node {}. status returned is ", topologyTemplateVertex, status);
127 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
129 StorageOperationStatus assosiateCommon = assosiateCommonForToscaElement(topologyTemplateVertex, topologyTemplate);
130 if (assosiateCommon != StorageOperationStatus.OK) {
131 return Either.right(assosiateCommon);
133 StorageOperationStatus associateCategory = assosiateMetadataToCategory(topologyTemplateVertex, topologyTemplate);
134 if (associateCategory != StorageOperationStatus.OK) {
135 return Either.right(associateCategory);
137 StorageOperationStatus associateInputs = associateInputsToComponent(topologyTemplateVertex, topologyTemplate);
138 if (associateInputs != StorageOperationStatus.OK) {
139 return Either.right(associateInputs);
141 StorageOperationStatus associateGroups = associateGroupsToComponent(topologyTemplateVertex, topologyTemplate);
142 if (associateGroups != StorageOperationStatus.OK) {
143 return Either.right(associateGroups);
145 StorageOperationStatus associatePolicies = associatePoliciesToComponent(topologyTemplateVertex, topologyTemplate);
146 if (associatePolicies != StorageOperationStatus.OK) {
147 return Either.right(associatePolicies);
149 StorageOperationStatus associateInstAttr = associateInstAttributesToComponent(topologyTemplateVertex, topologyTemplate);
150 if (associateInstAttr != StorageOperationStatus.OK) {
151 return Either.right(associateInstAttr);
153 StorageOperationStatus associateInstProperties = associateInstPropertiesToComponent(topologyTemplateVertex, topologyTemplate);
154 if (associateInstProperties != StorageOperationStatus.OK) {
155 return Either.right(associateInstProperties);
157 StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
158 if (associateInstInputs != StorageOperationStatus.OK) {
159 return Either.right(associateInstInputs);
161 StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
162 if (associateInstGroups != StorageOperationStatus.OK) {
163 return Either.right(associateInstInputs);
165 StorageOperationStatus associateRequirements = associateRequirementsToResource(topologyTemplateVertex, topologyTemplate);
166 if (associateRequirements != StorageOperationStatus.OK) {
167 return Either.right(associateRequirements);
169 StorageOperationStatus associateCapabilities = associateCapabilitiesToResource(topologyTemplateVertex, topologyTemplate);
170 if (associateCapabilities != StorageOperationStatus.OK) {
171 return Either.right(associateCapabilities);
173 StorageOperationStatus associateArtifacts = associateTopologyTemplateArtifactsToComponent(topologyTemplateVertex, topologyTemplate);
174 if (associateArtifacts != StorageOperationStatus.OK) {
175 return Either.right(associateArtifacts);
177 StorageOperationStatus addAdditionalInformation = addAdditionalInformationToResource(topologyTemplateVertex, topologyTemplate);
178 if (addAdditionalInformation != StorageOperationStatus.OK) {
179 return Either.right(addAdditionalInformation);
181 StorageOperationStatus associateCapProperties = associateCapPropertiesToResource(topologyTemplateVertex, topologyTemplate);
182 if (associateCapProperties != StorageOperationStatus.OK) {
183 return Either.right(associateCapProperties);
185 StorageOperationStatus associateInterfaces = associateInterfacesToComponent(topologyTemplateVertex, topologyTemplate);
186 if (associateInterfaces != StorageOperationStatus.OK) {
187 return Either.right(associateInterfaces);
189 StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
190 if (associatePathProperties != StorageOperationStatus.OK) {
191 return Either.right(associatePathProperties);
193 StorageOperationStatus associateNodeFilterToComponent = associateNodeFilterToComponent(topologyTemplateVertex, topologyTemplate);
194 if (associateNodeFilterToComponent != StorageOperationStatus.OK) {
195 return Either.right(associateNodeFilterToComponent);
197 final StorageOperationStatus associateServiceToModel = associateComponentToModel(topologyTemplateVertex, topologyTemplate,
198 EdgeLabelEnum.MODEL);
199 if (associateServiceToModel != StorageOperationStatus.OK) {
200 return Either.right(associateServiceToModel);
202 return Either.left(topologyTemplate);
205 private StorageOperationStatus associatePoliciesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
206 Map<String, PolicyDataDefinition> policies = topologyTemplate.getPolicies();
207 if (policies != null && !policies.isEmpty()) {
208 policies.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
209 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
212 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.POLICIES,
213 EdgeLabelEnum.POLICIES, policies);
214 if (assosiateElementToData.isRight()) {
215 return assosiateElementToData.right().value();
218 return StorageOperationStatus.OK;
221 private StorageOperationStatus associateForwardingPathToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
222 Map<String, ForwardingPathDataDefinition> forwardingPaths = topologyTemplate.getForwardingPaths();
223 return associateForwardingPathToComponent(topologyTemplateVertex, forwardingPaths);
226 private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
227 Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties();
228 if (MapUtils.isNotEmpty(calculatedCapProperties)) {
229 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(topologyTemplateVertex,
230 VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties);
231 if (associateElementToData.isRight()) {
232 return associateElementToData.right().value();
235 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties();
236 if (MapUtils.isNotEmpty(capabilitiesProperties)) {
237 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(topologyTemplateVertex,
238 VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties);
239 if (associateElementToData.isRight()) {
240 return associateElementToData.right().value();
243 return StorageOperationStatus.OK;
246 private StorageOperationStatus associateCapabilitiesToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
247 Map<String, MapListCapabilityDataDefinition> calculatedCapabilities = topologyTemplate.getCalculatedCapabilities();
248 if (calculatedCapabilities != null && !calculatedCapabilities.isEmpty()) {
249 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
250 VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calculatedCapabilities);
251 if (assosiateElementToData.isRight()) {
252 return assosiateElementToData.right().value();
255 Map<String, MapListCapabilityDataDefinition> fullfilledCapabilities = topologyTemplate.getFullfilledCapabilities();
256 if (fullfilledCapabilities != null && !fullfilledCapabilities.isEmpty()) {
257 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
258 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 = associateElementToData(nodeTypeVertex, VertexTypeEnum.CAPABILITIES,
266 EdgeLabelEnum.CAPABILITIES, capabilities);
267 if (associateElementToData.isRight()) {
268 return associateElementToData.right().value();
271 return StorageOperationStatus.OK;
274 private StorageOperationStatus associateRequirementsToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
275 Map<String, MapListRequirementDataDefinition> calculatedRequirements = topologyTemplate.getCalculatedRequirements();
276 if (calculatedRequirements != null && !calculatedRequirements.isEmpty()) {
277 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
278 VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calculatedRequirements);
279 if (assosiateElementToData.isRight()) {
280 return assosiateElementToData.right().value();
283 Map<String, MapListRequirementDataDefinition> fullfilledRequirements = topologyTemplate.getFullfilledRequirements();
284 if (fullfilledRequirements != null && !fullfilledRequirements.isEmpty()) {
285 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
286 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 = associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
294 EdgeLabelEnum.REQUIREMENTS, requirements);
295 if (associateElementToData.isRight()) {
296 return associateElementToData.right().value();
299 return StorageOperationStatus.OK;
302 private StorageOperationStatus associateTopologyTemplateArtifactsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
303 Map<String, ArtifactDataDefinition> addInformation = topologyTemplate.getServiceApiArtifacts();
304 if (addInformation != null && !addInformation.isEmpty()) {
305 addInformation.values().stream().filter(a -> a.getUniqueId() == null).forEach(a -> {
306 String uniqueId = UniqueIdBuilder
307 .buildPropertyUniqueId(nodeTypeVertex.getUniqueId().toLowerCase(), a.getArtifactLabel().toLowerCase());
308 a.setUniqueId(uniqueId);
310 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
311 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();
317 if (instArtifacts != null && !instArtifacts.isEmpty()) {
318 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
319 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();
325 if (instInfoArtifacts != null && !instInfoArtifacts.isEmpty()) {
326 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
327 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 = associateElementToData(nodeTypeVertex, VertexTypeEnum.REQUIREMENTS,
335 EdgeLabelEnum.REQUIREMENTS, requirements);
336 if (associateElementToData.isRight()) {
337 return associateElementToData.right().value();
340 return StorageOperationStatus.OK;
343 private StorageOperationStatus addAdditionalInformationToResource(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
344 Map<String, AdditionalInfoParameterDataDefinition> addInformation = topologyTemplate.getAdditionalInformation();
345 if (addInformation != null && !addInformation.isEmpty()) {
346 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
347 VertexTypeEnum.ADDITIONAL_INFORMATION, EdgeLabelEnum.ADDITIONAL_INFORMATION, addInformation);
348 if (assosiateElementToData.isRight()) {
349 return assosiateElementToData.right().value();
352 return StorageOperationStatus.OK;
355 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
356 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstProperties();
357 return associateInstPropertiesToComponent(nodeTypeVertex, instProps);
360 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
361 Map<String, MapPropertiesDataDefinition> instProps = topologyTemplate.getInstInputs();
362 return associateInstInputsToComponent(nodeTypeVertex, instProps);
365 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
366 Map<String, MapGroupsDataDefinition> instGroups = topologyTemplate.getInstGroups();
367 return associateInstGroupsToComponent(nodeTypeVertex, instGroups);
370 public StorageOperationStatus associateInstPropertiesToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instProps) {
371 if (instProps != null && !instProps.isEmpty()) {
372 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
373 VertexTypeEnum.INST_PROPERTIES, EdgeLabelEnum.INST_PROPERTIES, instProps);
374 if (assosiateElementToData.isRight()) {
375 return assosiateElementToData.right().value();
378 return StorageOperationStatus.OK;
381 public StorageOperationStatus associateInstInputsToComponent(GraphVertex nodeTypeVertex, Map<String, MapPropertiesDataDefinition> instInputs) {
382 if (instInputs != null && !instInputs.isEmpty()) {
383 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_INPUTS,
384 EdgeLabelEnum.INST_INPUTS, instInputs);
385 if (assosiateElementToData.isRight()) {
386 return assosiateElementToData.right().value();
389 return StorageOperationStatus.OK;
392 public StorageOperationStatus associateInstInterfacesToComponent(
393 GraphVertex nodeTypeVertex,
394 Map<String, MapInterfaceDataDefinition> instInterfaces
396 if (instInterfaces != null && !instInterfaces.isEmpty()) {
397 Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(
399 VertexTypeEnum.INST_INTERFACES,
400 EdgeLabelEnum.INST_INTERFACES,
402 if (associateElementToData.isRight()) {
403 return associateElementToData.right().value();
406 return StorageOperationStatus.OK;
409 public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
410 if (instGroups != null && !instGroups.isEmpty()) {
411 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS,
412 EdgeLabelEnum.INST_GROUPS, instGroups);
413 if (assosiateElementToData.isRight()) {
414 return assosiateElementToData.right().value();
417 return StorageOperationStatus.OK;
420 protected StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex,
421 Map<String, MapArtifactDataDefinition> instArtifacts) {
422 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS,
423 EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
426 public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex,
427 Map<String, MapArtifactDataDefinition> instArtifacts) {
428 return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS,
429 EdgeLabelEnum.INSTANCE_ARTIFACTS);
432 private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps,
433 VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
434 if (instProps != null && !instProps.isEmpty()) {
435 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, vertexType, edgeLabel,
437 if (assosiateElementToData.isRight()) {
438 return assosiateElementToData.right().value();
441 return StorageOperationStatus.OK;
444 public StorageOperationStatus associateOrAddCalcCapReqToComponent(GraphVertex nodeTypeVertex,
445 Map<String, MapListRequirementDataDefinition> calcRequirements,
446 Map<String, MapListCapabilityDataDefinition> calcCapabilty,
447 Map<String, MapCapabilityProperty> calculatedCapabilitiesProperties) {
448 if (!MapUtils.isEmpty(calcRequirements)) {
449 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex,
450 VertexTypeEnum.CALCULATED_REQUIREMENTS, EdgeLabelEnum.CALCULATED_REQUIREMENTS, calcRequirements);
451 if (assosiateElementToData.isRight()) {
452 return assosiateElementToData.right().value();
454 Map<String, MapListRequirementDataDefinition> fullFilled = new HashMap<>();
455 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_REQUIREMENTS,
456 EdgeLabelEnum.FULLFILLED_REQUIREMENTS, fullFilled);
457 if (assosiateElementToData.isRight()) {
458 return assosiateElementToData.right().value();
461 if (!MapUtils.isEmpty(calcCapabilty)) {
462 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateOrAddElementToData(nodeTypeVertex,
463 VertexTypeEnum.CALCULATED_CAPABILITIES, EdgeLabelEnum.CALCULATED_CAPABILITIES, calcCapabilty);
464 if (assosiateElementToData.isRight()) {
465 return assosiateElementToData.right().value();
467 Map<String, MapListCapabilityDataDefinition> fullFilled = new HashMap<>();
468 assosiateElementToData = associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.FULLFILLED_CAPABILITIES,
469 EdgeLabelEnum.FULLFILLED_CAPABILITIES, fullFilled);
470 if (assosiateElementToData.isRight()) {
471 return assosiateElementToData.right().value();
474 if (!MapUtils.isEmpty(calculatedCapabilitiesProperties)) {
475 return associateOrAddElementToData(nodeTypeVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES,
476 calculatedCapabilitiesProperties).right().on(v -> StorageOperationStatus.OK);
478 return StorageOperationStatus.OK;
481 private <T extends MapDataDefinition> Either<GraphVertex, StorageOperationStatus> associateOrAddElementToData(GraphVertex nodeTypeVertex,
482 VertexTypeEnum vertexTypeEnum,
483 EdgeLabelEnum edgeLabelEnum,
484 Map<String, T> dataMap) {
485 return janusGraphDao.getChildVertex(nodeTypeVertex, edgeLabelEnum, JsonParseFlagEnum.ParseJson)
486 .either(dataVertex -> addElementsToComponent(nodeTypeVertex, dataVertex, vertexTypeEnum, edgeLabelEnum, dataMap),
487 status -> associateElementToDataIfNotFound(status, nodeTypeVertex, vertexTypeEnum, edgeLabelEnum, dataMap));
490 private Either<GraphVertex, StorageOperationStatus> associateElementToDataIfNotFound(JanusGraphOperationStatus status, GraphVertex nodeTypeVertex,
491 VertexTypeEnum vertexTypeEnum, EdgeLabelEnum edgeLabelEnum,
492 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,
500 GraphVertex dataVertex,
501 VertexTypeEnum vertexTypeEnum,
502 EdgeLabelEnum edgeLabelEnum,
503 Map<String, T> dataMap) {
504 Optional<StorageOperationStatus> error = dataMap.entrySet().stream()
505 .map(e -> addElementToComponent(nodeTypeVertex.getUniqueId(), vertexTypeEnum, edgeLabelEnum, e))
506 .filter(s -> s != StorageOperationStatus.OK).findFirst();
507 if (error.isPresent()) {
508 return Either.right(error.get());
510 return Either.left(dataVertex);
513 private StorageOperationStatus associateInstAttributesToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
514 Map<String, MapAttributesDataDefinition> instAttr = topologyTemplate.getInstAttributes();
515 return associateInstAttributeToComponent(nodeTypeVertex, instAttr);
518 public StorageOperationStatus associateForwardingPathToComponent(GraphVertex nodeTypeVertex,
519 Map<String, ForwardingPathDataDefinition> forwardingPathMap) {
520 if (forwardingPathMap != null && !forwardingPathMap.isEmpty()) {
521 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
522 VertexTypeEnum.FORWARDING_PATH, EdgeLabelEnum.FORWARDING_PATH, forwardingPathMap);
523 if (assosiateElementToData.isRight()) {
524 return assosiateElementToData.right().value();
527 return StorageOperationStatus.OK;
530 public StorageOperationStatus associateInstAttributeToComponent(GraphVertex nodeTypeVertex, Map<String, MapAttributesDataDefinition> instAttr) {
531 if (instAttr != null && !instAttr.isEmpty()) {
532 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex,
533 VertexTypeEnum.INST_ATTRIBUTES, EdgeLabelEnum.INST_ATTRIBUTES, instAttr);
534 if (assosiateElementToData.isRight()) {
535 return assosiateElementToData.right().value();
538 return StorageOperationStatus.OK;
541 public StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, GroupDataDefinition> groups) {
542 if (groups != null && !groups.isEmpty()) {
543 groups.values().stream().filter(p -> p.getUniqueId() == null).forEach(p -> {
544 String uid = UniqueIdBuilder.buildGroupingUid(nodeTypeVertex.getUniqueId(), p.getName());
547 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.GROUPS,
548 EdgeLabelEnum.GROUPS, groups);
549 if (assosiateElementToData.isRight()) {
550 return assosiateElementToData.right().value();
553 return StorageOperationStatus.OK;
556 private StorageOperationStatus associateGroupsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
557 return associateGroupsToComponent(nodeTypeVertex, topologyTemplate.getGroups());
560 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
561 Map<String, PropertyDataDefinition> inputs = topologyTemplate.getInputs();
562 return associateInputsToComponent(nodeTypeVertex, inputs, topologyTemplate.getUniqueId());
565 public StorageOperationStatus associateInputsToComponent(GraphVertex nodeTypeVertex, Map<String, PropertyDataDefinition> inputs, String id) {
566 if (inputs != null && !inputs.isEmpty()) {
567 inputs.values().stream().filter(e -> e.getUniqueId() == null)
568 .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
569 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INPUTS,
570 EdgeLabelEnum.INPUTS, inputs);
571 if (assosiateElementToData.isRight()) {
572 return assosiateElementToData.right().value();
575 return StorageOperationStatus.OK;
578 public StorageOperationStatus associateOutputsToComponent(final GraphVertex nodeTypeVertex,
579 final Map<String, ? extends AttributeDataDefinition> outputs,
581 if (MapUtils.isNotEmpty(outputs)) {
582 outputs.values().stream().filter(e -> e.getUniqueId() == null)
583 .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
584 final Either<GraphVertex, StorageOperationStatus> associateElementToData
585 = associateElementToData(nodeTypeVertex, VertexTypeEnum.OUTPUTS, EdgeLabelEnum.OUTPUTS, outputs);
586 if (associateElementToData.isRight()) {
587 return associateElementToData.right().value();
590 return StorageOperationStatus.OK;
593 private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
594 nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
595 fillCommonMetadata(nodeTypeVertex, topologyTemplate);
596 if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
597 nodeTypeVertex.setJson(topologyTemplate.getCompositions());
599 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
600 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_VERSION_UUID,
601 topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_VERSION_ID));
602 nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS,
603 topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
604 return nodeTypeVertex;
607 private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
608 if (topologyTemplate.getResourceType() == null) {
610 return associateServiceMetadataToCategory(nodeTypeVertex, topologyTemplate);
613 return assosiateResourceMetadataToCategory(nodeTypeVertex, topologyTemplate);
617 private StorageOperationStatus associateServiceMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
618 String categoryName = topologyTemplate.getCategories().get(0).getName();
619 Either<GraphVertex, StorageOperationStatus> category = categoryOperation.getCategory(categoryName,
620 VertexTypeEnum.SERVICE_CATEGORY);
621 if (category.isRight()) {
622 log.trace("NO category {} for service {}", categoryName, topologyTemplate.getUniqueId());
623 return StorageOperationStatus.CATEGORY_NOT_FOUND;
625 GraphVertex categoryV = category.left().value();
626 JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(nodeTypeVertex, categoryV, EdgeLabelEnum.CATEGORY, new HashMap<>());
627 if (createEdge != JanusGraphOperationStatus.OK) {
628 log.trace("Failed to associate resource {} to category {} with id {}", topologyTemplate.getUniqueId(), categoryName,
629 categoryV.getUniqueId());
630 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createEdge);
632 return StorageOperationStatus.OK;
636 public Either<ToscaElement, StorageOperationStatus> getToscaElement(String uniqueId, ComponentParametersView componentParametersView) {
637 JsonParseFlagEnum parseFlag = componentParametersView.detectParseFlag();
638 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(uniqueId, ToscaElementTypeEnum.TOPOLOGY_TEMPLATE,
640 if (componentByLabelAndId.isRight()) {
641 return Either.right(componentByLabelAndId.right().value());
643 GraphVertex componentV = componentByLabelAndId.left().value();
644 return getToscaElement(componentV, componentParametersView);
647 // -------------------------------------------------------------
648 public Either<ToscaElement, StorageOperationStatus> getToscaElement(GraphVertex componentV, ComponentParametersView componentParametersView) {
649 TopologyTemplate toscaElement;
650 toscaElement = convertToTopologyTemplate(componentV);
651 JanusGraphOperationStatus status;
652 if (!componentParametersView.isIgnoreUsers()) {
653 status = setCreatorFromGraph(componentV, toscaElement);
654 if (status != JanusGraphOperationStatus.OK) {
655 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
657 status = setLastModifierFromGraph(componentV, toscaElement);
658 if (status != JanusGraphOperationStatus.OK) {
659 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
662 if (!componentParametersView.isIgnoreCategories()) {
663 status = setTopologyTempalteCategoriesFromGraph(componentV, toscaElement);
664 if (status != JanusGraphOperationStatus.OK) {
665 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
668 if (!componentParametersView.isIgnoreArtifacts()) {
669 JanusGraphOperationStatus storageStatus = setAllArtifactsFromGraph(componentV, toscaElement);
670 if (storageStatus != JanusGraphOperationStatus.OK) {
671 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
674 if (!componentParametersView.isIgnoreComponentInstancesProperties()) {
675 status = setComponentInstancesPropertiesFromGraph(componentV, toscaElement);
676 if (status != JanusGraphOperationStatus.OK) {
677 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
680 if (!componentParametersView.isIgnoreComponentInstancesAttributes()) {
681 status = setComponentInstancesAttributesFromGraph(componentV, toscaElement);
682 if (status != JanusGraphOperationStatus.OK) {
683 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
686 if (!componentParametersView.isIgnoreCapabilities()) {
687 status = setCapabilitiesFromGraph(componentV, toscaElement);
688 if (status != JanusGraphOperationStatus.OK) {
689 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
692 if (!componentParametersView.isIgnoreRequirements()) {
693 status = setRequirementsFromGraph(componentV, toscaElement);
694 if (status != JanusGraphOperationStatus.OK) {
695 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
698 if (!componentParametersView.isIgnoreAllVersions()) {
699 status = setAllVersions(componentV, toscaElement);
700 if (status != JanusGraphOperationStatus.OK) {
701 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
704 if (!componentParametersView.isIgnoreAdditionalInformation()) {
705 status = setAdditionalInformationFromGraph(componentV, toscaElement);
706 if (status != JanusGraphOperationStatus.OK) {
707 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
710 if (!componentParametersView.isIgnoreGroups()) {
711 status = setGroupsFromGraph(componentV, toscaElement);
712 if (status != JanusGraphOperationStatus.OK) {
713 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
716 if (!componentParametersView.isIgnorePolicies()) {
717 status = setPoliciesFromGraph(componentV, toscaElement);
718 if (status != JanusGraphOperationStatus.OK) {
719 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
722 if (!componentParametersView.isIgnoreComponentInstances()) {
723 status = setInstGroupsFromGraph(componentV, toscaElement);
724 //Mark all CIs that has archived origins
725 archiveOperation.setArchivedOriginsFlagInComponentInstances(componentV);
726 if (status != JanusGraphOperationStatus.OK) {
727 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
730 if (!componentParametersView.isIgnoreInputs()) {
731 status = setInputsFromGraph(componentV, toscaElement);
732 if (status != JanusGraphOperationStatus.OK) {
733 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
736 if (!componentParametersView.isIgnoreOutputs()) {
737 final JanusGraphOperationStatus storageStatus = setOutputsFromGraph(componentV, toscaElement);
738 if (storageStatus != JanusGraphOperationStatus.OK) {
739 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
742 if (!componentParametersView.isIgnoreProperties()) {
743 status = setPropertiesFromGraph(componentV, toscaElement);
744 if (status != JanusGraphOperationStatus.OK) {
745 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
748 if (!componentParametersView.isIgnoreComponentInstancesInputs()) {
749 status = setComponentInstancesInputsFromGraph(componentV, toscaElement);
750 if (status != JanusGraphOperationStatus.OK) {
751 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
754 if (!componentParametersView.isIgnoreCapabiltyProperties()) {
755 status = setComponentInstancesCapPropertiesFromGraph(componentV, toscaElement);
756 if (status != JanusGraphOperationStatus.OK) {
757 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
760 if (!componentParametersView.isIgnoreServicePath()) {
761 status = setForwardingGraphPropertiesFromGraph(componentV, toscaElement);
762 if (status != JanusGraphOperationStatus.OK) {
763 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
766 if (!componentParametersView.isIgnoreNodeFilter()) {
767 status = setNodeFilterComponentFromGraph(componentV, toscaElement);
768 if (status != JanusGraphOperationStatus.OK) {
769 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
772 if (!componentParametersView.isIgnoreSubstitutionFilter()) {
773 status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement);
774 if (status != JanusGraphOperationStatus.OK) {
775 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
778 if (!componentParametersView.isIgnoreInterfaces()) {
779 JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement);
780 if (storageStatus != JanusGraphOperationStatus.OK) {
781 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
784 if (!componentParametersView.isIgnoreComponentInstancesInterfaces()) {
785 JanusGraphOperationStatus storageStatus = setComponentInstancesInterfacesFromGraph(componentV, toscaElement);
786 if (storageStatus != JanusGraphOperationStatus.OK) {
787 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
790 if (!componentParametersView.isIgnoreDataType()) {
791 JanusGraphOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
792 if (storageStatus != JanusGraphOperationStatus.OK) {
793 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(storageStatus));
796 return Either.left(toscaElement);
799 private JanusGraphOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
800 Either<Map<String, DataTypeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
801 if (result.isLeft()) {
802 toscaElement.setDataTypes(result.left().value());
804 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
805 return result.right().value();
808 return JanusGraphOperationStatus.OK;
811 private JanusGraphOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
812 Either<Map<String, PolicyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
813 if (result.isLeft()) {
814 toscaElement.setPolicies(result.left().value());
816 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
817 return result.right().value();
820 return JanusGraphOperationStatus.OK;
823 private JanusGraphOperationStatus setInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
824 Either<Map<String, InterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INTERFACE);
825 if (result.isLeft()) {
826 topologyTemplate.setInterfaces(result.left().value());
828 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
829 return result.right().value();
832 return JanusGraphOperationStatus.OK;
835 private JanusGraphOperationStatus setComponentInstancesInterfacesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
836 Either<Map<String, MapInterfaceDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
837 EdgeLabelEnum.INST_INTERFACES);
838 if (result.isLeft()) {
839 result.left().value().entrySet().forEach(entry -> topologyTemplate.addComponentInstanceInterfaceMap(entry.getKey(), entry.getValue()));
841 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
842 return result.right().value();
845 return JanusGraphOperationStatus.OK;
848 private StorageOperationStatus associateInterfacesToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
849 Map<String, InterfaceDataDefinition> interfaceMap = topologyTemplate.getInterfaces();
850 if (interfaceMap != null && !interfaceMap.isEmpty()) {
851 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex,
852 VertexTypeEnum.INTERFACE, EdgeLabelEnum.INTERFACE, interfaceMap);
853 if (assosiateElementToData.isRight()) {
854 return assosiateElementToData.right().value();
857 return StorageOperationStatus.OK;
860 private StorageOperationStatus associateNodeFilterToComponent(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) {
861 Map<String, CINodeFilterDataDefinition> nodeFilterComponents = topologyTemplate.getNodeFilterComponents();
862 if (MapUtils.isNotEmpty(nodeFilterComponents)) {
863 Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex,
864 VertexTypeEnum.INTERFACE, EdgeLabelEnum.NODE_FILTER_TEMPLATE, nodeFilterComponents);
865 if (assosiateElementToData.isRight()) {
866 return assosiateElementToData.right().value();
869 return StorageOperationStatus.OK;
872 private JanusGraphOperationStatus setForwardingGraphPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
873 Either<Map<String, ForwardingPathDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
874 EdgeLabelEnum.FORWARDING_PATH);
875 if (result.isLeft()) {
876 topologyTemplate.setForwardingPaths(result.left().value());
878 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
879 return result.right().value();
882 return JanusGraphOperationStatus.OK;
885 private JanusGraphOperationStatus setComponentInstancesCapPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
886 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
887 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
888 if (result.isLeft()) {
889 topologyTemplate.setCalculatedCapabilitiesProperties(result.left().value());
891 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
892 return result.right().value();
895 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> capPropResult = getDataFromGraph(componentV,
896 EdgeLabelEnum.CAPABILITIES_PROPERTIES);
897 if (capPropResult.isLeft()) {
898 topologyTemplate.setCapabilitiesProperties(capPropResult.left().value());
900 if (capPropResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
901 return capPropResult.right().value();
904 return JanusGraphOperationStatus.OK;
907 private JanusGraphOperationStatus setPropertiesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
908 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.PROPERTIES);
909 if (result.isLeft()) {
910 toscaElement.setProperties(result.left().value());
912 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
913 return result.right().value();
916 return JanusGraphOperationStatus.OK;
919 private JanusGraphOperationStatus setInstGroupsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
920 Either<Map<String, MapGroupsDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_GROUPS);
921 if (result.isLeft()) {
922 topologyTemplate.setInstGroups(result.left().value());
924 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
925 return result.right().value();
928 return JanusGraphOperationStatus.OK;
931 private JanusGraphOperationStatus setComponentInstancesPropertiesFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
932 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
933 EdgeLabelEnum.INST_PROPERTIES);
934 if (result.isLeft()) {
935 topologyTemplate.setInstProperties(result.left().value());
937 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
938 return result.right().value();
941 return JanusGraphOperationStatus.OK;
944 private JanusGraphOperationStatus setComponentInstancesAttributesFromGraph(final GraphVertex componentV,
945 final TopologyTemplate topologyTemplate) {
946 final Either<Map<String, MapAttributesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
947 EdgeLabelEnum.INST_ATTRIBUTES);
948 if (result.isLeft()) {
949 topologyTemplate.setInstAttributes(result.left().value());
950 } else if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
951 return result.right().value();
953 return JanusGraphOperationStatus.OK;
956 private JanusGraphOperationStatus setComponentInstancesInputsFromGraph(GraphVertex componentV, TopologyTemplate topologyTemplate) {
957 Either<Map<String, MapPropertiesDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INST_INPUTS);
958 if (result.isLeft()) {
959 topologyTemplate.setInstInputs(result.left().value());
961 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
962 return result.right().value();
965 return JanusGraphOperationStatus.OK;
968 private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) {
969 final Either<Map<String, CINodeFilterDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
970 EdgeLabelEnum.NODE_FILTER_TEMPLATE);
971 if (result.isLeft()) {
972 topologyTemplate.setNodeFilterComponents(result.left().value());
974 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
975 return result.right().value();
978 return JanusGraphOperationStatus.OK;
981 private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV, final TopologyTemplate topologyTemplate) {
982 final Either<Map<String, SubstitutionFilterDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
983 EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE);
984 if (result.isLeft()) {
985 final Map<String, SubstitutionFilterDataDefinition> filters = result.left().value();
986 if (MapUtils.isEmpty(filters)) {
987 return JanusGraphOperationStatus.OK;
989 if (filters.values().size() > 1) {
990 log.error(EcompLoggerErrorCode.DATA_ERROR, TopologyTemplateOperation.class.getName(),
991 (ErrorLogOptionalData) null, "Only a single substitution filter is expected, but got '{}'", filters.values().size());
992 return JanusGraphOperationStatus.GENERAL_ERROR;
994 topologyTemplate.setSubstitutionFilters(new SubstitutionFilterDataDefinition(filters.values().iterator().next()));
996 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
997 return result.right().value();
1000 return JanusGraphOperationStatus.OK;
1004 protected <T extends ToscaElement> JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) {
1005 Either<Map<String, MapListRequirementDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
1006 EdgeLabelEnum.CALCULATED_REQUIREMENTS);
1007 if (result.isLeft()) {
1008 ((TopologyTemplate) toscaElement).setCalculatedRequirements(result.left().value());
1010 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1011 return result.right().value();
1014 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_REQUIREMENTS);
1015 if (result.isLeft()) {
1016 ((TopologyTemplate) toscaElement).setFullfilledRequirements(result.left().value());
1018 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1019 return result.right().value();
1022 Either<Map<String, ListRequirementDataDefinition>, JanusGraphOperationStatus> requirementResult = getDataFromGraph(componentV,
1023 EdgeLabelEnum.REQUIREMENTS);
1024 if (requirementResult.isLeft()) {
1025 toscaElement.setRequirements(requirementResult.left().value());
1027 if (requirementResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1028 return requirementResult.right().value();
1031 return JanusGraphOperationStatus.OK;
1034 protected <T extends ToscaElement> JanusGraphOperationStatus setCapabilitiesFromGraph(GraphVertex componentV, T toscaElement) {
1035 Either<Map<String, MapListCapabilityDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
1036 EdgeLabelEnum.CALCULATED_CAPABILITIES);
1037 if (result.isLeft()) {
1038 ((TopologyTemplate) toscaElement).setCalculatedCapabilities(result.left().value());
1040 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1041 return result.right().value();
1044 result = getDataFromGraph(componentV, EdgeLabelEnum.FULLFILLED_CAPABILITIES);
1045 if (result.isLeft()) {
1046 ((TopologyTemplate) toscaElement).setFullfilledCapabilities(result.left().value());
1048 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1049 return result.right().value();
1052 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV,
1053 EdgeLabelEnum.CAPABILITIES);
1054 if (capabilitiesResult.isLeft()) {
1055 toscaElement.setCapabilities(capabilitiesResult.left().value());
1057 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1058 return capabilitiesResult.right().value();
1061 return JanusGraphOperationStatus.OK;
1064 private JanusGraphOperationStatus setAllArtifactsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1065 JanusGraphOperationStatus storageStatus = setArtifactsFromGraph(componentV, toscaElement);
1066 if (storageStatus != JanusGraphOperationStatus.OK) {
1067 return storageStatus;
1069 Either<Map<String, ArtifactDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV,
1070 EdgeLabelEnum.SERVICE_API_ARTIFACTS);
1071 if (result.isLeft()) {
1072 toscaElement.setServiceApiArtifacts(result.left().value());
1074 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1075 return result.right().value();
1078 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> resultInstArt = getDataFromGraph(componentV,
1079 EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
1080 if (resultInstArt.isLeft()) {
1081 toscaElement.setInstDeploymentArtifacts(resultInstArt.left().value());
1083 if (resultInstArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1084 return resultInstArt.right().value();
1087 Either<Map<String, MapArtifactDataDefinition>, JanusGraphOperationStatus> instanceArt = getDataFromGraph(componentV,
1088 EdgeLabelEnum.INSTANCE_ARTIFACTS);
1089 if (instanceArt.isLeft()) {
1090 toscaElement.setInstanceArtifacts(instanceArt.left().value());
1092 if (instanceArt.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1093 return instanceArt.right().value();
1096 return JanusGraphOperationStatus.OK;
1099 private JanusGraphOperationStatus setInputsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1100 Either<Map<String, PropertyDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.INPUTS);
1101 if (result.isLeft()) {
1102 toscaElement.setInputs(result.left().value());
1104 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1105 return result.right().value();
1108 Either<Map<String, ListCapabilityDataDefinition>, JanusGraphOperationStatus> capabilitiesResult = getDataFromGraph(componentV,
1109 EdgeLabelEnum.CAPABILITIES);
1110 if (capabilitiesResult.isLeft()) {
1111 toscaElement.setCapabilities(capabilitiesResult.left().value());
1113 if (capabilitiesResult.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1114 return capabilitiesResult.right().value();
1117 return JanusGraphOperationStatus.OK;
1120 private JanusGraphOperationStatus setOutputsFromGraph(final GraphVertex componentV, final TopologyTemplate toscaElement) {
1121 final Either<Map<String, AttributeDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.OUTPUTS);
1122 if (result.isLeft()) {
1123 toscaElement.setOutputs(result.left().value());
1125 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1126 return result.right().value();
1129 return JanusGraphOperationStatus.OK;
1132 private JanusGraphOperationStatus setGroupsFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
1133 Either<Map<String, GroupDataDefinition>, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.GROUPS);
1134 if (result.isLeft()) {
1135 toscaElement.setGroups(result.left().value());
1137 if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) {
1138 return result.right().value();
1141 return JanusGraphOperationStatus.OK;
1144 private JanusGraphOperationStatus setTopologyTempalteCategoriesFromGraph(GraphVertex componentV, ToscaElement toscaElement) {
1145 List<CategoryDefinition> categories = new ArrayList<>();
1146 switch (componentV.getType()) {
1148 return setResourceCategoryFromGraph(componentV, toscaElement);
1150 return setServiceCategoryFromGraph(componentV, toscaElement, categories);
1152 log.debug("Not supported component type {} ", componentV.getType());
1155 return JanusGraphOperationStatus.OK;
1158 private JanusGraphOperationStatus setServiceCategoryFromGraph(GraphVertex componentV, ToscaElement toscaElement,
1159 List<CategoryDefinition> categories) {
1160 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao
1161 .getChildVertex(componentV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1162 if (childVertex.isRight()) {
1163 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, componentV.getUniqueId(),
1164 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 Object useServiceSubstitutionForNestedServices = metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
1174 category.setUseServiceSubstitutionForNestedServices(
1175 useServiceSubstitutionForNestedServices != null && (boolean) useServiceSubstitutionForNestedServices);
1176 Type listTypeCat = new TypeToken<List<String>>() {
1178 category.setNotApplicableMetadataKeys(
1179 (getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.NOT_APPLICABLE_METADATA_KEYS.getProperty()), listTypeCat)));
1180 List<String> iconsFromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
1181 category.setIcons(iconsFromJsonCat);
1182 category.setModels((getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.MODEL.getProperty()), listTypeCat)));
1183 final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {
1185 final List<MetadataKeyDataDefinition> metadataKeysfromJsonCat = getGson()
1186 .fromJson((String) metadataProperties.get(GraphPropertyEnum.METADATA_KEYS), metadataKeysTypeCat);
1187 category.setMetadataKeys(metadataKeysfromJsonCat);
1188 categories.add(category);
1189 toscaElement.setCategories(categories);
1190 return JanusGraphOperationStatus.OK;
1193 @SuppressWarnings("unchecked")
1194 private TopologyTemplate convertToTopologyTemplate(GraphVertex componentV) {
1195 TopologyTemplate topologyTemplate = super.convertToComponent(componentV);
1196 Map<String, CompositionDataDefinition> json = (Map<String, CompositionDataDefinition>) componentV.getJson();
1197 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));
1222 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_OUTPUTS);
1223 if (status != JanusGraphOperationStatus.OK) {
1224 log.debug("Failed to disassociate instances outputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1225 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1227 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.GROUPS);
1228 if (status != JanusGraphOperationStatus.OK) {
1229 log.debug("Failed to disassociate groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1230 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1232 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.POLICIES);
1233 if (status != JanusGraphOperationStatus.OK) {
1234 log.debug("Failed to disassociate policies for {} error {}", toscaElementVertex.getUniqueId(), status);
1235 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1237 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_GROUPS);
1238 if (status != JanusGraphOperationStatus.OK) {
1239 log.debug("Failed to disassociate instance groups for {} error {}", toscaElementVertex.getUniqueId(), status);
1240 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1242 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INPUTS);
1243 if (status != JanusGraphOperationStatus.OK) {
1244 log.debug("Failed to disassociate inputs for {} error {}", toscaElementVertex.getUniqueId(), status);
1245 Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1247 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.OUTPUTS);
1248 if (status != JanusGraphOperationStatus.OK) {
1249 log.debug("Failed to disassociate outputs 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));
1312 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.REQUIREMENTS);
1313 if (status != JanusGraphOperationStatus.OK) {
1314 log.debug("Failed to disassociate requirements for {} error {}", toscaElementVertex.getUniqueId(), status);
1315 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1317 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES);
1318 if (status != JanusGraphOperationStatus.OK) {
1319 log.debug("Failed to disassociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1320 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1322 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.INST_INTERFACES);
1323 if (status != JanusGraphOperationStatus.OK) {
1324 log.debug("Failed to disassociate instances interfaces for {} error {}", toscaElementVertex.getUniqueId(), status);
1325 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1327 status = janusGraphDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.NODE_FILTER_TEMPLATE);
1328 if (status != JanusGraphOperationStatus.OK) {
1329 log.debug("Failed to disassociate capabilities for {} error {}", toscaElementVertex.getUniqueId(), status);
1330 return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1333 toscaElementVertex.getVertex().remove();
1334 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!!
1353 // TODO add for Product
1354 if (toscaElementToUpdate.getComponentType() == ComponentTypeEnum.SERVICE) {
1355 return validateServiceCategory(toscaElementToUpdate, elementV);
1358 return validateResourceCategory(toscaElementToUpdate, elementV);
1363 protected <T extends ToscaElement> StorageOperationStatus updateDerived(T toscaElementToUpdate, GraphVertex updateElementV) {
1364 // not relevant now for topology template
1365 return StorageOperationStatus.OK;
1369 public <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T toscaElementToUpdate, JsonParseFlagEnum flag) {
1370 fillMetadata(elementV, (TopologyTemplate) toscaElementToUpdate, flag);
1373 private <T extends ToscaElement> StorageOperationStatus validateServiceCategory(T toscaElementToUpdate, GraphVertex elementV) {
1374 StorageOperationStatus status = StorageOperationStatus.OK;
1375 List<CategoryDefinition> newCategoryList = toscaElementToUpdate.getCategories();
1376 CategoryDefinition newCategory = newCategoryList.get(0);
1377 Either<GraphVertex, JanusGraphOperationStatus> childVertex = janusGraphDao
1378 .getChildVertex(elementV, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse);
1379 if (childVertex.isRight()) {
1380 log.debug("failed to fetch {} for tosca element with id {}, error {}", EdgeLabelEnum.CATEGORY, elementV.getUniqueId(),
1381 childVertex.right().value());
1382 return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childVertex.right().value());
1384 GraphVertex categoryV = childVertex.left().value();
1385 Map<GraphPropertyEnum, Object> metadataProperties = categoryV.getMetadataProperties();
1386 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
1391 .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,
1403 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,
1428 EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1429 edgeIterator.next().remove();
1432 if (result == null) {
1433 JanusGraphOperationStatus status = janusGraphDao
1434 .createEdge(userVertex, serviceVertex, EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER, null);
1435 if (status != JanusGraphOperationStatus.OK) {
1436 log.debug("Failed to associate user {} to component {}. Edge type is {}", userId, uniqueId,
1437 EdgeLabelEnum.LAST_DISTRIBUTION_STATE_MODIFIER);
1438 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
1441 if (result == null) {
1442 serviceVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, distributionStatus.name());
1443 long lastUpdateDate = System.currentTimeMillis();
1444 serviceVertex.setJsonMetadataField(JsonPresentationFields.LAST_UPDATE_DATE, lastUpdateDate);
1445 Either<GraphVertex, JanusGraphOperationStatus> updateRes = janusGraphDao.updateVertex(serviceVertex);
1446 if (updateRes.isRight()) {
1447 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateRes.right().value()));
1450 if (result == null) {
1451 result = Either.left(serviceVertex);
1457 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
1459 * @param componentId
1461 * @param capabilityName
1462 * @param capabilityType
1466 public Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties(String componentId,
1468 String capabilityName,
1469 String capabilityType,
1471 Either<List<ComponentInstanceProperty>, StorageOperationStatus> result = null;
1472 Map<String, MapCapabilityProperty> mapPropertiesDataDefinition = null;
1473 Either<GraphVertex, StorageOperationStatus> componentByLabelAndId = getComponentByLabelAndId(componentId,
1474 ToscaElementTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.NoParse);
1475 if (componentByLabelAndId.isRight()) {
1476 result = Either.right(componentByLabelAndId.right().value());
1478 if (componentByLabelAndId.isLeft()) {
1479 Either<Map<String, MapCapabilityProperty>, JanusGraphOperationStatus> getDataRes = getDataFromGraph(componentByLabelAndId.left().value(),
1480 EdgeLabelEnum.CALCULATED_CAP_PROPERTIES);
1481 if (getDataRes.isRight()) {
1482 result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getDataRes.right().value()));
1484 mapPropertiesDataDefinition = getDataRes.left().value();
1487 if (isNotEmptyMapOfProperties(instanceId, mapPropertiesDataDefinition)) {
1488 result = Either.left(findComponentInstanceCapabilityProperties(instanceId, capabilityName, capabilityType, ownerId,
1489 mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition()));
1494 public StorageOperationStatus updateComponentInstanceCapabilityProperties(Component containerComponent, String componentInstanceId,
1495 MapCapabilityProperty instanceProperties) {
1496 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.CALCULATED_CAP_PROPERTIES,
1497 instanceProperties, componentInstanceId);
1500 public StorageOperationStatus updateComponentInstanceInterfaces(Component containerComponent, String componentInstanceId,
1501 MapInterfaceDataDefinition instanceInterfaces) {
1502 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1503 return updateToscaDataDeepElementsBlockToToscaElement(containerComponent.getUniqueId(), EdgeLabelEnum.INST_INTERFACES, instanceInterfaces,
1504 componentInstanceId);
1506 return StorageOperationStatus.OK;
1510 public StorageOperationStatus updateComponentInterfaces(final String componentId, final MapInterfaceDataDefinition instanceInterfaces,
1511 final String componentInterfaceUpdatedKey) {
1512 if (MapUtils.isNotEmpty(instanceInterfaces.getMapToscaDataDefinition())) {
1513 return updateToscaDataDeepElementsBlockToToscaElement(componentId, EdgeLabelEnum.INTERFACE_ARTIFACTS, instanceInterfaces,
1514 componentInterfaceUpdatedKey);
1516 return StorageOperationStatus.OK;
1519 private boolean isNotEmptyMapOfProperties(String instanceId, Map<String, MapCapabilityProperty> mapPropertiesDataDefinition) {
1520 return MapUtils.isNotEmpty(mapPropertiesDataDefinition) && instanceId != null && mapPropertiesDataDefinition.get(instanceId) != null
1521 && MapUtils.isNotEmpty(mapPropertiesDataDefinition.get(instanceId).getMapToscaDataDefinition());
1524 private List<ComponentInstanceProperty> findComponentInstanceCapabilityProperties(String instanceId, String capabilityName, String capabilityType,
1526 Map<String, MapPropertiesDataDefinition> propertiesMap) {
1527 List<ComponentInstanceProperty> capPropsList = null;
1528 for (Entry<String, MapPropertiesDataDefinition> capProp : propertiesMap.entrySet()) {
1529 if (isBelongingPropertyMap(instanceId, capabilityName, capabilityType, ownerId, capProp)) {
1530 Map<String, PropertyDataDefinition> capMap = capProp.getValue().getMapToscaDataDefinition();
1531 if (capMap != null && !capMap.isEmpty()) {
1532 capPropsList = capMap.values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList());
1537 if (capPropsList == null) {
1538 capPropsList = new ArrayList<>();
1540 return capPropsList;
1543 private boolean isBelongingPropertyMap(String instanceId, String capabilityName, String capabilityType, String ownerId,
1544 Entry<String, MapPropertiesDataDefinition> capProp) {
1545 if (capProp != null) {
1546 String[] path = capProp.getKey().split(ModelConverter.CAP_PROP_DELIM);
1547 if (path.length < 4) {
1548 log.debug("wrong key format for capabilty, key {}", capProp);
1551 return path[path.length - 2].equals(capabilityType) && path[path.length - 1].equals(capabilityName) && path[1].equals(ownerId) && path[0]
1552 .equals(instanceId);
1557 public StorageOperationStatus addPolicyToToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1558 fillPolicyDefinition(componentV, policyDefinition, counter);
1559 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition,
1560 JsonPresentationFields.UNIQUE_ID);
1563 public StorageOperationStatus addPoliciesToToscaElement(GraphVertex componentV, List<PolicyDefinition> policies) {
1564 return addToscaDataToToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policies, JsonPresentationFields.UNIQUE_ID);
1567 public StorageOperationStatus updatePolicyOfToscaElement(GraphVertex componentV, PolicyDefinition policyDefinition) {
1568 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyDefinition,
1569 JsonPresentationFields.UNIQUE_ID);
1572 public StorageOperationStatus updatePoliciesOfToscaElement(GraphVertex componentV, List<PolicyDefinition> policiesDefinitions) {
1573 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policiesDefinitions,
1574 JsonPresentationFields.UNIQUE_ID);
1577 public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
1578 return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, policyId);
1581 public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
1582 return updateToscaDataOfToscaElement(componentV, EdgeLabelEnum.GROUPS, VertexTypeEnum.GROUPS, groupDefinition,
1583 JsonPresentationFields.CI_INVARIANT_NAME);
1586 private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
1587 String policyName = policyDefinition.getName();
1588 if (StringUtils.isBlank(policyName)) {
1589 policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME),
1590 policyDefinition.getPolicyTypeName(), counter);
1591 policyDefinition.setName(policyName);
1593 policyDefinition.setInvariantName(policyName);
1594 policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
1595 policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));
1596 policyDefinition.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
1597 policyDefinition.setPolicyUUID(UniqueIdBuilder.generateUUID());
1600 protected void revertNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1601 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1602 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException);
1603 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1604 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver
1605 .revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), this::getOriginToscaElement));
1607 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1608 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver
1609 .revertNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), this::getOriginToscaElement));
1611 topologyTemplateOperation
1612 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,
1613 toscaElement.getCalculatedCapabilities());
1614 topologyTemplateOperation
1615 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,
1616 toscaElement.getCalculatedRequirements());
1617 topologyTemplateOperation
1618 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
1619 toscaElement.getCalculatedCapabilitiesProperties());
1623 public void updateNamesOfCalculatedCapabilitiesRequirements(String componentId, TopologyTemplate toscaElement) {
1624 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances()) || MapUtils.isNotEmpty(toscaElement.getGroups())) {
1625 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException);
1626 if (MapUtils.isNotEmpty(toscaElement.getComponentInstances())) {
1627 toscaElement.getComponentInstances().values().forEach(i -> CapabilityRequirementNameResolver
1628 .updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, i.getUniqueId(), i.getNormalizedName(),
1629 this::getOriginToscaElement));
1631 if (MapUtils.isNotEmpty(toscaElement.getGroups())) {
1632 toscaElement.getGroups().values().forEach(g -> CapabilityRequirementNameResolver
1633 .updateNamesOfCalculatedCapabilitiesRequirements(toscaElement, g.getUniqueId(), g.getName(), this::getOriginToscaElement));
1635 topologyTemplateOperation
1636 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAPABILITIES, VertexTypeEnum.CALCULATED_CAPABILITIES,
1637 toscaElement.getCalculatedCapabilities());
1638 topologyTemplateOperation
1639 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_REQUIREMENTS, VertexTypeEnum.CALCULATED_REQUIREMENTS,
1640 toscaElement.getCalculatedRequirements());
1641 topologyTemplateOperation
1642 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, VertexTypeEnum.CALCULATED_CAP_PROPERTIES,
1643 toscaElement.getCalculatedCapabilitiesProperties());
1647 private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) {
1648 log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName());
1649 ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType());
1650 Either<ToscaElement, StorageOperationStatus> getOriginRes;
1651 if (elementType == ToscaElementTypeEnum.TOPOLOGY_TEMPLATE) {
1652 getOriginRes = this.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1654 getOriginRes = nodeTypeOperation.getToscaElement(CapabilityRequirementNameResolver.getActualComponentUid(instance), getFilter());
1656 if (getOriginRes.isRight()) {
1657 log.debug("Failed to get an origin component with uniqueId {}", CapabilityRequirementNameResolver.getActualComponentUid(instance));
1658 throw new StorageException(getOriginRes.right().value());
1660 return getOriginRes.left().value();
1663 private ToscaElementTypeEnum detectToscaType(OriginTypeEnum originType) {
1664 log.debug("#detectToscaType - type: {}", originType);
1665 if (originType == OriginTypeEnum.VFC || originType == OriginTypeEnum.CP || originType == OriginTypeEnum.VL
1666 || originType == OriginTypeEnum.Configuration || originType == OriginTypeEnum.VFCMT) {
1667 return ToscaElementTypeEnum.NODE_TYPE;
1669 return ToscaElementTypeEnum.TOPOLOGY_TEMPLATE;
1673 private ComponentParametersView getFilter() {
1674 ComponentParametersView filter = new ComponentParametersView();
1675 filter.setIgnoreCapabilities(false);
1676 filter.setIgnoreCapabiltyProperties(false);
1677 filter.setIgnoreRequirements(false);
1681 public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) {
1682 GraphVertex toscaElementV = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse).left().on(this::throwStorageException);
1683 updateCapOwnerId(toscaElement, componentId);
1684 updateReqOwnerId(toscaElement, componentId);
1685 updatePropertiesOwnerId(toscaElement, componentId);
1686 topologyTemplateOperation
1687 .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, toscaElement.getCapabilities());
1688 topologyTemplateOperation
1689 .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS, VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements());
1690 topologyTemplateOperation
1691 .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, toscaElement.getProperties());
1694 private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) {
1695 if (MapUtils.isNotEmpty(toscaElement.getCapabilities())) {
1696 toscaElement.getCapabilities().values().stream().flatMap(listCapDef -> listCapDef.getListToscaDataDefinition().stream())
1697 .forEach(capabilityDefinition -> capabilityDefinition.setOwnerId(ownerId));
1701 private void updateReqOwnerId(ToscaElement toscaElement, String ownerId) {
1702 if (MapUtils.isNotEmpty(toscaElement.getRequirements())) {
1703 toscaElement.getRequirements().values().stream().flatMap(listReqDef -> listReqDef.getListToscaDataDefinition().stream())
1704 .forEach(requirementDefinition -> requirementDefinition.setOwnerId(ownerId));
1708 private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) {
1709 Map<String, PropertyDataDefinition> properties = toscaElement.getProperties();
1710 if (MapUtils.isNotEmpty(properties)) {
1711 properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId));