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.components.impl;
23 import com.google.common.collect.Sets;
24 import fj.data.Either;
25 import org.apache.commons.collections.CollectionUtils;
26 import org.apache.commons.collections.MapUtils;
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.commons.lang3.tuple.ImmutablePair;
29 import org.openecomp.sdc.be.components.impl.instance.ComponentInstanceChangeOperationOrchestrator;
30 import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceMergeDataBusinessLogic;
31 import org.openecomp.sdc.be.components.merge.instance.DataForMergeHolder;
32 import org.openecomp.sdc.be.components.validation.ComponentValidations;
33 import org.openecomp.sdc.be.config.BeEcompErrorManager;
34 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
35 import org.openecomp.sdc.be.dao.api.ActionStatus;
36 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
37 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
38 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
39 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
40 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
42 import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
43 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
44 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
46 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
47 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
48 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
49 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
50 import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
51 import org.openecomp.sdc.be.model.Component;
52 import org.openecomp.sdc.be.model.ComponentParametersView;
53 import org.openecomp.sdc.be.model.CapabilityDefinition;
54 import org.openecomp.sdc.be.model.RequirementDefinition;
55 import org.openecomp.sdc.be.model.Resource;
56 import org.openecomp.sdc.be.model.Service;
57 import org.openecomp.sdc.be.model.User;
58 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
59 import org.openecomp.sdc.be.model.LifecycleStateEnum;
60 import org.openecomp.sdc.be.model.ArtifactDefinition;
61 import org.openecomp.sdc.be.model.DataTypeDefinition;
62 import org.openecomp.sdc.be.model.PropertyDefinition;
63 import org.openecomp.sdc.be.model.GroupDefinition;
64 import org.openecomp.sdc.be.model.InputDefinition;
65 import org.openecomp.sdc.be.model.RelationshipInfo;
66 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
67 import org.openecomp.sdc.be.model.ComponentInstance;
68 import org.openecomp.sdc.be.model.ComponentInstanceInput;
69 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
70 import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames;
71 import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
72 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
73 import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
74 import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
75 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
76 import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
77 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
78 import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
79 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
80 import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
81 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
82 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
83 import org.openecomp.sdc.common.api.Constants;
84 import org.openecomp.sdc.common.datastructure.Wrapper;
85 import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
86 import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
87 import org.openecomp.sdc.common.log.wrappers.Logger;
88 import org.openecomp.sdc.common.util.ValidationUtils;
89 import org.openecomp.sdc.exception.ResponseFormat;
90 import org.springframework.beans.factory.annotation.Autowired;
92 import java.util.ArrayList;
93 import java.util.Collection;
94 import java.util.Collections;
95 import java.util.HashMap;
96 import java.util.Iterator;
97 import java.util.List;
99 import java.util.Map.Entry;
100 import java.util.Objects;
101 import java.util.Optional;
102 import java.util.Set;
103 import java.util.UUID;
104 import java.util.function.BiConsumer;
105 import java.util.stream.Collectors;
107 import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
109 @org.springframework.stereotype.Component
110 public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
112 private static final Logger log = Logger.getLogger(ComponentInstanceBusinessLogic.class.getName());
113 private static final String VF_MODULE = "org.openecomp.groups.VfModule";
114 public static final String TRY_TO_CREATE_ENTRY_ON_GRAPH = "Try to create entry on graph";
115 public static final String FAILED_TO_CREATE_ENTRY_ON_GRAPH_FOR_COMPONENT_INSTANCE = "Failed to create entry on graph for component instance {}";
116 public static final String ENTITY_ON_GRAPH_IS_CREATED = "Entity on graph is created.";
117 public static final String INVALID_COMPONENT_TYPE = "invalid component type";
118 public static final String FAILED_TO_RETRIEVE_COMPONENT_COMPONENT_ID = "Failed to retrieve component, component id {}";
119 public static final String FAILED_TO_LOCK_SERVICE = "Failed to lock service {}";
120 public static final String CREATE_OR_UPDATE_PROPERTY_VALUE = "CreateOrUpdatePropertyValue";
123 private IComponentInstanceOperation componentInstanceOperation;
126 private ArtifactsBusinessLogic artifactBusinessLogic;
129 private ComponentInstanceMergeDataBusinessLogic compInstMergeDataBL;
132 private ComponentInstanceChangeOperationOrchestrator onChangeInstanceOperationOrchestrator;
135 private ForwardingPathOperation forwardingPathOperation;
137 public ComponentInstanceBusinessLogic() {
140 public Either<ComponentInstance, ResponseFormat> createComponentInstance(
141 String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance) {
142 return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, false, true);
145 public List<ComponentInstanceProperty> getComponentInstancePropertiesByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
146 List<ComponentInstanceProperty> resList = new ArrayList<>();
147 Map<String, List<ComponentInstanceProperty>> ciPropertiesMap = component.getComponentInstancesProperties();
148 if(ciPropertiesMap != null && !ciPropertiesMap.isEmpty()){
149 ciPropertiesMap.forEach(new BiConsumer<String, List<ComponentInstanceProperty>>() {
151 public void accept(String s, List<ComponentInstanceProperty> ciPropList) {
153 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(s)).findAny();
155 ciName = ciOp.get().getName();
156 if (ciPropList != null && !ciPropList.isEmpty()) {
157 for(ComponentInstanceProperty prop: ciPropList){
158 List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
159 if(inputsValues != null && !inputsValues.isEmpty()){
160 for(GetInputValueDataDefinition inputData: inputsValues){
161 if(isGetInputValueForInput(inputData, inputId)){
162 prop.setComponentInstanceId(s);
163 prop.setComponentInstanceName(ciName);
178 public List<ComponentInstanceInput> getComponentInstanceInputsByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
179 List<ComponentInstanceInput> resList = new ArrayList<>();
180 Map<String, List<ComponentInstanceInput>> ciInputsMap = component.getComponentInstancesInputs();
181 if(ciInputsMap != null && !ciInputsMap.isEmpty()){
182 ciInputsMap.forEach(new BiConsumer<String, List<ComponentInstanceInput>>() {
184 public void accept(String s, List<ComponentInstanceInput> ciPropList) {
186 Optional<ComponentInstance> ciOp = component.getComponentInstances().stream().filter(ci ->ci.getUniqueId().equals(s)).findAny();
188 ciName = ciOp.get().getName();
189 if (ciPropList != null && !ciPropList.isEmpty()) {
190 for(ComponentInstanceInput prop: ciPropList){
191 List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
192 if(inputsValues != null && !inputsValues.isEmpty()){
193 for(GetInputValueDataDefinition inputData: inputsValues){
194 if(isGetInputValueForInput(inputData, inputId)){
195 prop.setComponentInstanceId(s);
196 prop.setComponentInstanceName(ciName);
211 public Either<ComponentInstance, ResponseFormat> createComponentInstance(
212 String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance, boolean inTransaction, boolean needLock) {
214 Component origComponent = null;
215 Either<ComponentInstance, ResponseFormat> resultOp = null;
217 org.openecomp.sdc.be.model.Component containerComponent = null;
218 ComponentTypeEnum containerComponentType;
221 user = validateUserExists(userId, "create Component Instance", inTransaction);
223 Either<Boolean, ResponseFormat> validateValidJson = validateJsonBody(resourceInstance, ComponentInstance.class);
224 if (validateValidJson.isRight()) {
225 return Either.right(validateValidJson.right().value());
228 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
229 if (validateComponentType.isRight()) {
230 return Either.right(validateComponentType.right().value());
232 containerComponentType = validateComponentType.left().value();
235 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
236 if (validateComponentExists.isRight()) {
237 return Either.right(validateComponentExists.right().value());
239 containerComponent = validateComponentExists.left().value();
242 if (ModelConverter.isAtomicComponent(containerComponent)) {
243 log.debug("Cannot attach resource instances to container resource of type {}", containerComponent.assetType());
244 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType()));
247 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
248 if (validateCanWorkOnComponent.isRight()) {
249 return Either.right(validateCanWorkOnComponent.right().value());
252 if (resourceInstance != null && containerComponentType != null) {
253 OriginTypeEnum originType = resourceInstance.getOriginType();
254 if (originType == OriginTypeEnum.ServiceProxy) {
255 Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName("serviceProxy");
256 if (serviceProxyOrigin.isRight()) {
257 log.debug("Failed to fetch normative service proxy resource by tosca name, error {}", serviceProxyOrigin.right().value());
258 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value())));
260 origComponent = serviceProxyOrigin.left().value();
262 StorageOperationStatus fillProxyRes = fillProxyInstanceData(resourceInstance, origComponent);
263 if (fillProxyRes != StorageOperationStatus.OK) {
264 log.debug("Failed to fill service proxy resource data with data from service, error {}", fillProxyRes);
265 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(fillProxyRes)));
270 Either<Component, ResponseFormat> getOriginComponentRes = getAndValidateOriginComponentOfComponentInstance(containerComponentType, resourceInstance);
272 if (getOriginComponentRes.isRight()) {
273 return Either.right(getOriginComponentRes.right().value());
275 origComponent = getOriginComponentRes.left().value();
280 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "createComponentInstance");
281 if (lockComponent.isRight()) {
282 return Either.right(lockComponent.right().value());
285 log.debug("Try to create entry on graph");
286 resultOp = createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, user);
291 unlockComponent(resultOp, containerComponent);
295 private StorageOperationStatus fillProxyInstanceData(ComponentInstance resourceInstance, Component proxyTemplate) {
296 resourceInstance.setIsProxy(true);
297 ComponentParametersView filter = new ComponentParametersView(true);
298 filter.setIgnoreCapabilities(false);
299 filter.setIgnoreCapabiltyProperties(false);
300 filter.setIgnoreComponentInstances(false);
301 filter.setIgnoreRequirements(false);
302 Either<Component, StorageOperationStatus> serviceRes = toscaOperationFacade.getToscaElement(resourceInstance.getComponentUid(), filter);
303 if (serviceRes.isRight()) {
304 return serviceRes.right().value();
306 Component service = serviceRes.left().value();
307 Map<String, List<CapabilityDefinition>> capabilities = service.getCapabilities();
308 resourceInstance.setCapabilities(capabilities);
309 Map<String, List<RequirementDefinition>> req = service.getRequirements();
310 resourceInstance.setRequirements(req);
312 String name = service.getNormalizedName() + ToscaOperationFacade.PROXY_SUFFIX;
313 String toscaResourceName = ((Resource) proxyTemplate).getToscaResourceName();
314 int lastIndexOf = toscaResourceName.lastIndexOf('.');
315 if (lastIndexOf != -1) {
316 String proxyToscaName = toscaResourceName.substring(0, lastIndexOf + 1) + name;
317 resourceInstance.setToscaComponentName(proxyToscaName);
319 resourceInstance.setName(name);
320 resourceInstance.setIsProxy(true);
321 resourceInstance.setSourceModelInvariant(service.getInvariantUUID());
322 resourceInstance.setSourceModelName(service.getName());
323 resourceInstance.setSourceModelUuid(service.getUUID());
324 resourceInstance.setSourceModelUid(service.getUniqueId());
325 resourceInstance.setComponentUid(proxyTemplate.getUniqueId());
326 resourceInstance.setDescription("A Proxy for Service " + service.getName());
327 resourceInstance.setComponentVersion(service.getVersion());
329 return StorageOperationStatus.OK;
332 public Either<CreateAndAssotiateInfo, ResponseFormat> createAndAssociateRIToRI(String containerComponentParam, String containerComponentId, String userId, CreateAndAssotiateInfo createAndAssotiateInfo) {
334 Either<CreateAndAssotiateInfo, ResponseFormat> resultOp = null;
335 ComponentInstance resourceInstance = createAndAssotiateInfo.getNode();
336 RequirementCapabilityRelDef associationInfo = createAndAssotiateInfo.getAssociate();
338 User user = validateUserExists(userId, "create And Associate RI To RI", false);
340 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
341 if (validateComponentType.isRight()) {
342 return Either.right(validateComponentType.right().value());
345 final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
347 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
348 if (validateComponentExists.isRight()) {
349 return Either.right(validateComponentExists.right().value());
351 org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
353 if (ModelConverter.isAtomicComponent(containerComponent)) {
354 log.debug("Cannot attach resource instances to container resource of type {}", containerComponent.assetType());
355 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType()));
358 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
359 if (validateCanWorkOnComponent.isRight()) {
360 return Either.right(validateCanWorkOnComponent.right().value());
363 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "createAndAssociateRIToRI");
364 if (lockComponent.isRight()) {
365 return Either.right(lockComponent.right().value());
369 log.debug("Try to create entry on graph");
370 Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(resourceInstance);
372 if (eitherResourceName.isRight()) {
373 resultOp = Either.right(eitherResourceName.right().value());
376 Component origComponent = eitherResourceName.left().value();
378 Either<ComponentInstance, ResponseFormat> result = createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, user);
379 if (result.isRight()) {
380 log.debug("Failed to create resource instance {}", containerComponentId);
381 resultOp = Either.right(result.right().value());
386 log.debug("Entity on graph is created.");
387 ComponentInstance resResourceInfo = result.left().value();
388 if (associationInfo.getFromNode() == null || associationInfo.getFromNode().isEmpty()) {
389 associationInfo.setFromNode(resResourceInfo.getUniqueId());
391 associationInfo.setToNode(resResourceInfo.getUniqueId());
394 RequirementCapabilityRelDef requirementCapabilityRelDef = associationInfo;
395 Either<RequirementCapabilityRelDef, StorageOperationStatus> resultReqCapDef = toscaOperationFacade.associateResourceInstances(containerComponentId, requirementCapabilityRelDef);
396 if (resultReqCapDef.isLeft()) {
397 log.debug("Enty on graph is created.");
398 RequirementCapabilityRelDef resReqCapabilityRelDef = resultReqCapDef.left().value();
399 CreateAndAssotiateInfo resInfo = new CreateAndAssotiateInfo(resResourceInfo, resReqCapabilityRelDef);
400 resultOp = Either.left(resInfo);
404 log.info("Failed to associate node {} with node {}", associationInfo.getFromNode(), associationInfo.getToNode());
405 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(resultReqCapDef.right().value(), true), "", null));
410 unlockComponent(resultOp, containerComponent);
414 private Either<Component, ResponseFormat> getOriginComponentFromComponentInstance(ComponentInstance componentInstance) {
415 return getOriginComponentFromComponentInstance(componentInstance.getName(), componentInstance.getComponentUid());
418 private Either<Component, ResponseFormat> getInstanceOriginNode(ComponentInstance componentInstance) {
419 return getOriginComponentFromComponentInstance(componentInstance.getName(), componentInstance.getActualComponentUid());
422 private Either<Component, ResponseFormat> getOriginComponentFromComponentInstance(String componentInstanceName, String origComponetId) {
423 Either<Component, ResponseFormat> eitherResponse;
424 Either<Component, StorageOperationStatus> eitherComponent = toscaOperationFacade.getToscaFullElement(origComponetId);
425 if (eitherComponent.isRight()) {
426 log.debug("Failed to get origin component with id {} for component instance {} ", origComponetId, componentInstanceName);
427 eitherResponse = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponse(eitherComponent.right().value(), ComponentTypeEnum.RESOURCE), "", null));
429 eitherResponse = Either.left(eitherComponent.left().value());
431 return eitherResponse;
434 private Either<ComponentInstance, ResponseFormat> createComponentInstanceOnGraph(org.openecomp.sdc.be.model.Component containerComponent, Component originComponent, ComponentInstance componentInstance, User user) {
435 Either<ComponentInstance, ResponseFormat> resultOp;
437 Either<ImmutablePair<Component, String>, StorageOperationStatus> result = toscaOperationFacade.addComponentInstanceToTopologyTemplate(containerComponent, originComponent, componentInstance, false, user);
439 if (result.isRight()) {
440 log.debug("Failed to create entry on graph for component instance {}", componentInstance.getName());
441 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), "", null));
445 log.debug("Entity on graph is created.");
446 Component updatedComponent = result.left().value().getLeft();
447 Map<String, String> existingEnvVersions = new HashMap<>();
448 // TODO existingEnvVersions ??
449 Either<ActionStatus, ResponseFormat> addComponentInstanceArtifacts = addComponentInstanceArtifacts(updatedComponent, componentInstance, originComponent, user, existingEnvVersions);
450 if (addComponentInstanceArtifacts.isRight()) {
451 log.debug("Failed to create component instance {}", componentInstance.getName());
452 resultOp = Either.right(addComponentInstanceArtifacts.right().value());
456 Optional<ComponentInstance> updatedInstanceOptional = updatedComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(result.left().value().getRight())).findFirst();
457 if (!updatedInstanceOptional.isPresent()) {
458 log.debug("Failed to fetch new added component instance {} from component {}", componentInstance.getName(), containerComponent.getName());
459 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName()));
462 resultOp = Either.left(updatedInstanceOptional.get());
467 * addResourceInstanceArtifacts - add artifacts (HEAT_ENV) to resource instance The instance artifacts are generated from the resource's artifacts
468 * @param containerComponent
469 * @param componentInstance
470 * @param originComponent
472 * @param existingEnvVersions
475 protected Either<ActionStatus, ResponseFormat> addComponentInstanceArtifacts(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance componentInstance, org.openecomp.sdc.be.model.Component originComponent, User user, Map<String, String> existingEnvVersions) {
477 log.debug("add artifacts to resource instance");
478 List<GroupDefinition> filteredGroups = null;
479 ActionStatus status = setResourceArtifactsOnResourceInstance(componentInstance);
480 if (!ActionStatus.OK.equals(status)) {
481 ResponseFormat resultOp = componentsUtils.getResponseFormatForResourceInstance(status, "", null);
482 return Either.right(resultOp);
484 StorageOperationStatus artStatus;
485 // generate heat_env if necessary
486 Map<String, ArtifactDefinition> componentDeploymentArtifacts = componentInstance.getDeploymentArtifacts();
487 if (MapUtils.isNotEmpty(componentDeploymentArtifacts)) {
489 Map<String, ArtifactDefinition> finalDeploymentArtifacts = new HashMap<String, ArtifactDefinition>();
490 Map<String, List<ArtifactDefinition>> groupInstancesArtifacts = new HashMap<>();
492 for (ArtifactDefinition artifact : componentDeploymentArtifacts.values()) {
493 String type = artifact.getArtifactType();
494 if (!type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType())) {
495 finalDeploymentArtifacts.put(artifact.getArtifactLabel(), artifact);
497 if (!(type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()))) {
500 if (artifact.checkEsIdExist()) {
501 Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactBusinessLogic.createHeatEnvPlaceHolder(artifact, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(), NodeTypeEnum.ResourceInstance,
502 componentInstance.getName(), user, containerComponent, existingEnvVersions);
503 if (createHeatEnvPlaceHolder.isRight()) {
504 return Either.right(createHeatEnvPlaceHolder.right().value());
506 ArtifactDefinition artifactDefinition = createHeatEnvPlaceHolder.left().value();
508 finalDeploymentArtifacts.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
510 if (CollectionUtils.isNotEmpty(originComponent.getGroups())) {
511 filteredGroups = originComponent.getGroups().stream().filter(g -> g.getType().equals(VF_MODULE)).collect(Collectors.toList());
513 if (CollectionUtils.isNotEmpty(filteredGroups)) {
514 for (GroupDefinition groupInstance : filteredGroups) {
515 Optional<String> op = groupInstance.getArtifacts().stream().filter(p -> p.equals(artifactDefinition.getGeneratedFromId())).findAny();
516 if (op.isPresent()) {
517 List<ArtifactDefinition> artifactsUid;
518 if (groupInstancesArtifacts.containsKey(groupInstance.getUniqueId())) {
519 artifactsUid = groupInstancesArtifacts.get(groupInstance.getUniqueId());
521 artifactsUid = new ArrayList<>();
523 artifactsUid.add(artifactDefinition);
524 groupInstancesArtifacts.put(groupInstance.getUniqueId(), artifactsUid);
531 artStatus = toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, finalDeploymentArtifacts);
532 if (artStatus != StorageOperationStatus.OK) {
533 log.debug("Failed to add instance deployment artifacts for instance {} in conatiner {} error {}", componentInstance.getUniqueId(), containerComponent.getUniqueId(), artStatus);
534 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)));
537 StorageOperationStatus result = toscaOperationFacade.addGroupInstancesToComponentInstance(containerComponent, componentInstance, filteredGroups, groupInstancesArtifacts);
538 if (result != StorageOperationStatus.OK) {
539 log.debug("failed to update group instance for component instance {}", componentInstance.getUniqueId());
540 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result)));
542 componentInstance.setDeploymentArtifacts(finalDeploymentArtifacts);
545 artStatus = toscaOperationFacade.addInformationalArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, originComponent.getArtifacts());
546 if (artStatus != StorageOperationStatus.OK) {
547 log.debug("Failed to add informational artifacts to the instance {} belonging to the conatiner {}. Status is {}", componentInstance.getUniqueId(), containerComponent.getUniqueId(), artStatus);
548 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)));
551 componentInstance.setArtifacts(originComponent.getArtifacts());
552 return Either.left(ActionStatus.OK);
555 private ActionStatus setResourceArtifactsOnResourceInstance(ComponentInstance resourceInstance) {
556 Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = artifactBusinessLogic.getArtifacts(resourceInstance.getComponentUid(), NodeTypeEnum.Resource, ArtifactGroupTypeEnum.DEPLOYMENT, null);
558 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<String, ArtifactDefinition>();
559 if (getResourceDeploymentArtifacts.isRight()) {
560 StorageOperationStatus status = getResourceDeploymentArtifacts.right().value();
561 if (!status.equals(StorageOperationStatus.NOT_FOUND)) {
562 log.debug("Failed to fetch resource: {} artifacts. status is {}", resourceInstance.getComponentUid(), status);
563 return componentsUtils.convertFromStorageResponseForResourceInstance(status, true);
566 deploymentArtifacts = getResourceDeploymentArtifacts.left().value();
569 if (!deploymentArtifacts.isEmpty()) {
570 Map<String, ArtifactDefinition> tempDeploymentArtifacts = new HashMap<String, ArtifactDefinition>(deploymentArtifacts);
571 for (Entry<String, ArtifactDefinition> artifact : deploymentArtifacts.entrySet()) {
572 if (!artifact.getValue().checkEsIdExist()) {
573 tempDeploymentArtifacts.remove(artifact.getKey());
577 resourceInstance.setDeploymentArtifacts(tempDeploymentArtifacts);
580 return ActionStatus.OK;
583 public Either<ComponentInstance, ResponseFormat> updateComponentInstanceMetadata(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance componentInstance) {
584 return updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, componentInstance, false, true, true);
587 public Either<ComponentInstance, ResponseFormat> updateComponentInstanceMetadata(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance componentInstance, boolean inTransaction,
588 boolean needLock, boolean createNewTransaction) {
590 validateUserExists(userId, "update Component Instance", inTransaction);
592 Either<ComponentInstance, ResponseFormat> resultOp = null;
594 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
595 if (validateComponentType.isRight()) {
596 return Either.right(validateComponentType.right().value());
599 final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
601 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
602 if (validateComponentExists.isRight()) {
603 return Either.right(validateComponentExists.right().value());
605 org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
607 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
608 if (validateCanWorkOnComponent.isRight()) {
609 return Either.right(validateCanWorkOnComponent.right().value());
611 ComponentTypeEnum instanceType = getComponentType(containerComponentType);
612 Either<Boolean, StorageOperationStatus> validateParentStatus = toscaOperationFacade.validateComponentExists(componentInstance.getComponentUid());
613 if (validateParentStatus.isRight()) {
614 log.debug("Failed to get component instance {} on service {}", componentInstanceId, containerComponentId);
615 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, componentInstance.getName(), instanceType.getValue().toLowerCase()));
618 if (!validateParentStatus.left().value()) {
619 resultOp = Either.right(
620 componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(), instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(), containerComponentId));
625 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "updateComponentInstance");
626 if (lockComponent.isRight()) {
627 return Either.right(lockComponent.right().value());
632 Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(componentInstance);
634 if (eitherResourceName.isRight()) {
635 resultOp = Either.right(eitherResourceName.right().value());
638 Component origComponent = eitherResourceName.left().value();
640 resultOp = updateComponentInstanceMetadata(containerComponent, containerComponentType, origComponent, componentInstanceId, componentInstance);
645 unlockComponent(resultOp, containerComponent);
649 // New Multiple Instance Update API
650 public Either<List<ComponentInstance>, ResponseFormat> updateComponentInstance(String containerComponentParam, String containerComponentId, String userId, List<ComponentInstance> componentInstanceList, boolean needLock) {
652 Either<List<ComponentInstance>, ResponseFormat> resultOp = null;
653 org.openecomp.sdc.be.model.Component containerComponent = null;
655 validateUserExists(userId, "update Component Instance", true);
657 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
658 if (validateComponentType.isRight()) {
659 return Either.right(validateComponentType.right().value());
662 final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
664 ComponentParametersView componentFilter = new ComponentParametersView();
665 componentFilter.disableAll();
666 componentFilter.setIgnoreUsers(false);
667 componentFilter.setIgnoreComponentInstances(false);
668 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExistsByFilter(containerComponentId, containerComponentType, componentFilter);
669 if (validateComponentExists.isRight()) {
670 return Either.right(validateComponentExists.right().value());
673 containerComponent = validateComponentExists.left().value();
675 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
676 if (validateCanWorkOnComponent.isRight()) {
677 return Either.right(validateCanWorkOnComponent.right().value());
680 ComponentTypeEnum instanceType = getComponentType(containerComponentType);
682 for (ComponentInstance componentInstance : componentInstanceList) {
683 boolean validateParent = validateParent(containerComponent, componentInstance.getUniqueId());
684 if (!validateParent) {
685 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(), instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(),
686 containerComponentId));
693 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "updateComponentInstance");
694 if (lockComponent.isRight()) {
695 return Either.right(lockComponent.right().value());
699 List<ComponentInstance> updatedList = new ArrayList<>();
700 List<ComponentInstance> instancesFromContainerComponent = containerComponent.getComponentInstances();
701 List<ComponentInstance> listForUpdate = new ArrayList<>();
702 if (instancesFromContainerComponent == null || instancesFromContainerComponent.isEmpty())
703 containerComponent.setComponentInstances(componentInstanceList);
705 Iterator<ComponentInstance> iterator = instancesFromContainerComponent.iterator();
706 while (iterator.hasNext()) {
707 ComponentInstance origInst = iterator.next();
708 Optional<ComponentInstance> op = componentInstanceList.stream().filter(ci -> ci.getUniqueId().equals(origInst.getUniqueId())).findAny();
709 if (op.isPresent()) {
710 ComponentInstance updatedCi = op.get();
711 updatedCi = buildComponentInstance(updatedCi, origInst);
713 Boolean isUniqueName = validateInstanceNameUniquenessUponUpdate(containerComponent, origInst, updatedCi.getName());
715 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", origInst.getName(), updatedCi.getName());
716 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), origInst.getName()));
720 listForUpdate.add(updatedCi);
722 listForUpdate.add(origInst);
724 containerComponent.setComponentInstances(listForUpdate);
726 if (resultOp == null) {
727 Either<Component, StorageOperationStatus> updateStatus = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, componentFilter);
728 if (updateStatus.isRight()) {
729 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata belonging to container component {}. Status is {}. ", containerComponent.getName(), updateStatus.right().value());
730 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(updateStatus.right().value(), true), "", null));
733 for (ComponentInstance updatedInstance : updateStatus.left().value().getComponentInstances()) {
734 Optional<ComponentInstance> op = componentInstanceList.stream().filter(ci -> ci.getName().equals(updatedInstance.getName())).findAny();
735 if (op.isPresent()) {
736 updatedList.add(updatedInstance);
742 resultOp = Either.left(updatedList);
747 unlockComponent(resultOp, containerComponent);
752 private boolean validateParent(org.openecomp.sdc.be.model.Component containerComponent, String nodeTemplateId) {
753 return containerComponent.getComponentInstances().stream().anyMatch(p -> p.getUniqueId().equals(nodeTemplateId));
756 private ComponentTypeEnum getComponentType(ComponentTypeEnum containerComponentType) {
757 if (ComponentTypeEnum.PRODUCT.equals(containerComponentType)) {
758 return ComponentTypeEnum.SERVICE_INSTANCE;
760 return ComponentTypeEnum.RESOURCE_INSTANCE;
764 private Either<ComponentInstance, ResponseFormat> updateComponentInstanceMetadata(Component containerComponent, ComponentTypeEnum containerComponentType, org.openecomp.sdc.be.model.Component origComponent, String componentInstanceId,
765 ComponentInstance componentInstance) {
767 Either<ComponentInstance, ResponseFormat> resultOp = null;
768 Optional<ComponentInstance> componentInstanceOptional = null;
769 Either<ImmutablePair<Component, String>, StorageOperationStatus> updateRes = null;
770 ComponentInstance oldComponentInstance = null;
771 boolean isNameChanged = false;
773 if (resultOp == null) {
774 componentInstanceOptional = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(componentInstance.getUniqueId())).findFirst();
775 if (!componentInstanceOptional.isPresent()) {
776 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find the component instance {} in container component {}. ", componentInstance.getName(), containerComponent.getName());
777 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName()));
780 if (resultOp == null) {
781 oldComponentInstance = componentInstanceOptional.get();
782 String newInstanceName = componentInstance.getName();
783 if (oldComponentInstance != null && oldComponentInstance.getName() != null && !oldComponentInstance.getName().equals(newInstanceName))
784 isNameChanged = true;
785 Boolean isUniqueName = validateInstanceNameUniquenessUponUpdate(containerComponent, oldComponentInstance, newInstanceName);
787 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", oldComponentInstance.getName(), newInstanceName);
788 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), componentInstance.getName()));
791 if (resultOp == null) {
792 updateRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, origComponent, updateComponentInstanceMetadata(oldComponentInstance, componentInstance));
793 if (updateRes.isRight()) {
794 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata of component instance {} belonging to container component {}. Status is {}. ", componentInstance.getName(), containerComponent.getName(),
795 updateRes.right().value());
796 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(updateRes.right().value(), true), "", null));
798 // region - Update instance Groups
800 Either result = toscaOperationFacade.cleanAndAddGroupInstancesToComponentInstance(containerComponent, oldComponentInstance, componentInstanceId);
801 if (result.isRight())
802 CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to rename group instances for container {}. error {} ", componentInstanceId, result.right().value());
807 if (resultOp == null) {
808 String newInstanceId = updateRes.left().value().getRight();
809 Optional<ComponentInstance> updatedInstanceOptional = updateRes.left().value().getLeft().getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(newInstanceId)).findFirst();
811 if (!updatedInstanceOptional.isPresent()) {
812 log.debug("Failed to update metadata of component instance {} of container component {}", componentInstance.getName(), containerComponent.getName());
813 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName()));
815 resultOp = Either.left(updatedInstanceOptional.get());
819 if (resultOp == null) {
820 resultOp = Either.left(componentInstanceOptional.get());
827 * The normalized old vf name
828 * @param newNormailzedPrefix-
829 * The normalized new vf name
830 * @param qualifiedGroupInstanceName-
831 * old Group Instance Name
833 // modify group names
834 private String getNewGroupName(String oldPrefix, String newNormailzedPrefix, String qualifiedGroupInstanceName) {
835 if (qualifiedGroupInstanceName == null) {
836 log.info("CANNOT change group name ");
839 if (qualifiedGroupInstanceName.startsWith(oldPrefix) || qualifiedGroupInstanceName.startsWith(ValidationUtils.normalizeComponentInstanceName(oldPrefix)))
840 return qualifiedGroupInstanceName.replaceFirst(oldPrefix, newNormailzedPrefix);
841 return qualifiedGroupInstanceName;
844 private ComponentInstance updateComponentInstanceMetadata(ComponentInstance oldComponentInstance, ComponentInstance newComponentInstance) {
845 oldComponentInstance.setName(newComponentInstance.getName());
846 oldComponentInstance.setModificationTime(System.currentTimeMillis());
847 oldComponentInstance.setCustomizationUUID(UUID.randomUUID().toString());
848 if (oldComponentInstance.getGroupInstances() != null)
849 oldComponentInstance.getGroupInstances().forEach(group -> group.setName(getNewGroupName(oldComponentInstance.getNormalizedName(), ValidationUtils.normalizeComponentInstanceName(newComponentInstance.getName()), group.getName())));
850 return oldComponentInstance;
853 public Either<ComponentInstance, ResponseFormat> deleteComponentInstance(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId) {
855 validateUserExists(userId, "delete Component Instance", false);
857 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
858 if (validateComponentType.isRight()) {
859 return Either.right(validateComponentType.right().value());
862 final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
863 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
864 if (validateComponentExists.isRight()) {
865 return Either.right(validateComponentExists.right().value());
867 org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
868 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
869 if (validateCanWorkOnComponent.isRight()) {
870 return Either.right(validateCanWorkOnComponent.right().value());
873 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "deleteComponentInstance");
874 if (lockComponent.isRight()) {
875 return Either.right(lockComponent.right().value());
878 Either<ComponentInstance, ResponseFormat> resultOp = null;
880 resultOp = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
881 if (resultOp.isRight()){
884 Either<ComponentInstance, ResponseFormat> deleteEither = deleteForwardingPathsRelatedTobeDeletedComponentInstance(containerComponentId,
885 containerComponentType, resultOp);
886 if (deleteEither.isRight()){
892 unlockComponent(resultOp, containerComponent);
896 public Either<ComponentInstance, ResponseFormat> deleteForwardingPathsRelatedTobeDeletedComponentInstance(String containerComponentId, ComponentTypeEnum containerComponentType,
897 Either<ComponentInstance, ResponseFormat> resultOp) {
898 if(containerComponentType.equals(ComponentTypeEnum.SERVICE) && resultOp.isLeft() ){
899 final ComponentInstance componentInstance = resultOp.left().value();
900 List<String> pathIDsToBeDeleted = getForwardingPathsRelatedToComponentInstance(containerComponentId, componentInstance.getName());
901 if (!pathIDsToBeDeleted.isEmpty()) {
902 Either<Set<String>, ResponseFormat> deleteForwardingPathsEither = deleteForwardingPaths(containerComponentId,
904 if(deleteForwardingPathsEither.isRight()) {
905 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
914 private Either<Set<String>, ResponseFormat> deleteForwardingPaths(String serviceId, List<String> pathIdsToDelete){
916 Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
917 if(storageStatus.isRight()) {
918 return Either.right(componentsUtils.getResponseFormat(storageStatus.right().value()));
920 Either<Set<String>, StorageOperationStatus> result = forwardingPathOperation.deleteForwardingPath(storageStatus.left().value(),
921 Sets.newHashSet(pathIdsToDelete));
923 if(result.isRight()) {
924 return Either.right(componentsUtils.getResponseFormat(result.right().value()));
926 return Either.left(result.left().value());
929 private List<String> getForwardingPathsRelatedToComponentInstance(String containerComponentId, String componentInstanceId){
930 ComponentParametersView filter = new ComponentParametersView(true);
931 filter.setIgnoreForwardingPath(false);
932 Either<Service, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade
933 .getToscaElement(containerComponentId, filter);
934 Collection<ForwardingPathDataDefinition> allPaths = forwardingPathOrigin.left().value().getForwardingPaths().values();
935 List<String> pathIDsToBeDeleted = new ArrayList<>();
937 allPaths.stream().filter(path -> isPathRelatedToComponent(path,componentInstanceId ))
938 .forEach(path -> pathIDsToBeDeleted.add(path.getUniqueId()));
940 return pathIDsToBeDeleted;
943 private boolean isPathRelatedToComponent(ForwardingPathDataDefinition pathDataDefinition,
944 String componentInstanceId){
945 return pathDataDefinition.getPathElements().getListToscaDataDefinition()
946 .stream().anyMatch(elementDataDefinition -> elementDataDefinition.getFromNode().equalsIgnoreCase(componentInstanceId) ||
947 elementDataDefinition.getToNode()
948 .equalsIgnoreCase(componentInstanceId));
952 private Either<ComponentInstance, ResponseFormat> deleteComponentInstance(Component containerComponent, String componentInstanceId, ComponentTypeEnum containerComponentType) {
954 Either<ComponentInstance, ResponseFormat> resultOp = null;
955 ComponentInstance deletedInstance = null;
956 Either<ImmutablePair<Component, String>, StorageOperationStatus> deleteRes = toscaOperationFacade.deleteComponentInstanceFromTopologyTemplate(containerComponent, componentInstanceId);
958 if (deleteRes.isRight()) {
959 log.debug("Failed to delete entry on graph for resourceInstance {}", componentInstanceId);
960 ActionStatus status = componentsUtils.convertFromStorageResponse(deleteRes.right().value(), containerComponentType);
961 resultOp = Either.right(componentsUtils.getResponseFormat(status, componentInstanceId));
963 if (resultOp == null) {
964 log.debug("The component instance {} has been removed from container component {}. ", componentInstanceId, containerComponent);
965 deletedInstance = findAndRemoveComponentInstanceFromContainerComponent(componentInstanceId, containerComponent);
966 resultOp = Either.left(deletedInstance);
968 if (resultOp.isLeft() && CollectionUtils.isNotEmpty(containerComponent.getGroups())) {
969 List<GroupDataDefinition> groupsToUpdate = new ArrayList<>();
970 for (GroupDataDefinition currGroup : containerComponent.getGroups()) {
971 Map<String, String> members = currGroup.getMembers();
972 if (members != null && members.containsKey(deletedInstance.getName())) {
973 members.remove(deletedInstance.getName());
974 groupsToUpdate.add(currGroup);
977 Either<List<GroupDefinition>, StorageOperationStatus> updateGroupsRes = toscaOperationFacade.updateGroupsOnComponent(containerComponent, groupsToUpdate);
978 if (updateGroupsRes.isRight()) {
979 log.debug("Failed to delete component instance {} from group members. ", componentInstanceId);
980 ActionStatus status = componentsUtils.convertFromStorageResponse(updateGroupsRes.right().value(), containerComponentType);
981 resultOp = Either.right(componentsUtils.getResponseFormat(status, componentInstanceId));
984 if (resultOp.isLeft() && CollectionUtils.isNotEmpty(containerComponent.getInputs())) {
985 List<InputDefinition> inputsToDelete = containerComponent.getInputs().stream().filter(i -> i.getInstanceUniqueId() != null && i.getInstanceUniqueId().equals(componentInstanceId)).collect(Collectors.toList());
986 if (CollectionUtils.isNotEmpty(inputsToDelete)) {
987 StorageOperationStatus deleteInputsRes = toscaOperationFacade.deleteComponentInstanceInputsFromTopologyTemplate(containerComponent, inputsToDelete);
988 if (deleteInputsRes != StorageOperationStatus.OK) {
989 log.debug("Failed to delete inputs of the component instance {} from container component. ", componentInstanceId);
990 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteInputsRes, containerComponentType), componentInstanceId));
997 private ComponentInstance findAndRemoveComponentInstanceFromContainerComponent(String componentInstanceId, Component containerComponent) {
998 ComponentInstance foundInstance = null;
999 for (ComponentInstance instance : containerComponent.getComponentInstances()) {
1000 if (instance.getUniqueId().equals(componentInstanceId)) {
1001 foundInstance = instance;
1002 containerComponent.getComponentInstances().remove(instance);
1006 findAndRemoveComponentInstanceRelations(componentInstanceId, containerComponent);
1007 return foundInstance;
1010 private void findAndRemoveComponentInstanceRelations(String componentInstanceId, Component containerComponent) {
1011 if(CollectionUtils.isNotEmpty(containerComponent.getComponentInstancesRelations())){
1012 containerComponent.setComponentInstancesRelations(containerComponent.getComponentInstancesRelations().stream().filter(r -> isNotBelongingRelation(componentInstanceId, r)).collect(Collectors.toList()));
1016 private boolean isNotBelongingRelation(String componentInstanceId, RequirementCapabilityRelDef relation) {
1017 return !relation.getToNode().equals(componentInstanceId) && !relation.getFromNode().equals(componentInstanceId);
1020 public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
1021 return associateRIToRI(componentId, userId, requirementDef, componentTypeEnum, false, true, true);
1024 public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum, boolean inTransaction, boolean needLock,
1025 boolean createNewTransaction) {
1027 validateUserExists(userId, "associate Ri To RI", inTransaction);
1029 Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
1031 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(componentId, componentTypeEnum, null);
1032 if (validateComponentExists.isRight()) {
1033 return Either.right(validateComponentExists.right().value());
1035 org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
1037 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
1038 if (validateCanWorkOnComponent.isRight()) {
1039 return Either.right(validateCanWorkOnComponent.right().value());
1042 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "associateRIToRI");
1044 if (lockComponent.isRight()) {
1045 return Either.right(lockComponent.right().value());
1051 resultOp = associateRIToRIOnGraph(validateComponentExists.left().value(), requirementDef, componentTypeEnum, inTransaction);
1057 unlockComponent(resultOp, containerComponent);
1061 public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRIOnGraph(Component containerComponent, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum, boolean inTransaction) {
1063 log.debug("Try to create entry on graph");
1064 Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
1066 Either<RequirementCapabilityRelDef, StorageOperationStatus> result = toscaOperationFacade.associateResourceInstances(containerComponent.getUniqueId(), requirementDef);
1068 if (result.isLeft()) {
1069 log.debug("Enty on graph is created.");
1070 RequirementCapabilityRelDef requirementCapabilityRelDef = result.left().value();
1071 resultOp = Either.left(requirementCapabilityRelDef);
1075 log.debug("Failed to associate node: {} with node {}", requirementDef.getFromNode(), requirementDef.getToNode());
1076 String fromNameOrId = "";
1077 String toNameOrId = "";
1078 Either<ComponentInstance, StorageOperationStatus> fromResult = getResourceInstanceById(containerComponent, requirementDef.getFromNode());
1079 Either<ComponentInstance, StorageOperationStatus> toResult = getResourceInstanceById(containerComponent, requirementDef.getToNode());
1081 toNameOrId = requirementDef.getFromNode();
1082 fromNameOrId = requirementDef.getFromNode();
1083 if (fromResult.isLeft()) {
1084 fromNameOrId = fromResult.left().value().getName();
1086 if (toResult.isLeft()) {
1087 toNameOrId = toResult.left().value().getName();
1090 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), fromNameOrId, toNameOrId, requirementDef.getRelationships().get(0).getRelation().getRequirement()));
1097 public Either<RequirementCapabilityRelDef, ResponseFormat> dissociateRIFromRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
1098 validateUserExists(userId, "dissociate RI From RI", false);
1100 Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
1101 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(componentId, componentTypeEnum, null);
1102 if (validateComponentExists.isRight()) {
1103 return Either.right(validateComponentExists.right().value());
1105 org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
1107 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
1108 if (validateCanWorkOnComponent.isRight()) {
1109 return Either.right(validateCanWorkOnComponent.right().value());
1111 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "associateRIToRI");
1113 if (lockComponent.isRight()) {
1114 return Either.right(lockComponent.right().value());
1117 log.debug("Try to create entry on graph");
1118 Either<RequirementCapabilityRelDef, StorageOperationStatus> result = toscaOperationFacade.dissociateResourceInstances(componentId, requirementDef);
1119 if (result.isLeft()) {
1120 log.debug("Enty on graph is created.");
1121 RequirementCapabilityRelDef requirementCapabilityRelDef = result.left().value();
1122 resultOp = Either.left(requirementCapabilityRelDef);
1127 log.debug("Failed to dissocaite node {} from node {}", requirementDef.getFromNode(), requirementDef.getToNode());
1128 String fromNameOrId = "";
1129 String toNameOrId = "";
1130 Either<ComponentInstance, StorageOperationStatus> fromResult = getResourceInstanceById(containerComponent, requirementDef.getFromNode());
1131 Either<ComponentInstance, StorageOperationStatus> toResult = getResourceInstanceById(containerComponent, requirementDef.getToNode());
1133 toNameOrId = requirementDef.getFromNode();
1134 fromNameOrId = requirementDef.getFromNode();
1135 if (fromResult.isLeft()) {
1136 fromNameOrId = fromResult.left().value().getName();
1138 if (toResult.isLeft()) {
1139 toNameOrId = toResult.left().value().getName();
1143 .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), fromNameOrId, toNameOrId, requirementDef.getRelationships().get(0).getRelation().getRequirement()));
1147 unlockComponent(resultOp, containerComponent);
1151 * Allows to get relation contained in specified component according to received Id
1152 * @param componentId
1155 * @param componentTypeEnum
1158 public Either<RequirementCapabilityRelDef, ResponseFormat> getRelationById(String componentId, String relationId, String userId, ComponentTypeEnum componentTypeEnum) {
1160 Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
1162 org.openecomp.sdc.be.model.Component containerComponent = null;
1163 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = null;
1164 RequirementCapabilityRelDef foundRelation = null;
1166 validateUserExists(userId, "get relation by Id", false);
1168 if(resultOp == null){
1169 validateComponentExists = validateComponentExists(componentId, componentTypeEnum, null);
1170 if (validateComponentExists.isRight()) {
1171 resultOp = Either.right(validateComponentExists.right().value());
1174 if(resultOp == null){
1175 containerComponent = validateComponentExists.left().value();
1176 List<RequirementCapabilityRelDef> requirementCapabilityRelations = containerComponent.getComponentInstancesRelations();
1177 foundRelation = findRelation(relationId, requirementCapabilityRelations);
1178 if(foundRelation == null){
1179 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RELATION_NOT_FOUND, relationId, componentId);
1180 log.debug("Relation with id {} was not found on the component", relationId, componentId);
1181 resultOp = Either.right(responseFormat);
1184 if(resultOp == null){
1185 resultOp = setRelatedCapability(foundRelation, containerComponent);
1187 if(resultOp.isLeft()){
1188 resultOp = setRelatedRequirement(foundRelation, containerComponent);
1190 } catch (Exception e) {
1191 log.error("The exception {} occured upon get relation {} of the component {} ", e, relationId, componentId);
1192 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
1197 private RequirementCapabilityRelDef findRelation(String relationId, List<RequirementCapabilityRelDef> requirementCapabilityRelations) {
1198 for(RequirementCapabilityRelDef relationship : requirementCapabilityRelations){
1199 if(relationship.getRelationships().stream().filter(r -> r.getRelation().getId().equals(relationId)).findFirst().isPresent()){
1200 return relationship;
1206 private Either<RequirementCapabilityRelDef, ResponseFormat> setRelatedRequirement(RequirementCapabilityRelDef foundRelation, Component containerComponent) {
1207 Either<RequirementCapabilityRelDef, ResponseFormat> result = null;
1208 RelationshipInfo relationshipInfo = foundRelation.resolveSingleRelationship().getRelation();
1209 String instanceId = foundRelation.getFromNode();
1210 Optional<RequirementDefinition> foundRequirement;
1211 Optional<ComponentInstance> instance = containerComponent.getComponentInstances().stream().filter(i -> i.getUniqueId().equals(instanceId)).findFirst();
1212 if(!instance.isPresent()){
1213 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, instanceId, "instance", containerComponent.getComponentType().getValue(), containerComponent.getName());
1214 log.debug("Component instance with id {} was not found on the component", instanceId, containerComponent.getUniqueId());
1215 result = Either.right(responseFormat);
1218 for(List<RequirementDefinition> requirements : instance.get().getRequirements().values()){
1219 foundRequirement = requirements.stream().filter(r -> isBelongingRequirement(relationshipInfo, r)).findFirst();
1220 if(foundRequirement.isPresent()){
1221 foundRelation.resolveSingleRelationship().setRequirement(foundRequirement.get());
1222 result = Either.left(foundRelation);
1227 Either<RequirementDataDefinition, StorageOperationStatus> getfulfilledRequirementRes = toscaOperationFacade.getFulfilledRequirementByRelation(containerComponent.getUniqueId(), instanceId, foundRelation, (rel, req)->isBelongingRequirement(rel, req));
1228 if(getfulfilledRequirementRes.isRight()){
1229 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.REQUIREMENT_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, relationshipInfo.getRequirement(), instanceId, containerComponent.getUniqueId());
1230 log.debug("Requirement {} of instance {} was not found on the container {}. ", relationshipInfo.getCapability(), instanceId, containerComponent.getUniqueId());
1231 result = Either.right(responseFormat);
1233 foundRelation.resolveSingleRelationship().setRequirement(getfulfilledRequirementRes.left().value());
1237 result = Either.left(foundRelation);
1242 private boolean isBelongingRequirement(RelationshipInfo relationshipInfo, RequirementDataDefinition req) {
1243 return req.getName().equals(relationshipInfo.getRequirement()) &&
1244 req.getUniqueId().equals(relationshipInfo.getRequirementUid()) &&
1245 req.getOwnerId().equals(relationshipInfo.getRequirementOwnerId());
1248 private Either<RequirementCapabilityRelDef, ResponseFormat> setRelatedCapability(RequirementCapabilityRelDef foundRelation, Component containerComponent) {
1249 Either<RequirementCapabilityRelDef, ResponseFormat> result = null;
1250 RelationshipInfo relationshipInfo = foundRelation.resolveSingleRelationship().getRelation();
1251 String instanceId = foundRelation.getToNode();
1252 Optional<CapabilityDefinition> foundCapability;
1253 Optional<ComponentInstance> instance = containerComponent.getComponentInstances().stream().filter(i -> i.getUniqueId().equals(instanceId)).findFirst();
1254 if(!instance.isPresent()){
1255 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, instanceId, "instance", containerComponent.getComponentType().getValue(), containerComponent.getName());
1256 log.debug("Component instance with id {} was not found on the component", instanceId, containerComponent.getUniqueId());
1257 result = Either.right(responseFormat);
1260 for(List<CapabilityDefinition> capabilities : instance.get().getCapabilities().values()){
1261 foundCapability = capabilities.stream().filter(c -> isBelongingCapability(relationshipInfo, c)).findFirst();
1262 if(foundCapability.isPresent()){
1263 foundRelation.resolveSingleRelationship().setCapability(foundCapability.get());
1264 result = Either.left(foundRelation);
1269 Either<CapabilityDataDefinition, StorageOperationStatus> getfulfilledRequirementRes =
1270 toscaOperationFacade.getFulfilledCapabilityByRelation(containerComponent.getUniqueId(), instanceId, foundRelation, (rel, cap)->isBelongingCapability(rel, cap));
1271 if(getfulfilledRequirementRes.isRight()){
1272 ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, relationshipInfo.getCapability(), instanceId, containerComponent.getUniqueId());
1273 log.debug("Capability {} of instance {} was not found on the container {}. ", relationshipInfo.getCapability(), instanceId, containerComponent.getUniqueId());
1274 result = Either.right(responseFormat);
1276 foundRelation.resolveSingleRelationship().setCapability(getfulfilledRequirementRes.left().value());
1280 result = Either.left(foundRelation);
1285 private boolean isBelongingCapability(RelationshipInfo relationshipInfo, CapabilityDataDefinition cap) {
1286 return cap.getName().equals(relationshipInfo.getCapability()) &&
1287 cap.getUniqueId().equals(relationshipInfo.getCapabilityUid()) &&
1288 cap.getOwnerId().equals(relationshipInfo.getCapabilityOwnerId());
1291 private Either<ComponentInstanceProperty, ResponseFormat> updateAttributeValue(ComponentInstanceProperty attribute, String resourceInstanceId) {
1292 Either<ComponentInstanceProperty, StorageOperationStatus> eitherAttribute = componentInstanceOperation.updateAttributeValueInResourceInstance(attribute, resourceInstanceId, true);
1293 Either<ComponentInstanceProperty, ResponseFormat> result;
1294 if (eitherAttribute.isLeft()) {
1295 log.debug("Attribute value {} was updated on graph.", attribute.getValueUniqueUid());
1296 ComponentInstanceProperty instanceAttribute = eitherAttribute.left().value();
1298 result = Either.left(instanceAttribute);
1301 log.debug("Failed to update attribute value {} in resource instance {}", attribute, resourceInstanceId);
1303 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(eitherAttribute.right().value());
1305 result = Either.right(componentsUtils.getResponseFormat(actionStatus, ""));
1311 private Either<ComponentInstanceProperty, ResponseFormat> createAttributeValue(ComponentInstanceProperty attribute, String resourceInstanceId) {
1313 Either<ComponentInstanceProperty, ResponseFormat> result;
1315 Wrapper<Integer> indexCounterWrapper = new Wrapper<>();
1316 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
1317 validateIncrementCounter(resourceInstanceId, GraphPropertiesDictionary.ATTRIBUTE_COUNTER, indexCounterWrapper, errorWrapper);
1319 if (!errorWrapper.isEmpty()) {
1320 result = Either.right(errorWrapper.getInnerElement());
1322 Either<ComponentInstanceProperty, StorageOperationStatus> eitherAttribute = componentInstanceOperation.addAttributeValueToResourceInstance(attribute, resourceInstanceId, indexCounterWrapper.getInnerElement(), true);
1323 if (eitherAttribute.isLeft()) {
1324 log.debug("Attribute value was added to resource instance {}", resourceInstanceId);
1325 ComponentInstanceProperty instanceAttribute = eitherAttribute.left().value();
1326 result = Either.left(instanceAttribute);
1329 log.debug("Failed to add attribute value {} to resource instance {}", attribute, resourceInstanceId);
1331 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(eitherAttribute.right().value());
1332 result = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1340 * Create Or Updates Attribute Instance
1342 * @param componentTypeEnum
1343 * @param componentId
1344 * @param resourceInstanceId
1349 public Either<ComponentInstanceProperty, ResponseFormat> createOrUpdateAttributeValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, ComponentInstanceProperty attribute, String userId) {
1350 Either<ComponentInstanceProperty, ResponseFormat> result = null;
1351 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
1353 validateUserExist(userId, "create Or Update Attribute Value");
1354 if (errorWrapper.isEmpty()) {
1355 validateComponentTypeEnum(componentTypeEnum, "CreateOrUpdateAttributeValue", errorWrapper);
1357 if (errorWrapper.isEmpty()) {
1358 validateCanWorkOnComponent(componentId, componentTypeEnum, userId, errorWrapper);
1360 if (errorWrapper.isEmpty()) {
1361 validateComponentLock(componentId, componentTypeEnum, errorWrapper);
1365 if (errorWrapper.isEmpty()) {
1366 final boolean isCreate = Objects.isNull(attribute.getValueUniqueUid());
1368 result = createAttributeValue(attribute, resourceInstanceId);
1370 result = updateAttributeValue(attribute, resourceInstanceId);
1373 result = Either.right(errorWrapper.getInnerElement());
1379 if (result == null || result.isRight()) {
1380 titanDao.rollback();
1385 graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
1389 private boolean isNetworkRoleServiceProperty(ComponentInstanceProperty property, ComponentTypeEnum componentTypeEnum) {
1390 return StringUtils.isNotEmpty(property.getValue())
1391 && PropertyNames.NETWORK_ROLE.getPropertyName().equalsIgnoreCase(property.getName())
1392 && ComponentTypeEnum.SERVICE == componentTypeEnum;
1395 // US833308 VLI in service - specific network_role property value logic
1396 private StorageOperationStatus concatServiceNameToVLINetworkRolePropertiesValues(ToscaOperationFacade toscaOperationFacade, ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, List<ComponentInstanceProperty> properties) {
1397 for (ComponentInstanceProperty property: properties) {
1398 if (isNetworkRoleServiceProperty(property, componentTypeEnum)) {
1399 ComponentParametersView componentParametersView = new ComponentParametersView();
1400 componentParametersView.disableAll();
1401 componentParametersView.setIgnoreComponentInstances(false);
1402 Either<Component, StorageOperationStatus> getServiceResult = toscaOperationFacade.getToscaElement(componentId, componentParametersView);
1403 if (getServiceResult.isRight()) {
1404 return getServiceResult.right().value();
1406 Component service = getServiceResult.left().value();
1407 Optional<ComponentInstance> getInstance = service.getComponentInstances().stream().filter(p -> p.getUniqueId().equals(resourceInstanceId)).findAny();
1408 if (!getInstance.isPresent()) {
1409 return StorageOperationStatus.NOT_FOUND;
1411 String prefix = service.getSystemName() + ".";
1412 String value = property.getValue();
1413 if (OriginTypeEnum.VL == getInstance.get().getOriginType() && (!value.startsWith(prefix) || value.equalsIgnoreCase(prefix))) {
1414 property.setValue(prefix + value);
1418 return StorageOperationStatus.OK;
1421 public Either<List<ComponentInstanceProperty>, ResponseFormat> createOrUpdatePropertiesValues(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, List<ComponentInstanceProperty> properties, String userId) {
1423 Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
1425 /*-------------------------------Validations---------------------------------*/
1427 validateUserExists(userId, "create Or Update Properties Values", false);
1429 if (componentTypeEnum == null) {
1430 BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertiesValues", "invalid component type", ErrorSeverity.INFO);
1431 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
1434 Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
1436 if (getResourceResult.isRight()) {
1437 log.debug("Failed to retrieve component, component id {}", componentId);
1438 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
1441 Component containerComponent = getResourceResult.left().value();
1443 if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
1444 log.info("Restricted operation for user: {} on service {}", userId, componentId);
1445 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
1448 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, resourceInstanceId);
1449 if (resourceInstanceStatus.isRight()) {
1450 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, resourceInstanceId, componentId));
1453 ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
1454 // specific property value logic US833308
1455 StorageOperationStatus fetchByIdsStatus = concatServiceNameToVLINetworkRolePropertiesValues(toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties);
1456 if (StorageOperationStatus.OK != fetchByIdsStatus) {
1457 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(fetchByIdsStatus)));
1461 StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
1462 if (lockStatus != StorageOperationStatus.OK) {
1463 log.debug("Failed to lock service {}", componentId);
1464 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
1469 for (ComponentInstanceProperty property: properties) {
1470 Either<String, ResponseFormat> updatedPropertyValue = updatePropertyObjectValue(property, false);
1471 updatedPropertyValue.bimap(updatedValue -> updatePropertyOnContainerComponent(property,updatedValue, containerComponent, foundResourceInstance),
1472 responseFormat -> Either.right(responseFormat));
1475 Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
1476 if (updateContainerRes.isRight()) {
1477 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
1478 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1481 resultOp = Either.left(properties);
1485 if (resultOp == null || resultOp.isRight()) {
1486 titanDao.rollback();
1491 graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
1495 private ResponseFormat updateCapabilityPropertyOnContainerComponent(ComponentInstanceProperty property, String newValue, Component containerComponent, ComponentInstance foundResourceInstance,
1496 String capabilityType, String capabilityName) {
1497 String componentInstanceUniqueId = foundResourceInstance.getUniqueId();
1498 StringBuffer sb = new StringBuffer(componentInstanceUniqueId);
1499 sb.append(ModelConverter.CAP_PROP_DELIM).append(property.getOwnerId()).append(ModelConverter.CAP_PROP_DELIM).append(capabilityType).append(ModelConverter.CAP_PROP_DELIM).append(capabilityName);
1500 String capKey = sb.toString();
1502 Map<String, List<CapabilityDefinition>> capabilities = Optional.ofNullable(foundResourceInstance.getCapabilities())
1503 .orElse(Collections.emptyMap());
1504 List<CapabilityDefinition> capPerType = Optional.ofNullable(capabilities.get(capabilityType)).orElse(Collections.EMPTY_LIST);
1505 Optional<CapabilityDefinition> cap = capPerType.stream().filter(c -> c.getName().equals(capabilityName)).findAny();
1506 if (cap.isPresent()) {
1507 List<ComponentInstanceProperty> capProperties = cap.get().getProperties();
1508 if (capProperties != null) {
1509 Optional<ComponentInstanceProperty> instanceProperty = capProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
1510 StorageOperationStatus status;
1511 if (instanceProperty.isPresent()) {
1512 instanceProperty.get().setValue(newValue);
1513 List<String> path = new ArrayList<>();
1514 path.add(componentInstanceUniqueId);
1516 instanceProperty.get().setPath(path);
1517 status = toscaOperationFacade.updateComponentInstanceCapabiltyProperty(containerComponent, componentInstanceUniqueId, capKey, instanceProperty.get());
1518 if (status != StorageOperationStatus.OK) {
1519 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
1520 return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, "");
1523 foundResourceInstance.setCustomizationUUID(UUID.randomUUID().toString());
1529 return componentsUtils.getResponseFormat(ActionStatus.OK);
1532 private ResponseFormat updatePropertyOnContainerComponent(ComponentInstanceProperty property, String newValue, Component containerComponent, ComponentInstance foundResourceInstance) {
1533 List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(foundResourceInstance.getUniqueId());
1534 Optional<ComponentInstanceProperty> instanceProperty = instanceProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
1535 StorageOperationStatus status;
1536 instanceProperty.get().setValue(newValue);
1537 if (instanceProperty.isPresent()) {
1538 status = toscaOperationFacade.updateComponentInstanceProperty(containerComponent, foundResourceInstance.getUniqueId(), property);
1540 status = toscaOperationFacade.addComponentInstanceProperty(containerComponent, foundResourceInstance.getUniqueId(), property);
1542 if (status != StorageOperationStatus.OK) {
1543 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
1544 return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, "");
1546 List<String> path = new ArrayList<>();
1547 path.add(foundResourceInstance.getUniqueId());
1548 property.setPath(path);
1550 foundResourceInstance.setCustomizationUUID(UUID.randomUUID().toString());
1551 return componentsUtils.getResponseFormat(ActionStatus.OK);
1554 private <T extends PropertyDefinition> Either<String,ResponseFormat> updatePropertyObjectValue(T property, boolean isInput) {
1555 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypesEither = dataTypeCache.getAll();
1556 if (allDataTypesEither.isRight()) {
1557 TitanOperationStatus status = allDataTypesEither.right().value();
1558 BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
1559 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status))));
1561 Map<String, DataTypeDefinition> allDataTypes = allDataTypesEither.left().value();
1562 String innerType = null;
1563 String propertyType = property.getType();
1564 ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
1565 log.debug("The type of the property {} is {}", property.getUniqueId(), propertyType);
1567 if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
1568 SchemaDefinition def = property.getSchema();
1570 log.debug("Schema doesn't exists for property of type {}", type);
1571 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
1573 PropertyDataDefinition propDef = def.getProperty();
1574 if (propDef == null) {
1575 log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
1576 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
1578 innerType = propDef.getType();
1580 // Specific Update Logic
1581 Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(propertyType, property.getValue(), true, innerType, allDataTypes);
1582 String newValue = property.getValue();
1583 if (isValid.isRight()) {
1584 Boolean res = isValid.right().value();
1586 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT))));
1589 Object object = isValid.left().value();
1590 if (object != null) {
1591 newValue = object.toString();
1595 ImmutablePair<String, Boolean> pair = propertyOperation.validateAndUpdateRules(propertyType, ((ComponentInstanceProperty) property).getRules(), innerType, allDataTypes, true);
1596 if (pair.getRight() != null && pair.getRight() == false) {
1597 BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(), property.getName(), propertyType);
1598 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT))));
1601 return Either.left(newValue);
1604 private ResponseFormat updateInputOnContainerComponent(ComponentInstanceInput input, String newValue, Component containerComponent, ComponentInstance foundResourceInstance) {
1605 List<ComponentInstanceInput> instanceProperties = containerComponent.getComponentInstancesInputs().get(foundResourceInstance.getUniqueId());
1606 Optional<ComponentInstanceInput> instanceProperty = instanceProperties.stream().filter(p -> p.getUniqueId().equals(input.getUniqueId())).findAny();
1607 StorageOperationStatus status;
1608 if (instanceProperty.isPresent()) {
1609 instanceProperty.get().setValue(input.getValue());
1610 status = toscaOperationFacade.updateComponentInstanceInput(containerComponent, foundResourceInstance.getUniqueId(), input);
1612 status = toscaOperationFacade.addComponentInstanceInput(containerComponent, foundResourceInstance.getUniqueId(), input);
1614 if (status != StorageOperationStatus.OK) {
1615 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
1616 return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, "");
1618 foundResourceInstance.setCustomizationUUID(UUID.randomUUID().toString());
1619 return componentsUtils.getResponseFormat(ActionStatus.OK);
1622 public Either<List<ComponentInstanceInput>, ResponseFormat> createOrUpdateInstanceInputValues(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, List<ComponentInstanceInput> inputs, String userId) {
1624 Either<List<ComponentInstanceInput>, ResponseFormat> resultOp = null;
1626 validateUserExists(userId, "create Or Update Property Value", false);
1628 if (componentTypeEnum == null) {
1629 BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertyValue", "invalid component type", ErrorSeverity.INFO);
1630 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
1633 Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
1635 if (getResourceResult.isRight()) {
1636 log.debug("Failed to retrieve component, component id {}", componentId);
1637 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
1640 Component containerComponent = getResourceResult.left().value();
1642 if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
1643 log.info("Restricted operation for user: {} on service {}", userId, componentId);
1644 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
1647 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, resourceInstanceId);
1648 if (resourceInstanceStatus.isRight()) {
1649 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, resourceInstanceId, componentId));
1653 ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
1656 StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
1657 if (lockStatus != StorageOperationStatus.OK) {
1658 log.debug("Failed to lock service {}", componentId);
1659 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
1663 for (ComponentInstanceInput input: inputs) {
1664 Either<String, ResponseFormat> updatedInputValue = updatePropertyObjectValue(input, true);
1665 updatedInputValue.bimap(updatedValue -> updateInputOnContainerComponent(input,updatedValue, containerComponent, foundResourceInstance),
1666 responseFormat -> Either.right(responseFormat));
1669 Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
1671 if (updateContainerRes.isRight()) {
1672 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
1673 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1676 resultOp = Either.left(inputs);
1680 if (resultOp == null || resultOp.isRight()) {
1681 titanDao.rollback();
1686 graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
1691 public Either<ComponentInstanceProperty, ResponseFormat> createOrUpdateGroupInstancePropertyValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, String groupInstanceId, ComponentInstanceProperty property,
1694 Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
1696 validateUserExists(userId, "create Or Update Property Value", false);
1698 if (componentTypeEnum == null) {
1699 BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertyValue", "invalid component type", ErrorSeverity.INFO);
1700 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
1704 if (!ComponentValidationUtils.canWorkOnComponent(componentId, toscaOperationFacade, userId)) {
1705 log.info("Restricted operation for user: {} on service: {}", userId, componentId);
1706 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
1710 StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
1711 if (lockStatus != StorageOperationStatus.OK) {
1712 log.debug("Failed to lock service {}", componentId);
1713 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
1717 String propertyValueUid = property.getValueUniqueUid();
1719 if (propertyValueUid == null) {
1721 Either<Integer, StorageOperationStatus> counterRes = groupInstanceOperation.increaseAndGetGroupInstancePropertyCounter(groupInstanceId);
1723 if (counterRes.isRight()) {
1724 log.debug("increaseAndGetResourcePropertyCounter failed resource instance: {} property: {}", resourceInstanceId, property);
1725 StorageOperationStatus status = counterRes.right().value();
1726 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
1727 resultOp = Either.right(componentsUtils.getResponseFormat(actionStatus));
1729 Integer index = counterRes.left().value();
1730 Either<ComponentInstanceProperty, StorageOperationStatus> result = groupInstanceOperation.addPropertyValueToGroupInstance(property, resourceInstanceId, index, true);
1732 if (result.isLeft()) {
1733 log.trace("Property value was added to resource instance {}", resourceInstanceId);
1734 ComponentInstanceProperty instanceProperty = result.left().value();
1736 resultOp = Either.left(instanceProperty);
1739 log.debug("Failed to add property value: {} to resource instance {}", property, resourceInstanceId);
1741 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
1743 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1747 Either<ComponentInstanceProperty, StorageOperationStatus> result = groupInstanceOperation.updatePropertyValueInGroupInstance(property, resourceInstanceId, true);
1749 if (result.isLeft()) {
1750 log.debug("Property value {} was updated on graph.", property.getValueUniqueUid());
1751 ComponentInstanceProperty instanceProperty = result.left().value();
1753 resultOp = Either.left(instanceProperty);
1756 log.debug("Failed to update property value: {}, in resource instance {}", property, resourceInstanceId);
1758 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
1760 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1763 if (resultOp.isLeft()) {
1764 StorageOperationStatus updateCustomizationUUID = componentInstanceOperation.updateCustomizationUUID(resourceInstanceId);
1765 if (updateCustomizationUUID != StorageOperationStatus.OK) {
1766 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(updateCustomizationUUID);
1768 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1775 if (resultOp == null || resultOp.isRight()) {
1776 titanDao.rollback();
1781 graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
1786 public Either<ComponentInstanceInput, ResponseFormat> createOrUpdateInputValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, ComponentInstanceInput inputProperty, String userId) {
1788 Either<ComponentInstanceInput, ResponseFormat> resultOp = null;
1790 validateUserExists(userId, "create Or Update Input Value", false);
1792 if (componentTypeEnum == null) {
1793 BeEcompErrorManager.getInstance().logInvalidInputError("createOrUpdateInputValue", "invalid component type", ErrorSeverity.INFO);
1794 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
1798 if (!ComponentValidationUtils.canWorkOnComponent(componentId, toscaOperationFacade, userId)) {
1799 log.info("Restricted operation for user: {} on service: {}", userId, componentId);
1800 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
1804 StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
1805 if (lockStatus != StorageOperationStatus.OK) {
1806 log.debug("Failed to lock service {}", componentId);
1807 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
1811 String propertyValueUid = inputProperty.getValueUniqueUid();
1812 if (propertyValueUid == null) {
1814 Either<Integer, StorageOperationStatus> counterRes = componentInstanceOperation.increaseAndGetResourceInstanceSpecificCounter(resourceInstanceId, GraphPropertiesDictionary.INPUT_COUNTER, true);
1816 if (counterRes.isRight()) {
1817 log.debug("increaseAndGetResourceInputCounter failed resource instance {} inputProperty {}", resourceInstanceId, inputProperty);
1818 StorageOperationStatus status = counterRes.right().value();
1819 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
1820 resultOp = Either.right(componentsUtils.getResponseFormat(actionStatus));
1822 Integer index = counterRes.left().value();
1823 Either<ComponentInstanceInput, StorageOperationStatus> result = componentInstanceOperation.addInputValueToResourceInstance(inputProperty, resourceInstanceId, index, true);
1825 if (result.isLeft()) {
1826 log.debug("Property value was added to resource instance {}", resourceInstanceId);
1827 ComponentInstanceInput instanceProperty = result.left().value();
1829 resultOp = Either.left(instanceProperty);
1833 log.debug("Failed to add input value {} to resource instance {}", inputProperty, resourceInstanceId);
1835 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
1837 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1843 Either<ComponentInstanceInput, StorageOperationStatus> result = componentInstanceOperation.updateInputValueInResourceInstance(inputProperty, resourceInstanceId, true);
1845 if (result.isLeft()) {
1846 log.debug("Input value {} was updated on graph.", inputProperty.getValueUniqueUid());
1847 ComponentInstanceInput instanceProperty = result.left().value();
1849 resultOp = Either.left(instanceProperty);
1853 log.debug("Failed to update property value {} in resource instance {}", inputProperty, resourceInstanceId);
1855 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
1857 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1864 if (resultOp == null || resultOp.isRight()) {
1865 titanDao.rollback();
1870 graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
1875 public Either<ComponentInstanceProperty, ResponseFormat> deletePropertyValue(ComponentTypeEnum componentTypeEnum, String serviceId, String resourceInstanceId, String propertyValueId, String userId) {
1877 validateUserExists(userId, "delete Property Value", false);
1879 Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
1881 if (componentTypeEnum == null) {
1882 BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertyValue", "invalid component type", ErrorSeverity.INFO);
1883 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
1887 if (!ComponentValidationUtils.canWorkOnComponent(serviceId, toscaOperationFacade, userId)) {
1888 log.info("Restricted operation for user {} on service {}", userId, serviceId);
1889 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
1893 StorageOperationStatus lockStatus = graphLockOperation.lockComponent(serviceId, componentTypeEnum.getNodeType());
1894 if (lockStatus != StorageOperationStatus.OK) {
1895 log.debug("Failed to lock service {}", serviceId);
1896 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
1900 Either<ComponentInstanceProperty, StorageOperationStatus> result = propertyOperation.removePropertyValueFromResourceInstance(propertyValueId, resourceInstanceId, true);
1902 if (result.isLeft()) {
1903 log.debug("Property value {} was removed from graph.", propertyValueId);
1904 ComponentInstanceProperty instanceProperty = result.left().value();
1906 resultOp = Either.left(instanceProperty);
1910 log.debug("Failed to remove property value {} in resource instance {}", propertyValueId, resourceInstanceId);
1912 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
1914 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
1920 if (resultOp == null || resultOp.isRight()) {
1921 titanDao.rollback();
1926 graphLockOperation.unlockComponent(serviceId, componentTypeEnum.getNodeType());
1931 private Either<Component, ResponseFormat> getAndValidateOriginComponentOfComponentInstance(ComponentTypeEnum containerComponentType, ComponentInstance componentInstance) {
1933 Either<Component, ResponseFormat> eitherResponse = null;
1934 ComponentTypeEnum componentType = getComponentTypeByParentComponentType(containerComponentType);
1935 Component component;
1936 ResponseFormat errorResponse;
1937 Either<Component, StorageOperationStatus> getComponentRes = toscaOperationFacade.getToscaFullElement(componentInstance.getComponentUid());
1938 if (getComponentRes.isRight()) {
1939 log.debug("Failed to get the component with id {} for component instance {} creation. ", componentInstance.getComponentUid(), componentInstance.getName());
1940 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentRes.right().value(), componentType);
1941 errorResponse = componentsUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
1942 eitherResponse = Either.right(errorResponse);
1944 if (eitherResponse == null) {
1945 component = getComponentRes.left().value();
1946 LifecycleStateEnum resourceCurrState = component.getLifecycleState();
1947 if (resourceCurrState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
1948 ActionStatus actionStatus = ActionStatus.ILLEGAL_COMPONENT_STATE;
1949 errorResponse = componentsUtils.getResponseFormat(actionStatus, component.getComponentType().toString(), component.getName(), resourceCurrState.toString());
1950 eitherResponse = Either.right(errorResponse);
1953 if (eitherResponse == null) {
1954 eitherResponse = Either.left(getComponentRes.left().value());
1956 return eitherResponse;
1959 public Either<Set<String>, ResponseFormat> forwardingPathOnVersionChange(String containerComponentParam,
1960 String containerComponentId,
1961 String componentInstanceId,
1962 ComponentInstance newComponentInstance) {
1963 Either<Set<String>, ResponseFormat> resultOp;
1964 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
1965 if (validateComponentType.isRight()) {
1966 return Either.right(validateComponentType.right().value());
1968 final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
1969 ComponentParametersView componentParametersView = getComponentParametersViewForForwardingPath();
1972 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists =
1973 validateComponentExists(containerComponentId, containerComponentType, componentParametersView);
1974 if (validateComponentExists.isRight()) {
1975 return Either.right(validateComponentExists.right().value());
1977 Component containerComponent = validateComponentExists.left().value();
1979 //Fetch current component instance
1980 Either<ComponentInstance, StorageOperationStatus> eitherResourceInstance =
1981 getResourceInstanceById(containerComponent, componentInstanceId);
1982 if (eitherResourceInstance.isRight()) {
1983 resultOp = Either.right(componentsUtils.getResponseFormat(
1984 ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceId, containerComponentId));
1987 ComponentInstance currentResourceInstance = eitherResourceInstance.left().value();
1989 //Check whether new componentInstance exists
1990 String resourceId = newComponentInstance.getComponentUid();
1991 Either<Boolean, StorageOperationStatus> componentExistsRes = toscaOperationFacade.validateComponentExists(resourceId);
1992 if (componentExistsRes.isRight()) {
1993 log.debug("Failed to find resource {} ", resourceId);
1994 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse
1995 (componentExistsRes.right().value()), resourceId));
1997 } else if (!componentExistsRes.left().value()) {
1998 log.debug("The resource {} not found ", resourceId);
1999 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceId));
2003 //Fetch component using new component instance uid
2004 Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(newComponentInstance);
2005 if (eitherResourceName.isRight()) {
2006 resultOp = Either.right(eitherResourceName.right().value());
2009 Component updatedContainerComponent=eitherResourceName.left().value();
2010 Set<String> toDeleteForwardingPaths = getForwardingPaths(containerComponent,
2011 currentResourceInstance, updatedContainerComponent);
2012 resultOp=Either.left(toDeleteForwardingPaths);
2017 private Set<String> getForwardingPaths(Component containerComponent, ComponentInstance currentResourceInstance,
2018 Component updatedContainerComponent) {
2019 DataForMergeHolder dataForMergeHolder=new DataForMergeHolder();
2020 dataForMergeHolder.setOrigComponentInstId(currentResourceInstance.getUniqueId());
2022 Service service = (Service) containerComponent;
2023 ForwardingPathUtils forwardingPathUtils = new ForwardingPathUtils();
2025 return forwardingPathUtils.
2026 getForwardingPathsToBeDeletedOnVersionChange(service,dataForMergeHolder,updatedContainerComponent);
2029 private ComponentParametersView getComponentParametersViewForForwardingPath() {
2030 ComponentParametersView componentParametersView = new ComponentParametersView();
2031 componentParametersView.setIgnoreCapabiltyProperties(false);
2032 componentParametersView.setIgnoreForwardingPath(false);
2033 return componentParametersView;
2036 public Either<ComponentInstance, ResponseFormat> changeComponentInstanceVersion(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance newComponentInstance) {
2038 User user = validateUserExists(userId, "change Component Instance Version", false);
2040 Either<ComponentInstance, ResponseFormat> resultOp = null;
2042 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
2043 if (validateComponentType.isRight()) {
2044 return Either.right(validateComponentType.right().value());
2047 final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
2048 ComponentParametersView componentParametersView = new ComponentParametersView();
2049 componentParametersView.setIgnoreCapabiltyProperties(false);
2050 Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, componentParametersView);
2051 if (validateComponentExists.isRight()) {
2052 return Either.right(validateComponentExists.right().value());
2054 org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
2056 Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
2057 if (validateCanWorkOnComponent.isRight()) {
2058 return Either.right(validateCanWorkOnComponent.right().value());
2061 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceId);
2062 if (resourceInstanceStatus.isRight()) {
2063 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceId, containerComponentId));
2067 ComponentInstance currentResourceInstance = resourceInstanceStatus.left().value();
2069 return changeInstanceVersion(containerComponent, currentResourceInstance, newComponentInstance, user, containerComponentType );
2072 public Either<ComponentInstance, ResponseFormat> changeInstanceVersion(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance currentResourceInstance,
2073 ComponentInstance newComponentInstance, User user, final ComponentTypeEnum containerComponentType ) {
2074 Either<ComponentInstance, ResponseFormat> resultOp = null;
2075 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus;
2077 Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "changeComponentInstanceVersion");
2078 String containerComponentId = containerComponent.getUniqueId();
2079 String componentInstanceId = currentResourceInstance.getUniqueId();
2080 if (lockComponent.isRight()) {
2081 return Either.right(lockComponent.right().value());
2087 if (currentResourceInstance.getComponentUid().equals(newComponentInstance.getComponentUid())) {
2088 resultOp = Either.left(currentResourceInstance);
2092 String resourceId = newComponentInstance.getComponentUid();
2096 Either<Boolean, StorageOperationStatus> componentExistsRes = toscaOperationFacade.validateComponentExists(resourceId);
2097 if (componentExistsRes.isRight()) {
2098 log.debug("Failed to validate existing of the component {}. Status is {} ", resourceId);
2099 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentExistsRes.right().value()), resourceId));
2101 } else if (!componentExistsRes.left().value()) {
2102 log.debug("The resource {} not found ", resourceId);
2103 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceId));
2107 Either<Component, ResponseFormat> eitherOriginComponent = getInstanceOriginNode(currentResourceInstance);
2109 if (eitherOriginComponent.isRight()) {
2110 resultOp = Either.right(eitherOriginComponent.right().value());
2113 DataForMergeHolder dataHolder = compInstMergeDataBL.saveAllDataBeforeDeleting(containerComponent, currentResourceInstance, eitherOriginComponent.left().value());
2114 resultOp = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
2115 if (resultOp.isRight()) {
2116 log.debug("failed to delete resource instance {}", resourceId);
2119 ComponentInstance resResourceInfo = resultOp.left().value();
2120 Component origComponent = null;
2121 OriginTypeEnum originType = currentResourceInstance.getOriginType();
2122 if (originType == OriginTypeEnum.ServiceProxy) {
2123 Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName("serviceProxy");
2124 if (serviceProxyOrigin.isRight()) {
2125 log.debug("Failed to fetch normative service proxy resource by tosca name, error {}", serviceProxyOrigin.right().value());
2126 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value())));
2128 origComponent = serviceProxyOrigin.left().value();
2130 StorageOperationStatus fillProxyRes = fillProxyInstanceData(newComponentInstance, origComponent);
2132 if (fillProxyRes != StorageOperationStatus.OK) {
2133 log.debug("Failed to fill service proxy resource data with data from service, error {}", fillProxyRes);
2134 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(fillProxyRes)));
2137 newComponentInstance.setOriginType(originType);
2141 Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(newComponentInstance);
2143 if (eitherResourceName.isRight()) {
2144 resultOp = Either.right(eitherResourceName.right().value());
2148 origComponent = eitherResourceName.left().value();
2150 newComponentInstance.setName(resResourceInfo.getName());
2153 newComponentInstance.setInvariantName(resResourceInfo.getInvariantName());
2154 newComponentInstance.setPosX(resResourceInfo.getPosX());
2155 newComponentInstance.setPosY(resResourceInfo.getPosY());
2156 newComponentInstance.setDescription(resResourceInfo.getDescription());
2158 resultOp = createComponentInstanceOnGraph(containerComponent, origComponent, newComponentInstance, user);
2160 if (resultOp.isRight()) {
2161 log.debug("failed to create resource instance {}", resourceId);
2165 ComponentInstance updatedComponentInstance = resultOp.left().value();
2166 if (resultOp.isRight()) {
2167 log.debug("failed to create resource instance {}", resourceId);
2171 Either<Component, ResponseFormat> mergeStatusEither = compInstMergeDataBL.mergeComponentUserOrigData(user, dataHolder, containerComponent, containerComponentId, newComponentInstance.getUniqueId());
2172 if (mergeStatusEither.isRight()) {
2173 return Either.right(mergeStatusEither.right().value());
2176 ActionStatus postChangeVersionResult = onChangeInstanceOperationOrchestrator.doPostChangeVersionOperations(containerComponent, currentResourceInstance, newComponentInstance);
2177 if (postChangeVersionResult != ActionStatus.OK) {
2178 return Either.right(componentsUtils.getResponseFormat(postChangeVersionResult));
2181 ComponentParametersView filter = new ComponentParametersView(true);
2182 filter.setIgnoreComponentInstances(false);
2183 Either<Component, StorageOperationStatus> updatedComponentRes = toscaOperationFacade.getToscaElement(containerComponentId, filter);
2184 if (updatedComponentRes.isRight()) {
2185 StorageOperationStatus storageOperationStatus = updatedComponentRes.right().value();
2186 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus, containerComponent.getComponentType());
2187 ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
2188 log.debug("Component with id {} was not found", containerComponentId);
2189 return Either.right(responseFormat);
2191 resourceInstanceStatus = getResourceInstanceById(updatedComponentRes.left().value(), updatedComponentInstance.getUniqueId());
2192 if (resourceInstanceStatus.isRight()) {
2193 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceInstanceStatus.right().value()), updatedComponentInstance.getUniqueId()));
2196 resultOp = Either.left(resourceInstanceStatus.left().value());
2200 unlockComponent(resultOp, containerComponent);
2205 public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesById(String containerComponentTypeParam, String containerComponentId, String componentInstanceUniqueId, String userId) {
2206 final String ECOMP_ERROR_CONTEXT = "Get Component Instance Properties By Id";
2207 Component containerComponent = null;
2209 Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
2211 validateUserExists(userId, ECOMP_ERROR_CONTEXT, false);
2213 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentTypeParam);
2214 if (validateComponentType.isRight()) {
2215 resultOp = Either.right(validateComponentType.right().value());
2219 Either<Component, StorageOperationStatus> validateContainerComponentExists = toscaOperationFacade.getToscaElement(containerComponentId);
2220 if (validateContainerComponentExists.isRight()) {
2221 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(validateContainerComponentExists.right().value())));
2224 containerComponent = validateContainerComponentExists.left().value();
2226 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId);
2227 if (resourceInstanceStatus.isRight()) {
2228 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId));
2232 List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(componentInstanceUniqueId);
2233 if (CollectionUtils.isEmpty(instanceProperties)) {
2234 instanceProperties = new ArrayList<>();
2236 resultOp = Either.left(instanceProperties);
2239 unlockComponent(resultOp, containerComponent);
2243 protected void validateIncrementCounter(String resourceInstanceId, GraphPropertiesDictionary counterType, Wrapper<Integer> instaceCounterWrapper, Wrapper<ResponseFormat> errorWrapper) {
2244 Either<Integer, StorageOperationStatus> counterRes = componentInstanceOperation.increaseAndGetResourceInstanceSpecificCounter(resourceInstanceId, counterType, true);
2246 if (counterRes.isRight()) {
2247 log.debug("increase And Get {} failed resource instance {}", counterType, resourceInstanceId);
2248 StorageOperationStatus status = counterRes.right().value();
2249 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
2250 errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus));
2252 instaceCounterWrapper.setInnerElement(counterRes.left().value());
2258 * updates componentInstance modificationTime
2260 * @param componentInstance
2261 * @param componentInstanceType
2262 * @param modificationTime
2263 * @param inTransaction
2266 public Either<ComponentInstanceData, ResponseFormat> updateComponentInstanceModificationTimeAndCustomizationUuid(ComponentInstance componentInstance, NodeTypeEnum componentInstanceType, Long modificationTime, boolean inTransaction) {
2267 Either<ComponentInstanceData, ResponseFormat> result;
2268 Either<ComponentInstanceData, StorageOperationStatus> updateComponentInstanceRes = componentInstanceOperation.updateComponentInstanceModificationTimeAndCustomizationUuidOnGraph(componentInstance, componentInstanceType, modificationTime,
2270 if (updateComponentInstanceRes.isRight()) {
2271 log.debug("Failed to update component instance {} with new last update date and mofifier. Status is {}. ", componentInstance.getName(), updateComponentInstanceRes.right().value());
2272 result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateComponentInstanceRes.right().value())));
2274 result = Either.left(updateComponentInstanceRes.left().value());
2279 public Either<ComponentInstance, ResponseFormat> deleteServiceProxy() {
2280 // TODO Add implementation
2281 Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance());
2285 public Either<ComponentInstance, ResponseFormat> createServiceProxy() {
2286 // TODO Add implementation
2287 Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance());
2291 public Either<ComponentInstance, ResponseFormat> changeServiceProxyVersion() {
2292 // TODO Add implementation
2293 Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance());
2297 private Boolean validateInstanceNameUniquenessUponUpdate(Component containerComponent, ComponentInstance oldComponentInstance, String newInstanceName) {
2298 return ComponentValidations.validateNameIsUniqueInComponent(oldComponentInstance.getName(), newInstanceName, containerComponent);
2301 private Either<ComponentInstance, StorageOperationStatus> getResourceInstanceById(Component containerComponent, String instanceId) {
2303 Either<ComponentInstance, StorageOperationStatus> result = null;
2304 List<ComponentInstance> instances = containerComponent.getComponentInstances();
2305 Optional<ComponentInstance> foundInstance = null;
2306 if (CollectionUtils.isEmpty(instances)) {
2307 result = Either.right(StorageOperationStatus.NOT_FOUND);
2309 if (result == null) {
2310 foundInstance = instances.stream().filter(i -> i.getUniqueId().equals(instanceId)).findFirst();
2311 if (!foundInstance.isPresent()) {
2312 result = Either.right(StorageOperationStatus.NOT_FOUND);
2315 if (result == null) {
2316 result = Either.left(foundInstance.get());
2321 private ComponentInstance buildComponentInstance(ComponentInstance resourceInstanceForUpdate, ComponentInstance origInstanceForUpdate) {
2323 Long creationDate = origInstanceForUpdate.getCreationTime();
2325 Long modificationTime = System.currentTimeMillis();
2326 resourceInstanceForUpdate.setCreationTime(creationDate);
2327 resourceInstanceForUpdate.setModificationTime(modificationTime);
2329 resourceInstanceForUpdate.setCustomizationUUID(origInstanceForUpdate.getCustomizationUUID());
2331 if (StringUtils.isEmpty(resourceInstanceForUpdate.getName()) && StringUtils.isNotEmpty(origInstanceForUpdate.getName())) {
2332 resourceInstanceForUpdate.setName(origInstanceForUpdate.getName());
2335 resourceInstanceForUpdate.setNormalizedName(ValidationUtils.normalizeComponentInstanceName(resourceInstanceForUpdate.getName()));
2337 if (StringUtils.isEmpty(resourceInstanceForUpdate.getIcon()))
2338 resourceInstanceForUpdate.setIcon(origInstanceForUpdate.getIcon());
2340 if (StringUtils.isEmpty(resourceInstanceForUpdate.getComponentVersion()))
2341 resourceInstanceForUpdate.setComponentVersion(origInstanceForUpdate.getComponentVersion());
2343 if (StringUtils.isEmpty(resourceInstanceForUpdate.getComponentName()))
2344 resourceInstanceForUpdate.setComponentName(origInstanceForUpdate.getComponentName());
2346 if (StringUtils.isEmpty(resourceInstanceForUpdate.getToscaComponentName()))
2347 resourceInstanceForUpdate.setToscaComponentName(origInstanceForUpdate.getToscaComponentName());
2349 if (resourceInstanceForUpdate.getOriginType() == null) {
2350 resourceInstanceForUpdate.setOriginType(origInstanceForUpdate.getOriginType());
2352 if(resourceInstanceForUpdate.getOriginType() == OriginTypeEnum.ServiceProxy)
2353 resourceInstanceForUpdate.setIsProxy(true);
2354 if (resourceInstanceForUpdate.getSourceModelInvariant() == null) {
2355 resourceInstanceForUpdate.setSourceModelInvariant(origInstanceForUpdate.getSourceModelInvariant());
2357 if (resourceInstanceForUpdate.getSourceModelName() == null) {
2358 resourceInstanceForUpdate.setSourceModelName(origInstanceForUpdate.getSourceModelName());
2360 if (resourceInstanceForUpdate.getSourceModelUuid() == null) {
2361 resourceInstanceForUpdate.setSourceModelUuid(origInstanceForUpdate.getSourceModelUuid());
2363 if (resourceInstanceForUpdate.getSourceModelUid() == null) {
2364 resourceInstanceForUpdate.setSourceModelUid(origInstanceForUpdate.getSourceModelUid());
2366 return resourceInstanceForUpdate;
2369 * Returns list of ComponentInstanceProperty belonging to component instance capability specified by name, type and ownerId
2370 * @param containerComponentType
2371 * @param containerComponentId
2372 * @param componentInstanceUniqueId
2373 * @param capabilityType
2374 * @param capabilityName
2379 public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstanceCapabilityPropertiesById(String containerComponentType, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName, String ownerId, String userId) {
2381 Component containerComponent = null;
2383 Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
2385 validateUserExists(userId, "Get Component Instance Properties By Id", false);
2386 if(resultOp == null){
2387 Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentType);
2388 if (validateComponentType.isRight()) {
2389 resultOp = Either.right(validateComponentType.right().value());
2392 if(resultOp == null){
2393 Either<Component, StorageOperationStatus> validateContainerComponentExists = toscaOperationFacade.getToscaFullElement(containerComponentId);
2394 if (validateContainerComponentExists.isRight()) {
2395 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(validateContainerComponentExists.right().value())));
2397 containerComponent = validateContainerComponentExists.left().value();
2400 if(resultOp == null){
2401 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId);
2402 if (resourceInstanceStatus.isRight()) {
2403 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId));
2405 resultOp = findCapabilityOfInstance(containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, resourceInstanceStatus.left().value().getCapabilities());
2410 unlockComponent(resultOp, containerComponent);
2414 private Either<List<ComponentInstanceProperty>, ResponseFormat> findCapabilityOfInstance( String componentId, String instanceId, String capabilityType, String capabilityName, String ownerId, Map<String, List<CapabilityDefinition>> instanceCapabilities) {
2415 Either<List<ComponentInstanceProperty>, ResponseFormat> result = null;
2416 CapabilityDefinition foundCapability;
2417 if (MapUtils.isNotEmpty(instanceCapabilities)) {
2418 List<CapabilityDefinition> capabilitiesPerType = instanceCapabilities.get(capabilityType);
2419 if (capabilitiesPerType != null) {
2420 Optional<CapabilityDefinition> capabilityOpt = capabilitiesPerType.stream().filter(c -> c.getName().equals(capabilityName) && c.getOwnerId().equals(ownerId)).findFirst();
2421 if (capabilityOpt.isPresent()) {
2422 foundCapability = capabilityOpt.get();
2423 result = Either.left(foundCapability.getProperties() == null ? new ArrayList<>() : foundCapability.getProperties());
2427 if (result == null) {
2428 result = fetchComponentInstanceCapabilityProperties(componentId, instanceId, capabilityType, capabilityName, ownerId);
2433 private Either<List<ComponentInstanceProperty>, ResponseFormat> fetchComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityType, String capabilityName, String ownerId) {
2434 Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
2436 Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties = toscaOperationFacade.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType, ownerId);
2437 if(getComponentInstanceCapabilityProperties.isRight()){
2438 resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getComponentInstanceCapabilityProperties.right().value()), capabilityType, instanceId, componentId));
2440 resultOp = Either.left(getComponentInstanceCapabilityProperties.left().value());
2442 } catch(Exception e){
2443 log.error("The exception {} occurred upon the component {} instance {} capability {} properties retrieving. ", componentId, instanceId, capabilityName, e);
2444 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
2449 private ResponseFormat updateCapabilityPropertyOnContainerComponent(ComponentInstanceProperty property, String newValue, Component containerComponent, ComponentInstance foundResourceInstance,
2450 String capabilityType, String capabilityName, String ownerId) {
2451 String componentInstanceUniqueId = foundResourceInstance.getUniqueId();
2452 StringBuilder sb = new StringBuilder(componentInstanceUniqueId);
2453 sb.append(ModelConverter.CAP_PROP_DELIM).append(property.getOwnerId()).append(ModelConverter.CAP_PROP_DELIM).append(capabilityType).append(ModelConverter.CAP_PROP_DELIM).append(capabilityName);
2454 String capKey = sb.toString();
2456 Map<String, List<CapabilityDefinition>> capabilities = Optional.ofNullable(foundResourceInstance.getCapabilities())
2457 .orElse(Collections.emptyMap());
2458 List<CapabilityDefinition> capPerType = Optional.ofNullable(capabilities.get(capabilityType)).orElse(Collections.emptyList());
2459 Optional<CapabilityDefinition> cap = capPerType.stream().filter(c -> c.getName().equals(capabilityName) && c.getOwnerId().equals(ownerId)).findAny();
2460 if (cap.isPresent()) {
2461 List<ComponentInstanceProperty> capProperties = cap.get().getProperties();
2462 if (capProperties != null) {
2463 Optional<ComponentInstanceProperty> instanceProperty = capProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
2464 StorageOperationStatus status;
2465 if (instanceProperty.isPresent()) {
2466 instanceProperty.get().setValue(newValue);
2467 List<String> path = new ArrayList<>();
2468 path.add(componentInstanceUniqueId);
2470 instanceProperty.get().setPath(path);
2471 status = toscaOperationFacade.updateComponentInstanceCapabiltyProperty(containerComponent, componentInstanceUniqueId, capKey, instanceProperty.get());
2472 if (status != StorageOperationStatus.OK) {
2473 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
2474 return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, "");
2477 foundResourceInstance.setCustomizationUUID(UUID.randomUUID().toString());
2481 return componentsUtils.getResponseFormat(ActionStatus.OK);
2484 public Either<List<ComponentInstanceProperty>, ResponseFormat> updateInstanceCapabilityProperties(ComponentTypeEnum componentTypeEnum, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName, String ownerId,
2485 List<ComponentInstanceProperty> properties, String userId) {
2486 Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
2488 validateUserExists(userId, "update instance capability property", false);
2490 if (componentTypeEnum == null) {
2491 BeEcompErrorManager.getInstance().logInvalidInputError("updateInstanceCapabilityProperty", "invalid component type", ErrorSeverity.INFO);
2492 return Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
2494 Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade.getToscaFullElement(containerComponentId);
2496 if (getResourceResult.isRight()) {
2497 log.debug("Failed to retrieve component, component id {}", containerComponentId);
2498 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
2500 Component containerComponent = getResourceResult.left().value();
2502 if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
2503 log.info("Restricted operation for user: {sourcePropList} on component {}", userId, containerComponentId);
2504 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
2506 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId);
2507 if (resourceInstanceStatus.isRight()) {
2508 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId));
2510 ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
2512 StorageOperationStatus lockStatus = graphLockOperation.lockComponent(containerComponentId, componentTypeEnum.getNodeType());
2513 if (lockStatus != StorageOperationStatus.OK) {
2514 log.debug("Failed to lock component {}", containerComponentId);
2515 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
2518 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = dataTypeCache.getAll();
2519 if (allDataTypes.isRight()) {
2520 TitanOperationStatus status = allDataTypes.right().value();
2521 BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
2522 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertTitanStatusToStorageStatus(status))));
2526 for (ComponentInstanceProperty property : properties) {
2527 Either<String, ResponseFormat> newPropertyValueEither = updatePropertyObjectValue(property, false);
2528 newPropertyValueEither.bimap(updatedValue ->
2529 updateCapabilityPropertyOnContainerComponent(property,updatedValue, containerComponent, foundResourceInstance, capabilityType, capabilityName, ownerId),
2530 responseFormat -> Either.right(responseFormat));
2532 Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
2534 if (updateContainerRes.isRight()) {
2535 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
2536 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
2539 resultOp = Either.left(properties);
2543 if (resultOp == null || resultOp.isRight()) {
2544 titanDao.rollback();
2549 graphLockOperation.unlockComponent(containerComponentId, componentTypeEnum.getNodeType());
2553 public Either<List<ComponentInstanceProperty>, ResponseFormat> updateInstanceCapabilityProperties(ComponentTypeEnum componentTypeEnum, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName,
2554 List<ComponentInstanceProperty> properties, String userId) {
2555 Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
2557 validateUserExists(userId, "update instance capability property", false);
2559 if (componentTypeEnum == null) {
2560 BeEcompErrorManager.getInstance().logInvalidInputError("updateInstanceCapabilityProperty", "invalid component type", ErrorSeverity.INFO);
2561 return Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
2563 Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade.getToscaFullElement(containerComponentId);
2565 if (getResourceResult.isRight()) {
2566 log.debug("Failed to retrieve component, component id {}", containerComponentId);
2567 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
2569 Component containerComponent = getResourceResult.left().value();
2571 if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
2572 log.info("Restricted operation for user: {} on component {}", userId, containerComponentId);
2573 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
2575 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId);
2576 if (resourceInstanceStatus.isRight()) {
2577 return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId));
2579 ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
2581 StorageOperationStatus lockStatus = graphLockOperation.lockComponent(containerComponentId, componentTypeEnum.getNodeType());
2582 if (lockStatus != StorageOperationStatus.OK) {
2583 log.debug("Failed to lock component {}", containerComponentId);
2584 return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
2588 for (ComponentInstanceProperty property : properties) {
2589 Either<String, ResponseFormat> newPropertyValueEither = updatePropertyObjectValue(property, false);
2590 newPropertyValueEither.bimap(updatedValue ->
2591 updateCapabilityPropertyOnContainerComponent(property,updatedValue, containerComponent, foundResourceInstance, capabilityType, capabilityName),
2592 responseFormat -> Either.right(responseFormat));
2594 Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
2596 if (updateContainerRes.isRight()) {
2597 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
2598 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
2601 resultOp = Either.left(properties);
2605 if (resultOp == null || resultOp.isRight()) {
2606 titanDao.rollback();
2611 graphLockOperation.unlockComponent(containerComponentId, componentTypeEnum.getNodeType());
2615 public Either<Map<String, ComponentInstance>, ResponseFormat> copyComponentInstance(ComponentInstance inputComponentInstance,
2616 String containerComponentId,
2617 String componentInstanceId,
2620 Map<String, ComponentInstance> resultMap = new HashMap<>();
2621 Either<Component, StorageOperationStatus> getOrigComponent = toscaOperationFacade.getToscaElement(containerComponentId);
2622 if (getOrigComponent.isRight()) {
2623 log.error("Failed to get the original component information");
2624 return Either.right(componentsUtils.getResponseFormat(
2625 ActionStatus.USER_DEFINED, "Failed to copy the component instance to the canvas"));
2628 Component origComponent = getOrigComponent.left().value();
2630 Either<Boolean, ResponseFormat> lockComponent = lockComponent(origComponent, "copyComponentInstance");
2631 if (lockComponent.isRight()) {
2632 log.error("destComponentInstance's data is {}", origComponent.toString());
2633 return Either.right(lockComponent.right().value());
2637 Either<ComponentInstance, ResponseFormat> actionResponse = null;
2639 actionResponse = createComponentInstance(
2640 "services", containerComponentId, userId, inputComponentInstance, true, false);
2646 // on failure of the create instance unlock the resource and rollback the transaction.
2647 if (null== actionResponse || actionResponse.isRight()) {
2648 titanDao.rollback();
2649 log.error("Failed to copy the component instance to the canvas");
2651 unlockComponent(actionResponse, origComponent);
2653 return Either.right(componentsUtils.getResponseFormat(
2654 ActionStatus.USER_DEFINED, "Failed to copy the component instance to the canvas"));
2659 Either<String, ResponseFormat> resultOp = null;
2662 ComponentInstance destComponentInstance = actionResponse.left().value();
2663 log.debug("destComponentInstance's data is {}", destComponentInstance.toString());
2666 resultOp = deepCopyComponentInstance(
2667 origComponent, containerComponentId, componentInstanceId, destComponentInstance, userId);
2669 resultMap.put("componentInstance", destComponentInstance);
2673 unlockComponent(resultOp, origComponent);
2675 if (resultOp == null || resultOp.isRight()) {
2676 titanDao.rollback();
2677 log.error("Failed to deep copy component instance");
2678 return Either.right(componentsUtils.getResponseFormat(
2679 ActionStatus.USER_DEFINED, "Failed to deep copy the component instance to the canvas"));
2682 log.debug("Success trasaction commit");
2686 return Either.left(resultMap);
2689 private Either<String, ResponseFormat> deepCopyComponentInstance(
2690 Component sourceComponent, String containerComponentId, String sourceComponentInstanceId,
2691 ComponentInstance destComponentInstance, String userId) {
2693 Either<Component, StorageOperationStatus> getDestComponent = toscaOperationFacade.getToscaElement(containerComponentId);
2694 if (getDestComponent.isRight()) {
2695 log.error("Failed to get the dest component information");
2696 return Either.right(componentsUtils.getResponseFormat(
2697 ActionStatus.USER_DEFINED, "Failed to copy the component instance to the canvas"));
2700 Component destComponent = getDestComponent.left().value();
2702 Either<String, ResponseFormat> copyComponentInstanceWithPropertiesAndInputs = copyComponentInstanceWithPropertiesAndInputs(
2703 sourceComponent, destComponent, sourceComponentInstanceId, destComponentInstance, userId);
2704 if (copyComponentInstanceWithPropertiesAndInputs.isRight()) {
2705 log.error("Failed to copy component instance with properties and inputs as part of deep copy");
2706 return Either.right(componentsUtils.getResponseFormat(
2707 ActionStatus.USER_DEFINED, "Failed to copy the component instance with properties and inputs as part of deep copy"));
2710 Either<String, ResponseFormat> copyComponentInstanceWithAttributes = copyComponentInstanceWithAttributes(
2711 sourceComponent, destComponent, sourceComponentInstanceId, destComponentInstance, userId);
2712 if (copyComponentInstanceWithAttributes.isRight()) {
2713 log.error("Failed to copy component instance with attributes as part of deep copy");
2714 return Either.right(componentsUtils.getResponseFormat(
2715 ActionStatus.USER_DEFINED, "Failed to copy the component instance with attributes as part of deep copy"));
2717 return Either.left("Copy component Instance OK");
2720 private Either<String, ResponseFormat> copyComponentInstanceWithPropertiesAndInputs(
2721 Component sourceComponent, Component destComponent, String sourceComponentInstanceId,
2722 ComponentInstance destComponentInstance, String userId) {
2723 log.debug("start to copy ComponentInstance with properties and inputs");
2725 List<ComponentInstanceProperty> sourcePropList = null;
2726 if (sourceComponent.getComponentInstancesProperties() != null
2727 && sourceComponent.getComponentInstancesProperties().get(sourceComponentInstanceId) != null) {
2728 sourcePropList = sourceComponent.getComponentInstancesProperties().get(sourceComponentInstanceId);
2729 log.debug("sourcePropList");
2732 List<ComponentInstanceProperty> destPropList = null;
2733 String destComponentInstanceId = destComponentInstance.getUniqueId();
2734 log.debug("destComponentInstanceId: {}", destComponentInstance.getUniqueId());
2735 if (destComponent.getComponentInstancesProperties() != null
2736 && destComponent.getComponentInstancesProperties().get(destComponentInstanceId) != null) {
2737 destPropList = destComponent.getComponentInstancesProperties().get(destComponentInstanceId);
2738 log.debug("destPropList {}");
2741 List<ComponentInstancePropInput> componentInstancePropInputList = new ArrayList<>();
2743 if (null != destPropList && null != sourcePropList) {
2744 log.debug("start to set property and attribute");
2745 for (ComponentInstanceProperty destProp : destPropList) {
2746 String destPropertyName = destProp.getName();
2747 for (ComponentInstanceProperty sourceProp : sourcePropList) {
2748 if (!destPropertyName.equals(sourceProp.getName())) {
2751 log.debug("now set property");
2752 if (sourceProp.getGetInputValues() == null && !StringUtils.isEmpty(sourceProp.getValue())
2753 && (destProp.getValue() == null || !destProp.getValue().equals(sourceProp.getValue()))) {
2754 log.debug("Now starting to copy the property {} in value {}", destPropertyName, sourceProp.getValue());
2756 destProp.setValue(sourceProp.getValue());
2757 Either<String, ResponseFormat> updatePropertyValueEither = updateComponentInstanceProperty(
2758 destComponent.getUniqueId(), destComponentInstanceId, destProp);
2759 if (updatePropertyValueEither.isRight()) {
2760 log.error("Failed to copy the property {}", destPropertyName);
2761 return Either.right(componentsUtils.getResponseFormat(
2762 ActionStatus.INVALID_CONTENT_PARAM, "Failed to paste component instance to the canvas, property copy"));
2767 log.debug("Now start to update inputs");
2769 if (sourceProp.getGetInputValues() != null) {
2770 if (sourceProp.getGetInputValues().size() < 1) {
2771 log.debug("property is return from input, set by man");
2774 log.debug("Now starting to copy the {} property", destPropertyName);
2776 Either<String, ResponseFormat> getSourceInputDefaultValue = getInputListDefaultValue(
2777 sourceComponent, sourceProp.getGetInputValues().get(0).getInputId());
2778 if (getSourceInputDefaultValue.isRight()) {
2779 return Either.right(getSourceInputDefaultValue.right().value());
2781 componentInstancePropInputList.add(new ComponentInstancePropInput(destProp));
2786 return Either.left("Copy component Instance OK");
2789 private Either<String, ResponseFormat> copyComponentInstanceWithAttributes(Component sourceComponent,
2790 Component destComponent,
2791 String sourceComponentInstanceId,
2792 ComponentInstance destComponentInstance,
2794 String destComponentInstanceId = destComponentInstance.getUniqueId();
2796 log.info("start to copy component instance with attributes");
2798 List<ComponentInstanceProperty> sourceAttributeList = null;
2799 if (sourceComponent.getComponentInstancesAttributes() != null
2800 && sourceComponent.getComponentInstancesAttributes().get(sourceComponentInstanceId) != null) {
2801 sourceAttributeList = sourceComponent.getComponentInstancesAttributes().get(sourceComponentInstanceId);
2802 log.info("sourceAttributes {}");
2805 List<ComponentInstanceProperty> destAttributeList = null;
2806 if (destComponent.getComponentInstancesAttributes() != null
2807 && destComponent.getComponentInstancesAttributes().get(destComponentInstanceId) != null) {
2808 destAttributeList = destComponent.getComponentInstancesAttributes().get(destComponentInstanceId);
2809 log.info("destAttributeList {}");
2811 if (null != sourceAttributeList && null != destAttributeList) {
2812 log.info("set attribute");
2814 for (ComponentInstanceProperty sourceAttribute : sourceAttributeList) {
2815 String sourceAttributeName = sourceAttribute.getName();
2816 for (ComponentInstanceProperty destAttribute : destAttributeList) {
2817 if (sourceAttributeName.equals(destAttribute.getName())) {
2818 if (sourceAttribute.getValue() != null && !sourceAttribute.getValue().isEmpty()) {
2819 log.debug("Start to copy the attribute exists {}", sourceAttributeName);
2821 sourceAttribute.setUniqueId(
2822 UniqueIdBuilder.buildResourceInstanceUniuqeId(
2823 "attribute" , destComponentInstanceId.split("\\.")[1] , sourceAttributeName));
2825 Either<ComponentInstanceProperty, ResponseFormat> updateAttributeValueEither =
2826 createOrUpdateAttributeValueForCopyPaste(ComponentTypeEnum.SERVICE,
2827 destComponent.getUniqueId(), destComponentInstanceId, sourceAttribute,
2829 if (updateAttributeValueEither.isRight()) {
2830 log.error("Failed to copy the attribute");
2831 return Either.right(componentsUtils
2832 .getResponseFormat(ActionStatus.INVALID_CONTENT_PARAM,
2833 "Failed to paste component instance to the canvas, attribute copy"));
2842 return Either.left("Copy component Instance OK");
2845 private Either<ComponentInstanceProperty, ResponseFormat> createOrUpdateAttributeValueForCopyPaste(ComponentTypeEnum componentTypeEnum,
2847 String resourceInstanceId,
2848 ComponentInstanceProperty attribute,
2851 Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
2853 validateUserExists(userId, "Create or Update attribute value", false);
2855 if (componentTypeEnum == null) {
2856 BeEcompErrorManager.getInstance().logInvalidInputError(
2857 "createOrUpdateAttributeValue", "invalid component type", ErrorSeverity.INFO);
2858 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
2862 Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
2864 if (getResourceResult.isRight()) {
2865 log.info("Failed to retrieve component id {}", componentId);
2866 resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
2870 Component containerComponent = getResourceResult.left().value();
2872 Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, resourceInstanceId);
2874 if (resourceInstanceStatus.isRight()) {
2875 resultOp = Either.right(componentsUtils.getResponseFormat(
2876 ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, resourceInstanceId, componentId));
2880 ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
2883 String propertyType = attribute.getType();
2884 ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
2885 log.info("The type of attribute id{},is {} ", attribute.getUniqueId(), propertyType);
2887 if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
2888 SchemaDefinition def = attribute.getSchema();
2890 log.info("Schema doesn't exists for attribute of type {}", type);
2891 return Either.right(componentsUtils.getResponseFormat(
2892 componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
2894 PropertyDataDefinition propDef = def.getProperty();
2895 if (propDef == null) {
2896 log.info("Attribute in Schema Definition inside attribute of type {} doesn't exist", type);
2897 return Either.right(componentsUtils.getResponseFormat(
2898 componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
2902 List<ComponentInstanceProperty> instanceAttributes = containerComponent.
2903 getComponentInstancesAttributes().get(resourceInstanceId);
2904 Optional<ComponentInstanceProperty> instanceAttribute =
2905 instanceAttributes.stream().filter(p -> p.getUniqueId().equals(attribute.getUniqueId())).findAny();
2906 StorageOperationStatus status;
2908 if (instanceAttribute.isPresent()) {
2909 log.info("updateComponentInstanceAttribute");
2910 status = toscaOperationFacade.updateComponentInstanceAttribute(containerComponent, foundResourceInstance.getUniqueId(), attribute);
2912 log.info("addComponentInstanceAttribute");
2913 status = toscaOperationFacade.addComponentInstanceAttribute(containerComponent, foundResourceInstance.getUniqueId(), attribute);
2915 if (status != StorageOperationStatus.OK) {
2916 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
2917 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
2920 List<String> path = new ArrayList<>();
2921 path.add(foundResourceInstance.getUniqueId());
2922 attribute.setPath(path);
2924 foundResourceInstance.setCustomizationUUID(UUID.randomUUID().toString());
2925 Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.
2926 updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
2928 if (updateContainerRes.isRight()) {
2929 ActionStatus actionStatus = componentsUtils.
2930 convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
2931 resultOp = Either.right(componentsUtils.
2932 getResponseFormatForResourceInstanceProperty(actionStatus, ""));
2935 resultOp = Either.left(attribute);
2942 private Either<String, ResponseFormat> updateComponentInstanceProperty(String containerComponentId,
2943 String componentInstanceId,
2944 ComponentInstanceProperty property) {
2945 Either<String, ResponseFormat> resultOp;
2946 Either<Component, StorageOperationStatus> getComponent = toscaOperationFacade.getToscaElement(containerComponentId);
2948 if (getComponent.isRight()) {
2949 log.error("Failed to get the component information");
2950 return Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(
2951 ActionStatus.INVALID_CONTENT_PARAM, "Failed to get the component information"));
2954 Component containerComponent = getComponent.left().value();
2956 StorageOperationStatus status = toscaOperationFacade.updateComponentInstanceProperty(
2957 containerComponent, componentInstanceId, property);
2958 if (status != StorageOperationStatus.OK) {
2959 ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
2960 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
2964 Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.
2965 updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
2967 if (updateContainerRes.isRight()) {
2968 ActionStatus actionStatus = componentsUtils.
2969 convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
2970 resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
2974 return Either.left("Update OK");
2977 private Either<String, ResponseFormat> getInputListDefaultValue(Component component, String inputId) {
2978 List<InputDefinition> inputList = component.getInputs();
2979 for (InputDefinition input : inputList) {
2980 if (input.getUniqueId().equals(inputId)) {
2981 if (input.getDefaultValue() == null) {
2982 log.debug("The input's default value is null");
2983 return Either.left(null);
2985 return Either.left(input.getDefaultValue());
2988 log.error("The input's default value with id {} is not found", inputId);
2989 return Either.right(componentsUtils.getResponseFormat(
2990 ActionStatus.USER_DEFINED, "Failed to paste component instance to the canvas"));