use of org.onap.so.bpmn.core.domain.Resource in project so by onap.
the class InstnaceResourceListTest method testVFResourceWithModule.
@Test
public void testVFResourceWithModule() throws IOException {
String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json")));
VnfResource vnfResource = new VnfResource();
vnfResource.setResourceInput("{\"a\":\"ipaddress|127.0.0.1\"}");
// Come from package org.onap.so.bpmn.core.domain.VnfResourceTest
List<ModuleResource> moduleResources;
moduleResources = new ArrayList<>();
ModuleResource moduleresource = getModuleResource();
moduleResources.add(moduleresource);
vnfResource.setModules(moduleResources);
List<Resource> instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest);
Assert.assertEquals(2, instanceResourceList.size());
Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
Assert.assertEquals(ResourceType.MODULE, instanceResourceList.get(1).getResourceType());
}
use of org.onap.so.bpmn.core.domain.Resource in project so by onap.
the class InstnaceResourceListTest method testVFWithEmptyGroupResource.
// Test when PK is not empty and PK does not contain any groups
@Test
public void testVFWithEmptyGroupResource() throws IOException {
String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json")));
VnfResource vnfResource = new VnfResource();
vnfResource.setResourceInput("{\"a\":\"[emptygroup_list,INDEX,name]\"}");
List<Resource> instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest);
Assert.assertEquals(1, instanceResourceList.size());
Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
}
use of org.onap.so.bpmn.core.domain.Resource in project so by onap.
the class InstnaceResourceListTest method testSimpleVFResourceWithGroup.
@Test
public void testSimpleVFResourceWithGroup() throws IOException {
String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json")));
VnfResource vnfResource = new VnfResource();
vnfResource.setResourceInput("{\"a\":\"ipaddress|127.0.0.1\"}");
createGroupKeyResource(vnfResource);
List<Resource> instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest);
Assert.assertEquals(2, instanceResourceList.size());
Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(1).getResourceType());
Assert.assertEquals("wan", instanceResourceList.get(1).getModelInfo().getModelName());
}
use of org.onap.so.bpmn.core.domain.Resource in project so by onap.
the class InstanceResourceList method getPrimaryKey.
// this method returns key from resource input
// e.g. {\"sdwansite_emails\" : \"[sdwansiteresource_list(PK), INDEX, sdwansite_emails]|default\",
// ....}
// it will return sdwansiteresource_list
private static String getPrimaryKey(Resource resource) {
String resourceInput = "";
if (resource instanceof VnfResource) {
resourceInput = ((VnfResource) resource).getResourceInput();
} else if (resource instanceof GroupResource) {
resourceInput = ((GroupResource) resource).getVnfcs().get(0).getResourceInput();
}
Gson gson = new Gson();
Type type = new TypeToken<Map<String, String>>() {
}.getType();
Map<String, String> map = gson.fromJson(resourceInput, type);
if (map != null) {
Optional<String> pkOpt = map.values().stream().filter(e -> e.contains("[")).map(e -> e.replace("[", "")).map(e -> e.split(",")[0]).findFirst();
return pkOpt.isPresent() ? pkOpt.get() : "";
} else {
return "";
}
}
use of org.onap.so.bpmn.core.domain.Resource in project so by onap.
the class InstanceResourceList method getInstanceResourceList.
public static List<Resource> getInstanceResourceList(final VnfResource vnfResource, final String uuiRequest) {
List<Resource> sequencedResourceList = new ArrayList<>();
Gson gson = new Gson();
JsonObject servJsonObject = gson.fromJson(uuiRequest, JsonObject.class);
JsonObject reqInputJsonObj = servJsonObject.getAsJsonObject("service").getAsJsonObject("parameters").getAsJsonObject("requestInputs");
String pk = getPrimaryKey(vnfResource);
// if pk is not empty that means it can contain list of VNF
if (!pk.isEmpty()) {
JsonElement vfNode = reqInputJsonObj.get(pk);
if (vfNode.isJsonArray()) {
// multiple instance of VNF
JsonArray vfNodeList = vfNode.getAsJsonArray();
for (JsonElement vf : vfNodeList) {
JsonObject vfObj = vf.getAsJsonObject();
// Add VF first before adding groups
sequencedResourceList.add(vnfResource);
List<Resource> sequencedGroupResourceList = getGroupResourceInstanceList(vnfResource, vfObj);
if (!sequencedGroupResourceList.isEmpty()) {
sequencedResourceList.addAll(sequencedGroupResourceList);
}
}
}
} else {
// if pk is empty that means it has only one VNF Node
// Add VF first before adding groups
sequencedResourceList.add(vnfResource);
// check the groups for this VNF and add into resource list
List<Resource> sequencedGroupResourceList = getGroupResourceInstanceList(vnfResource, reqInputJsonObj);
if (!sequencedGroupResourceList.isEmpty()) {
sequencedResourceList.addAll(sequencedGroupResourceList);
}
}
// In negative case consider only VNF resource only
if (sequencedResourceList.isEmpty()) {
sequencedResourceList.add(vnfResource);
}
// check if the resource contains vf-module
if (isVnfResourceWithVfModule(vnfResource)) {
sequencedResourceList.addAll(vnfResource.getVfModules());
}
return sequencedResourceList;
}
Aggregations