summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorTait,Trevor(rt0435) <rtait@amdocs.com>2019-01-31 08:44:51 -0500
committerTait,Trevor(rt0435) <rtait@amdocs.com>2019-01-31 08:45:12 -0500
commit7aa6d16dff7103b7b83fbd3261c2caa374b7810e (patch)
treed5c0bbbef0816d77983c67c206192c2403d8c83f /src/main
parent5b6272525b9cd876191104d4c1e64a91cace1c74 (diff)
SDNC Context Builder : L2 Fabric Retrieval - pnf
Code to retrieve pnf data from SDNC. Includes new URI to GET port-mirror-configurations. Issue-ID: LOG-778 Change-Id: I0264e544d1f08f660ee783b626438a1259617a69 Signed-off-by: Tait,Trevor(rt0435) <rtait@amdocs.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java8
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/GenericResourceApiHandler.java7
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java36
3 files changed, 44 insertions, 7 deletions
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java
index 35fe248..ebf308c 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java
@@ -55,6 +55,9 @@ public class SdncConfiguration {
@Value("${sdnc.genericResourcePath}")
private String genericResourcePath;
+ @Value("${sdnc.portMirrorResourcePath}")
+ private String portMirrorResourcePath;
+
@Value("${sdnc.vnfPath}")
private String vnfPath;
@@ -118,6 +121,11 @@ public class SdncConfiguration {
return genericResourcePath;
}
+ @Bean(name="sdncPortMirrorResourcePath")
+ public String getPortMirrorResourcePath() {
+ return portMirrorResourcePath;
+ }
+
@Bean(name="sdncVnfPath")
public String getVnfPath() {
return vnfPath;
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/GenericResourceApiHandler.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/GenericResourceApiHandler.java
index f9655b0..8261e59 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/GenericResourceApiHandler.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/GenericResourceApiHandler.java
@@ -42,8 +42,8 @@ public class GenericResourceApiHandler {
private String sdncBasicAuthorization;
@Autowired
private String sdncGenericResourcePath;
-
- private String specPath = "config/sdncgenericresource.spec";
+ @Autowired
+ private String sdncPortMirrorResourcePath;
public ModelContext process(Exchange exchange) throws AuditException {
@@ -55,7 +55,8 @@ public class GenericResourceApiHandler {
try {
String sdncResponse = RestUtil.getSdncGenericResource(jerseyClient, sdncBaseUrl, sdncBasicAuthorization, sdncGenericResourcePath, serviceInstanceId);
- context = RestUtil.transformGenericResource(sdncResponse, specPath);
+ context = RestUtil.transformGenericResource(sdncResponse);
+ context.setPnfs(RestUtil.getPnfFromSdncResonse(jerseyClient, sdncBaseUrl, sdncBasicAuthorization, sdncPortMirrorResourcePath, sdncResponse));
} catch (AuditException ae) {
throw ae;
} catch (Exception e) {
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java
index ec1d0c9..ab48ac5 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java
@@ -21,6 +21,9 @@ package org.onap.pomba.contextbuilder.sdnc.util;
import com.bazaarvoice.jolt.Chainr;
import com.bazaarvoice.jolt.JsonUtils;
import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -47,6 +50,7 @@ import org.onap.pomba.common.datatypes.Attribute;
import org.onap.pomba.common.datatypes.Attribute.Name;
import org.onap.pomba.common.datatypes.ModelContext;
import org.onap.pomba.common.datatypes.Network;
+import org.onap.pomba.common.datatypes.PNF;
import org.onap.pomba.common.datatypes.Service;
import org.onap.pomba.common.datatypes.VFModule;
import org.onap.pomba.common.datatypes.VNF;
@@ -91,7 +95,10 @@ public class RestUtil {
private static final String FORWARD_SLASH = "/";
// SDNC vnf Json Path
- private static final String SPEC_PATH = "config/vnflist.spec";
+ private static final String VNF_SPEC_PATH = "config/vnflist.spec";
+ private static final String GENERIC_API_SPEC_PATH = "config/sdncgenericresource.spec";
+ private static final String PROVIDED_CONFIGURATIONS_SPEC_PATH = "config/providedConfigurations.spec";
+ private static final String PORT_MIRROR_CONFIGURATIONS_SPEC_PATH = "config/portMirrorConfigurations.spec";
// Parameters for Query SDNC Model Data REST API URL
private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
@@ -207,8 +214,8 @@ public class RestUtil {
}
- public static ModelContext transformGenericResource(String sdncResponse, String SPEC_PATH) {
- List<Object> jsonSpec = JsonUtils.filepathToList(SPEC_PATH);
+ public static ModelContext transformGenericResource(String sdncResponse) {
+ List<Object> jsonSpec = JsonUtils.filepathToList(GENERIC_API_SPEC_PATH);
Object jsonInput = JsonUtils.jsonToObject(sdncResponse);
Chainr chainr = Chainr.fromSpec(jsonSpec);
Object transObject = chainr.transform(jsonInput);
@@ -217,6 +224,27 @@ public class RestUtil {
}
+ public static List<PNF> getPnfFromSdncResonse(Client sdncClient, String sdncBaseUrl, String authorization, String sdncPortMirrorResourcePath, String sdncResponse) throws AuditException {
+ List<Object> providedConfigurationsSpec = JsonUtils.filepathToList(PROVIDED_CONFIGURATIONS_SPEC_PATH);
+ Object providedConfigurationsInput = JsonUtils.jsonToObject(sdncResponse);
+ Chainr providedConfigurations = Chainr.fromSpec(providedConfigurationsSpec);
+ Object providedConfigurationsObject = providedConfigurations.transform(providedConfigurationsInput);
+ Gson gson = new Gson();
+ JsonElement jsonElement = gson.toJsonTree(providedConfigurationsObject);
+ JsonObject jsonObject = (JsonObject) jsonElement;
+ JsonArray jsonArray = jsonObject.getAsJsonArray("configuration-id");
+ for (JsonElement configurationId : jsonArray) {
+ String pnfId = configurationId.getAsString();
+ String portMirrorResponse = getSdncGenericResource(sdncClient, sdncBaseUrl, authorization, sdncPortMirrorResourcePath, pnfId);
+ List<Object> portMirrorSpec = JsonUtils.filepathToList(PORT_MIRROR_CONFIGURATIONS_SPEC_PATH);
+ Object portMirrorInput = JsonUtils.jsonToObject(portMirrorResponse);
+ Chainr portMirror = Chainr.fromSpec(portMirrorSpec);
+ Object portMirrorObject = portMirror.transform(portMirrorInput);
+ return gson.fromJson(JsonUtils.toPrettyJsonString(portMirrorObject), ModelContext.class).getPnfs();
+ }
+ return new ArrayList<>();
+ }
+
/**
* Transform the AAI and SDNC models to the audit common model
* @param aaiVnfLst
@@ -526,7 +554,7 @@ public class RestUtil {
* Extract the vnf-list from the Json payload.
*/
private static List<Vnf> extractVnfList(String payload) throws AuditException {
- List<Object> jsonSpec = JsonUtils.filepathToList(SPEC_PATH);
+ List<Object> jsonSpec = JsonUtils.filepathToList(VNF_SPEC_PATH);
Object jsonInput = JsonUtils.jsonToObject(payload);
Chainr chainr = Chainr.fromSpec(jsonSpec);
Object transObject = chainr.transform(jsonInput);