aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2020-08-05 10:17:31 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-05 10:17:31 +0000
commitce504e80dadb6d1751ebc773e57afd3253d9dfc0 (patch)
treef0cc7d0d8053e6f2b17f677eb159306b97760d0e
parentf1f38c6baca214137b18a3d83087a04379f39983 (diff)
parente6f9402455d0931c6d2e078a7780ed3969fe0121 (diff)
Merge "Sonar fixes"
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java69
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java4
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java21
-rw-r--r--so-sdn-clients/pom.xml6
4 files changed, 46 insertions, 54 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java
index 6831a656a8..92ed61df67 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/SdncInputParametersProvider.java
@@ -50,11 +50,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class SdncInputParametersProvider extends AbstractInputParametersProvider<GenericVnf> {
private static final Logger LOGGER = LoggerFactory.getLogger(SdncInputParametersProvider.class);
-
private static final String VNF_PARAMETERS_PATH = "$..vnf-parameters";
-
private final SDNCClient sdncClient;
-
private final ObjectMapper mapper;
@Autowired
@@ -68,34 +65,12 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider
final String vnfName = genericVnf.getVnfName();
final String vnfType = getVnfType(genericVnf);
final String url = getPreloadVnfsUrl(vnfName, vnfType);
+ final InputParameter inputParameter = parseInputParametersUsingUrl(url);
- try {
- LOGGER.debug("Will query sdnc for input parameters using url: {}", url);
- final String jsonResponse = sdncClient.get(url);
- final String json = JsonPathUtil.getInstance().locateResult(jsonResponse, VNF_PARAMETERS_PATH).orElse(null);
-
- try {
-
- if (json != null) {
- final List<VnfParameter> vnfParametersArray =
- mapper.readValue(json, new TypeReference<List<VnfParameter>>() {});
- final Map<String, String> vnfParametersMap = getVnfParameterMap(vnfParametersArray);
- final Map<String, String> additionalParameters = getAdditionalParameters(vnfParametersMap);
- final List<ExternalVirtualLink> extVirtualLinks = getExtVirtualLinks(vnfParametersMap);
- final InputParameter inputParameter = new InputParameter(additionalParameters, extVirtualLinks);
- LOGGER.info("InputParameter found in sdnc response : {}", inputParameter);
- return inputParameter;
- }
-
- } catch (final IOException exception) {
- LOGGER.error("Unable to parse vnf parameters : {}", json, exception);
- }
- } catch (final Exception exception) {
- LOGGER.error("Unable to retrieve/parse input parameters using URL: {} ", url, exception);
- }
+ if (inputParameter != null)
+ return inputParameter;
LOGGER.warn("No input parameters found ...");
return NullInputParameter.NULL_INSTANCE;
-
}
private List<ExternalVirtualLink> getExtVirtualLinks(final Map<String, String> vnfParametersMap) {
@@ -109,19 +84,18 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider
private Map<String, String> getAdditionalParameters(final Map<String, String> vnfParametersMap) {
final String additionalParamsString = vnfParametersMap.get(ADDITIONAL_PARAMS);
+
if (additionalParamsString != null && !additionalParamsString.isEmpty()) {
return parseAdditionalParameters(additionalParamsString);
}
return Collections.emptyMap();
}
-
private Map<String, String> getVnfParameterMap(final List<VnfParameter> array) {
if (array != null) {
return array.stream().filter(vnfParam -> vnfParam.getName() != null && vnfParam.getValue() != null)
.collect(Collectors.toMap(VnfParameter::getName, VnfParameter::getValue));
}
-
return Collections.emptyMap();
}
@@ -131,10 +105,43 @@ public class SdncInputParametersProvider extends AbstractInputParametersProvider
private String getVnfType(final GenericVnf genericVnf) {
final ModelInfoGenericVnf modelInfoGenericVnf = genericVnf.getModelInfoGenericVnf();
- if (modelInfoGenericVnf != null && modelInfoGenericVnf.getModelName() != null) {
+ if (modelInfoGenericVnf != null) {
return modelInfoGenericVnf.getModelName();
}
return genericVnf.getVnfType();
}
+ private InputParameter parseInputParametersUsingUrl(String url) {
+ try {
+ LOGGER.debug("Will query sdnc for input parameters using url: {}", url);
+ final String jsonResponse = sdncClient.get(url);
+ final String json = JsonPathUtil.getInstance().locateResult(jsonResponse, VNF_PARAMETERS_PATH).orElse(null);
+ final InputParameter inputParameter = parseVnfParameters(json);
+
+ if (inputParameter != null)
+ return inputParameter;
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to retrieve/parse input parameters using URL: {} ", url, exception);
+ }
+ return null;
+ }
+
+ private InputParameter parseVnfParameters(String json) {
+ try {
+ if (json != null) {
+ final List<VnfParameter> vnfParametersArray =
+ mapper.readValue(json, new TypeReference<List<VnfParameter>>() {});
+ final Map<String, String> vnfParametersMap = getVnfParameterMap(vnfParametersArray);
+ final Map<String, String> additionalParameters = getAdditionalParameters(vnfParametersMap);
+ final List<ExternalVirtualLink> extVirtualLinks = getExtVirtualLinks(vnfParametersMap);
+ final InputParameter inputParameter = new InputParameter(additionalParameters, extVirtualLinks);
+ LOGGER.info("InputParameter found in sdnc response : {}", inputParameter);
+ return inputParameter;
+ }
+
+ } catch (final IOException exception) {
+ LOGGER.error("Unable to parse vnf parameters : {}", json, exception);
+ }
+ return null;
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java
index ac939d04ec..bdd738b031 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/UserParamInputParametersProvider.java
@@ -40,12 +40,12 @@ public class UserParamInputParametersProvider extends AbstractInputParametersPro
final InputParameter inputParameter = new InputParameter();
final Object additionalParams = userParams.get(ADDITIONAL_PARAMS);
- if (additionalParams != null && additionalParams instanceof String) {
+ if (additionalParams instanceof String) {
inputParameter.setAdditionalParams(parseAdditionalParameters(additionalParams.toString()));
}
final Object extVirtualLinks = userParams.get(EXT_VIRTUAL_LINKS);
- if (extVirtualLinks != null && extVirtualLinks instanceof String) {
+ if (extVirtualLinks instanceof String) {
inputParameter.setExtVirtualLinks(parseExternalVirtualLinks(extVirtualLinks.toString()));
}
LOGGER.info("InputParameter found in userParams : {}", inputParameter);
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java
index 0d45dad6fe..2491c99bc4 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/utils/VnfParameter.java
@@ -35,30 +35,18 @@ public class VnfParameter {
@JsonProperty("vnf-parameter-value")
private String value;
- /**
- * @return the name
- */
public String getName() {
return name;
}
- /**
- * @param name the name to set
- */
public void setName(final String name) {
this.name = name;
}
- /**
- * @return the value
- */
public String getValue() {
return value;
}
- /**
- * @param value the value to set
- */
public void setValue(final String value) {
this.value = value;
}
@@ -66,10 +54,9 @@ public class VnfParameter {
@Override
public int hashCode() {
final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return Objects.hash(name, value);
+ int nameResult = prime + ((name == null) ? 0 : name.hashCode());
+ int valueResult = prime + ((value == null) ? 0 : value.hashCode());
+ return Objects.hash(nameResult, valueResult);
}
@Override
@@ -78,7 +65,6 @@ public class VnfParameter {
VnfParameter other = (VnfParameter) obj;
return Objects.equals(name, other.name) && Objects.equals(value, other.value);
}
-
return false;
}
@@ -86,5 +72,4 @@ public class VnfParameter {
public String toString() {
return "VnfParameter [name=" + name + ", value=" + value + "]";
}
-
}
diff --git a/so-sdn-clients/pom.xml b/so-sdn-clients/pom.xml
index c9b417b230..66780c75d3 100644
--- a/so-sdn-clients/pom.xml
+++ b/so-sdn-clients/pom.xml
@@ -53,7 +53,7 @@
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
- <pluginExecution>
+ <pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
@@ -112,7 +112,7 @@
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
- <exclusion>
+ <exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
@@ -152,7 +152,7 @@
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
</dependency>