Переглянути джерело

AMBARI-4419. Add Passive state for Host, Service, HostComponent (ncole)

Nate Cole 11 роки тому
батько
коміт
95f0159acb
34 змінених файлів з 916 додано та 122 видалено
  1. 12 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
  2. 44 1
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
  3. 9 1
      ambari-server/src/main/java/org/apache/ambari/server/controller/HostRequest.java
  4. 17 1
      ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java
  5. 15 7
      ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
  6. 15 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
  7. 13 3
      ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceRequest.java
  8. 12 6
      ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
  9. 17 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
  10. 31 9
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
  11. 44 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
  12. 13 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
  13. 13 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
  14. 14 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
  15. 13 0
      ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
  16. 37 0
      ambari-server/src/main/java/org/apache/ambari/server/state/PassiveState.java
  17. 12 0
      ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
  18. 12 0
      ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
  19. 23 0
      ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
  20. 78 37
      ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
  21. 31 2
      ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
  22. 3 3
      ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
  23. 3 3
      ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
  24. 3 3
      ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
  25. 3 3
      ambari-server/src/main/resources/Ambari-DDL-Postgres-REMOTE-CREATE.sql
  26. 3 0
      ambari-server/src/main/resources/properties.json
  27. 5 2
      ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql
  28. 4 0
      ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
  29. 4 0
      ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
  30. 292 36
      ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
  31. 7 0
      ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
  32. 37 5
      ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
  33. 33 0
      ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
  34. 44 0
      ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java

+ 12 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java

@@ -24,6 +24,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.scheduler.ExecutionScheduleManager;
 import org.apache.ambari.server.scheduler.ExecutionScheduleManager;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentFactory;
 import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -518,5 +519,16 @@ public interface AmbariManagementController {
    * Get Execution Schedule Manager
    * Get Execution Schedule Manager
    */
    */
   public ExecutionScheduleManager getExecutionScheduleManager();
   public ExecutionScheduleManager getExecutionScheduleManager();
+
+  /**
+   * Gets the effective passive state for a host component
+   * @param cluster the cluster
+   * @param service the service
+   * @param sch the service component host
+   * @return the passive state
+   * @throws AmbariException
+   */
+  public PassiveState getEffectivePassiveState(Cluster cluster, Service service,
+      ServiceComponentHost sch) throws AmbariException;
 }
 }
   
   

+ 44 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -25,6 +25,7 @@ import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.HashSet;
 import java.util.List;
 import java.util.List;
@@ -78,6 +79,7 @@ import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Injector;
 import com.google.inject.Singleton;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
 import com.google.inject.persist.Transactional;
+
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.*;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.*;
 
 
 @Singleton
 @Singleton
@@ -666,7 +668,7 @@ public class AmbariManagementControllerImpl implements
       }
       }
       checkDesiredState = true;
       checkDesiredState = true;
     }
     }
-
+    
     for (Service s : services) {
     for (Service s : services) {
       // filter on component name if provided
       // filter on component name if provided
       Set<ServiceComponent> components = new HashSet<ServiceComponent>();
       Set<ServiceComponent> components = new HashSet<ServiceComponent>();
@@ -705,6 +707,7 @@ public class AmbariManagementControllerImpl implements
             if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
             if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
               continue;
               continue;
             }
             }
+            r.setPassiveState(getEffectivePassiveState(cluster, s, sch).name());
             response.add(r);
             response.add(r);
           } catch (ServiceComponentHostNotFoundException e) {
           } catch (ServiceComponentHostNotFoundException e) {
             if (request.getServiceName() != null && request.getComponentName() != null) {
             if (request.getServiceName() != null && request.getComponentName() != null) {
@@ -736,6 +739,8 @@ public class AmbariManagementControllerImpl implements
             if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
             if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
               continue;
               continue;
             }
             }
+            
+            r.setPassiveState(getEffectivePassiveState(cluster, s, sch).name());
             response.add(r);
             response.add(r);
           }
           }
         }
         }
@@ -743,6 +748,30 @@ public class AmbariManagementControllerImpl implements
     }
     }
     return response;
     return response;
   }
   }
+  
+  @Override
+  public PassiveState getEffectivePassiveState(Cluster cluster, Service service,
+      ServiceComponentHost sch) throws AmbariException
+      {
+    
+    Map<String, Host> map = clusters.getHostsForCluster(cluster.getClusterName());
+    if (null == map)
+      return PassiveState.ACTIVE;
+    
+    Host host = clusters.getHostsForCluster(cluster.getClusterName()).get(sch.getHostName());
+    if (null == host) // better not
+      throw new HostNotFoundException(cluster.getClusterName(), sch.getHostName());
+    
+    if (PassiveState.PASSIVE == sch.getPassiveState())
+      return PassiveState.PASSIVE;
+
+    if (PassiveState.ACTIVE != service.getPassiveState() ||
+        PassiveState.ACTIVE != host.getPassiveState(cluster.getClusterId()))
+      return PassiveState.IMPLIED;
+    
+    return sch.getPassiveState();
+  }
+  
 
 
   private Set<ConfigurationResponse> getConfigurations(
   private Set<ConfigurationResponse> getConfigurations(
       ConfigurationRequest request) throws AmbariException {
       ConfigurationRequest request) throws AmbariException {
@@ -1471,6 +1500,20 @@ public class AmbariManagementControllerImpl implements
               + " desired state, desiredState=" + newState.toString());
               + " desired state, desiredState=" + newState.toString());
         }
         }
       }
       }
