aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java33
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java88
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java55
-rw-r--r--common/pom.xml2
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeBase.java (renamed from common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNode.java)34
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/DSLOutputNode.java8
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQuery.java10
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/DSLQueryBuilder.java64
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/DSLStartNode.java19
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/DSLTraversal.java33
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/Node.java5
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/Output.java7
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/Start.java7
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/TraversalBuilder.java17
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/__.java13
-rw-r--r--common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java59
16 files changed, 213 insertions, 241 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/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/pom.xml b/common/pom.xml
index e36001833d..d373d620cd 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -59,7 +59,7 @@
<dependency>
<groupId>org.onap.aai.schema-service</groupId>
<artifactId>aai-schema</artifactId>
- <version>1.6.4-SNAPSHOT</version>
+ <version>1.6.5</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
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/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());
}
}