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 "";
}
}
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;
}
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;
}
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"), "");
}
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());
}
Aggregations