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.operations.impl;
23 import com.thinkaurelius.titan.core.TitanGraph;
24 import com.thinkaurelius.titan.core.TitanVertex;
25 import fj.data.Either;
26 import java.util.HashMap;
28 import java.util.UUID;
29 import java.util.function.Supplier;
30 import org.apache.commons.lang3.tuple.ImmutablePair;
31 import org.apache.tinkerpop.gremlin.structure.Vertex;
32 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
33 import org.openecomp.sdc.be.config.BeEcompErrorManager;
34 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
35 import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
36 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
37 import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
38 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
39 import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
40 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
41 import org.openecomp.sdc.be.dao.titan.HealingTitanGenericDao;
42 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
43 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
45 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
46 import org.openecomp.sdc.be.model.ComponentInstance;
47 import org.openecomp.sdc.be.model.ComponentInstanceInput;
48 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
49 import org.openecomp.sdc.be.model.DataTypeDefinition;
50 import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement;
51 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
52 import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
53 import org.openecomp.sdc.be.model.operations.api.IInputsOperation;
54 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
55 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
56 import org.openecomp.sdc.be.resources.data.AttributeData;
57 import org.openecomp.sdc.be.resources.data.AttributeValueData;
58 import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
59 import org.openecomp.sdc.be.resources.data.InputValueData;
60 import org.openecomp.sdc.be.resources.data.InputsData;
61 import org.openecomp.sdc.common.datastructure.Wrapper;
62 import org.openecomp.sdc.common.log.wrappers.Logger;
63 import org.springframework.beans.factory.annotation.Autowired;
65 @org.springframework.stereotype.Component("component-instance-operation")
66 public class ComponentInstanceOperation extends AbstractOperation implements IComponentInstanceOperation {
68 public ComponentInstanceOperation() {
72 private static final Logger log = Logger.getLogger(ComponentInstanceOperation.class.getName());
75 PropertyOperation propertyOperation;
78 private IInputsOperation inputOperation;
81 private ApplicationDataTypeCache dataTypeCache;
86 * @param titanGenericDao
88 public void setTitanGenericDao(HealingTitanGenericDao titanGenericDao) {
89 this.titanGenericDao = titanGenericDao;
93 public Either<Integer, StorageOperationStatus> increaseAndGetResourceInstanceSpecificCounter(String resourceInstanceId, GraphPropertiesDictionary counterType, boolean inTransaction) {
95 Either<Integer, StorageOperationStatus> result = null;
98 Either<TitanGraph, TitanOperationStatus> graphResult = titanGenericDao.getGraph();
99 if (graphResult.isRight()) {
100 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(graphResult.right().value()));
103 Either<TitanVertex, TitanOperationStatus> vertexService = titanGenericDao.getVertexByProperty(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), resourceInstanceId);
104 if (vertexService.isRight()) {
105 log.debug("failed to fetch vertex of resource instance for id = {}", resourceInstanceId);
106 TitanOperationStatus status = vertexService.right().value();
107 if (status == TitanOperationStatus.NOT_FOUND) {
108 status = TitanOperationStatus.INVALID_ID;
110 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(vertexService.right().value()));
113 Vertex vertex = vertexService.left().value();
115 VertexProperty<Object> vertexProperty = vertex.property(counterType.getProperty());
117 if (vertexProperty.isPresent()) {
118 if (vertexProperty.value() != null) {
119 counter = (Integer) vertexProperty.value();
124 vertex.property(counterType.getProperty(), counter);
126 result = Either.left(counter);
130 if (!inTransaction) {
131 if (result == null || result.isRight()) {
132 log.error("increaseAndGetResourceInstanceSpecificCounter operation : Going to execute rollback on graph.");
133 titanGenericDao.rollback();
135 log.debug("increaseAndGetResourceInstanceSpecificCounter operation : Going to execute commit on graph.");
136 titanGenericDao.commit();
143 private void connectAttValueDataToComponentInstanceData(Wrapper<TitanOperationStatus> errorWrapper, ComponentInstanceData compIns, AttributeValueData attValueData) {
145 Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao.createRelation(compIns, attValueData, GraphEdgeLabels.ATTRIBUTE_VALUE, null);
147 if (createRelResult.isRight()) {
148 TitanOperationStatus operationStatus = createRelResult.right().value();
149 errorWrapper.setInnerElement(operationStatus);
150 BeEcompErrorManager.getInstance().logInternalFlowError("connectAttValueDataToComponentInstanceData",
151 "Failed to associate resource instance " + compIns.getUniqueId() + " attribute value " + attValueData.getUniqueId() + " in graph. status is " + operationStatus, ErrorSeverity.ERROR);
155 private void connectAttValueDataToAttData(Wrapper<TitanOperationStatus> errorWrapper, AttributeData attData, AttributeValueData attValueData) {
157 Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao.createRelation(attValueData, attData, GraphEdgeLabels.ATTRIBUTE_IMPL, null);
159 if (createRelResult.isRight()) {
160 TitanOperationStatus operationStatus = createRelResult.right().value();
161 BeEcompErrorManager.getInstance().logInternalFlowError("connectAttValueDataToAttData",
162 "Failed to associate attribute value " + attValueData.getUniqueId() + " to attribute " + attData.getUniqueId() + " in graph. status is " + operationStatus, ErrorSeverity.ERROR);
164 errorWrapper.setInnerElement(operationStatus);
168 private void createAttributeValueDataNode(ComponentInstanceProperty attributeInstanceProperty, Integer index, Wrapper<TitanOperationStatus> errorWrapper, ComponentInstanceData resourceInstanceData,
169 Wrapper<AttributeValueData> attValueDataWrapper) {
170 String valueUniqueUid = attributeInstanceProperty.getValueUniqueUid();
171 if (valueUniqueUid == null) {
173 String attValueDatauniqueId = UniqueIdBuilder.buildResourceInstanceAttributeValueUid(resourceInstanceData.getUniqueId(), index);
174 AttributeValueData attributeValueData = buildAttributeValueDataFromComponentInstanceAttribute(attributeInstanceProperty, attValueDatauniqueId);
176 log.debug("Before adding attribute value to graph {}", attributeValueData);
177 Either<AttributeValueData, TitanOperationStatus> createNodeResult = titanGenericDao.createNode(attributeValueData, AttributeValueData.class);
178 log.debug("After adding attribute value to graph {}", attributeValueData);
180 if (createNodeResult.isRight()) {
181 TitanOperationStatus operationStatus = createNodeResult.right().value();
182 errorWrapper.setInnerElement(operationStatus);
184 attValueDataWrapper.setInnerElement(createNodeResult.left().value());
188 BeEcompErrorManager.getInstance().logInternalFlowError("CreateAttributeValueDataNode", "attribute value already exists.", ErrorSeverity.ERROR);
189 errorWrapper.setInnerElement(TitanOperationStatus.ALREADY_EXIST);
193 private AttributeValueData buildAttributeValueDataFromComponentInstanceAttribute(ComponentInstanceProperty resourceInstanceAttribute, String uniqueId) {
194 AttributeValueData attributeValueData = new AttributeValueData();
195 attributeValueData.setUniqueId(uniqueId);
196 attributeValueData.setHidden(resourceInstanceAttribute.isHidden());
197 attributeValueData.setValue(resourceInstanceAttribute.getValue());
198 attributeValueData.setType(resourceInstanceAttribute.getType());
199 long currentTimeMillis = System.currentTimeMillis();
200 attributeValueData.setCreationTime(currentTimeMillis);
201 attributeValueData.setModificationTime(currentTimeMillis);
202 return attributeValueData;
205 private static final class UpdateDataContainer<SomeData, SomeValueData> {
206 final Wrapper<SomeValueData> valueDataWrapper;
207 final Wrapper<SomeData> dataWrapper;
208 final GraphEdgeLabels graphEdge;
209 final Supplier<Class<SomeData>> someDataClassGen;
210 final Supplier<Class<SomeValueData>> someValueDataClassGen;
211 final NodeTypeEnum nodeType;
212 final NodeTypeEnum nodeTypeValue;
214 private UpdateDataContainer(GraphEdgeLabels graphEdge, Supplier<Class<SomeData>> someDataClassGen, Supplier<Class<SomeValueData>> someValueDataClassGen, NodeTypeEnum nodeType, NodeTypeEnum nodeTypeValue) {
216 this.valueDataWrapper = new Wrapper<>();
217 this.dataWrapper = new Wrapper<>();
218 this.graphEdge = graphEdge;
219 this.someDataClassGen = someDataClassGen;
220 this.someValueDataClassGen = someValueDataClassGen;
221 this.nodeType = nodeType;
222 this.nodeTypeValue = nodeTypeValue;
225 public Wrapper<SomeValueData> getValueDataWrapper() {
226 return valueDataWrapper;
229 public Wrapper<SomeData> getDataWrapper() {
233 public GraphEdgeLabels getGraphEdge() {
237 public Supplier<Class<SomeData>> getSomeDataClassGen() {
238 return someDataClassGen;
241 public Supplier<Class<SomeValueData>> getSomeValueDataClassGen() {
242 return someValueDataClassGen;
245 public NodeTypeEnum getNodeType() {
249 public NodeTypeEnum getNodeTypeValue() {
250 return nodeTypeValue;
255 * update value of attribute on resource instance
257 * @param resourceInstanceAttribute
258 * @param resourceInstanceId
261 private Either<AttributeValueData, TitanOperationStatus> updateAttributeOfResourceInstance(ComponentInstanceProperty resourceInstanceAttribute, String resourceInstanceId) {
263 Either<AttributeValueData, TitanOperationStatus> result = null;
264 Wrapper<TitanOperationStatus> errorWrapper = new Wrapper<>();
265 UpdateDataContainer<AttributeData, AttributeValueData> updateDataContainer = new UpdateDataContainer<>(GraphEdgeLabels.ATTRIBUTE_IMPL, (() -> AttributeData.class), (() -> AttributeValueData.class), NodeTypeEnum.Attribute,
266 NodeTypeEnum.AttributeValue);
267 preUpdateElementOfResourceInstanceValidations(updateDataContainer, resourceInstanceAttribute, resourceInstanceId, errorWrapper);
268 if (errorWrapper.isEmpty()) {
269 AttributeValueData attributeValueData = updateDataContainer.getValueDataWrapper().getInnerElement();
270 attributeValueData.setHidden(resourceInstanceAttribute.isHidden());
271 attributeValueData.setValue(resourceInstanceAttribute.getValue());
272 Either<AttributeValueData, TitanOperationStatus> updateRes = titanGenericDao.updateNode(attributeValueData, AttributeValueData.class);
273 if (updateRes.isRight()) {
274 TitanOperationStatus status = updateRes.right().value();
275 errorWrapper.setInnerElement(status);
277 result = Either.left(updateRes.left().value());
280 if (!errorWrapper.isEmpty()) {
281 result = Either.right(errorWrapper.getInnerElement());
287 private Either<AttributeValueData, TitanOperationStatus> addAttributeToResourceInstance(ComponentInstanceProperty attributeInstanceProperty, String resourceInstanceId, Integer index) {
288 Wrapper<TitanOperationStatus> errorWrapper = new Wrapper<>();
289 Wrapper<ComponentInstanceData> compInsWrapper = new Wrapper<>();
290 Wrapper<AttributeData> attDataWrapper = new Wrapper<>();
291 Wrapper<AttributeValueData> attValueDataWrapper = new Wrapper<>();
294 validateRIExist(resourceInstanceId, compInsWrapper, errorWrapper);
296 if (errorWrapper.isEmpty()) {
297 // Verify Attribute Exist
298 validateElementExistInGraph(attributeInstanceProperty.getUniqueId(), NodeTypeEnum.Attribute, () -> AttributeData.class, attDataWrapper, errorWrapper);
300 if (errorWrapper.isEmpty()) {
301 // Create AttributeValueData that is connected to RI
302 createAttributeValueDataNode(attributeInstanceProperty, index, errorWrapper, compInsWrapper.getInnerElement(), attValueDataWrapper);
304 if (errorWrapper.isEmpty()) {
305 // Connect AttributeValueData (Att on RI) to AttData (Att on
307 connectAttValueDataToAttData(errorWrapper, attDataWrapper.getInnerElement(), attValueDataWrapper.getInnerElement());
309 if (errorWrapper.isEmpty()) {
310 // Connect AttributeValueData to RI
311 connectAttValueDataToComponentInstanceData(errorWrapper, compInsWrapper.getInnerElement(), attValueDataWrapper.getInnerElement());
314 if (errorWrapper.isEmpty()) {
315 return Either.left(attValueDataWrapper.getInnerElement());
317 return Either.right(errorWrapper.getInnerElement());
322 private <SomeData extends GraphNode, SomeValueData extends GraphNode> void preUpdateElementOfResourceInstanceValidations(UpdateDataContainer<SomeData, SomeValueData> updateDataContainer, IComponentInstanceConnectedElement resourceInstanceProerty,
323 String resourceInstanceId, Wrapper<TitanOperationStatus> errorWrapper) {
325 if (errorWrapper.isEmpty()) {
326 // Verify VFC instance Exist
327 validateRIExist(resourceInstanceId, errorWrapper);
330 if (errorWrapper.isEmpty()) {
331 // Example: Verify Property connected to VFC exist
332 validateElementConnectedToComponentExist(updateDataContainer, resourceInstanceProerty, errorWrapper);
335 if (errorWrapper.isEmpty()) {
336 // Example: Verify PropertyValue connected to VFC Instance exist
337 validateElementConnectedToComponentInstanceExist(updateDataContainer, resourceInstanceProerty, errorWrapper);
340 if (errorWrapper.isEmpty()) {
341 // Example: Verify PropertyValue connected Property
342 validateElementConnectedToInstance(updateDataContainer, resourceInstanceProerty, errorWrapper);
346 private <SomeData extends GraphNode, SomeValueData extends GraphNode> void validateElementConnectedToInstance(UpdateDataContainer<SomeData, SomeValueData> updateDataContainer, IComponentInstanceConnectedElement resourceInstanceProerty,
347 Wrapper<TitanOperationStatus> errorWrapper) {
348 Either<ImmutablePair<SomeData, GraphEdge>, TitanOperationStatus> child = titanGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(updateDataContainer.getNodeTypeValue()), resourceInstanceProerty.getValueUniqueUid(),
349 updateDataContainer.getGraphEdge(), updateDataContainer.getNodeType(), updateDataContainer.getSomeDataClassGen().get());
351 if (child.isRight()) {
352 TitanOperationStatus status = child.right().value();
353 if (status == TitanOperationStatus.NOT_FOUND) {
354 status = TitanOperationStatus.INVALID_ID;
356 errorWrapper.setInnerElement(status);
359 updateDataContainer.getDataWrapper().setInnerElement(child.left().value().left);
363 private <SomeValueData extends GraphNode, SomeData extends GraphNode> void validateElementConnectedToComponentInstanceExist(UpdateDataContainer<SomeData, SomeValueData> updateDataContainer,
364 IComponentInstanceConnectedElement resourceInstanceProerty, Wrapper<TitanOperationStatus> errorWrapper) {
365 String valueUniqueUid = resourceInstanceProerty.getValueUniqueUid();
366 if (valueUniqueUid == null) {
367 errorWrapper.setInnerElement(TitanOperationStatus.INVALID_ID);
369 Either<SomeValueData, TitanOperationStatus> findPropertyValueRes = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(updateDataContainer.getNodeTypeValue()), valueUniqueUid, updateDataContainer.getSomeValueDataClassGen().get());
370 if (findPropertyValueRes.isRight()) {
371 TitanOperationStatus status = findPropertyValueRes.right().value();
372 if (status == TitanOperationStatus.NOT_FOUND) {
373 status = TitanOperationStatus.INVALID_ID;
375 errorWrapper.setInnerElement(status);
377 updateDataContainer.getValueDataWrapper().setInnerElement(findPropertyValueRes.left().value());
382 private <SomeData extends GraphNode, SomeValueData extends GraphNode> void validateElementConnectedToComponentExist(UpdateDataContainer<SomeData, SomeValueData> updateDataContainer,
383 IComponentInstanceConnectedElement resourceInstanceElementConnected, Wrapper<TitanOperationStatus> errorWrapper) {
384 String uniqueId = resourceInstanceElementConnected.getUniqueId();
385 Either<SomeData, TitanOperationStatus> findPropertyDefRes = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(updateDataContainer.getNodeType()), uniqueId, updateDataContainer.getSomeDataClassGen().get());
387 if (findPropertyDefRes.isRight()) {
388 TitanOperationStatus status = findPropertyDefRes.right().value();
389 errorWrapper.setInnerElement(status);
393 private void validateRIExist(String resourceInstanceId, Wrapper<TitanOperationStatus> errorWrapper) {
394 validateRIExist(resourceInstanceId, null, errorWrapper);
397 private void validateRIExist(String resourceInstanceId, Wrapper<ComponentInstanceData> compInsDataWrapper, Wrapper<TitanOperationStatus> errorWrapper) {
398 validateElementExistInGraph(resourceInstanceId, NodeTypeEnum.ResourceInstance, () -> ComponentInstanceData.class, compInsDataWrapper, errorWrapper);
401 public <ElementData extends GraphNode> void validateElementExistInGraph(String elementUniqueId, NodeTypeEnum elementNodeType, Supplier<Class<ElementData>> elementClassGen, Wrapper<ElementData> elementDataWrapper,
402 Wrapper<TitanOperationStatus> errorWrapper) {
403 Either<ElementData, TitanOperationStatus> findResInstanceRes = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(elementNodeType), elementUniqueId, elementClassGen.get());
404 if (findResInstanceRes.isRight()) {
405 TitanOperationStatus status = findResInstanceRes.right().value();
406 if (status == TitanOperationStatus.NOT_FOUND) {
407 status = TitanOperationStatus.INVALID_ID;
409 errorWrapper.setInnerElement(status);
411 if (elementDataWrapper != null) {
412 elementDataWrapper.setInnerElement(findResInstanceRes.left().value());
418 * add property to resource instance
420 * @param resourceInstanceId
424 private Either<InputValueData, TitanOperationStatus> addInputToResourceInstance(ComponentInstanceInput resourceInstanceInput, String resourceInstanceId, Integer index) {
426 Either<ComponentInstanceData, TitanOperationStatus> findResInstanceRes = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceInstance), resourceInstanceId, ComponentInstanceData.class);
428 if (findResInstanceRes.isRight()) {
429 TitanOperationStatus status = findResInstanceRes.right().value();
430 if (status == TitanOperationStatus.NOT_FOUND) {
431 status = TitanOperationStatus.INVALID_ID;
433 return Either.right(status);
436 String propertyId = resourceInstanceInput.getUniqueId();
437 Either<InputsData, TitanOperationStatus> findPropertyDefRes = titanGenericDao.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Input), propertyId, InputsData.class);
439 if (findPropertyDefRes.isRight()) {
440 TitanOperationStatus status = findPropertyDefRes.right().value();
441 if (status == TitanOperationStatus.NOT_FOUND) {
442 status = TitanOperationStatus.INVALID_ID;
444 return Either.right(status);
447 String valueUniqueUid = resourceInstanceInput.getValueUniqueUid();
448 if (valueUniqueUid == null) {
450 InputsData propertyData = findPropertyDefRes.left().value();
452 ComponentInstanceData resourceInstanceData = findResInstanceRes.left().value();
454 ImmutablePair<TitanOperationStatus, String> isInputValueExists = inputOperation.findInputValue(resourceInstanceId, propertyId);
455 if (isInputValueExists.getLeft() == TitanOperationStatus.ALREADY_EXIST) {
456 log.debug("The property {} already added to the resource instance {}", propertyId, resourceInstanceId);
457 resourceInstanceInput.setValueUniqueUid(isInputValueExists.getRight());
460 if (isInputValueExists.getLeft() != TitanOperationStatus.NOT_FOUND) {
461 log.debug("After finding input value of {} on componenet instance {}", propertyId, resourceInstanceId);
462 return Either.right(isInputValueExists.getLeft());
465 String innerType = null;
467 PropertyDataDefinition propDataDef = propertyData.getPropertyDataDefinition();
468 String propertyType = propDataDef.getType();
469 String value = resourceInstanceInput.getValue();
470 ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
472 if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
473 SchemaDefinition def = propDataDef.getSchema();
475 log.debug("Schema doesn't exists for property of type {}", type);
476 return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
478 PropertyDataDefinition propDef = def.getProperty();
479 if (propDef == null) {
480 log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
481 return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
483 innerType = propDef.getType();
486 log.debug("Before validateAndUpdatePropertyValue");
487 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = dataTypeCache.getAll();
488 if (allDataTypes.isRight()) {
489 TitanOperationStatus status = allDataTypes.right().value();
490 BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
491 return Either.right(status);
494 String uniqueId = UniqueIdBuilder.buildResourceInstanceInputValueUid(resourceInstanceData.getUniqueId(), index);
495 InputValueData propertyValueData = new InputValueData();
496 propertyValueData.setUniqueId(uniqueId);
497 propertyValueData.setValue(value);
499 log.debug("Before validateAndUpdateRules");
500 ImmutablePair<String, Boolean> pair = propertyOperation.validateAndUpdateRules(propertyType, resourceInstanceInput.getRules(), innerType, allDataTypes.left().value(), true);
501 log.debug("After validateAndUpdateRules. pair = {} ", pair);
502 if (pair.getRight() != null && !pair.getRight()) {
503 BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(), resourceInstanceInput.getName(), propertyType);
504 return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
506 log.debug("Before adding property value to graph {}", propertyValueData);
507 Either<InputValueData, TitanOperationStatus> createNodeResult = titanGenericDao.createNode(propertyValueData, InputValueData.class);
508 log.debug("After adding property value to graph {}", propertyValueData);
510 if (createNodeResult.isRight()) {
511 TitanOperationStatus operationStatus = createNodeResult.right().value();
512 return Either.right(operationStatus);
515 Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao.createRelation(propertyValueData, propertyData, GraphEdgeLabels.INPUT_IMPL, null);
517 if (createRelResult.isRight()) {
518 TitanOperationStatus operationStatus = createRelResult.right().value();
519 log.error("Failed to associate property value {} to property {} in graph. status is {}", uniqueId, propertyId, operationStatus);
520 return Either.right(operationStatus);
523 Map<String, Object> properties1 = new HashMap<>();
525 properties1.put(GraphEdgePropertiesDictionary.NAME.getProperty(), resourceInstanceData.getComponentInstDataDefinition().getName());
526 properties1.put(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(), resourceInstanceData.getComponentInstDataDefinition().getUniqueId());
528 createRelResult = titanGenericDao.createRelation(resourceInstanceData, propertyValueData, GraphEdgeLabels.INPUT_VALUE, properties1);
530 if (createRelResult.isRight()) {
531 TitanOperationStatus operationStatus = createNodeResult.right().value();
532 log.error("Failed to associate resource instance {} property value {} in graph. status is {}", resourceInstanceId, uniqueId, operationStatus);
533 return Either.right(operationStatus);
537 return Either.left(createNodeResult.left().value());
539 log.error("property value already exists.");
540 return Either.right(TitanOperationStatus.ALREADY_EXIST);
546 public Either<ComponentInstanceProperty, StorageOperationStatus> addAttributeValueToResourceInstance(ComponentInstanceProperty resourceInstanceAttribute, String resourceInstanceId, Integer index, boolean inTransaction) {
547 Either<ComponentInstanceProperty, StorageOperationStatus> result = null;
551 Either<AttributeValueData, TitanOperationStatus> eitherStatus = this.addAttributeToResourceInstance(resourceInstanceAttribute, resourceInstanceId, index);
553 if (eitherStatus.isRight()) {
554 log.error("Failed to add attribute value {} to resource instance {} in Graph. status is {}", resourceInstanceAttribute, resourceInstanceId, eitherStatus.right().value().name());
555 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherStatus.right().value()));
558 AttributeValueData attributeValueData = eitherStatus.left().value();
560 ComponentInstanceProperty attributeValueResult = buildResourceInstanceAttribute(attributeValueData, resourceInstanceAttribute);
561 log.debug("The returned ResourceInstanceAttribute is {}", attributeValueResult);
563 result = Either.left(attributeValueResult);
569 handleTransactionCommitRollback(inTransaction, result);
573 private ComponentInstanceProperty buildResourceInstanceAttribute(AttributeValueData attributeValueData, ComponentInstanceProperty resourceInstanceAttribute) {
574 Boolean hidden = attributeValueData.isHidden();
575 String uid = attributeValueData.getUniqueId();
576 return new ComponentInstanceProperty(hidden, resourceInstanceAttribute, uid);
580 public Either<ComponentInstanceProperty, StorageOperationStatus> updateAttributeValueInResourceInstance(ComponentInstanceProperty resourceInstanceAttribute, String resourceInstanceId, boolean inTransaction) {
582 Either<ComponentInstanceProperty, StorageOperationStatus> result = null;
585 Either<AttributeValueData, TitanOperationStatus> eitherAttributeValue = updateAttributeOfResourceInstance(resourceInstanceAttribute, resourceInstanceId);
587 if (eitherAttributeValue.isRight()) {
588 log.error("Failed to add attribute value {} to resource instance {} in Graph. status is {}", resourceInstanceAttribute, resourceInstanceId, eitherAttributeValue.right().value().name());
589 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherAttributeValue.right().value()));
592 AttributeValueData attributeValueData = eitherAttributeValue.left().value();
594 ComponentInstanceProperty attributeValueResult = buildResourceInstanceAttribute(attributeValueData, resourceInstanceAttribute);
595 log.debug("The returned ResourceInstanceAttribute is {}", attributeValueResult);
597 result = Either.left(attributeValueResult);
603 handleTransactionCommitRollback(inTransaction, result);
609 public Either<ComponentInstanceInput, StorageOperationStatus> addInputValueToResourceInstance(ComponentInstanceInput resourceInstanceInput, String resourceInstanceId, Integer index, boolean inTransaction) {
612 /// Ignore rules received from client till support
613 resourceInstanceInput.setRules(null);
617 Either<ComponentInstanceInput, StorageOperationStatus> result = null;
621 Either<InputValueData, TitanOperationStatus> eitherStatus = addInputToResourceInstance(resourceInstanceInput, resourceInstanceId, index);
623 if (eitherStatus.isRight()) {
624 log.error("Failed to add input value {} to resource instance {} in Graph. status is {}", resourceInstanceInput, resourceInstanceId, eitherStatus.right().value().name());
625 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(eitherStatus.right().value()));
628 InputValueData propertyValueData = eitherStatus.left().value();
630 ComponentInstanceInput propertyValueResult = inputOperation.buildResourceInstanceInput(propertyValueData, resourceInstanceInput);
631 log.debug("The returned ResourceInstanceProperty is {}", propertyValueResult);
633 Either<String, TitanOperationStatus> findDefaultValue = propertyOperation.findDefaultValueFromSecondPosition(resourceInstanceInput.getPath(), resourceInstanceInput.getUniqueId(), resourceInstanceInput.getDefaultValue());
634 if (findDefaultValue.isRight()) {
635 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(findDefaultValue.right().value()));
638 String defaultValue = findDefaultValue.left().value();
639 propertyValueResult.setDefaultValue(defaultValue);
640 log.debug("The returned default value in ResourceInstanceProperty is {}", defaultValue);
642 result = Either.left(propertyValueResult);
648 if (!inTransaction) {
649 if (result == null || result.isRight()) {
650 log.error("Going to execute rollback on graph.");
651 titanGenericDao.rollback();
653 log.debug("Going to execute commit on graph.");
654 titanGenericDao.commit();
662 public Either<ComponentInstanceInput, StorageOperationStatus> updateInputValueInResourceInstance(ComponentInstanceInput input, String resourceInstanceId, boolean b) {
667 public StorageOperationStatus updateCustomizationUUID(String componentInstanceId) {
668 Either<TitanVertex, TitanOperationStatus> vertexByProperty = titanGenericDao.getVertexByProperty(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), componentInstanceId);
669 if (vertexByProperty.isRight()) {
670 log.debug("Failed to fetch component instance by id {} error {}", componentInstanceId, vertexByProperty.right().value());
671 return DaoStatusConverter.convertTitanStatusToStorageStatus(vertexByProperty.right().value());
673 UUID uuid = UUID.randomUUID();
674 TitanVertex ciVertex = vertexByProperty.left().value();
675 ciVertex.property(GraphPropertiesDictionary.CUSTOMIZATION_UUID.getProperty(), uuid.toString());
677 return StorageOperationStatus.OK;
681 public Either<ComponentInstanceData, StorageOperationStatus> updateComponentInstanceModificationTimeAndCustomizationUuidOnGraph(ComponentInstance componentInstance, NodeTypeEnum componentInstanceType, Long modificationTime, boolean inTransaction) {
683 log.debug("Going to update modification time of component instance {}. ", componentInstance.getName());
684 Either<ComponentInstanceData, StorageOperationStatus> result = null;
686 ComponentInstanceData componentData = new ComponentInstanceData(componentInstance, componentInstance.getGroupInstances().size());
687 componentData.getComponentInstDataDefinition().setModificationTime(modificationTime);
688 componentData.getComponentInstDataDefinition().setCustomizationUUID(UUID.randomUUID().toString());
689 Either<ComponentInstanceData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(componentData, ComponentInstanceData.class);
690 if (updateNode.isRight()) {
691 log.error("Failed to update resource {}. status is {}", componentInstance.getUniqueId(), updateNode.right().value());
692 result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value()));
694 result = Either.left(updateNode.left().value());
697 log.error("Exception occured during update modification date of compomemt instance{}. The message is {}. ", componentInstance.getName(), e.getMessage(), e);
698 result = Either.right(StorageOperationStatus.GENERAL_ERROR);
701 if (result == null || result.isRight()) {
702 log.error("Going to execute rollback on graph.");
703 titanGenericDao.rollback();
705 log.debug("Going to execute commit on graph.");
706 titanGenericDao.commit();