summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/main
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-05-02 16:46:14 -0400
committerRob Daugherty <rd472p@att.com>2018-05-04 15:28:51 +0000
commit3ee4ec41ac18e51a16eafa767e090502b1a33fb5 (patch)
tree11a4d7b6c3bc5b88ce8dd67f12c7726c9f7dd80f /adapters/mso-adapter-utils/src/main
parent13999df2b5cbcfd29d479e20970b39ba876725f3 (diff)
Fix CloudConfig junits
...for some definition of the word "fix". There is still a lot that's less than ideal about how CloudConfig is handled, and with how the unit tests are written. Change-Id: Ic8c66c64d336f22c141687cf41a4828810bf1aec Issue-ID: SO-584 Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/main')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java8
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java16
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java2
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java14
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java17
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java13
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java18
7 files changed, 50 insertions, 38 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java
index 3281f0489c..2b385910d9 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java
@@ -92,11 +92,11 @@ public class CloudConfigFactory implements Serializable {
public CloudConfig getCloudConfig () {
rwl.readLock ().lock ();
try {
- if (cloudConfigCache.isValidCloudConfig()) {
- return cloudConfigCache.clone ();
- } else {
- return new CloudConfig();
+ if (!cloudConfigCache.isValidCloudConfig()) {
+ // Not ideal, but better than returning an invalid object
+ throw new IllegalStateException("No valid CloudConfig is loaded");
}
+ return cloudConfigCache.clone ();
} finally {
rwl.readLock ().unlock ();
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
index 3f5da19854..f7723b6a8f 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
@@ -100,9 +100,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
// The cache key is "tenantId:cloudId"
private static Map <String, HeatCacheEntry> heatClientCache = new HashMap <> ();
- // Fetch cloud configuration each time (may be cached in CloudConfig class)
- protected CloudConfig cloudConfig;
-
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
protected MsoJavaProperties msoProps = null;
@@ -145,11 +142,12 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
} catch (MsoPropertiesException e) {
LOGGER.error (MessageEnum.LOAD_PROPERTIES_FAIL, "Unknown. Mso Properties ID not found in cache: " + msoPropID, "", "", MsoLogger.ErrorCode.DataError, "Exception - Mso Properties ID not found in cache", e);
}
- cloudConfig = cloudConfigFactory.getCloudConfig ();
LOGGER.debug("MsoHeatUtils:" + msoPropID);
-
}
+ protected CloudConfigFactory getCloudConfigFactory() {
+ return cloudConfigFactory;
+ }
/**
* keep this old method signature here to maintain backwards compatibility. keep others as well.
@@ -325,7 +323,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
}
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
LOGGER.debug("Found: " + cloudSite.toString());
// Get a Heat client. They are cached between calls (keyed by tenantId:cloudId)
@@ -661,7 +659,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
LOGGER.debug ("Query HEAT stack: " + stackName + " in tenant " + tenantId);
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
LOGGER.debug("Found: " + cloudSite.toString());
@@ -723,7 +721,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
String stackName,
boolean pollForCompletion) throws MsoException {
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
LOGGER.debug("Found: " + cloudSite.toString());
@@ -863,7 +861,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{
*/
public List <StackInfo> queryAllStacks (String tenantId, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
// Get a Heat client. They are cached between calls (keyed by tenantId:cloudId)
Heat heatClient = getHeatClient (cloudSite, tenantId);
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java
index 595da58270..08ae9df4b5 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java
@@ -193,7 +193,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
}
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
// Get a Heat client. They are cached between calls (keyed by tenantId:cloudId)
// This could throw MsoTenantNotFound or MsoOpenstackException (both propagated)
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java
index 018396d6ec..6bec917d9d 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java
@@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
+
+import org.openecomp.mso.cloud.CloudConfigFactory;
import org.openecomp.mso.cloud.CloudIdentity;
import org.openecomp.mso.cloud.CloudSite;
import org.openecomp.mso.logger.MsoAlarmLogger;
@@ -64,8 +66,8 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
String msoPropID;
- public MsoKeystoneUtils (String msoPropID) {
- super(msoPropID);
+ public MsoKeystoneUtils(String msoPropID, CloudConfigFactory cloudConfigFactory) {
+ super(msoPropID, cloudConfigFactory);
this.msoPropID = msoPropID;
LOGGER.debug("MsoKeyStoneUtils:" + msoPropID);
}
@@ -93,7 +95,7 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
Map <String, String> metadata,
boolean backout) throws MsoException {
// Obtain the cloud site information where we will create the tenant
- Optional<CloudSite> cloudSiteOpt = cloudConfig.getCloudSite(cloudSiteId);
+ Optional<CloudSite> cloudSiteOpt = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId);
if (!cloudSiteOpt.isPresent()) {
LOGGER.error(MessageEnum.RA_CREATE_TENANT_ERR, "MSOCloudSite not found", "", "", MsoLogger.ErrorCode.DataError, "MSOCloudSite not found");
throw new MsoCloudSiteNotFound (cloudSiteId);
@@ -197,7 +199,7 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
*/
public MsoTenant queryTenant (String tenantId, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will query the tenant
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite);
@@ -245,7 +247,7 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
*/
public MsoTenant queryTenantByName (String tenantName, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will query the tenant
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite);
@@ -290,7 +292,7 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
*/
public boolean deleteTenant (String tenantId, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will query the tenant
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite);
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java
index 9eba799e18..df769ec0c2 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java
@@ -65,8 +65,7 @@ public class MsoNeutronUtils extends MsoCommonUtils
// The cache key is "tenantId:cloudId"
private static Map<String,NeutronCacheEntry> neutronClientCache = new HashMap<>();
- // Fetch cloud configuration each time (may be cached in CloudConfig class)
- private CloudConfig cloudConfig;
+ private CloudConfigFactory cloudConfigFactory;
private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
private String msoPropID;
@@ -76,9 +75,13 @@ public class MsoNeutronUtils extends MsoCommonUtils
};
public MsoNeutronUtils(String msoPropID, CloudConfigFactory cloudConfigFactory) {
- cloudConfig = cloudConfigFactory.getCloudConfig();
+ this.cloudConfigFactory = cloudConfigFactory;
this.msoPropID = msoPropID;
}
+
+ protected CloudConfigFactory getCloudConfigFactory() {
+ return cloudConfigFactory;
+ }
/**
* Create a network with the specified parameters in the given cloud/tenant.
@@ -101,7 +104,7 @@ public class MsoNeutronUtils extends MsoCommonUtils
throws MsoException
{
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
Quantum neutronClient = getNeutronClient (cloudSite, tenantId);
@@ -179,7 +182,7 @@ public class MsoNeutronUtils extends MsoCommonUtils
LOGGER.debug("In queryNetwork");
// Obtain the cloud site information
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
Quantum neutronClient = getNeutronClient (cloudSite, tenantId);
@@ -219,7 +222,7 @@ public class MsoNeutronUtils extends MsoCommonUtils
public boolean deleteNetwork(String networkId, String tenantId, String cloudSiteId) throws MsoException
{
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
Quantum neutronClient = getNeutronClient (cloudSite, tenantId);
try {
@@ -276,7 +279,7 @@ public class MsoNeutronUtils extends MsoCommonUtils
throws MsoException
{
// Obtain the cloud site information where we will create the stack
- CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ CloudSite cloudSite = getCloudConfigFactory().getCloudConfig().getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
Quantum neutronClient = getNeutronClient (cloudSite, tenantId);
// Check that the network exists
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java
index 2cd4597c18..964babd1e0 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java
@@ -22,7 +22,6 @@ package org.openecomp.mso.openstack.utils;
import java.util.Map;
-import org.openecomp.mso.cloud.CloudConfig;
import org.openecomp.mso.cloud.CloudConfigFactory;
import org.openecomp.mso.cloud.CloudIdentity;
import org.openecomp.mso.logger.MessageEnum;
@@ -36,16 +35,14 @@ import org.openecomp.mso.properties.MsoPropertiesFactory;
public abstract class MsoTenantUtils extends MsoCommonUtils {
- protected CloudConfigFactory cloudConfigFactory;
+ private CloudConfigFactory cloudConfigFactory;
protected MsoPropertiesFactory msoPropFactory;
protected static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
protected MsoJavaProperties msoProps;
- protected CloudConfig cloudConfig;
- public MsoTenantUtils (String msoPropID) {
- cloudConfigFactory = new CloudConfigFactory();
+ public MsoTenantUtils (String msoPropID, CloudConfigFactory cloudConfigFactory) {
+ this.cloudConfigFactory = cloudConfigFactory;
msoPropFactory = new MsoPropertiesFactory();
- cloudConfig = cloudConfigFactory.getCloudConfig ();
LOGGER.debug("msoTenantUtils:" + msoPropID);
@@ -56,6 +53,10 @@ public abstract class MsoTenantUtils extends MsoCommonUtils {
}
}
+ public CloudConfigFactory getCloudConfigFactory() {
+ return cloudConfigFactory;
+ }
+
public abstract String createTenant (String tenantName, String cloudSiteId, Map <String, String> metadata, boolean backout)
throws MsoException;
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java
index cc9e869608..49c262268d 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java
@@ -33,18 +33,25 @@ import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
public class MsoTenantUtilsFactory {
private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
- private CloudConfigFactory cloudConfigFactory= new CloudConfigFactory();
- private CloudConfig cloudConfig;
+ private CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
private String msoPropID;
public MsoTenantUtilsFactory (String msoPropID) {
this.msoPropID = msoPropID;
}
+ public void setCloudConfigFactory(CloudConfigFactory cloudConfigFactory) {
+ this.cloudConfigFactory = cloudConfigFactory;
+ }
+
+ public CloudConfigFactory getCloudConfigFactory() {
+ return cloudConfigFactory;
+ }
+
//based on Cloud IdentityServerType returns ORM or KEYSTONE Utils
public MsoTenantUtils getTenantUtils(String cloudSiteId) throws MsoCloudSiteNotFound {
// Obtain the cloud site information
- cloudConfig = cloudConfigFactory.getCloudConfig();
+ CloudConfig cloudConfig = getCloudConfigFactory().getCloudConfig();
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
() -> new MsoCloudSiteNotFound(cloudSiteId));
return getTenantUtilsByServerType(cloudSite.getIdentityService().getIdentityServerType().toString());
@@ -54,10 +61,11 @@ public class MsoTenantUtilsFactory {
MsoTenantUtils tenantU = null;
if (CloudIdentity.IdentityServerType.KEYSTONE.toString().equals(serverType)) {
- tenantU = new MsoKeystoneUtils (msoPropID);
+ tenantU = new MsoKeystoneUtils(msoPropID, getCloudConfigFactory());
} else {
try {
- tenantU = CloudIdentity.IdentityServerType.valueOf(serverType).getMsoTenantUtilsClass().getConstructor(String.class).newInstance(msoPropID);
+ tenantU = CloudIdentity.IdentityServerType.valueOf(serverType).getMsoTenantUtilsClass()
+ .getConstructor(String.class, CloudConfigFactory.class).newInstance(msoPropID, getCloudConfigFactory());
} catch (InvocationTargetException | InstantiationException | NoSuchMethodException | IllegalAccessException e) {
throw new RuntimeException("Could not instantiate an MsoTenantUtils class for " + serverType, e);
}