Search in sources :

Example 1 with GroupResource

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

the class InstnaceResourceListTest method prepareGroupResource.

private GroupResource prepareGroupResource(String sourceInput, String modelName) {
    VnfcResource vnfcDeviceResource = new VnfcResource();
    vnfcDeviceResource.setResourceInput(sourceInput);
    GroupResource groupResource = new GroupResource();
    groupResource.setVnfcs(Arrays.asList(vnfcDeviceResource));
    ModelInfo deviceModel = new ModelInfo();
    deviceModel.setModelName(modelName);
    groupResource.setModelInfo(deviceModel);
    return groupResource;
}
Also used : VnfcResource(org.onap.so.bpmn.core.domain.VnfcResource) ModelInfo(org.onap.so.bpmn.core.domain.ModelInfo) GroupResource(org.onap.so.bpmn.core.domain.GroupResource)

Example 2 with GroupResource

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

the class InstnaceResourceListTest method createGroupKeyResource.

private void createGroupKeyResource(VnfResource vnfResource) {
    GroupResource groupResource = prepareGroupResource("{\"a\":\"test|default_value\"}", "wan");
    vnfResource.setGroupOrder("wan");
    vnfResource.setGroups(Arrays.asList(groupResource));
}
Also used : GroupResource(org.onap.so.bpmn.core.domain.GroupResource)

Example 3 with GroupResource

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

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

the class ResourceRequestBuilderTest method getListResourceInputTest.

@Test
public void getListResourceInputTest() throws Exception {
    List<Map> vnfdata = null;
    List<Resource> resources = new ArrayList<>();
    if (this.serviceInput.containsKey("serviceResources")) {
        vnfdata = (List<Map>) ((Map) this.serviceInput.get("serviceResources")).get("serviceVnfs");
    }
    assertNotNull(vnfdata);
    vnfdata.forEach(e -> {
        if (e.get("resourceType").equals("VNF")) {
            VnfResource r = new VnfResource();
            r.setResourceInput(e.get("resourceInput").toString());
            resources.add(r);
        } else if (e.get("resourceType").equals("GROUP")) {
            GroupResource r = new GroupResource();
            VnfcResource vfc = new VnfcResource();
            vfc.setResourceInput(e.get("resourceInput").toString());
            List<VnfcResource> vfcList = new ArrayList();
            vfcList.add(vfc);
            r.setVnfcs(vfcList);
            resources.add(r);
        }
    });
    assertEquals(9, resources.size());
    // VF level request
    Map<String, Object> currentVFData = new HashMap<>();
    Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(0), this.userInputMap, currentVFData);
    assertEquals("b", stringObjectMap.get("a"));
    assertEquals("hub_spoke", stringObjectMap.get("topology"));
    assertEquals("defaultvpn", stringObjectMap.get("name"));
    assertTrue(((String) stringObjectMap.get("sitelist")).contains("["));
    // vfc level request
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(1), this.userInputMap, currentVFData);
    assertEquals("", stringObjectMap.get("a"));
    assertEquals("layer3-port", stringObjectMap.get("portswitch"));
    assertEquals("192.168.10.1", stringObjectMap.get("ipAddress"));
    assertEquals("vCPE", stringObjectMap.get("deviceName"));
    // vfc level request
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(2), this.userInputMap, currentVFData);
    assertEquals("", stringObjectMap.get("a"));
    assertEquals("layer2-port", stringObjectMap.get("portswitch"));
    assertEquals("192.168.11.1", stringObjectMap.get("ipAddress"));
    assertEquals("CPE_Beijing", stringObjectMap.get("deviceName"));
    // VF level request
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(3), this.userInputMap, currentVFData);
    assertEquals("Huawei Private Cloud", stringObjectMap.get("address"));
    assertEquals("dsvpn_hub1", stringObjectMap.get("role"));
    assertTrue(((String) stringObjectMap.get("wanlist")).contains("["));
    assertTrue(((String) stringObjectMap.get("devlist")).contains("["));
    // VFC request
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(4), this.userInputMap, currentVFData);
    assertEquals("Huawei Private Cloud", stringObjectMap.get("address"));
    assertEquals("20000", stringObjectMap.get("postcode"));
    assertEquals("single_gateway", stringObjectMap.get("type"));
    assertEquals("vCPE", stringObjectMap.get("deviceName"));
    assertEquals("DHCP", stringObjectMap.get("ipMode"));
    // VFC request again
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(5), this.userInputMap, currentVFData);
    assertEquals("Huawei Private Cloud", stringObjectMap.get("address"));
    assertEquals("20000", stringObjectMap.get("postcode"));
    assertEquals("single_gateway", stringObjectMap.get("type"));
    assertEquals("20.20.20.1", stringObjectMap.get("systemip"));
    assertEquals("default_ipv6", stringObjectMap.get("systemipv6"));
    assertEquals("VNF", stringObjectMap.get("devclass"));
    // VF level request
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(6), this.userInputMap, currentVFData);
    assertEquals("Huawei Public Cloud", stringObjectMap.get("address"));
    assertEquals("dsvpn_hub", stringObjectMap.get("role"));
    assertTrue(((String) stringObjectMap.get("wanlist")).contains("["));
    assertTrue(((String) stringObjectMap.get("devlist")).contains("["));
    // VFC request
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(7), this.userInputMap, currentVFData);
    assertEquals("Huawei Public Cloud", stringObjectMap.get("address"));
    assertEquals("20001", stringObjectMap.get("postcode"));
    assertEquals("multiple_gateway", stringObjectMap.get("type"));
    assertEquals("CPE_Beijing", stringObjectMap.get("deviceName"));
    assertEquals("Static", stringObjectMap.get("ipMode"));
    // VFC request again
    stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resources.get(8), this.userInputMap, currentVFData);
    assertEquals("Huawei Public Cloud", stringObjectMap.get("address"));
    assertEquals("20001", stringObjectMap.get("postcode"));
    assertEquals("multiple_gateway", stringObjectMap.get("type"));
    assertEquals("20.20.20.2", stringObjectMap.get("systemip"));
    assertEquals("default_ipv6", stringObjectMap.get("systemipv6"));
    assertEquals("PNF", stringObjectMap.get("devclass"));
}
Also used : HashMap(java.util.HashMap) 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) ArrayList(java.util.ArrayList) GroupResource(org.onap.so.bpmn.core.domain.GroupResource) VnfResource(org.onap.so.bpmn.core.domain.VnfResource) VnfcResource(org.onap.so.bpmn.core.domain.VnfcResource) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 5 with GroupResource

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

