diff options
author | 2018-03-07 10:18:39 +0100 | |
---|---|---|
committer | 2018-03-12 13:42:34 +0100 | |
commit | f546e4acc2cc81f734f3b0160069b3e48b9c5be3 (patch) | |
tree | aefc0e4c34e847d5e9d523272dce251f4b3015e8 /adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java | |
parent | 4370cf4eefb3de99b5eff870f90637931e9759e1 (diff) |
junit adding and refactor for CloudConfig
Change-Id: I3b98e6f8633347970be70e7b93680ec8ed4daacc
Issue-ID: SO-430
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java')
-rw-r--r-- | adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java | 60 |
1 files changed, 16 insertions, 44 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 445c135dab..144506c3bd 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 @@ -20,12 +20,10 @@ package org.openecomp.mso.cloud; - import java.io.IOException; import java.io.Serializable; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantReadWriteLock; - import javax.ejb.ConcurrencyManagement; import javax.ejb.ConcurrencyManagementType; import javax.ejb.LocalBean; @@ -36,22 +34,17 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; - import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; - +import org.openecomp.mso.logger.MessageEnum; import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; import org.openecomp.mso.openstack.utils.MsoHeatUtils; import org.openecomp.mso.openstack.utils.MsoKeystoneUtils; import org.openecomp.mso.openstack.utils.MsoNeutronUtils; -import org.openecomp.mso.properties.MsoPropertiesException; -import org.openecomp.mso.logger.MessageEnum; /** * This class returns a cloud Config instances - * - * */ @Singleton(name = "CloudConfigFactory") @@ -62,13 +55,13 @@ public class CloudConfigFactory implements Serializable { private static final long serialVersionUID = 2956662716453261085L; - private static CloudConfig cloudConfigCache = new CloudConfig (); + private CloudConfig cloudConfigCache = new CloudConfig(); protected static String prefixMsoPropertiesPath = System.getProperty ("mso.config.path"); private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); - private static int refreshTimer; + private int refreshTimer; private static final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock (); @@ -79,7 +72,6 @@ public class CloudConfigFactory implements Serializable { } public void initializeCloudConfig (String filePath, int refreshTimer) throws MsoCloudIdentityNotFound { - rwl.writeLock ().lock (); try { cloudConfigCache.loadCloudConfig (prefixMsoPropertiesPath + filePath, refreshTimer); @@ -95,18 +87,6 @@ public class CloudConfigFactory implements Serializable { } } - public void changeMsoPropertiesFilePath (String newMsoPropPath) { - rwl.writeLock ().lock (); - try { - CloudConfigFactory.cloudConfigCache.configFilePath = prefixMsoPropertiesPath + newMsoPropPath; - } finally { - rwl.writeLock ().unlock (); - } - } - - public CloudConfigFactory () { - } - public CloudConfig getCloudConfig () { rwl.readLock ().lock (); try { @@ -127,7 +107,7 @@ public class CloudConfigFactory implements Serializable { * @return true if Properties have been reloaded, false otherwise */ @Schedule(minute = "*/1", hour = "*", persistent = false) - public static void reloadCloudConfig () { + public void reloadCloudConfig () { try { if (!rwl.writeLock ().tryLock () && !rwl.writeLock ().tryLock (30L, TimeUnit.SECONDS)) { @@ -180,23 +160,17 @@ public class CloudConfigFactory implements Serializable { @Path("/showConfig") @Produces("text/plain") public Response showCloudConfig () { - CloudConfig cloudConfig = this.getCloudConfig (); - if (cloudConfig != null) { - StringBuffer response = new StringBuffer (); - response.append ("Cloud Sites:\n"); - for (CloudSite site : cloudConfig.getCloudSites ().values ()) { - response.append(site.toString()).append("\n"); - } - - response.append ("\n\nCloud Identity Services:\n"); - for (CloudIdentity identity : cloudConfig.getIdentityServices ().values ()) { - response.append(identity.toString()).append("\n"); - } - - return Response.status (200).entity (response).build (); - } else { - return Response.status (500).entity ("Cloud Config has not been loaded properly, this could be due to a bad JSON structure (Check the logs for additional details)").build (); + CloudConfig cloudConfig = this.getCloudConfig(); + StringBuffer response = new StringBuffer(); + response.append("Cloud Sites:\n"); + for (CloudSite site : cloudConfig.getCloudSites().values()) { + response.append(site.toString()).append("\n"); + } + response.append("\n\nCloud Identity Services:\n"); + for (CloudIdentity identity : cloudConfig.getIdentityServices().values()) { + response.append(identity.toString()).append("\n"); } + return Response.status(200).entity(response).build(); } @GET @@ -207,8 +181,7 @@ public class CloudConfigFactory implements Serializable { MsoKeystoneUtils.adminCacheReset (); MsoHeatUtils.heatCacheReset (); MsoNeutronUtils.neutronCacheReset (); - - String response = "Client caches reset. All entries removed."; + String response = "Client caches reset. All entries removed."; return Response.status (200).entity (response).build (); } @@ -220,8 +193,7 @@ public class CloudConfigFactory implements Serializable { MsoKeystoneUtils.adminCacheCleanup (); MsoHeatUtils.heatCacheCleanup (); MsoNeutronUtils.neutronCacheCleanup (); - - String response = "Client caches cleaned up. All expired entries removed"; + String response = "Client caches cleaned up. All expired entries removed."; return Response.status (200).entity (response).build (); } |