incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1432294 [2/4] - in /incubator/ambari/trunk: ./ ambari-agent/ ambari-agent/conf/unix/ ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/ ambari-agent/src/main/puppet/modules/hdp-hcat/files/ ambari-agent/src/main/puppet/modules/hdp-h...
Date Fri, 11 Jan 2013 21:35:07 GMT
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java Fri Jan 11 21:35:03 2013
@@ -105,6 +105,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";
@@ -290,6 +293,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
    */

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Fri Jan 11 21:35:03 2013
@@ -105,7 +105,9 @@ public class AmbariManagementControllerI
   private AmbariMetaInfo ambariMetaInfo;
   @Inject
   private Users users;
-
+  @Inject
+  private HostsMap hostsMap;
+  
   final private String masterHostname;
 
   final private static String JDK_RESOURCE_LOCATION =
@@ -898,7 +900,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 +1689,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);
@@ -3156,7 +3158,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/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java Fri Jan 11 21:35:03 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());

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/HostsMap.java Fri Jan 11 21:35:03 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);
+}
+
+}

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,172 @@
+/**
+ * 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 final String clusterName;
+  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>>>();
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Create a cluster definition.
+   */
+  public ClusterDefinition() {
+    this.clusterName = readClusterDefinition();
+  }
+
+
+  // ----- ClusterDefinition -------------------------------------------------
+
+  /**
+   * Get the name of the cluster.
+   *
+   * @return the cluster name
+   */
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  /**
+   * 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;
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Read the gsInstaller cluster definition file.
+   *
+   * @return the cluster name
+   */
+  private String readClusterDefinition() {
+    String clusterName = DEFAULT_CLUSTER_NAME;
+
+    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 {
+          String[] parts = line.split("\\s+");
+          assert(parts.length == 3);
+
+          String serviceName   = parts[0];
+          String componentName = parts[1];
+          String hostName      = parts[2];
+
+          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);
+    }
+    return clusterName;
+  }
+}

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,73 @@
+/**
+ * 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.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");
+
+
+  // ----- 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);
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create the resources based on the cluster definition.
+   */
+  private void initClusterResources() {
+    Resource cluster = new ResourceImpl(Resource.Type.Cluster);
+    cluster.setProperty(CLUSTER_NAME_PROPERTY_ID, getClusterDefinition().getClusterName());
+    addResource(cluster);
+  }
+}

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,84 @@
+/**
+ * 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.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");
+
+
+  // ----- 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);
+  }
+
+
+  // ----- 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/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,89 @@
+/**
+ * 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.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");
+
+
+  // ----- 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);
+  }
+
+
+  // ----- 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/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,82 @@
+/**
+ * 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.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");
+
+
+  // ----- 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);
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create the resources based on the cluster definition.
+   */
+  private void initHostResources() {
+    String      clusterName = getClusterDefinition().getClusterName();
+    Set<String> hosts       = getClusterDefinition().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/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,52 @@
+/**
+ * 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.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;
+
+  // ----- 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/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,44 @@
+/**
+ * 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;
+
+/**
+ * A provider module implementation that uses the GSInstaller resource provider.
+ */
+public class GSInstallerProviderModule extends AbstractProviderModule {
+
+  private final ClusterDefinition clusterDefinition;
+
+  // ----- Constructors ------------------------------------------------------
+
+  public GSInstallerProviderModule() {
+    clusterDefinition = new ClusterDefinition();
+  }
+
+  // ----- utility methods ---------------------------------------------------
+
+  @Override
+  protected ResourceProvider createResourceProvider(Resource.Type type) {
+    return GSInstallerResourceProvider.getResourceProvider(type, clusterDefinition);
+  }
+}

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,148 @@
+/**
+ * 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.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * An abstract resource provider for a gsInstaller defined cluster.
+ */
+public abstract class GSInstallerResourceProvider implements ResourceProvider {
+
+  private final ClusterDefinition clusterDefinition;
+
+  private final Set<Resource> resources = new HashSet<Resource>();
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a resource provider based on the given cluster definition.
+   *
+   * @param clusterDefinition  the cluster definition
+   */
+  public GSInstallerResourceProvider(ClusterDefinition clusterDefinition) {
+    this.clusterDefinition = clusterDefinition;
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public RequestStatus createResources(Request request)
+      throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
+    throw new UnsupportedOperationException("Management operations are not supported");
+  }
+
+  @Override
+  public Set<Resource> getResources(Request request, Predicate predicate)
+      throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+
+    Set<Resource> resultSet = new HashSet<Resource>();
+
+    for (Resource resource : resources) {
+      if (predicate == null || predicate.evaluate(resource)) {
+        resultSet.add(new ResourceImpl(resource));
+      }
+    }
+    return resultSet;
+  }
+
+  @Override
+  public RequestStatus updateResources(Request request, Predicate predicate)
+      throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+    throw new UnsupportedOperationException("Management operations are not supported");
+  }
+
+  @Override
+  public RequestStatus deleteResources(Predicate predicate)
+      throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+    throw new UnsupportedOperationException("Management operations are not supported");
+  }
+
+  @Override
+  public Set<String> checkPropertyIds(Set<String> propertyIds) {
+    propertyIds = new HashSet<String>(propertyIds);
+    propertyIds.removeAll(getPropertyIdsForSchema());
+    return propertyIds;
+  }
+
+
+  // ----- accessors ---------------------------------------------------------
+
+  /**
+   * Get the configuration provider.
+   *
+   * @return the configuration provider
+   */
+  protected ClusterDefinition getClusterDefinition() {
+    return clusterDefinition;
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Add a resource to the set of resources provided by this provider.
+   *
+   * @param resource  the resource to add
+   */
+  protected void addResource(Resource resource) {
+    resources.add(resource);
+  }
+
+  /**
+   * Factory method for obtaining a resource provider based on a given type.
+   *
+   * @param type               the resource type
+   * @param clusterDefinition  the cluster definition
+   *
+   * @return a new resource provider
+   */
+  public static ResourceProvider getResourceProvider(Resource.Type type,
+                                                     ClusterDefinition clusterDefinition) {
+    switch (type) {
+      case Cluster:
+        return new GSInstallerClusterProvider(clusterDefinition);
+      case Service:
+        return new GSInstallerServiceProvider(clusterDefinition);
+      case Component:
+        return new GSInstallerComponentProvider(clusterDefinition);
+      case Host:
+        return new GSInstallerHostProvider(clusterDefinition);
+      case HostComponent:
+        return new GSInstallerHostComponentProvider(clusterDefinition);
+      default:
+        return new GSInstallerNoOpProvider(type, clusterDefinition);
+    }
+  }
+}

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,80 @@
+/**
+ * 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.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A service resource provider for a gsInstaller defined cluster.
+ */
+public class GSInstallerServiceProvider extends GSInstallerResourceProvider{
+
+  // Services
+  protected static final String SERVICE_CLUSTER_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("ServiceInfo", "cluster_name");
+  protected static final String SERVICE_SERVICE_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("ServiceInfo", "service_name");
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Construct a resource provider based on the given cluster definition.
+   *
+   * @param clusterDefinition  the cluster definition
+   */
+  public GSInstallerServiceProvider(ClusterDefinition clusterDefinition) {
+    super(clusterDefinition);
+    initServiceResources();
+  }
+
+
+  // ----- ResourceProvider --------------------------------------------------
+
+  @Override
+  public Set<String> getPropertyIdsForSchema() {
+    return PropertyHelper.getPropertyIds(Resource.Type.Service);
+  }
+
+  @Override
+  public Map<Resource.Type, String> getKeyPropertyIds() {
+    return PropertyHelper.getKeyPropertyIds(Resource.Type.Service);
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Create the resources based on the cluster definition.
+   */
+  private void initServiceResources() {
+    String      clusterName = getClusterDefinition().getClusterName();
+    Set<String> services    = getClusterDefinition().getServices();
+
+    for (String serviceName : services) {
+      Resource service = new ResourceImpl(Resource.Type.Service);
+      service.setProperty(SERVICE_CLUSTER_NAME_PROPERTY_ID, clusterName);
+      service.setProperty(SERVICE_SERVICE_NAME_PROPERTY_ID, serviceName);
+      addResource(service);
+    }
+  }
+}

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java?rev=1432294&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java Fri Jan 11 21:35:03 2013
@@ -0,0 +1,346 @@
+/**
+ * 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.internal;
+
+import org.apache.ambari.server.controller.AmbariServer;
+import org.apache.ambari.server.controller.ganglia.GangliaComponentPropertyProvider;
+import org.apache.ambari.server.controller.ganglia.GangliaHostComponentPropertyProvider;
+import org.apache.ambari.server.controller.ganglia.GangliaHostPropertyProvider;
+import org.apache.ambari.server.controller.ganglia.GangliaReportPropertyProvider;
+import org.apache.ambari.server.controller.ganglia.GangliaHostProvider;
+import org.apache.ambari.server.controller.jmx.JMXHostProvider;
+import org.apache.ambari.server.controller.jmx.JMXPropertyProvider;
+import org.apache.ambari.server.controller.spi.*;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.controller.AmbariManagementController;
+
+import com.google.inject.Inject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * An abstract provider module implementation.
+ */
+public abstract class AbstractProviderModule implements ProviderModule, ResourceProviderObserver, JMXHostProvider, GangliaHostProvider {
+
+  private static final String HOST_CLUSTER_NAME_PROPERTY_ID             = PropertyHelper.getPropertyId("Hosts", "cluster_name");
+  private static final String HOST_NAME_PROPERTY_ID                     = PropertyHelper.getPropertyId("Hosts", "host_name");
+  private static final String HOST_IP_PROPERTY_ID                       = PropertyHelper.getPropertyId("Hosts", "ip");
+  private static final String CLUSTER_NAME_PROPERTY_ID                  = PropertyHelper.getPropertyId("Clusters", "cluster_name");
+  private static final String HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID   = PropertyHelper.getPropertyId("HostRoles", "cluster_name");
+  private static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID      = PropertyHelper.getPropertyId("HostRoles", "host_name");
+  private static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name");
+  private static final String GANGLIA_SERVER                            = "GANGLIA_SERVER";
+  private static final String GANGLIA_MONITOR                           = "GANGLIA_MONITOR";
+  private static final String GANGLIA_SERVER_OLD                        = "GANGLIA_MONITOR_SERVER";
+
+  /**
+   * The map of resource providers.
+   */
+  private final Map<Resource.Type, ResourceProvider> resourceProviders = new HashMap<Resource.Type, ResourceProvider>();
+
+  /**
+   * The map of lists of property providers.
+   */
+  private final Map<Resource.Type,List<PropertyProvider>> propertyProviders = new HashMap<Resource.Type, List<PropertyProvider>>();
+
+  @Inject
+  private AmbariManagementController managementController;
+
+  /**
+   * The map of hosts.
+   */
+  private Map<String, Map<String, String>> clusterHostMap;
+
+  private Map<String, Map<String, String>> clusterHostComponentMap;
+
+  /**
+   * The host name of the Ganglia collector.
+   */
+  private Map<String, String> clusterGangliaCollectorMap;
+
+  private volatile boolean initialized = false;
+
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(AbstractProviderModule.class);
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  /**
+   * Create a default provider module.
+   */
+  public AbstractProviderModule() {
+    if (managementController == null) {
+      managementController = AmbariServer.getController();
+    }
+  }
+
+
+  // ----- ProviderModule ----------------------------------------------------
+
+  @Override
+  public ResourceProvider getResourceProvider(Resource.Type type) {
+    if (!propertyProviders.containsKey(type)) {
+      registerResourceProvider(type);
+    }
+    return resourceProviders.get(type);
+  }
+
+  @Override
+  public List<PropertyProvider> getPropertyProviders(Resource.Type type) {
+
+    if (!propertyProviders.containsKey(type)) {
+      createPropertyProviders(type);
+    }
+    return propertyProviders.get(type);
+  }
+
+
+  // ----- ResourceProviderObserver ------------------------------------------
+
+  @Override
+  public void update(ResourceProviderEvent event) {
+    Resource.Type type = event.getResourceType();
+
+    if (type == Resource.Type.Cluster ||
+        type == Resource.Type.Host ||
+        type == Resource.Type.HostComponent) {
+      resetInit();
+    }
+  }
+
+
+  // ----- JMXHostProvider ---------------------------------------------------
+
+  @Override
+  public String getHostName(String clusterName, String componentName) throws SystemException {
+    checkInit();
+    return clusterHostComponentMap.get(clusterName).get(componentName);
+  }
+
+  @Override
+  public Map<String, String> getHostMapping(String clusterName) throws SystemException {
+    checkInit();
+    return clusterHostMap.get(clusterName);
+  }
+
+
+  // ----- GangliaHostProvider -----------------------------------------------
+
+  @Override
+  public String getGangliaCollectorHostName(String clusterName) throws SystemException {
+    checkInit();
+    return clusterGangliaCollectorMap.get(clusterName);
+  }
+
+
+  // ----- utility methods ---------------------------------------------------
+
+  protected abstract ResourceProvider createResourceProvider(Resource.Type type);
+
+  protected void registerResourceProvider(Resource.Type type) {
+    ResourceProvider resourceProvider = createResourceProvider(type);
+
+    if (resourceProvider instanceof ObservableResourceProvider) {
+      ((ObservableResourceProvider)resourceProvider).addObserver(this);
+    }
+
+    putResourceProvider(type, resourceProvider);
+  }
+
+  protected void putResourceProvider(Resource.Type type, ResourceProvider resourceProvider) {
+    resourceProviders.put( type , resourceProvider);
+  }
+
+  protected void putPropertyProviders(Resource.Type type, List<PropertyProvider> providers) {
+    propertyProviders.put(type, providers);
+  }
+
+  protected void createPropertyProviders(Resource.Type type) {
+
+    List<PropertyProvider> providers = new LinkedList<PropertyProvider>();
+
+    URLStreamProvider streamProvider = new URLStreamProvider();
+
+    switch (type){
+      case Cluster :
+        providers.add(new GangliaReportPropertyProvider(
+            PropertyHelper.getGangliaPropertyIds(type).get("*"),
+            streamProvider,
+            this,
+            PropertyHelper.getPropertyId("Clusters", "cluster_name")));
+        break;
+      case Host :
+        providers.add(new GangliaHostPropertyProvider(
+            PropertyHelper.getGangliaPropertyIds(type),
+            streamProvider,
+            this,
+            PropertyHelper.getPropertyId("Hosts", "cluster_name"),
+            PropertyHelper.getPropertyId("Hosts", "host_name")
+        ));
+        break;
+      case Component :
+        providers.add(new JMXPropertyProvider(
+            PropertyHelper.getJMXPropertyIds(type),
+            streamProvider,
+            this,
+            PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+            null,
+            PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")));
+
+        providers.add(new GangliaComponentPropertyProvider(
+            PropertyHelper.getGangliaPropertyIds(type),
+            streamProvider,
+            this,
+            PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+            PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")));
+        break;
+      case HostComponent:
+        providers.add(new JMXPropertyProvider(
+            PropertyHelper.getJMXPropertyIds(type),
+            streamProvider,
+            this,
+            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+            PropertyHelper.getPropertyId("HostRoles", "host_name"),
+            PropertyHelper.getPropertyId("HostRoles", "component_name")));
+
+        providers.add(new GangliaHostComponentPropertyProvider(
+            PropertyHelper.getGangliaPropertyIds(type),
+            streamProvider,
+            this,
+            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+            PropertyHelper.getPropertyId("HostRoles", "host_name"),
+            PropertyHelper.getPropertyId("HostRoles", "component_name")));
+        break;
+      default :
+        break;
+    }
+    putPropertyProviders(type, providers);
+  }
+
+  private void checkInit() throws SystemException{
+    if (!initialized) {
+      synchronized (this) {
+        if (!initialized) {
+          initProviderMaps();
+          initialized = true;
+        }
+      }
+    }
+  }
+
+  private void resetInit() {
+    if (initialized) {
+      synchronized (this) {
+        initialized = false;
+      }
+    }
+  }
+
+  private void initProviderMaps() throws SystemException{
+    ResourceProvider provider = getResourceProvider(Resource.Type.Cluster);
+    Request          request  = PropertyHelper.getReadRequest(CLUSTER_NAME_PROPERTY_ID);
+
+    try {
+      Set<Resource> clusters = provider.getResources(request, null);
+
+      clusterHostMap             = new HashMap<String, Map<String, String>>();
+      clusterHostComponentMap    = new HashMap<String, Map<String, String>>();
+      clusterGangliaCollectorMap = new HashMap<String, String>();
+
+      for (Resource cluster : clusters) {
+
+        String clusterName = (String) cluster.getPropertyValue(CLUSTER_NAME_PROPERTY_ID);
+
+        // initialize the host map from the known hosts...
+        provider = getResourceProvider(Resource.Type.Host);
+        request  = PropertyHelper.getReadRequest(HOST_NAME_PROPERTY_ID, HOST_IP_PROPERTY_ID);
+
+        Predicate predicate   = new PredicateBuilder().property(HOST_CLUSTER_NAME_PROPERTY_ID).
+            equals(clusterName).toPredicate();
+
+        Set<Resource>       hosts   = provider.getResources(request, predicate);
+        Map<String, String> hostMap = clusterHostMap.get(clusterName);
+
+        if (hostMap == null) {
+          hostMap = new HashMap<String, String>();
+          clusterHostMap.put(clusterName, hostMap);
+        }
+
+        for (Resource host : hosts) {
+          String hostName = (String) host.getPropertyValue(HOST_NAME_PROPERTY_ID);
+          String hostIp   = (String) host.getPropertyValue(HOST_IP_PROPERTY_ID);
+          hostMap.put(hostName, hostIp == null ? hostName : hostIp);
+        }
+
+        // initialize the host component map and Ganglia server from the known hosts components...
+        provider = getResourceProvider(Resource.Type.HostComponent);
+
+        request = PropertyHelper.getReadRequest(HOST_COMPONENT_HOST_NAME_PROPERTY_ID,
+            HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
+
+        predicate = new PredicateBuilder().property(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID).
+            equals(clusterName).toPredicate();
+
+        Set<Resource>       hostComponents   = provider.getResources(request, predicate);
+        Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName);
+
+        if (hostComponentMap == null) {
+          hostComponentMap = new HashMap<String, String>();
+          clusterHostComponentMap.put(clusterName, hostComponentMap);
+        }
+
+        for (Resource hostComponent : hostComponents) {
+          String componentName = (String) hostComponent.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
+          String hostName      = (String) hostComponent.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID);
+
+          hostComponentMap.put(componentName, hostMap.get(hostName));
+
+          // record the Ganglia server for the current cluster
+          if (componentName.equals(GANGLIA_SERVER) || componentName.equals(GANGLIA_MONITOR) ||componentName.equals(GANGLIA_SERVER_OLD)) {
+            clusterGangliaCollectorMap.put(clusterName, clusterHostMap.get(clusterName).get(hostName));
+          }
+        }
+      }
+    } catch (UnsupportedPropertyException e) {
+      if (LOG.isErrorEnabled()) {
+        LOG.error("Caught UnsupportedPropertyException while trying to get the host mappings.", e);
+      }
+      throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
+    } catch (NoSuchResourceException e) {
+      if (LOG.isErrorEnabled()) {
+        LOG.error("Caught NoSuchResourceException exception while trying to get the host mappings.", e);
+      }
+      throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
+    } catch (NoSuchParentResourceException e) {
+      if (LOG.isErrorEnabled()) {
+        LOG.error("Caught NoSuchParentResourceException exception while trying to get the host mappings.", e);
+      }
+      throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
+    }
+  }
+}

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java Fri Jan 11 21:35:03 2013
@@ -18,80 +18,20 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import com.google.inject.Inject;
+import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.AmbariServer;
-import org.apache.ambari.server.controller.ganglia.GangliaComponentPropertyProvider;
-import org.apache.ambari.server.controller.ganglia.GangliaHostComponentPropertyProvider;
-import org.apache.ambari.server.controller.ganglia.GangliaHostPropertyProvider;
-import org.apache.ambari.server.controller.ganglia.GangliaReportPropertyProvider;
-import org.apache.ambari.server.controller.ganglia.GangliaHostProvider;
-import org.apache.ambari.server.controller.jmx.JMXHostProvider;
-import org.apache.ambari.server.controller.jmx.JMXPropertyProvider;
-import org.apache.ambari.server.controller.spi.*;
-import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.controller.AmbariManagementController;
-
-import com.google.inject.Inject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 /**
  * The default provider module implementation.
  */
-public class DefaultProviderModule implements ProviderModule, ResourceProviderObserver, JMXHostProvider, GangliaHostProvider {
-
-  private static final String HOST_CLUSTER_NAME_PROPERTY_ID             = PropertyHelper.getPropertyId("HostRoles", "cluster_name");
-  private static final String HOST_NAME_PROPERTY_ID                     = PropertyHelper.getPropertyId("Hosts", "host_name");
-  private static final String HOST_IP_PROPERTY_ID                       = PropertyHelper.getPropertyId("Hosts", "ip");
-  private static final String HOST_ATTRIBUTES_PROPERTY_ID               = PropertyHelper.getPropertyId("Hosts", "attributes");
-  private static final String CLUSTER_NAME_PROPERTY_ID                  = PropertyHelper.getPropertyId("Clusters", "cluster_name");
-  private static final String HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID   = PropertyHelper.getPropertyId("HostRoles", "cluster_name");
-  private static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID      = PropertyHelper.getPropertyId("HostRoles", "host_name");
-  private static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name");
-  private static final String GANGLIA_SERVER                            = "GANGLIA_SERVER";
-  private static final String GANGLIA_SERVER_OLD                        = "GANGLIA_MONITOR_SERVER";
-
-  /**
-   * The map of resource providers.
-   */
-  private final Map<Resource.Type, ResourceProvider> resourceProviders = new HashMap<Resource.Type, ResourceProvider>();
-
-  /**
-   * The map of lists of property providers.
-   */
-  private final Map<Resource.Type,List<PropertyProvider>> propertyProviders = new HashMap<Resource.Type, List<PropertyProvider>>();
-
+public class DefaultProviderModule extends AbstractProviderModule {
   @Inject
   private AmbariManagementController managementController;
 
-  /**
-   * The map of hosts.
-   */
-  private Map<String, Map<String, String>> clusterHostMap;
-
-  private Map<String, Map<String, String>> clusterHostComponentMap;
-
-  /**
-   * The host name of the Ganglia collector.
-   */
-  private Map<String, String> clusterGangliaCollectorMap;
-
-
-  private volatile boolean initialized = false;
-
-
-
-
-  protected final static Logger LOG =
-      LoggerFactory.getLogger(DefaultProviderModule.class);
-
-
   // ----- Constructors ------------------------------------------------------
 
   /**
@@ -104,247 +44,11 @@ public class DefaultProviderModule imple
   }
 
 
-  // ----- ProviderModule ----------------------------------------------------
-
-  @Override
-  public ResourceProvider getResourceProvider(Resource.Type type) {
-    if (!propertyProviders.containsKey(type)) {
-      createResourceProvider(type);
-    }
-    return resourceProviders.get(type);
-  }
-
-  @Override
-  public List<PropertyProvider> getPropertyProviders(Resource.Type type) {
-
-    if (!propertyProviders.containsKey(type)) {
-      createPropertyProviders(type);
-    }
-    return propertyProviders.get(type);
-  }
-
-
-  // ----- ResourceProviderObserver ------------------------------------------
-
-  @Override
-  public void update(ResourceProviderEvent event) {
-    Resource.Type type = event.getResourceType();
-
-    if (type == Resource.Type.Cluster ||
-        type == Resource.Type.Host ||
-        type == Resource.Type.HostComponent) {
-      resetInit();
-    }
-  }
-
-
-  // ----- JMXHostProvider ---------------------------------------------------
-
-  @Override
-  public String getHostName(String clusterName, String componentName) throws SystemException {
-    checkInit();
-    return clusterHostComponentMap.get(clusterName).get(componentName);
-  }
-
-  @Override
-  public Map<String, String> getHostMapping(String clusterName) throws SystemException {
-    checkInit();
-    return clusterHostMap.get(clusterName);
-  }
-
-
-  // ----- GangliaHostProvider -----------------------------------------------
-
-  @Override
-  public String getGangliaCollectorHostName(String clusterName) throws SystemException {
-    checkInit();
-    return clusterGangliaCollectorMap.get(clusterName);
-  }
-
-
   // ----- utility methods ---------------------------------------------------
 
-  protected void putResourceProvider(Resource.Type type, ResourceProvider resourceProvider) {
-    resourceProviders.put( type , resourceProvider);
-  }
-
-  protected void createResourceProvider(Resource.Type type) {
-    ResourceProvider resourceProvider =
-        ResourceProviderImpl.getResourceProvider(type, PropertyHelper.getPropertyIds(type),
+  @Override
+  protected ResourceProvider createResourceProvider(Resource.Type type) {
+    return ResourceProviderImpl.getResourceProvider(type, PropertyHelper.getPropertyIds(type),
             PropertyHelper.getKeyPropertyIds(type), managementController);
-
-    if (resourceProvider instanceof ObservableResourceProvider) {
-      ((ObservableResourceProvider)resourceProvider).addObserver(this);
-    }
-
-    putResourceProvider(type, resourceProvider);
-  }
-
-  protected void putPropertyProviders(Resource.Type type, List<PropertyProvider> providers) {
-    propertyProviders.put(type, providers);
-  }
-
-  protected void createPropertyProviders(Resource.Type type) {
-
-    List<PropertyProvider> providers = new LinkedList<PropertyProvider>();
-
-    URLStreamProvider streamProvider = new URLStreamProvider();
-
-    switch (type){
-      case Cluster :
-        providers.add(new GangliaReportPropertyProvider(
-            PropertyHelper.getGangliaPropertyIds(type).get("*"),
-            streamProvider,
-            this,
-            PropertyHelper.getPropertyId("Clusters", "cluster_name")));
-        break;
-      case Host :
-        providers.add(new GangliaHostPropertyProvider(
-            PropertyHelper.getGangliaPropertyIds(type),
-            streamProvider,
-            this,
-            PropertyHelper.getPropertyId("Hosts", "cluster_name"),
-            PropertyHelper.getPropertyId("Hosts", "host_name")
-        ));
-        break;
-      case Component :
-        providers.add(new JMXPropertyProvider(
-            PropertyHelper.getJMXPropertyIds(type),
-            streamProvider,
-            this,
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
-            null,
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")));
-
-        providers.add(new GangliaComponentPropertyProvider(
-            PropertyHelper.getGangliaPropertyIds(type),
-            streamProvider,
-            this,
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")));
-        break;
-      case HostComponent:
-        providers.add(new JMXPropertyProvider(
-            PropertyHelper.getJMXPropertyIds(type),
-            streamProvider,
-            this,
-            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
-            PropertyHelper.getPropertyId("HostRoles", "host_name"),
-            PropertyHelper.getPropertyId("HostRoles", "component_name")));
-
-        providers.add(new GangliaHostComponentPropertyProvider(
-            PropertyHelper.getGangliaPropertyIds(type),
-            streamProvider,
-            this,
-            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
-            PropertyHelper.getPropertyId("HostRoles", "host_name"),
-            PropertyHelper.getPropertyId("HostRoles", "component_name")));
-        break;
-      default :
-        break;
-    }
-    putPropertyProviders(type, providers);
-  }
-
-  private void checkInit() throws SystemException{
-    if (!initialized) {
-      synchronized (this) {
-        if (!initialized) {
-          initProviderMaps();
-          initialized = true;
-        }
-      }
-    }
-  }
-
-  private void resetInit() {
-    if (initialized) {
-      synchronized (this) {
-        initialized = false;
-      }
-    }
-  }
-
-  private void initProviderMaps() throws SystemException{
-    ResourceProvider provider = getResourceProvider(Resource.Type.Cluster);
-    Request          request  = PropertyHelper.getReadRequest(CLUSTER_NAME_PROPERTY_ID);
-
-    try {
-      Set<Resource> clusters = provider.getResources(request, null);
-
-      clusterHostMap             = new HashMap<String, Map<String, String>>();
-      clusterHostComponentMap    = new HashMap<String, Map<String, String>>();
-      clusterGangliaCollectorMap = new HashMap<String, String>();
-
-      for (Resource cluster : clusters) {
-
-        String clusterName = (String) cluster.getPropertyValue(CLUSTER_NAME_PROPERTY_ID);
-
-        // initialize the host map from the known hosts...
-        provider = getResourceProvider(Resource.Type.Host);
-        request  = PropertyHelper.getReadRequest(HOST_NAME_PROPERTY_ID, HOST_IP_PROPERTY_ID,
-            HOST_ATTRIBUTES_PROPERTY_ID);
-
-        Predicate predicate   = new PredicateBuilder().property(HOST_CLUSTER_NAME_PROPERTY_ID).
-            equals(clusterName).toPredicate();
-
-        Set<Resource>       hosts   = provider.getResources(request, predicate);
-        Map<String, String> hostMap = clusterHostMap.get(clusterName);
-
-        if (hostMap == null) {
-          hostMap = new HashMap<String, String>();
-          clusterHostMap.put(clusterName, hostMap);
-        }
-
-        for (Resource host : hosts) {
-          hostMap.put((String) host.getPropertyValue(HOST_NAME_PROPERTY_ID),
-              (String) host.getPropertyValue(HOST_IP_PROPERTY_ID));
-        }
-
-        // initialize the host component map and Ganglia server from the known hosts components...
-        provider = getResourceProvider(Resource.Type.HostComponent);
-
-        request = PropertyHelper.getReadRequest(HOST_COMPONENT_HOST_NAME_PROPERTY_ID,
-            HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
-
-        predicate = new PredicateBuilder().property(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID).
-            equals(clusterName).toPredicate();
-
-        Set<Resource>       hostComponents   = provider.getResources(request, predicate);
-        Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName);
-
-        if (hostComponentMap == null) {
-          hostComponentMap = new HashMap<String, String>();
-          clusterHostComponentMap.put(clusterName, hostComponentMap);
-        }
-
-        for (Resource hostComponent : hostComponents) {
-          String componentName = (String) hostComponent.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
-          String hostName      = (String) hostComponent.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID);
-
-          hostComponentMap.put(componentName, hostMap.get(hostName));
-
-          // record the Ganglia server for the current cluster
-          if (componentName.equals(GANGLIA_SERVER) || componentName.equals(GANGLIA_SERVER_OLD)) {
-            clusterGangliaCollectorMap.put(clusterName, clusterHostMap.get(clusterName).get(hostName));
-          }
-        }
-      }
-    } catch (UnsupportedPropertyException e) {
-      if (LOG.isErrorEnabled()) {
-        LOG.error("Caught UnsupportedPropertyException while trying to get the host mappings.", e);
-      }
-      throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
-    } catch (NoSuchResourceException e) {
-      if (LOG.isErrorEnabled()) {
-        LOG.error("Caught NoSuchResourceException exception while trying to get the host mappings.", e);
-      }
-      throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
-    } catch (NoSuchParentResourceException e) {
-      if (LOG.isErrorEnabled()) {
-        LOG.error("Caught NoSuchParentResourceException exception while trying to get the host mappings.", e);
-      }
-      throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
-    }
   }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java Fri Jan 11 21:35:03 2013
@@ -55,6 +55,27 @@ public class ResourceImpl implements Res
     this.type = type;
   }
 
+  /**
+   * Copy constructor
+   *
+   * @param resource  the resource to copy
+   */
+  public ResourceImpl(Resource resource) {
+    this.type = resource.getType();
+
+    for (Map.Entry<String, Map<String, Object>> categoryEntry : resource.getPropertiesMap().entrySet()) {
+      String category = categoryEntry.getKey();
+      Map<String, Object> propertyMap = categoryEntry.getValue();
+      if (propertyMap != null) {
+        for (Map.Entry<String, Object> propertyEntry : propertyMap.entrySet()) {
+          String propertyId    = (category == null ? "" : category + "/") + propertyEntry.getKey();
+          Object propertyValue = propertyEntry.getValue();
+          setProperty(propertyId, propertyValue);
+        }
+      }
+    }
+  }
+
 
   // ----- Resource ----------------------------------------------------------
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java Fri Jan 11 21:35:03 2013
@@ -18,32 +18,22 @@
 
 package org.apache.ambari.server.controller.jdbc;
 
-import org.apache.ambari.server.controller.internal.DefaultProviderModule;
+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 org.apache.ambari.server.controller.utilities.DBHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 
 /**
- * The default provider module implementation.
+ * A provider module implementation that uses the JDBC resource provider.
  */
-public class JDBCProviderModule extends DefaultProviderModule {
-
-
-  // ----- Constructors ------------------------------------------------------
-
-  /**
-   * Create a default provider module.
-   */
-  public JDBCProviderModule() {
-    super();
-  }
-
+public class JDBCProviderModule extends AbstractProviderModule {
   // ----- utility methods ---------------------------------------------------
 
   @Override
-  protected void createResourceProvider(Resource.Type type) {
-    putResourceProvider( type, new JDBCResourceProvider(DBHelper.CONNECTION_FACTORY, type,
+  protected ResourceProvider createResourceProvider(Resource.Type type) {
+    return new JDBCResourceProvider(DBHelper.CONNECTION_FACTORY, type,
         PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type)));
+        PropertyHelper.getKeyPropertyIds(type));
   }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ProviderModule.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ProviderModule.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ProviderModule.java Fri Jan 11 21:35:03 2013
@@ -33,5 +33,12 @@ public interface ProviderModule {
    */
   public ResourceProvider getResourceProvider(Resource.Type type);
 
+  /**
+   * Get the list of property providers for the given resource type.
+   *
+   * @param type  the resource type
+   *
+   * @return the list of property providers
+   */
   public List<PropertyProvider> getPropertyProviders(Resource.Type type);
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java Fri Jan 11 21:35:03 2013
@@ -58,7 +58,7 @@ public class ServiceConfigMappingDAO {
                 + " WHERE "
                 + " config.clusterId = ?1"
                 + " AND config.serviceName = ?2"
-                + " AND config.configType IN ?5",
+                + " AND config.configType IN ?3",
             ServiceConfigMappingEntity.class);
     return daoUtils.selectList(query, clusterId, serviceName, configTypes);
   }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java?rev=1432294&r1=1432293&r2=1432294&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java Fri Jan 11 21:35:03 2013
@@ -17,10 +17,26 @@
  */
 package org.apache.ambari.server.utils;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.xml.bind.JAXBException;
+
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.controller.HostsMap;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
@@ -32,15 +48,6 @@ import org.codehaus.jackson.map.JsonMapp
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.map.SerializationConfig;
 
-import javax.xml.bind.JAXBException;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.nio.charset.Charset;
-import java.util.*;
-
 public class StageUtils {
   private static Log LOG = LogFactory.getLog(StageUtils.class);
   
@@ -99,6 +106,7 @@ public class StageUtils {
     Stage s = new Stage(requestId, "/tmp", "cluster1");
     s.setStageId(stageId);
     long now = System.currentTimeMillis();
+    String filename = null;
     s.addHostRoleExecutionCommand(hostname, Role.NAMENODE, RoleCommand.INSTALL,
         new ServiceComponentHostInstallEvent("NAMENODE", hostname, now, "HDP-1.2.0"),
         "cluster1", "HDFS");
@@ -150,7 +158,8 @@ public class StageUtils {
     return mapper.readValue(is, clazz);
   }
   
-  public static Map<String, List<String>> getClusterHostInfo(Cluster cluster) {
+  
+  public static Map<String, List<String>> getClusterHostInfo(Cluster cluster, HostsMap hostsMap) {
     Map<String, List<String>> info = new HashMap<String, List<String>>();
     if (cluster.getServices() != null) {
       for (String serviceName : cluster.getServices().keySet()) {
@@ -168,12 +177,13 @@ public class StageUtils {
                 && !scomp.getServiceComponentHosts().isEmpty()) {
               List<String> hostList = new ArrayList<String>();
               for (String host: scomp.getServiceComponentHosts().keySet()) {
-                hostList.add(host);
+                String mappedHost = hostsMap.getHostMap(host);
+                hostList.add(mappedHost);
               }
               info.put(clusterInfoKey, hostList);
             }
             //Add ambari db server
-            info.put("ambari_db_server_host", Arrays.asList(getHostName()));
+            info.put("ambari_db_server_host", Arrays.asList(hostsMap.getHostMap(getHostName())));
           }
         }
       }



Mime
View raw message