Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
public class MockClientRequestInterceptor
extends DefaultClientRequestInterceptor {

MockRM mockRM = null;

public void init(String user) {
MockRM mockRM = new MockRM(super.getConf()) {
mockRM = new MockRM(super.getConf()) {
@Override
protected ClientRMService createClientRMService() {
return new ClientRMService(getRMContext(), getResourceScheduler(),
Expand Down Expand Up @@ -68,4 +70,11 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
super.setRMClient(mockRM.getClientRMService());
}

@Override
public void shutdown() {
if (mockRM != null) {
mockRM.stop();
}
super.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.apache.hadoop.yarn.server.resourcemanager.security.RMDelegationTokenSecretManager;
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Extends the FederationClientInterceptor and overrides methods to provide a
Expand All @@ -56,6 +58,9 @@
public class TestableFederationClientInterceptor
extends FederationClientInterceptor {

private static final Logger LOG =
LoggerFactory.getLogger(TestableFederationClientInterceptor.class);

private ConcurrentHashMap<SubClusterId, MockRM> mockRMs =
new ConcurrentHashMap<>();

Expand Down Expand Up @@ -161,4 +166,31 @@ private void initNodeAttributes(SubClusterId subClusterId, MockRM mockRM) {
throw new RuntimeException(e);
}
}

@Override
public void shutdown() {
if (mockRMs != null && !mockRMs.isEmpty()) {
for (Map.Entry<SubClusterId, MockRM> item : mockRMs.entrySet()) {
SubClusterId subClusterId = item.getKey();

// close mockNM
MockNM mockNM = mockNMs.getOrDefault(subClusterId, null);
try {
mockNM.unRegisterNode();
mockNM = null;
} catch (Exception e) {
LOG.error("mockNM unRegisterNode error.", e);
}

// close mockRM
MockRM mockRM = item.getValue();
if (mockRM != null) {
mockRM.stop();
}
}
}
mockNMs.clear();
mockRMs.clear();
super.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
public class MockRMAdminRequestInterceptor
extends DefaultRMAdminRequestInterceptor {

MockRM mockRM = null;
public void init(String user) {
MockRM mockRM = new MockRM(super.getConf()) {
mockRM = new MockRM(super.getConf()) {
@Override
protected AdminService createAdminService() {
return new AdminService(this) {
Expand All @@ -60,4 +61,12 @@ protected void stopServer() {
mockRM.start();
super.setRMAdmin(mockRM.getAdminService());
}

@Override
public void shutdown() {
if (mockRM != null) {
mockRM.stop();
}
super.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.minikdc.MiniKdc;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
Expand All @@ -34,6 +35,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -107,6 +109,8 @@ public static void beforeSecureRouterTestClass() throws Exception {
// Router Kerberos KeyTab configuration
conf.set(YarnConfiguration.ROUTER_PRINCIPAL, ROUTER_LOCALHOST_REALM);
conf.set(YarnConfiguration.ROUTER_KEYTAB, routerKeytab.getAbsolutePath());

DefaultMetricsSystem.setMiniClusterMode(true);
}

/**
Expand Down Expand Up @@ -214,6 +218,12 @@ protected synchronized void stopSecureRouter() throws Exception {
public static void afterSecureRouterTest() throws Exception {
LOG.info("teardown of kdc instance.");
teardownKDC();
if (mockRMs != null && mockRMs.isEmpty()) {
for (MockRM mockRM : mockRMs.values()) {
mockRM.close();
}
}
mockRMs.clear();
}

public static MiniKdc getKdc() {
Expand Down