changeset 562:faa61b45ba32

Remove and refactor db options review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-August/002883.html reviewed-by: jerboaa
author Mario Torre <neugens.limasoftware@gmail.com>
date Wed, 22 Aug 2012 19:23:39 +0200
parents 995b2dd560b0
children 51f768003f10
files agent/cli/src/main/java/com/redhat/thermostat/agent/cli/StorageCommand.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBConfig.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBOptionParser.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBStartupConfiguration.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/MongoProcessRunner.java agent/cli/src/test/java/com/redhat/thermostat/agent/cli/DBServiceTest.java distribution/config/db.properties
diffstat 7 files changed, 33 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/StorageCommand.java	Wed Aug 22 19:22:52 2012 +0200
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/StorageCommand.java	Wed Aug 22 19:23:39 2012 +0200
@@ -133,27 +133,19 @@
             throw new InvalidConfigurationException(e);
         }
         
-        if (properties.containsKey(DBConfig.LOCAL.name())) {
-            String port = (String) properties.get(DBConfig.LOCAL.name());
+        if (properties.containsKey(DBConfig.PORT.name())) {
+            String port = (String) properties.get(DBConfig.PORT.name());
             int localPort = Integer.parseInt(port);
-            configuration.setLocalPort(localPort);
+            configuration.setPort(localPort);
         } else {
-            throw new InvalidConfigurationException(DBConfig.LOCAL + " property missing");
+            throw new InvalidConfigurationException(DBConfig.PORT + " property missing");
         }
         
-        if (properties.containsKey(DBConfig.CLUSTER.name())) {
-            String port = (String) properties.get(DBConfig.CLUSTER.name());
-            int localPort = Integer.parseInt(port);
-            configuration.setClusterPort(localPort);
+        if (properties.containsKey(DBConfig.PROTOCOL.name())) {
+            String url = (String) properties.get(DBConfig.PROTOCOL.name());
+            configuration.setProtocol(url);
         } else {
-            throw new InvalidConfigurationException(DBConfig.CLUSTER + " property missing");
-        }
-        
-        if (properties.containsKey(DBConfig.URL.name())) {
-            String url = (String) properties.get(DBConfig.URL.name());
-            configuration.setUrl(url);
-        } else {
-            throw new InvalidConfigurationException(DBConfig.URL + " property missing");
+            throw new InvalidConfigurationException(DBConfig.PROTOCOL + " property missing");
         }
         
         if (properties.containsKey(DBConfig.BIND.name())) {
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBConfig.java	Wed Aug 22 19:22:52 2012 +0200
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBConfig.java	Wed Aug 22 19:23:39 2012 +0200
@@ -44,7 +44,6 @@
 public enum DBConfig {
 
     BIND,
-    LOCAL,
-    CLUSTER,
-    URL,
+    PORT,
+    PROTOCOL,
 }
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBOptionParser.java	Wed Aug 22 19:22:52 2012 +0200
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBOptionParser.java	Wed Aug 22 19:23:39 2012 +0200
@@ -85,14 +85,10 @@
         }
         
         // leave at the end, since it depends on the previous settings
-        String url = configuration.getUrl();
-        long port = configuration.getLocalPort();
-        configuration.setLocal(true);
-        if (args.hasArgument(DBArgs.CLUSTER.option)) {
-            port = configuration.getClusterPort();
-            configuration.setLocal(false);
-        }
-        configuration.setDBConnectionString(url + ":" + port);
+        String urlPrefix = configuration.getProtocol();
+        String address = configuration.getBindIP();
+        long port = configuration.getPort();
+        configuration.setDBConnectionString(urlPrefix + "://" + address + ":" + port);
     }
 
     public boolean isDryRun() {
@@ -104,8 +100,6 @@
     }
 
     static enum DBArgs {
-                        
-        CLUSTER("cluster", Translate.localize(LocaleResources.COMMAND_STORAGE_ARGUMENT_CLUSTER_DESCRIPTION), ApplicationState.NONE),
                 
         DRY("dryRun", Translate.localize(LocaleResources.COMMAND_STORAGE_ARGUMENT_DRYRUN_DESCRIPTION), ApplicationState.NONE),
         
@@ -132,11 +126,10 @@
     }
 
     public static Collection<ArgumentSpec> getAcceptedArguments() {
-        ArgumentSpec cluster = new SimpleArgumentSpec(DBArgs.CLUSTER.option, "c", DBArgs.CLUSTER.description, false, false);
         ArgumentSpec dryRun = new SimpleArgumentSpec(DBArgs.DRY.option, "d", DBArgs.DRY.description, false, false);
         ArgumentSpec start = new SimpleArgumentSpec(DBArgs.START.option, DBArgs.START.description);
         ArgumentSpec stop = new SimpleArgumentSpec(DBArgs.STOP.option, DBArgs.STOP.description);
         ArgumentSpec quiet = new SimpleArgumentSpec(DBArgs.QUIET.option, "q", DBArgs.QUIET.description, false, false);
-        return Arrays.asList(cluster, dryRun, start, stop, quiet);
+        return Arrays.asList(dryRun, start, stop, quiet);
     }
 }
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBStartupConfiguration.java	Wed Aug 22 19:22:52 2012 +0200
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/DBStartupConfiguration.java	Wed Aug 22 19:23:39 2012 +0200
@@ -49,16 +49,13 @@
     private File pidFile;
         
     private long localPort;
