diff options
25 files changed, 543 insertions, 246 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java index f2e0762a79..fca1d3a45e 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java @@ -46,32 +46,8 @@ import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceMacroHolder; import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceNetworks; import org.onap.so.adapters.catalogdb.catalogrest.QueryServiceVnfs; import org.onap.so.adapters.catalogdb.catalogrest.QueryVfModule; -import org.onap.so.db.catalog.beans.AllottedResource; -import org.onap.so.db.catalog.beans.AllottedResourceCustomization; -import org.onap.so.db.catalog.beans.InstanceGroup; -import org.onap.so.db.catalog.beans.NetworkResource; -import org.onap.so.db.catalog.beans.NetworkResourceCustomization; -import org.onap.so.db.catalog.beans.Recipe; -import org.onap.so.db.catalog.beans.Service; -import org.onap.so.db.catalog.beans.ToscaCsar; -import org.onap.so.db.catalog.beans.VfModule; -import org.onap.so.db.catalog.beans.VfModuleCustomization; -import org.onap.so.db.catalog.beans.VnfRecipe; -import org.onap.so.db.catalog.beans.VnfResource; -import org.onap.so.db.catalog.beans.VnfResourceCustomization; -import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository; -import org.onap.so.db.catalog.data.repository.AllottedResourceRepository; -import org.onap.so.db.catalog.data.repository.ArRecipeRepository; -import org.onap.so.db.catalog.data.repository.InstanceGroupRepository; -import org.onap.so.db.catalog.data.repository.NetworkRecipeRepository; -import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository; -import org.onap.so.db.catalog.data.repository.NetworkResourceRepository; -import org.onap.so.db.catalog.data.repository.ServiceRepository; -import org.onap.so.db.catalog.data.repository.ToscaCsarRepository; -import org.onap.so.db.catalog.data.repository.VFModuleRepository; -import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository; -import org.onap.so.db.catalog.data.repository.VnfRecipeRepository; -import org.onap.so.db.catalog.data.repository.VnfResourceRepository; +import org.onap.so.db.catalog.beans.*; +import org.onap.so.db.catalog.data.repository.*; import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,6 +102,9 @@ public class CatalogDbAdapterRest { @Autowired private InstanceGroupRepository instanceGroupRepository; + @Autowired + private ServiceInfoRepository serviceInfoRepository; + private static final String NO_MATCHING_PARAMETERS = "no matching parameters"; public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) { @@ -328,6 +307,8 @@ public class CatalogDbAdapterRest { respStatus = HttpStatus.SC_NOT_FOUND; qryResp = new QueryServiceMacroHolder(); } else { + ServiceInfo serviceInfo = serviceInfoRepository.findByService(ret.getService()); + ret.setServiceInfo(serviceInfo); qryResp = new QueryServiceMacroHolder(ret); logger.debug("serviceMacroHolder qryResp= {}", qryResp); } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml index 977541cc16..54f05859d9 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml @@ -103,6 +103,8 @@ </goals> <configuration> <sources> + <source>${project.basedir}/target/generated-sources/etsicatalog/notification/src/gen/java/main</source> + <source>${project.basedir}/target/generated-sources/sol003-vnf-packagemanagement/notification/src/gen/java/main</source> <source>${project.basedir}/target/generated-sources/vnfmadapter/src/gen/java/main</source> </sources> </configuration> @@ -110,6 +112,36 @@ </executions> </plugin> </plugins> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>io.swagger</groupId> + <artifactId>swagger-codegen-maven-plugin</artifactId> + <goals> + <goal>generate</goal> + </goals> + <versionRange>[2.2.0,)</versionRange> + </pluginExecutionFilter> + <action> + <execute> + <runOnIncremental>false</runOnIncremental> + </execute> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> </build> <dependencies> <dependency> diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml index dacd5d96b6..ab524ca808 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml +++ b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-ext-clients/pom.xml @@ -156,6 +156,36 @@ </executions> </plugin> </plugins> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>io.swagger</groupId> + <artifactId>swagger-codegen-maven-plugin</artifactId> + <goals> + <goal>generate</goal> + </goals> + <versionRange>[2.2.0,)</versionRange> + </pluginExecutionFilter> + <action> + <execute> + <runOnIncremental>false</runOnIncremental> + </execute> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> </build> <dependencies> diff --git a/bpmn/so-bpmn-tasks/pom.xml b/bpmn/so-bpmn-tasks/pom.xml index cffb67a968..47415240f9 100644 --- a/bpmn/so-bpmn-tasks/pom.xml +++ b/bpmn/so-bpmn-tasks/pom.xml @@ -97,6 +97,36 @@ </executions> </plugin> </plugins> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>io.swagger</groupId> + <artifactId>swagger-codegen-maven-plugin</artifactId> + <goals> + <goal>generate</goal> + </goals> + <versionRange>[2.2.0,)</versionRange> + </pluginExecutionFilter> + <action> + <execute> + <runOnIncremental>false</runOnIncremental> + </execute> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> </build> <dependencyManagement> <dependencies> diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java index a162088cb2..7e5cf19b21 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java @@ -45,9 +45,7 @@ import java.util.Map; @Component public class AAIUpdateTasks { private static final Logger logger = LoggerFactory.getLogger(AAIUpdateTasks.class); - private static final String ALACARTE = "aLaCarte"; - private static final String MULTI_STAGE_DESIGN_OFF = "false"; - private static final String MULTI_STAGE_DESIGN_ON = "true"; + @Autowired private AAIServiceInstanceResources aaiServiceInstanceResources; @Autowired @@ -149,8 +147,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update HeatStackId and VolumeGroup in AAI - * - * @param execution */ public void updateHeatStackIdVolumeGroup(BuildingBlockExecution execution) { try { @@ -172,87 +168,27 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of VfModule to Assigned in AAI - * - * @param execution */ public void updateOrchestrationStatusAssignedVfModule(BuildingBlockExecution execution) { - try { - VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - vfModule.setHeatStackId(""); - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.ASSIGNED); - } catch (Exception ex) { - logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusAssignedVfModule", ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } + updateOrchestrationStatusForVfModule(execution, OrchestrationStatus.ASSIGNED); } /** * BPMN access method to update status of VfModule to PendingActivation in AAI - * - * @param execution */ public void updateOrchestrationStatusPendingActivationVfModule(BuildingBlockExecution execution) { - try { - VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, - OrchestrationStatus.PENDING_ACTIVATION); - } catch (Exception ex) { - logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusPendingActivationVfModule", ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } - } - - /** - * BPMN access method to update status of VfModule to AssignedOrPendingActivation in AAI - * - * @param execution - */ - public void updateOrchestrationStatusAssignedOrPendingActivationVfModule(BuildingBlockExecution execution) { - try { - VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - vfModule.setHeatStackId(""); - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - String multiStageDesign = MULTI_STAGE_DESIGN_OFF; - if (vnf.getModelInfoGenericVnf() != null) { - multiStageDesign = vnf.getModelInfoGenericVnf().getMultiStageDesign(); - } - boolean aLaCarte = (boolean) execution.getVariable(ALACARTE); - if (aLaCarte && multiStageDesign != null && multiStageDesign.equalsIgnoreCase(MULTI_STAGE_DESIGN_ON)) { - aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, - OrchestrationStatus.PENDING_ACTIVATION); - } else { - aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.ASSIGNED); - } - } catch (Exception ex) { - logger.error( - "Exception occurred in AAIUpdateTasks updateOrchestrationStatusAssignedOrPendingActivationVfModule", - ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } + updateOrchestrationStatusForVfModule(execution, OrchestrationStatus.PENDING_ACTIVATION); } /** * BPMN access method to update status of VfModule to Created in AAI - * - * @param execution */ public void updateOrchestrationStatusCreatedVfModule(BuildingBlockExecution execution) { - try { - VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.CREATED); - } catch (Exception ex) { - logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusCreatedVfModule", ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } + updateOrchestrationStatusForVfModule(execution, OrchestrationStatus.CREATED); } /** * BPMN access method to update aaiDeactivateVfModuleRollback to true for deactivating the VfModule - * - * @param execution */ public void updateOrchestrationStatusDeactivateVfModule(BuildingBlockExecution execution) { execution.setVariable("aaiDeactivateVfModuleRollback", false); @@ -800,4 +736,20 @@ public class AAIUpdateTasks { } } + private void updateOrchestrationStatusForVfModule(BuildingBlockExecution execution, OrchestrationStatus status) { + try { + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + if (status.equals(OrchestrationStatus.ASSIGNED)) { + vfModule.setHeatStackId(""); + } + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, status); + } catch (Exception ex) { + logger.error( + "Exception occurred in AAIUpdateTasks during update orchestration status to {} for " + "vf module", + status, ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index e26009a1de..e5b003a437 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -40,7 +40,6 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; 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.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.OrchestrationStatus; import java.util.HashMap; @@ -258,60 +257,6 @@ public class AAIUpdateTasksTest extends BaseTaskTest { } @Test - public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception { - execution.setVariable("aLaCarte", true); - ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setMultiStageDesign("false"); - genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); - doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, - OrchestrationStatus.ASSIGNED); - aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); - verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, - OrchestrationStatus.ASSIGNED); - assertEquals("", vfModule.getHeatStackId()); - } - - @Test - public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest() - throws Exception { - execution.setVariable("aLaCarte", false); - ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setMultiStageDesign("true"); - genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); - doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, - OrchestrationStatus.ASSIGNED); - aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); - verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, - OrchestrationStatus.ASSIGNED); - assertEquals("", vfModule.getHeatStackId()); - } - - @Test - public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception { - execution.setVariable("aLaCarte", true); - ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setMultiStageDesign("true"); - genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); - doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, - OrchestrationStatus.PENDING_ACTIVATION); - aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); - verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, - OrchestrationStatus.PENDING_ACTIVATION); - assertEquals("", vfModule.getHeatStackId()); - } - - @Test - public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception { - execution.setVariable("aLaCarte", true); - doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, - genericVnf, OrchestrationStatus.ASSIGNED); - - expectedException.expect(BpmnError.class); - - aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution); - } - - @Test public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception { doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); diff --git a/common/src/main/java/org/onap/so/client/RestClient.java b/common/src/main/java/org/onap/so/client/RestClient.java index 077ba24c2b..30389de742 100644 --- a/common/src/main/java/org/onap/so/client/RestClient.java +++ b/common/src/main/java/org/onap/so/client/RestClient.java @@ -188,8 +188,7 @@ public abstract class RestClient { client.register(new PayloadLoggingClientFilter(this.getMaxPayloadSize())); } CommonObjectMapperProvider provider = this.getCommonObjectMapperProvider(); - client.register(new JacksonJsonProvider(provider.getMapper())); - + client.register(provider).register(new JacksonJsonProvider(provider.getMapper())); metricLogClientFilter = new SOMetricLogClientFilter(); mdcSetup.setTargetEntity(getTargetEntity()); client.register(metricLogClientFilter); diff --git a/common/src/main/java/org/onap/so/client/aai/AAIVersion.java b/common/src/main/java/org/onap/so/client/aai/AAIVersion.java index 4f06b787f7..42887884db 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIVersion.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIVersion.java @@ -23,7 +23,16 @@ package org.onap.so.client.aai; import org.onap.so.client.graphinventory.GraphInventoryVersion; public enum AAIVersion implements GraphInventoryVersion { - V13("v13"), V14("v14"), V15("v15"), V16("v16"), V17("v17"), V18("v18"), V19("v19"); + V10("V10"), + V11("V11"), + V12("V12"), + V13("v13"), + V14("v14"), + V15("v15"), + V16("v16"), + V17("v17"), + V18("v18"), + V19("v19"); public static final AAIVersion LATEST = AAIVersion.values()[AAIVersion.values().length - 1]; private final String value; diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNode.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeBase.java index 7ee5bd328e..5802e9c4e8 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNode.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeBase.java @@ -26,41 +26,51 @@ import java.util.List; import org.onap.so.client.aai.entities.QueryStep; import org.onap.so.client.graphinventory.GraphInventoryObjectName; -public class DSLNode implements QueryStep { +public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep { - private final String nodeName; - private final List<DSLNodeKey> nodeKeys; - private final StringBuilder query = new StringBuilder(); - private boolean output = false; + protected final String nodeName; + protected final List<DSLNodeKey> nodeKeys; + protected final StringBuilder query; + protected boolean output = false; - public DSLNode() { + public DSLNodeBase() { this.nodeName = ""; this.nodeKeys = new ArrayList<>(); + this.query = new StringBuilder(); } - public DSLNode(GraphInventoryObjectName name) { + public DSLNodeBase(GraphInventoryObjectName name) { this.nodeName = name.typeName(); this.nodeKeys = new ArrayList<>(); + this.query = new StringBuilder(); query.append(nodeName); } - public DSLNode(GraphInventoryObjectName name, DSLNodeKey... key) { + public DSLNodeBase(GraphInventoryObjectName name, DSLNodeKey... key) { this.nodeName = name.typeName(); this.nodeKeys = Arrays.asList(key); + this.query = new StringBuilder(); query.append(nodeName); } - public DSLNode output() { + public DSLNodeBase(DSLNodeBase<?> copy) { + this.nodeName = copy.nodeName; + this.nodeKeys = copy.nodeKeys; + this.query = new StringBuilder(copy.query); + this.output = copy.output; + } + + public DSLOutputNode output() { this.output = true; - return this; + return new DSLOutputNode(this); } - public DSLNode and(DSLNodeKey... key) { + public T and(DSLNodeKey... key) { this.nodeKeys.addAll(Arrays.asList(key)); - return this; + return (T) this; } @Override diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLOutputNode.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLOutputNode.java new file mode 100644 index 0000000000..d799795650 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLOutputNode.java @@ -0,0 +1,8 @@ +package org.onap.so.client.graphinventory.entities; + +public class DSLOutputNode extends DSLNodeBase<DSLOutputNode> implements Output { + + public DSLOutputNode(DSLNodeBase<?> copy) { + super(copy); + } +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQuery.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQuery.java index 3056c9ca80..1fa79a714c 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQuery.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQuery.java @@ -31,17 +31,11 @@ public class DSLQuery { } - public DSLQuery(String dsl) { - this.dsl = dsl; + public DSLQuery(DSLTraversal<? extends Output> dsl) { + this.dsl = dsl.get(); } public String getDsl() { return dsl; } - - public void setDsl(String dsl) { - this.dsl = dsl; - } - - } diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQueryBuilder.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQueryBuilder.java index 540472a88d..7ff6e2ed22 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQueryBuilder.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQueryBuilder.java @@ -27,35 +27,31 @@ import java.util.List; import java.util.stream.Collectors; import org.onap.so.client.aai.entities.QueryStep; import org.onap.so.client.graphinventory.GraphInventoryObjectName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Joiner; - -public class DSLQueryBuilder<S, E> implements QueryStep { +public class DSLQueryBuilder<S, E> { private List<QueryStep> steps = new ArrayList<>(); private String suffix = ""; - private static final Logger logger = LoggerFactory.getLogger(DSLQueryBuilder.class); - public DSLQueryBuilder() { + protected DSLQueryBuilder() { } - public DSLQueryBuilder(DSLNode node) { + protected DSLQueryBuilder(QueryStep node) { steps.add(node); } - public DSLQueryBuilder<S, DSLNode> node(DSLNode node) { + public <T> DSLQueryBuilder<S, DSLNodeBase<?>> node(DSLNodeBase<?> node) { steps.add(node); - return (DSLQueryBuilder<S, DSLNode>) this; + return (DSLQueryBuilder<S, DSLNodeBase<?>>) this; } - public DSLQueryBuilder<S, E> output() { + public DSLQueryBuilder<S, Node> output() { Object obj = steps.get(steps.size() - 1); - if (obj instanceof DSLNode) { - ((DSLNode) steps.get(steps.size() - 1)).output(); + if (obj instanceof DSLNodeBase) { + ((DSLNodeBase) steps.get(steps.size() - 1)).output(); } else if (obj.getClass().getName().contains("$$Lambda$")) { // process lambda expressions for (Field f : obj.getClass().getDeclaredFields()) { @@ -63,27 +59,28 @@ public class DSLQueryBuilder<S, E> implements QueryStep { Object o; try { o = f.get(obj); - if (o instanceof DSLQueryBuilder && ((DSLQueryBuilder) o).steps.get(0) instanceof DSLNode) { - ((DSLNode) ((DSLQueryBuilder) o).steps.get(0)).output(); + if (o instanceof DSLQueryBuilder && ((DSLQueryBuilder) o).steps.get(0) instanceof DSLNodeBase) { + ((DSLNodeBase) ((DSLQueryBuilder) o).steps.get(0)).output(); } } catch (IllegalArgumentException | IllegalAccessException e) { - logger.error("Exception occured", e); } f.setAccessible(false); break; } } - return this; + return (DSLQueryBuilder<S, Node>) this; } - public <E2> DSLQueryBuilder<S, E2> union(final DSLQueryBuilder<?, E2>... union) { + @SafeVarargs + public final <E2> DSLQueryBuilder<S, E2> union(final DSLQueryBuilder<?, E2>... union) { List<DSLQueryBuilder<?, ?>> unions = Arrays.asList(union); steps.add(() -> { StringBuilder query = new StringBuilder(); - query.append("> [ ").append( - Joiner.on(", ").join(unions.stream().map(item -> item.build()).collect(Collectors.toList()))) + query.append("> [ ") + .append(Joiner.on(", ") + .join(unions.stream().map(item -> item.compile()).collect(Collectors.toList()))) .append(" ]"); return query.toString(); }); @@ -95,7 +92,7 @@ public class DSLQueryBuilder<S, E> implements QueryStep { steps.add(() -> { StringBuilder query = new StringBuilder(); - query.append(where.build()).append(")"); + query.append(where.compile()).append(")"); String result = query.toString(); if (!result.startsWith(">")) { result = "> " + result; @@ -105,22 +102,22 @@ public class DSLQueryBuilder<S, E> implements QueryStep { return this; } - public DSLQueryBuilder<S, E> to(DSLQueryBuilder<?, ?> to) { + public <E2> DSLQueryBuilder<S, E2> to(DSLQueryBuilder<?, E2> to) { steps.add(() -> { StringBuilder query = new StringBuilder(); - query.append("> ").append(to.build()); + query.append("> ").append(to.compile()); return query.toString(); }); - return this; + return (DSLQueryBuilder<S, E2>) this; } public DSLQueryBuilder<S, E> to(GraphInventoryObjectName name) { - return to(__.node(name)); + return (DSLQueryBuilder<S, E>) to(__.node(name)); } public DSLQueryBuilder<S, E> to(GraphInventoryObjectName name, DSLNodeKey... key) { - return to(__.node(name, key)); + return (DSLQueryBuilder<S, E>) to(__.node(name, key)); } public DSLQueryBuilder<S, E> limit(int limit) { @@ -128,24 +125,19 @@ public class DSLQueryBuilder<S, E> implements QueryStep { return this; } - @Override - public String build() { - return compile(); + public DSLTraversal<E> build() { + return new DSLTraversal<>(compile()); } @Override public String toString() { - return build(); + return build().get(); } @Override public boolean equals(Object o) { if (o != null) { - if (o instanceof QueryStep) { - return ((QueryStep) o).build().equals(this.build()); - } else if (o instanceof String) { - return o.equals(this.build()); - } + return o.toString().equals(toString()); } return false; } @@ -153,11 +145,11 @@ public class DSLQueryBuilder<S, E> implements QueryStep { @Override public int hashCode() { - return build().hashCode(); + return compile().hashCode(); } private String compile() { - return Joiner.on(" ").join(steps.stream().map(item -> item.build()).collect(Collectors.toList())) + suffix; + return String.join(" ", steps.stream().map(item -> item.build()).collect(Collectors.toList())) + suffix; } protected QueryStep getFirst() { diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLStartNode.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLStartNode.java new file mode 100644 index 0000000000..fb0772726f --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLStartNode.java @@ -0,0 +1,19 @@ +package org.onap.so.client.graphinventory.entities; + +import org.onap.so.client.graphinventory.GraphInventoryObjectName; + +public class DSLStartNode extends DSLNodeBase<DSLStartNode> implements Start { + + + public DSLStartNode() { + super(); + } + + public DSLStartNode(GraphInventoryObjectName name) { + super(name); + } + + public DSLStartNode(GraphInventoryObjectName name, DSLNodeKey... key) { + super(name, key); + } +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLTraversal.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLTraversal.java new file mode 100644 index 0000000000..40f80463b2 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLTraversal.java @@ -0,0 +1,33 @@ +package org.onap.so.client.graphinventory.entities; + +public class DSLTraversal<T> { + + private final String traversal; + + protected DSLTraversal(String traversal) { + this.traversal = traversal; + } + + public String get() { + return traversal; + } + + @Override + public String toString() { + return traversal; + } + + @Override + public int hashCode() { + return traversal.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o != null) { + return this.toString().equals(o); + } + return false; + } + +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/Node.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/Node.java new file mode 100644 index 0000000000..cdaae7d91f --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/Node.java @@ -0,0 +1,5 @@ +package org.onap.so.client.graphinventory.entities; + +public interface Node extends Output { + +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/Output.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/Output.java new file mode 100644 index 0000000000..06b8b65984 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/Output.java @@ -0,0 +1,7 @@ +package org.onap.so.client.graphinventory.entities; + +import org.onap.so.client.aai.entities.QueryStep; + +public interface Output extends QueryStep { + +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/Start.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/Start.java new file mode 100644 index 0000000000..c649e36eca --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/Start.java @@ -0,0 +1,7 @@ +package org.onap.so.client.graphinventory.entities; + +import org.onap.so.client.aai.entities.QueryStep; + +public interface Start extends QueryStep { + +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/TraversalBuilder.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/TraversalBuilder.java new file mode 100644 index 0000000000..0af29f78e6 --- /dev/null +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/TraversalBuilder.java @@ -0,0 +1,17 @@ +package org.onap.so.client.graphinventory.entities; + +public class TraversalBuilder { + + + private TraversalBuilder() { + + } + + public static DSLQueryBuilder<Start, Start> fragment(Start node) { + return new DSLQueryBuilder<>(node); + } + + public static DSLQueryBuilder<Output, Output> traversal(Output node) { + return new DSLQueryBuilder<>(node); + } +} diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java index 87d4d84cac..ca0bd9e00d 100644 --- a/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java +++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java @@ -32,24 +32,25 @@ public class __ { return new DSLQueryBuilder<>(); } - public static <A> DSLQueryBuilder<A, A> start(DSLNode node) { + public static <A> DSLQueryBuilder<A, A> start(Start node) { return new DSLQueryBuilder<>(node); } - public static DSLQueryBuilder<DSLNode, DSLNode> node(GraphInventoryObjectName name) { + public static DSLQueryBuilder<DSLStartNode, DSLStartNode> node(GraphInventoryObjectName name) { - return __.<DSLNode>start(new DSLNode(name)); + return __.<DSLStartNode>start(new DSLStartNode(name)); } - public static DSLQueryBuilder<DSLNode, DSLNode> node(GraphInventoryObjectName name, DSLNodeKey... key) { - return __.<DSLNode>start(new DSLNode(name, key)); + public static DSLQueryBuilder<DSLStartNode, DSLStartNode> node(GraphInventoryObjectName name, DSLNodeKey... key) { + return __.<DSLStartNode>start(new DSLStartNode(name, key)); } public static DSLNodeKey key(String keyName, Object... value) { return new DSLNodeKey(keyName, value); } - public static <A, B> DSLQueryBuilder<A, B> union(final DSLQueryBuilder<?, B>... traversal) { + @SafeVarargs + public static final <A, B> DSLQueryBuilder<A, B> union(final DSLQueryBuilder<?, B>... traversal) { return __.<A>identity().union(traversal); } diff --git a/common/src/main/java/org/onap/so/client/policy/CommonObjectMapperProvider.java b/common/src/main/java/org/onap/so/client/policy/CommonObjectMapperProvider.java index c55370f7dc..334e0f7231 100644 --- a/common/src/main/java/org/onap/so/client/policy/CommonObjectMapperProvider.java +++ b/common/src/main/java/org/onap/so/client/policy/CommonObjectMapperProvider.java @@ -20,13 +20,16 @@ package org.onap.so.client.policy; +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -public class CommonObjectMapperProvider { +@Provider +public class CommonObjectMapperProvider implements ContextResolver<ObjectMapper> { protected ObjectMapper mapper; @@ -43,4 +46,10 @@ public class CommonObjectMapperProvider { public ObjectMapper getMapper() { return mapper; } + + @Override + public ObjectMapper getContext(Class<?> type) { + + return mapper; + } } diff --git a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java index fb45652d53..1a1a7d124e 100644 --- a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java +++ b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java @@ -23,17 +23,19 @@ package org.onap.so.client.aai; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.onap.so.client.graphinventory.entities.DSLNode; import org.onap.so.client.graphinventory.entities.DSLNodeKey; import org.onap.so.client.graphinventory.entities.DSLQueryBuilder; +import org.onap.so.client.graphinventory.entities.DSLStartNode; +import org.onap.so.client.graphinventory.entities.Output; +import org.onap.so.client.graphinventory.entities.Start; +import org.onap.so.client.graphinventory.entities.TraversalBuilder; import org.onap.so.client.graphinventory.entities.__; public class DSLQueryBuilderTest { - @Test public void whereTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment(new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "att-nc"), __.key("cloud-region-id", "test"))); builder.to(__.node(AAIObjectType.VLAN_TAG)) @@ -42,13 +44,13 @@ public class DSLQueryBuilderTest { assertEquals("cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'test') > " + "vlan-tag (> owning-entity('owning-entity-name', 'name')) > " + "vlan-tag*('vlan-id-outer', '108')", - builder.build()); + builder.build().get()); } @Test public void unionTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = - new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()), __.node(AAIObjectType.VSERVER) @@ -56,53 +58,53 @@ public class DSLQueryBuilderTest { assertEquals( "generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]", - builder.build()); + builder.build().get()); } @Test public void whereUnionTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = - new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); builder.where(__.union(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")), __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1"))))); assertEquals("generic-vnf*('vnf-id', 'vnfId') (> [ pserver('hostname', 'hostname1'), " - + "vserver > pserver('hostname', 'hostname1') ])", builder.build()); + + "vserver > pserver('hostname', 'hostname1') ])", builder.build().get()); } @Test public void notNullTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>( - new DSLNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "", "null").not()).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder.traversal( + new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "", "null").not()).output()); - assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build()); + assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build().get()); } @Test public void shortCutToTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = - new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id")); assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')", - builder.build()); + builder.build().get()); } @Test public void limitTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = - new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); builder.to(AAIObjectType.P_INTERFACE).limit(2).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id")); assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id') LIMIT 2", - builder.build()); + builder.build().get()); } @Test public void equalsTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = - new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id")); assertTrue( @@ -110,10 +112,9 @@ public class DSLQueryBuilderTest { assertTrue(builder.equals(builder)); } - @Test public void mixedTypeTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment(new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "owner"), __.key("cloud-region-id", "id"))); builder.to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", 167), __.key("my-boolean", true)).output()); assertTrue(builder.equals( @@ -122,19 +123,19 @@ public class DSLQueryBuilderTest { @Test public void outputOnNodeLambdasTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = - new DSLQueryBuilder<>(new DSLNode(AAIObjectType.L_INTERFACE, new DSLNodeKey("interface-id", "myId"))); + DSLQueryBuilder<Start, Start> builder = TraversalBuilder + .fragment(new DSLStartNode(AAIObjectType.L_INTERFACE, new DSLNodeKey("interface-id", "myId"))); builder.to(AAIObjectType.VSERVER, __.key("vserver-name", "myName")).output().to(AAIObjectType.P_INTERFACE) .output(); assertEquals("l-interface('interface-id', 'myId') > vserver*('vserver-name', 'myName') > p-interface*", - builder.build()); + builder.build().get()); } @Test public void skipOutputOnUnionTest() { - DSLQueryBuilder<DSLNode, DSLNode> builder = - new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()), __.node(AAIObjectType.VSERVER) @@ -143,6 +144,6 @@ public class DSLQueryBuilderTest { assertEquals( "generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]", - builder.build()); + builder.build().get()); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java index 0afc272b0a..168f82bdf3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java @@ -23,9 +23,7 @@ package org.onap.so.apihandlerinfra; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.PostConstruct; -import javax.servlet.ServletConfig; import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Context; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletProperties; import org.onap.logging.filter.base.Constants; @@ -96,6 +94,7 @@ public class JerseyConfiguration extends ResourceConfig { // this registration seems to be needed to get predictable // execution behavior for the above JSON Exception Mappers register(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.class); + register(ModelDistributionRequest.class); property(ServletProperties.FILTER_FORWARD_ON_404, true); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/AAIDeserializeTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/AAIDeserializeTest.java new file mode 100644 index 0000000000..e6409fab87 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/AAIDeserializeTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.apihandlerinfra; + + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import javax.ws.rs.core.MediaType; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.domain.yang.Tenant; +import org.onap.so.client.aai.AAIVersion; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class AAIDeserializeTest extends BaseTest { + + private final ObjectMapper mapper = new ObjectMapper(); + + @Autowired + private MsoRequest msoReq; + + @Value("${wiremock.server.port}") + private String wiremockPort; + + @Before + public void beforeClass() { + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + public String inputStream(String JsonInput) throws IOException { + JsonInput = "src/test/resources/MsoRequestTest" + JsonInput; + return new String(Files.readAllBytes(Paths.get(JsonInput))); + } + + @Test + public void doNotFailOnUnknownPropertiesTest() throws JsonParseException, JsonMappingException, IOException { + wireMockServer.stubFor(get(("/aai/" + AAIVersion.LATEST + + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/mdt1/tenants/tenant/88a6ca3ee0394ade9403f075db23167e")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("aai/UnknownProperty.json") + .withStatus(org.apache.http.HttpStatus.SC_OK))); + ServiceInstancesRequest sir = mapper.readValue(inputStream("/AAI.json"), ServiceInstancesRequest.class); + String tenantId = "88a6ca3ee0394ade9403f075db23167e"; + String tenantNameFromAAI = "testTenantName"; + String cloudOwner = "cloudOwner"; + sir.getRequestDetails().getCloudConfiguration().setCloudOwner(cloudOwner); + Tenant tenant = new Tenant(); + tenant.setTenantId(tenantId); + tenant.setTenantName(tenantNameFromAAI); + String tenantName = msoReq.getTenantNameFromAAI(sir); + assertEquals(tenantNameFromAAI, tenantName); + } + +} + diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/MsoRequestTest/AAI.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/MsoRequestTest/AAI.json new file mode 100644 index 0000000000..455d73a13b --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/MsoRequestTest/AAI.json @@ -0,0 +1,132 @@ +{ + "requestDetails": { + "modelInfo": { + "modelType": "service", + "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelName": "model-name", + "modelVersion": "10" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "owningEntity": { + "owningEntityId": "038d99af-0427-42c2-9d15-971b99b9b489", + "owningEntityName": "PACKET CORE" + }, + "project": { + "projectName": "{some project name}" + }, + "subscriberInfo": { + "globalSubscriberId": "{some subscriber id}" + }, + "requestInfo": { + "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "source": "VID", + "suppressRollback": true, + "requestorId": "xxxxxx" + }, + "requestParameters": { + "subscriptionServiceType": "type", + "aLaCarte": false, + "userParams": [ + { + "service": { + "modelInfo": { + "modelType": "service", + "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelName": "model-name", + "modelVersion": "10" + }, + "instanceParams": [], + "resources": { + "vnfs": [ + { + "modelInfo": { + "modelCustomizationName": "model-name 0", + "modelName": "model-name", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelCustomizationId": "ab153b6e-c364-44c0-bef6-1f2982117f04" + }, + "cloudConfiguration": { + "lcpCloudRegionId": "mdt1", + "tenantId": "88a6ca3ee0394ade9403f075db23167e" + }, + "platform": { + "platformName": "someValue" + }, + "lineOfBusiness": { + "lineOfBusinessName": "someValue" + }, + "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "instanceParams": [ + { + "instanceName": "someVnfInstanceName" + } + ], + "vfModules": [ + { + "modelInfo": { + "modelName": "name._base__BV..module-0", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelCustomizationId": "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f" + }, + "instanceParams": [ + { + "vmx_int_net_len": "24", + "asn": "someValue" + } + ] + }, + { + "modelInfo": { + "modelName": "name._vRE_BV..module-1", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelCustomizationId": "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", + "modelType": "vfModule" + }, + "instanceParams": [ + { + "availability_zone_0": "mtpocdv-kvm-az01", + "vre_a_volume_size_0": "100" + } + ] + }, + { + "modelInfo": { + "modelName": "name._vRE_BV..module-1", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelCustomizationId": "72d9d1cd-f46d-447a-abdb-451d6fb05fa8" + }, + "instanceParams": [ + { + "availability_zone_0": "mtpocdv-kvm-az01", + "vre_a_volume_size_0": "50" + } + ] + }, + { + "modelInfo": { + "modelName": "name.BV..module-2", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelCustomizationId": "da4d4327-fb7d-4311-ac7a-be7ba60cf969" + }, + "instanceParams": [ + { + "availability_zone_0": "mtpocdv-kvm-az01", + "vmx_vpfe_int_ip_0": "192.168.0.16" + } + ] + } + ] + } + ] + } + } + } + ] + } + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/aai/UnknownProperty.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/aai/UnknownProperty.json new file mode 100644 index 0000000000..e606f8aa30 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/aai/UnknownProperty.json @@ -0,0 +1 @@ +{"tenant-id":"78491aac74be4fab9873db114774b475","tenant-name":"testTenantName", "test":"test", "parent-id": "25239", "tenant-context":"Development","resource-version":"1581690782612"}
\ No newline at end of file |