diff options
author | Steve Smokowski <ss835w@att.com> | 2019-08-16 13:06:00 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-08-16 13:06:00 +0000 |
commit | 4c41bf52c861e9a517e61beb9252349037fa6417 (patch) | |
tree | 64ccd6f5c4d7d5fd7404efe96a49a594997408f0 /bpmn | |
parent | 27eb14bb20dddcbb3a1ef6abbc5adedbb628c5bd (diff) | |
parent | fa36daa658a50d9ca2e57cae649d63c0e9e2882a (diff) |
Merge "Initial commit of validation framework to APIH"
Diffstat (limited to 'bpmn')
14 files changed, 71 insertions, 124 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/ListenerRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/ListenerRunner.java deleted file mode 100644 index 3c36052dca..0000000000 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/ListenerRunner.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.common.listener; - -import java.lang.annotation.Annotation; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import javax.annotation.Priority; -import org.onap.so.client.exception.ExceptionBuilder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; - -public abstract class ListenerRunner { - - @Autowired - protected ApplicationContext context; - - @Autowired - protected ExceptionBuilder exceptionBuilder; - - protected <T> List<T> filterListeners(List<T> validators, Predicate<T> predicate) { - return validators.stream().filter(item -> { - return !item.getClass().isAnnotationPresent(Skip.class) && predicate.test(item); - }).sorted(Comparator.comparing(item -> { - Priority p = Optional.ofNullable(item.getClass().getAnnotation(Priority.class)).orElse(new Priority() { - public int value() { - return 1000; - } - - @Override - public Class<? extends Annotation> annotationType() { - return Priority.class; - } - }); - return p.value(); - })).collect(Collectors.toList()); - } - -} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/Skip.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/Skip.java deleted file mode 100644 index a0543fd3cc..0000000000 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/Skip.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.common.listener; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface Skip { - -} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java index 68cda5c22b..69151ff74f 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/db/RequestsDbListenerRunner.java @@ -27,9 +27,9 @@ import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.PostConstruct; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.listener.ListenerRunner; import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.listener.ListenerRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java index 5f4dc871fb..ea7de687ee 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/flowmanipulator/FlowManipulatorListenerRunner.java @@ -27,8 +27,8 @@ import java.util.Optional; import java.util.stream.Collectors; import javax.annotation.PostConstruct; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.listener.ListenerRunner; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.listener.ListenerRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/FlowValidatorRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/FlowValidatorRunner.java index 040522b576..02cddf3655 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/FlowValidatorRunner.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/FlowValidatorRunner.java @@ -28,9 +28,11 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.DelegateExecutionImpl; -import org.onap.so.bpmn.common.listener.ListenerRunner; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.listener.ListenerRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -47,6 +49,9 @@ public abstract class FlowValidatorRunner<S extends FlowValidator, E extends Flo private static Logger logger = LoggerFactory.getLogger(FlowValidatorRunner.class); + @Autowired + protected ExceptionBuilder exceptionBuilder; + protected List<S> preFlowValidators; protected List<E> postFlowValidators; diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/BuildingBlockValidatorRunnerTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/BuildingBlockValidatorRunnerTest.java index 2c0377d11c..f4fe6d7158 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/BuildingBlockValidatorRunnerTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/BuildingBlockValidatorRunnerTest.java @@ -47,7 +47,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {ValidationConfig.class}) -public class BuildingBlockValidatorRunnerTest { +public class BuildingBlockValidatorRunnerTest extends BuildingBlockValidatorRunner { @Rule public ExpectedException thrown = ExpectedException.none(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/WorkflowValidatorRunnerTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/WorkflowValidatorRunnerTest.java index 0143e567af..596eced1d1 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/WorkflowValidatorRunnerTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/WorkflowValidatorRunnerTest.java @@ -45,7 +45,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {ValidationConfig.class}) -public class WorkflowValidatorRunnerTest { +public class WorkflowValidatorRunnerTest extends WorkflowValidatorRunner { @Rule public ExpectedException thrown = ExpectedException.none(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/MyDisabledValidator.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/MyDisabledValidator.java index af64ed2de6..544d370a3c 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/MyDisabledValidator.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/MyDisabledValidator.java @@ -23,8 +23,8 @@ package org.onap.so.bpmn.common.listener.validation; import java.util.Collections; import java.util.Optional; 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.listener.Skip; import org.springframework.stereotype.Component; @Component diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/ValidationConfig.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/ValidationConfig.java index 068f433dd5..a3692a50b7 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/ValidationConfig.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/listener/validation/ValidationConfig.java @@ -21,13 +21,13 @@ package org.onap.so.bpmn.common.listener.validation; import org.onap.so.bpmn.common.DefaultToShortClassNameBeanNameGenerator; -import org.onap.so.bpmn.common.listener.ListenerRunner; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.listener.ListenerRunner; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration -@ComponentScan(basePackageClasses = {ExceptionBuilder.class, ListenerRunner.class}, +@ComponentScan(basePackageClasses = {ExceptionBuilder.class, ListenerRunner.class, WorkflowValidatorRunner.class}, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class) public class ValidationConfig { 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); |