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 2013/11/01 22:14:11 UTC
[2/2] git commit: AMBARI-3669. Remove HBase port scanner and
ha_status (ncole)
AMBARI-3669. Remove HBase port scanner and ha_status (ncole)
Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/c6c4e348
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/c6c4e348
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/c6c4e348
Branch: refs/heads/trunk
Commit: c6c4e3483d943f1865a5110d91cad9e27f361ba0
Parents: 6b9ca4b
Author: Nate Cole <nc...@hortonworks.com>
Authored: Fri Nov 1 16:33:26 2013 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Fri Nov 1 17:13:46 2013 -0400
----------------------------------------------------------------------
.../ambari/server/agent/HeartBeatHandler.java | 47 +-
.../ambari/server/agent/HeartbeatMonitor.java | 13 +-
.../server/controller/ControllerModule.java | 51 +-
.../ServiceComponentHostResponse.java | 22 -
.../AbstractControllerResourceProvider.java | 1 -
.../internal/HostComponentResourceProvider.java | 8 -
.../controller/jmx/JMXPropertyProvider.java | 35 +-
.../server/state/ServiceComponentHost.java | 2 -
.../svccomphost/HBaseMasterPortScanner.java | 337 --------
.../svccomphost/ServiceComponentHostImpl.java | 13 -
.../src/main/resources/properties.json | 1 -
.../HostComponentResourceProviderTest.java | 55 --
.../controller/jmx/JMXPropertyProviderTest.java | 39 +-
.../controller/jmx/TestStreamProvider.java | 1 +
.../svccomphost/HBaseMasterPortScannerTest.java | 244 ------
.../test/resources/hbase_hbasemaster_jmx_2.json | 840 +++++++++++++++++++
16 files changed, 960 insertions(+), 749 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index 5b328b5..69a86be 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -17,16 +17,31 @@
*/
package org.apache.ambari.server.agent;
-import com.google.gson.Gson;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.Singleton;
-import org.apache.ambari.server.*;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.HostNotFoundException;
+import org.apache.ambari.server.RoleCommand;
+import org.apache.ambari.server.ServiceComponentHostNotFoundException;
+import org.apache.ambari.server.ServiceComponentNotFoundException;
+import org.apache.ambari.server.ServiceNotFoundException;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.metadata.ActionMetadata;
-import org.apache.ambari.server.state.*;
+import org.apache.ambari.server.state.AgentVersion;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.host.HostHealthyHeartbeatEvent;
import org.apache.ambari.server.state.host.HostRegistrationRequestEvent;
@@ -42,12 +57,10 @@ import org.apache.ambari.server.utils.VersionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.ambari.server.state.svccomphost.HBaseMasterPortScanner;
+import com.google.gson.Gson;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Singleton;
/**
@@ -68,8 +81,6 @@ public class HeartBeatHandler {
AmbariMetaInfo ambariMetaInfo;
@Inject
ActionMetadata actionMetadata;
- @Inject
- HBaseMasterPortScanner scanner;
private HeartbeatMonitor heartbeatMonitor;
@Inject
private Gson gson;
@@ -83,7 +94,6 @@ public class HeartBeatHandler {
this.actionQueue = aq;
this.actionManager = am;
this.heartbeatMonitor = new HeartbeatMonitor(fsm, aq, am, 60000);
- this.heartbeatMonitor.setScanner(scanner);
injector.injectMembers(this);
}
@@ -157,7 +167,6 @@ public class HeartBeatHandler {
hostObject.handleEvent(new HostUnhealthyHeartbeatEvent(hostname, now,
null));
}
- if (hostState != hostObject.getState()) scanner.updateHBaseMaster(hostObject);
} catch (InvalidStateTransitionException ex) {
LOG.warn("Asking agent to reregister due to " + ex.getMessage(), ex);
hostObject.setState(HostState.INIT);
@@ -231,9 +240,6 @@ public class HeartBeatHandler {
scHost.handleEvent(new ServiceComponentHostOpInProgressEvent(schName,
hostname, now));
}
- if (state != scHost.getState() && schName.equals(Role.HBASE_MASTER.toString())) {
- scanner.updateHBaseMaster(cl);
- }
} catch (ServiceComponentNotFoundException scnex) {
LOG.warn("Service component not found ", scnex);
} catch (InvalidStateTransitionException ex) {
@@ -275,9 +281,6 @@ public class HeartBeatHandler {
+ " of cluster " + status.getClusterName()
+ " has changed from " + prevState + " to " + liveState
+ " at host " + hostname);
- if (scHost.getServiceComponentName().equals(Role.HBASE_MASTER.toString())) {
- scanner.updateHBaseMaster(scHost);
- }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
index 6161c63..bb348c6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
@@ -18,10 +18,10 @@
package org.apache.ambari.server.agent;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import java.util.HashMap;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.ActionManager;
@@ -37,7 +37,6 @@ import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.host.HostHeartbeatLostEvent;
-import org.apache.ambari.server.state.svccomphost.HBaseMasterPortScanner;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -52,11 +51,6 @@ public class HeartbeatMonitor implements Runnable {
private final int threadWakeupInterval; //1 minute
private volatile boolean shouldRun = true;
private Thread monitorThread = null;
- private HBaseMasterPortScanner scanner;
-
- public void setScanner(HBaseMasterPortScanner scanner) {
- this.scanner = scanner;
- }
public HeartbeatMonitor(Clusters fsm, ActionQueue aq, ActionManager am,
int threadWakeupInterval) {
@@ -141,11 +135,6 @@ public class HeartbeatMonitor implements Runnable {
}
}
- // hbase
- if (hostState != hostObj.getState() && scanner != null) {
- scanner.updateHBaseMaster(hostObj);
- }
-
//Purge action queue
actionQueue.dequeueAll(host);
//notify action manager
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index f35e277..1b2ebda 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -18,36 +18,52 @@
package org.apache.ambari.server.controller;
-import org.apache.ambari.server.state.configgroup.ConfigGroup;
-import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
-import org.apache.ambari.server.state.configgroup.ConfigGroupImpl;
-import org.apache.ambari.server.state.svccomphost.HBaseMasterPortScanner;
-import com.google.gson.Gson;
-import com.google.inject.Scopes;
-import com.google.inject.assistedinject.FactoryModuleBuilder;
-import com.google.inject.persist.jpa.JpaPersistModule;
-import org.apache.ambari.server.actionmanager.*;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.ambari.server.actionmanager.ActionDBAccessor;
+import org.apache.ambari.server.actionmanager.ActionDBAccessorImpl;
+import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
+import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
+import org.apache.ambari.server.actionmanager.HostRoleCommandFactoryImpl;
+import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.PersistenceType;
import org.apache.ambari.server.serveraction.ServerActionManager;
import org.apache.ambari.server.serveraction.ServerActionManagerImpl;
-import org.apache.ambari.server.state.*;
+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.ConfigImpl;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentFactory;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceComponentHostFactory;
+import org.apache.ambari.server.state.ServiceComponentImpl;
+import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.ServiceImpl;
import org.apache.ambari.server.state.cluster.ClusterFactory;
import org.apache.ambari.server.state.cluster.ClusterImpl;
import org.apache.ambari.server.state.cluster.ClustersImpl;
+import org.apache.ambari.server.state.configgroup.ConfigGroup;
+import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
+import org.apache.ambari.server.state.configgroup.ConfigGroupImpl;
import org.apache.ambari.server.state.host.HostFactory;
import org.apache.ambari.server.state.host.HostImpl;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Singleton;
-import com.google.inject.name.Names;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
+import com.google.gson.Gson;
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.name.Names;
+import com.google.inject.persist.jpa.JpaPersistModule;
/**
* Used for injection purposes.
@@ -91,7 +107,6 @@ public class ControllerModule extends AbstractModule {
bind(AmbariManagementController.class)
.to(AmbariManagementControllerImpl.class);
bind(AbstractRootServiceResponseFactory.class).to(RootServiceResponseFactory.class);
- bind(HBaseMasterPortScanner.class).in(Singleton.class);
bind(ServerActionManager.class).to(ServerActionManagerImpl.class);
requestStaticInjection(ExecutionCommandWrapper.class);
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/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 eba7da8..e773871 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
@@ -48,8 +48,6 @@ public class ServiceComponentHostResponse {
private String desiredState;
- private String ha_status = "NA";
-
private boolean staleConfig = false;
@@ -198,26 +196,6 @@ public class ServiceComponentHostResponse {
this.clusterName = clusterName;
}
- /**
- *
- * @return ha_status status of HBaseMaster
- */
- public String getHa_status() {
- return ha_status;
- }
-
-
- /**
- *
- * @param ha_status the state of HBaseMaster
- */
- public void setHa_status(String ha_status) {
- this.ha_status = ha_status;
- }
-
-
-
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
index 464040e..dc2575e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.controller.internal;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.predicate.ArrayPredicate;
-import org.apache.ambari.server.controller.predicate.ComparisonPredicate;
import org.apache.ambari.server.controller.predicate.EqualsPredicate;
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Resource;
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/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 006e59b..eb419f3 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
@@ -58,8 +58,6 @@ class HostComponentResourceProvider extends AbstractControllerResourceProvider {
= PropertyHelper.getPropertyId("HostRoles", "configs");
protected static final String HOST_COMPONENT_DESIRED_CONFIGS_PROPERTY_ID
= PropertyHelper.getPropertyId("HostRoles", "desired_configs");
- protected static final String HOST_COMPONENT_HIGH_AVAILABILITY_PROPERTY_ID
- = PropertyHelper.getPropertyId("HostRoles", "ha_status");
protected static final String HOST_COMPONENT_STACK_ID_PROPERTY_ID
= PropertyHelper.getPropertyId("HostRoles", "stack_id");
protected static final String HOST_COMPONENT_DESIRED_STACK_ID_PROPERTY_ID
@@ -166,11 +164,6 @@ class HostComponentResourceProvider extends AbstractControllerResourceProvider {
for (ServiceComponentHostResponse response : responses) {
Resource resource = new ResourceImpl(Resource.Type.HostComponent);
- if((response.getComponentName()).equals(Role.HBASE_MASTER.toString())) {
- requestedIds.add(HOST_COMPONENT_HIGH_AVAILABILITY_PROPERTY_ID);
- }else{
- requestedIds.remove(HOST_COMPONENT_HIGH_AVAILABILITY_PROPERTY_ID);
- }
setResourceProperty(resource, HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID, response.getClusterName(), requestedIds);
setResourceProperty(resource, HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds);
setResourceProperty(resource, HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds);
@@ -181,7 +174,6 @@ class HostComponentResourceProvider extends AbstractControllerResourceProvider {
response.getStackVersion(), requestedIds);
setResourceProperty(resource, HOST_COMPONENT_DESIRED_STACK_ID_PROPERTY_ID,
response.getDesiredStackVersion(), requestedIds);
- setResourceProperty(resource, HOST_COMPONENT_HIGH_AVAILABILITY_PROPERTY_ID, response.getHa_status(), requestedIds);
setResourceProperty(resource, HOST_COMPONENT_CONFIGS_PROPERTY_ID,
response.getConfigs(), requestedIds);
setResourceProperty(resource, HOST_COMPONENT_DESIRED_CONFIGS_PROPERTY_ID,
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
index baa39bd..1f9bbff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
@@ -344,24 +344,33 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
String property = propertyInfo.getPropertyId();
String category = "";
+
List<String> keyList = new LinkedList<String>();
- int keyStartIndex = property.indexOf('[', 0);
- int firstKeyIndex = keyStartIndex > -1 ? keyStartIndex : property.length();
- while (keyStartIndex > -1) {
+
+ int keyStartIndex = property.indexOf('[');
+ if (-1 != keyStartIndex) {
int keyEndIndex = property.indexOf(']', keyStartIndex);
- if (keyEndIndex > -1 & keyEndIndex > keyStartIndex) {
- keyList.add(property.substring(keyStartIndex + 1, keyEndIndex));
- keyStartIndex = property.indexOf('[', keyEndIndex);
- }
- else {
- keyStartIndex = -1;
+ if (-1 != keyEndIndex && keyEndIndex > keyStartIndex) {
+ keyList.add(property.substring(keyStartIndex+1, keyEndIndex));
}
}
+
+ if (!containsArguments(propertyId)) {
+ int dotIndex = property.indexOf('.', property.indexOf('='));
+ if (-1 != dotIndex) {
+ category = property.substring(0, dotIndex);
+ property = (-1 == keyStartIndex) ?
+ property.substring(dotIndex+1) :
+ property.substring(dotIndex+1, keyStartIndex);
+ }
+ } else {
+ int firstKeyIndex = keyStartIndex > -1 ? keyStartIndex : property.length();
+ int dotIndex = property.lastIndexOf('.', firstKeyIndex);
- int dotIndex = property.lastIndexOf('.', firstKeyIndex - 1);
- if (dotIndex != -1){
- category = property.substring(0, dotIndex);
- property = property.substring(dotIndex + 1, firstKeyIndex);
+ if (dotIndex != -1) {
+ category = property.substring(0, dotIndex);
+ property = property.substring(dotIndex + 1, firstKeyIndex);
+ }
}
if (containsArguments(propertyId)) {
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/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 eb4acf9..627d24d 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
@@ -86,8 +86,6 @@ public interface ServiceComponentHost {
public void setState(State state);
- public void setHAState(String status);
-
public Map<String, Config> getConfigs() throws AmbariException;
public StackId getStackVersion();
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java
deleted file mode 100644
index cdcd800..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java
+++ /dev/null
@@ -1,337 +0,0 @@
-/**
- * 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.svccomphost;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import java.net.ConnectException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.Role;
-import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.State;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This class encapsulates the HBaseMaster scanner thread. HBaseMaster scanner
- * start scan if Host, ServiceComponentHost or Cluster change own state.
- */
-@Singleton
-public class HBaseMasterPortScanner implements Runnable {
-
- private static Log LOG = LogFactory.getLog(HBaseMasterPortScanner.class);
- private Thread schedulerThread = null;
- private final Object wakeupSyncObject = new Object();
- private int defaultScanTimeoutMsc = 300;
- private int scanTimeoutMsc = defaultScanTimeoutMsc;
- private int testScanTimeoutMsc;
- private int rescanTimeoutMsc = 60000;
- private final int port = 60010;
- private int maxAttempts = 3;
- private int attempts = 0;
- protected int countAttempts = 0;
- private Map<ServiceComponentHost,Boolean> componentHostMap;
- private Cluster currentCluster;
- private Timer scheduleTimer;
- private RescanSchedulerTask rescanSchedulerTask;
- @Inject
- protected Clusters clusters;
-
- /**
- *
- * @param defaultScanTimeoutMsc set default timeout for port scan
- */
- public void setDefaultScanTimeoutMsc(int defaultScanTimeoutMsc) {
- this.defaultScanTimeoutMsc = defaultScanTimeoutMsc;
- this.scanTimeoutMsc = this.defaultScanTimeoutMsc;
- }
-
-
- /**
- *
- * @param maxAttempts set maximum attempts to scan
- */
- public void setMaxAttempts(int maxAttempts) {
- this.maxAttempts = maxAttempts;
- }
-
- /**
- *
- * @param rescanTimeoutMsc timeout for latter rescan
- */
- public void setRescanTimeoutMsc(int rescanTimeoutMsc) {
- this.rescanTimeoutMsc = rescanTimeoutMsc;
- }
-
- /**
- *
- * @return tested value (need unitests)
- */
- public int getTestScanTimeoutMsc() {
- return testScanTimeoutMsc;
- }
-
-
- /**
- *
- * @return task for latter scan
- */
- public RescanSchedulerTask getRescanSchedulerTask() {
- return rescanSchedulerTask;
- }
-
-
- /**
- * true if scanner should run ASAP. We need this flag to avoid sleep in
- * situations, when we receive updateHBaseMaster request during running a
- * scanner iteration.
- */
- private boolean activeAwakeRequest = false;
-
- public HBaseMasterPortScanner(Timer timer) {
- scheduleTimer = timer;
- }
-
- public HBaseMasterPortScanner() {
- scheduleTimer = new Timer();
- this.start();
- }
-
- private void start() {
- schedulerThread = new Thread(this, this.getClass().getSimpleName());
- schedulerThread.start();
- if (LOG.isDebugEnabled()) {
- LOG.debug("HBaseMasterPortScanner started");
- }
- }
-
-
- /**
- * Should be called from another thread when we want HBase Master scanner to
- * make a run ASAP (for example, to process desired configs of SCHs). The
- * method is guaranteed to return quickly.
- */
- public void updateHBaseMaster(Cluster cluster) {
- synchronized (wakeupSyncObject) {
- collectServiceComponentHostsForCluster(cluster);
- if(componentHostMap!=null && !componentHostMap.isEmpty()){
- LOG.debug("HBaseMasterPortScanner start scanning for cluster " + cluster.getClusterName());
- activeAwakeRequest = true;
- wakeupSyncObject.notify();
- } else LOG.debug("No for scan (with HBaseMaster component)");
- }
- }
-
- public void updateHBaseMaster(Host host) {
- synchronized (wakeupSyncObject) {
- Set<Cluster> clustersSet;
- try {
- clustersSet = clusters.getClustersForHost(host.getHostName());
- } catch (AmbariException ex) {
- return;
- }
- Iterator<Cluster> iter = clustersSet.iterator();
- while (iter.hasNext()) {
- collectServiceComponentHostsForCluster(iter.next());
- }
- if(componentHostMap!=null && !componentHostMap.isEmpty()){
- LOG.debug("HBaseMasterPortScanner start scanning for Host " + host.getHostName());
- activeAwakeRequest = true;
- wakeupSyncObject.notify();
- } else LOG.debug("No for scan (with HBaseMaster component)");
- }
- }
-
- public void updateHBaseMaster(ServiceComponentHost host) {
- synchronized (wakeupSyncObject) {
- try {
- collectServiceComponentHostsForCluster(clusters.getCluster(host.getClusterName()));
- } catch (AmbariException ex) {
- LOG.warn(ex);
- return;
- }
- if(componentHostMap!=null && !componentHostMap.isEmpty()){
- LOG.debug("HBaseMasterPortScanner start scanning for ServiceComponentHost " + host.getServiceComponentName());
- activeAwakeRequest = true;
- wakeupSyncObject.notify();
- } else LOG.debug("No for scan (with HBaseMaster component)");
- }
- }
-
- private void collectServiceComponentHostsForCluster(Cluster cluster) {
- currentCluster = cluster;
- componentHostMap = new HashMap<ServiceComponentHost, Boolean>();
- Map<String, Host> hosts = null;
- try {
- hosts = clusters.getHostsForCluster(currentCluster.getClusterName());
- } catch (AmbariException ex) {
- LOG.warn(ex);
- return;
- }
- for (Map.Entry<String, Host> entry : hosts.entrySet()) {
- if (entry.getValue() != null) {
- List<ServiceComponentHost> componentHosts = currentCluster.getServiceComponentHosts(entry.getValue().getHostName());
- for (ServiceComponentHost componentHost : componentHosts) {
- if (componentHost != null && componentHost.getServiceComponentName() != null && componentHost.getServiceComponentName().equals(Role.HBASE_MASTER.toString())) {
- componentHostMap.put(componentHost, false);
- }
- }
- }
- }
-
- }
-
- @Override
- public void run() {
- while (true) {
- execute();
- if (activeAwakeRequest) {
- activeAwakeRequest = false;
- continue;
- }
- try {
- synchronized (wakeupSyncObject) {
- wakeupSyncObject.wait();
- }
- } catch (InterruptedException ex) {
- activeAwakeRequest = true;
- }
- }
- }
-
- protected void execute() {
- if (rescanSchedulerTask != null) {
- rescanSchedulerTask.cancel();
- scheduleTimer.purge();
- }
- activeAwakeRequest = false;
- if (componentHostMap != null) {
- for (Map.Entry<ServiceComponentHost, Boolean> entry : componentHostMap.entrySet()) {
- entry.setValue(scan(entry.getKey().getHostName()));
- if (activeAwakeRequest) {
- scanTimeoutMsc = defaultScanTimeoutMsc;
- attempts = 0;
- break;
- }
- }
- attempts++;
- countAttempts = attempts;
- LOG.info("Attempt to scan of HBASE_MASTER port : " + attempts);
- if (validateScanResults(componentHostMap)) {
- //If results valid set it to ServiceComponentHost
- setScanResults(componentHostMap);
- scanTimeoutMsc = defaultScanTimeoutMsc;
- attempts = 0;
- } else {
- if (attempts <= maxAttempts) {
- //Increase timeout
- scanTimeoutMsc += defaultScanTimeoutMsc;
- testScanTimeoutMsc = scanTimeoutMsc;
- LOG.info("Increase timeout for scan HBASE_MASTER port to : " + scanTimeoutMsc);
- activeAwakeRequest = true;
- } else {
- LOG.info("No valid data about HBASE_MASTER, ports will rescanned after " + rescanTimeoutMsc / 1000 + " seconds");
- scanTimeoutMsc = defaultScanTimeoutMsc;
- attempts = 0;
- //Create task for latter scan
- rescanSchedulerTask = new RescanSchedulerTask(currentCluster);
- scheduleTimer.schedule(rescanSchedulerTask, rescanTimeoutMsc);
- }
- }
-
- }
-
- }
-
- private void setScanResults(Map<ServiceComponentHost, Boolean> scanResuls){
- for (Map.Entry<ServiceComponentHost, Boolean> entry : scanResuls.entrySet()) {
- entry.getKey().setHAState((entry.getValue()) ? "active" : "passive");
- }
- LOG.info("Set result of HBASE_MASTER scan");
- }
-
- private boolean validateScanResults(Map<ServiceComponentHost, Boolean> scanResuls) {
- boolean res = false;
- int activeMasters = 0;
- int startedComponents = 0;
- for (Map.Entry<ServiceComponentHost, Boolean> entry : scanResuls.entrySet()) {
- activeMasters += (entry.getValue() && entry.getKey().getState() == State.STARTED) ? 1 : 0;
- startedComponents += (entry.getKey().getState() == State.STARTED) ? 1 : 0;
- }
- if (startedComponents > 0) {
- if (activeMasters == 0 || activeMasters > 1) {
- res = false;
- } else {
- res = true;
- }
- } else {
- if (activeMasters > 0) {
- res = false;
- } else {
- res = true;
- }
- }
- LOG.info("Results of HBASE_MASTER scan are " + ((res) ? "valid" : "invalid"));
- return res;
- }
-
- protected boolean scan(String hostname) {
- try {
- Socket socket = new Socket();
- socket.connect(new InetSocketAddress(hostname, port), scanTimeoutMsc);
- socket.close();
- LOG.info(hostname + ":" + port + " HBASE_MASTER active");
- return true;
- } catch (ConnectException e) {
- LOG.info(hostname + ":" + port + " HBASE_MASTER passive");
- return false;
- } catch (Exception ex) {
- LOG.info(hostname + ":" + port + " HBASE_MASTER passive");
- LOG.error(ex);
- return false;
- }
- }
-
- private class RescanSchedulerTask extends TimerTask {
-
- private Cluster cl;
-
- public RescanSchedulerTask(Cluster cl) {
- this.cl = cl;
- }
-
- @Override
- public void run() {
- LOG.info("Start scheduled rescan of HBASE_MASTER ports for cluster "+ cl.getClusterName());
- updateHBaseMaster(cl);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/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 2c79f96..71ae98f 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
@@ -103,7 +103,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
private long lastOpStartTime;
private long lastOpEndTime;
private long lastOpLastUpdateTime;
- private String ha_status = "passive";
private Map<String, DesiredConfig> actualConfigs = new HashMap<String, DesiredConfig>();
private static final StateMachineFactory
@@ -487,17 +486,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
private final StateMachine<State,
ServiceComponentHostEventType, ServiceComponentHostEvent> stateMachine;
- @Override
- public void setHAState(String status) {
- try {
- writeLock.lock();
- ha_status = status;
- }
- finally {
- writeLock.unlock();
- }
- }
-
static class ServiceComponentHostOpCompletedTransition
implements SingleArcTransition<ServiceComponentHostImpl,
ServiceComponentHostEvent> {
@@ -1315,7 +1303,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
getDesiredState().toString(),
getDesiredStackVersion().getStackId());
- r.setHa_status(ha_status);
r.setActualConfigs(actualConfigs);
try {
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/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 fd02437..fa04735 100644
--- a/ambari-server/src/main/resources/properties.json
+++ b/ambari-server/src/main/resources/properties.json
@@ -67,7 +67,6 @@
"HostRoles/actual_configs",
"params/run_smoke_test",
"HostRoles/nagios_alerts",
- "HostRoles/ha_status",
"HostRoles/stale_configs",
"_"
],
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
index 95c412c..b84f96e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
@@ -41,7 +41,6 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
-import org.apache.ambari.server.Role;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
@@ -176,60 +175,6 @@ public class HostComponentResourceProviderTest {
verify(managementController);
}
-
- @Test
- public void testGetResources_return_ha_status_property() throws Exception {
- Resource.Type type = Resource.Type.HostComponent;
- AmbariManagementController managementController = createMock(AmbariManagementController.class);
- Set<ServiceComponentHostResponse> allResponse = new HashSet<ServiceComponentHostResponse>();
- for (Role role : Role.values()) {
- allResponse.add(new ServiceComponentHostResponse(
- "Cluster100", "Service100", role.toString(), "Host100", null, null, "", "", "", ""));
- }
-
-
-
- // set expectations
- expect(managementController.getHostComponents(
- AbstractResourceProviderTest.Matcher.getHostComponentRequestSet(
- "Cluster100", null, null, null, null, null))).andReturn(allResponse).once();
-
- // replay
- replay(managementController);
-
- ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
- type,
- PropertyHelper.getPropertyIds(type),
- PropertyHelper.getKeyPropertyIds(type),
- managementController);
-
- Set<String> propertyIds = new HashSet<String>();
-
- propertyIds.add(HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID);
- propertyIds.add(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
-
- Predicate predicate = new PredicateBuilder().property(
- HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").toPredicate();
- Request request = PropertyHelper.getReadRequest(propertyIds);
- Set<Resource> resources = provider.getResources(request, predicate);
-
- for (Resource resource : resources) {
- Object ha_status = resource.getPropertyValue(
- HostComponentResourceProvider.HOST_COMPONENT_HIGH_AVAILABILITY_PROPERTY_ID);
- //ha_status must have only HBASE_MASTER component
- if(ha_status != null)
- {
- Assert.assertEquals(Role.HBASE_MASTER.toString(), resource.getPropertyValue(
- HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).toString());
- }else{
- Assert.assertNotSame(Role.HBASE_MASTER.toString(), resource.getPropertyValue(
- HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).toString());
- }
- }
-
- verify(managementController);
- }
-
@Test
public void testUpdateResources() throws Exception {
Resource.Type type = Resource.Type.HostComponent;
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
index 38684ab..bd417df 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
@@ -808,6 +808,42 @@ public class JMXPropertyProviderTest {
Assert.assertEquals(preSize, resource.getPropertiesMap().size());
}
+
+ @Test
+ public void testPopulateResources_HBaseMaster2() throws Exception {
+ TestStreamProvider streamProvider = new TestStreamProvider();
+ TestJMXHostProvider hostProvider = new TestJMXHostProvider(false);
+
+ JMXPropertyProvider propertyProvider = new JMXPropertyProvider(
+ PropertyHelper.getJMXPropertyIds(Resource.Type.HostComponent, PropertyHelper.MetricsVersion.HDP2),
+ streamProvider,
+ hostProvider,
+ PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+ PropertyHelper.getPropertyId("HostRoles", "host_name"),
+ PropertyHelper.getPropertyId("HostRoles", "component_name"),
+ PropertyHelper.getPropertyId("HostRoles", "state"),
+ Collections.singleton("STARTED"));
+
+ Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+
+ resource.setProperty("HostRoles/cluster_name", "HBM2");
+ resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
+ resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "HBASE_MASTER");
+ resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+
+
+ // request with an empty set should get all supported properties
+ Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
+
+ Set<Resource> res = propertyProvider.populateResources(Collections.singleton(resource), request, null);
+ Assert.assertEquals(1, res.size());
+
+ Map<String, Map<String, Object>> map = res.iterator().next().getPropertiesMap();
+
+ Assert.assertTrue(map.containsKey("metrics/hbase/master"));
+ // uses 'tag.isActiveMaster' (name with a dot)
+ Assert.assertTrue(map.get("metrics/hbase/master").containsKey("IsActiveMaster"));
+ }
private static class TestJMXHostProvider implements JMXHostProvider {
private final boolean unknownPort;
@@ -828,6 +864,7 @@ public class JMXPropertyProviderTest {
if (unknownPort) {
return null;
}
+
if (componentName.equals("NAMENODE"))
return "50070";
else if (componentName.equals("DATANODE"))
@@ -837,7 +874,7 @@ public class JMXPropertyProviderTest {
else if (componentName.equals("TASKTRACKER"))
return "50060";
else if (componentName.equals("HBASE_MASTER"))
- return "60010";
+ return null == clusterName ? "60010" : "60011";
else if (componentName.equals("JOURNALNODE"))
return "8480";
else
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java
index 4f0a6d3..8d7832e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/TestStreamProvider.java
@@ -35,6 +35,7 @@ public class TestStreamProvider implements StreamProvider {
FILE_MAPPING.put("50030", "mapreduce_jobtracker_jmx.json");
FILE_MAPPING.put("50060", "mapreduce_tasktracker_jmx.json");
FILE_MAPPING.put("60010", "hbase_hbasemaster_jmx.json");
+ FILE_MAPPING.put("60011", "hbase_hbasemaster_jmx_2.json");
FILE_MAPPING.put("8088", "resourcemanager_jmx.json");
FILE_MAPPING.put("8480", "hdfs_journalnode_jmx.json");
}
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c6c4e348/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java
deleted file mode 100644
index a88b037..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/**
- * 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.svccomphost;
-
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.Timer;
-import org.apache.ambari.server.AmbariException;
-import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DATANODE;
-import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyCluster;
-import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyOsType;
-import static org.apache.ambari.server.agent.DummyHeartbeatConstants.HDFS;
-import static org.apache.ambari.server.agent.DummyHeartbeatConstants.HBASE_MASTER;
-import static org.apache.ambari.server.agent.DummyHeartbeatConstants.NAMENODE;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.Service;
-import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.ServiceFactory;
-import org.apache.ambari.server.state.StackId;
-import org.apache.ambari.server.state.State;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author root
- */
-public class HBaseMasterPortScannerTest {
-
- private static final Logger log = LoggerFactory.getLogger(HBaseMasterPortScannerTest.class);
- private static List<String> hostnames;
- private static Injector injector;
- private static HBaseMasterPortScannerMock scaner;
- private static ServiceFactory serviceFactory;
- private static AmbariMetaInfo metaInfo;
- private static Clusters clusters;
- private static Cluster cluster;
- private static Host host;
- private static ServiceComponentHost serviceComponentHost;
- private static int scanTimeOut = 100;
- private static int reScanTimeOut = 1000;
- private static int maxAttempts = 2;
- private static Timer timerMock = mock(Timer.class);
-
- public HBaseMasterPortScannerTest() {
- }
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- injector = Guice.createInjector(new InMemoryDefaultTestModule());
- injector.getInstance(GuiceJpaInitializer.class);
- hostnames = new ArrayList<String>();
- hostnames.add("127.0.0.1");
- hostnames.add("host1");
- hostnames.add("host2");
- hostnames.add("host3");
- clusters = injector.getInstance(Clusters.class);
- scaner = new HBaseMasterPortScannerMock(clusters);
- metaInfo = injector.getInstance(AmbariMetaInfo.class);
- serviceFactory = injector.getInstance(ServiceFactory.class);
- metaInfo.init();
- clusters.addCluster(DummyCluster);
- cluster = clusters.getCluster(DummyCluster);
- cluster.setDesiredStackVersion(new StackId("HDP-0.2"));
- Set<String> hostNamesSet = new HashSet<String>();
- for (String hostname : hostnames) {
- clusters.addHost(hostname);
- clusters.getHost(hostname).persist();
- Host hostObject = clusters.getHost(hostname);
- hostObject.setIPv4("ipv4");
- hostObject.setIPv6("ipv6");
- hostObject.setOsType(DummyOsType);
- hostNamesSet.add(hostname);
- if (hostname.equals("127.0.0.1")) {
- host = hostObject;
- }
- }
- clusters.mapHostsToCluster(hostNamesSet, DummyCluster);
- Service service = cluster.addService(HDFS);
- service.persist();
- service.addServiceComponent(NAMENODE).persist();
- service.getServiceComponent(NAMENODE).addServiceComponentHost("127.0.0.1").persist();
- service.addServiceComponent(DATANODE).persist();
- service.getServiceComponent(DATANODE).addServiceComponentHost("127.0.0.1").persist();
- service = serviceFactory.createNew(cluster, "HBASE");
- cluster.addService(service);
- service.persist();
- service = cluster.getService("HBASE");
- service.addServiceComponent(HBASE_MASTER).persist();
- service.persist();
- for (String hostname : hostnames) {
- service.getServiceComponent(HBASE_MASTER).addServiceComponentHost(hostname).persist();
- if (hostname.equals("127.0.0.1")) {
- serviceComponentHost = service.getServiceComponent(HBASE_MASTER).getServiceComponentHost(hostname);
- serviceComponentHost.setState(State.STARTED);
- }
- }
- when(timerMock.purge()).thenReturn(0);
- }
-
-
- @Before
- public void setUp() throws AmbariException, Exception {
- serviceComponentHost.setHAState("passive");
- }
-
- /**
- * Test of updateHBaseMaster method, of class HBaseMasterPortScaner.
- */
- @Test
- public void testUpdateHBaseMaster_Cluster() throws InterruptedException {
- scaner.setDefaultScanTimeoutMsc(scanTimeOut);
- scaner.setMaxAttempts(maxAttempts);
- scaner.setRescanTimeoutMsc(reScanTimeOut);
- log.debug("updateHBaseMaster - pass Cluster");
- scaner.updateHBaseMaster(cluster);
- scaner.execute();
- assertEquals("active", serviceComponentHost.convertToResponse().getHa_status());
- }
-
- /**
- * Test of updateHBaseMaster method, of class HBaseMasterPortScaner.
- */
- @Test
- public void testUpdateHBaseMaster_Host() throws InterruptedException {
- scaner.setDefaultScanTimeoutMsc(scanTimeOut);
- scaner.setMaxAttempts(maxAttempts);
- scaner.setRescanTimeoutMsc(reScanTimeOut);
- log.debug("updateHBaseMaster - pass Host");
- scaner.updateHBaseMaster(host);
- scaner.execute();
- assertEquals("active", serviceComponentHost.convertToResponse().getHa_status());
- }
-
- /**
- * Test of updateHBaseMaster method, of class HBaseMasterPortScaner.
- */
- @Test
- public void testUpdateHBaseMaster_ServiceComponentHost() throws InterruptedException {
- scaner.setDefaultScanTimeoutMsc(scanTimeOut);
- scaner.setMaxAttempts(maxAttempts);
- scaner.setRescanTimeoutMsc(reScanTimeOut);
- log.debug("updateHBaseMaster - pass ServiceComponentHost");
- scaner.updateHBaseMaster(serviceComponentHost);
- scaner.execute();
- assertEquals("active", serviceComponentHost.convertToResponse().getHa_status());
- }
-
-
- /**
- * Test case of if port is closed or not enough scan timeout.
- */
- @Test
- public void testOfBrokenMasterScenario() throws InterruptedException {
- scaner.setLiveHBaseHost("");
- scaner.setDefaultScanTimeoutMsc(scanTimeOut);
- scaner.setMaxAttempts(maxAttempts);
- scaner.setRescanTimeoutMsc(reScanTimeOut);
- log.debug("testOfBrokenMasterScenario start");
- scaner.updateHBaseMaster(cluster);
- scaner.execute(3);
- //Should not be active masters
- assertEquals("passive", serviceComponentHost.convertToResponse().getHa_status());
- serviceComponentHost.setHAState("passive");
- //Scanner should try to scan maxAttempts times
- assertEquals(maxAttempts, scaner.getCountAttempts()-1);
- //Timeout for scan should be scanTimeOut * scaner.getCountAttempts()
- assertEquals(scanTimeOut * scaner.getCountAttempts(), scaner.getTestScanTimeoutMsc());
- //Task for latter scan shoul be created
- assertNotNull(scaner.getRescanSchedulerTask());
- scaner.setLiveHBaseHost("127.0.0.1");
- scaner.execute(3);
- //Test active masters after latter rescan
- assertEquals("active", serviceComponentHost.convertToResponse().getHa_status());
- }
-
-
- public static class HBaseMasterPortScannerMock extends HBaseMasterPortScanner {
-
- private String liveHBaseHost = "127.0.0.1";
-
- public void setLiveHBaseHost(String liveHBaseHost) {
- this.liveHBaseHost = liveHBaseHost;
- }
-
- @Override
- protected boolean scan(String hostname) {
- return (hostname.equals(liveHBaseHost)) ? true : false;
- }
-
- public int getCountAttempts() {
- return countAttempts;
- }
-
-
- public HBaseMasterPortScannerMock(Clusters c) {
- super(timerMock);
- clusters = c;
- }
-
- @Override
- public void execute() {
- super.execute();
- }
-
- public void execute(int count) {
- for (int i = 0; i < count; i++) {
- execute();
- }
- }
-
- }
-
-}
\ No newline at end of file