+      
+      if (null != request.getPassiveState()) {
+        PassiveState newPassive = PassiveState.valueOf(request.getPassiveState());
+        PassiveState oldPassive = getEffectivePassiveState(cluster, s, sch);
+        
+        if (newPassive != oldPassive) {
+          if (newPassive.equals(PassiveState.IMPLIED)) {
+            throw new IllegalArgumentException("Invalid arguments, can only set " +
+              "passive state to one of " + EnumSet.of(PassiveState.ACTIVE, PassiveState.PASSIVE));
+          } else {
+            sch.setPassiveState(newPassive);
+          }
+        }
+      }
 
 
       if (newState == null) {
       if (newState == null) {
         if (LOG.isDebugEnabled()) {
         if (LOG.isDebugEnabled()) {

+ 9 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/HostRequest.java

@@ -18,7 +18,6 @@
 
 
 package org.apache.ambari.server.controller;
 package org.apache.ambari.server.controller;
 
 
-import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Map.Entry;
 
 
@@ -30,6 +29,7 @@ public class HostRequest {
   private Map<String, String> hostAttributes; // CREATE/UPDATE
   private Map<String, String> hostAttributes; // CREATE/UPDATE
   private String rackInfo;
   private String rackInfo;
   private ConfigurationRequest desiredConfig; // UPDATE
   private ConfigurationRequest desiredConfig; // UPDATE
+  private String passiveState; // UPDATE
 
 
   public HostRequest(String hostname, String clusterName, Map<String, String> hostAttributes) {
   public HostRequest(String hostname, String clusterName, Map<String, String> hostAttributes) {
     this.hostname = hostname;
     this.hostname = hostname;
@@ -84,6 +84,14 @@ public class HostRequest {
   public ConfigurationRequest getDesiredConfig() {
   public ConfigurationRequest getDesiredConfig() {
     return desiredConfig;
     return desiredConfig;
   }
   }
+  
+  public void setPassiveState(String state) {
+    passiveState = state;
+  }
+  
+  public String getPassiveState() {
+    return passiveState;
+  }
 
 
   public String toString() {
   public String toString() {
     StringBuilder sb = new StringBuilder();
     StringBuilder sb = new StringBuilder();

+ 17 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java

@@ -29,6 +29,7 @@ import org.apache.ambari.server.state.AgentVersion;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.HostConfig;
 import org.apache.ambari.server.state.HostConfig;
 import org.apache.ambari.server.state.HostHealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus;
+import org.apache.ambari.server.state.PassiveState;
 
 
 public class HostResponse {
 public class HostResponse {
 
 
@@ -144,6 +145,8 @@ public class HostResponse {
    */
    */
   private String status;
   private String status;
 
 
+  private PassiveState passiveState = null;
+
   public HostResponse(String hostname, String clusterName,
   public HostResponse(String hostname, String clusterName,
                       String ipv4, String ipv6, int cpuCount, int phCpuCount, String osArch, String osType,
                       String ipv4, String ipv6, int cpuCount, int phCpuCount, String osArch, String osType,
                       String osInfo, long availableMemBytes, long totalMemBytes,
                       String osInfo, long availableMemBytes, long totalMemBytes,
@@ -151,7 +154,6 @@ public class HostResponse {
                       long lastRegistrationTime, String rackInfo,
                       long lastRegistrationTime, String rackInfo,
                       Map<String, String> hostAttributes, AgentVersion agentVersion,
                       Map<String, String> hostAttributes, AgentVersion agentVersion,
                       HostHealthStatus healthStatus, String hostState, String status) {
                       HostHealthStatus healthStatus, String hostState, String status) {
-    super();
     this.hostname = hostname;
     this.hostname = hostname;
     this.clusterName = clusterName;
     this.clusterName = clusterName;
     this.ipv4 = ipv4;
     this.ipv4 = ipv4;
@@ -519,4 +521,18 @@ public class HostResponse {
   public void setStatus(String status) {
   public void setStatus(String status) {
     this.status = status;
     this.status = status;
   }
   }
+
+  /**
+   * @param state
+   */
+  public void setPassiveState(PassiveState state) {
+    passiveState = state;
+  }
+  
+  /**
+   * @return the passive state
+   */
+  public PassiveState getPassiveState() {
+    return passiveState;
+  }
 }
 }

+ 15 - 7
ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java

@@ -23,20 +23,14 @@ package org.apache.ambari.server.controller;
 public class ServiceComponentHostRequest {
 public class ServiceComponentHostRequest {
 
 
   private String clusterName; // REF
   private String clusterName; // REF
-
   private String serviceName;
   private String serviceName;
-
   private String componentName;
   private String componentName;
-
   private String hostname;
   private String hostname;
-
   private String desiredState; // CREATE/UPDATE
   private String desiredState; // CREATE/UPDATE
-
   private String desiredStackId; // UPDATE
   private String desiredStackId; // UPDATE
-
   private String staleConfig; // GET - predicate
   private String staleConfig; // GET - predicate
-
   private String adminState; // GET - predicate
   private String adminState; // GET - predicate
+  private String passiveState; // UPDATE
   
   
   public ServiceComponentHostRequest(String clusterName,
   public ServiceComponentHostRequest(String clusterName,
                                      String serviceName,
                                      String serviceName,
@@ -177,4 +171,18 @@ public class ServiceComponentHostRequest {
         + "}");
         + "}");
     return sb.toString();
     return sb.toString();
   }
   }
+
+  /**
+   * @param state the passive state
+   */
+  public void setPassiveState(String state) {
+    passiveState = state;
+  }
+  
+  /**
+   * @return the passive state
+   */
+  public String getPassiveState() {
+    return passiveState;
+  }
 }
 }

+ 15 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java

@@ -37,6 +37,7 @@ public class ServiceComponentHostResponse {
   private String desiredState;
   private String desiredState;
   private boolean staleConfig = false;
   private boolean staleConfig = false;
   private String adminState = null;
   private String adminState = null;
+  private String passiveState = null;
 
 
 
 
   public ServiceComponentHostResponse(String clusterName, String serviceName,
   public ServiceComponentHostResponse(String clusterName, String serviceName,
@@ -252,4 +253,18 @@ public class ServiceComponentHostResponse {
     staleConfig = stale;
     staleConfig = stale;
   }
   }
 
 
+  /**
+   * @return the passive state
+   */
+  public String getPassiveState() {
+    return passiveState;
+  }
+  
+  /**
+   * @param state the passive state
+   */
+  public void setPassiveState(String state) {
+    passiveState = state;
+  }
+
 }
 }

+ 13 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceRequest.java

@@ -18,17 +18,16 @@
 package org.apache.ambari.server.controller;
 package org.apache.ambari.server.controller;
 
 
 
 
+
 public class ServiceRequest {
 public class ServiceRequest {
 
 
   private String clusterName; // REF
   private String clusterName; // REF
-
   private String serviceName; // GET/CREATE/UPDATE/DELETE
   private String serviceName; // GET/CREATE/UPDATE/DELETE
-
   private String desiredState; // CREATE/UPDATE
   private String desiredState; // CREATE/UPDATE
+  private String passiveState; // UPDATE
 
 
   public ServiceRequest(String clusterName, String serviceName,
   public ServiceRequest(String clusterName, String serviceName,
                         String desiredState) {
                         String desiredState) {
-    super();
     this.clusterName = clusterName;
     this.clusterName = clusterName;
     this.serviceName = serviceName;
     this.serviceName = serviceName;
     this.desiredState = desiredState;
     this.desiredState = desiredState;
@@ -75,6 +74,17 @@ public class ServiceRequest {
   public void setClusterName(String clusterName) {
   public void setClusterName(String clusterName) {
     this.clusterName = clusterName;
     this.clusterName = clusterName;
   }
   }
+  
+  /**
+   * @param state the new passive state
+   */
+  public void setPassiveState(String state) {
+    passiveState = state;
+  }
+  
+  public String getPassiveState() {
+    return passiveState;
+  }
 
 
   public String toString() {
   public String toString() {
     StringBuilder sb = new StringBuilder();
     StringBuilder sb = new StringBuilder();

+ 12 - 6
ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java

@@ -18,30 +18,28 @@
 
 
 package org.apache.ambari.server.controller;
 package org.apache.ambari.server.controller;
 
 
-import java.util.Map;
+import org.apache.ambari.server.state.PassiveState;
 
 
 public class ServiceResponse {
 public class ServiceResponse {
 
 
   private Long clusterId;
   private Long clusterId;
-
   private String clusterName;
   private String clusterName;
-
   private String serviceName;
   private String serviceName;
-
   private String desiredStackVersion;
   private String desiredStackVersion;
-
   private String desiredState;
   private String desiredState;
+  private String passiveState;
 
 
   public ServiceResponse(Long clusterId, String clusterName,
   public ServiceResponse(Long clusterId, String clusterName,
                          String serviceName,
                          String serviceName,
                          String desiredStackVersion, String desiredState) {
                          String desiredStackVersion, String desiredState) {
-    super();
     this.clusterId = clusterId;
     this.clusterId = clusterId;
     this.clusterName = clusterName;
     this.clusterName = clusterName;
     this.serviceName = serviceName;
     this.serviceName = serviceName;
     this.setDesiredStackVersion(desiredStackVersion);
     this.setDesiredStackVersion(desiredStackVersion);
     this.setDesiredState(desiredState);
     this.setDesiredState(desiredState);
   }
   }
+  
+  
 
 
   /**
   /**
    * @return the serviceName
    * @return the serviceName
@@ -135,6 +133,14 @@ public class ServiceResponse {
 
 
     return true;
     return true;
   }
   }
+  
+  public void setPassiveState(String state) {
+    passiveState = state;
+  }
+  
+  public String getPassiveState() {
+    return passiveState;
+  }
 
 
   @Override
   @Override
   public int hashCode() {
   public int hashCode() {

+ 17 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java

@@ -20,6 +20,7 @@ package org.apache.ambari.server.controller.internal;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
 import com.google.inject.assistedinject.AssistedInject;
 import com.google.inject.persist.Transactional;
 import com.google.inject.persist.Transactional;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -37,6 +38,7 @@ import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.state.PassiveState;
 
 
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashMap;
@@ -75,6 +77,9 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
       = PropertyHelper.getPropertyId("HostRoles", "stale_configs");
       = PropertyHelper.getPropertyId("HostRoles", "stale_configs");
   protected static final String HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID
   protected static final String HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID
       = PropertyHelper.getPropertyId("HostRoles", "desired_admin_state");
       = PropertyHelper.getPropertyId("HostRoles", "desired_admin_state");
+  protected static final String HOST_COMPONENT_PASSIVE_STATE_PROPERTY_ID
+      = "HostRoles/passive_state";
+  
   //Component name mappings
   //Component name mappings
   private static final Map<String, PropertyProvider> HOST_COMPONENT_PROPERTIES_PROVIDER = new HashMap<String, PropertyProvider>();
   private static final Map<String, PropertyProvider> HOST_COMPONENT_PROPERTIES_PROVIDER = new HashMap<String, PropertyProvider>();
   private static final int HOST_COMPONENT_HTTP_PROPERTY_REQUEST_CONNECT_TIMEOUT = 1500;   //milliseconds
   private static final int HOST_COMPONENT_HTTP_PROPERTY_REQUEST_CONNECT_TIMEOUT = 1500;   //milliseconds
@@ -192,10 +197,16 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
           response.getActualConfigs(), requestedIds);
           response.getActualConfigs(), requestedIds);
       setResourceProperty(resource, HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID,
       setResourceProperty(resource, HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID,
           Boolean.valueOf(response.isStaleConfig()), requestedIds);
           Boolean.valueOf(response.isStaleConfig()), requestedIds);
+      
       if (response.getAdminState() != null) {
       if (response.getAdminState() != null) {
         setResourceProperty(resource, HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID,
         setResourceProperty(resource, HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID,
             response.getAdminState(), requestedIds);
             response.getAdminState(), requestedIds);
       }
       }
+      
+      if (null != response.getPassiveState()) {
+        setResourceProperty(resource, HOST_COMPONENT_PASSIVE_STATE_PROPERTY_ID,
+            response.getPassiveState(), requestedIds);
+      }
 
 
       String componentName = (String) resource.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
       String componentName = (String) resource.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
       PropertyProvider propertyProvider = HOST_COMPONENT_PROPERTIES_PROVIDER.get(componentName);
       PropertyProvider propertyProvider = HOST_COMPONENT_PROPERTIES_PROVIDER.get(componentName);
@@ -302,10 +313,16 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
       serviceComponentHostRequest.setStaleConfig(
       serviceComponentHostRequest.setStaleConfig(
           properties.get(HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID).toString().toLowerCase());
           properties.get(HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID).toString().toLowerCase());
     }
     }
+    
     if (properties.get(HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID) != null) {
     if (properties.get(HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID) != null) {
       serviceComponentHostRequest.setAdminState(
       serviceComponentHostRequest.setAdminState(
           properties.get(HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID).toString());
           properties.get(HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID).toString());
     }
     }
+    
+    Object o = properties.get(HOST_COMPONENT_PASSIVE_STATE_PROPERTY_ID);
+    if (null != o) {
+      serviceComponentHostRequest.setPassiveState (o.toString());
+    }
 
 
     return serviceComponentHostRequest;
     return serviceComponentHostRequest;
   }
   }

+ 31 - 9
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java

@@ -20,7 +20,7 @@ package org.apache.ambari.server.controller.internal;
 import java.text.MessageFormat;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Arrays;
-import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.HashSet;
 import java.util.List;
 import java.util.List;
@@ -33,13 +33,10 @@ import org.apache.ambari.server.DuplicateResourceException;
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.ParentObjectNotFoundException;
 import org.apache.ambari.server.ParentObjectNotFoundException;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.ConfigurationRequest;
 import org.apache.ambari.server.controller.ConfigurationRequest;
 import org.apache.ambari.server.controller.HostRequest;
 import org.apache.ambari.server.controller.HostRequest;
 import org.apache.ambari.server.controller.HostResponse;
 import org.apache.ambari.server.controller.HostResponse;
-import org.apache.ambari.server.controller.ServiceComponentHostRequest;
-import org.apache.ambari.server.controller.ServiceComponentHostResponse;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Predicate;
@@ -52,17 +49,14 @@ import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.HostHealthStatus;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.StackId;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
-
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
 import com.google.inject.assistedinject.AssistedInject;
 import com.google.inject.persist.Transactional;
 import com.google.inject.persist.Transactional;
@@ -106,7 +100,8 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
   
   
   protected static final String HOST_HOST_STATUS_PROPERTY_ID =
   protected static final String HOST_HOST_STATUS_PROPERTY_ID =
       PropertyHelper.getPropertyId("Hosts", "host_status");
       PropertyHelper.getPropertyId("Hosts", "host_status");
-  
+  protected static final String HOST_PASSIVE_STATE_PROPERTY_ID = 
+      PropertyHelper.getPropertyId("Hosts", "passive_state");
   
   
   protected static final String HOST_HOST_HEALTH_REPORT_PROPERTY_ID =
   protected static final String HOST_HOST_HEALTH_REPORT_PROPERTY_ID =
       PropertyHelper.getPropertyId("Hosts", "host_health_report");
       PropertyHelper.getPropertyId("Hosts", "host_health_report");
@@ -232,6 +227,13 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
           response.getHostState(), requestedIds);
           response.getHostState(), requestedIds);
       setResourceProperty(resource, HOST_DESIRED_CONFIGS_PROPERTY_ID,
       setResourceProperty(resource, HOST_DESIRED_CONFIGS_PROPERTY_ID,
           response.getDesiredHostConfigs(), requestedIds);
           response.getDesiredHostConfigs(), requestedIds);
+      
+      // only when a cluster request
+      if (null != response.getPassiveState()) {
+        setResourceProperty(resource, HOST_PASSIVE_STATE_PROPERTY_ID,
+            response.getPassiveState(), requestedIds);
+      }
+      
       resources.add(resource);
       resources.add(resource);
     }
     }
     return resources;
     return resources;
@@ -319,6 +321,10 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     hostRequest.setPublicHostName((String) properties.get(HOST_PUBLIC_NAME_PROPERTY_ID));
     hostRequest.setPublicHostName((String) properties.get(HOST_PUBLIC_NAME_PROPERTY_ID));
     hostRequest.setRackInfo((String) properties.get(HOST_RACK_INFO_PROPERTY_ID));
     hostRequest.setRackInfo((String) properties.get(HOST_RACK_INFO_PROPERTY_ID));
     
     
+    Object o = properties.get(HOST_PASSIVE_STATE_PROPERTY_ID);
+    if (null != o)
+      hostRequest.setPassiveState(o.toString());
+    
     ConfigurationRequest cr = getConfigurationRequest("Hosts", properties);
     ConfigurationRequest cr = getConfigurationRequest("Hosts", properties);
     
     
     hostRequest.setDesiredConfig(cr);
     hostRequest.setDesiredConfig(cr);
@@ -488,8 +494,10 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       if (clusterName != null) {
       if (clusterName != null) {
         if (clusters.getClustersForHost(h.getHostName()).contains(cluster)) {
         if (clusters.getClustersForHost(h.getHostName()).contains(cluster)) {
           HostResponse r = h.convertToResponse();
           HostResponse r = h.convertToResponse();
+          
           r.setClusterName(clusterName);
           r.setClusterName(clusterName);
           r.setDesiredHostConfigs(h.getDesiredHostConfigs(cluster));
           r.setDesiredHostConfigs(h.getDesiredHostConfigs(cluster));
+          r.setPassiveState(h.getPassiveState(cluster.getClusterId()));
 
 
           response.add(r);
           response.add(r);
         } else if (hostName != null) {
         } else if (hostName != null) {
@@ -555,6 +563,20 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       if (null != request.getPublicHostName()) {
       if (null != request.getPublicHostName()) {
         h.setPublicHostName(request.getPublicHostName());
         h.setPublicHostName(request.getPublicHostName());
       }
       }
+      
+      if (null != request.getClusterName() && null != request.getPassiveState()) {
+        Cluster c = clusters.getCluster(request.getClusterName());
+        PassiveState newStatus = PassiveState.valueOf(request.getPassiveState());
+        PassiveState oldStatus = h.getPassiveState(c.getClusterId());
+        if (!newStatus.equals(oldStatus)) {
+          if (newStatus.equals(PassiveState.IMPLIED)) {
+            throw new IllegalArgumentException("Invalid arguments, can only set " +
+              "passive state to one of " + EnumSet.of(PassiveState.ACTIVE, PassiveState.PASSIVE));
+          } else {
+            h.setPassiveState(c.getClusterId(), newStatus);
+          }
+        }
+      }
 
 
       if (null != request.getClusterName() && null != request.getDesiredConfig()) {
       if (null != request.getClusterName() && null != request.getDesiredConfig()) {
         Cluster c = clusters.getCluster(request.getClusterName());
         Cluster c = clusters.getCluster(request.getClusterName());

+ 44 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java

@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Iterator;
@@ -54,6 +55,7 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHost;
@@ -78,6 +80,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
   protected static final String SERVICE_CLUSTER_NAME_PROPERTY_ID    = PropertyHelper.getPropertyId("ServiceInfo", "cluster_name");
   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_NAME_PROPERTY_ID    = PropertyHelper.getPropertyId("ServiceInfo", "service_name");
   protected static final String SERVICE_SERVICE_STATE_PROPERTY_ID   = PropertyHelper.getPropertyId("ServiceInfo", "state");
   protected static final String SERVICE_SERVICE_STATE_PROPERTY_ID   = PropertyHelper.getPropertyId("ServiceInfo", "state");
+  protected static final String SERVICE_PASSIVE_STATE_PROPERTY_ID   = PropertyHelper.getPropertyId("ServiceInfo", "passive_state");
 
 
   //Parameters from the predicate
   //Parameters from the predicate
   private static final String QUERY_PARAMETERS_RUN_SMOKE_TEST_ID =
   private static final String QUERY_PARAMETERS_RUN_SMOKE_TEST_ID =
@@ -172,6 +175,8 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
       setResourceProperty(resource, SERVICE_SERVICE_STATE_PROPERTY_ID,
       setResourceProperty(resource, SERVICE_SERVICE_STATE_PROPERTY_ID,
           calculateServiceState(response.getClusterName(), response.getServiceName()),
           calculateServiceState(response.getClusterName(), response.getServiceName()),
           requestedIds);
           requestedIds);
+      setResourceProperty(resource, SERVICE_PASSIVE_STATE_PROPERTY_ID,
+          response.getPassiveState(), requestedIds);
       resources.add(resource);
       resources.add(resource);
     }
     }
     return resources;
     return resources;
@@ -270,6 +275,10 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
         (String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID),
         (String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID),
         (String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID),
         (String) properties.get(SERVICE_SERVICE_NAME_PROPERTY_ID),
         (String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID));
         (String) properties.get(SERVICE_SERVICE_STATE_PROPERTY_ID));
+    
+    Object o = properties.get(SERVICE_PASSIVE_STATE_PROPERTY_ID);
+    if (null != o)
+      svcRequest.setPassiveState(o.toString());
 
 
     return svcRequest;
     return svcRequest;
   }
   }
@@ -541,6 +550,18 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
               + " desired state, desiredState=" + newState);
               + " desired state, desiredState=" + newState);
         }
         }
       }
       }
+      
+      if (null != request.getPassiveState()) {
+        PassiveState newPassive = PassiveState.valueOf(request.getPassiveState());
+        if (newPassive  != s.getPassiveState()) {
+          if (newPassive.equals(PassiveState.IMPLIED)) {
+            throw new IllegalArgumentException("Invalid arguments, can only set " +
+              "passive state to one of " + EnumSet.of(PassiveState.ACTIVE, PassiveState.PASSIVE));
+          } else {
+            s.setPassiveState(newPassive);
+          }
+        }
+      }
 
 
       if (newState == null) {
       if (newState == null) {
         if (LOG.isDebugEnabled()) {
         if (LOG.isDebugEnabled()) {
@@ -551,6 +572,13 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
         }
         }
         continue;
         continue;
       }
       }
+      
+      if (requests.size() > 1 && PassiveState.ACTIVE != s.getPassiveState()) {
+        LOG.info("Operations cannot be applied to service " + s.getName() +
+            " in the passive state of " + s.getPassiveState());
+        continue;
+      }
+      
 
 
       seenNewStates.add(newState);
       seenNewStates.add(newState);
 
 
@@ -619,6 +647,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
             }
             }
             continue;
             continue;
           }
           }
+          
           if (newState == oldSchState) {
           if (newState == oldSchState) {
             ignoredScHosts.add(sch);
             ignoredScHosts.add(sch);
             if (LOG.isDebugEnabled()) {
             if (LOG.isDebugEnabled()) {
@@ -632,6 +661,21 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
             }
             }
             continue;
             continue;
           }
           }
+          
+          PassiveState schPassive = controller.getEffectivePassiveState(cluster, s, sch);
+          if (PassiveState.ACTIVE != schPassive) {
+            ignoredScHosts.add(sch);
+            if (LOG.isDebugEnabled()) {
+              LOG.debug("Ignoring " + schPassive + " ServiceComponentHost"
+                  + ", clusterName=" + request.getClusterName()
+                  + ", serviceName=" + s.getName()
+                  + ", componentName=" + sc.getName()
+                  + ", hostname=" + sch.getHostName());
+            }
+            continue;
+          }
+          
+          
           if (sc.isClientComponent() &&
           if (sc.isClientComponent() &&
               !newState.isValidClientComponentState()) {
               !newState.isValidClientComponentState()) {
             continue;
             continue;

+ 13 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java

@@ -20,6 +20,7 @@ package org.apache.ambari.server.orm.entities;
 import javax.persistence.*;
 import javax.persistence.*;
 
 
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.HostComponentAdminState;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.State;
 
 
 import static org.apache.commons.lang.StringUtils.defaultString;
 import static org.apache.commons.lang.StringUtils.defaultString;
@@ -68,6 +69,10 @@ public class HostComponentDesiredStateEntity {
   @ManyToOne
   @ManyToOne
   @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   private HostEntity hostEntity;
   private HostEntity hostEntity;
+  
+  @Enumerated(value = EnumType.STRING)
+  @Column(name="passive_state", nullable = false, insertable = true, updatable = true)
+  private PassiveState passiveState = PassiveState.ACTIVE;
 
 
   public Long getClusterId() {
   public Long getClusterId() {
     return clusterId;
     return clusterId;
@@ -125,6 +130,14 @@ public class HostComponentDesiredStateEntity {
   public void setAdminState(HostComponentAdminState attribute) {
   public void setAdminState(HostComponentAdminState attribute) {
     this.adminState = attribute;
     this.adminState = attribute;
   }
   }
+  
+  public PassiveState getPassiveState() {
+    return passiveState;
+  }
+  
+  public void setPassiveState(PassiveState state) {
+    passiveState = state;
+  }
 
 
   @Override
   @Override
   public boolean equals(Object o) {
   public boolean equals(Object o) {

+ 13 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java

@@ -19,6 +19,7 @@
 package org.apache.ambari.server.orm.entities;
 package org.apache.ambari.server.orm.entities;
 
 
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
 
 
 import javax.persistence.*;
 import javax.persistence.*;
@@ -52,6 +53,10 @@ public class HostStateEntity {
   @Column(name = "current_state", nullable = false, insertable = true, updatable = true)
   @Column(name = "current_state", nullable = false, insertable = true, updatable = true)
   @Enumerated(value = EnumType.STRING)
   @Enumerated(value = EnumType.STRING)
   private HostState currentState = HostState.INIT;
   private HostState currentState = HostState.INIT;
+  
+  @Column(name="passive_state", nullable = true, insertable = true, updatable = true)
+  private String passiveState = null;
+  
 
 
   @OneToOne
   @OneToOne
   @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
@@ -105,6 +110,14 @@ public class HostStateEntity {
     this.currentState = currentState;
     this.currentState = currentState;
   }
   }
 
 
+  public String getPassiveState() {
+    return passiveState;
+  }  
+  
+  public void setPassiveState(String state) {
+    passiveState = state;
+  }
+
   @Override
   @Override
   public boolean equals(Object o) {
   public boolean equals(Object o) {
     if (this == o) return true;
     if (this == o) return true;

+ 14 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java

@@ -18,6 +18,7 @@
 
 
 package org.apache.ambari.server.orm.entities;
 package org.apache.ambari.server.orm.entities;
 
 
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.State;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
 
 
@@ -48,6 +49,11 @@ public class ServiceDesiredStateEntity {
   @Basic
   @Basic
   private String desiredStackVersion = "";
   private String desiredStackVersion = "";
 
 
+  @Column(name = "passive_state", nullable = false, insertable = true, updatable = true)
+  @Enumerated(value = EnumType.STRING)
+  private PassiveState passiveState = PassiveState.ACTIVE;
+  
+  
   @OneToOne
   @OneToOne
   @javax.persistence.JoinColumns(
   @javax.persistence.JoinColumns(
       {
       {
@@ -95,6 +101,14 @@ public class ServiceDesiredStateEntity {
   public void setDesiredStackVersion(String desiredStackVersion) {
   public void setDesiredStackVersion(String desiredStackVersion) {
     this.desiredStackVersion = desiredStackVersion;
     this.desiredStackVersion = desiredStackVersion;
   }
   }
+  
+  public PassiveState getPassiveState() {
+    return passiveState;
+  }  
+  
+  public void setPassiveState(PassiveState state) {
+    passiveState = state;
+  }
 
 
   @Override
   @Override
   public boolean equals(Object o) {
   public boolean equals(Object o) {

+ 13 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Host.java

@@ -329,4 +329,17 @@ public interface Host {
    * @throws AmbariException
    * @throws AmbariException
    */
    */
   public Map<String, HostConfig> getDesiredHostConfigs(Cluster cluster) throws AmbariException;
   public Map<String, HostConfig> getDesiredHostConfigs(Cluster cluster) throws AmbariException;
+  
+  /**
+   * Sets the passive state for the host.
+   * @param clusterId the cluster id
+   * @param state the state
+   */
+  public void setPassiveState(long clusterId, PassiveState state);
+  
+  /**
+   * @param clusterId the cluster id
+   * @return the passive state
+   */
+  public PassiveState getPassiveState(long clusterId);
 }
 }

+ 37 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/PassiveState.java

@@ -0,0 +1,37 @@
+/**
+ * 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.state;
+
+/**
+ * Indicates when a Service or Host participates in automated opererations, and
+ * if alerts are enabled.
+ */
+public enum PassiveState {
+  /**
+   * All group-targeted commands are available.  Alerts enabled.
+   */
+  ACTIVE,
+  /**
+   * Target was actively put into passive state.  Alerts disabled.
+   */
+  PASSIVE,
+  /**
+   * Target is passive, implied by a parent target.
+   */
+  IMPLIED
+}

+ 12 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Service.java

@@ -22,6 +22,7 @@ import java.util.Map;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReadWriteLock;
 
 
 import com.google.inject.persist.Transactional;
 import com.google.inject.persist.Transactional;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.ServiceResponse;
 import org.apache.ambari.server.controller.ServiceResponse;
 
 
@@ -87,6 +88,17 @@ public interface Service {
    * @return cluster-global lock
    * @return cluster-global lock
    */
    */
   ReadWriteLock getClusterGlobalLock();
   ReadWriteLock getClusterGlobalLock();
+  
+  /**
+   * Sets the passive state for the service
+   * @param state the status
+   */
+  public void setPassiveState(PassiveState state);
+  
+  /**
+   * @return the passive state
+   */
+  public PassiveState getPassiveState();
 
 
   public enum Type {
   public enum Type {
     HDFS,
     HDFS,

+ 12 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java

@@ -113,4 +113,16 @@ public interface ServiceComponentHost {
   public Map<String, HostConfig> getActualConfigs();
   public Map<String, HostConfig> getActualConfigs();
 
 
   public HostState getHostState();
   public HostState getHostState();
+
+  /**
+   * @param state the passive state
+   */
+  public void setPassiveState(PassiveState state);
+  
+  /**
+   * @return the passive state
+   */
+  public PassiveState getPassiveState();
+
+  
 }
 }

+ 23 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java

@@ -384,6 +384,8 @@ public class ServiceImpl implements Service {
             getName(),
             getName(),
             getDesiredStackVersion().getStackId(),
             getDesiredStackVersion().getStackId(),
             getDesiredState().toString());
             getDesiredState().toString());
+        
+        r.setPassiveState(getPassiveState().name());
         return r;
         return r;
       } finally {
       } finally {
         readWriteLock.readLock().unlock();
         readWriteLock.readLock().unlock();
@@ -648,5 +650,26 @@ public class ServiceImpl implements Service {
 
 
     clusterServiceDAO.removeByPK(pk);
     clusterServiceDAO.removeByPK(pk);
   }
   }
+  
+  @Override
+  public void setPassiveState(PassiveState state) {
+    clusterGlobalLock.readLock().lock();
+    try {
+      try {
+        readWriteLock.writeLock().lock();
+        serviceDesiredStateEntity.setPassiveState(state);
+        saveIfPersisted();
+      } finally {
+        readWriteLock.writeLock().unlock();
+      }
+    } finally {
+      clusterGlobalLock.readLock().unlock();
+    }
+  }
+  
+  @Override
+  public PassiveState getPassiveState() {
+    return serviceDesiredStateEntity.getPassiveState();
+  }
 
 
 }
 }

+ 78 - 37
ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java

@@ -34,7 +34,6 @@ import org.apache.ambari.server.controller.HostResponse;
 import org.apache.ambari.server.orm.cache.HostConfigMapping;
 import org.apache.ambari.server.orm.cache.HostConfigMapping;
 import org.apache.ambari.server.orm.cache.HostConfigMappingImpl;
 import org.apache.ambari.server.orm.cache.HostConfigMappingImpl;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
-import org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO;
 import org.apache.ambari.server.orm.dao.HostConfigMappingDAO;
 import org.apache.ambari.server.orm.dao.HostConfigMappingDAO;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.HostStateDAO;
 import org.apache.ambari.server.orm.dao.HostStateDAO;
@@ -53,6 +52,7 @@ import org.apache.ambari.server.state.HostEventType;
 import org.apache.ambari.server.state.HostHealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.configgroup.ConfigGroup;
 import org.apache.ambari.server.state.configgroup.ConfigGroup;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.fsm.SingleArcTransition;
 import org.apache.ambari.server.state.fsm.SingleArcTransition;
@@ -71,12 +71,30 @@ import com.google.inject.persist.Transactional;
 public class HostImpl implements Host {
 public class HostImpl implements Host {
 
 
   private static final Log LOG = LogFactory.getLog(HostImpl.class);
   private static final Log LOG = LogFactory.getLog(HostImpl.class);
+  private static final String HARDWAREISA = "hardware_isa";
+  private static final String HARDWAREMODEL = "hardware_model";
+  private static final String INTERFACES = "interfaces";
+  private static final String KERNEL = "kernel";
+  private static final String KERNELMAJOREVERSON = "kernel_majorversion";
+  private static final String KERNELRELEASE = "kernel_release";
+  private static final String KERNELVERSION = "kernel_version";
+  private static final String MACADDRESS = "mac_address";
+  private static final String NETMASK = "netmask";
+  private static final String OSFAMILY = "os_family";
+  private static final String PHYSICALPROCESSORCOUNT = "physicalprocessors_count";
+  private static final String PROCESSORCOUNT = "processors_count";
+  private static final String SELINUXENABLED = "selinux_enabled";
+  private static final String SWAPSIZE = "swap_size";
+  private static final String SWAPFREE = "swap_free";
+  private static final String TIMEZONE = "timezone";
+
+  
   private final Gson gson;
   private final Gson gson;
 
 
-  private static final Type diskInfoType =
-      new TypeToken<List<DiskInfo>>() {}.getType();
   private static final Type hostAttributesType =
   private static final Type hostAttributesType =
       new TypeToken<Map<String, String>>() {}.getType();
       new TypeToken<Map<String, String>>() {}.getType();
+  private static final Type passiveMapType =
+      new TypeToken<Map<Long, PassiveState>>() {}.getType();
 
 
   ReadWriteLock rwLock;
   ReadWriteLock rwLock;
   private final Lock readLock;
   private final Lock readLock;
@@ -84,37 +102,21 @@ public class HostImpl implements Host {
 
 
   private HostEntity hostEntity;
   private HostEntity hostEntity;
   private HostStateEntity hostStateEntity;
   private HostStateEntity hostStateEntity;
-  private Injector injector;
   private HostDAO hostDAO;
   private HostDAO hostDAO;
   private HostStateDAO hostStateDAO;
   private HostStateDAO hostStateDAO;
   private ClusterDAO clusterDAO;
   private ClusterDAO clusterDAO;
   private Clusters clusters;
   private Clusters clusters;
   private HostConfigMappingDAO hostConfigMappingDAO;
   private HostConfigMappingDAO hostConfigMappingDAO;
-  private ConfigGroupHostMappingDAO configGroupHostMappingDAO;
 
 
   private long lastHeartbeatTime = 0L;
   private long lastHeartbeatTime = 0L;
   private AgentEnv lastAgentEnv = null;
   private AgentEnv lastAgentEnv = null;
   private List<DiskInfo> disksInfo = new ArrayList<DiskInfo>();
   private List<DiskInfo> disksInfo = new ArrayList<DiskInfo>();
   private boolean persisted = false;
   private boolean persisted = false;
   private Integer currentPingPort = null;
   private Integer currentPingPort = null;
+  
+  private final StateMachine<HostState, HostEventType, HostEvent> stateMachine;
+  private Map<Long, PassiveState> passiveMap = null;
 
 
-  private static final String HARDWAREISA = "hardware_isa";
-  private static final String HARDWAREMODEL = "hardware_model";
-  private static final String INTERFACES = "interfaces";
-  private static final String KERNEL = "kernel";
-  private static final String KERNELMAJOREVERSON = "kernel_majorversion";
-  private static final String KERNELRELEASE = "kernel_release";
-  private static final String KERNELVERSION = "kernel_version";
-  private static final String MACADDRESS = "mac_address";
-  private static final String NETMASK = "netmask";
-  private static final String OSFAMILY = "os_family";
-  private static final String PHYSICALPROCESSORCOUNT =
-      "physicalprocessors_count";
-  private static final String PROCESSORCOUNT = "processors_count";
-  private static final String SELINUXENABLED = "selinux_enabled";
-  private static final String SWAPSIZE = "swap_size";
-  private static final String SWAPFREE = "swap_free";
-  private static final String TIMEZONE = "timezone";
   
   
   
   
   //In-memory status, based on host components states
   //In-memory status, based on host components states
@@ -205,8 +207,6 @@ public class HostImpl implements Host {
 
 
    .installTopology();
    .installTopology();
 
 
-  private final StateMachine<HostState, HostEventType, HostEvent> stateMachine;
-
   @Inject
   @Inject
   public HostImpl(@Assisted HostEntity hostEntity,
   public HostImpl(@Assisted HostEntity hostEntity,
       @Assisted boolean persisted, Injector injector) {
       @Assisted boolean persisted, Injector injector) {
@@ -216,7 +216,6 @@ public class HostImpl implements Host {
     this.writeLock = rwLock.writeLock();
     this.writeLock = rwLock.writeLock();
 
 
     this.hostEntity = hostEntity;
     this.hostEntity = hostEntity;
-    this.injector = injector;
     this.persisted = persisted;
     this.persisted = persisted;
     this.hostDAO = injector.getInstance(HostDAO.class);
     this.hostDAO = injector.getInstance(HostDAO.class);
     this.hostStateDAO = injector.getInstance(HostStateDAO.class);
     this.hostStateDAO = injector.getInstance(HostStateDAO.class);
@@ -224,8 +223,6 @@ public class HostImpl implements Host {
     this.clusterDAO = injector.getInstance(ClusterDAO.class);
     this.clusterDAO = injector.getInstance(ClusterDAO.class);
     this.clusters = injector.getInstance(Clusters.class);
     this.clusters = injector.getInstance(Clusters.class);
     this.hostConfigMappingDAO = injector.getInstance(HostConfigMappingDAO.class);
     this.hostConfigMappingDAO = injector.getInstance(HostConfigMappingDAO.class);
-    this.configGroupHostMappingDAO = injector.getInstance
-      (ConfigGroupHostMappingDAO.class);
 
 
     hostStateEntity = hostEntity.getHostStateEntity();
     hostStateEntity = hostEntity.getHostStateEntity();
     if (hostStateEntity == null) {
     if (hostStateEntity == null) {
@@ -242,16 +239,6 @@ public class HostImpl implements Host {
 
 
   }
   }
 
 
-//  //TODO delete
-//  public HostImpl(String hostname) {
-//    this.stateMachine = stateMachineFactory.make(this);
-//    ReadWriteLock rwLock = new ReentrantReadWriteLock();
-//    this.readLock = rwLock.readLock();
-//    this.writeLock = rwLock.writeLock();
-//    setHostName(hostname);
-//    setHealthStatus(new HostHealthStatus(HealthStatus.UNKNOWN, ""));
-//  }
-
   static class HostRegistrationReceived
   static class HostRegistrationReceived
       implements SingleArcTransition<HostImpl, HostEvent> {
       implements SingleArcTransition<HostImpl, HostEvent> {
 
 
@@ -1239,6 +1226,60 @@ public class HostImpl implements Host {
     HostConfigMapping findSelectedByType = hostConfigMappingDAO.findSelectedByType(clusterId,
     HostConfigMapping findSelectedByType = hostConfigMappingDAO.findSelectedByType(clusterId,
         hostEntity.getHostName(), type);
         hostEntity.getHostName(), type);
     
     
+    
     return findSelectedByType;
     return findSelectedByType;
   }
   }
+  
+  private void ensurePassiveMap() {
+    if (null == passiveMap) {
+      String entity = hostStateEntity.getPassiveState();
+      if (null == entity) {
+        passiveMap = new HashMap<Long, PassiveState>();
+      } else {
+        try {
+          passiveMap = gson.fromJson(entity, passiveMapType);
+        } catch (Exception e) {
+          passiveMap = new HashMap<Long, PassiveState>();
+        }
+      }
+    }
+  }
+  
+  @Override
+  public void setPassiveState(long clusterId, PassiveState state) {
+    try {
+      writeLock.lock();
+      
+      ensurePassiveMap();
+      
+      passiveMap.put(Long.valueOf(clusterId), state);
+      String json = gson.toJson(passiveMap, passiveMapType);
+      
+      hostStateEntity.setPassiveState(json);
+      saveIfPersisted();
+    } finally {
+      writeLock.unlock();
+    }
+  }
+  
+  @Override
+  public PassiveState getPassiveState(long clusterId) {
+    try {
+      readLock.lock();
+
+      ensurePassiveMap();
+      
+      Long id = Long.valueOf(clusterId);
+      
+      if (!passiveMap.containsKey(id))
+        passiveMap.put(id, PassiveState.ACTIVE);
+        
+      return passiveMap.get(id);
+    } finally {
+      readLock.unlock();
+    }
+  }
+  
 }
 }
+
+  

+ 31 - 2
ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java

@@ -45,6 +45,7 @@ import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.HostConfig;
 import org.apache.ambari.server.state.HostConfig;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHostEvent;
 import org.apache.ambari.server.state.ServiceComponentHostEvent;
@@ -481,7 +482,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
 
 
      .installTopology();
      .installTopology();
 
 
-
   private final StateMachine<State,
   private final StateMachine<State,
       ServiceComponentHostEventType, ServiceComponentHostEvent> stateMachine;
       ServiceComponentHostEventType, ServiceComponentHostEvent> stateMachine;
 
 
@@ -1367,8 +1367,37 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
     } finally {
     } finally {
       clusterGlobalLock.readLock().unlock();
       clusterGlobalLock.readLock().unlock();
     }
     }
-
   }
   }
   
   
+  @Override
+  public void setPassiveState(PassiveState state) {
+    clusterGlobalLock.readLock().lock();
+    try {
+      writeLock.lock();
+      try {
+        desiredStateEntity.setPassiveState(state);
+        saveIfPersisted();
+      } finally {
+        writeLock.unlock();
+      }
+    } finally {
+      clusterGlobalLock.readLock().unlock();
+    }
+  }
+
+  @Override
+  public PassiveState getPassiveState() {
+    clusterGlobalLock.readLock().lock();
+    try {
+      readLock.lock();
+      try {
+        return desiredStateEntity.getPassiveState();
+      } finally {
+        readLock.unlock();
+      }
+    } finally {
+      clusterGlobalLock.readLock().unlock();
+    }
+  }
   
   
 }
 }

+ 3 - 3
ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql

@@ -30,12 +30,12 @@ CREATE TABLE clusters (cluster_id BIGINT NOT NULL, cluster_info VARCHAR(255) NOT
 CREATE TABLE clusterconfig (version_tag VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, config_data LONGTEXT NOT NULL, create_timestamp BIGINT NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
 CREATE TABLE clusterconfig (version_tag VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, config_data LONGTEXT NOT NULL, create_timestamp BIGINT NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
 CREATE TABLE clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_enabled INTEGER NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_enabled INTEGER NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
 CREATE TABLE clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
-CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), passive_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE', PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, host_attributes LONGTEXT NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, ph_cpu_count INTEGER, public_host_name VARCHAR(255), rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
 CREATE TABLE hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, host_attributes LONGTEXT NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, ph_cpu_count INTEGER, public_host_name VARCHAR(255), rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
-CREATE TABLE hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, passive_state VARCHAR(512), PRIMARY KEY (host_name));
 CREATE TABLE servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
 CREATE TABLE servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
-CREATE TABLE servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, service_name));
+CREATE TABLE servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, passive_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE', PRIMARY KEY (cluster_id, service_name));
 CREATE TABLE roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
 CREATE TABLE roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
 CREATE TABLE users (user_id INTEGER, create_time TIMESTAMP DEFAULT NOW(), ldap_user INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL, user_password VARCHAR(255), PRIMARY KEY (user_id));
 CREATE TABLE users (user_id INTEGER, create_time TIMESTAMP DEFAULT NOW(), ldap_user INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL, user_password VARCHAR(255), PRIMARY KEY (user_id));
 CREATE TABLE execution_command (task_id BIGINT NOT NULL, command LONGBLOB, PRIMARY KEY (task_id));
 CREATE TABLE execution_command (task_id BIGINT NOT NULL, command LONGBLOB, PRIMARY KEY (task_id));

+ 3 - 3
ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql

@@ -20,12 +20,12 @@ CREATE TABLE clusters (cluster_id NUMBER(19) NOT NULL, cluster_info VARCHAR2(255
 CREATE TABLE clusterconfig (version_tag VARCHAR2(255) NOT NULL, type_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, config_data CLOB NOT NULL, create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
 CREATE TABLE clusterconfig (version_tag VARCHAR2(255) NOT NULL, type_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, config_data CLOB NOT NULL, create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
 CREATE TABLE clusterservices (service_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, service_enabled NUMBER(10) NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE clusterservices (service_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, service_enabled NUMBER(10) NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE clusterstate (cluster_id NUMBER(19) NOT NULL, current_cluster_state VARCHAR2(255) NULL, current_stack_version VARCHAR2(255) NULL, PRIMARY KEY (cluster_id));
 CREATE TABLE clusterstate (cluster_id NUMBER(19) NOT NULL, current_cluster_state VARCHAR2(255) NULL, current_stack_version VARCHAR2(255) NULL, PRIMARY KEY (cluster_id));
-CREATE TABLE hostcomponentdesiredstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, admin_state VARCHAR2(32) NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentdesiredstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, admin_state VARCHAR2(32) NULL, passive_state VARCHAR2(32) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hostcomponentstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, current_stack_version VARCHAR2(255) NOT NULL, current_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hostcomponentstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, current_stack_version VARCHAR2(255) NOT NULL, current_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE hosts (host_name VARCHAR2(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR2(255) NULL, discovery_status VARCHAR2(2000) NULL, host_attributes CLOB NULL, ipv4 VARCHAR2(255) NULL, ipv6 VARCHAR2(255) NULL, last_registration_time INTEGER NOT NULL, os_arch VARCHAR2(255) NULL, os_info VARCHAR2(1000) NULL, os_type VARCHAR2(255) NULL, ph_cpu_count INTEGER NOT NULL, public_host_name VARCHAR2(255) NULL, rack_info VARCHAR2(255) NOT NULL, total_mem INTEGER NOT NULL, PRIMARY KEY (host_name));
 CREATE TABLE hosts (host_name VARCHAR2(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR2(255) NULL, discovery_status VARCHAR2(2000) NULL, host_attributes CLOB NULL, ipv4 VARCHAR2(255) NULL, ipv6 VARCHAR2(255) NULL, last_registration_time INTEGER NOT NULL, os_arch VARCHAR2(255) NULL, os_info VARCHAR2(1000) NULL, os_type VARCHAR2(255) NULL, ph_cpu_count INTEGER NOT NULL, public_host_name VARCHAR2(255) NULL, rack_info VARCHAR2(255) NOT NULL, total_mem INTEGER NOT NULL, PRIMARY KEY (host_name));
-CREATE TABLE hoststate (agent_version VARCHAR2(255) NULL, available_mem NUMBER(19) NOT NULL, current_state VARCHAR2(255) NOT NULL, health_status VARCHAR2(255) NULL, host_name VARCHAR2(255) NOT NULL, time_in_state NUMBER(19) NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE hoststate (agent_version VARCHAR2(255) NULL, available_mem NUMBER(19) NOT NULL, current_state VARCHAR2(255) NOT NULL, health_status VARCHAR2(255) NULL, host_name VARCHAR2(255) NOT NULL, time_in_state NUMBER(19) NOT NULL, passive_state VARCHAR2(512), PRIMARY KEY (host_name));
 CREATE TABLE servicecomponentdesiredstate (component_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
 CREATE TABLE servicecomponentdesiredstate (component_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
-CREATE TABLE servicedesiredstate (cluster_id NUMBER(19) NOT NULL, desired_host_role_mapping NUMBER(10) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, service_name));
+CREATE TABLE servicedesiredstate (cluster_id NUMBER(19) NOT NULL, desired_host_role_mapping NUMBER(10) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, passive_state VARCHAR2(32) NOT NULL DEFAULT, PRIMARY KEY (cluster_id, service_name));
 CREATE TABLE roles (role_name VARCHAR2(255) NOT NULL, PRIMARY KEY (role_name));
 CREATE TABLE roles (role_name VARCHAR2(255) NOT NULL, PRIMARY KEY (role_name));
 CREATE TABLE users (user_id NUMBER(10) NOT NULL, create_time TIMESTAMP NULL, ldap_user NUMBER(10) DEFAULT 0, user_name VARCHAR2(255) NULL, user_password VARCHAR2(255) NULL, PRIMARY KEY (user_id));
 CREATE TABLE users (user_id NUMBER(10) NOT NULL, create_time TIMESTAMP NULL, ldap_user NUMBER(10) DEFAULT 0, user_name VARCHAR2(255) NULL, user_password VARCHAR2(255) NULL, PRIMARY KEY (user_id));
 CREATE TABLE execution_command (task_id NUMBER(19) NOT NULL, command BLOB NULL, PRIMARY KEY (task_id));
 CREATE TABLE execution_command (task_id NUMBER(19) NOT NULL, command BLOB NULL, PRIMARY KEY (task_id));

+ 3 - 3
ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql

@@ -43,7 +43,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.clusterservices TO :username;
 CREATE TABLE ambari.clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
 CREATE TABLE ambari.clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.clusterstate TO :username;
 GRANT ALL PRIVILEGES ON TABLE ambari.clusterstate TO :username;
 
 
-CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), passive_state VARCHAR(32) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentdesiredstate TO :username;
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentdesiredstate TO :username;
 
 
 CREATE TABLE ambari.hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE ambari.hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
@@ -52,13 +52,13 @@ GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentstate TO :username;
 CREATE TABLE ambari.hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, host_attributes VARCHAR(20000) NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), public_host_name VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
 CREATE TABLE ambari.hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, host_attributes VARCHAR(20000) NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), public_host_name VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.hosts TO :username;
 GRANT ALL PRIVILEGES ON TABLE ambari.hosts TO :username;
 
 
-CREATE TABLE ambari.hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE ambari.hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, passive_state VARCHAR(512), PRIMARY KEY (host_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.hoststate TO :username;
 GRANT ALL PRIVILEGES ON TABLE ambari.hoststate TO :username;
 
 
 CREATE TABLE ambari.servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
 CREATE TABLE ambari.servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.servicecomponentdesiredstate TO :username;
 GRANT ALL PRIVILEGES ON TABLE ambari.servicecomponentdesiredstate TO :username;
 
 
-CREATE TABLE ambari.servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, service_name));
+CREATE TABLE ambari.servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, passive_state VARCHAR(32) NOT NULL, PRIMARY KEY (cluster_id, service_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.servicedesiredstate TO :username;
 GRANT ALL PRIVILEGES ON TABLE ambari.servicedesiredstate TO :username;
 
 
 CREATE TABLE ambari.roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
 CREATE TABLE ambari.roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));

+ 3 - 3
ambari-server/src/main/resources/Ambari-DDL-Postgres-REMOTE-CREATE.sql

@@ -24,12 +24,12 @@ CREATE TABLE ambari.clusterconfig (version_tag VARCHAR(255) NOT NULL, type_name
 CREATE TABLE ambari.clusterconfigmapping (cluster_id bigint NOT NULL, type_name VARCHAR(255) NOT NULL, version_tag VARCHAR(255) NOT NULL, create_timestamp BIGINT NOT NULL, selected INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY (cluster_id, type_name, create_timestamp));
 CREATE TABLE ambari.clusterconfigmapping (cluster_id bigint NOT NULL, type_name VARCHAR(255) NOT NULL, version_tag VARCHAR(255) NOT NULL, create_timestamp BIGINT NOT NULL, selected INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY (cluster_id, type_name, create_timestamp));
 CREATE TABLE ambari.clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_enabled INTEGER NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE ambari.clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_enabled INTEGER NOT NULL, PRIMARY KEY (service_name, cluster_id));
 CREATE TABLE ambari.clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
 CREATE TABLE ambari.clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
-CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, passive_state VARCHAR(32) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE ambari.hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE ambari.hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 CREATE TABLE ambari.hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, host_attributes VARCHAR(20000) NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), public_host_name VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
 CREATE TABLE ambari.hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, host_attributes VARCHAR(20000) NOT NULL, ipv4 VARCHAR(255), ipv6 VARCHAR(255), public_host_name VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
-CREATE TABLE ambari.hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL,  PRIMARY KEY (host_name));
+CREATE TABLE ambari.hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, passive_state VARCHAR(512) PRIMARY KEY (host_name));
 CREATE TABLE ambari.servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
 CREATE TABLE ambari.servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
-CREATE TABLE ambari.servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, service_name));
+CREATE TABLE ambari.servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, passive_state VARCHAR(32) NOT NULL, PRIMARY KEY (cluster_id, service_name));
 CREATE TABLE ambari.roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
 CREATE TABLE ambari.roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
 CREATE TABLE ambari.users (user_id INTEGER, ldap_user INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL, create_time TIMESTAMP DEFAULT NOW(), user_password VARCHAR(255), PRIMARY KEY (user_id), UNIQUE (ldap_user, user_name));
 CREATE TABLE ambari.users (user_id INTEGER, ldap_user INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL, create_time TIMESTAMP DEFAULT NOW(), user_password VARCHAR(255), PRIMARY KEY (user_id), UNIQUE (ldap_user, user_name));
 CREATE TABLE ambari.execution_command (command bytea, task_id BIGINT NOT NULL, PRIMARY KEY (task_id));
 CREATE TABLE ambari.execution_command (command bytea, task_id BIGINT NOT NULL, PRIMARY KEY (task_id));

+ 3 - 0
ambari-server/src/main/resources/properties.json

@@ -11,6 +11,7 @@
         "ServiceInfo/service_name",
         "ServiceInfo/service_name",
         "ServiceInfo/cluster_name",
         "ServiceInfo/cluster_name",
         "ServiceInfo/state",
         "ServiceInfo/state",
+        "ServiceInfo/passive_state",
         "Services/description",
         "Services/description",
         "Services/display_name",
         "Services/display_name",
         "Services/attributes",
         "Services/attributes",
@@ -37,6 +38,7 @@
         "Hosts/host_health_report",
         "Hosts/host_health_report",
         "Hosts/public_host_name",
         "Hosts/public_host_name",
         "Hosts/host_state",
         "Hosts/host_state",
+        "Hosts/passive_state",
         "Hosts/desired_configs",
         "Hosts/desired_configs",
         "_"
         "_"
     ],
     ],
@@ -65,6 +67,7 @@
         "HostRoles/nagios_alerts",
         "HostRoles/nagios_alerts",
         "HostRoles/stale_configs",
         "HostRoles/stale_configs",
         "HostRoles/desired_admin_state",
         "HostRoles/desired_admin_state",
+        "HostRoles/passive_state",
         "_"
         "_"
     ],
     ],
     "Configuration":[
     "Configuration":[

+ 5 - 2
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql

@@ -24,7 +24,6 @@ UPDATE metainfo SET "metainfo_value" = '${ambariVersion}' WHERE metainfo_key = '
 
 
 ALTER TABLE hostcomponentdesiredstate ADD admin_state VARCHAR(32);
 ALTER TABLE hostcomponentdesiredstate ADD admin_state VARCHAR(32);
 
 
-
 --1.5.0
 --1.5.0
 CREATE TABLE request (request_id BIGINT NOT NULL, cluster_id BIGINT, request_schedule_id BIGINT, command_name VARCHAR(255), create_time BIGINT NOT NULL, end_time BIGINT NOT NULL, inputs LONGTEXT, request_context VARCHAR(255), request_type VARCHAR(255), start_time BIGINT NOT NULL, status VARCHAR(255), target_component VARCHAR(255), target_hosts LONGTEXT, target_service VARCHAR(255), PRIMARY KEY (request_id));
 CREATE TABLE request (request_id BIGINT NOT NULL, cluster_id BIGINT, request_schedule_id BIGINT, command_name VARCHAR(255), create_time BIGINT NOT NULL, end_time BIGINT NOT NULL, inputs LONGTEXT, request_context VARCHAR(255), request_type VARCHAR(255), start_time BIGINT NOT NULL, status VARCHAR(255), target_component VARCHAR(255), target_hosts LONGTEXT, target_service VARCHAR(255), PRIMARY KEY (request_id));
 CREATE TABLE requestschedule (schedule_id bigint, cluster_id BIGINT NOT NULL, description varchar(255), status varchar(255), batch_separation_seconds smallint, batch_toleration_limit smallint, create_user varchar(255), create_timestamp bigint, update_user varchar(255), update_timestamp bigint, minutes varchar(10), hours varchar(10), days_of_month varchar(10), month varchar(10), day_of_week varchar(10), yearToSchedule varchar(10), startTime varchar(50), endTime varchar(50), last_execution_status varchar(255), PRIMARY KEY(schedule_id));
 CREATE TABLE requestschedule (schedule_id bigint, cluster_id BIGINT NOT NULL, description varchar(255), status varchar(255), batch_separation_seconds smallint, batch_toleration_limit smallint, create_user varchar(255), create_timestamp bigint, update_user varchar(255), update_timestamp bigint, minutes varchar(10), hours varchar(10), days_of_month varchar(10), month varchar(10), day_of_week varchar(10), yearToSchedule varchar(10), startTime varchar(50), endTime varchar(50), last_execution_status varchar(255), PRIMARY KEY(schedule_id));
@@ -79,4 +78,8 @@ create index idx_qrtz_ft_inst_job_req_rcvry on QRTZ_FIRED_TRIGGERS(SCHED_NAME,IN
 create index idx_qrtz_ft_j_g on QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);
 create index idx_qrtz_ft_j_g on QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);
 create index idx_qrtz_ft_jg on QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP);
 create index idx_qrtz_ft_jg on QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP);
 create index idx_qrtz_ft_t_g on QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
 create index idx_qrtz_ft_t_g on QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
-create index idx_qrtz_ft_tg on QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
+create index idx_qrtz_ft_tg on QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
+
+ALTER TABLE hostcomponentdesiredstate ADD passive_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE';
+ALTER TABLE servicedesiredstate ADD passive_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE';
+ALTER TABLE hoststate ADD passive_state VARCHAR(512);

+ 4 - 0
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql

@@ -27,6 +27,7 @@ ALTER TABLE stage ADD (cluster_host_info BLOB DEFAULT NULL);
 
 
 -- add decommission state
 -- add decommission state
 ALTER TABLE hostcomponentdesiredstate ADD (admin_state VARCHAR2 (32) DEFAULT NULL);
 ALTER TABLE hostcomponentdesiredstate ADD (admin_state VARCHAR2 (32) DEFAULT NULL);
+ALTER TABLE hostcomponentdesiredstate ADD (passive_state VARCHAR2 (32) NOT NULL DEFAULT 'ACTIVE');
 
 
 -- DML
 -- DML
 --Upgrade version to current
 --Upgrade version to current
@@ -401,4 +402,7 @@ create index idx_qrtz_ft_jg on qrtz_fired_triggers(SCHED_NAME,JOB_GROUP);
 create index idx_qrtz_ft_t_g on qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
 create index idx_qrtz_ft_t_g on qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
 create index idx_qrtz_ft_tg on qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);
 create index idx_qrtz_ft_tg on qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);
 
 
+ALTER TABLE hoststate ADD (passive_state VARCHAR2(512) DEFAULT NULL);
+ALTER TABLE servicedesiredstate ADD (passive_state VARCHAR2(32) NOT NULL DEFAULT 'ACTIVE');
+
 commit;
 commit;

+ 4 - 0
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql

@@ -134,6 +134,7 @@ ALTER TABLE ambari.configgrouphostmapping ADD CONSTRAINT FK_configgrouphostmappi
 
 
 -- add decommission state
 -- add decommission state
 ALTER TABLE ambari.hostcomponentdesiredstate ADD COLUMN admin_state VARCHAR(32);
 ALTER TABLE ambari.hostcomponentdesiredstate ADD COLUMN admin_state VARCHAR(32);
+ALTER TABLE ambari.hostcomponentdesiredstate ADD COLUMN passive_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE'
 
 
 --Move cluster host info for old execution commands to stage table
 --Move cluster host info for old execution commands to stage table
 UPDATE ambari.stage sd
 UPDATE ambari.stage sd
@@ -420,3 +421,6 @@ create index idx_qrtz_ft_j_g on ambari.qrtz_fired_triggers(SCHED_NAME,JOB_NAME,J
 create index idx_qrtz_ft_jg on ambari.qrtz_fired_triggers(SCHED_NAME,JOB_GROUP);
 create index idx_qrtz_ft_jg on ambari.qrtz_fired_triggers(SCHED_NAME,JOB_GROUP);
 create index idx_qrtz_ft_t_g on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
 create index idx_qrtz_ft_t_g on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
 create index idx_qrtz_ft_tg on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);
 create index idx_qrtz_ft_tg on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);
+
+ALTER TABLE ambari.hoststate ADD COLUMN passive_state VARCHAR(512);
+ALTER TABLE ambari.servicedesiredstate ADD COLUMN passive_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE';

+ 292 - 36
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -18,14 +18,37 @@
 
 
 package org.apache.ambari.server.controller;
 package org.apache.ambari.server.controller;
 
 
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
-import com.google.inject.persist.Transactional;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.lang.reflect.Type;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+
 import junit.framework.Assert;
 import junit.framework.Assert;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.DuplicateResourceException;
 import org.apache.ambari.server.DuplicateResourceException;
@@ -47,7 +70,6 @@ import org.apache.ambari.server.actionmanager.TargetHostType;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.controller.internal.ActionResourceProviderTest;
 import org.apache.ambari.server.controller.internal.ComponentResourceProviderTest;
 import org.apache.ambari.server.controller.internal.ComponentResourceProviderTest;
 import org.apache.ambari.server.controller.internal.HostResourceProviderTest;
 import org.apache.ambari.server.controller.internal.HostResourceProviderTest;
 import org.apache.ambari.server.controller.internal.ServiceResourceProviderTest;
 import org.apache.ambari.server.controller.internal.ServiceResourceProviderTest;
@@ -72,6 +94,7 @@ import org.apache.ambari.server.state.ConfigImpl;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponent;
@@ -102,33 +125,13 @@ import org.junit.rules.ExpectedException;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
-import javax.persistence.EntityManager;
-import java.io.File;
-import java.lang.reflect.Type;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
+import com.google.inject.persist.Transactional;
 
 
 public class AmbariManagementControllerTest {
 public class AmbariManagementControllerTest {
 
 
@@ -146,7 +149,6 @@ public class AmbariManagementControllerTest {
   private static final int STACK_VERSIONS_CNT = 10;
   private static final int STACK_VERSIONS_CNT = 10;
   private static final int REPOS_CNT = 3;
   private static final int REPOS_CNT = 3;
   private static final int STACKS_CNT = 1;
   private static final int STACKS_CNT = 1;
-  private static final int STACK_SERVICES_CNT = 5 ;
   private static final int STACK_PROPERTIES_CNT = 81;
   private static final int STACK_PROPERTIES_CNT = 81;
   private static final int STACK_COMPONENTS_CNT = 3;
   private static final int STACK_COMPONENTS_CNT = 3;
   private static final int OS_CNT = 2;
   private static final int OS_CNT = 2;
@@ -8867,6 +8869,260 @@ public class AmbariManagementControllerTest {
     }
     }
   }
   }
 
 
+  @Test
+  public void testPassiveStates() throws Exception {
+    String clusterName = "c1";
+    createCluster(clusterName);
+    clusters.getCluster(clusterName)
+        .setDesiredStackVersion(new StackId("HDP-0.1"));
+    String serviceName = "HDFS";
+    createService(clusterName, serviceName, null);
+    String componentName1 = "NAMENODE";
+    String componentName2 = "DATANODE";
+    String componentName3 = "HDFS_CLIENT";
+    createServiceComponent(clusterName, serviceName, componentName1,
+        State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName2,
+        State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName3,
+        State.INIT);
+
+    String host1 = "h1";
+    clusters.addHost(host1);
+    clusters.getHost("h1").setOsType("centos5");
+    clusters.getHost("h1").setState(HostState.HEALTHY);
+    clusters.getHost("h1").persist();
+    String host2 = "h2";
+    clusters.addHost(host2);
+    clusters.getHost("h2").setOsType("centos5");
+    clusters.getHost("h2").setState(HostState.HEALTHY);
+    clusters.getHost("h2").persist();
+    
+    clusters.mapHostToCluster(host1, clusterName);
+    clusters.mapHostToCluster(host2, clusterName);
+
+    createServiceComponentHost(clusterName, serviceName, componentName1, host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2, host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2, host2, null);
+
+    Map<String, String> requestProperties = new HashMap<String, String>();
+    requestProperties.put("context", "Called from a test");
+    
+    
+    Cluster cluster = clusters.getCluster(clusterName);
+    Service service = cluster.getService(serviceName);
+    Map<String, Host> hosts = clusters.getHostsForCluster(clusterName);
+    
+    // test updating a service
+    ServiceRequest sr = new ServiceRequest(clusterName, serviceName, null);
+    sr.setPassiveState(PassiveState.PASSIVE.name());
+    ServiceResourceProviderTest.updateServices(controller, Collections.singleton(sr),
+        requestProperties, false, false);
+    Assert.assertEquals(PassiveState.PASSIVE, service.getPassiveState());
+    
+    // check the host components implied state vs desired state
+    for (ServiceComponent sc : service.getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        Assert.assertEquals(PassiveState.IMPLIED,
+            controller.getEffectivePassiveState(cluster, service, sch));
+        Assert.assertEquals(PassiveState.ACTIVE, sch.getPassiveState());
+      }
+    }
+    
+    // reset
+    sr.setPassiveState(PassiveState.ACTIVE.name());
+    ServiceResourceProviderTest.updateServices(controller, Collections.singleton(sr),
+        requestProperties, false, false);
+    Assert.assertEquals(PassiveState.ACTIVE, service.getPassiveState());
+    
+    // check the host components implied state vs desired state
+    for (ServiceComponent sc : service.getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        Assert.assertEquals(PassiveState.ACTIVE,
+            controller.getEffectivePassiveState(cluster, service, sch));
+        Assert.assertEquals(PassiveState.ACTIVE, sch.getPassiveState());
+      }
+    }
+    
+    // passivate a host
+    HostRequest hr = new HostRequest(host1, clusterName, requestProperties);
+    hr.setPassiveState(PassiveState.PASSIVE.name());
+    HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr));
+    
+    Host host = hosts.get(host1);
+    Assert.assertEquals(PassiveState.PASSIVE, host.getPassiveState(cluster.getClusterId()));
+    
+    // check the host components implied state vs desired state, only for affected hosts
+    for (ServiceComponent sc : service.getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        PassiveState implied = controller.getEffectivePassiveState(cluster, service, sch);
+        if (sch.getHostName().equals(host1)) {
+          Assert.assertEquals(PassiveState.IMPLIED, implied);
+        } else {
+          Assert.assertEquals(PassiveState.ACTIVE, implied);
+        }
+        Assert.assertEquals(PassiveState.ACTIVE, sch.getPassiveState());
+      }
+    }
+    
+    // reset
+    hr.setPassiveState(PassiveState.ACTIVE.name());
+    HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr));
+    
+    host = hosts.get(host1);
+    Assert.assertEquals(PassiveState.ACTIVE, host.getPassiveState(cluster.getClusterId()));
+    
+    // check the host components active state vs desired state
+    for (ServiceComponent sc : service.getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        Assert.assertEquals(PassiveState.ACTIVE,
+            controller.getEffectivePassiveState(cluster, service, sch));
+        Assert.assertEquals(PassiveState.ACTIVE, sch.getPassiveState());
+      }
+    }
+    
+    // only do one SCH
+    ServiceComponentHost targetSch = service.getServiceComponent(
+        componentName2).getServiceComponentHosts().get(host2);
+    Assert.assertNotNull(targetSch);
+    targetSch.setPassiveState(PassiveState.PASSIVE);
+
+    // check the host components active state vs desired state
+    Assert.assertEquals(PassiveState.PASSIVE, controller.getEffectivePassiveState(cluster, service, targetSch));
+    
+    // update the service
+    service.setPassiveState(PassiveState.PASSIVE);
+    Assert.assertEquals(PassiveState.PASSIVE, controller.getEffectivePassiveState(cluster, service, targetSch));
+    
+    // make SCH active
+    targetSch.setPassiveState(PassiveState.ACTIVE);
+    Assert.assertEquals(PassiveState.IMPLIED, controller.getEffectivePassiveState(cluster, service, targetSch));
+    
+    // update the service
+    service.setPassiveState(PassiveState.ACTIVE);
+    Assert.assertEquals(PassiveState.ACTIVE, controller.getEffectivePassiveState(cluster, service, targetSch));
+    
+    host = hosts.get(host2);
+    // update host
+    host.setPassiveState(cluster.getClusterId(), PassiveState.PASSIVE);
+    Assert.assertEquals(PassiveState.IMPLIED, controller.getEffectivePassiveState(cluster, service, targetSch));
+    
+    targetSch.setPassiveState(PassiveState.PASSIVE);
+    Assert.assertEquals(PassiveState.PASSIVE, controller.getEffectivePassiveState(cluster, service, targetSch));
+
+  }
+
+  @Test
+  public void testPassiveSkipServices() throws Exception {
+    String clusterName = "c1";
+    createCluster(clusterName);
+    clusters.getCluster(clusterName)
+        .setDesiredStackVersion(new StackId("HDP-0.1"));
+    
+    String serviceName1 = "HDFS";
+    String serviceName2 = "MAPREDUCE";
+    createService(clusterName, serviceName1, null);
+    createService(clusterName, serviceName2, null);
+    
+    String componentName1_1 = "NAMENODE";
+    String componentName1_2 = "DATANODE";
+    String componentName1_3 = "HDFS_CLIENT";
+    createServiceComponent(clusterName, serviceName1, componentName1_1,
+        State.INIT);
+    createServiceComponent(clusterName, serviceName1, componentName1_2,
+        State.INIT);
+    createServiceComponent(clusterName, serviceName1, componentName1_3,
+        State.INIT);
+    
+    String componentName2_1 = "JOBTRACKER";
+    String componentName2_2 = "TASKTRACKER";
+    createServiceComponent(clusterName, serviceName2, componentName2_1,
+        State.INIT);
+    createServiceComponent(clusterName, serviceName2, componentName2_2,
+        State.INIT);
+    
+
+    String host1 = "h1";
+    clusters.addHost(host1);
+    clusters.getHost("h1").setOsType("centos5");
+    clusters.getHost("h1").setState(HostState.HEALTHY);
+    clusters.getHost("h1").persist();
+    String host2 = "h2";
+    clusters.addHost(host2);
+    clusters.getHost("h2").setOsType("centos5");
+    clusters.getHost("h2").setState(HostState.HEALTHY);
+    clusters.getHost("h2").persist();
+    
+    clusters.mapHostToCluster(host1, clusterName);
+    clusters.mapHostToCluster(host2, clusterName);
+
+    createServiceComponentHost(clusterName, serviceName1, componentName1_1, host1, null);
+    createServiceComponentHost(clusterName, serviceName1, componentName1_2, host1, null);
+    createServiceComponentHost(clusterName, serviceName1, componentName1_2, host2, null);
+    
+    createServiceComponentHost(clusterName, serviceName2, componentName2_1, host1, null);
+    createServiceComponentHost(clusterName, serviceName2, componentName2_2, host2, null);
+    
+    installService(clusterName, serviceName1, false, false);
+    installService(clusterName, serviceName2, false, false);
+    
+    startService(clusterName, serviceName1, false, false);
+    startService(clusterName, serviceName2, false, false);
+    
+    Map<String, String> requestProperties = new HashMap<String, String>();
+    requestProperties.put("context", "Called from a test");
+    
+    Cluster cluster = clusters.getCluster(clusterName);
+    
+    for (Service service : cluster.getServices().values()) {
+      Assert.assertEquals(State.STARTED, service.getDesiredState());
+    }
+    
+    Service service2 = cluster.getService(serviceName2);
+    service2.setPassiveState(PassiveState.PASSIVE);
+    
+    Set<ServiceRequest> srs = new HashSet<ServiceRequest>();
+    srs.add(new ServiceRequest(clusterName, serviceName1, State.INSTALLED.name()));
+    srs.add(new ServiceRequest(clusterName, serviceName2, State.INSTALLED.name()));
+    RequestStatusResponse rsr = ServiceResourceProviderTest.updateServices(controller, srs, requestProperties, false, false);
+    
+    for (ShortTaskStatus sts : rsr.getTasks()) {
+      String role = sts.getRole();
+      Assert.assertFalse(role.equals(componentName2_1));
+      Assert.assertFalse(role.equals(componentName2_2));
+    }
+
+    for (Service service : cluster.getServices().values()) {
+      if (service.getName().equals(serviceName2))
+        Assert.assertEquals(State.STARTED, service.getDesiredState());
+      else
+        Assert.assertEquals(State.INSTALLED, service.getDesiredState());
+    }
+    
+    service2.setPassiveState(PassiveState.ACTIVE);
+    ServiceResourceProviderTest.updateServices(controller, srs, requestProperties, false, false);
+    for (Service service : cluster.getServices().values()) {
+      Assert.assertEquals(State.INSTALLED, service.getDesiredState());
+    }
+    
+    startService(clusterName, serviceName1, false, false);
+    startService(clusterName, serviceName2, false, false);
+    
+    // test host
+    Host h1 = clusters.getHost(host1);
+    h1.setPassiveState(cluster.getClusterId(), PassiveState.PASSIVE);
+    
+    srs = new HashSet<ServiceRequest>();
+    srs.add(new ServiceRequest(clusterName, serviceName1, State.INSTALLED.name()));
+    srs.add(new ServiceRequest(clusterName, serviceName2, State.INSTALLED.name()));
+    
+    rsr = ServiceResourceProviderTest.updateServices(controller, srs, requestProperties, false, false);
+    
+    for (ShortTaskStatus sts : rsr.getTasks()) {
+      Assert.assertFalse(sts.getHostName().equals(host1));
+    }
+    
+  }  
 }
 }
 
 
   
   

+ 7 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java

@@ -1142,4 +1142,11 @@ public class HostResourceProviderTest {
     HostResourceProvider provider = getHostProvider(controller);
     HostResourceProvider provider = getHostProvider(controller);
     provider.deleteHosts(requests);
     provider.deleteHosts(requests);
   }
   }
