Skip to content
Browse files

added system configuration retrieval

  • Loading branch information...
1 parent 60ba150 commit 90b98c5bb1fb6c820f28e0069ef0d098149ef301 @ddossot ddossot committed Oct 24, 2011
View
18 src/it/java/eu/openanalytics/rsb/RestAdminITCase.java
@@ -21,8 +21,11 @@
package eu.openanalytics.rsb;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.StringReader;
@@ -33,7 +36,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
-import org.junit.Ignore;
import org.junit.Test;
import com.meterware.httpunit.GetMethodWebRequest;
@@ -44,6 +46,7 @@
import com.meterware.httpunit.WebResponse;
import eu.openanalytics.rsb.config.Configuration;
+import eu.openanalytics.rsb.config.PersistedConfiguration;
import eu.openanalytics.rsb.rest.types.Catalog;
import eu.openanalytics.rsb.rest.types.CatalogDirectory;
import eu.openanalytics.rsb.rest.types.CatalogFileType;
@@ -52,12 +55,19 @@
* @author "OpenAnalytics <rsb.development@openanalytics.eu>"
*/
public class RestAdminITCase extends AbstractITCase {
- // FIXME reactivate
- @Ignore
+ @Test
+ public void getSystemConfiguration() throws Exception {
+ final WebConversation wc = new WebConversation();
+ final WebRequest request = new GetMethodWebRequest(RSB_BASE_URI + "/api/rest/admin/system/configuration");
+ final WebResponse response = wc.sendRequest(request);
+ assertEquals(200, response.getResponseCode());
+ assertThat(Util.fromJson(response.getText(), PersistedConfiguration.class), is(instanceOf(PersistedConfiguration.class)));
+ }
+
@Test
public void restart() throws Exception {
final WebConversation wc = new WebConversation();
- final WebRequest request = new PostMethodWebRequest(RSB_BASE_URI + "/api/rest/admin/restart");
+ final WebRequest request = new PostMethodWebRequest(RSB_BASE_URI + "/api/rest/admin/system/restart");
final WebResponse response = wc.sendRequest(request);
assertEquals(200, response.getResponseCode());
assertEquals("RESTARTED", response.getText());
View
12 src/main/java/eu/openanalytics/rsb/component/AdminResource.java
@@ -56,6 +56,7 @@
import eu.openanalytics.rsb.Constants;
import eu.openanalytics.rsb.Util;
import eu.openanalytics.rsb.config.Configuration;
+import eu.openanalytics.rsb.config.PersistedConfiguration;
import eu.openanalytics.rsb.cxf.ReloadableCXFServlet;
import eu.openanalytics.rsb.rest.types.Catalog;
import eu.openanalytics.rsb.rest.types.CatalogDirectory;
@@ -69,13 +70,22 @@
public class AdminResource extends AbstractComponent implements ApplicationContextAware {
private static final String CATALOG_SUBPATH = "catalog";
+ private static final String SYSTEM_SUBPATH = "system";
+
private ConfigurableApplicationContext applicationContext;
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
this.applicationContext = (ConfigurableApplicationContext) applicationContext;
}
- @Path("/restart")
+ @Path("/" + SYSTEM_SUBPATH + "/configuration")
+ @GET
+ @Produces({ Constants.JSON_CONTENT_TYPE })
+ public Response getSystemConfiguration() {
+ return Response.ok(Util.toJson(new PersistedConfiguration(getConfiguration()))).build();
+ }
+
+ @Path("/" + SYSTEM_SUBPATH + "/restart")
@POST
@Produces({ Constants.TEXT_CONTENT_TYPE })
public Response restart() {
View
27 src/main/java/eu/openanalytics/rsb/config/PersistedConfiguration.java
@@ -283,6 +283,29 @@ public void setJobConfigurationFileName(final String jobConfigurationFileName) {
private List<PersistedDepositEmailConfiguration> depositEmailAccounts;
private List<File> dataDirectories;
+ public PersistedConfiguration() {
+ // NOOP
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public PersistedConfiguration(final Configuration configuration) {
+ setActiveMqWorkDirectory(configuration.getActiveMqWorkDirectory());
+ setAdministratorEmail(configuration.getAdministratorEmail());
+ setApplicationSpecificRserviPoolUris(configuration.getApplicationSpecificRserviPoolUris());
+ setCatalogRootDirectory(configuration.getRScriptsCatalogDirectory().getParentFile());
+ setDataDirectories(configuration.getDataDirectories());
+ setDefaultRserviPoolUri(configuration.getDefaultRserviPoolUri());
+ setDepositEmailAccounts((List) configuration.getDepositEmailAccounts());
+ setDepositRootDirectories((List) configuration.getDepositRootDirectories());
+ setJmxConfiguration((PersistedJmxConfiguration) configuration.getJmxConfiguration());
+ setJobStatisticsHandlerConfiguration((PersistedJobStatisticsHandlerConfiguration) configuration
+ .getJobStatisticsHandlerConfiguration());
+ setJobTimeOut(configuration.getJobTimeOut());
+ setNumberOfConcurrentJobWorkersPerQueue(configuration.getNumberOfConcurrentJobWorkersPerQueue());
+ setResultsDirectory(configuration.getResultsDirectory());
+ setSmtpConfiguration((PersistedSmtpConfiguration) configuration.getSmtpConfiguration());
+ }
+
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
@@ -293,8 +316,8 @@ public String toString() {
* <ul>
* <li>{@link eu.openanalytics.rsb.config.Configuration#R_SCRIPTS_CATALOG_SUBDIR}: catalog of R scripts</li>
* <li>{@link eu.openanalytics.rsb.config.Configuration#SWEAVE_FILES_CATALOG_SUBDIR}: catalog of Sweave files</li>
- * <li>{@link eu.openanalytics.rsb.config.Configuration#JOB_CONFIGURATIONS_CATALOG_SUBDIR}: catalog of ready made job
- * configurations</li>
+ * <li>{@link eu.openanalytics.rsb.config.Configuration#JOB_CONFIGURATIONS_CATALOG_SUBDIR}: catalog of ready made
+ * job configurations</li>
* <li>{@link eu.openanalytics.rsb.config.Configuration#EMAIL_REPLIES_CATALOG_SUBDIR}: catalog of Email replies</li>
* </ul>
* If any of these sub-directories do not pre-exist, RSB will try to create it.
View
19 src/main/java/eu/openanalytics/rsb/config/PersistedConfigurationAdapter.java
@@ -39,25 +39,10 @@
* @author "OpenAnalytics &lt;rsb.development@openanalytics.eu&gt;"
*/
public class PersistedConfigurationAdapter implements Configuration {
- private static final class DefaultJmxRmiConfiguration implements JmxConfiguration {
- private static final long serialVersionUID = 1L;
-
- public int getStubPort() {
- return 9098;
- }
-
- public int getRegistryPort() {
- return 9099;
- }
-
- public int getHttpPort() {
- return 8889;
- }
- }
-
private static final long serialVersionUID = 1L;
- public static final JmxConfiguration DEFAULT_JMX_RMI_CONFIGURATION = new DefaultJmxRmiConfiguration();
+ public static final JmxConfiguration DEFAULT_JMX_RMI_CONFIGURATION = new PersistedConfiguration.PersistedJmxConfiguration(9098, 9099,
+ 8889);
private final PersistedConfiguration persistedConfiguration;
private final URL configurationUrl;
View
13 src/test/java/eu/openanalytics/rsb/component/AdminResourceTestCase.java
@@ -21,6 +21,7 @@
package eu.openanalytics.rsb.component;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -44,7 +45,10 @@
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.context.ConfigurableApplicationContext;
+import eu.openanalytics.rsb.Util;
import eu.openanalytics.rsb.config.Configuration;
+import eu.openanalytics.rsb.config.ConfigurationFactory;
+import eu.openanalytics.rsb.config.PersistedConfiguration;
import eu.openanalytics.rsb.rest.types.Catalog;
/**
@@ -72,6 +76,15 @@ public void prepareTest() throws UnknownHostException {
}
@Test
+ public void getSystemConfiguration() throws Exception {
+ adminResource.setConfiguration(ConfigurationFactory.loadJsonConfiguration());
+ final Response response = adminResource.getSystemConfiguration();
+ assertThat(response.getStatus(), is(200));
+ assertThat(Util.fromJson(response.getEntity().toString(), PersistedConfiguration.class),
+ is(instanceOf(PersistedConfiguration.class)));
+ }
+
+ @Test
public void restart() throws Exception {
final Response response = adminResource.restart();
assertThat(response.getStatus(), is(200));

0 comments on commit 90b98c5

Please sign in to comment.
Something went wrong with that request. Please try again.