Search in sources :

Example 6 with GetNewApplicationResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse in project kitten by cloudera.

the class YarnClientServiceImpl method startUp.

@Override
protected void startUp() throws IOException {
    ByteBuffer serializedTokens = null;
    if (UserGroupInformation.isSecurityEnabled()) {
        Configuration conf = this.yarnClientFactory.getConfig();
        FileSystem fs = FileSystem.get(conf);
        Credentials credentials = new Credentials();
        String tokenRenewer = this.yarnClientFactory.getConfig().get(YarnConfiguration.RM_PRINCIPAL);
        if (tokenRenewer == null || tokenRenewer.length() == 0) {
            throw new IOException("Can't get Master Kerberos principal for the RM to use as renewer");
        }
        // For now, only getting tokens for the default file-system.
        final Token<?>[] tokens = fs.addDelegationTokens(tokenRenewer, credentials);
        if (tokens != null) {
            for (Token<?> token : tokens) {
                LOG.info("Got delegation token for " + fs.getUri() + "; " + token);
            }
        }
        DataOutputBuffer dob = new DataOutputBuffer();
        credentials.writeTokenStorageToStream(dob);
        serializedTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
    }
    this.yarnClient = yarnClientFactory.connect();
    YarnClientApplication clientApp = getNewApplication();
    GetNewApplicationResponse newApp = clientApp.getNewApplicationResponse();
    ContainerLaunchContextFactory clcFactory = new ContainerLaunchContextFactory(newApp.getMaximumResourceCapability(), serializedTokens);
    ApplicationSubmissionContext appContext = clientApp.getApplicationSubmissionContext();
    this.applicationId = appContext.getApplicationId();
    appContext.setApplicationName(parameters.getApplicationName());
    // Setup the container for the application master.
    ContainerLaunchParameters appMasterParams = parameters.getApplicationMasterParameters(applicationId);
    ContainerLaunchContext clc = clcFactory.create(appMasterParams);
    LOG.debug("Master context: " + clc);
    appContext.setResource(clcFactory.createResource(appMasterParams));
    appContext.setQueue(parameters.getQueue());
    appContext.setPriority(clcFactory.createPriority(appMasterParams.getPriority()));
    appContext.setAMContainerSpec(clc);
    submitApplication(appContext);
    // Make sure we stop the application in the case that it isn't done already.
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            if (YarnClientServiceImpl.this.isRunning()) {
                YarnClientServiceImpl.this.stop();
            }
        }
    });
    stopwatch.start();
}
Also used : GetNewApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnClientApplication(org.apache.hadoop.yarn.client.api.YarnClientApplication) ContainerLaunchParameters(com.cloudera.kitten.ContainerLaunchParameters) Token(org.apache.hadoop.security.token.Token) IOException(java.io.IOException) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) ByteBuffer(java.nio.ByteBuffer) FileSystem(org.apache.hadoop.fs.FileSystem) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) ContainerLaunchContextFactory(com.cloudera.kitten.ContainerLaunchContextFactory) Credentials(org.apache.hadoop.security.Credentials)

Example 7 with GetNewApplicationResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse in project alluxio by Alluxio.

the class Client method submitApplication.

/**
   * Submits an application to the ResourceManager to run ApplicationMaster.
   *
   * The stable Yarn API provides a convenience method (YarnClient#createApplication) for creating
   * applications and setting up the application submission context. This was not available in the
   * alpha API.
   */
private void submitApplication() throws YarnException, IOException {
    // Initialize a YarnClient
    mYarnClient = YarnClient.createYarnClient();
    mYarnClient.init(mYarnConf);
    mYarnClient.start();
    // Create an application, get and check the information about the cluster
    YarnClientApplication app = mYarnClient.createApplication();
    // Get a response of this application, containing information of the cluster
    GetNewApplicationResponse appResponse = app.getNewApplicationResponse();
    // Check if the cluster has enough resource to launch the ApplicationMaster
    checkClusterResource(appResponse);
    // Check that there are enough hosts in the cluster to support the desired number of workers
    checkNodesAvailable();
    // Set up the container launch context for the application master
    mAmContainer = Records.newRecord(ContainerLaunchContext.class);
    setupContainerLaunchContext();
    // Finally, set-up ApplicationSubmissionContext for the application
    mAppContext = app.getApplicationSubmissionContext();
    setupApplicationSubmissionContext();
    // Submit the application to the applications manager.
    // Ignore the response as either a valid response object is returned on success
    // or an exception thrown to denote some form of a failure
    mAppId = mAppContext.getApplicationId();
    System.out.println("Submitting application of id " + mAppId + " to ResourceManager");
    mYarnClient.submitApplication(mAppContext);
    monitorApplication();
}
Also used : GetNewApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse) YarnClientApplication(org.apache.hadoop.yarn.client.api.YarnClientApplication) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext)