+  
+  public static void updateHosts(AmbariManagementController controller, Set<HostRequest> requests)
+      throws AmbariException {
+    HostResourceProvider provider = getHostProvider(controller);
+    provider.updateHosts(requests);
+  }
+  
 }
 }

+ 37 - 5
ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java

@@ -18,13 +18,14 @@
 
 
 package org.apache.ambari.server.state;
 package org.apache.ambari.server.state;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
 
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
-
 import junit.framework.Assert;
 import junit.framework.Assert;
 
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.AmbariException;
@@ -32,11 +33,15 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.ServiceResponse;
 import org.apache.ambari.server.controller.ServiceResponse;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
+import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.junit.After;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.Test;
 
 
-import static org.junit.Assert.*;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
 
 
 public class ServiceTest {
 public class ServiceTest {
 
 
@@ -279,4 +284,31 @@ public class ServiceTest {
     }
     }
   }
   }
 
 
+  @Test
+  public void testServicePassive() throws Exception {
+    String serviceName = "HDFS";
+    Service s = serviceFactory.createNew(cluster, serviceName);
+    cluster.addService(s);
+    s.persist();
+
+    Service service = cluster.getService(serviceName);
+    Assert.assertNotNull(service);
+
+    ClusterServiceDAO dao = injector.getInstance(ClusterServiceDAO.class);
+    ClusterServiceEntity entity = dao.findByClusterAndServiceNames(clusterName, serviceName);
+    Assert.assertNotNull(entity);
+    Assert.assertEquals(PassiveState.ACTIVE, entity.getServiceDesiredStateEntity().getPassiveState());
+    Assert.assertEquals(PassiveState.ACTIVE, service.getPassiveState());
+    
+    service.setPassiveState(PassiveState.PASSIVE);
+    Assert.assertEquals(PassiveState.PASSIVE, service.getPassiveState());
+
+    entity = dao.findByClusterAndServiceNames(clusterName, serviceName);
+    Assert.assertNotNull(entity);
+    Assert.assertEquals(PassiveState.PASSIVE, entity.getServiceDesiredStateEntity().getPassiveState());
+    
+    
+  }
+  
+  
 }
 }

