You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2013/02/04 03:24:02 UTC

svn commit: r1442010 [10/29] - in /incubator/ambari/branches/branch-1.2: ./ ambari-agent/ ambari-agent/conf/unix/ ambari-agent/src/examples/ ambari-agent/src/main/puppet/modules/hdp-ganglia/files/ ambari-agent/src/main/puppet/modules/hdp-ganglia/manife...

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/Register.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/Register.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/Register.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/Register.java Mon Feb  4 02:23:55 2013
@@ -31,6 +31,7 @@ public class Register {
   private String hostname;
   private HostInfo hardwareProfile;
   private String publicHostname;
+  private AgentEnv agentEnv;
 
   @JsonProperty("responseId")
   public int getResponseId() {
@@ -50,22 +51,22 @@ public class Register {
     return hostname;
   }
   
-  public HostInfo getHardwareProfile() {
-    return hardwareProfile;
-  }
-
-  public void setTimestamp(long timestamp) {
-    this.timestamp = timestamp;
-  }
-
   public void setHostname(String hostname) {
     this.hostname = hostname;
   }
-
+  
+  public HostInfo getHardwareProfile() {
+    return hardwareProfile;
+  }
+  
   public void setHardwareProfile(HostInfo hardwareProfile) {
     this.hardwareProfile = hardwareProfile;
   }
   
+  public void setTimestamp(long timestamp) {
+    this.timestamp = timestamp;
+  }
+
   public String getPublicHostname() {
     return publicHostname;
   }
@@ -73,6 +74,14 @@ public class Register {
   public void setPublicHostname(String name) {
     publicHostname = name;
   }
+  
+  public AgentEnv getAgentEnv() {
+    return agentEnv;
+  }
+  
+  public void setAgentEnv(AgentEnv env) {
+    agentEnv = env;
+  }
 
   @Override
   public String toString() {

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/agent/StatusCommand.java Mon Feb  4 02:23:55 2013
@@ -18,6 +18,7 @@
 package org.apache.ambari.server.agent;
 
 import java.util.List;
+import java.util.Map;
 
 import org.codehaus.jackson.annotate.JsonProperty;
 
@@ -33,6 +34,7 @@ public class StatusCommand extends Agent
   private String clusterName;
   private String serviceName;
   private String componentName;
+  private Map<String, Map<String, String>> configurations;
 
   @JsonProperty("clusterName")
   public String getClusterName() {
@@ -63,4 +65,14 @@ public class StatusCommand extends Agent
   public void setComponentName(String componentName) {
     this.componentName = componentName;
   }
+  
+  @JsonProperty("configurations")
+  public Map<String, Map<String, String>> getConfigurations() {
+    return configurations;
+  }
+
+  @JsonProperty("configurations")
+  public void setConfigurations(Map<String, Map<String, String>> configurations) {
+    this.configurations = configurations;
+  }
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java Mon Feb  4 02:23:55 2013
@@ -147,6 +147,11 @@ public class QueryImpl implements Query 
       m_mapSubResources.putAll(m_resource.getSubResources());
     }
 
+    if (LOG.isInfoEnabled()) {
+      //todo: include predicate info.  Need to implement toString for all predicates.
+      LOG.info("Executing resource query: " + m_resource.getIds());
+    }
+
     Predicate predicate = createPredicate(m_resource);
     Iterable<Resource> iterResource = getClusterController().getResources(
         resourceType, createRequest(), predicate);
@@ -157,7 +162,7 @@ public class QueryImpl implements Query 
       // add a child node for the resource and provide a unique name.  The name is never used.
       //todo: provide a more meaningful node name
       TreeNode<Resource> node = tree.addChild(resource, resource.getType() + ":" + count++);
-       for (Map.Entry<String, ResourceInstance> entry : m_mapSubResources.entrySet()) {
+      for (Map.Entry<String, ResourceInstance> entry : m_mapSubResources.entrySet()) {
         String subResCategory = entry.getKey();
         ResourceInstance r = entry.getValue();
 

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceImpl.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceImpl.java Mon Feb  4 02:23:55 2013
@@ -139,7 +139,7 @@ public class ResourceInstanceImpl implem
     ResourceInstanceImpl that = (ResourceInstanceImpl) o;
 
     return m_mapResourceIds.equals(that.m_mapResourceIds) &&
-           m_query.equals(that.m_query) &&
+           m_query == that.m_query &&
            m_resourceDefinition.equals(that.m_resourceDefinition) &&
            m_mapSubResources == null ? that.m_mapSubResources == null :
                m_mapSubResources.equals(that.m_mapSubResources);
@@ -147,7 +147,7 @@ public class ResourceInstanceImpl implem
 
   @Override
   public int hashCode() {
-    int result =m_query.hashCode();
+    int result = 13;
     result = 31 * result + m_mapResourceIds.hashCode();
     result = 31 * result + m_resourceDefinition.hashCode();
     result = 31 * result + (m_mapSubResources != null ? m_mapSubResources.hashCode() : 0);

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java Mon Feb  4 02:23:55 2013
@@ -31,6 +31,7 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import java.io.File;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -75,7 +76,14 @@ public class AmbariMetaInfo {
     private static final String PROPERTY_XML_PROPERTY_NAME = "name";
     private static final String PROPERTY_XML_PROPERTY_VALUE = "value";
     private static final String PROPERTY_XML_PROPERTY_DESCRIPTION = "description";
-
+    private static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
+      @Override
+      public boolean accept(File dir, String s) {
+        if (s.equals(".svn") || s.equals(".git"))
+          return false;
+        return true;
+      }
+    };
 
     /**
      * Ambari Meta Info Object
@@ -357,11 +365,11 @@ public class AmbariMetaInfo {
             throw new IOException("" + Configuration.METADETA_DIR_PATH
                     + " should be a directory with stack"
                     + ", stackRoot=" + stackRoot.getAbsolutePath());
-        File[] stacks = stackRoot.listFiles();
+        File[] stacks = stackRoot.listFiles(FILENAME_FILTER);
         for (File stackFolder : stacks) {
             if (stackFolder.isFile())
                 continue;
-            File[] concretStacks = stackFolder.listFiles();
+            File[] concretStacks = stackFolder.listFiles(FILENAME_FILTER);
             for (File stack : concretStacks) {
                 if (stack.isFile())
                     continue;
@@ -395,7 +403,7 @@ public class AmbariMetaInfo {
                 // Get services for this stack
                 File servicesRootFolder = new File(stack.getAbsolutePath()
                         + File.separator + SERVICES_FOLDER_NAME);
-                File[] servicesFolders = servicesRootFolder.listFiles();
+                File[] servicesFolders = servicesRootFolder.listFiles(FILENAME_FILTER);
 
                 if (servicesFolders != null) {
                     for (File serviceFolder : servicesFolders) {
@@ -421,7 +429,7 @@ public class AmbariMetaInfo {
                         // Get all properties from all "configs/*-site.xml" files
                         File serviceConfigFolder = new File(serviceFolder.getAbsolutePath()
                                 + File.separator + SERVICE_CONFIG_FOLDER_NAME);
-                        File[] configFiles = serviceConfigFolder.listFiles();
+                        File[] configFiles = serviceConfigFolder.listFiles(FILENAME_FILTER);
                         if (configFiles != null) {
                             for (File config : configFiles) {
                                 if (config.getName().endsWith(SERVICE_CONFIG_FILE_NAME_POSTFIX)) {

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java Mon Feb  4 02:23:55 2013
@@ -47,7 +47,7 @@ public class Configuration {
   public static final String BOOTSTRAP_DIR_DEFAULT = "/var/run/ambari-server/bootstrap";
   public static final String WEBAPP_DIR = "webapp.dir";
   public static final String BOOTSTRAP_SCRIPT = "bootstrap.script";
-    public static final String BOOTSTRAP_SCRIPT_DEFAULT =  "/usr/bin/ambari_bootstrap";
+  public static final String BOOTSTRAP_SCRIPT_DEFAULT =  "/usr/bin/ambari_bootstrap";
   public static final String BOOTSTRAP_SETUP_AGENT_SCRIPT = "bootstrap.setup_agent.script";
   public static final String BOOTSTRAP_SETUP_AGENT_PASSWORD = "bootstrap.setup_agent.password";
   public static final String BOOTSTRAP_MASTER_HOSTNAME = "bootstrap.master_host_name";
@@ -70,21 +70,22 @@ public class Configuration {
 
 
   public static final String CLIENT_SECURITY_KEY = "client.security";
-  public static final String LDAP_USE_SSL_KEY = "authorization.ldap.useSSL";
+  public static final String CLIENT_API_PORT_KEY = "client.api.port";
+  public static final String LDAP_USE_SSL_KEY = "authentication.ldap.useSSL";
   public static final String LDAP_PRIMARY_URL_KEY =
-      "authorization.ldap.primaryUrl";
+      "authentication.ldap.primaryUrl";
   public static final String LDAP_SECONDARY_URL_KEY =
-      "authorization.ldap.secondaryUrl";
+      "authentication.ldap.secondaryUrl";
   public static final String LDAP_BASE_DN_KEY =
-      "authorization.ldap.baseDn";
+      "authentication.ldap.baseDn";
   public static final String LDAP_BIND_ANONYMOUSLY_KEY =
-      "authorization.ldap.bindAnonymously";
+      "authentication.ldap.bindAnonymously";
   public static final String LDAP_MANAGER_DN_KEY =
-      "authorization.ldap.managerDn";
+      "authentication.ldap.managerDn";
   public static final String LDAP_MANAGER_PASSWORD_KEY =
-      "authorization.ldap.managerPassword";
+      "authentication.ldap.managerPassword";
   public static final String LDAP_USERNAME_ATTRIBUTE_KEY =
-      "authorization.ldap.usernameAttribute";
+      "authentication.ldap.usernameAttribute";
 
   public static final String USER_ROLE_NAME_KEY =
       "authorization.userRoleName";
@@ -105,6 +106,9 @@ public class Configuration {
   public static final String OS_VERSION_KEY =
       "server.os_type";
 
+  public static final String SRVR_HOSTS_MAPPING = 
+      "server.hosts.mapping";
+
   private static final String SRVR_KSTR_DIR_DEFAULT = ".";
   public static final String SRVR_CRT_NAME_DEFAULT = "ca.crt";
   public static final String SRVR_KEY_NAME_DEFAULT = "ca.key";
@@ -116,6 +120,7 @@ public class Configuration {
       "/var/share/ambari/resources/";
 
   private static final String CLIENT_SECURITY_DEFAULT = "local";
+  private static final int CLIENT_API_PORT_DEFAULT = 8080;
 
   private static final String USER_ROLE_NAME_DEFAULT = "user";
   private static final String ADMIN_ROLE_NAME_DEFAULT = "admin";
@@ -130,6 +135,8 @@ public class Configuration {
   private static final String PERSISTENCE_IN_MEMORY_DEFAULT = "true";
 
 
+
+
   private static final Logger LOG = LoggerFactory.getLogger(
       Configuration.class);
 
@@ -163,7 +170,7 @@ public class Configuration {
     configsMap.put(KSTR_NAME_KEY, properties.getProperty(
         KSTR_NAME_KEY, KSTR_NAME_DEFAULT));
     configsMap.put(SRVR_CRT_PASS_FILE_KEY, properties.getProperty(
-     SRVR_CRT_PASS_FILE_KEY, SRVR_CRT_PASS_FILE_DEFAULT));
+        SRVR_CRT_PASS_FILE_KEY, SRVR_CRT_PASS_FILE_DEFAULT));
     configsMap.put(PASSPHRASE_ENV_KEY, properties.getProperty(
         PASSPHRASE_ENV_KEY, PASSPHRASE_ENV_DEFAULT));
     configsMap.put(PASSPHRASE_KEY, System.getenv(configsMap.get(
@@ -175,7 +182,7 @@ public class Configuration {
     configsMap.put(RESOURCES_DIR_KEY, properties.getProperty(
         RESOURCES_DIR_KEY, RESOURCES_DIR_DEFAULT));
     configsMap.put(SRVR_CRT_PASS_LEN_KEY, properties.getProperty(
-     SRVR_CRT_PASS_LEN_KEY, SRVR_CRT_PASS_LEN_DEFAULT));
+        SRVR_CRT_PASS_LEN_KEY, SRVR_CRT_PASS_LEN_DEFAULT));
 
     File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
         + configsMap.get(SRVR_CRT_PASS_FILE_KEY));
@@ -189,12 +196,12 @@ public class Configuration {
         FileUtils.writeStringToFile(passFile, randStr);
 
       } catch (IOException e) {
-          e.printStackTrace();
-          throw new RuntimeException(
+        e.printStackTrace();
+        throw new RuntimeException(
             "Error reading certificate password from file");
       }
     } else {
-        LOG.info("Reading password from existing file");
+      LOG.info("Reading password from existing file");
       try {
         randStr = FileUtils.readFileToString(passFile);
       } catch (IOException e) {
@@ -226,7 +233,7 @@ public class Configuration {
       LOG.info("No configuration file " + CONFIG_FILE + " found in classpath.", fnf);
     } catch (IOException ie) {
       throw new IllegalArgumentException("Can't read configuration file " +
-       CONFIG_FILE, ie);
+          CONFIG_FILE, ie);
     }
 
     return properties;
@@ -235,7 +242,7 @@ public class Configuration {
   public File getBootStrapDir() {
     String fileName = properties.getProperty(BOOTSTRAP_DIR);
     if (fileName == null) {
-        fileName = BOOTSTRAP_DIR_DEFAULT;
+      fileName = BOOTSTRAP_DIR_DEFAULT;
     }
     return new File(fileName);
   }
@@ -290,6 +297,15 @@ public class Configuration {
   }
 
   /**
+   * Get the file that will be used for host mapping.
+   * @return null if such a file is not present, value if present.
+   */
+  public String getHostsMapFile() {
+    LOG.info("Hosts Mapping File " +  properties.getProperty(SRVR_HOSTS_MAPPING));
+    return properties.getProperty(SRVR_HOSTS_MAPPING);
+  }
+
+  /**
    * Gets ambari stack-path
    * @return String
    */
@@ -380,4 +396,9 @@ public class Configuration {
     return properties.getProperty(BOOTSTRAP_MASTER_HOSTNAME, defaultValue);
   }
 
+
+  public int getClientApiPort() {
+    return Integer.parseInt(properties.getProperty(CLIENT_API_PORT_KEY, String.valueOf(CLIENT_API_PORT_DEFAULT)));
+  }
+
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Mon Feb  4 02:23:55 2013
@@ -30,6 +30,7 @@ import org.apache.ambari.server.actionma
 import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
 import org.apache.ambari.server.security.authorization.User;
@@ -57,6 +58,7 @@ import org.apache.ambari.server.state.sv
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -105,7 +107,13 @@ public class AmbariManagementControllerI
   private AmbariMetaInfo ambariMetaInfo;
   @Inject
   private Users users;
+  @Inject
+  private HostsMap hostsMap;
+  @Inject
+  private Configuration configs;
 
+
+  
   final private String masterHostname;
 
   final private static String JDK_RESOURCE_LOCATION =
@@ -123,9 +131,14 @@ public class AmbariManagementControllerI
     this.gson = injector.getInstance(Gson.class);
     LOG.info("Initializing the AmbariManagementControllerImpl");
     this.masterHostname =  InetAddress.getLocalHost().getCanonicalHostName();
-    this.jdkResourceUrl = "http://" + masterHostname + ":"
-        + AmbariServer.getResourcesPort()
-        + JDK_RESOURCE_LOCATION;
+    
+    if (configs != null) {
+      this.jdkResourceUrl = "http://" + masterHostname + ":"
+          + configs.getClientApiPort()
+          + JDK_RESOURCE_LOCATION; 
+    } else {
+    		this.jdkResourceUrl = null;
+    }
   }
 
   @Override
@@ -898,7 +911,7 @@ public class AmbariManagementControllerI
 
     // Generate cluster host info
     execCmd.setClusterHostInfo(
-        StageUtils.getClusterHostInfo(cluster));
+        StageUtils.getClusterHostInfo(cluster, hostsMap));
 
     Host host = clusters.getHost(scHost.getHostName());
 
@@ -1687,7 +1700,7 @@ public class AmbariManagementControllerI
         // Generate cluster host info
         stage.getExecutionCommandWrapper(clientHost, smokeTestRole)
             .getExecutionCommand()
-            .setClusterHostInfo(StageUtils.getClusterHostInfo(cluster));
+            .setClusterHostInfo(StageUtils.getClusterHostInfo(cluster, hostsMap));
       }
 
       RoleGraph rg = new RoleGraph(rco);
@@ -1809,17 +1822,6 @@ public class AmbariManagementControllerI
       ServiceComponentHost sch,
       State currentState, State newDesiredState)
           throws AmbariException {
-    if (currentState == State.STARTED
-        || currentState == State.STARTING) {
-      throw new AmbariException("Changing of configs not supported"
-          + " in STARTING or STARTED state"
-          + ", clusterName=" + sch.getClusterName()
-          + ", serviceName=" + sch.getServiceName()
-          + ", componentName=" + sch.getServiceComponentName()
-          + ", hostname=" + sch.getHostName()
-          + ", currentState=" + currentState
-          + ", newDesiredState=" + newDesiredState);
-    }
 
     if (newDesiredState != null) {
       if (!(newDesiredState == State.INIT
@@ -2698,9 +2700,7 @@ public class AmbariManagementControllerI
   @Override
   public synchronized void deleteCluster(ClusterRequest request)
       throws AmbariException {
-    throw new AmbariException("Delete cluster not supported");
 
-    /*
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()) {
       // FIXME throw correct error
@@ -2714,13 +2714,22 @@ public class AmbariManagementControllerI
       // deleting whole cluster
       clusters.deleteCluster(request.getClusterName());
     }
-    */
   }
 
   @Override
   public RequestStatusResponse deleteServices(Set<ServiceRequest> request)
       throws AmbariException {
-    throw new AmbariException("Delete services not supported");
+
+    for (ServiceRequest serviceRequest : request) {
+      if (StringUtils.isEmpty(serviceRequest.getClusterName()) || StringUtils.isEmpty(serviceRequest.getServiceName())) {
+        // FIXME throw correct error
+        throw new AmbariException("invalid arguments");
+      } else {
+        clusters.getCluster(serviceRequest.getClusterName()).deleteService(serviceRequest.getServiceName());
+      }
+    }
+    return null;
+
   }
 
   @Override
@@ -3156,7 +3165,7 @@ public class AmbariManagementControllerI
         .getExecutionCommandWrapper(hostName, actionRequest.getActionName())
         .getExecutionCommand()
         .setClusterHostInfo(
-            StageUtils.getClusterHostInfo(clusters.getCluster(clusterName)));
+            StageUtils.getClusterHostInfo(clusters.getCluster(clusterName), hostsMap));
   }
 
   private void addDecommissionDatanodeAction(

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java Mon Feb  4 02:23:55 2013
@@ -74,7 +74,6 @@ public class AmbariServer {
   public static final int AGENT_ONE_WAY_AUTH = 8440;
   public static final int AGENT_TWO_WAY_AUTH = 8441;
   public static final int CLIENT_SSL_API_PORT = 8443;
-  public static final int CLIENT_API_PORT = 8080;
 
   private Server server = null;
   private Server serverForAgent = null;
@@ -98,9 +97,6 @@ public class AmbariServer {
     return configs.getServerOsType();
   }
 
-  public static int getResourcesPort() {
-    return CLIENT_API_PORT;
-  }
 
   private static AmbariManagementController clusterController = null;
 
@@ -278,7 +274,7 @@ public class AmbariServer {
       } 
       else  {
         apiConnector = new SelectChannelConnector();
-        apiConnector.setPort(CLIENT_API_PORT);
+        apiConnector.setPort(configs.getClientApiPort());
       }
 
       server.addConnector(apiConnector);

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java Mon Feb  4 02:23:55 2013
@@ -51,15 +51,18 @@ public class ControllerModule extends Ab
 
   private final Configuration configuration;
   private final AmbariMetaInfo ambariMetaInfo;
-
+  private final HostsMap hostsMap;
+  
   public ControllerModule() throws Exception {
     configuration = new Configuration();
     ambariMetaInfo = new AmbariMetaInfo(configuration);
+    hostsMap = new HostsMap(configuration);
   }
 
   public ControllerModule(Properties properties) throws Exception {
     configuration = new Configuration(properties);
     ambariMetaInfo = new AmbariMetaInfo(configuration);
+    hostsMap = new HostsMap(configuration);
   }
 
   @Override
@@ -69,7 +72,8 @@ public class ControllerModule extends Ab
 
     bind(Configuration.class).toInstance(configuration);
     bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);
-
+    bind(HostsMap.class).toInstance(hostsMap);
+    
     bind(PasswordEncoder.class).toInstance(new StandardPasswordEncoder());
 
     JpaPersistModule jpaPersistModule = new JpaPersistModule(configuration.getPersistenceType().getUnitName());

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java Mon Feb  4 02:23:55 2013
@@ -18,16 +18,15 @@
 
 package org.apache.ambari.server.controller;
 
-import org.apache.ambari.server.agent.DiskInfo;
-import org.apache.ambari.server.state.AgentVersion;
-import org.apache.ambari.server.state.HostHealthStatus;
-
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
+
+import org.apache.ambari.server.agent.AgentEnv;
+import org.apache.ambari.server.agent.DiskInfo;
+import org.apache.ambari.server.state.AgentVersion;
+import org.apache.ambari.server.state.HostHealthStatus;
 
 public class HostResponse {
 
@@ -84,6 +83,11 @@ public class HostResponse {
    * Last heartbeat timestamp from the Host
    */
   private long lastHeartbeatTime;
+  
+  /**
+   * Last environment information
+   */
+  private AgentEnv lastAgentEnv;
 
   /**
    * Last registration timestamp for the Host
@@ -439,4 +443,17 @@ public class HostResponse {
     this.hostState = hostState;
   }
 
+  
+  public AgentEnv getLastAgentEnv() {
+    return lastAgentEnv;
+  }
+  
+  /**
+   * @param lastAgentEnv
+   */
+  public void setLastAgentEnv(AgentEnv agentEnv) {
+    lastAgentEnv = agentEnv;
+  }
+  
+
 }

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,95 @@
+/**
+ * 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.server.controller;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Stores the mapping of hostnames to be used in any configuration on 
+ * the server.
+ *  
+ */
+@Singleton
+public class HostsMap {
+  private final static Logger LOG = LoggerFactory
+      .getLogger(HostsMap.class);
+
+  private String hostsMapFile;
+  private Properties hostsMap;
+
+  @Inject
+  public HostsMap(Configuration conf) {
+    hostsMapFile = conf.getHostsMapFile();
+    setupMap();
+  }
+  
+  public HostsMap(String file) {
+    hostsMapFile = file;
+  }
+
+  public void setupMap() {
+    InputStream inputStream = null;
+    LOG.info("Using hostsmap file " + this.hostsMapFile);
+    try {
+      if (hostsMapFile != null) {
+        hostsMap = new Properties();
+        inputStream = new FileInputStream(new File(hostsMapFile));
+        // load the properties
+        hostsMap.load(inputStream);
+      }
+    } catch (FileNotFoundException fnf) {
+      LOG.info("No configuration file " + hostsMapFile + " found in classpath.", fnf);
+    } catch (IOException ie) {
+      throw new IllegalArgumentException("Can't read configuration file " +
+          hostsMapFile, ie);
+    } finally {
+      if (inputStream != null) {
+        try {
+          inputStream.close();
+        } catch(IOException io) {
+          //ignore 
+        }
+      }
+    }
+  }
+
+/**
+ * Return map of the hostname if available
+ * @param hostName hostname map
+ * @return 
+ */
+public String getHostMap(String hostName) {
+  if (hostsMapFile == null) 
+    return hostName;
+  return hostsMap.getProperty(hostName, hostName);
+}
+
+}

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java Mon Feb  4 02:23:55 2013
@@ -22,7 +22,9 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
 
+import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * Ganglia property provider implementation for component resources.
@@ -56,7 +58,7 @@ public class GangliaComponentPropertyPro
   }
 
   @Override
-  protected String getGangliaClusterName(Resource resource, String clusterName) {
-    return GANGLIA_CLUSTER_NAMES.get(getComponentName(resource));
+  protected Set<String> getGangliaClusterNames(Resource resource, String clusterName) {
+    return Collections.singleton(GANGLIA_CLUSTER_NAME_MAP.get(getComponentName(resource)));
   }
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java Mon Feb  4 02:23:55 2013
@@ -22,7 +22,9 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
 
+import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * Ganglia property provider implementation for host component resources.
@@ -57,7 +59,7 @@ public class GangliaHostComponentPropert
   }
 
   @Override
-  protected String getGangliaClusterName(Resource resource, String clusterName) {
-    return GANGLIA_CLUSTER_NAMES.get(getComponentName(resource));
+  protected Set<String> getGangliaClusterNames(Resource resource, String clusterName) {
+    return Collections.singleton(GANGLIA_CLUSTER_NAME_MAP.get(getComponentName(resource)));
   }
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java Mon Feb  4 02:23:55 2013
@@ -22,13 +22,25 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
 
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * Ganglia property provider implementation for host resources.
  */
 public class GangliaHostPropertyProvider extends GangliaPropertyProvider{
-
+  /**
+   * Set of Ganglia cluster names.
+   */
+ private static final Set<String> GANGLIA_CLUSTER_NAMES = new HashSet<String>();
+
+ static {
+   GANGLIA_CLUSTER_NAMES.add("HDPNameNode");
+   GANGLIA_CLUSTER_NAMES.add("HDPSlaves");
+   GANGLIA_CLUSTER_NAMES.add("HDPJobTracker");
+   GANGLIA_CLUSTER_NAMES.add("HDPHBaseMaster");
+ }
 
   // ----- Constructors ------------------------------------------------------
 
@@ -56,7 +68,7 @@ public class GangliaHostPropertyProvider
   }
 
   @Override
-  protected String getGangliaClusterName(Resource resource, String clusterName) {
-    return "HDPSlaves";
+  protected Set<String> getGangliaClusterNames(Resource resource, String clusterName) {
+    return GANGLIA_CLUSTER_NAMES;
   }
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java Mon Feb  4 02:23:55 2013
@@ -152,4 +152,22 @@ public class GangliaMetric {
 
     return stringBuilder.toString();
   }
+
+  public static class TemporalMetric {
+    private Number m_value;
+    private Number m_time;
+
+    public TemporalMetric(Number value, Number time) {
+      m_value = value;
+      m_time = time;
+    }
+
+    public Number getValue() {
+      return m_value;
+    }
+
+    public Number getTime() {
+      return m_time;
+    }
+  }
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java Mon Feb  4 02:23:55 2013
@@ -22,19 +22,13 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.*;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.BufferedReader;
 import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.io.InputStreamReader;
+import java.util.*;
 
 /**
  * Abstract property provider implementation for a Ganglia source.
@@ -59,19 +53,20 @@ public abstract class GangliaPropertyPro
   private final String componentNamePropertyId;
 
 
+
   /**
    * Map of Ganglia cluster names keyed by component type.
    */
-  public static final Map<String, String> GANGLIA_CLUSTER_NAMES = new HashMap<String, String>();
+  public static final Map<String, String> GANGLIA_CLUSTER_NAME_MAP = new HashMap<String, String>();
 
   static {
-    GANGLIA_CLUSTER_NAMES.put("NAMENODE",           "HDPNameNode");
-    GANGLIA_CLUSTER_NAMES.put("DATANODE",           "HDPSlaves");
-    GANGLIA_CLUSTER_NAMES.put("JOBTRACKER",         "HDPJobTracker");
-    GANGLIA_CLUSTER_NAMES.put("TASKTRACKER",        "HDPSlaves");
-    GANGLIA_CLUSTER_NAMES.put("HBASE_MASTER",       "HDPHBaseMaster");
-    GANGLIA_CLUSTER_NAMES.put("HBASE_CLIENT",       "HDPSlaves");
-    GANGLIA_CLUSTER_NAMES.put("HBASE_REGIONSERVER", "HDPSlaves");
+    GANGLIA_CLUSTER_NAME_MAP.put("NAMENODE",           "HDPNameNode");
+    GANGLIA_CLUSTER_NAME_MAP.put("DATANODE",           "HDPSlaves");
+    GANGLIA_CLUSTER_NAME_MAP.put("JOBTRACKER",         "HDPJobTracker");
+    GANGLIA_CLUSTER_NAME_MAP.put("TASKTRACKER",        "HDPSlaves");
+    GANGLIA_CLUSTER_NAME_MAP.put("HBASE_MASTER",       "HDPHBaseMaster");
+    GANGLIA_CLUSTER_NAME_MAP.put("HBASE_CLIENT",       "HDPSlaves");
+    GANGLIA_CLUSTER_NAME_MAP.put("HBASE_REGIONSERVER", "HDPSlaves");
   }
 
   protected final static Logger LOG =
@@ -92,7 +87,8 @@ public abstract class GangliaPropertyPro
     this.hostNamePropertyId       = hostNamePropertyId;
     this.componentNamePropertyId  = componentNamePropertyId;
 
-    propertyIds = new HashSet<String>();
+    propertyIds  = new HashSet<String>();
+
     for (Map.Entry<String, Map<String, PropertyInfo>> entry : componentPropertyInfoMap.entrySet()) {
       propertyIds.addAll(entry.getValue().keySet());
     }
@@ -118,9 +114,11 @@ public abstract class GangliaPropertyPro
     for (Map.Entry<String, Map<TemporalInfo, RRDRequest>> clusterEntry : requestMap.entrySet()) {
       // For each request ...
       for (RRDRequest rrdRequest : clusterEntry.getValue().values() ) {
+        //todo: property provider can reduce set of resources
         keepers.addAll(rrdRequest.populateResources());
       }
     }
+    //todo: ignoring keepers returned by the provider
     return resources;
   }
 
@@ -167,7 +165,7 @@ public abstract class GangliaPropertyPro
    *
    * @return the ganglia cluster name
    */
-  protected abstract String getGangliaClusterName(Resource resource, String clusterName);
+  protected abstract Set<String> getGangliaClusterNames(Resource resource, String clusterName);
 
 
   /**
@@ -227,25 +225,27 @@ public abstract class GangliaPropertyPro
         requestMap.put(clusterName, requests);
       }
 
-      ResourceKey key =
-          new ResourceKey(getHostName(resource), getGangliaClusterName(resource, clusterName));
-
-      Map<String, PropertyInfo> metrics = componentPropertyInfoMap.get(getComponentName(resource));
-
-      if (metrics != null) {
-        for (String propertyId : ids) {
-          PropertyInfo propertyInfo = metrics.get(propertyId);
-          if (propertyInfo != null) {
-            TemporalInfo temporalInfo = request.getTemporalInfo(propertyId);
-
-            if ((temporalInfo == null && propertyInfo.isPointInTime()) || (temporalInfo != null && propertyInfo.isTemporal())) {
-              RRDRequest rrdRequest = requests.get(temporalInfo);
-              if (rrdRequest == null) {
-                rrdRequest = new RRDRequest(clusterName, temporalInfo);
-                requests.put(temporalInfo, rrdRequest);
+      for (String gangliaClusterName : getGangliaClusterNames(resource, clusterName)) {
+        ResourceKey key =
+            new ResourceKey(getHostName(resource), gangliaClusterName);
+
+        Map<String, PropertyInfo> metrics = componentPropertyInfoMap.get(getComponentName(resource));
+
+        if (metrics != null) {
+          for (String propertyId : ids) {
+            PropertyInfo propertyInfo = metrics.get(propertyId);
+            if (propertyInfo != null) {
+              TemporalInfo temporalInfo = request.getTemporalInfo(propertyId);
+
+              if ((temporalInfo == null && propertyInfo.isPointInTime()) || (temporalInfo != null && propertyInfo.isTemporal())) {
+                RRDRequest rrdRequest = requests.get(temporalInfo);
+                if (rrdRequest == null) {
+                  rrdRequest = new RRDRequest(clusterName, temporalInfo);
+                  requests.put(temporalInfo, rrdRequest);
+                }
+                rrdRequest.putResource(key, resource);
+                rrdRequest.putPropertyId(propertyInfo.getPropertyId(), propertyId);
               }
-              rrdRequest.putResource(key, resource);
-              rrdRequest.putPropertyId(propertyInfo.getPropertyId(), propertyId);
             }
           }
         }
@@ -311,6 +311,7 @@ public abstract class GangliaPropertyPro
     }
     else {
       sb.append("&e=now");
+      sb.append("&pt=true");
     }
 
     return sb.toString();
@@ -414,31 +415,76 @@ public abstract class GangliaPropertyPro
     public Collection<Resource> populateResources() throws SystemException {
 
       String spec = getSpec(clusterName, clusterSet, hostSet, metrics.keySet(), temporalInfo);
-      Collection<Resource> populatedResources = new HashSet<Resource>();
-
+      BufferedReader reader = null;
       try {
-        List<GangliaMetric> gangliaMetrics = new ObjectMapper().readValue(getStreamProvider().readFrom(spec),
-            new TypeReference<List<GangliaMetric>>() {
-            });
-
-        if (gangliaMetrics != null) {
-          for (GangliaMetric gangliaMetric : gangliaMetrics) {
-
-            ResourceKey key = new ResourceKey(gangliaMetric.getHost_name(), gangliaMetric.getCluster_name());
-            Set<Resource> resourceSet = resources.get(key);
-            if (resourceSet != null) {
-              for (Resource resource : resourceSet) {
-                populateResource(resource, gangliaMetric);
-              }
+        reader = new BufferedReader(new InputStreamReader(
+            getStreamProvider().readFrom(spec)));
+
+        int startTime = convertToNumber(reader.readLine()).intValue();
+
+        String dsName = reader.readLine();
+        while(! dsName.equals("[AMBARI_END]")) {
+          GangliaMetric metric = new GangliaMetric();
+          List<GangliaMetric.TemporalMetric> listTemporalMetrics =
+              new ArrayList<GangliaMetric.TemporalMetric>();
+
+          metric.setDs_name(dsName);
+          metric.setCluster_name(reader.readLine());
+          metric.setHost_name(reader.readLine());
+          metric.setMetric_name(reader.readLine());
+
+          int time = convertToNumber(reader.readLine()).intValue();
+          int step = convertToNumber(reader.readLine()).intValue();
+
+          String val = reader.readLine();
+          while(! val.equals("[AMBARI_DP_END]")) {
+            listTemporalMetrics.add(
+                new GangliaMetric.TemporalMetric(convertToNumber(val), time));
+            time += step;
+            val = reader.readLine();
+          }
+
+          //todo: change setter in GangliaMetric to take collection
+          Number[][] datapointsArray = new Number[listTemporalMetrics.size()][2];
+          for (int i = 0; i < listTemporalMetrics.size(); ++i) {
+            GangliaMetric.TemporalMetric m = listTemporalMetrics.get(i);
+            datapointsArray[i][0] = m.getValue();
+            datapointsArray[i][1] = m.getTime();
+          }
+          metric.setDatapoints(datapointsArray);
+
+          ResourceKey key = new ResourceKey(metric.getHost_name(), metric.getCluster_name());
+          Set<Resource> resourceSet = resources.get(key);
+          if (resourceSet != null) {
+            for (Resource resource : resourceSet) {
+              populateResource(resource, metric);
             }
           }
+
+          dsName = reader.readLine();
+        }
+        int endTime = convertToNumber(reader.readLine()).intValue();
+
+        if (LOG.isInfoEnabled()) {
+          LOG.info("Ganglia resource population time: " + (endTime - startTime));
         }
       } catch (IOException e) {
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Caught exception getting Ganglia metrics : spec=" + spec, e);
+        if (LOG.isErrorEnabled()) {
+          LOG.error("Caught exception getting Ganglia metrics : spec=" + spec, e);
+        }
+      } finally {
+        if (reader != null) {
+          try {
+            reader.close();
+          } catch (IOException e) {
+            if (LOG.isWarnEnabled()) {
+              LOG.warn("Unable to close http input steam : spec=" + spec, e);
+            }
+          }
         }
       }
-      return populatedResources;
+      //todo: filter out resources and return keepers
+      return Collections.emptySet();
     }
 
     /**
@@ -462,6 +508,10 @@ public abstract class GangliaPropertyPro
         }
       }
     }
+
+    private Number convertToNumber(String s) {
+      return s.contains(".") ? Double.parseDouble(s) : Long.parseLong(s);
+    }
   }
 
 

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,416 @@
+/**
+ * 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.server.controller.gsinstaller;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Defines the cluster created by gsInstaller.
+ */
+public class ClusterDefinition {
+
+  private static final String CLUSTER_DEFINITION_FILE = "gsInstaller-hosts.txt";
+  private static final String DEFAULT_CLUSTER_NAME    = "ambari";
+  private static final String CLUSTER_NAME_TAG        = "CLUSTER=";
+  private static final String DEFAULT_VERSION_ID      = "HDP-1.2.0";
+  private static final String VERSION_ID_TAG          = "VERSION=";
+
+  private final Set<String> services = new HashSet<String>();
+  private final Set<String> hosts = new HashSet<String>();
+  private final Map<String, Set<String>> components = new HashMap<String, Set<String>>();
+  private final Map<String, Map<String, Set<String>>> hostComponents = new HashMap<String, Map<String, Set<String>>>();
+
+  private final GSInstallerStateProvider stateProvider;
+  private String clusterName;
+  private String versionId;
+
+  /**
+   * Index of host names to host component state.
+   */
+  private final Map<String, Set<HostComponentState>> hostStateMap = new HashMap<String, Set<HostComponentState>>();
+
+  /**
+   * Index of service names to host component state.
+   */
+  private final Map<String, Set<HostComponentState>> serviceStateMap = new HashMap<String, Set<HostComponentState>>();
+
+  /**
+   * Index of component names to host component state.
+   */
+  private final Map<String, Set<HostComponentState>> componentStateMap = new HashMap<String, Set<HostComponentState>>();
+
+  /**
+   * Index of host component names to host component state.
+   */
+  private final Map<String, HostComponentState> hostComponentStateMap = new HashMap<String, HostComponentState>();
+
+  /**
+   * Component name mapping to account for differences in what is provided by the gsInstaller
+   * and what is expected by the Ambari providers.
+   */
+  private static final Map<String, String> componentNameMap = new HashMap<String, String>();
+
+  static {
+    componentNameMap.put("GANGLIA", "GANGLIA_SERVER");
+  }
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Create a cluster definition.
+   */
+  public ClusterDefinition(GSInstallerStateProvider stateProvider) {
+    this.stateProvider = stateProvider;
+    this.clusterName   = DEFAULT_CLUSTER_NAME;
+    this.versionId     = DEFAULT_VERSION_ID;
+    readClusterDefinition();
+    setHostComponentState();
+  }
+
+
+  // ----- ClusterDefinition -------------------------------------------------
+
+  /**
+   * Get the name of the cluster.
+   *
+   * @return the cluster name
+   */
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  /**
+   * Get the name of the cluster.
+   *
+   * @return the cluster name
+   */
+  public String getVersionId() {
+    return versionId;
+  }
+
+  /**
+   * Get the services for the cluster.
+   *
+   * @return the set of service names
+   */
+  public Set<String> getServices() {
+    return services;
+  }
+
+  /**
+   * Get the hosts for the cluster.
+   *
+   * @return the set of hosts names
+   */
+  public Set<String> getHosts() {
+    return hosts;
+  }
+
+  /**
+   * Get the components for the given service.
+   *
+   * @param service  the service name
+   *
+   * @return the set of component names for the given service name
+   */
+  public Set<String> getComponents(String service) {
+    return components.get(service);
+  }
+
+  /**
+   * Get the host components for the given service and host.
+   *
+   * @param service  the service name
+   * @param host     the host name
+   *
+   * @return the set of host component names for the given service and host names
+   */
+  public Set<String> getHostComponents(String service, String host) {
+    Set<String> resultSet = null;
+    Map<String, Set<String>> serviceHostComponents = hostComponents.get(service);
+    if (serviceHostComponents != null) {
+      resultSet = serviceHostComponents.get(host);
+    }
+    return resultSet == null ? Collections.<String>emptySet() : resultSet;
+  }
+
+  /**
+   * Get the host state from the given host name.
+   *
+   * @param hostName  the host name
+   *
+   * @return the host state
+   */
+  public String getHostState(String hostName) {
+    return isHealthy(hostStateMap.get(hostName)) ? "HEALTHY" : "INIT";
+  }
+
+  /**
+   * Get the service state from the given service name.
+   *
+   * @param serviceName  the service name
+   *
+   * @return the service state
+   */
+  public String getServiceState(String serviceName) {
+    return isHealthy(serviceStateMap.get(serviceName)) ? "STARTED" : "INIT";
+  }
+
+  /**
+   * Get the component state from the give service name and component name.
+   *
+   * @param serviceName    the service name
+   * @param componentName  the component name
+   *
+   * @return the component state
+   */
+  public String getComponentState(String serviceName, String componentName) {
+    return isHealthy(componentStateMap.get(getComponentKey(serviceName, componentName))) ? "STARTED" : "INIT";
+  }
+
+  /**
+   * Get the host component name from the given host name, service name and component name.
+   *
+   * @param hostName       the host name
+   * @param serviceName    the service name
+   * @param componentName  the component name
+   *
+   * @return the host component state
+   */
+  public String getHostComponentState(String hostName, String serviceName, String componentName) {
+    return isHealthy(hostComponentStateMap.get(getHostComponentKey(hostName, serviceName, componentName))) ? "STARTED" : "INIT";
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Read the gsInstaller cluster definition file.
+   */
+  private void readClusterDefinition() {
+    try {
+      InputStream    is = this.getClass().getClassLoader().getResourceAsStream(CLUSTER_DEFINITION_FILE);
+      BufferedReader br = new BufferedReader(new InputStreamReader(is));
+
+      String line;
+      while ((line = br.readLine()) != null) {
+        line = line.trim();
+        if (line.startsWith(CLUSTER_NAME_TAG)) {
+          clusterName = line.substring(CLUSTER_NAME_TAG.length());
+        }
+        else if (line.startsWith(VERSION_ID_TAG)) {
+          versionId = line.substring(VERSION_ID_TAG.length());
+        }
+        else {
+          String[] parts = line.split("\\s+");
+          assert(parts.length == 3);
+
+          String serviceName   = parts[0];
+          String componentName = parts[1];
+          String hostName      = parts[2];
+
+          // translate the component name if required
+          if (componentNameMap.containsKey(componentName)) {
+            componentName = componentNameMap.get(componentName);
+          }
+
+          services.add(serviceName);
+          Set<String> serviceComponents = components.get(serviceName);
+          if (serviceComponents == null) {
+            serviceComponents = new HashSet<String>();
+            components.put(serviceName, serviceComponents);
+          }
+          serviceComponents.add(componentName);
+
+          Map<String, Set<String>> serviceHostComponents = hostComponents.get(serviceName);
+          if (serviceHostComponents == null) {
+            serviceHostComponents = new HashMap<String, Set<String>>();
+            hostComponents.put(serviceName, serviceHostComponents);
+          }
+
+          Set<String> hostHostComponents = serviceHostComponents.get(hostName);
+          if (hostHostComponents == null) {
+            hostHostComponents = new HashSet<String>();
+            serviceHostComponents.put(hostName, hostHostComponents);
+          }
+          hostHostComponents.add(componentName);
+          hosts.add(hostName);
+        }
+      }
+    } catch (IOException e) {
+      String msg = "Caught exception reading " + CLUSTER_DEFINITION_FILE + ".";
+      throw new IllegalStateException(msg, e);
+    }
+  }
+
+  /**
+   * Set the host component state maps.
+   */
+  private void setHostComponentState() {
+    for (Map.Entry<String, Map<String, Set<String>>> serviceEntry : hostComponents.entrySet()) {
+      String serviceName = serviceEntry.getKey();
+
+      for (Map.Entry<String, Set<String>> hostEntry : serviceEntry.getValue().entrySet()) {
+        String hostName = hostEntry.getKey();
+
+        for (String componentName : hostEntry.getValue()) {
+
+          HostComponentState state = new HostComponentState(hostName, componentName);
+
+          // add state to hosts
+          addState(hostName, hostStateMap, state);
+
+          // add state to services
+          addState(serviceName, serviceStateMap, state);
+
+          // add state to components
+          addState(getComponentKey(serviceName, componentName), componentStateMap, state);
+
+          // add state to host components
+          hostComponentStateMap.put(getHostComponentKey(hostName, serviceName, componentName), state);
+        }
+      }
+    }
+  }
+
+  /**
+   * Add the given host component state object to the given map of state objects.
+   *
+   * @param hostName  the host name
+   * @param stateMap  the map of state objects
+   * @param state     the state
+   */
+  private static void addState(String hostName, Map<String, Set<HostComponentState>> stateMap, HostComponentState state) {
+    Set<HostComponentState> states = stateMap.get(hostName);
+    if (states == null) {
+      states = new HashSet<HostComponentState>();
+      stateMap.put(hostName, states);
+    }
+    states.add(state);
+  }
+
+  /**
+   * Get a key from the given service name and component name.
+   *
+   * @param serviceName    the service name
+   * @param componentName  the component name
+   *
+   * @return the key
+   */
+  private String getComponentKey(String serviceName, String componentName) {
+    return serviceName + "." + componentName;
+  }
+
+  /**
+   * Get a key from the given host name, service name and component name.
+   *
+   * @param hostName       the host name
+   * @param serviceName    the service name
+   * @param componentName  the component name
+   *
+   * @return the key
+   */
+  private String getHostComponentKey(String hostName, String serviceName, String componentName) {
+    return hostName + "." + serviceName + "." + componentName;
+  }
+
+  /**
+   * Determine whether or not the host components associated
+   * with the given states are healthy.
+   *
+   * @param states  the states
+   *
+   * @return true if the associated host components are healthy
+   */
+  private boolean isHealthy(Set<HostComponentState> states) {
+    if (states != null) {
+      for (HostComponentState state : states) {
+        if (!state.isHealthy()) {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Determine whether or not the host component associated
+   * with the given state is healthy.
+   *
+   * @param state  the state
+   *
+   * @return true if the associated host component is healthy
+   */
+  private boolean isHealthy(HostComponentState state) {
+    return state == null || state.isHealthy();
+  }
+
+
+  // ----- inner classes -----------------------------------------------------
+
+  /**
+   * A state object used to check the health of a host component.
+   */
+  private class HostComponentState {
+    private final String hostName;
+    private final String componentName;
+    private boolean healthy = true;
+    private long lastAccess;
+
+    /**
+     * Expiry for the health value.
+     */
+    private static final int EXPIRY = 15000;
+
+    // ----- Constructor -----------------------------------------------------
+
+    /**
+     * Constructor.
+     *
+     * @param hostName       the host name
+     * @param componentName  the component name
+     */
+    HostComponentState(String hostName, String componentName) {
+      this.hostName      = hostName;
+      this.componentName = componentName;
+    }
+
+    /**
+     * Determine whether or not the associated host component is healthy.
+     *
+     * @return true if the associated host component is healthy
+     */
+    public boolean isHealthy() {
+      if (System.currentTimeMillis() - lastAccess > EXPIRY) {
+        // health value has expired... get it again
+        healthy = stateProvider.isHealthy(hostName, componentName);
+        this.lastAccess = System.currentTimeMillis();
+      }
+      return healthy;
+    }
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,87 @@
+/**
+ * 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.server.controller.gsinstaller;
+
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A cluster resource provider for a gsInstaller defined cluster.
+ */
+public class GSInstallerClusterProvider extends GSInstallerResourceProvider{
+
+  // Clusters
+  protected static final String CLUSTER_NAME_PROPERTY_ID    = PropertyHelper.getPropertyId("Clusters", "cluster_name");
+  protected static final String CLUSTER_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "version");
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a resource provider based on the given cluster definition.
+   *
+   * @param clusterDefinition  the cluster definition
+   */
+  public GSInstallerClusterProvider(ClusterDefinition clusterDefinition) {
+    super(clusterDefinition);
+    initClusterResources();
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public Set<String> getPropertyIdsForSchema() {
+    return PropertyHelper.getPropertyIds(Resource.Type.Cluster);
+  }
+
+  @Override
+  public Map<Resource.Type, String> getKeyPropertyIds() {
+    return PropertyHelper.getKeyPropertyIds(Resource.Type.Cluster);
+  }
+
+
+  // ----- GSInstallerResourceProvider ---------------------------------------
+
+  @Override
+  public void updateProperties(Resource resource, Request request, Predicate predicate) {
+    // Do nothing
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create the resources based on the cluster definition.
+   */
+  private void initClusterResources() {
+    Resource cluster = new ResourceImpl(Resource.Type.Cluster);
+    ClusterDefinition clusterDefinition = getClusterDefinition();
+    cluster.setProperty(CLUSTER_NAME_PROPERTY_ID, clusterDefinition.getClusterName());
+    cluster.setProperty(CLUSTER_VERSION_PROPERTY_ID, clusterDefinition.getVersionId());
+
+    addResource(cluster);
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,102 @@
+/**
+ * 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.server.controller.gsinstaller;
+
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A component resource provider for a gsInstaller defined cluster.
+ */
+public class GSInstallerComponentProvider extends GSInstallerResourceProvider{
+
+  // Components
+  protected static final String COMPONENT_CLUSTER_NAME_PROPERTY_ID    = PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name");
+  protected static final String COMPONENT_SERVICE_NAME_PROPERTY_ID    = PropertyHelper.getPropertyId("ServiceComponentInfo", "service_name");
+  protected static final String COMPONENT_COMPONENT_NAME_PROPERTY_ID  = PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name");
+  protected static final String COMPONENT_STATE_PROPERTY_ID           = PropertyHelper.getPropertyId("ServiceComponentInfo", "state");
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a resource provider based on the given cluster definition.
+   *
+   * @param clusterDefinition  the cluster definition
+   */
+  public GSInstallerComponentProvider(ClusterDefinition clusterDefinition) {
+    super(clusterDefinition);
+    initComponentResources();
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public Set<String> getPropertyIdsForSchema() {
+    return PropertyHelper.getPropertyIds(Resource.Type.Component);
+  }
+
+  @Override
+  public Map<Resource.Type, String> getKeyPropertyIds() {
+    return PropertyHelper.getKeyPropertyIds(Resource.Type.Component);
+  }
+
+
+  // ----- GSInstallerResourceProvider ---------------------------------------
+
+  @Override
+  public void updateProperties(Resource resource, Request request, Predicate predicate) {
+
+    Set<String> propertyIds = getRequestPropertyIds(request, predicate);
+    if (propertyIds.contains(COMPONENT_STATE_PROPERTY_ID)) {
+      String serviceName   = (String) resource.getPropertyValue(COMPONENT_SERVICE_NAME_PROPERTY_ID);
+      String componentName = (String) resource.getPropertyValue(COMPONENT_COMPONENT_NAME_PROPERTY_ID);
+      resource.setProperty(COMPONENT_STATE_PROPERTY_ID, getClusterDefinition().getComponentState(serviceName, componentName));
+    }
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create the resources based on the cluster definition.
+   */
+  private void initComponentResources() {
+    String      clusterName = getClusterDefinition().getClusterName();
+    Set<String> services    = getClusterDefinition().getServices();
+    for (String serviceName : services) {
+      Set<String> components = getClusterDefinition().getComponents(serviceName);
+      for (String componentName : components) {
+        Resource component = new ResourceImpl(Resource.Type.Component);
+        component.setProperty(COMPONENT_CLUSTER_NAME_PROPERTY_ID, clusterName);
+        component.setProperty(COMPONENT_SERVICE_NAME_PROPERTY_ID, serviceName);
+        component.setProperty(COMPONENT_COMPONENT_NAME_PROPERTY_ID, componentName);
+
+        addResource(component);
+      }
+    }
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,113 @@
+/**
+ * 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.server.controller.gsinstaller;
+
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A host component resource provider for a gsInstaller defined cluster.
+ */
+public class GSInstallerHostComponentProvider extends GSInstallerResourceProvider{
+
+  // Host Components
+  protected static final String HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID   = PropertyHelper.getPropertyId("HostRoles", "cluster_name");
+  protected static final String HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID   = PropertyHelper.getPropertyId("HostRoles", "service_name");
+  protected static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name");
+  protected static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID      = PropertyHelper.getPropertyId("HostRoles", "host_name");
+  protected static final String HOST_COMPONENT_STATE_PROPERTY_ID          = PropertyHelper.getPropertyId("HostRoles", "state");
+  protected static final String HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID  = PropertyHelper.getPropertyId("HostRoles", "desired_state");
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a resource provider based on the given cluster definition.
+   *
+   * @param clusterDefinition  the cluster definition
+   */
+  public GSInstallerHostComponentProvider(ClusterDefinition clusterDefinition) {
+    super(clusterDefinition);
+    initHostComponentResources();
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public Set<String> getPropertyIdsForSchema() {
+    return PropertyHelper.getPropertyIds(Resource.Type.HostComponent);
+  }
+
+  @Override
+  public Map<Resource.Type, String> getKeyPropertyIds() {
+    return PropertyHelper.getKeyPropertyIds(Resource.Type.HostComponent);
+  }
+
+
+  // ----- GSInstallerResourceProvider ---------------------------------------
+
+  @Override
+  public void updateProperties(Resource resource, Request request, Predicate predicate) {
+    Set<String> propertyIds = getRequestPropertyIds(request, predicate);
+    if (propertyIds.contains(HOST_COMPONENT_STATE_PROPERTY_ID) ||
+        propertyIds.contains(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)) {
+      String serviceName   = (String) resource.getPropertyValue(HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID);
+      String componentName = (String) resource.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
+      String hostName      = (String) resource.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID);
+
+      String hostComponentState = getClusterDefinition().getHostComponentState(hostName, serviceName, componentName);
+
+      resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, hostComponentState);
+      resource.setProperty(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID, hostComponentState);
+    }
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create the resources based on the cluster definition.
+   */
+  private void initHostComponentResources() {
+    String      clusterName = getClusterDefinition().getClusterName();
+    Set<String> services    = getClusterDefinition().getServices();
+    for (String serviceName : services) {
+      Set<String> hosts = getClusterDefinition().getHosts();
+      for (String hostName : hosts) {
+        Set<String> hostComponents = getClusterDefinition().getHostComponents(serviceName, hostName);
+        for (String componentName : hostComponents) {
+          Resource hostComponent = new ResourceImpl(Resource.Type.HostComponent);
+          hostComponent.setProperty(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID, clusterName);
+          hostComponent.setProperty(HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID, serviceName);
+          hostComponent.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, componentName);
+          hostComponent.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, hostName);
+
+          addResource(hostComponent);
+        }
+      }
+    }
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,100 @@
+/**
+ * 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.server.controller.gsinstaller;
+
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A host resource provider for a gsInstaller defined cluster.
+ */
+public class GSInstallerHostProvider extends GSInstallerResourceProvider{
+
+  // Hosts
+  protected static final String HOST_CLUSTER_NAME_PROPERTY_ID =
+      PropertyHelper.getPropertyId("Hosts", "cluster_name");
+  protected static final String HOST_NAME_PROPERTY_ID =
+      PropertyHelper.getPropertyId("Hosts", "host_name");
+  protected static final String HOST_STATE_PROPERTY_ID =
+      PropertyHelper.getPropertyId("Hosts", "host_state");
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a resource provider based on the given cluster definition.
+   *
+   * @param clusterDefinition  the cluster definition
+   */
+  public GSInstallerHostProvider(ClusterDefinition clusterDefinition) {
+    super(clusterDefinition);
+    initHostResources();
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public Set<String> getPropertyIdsForSchema() {
+    return PropertyHelper.getPropertyIds(Resource.Type.Host);
+  }
+
+  @Override
+  public Map<Resource.Type, String> getKeyPropertyIds() {
+    return PropertyHelper.getKeyPropertyIds(Resource.Type.Host);
+  }
+
+
+  // ----- GSInstallerResourceProvider ---------------------------------------
+
+  @Override
+  public void updateProperties(Resource resource, Request request, Predicate predicate) {
+    Set<String> propertyIds = getRequestPropertyIds(request, predicate);
+    if (propertyIds.contains(HOST_STATE_PROPERTY_ID)) {
+      String hostName = (String) resource.getPropertyValue(HOST_NAME_PROPERTY_ID);
+      resource.setProperty(HOST_STATE_PROPERTY_ID, getClusterDefinition().getHostState(hostName));
+    }
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create the resources based on the cluster definition.
+   */
+  private void initHostResources() {
+    ClusterDefinition clusterDefinition = getClusterDefinition();
+    String            clusterName       = clusterDefinition.getClusterName();
+    Set<String>       hosts             = clusterDefinition.getHosts();
+
+    for (String hostName : hosts) {
+      Resource host = new ResourceImpl(Resource.Type.Host);
+      host.setProperty(HOST_CLUSTER_NAME_PROPERTY_ID, clusterName);
+      host.setProperty(HOST_NAME_PROPERTY_ID, hostName);
+
+      addResource(host);
+    }
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,61 @@
+/**
+ * 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.server.controller.gsinstaller;
+
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A NO-OP resource provider for a gsInstaller defined cluster.
+ */
+public class GSInstallerNoOpProvider extends GSInstallerResourceProvider{
+
+  private final Resource.Type type;
+
+  // ----- GSInstallerResourceProvider ---------------------------------------
+
+  @Override
+  public void updateProperties(Resource resource, Request request, Predicate predicate) {
+    // Do nothing
+  }
+
+  // ----- Constructors ------------------------------------------------------
+
+  public GSInstallerNoOpProvider(Resource.Type type, ClusterDefinition clusterDefinition) {
+    super(clusterDefinition);
+    this.type = type;
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public Set<String> getPropertyIdsForSchema() {
+    return PropertyHelper.getPropertyIds(type);
+  }
+
+  @Override
+  public Map<Resource.Type, String> getKeyPropertyIds() {
+    return PropertyHelper.getKeyPropertyIds(type);
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,92 @@
+/**
+ * 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.server.controller.gsinstaller;
+
+import org.apache.ambari.server.controller.internal.AbstractProviderModule;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A provider module implementation that uses the GSInstaller resource provider.
+ */
+public class GSInstallerProviderModule extends AbstractProviderModule implements GSInstallerStateProvider{
+
+  private final ClusterDefinition clusterDefinition;
+
+  private static final Map<String, String> PORTS = new HashMap<String, String>();
+
+  static {
+    PORTS.put("NAMENODE", "50070");
+    PORTS.put("DATANODE", "50075");
+    PORTS.put("JOBTRACKER", "50030");
+    PORTS.put("TASKTRACKER", "50060");
+    PORTS.put("HBASE_MASTER", "60010");
+  }
+
+  private static final int TIMEOUT = 5000;
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  public GSInstallerProviderModule() {
+    clusterDefinition = new ClusterDefinition(this);
+  }
+
+
+  // ----- GSInstallerStateProvider ------------------------------------------
+
+  @Override
+  public boolean isHealthy(String hostName, String componentName) {
+    String port = PORTS.get(componentName);
+    if (port != null) {
+      StringBuilder sb = new StringBuilder();
+      sb.append("http://").append(hostName);
+      sb.append(":").append(port);
+
+      try {
+        HttpURLConnection connection = (HttpURLConnection) new URL(sb.toString()).openConnection();
+
+        connection.setRequestMethod("HEAD");
+        connection.setConnectTimeout(TIMEOUT);
+        connection.setReadTimeout(TIMEOUT);
+
+        int code = connection.getResponseCode();
+
+        return code >= 200 && code <= 399;
+      } catch (IOException exception) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+
+  // ----- utility methods ---------------------------------------------------
+
+  @Override
+  protected ResourceProvider createResourceProvider(Resource.Type type) {
+    return GSInstallerResourceProvider.getResourceProvider(type, clusterDefinition);
+  }
+}