You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2014/01/27 19:26:05 UTC
[1/2] AMBARI-4419. Add Passive state for Host, Service,
HostComponent (ncole)
Updated Branches:
refs/heads/trunk bc102b327 -> 95f0159ac
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index bc2039e..f36471f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -18,14 +18,37 @@
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 org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ClusterNotFoundException;
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.api.services.AmbariMetaInfo;
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.HostResourceProviderTest;
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.HostComponentAdminState;
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.Service;
import org.apache.ambari.server.state.ServiceComponent;
@@ -102,33 +125,13 @@ import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
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 {
@@ -146,7 +149,6 @@ public class AmbariManagementControllerTest {
private static final int STACK_VERSIONS_CNT = 10;
private static final int REPOS_CNT = 3;
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_COMPONENTS_CNT = 3;
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));
+ }
+
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
index 9bf0c94..951c4ad 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
@@ -1142,4 +1142,11 @@ public class HostResourceProviderTest {
HostResourceProvider provider = getHostProvider(controller);
provider.deleteHosts(requests);
}
+
+ public static void updateHosts(AmbariManagementController controller, Set<HostRequest> requests)
+ throws AmbariException {
+ HostResourceProvider provider = getHostProvider(controller);
+ provider.updateHosts(requests);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
index f9658fa..066f4c4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
@@ -18,13 +18,14 @@
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.Map;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
-
import junit.framework.Assert;
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.orm.GuiceJpaInitializer;
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.Before;
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 {
@@ -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());
+
+
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
index 272a448..50ef1ad 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
+++ b/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.dao.HostDAO;
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.Cluster;
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.HealthStatus;
import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.PassiveState;
import org.apache.ambari.server.state.StackId;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -410,4 +412,35 @@ public class HostTest {
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()));
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index da3e3e1..6046bb8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/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.orm.GuiceJpaInitializer;
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.Clusters;
import org.apache.ambari.server.state.Config;
import org.apache.ambari.server.state.ConfigFactory;
import org.apache.ambari.server.state.Host;
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.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -796,6 +800,46 @@ public class ServiceComponentHostTest {
cluster.addConfig(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());
+
+ }
[2/2] git commit: AMBARI-4419. Add Passive state for Host, Service,
HostComponent (ncole)
Posted by nc...@apache.org.
AMBARI-4419. Add Passive state for Host, Service, HostComponent (ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/95f0159a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/95f0159a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/95f0159a
Branch: refs/heads/trunk
Commit: 95f0159acb8766b3e43ed6a46796c3bf5d1255fd
Parents: bc102b3
Author: Nate Cole <nc...@hortonworks.com>
Authored: Fri Jan 24 17:34:26 2014 -0500
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Mon Jan 27 13:23:48 2014 -0500
----------------------------------------------------------------------
.../controller/AmbariManagementController.java | 12 +
.../AmbariManagementControllerImpl.java | 45 ++-
.../ambari/server/controller/HostRequest.java | 10 +-
.../ambari/server/controller/HostResponse.java | 18 +-
.../controller/ServiceComponentHostRequest.java | 22 +-
.../ServiceComponentHostResponse.java | 15 +
.../server/controller/ServiceRequest.java | 16 +-
.../server/controller/ServiceResponse.java | 18 +-
.../internal/HostComponentResourceProvider.java | 17 +
.../internal/HostResourceProvider.java | 40 ++-
.../internal/ServiceResourceProvider.java | 44 +++
.../HostComponentDesiredStateEntity.java | 13 +
.../server/orm/entities/HostStateEntity.java | 13 +
.../orm/entities/ServiceDesiredStateEntity.java | 14 +
.../org/apache/ambari/server/state/Host.java | 13 +
.../ambari/server/state/PassiveState.java | 37 +++
.../org/apache/ambari/server/state/Service.java | 12 +
.../server/state/ServiceComponentHost.java | 12 +
.../apache/ambari/server/state/ServiceImpl.java | 23 ++
.../ambari/server/state/host/HostImpl.java | 115 ++++---
.../svccomphost/ServiceComponentHostImpl.java | 33 +-
.../main/resources/Ambari-DDL-MySQL-CREATE.sql | 6 +-
.../main/resources/Ambari-DDL-Oracle-CREATE.sql | 6 +-
.../resources/Ambari-DDL-Postgres-CREATE.sql | 6 +-
.../Ambari-DDL-Postgres-REMOTE-CREATE.sql | 6 +-
.../src/main/resources/properties.json | 3 +
.../upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql | 7 +-
.../upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql | 4 +
.../ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql | 4 +
.../AmbariManagementControllerTest.java | 328 +++++++++++++++++--
.../internal/HostResourceProviderTest.java | 7 +
.../apache/ambari/server/state/ServiceTest.java | 42 ++-
.../ambari/server/state/host/HostTest.java | 33 ++
.../svccomphost/ServiceComponentHostTest.java | 44 +++
34 files changed, 916 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
index 26a02a4..cab12e9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
+++ b/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.state.Cluster;
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.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -518,5 +519,16 @@ public interface AmbariManagementController {
* Get Execution Schedule Manager
*/
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;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index a9b6364..2e1c3cd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/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.Collection;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -78,6 +79,7 @@ import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;
import com.google.inject.persist.Transactional;
+
import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.*;
@Singleton
@@ -666,7 +668,7 @@ public class AmbariManagementControllerImpl implements
}
checkDesiredState = true;
}
-
+
for (Service s : services) {
// filter on component name if provided
Set<ServiceComponent> components = new HashSet<ServiceComponent>();
@@ -705,6 +707,7 @@ public class AmbariManagementControllerImpl implements
if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
continue;
}
+ r.setPassiveState(getEffectivePassiveState(cluster, s, sch).name());
response.add(r);
} catch (ServiceComponentHostNotFoundException e) {
if (request.getServiceName() != null && request.getComponentName() != null) {
@@ -736,6 +739,8 @@ public class AmbariManagementControllerImpl implements
if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
continue;
}
+
+ r.setPassiveState(getEffectivePassiveState(cluster, s, sch).name());
response.add(r);
}
}
@@ -743,6 +748,30 @@ public class AmbariManagementControllerImpl implements
}
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(
ConfigurationRequest request) throws AmbariException {
@@ -1471,6 +1500,20 @@ public class AmbariManagementControllerImpl implements
+ " 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 (LOG.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/HostRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/HostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/HostRequest.java
index 12dd0f6..398b3a7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/HostRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/HostRequest.java
@@ -18,7 +18,6 @@
package org.apache.ambari.server.controller;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -30,6 +29,7 @@ public class HostRequest {
private Map<String, String> hostAttributes; // CREATE/UPDATE
private String rackInfo;
private ConfigurationRequest desiredConfig; // UPDATE
+ private String passiveState; // UPDATE
public HostRequest(String hostname, String clusterName, Map<String, String> hostAttributes) {
this.hostname = hostname;
@@ -84,6 +84,14 @@ public class HostRequest {
public ConfigurationRequest getDesiredConfig() {
return desiredConfig;
}
+
+ public void setPassiveState(String state) {
+ passiveState = state;
+ }
+
+ public String getPassiveState() {
+ return passiveState;
+ }
public String toString() {
StringBuilder sb = new StringBuilder();
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java
index 616a1ea..97bc7b7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/HostResponse.java
+++ b/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.HostConfig;
import org.apache.ambari.server.state.HostHealthStatus;
+import org.apache.ambari.server.state.PassiveState;
public class HostResponse {
@@ -144,6 +145,8 @@ public class HostResponse {
*/
private String status;
+ private PassiveState passiveState = null;
+
public HostResponse(String hostname, String clusterName,
String ipv4, String ipv6, int cpuCount, int phCpuCount, String osArch, String osType,
String osInfo, long availableMemBytes, long totalMemBytes,
@@ -151,7 +154,6 @@ public class HostResponse {
long lastRegistrationTime, String rackInfo,
Map<String, String> hostAttributes, AgentVersion agentVersion,
HostHealthStatus healthStatus, String hostState, String status) {
- super();
this.hostname = hostname;
this.clusterName = clusterName;
this.ipv4 = ipv4;
@@ -519,4 +521,18 @@ public class HostResponse {
public void setStatus(String status) {
this.status = status;
}
+
+ /**
+ * @param state
+ */
+ public void setPassiveState(PassiveState state) {
+ passiveState = state;
+ }
+
+ /**
+ * @return the passive state
+ */
+ public PassiveState getPassiveState() {
+ return passiveState;
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
index 6b673b0..0891560 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
+++ b/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 {
private String clusterName; // REF
-
private String serviceName;
-
private String componentName;
-
private String hostname;
-
private String desiredState; // CREATE/UPDATE
-
private String desiredStackId; // UPDATE
-
private String staleConfig; // GET - predicate
-
private String adminState; // GET - predicate
+ private String passiveState; // UPDATE
public ServiceComponentHostRequest(String clusterName,
String serviceName,
@@ -177,4 +171,18 @@ public class ServiceComponentHostRequest {
+ "}");
return sb.toString();
}
+
+ /**
+ * @param state the passive state
+ */
+ public void setPassiveState(String state) {
+ passiveState = state;
+ }
+
+ /**
+ * @return the passive state
+ */
+ public String getPassiveState() {
+ return passiveState;
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
index a776ac2..2777f3f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
@@ -37,6 +37,7 @@ public class ServiceComponentHostResponse {
private String desiredState;
private boolean staleConfig = false;
private String adminState = null;
+ private String passiveState = null;
public ServiceComponentHostResponse(String clusterName, String serviceName,
@@ -252,4 +253,18 @@ public class ServiceComponentHostResponse {
staleConfig = stale;
}
+ /**
+ * @return the passive state
+ */
+ public String getPassiveState() {
+ return passiveState;
+ }
+
+ /**
+ * @param state the passive state
+ */
+ public void setPassiveState(String state) {
+ passiveState = state;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceRequest.java
index 03ea6a9..d98e7a1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceRequest.java
@@ -18,17 +18,16 @@
package org.apache.ambari.server.controller;
+
public class ServiceRequest {
private String clusterName; // REF
-
private String serviceName; // GET/CREATE/UPDATE/DELETE
-
private String desiredState; // CREATE/UPDATE
+ private String passiveState; // UPDATE
public ServiceRequest(String clusterName, String serviceName,
String desiredState) {
- super();
this.clusterName = clusterName;
this.serviceName = serviceName;
this.desiredState = desiredState;
@@ -75,6 +74,17 @@ public class ServiceRequest {
public void setClusterName(String 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() {
StringBuilder sb = new StringBuilder();
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
index 82b61e8..99cb100 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
@@ -18,30 +18,28 @@
package org.apache.ambari.server.controller;
-import java.util.Map;
+import org.apache.ambari.server.state.PassiveState;
public class ServiceResponse {
private Long clusterId;
-
private String clusterName;
-
private String serviceName;
-
private String desiredStackVersion;
-
private String desiredState;
+ private String passiveState;
public ServiceResponse(Long clusterId, String clusterName,
String serviceName,
String desiredStackVersion, String desiredState) {
- super();
this.clusterId = clusterId;
this.clusterName = clusterName;
this.serviceName = serviceName;
this.setDesiredStackVersion(desiredStackVersion);
this.setDesiredState(desiredState);
}
+
+
/**
* @return the serviceName
@@ -135,6 +133,14 @@ public class ServiceResponse {
return true;
}
+
+ public void setPassiveState(String state) {
+ passiveState = state;
+ }
+
+ public String getPassiveState() {
+ return passiveState;
+ }
@Override
public int hashCode() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
index dbc81a2..c2ca857 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
+++ b/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.AssistedInject;
import com.google.inject.persist.Transactional;
+
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
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.UnsupportedPropertyException;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.state.PassiveState;
import java.util.Arrays;
import java.util.HashMap;
@@ -75,6 +77,9 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
= PropertyHelper.getPropertyId("HostRoles", "stale_configs");
protected static final String HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID
= PropertyHelper.getPropertyId("HostRoles", "desired_admin_state");
+ protected static final String HOST_COMPONENT_PASSIVE_STATE_PROPERTY_ID
+ = "HostRoles/passive_state";
+
//Component name mappings
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
@@ -192,10 +197,16 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
response.getActualConfigs(), requestedIds);
setResourceProperty(resource, HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID,
Boolean.valueOf(response.isStaleConfig()), requestedIds);
+
if (response.getAdminState() != null) {
setResourceProperty(resource, HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID,
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);
PropertyProvider propertyProvider = HOST_COMPONENT_PROPERTIES_PROVIDER.get(componentName);
@@ -302,10 +313,16 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
serviceComponentHostRequest.setStaleConfig(
properties.get(HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID).toString().toLowerCase());
}
+
if (properties.get(HOST_COMPONENT_DESIRED_ADMIN_STATE_PROPERTY_ID) != null) {
serviceComponentHostRequest.setAdminState(
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;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index 1759826..1eb9a8a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ b/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.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
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.ObjectNotFoundException;
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.ConfigurationRequest;
import org.apache.ambari.server.controller.HostRequest;
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.NoSuchResourceException;
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.state.Cluster;
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.DesiredConfig;
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.StackId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import com.google.inject.persist.Transactional;
@@ -106,7 +100,8 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
protected static final String HOST_HOST_STATUS_PROPERTY_ID =
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 =
PropertyHelper.getPropertyId("Hosts", "host_health_report");
@@ -232,6 +227,13 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
response.getHostState(), requestedIds);
setResourceProperty(resource, HOST_DESIRED_CONFIGS_PROPERTY_ID,
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);
}
return resources;
@@ -319,6 +321,10 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
hostRequest.setPublicHostName((String) properties.get(HOST_PUBLIC_NAME_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);
hostRequest.setDesiredConfig(cr);
@@ -488,8 +494,10 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
if (clusterName != null) {
if (clusters.getClustersForHost(h.getHostName()).contains(cluster)) {
HostResponse r = h.convertToResponse();
+
r.setClusterName(clusterName);
r.setDesiredHostConfigs(h.getDesiredHostConfigs(cluster));
+ r.setPassiveState(h.getPassiveState(cluster.getClusterId()));
response.add(r);
} else if (hostName != null) {
@@ -555,6 +563,20 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
if (null != 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()) {
Cluster c = clusters.getCluster(request.getClusterName());
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
index 6387255..1145b1b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
+++ b/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.Collection;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
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.Clusters;
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.ServiceComponent;
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_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_PASSIVE_STATE_PROPERTY_ID = PropertyHelper.getPropertyId("ServiceInfo", "passive_state");
//Parameters from the predicate
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,
calculateServiceState(response.getClusterName(), response.getServiceName()),
requestedIds);
+ setResourceProperty(resource, SERVICE_PASSIVE_STATE_PROPERTY_ID,
+ response.getPassiveState(), requestedIds);
resources.add(resource);
}
return resources;
@@ -270,6 +275,10 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
(String) properties.get(SERVICE_CLUSTER_NAME_PROPERTY_ID),
(String) properties.get(SERVICE_SERVICE_NAME_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;
}
@@ -541,6 +550,18 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
+ " 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 (LOG.isDebugEnabled()) {
@@ -551,6 +572,13 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
}
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);
@@ -619,6 +647,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
}
continue;
}
+
if (newState == oldSchState) {
ignoredScHosts.add(sch);
if (LOG.isDebugEnabled()) {
@@ -632,6 +661,21 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
}
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() &&
!newState.isValidClientComponentState()) {
continue;
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
index 7f04c51..ed9da4b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
+++ b/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 org.apache.ambari.server.state.HostComponentAdminState;
+import org.apache.ambari.server.state.PassiveState;
import org.apache.ambari.server.state.State;
import static org.apache.commons.lang.StringUtils.defaultString;
@@ -68,6 +69,10 @@ public class HostComponentDesiredStateEntity {
@ManyToOne
@JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
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() {
return clusterId;
@@ -125,6 +130,14 @@ public class HostComponentDesiredStateEntity {
public void setAdminState(HostComponentAdminState attribute) {
this.adminState = attribute;
}
+
+ public PassiveState getPassiveState() {
+ return passiveState;
+ }
+
+ public void setPassiveState(PassiveState state) {
+ passiveState = state;
+ }
@Override
public boolean equals(Object o) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
index 35b9a4d..a535222 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
@@ -19,6 +19,7 @@
package org.apache.ambari.server.orm.entities;
import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.PassiveState;
import org.apache.commons.lang.StringUtils;
import javax.persistence.*;
@@ -52,6 +53,10 @@ public class HostStateEntity {
@Column(name = "current_state", nullable = false, insertable = true, updatable = true)
@Enumerated(value = EnumType.STRING)
private HostState currentState = HostState.INIT;
+
+ @Column(name="passive_state", nullable = true, insertable = true, updatable = true)
+ private String passiveState = null;
+
@OneToOne
@JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
@@ -105,6 +110,14 @@ public class HostStateEntity {
this.currentState = currentState;
}
+ public String getPassiveState() {
+ return passiveState;
+ }
+
+ public void setPassiveState(String state) {
+ passiveState = state;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
index 1af9406..3457934 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.orm.entities;
+import org.apache.ambari.server.state.PassiveState;
import org.apache.ambari.server.state.State;
import org.apache.commons.lang.StringUtils;
@@ -48,6 +49,11 @@ public class ServiceDesiredStateEntity {
@Basic
private String desiredStackVersion = "";
+ @Column(name = "passive_state", nullable = false, insertable = true, updatable = true)
+ @Enumerated(value = EnumType.STRING)
+ private PassiveState passiveState = PassiveState.ACTIVE;
+
+
@OneToOne
@javax.persistence.JoinColumns(
{
@@ -95,6 +101,14 @@ public class ServiceDesiredStateEntity {
public void setDesiredStackVersion(String desiredStackVersion) {
this.desiredStackVersion = desiredStackVersion;
}
+
+ public PassiveState getPassiveState() {
+ return passiveState;
+ }
+
+ public void setPassiveState(PassiveState state) {
+ passiveState = state;
+ }
@Override
public boolean equals(Object o) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
index 832de26..491356f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
@@ -329,4 +329,17 @@ public interface Host {
* @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);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/state/PassiveState.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/PassiveState.java b/ambari-server/src/main/java/org/apache/ambari/server/state/PassiveState.java
new file mode 100644
index 0000000..e7f2d2a
--- /dev/null
+++ b/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
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
index 5fe2d71..b4238e0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
+++ b/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 com.google.inject.persist.Transactional;
+
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.ServiceResponse;
@@ -87,6 +88,17 @@ public interface Service {
* @return cluster-global lock
*/
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 {
HDFS,
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
index 4ce632a..cff1861 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
+++ b/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 HostState getHostState();
+
+ /**
+ * @param state the passive state
+ */
+ public void setPassiveState(PassiveState state);
+
+ /**
+ * @return the passive state
+ */
+ public PassiveState getPassiveState();
+
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
index 0e978ea..f8b3785 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
@@ -384,6 +384,8 @@ public class ServiceImpl implements Service {
getName(),
getDesiredStackVersion().getStackId(),
getDesiredState().toString());
+
+ r.setPassiveState(getPassiveState().name());
return r;
} finally {
readWriteLock.readLock().unlock();
@@ -648,5 +650,26 @@ public class ServiceImpl implements Service {
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();
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
index f8bf36e..4ffb369 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
+++ b/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.HostConfigMappingImpl;
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.HostDAO;
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.HealthStatus;
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.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.fsm.SingleArcTransition;
@@ -71,12 +71,30 @@ import com.google.inject.persist.Transactional;
public class HostImpl implements Host {
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 static final Type diskInfoType =
- new TypeToken<List<DiskInfo>>() {}.getType();
private static final Type hostAttributesType =
new TypeToken<Map<String, String>>() {}.getType();
+ private static final Type passiveMapType =
+ new TypeToken<Map<Long, PassiveState>>() {}.getType();
ReadWriteLock rwLock;
private final Lock readLock;
@@ -84,37 +102,21 @@ public class HostImpl implements Host {
private HostEntity hostEntity;
private HostStateEntity hostStateEntity;
- private Injector injector;
private HostDAO hostDAO;
private HostStateDAO hostStateDAO;
private ClusterDAO clusterDAO;
private Clusters clusters;
private HostConfigMappingDAO hostConfigMappingDAO;
- private ConfigGroupHostMappingDAO configGroupHostMappingDAO;
private long lastHeartbeatTime = 0L;
private AgentEnv lastAgentEnv = null;
private List<DiskInfo> disksInfo = new ArrayList<DiskInfo>();
private boolean persisted = false;
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
@@ -205,8 +207,6 @@ public class HostImpl implements Host {
.installTopology();
- private final StateMachine<HostState, HostEventType, HostEvent> stateMachine;
-
@Inject
public HostImpl(@Assisted HostEntity hostEntity,
@Assisted boolean persisted, Injector injector) {
@@ -216,7 +216,6 @@ public class HostImpl implements Host {
this.writeLock = rwLock.writeLock();
this.hostEntity = hostEntity;
- this.injector = injector;
this.persisted = persisted;
this.hostDAO = injector.getInstance(HostDAO.class);
this.hostStateDAO = injector.getInstance(HostStateDAO.class);
@@ -224,8 +223,6 @@ public class HostImpl implements Host {
this.clusterDAO = injector.getInstance(ClusterDAO.class);
this.clusters = injector.getInstance(Clusters.class);
this.hostConfigMappingDAO = injector.getInstance(HostConfigMappingDAO.class);
- this.configGroupHostMappingDAO = injector.getInstance
- (ConfigGroupHostMappingDAO.class);
hostStateEntity = hostEntity.getHostStateEntity();
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
implements SingleArcTransition<HostImpl, HostEvent> {
@@ -1239,6 +1226,60 @@ public class HostImpl implements Host {
HostConfigMapping findSelectedByType = hostConfigMappingDAO.findSelectedByType(clusterId,
hostEntity.getHostName(), type);
+
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();
+ }
+ }
+
}
+
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index d9135c0..b90027b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/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.HostConfig;
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.ServiceComponentHost;
import org.apache.ambari.server.state.ServiceComponentHostEvent;
@@ -481,7 +482,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
.installTopology();
-
private final StateMachine<State,
ServiceComponentHostEventType, ServiceComponentHostEvent> stateMachine;
@@ -1367,8 +1367,37 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
} finally {
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();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 4f6068e..0aa3f5b 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/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 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 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 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 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 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));
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index b2c255e..5662637 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/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 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 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 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 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 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));
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index f15ccd1..78dce48 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/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));
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;
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));
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;
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;
-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;
CREATE TABLE ambari.roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/Ambari-DDL-Postgres-REMOTE-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-REMOTE-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-REMOTE-CREATE.sql
index 0586ba3..3cbfe3b 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-REMOTE-CREATE.sql
+++ b/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.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.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.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.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.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));
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/properties.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/properties.json b/ambari-server/src/main/resources/properties.json
index 1e555c2..4a824d3 100644
--- a/ambari-server/src/main/resources/properties.json
+++ b/ambari-server/src/main/resources/properties.json
@@ -11,6 +11,7 @@
"ServiceInfo/service_name",
"ServiceInfo/cluster_name",
"ServiceInfo/state",
+ "ServiceInfo/passive_state",
"Services/description",
"Services/display_name",
"Services/attributes",
@@ -37,6 +38,7 @@
"Hosts/host_health_report",
"Hosts/public_host_name",
"Hosts/host_state",
+ "Hosts/passive_state",
"Hosts/desired_configs",
"_"
],
@@ -65,6 +67,7 @@
"HostRoles/nagios_alerts",
"HostRoles/stale_configs",
"HostRoles/desired_admin_state",
+ "HostRoles/passive_state",
"_"
],
"Configuration":[
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql
index 702a8d4..509d1cf 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-MySQL-UPGRADE.sql
+++ b/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);
-
--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 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_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_tg on QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
\ No newline at end of file
+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);
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
index 4edd1a2..4b055cb 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
+++ b/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
ALTER TABLE hostcomponentdesiredstate ADD (admin_state VARCHAR2 (32) DEFAULT NULL);
+ALTER TABLE hostcomponentdesiredstate ADD (passive_state VARCHAR2 (32) NOT NULL DEFAULT 'ACTIVE');
-- DML
--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_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;
http://git-wip-us.apache.org/repos/asf/ambari/blob/95f0159a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
index ae2e02f..3034bf9 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
+++ b/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
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
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_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);
+
+ALTER TABLE ambari.hoststate ADD COLUMN passive_state VARCHAR(512);
+ALTER TABLE ambari.servicedesiredstate ADD COLUMN passive_state VARCHAR(32) NOT NULL DEFAULT 'ACTIVE';