Search in sources :

Example 41 with YarnApplicationState

use of org.apache.hadoop.yarn.api.records.YarnApplicationState in project ignite by apache.

the class IgniteYarnClient method main.

/**
     * Main methods has one mandatory parameter and one optional parameter.
     *
     * @param args Path to jar mandatory parameter and property file is optional.
     */
public static void main(String[] args) throws Exception {
    checkArguments(args);
    // Set path to app master jar.
    String pathAppMasterJar = args[0];
    ClusterProperties props = ClusterProperties.from(args.length == 2 ? args[1] : null);
    YarnConfiguration conf = new YarnConfiguration();
    YarnClient yarnClient = YarnClient.createYarnClient();
    yarnClient.init(conf);
    yarnClient.start();
    // Create application via yarnClient
    YarnClientApplication app = yarnClient.createApplication();
    FileSystem fs = FileSystem.get(conf);
    Path ignite;
    // Load ignite and jar
    if (props.ignitePath() == null)
        ignite = getIgnite(props, fs);
    else
        ignite = new Path(props.ignitePath());
    // Upload the jar file to HDFS.
    Path appJar = IgniteYarnUtils.copyLocalToHdfs(fs, pathAppMasterJar, props.igniteWorkDir() + File.separator + IgniteYarnUtils.JAR_NAME);
    // Set up the container launch context for the application master
    ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
    amContainer.setCommands(Collections.singletonList(Environment.JAVA_HOME.$() + "/bin/java -Xmx512m " + ApplicationMaster.class.getName() + IgniteYarnUtils.SPACE + ignite.toUri() + IgniteYarnUtils.YARN_LOG_OUT));
    // Setup jar for ApplicationMaster
    LocalResource appMasterJar = IgniteYarnUtils.setupFile(appJar, fs, LocalResourceType.FILE);
    amContainer.setLocalResources(Collections.singletonMap(IgniteYarnUtils.JAR_NAME, appMasterJar));
    // Setup CLASSPATH for ApplicationMaster
    Map<String, String> appMasterEnv = props.toEnvs();
    setupAppMasterEnv(appMasterEnv, conf);
    amContainer.setEnvironment(appMasterEnv);
    // Setup security tokens
    if (UserGroupInformation.isSecurityEnabled()) {
        Credentials creds = new Credentials();
        String tokRenewer = conf.get(YarnConfiguration.RM_PRINCIPAL);
        if (tokRenewer == null || tokRenewer.length() == 0)
            throw new IOException("Master Kerberos principal for the RM is not set.");
        log.info("Found RM principal: " + tokRenewer);
        final Token<?>[] tokens = fs.addDelegationTokens(tokRenewer, creds);
        if (tokens != null)
            log.info("File system delegation tokens: " + Arrays.toString(tokens));
        amContainer.setTokens(IgniteYarnUtils.createTokenBuffer(creds));
    }
    // Set up resource type requirements for ApplicationMaster
    Resource capability = Records.newRecord(Resource.class);
    capability.setMemory(512);
    capability.setVirtualCores(1);
    // Finally, set-up ApplicationSubmissionContext for the application
    ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
    // application name
    appContext.setApplicationName("ignition");
    appContext.setAMContainerSpec(amContainer);
    appContext.setResource(capability);
    // queue
    appContext.setQueue("default");
    // Submit application
    ApplicationId appId = appContext.getApplicationId();
    yarnClient.submitApplication(appContext);
    log.log(Level.INFO, "Submitted application. Application id: {0}", appId);
    ApplicationReport appReport = yarnClient.getApplicationReport(appId);
    YarnApplicationState appState = appReport.getYarnApplicationState();
    while (appState == YarnApplicationState.NEW || appState == YarnApplicationState.NEW_SAVING || appState == YarnApplicationState.SUBMITTED || appState == YarnApplicationState.ACCEPTED) {
        TimeUnit.SECONDS.sleep(1L);
        appReport = yarnClient.getApplicationReport(appId);
        if (appState != YarnApplicationState.ACCEPTED && appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED)
            log.log(Level.INFO, "Application {0} is ACCEPTED.", appId);
        appState = appReport.getYarnApplicationState();
    }
    log.log(Level.INFO, "Application {0} is {1}.", new Object[] { appId, appState });
}
Also used : Path(org.apache.hadoop.fs.Path) YarnClientApplication(org.apache.hadoop.yarn.client.api.YarnClientApplication) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) Token(org.apache.hadoop.security.token.Token) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) IOException(java.io.IOException) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) FileSystem(org.apache.hadoop.fs.FileSystem) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Credentials(org.apache.hadoop.security.Credentials)

Aggregations

YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)41 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)27 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)11 IOException (java.io.IOException)10 FinalApplicationStatus (org.apache.hadoop.yarn.api.records.FinalApplicationStatus)8 HashSet (java.util.HashSet)7 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)7 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)6 ArrayList (java.util.ArrayList)5 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)5 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)5 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)5 Test (org.junit.Test)5 Path (org.apache.hadoop.fs.Path)4 Resource (org.apache.hadoop.yarn.api.records.Resource)4 YarnClientApplication (org.apache.hadoop.yarn.client.api.YarnClientApplication)4 File (java.io.File)3 HashMap (java.util.HashMap)3 FileSystem (org.apache.hadoop.fs.FileSystem)3