summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-05-27 11:58:10 +0100
committerMichael Morris <michael.morris@est.tech>2022-06-02 13:38:18 +0000
commite159dee791441b68d142323f7d951b0592841c7f (patch)
tree246064e0cc3151f7b2604cb77531fcc6d4394fbb /catalog-be/src
parent27cbc536b9a8f10e32b2189effc5466cbe571701 (diff)
Support of get_property for instance properties
Support of get_property for INSTANCE properties, as currently only SELF properties can be selected. Change-Id: I80611002964a6ebb515134155c321f2d7f87811c Issue-ID: SDC-4026 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java56
4 files changed, 86 insertions, 4 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
index 99abb7b1ab..53f7c1d41a 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
@@ -2717,3 +2717,11 @@ errors:
messageId: "SVC4170"
}
+ #---------SVC4171-----------------------------
+ # %1 - Instance name
+ TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND: {
+ code: 404,
+ message: "The instance '%1' was not found.",
+ messageId: "SVC4171"
+ }
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index 1fa459da80..7ea00b1d46 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -2374,12 +2374,21 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
private <T extends PropertyDefinition> void validateToscaGetFunction(T property, Component parentComponent) {
final ToscaGetFunctionDataDefinition toscaGetFunction = property.getToscaGetFunction();
+ validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource());
if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_INPUT) {
validateGetFunction(property, parentComponent.getInputs(), parentComponent.getModel());
return;
}
if (toscaGetFunction.getFunctionType() == ToscaGetFunctionType.GET_PROPERTY) {
- validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel());
+ if (toscaGetFunction.getPropertySource() == PropertySource.SELF) {
+ validateGetFunction(property, parentComponent.getProperties(), parentComponent.getModel());
+ } else if (toscaGetFunction.getPropertySource() == PropertySource.INSTANCE) {
+ final ComponentInstance componentInstance =
+ parentComponent.getComponentInstanceById(toscaGetFunction.getSourceUniqueId())
+ .orElseThrow(ToscaGetFunctionExceptionSupplier.instanceNotFound(toscaGetFunction.getSourceName()));
+ validateGetFunction(property, componentInstance.getProperties(), parentComponent.getModel());
+ }
+
return;
}
@@ -2396,7 +2405,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
toscaGetFunction.getFunctionType()
).get();
}
- validateGetPropertySource(toscaGetFunction.getFunctionType(), toscaGetFunction.getPropertySource());
final String getFunctionPropertyUniqueId = toscaGetFunction.getPropertyUniqueId();
T referredProperty = (T) parentProperties.stream()
.filter(property1 -> getFunctionPropertyUniqueId.equals(property1.getUniqueId()))
@@ -2458,7 +2466,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
private void validateGetPropertySource(final ToscaGetFunctionType functionType, final PropertySource propertySource) {
- if (propertySource != PropertySource.SELF) {
+ if (functionType == ToscaGetFunctionType.GET_INPUT && propertySource != PropertySource.SELF) {
+ throw ToscaGetFunctionExceptionSupplier
+ .targetSourceNotSupported(functionType, propertySource).get();
+ }
+ if (functionType == ToscaGetFunctionType.GET_PROPERTY && !List.of(PropertySource.SELF, PropertySource.INSTANCE).contains(propertySource)) {
throw ToscaGetFunctionExceptionSupplier
.targetSourceNotSupported(functionType, propertySource).get();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java
index d54cb79ba5..5e1d005bfa 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaGetFunctionExceptionSupplier.java
@@ -91,4 +91,12 @@ public class ToscaGetFunctionExceptionSupplier {
functionType.getFunctionName(), referredPropertySchemaType, propertySchemaType
);
}
+
+ public static Supplier<ByActionStatusComponentException> instanceNotFound(final String instanceName) {
+ return () -> new ByActionStatusComponentException(
+ ActionStatus.TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND,
+ instanceName
+ );
+ }
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
index c0ad54c699..c7d66bf80f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
@@ -396,7 +396,7 @@ class ComponentInstanceBusinessLogicTest {
getPropertyPropertyName,
mapToscaType,
"string",
- String.format("get_property: [\"%s\"]", String.join(",", containerPropertyPath)),
+ String.format("\"get_property\": [\"%s\", \"%s\"]", PropertySource.SELF, String.join("\", \"", containerPropertyPath)),
createGetToscaFunction(containerPropertyPath.get(containerPropertyPath.size() - 1), containerPropertyId,
containerPropertyPath, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, containerComponentId, containerComponentName)
);
@@ -458,6 +458,60 @@ class ComponentInstanceBusinessLogicTest {
assertThat(actualResponseFormat.left().value()).isEqualTo(resourceInstanceProperties);
}
+ @Test
+ void testToscaGetPropertyOnInstanceValidation() {
+ final String userId = "userId";
+ final String containerComponentId = "containerComponentId";
+ final String containerComponentName = "containerComponentName";
+ final String instanceUniqueId = String.format("%s.%s", containerComponentId, "instanceId");
+
+ final List<String> parentPropertyPath = List.of("property1");
+ final String containerPropertyId = String.format("%s.%s", containerComponentId, parentPropertyPath.get(0));
+ final ComponentInstanceProperty getPropertyOnInstanceProperty = createComponentInstanceProperty(
+ String.format("%s.%s", containerComponentId, "getPropertyOnInstanceProperty"),
+ "getPropertyOnInstanceProperty",
+ "string",
+ null,
+ String.format("\"get_property\": [\"%s\", \"%s\"]", PropertySource.INSTANCE, parentPropertyPath.get(0)),
+ createGetToscaFunction(parentPropertyPath.get(0), containerPropertyId, parentPropertyPath, PropertySource.INSTANCE,
+ ToscaGetFunctionType.GET_PROPERTY, instanceUniqueId, containerComponentName)
+ );
+
+ //creating component that has the instance properties
+ final Component component = new Service();
+ component.setUniqueId(containerComponentId);
+ component.setName(containerComponentName);
+ component.setLastUpdaterUserId(userId);
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ //adding instance properties to the component
+ final List<ComponentInstanceProperty> resourceInstanceProperties = List.of(getPropertyOnInstanceProperty);
+ final Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
+ componentInstanceProps.put(instanceUniqueId, resourceInstanceProperties);
+ component.setComponentInstancesProperties(componentInstanceProps);
+
+ //creating resource property that will be get
+ final var propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName(parentPropertyPath.get(0));
+ propertyDefinition.setUniqueId(containerPropertyId);
+ final String property1Type = "string";
+ propertyDefinition.setType(property1Type);
+ //creating resource instance to be added to the component
+ final ComponentInstance resourceInstance = createComponentInstance("resourceInstance");
+ resourceInstance.setUniqueId(instanceUniqueId);
+ resourceInstance.setProperties(List.of(propertyDefinition));
+ component.setComponentInstances(List.of(resourceInstance));
+
+ mockComponentForToscaGetFunctionValidation(component);
+
+ //when
+ final Either<List<ComponentInstanceProperty>, ResponseFormat> actualResponseFormat = componentInstanceBusinessLogic
+ .createOrUpdatePropertiesValues(
+ ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentId, instanceUniqueId, resourceInstanceProperties, userId);
+ //then
+ assertTrue(actualResponseFormat.isLeft());
+ assertThat(actualResponseFormat.left().value()).isEqualTo(resourceInstanceProperties);
+ }
+
private DataTypeDefinition createDataType(final String name, final Map<String, String> propertyNameAndTypeMap) {
final var dataTypeDefinition = new DataTypeDefinition();
dataTypeDefinition.setName(name);