YARN-5519. Add SubClusterId in AddApplicationHomeSubClusterResponse for Router Failover. (Ellen Hui via Subru)

This commit is contained in:
Subru Krishnan 2016-08-15 14:47:02 -07:00 committed by Carlo Curino
parent b747d59f41
commit e4f928cf9c
6 changed files with 120 additions and 63 deletions

View File

@ -51,15 +51,20 @@ public interface FederationApplicationHomeSubClusterStore {
/** /**
* Register the home {@code SubClusterId} of the newly submitted * Register the home {@code SubClusterId} of the newly submitted
* {@code ApplicationId}. Currently response is empty if the operation was * {@code ApplicationId}. Currently response is empty if the operation was
* successful, if not an exception reporting reason for a failure. * successful, if not an exception reporting reason for a failure. If a
* mapping for the application already existed, the {@code SubClusterId} in
* this response will return the existing mapping which might be different
* from that in the {@code AddApplicationHomeSubClusterRequest}.
* *
* @param request the request to register a new application with its home * @param request the request to register a new application with its home
* sub-cluster * sub-cluster
* @return empty on successful registration of the application in the * @return upon successful registration of the application in the StateStore,
* StateStore, if not an exception reporting reason for a failure * {@code AddApplicationHomeSubClusterRequest} containing the home
* sub-cluster of the application. Otherwise, an exception reporting
* reason for a failure
* @throws YarnException if the request is invalid/fails * @throws YarnException if the request is invalid/fails
*/ */
AddApplicationHomeSubClusterResponse addApplicationHomeSubClusterMap( AddApplicationHomeSubClusterResponse addApplicationHomeSubCluster(
AddApplicationHomeSubClusterRequest request) throws YarnException; AddApplicationHomeSubClusterRequest request) throws YarnException;
/** /**
@ -73,7 +78,7 @@ AddApplicationHomeSubClusterResponse addApplicationHomeSubClusterMap(
* not an exception reporting reason for a failure * not an exception reporting reason for a failure
* @throws YarnException if the request is invalid/fails * @throws YarnException if the request is invalid/fails
*/ */
UpdateApplicationHomeSubClusterResponse updateApplicationHomeSubClusterMap( UpdateApplicationHomeSubClusterResponse updateApplicationHomeSubCluster(
UpdateApplicationHomeSubClusterRequest request) throws YarnException; UpdateApplicationHomeSubClusterRequest request) throws YarnException;
/** /**
@ -85,7 +90,7 @@ UpdateApplicationHomeSubClusterResponse updateApplicationHomeSubClusterMap(
* subcluster * subcluster
* @throws YarnException if the request is invalid/fails * @throws YarnException if the request is invalid/fails
*/ */
GetApplicationHomeSubClusterResponse getApplicationHomeSubClusterMap( GetApplicationHomeSubClusterResponse getApplicationHomeSubCluster(
GetApplicationHomeSubClusterRequest request) throws YarnException; GetApplicationHomeSubClusterRequest request) throws YarnException;
/** /**
@ -96,7 +101,7 @@ GetApplicationHomeSubClusterResponse getApplicationHomeSubClusterMap(
* @return the mapping of all submitted application to it's home sub-cluster * @return the mapping of all submitted application to it's home sub-cluster
* @throws YarnException if the request is invalid/fails * @throws YarnException if the request is invalid/fails
*/ */
GetApplicationsHomeSubClusterResponse getApplicationsHomeSubClusterMap( GetApplicationsHomeSubClusterResponse getApplicationsHomeSubCluster(
GetApplicationsHomeSubClusterRequest request) throws YarnException; GetApplicationsHomeSubClusterRequest request) throws YarnException;
/** /**
@ -110,7 +115,7 @@ GetApplicationsHomeSubClusterResponse getApplicationsHomeSubClusterMap(
* not an exception reporting reason for a failure * not an exception reporting reason for a failure
* @throws YarnException if the request is invalid/fails * @throws YarnException if the request is invalid/fails
*/ */
DeleteApplicationHomeSubClusterResponse deleteApplicationHomeSubClusterMap( DeleteApplicationHomeSubClusterResponse deleteApplicationHomeSubCluster(
DeleteApplicationHomeSubClusterRequest request) throws YarnException; DeleteApplicationHomeSubClusterRequest request) throws YarnException;
} }

