From 13af621442b4c74d9e63ede8e42dbae48aaa64c9 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Tue, 8 Oct 2019 18:27:36 +0100 Subject: Onboard PNF software version Change-Id: Id9e32e01f6c2f4c39c8ff10816d982cbb3063bf7 Issue-ID: SDC-2589 Signed-off-by: andre.schmid --- .../operations/ToscaOperationFacade.java | 63 ++++++++++------------ .../exception/ToscaOperationException.java | 36 +++++++++++++ 2 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index 43f3487924..ab08f5c339 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -2229,50 +2229,45 @@ public class ToscaOperationFacade { return nodeTemplateOperation.generateCustomizationUUIDOnInstanceGroup(componentId, instanceId, groupInstances); } - public Either addPropertyToComponent(String propertyName, + public Either addPropertyToComponent(String propertyName, PropertyDefinition newPropertyDefinition, Component component) { - - Either result = null; - Either getUpdatedComponentRes = null; newPropertyDefinition.setName(propertyName); StorageOperationStatus status = getToscaElementOperation(component) .addToscaDataToToscaElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, newPropertyDefinition, JsonPresentationFields.NAME); if (status != StorageOperationStatus.OK) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to add the property {} to the component {}. Status is {}. ", propertyName, component.getName(), status); - result = Either.right(status); - } - if (result == null) { - ComponentParametersView filter = new ComponentParametersView(true); - filter.setIgnoreProperties(false); - filter.setIgnoreInputs(false); - getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter); - if (getUpdatedComponentRes.isRight()) { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated component {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value()); - result = Either.right(status); - } - } - if (result == null) { - PropertyDefinition newProperty = null; - List properties = - (getUpdatedComponentRes.left().value()).getProperties(); - if (CollectionUtils.isNotEmpty(properties)) { - Optional propertyOptional = properties.stream().filter( - propertyEntry -> propertyEntry.getName().equals(propertyName)).findAny(); - if (propertyOptional.isPresent()) { - newProperty = propertyOptional.get(); - } - } - if (newProperty == null) { - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the component {}. Status is {}. ", propertyName, component.getUniqueId(), StorageOperationStatus.NOT_FOUND); - result = Either.right(StorageOperationStatus.NOT_FOUND); - } else { - result = Either.left(newProperty); - } + return Either.right(status); } - return result; + + ComponentParametersView filter = new ComponentParametersView(true); + filter.setIgnoreProperties(false); + filter.setIgnoreInputs(false); + Either getUpdatedComponentRes = getToscaElement(component.getUniqueId(), filter); + if (getUpdatedComponentRes.isRight()) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to get updated component {}. Status is {}. ", component.getUniqueId(), getUpdatedComponentRes.right().value()); + return Either.right(status); + } + + PropertyDefinition newProperty = null; + List properties = + (getUpdatedComponentRes.left().value()).getProperties(); + if (CollectionUtils.isNotEmpty(properties)) { + Optional propertyOptional = properties.stream().filter( + propertyEntry -> propertyEntry.getName().equals(propertyName)).findAny(); + if (propertyOptional.isPresent()) { + newProperty = propertyOptional.get(); + } + } + if (newProperty == null) { + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find recently added property {} on the component {}. Status is {}. ", propertyName, component.getUniqueId(), StorageOperationStatus.NOT_FOUND); + return Either.right(StorageOperationStatus.NOT_FOUND); + } + + return Either.left(newProperty); } + public StorageOperationStatus deletePropertyOfComponent(Component component, String propertyName) { return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, propertyName, JsonPresentationFields.NAME); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java new file mode 100644 index 0000000000..b5b7da8d26 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ToscaOperationException.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception; + +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; + +public class ToscaOperationException extends Exception { + + private final StorageOperationStatus storageOperationStatus; + + public ToscaOperationException(String s, StorageOperationStatus storageOperationStatus) { + super(String.format("%s. Operation Status: %s", s, storageOperationStatus.name())); + this.storageOperationStatus = storageOperationStatus; + } + + public StorageOperationStatus getStorageOperationStatus() { + return storageOperationStatus; + } +} -- cgit 1.2.3-korg