From d94e70c95f4a5c7d798f15c3665eb0d838b2bf88 Mon Sep 17 00:00:00 2001 From: Radovan Zvoncek Date: Thu, 9 Apr 2015 11:48:36 +0200 Subject: [PATCH] Enable GUI headers also through reaper configuration --- README.md | 7 ++++++ .../com/spotify/reaper/ReaperApplication.java | 8 +++---- .../ReaperApplicationConfiguration.java | 24 +++++++++++++++---- src/test/resources/cassandra-reaper.yaml | 4 ++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d49bc59ed..663c6a9b4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ Current version supports running Cassandra cluster repairs in segmented manner, opportunistically running multiple parallel repairs at the same time on different nodes within the cluster. Basic repair scheduling functionality is also supported. +Cassandra Reaper does not come with a GUI, but please check +[this project](https://github.com/spodkowinski/cassandra-reaper-ui) if you'd like to use one. + Please see the [Issues](https://github.com/spotify/cassandra-reaper/issues) section for more information on planned development, and known issues. @@ -121,6 +124,10 @@ The Reaper service specific configuration values are: Optional setting for giving username and password credentials for the used JMX connections in case you are using password based JMX authentication with your Cassandra clusters. +* enableCrossOrigin: + + Optional setting which you can set to be "true", if you wish to enable the CORS headers + for running an external GUI application, like [this project](https://github.com/spodkowinski/cassandra-reaper-ui). Notice that in the *server* section of the configuration, if you want to bind the service to all interfaces, use value "0.0.0.0", or just leave the *bindHost* line away completely. diff --git a/src/main/java/com/spotify/reaper/ReaperApplication.java b/src/main/java/com/spotify/reaper/ReaperApplication.java index cc4c9431c..60bf2a0ed 100644 --- a/src/main/java/com/spotify/reaper/ReaperApplication.java +++ b/src/main/java/com/spotify/reaper/ReaperApplication.java @@ -126,10 +126,10 @@ public void run(ReaperApplicationConfiguration config, context.jmxConnectionFactory.setJmxPorts(jmxPorts); } - // enable cross-origin requests for testing cassandra-reaper-ui - if (System.getProperty("enableCrossOrigin") != null) { - final FilterRegistration.Dynamic cors = - environment.servlets().addFilter("crossOriginRequests", CrossOriginFilter.class); + // Enable cross-origin requests for using external GUI applications. + if (config.isEnableCrossOrigin() || System.getProperty("enableCrossOrigin") != null) { + final FilterRegistration.Dynamic cors = environment.servlets() + .addFilter("crossOriginRequests", CrossOriginFilter.class); cors.setInitParameter("allowedOrigins", "*"); cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin"); cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD"); diff --git a/src/main/java/com/spotify/reaper/ReaperApplicationConfiguration.java b/src/main/java/com/spotify/reaper/ReaperApplicationConfiguration.java index ddbafcada..4df3ad3df 100644 --- a/src/main/java/com/spotify/reaper/ReaperApplicationConfiguration.java +++ b/src/main/java/com/spotify/reaper/ReaperApplicationConfiguration.java @@ -55,6 +55,8 @@ public class ReaperApplicationConfiguration extends Configuration { @NotEmpty private String storageType; + private String enableCrossOrigin; + @Valid @NotNull @JsonProperty @@ -62,7 +64,7 @@ public class ReaperApplicationConfiguration extends Configuration { @JsonProperty private Map jmxPorts; - + @JsonProperty private JmxCredentials jmxAuth; @@ -103,6 +105,18 @@ public String getStorageType() { return storageType; } + public void setEnableCrossOrigin(String enableCrossOrigin) { + this.enableCrossOrigin = enableCrossOrigin; + } + + public String getEnableCrossOrigin() { + return this.enableCrossOrigin; + } + + public boolean isEnableCrossOrigin() { + return this.enableCrossOrigin != null && this.enableCrossOrigin.equalsIgnoreCase("true"); + } + public void setStorageType(String storageType) { this.storageType = storageType; } @@ -139,21 +153,21 @@ public JmxCredentials getJmxAuth() { public void setJmxAuth(JmxCredentials jmxAuth) { this.jmxAuth = jmxAuth; } - + public static class JmxCredentials { - + @JsonProperty private String username; @JsonProperty private String password; - + public String getUsername() { return username; } public String getPassword() { return password; } - + } } diff --git a/src/test/resources/cassandra-reaper.yaml b/src/test/resources/cassandra-reaper.yaml index e028c8f31..41702e47a 100644 --- a/src/test/resources/cassandra-reaper.yaml +++ b/src/test/resources/cassandra-reaper.yaml @@ -17,6 +17,10 @@ hangingRepairTimeoutMins: 30 # storageType is either "database" or "memory" storageType: memory +# Enable HTTP headers to that GUI can work +# GUI lives at https://github.com/spodkowinski/cassandra-reaper-ui +enableCrossOrigin: true + # custom jmx port mappings that will be used instead of the default port for specified hosts (optional) #jmxPorts: # 127.0.0.1: 7100