Search in sources :

Example 1 with AddToClusterNodeLabelsResponse

use of org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse in project hadoop by apache.

the class AdminService method addToClusterNodeLabels.

@Override
public AddToClusterNodeLabelsResponse addToClusterNodeLabels(AddToClusterNodeLabelsRequest request) throws YarnException, IOException {
    final String operation = "addToClusterNodeLabels";
    final String msg = "add labels.";
    UserGroupInformation user = checkAcls(operation);
    checkRMStatus(user.getShortUserName(), operation, msg);
    AddToClusterNodeLabelsResponse response = recordFactory.newRecordInstance(AddToClusterNodeLabelsResponse.class);
    try {
        rmContext.getNodeLabelManager().addToCluserNodeLabels(request.getNodeLabels());
        RMAuditLogger.logSuccess(user.getShortUserName(), operation, "AdminService");
        return response;
    } catch (IOException ioe) {
        throw logAndWrapException(ioe, user.getShortUserName(), operation, msg);
    }
}
Also used : AddToClusterNodeLabelsResponse(org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 2 with AddToClusterNodeLabelsResponse

use of org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse in project hadoop by apache.

the class TestRMAdminCLI method configure.

@SuppressWarnings("static-access")
@Before
public void configure() throws IOException, YarnException {
    remoteAdminServiceAccessed = false;
    admin = mock(ResourceManagerAdministrationProtocol.class);
    when(admin.addToClusterNodeLabels(any(AddToClusterNodeLabelsRequest.class))).thenAnswer(new Answer<AddToClusterNodeLabelsResponse>() {

        @Override
        public AddToClusterNodeLabelsResponse answer(InvocationOnMock invocation) throws Throwable {
            remoteAdminServiceAccessed = true;
            return AddToClusterNodeLabelsResponse.newInstance();
        }
    });
    haadmin = mock(HAServiceProtocol.class);
    when(haadmin.getServiceStatus()).thenReturn(new HAServiceStatus(HAServiceProtocol.HAServiceState.INITIALIZING));
    final HAServiceTarget haServiceTarget = mock(HAServiceTarget.class);
    when(haServiceTarget.getProxy(any(Configuration.class), anyInt())).thenReturn(haadmin);
    rmAdminCLI = new RMAdminCLI(new Configuration()) {

        @Override
        protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
            return admin;
        }

        @Override
        protected HAServiceTarget resolveTarget(String rmId) {
            return haServiceTarget;
        }
    };
    initDummyNodeLabelsManager();
    rmAdminCLI.localNodeLabelsManager = dummyNodeLabelsManager;
    YarnConfiguration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
    conf.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2");
    conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADDRESS, "rm1"), HOST_A + ":12345");
    conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADMIN_ADDRESS, "rm1"), HOST_A + ":12346");
    conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADDRESS, "rm2"), HOST_B + ":12345");
    conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADMIN_ADDRESS, "rm2"), HOST_B + ":12346");
    rmAdminCLIWithHAEnabled = new RMAdminCLI(conf) {

        @Override
        protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
            return admin;
        }

        @Override
        protected HAServiceTarget resolveTarget(String rmId) {
            HAServiceTarget target = super.resolveTarget(rmId);
            HAServiceTarget spy = Mockito.spy(target);
            // Override the target to return our mock protocol
            try {
                Mockito.doReturn(haadmin).when(spy).getProxy(Mockito.<Configuration>any(), Mockito.anyInt());
                Mockito.doReturn(false).when(spy).isAutoFailoverEnabled();
            } catch (IOException e) {
                // mock setup doesn't really throw
                throw new AssertionError(e);
            }
            return spy;
        }
    };
}
Also used : AddToClusterNodeLabelsResponse(org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) HAServiceTarget(org.apache.hadoop.ha.HAServiceTarget) IOException(java.io.IOException) ResourceManagerAdministrationProtocol(org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol) HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AddToClusterNodeLabelsRequest(org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)2 AddToClusterNodeLabelsResponse (org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsResponse)2 Configuration (org.apache.hadoop.conf.Configuration)1 HAServiceProtocol (org.apache.hadoop.ha.HAServiceProtocol)1 HAServiceStatus (org.apache.hadoop.ha.HAServiceStatus)1 HAServiceTarget (org.apache.hadoop.ha.HAServiceTarget)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 ResourceManagerAdministrationProtocol (org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol)1 AddToClusterNodeLabelsRequest (org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1