Search in sources :

Example 6 with Resource

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());
}
Also used : VnfResource(org.onap.so.bpmn.core.domain.VnfResource) GroupResource(org.onap.so.bpmn.core.domain.GroupResource) VnfcResource(org.onap.so.bpmn.core.domain.VnfcResource) VnfResource(org.onap.so.bpmn.core.domain.VnfResource) Resource(org.onap.so.bpmn.core.domain.Resource) ModuleResource(org.onap.so.bpmn.core.domain.ModuleResource) ModuleResource(org.onap.so.bpmn.core.domain.ModuleResource) Test(org.junit.Test)

Example 7 with Resource

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());
}
Also used : VnfResource(org.onap.so.bpmn.core.domain.VnfResource) GroupResource(org.onap.so.bpmn.core.domain.GroupResource) VnfcResource(org.onap.so.bpmn.core.domain.VnfcResource) VnfResource(org.onap.so.bpmn.core.domain.VnfResource) Resource(org.onap.so.bpmn.core.domain.Resource) ModuleResource(org.onap.so.bpmn.core.domain.ModuleResource) Test(org.junit.Test)

Example 8 with Resource

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());
}
Also used : VnfResource(org.onap.so.bpmn.core.domain.VnfResource) GroupResource(org.onap.so.bpmn.core.domain.GroupResource) VnfcResource(org.onap.so.bpmn.core.domain.VnfcResource) VnfResource(org.onap.so.bpmn.core.domain.VnfResource) Resource(org.onap.so.bpmn.core.domain.Resource) ModuleResource(org.onap.so.bpmn.core.domain.ModuleResource) Test(org.junit.Test)

Example 9 with Resource

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 "";
    }
}
Also used : JsonObject(com.google.gson.JsonObject) GroupResource(org.onap.so.bpmn.core.domain.GroupResource) TypeToken(com.google.common.reflect.TypeToken) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) JsonArray(com.google.gson.JsonArray) List(java.util.List) Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) VnfResource(org.onap.so.bpmn.core.domain.VnfResource) Map(java.util.Map) Resource(org.onap.so.bpmn.core.domain.Resource) Optional(java.util.Optional) VnfResource(org.onap.so.bpmn.core.domain.VnfResource) Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) Map(java.util.Map) GroupResource(org.onap.so.bpmn.core.domain.GroupResource)

Example 10 with Resource

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;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) GroupResource(org.onap.so.bpmn.core.domain.GroupResource) VnfResource(org.onap.so.bpmn.core.domain.VnfResource) Resource(org.onap.so.bpmn.core.domain.Resource) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject)

Aggregations

Resource (org.onap.so.bpmn.core.domain.Resource)18 VnfResource (org.onap.so.bpmn.core.domain.VnfResource)17 Test (org.junit.Test)15 HashMap (java.util.HashMap)10 GroupResource (org.onap.so.bpmn.core.domain.GroupResource)9 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)8 WorkflowException (org.onap.so.bpmn.core.WorkflowException)8 AllottedResource (org.onap.so.bpmn.core.domain.AllottedResource)8 HomingSolution (org.onap.so.bpmn.core.domain.HomingSolution)8 NetworkResource (org.onap.so.bpmn.core.domain.NetworkResource)8 ServiceDecomposition (org.onap.so.bpmn.core.domain.ServiceDecomposition)8 VnfcResource (org.onap.so.bpmn.core.domain.VnfcResource)7 ModuleResource (org.onap.so.bpmn.core.domain.ModuleResource)6 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Map (java.util.Map)3 Gson (com.google.gson.Gson)2 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2