incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1213324 - in /incubator/ambari/trunk: controller/src/main/java/org/apache/ambari/configuration/ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/java/org/apache/ambari/datastore/ controller/src/test/java/org/apach...
Date Mon, 12 Dec 2011 17:21:56 GMT
Author: omalley
Date: Mon Dec 12 17:21:56 2011
New Revision: 1213324

URL: http://svn.apache.org/viewvc?rev=1213324&view=rev
Log:
AMBARI-153. More updates to the configuration.

Added:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/configuration/Configuration.java
Removed:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/configuration/ConfigurationModule.java
    incubator/ambari/trunk/src/site/resources/application.html
    incubator/ambari/trunk/src/site/resources/schema1.xsd
Modified:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/datastore/DataStoreFactory.java
    incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java

Added: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/configuration/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/configuration/Configuration.java?rev=1213324&view=auto
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/configuration/Configuration.java
(added)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/configuration/Configuration.java
Mon Dec 12 17:21:56 2011
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.configuration;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.google.inject.Inject;
+
+/**
+ * Ambari configuration.
+ * Reads properties from ambari.properties
+ */
+public class Configuration {
+  private static final String AMBARI_CONF_VAR = "AMBARI_CONF_DIR";
+  private static final String CONFIG_FILE = "ambari.properties";
+  
+  private static final Log LOG = LogFactory.getLog(Configuration.class);
+  
+  private final URI dataStore;
+  
+  @Inject
+  Configuration() {
+    this(readConfigFile());
+  }
+  
+  protected Configuration(Properties properties) {
+    // get the data store
+    String dataStoreString = properties.getProperty("data.store", 
+                                                    "zk://localhost:2181/");
+    try {
+      dataStore = new URI(dataStoreString);
+    } catch (URISyntaxException e) {
+      throw new IllegalArgumentException("Can't parse data.store: " + 
+                                         dataStoreString, e);
+    }    
+  }
+  
+  /**
+   * Find, read, and parse the configuration file.
+   * @return the properties that were found or empty if no file was found
+   */
+  private static Properties readConfigFile() {
+    Properties properties = new Properties();
+
+    // get the configuration directory and filename
+    String confDir = System.getenv(AMBARI_CONF_VAR);
+    if (confDir == null) {
+      confDir = "/etc/ambari";
+    }
+    String filename = confDir + "/" + CONFIG_FILE;
+    
+    // load the properties
+    try {
+      properties.load(new FileInputStream(filename));
+    } catch (FileNotFoundException fnf) {
+      LOG.info("No configuration file " + filename + " found.", fnf);
+    } catch (IOException ie) {
+      throw new IllegalArgumentException("Can't read configuration file " + 
+                                         filename, ie);
+    }
+    return properties;  
+  }
+
+  /**
+   * Get the URI for the persistent data store.
+   * @return the data store URI
+   */
+  public URI getDataStore() {
+    return dataStore;
+  }
+}

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java?rev=1213324&r1=1213323&r2=1213324&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Controller.java
Mon Dec 12 17:21:56 2011
@@ -26,7 +26,6 @@ import org.apache.commons.logging.LogFac
 
 import org.apache.ambari.common.util.DaemonWatcher;
 import org.apache.ambari.common.util.ExceptionUtil;
-import org.apache.ambari.configuration.ConfigurationModule;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.security.Constraint;
 import org.mortbay.jetty.security.ConstraintMapping;
@@ -120,8 +119,7 @@ public class Controller {
   }
 
   public static void main(String[] args) throws IOException {
-    Injector injector = Guice.createInjector(new ConfigurationModule(),
-                                             new ControllerModule());
+    Injector injector = Guice.createInjector(new ControllerModule());
     DaemonWatcher.createInstance(System.getProperty("PID"), 9100);
     try {
       Controller controller = injector.getInstance(Controller.class);

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/datastore/DataStoreFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/datastore/DataStoreFactory.java?rev=1213324&r1=1213323&r2=1213324&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/datastore/DataStoreFactory.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/datastore/DataStoreFactory.java
Mon Dec 12 17:21:56 2011
@@ -19,24 +19,18 @@ package org.apache.ambari.datastore;
 
 import java.io.IOException;
 import java.net.URI;
-import java.net.URISyntaxException;
 
+import org.apache.ambari.configuration.Configuration;
 
 import com.google.inject.Inject;
-import com.google.inject.name.Named;
 
 public class DataStoreFactory {
 
   private final DataStore ds;
   
   @Inject
-  DataStoreFactory(@Named("data.store") String dataStore) throws IOException {
-    URI uri;
-    try {
-      uri = new URI(dataStore);
-    } catch (URISyntaxException e) {
-      throw new IllegalArgumentException("Bad data store URI: " + dataStore, e);
-    }
+  DataStoreFactory(Configuration conf) throws IOException {
+    URI uri = conf.getDataStore();
     String scheme = uri.getScheme();
     if ("zk".equals(scheme)) {
       String auth = uri.getAuthority();

Modified: incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java?rev=1213324&r1=1213323&r2=1213324&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java
(original)
+++ incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java
Mon Dec 12 17:21:56 2011
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import org.apache.ambari.common.rest.agent.Action;
 import org.apache.ambari.common.rest.agent.Action.Kind;
@@ -39,6 +40,7 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.Node;
 import org.apache.ambari.common.rest.entities.NodeState;
 import org.apache.ambari.components.ComponentPlugin;
+import org.apache.ambari.configuration.Configuration;
 import org.apache.ambari.controller.HeartbeatHandler.ClusterNameAndRev;
 import org.apache.ambari.controller.HeartbeatHandler.SpecialServiceIDs;
 import org.apache.ambari.event.EventHandler;
@@ -58,7 +60,6 @@ import org.testng.annotations.Test;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.name.Names;
 
 public class TestHeartbeat {
   
@@ -77,11 +78,21 @@ public class TestHeartbeat {
   final String script = "script-content";
   final int scriptHash = script.hashCode();
   
-  class TestModule extends ControllerModule {
+  private static class TestConfiguration extends Configuration {
+    TestConfiguration() {
+      super(getProperties());
+    }
+    private static Properties getProperties() {
+      Properties props = new Properties();
+      props.setProperty("data.store", "test:/");
+      return props;
+    }
+  }
+  private static class TestModule extends ControllerModule {
     @Override
     protected void configure() {
       super.configure();
-      bindConstant().annotatedWith(Names.named("data.store")).to("test:/");
+      bind(Configuration.class).to(TestConfiguration.class);
       bind(FSMDriverInterface.class).to(TestFSMDriverImpl.class);
     }
   }



Mime
View raw message