+ 33 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java

@@ -40,6 +40,7 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.entities.HostStateEntity;
 import org.apache.ambari.server.state.AgentVersion;
 import org.apache.ambari.server.state.AgentVersion;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Clusters;
@@ -50,6 +51,7 @@ import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostHealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackId;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.LogFactory;
@@ -410,4 +412,35 @@ public class HostTest {
     Assert.assertEquals("Expect no mapping configs", 0, map.size());
     Assert.assertEquals("Expect no mapping configs", 0, map.size());
     
     
   }
   }
+  
+  @Test
+  public void testHostPassive() throws Exception {
+    AmbariMetaInfo metaInfo = injector.getInstance(AmbariMetaInfo.class);
+    metaInfo.init();
+    
+    clusters.addCluster("c1");
+    Cluster c1 = clusters.getCluster("c1");
+    Assert.assertEquals("c1", c1.getClusterName());
+    Assert.assertEquals(1, c1.getClusterId());
+    clusters.addHost("h1");
+    Host host = clusters.getHost("h1");
+    host.setIPv4("ipv4");
+    host.setIPv6("ipv6");
+    host.setOsType("centos5");
+    host.persist();
+    c1.setDesiredStackVersion(new StackId("HDP-0.1"));
+    clusters.mapHostToCluster("h1", "c1");
+
+    HostEntity entity = hostDAO.findByName("h1");
+    HostStateEntity stateEntity = entity.getHostStateEntity();
+    Assert.assertNull(stateEntity.getPassiveState());
+    Assert.assertEquals(PassiveState.ACTIVE, host.getPassiveState(c1.getClusterId()));
+    
+    host.setPassiveState(c1.getClusterId(), PassiveState.PASSIVE);
+
+    entity = hostDAO.findByName("h1");
+    stateEntity = entity.getHostStateEntity();
+    Assert.assertNotNull(stateEntity.getPassiveState());
+    Assert.assertEquals(PassiveState.PASSIVE, host.getPassiveState(c1.getClusterId()));
+  }
 }
 }