the class InstnaceResourceListTest method createResourceSequence.

private VnfResource createResourceSequence() {
    VnfResource vnfResource = new VnfResource();
    vnfResource.setResourceInput("{\"a\":\"[sdwansiteresource_list,INDEX,sdwansiteresource_list]\"}");
    GroupResource groupResource = prepareGroupResource("{\"a\":\"[sdwansitewan_list,INDEX,test]\"}", "sitewan");
    GroupResource groupResource2 = prepareGroupResource("{\"a\":\"[sdwandevice_list,INDEX,test]\"}", "device");
    GroupResource groupDummyResource = prepareGroupResource("{\"a\":\"[dummy,INDEX,test]\"}", "dummy");
    vnfResource.setGroupOrder("device,sitewan,dummy");
    vnfResource.setGroups(Arrays.asList(groupResource, groupResource2, groupDummyResource));
    return vnfResource;
}
Also used : VnfResource(org.onap.so.bpmn.core.domain.VnfResource) GroupResource(org.onap.so.bpmn.core.domain.GroupResource)

Aggregations

GroupResource (org.onap.so.bpmn.core.domain.GroupResource)5 VnfResource (org.onap.so.bpmn.core.domain.VnfResource)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Resource (org.onap.so.bpmn.core.domain.Resource)2 VnfcResource (org.onap.so.bpmn.core.domain.VnfcResource)2 TypeToken (com.google.common.reflect.TypeToken)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Test (org.junit.Test)1 BaseTest (org.onap.so.BaseTest)1 ModelInfo (org.onap.so.bpmn.core.domain.ModelInfo)1