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 [11/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...

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,188 @@
+/**
+ * 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 org.apache.ambari.server.controller.utilities.PredicateHelper;
+
+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)) {
+        ResourceImpl newResource = new ResourceImpl(resource);
+        updateProperties(newResource, request, predicate);
+        resultSet.add(newResource);
+      }
+    }
+    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);
+  }
+
+
+  // ----- GSInstallerResourceProvider ---------------------------------------
+
+  /**
+   * Update the resource with any properties handled by the resource provider.
+   *
+   * @param resource   the resource to update
+   * @param request    the request
+   * @param predicate  the predicate
+   */
+  public abstract void updateProperties(Resource resource, Request request, Predicate predicate);
+
+  /**
+   * Get the set of property ids required to satisfy the given request.
+   *
+   * @param request              the request
+   * @param predicate            the predicate
+   *
+   * @return the set of property ids needed to satisfy the request
+   */
+  protected Set<String> getRequestPropertyIds(Request request, Predicate predicate) {
+    Set<String> propertyIds  = request.getPropertyIds();
+
+    // if no properties are specified, then return them all
+    if (propertyIds == null || propertyIds.isEmpty()) {
+      return new HashSet<String>(getPropertyIdsForSchema());
+    }
+
+    propertyIds = new HashSet<String>(propertyIds);
+
+    if (predicate != null) {
+      propertyIds.addAll(PredicateHelper.getPropertyIds(predicate));
+    }
+    return propertyIds;
+  }
+
+  /**
+   * 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,96 @@
+/**
+ * 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 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");
+  protected static final String SERVICE_SERVICE_STATE_PROPERTY_ID   = PropertyHelper.getPropertyId("ServiceInfo", "state");
+
+
+  // ----- 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);
+  }
+
+
+  // ----- GSInstallerResourceProvider ---------------------------------------
+
+  @Override
+  public void updateProperties(Resource resource, Request request, Predicate predicate) {
+    Set<String> propertyIds = getRequestPropertyIds(request, predicate);
+    if (propertyIds.contains(SERVICE_SERVICE_STATE_PROPERTY_ID)) {
+      String serviceName = (String) resource.getPropertyValue(SERVICE_SERVICE_NAME_PROPERTY_ID);
+      resource.setProperty(SERVICE_SERVICE_STATE_PROPERTY_ID, getClusterDefinition().getServiceState(serviceName));
+    }
+  }
+
+
+  // ----- 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerStateProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerStateProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerStateProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerStateProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,35 @@
+/**
+ * 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;
+
+/**
+ * Interface to provide component state to the gsInstaller resource provider.
+ */
+public interface GSInstallerStateProvider {
+  /**
+   * Determine whether or not the host component identified by the given host name
+   * and component name is healthy.
+   *
+   * @param hostName       the host name
+   * @param componentName  the component name
+   *
+   * @return true if the host component is healthy
+   */
+  public boolean isHealthy(String hostName, String componentName);
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,318 @@
+/**
+ * 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 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";
+
+  /**
+   * 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 host components.
+   */
+  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);
+  }
+
+
+  // ----- 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")));
+        
+        providers.add(new HttpProxyPropertyProvider(
+            new URLStreamProvider(1500),
+            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);
+
+      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 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 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, hostName);
+
+          // record the Ganglia server for the current cluster
+          if (componentName.equals(GANGLIA_SERVER)) {
+            clusterGangliaCollectorMap.put(clusterName, 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.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/internal/DefaultProviderModule.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java Mon Feb  4 02:23:55 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.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/internal/HostResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java Mon Feb  4 02:23:55 2013
@@ -68,6 +68,8 @@ class HostResourceProvider extends Resou
       PropertyHelper.getPropertyId("Hosts", "host_health_report");
   protected static final String HOST_STATE_PROPERTY_ID =
       PropertyHelper.getPropertyId("Hosts", "host_state");
+  protected static final String HOST_LAST_AGENT_ENV_PROPERTY_ID =
+      PropertyHelper.getPropertyId("Hosts", "last_agent_env");
 
   private static Set<String> pkPropertyIds =
       new HashSet<String>(Arrays.asList(new String[]{
@@ -167,6 +169,8 @@ class HostResourceProvider extends Resou
           response.getRackInfo(), requestedIds);
       setResourceProperty(resource, HOST_LAST_HEARTBEAT_TIME_PROPERTY_ID,
           response.getLastHeartbeatTime(), requestedIds);
+      setResourceProperty(resource, HOST_LAST_AGENT_ENV_PROPERTY_ID,
+          response.getLastAgentEnv(), requestedIds);
       setResourceProperty(resource, HOST_LAST_REGISTRATION_TIME_PROPERTY_ID,
           response.getLastRegistrationTime(), requestedIds);
       setResourceProperty(resource, HOST_HOST_STATUS_PROPERTY_ID,

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java?rev=1442010&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java Mon Feb  4 02:23:55 2013
@@ -0,0 +1,151 @@
+/**
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.PropertyProvider;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.controller.utilities.StreamProvider;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Property provider that is used to read HTTP data from another server.
+ */
+public class HttpProxyPropertyProvider implements PropertyProvider {
+
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(HttpProxyPropertyProvider.class);
+
+  private static final Map<String, String> URL_TEMPLATES = new HashMap<String, String>();
+  private static final Map<String, String> MAPPINGS = new HashMap<String, String>();
+  
+  static {
+    URL_TEMPLATES.put("NAGIOS_SERVER", "http://%s/ambarinagios/nagios/nagios_alerts.php?q1=alerts&alert_type=all");
+    
+    MAPPINGS.put("NAGIOS_SERVER", PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
+  }
+  
+  private StreamProvider streamProvider = null;
+  // !!! not yet used, but make consistent
+  private String clusterNamePropertyId = null;
+  private String hostNamePropertyId = null;
+  private String componentNamePropertyId = null;
+  
+  private Set<String> propertyIds = new HashSet<String>();
+  
+  public HttpProxyPropertyProvider(
+      StreamProvider stream,
+      String clusterNamePropertyId,
+      String hostNamePropertyId,
+      String componentNamePropertyId) {
+    this.streamProvider = stream;
+    this.clusterNamePropertyId = clusterNamePropertyId;
+    this.hostNamePropertyId = hostNamePropertyId;
+    this.componentNamePropertyId = componentNamePropertyId;
+    
+    propertyIds.addAll(MAPPINGS.values());
+  }
+
+  /**
+   * This method only checks if an HTTP-type property should be fulfilled.  No
+   * modification is performed on the resources.
+   */
+  @Override
+  public Set<Resource> populateResources(Set<Resource> resources,
+      Request request, Predicate predicate) throws SystemException {
+    
+    Set<String> ids = PropertyHelper.getRequestPropertyIds(propertyIds, request, predicate);
+    
+    if (0 == ids.size())
+      return resources;
+
+    for (Resource resource : resources) {
+      
+      Object hostName = resource.getPropertyValue(hostNamePropertyId);
+      Object componentName = resource.getPropertyValue(componentNamePropertyId);
+      
+      if (null != hostName && null != componentName &&
+          MAPPINGS.containsKey(componentName.toString()) &&
+          URL_TEMPLATES.containsKey(componentName.toString())) {
+        
+        String template = URL_TEMPLATES.get(componentName.toString());
+        String propertyId = MAPPINGS.get(componentName.toString());
+        String url = String.format(template, hostName);
+        
+        getHttpResponse(resource, url, propertyId);
+      }
+    }
+    
+    return resources;
+  }
+
+  @Override
+  public Set<String> getPropertyIds() {
+    return propertyIds;
+  }
+
+  @Override
+  public Set<String> checkPropertyIds(Set<String> propertyIds) {
+    if (!this.propertyIds.containsAll(propertyIds)) {
+      Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);
+      unsupportedPropertyIds.removeAll(this.propertyIds);
+      return unsupportedPropertyIds;
+    }
+    return Collections.emptySet();
+  }
+  
+  private void getHttpResponse(Resource r, String url, String propertyIdToSet) {
+    
+    InputStream in = null;
+    try {
+      in = streamProvider.readFrom(url);
+      
+      String str = IOUtils.toString(in, "UTF-8");
+      
+      r.setProperty(propertyIdToSet, str);
+    }
+    catch (IOException ioe) {
+      LOG.error("Error reading HTTP response from " + url);
+    }
+    finally {
+      if (null != in) {
+        try {
+          in.close();
+        }
+        catch (IOException ioe) {
+          // 
+        }
+      }
+    }
+    
+  }
+
+}

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.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/internal/ResourceImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java Mon Feb  4 02:23:55 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.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/internal/URLStreamProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java Mon Feb  4 02:23:55 2013
@@ -18,20 +18,38 @@
 
 package org.apache.ambari.server.controller.internal;
 
-import org.apache.ambari.server.controller.utilities.StreamProvider;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
 
+import org.apache.ambari.server.controller.utilities.StreamProvider;
+
 /**
  * URL based implementation of a stream provider.
  */
 public class URLStreamProvider implements StreamProvider {
+  
+  private int connTimeout = -1;
+  
+  public URLStreamProvider() {
+  }
+  
+  /**
+   * Provide the connection timeout for the underlying connection.
+   * 
+   * @param connectionTimeout time, in milliseconds, to attempt a connection
+   */
+  public URLStreamProvider(int connectionTimeout) {
+    connTimeout = connectionTimeout;
+  }
+  
   @Override
   public InputStream readFrom(String spec) throws IOException {
     URLConnection connection = new URL(spec).openConnection();
+    if (connTimeout > 0) {
+      connection.setConnectTimeout(connTimeout);
+    }
     connection.setDoOutput(true);
     return connection.getInputStream();
   }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.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/jdbc/JDBCProviderModule.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCProviderModule.java Mon Feb  4 02:23:55 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.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/jmx/JMXHostProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java Mon Feb  4 02:23:55 2013
@@ -37,16 +37,4 @@ public interface JMXHostProvider {
    * @throws SystemException of unable to ge the JMX host name
    */
   public String getHostName(String clusterName, String componentName) throws SystemException;
-
-
-  /**
-   * Get the host name mappings for the given cluster name.
-   *
-   * @param clusterName  the cluster name
-   *
-   * @return the host name mappings
-   *
-   * @throws SystemException if unable to get the host mappings
-   */
-  public Map<String, String> getHostMapping(String clusterName) throws SystemException ;
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXMetricHolder.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXMetricHolder.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/jmx/JMXMetricHolder.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXMetricHolder.java Mon Feb  4 02:23:55 2013
@@ -24,7 +24,7 @@ import java.util.Map;
 /**
  *
  */
-public class JMXMetricHolder {
+public final class JMXMetricHolder {
 
   private List<Map<String, Object>> beans;
 

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.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/jmx/JMXPropertyProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java Mon Feb  4 02:23:55 2013
@@ -22,11 +22,14 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.spi.*;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.codehaus.jackson.map.DeserializationConfig;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.ObjectReader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -62,6 +65,8 @@ public class JMXPropertyProvider impleme
 
   private final String componentNamePropertyId;
 
+  private final static ObjectReader objectReader;
+
 
   static {
     JMX_PORTS.put("NAMENODE",     "50070");
@@ -69,6 +74,10 @@ public class JMXPropertyProvider impleme
     JMX_PORTS.put("JOBTRACKER",   "50030");
     JMX_PORTS.put("TASKTRACKER",  "50060");
     JMX_PORTS.put("HBASE_MASTER", "60010");
+
+    ObjectMapper objectMapper = new ObjectMapper();
+    objectMapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false);
+    objectReader = objectMapper.reader(JMXMetricHolder.class);
   }
 
   protected final static Logger LOG =
@@ -159,12 +168,6 @@ public class JMXPropertyProvider impleme
     }
 
     String clusterName   = (String) resource.getPropertyValue(clusterNamePropertyId);
-
-    // TODO : what should we do if the host mapping is null?
-    if (jmxHostProvider.getHostMapping(clusterName) == null) {
-      return true;
-    }
-
     String componentName = (String) resource.getPropertyValue(componentNamePropertyId);
     String port          = JMX_PORTS.get(componentName);
 
@@ -173,8 +176,7 @@ public class JMXPropertyProvider impleme
       hostName = jmxHostProvider.getHostName(clusterName, componentName);
     }
     else {
-      String name = (String) resource.getPropertyValue(hostNamePropertyId);
-      hostName = jmxHostProvider.getHostMapping(clusterName).get(name);
+      hostName = (String) resource.getPropertyValue(hostNamePropertyId);
     }
 
     Map<String, PropertyInfo> metrics = componentMetrics.get(componentName);
@@ -184,9 +186,10 @@ public class JMXPropertyProvider impleme
     }
 
     String spec = getSpec(hostName + ":" + port);
-
+    InputStream in = null;
     try {
-      JMXMetricHolder metricHolder = new ObjectMapper().readValue(streamProvider.readFrom(spec), JMXMetricHolder.class);
+      in = streamProvider.readFrom(spec);
+      JMXMetricHolder metricHolder = objectReader.readValue(in);
 
       Map<String, Map<String, Object>> categories = new HashMap<String, Map<String, Object>>();
 
@@ -247,8 +250,18 @@ public class JMXPropertyProvider impleme
         }
       }
     } catch (IOException e) {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Caught exception getting JMX metrics : spec=" + spec, e);
+      if (LOG.isErrorEnabled()) {
+        LOG.error("Caught exception getting JMX metrics : spec=" + spec, e);
+      }
+    } finally {
+      if (in != null) {
+        try {
+          in.close();
+        } catch (IOException e) {
+          if (LOG.isWarnEnabled()) {
+            LOG.warn("Unable to close http input steam : spec=" + spec, e);
+          }
+        }
       }
     }
 

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ProviderModule.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/spi/ProviderModule.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ProviderModule.java Mon Feb  4 02:23:55 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java Mon Feb  4 02:23:55 2013
@@ -108,4 +108,9 @@ public class ClusterDAO {
     remove(findByName(clusterName));
   }
 
+  @Transactional
+  public void removeByPK(long id) {
+    remove(findById(id));
+  }
+
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigMappingDAO.java Mon Feb  4 02:23:55 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/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java Mon Feb  4 02:23:55 2013
@@ -159,7 +159,7 @@ public class ClusterEntity {
 
   private Collection<StageEntity> stages;
 
-  @OneToMany(mappedBy = "cluster")
+  @OneToMany(mappedBy = "cluster", cascade = CascadeType.REMOVE)
   public Collection<StageEntity> getStages() {
     return stages;
   }
@@ -169,7 +169,7 @@ public class ClusterEntity {
   }
   
   private Collection<ClusterConfigEntity> configEntities;
-  @OneToMany(mappedBy = "clusterEntity")
+  @OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
   public Collection<ClusterConfigEntity> getClusterConfigEntities() {
     return configEntities;
   }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java Mon Feb  4 02:23:55 2013
@@ -105,7 +105,7 @@ public class ClusterServiceEntity {
 
   private ServiceDesiredStateEntity serviceDesiredStateEntity;
 
-  @OneToOne(mappedBy = "clusterServiceEntity")
+  @OneToOne(mappedBy = "clusterServiceEntity", cascade = CascadeType.ALL)
   public ServiceDesiredStateEntity getServiceDesiredStateEntity() {
     return serviceDesiredStateEntity;
   }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java Mon Feb  4 02:23:55 2013
@@ -158,7 +158,7 @@ public class HostComponentStateEntity {
 
   private Collection<HostComponentConfigMappingEntity> configMappingEntities;
   @OneToMany(mappedBy = "hostComponentStateEntity", cascade = CascadeType.ALL)
-  public Collection<HostComponentConfigMappingEntity> getHostComponentConfigMappingEntities() {
+   public Collection<HostComponentConfigMappingEntity> getHostComponentConfigMappingEntities() {
     return configMappingEntities;
   }
 

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java Mon Feb  4 02:23:55 2013
@@ -245,7 +245,7 @@ public class HostRoleCommandEntity {
 
   private ExecutionCommandEntity executionCommand;
 
-  @OneToOne(mappedBy = "hostRoleCommand")
+  @OneToOne(mappedBy = "hostRoleCommand", cascade = CascadeType.REMOVE)
   public ExecutionCommandEntity getExecutionCommand() {
     return executionCommand;
   }
@@ -277,4 +277,4 @@ public class HostRoleCommandEntity {
   public void setHost(HostEntity host) {
     this.host = host;
   }
-}
\ No newline at end of file
+}

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java Mon Feb  4 02:23:55 2013
@@ -115,7 +115,11 @@ public class ServiceDesiredStateEntity {
   private ClusterServiceEntity clusterServiceEntity;
 
   @OneToOne
-  @javax.persistence.JoinColumns({@javax.persistence.JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false), @javax.persistence.JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false)})
+  @javax.persistence.JoinColumns(
+      {
+          @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+          @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false)
+      })
   public ClusterServiceEntity getClusterServiceEntity() {
     return clusterServiceEntity;
   }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java Mon Feb  4 02:23:55 2013
@@ -111,7 +111,7 @@ public class StageEntity {
 
   private Collection<HostRoleCommandEntity> hostRoleCommands;
 
-  @OneToMany(mappedBy = "stage")
+  @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
   public Collection<HostRoleCommandEntity> getHostRoleCommands() {
     return hostRoleCommands;
   }
@@ -122,7 +122,7 @@ public class StageEntity {
 
   private Collection<RoleSuccessCriteriaEntity> roleSuccessCriterias;
 
-  @OneToMany(mappedBy = "stage")
+  @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
   public Collection<RoleSuccessCriteriaEntity> getRoleSuccessCriterias() {
     return roleSuccessCriterias;
   }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java Mon Feb  4 02:23:55 2013
@@ -101,4 +101,6 @@ public interface Cluster {
   public void deleteService(String serviceName) throws AmbariException;
 
   public boolean canBeRemoved();
+
+  public void delete() throws AmbariException;
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java Mon Feb  4 02:23:55 2013
@@ -42,7 +42,7 @@ public class ConfigImpl implements Confi
   private String versionTag;
   private Map<String, String> properties;
   private ClusterConfigEntity entity;
-  
+
   @Inject
   private ClusterDAO clusterDAO;
   @Inject
@@ -111,7 +111,7 @@ public class ConfigImpl implements Confi
   
   @Transactional
   @Override
-  public void persist() {
+  public synchronized void persist() {
     
     ClusterEntity clusterEntity = clusterDAO.findById(cluster.getClusterId());
     
@@ -128,7 +128,7 @@ public class ConfigImpl implements Confi
     clusterEntity.getClusterConfigEntities().add(entity);
     clusterDAO.merge(clusterEntity);
     cluster.refresh();
-    
+
   }
 
 

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java Mon Feb  4 02:23:55 2013
@@ -21,6 +21,7 @@ package org.apache.ambari.server.state;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ambari.server.agent.AgentEnv;
 import org.apache.ambari.server.agent.DiskInfo;
 import org.apache.ambari.server.agent.HostInfo;
 import org.apache.ambari.server.controller.HostResponse;
@@ -210,6 +211,16 @@ public interface Host {
   public void setLastHeartbeatTime(long lastHeartbeatTime);
 
   /**
+   * Sets the latest agent environment that arrived in a heartbeat.
+   */
+  public void setLastAgentEnv(AgentEnv env);
+  
+  /**
+   * Gets the latest agent environment that arrived in a heartbeat.
+   */
+  public AgentEnv getLastAgentEnv();
+  
+  /**
    * Version of the Ambari Agent running on the host
    * @return the agentVersion
    */

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java Mon Feb  4 02:23:55 2013
@@ -76,11 +76,12 @@ public interface Service {
    */
   public boolean canBeRemoved();
 
-  public void removeAllComponents() throws AmbariException;
+  public void deleteAllComponents() throws AmbariException;
 
   public void deleteServiceComponent(String componentName)
       throws AmbariException;
 
   public boolean isClientOnlyService();
 
+  public void delete() throws AmbariException;
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java Mon Feb  4 02:23:55 2013
@@ -75,11 +75,13 @@ public interface ServiceComponent {
 
   public boolean canBeRemoved();
 
-  public void removeAllServiceComponentHosts() throws AmbariException;
+  public void deleteAllServiceComponentHosts() throws AmbariException;
 
-  public void removeServiceComponentHosts(String hostname)
+  public void deleteServiceComponentHosts(String hostname)
       throws AmbariException;
 
   ServiceComponentHost addServiceComponentHost(
       String hostName) throws AmbariException;
+
+  public void delete() throws AmbariException;
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java Mon Feb  4 02:23:55 2013
@@ -104,4 +104,6 @@ public interface ServiceComponentHost {
   public void debugDump(StringBuilder sb);
 
   public boolean canBeRemoved();
+
+  public void delete() throws AmbariException;
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java Mon Feb  4 02:23:55 2013
@@ -487,30 +487,27 @@ public class ServiceComponentImpl implem
 
   @Override
   public synchronized boolean canBeRemoved() {
-    State state = getDesiredState();
-    if (state != State.INIT
-        && state != State.UNINSTALLED) {
+    if (!getDesiredState().isRemovableState()) {
       return false;
     }
 
-    boolean safeToRemove = true;
     for (ServiceComponentHost sch : hostComponents.values()) {
       if (!sch.canBeRemoved()) {
-        safeToRemove = false;
         LOG.warn("Found non removable hostcomponent when trying to"
             + " delete service component"
             + ", clusterName=" + getClusterName()
             + ", serviceName=" + getServiceName()
             + ", componentName=" + getName()
             + ", hostname=" + sch.getHostName());
-        break;
+        return false;
       }
     }
-    return safeToRemove;
+    return true;
   }
 
   @Override
-  public synchronized void removeAllServiceComponentHosts()
+  @Transactional
+  public synchronized void deleteAllServiceComponentHosts()
       throws AmbariException {
     LOG.info("Deleting all servicecomponenthosts for component"
         + ", clusterName=" + getClusterName()
@@ -527,12 +524,16 @@ public class ServiceComponentImpl implem
             + ", hostname=" + sch.getHostName());
       }
     }
+
+    for (ServiceComponentHost serviceComponentHost : hostComponents.values()) {
+      serviceComponentHost.delete();
+    }
+
     hostComponents.clear();
-    // FIXME update DB
   }
 
   @Override
-  public synchronized void removeServiceComponentHosts(String hostname)
+  public synchronized void deleteServiceComponentHosts(String hostname)
       throws AmbariException {
     ServiceComponentHost sch = getServiceComponentHost(hostname);
     LOG.info("Deleting servicecomponenthost for cluster"
@@ -547,16 +548,39 @@ public class ServiceComponentImpl implem
           + ", componentName=" + getName()
           + ", hostname=" + sch.getHostName());
     }
+    sch.delete();
     hostComponents.remove(hostname);
-    // FIXME update DB
   }
 
   @Override
   public synchronized void deleteDesiredConfigs(Set<String> configTypes) {
+    componentConfigMappingDAO.removeByType(configTypes);
     for (String configType : configTypes) {
       desiredConfigs.remove(configType);
     }
-    componentConfigMappingDAO.removeByType(configTypes);
+  }
+
+  @Override
+  @Transactional
+  public synchronized void delete() throws AmbariException {
+    deleteAllServiceComponentHosts();
+
+    if (persisted) {
+      removeEntities();
+      persisted = false;
+    }
+
+    desiredConfigs.clear();
+  }
+
+  @Transactional
+  protected void removeEntities() throws AmbariException {
+    ServiceComponentDesiredStateEntityPK pk = new ServiceComponentDesiredStateEntityPK();
+    pk.setClusterId(getClusterId());
+    pk.setComponentName(getName());
+    pk.setServiceName(getServiceName());
+
+    serviceComponentDesiredStateDAO.removeByPK(pk);
   }
 
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java Mon Feb  4 02:23:55 2013
@@ -414,8 +414,10 @@ public class ServiceImpl implements Serv
     serviceDesiredStateDAO.create(serviceDesiredStateEntity);
     clusterEntity.getClusterServiceEntities().add(serviceEntity);
     clusterDAO.merge(clusterEntity);
-    serviceEntity = clusterServiceDAO.merge(serviceEntity);
-    serviceDesiredStateEntity = serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
+//    serviceEntity =
+        clusterServiceDAO.merge(serviceEntity);
+//    serviceDesiredStateEntity =
+        serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
   }
 
   @Transactional
@@ -442,28 +444,25 @@ public class ServiceImpl implements Serv
 
   @Override
   public synchronized boolean canBeRemoved() {
-    State state = getDesiredState();
-    if (state != State.INIT
-        && state != State.UNINSTALLED) {
+    if (!getDesiredState().isRemovableState()) {
       return false;
     }
 
-    boolean safeToRemove = true;
     for (ServiceComponent sc : components.values()) {
       if (!sc.canBeRemoved()) {
-        safeToRemove = false;
         LOG.warn("Found non removable component when trying to delete service"
             + ", clusterName=" + cluster.getClusterName()
             + ", serviceName=" + getName()
             + ", componentName=" + sc.getName());
-        break;
+        return false;
       }
     }
-    return safeToRemove;
+    return true;
   }
 
   @Override
-  public synchronized void removeAllComponents() throws AmbariException {
+  @Transactional
+  public synchronized void deleteAllComponents() throws AmbariException {
     LOG.info("Deleting all components for service"
         + ", clusterName=" + cluster.getClusterName()
         + ", serviceName=" + getName());
@@ -477,11 +476,12 @@ public class ServiceImpl implements Serv
             + ", componentName=" + component.getName());
       }
     }
-    for (ServiceComponent component : components.values()) {
-      component.removeAllServiceComponentHosts();
+
+    for (ServiceComponent serviceComponent : components.values()) {
+      serviceComponent.delete();
     }
+
     components.clear();
-    // FIXME update DB
   }
 
   @Override
@@ -499,9 +499,9 @@ public class ServiceImpl implements Serv
           + ", serviceName=" + getName()
           + ", componentName=" + componentName);
     }
-    component.removeAllServiceComponentHosts();
+
+    component.delete();
     components.remove(componentName);
-    // FIXME update DB
   }
 
   @Override
@@ -509,4 +509,26 @@ public class ServiceImpl implements Serv
     return isClientOnlyService;
   }
 
+  @Override
+  @Transactional
+  public synchronized void delete() throws AmbariException {
+    deleteAllComponents();
+
+    if (persisted) {
+      removeEntities();
+      persisted = false;
+    }
+
+    desiredConfigs.clear();
+  }
+
+  @Transactional
+  protected void removeEntities() throws AmbariException {
+    ClusterServiceEntityPK pk = new ClusterServiceEntityPK();
+    pk.setClusterId(getClusterId());
+    pk.setServiceName(getName());
+
+    clusterServiceDAO.removeByPK(pk);
+  }
+
 }

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/State.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/State.java?rev=1442010&r1=1442009&r2=1442010&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/State.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/state/State.java Mon Feb  4 02:23:55 2013
@@ -121,4 +121,22 @@ public enum State {
     }
   }
 
+  /**
+   * Indicates whether or not the resource with this state
+   * can be removed.
+   *
+   * @return true if this is a removable state
+   */
+  public boolean isRemovableState() {
+    switch (State.values()[this.state]) {
+      case INIT:
+      case INSTALLING:
+      case INSTALLED:
+      case INSTALL_FAILED:
+      case UNINSTALLED:
+        return true;
+      default:
+        return false;
+    }
+  }
 }