-    private long clusterPort;
     
-    private String url;
+    private String protocol;
     
     private String dbConnectionString;
     
     private String ip;
-    
-    private boolean local;
-    
+        
     public DBStartupConfiguration() throws InvalidConfigurationException {
         dbPath = ConfigUtils.getStorageDirectory();
         logFile = ConfigUtils.getStorageLogFile();
@@ -77,28 +74,20 @@
         return pidFile;
     }
    
-    public void setLocalPort(long localPort) {
+    public void setPort(long localPort) {
         this.localPort = localPort;
     }
     
-    public long getLocalPort() {
+    public long getPort() {
         return localPort;
     }
     
-    public long getClusterPort() {
-        return clusterPort;
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
     }
     
-    public void setClusterPort(long clusterPort) {
-        this.clusterPort = clusterPort;
-    }
-    
-    public void setUrl(String url) {
-        this.url = url;
-    }
-    
-    public String getUrl() {
-        return url;
+    public String getProtocol() {
+        return protocol;
     }
     
     void setDBConnectionString(String dbConnectionString) {
@@ -117,12 +106,4 @@
     public String getBindIP() {
         return ip;
     }
-    
-    void setLocal(boolean local) {
-        this.local = local;
-    }
-    
-    public boolean isLocal() {
-        return local;
-    }
 }
\ No newline at end of file
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/MongoProcessRunner.java	Wed Aug 22 19:22:52 2012 +0200
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/MongoProcessRunner.java	Wed Aug 22 19:23:39 2012 +0200
@@ -173,11 +173,7 @@
         commands.add(configuration.getPidFile().getCanonicalPath());
 
         commands.add("--port");
-        if (configuration.isLocal()) {
-            commands.add(Long.toString(configuration.getLocalPort()));
-        } else {
-            commands.add(Long.toString(configuration.getClusterPort()));
-        }
+        commands.add(Long.toString(configuration.getPort()));
         
         LoggedExternalProcess process = new LoggedExternalProcess(commands);
         int status = -1;
--- a/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/DBServiceTest.java	Wed Aug 22 19:22:52 2012 +0200
+++ b/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/DBServiceTest.java	Wed Aug 22 19:23:39 2012 +0200
@@ -73,12 +73,9 @@
 
 public class DBServiceTest {
     
-    private static final String LOCAL = "27518";
-    private static final String CLUSTER = "27517";
-    
+    private static final String PORT = "27518";
     private static final String BIND = "127.0.0.1";
-    
-    private static final String URL = "mongodb://127.0.0.1";
+    private static final String PROTOCOL = "mongodb";
     private static final String DB = "storage/db";
 
     private String tmpDir;
@@ -105,9 +102,8 @@
             Properties props = new Properties();
             
             props.setProperty(DBConfig.BIND.name(), BIND);
-            props.setProperty(DBConfig.LOCAL.name(), LOCAL);
-            props.setProperty(DBConfig.CLUSTER.name(), CLUSTER);
-            props.setProperty(DBConfig.URL.name(), URL);
+            props.setProperty(DBConfig.PORT.name(), PORT);
+            props.setProperty(DBConfig.PROTOCOL.name(), PROTOCOL);
 
             props.store(new FileOutputStream(tmpConfigs), "thermostat test properties");
             
@@ -137,9 +133,8 @@
         DBStartupConfiguration conf = service.getConfiguration();
         
         Assert.assertEquals(tmpDir + DB, conf.getDBPath().getPath());
-        Assert.assertEquals(Integer.parseInt(LOCAL), conf.getLocalPort());
-        Assert.assertEquals(Integer.parseInt(CLUSTER), conf.getClusterPort());
-        Assert.assertEquals(URL, conf.getUrl());
+        Assert.assertEquals(Integer.parseInt(PORT), conf.getPort());
+        Assert.assertEquals(PROTOCOL, conf.getProtocol());
     }
     
     private StorageCommand prepareService(boolean startSuccess) throws IOException,
@@ -265,8 +260,7 @@
         StorageCommand dbService = new StorageCommand();
         Collection<ArgumentSpec> args = dbService.getAcceptedArguments();
         assertNotNull(args);
-        assertEquals(5, args.size());
-        assertTrue(args.contains(new SimpleArgumentSpec("cluster", "c", "launch the db in cluster mode, if not specified, local mode is the default", false, false)));
+        assertEquals(4, args.size());
         assertTrue(args.contains(new SimpleArgumentSpec("dryRun", "d", "run the service in dry run mode", false, false)));
         assertTrue(args.contains(new SimpleArgumentSpec("start", "start the database")));
         assertTrue(args.contains(new SimpleArgumentSpec("stop", "stop the database")));
--- a/distribution/config/db.properties	Wed Aug 22 19:22:52 2012 +0200
+++ b/distribution/config/db.properties	Wed Aug 22 19:23:39 2012 +0200
@@ -1,4 +1,3 @@
-LOCAL=27518
-CLUSTER=27517
+PORT=27518
 BIND=127.0.0.1
-URL=mongodb\://127.0.0.1
+PROTOCOL=mongodb