summaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnf-adapter
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-01-08 12:40:46 +0100
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-01-29 12:58:05 +0100
commit8d977df8ba8a63e8c76f58825854fd53f8e638ba (patch)
tree7a1e606d524ff5ea67715f4b1ef00b94545e9e61 /adapters/mso-vnf-adapter
parent1672a4db05c0e313ce258efe26a75f995c162bb5 (diff)
refactoring - add Optional
change possible null return value to Optional Change-Id: I70bf78a51b901a74932b00d1d8735bef5eeacef7 Issue-ID: SO-360 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'adapters/mso-vnf-adapter')
-rw-r--r--adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java26
1 files changed, 12 insertions, 14 deletions
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
index fb86b8c520..be6e752c0e 100644
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java
@@ -21,7 +21,7 @@
package org.openecomp.mso.adapters.vnf;
-
+import java.util.Optional;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.ObjectMapper;
@@ -953,15 +953,14 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
if (minVersionVnf != null && maxVersionVnf != null) {
MavenLikeVersioning aicV = new MavenLikeVersioning();
- CloudSite cloudSite = null;
if (this.cloudConfig == null) {
this.cloudConfig = this.cloudConfigFactory.getCloudConfig();
}
// double check
if (this.cloudConfig != null) {
- cloudSite = this.cloudConfig.getCloudSite(cloudSiteId);
- if (cloudSite != null) {
- aicV.setVersion(cloudSite.getAic_version());
+ Optional<CloudSite> cloudSiteOpt = this.cloudConfig.getCloudSite(cloudSiteId);
+ if (cloudSiteOpt.isPresent()) {
+ aicV.setVersion(cloudSiteOpt.get().getAic_version());
// Add code to handle unexpected values in here
boolean moreThanMin = true;
boolean equalToMin = true;
@@ -980,10 +979,10 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
if (!doNotTest) {
if ((moreThanMin || equalToMin) // aic >= min
&& (equalToMax || !(moreThanMax))) { //aic <= max
- LOGGER.debug("VNF Resource " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource.getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " supported on Cloud: " + cloudSite.getId() + " with AIC_Version:" + cloudSite.getAic_version());
+ LOGGER.debug("VNF Resource " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource.getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " supported on Cloud: " + cloudSiteOpt.get().getId() + " with AIC_Version:" + cloudSiteOpt.get().getAic_version());
} else {
// ERROR
- String error = "VNF Resource type: " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource.getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " NOT supported on Cloud: " + cloudSite.getId() + " with AIC_Version:" + cloudSite.getAic_version();
+ String error = "VNF Resource type: " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource.getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " NOT supported on Cloud: " + cloudSiteOpt.get().getId() + " with AIC_Version:" + cloudSiteOpt.get().getAic_version();
LOGGER.error(MessageEnum.RA_CONFIG_EXC, error, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion");
LOGGER.debug(error);
throw new VnfException(error, MsoExceptionCategory.USERDATA);
@@ -1703,26 +1702,25 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
}
if (minVersionVnf != null && maxVersionVnf != null) {
MavenLikeVersioning aicV = new MavenLikeVersioning();
- CloudSite cloudSite = null;
//String aicVersion = "";
if (this.cloudConfig == null) {
this.cloudConfig = this.cloudConfigFactory.getCloudConfig();
}
// double check
if (this.cloudConfig != null) {
- cloudSite = this.cloudConfig.getCloudSite(cloudSiteId);
- if (cloudSite != null) {
- aicV.setVersion(cloudSite.getAic_version());
+ Optional<CloudSite> cloudSiteOpt = this.cloudConfig.getCloudSite(cloudSiteId);
+ if (cloudSiteOpt.isPresent()) {
+ aicV.setVersion(cloudSiteOpt.get().getAic_version());
if ((aicV.isMoreRecentThan(minVersionVnf) || aicV.isTheSameVersion(minVersionVnf)) // aic >= min
&& (aicV.isTheSameVersion(maxVersionVnf) || !(aicV.isMoreRecentThan(maxVersionVnf)))) { //aic <= max
- LOGGER.debug("VNF Resource " + vnfResource.getModelName() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " supported on Cloud: " + cloudSite.getId() + " with AIC_Version:" + cloudSite.getAic_version());
+ LOGGER.debug("VNF Resource " + vnfResource.getModelName() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " supported on Cloud: " + cloudSiteOpt.get().getId() + " with AIC_Version:" + cloudSiteOpt.get().getAic_version());
} else {
// ERROR
- String error = "VNF Resource type: " + vnfResource.getModelName() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " NOT supported on Cloud: " + cloudSite.getId() + " with AIC_Version:" + cloudSite.getAic_version();
+ String error = "VNF Resource type: " + vnfResource.getModelName() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + " NOT supported on Cloud: " + cloudSiteOpt.get().getId() + " with AIC_Version:" + cloudSiteOpt.get().getAic_version();
LOGGER.error(MessageEnum.RA_CONFIG_EXC, error, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion");
LOGGER.debug(error);
throw new VnfException(error, MsoExceptionCategory.USERDATA);
- }
+ }
} // let this error out downstream to avoid introducing uncertainty at this stage
} else {
LOGGER.debug("cloudConfig is NULL - cannot check cloud site version");