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;
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")
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");
prefixMsoPropertiesPath = "";
}
}
-
+
public void initializeCloudConfig (String filePath, int refreshTimer) throws MsoCloudIdentityNotFound {
-
rwl.writeLock ().lock ();
try {
cloudConfigCache.loadCloudConfig (prefixMsoPropertiesPath + filePath, refreshTimer);
}
}
- 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 ();
}
/**
* 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 () {
@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
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 ();
}
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 ();
}