View File

@ -89,7 +89,6 @@ public void close() {
public SubClusterRegisterResponse registerSubCluster( public SubClusterRegisterResponse registerSubCluster(
SubClusterRegisterRequest request) throws YarnException { SubClusterRegisterRequest request) throws YarnException {
SubClusterInfo subClusterInfo = request.getSubClusterInfo(); SubClusterInfo subClusterInfo = request.getSubClusterInfo();
subClusterInfo.setLastStartTime(clock.getTime());
membership.put(subClusterInfo.getSubClusterId(), subClusterInfo); membership.put(subClusterInfo.getSubClusterId(), subClusterInfo);
return SubClusterRegisterResponse.newInstance(); return SubClusterRegisterResponse.newInstance();
} }
@ -156,21 +155,22 @@ public GetSubClustersInfoResponse getSubClusters(
// FederationApplicationHomeSubClusterStore methods // FederationApplicationHomeSubClusterStore methods
@Override @Override
public AddApplicationHomeSubClusterResponse addApplicationHomeSubClusterMap( public AddApplicationHomeSubClusterResponse addApplicationHomeSubCluster(
AddApplicationHomeSubClusterRequest request) throws YarnException { AddApplicationHomeSubClusterRequest request) throws YarnException {
ApplicationId appId = ApplicationId appId =
request.getApplicationHomeSubCluster().getApplicationId(); request.getApplicationHomeSubCluster().getApplicationId();
if (applications.containsKey(appId)) {
throw new YarnException("Application " + appId + " already exists"); if (!applications.containsKey(appId)) {
applications.put(appId,
request.getApplicationHomeSubCluster().getHomeSubCluster());
} }
applications.put(appId, return AddApplicationHomeSubClusterResponse
request.getApplicationHomeSubCluster().getHomeSubCluster()); .newInstance(applications.get(appId));
return AddApplicationHomeSubClusterResponse.newInstance();
} }
@Override @Override
public UpdateApplicationHomeSubClusterResponse updateApplicationHomeSubClusterMap( public UpdateApplicationHomeSubClusterResponse updateApplicationHomeSubCluster(
UpdateApplicationHomeSubClusterRequest request) throws YarnException { UpdateApplicationHomeSubClusterRequest request) throws YarnException {
ApplicationId appId = ApplicationId appId =
request.getApplicationHomeSubCluster().getApplicationId(); request.getApplicationHomeSubCluster().getApplicationId();
@ -184,7 +184,7 @@ public UpdateApplicationHomeSubClusterResponse updateApplicationHomeSubClusterMa
} }
@Override @Override
public GetApplicationHomeSubClusterResponse getApplicationHomeSubClusterMap( public GetApplicationHomeSubClusterResponse getApplicationHomeSubCluster(
GetApplicationHomeSubClusterRequest request) throws YarnException { GetApplicationHomeSubClusterRequest request) throws YarnException {
ApplicationId appId = request.getApplicationId(); ApplicationId appId = request.getApplicationId();
if (!applications.containsKey(appId)) { if (!applications.containsKey(appId)) {
@ -196,7 +196,7 @@ public GetApplicationHomeSubClusterResponse getApplicationHomeSubClusterMap(
} }
@Override @Override
public GetApplicationsHomeSubClusterResponse getApplicationsHomeSubClusterMap( public GetApplicationsHomeSubClusterResponse getApplicationsHomeSubCluster(
GetApplicationsHomeSubClusterRequest request) throws YarnException { GetApplicationsHomeSubClusterRequest request) throws YarnException {
List<ApplicationHomeSubCluster> result = List<ApplicationHomeSubCluster> result =
new ArrayList<ApplicationHomeSubCluster>(); new ArrayList<ApplicationHomeSubCluster>();
@ -210,7 +210,7 @@ public GetApplicationsHomeSubClusterResponse getApplicationsHomeSubClusterMap(
} }
@Override @Override
public DeleteApplicationHomeSubClusterResponse deleteApplicationHomeSubClusterMap( public DeleteApplicationHomeSubClusterResponse deleteApplicationHomeSubCluster(
DeleteApplicationHomeSubClusterRequest request) throws YarnException { DeleteApplicationHomeSubClusterRequest request) throws YarnException {
ApplicationId appId = request.getApplicationId(); ApplicationId appId = request.getApplicationId();
if (!applications.containsKey(appId)) { if (!applications.containsKey(appId)) {

View File

@ -24,10 +24,13 @@
/** /**
* AddApplicationHomeSubClusterResponse contains the answer from the * AddApplicationHomeSubClusterResponse contains the answer from the
* {@code FederationApplicationHomeSubClusterStore} to a request to insert a * {@code FederationApplicationHomeSubClusterStore} to a request to insert a
* newly generated applicationId and its owner. Currently response is empty if * newly generated applicationId and its owner.
* the operation was successful, if not an exception reporting reason for a
* failure.
* *
* The response contains application's home sub-cluster as it is stored in the
* {@code FederationApplicationHomeSubClusterStore}. If a mapping for the
* application already existed, the {@code SubClusterId} in this response will
* return the existing mapping which might be different from that in the
* {@code AddApplicationHomeSubClusterRequest}.
*/ */
@Private @Private
@Unstable @Unstable
@ -35,10 +38,28 @@ public abstract class AddApplicationHomeSubClusterResponse {
@Private @Private
@Unstable @Unstable
public static AddApplicationHomeSubClusterResponse newInstance() { public static AddApplicationHomeSubClusterResponse newInstance(
SubClusterId homeSubCluster) {
AddApplicationHomeSubClusterResponse response = AddApplicationHomeSubClusterResponse response =
Records.newRecord(AddApplicationHomeSubClusterResponse.class); Records.newRecord(AddApplicationHomeSubClusterResponse.class);
response.setHomeSubCluster(homeSubCluster);
return response; return response;
} }
/**
* Set the home sub-cluster that this application has been assigned to.
*
* @param homeSubCluster the {@link SubClusterId} of this application's home
* sub-cluster
*/
public abstract void setHomeSubCluster(SubClusterId homeSubCluster);
/**
* Get the home sub-cluster that this application has been assigned to. This
* may not match the {@link SubClusterId} in the corresponding response, if
* the mapping for the request's application already existed.
*
* @return the {@link SubClusterId} of this application's home sub-cluster
*/
public abstract SubClusterId getHomeSubCluster();
} }

View File

@ -20,7 +20,10 @@
import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.AddApplicationHomeSubClusterResponseProto; import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.AddApplicationHomeSubClusterResponseProto;
import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.AddApplicationHomeSubClusterResponseProtoOrBuilder;
import org.apache.hadoop.yarn.federation.proto.YarnServerFederationProtos.SubClusterIdProto;
import org.apache.hadoop.yarn.server.federation.store.records.AddApplicationHomeSubClusterResponse; import org.apache.hadoop.yarn.server.federation.store.records.AddApplicationHomeSubClusterResponse;
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
import com.google.protobuf.TextFormat; import com.google.protobuf.TextFormat;
@ -48,12 +51,40 @@ public AddApplicationHomeSubClusterResponsePBImpl(
viaProto = true; viaProto = true;
} }
private void maybeInitBuilder() {
if (viaProto || builder == null) {
builder = AddApplicationHomeSubClusterResponseProto.newBuilder(proto);
}
viaProto = false;
}
public AddApplicationHomeSubClusterResponseProto getProto() { public AddApplicationHomeSubClusterResponseProto getProto() {
proto = viaProto ? proto : builder.build(); proto = viaProto ? proto : builder.build();
viaProto = true; viaProto = true;
return proto; return proto;
} }
@Override
public void setHomeSubCluster(SubClusterId homeSubCluster) {
maybeInitBuilder();
if (homeSubCluster == null) {
builder.clearHomeSubCluster();
return;
}
builder.setHomeSubCluster(convertToProtoFormat(homeSubCluster));
}
@Override
public SubClusterId getHomeSubCluster() {
AddApplicationHomeSubClusterResponseProtoOrBuilder p =
viaProto ? proto : builder;
if (!p.hasHomeSubCluster()) {
return null;
}
return convertFromProtoFormat(p.getHomeSubCluster());
}
@Override @Override
public int hashCode() { public int hashCode() {
return getProto().hashCode(); return getProto().hashCode();
@ -75,4 +106,12 @@ public String toString() {
return TextFormat.shortDebugString(getProto()); return TextFormat.shortDebugString(getProto());
} }
private SubClusterId convertFromProtoFormat(SubClusterIdProto sc) {
return new SubClusterIdPBImpl(sc);
}
private SubClusterIdProto convertToProtoFormat(SubClusterId sc) {
return ((SubClusterIdPBImpl) sc).getProto();
}
} }

View File

@ -102,6 +102,7 @@ message AddApplicationHomeSubClusterRequestProto {
} }
message AddApplicationHomeSubClusterResponseProto { message AddApplicationHomeSubClusterResponseProto {
optional SubClusterIdProto home_sub_cluster = 1;
} }
message UpdateApplicationHomeSubClusterRequestProto { message UpdateApplicationHomeSubClusterRequestProto {

View File

@ -94,7 +94,7 @@ public void testRegisterSubCluster() throws Exception {
@Test @Test
public void testDeregisterSubCluster() throws Exception { public void testDeregisterSubCluster() throws Exception {
SubClusterId subClusterId = SubClusterId.newInstance("SC"); SubClusterId subClusterId = SubClusterId.newInstance("SC");
registerSubCluster(subClusterId); registerSubCluster(createSubClusterInfo(subClusterId));
SubClusterDeregisterRequest deregisterRequest = SubClusterDeregisterRequest SubClusterDeregisterRequest deregisterRequest = SubClusterDeregisterRequest
.newInstance(subClusterId, SubClusterState.SC_UNREGISTERED); .newInstance(subClusterId, SubClusterState.SC_UNREGISTERED);
@ -124,7 +124,7 @@ public void testGetSubClusterInfo() throws Exception {
SubClusterId subClusterId = SubClusterId.newInstance("SC"); SubClusterId subClusterId = SubClusterId.newInstance("SC");
SubClusterInfo subClusterInfo = createSubClusterInfo(subClusterId); SubClusterInfo subClusterInfo = createSubClusterInfo(subClusterId);
registerSubCluster(subClusterId); registerSubCluster(subClusterInfo);
GetSubClusterInfoRequest request = GetSubClusterInfoRequest request =
GetSubClusterInfoRequest.newInstance(subClusterId); GetSubClusterInfoRequest.newInstance(subClusterId);
@ -184,10 +184,10 @@ public void testGetAllSubClustersInfo() throws Exception {
@Test @Test
public void testSubClusterHeartbeat() throws Exception { public void testSubClusterHeartbeat() throws Exception {
SubClusterId subClusterId = SubClusterId.newInstance("SC"); SubClusterId subClusterId = SubClusterId.newInstance("SC");
registerSubCluster(subClusterId); registerSubCluster(createSubClusterInfo(subClusterId));
SubClusterHeartbeatRequest heartbeatRequest = SubClusterHeartbeatRequest SubClusterHeartbeatRequest heartbeatRequest = SubClusterHeartbeatRequest
.newInstance(subClusterId, SubClusterState.SC_RUNNING, "cabability"); .newInstance(subClusterId, SubClusterState.SC_RUNNING, "capability");
stateStore.subClusterHeartbeat(heartbeatRequest); stateStore.subClusterHeartbeat(heartbeatRequest);
Assert.assertEquals(SubClusterState.SC_RUNNING, Assert.assertEquals(SubClusterState.SC_RUNNING,
@ -199,7 +199,7 @@ public void testSubClusterHeartbeat() throws Exception {
public void testSubClusterHeartbeatUnknownSubCluster() throws Exception { public void testSubClusterHeartbeatUnknownSubCluster() throws Exception {
SubClusterId subClusterId = SubClusterId.newInstance("SC"); SubClusterId subClusterId = SubClusterId.newInstance("SC");
SubClusterHeartbeatRequest heartbeatRequest = SubClusterHeartbeatRequest SubClusterHeartbeatRequest heartbeatRequest = SubClusterHeartbeatRequest
.newInstance(subClusterId, SubClusterState.SC_RUNNING, "cabability"); .newInstance(subClusterId, SubClusterState.SC_RUNNING, "capability");
try { try {
stateStore.subClusterHeartbeat(heartbeatRequest); stateStore.subClusterHeartbeat(heartbeatRequest);
@ -213,7 +213,7 @@ public void testSubClusterHeartbeatUnknownSubCluster() throws Exception {
// Test FederationApplicationHomeSubClusterStore // Test FederationApplicationHomeSubClusterStore
@Test @Test
public void testAddApplicationHomeSubClusterMap() throws Exception { public void testAddApplicationHomeSubCluster() throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
SubClusterId subClusterId = SubClusterId.newInstance("SC"); SubClusterId subClusterId = SubClusterId.newInstance("SC");
ApplicationHomeSubCluster ahsc = ApplicationHomeSubCluster ahsc =
@ -222,15 +222,15 @@ public void testAddApplicationHomeSubClusterMap() throws Exception {
AddApplicationHomeSubClusterRequest request = AddApplicationHomeSubClusterRequest request =
AddApplicationHomeSubClusterRequest.newInstance(ahsc); AddApplicationHomeSubClusterRequest.newInstance(ahsc);
AddApplicationHomeSubClusterResponse response = AddApplicationHomeSubClusterResponse response =
stateStore.addApplicationHomeSubClusterMap(request); stateStore.addApplicationHomeSubCluster(request);
Assert.assertNotNull(response); Assert.assertEquals(subClusterId, response.getHomeSubCluster());
Assert.assertEquals(subClusterId, queryApplicationHomeSC(appId)); Assert.assertEquals(subClusterId, queryApplicationHomeSC(appId));
} }
@Test @Test
public void testAddApplicationHomeSubClusterMapAppAlreadyExists() public void testAddApplicationHomeSubClusterAppAlreadyExists()
throws Exception { throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
SubClusterId subClusterId1 = SubClusterId.newInstance("SC1"); SubClusterId subClusterId1 = SubClusterId.newInstance("SC1");
@ -240,21 +240,17 @@ public void testAddApplicationHomeSubClusterMapAppAlreadyExists()
ApplicationHomeSubCluster ahsc2 = ApplicationHomeSubCluster ahsc2 =
ApplicationHomeSubCluster.newInstance(appId, subClusterId2); ApplicationHomeSubCluster.newInstance(appId, subClusterId2);
try { AddApplicationHomeSubClusterResponse response =
stateStore.addApplicationHomeSubClusterMap( stateStore.addApplicationHomeSubCluster(
AddApplicationHomeSubClusterRequest.newInstance(ahsc2)); AddApplicationHomeSubClusterRequest.newInstance(ahsc2));
Assert.fail();
} catch (YarnException e) {
Assert.assertTrue(e.getMessage()
.startsWith("Application " + appId.toString() + " already exists"));
}
Assert.assertEquals(subClusterId1, response.getHomeSubCluster());
Assert.assertEquals(subClusterId1, queryApplicationHomeSC(appId)); Assert.assertEquals(subClusterId1, queryApplicationHomeSC(appId));
} }
@Test @Test
public void testDeleteApplicationHomeSubClusterMap() throws Exception { public void testDeleteApplicationHomeSubCluster() throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
SubClusterId subClusterId = SubClusterId.newInstance("SC"); SubClusterId subClusterId = SubClusterId.newInstance("SC");
addApplicationHomeSC(appId, subClusterId); addApplicationHomeSC(appId, subClusterId);
@ -263,7 +259,7 @@ public void testDeleteApplicationHomeSubClusterMap() throws Exception {
DeleteApplicationHomeSubClusterRequest.newInstance(appId); DeleteApplicationHomeSubClusterRequest.newInstance(appId);
DeleteApplicationHomeSubClusterResponse response = DeleteApplicationHomeSubClusterResponse response =
stateStore.deleteApplicationHomeSubClusterMap(delRequest); stateStore.deleteApplicationHomeSubCluster(delRequest);
Assert.assertNotNull(response); Assert.assertNotNull(response);
try { try {
@ -277,14 +273,13 @@ public void testDeleteApplicationHomeSubClusterMap() throws Exception {
} }
@Test @Test
public void testDeleteApplicationHomeSubClusterMapUnknownApp() public void testDeleteApplicationHomeSubClusterUnknownApp() throws Exception {
throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
DeleteApplicationHomeSubClusterRequest delRequest = DeleteApplicationHomeSubClusterRequest delRequest =
DeleteApplicationHomeSubClusterRequest.newInstance(appId); DeleteApplicationHomeSubClusterRequest.newInstance(appId);
try { try {
stateStore.deleteApplicationHomeSubClusterMap(delRequest); stateStore.deleteApplicationHomeSubCluster(delRequest);
Assert.fail(); Assert.fail();
} catch (YarnException e) { } catch (YarnException e) {
Assert.assertTrue(e.getMessage() Assert.assertTrue(e.getMessage()
@ -293,7 +288,7 @@ public void testDeleteApplicationHomeSubClusterMapUnknownApp()
} }
@Test @Test
public void testGetApplicationHomeSubClusterMap() throws Exception { public void testGetApplicationHomeSubCluster() throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
SubClusterId subClusterId = SubClusterId.newInstance("SC"); SubClusterId subClusterId = SubClusterId.newInstance("SC");
addApplicationHomeSC(appId, subClusterId); addApplicationHomeSC(appId, subClusterId);
@ -302,7 +297,7 @@ public void testGetApplicationHomeSubClusterMap() throws Exception {
GetApplicationHomeSubClusterRequest.newInstance(appId); GetApplicationHomeSubClusterRequest.newInstance(appId);
GetApplicationHomeSubClusterResponse result = GetApplicationHomeSubClusterResponse result =
stateStore.getApplicationHomeSubClusterMap(getRequest); stateStore.getApplicationHomeSubCluster(getRequest);
Assert.assertEquals(appId, Assert.assertEquals(appId,
result.getApplicationHomeSubCluster().getApplicationId()); result.getApplicationHomeSubCluster().getApplicationId());
@ -311,13 +306,13 @@ public void testGetApplicationHomeSubClusterMap() throws Exception {
} }
@Test @Test
public void testGetApplicationHomeSubClusterMapUnknownApp() throws Exception { public void testGetApplicationHomeSubClusterUnknownApp() throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
GetApplicationHomeSubClusterRequest request = GetApplicationHomeSubClusterRequest request =
GetApplicationHomeSubClusterRequest.newInstance(appId); GetApplicationHomeSubClusterRequest.newInstance(appId);
try { try {
stateStore.getApplicationHomeSubClusterMap(request); stateStore.getApplicationHomeSubCluster(request);
Assert.fail(); Assert.fail();
} catch (YarnException e) { } catch (YarnException e) {
Assert.assertTrue(e.getMessage() Assert.assertTrue(e.getMessage()
@ -326,7 +321,7 @@ public void testGetApplicationHomeSubClusterMapUnknownApp() throws Exception {
} }
@Test @Test
public void testGetApplicationsHomeSubClusterMap() throws Exception { public void testGetApplicationsHomeSubCluster() throws Exception {
ApplicationId appId1 = ApplicationId.newInstance(1, 1); ApplicationId appId1 = ApplicationId.newInstance(1, 1);
SubClusterId subClusterId1 = SubClusterId.newInstance("SC1"); SubClusterId subClusterId1 = SubClusterId.newInstance("SC1");
ApplicationHomeSubCluster ahsc1 = ApplicationHomeSubCluster ahsc1 =
@ -344,7 +339,7 @@ public void testGetApplicationsHomeSubClusterMap() throws Exception {
GetApplicationsHomeSubClusterRequest.newInstance(); GetApplicationsHomeSubClusterRequest.newInstance();
GetApplicationsHomeSubClusterResponse result = GetApplicationsHomeSubClusterResponse result =
stateStore.getApplicationsHomeSubClusterMap(getRequest); stateStore.getApplicationsHomeSubCluster(getRequest);
Assert.assertEquals(2, result.getAppsHomeSubClusters().size()); Assert.assertEquals(2, result.getAppsHomeSubClusters().size());
Assert.assertTrue(result.getAppsHomeSubClusters().contains(ahsc1)); Assert.assertTrue(result.getAppsHomeSubClusters().contains(ahsc1));
@ -352,7 +347,7 @@ public void testGetApplicationsHomeSubClusterMap() throws Exception {
} }
@Test @Test
public void testUpdateApplicationHomeSubClusterMap() throws Exception { public void testUpdateApplicationHomeSubCluster() throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
SubClusterId subClusterId1 = SubClusterId.newInstance("SC1"); SubClusterId subClusterId1 = SubClusterId.newInstance("SC1");
addApplicationHomeSC(appId, subClusterId1); addApplicationHomeSC(appId, subClusterId1);
@ -365,16 +360,14 @@ public void testUpdateApplicationHomeSubClusterMap() throws Exception {
UpdateApplicationHomeSubClusterRequest.newInstance(ahscUpdate); UpdateApplicationHomeSubClusterRequest.newInstance(ahscUpdate);
UpdateApplicationHomeSubClusterResponse response = UpdateApplicationHomeSubClusterResponse response =
stateStore.updateApplicationHomeSubClusterMap(updateRequest); stateStore.updateApplicationHomeSubCluster(updateRequest);
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(subClusterId2, queryApplicationHomeSC(appId)); Assert.assertEquals(subClusterId2, queryApplicationHomeSC(appId));
} }
@Test @Test
public void testUpdateApplicationHomeSubClusterMapUnknownApp() public void testUpdateApplicationHomeSubClusterUnknownApp() throws Exception {
throws Exception {
ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationId appId = ApplicationId.newInstance(1, 1);
SubClusterId subClusterId1 = SubClusterId.newInstance("SC1"); SubClusterId subClusterId1 = SubClusterId.newInstance("SC1");
ApplicationHomeSubCluster ahsc = ApplicationHomeSubCluster ahsc =
@ -384,7 +377,7 @@ public void testUpdateApplicationHomeSubClusterMapUnknownApp()
UpdateApplicationHomeSubClusterRequest.newInstance(ahsc); UpdateApplicationHomeSubClusterRequest.newInstance(ahsc);
try { try {
stateStore.updateApplicationHomeSubClusterMap((updateRequest)); stateStore.updateApplicationHomeSubCluster((updateRequest));
Assert.fail(); Assert.fail();
} catch (YarnException e) { } catch (YarnException e) {
Assert.assertTrue(e.getMessage() Assert.assertTrue(e.getMessage()
@ -484,7 +477,7 @@ private SubClusterInfo createSubClusterInfo(SubClusterId subClusterId) {
return SubClusterInfo.newInstance(subClusterId, amRMAddress, return SubClusterInfo.newInstance(subClusterId, amRMAddress,
clientRMAddress, rmAdminAddress, webAppAddress, SubClusterState.SC_NEW, clientRMAddress, rmAdminAddress, webAppAddress, SubClusterState.SC_NEW,
CLOCK.getTime(), "cabability"); CLOCK.getTime(), "capability");
} }
private SubClusterPolicyConfiguration createSCPolicyConf(String queueName, private SubClusterPolicyConfiguration createSCPolicyConf(String queueName,
@ -499,7 +492,7 @@ private void addApplicationHomeSC(ApplicationId appId,
ApplicationHomeSubCluster.newInstance(appId, subClusterId); ApplicationHomeSubCluster.newInstance(appId, subClusterId);
AddApplicationHomeSubClusterRequest request = AddApplicationHomeSubClusterRequest request =
AddApplicationHomeSubClusterRequest.newInstance(ahsc); AddApplicationHomeSubClusterRequest.newInstance(ahsc);
stateStore.addApplicationHomeSubClusterMap(request); stateStore.addApplicationHomeSubCluster(request);
} }
private void setPolicyConf(String queue, String policyType) private void setPolicyConf(String queue, String policyType)
@ -510,10 +503,8 @@ private void setPolicyConf(String queue, String policyType)
stateStore.setPolicyConfiguration(request); stateStore.setPolicyConfiguration(request);
} }
private void registerSubCluster(SubClusterId subClusterId) private void registerSubCluster(SubClusterInfo subClusterInfo)
throws YarnException { throws YarnException {
SubClusterInfo subClusterInfo = createSubClusterInfo(subClusterId);
stateStore.registerSubCluster( stateStore.registerSubCluster(
SubClusterRegisterRequest.newInstance(subClusterInfo)); SubClusterRegisterRequest.newInstance(subClusterInfo));
} }
@ -531,7 +522,7 @@ private SubClusterId queryApplicationHomeSC(ApplicationId appId)
GetApplicationHomeSubClusterRequest.newInstance(appId); GetApplicationHomeSubClusterRequest.newInstance(appId);
GetApplicationHomeSubClusterResponse response = GetApplicationHomeSubClusterResponse response =
stateStore.getApplicationHomeSubClusterMap(request); stateStore.getApplicationHomeSubCluster(request);
return response.getApplicationHomeSubCluster().getHomeSubCluster(); return response.getApplicationHomeSubCluster().getHomeSubCluster();
} }