diff options
author | Smokowski, Steven <steve.smokowski@att.com> | 2019-08-15 21:40:16 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2019-08-15 21:43:44 -0400 |
commit | fa36daa658a50d9ca2e57cae649d63c0e9e2882a (patch) | |
tree | 09bec4b384664e59c5e3671eec5f17f8c68e8a02 /bpmn/so-bpmn-tasks | |
parent | e536a1035d0f224de32f76a1226c772b8f8d7c01 (diff) |
Initial commit of validation framework to APIH
Move ListenerRunner to common location
Adjust request params name, update junit tests
Update validations to work properly
Properly escape period for the string split
Issue-ID: SO-2232
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Ia468cf7062cccf30e28afeb7a5cddc37ceb2e002
Diffstat (limited to 'bpmn/so-bpmn-tasks')
5 files changed, 58 insertions, 27 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java index 68cfd487b3..bd60fbe38c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java @@ -71,6 +71,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import com.google.common.base.Strings; @Component public class AAICreateTasks { @@ -184,24 +185,35 @@ public class AAICreateTasks { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); OwningEntity owningEntity = serviceInstance.getOwningEntity(); - String owningEntityId = owningEntity.getOwningEntityId(); - String owningEntityName = owningEntity.getOwningEntityName(); - if (owningEntityId == null || "".equals(owningEntityId)) { - String msg = "Exception in AAICreateOwningEntity. OwningEntityId is null."; + if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId()) + && Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) { + String msg = "Exception in AAICreateOwningEntity. OwningEntityId and Name are null."; execution.setVariable("ErrorCreateOEAAI", msg); exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); + } else if (Strings.isNullOrEmpty(owningEntity.getOwningEntityId()) + && !Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) { + if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) { + org.onap.aai.domain.yang.OwningEntity aaiEntity = + aaiSIResources.getOwningEntityByName(owningEntity.getOwningEntityName()); + owningEntity.setOwningEntityId(aaiEntity.getOwningEntityId()); + owningEntity.setOwningEntityName(owningEntity.getOwningEntityName()); + aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance); + } else { + owningEntity.setOwningEntityId(UUID.randomUUID().toString()); + aaiSIResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance); + } } else { if (aaiSIResources.existsOwningEntity(owningEntity)) { aaiSIResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance); } else { - if (owningEntityName == null || "".equals(owningEntityName)) { + if (Strings.isNullOrEmpty(owningEntity.getOwningEntityName())) { String msg = "Exception in AAICreateOwningEntity. Can't create an owningEntity with no owningEntityName."; logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue(), msg); exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); } else { - if (aaiSIResources.existsOwningEntityName(owningEntityName)) { + if (aaiSIResources.existsOwningEntityName(owningEntity.getOwningEntityName())) { String msg = "Exception in AAICreateOwningEntity. Can't create OwningEntity as name already exists in AAI associated with a different owning-entity-id (name must be unique)"; logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java index fc3f2aec7a..52d294955a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java @@ -23,10 +23,10 @@ package org.onap.so.bpmn.infrastructure.validations; import java.util.Optional; import java.util.regex.Pattern; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.listener.Skip; import org.onap.so.bpmn.common.listener.validation.PreBuildingBlockValidator; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.listener.Skip; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIEntityNotFoundException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIEntityNotFoundException.java new file mode 100644 index 0000000000..5f65e5d76d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIEntityNotFoundException.java @@ -0,0 +1,16 @@ +package org.onap.so.client.orchestration; + +public class AAIEntityNotFoundException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -107868951852460677L; + + public AAIEntityNotFoundException(String error) { + super(error); + } + + + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java index c41f3fa56c..fc1528526c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java @@ -22,7 +22,9 @@ package org.onap.so.client.orchestration; +import java.util.List; import java.util.Optional; +import org.onap.aai.domain.yang.OwningEntities; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; @@ -120,6 +122,25 @@ public class AAIServiceInstanceResources { return aaiRC.exists(owningEntityUri); } + public org.onap.aai.domain.yang.OwningEntity getOwningEntityByName(String owningEntityName) + throws AAIEntityNotFoundException { + AAIResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.OWNING_ENTITY) + .queryParam("owning-entity-name", owningEntityName); + AAIResourcesClient aaiRC = injectionHelper.getAaiClient(); + Optional<OwningEntities> owningEntities = aaiRC.get(OwningEntities.class, owningEntityUri); + if (owningEntities.isPresent()) { + List<org.onap.aai.domain.yang.OwningEntity> owningEntityList = owningEntities.get().getOwningEntity(); + if (owningEntityList.size() > 1) { + throw new AAIEntityNotFoundException( + "Non unique result returned for owning entity name: " + owningEntityName); + } else { + return owningEntityList.get(0); + } + } else { + throw new AAIEntityNotFoundException("No result returned for owning entity name: " + owningEntityName); + } + } + public void connectOwningEntityandServiceInstance(OwningEntity owningEntity, ServiceInstance serviceInstance) { AAIResourceUri owningEntityURI = AAIUriFactory.createResourceUri(AAIObjectType.OWNING_ENTITY, owningEntity.getOwningEntityId()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java index ed3ec759c3..a8550d8df9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java @@ -54,16 +54,16 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.OrchestrationStatus; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; public class AAICreateTasksTest extends BaseTaskTest { @@ -272,24 +272,6 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createOwningEntityNullOwningEntityIdTest() throws Exception { - expectedException.expect(BpmnError.class); - - serviceInstance.getOwningEntity().setOwningEntityId(null); - - aaiCreateTasks.createOwningEntity(execution); - } - - @Test - public void createOwningEntityEmptyOwningEntityIdTest() throws Exception { - expectedException.expect(BpmnError.class); - - serviceInstance.getOwningEntity().setOwningEntityId(""); - - aaiCreateTasks.createOwningEntity(execution); - } - - @Test public void createOwningEntityNullOwningEntityNameTest() throws Exception { expectedException.expect(BpmnError.class); |