Example 8 with GetNewApplicationResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse in project alluxio by Alluxio.

the class ClientTest method generateMaxAllocation.

private void generateMaxAllocation(Resource resource) throws Exception {
    YarnClientApplication mockYarnClientApplication = mock(YarnClientApplication.class);
    doReturn(mockYarnClientApplication).when(mYarnClient).createApplication();
    GetNewApplicationResponse mockNewApplicationResponse = mock(GetNewApplicationResponse.class);
    doReturn(mockNewApplicationResponse).when(mockYarnClientApplication).getNewApplicationResponse();
    doReturn(resource).when(mockNewApplicationResponse).getMaximumResourceCapability();
}
Also used : GetNewApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse) YarnClientApplication(org.apache.hadoop.yarn.client.api.YarnClientApplication)

Example 9 with GetNewApplicationResponse

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

the class TestRM method testGetNewAppId.

@Test
public void testGetNewAppId() throws Exception {
    Logger rootLogger = LogManager.getRootLogger();
    rootLogger.setLevel(Level.DEBUG);
    MockRM rm = new MockRM(conf);
    rm.start();
    GetNewApplicationResponse resp = rm.getNewAppId();
    assert (resp.getApplicationId().getId() != 0);
    assert (resp.getMaximumResourceCapability().getMemorySize() > 0);
    rm.stop();
}
Also used : GetNewApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse) Logger(org.apache.log4j.Logger) Test(org.junit.Test)

Example 10 with GetNewApplicationResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse in project weave by continuuity.

the class Hadoop20YarnAppClient method createLauncher.

@Override
public ProcessLauncher<ApplicationId> createLauncher(WeaveSpecification weaveSpec) throws Exception {
    // Request for new application
    final GetNewApplicationResponse response = yarnClient.getNewApplication();
    final ApplicationId appId = response.getApplicationId();
    // Setup the context for application submission
    final ApplicationSubmissionContext appSubmissionContext = Records.newRecord(ApplicationSubmissionContext.class);
    appSubmissionContext.setApplicationId(appId);
    appSubmissionContext.setApplicationName(weaveSpec.getName());
    appSubmissionContext.setUser(user);
    ApplicationSubmitter submitter = new ApplicationSubmitter() {

        @Override
        public ProcessController<YarnApplicationReport> submit(YarnLaunchContext launchContext, Resource capability) {
            ContainerLaunchContext context = launchContext.getLaunchContext();
            addRMToken(context);
            context.setUser(appSubmissionContext.getUser());
            context.setResource(adjustMemory(response, capability));
            appSubmissionContext.setAMContainerSpec(context);
            try {
                yarnClient.submitApplication(appSubmissionContext);
                return new ProcessControllerImpl(yarnClient, appId);
            } catch (YarnRemoteException e) {
                LOG.error("Failed to submit application {}", appId, e);
                throw Throwables.propagate(e);
            }
        }
    };
    return new ApplicationMasterProcessLauncher(appId, submitter);
}
Also used : ApplicationMasterProcessLauncher(com.continuuity.weave.internal.appmaster.ApplicationMasterProcessLauncher) GetNewApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) Resource(org.apache.hadoop.yarn.api.records.Resource) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationSubmitter(com.continuuity.weave.internal.appmaster.ApplicationSubmitter) YarnRemoteException(org.apache.hadoop.yarn.exceptions.YarnRemoteException)

Aggregations

GetNewApplicationResponse (org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse)16 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)9 YarnClientApplication (org.apache.hadoop.yarn.client.api.YarnClientApplication)9 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)8 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)7 ByteBuffer (java.nio.ByteBuffer)5 Resource (org.apache.hadoop.yarn.api.records.Resource)5 IOException (java.io.IOException)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)4 GetNewApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest)4 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)4 QueueInfo (org.apache.hadoop.yarn.api.records.QueueInfo)4 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Path (org.apache.hadoop.fs.Path)3 Credentials (org.apache.hadoop.security.Credentials)3 Token (org.apache.hadoop.security.token.Token)3 YarnClusterMetrics (org.apache.hadoop.yarn.api.records.YarnClusterMetrics)3