+ 44 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java

@@ -30,12 +30,16 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.ServiceComponentHostResponse;
 import org.apache.ambari.server.controller.ServiceComponentHostResponse;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
+import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostConfig;
 import org.apache.ambari.server.state.HostConfig;
+import org.apache.ambari.server.state.PassiveState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentFactory;
 import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -796,6 +800,46 @@ public class ServiceComponentHostTest {
     cluster.addConfig(config);
     cluster.addConfig(config);
     cluster.addDesiredConfig("user", config);
     cluster.addDesiredConfig("user", config);
   }
   }
+  
+  @Test
+  public void testPassive() throws Exception {
+    String stackVersion="HDP-2.0.6";
+    String clusterName = "c2";
+    String hostName = "h3";
+    
+    clusters.addCluster(clusterName);
+    clusters.addHost(hostName);
+    clusters.getHost(hostName).setOsType("centos5");
+    clusters.getHost(hostName).persist();
+    clusters.getCluster(clusterName).setDesiredStackVersion(
+        new StackId(stackVersion));
+    metaInfo.init();
+    clusters.mapHostToCluster(hostName, clusterName);    
+    
+    Cluster cluster = clusters.getCluster(clusterName);
+    
+    ServiceComponentHost sch1 = createNewServiceComponentHost(cluster, "HDFS", "NAMENODE", hostName);
+    ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName);
+    ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName);
+
+    HostComponentDesiredStateEntityPK pk = new HostComponentDesiredStateEntityPK();
+    pk.setClusterId(Long.valueOf(cluster.getClusterId()));
+    pk.setComponentName(sch1.getServiceComponentName());
+    pk.setServiceName(sch1.getServiceName());
+    pk.setHostName(hostName);
+    
+    HostComponentDesiredStateDAO dao = injector.getInstance(HostComponentDesiredStateDAO.class);
+    HostComponentDesiredStateEntity entity = dao.findByPK(pk);
+    Assert.assertEquals(PassiveState.ACTIVE, entity.getPassiveState());
+    Assert.assertEquals(PassiveState.ACTIVE, sch1.getPassiveState());
+    
+    sch1.setPassiveState(PassiveState.PASSIVE);
+    Assert.assertEquals(PassiveState.PASSIVE, sch1.getPassiveState());
+    
+    entity = dao.findByPK(pk);
+    Assert.assertEquals(PassiveState.PASSIVE, entity.getPassiveState());
+
+  }