aboutsummaryrefslogtreecommitdiffstats
path: root/appc-outbound/appc-network-inventory-client
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-26 13:47:24 +0100
committerPatrick Brady <pb071s@att.com>2018-02-26 19:11:30 +0000
commit8c7900939c52fb8770827c1beaac9753f42b0d02 (patch)
tree19eceed01f5e1dff7f4f5b1528821967f2e52ba2 /appc-outbound/appc-network-inventory-client
parentcccb65875f5716aaca9494d28233aaf6285312e2 (diff)
appc-network-client-provider sonar fixes part 2
Sonar fixes in whole module Change-Id: If36f6b7762c0caa1ccd4f5c9efa57c08f97a2c87 Issue-ID: APPC-672 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-outbound/appc-network-inventory-client')
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/data/AaiVmInfo.java8
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java150
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/utils/AaiClientConstant.java5
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java4
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java4
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/SecureRestClientTrustManager.java10
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseException.java8
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java48
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java18
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java31
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/ResponseHandlerInterface.java3
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RestClientInterface.java6
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java5
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/utils/InstarClientConstant.java14
14 files changed, 169 insertions, 145 deletions
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/data/AaiVmInfo.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/data/AaiVmInfo.java
index 266b29000..eda8cb767 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/data/AaiVmInfo.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/data/AaiVmInfo.java
@@ -28,6 +28,10 @@ import java.util.List;
public class AaiVmInfo {
+ private String vserverId;
+ private String vserverName;
+ private List<AaiVnfcInfo> vnfcInfo;
+
public String getVserverId() {
return vserverId;
}
@@ -51,8 +55,4 @@ public class AaiVmInfo {
public void setVnfcInfo(List<AaiVnfcInfo> vnfcInfo) {
this.vnfcInfo = vnfcInfo;
}
-
- String vserverId;
- String vserverName;
- List<AaiVnfcInfo> vnfcInfo;
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java
index e97d84f34..61ca3dfa7 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/interfaceImpl/AaiInterfaceRulesHandler.java
@@ -42,6 +42,9 @@ import org.onap.sdnc.config.params.data.ResponseKey;
public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
private static final EELFLogger log = EELFManager.getInstance().getLogger(AaiInterfaceRulesHandler.class);
+ private static final String STR_RETURNING_VALUES = "Returning values: ";
+ private static final String STR_VNF_INFO_VM = "tmp.vnfInfo.vm[";
+
private Parameter parameters;
private SvcLogicContext context;
private AaiVnfInfo vnfInfoData;
@@ -53,7 +56,7 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
}
@Override
- public void processRule() throws IllegalStateException {
+ public void processRule() {
String fn = "AaiInterfaceIpAddressHandler.processRule";
log.info(fn + "Processing rule :" + parameters.getRuleType());
@@ -69,33 +72,39 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
if (null == filterKeys) {
continue;
}
-
- if (StringUtils.isNotBlank(filterKeys.getUniqueKeyName())) {
- respKeys.setUniqueKeyName(filterKeys.getUniqueKeyName());
- }
- if (StringUtils.isNotBlank(filterKeys.getUniqueKeyValue())) {
- respKeys.setUniqueKeyValue(filterKeys.getUniqueKeyValue());
- }
if (StringUtils.isNotBlank(filterKeys.getFieldKeyName())) {
respKeys.setFieldKeyName(filterKeys.getFieldKeyName());
}
- if (StringUtils.isNotBlank(filterKeys.getFilterByField())) {
- respKeys.setFilterByField(filterKeys.getFilterByField());
- }
- if (StringUtils.isNotBlank(filterKeys.getFilterByValue())) {
- respKeys.setFilterByValue(filterKeys.getFilterByValue());
- }
+ trySetUniqueKey(respKeys, filterKeys);
+ trySetFilters(respKeys, filterKeys);
}
-
processKeys(respKeys, parameters.getName());
}
- public void processKeys(ResponseKey filterKey, String aaiKey) {
+ private void trySetFilters(ResponseKey respKeys, ResponseKey filterKeys) {
+ if (StringUtils.isNotBlank(filterKeys.getFilterByField())) {
+ respKeys.setFilterByField(filterKeys.getFilterByField());
+ }
+ if (StringUtils.isNotBlank(filterKeys.getFilterByValue())) {
+ respKeys.setFilterByValue(filterKeys.getFilterByValue());
+ }
+ }
+
+ private void trySetUniqueKey(ResponseKey respKeys, ResponseKey filterKeys) {
+ if (StringUtils.isNotBlank(filterKeys.getUniqueKeyName())) {
+ respKeys.setUniqueKeyName(filterKeys.getUniqueKeyName());
+ }
+ if (StringUtils.isNotBlank(filterKeys.getUniqueKeyValue())) {
+ respKeys.setUniqueKeyValue(filterKeys.getUniqueKeyValue());
+ }
+ }
+
+ private void processKeys(ResponseKey filterKey, String aaiKey) {
String fn = "AaiInterfaceRulesHandler.processKeys()::";
log.info(fn + "processing for " + aaiKey);
- String values = new String();
- JSONObject aaiKeyValues = null;
+ String values = "";
+ JSONObject aaiKeyValues;
log.info("Aai Data in Context : " + context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
if (context.getAttribute(AaiClientConstant.AAI_KEY_VALUES) != null) {
aaiKeyValues = new JSONObject(context.getAttribute(AaiClientConstant.AAI_KEY_VALUES));
@@ -118,117 +127,115 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
}
aaiKeyValues.put(aaiKey, values);
context.setAttribute(AaiClientConstant.AAI_KEY_VALUES, aaiKeyValues.toString());
- return;
}
private String getVServerDetailsFromContext(String fieldKeyName, String filterByField, String filterByValue) {
String fn = "AaiInterfaceRulesHander::getVServerDetailsFromContext():";
- String values = "";
+ StringBuilder values = new StringBuilder("");
log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByName:" + filterByField + " FilterByValue:"
+ filterByValue);
if (!StringUtils.equalsIgnoreCase(fieldKeyName, "vserver-name")) {
- log.info(fn + "Returning values:" + values);
- return values;
+ log.info(fn + STR_RETURNING_VALUES + values);
+ return values.toString();
}
- if (StringUtils.isNotEmpty(filterByField)
- && StringUtils.isNotEmpty(filterByValue)) {
+ if (validateFilters(filterByField, filterByValue)) {
int vmIndex = -1;
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
vmIndex++;
- if (!StringUtils.equalsIgnoreCase(filterByField, "vm-number")) {
- continue;
- }
-
int vmNumber = Integer.parseInt(filterByValue);
- if (vmNumber != vmIndex) {
+ if (!StringUtils.equalsIgnoreCase(filterByField, "vm-number") || vmNumber != vmIndex) {
continue;
}
-
- if (StringUtils.isBlank(values)) {
- values = vm.getVserverName();
+ if (StringUtils.isBlank(values.toString())) {
+ values = new StringBuilder(vm.getVserverName());
} else {
- values = values + "," + vm.getVserverName();
+ values.append(",").append(vm.getVserverName());
}
}
} else {
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
- if (StringUtils.isBlank(values)) {
- values = vm.getVserverName();
+ if (StringUtils.isBlank(values.toString())) {
+ values = new StringBuilder(vm.getVserverName());
} else {
- values = values + "," + vm.getVserverName();
+ values.append(",").append(vm.getVserverName());
}
}
}
+ log.info(fn + STR_RETURNING_VALUES + values);
+ return values.toString();
+ }
- log.info(fn + "Returning values:" + values);
- return values;
+ private boolean validateFilters(String filterByField, String filterByValue) {
+ return StringUtils.isNotEmpty(filterByField) && StringUtils.isNotEmpty(filterByValue);
}
//split from getVnfcDetailsFromContext
private String add2ValuesIpaddressV4OamVipNotEmpty(String values, String filterByField, String filterByValue) {
+ StringBuilder builder = new StringBuilder(values);
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
+
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
if (!StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
|| !StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode())) {
continue;
}
- if (StringUtils.isBlank(values)) {
- values = vnfcInfo.getVnfcOamIpAddress();
+ if (StringUtils.isBlank(builder.toString())) {
+ builder = new StringBuilder(vnfcInfo.getVnfcOamIpAddress());
} else {
- values = values + "," + vnfcInfo.getVnfcOamIpAddress();
+ builder.append(",").append(vnfcInfo.getVnfcOamIpAddress());
}
}
-
}
- return values;
+ return builder.toString();
}
//split from getVnfcDetailsFromContext
private String add2ValuesIpaddressV4OamVipEmpty(String values, String filterByField, String filterByValue) {
+ StringBuilder builder = new StringBuilder(values);
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
- if (StringUtils.isBlank(values)) {
- values = vnfcInfo.getVnfcOamIpAddress();
+ if (StringUtils.isBlank(builder.toString())) {
+ builder = new StringBuilder(vnfcInfo.getVnfcOamIpAddress());
} else {
- values = values + "," + vnfcInfo.getVnfcOamIpAddress();
+ builder.append(",").append(vnfcInfo.getVnfcOamIpAddress());
}
}
}
- return values;
+ return builder.toString();
}
//split from getVnfcDetailsFromContext
private String add2ValuesVnfcNameNotEmpty(String values, String filterByField, String filterByValue) {
+ StringBuilder builder = new StringBuilder(values);
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
if (!StringUtils.equalsIgnoreCase(filterByField, "vnfc-function-code")
|| !StringUtils.equalsIgnoreCase(filterByValue, vnfcInfo.getVnfcFunctionCode())) {
continue;
}
-
- if (StringUtils.isBlank(values)) {
- values = vnfcInfo.getVnfcName();
+ if (StringUtils.isBlank(builder.toString())) {
+ builder = new StringBuilder(vnfcInfo.getVnfcName());
} else {
- values = values + "," + vnfcInfo.getVnfcName();
+ builder.append(",").append(vnfcInfo.getVnfcName());
}
}
-
}
- return values;
+ return builder.toString();
}
//split from getVnfcDetailsFromContext
private String add2ValuesVnfcNameEmpty(String values, String filterByField, String filterByValue) {
for (AaiVmInfo vm : vnfInfoData.getVmInfo()) {
+ StringBuilder builder = new StringBuilder(values);
for (AaiVnfcInfo vnfcInfo : vm.getVnfcInfo()) {
- if (StringUtils.isBlank(values)) {
- values = vnfcInfo.getVnfcName();
+ if (StringUtils.isBlank(builder.toString())) {
+ builder = new StringBuilder(vnfcInfo.getVnfcName());
} else {
- values = values + "," + vnfcInfo.getVnfcName();
+ builder.append(",").append(vnfcInfo.getVnfcName());
}
}
}
@@ -241,7 +248,7 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
log.info(fn + "FieldKeyName:" + fieldKeyName + " FilterByField:" + filterByField + " FilterByValue:"
+ filterByValue);
if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipaddress-v4-oam-vip")) {
- if (StringUtils.isNotEmpty(filterByField) && StringUtils.isNotEmpty(filterByValue)) {
+ if (validateFilters(filterByField, filterByValue)) {
values = add2ValuesIpaddressV4OamVipNotEmpty(values, filterByField, filterByValue);
} else {
values = add2ValuesIpaddressV4OamVipEmpty(values, filterByField, filterByValue);
@@ -254,7 +261,7 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
values = add2ValuesVnfcNameEmpty(values, filterByField, filterByValue);
}
}
- log.info(fn + "Returning values:" + values);
+ log.info(fn + STR_RETURNING_VALUES + values);
return values;
}
@@ -263,12 +270,10 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
log.info("getVnfDetailsFromContext::" + fieldKeyName);
String values = "";
if (StringUtils.equalsIgnoreCase(fieldKeyName, "vnf-name")) {
- String vnfName = context.getAttribute("tmp.vnfInfo.vnf.vnf-name");
- values = vnfName;
+ values = context.getAttribute("tmp.vnfInfo.vnf.vnf-name");
}
if (StringUtils.equalsIgnoreCase(fieldKeyName, "ipv4-oam-ipaddress")) {
- String ipv4OamAddress = context.getAttribute("tmp.vnfInfo.vnf.ipv4-oam-address");
- values = ipv4OamAddress;
+ values = context.getAttribute("tmp.vnfInfo.vnf.ipv4-oam-address");
}
return values;
}
@@ -277,11 +282,11 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
return vnfInfoData;
}
- public void setVnfInfoData(AaiVnfInfo vnfInfoData) {
+ private void setVnfInfoData(AaiVnfInfo vnfInfoData) {
this.vnfInfoData = vnfInfoData;
}
- public AaiVnfInfo generateAaiVnfInfoData() {
+ private AaiVnfInfo generateAaiVnfInfoData() {
log.info("AaiInterfaceRulesHandlerImpl:generateAaiVnfInfoData(): Printing variables in context");
for (Object key : context.getAttributeKeySet()) {
@@ -290,7 +295,6 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
log.debug("generateAaiVnfInfoData():: " + parmName + "=" + parmValue);
}
-
String vmcount = context.getAttribute("tmp.vnfInfo.vm-count");
int vmCount = 0;
if (!StringUtils.isBlank(vmcount)) {
@@ -299,24 +303,24 @@ public class AaiInterfaceRulesHandler implements RuleHandlerInterface {
log.info("generateAaiVnfInfoData::" + "vmCount:" + vmCount);
AaiVnfInfo vnfInfo = new AaiVnfInfo();
vnfInfo.setVnfName("vnf-name");
- ArrayList<AaiVmInfo> vmList = new ArrayList<AaiVmInfo>();
+ ArrayList<AaiVmInfo> vmList = new ArrayList<>();
for (int i = 0; i < vmCount; i++) {
AaiVmInfo vm = new AaiVmInfo();
- String vnfcCountStr = context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-count");
+ String vnfcCountStr = context.getAttribute(STR_VNF_INFO_VM + i + "].vnfc-count");
int vnfcCount = Integer.parseInt(vnfcCountStr);
- ArrayList<AaiVnfcInfo> vnfcInfoList = new ArrayList<AaiVnfcInfo>();
+ ArrayList<AaiVnfcInfo> vnfcInfoList = new ArrayList<>();
for (int j = 0; j < vnfcCount; j++) {
AaiVnfcInfo vnfcInfo = new AaiVnfcInfo();
- vnfcInfo.setVnfcName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name"));
- vnfcInfo.setVnfcFunctionCode(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-function-code"));
+ vnfcInfo.setVnfcName(context.getAttribute(STR_VNF_INFO_VM + i + "].vnfc-name"));
+ vnfcInfo.setVnfcFunctionCode(context.getAttribute(STR_VNF_INFO_VM + i + "].vnfc-function-code"));
vnfcInfo.setVnfcOamIpAddress(
- context.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-ipaddress-v4-oam-vip"));
+ context.getAttribute(STR_VNF_INFO_VM + i + "].vnfc-ipaddress-v4-oam-vip"));
vnfcInfoList.add(vnfcInfo);
}
vm.setVnfcInfo(vnfcInfoList);
- vm.setVserverId(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-id"));
- vm.setVserverName(context.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-name"));
+ vm.setVserverId(context.getAttribute(STR_VNF_INFO_VM + i + "].vserver-id"));
+ vm.setVserverName(context.getAttribute(STR_VNF_INFO_VM + i + "].vserver-name"));
vmList.add(vm);
}
vnfInfo.setVmInfo(vmList);
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/utils/AaiClientConstant.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/utils/AaiClientConstant.java
index 9b7bd80e4..b1e7ac8ae 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/utils/AaiClientConstant.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/aai/utils/AaiClientConstant.java
@@ -26,9 +26,6 @@ package org.onap.appc.aai.utils;
public class AaiClientConstant {
- private AaiClientConstant() {
- }//hidden public constructor
-
public static final String INPUT_PARAM_RESPONSE_PRIFIX = "responsePrefix";
public static final String OUTPUT_PARAM_STATUS = "status";
public static final String OUTPUT_PARAM_ERROR_MESSAGE = "error-message";
@@ -38,4 +35,6 @@ public class AaiClientConstant {
public static final String AAI_KEYS = "aaiKeys";
public static final String SOURCE_SYSTEM_AAI = "AAI";
public static final String AAI_KEY_VALUES = "AAI-KEY-VALUES";
+
+ private AaiClientConstant() {}
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java
index f36ede8a6..527ffc029 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/InstarClientActivator.java
@@ -35,7 +35,7 @@ import org.osgi.framework.ServiceRegistration;
public class InstarClientActivator implements BundleActivator {
- private List<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
+ private List<ServiceRegistration> registrations = new LinkedList<>();
private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarClientActivator.class);
@Override
@@ -51,8 +51,6 @@ public class InstarClientActivator implements BundleActivator {
public void stop(BundleContext arg0) throws Exception {
for (ServiceRegistration registration : registrations) {
registration.unregister();
- registration = null;
}
-
}
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java
index fc4003ac4..7bcab6648 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java
@@ -84,7 +84,7 @@ public class Dme2Client {
}
}
- public ClientResponse sendtoInstar() throws SvcLogicException {
+ private ClientResponse sendToInstar() throws SvcLogicException {
log.info("Called Send with operation Name=" + this.operationName + "and = " +
properties.getProperty(operationName + InstarClientConstant.BASE_URL));
@@ -172,7 +172,7 @@ public class Dme2Client {
return IOUtils.toString(Dme2Client.class.getClassLoader().getResourceAsStream("/tmp/sampleResponse"),
Charset.defaultCharset());
}
- ClientResponse clientResponse = sendtoInstar();
+ ClientResponse clientResponse = sendToInstar();
if (clientResponse != null) {
response = clientResponse.getEntity(String.class);
log.info(clientResponse.getStatus() + " Status, Response :" + response);
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/SecureRestClientTrustManager.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/SecureRestClientTrustManager.java
index 12aba769a..120495f29 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/SecureRestClientTrustManager.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/SecureRestClientTrustManager.java
@@ -33,24 +33,22 @@ public class SecureRestClientTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
- throws CertificateException {
- }
+ throws CertificateException { /*TODO implement this method*/}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
- throws CertificateException {
- }
+ throws CertificateException { /*TODO implement this method*/ }
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
- public boolean isClientTrusted(X509Certificate[] arg0) {
+ public boolean isClientTrusted(X509Certificate[] arg) {
return true;
}
- public boolean isServerTrusted(X509Certificate[] arg0) {
+ public boolean isServerTrusted(X509Certificate[] arg) {
return true;
}
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseException.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseException.java
new file mode 100644
index 000000000..59df2e26f
--- /dev/null
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseException.java
@@ -0,0 +1,8 @@
+package org.onap.appc.instar.interfaceImpl;
+
+public class InstarResponseException extends Exception{
+
+ public InstarResponseException(String message) {
+ super(message);
+ }
+}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java
index 3cd965620..b9d97b4bf 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarResponseHandlerImpl.java
@@ -37,13 +37,12 @@ public class InstarResponseHandlerImpl implements ResponseHandlerInterface {
private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarResponseHandlerImpl.class);
- ResponseKey resKey = null;
- SvcLogicContext ctxt = null;
+ private ResponseKey resKey = null;
+ private SvcLogicContext ctxt = null;
public InstarResponseHandlerImpl(ResponseKey filterKeys, SvcLogicContext context) {
this.resKey = filterKeys;
this.ctxt = context;
-
}
@Override
@@ -68,21 +67,28 @@ public class InstarResponseHandlerImpl implements ResponseHandlerInterface {
log.info(fn + "Appc Filter Key :" + ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey
.getUniqueKeyValue());
- if (res.getString(InstarClientConstant.FDQN) != null &&
- res.getString(InstarClientConstant.FDQN)
- .equalsIgnoreCase(ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue())) {
- if (resKey.getFieldKeyName().equals(InstarClientConstant.V4_ADDRESS)) {
- instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_ADDRESS));
- } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V4_SUBNET)) {
- instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_SUBNET));
- } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY)) {
- instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY));
- } else if (resKey.getFieldKeyName().equals(InstarClientConstant.V6_ADDRESS)) {
- instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_ADDRESS));
- } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V6_SUBNET)) {
- instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_SUBNET));
- } else if (resKey.getFieldKeyName().equals(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY)) {
- instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY));
+ if (hasValidFdqn(res)) {
+ switch (resKey.getFieldKeyName()) {
+ case InstarClientConstant.V4_ADDRESS:
+ instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_ADDRESS));
+ break;
+ case InstarClientConstant.INSTAR_V4_SUBNET:
+ instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_SUBNET));
+ break;
+ case InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY:
+ instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V4_DEFAULT_GATEWAY));
+ break;
+ case InstarClientConstant.V6_ADDRESS:
+ instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_ADDRESS));
+ break;
+ case InstarClientConstant.INSTAR_V6_SUBNET:
+ instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_SUBNET));
+ break;
+ case InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY:
+ instarKeyValues.put(instarKey, res.getString(InstarClientConstant.INSTAR_V6_DEFAULT_GATEWAY));
+ break;
+ default:
+ break;
}
break;
}
@@ -92,4 +98,10 @@ public class InstarResponseHandlerImpl implements ResponseHandlerInterface {
return instarKeyValues;
}
+
+ private boolean hasValidFdqn(JSONObject res) {
+ return res.getString(InstarClientConstant.FDQN) != null &&
+ res.getString(InstarClientConstant.FDQN)
+ .equalsIgnoreCase(ctxt.getAttribute(InstarClientConstant.VNF_NAME) + resKey.getUniqueKeyValue());
+ }
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java
index bb4656772..a08bde472 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InstarRestClientImpl.java
@@ -26,7 +26,8 @@ package org.onap.appc.instar.interfaceImpl;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import java.util.HashMap;
+import java.io.IOException;
+import java.util.Map;
import org.onap.appc.instar.dme2client.Dme2Client;
import org.onap.appc.instar.interfaces.RestClientInterface;
import org.onap.appc.instar.utils.InstarClientConstant;
@@ -34,18 +35,18 @@ import org.onap.appc.instar.utils.InstarClientConstant;
public class InstarRestClientImpl implements RestClientInterface {
private static final EELFLogger log = EELFManager.getInstance().getLogger(InstarRestClientImpl.class);
- HashMap<String, String> requestData = null;
- Dme2Client dme2Client;
+ private Map<String, String> requestData = null;
+ private Dme2Client dme2Client;
- public InstarRestClientImpl(HashMap<String, String> instarRequestData) {
+ public InstarRestClientImpl(Map<String, String> instarRequestData) {
this.requestData = instarRequestData;
}
@Override
- public String sendRequest(String operation) throws Exception {
+ public String sendRequest(String operation) throws InstarResponseException, IOException {
- String instarResponse = null;
+ String instarResponse;
try {
if (operation != null && operation
.equalsIgnoreCase(InstarClientConstant.OPERATION_GET_IPADDRESS_BY_VNF_NAME)) {
@@ -53,11 +54,10 @@ public class InstarRestClientImpl implements RestClientInterface {
}
instarResponse = dme2Client.send();
log.info("Resposne in InstarRestClientImpl = " + instarResponse);
- if (instarResponse == null || instarResponse.length() < 0) {
- throw new Exception("No Data received from Instar for this call " + operation);
+ if (instarResponse == null || instarResponse.isEmpty()) {
+ throw new InstarResponseException("No Data received from Instar for this call " + operation);
}
} catch (Exception e) {
- e.printStackTrace();
throw e;
}
return instarResponse;
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java
index bef613fa2..6c72ffa9b 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaceImpl/InterfaceIpAddressImpl.java
@@ -26,8 +26,10 @@ package org.onap.appc.instar.interfaceImpl;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.onap.appc.instar.interfaces.ResponseHandlerInterface;
import org.onap.appc.instar.interfaces.RestClientInterface;
import org.onap.appc.instar.interfaces.RuleHandlerInterface;
@@ -48,38 +50,35 @@ public class InterfaceIpAddressImpl implements RuleHandlerInterface {
}
@Override
- public void processRule() throws Exception {
+ public void processRule() throws InstarResponseException, IOException {
String fn = "InterfaceIpAddressHandler.processRule";
log.info(fn + "Processing rule :" + parameters.getRuleType());
String operationName;
- RestClientInterface restClient = null;
- ResponseHandlerInterface responseHandler = null;
+ RestClientInterface restClient;
+ ResponseHandlerInterface responseHandler;
List<ResponseKey> responseKeyList = parameters.getResponseKeys();
- if (responseKeyList != null && responseKeyList.size() > 0) {
+ if (responseKeyList != null && !responseKeyList.isEmpty()) {
for (ResponseKey filterKeys : responseKeyList) {
- //response.setUniqueKeyValue(response.getUniqueKeyValue()+ context.getAttribute(InstarClientConstant.VNF_NAME));
- switch (parameters.getSource()) {
- case InstarClientConstant.SOURCE_SYSTEM_INSTAR:
- restClient = new InstarRestClientImpl(createInstarRequestData(context));
- responseHandler = new InstarResponseHandlerImpl(filterKeys, context);
- operationName = "getIpAddressByVnf";
- break;
- default:
- throw new Exception("No Client registered for : " + parameters.getSource());
+ if (parameters.getSource().equals(InstarClientConstant.SOURCE_SYSTEM_INSTAR)) {
+ restClient = new InstarRestClientImpl(createInstarRequestData(context));
+ responseHandler = new InstarResponseHandlerImpl(filterKeys, context);
+ operationName = "getIpAddressByVnf";
+ } else {
+ throw new InstarResponseException("No Client registered for : " + parameters.getSource());
}
responseHandler.processResponse(restClient.sendRequest(operationName), parameters.getName());
}
} else {
- throw new Exception("NO response Keys set for : " + parameters.getRuleType());
+ throw new InstarResponseException("NO response Keys set for : " + parameters.getRuleType());
}
}
- private HashMap<String, String> createInstarRequestData(SvcLogicContext ctxt) {
- HashMap<String, String> requestParams = new HashMap<String, String>();
+ private Map<String, String> createInstarRequestData(SvcLogicContext ctxt) {
+ HashMap<String, String> requestParams = new HashMap<>();
requestParams.put(InstarClientConstant.VNF_NAME, ctxt.getAttribute(InstarClientConstant.VNF_NAME));
return requestParams;
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/ResponseHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/ResponseHandlerInterface.java
index 52323c223..499f7aae0 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/ResponseHandlerInterface.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/ResponseHandlerInterface.java
@@ -24,7 +24,8 @@
package org.onap.appc.instar.interfaces;
+@FunctionalInterface
public interface ResponseHandlerInterface {
- public Object processResponse(String response, String instarKey);
+ Object processResponse(String response, String instarKey);
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RestClientInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RestClientInterface.java
index 37c8dbeb4..bac3bfb9b 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RestClientInterface.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RestClientInterface.java
@@ -24,7 +24,11 @@
package org.onap.appc.instar.interfaces;
+import java.io.IOException;
+import org.onap.appc.instar.interfaceImpl.InstarResponseException;
+
+@FunctionalInterface
public interface RestClientInterface {
- public String sendRequest(String operation) throws Exception;
+ String sendRequest(String operation) throws InstarResponseException, IOException;
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java
index 4d75ff44d..be9b45560 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/interfaces/RuleHandlerInterface.java
@@ -24,8 +24,11 @@
package org.onap.appc.instar.interfaces;
+import java.io.IOException;
+import org.onap.appc.instar.interfaceImpl.InstarResponseException;
+@FunctionalInterface
public interface RuleHandlerInterface {
- public void processRule() throws Exception;
+ void processRule() throws InstarResponseException, IOException;
}
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/utils/InstarClientConstant.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/utils/InstarClientConstant.java
index 4fbe023f6..9a96f7380 100644
--- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/utils/InstarClientConstant.java
+++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/utils/InstarClientConstant.java
@@ -26,11 +26,11 @@ package org.onap.appc.instar.utils;
public class InstarClientConstant {
- public static String INPUT_PARAM_RESPONSE_PRIFIX = "responsePrefix";
- public static String OUTPUT_PARAM_STATUS = "status";
- public static String OUTPUT_PARAM_ERROR_MESSAGE = "error-message";
- public static String OUTPUT_STATUS_SUCCESS = "success";
- public static String OUTPUT_STATUS_FAILURE = "failure";
+ public static final String INPUT_PARAM_RESPONSE_PRIFIX = "responsePrefix";
+ public static final String OUTPUT_PARAM_STATUS = "status";
+ public static final String OUTPUT_PARAM_ERROR_MESSAGE = "error-message";
+ public static final String OUTPUT_STATUS_SUCCESS = "success";
+ public static final String OUTPUT_STATUS_FAILURE = "failure";
public static final String INSTAR_KEYS = "instarKeys";
public static final String INTERFACE_IP_ADDRESS = "interface-ip-address";
@@ -72,10 +72,8 @@ public class InstarClientConstant {
public static final String APPC_PROPERTIES = "appc.properties";
public static final String METHOD = "_method";
public static final String OPERATION_GET_IPADDRESS_BY_VNF_NAME = "getIpAddressByVnf";
-
public static final String OUTBOUND_PROPERTIES = "/outbound.properties";
- public static String CONTENT_TYPE = "application/json";
- public static String RETURNED_RESPONSE_TYPE = "application/json";
+ private InstarClientConstant() {}
}