Merge "Reorder modifiers"
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / cloud / CloudConfigFactory.java
index 2d6d027..2b38591 100644 (file)
 
 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;
@@ -37,21 +35,18 @@ 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;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
 
 /**
  * This class returns a cloud Config instances
- *
- *
  */
 
 @Singleton(name = "CloudConfigFactory")
@@ -62,7 +57,7 @@ public class CloudConfigFactory implements Serializable {
 
     private static final long serialVersionUID = 2956662716453261085L;
 
-    private static CloudConfig cloudConfigCache = new CloudConfig ();
+    private static CloudConfig cloudConfigCache = new CloudConfig();
 
     protected static String prefixMsoPropertiesPath = System.getProperty ("mso.config.path");
 
@@ -77,9 +72,8 @@ public class CloudConfigFactory implements Serializable {
             prefixMsoPropertiesPath = "";
         }
     }
-
+    
     public void initializeCloudConfig (String filePath, int refreshTimer) throws MsoCloudIdentityNotFound {
-
         rwl.writeLock ().lock ();
         try {
             cloudConfigCache.loadCloudConfig (prefixMsoPropertiesPath + filePath, refreshTimer);
@@ -95,26 +89,14 @@ 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 {
-            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 ();
         }
@@ -123,8 +105,6 @@ public class CloudConfigFactory implements Serializable {
     /**
      * This method is not intended to be called, it's used to refresh the config
      * automatically
-     *
-     * @return true if Properties have been reloaded, false otherwise
      */
     @Schedule(minute = "*/1", hour = "*", persistent = false)
     public void reloadCloudConfig () {
@@ -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 ();
     }