Search in sources :

Example 11 with VnfResource

use of org.onap.so.bpmn.core.domain.VnfResource 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 12 with VnfResource

use of org.onap.so.bpmn.core.domain.VnfResource 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)

Example 13 with VnfResource

use of org.onap.so.bpmn.core.domain.VnfResource in project so by onap.

the class DecomposeJsonUtilTest method createVnfResourceData.

// data creation section
private VnfResource createVnfResourceData() {
    vnfResource = new VnfResource();
    vnfResource.setResourceId("resourceId");
    vnfResource.setNfFunction("nfFunction");
    vnfResource.setNfNamingCode("nfNamingCode");
    vnfResource.setNfRole("nfRole");
    return vnfResource;
}
Also used : VnfResource(org.onap.so.bpmn.core.domain.VnfResource)

Example 14 with VnfResource

use of org.onap.so.bpmn.core.domain.VnfResource in project so by onap.

the class ResourceRequestBuilderTest method testGetResourceInputEmptyValue.

@Test
public void testGetResourceInputEmptyValue() {
    VnfResource resource = new VnfResource();
    resource.setResourceType(ResourceType.VNF);
    resource.setResourceInput("{\"a\":\"key1|\"}");
    HashMap serviceInput = new HashMap();
    serviceInput.put("key2", "value");
    Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resource, serviceInput, null);
    assertEquals(stringObjectMap.get("a"), "");
}
Also used : VnfResource(org.onap.so.bpmn.core.domain.VnfResource) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 15 with VnfResource

use of org.onap.so.bpmn.core.domain.VnfResource in project so by onap.

the class ResourceRequestBuilderTest method getResourceInputWithEmptyServiceResourcesTest.

@Test
public void getResourceInputWithEmptyServiceResourcesTest() throws Exception {
    VnfResource resource = new VnfResource();
    resource.setResourceType(ResourceType.VNF);
    resource.setResourceInput(null);
    HashMap serviceInput = new HashMap();
    serviceInput.put("key1", "value");
    Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resource, serviceInput, null);
    assertEquals(0, stringObjectMap.size());
}
Also used : VnfResource(org.onap.so.bpmn.core.domain.VnfResource) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Aggregations

VnfResource (org.onap.so.bpmn.core.domain.VnfResource)20 Test (org.junit.Test)16 Resource (org.onap.so.bpmn.core.domain.Resource)11 GroupResource (org.onap.so.bpmn.core.domain.GroupResource)10 HashMap (java.util.HashMap)8 VnfcResource (org.onap.so.bpmn.core.domain.VnfcResource)7 BaseTest (org.onap.so.BaseTest)6 ModuleResource (org.onap.so.bpmn.core.domain.ModuleResource)6 ArrayList (java.util.ArrayList)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 List (java.util.List)2 Map (java.util.Map)2 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)2 WorkflowException (org.onap.so.bpmn.core.WorkflowException)2 AllottedResource (org.onap.so.bpmn.core.domain.AllottedResource)2 HomingSolution (org.onap.so.bpmn.core.domain.HomingSolution)2 NetworkResource (org.onap.so.bpmn.core.domain.NetworkResource)2