Example usage for org.apache.hadoop.yarn.api.records ApplicationReport getName

List of usage examples for org.apache.hadoop.yarn.api.records ApplicationReport getName

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ApplicationReport getName.

Prototype

@Public
@Stable
public abstract String getName();

Source Link

Document

Get the user-defined name of the application.

Usage

From source file:io.hops.hopsworks.api.zeppelin.rest.InterpreterRestApi.java

License:Apache License

private List<JobAdministration.YarnApplicationReport> fetchJobs(String username) {
    JobAdministration jobAdmin = new JobAdministration();
    List<JobAdministration.YarnApplicationReport> reports = new ArrayList<>();
    YarnClient client = YarnClient.createYarnClient();
    Configuration conf = settings.getConfiguration();
    client.init(conf);//w w  w  . jav a 2s . c  om
    client.start();
    try {
        //Create our custom YarnApplicationReport Pojo
        for (ApplicationReport appReport : client.getApplications(PREDICATE)) {
            if (username.equals(appReport.getUser())) {
                reports.add(jobAdmin.new YarnApplicationReport(appReport.getApplicationId().toString(),
                        appReport.getName(), appReport.getUser(), appReport.getStartTime(),
                        appReport.getFinishTime(), appReport.getApplicationId().getClusterTimestamp(),
                        appReport.getApplicationId().getId(), appReport.getYarnApplicationState().name()));
            }
        }
    } catch (YarnException | IOException ex) {
        logger.error("", ex);
    }
    return reports;
}

From source file:org.apache.ambari.view.slider.SliderAppsViewControllerImpl.java

License:Apache License

private SliderApp createSliderAppObject(ApplicationReport yarnApp, Set<String> properties,
        SliderClient sliderClient) {//from  w w w.j  a  va  2  s .  c o m
    if (yarnApp == null) {
        return null;
    }

    SliderApp app = new SliderApp();
    app.setState(yarnApp.getYarnApplicationState().name());

    // Valid Slider App?
    // We want all Slider apps except the ones which properly finished.
    if (YarnApplicationState.FINISHED.equals(yarnApp.getYarnApplicationState())) {
        try {
            if (sliderClient.actionExists(yarnApp.getName(), false) == LauncherExitCodes.EXIT_SUCCESS) {
                app.setState(SliderApp.STATE_FROZEN);
            }
        } catch (UnknownApplicationInstanceException e) {
            return null; // Application not in HDFS - means it is not frozen
        } catch (YarnException e) {
            logger.warn("Unable to determine frozen state for " + yarnApp.getName(), e);
            return null;
        } catch (IOException e) {
            logger.warn("Unable to determine frozen state for " + yarnApp.getName(), e);
            return null;
        }
    }
    if (YarnApplicationState.KILLED.equals(yarnApp.getYarnApplicationState())
            || YarnApplicationState.FAILED.equals(yarnApp.getYarnApplicationState())) {
        try {
            if (sliderClient.actionExists(yarnApp.getName(), false) != LauncherExitCodes.EXIT_SUCCESS) {
                // YARN application is killed or failed, and no HDFS content - Application has been destroyed.
                return null;
            }
        } catch (UnknownApplicationInstanceException e) {
            return null; // Application not in HDFS - means it is not frozen
        } catch (YarnException e) {
            logger.warn("Unable to determine status of killed app " + yarnApp.getName(), e);
            return null;
        } catch (IOException e) {
            logger.warn("Unable to determine status of killed app " + yarnApp.getName(), e);
            return null;
        }
    }

    app.setId(getApplicationIdString(yarnApp.getApplicationId()));
    app.setName(yarnApp.getName());
    app.setUser(yarnApp.getUser());
    app.setDiagnostics(yarnApp.getDiagnostics());
    app.setYarnId(yarnApp.getApplicationId().toString());
    app.setStartTime(yarnApp.getStartTime());
    app.setEndTime(yarnApp.getFinishTime());
    Set<String> applicationTags = yarnApp.getApplicationTags();
    if (applicationTags != null && applicationTags.size() > 0) {
        for (String tag : applicationTags) {
            int index = tag.indexOf(':');
            if (index > 0 && index < tag.length() - 1) {
                String key = tag.substring(0, index).trim();
                String value = tag.substring(index + 1).trim();
                if ("name".equals(key)) {
                    app.setType(value);
                } else if ("version".equals(key)) {
                    app.setAppVersion(value);
                } else if ("description".equals(key)) {
                    app.setDescription(value);
                }
            }
        }
    }
    if (properties != null && !properties.isEmpty()) {
        SliderAppType matchedAppType = null;
        List<SliderAppType> matchingAppTypes = getSliderAppTypes(null);
        if (matchingAppTypes != null && matchingAppTypes.size() > 0) {
            for (SliderAppType appType : matchingAppTypes) {
                if ((appType.getTypeName() != null && appType.getTypeName().equalsIgnoreCase(app.getType()))
                        && (appType.getTypeVersion() != null
                                && appType.getTypeVersion().equalsIgnoreCase(app.getAppVersion()))) {
                    matchedAppType = appType;
                    break;
                }
            }
        }

        SliderAppMasterClient sliderAppClient = yarnApp.getTrackingUrl() == null ? null
                : new SliderAppMasterClient(yarnApp.getTrackingUrl());
        SliderAppMasterData appMasterData = null;
        Map<String, String> quickLinks = new HashMap<String, String>();
        Set<String> metrics = new HashSet<String>();
        for (String property : properties) {
            if ("RUNNING".equals(app.getState())) {
                if (sliderAppClient != null) {
                    if (appMasterData == null) {
                        appMasterData = sliderAppClient.getAppMasterData();
                    }
                    if (appMasterData != null && "urls".equals(property.toLowerCase())) {
                        if (quickLinks.isEmpty()) {
                            quickLinks = sliderAppClient.getQuickLinks(appMasterData.publisherUrl);
                        }
                        app.setUrls(quickLinks);
                    } else if (appMasterData != null && "configs".equals(property.toLowerCase())) {
                        Map<String, Map<String, String>> configs = sliderAppClient
                                .getConfigs(appMasterData.publisherUrl);
                        app.setConfigs(configs);
                    } else if (appMasterData != null && "jmx".equals(property.toLowerCase())) {
                        if (quickLinks.isEmpty()) {
                            quickLinks = sliderAppClient.getQuickLinks(appMasterData.publisherUrl);
                        }
                        if (quickLinks != null && quickLinks.containsKey("JMX")) {
                            String jmxUrl = quickLinks.get("JMX");
                            if (matchedAppType != null) {
                                MetricsHolder metricsHolder = appMetrics.get(matchedAppType.uniqueName());
                                app.setJmx(sliderAppClient.getJmx(jmxUrl, viewContext, matchedAppType,
                                        metricsHolder));
                            }
                        }
                        Map<String, Map<String, String>> configs = sliderAppClient
                                .getConfigs(appMasterData.publisherUrl);
                        app.setConfigs(configs);
                    } else if ("components".equals(property.toLowerCase())) {
                        try {
                            ClusterDescription description = sliderClient
                                    .getClusterDescription(yarnApp.getName());
                            if (description != null && description.status != null
                                    && !description.status.isEmpty()) {
                                Map<String, SliderAppComponent> componentTypeMap = new HashMap<String, SliderAppComponent>();
                                for (Entry<String, Object> e : description.status.entrySet()) {
                                    @SuppressWarnings("unchecked")
                                    Map<String, Map<String, Map<String, Object>>> componentsObj = (Map<String, Map<String, Map<String, Object>>>) e
                                            .getValue();
                                    boolean isLive = "live".equals(e.getKey());
                                    for (Entry<String, Map<String, Map<String, Object>>> componentEntry : componentsObj
                                            .entrySet()) {
                                        SliderAppComponent appComponent = componentTypeMap
                                                .get(componentEntry.getKey());
                                        if (appComponent == null) {
                                            appComponent = new SliderAppComponent();
                                            appComponent.setComponentName(componentEntry.getKey());
                                            appComponent.setActiveContainers(
                                                    new HashMap<String, Map<String, String>>());
                                            appComponent.setCompletedContainers(
                                                    new HashMap<String, Map<String, String>>());
                                            componentTypeMap.put(componentEntry.getKey(), appComponent);
                                        }
                                        for (Entry<String, Map<String, Object>> containerEntry : componentEntry
                                                .getValue().entrySet()) {
                                            Map<String, String> containerDataMap = new HashMap<String, String>();
                                            String containerId = containerEntry.getKey();
                                            Map<String, Object> containerValues = containerEntry.getValue();
                                            for (String containerProperty : containerValues.keySet()) {
                                                Object containerPropertyValue = containerValues
                                                        .get(containerProperty);
                                                containerDataMap.put(containerProperty,
                                                        containerPropertyValue.toString());
                                            }
                                            if (isLive) {
                                                appComponent.getActiveContainers().put(containerId,
                                                        containerDataMap);
                                            } else {
                                                appComponent.getCompletedContainers().put(containerId,
                                                        containerDataMap);
                                            }
                                        }
                                        // Set total instances count from statistics
                                        appComponent.setInstanceCount(appComponent.getActiveContainers().size()
                                                + appComponent.getCompletedContainers().size());
                                        if (description.statistics != null && description.statistics
                                                .containsKey(componentEntry.getKey())) {
                                            Map<String, Integer> statisticsMap = description.statistics
                                                    .get(componentEntry.getKey());
                                            if (statisticsMap.containsKey("containers.desired")) {
                                                appComponent.setInstanceCount(
                                                        statisticsMap.get("containers.desired"));
                                            }
                                        }
                                    }
                                }
                                app.setAlerts(
                                        sliderAlerts.generateComponentsAlerts(componentTypeMap, app.getType()));
                                app.setComponents(componentTypeMap);
                            }
                        } catch (UnknownApplicationInstanceException e) {
                            logger.warn("Unable to determine app components for " + yarnApp.getName(), e);
                        } catch (YarnException e) {
                            logger.warn("Unable to determine app components for " + yarnApp.getName(), e);
                            throw new RuntimeException(e.getMessage(), e);
                        } catch (IOException e) {
                            logger.warn("Unable to determine app components for " + yarnApp.getName(), e);
                            throw new RuntimeException(e.getMessage(), e);
                        }
                    } else if (property.startsWith(METRICS_PREFIX)) {
                        metrics.add(property.substring(METRICS_PREFIX.length()));
                    } else if ("supportedMetrics".equals(property)) {
                        if (matchedAppType != null) {
                            app.setSupportedMetrics(matchedAppType.getSupportedMetrics());
                        }
                    }
                }
            }
        }
        if (metrics.size() > 0) {
            if (quickLinks.isEmpty()) {
                quickLinks = sliderAppClient.getQuickLinks(appMasterData.publisherUrl);
            }
            if (quickLinks != null && quickLinks.containsKey(METRICS_API_NAME)) {
                String metricsUrl = quickLinks.get(METRICS_API_NAME);
                MetricsHolder metricsHolder = appMetrics.get(matchedAppType.uniqueName());
                app.setMetrics(sliderAppClient.getMetrics(yarnApp.getName(), metricsUrl, metrics, null,
                        viewContext, matchedAppType, metricsHolder));
            }
        }
    }
    return app;
}

From source file:org.apache.flink.yarn.YARNSessionCapacitySchedulerITCase.java

License:Apache License

/**
 * Test TaskManager failure and also if the vcores are set correctly (see issue FLINK-2213).
 *//*from w  w  w . jav a 2s. c  o  m*/
@Test(timeout = 100000) // timeout after 100 seconds
public void testTaskManagerFailure() {
    LOG.info("Starting testTaskManagerFailure()");
    Runner runner = startWithArgs(
            new String[] { "-j", flinkUberjar.getAbsolutePath(), "-t", flinkLibFolder.getAbsolutePath(), "-n",
                    "1", "-jm", "768", "-tm", "1024", "-s", "3", // set the slots 3 to check if the vCores are set properly!
                    "-nm", "customName", "-Dfancy-configuration-value=veryFancy",
                    "-Dyarn.maximum-failed-containers=3", "-D" + ConfigConstants.YARN_VCORES + "=2" },
            "Number of connected TaskManagers changed to 1. Slots available: 3", RunTypes.YARN_SESSION);

    Assert.assertEquals(2, getRunningContainers());

    // ------------------------ Test if JobManager web interface is accessible -------

    YarnClient yc = null;
    try {
        yc = YarnClient.createYarnClient();
        yc.init(yarnConfiguration);
        yc.start();

        List<ApplicationReport> apps = yc.getApplications(EnumSet.of(YarnApplicationState.RUNNING));
        Assert.assertEquals(1, apps.size()); // Only one running
        ApplicationReport app = apps.get(0);
        Assert.assertEquals("customName", app.getName());
        String url = app.getTrackingUrl();
        if (!url.endsWith("/")) {
            url += "/";
        }
        if (!url.startsWith("http://")) {
            url = "http://" + url;
        }
        LOG.info("Got application URL from YARN {}", url);

        String response = TestBaseUtils.getFromHTTP(url + "taskmanagers/");

        JsonNode parsedTMs = new ObjectMapper().readTree(response);
        ArrayNode taskManagers = (ArrayNode) parsedTMs.get("taskmanagers");
        Assert.assertNotNull(taskManagers);
        Assert.assertEquals(1, taskManagers.size());
        Assert.assertEquals(3, taskManagers.get(0).get("slotsNumber").asInt());

        // get the configuration from webinterface & check if the dynamic properties from YARN show up there.
        String jsonConfig = TestBaseUtils.getFromHTTP(url + "jobmanager/config");
        Map<String, String> parsedConfig = WebMonitorUtils.fromKeyValueJsonArray(jsonConfig);

        Assert.assertEquals("veryFancy", parsedConfig.get("fancy-configuration-value"));
        Assert.assertEquals("3", parsedConfig.get("yarn.maximum-failed-containers"));
        Assert.assertEquals("2", parsedConfig.get(ConfigConstants.YARN_VCORES));

        // -------------- FLINK-1902: check if jobmanager hostname/port are shown in web interface
        // first, get the hostname/port
        String oC = outContent.toString();
        Pattern p = Pattern.compile("Flink JobManager is now running on ([a-zA-Z0-9.-]+):([0-9]+)");
        Matcher matches = p.matcher(oC);
        String hostname = null;
        String port = null;
        while (matches.find()) {
            hostname = matches.group(1).toLowerCase();
            port = matches.group(2);
        }
        LOG.info("Extracted hostname:port: {} {}", hostname, port);

        Assert.assertEquals("unable to find hostname in " + jsonConfig, hostname,
                parsedConfig.get(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY));
        Assert.assertEquals("unable to find port in " + jsonConfig, port,
                parsedConfig.get(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY));

        // test logfile access
        String logs = TestBaseUtils.getFromHTTP(url + "jobmanager/log");
        Assert.assertTrue(logs.contains("Starting YARN ApplicationMaster"));
        Assert.assertTrue(logs.contains("Starting JobManager"));
        Assert.assertTrue(logs.contains("Starting JobManager Web Frontend"));
    } catch (Throwable e) {
        LOG.warn("Error while running test", e);
        Assert.fail(e.getMessage());
    }

    // ------------------------ Kill container with TaskManager and check if vcores are set correctly -------

    // find container id of taskManager:
    ContainerId taskManagerContainer = null;
    NodeManager nodeManager = null;
    UserGroupInformation remoteUgi = null;
    NMTokenIdentifier nmIdent = null;
    try {
        remoteUgi = UserGroupInformation.getCurrentUser();
    } catch (IOException e) {
        LOG.warn("Unable to get curr user", e);
        Assert.fail();
    }
    for (int nmId = 0; nmId < NUM_NODEMANAGERS; nmId++) {
        NodeManager nm = yarnCluster.getNodeManager(nmId);
        ConcurrentMap<ContainerId, Container> containers = nm.getNMContext().getContainers();
        for (Map.Entry<ContainerId, Container> entry : containers.entrySet()) {
            String command = Joiner.on(" ").join(entry.getValue().getLaunchContext().getCommands());
            if (command.contains(YarnTaskManager.class.getSimpleName())) {
                taskManagerContainer = entry.getKey();
                nodeManager = nm;
                nmIdent = new NMTokenIdentifier(taskManagerContainer.getApplicationAttemptId(), null, "", 0);
                // allow myself to do stuff with the container
                // remoteUgi.addCredentials(entry.getValue().getCredentials());
                remoteUgi.addTokenIdentifier(nmIdent);
            }
        }
        sleep(500);
    }

    Assert.assertNotNull("Unable to find container with TaskManager", taskManagerContainer);
    Assert.assertNotNull("Illegal state", nodeManager);

    try {
        List<NodeReport> nodeReports = yc.getNodeReports(NodeState.RUNNING);

        // we asked for one node with 2 vcores so we expect 2 vcores
        int userVcores = 0;
        for (NodeReport rep : nodeReports) {
            userVcores += rep.getUsed().getVirtualCores();
        }
        Assert.assertEquals(2, userVcores);
    } catch (Exception e) {
        Assert.fail("Test failed: " + e.getMessage());
    }

    yc.stop();

    List<ContainerId> toStop = new LinkedList<ContainerId>();
    toStop.add(taskManagerContainer);
    StopContainersRequest scr = StopContainersRequest.newInstance(toStop);

    try {
        nodeManager.getNMContext().getContainerManager().stopContainers(scr);
    } catch (Throwable e) {
        LOG.warn("Error stopping container", e);
        Assert.fail("Error stopping container: " + e.getMessage());
    }

    // stateful termination check:
    // wait until we saw a container being killed and AFTERWARDS a new one launched
    boolean ok = false;
    do {
        LOG.debug("Waiting for correct order of events. Output: {}", errContent.toString());

        String o = errContent.toString();
        int killedOff = o.indexOf("Container killed by the ApplicationMaster");
        if (killedOff != -1) {
            o = o.substring(killedOff);
            ok = o.indexOf("Launching TaskManager") > 0;
        }
        sleep(1000);
    } while (!ok);

    // send "stop" command to command line interface
    runner.sendStop();
    // wait for the thread to stop
    try {
        runner.join(1000);
    } catch (InterruptedException e) {
        LOG.warn("Interrupted while stopping runner", e);
    }
    LOG.warn("stopped");

    // ----------- Send output to logger
    System.setOut(originalStdout);
    System.setErr(originalStderr);
    String oC = outContent.toString();
    String eC = errContent.toString();
    LOG.info("Sending stdout content through logger: \n\n{}\n\n", oC);
    LOG.info("Sending stderr content through logger: \n\n{}\n\n", eC);

    // ------ Check if everything happened correctly
    Assert.assertTrue("Expect to see failed container", eC.contains("New messages from the YARN cluster"));

    Assert.assertTrue("Expect to see failed container",
            eC.contains("Container killed by the ApplicationMaster"));

    Assert.assertTrue("Expect to see new container started",
            eC.contains("Launching TaskManager") && eC.contains("on host"));

    // cleanup auth for the subsequent tests.
    remoteUgi.getTokenIdentifiers().remove(nmIdent);

    LOG.info("Finished testTaskManagerFailure()");
}

From source file:org.apache.flink.yarn.YARNSessionFIFOITCase.java

License:Apache License

/**
 * Test regular operation, including command line parameter parsing.
 *//*from w  w w.  j  a  v  a2s  . c  om*/
@Test(timeout = 60000) // timeout after a minute.
public void testDetachedMode() {
    LOG.info("Starting testDetachedMode()");
    addTestAppender(FlinkYarnSessionCli.class, Level.INFO);
    Runner runner = startWithArgs(new String[] { "-j", flinkUberjar.getAbsolutePath(), "-t",
            flinkLibFolder.getAbsolutePath(), "-n", "1", "-jm", "768", "-tm", "1024", "--name", "MyCustomName", // test setting a custom name
            "--detached" }, "Flink JobManager is now running on", RunTypes.YARN_SESSION);

    checkForLogString("The Flink YARN client has been started in detached mode");

    Assert.assertFalse("The runner should detach.", runner.isAlive());

    LOG.info("Waiting until two containers are running");
    // wait until two containers are running
    while (getRunningContainers() < 2) {
        sleep(500);
    }
    LOG.info("Two containers are running. Killing the application");

    // kill application "externally".
    try {
        YarnClient yc = YarnClient.createYarnClient();
        yc.init(yarnConfiguration);
        yc.start();
        List<ApplicationReport> apps = yc.getApplications(EnumSet.of(YarnApplicationState.RUNNING));
        Assert.assertEquals(1, apps.size()); // Only one running
        ApplicationReport app = apps.get(0);

        Assert.assertEquals("MyCustomName", app.getName());
        ApplicationId id = app.getApplicationId();
        yc.killApplication(id);

        while (yc.getApplications(EnumSet.of(YarnApplicationState.KILLED)).size() == 0) {
            sleep(500);
        }
    } catch (Throwable t) {
        LOG.warn("Killing failed", t);
        Assert.fail();
    }

    LOG.info("Finished testDetachedMode()");
}

From source file:org.apache.gobblin.yarn.GobblinYarnAppLauncher.java

License:Apache License

/**
 * Setup and submit the Gobblin Yarn application.
 *
 * @throws IOException if there's anything wrong setting up and submitting the Yarn application
 * @throws YarnException if there's anything wrong setting up and submitting the Yarn application
 *///from  ww  w .  j a  v a 2s .c  om
@VisibleForTesting
ApplicationId setupAndSubmitApplication() throws IOException, YarnException {
    YarnClientApplication gobblinYarnApp = this.yarnClient.createApplication();
    ApplicationSubmissionContext appSubmissionContext = gobblinYarnApp.getApplicationSubmissionContext();
    appSubmissionContext.setApplicationType(GOBBLIN_YARN_APPLICATION_TYPE);
    ApplicationId applicationId = appSubmissionContext.getApplicationId();

    GetNewApplicationResponse newApplicationResponse = gobblinYarnApp.getNewApplicationResponse();
    // Set up resource type requirements for ApplicationMaster
    Resource resource = prepareContainerResource(newApplicationResponse);

    // Add lib jars, and jars and files that the ApplicationMaster need as LocalResources
    Map<String, LocalResource> appMasterLocalResources = addAppMasterLocalResources(applicationId);

    ContainerLaunchContext amContainerLaunchContext = Records.newRecord(ContainerLaunchContext.class);
    amContainerLaunchContext.setLocalResources(appMasterLocalResources);
    amContainerLaunchContext.setEnvironment(YarnHelixUtils.getEnvironmentVariables(this.yarnConfiguration));
    amContainerLaunchContext
            .setCommands(Lists.newArrayList(buildApplicationMasterCommand(resource.getMemory())));

    Map<ApplicationAccessType, String> acls = new HashMap<>(1);
    acls.put(ApplicationAccessType.VIEW_APP, this.appViewAcl);
    amContainerLaunchContext.setApplicationACLs(acls);

    if (UserGroupInformation.isSecurityEnabled()) {
        setupSecurityTokens(amContainerLaunchContext);
    }

    // Setup the application submission context
    appSubmissionContext.setApplicationName(this.applicationName);
    appSubmissionContext.setResource(resource);
    appSubmissionContext.setQueue(this.appQueueName);
    appSubmissionContext.setPriority(Priority.newInstance(0));
    appSubmissionContext.setAMContainerSpec(amContainerLaunchContext);
    // Also setup container local resources by copying local jars and files the container need to HDFS
    addContainerLocalResources(applicationId);

    // Submit the application
    LOGGER.info("Submitting application " + applicationId);
    this.yarnClient.submitApplication(appSubmissionContext);

    LOGGER.info("Application successfully submitted and accepted");
    ApplicationReport applicationReport = this.yarnClient.getApplicationReport(applicationId);
    LOGGER.info("Application Name: " + applicationReport.getName());
    LOGGER.info("Application Tracking URL: " + applicationReport.getTrackingUrl());
    LOGGER.info("Application User: " + applicationReport.getUser() + " Queue: " + applicationReport.getQueue());

    return applicationId;
}

From source file:org.apache.hoya.tools.HoyaUtils.java

License:Apache License

public static String appReportToString(ApplicationReport r, String separator) {
    StringBuilder builder = new StringBuilder(512);
    builder.append("application ").append(r.getName()).append("/").append(r.getApplicationType());
    builder.append(separator).append("state: ").append(r.getYarnApplicationState());
    builder.append(separator).append("URL: ").append(r.getTrackingUrl());
    builder.append(separator).append("Started ").append(new Date(r.getStartTime()).toGMTString());
    long finishTime = r.getFinishTime();
    if (finishTime > 0) {
        builder.append(separator).append("Finished ").append(new Date(finishTime).toGMTString());
    }/*from  ww  w  . j av  a 2s  .  com*/
    builder.append(separator).append("RPC :").append(r.getHost()).append(':').append(r.getRpcPort());
    String diagnostics = r.getDiagnostics();
    if (!diagnostics.isEmpty()) {
        builder.append(separator).append("Diagnostics :").append(diagnostics);
    }
    return builder.toString();
}

From source file:org.apache.hoya.tools.HoyaUtils.java

License:Apache License

/**
 * convert an AM report to a string for diagnostics
 * @param report the report//  w  w  w.  ja  va  2  s.  c om
 * @return the string value
 */
public static String reportToString(ApplicationReport report) {
    if (report == null) {
        return "Null application report";
    }

    return "App " + report.getName() + "/" + report.getApplicationType() + "# " + report.getApplicationId()
            + " user " + report.getUser() + " is in state " + report.getYarnApplicationState() + "RPC: "
            + report.getHost() + ":" + report.getRpcPort();
}

From source file:org.apache.hoya.yarn.appmaster.rpc.RpcBinder.java

License:Apache License

public static HoyaClusterProtocol getProxy(final Configuration conf, ApplicationReport application,
        final int rpcTimeout) throws IOException, HoyaException, InterruptedException {

    String host = application.getHost();
    int port = application.getRpcPort();
    String address = host + ":" + port;
    if (host == null || 0 == port) {
        throw new HoyaException(HoyaExitCodes.EXIT_CONNECTIVITY_PROBLEM,
                "Hoya YARN instance " + application.getName() + " isn't providing a valid address for the"
                        + " Hoya RPC protocol: " + address);
    }// w ww.j a v a 2 s. c om

    UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
    final UserGroupInformation newUgi = UserGroupInformation.createRemoteUser(currentUser.getUserName());
    final InetSocketAddress serviceAddr = NetUtils.createSocketAddrForHost(application.getHost(),
            application.getRpcPort());
    HoyaClusterProtocol realProxy;

    log.debug("Connecting to {}", serviceAddr);
    if (UserGroupInformation.isSecurityEnabled()) {
        org.apache.hadoop.yarn.api.records.Token clientToAMToken = application.getClientToAMToken();
        Token<ClientToAMTokenIdentifier> token = ConverterUtils.convertFromYarn(clientToAMToken, serviceAddr);
        newUgi.addToken(token);
        realProxy = newUgi.doAs(new PrivilegedExceptionAction<HoyaClusterProtocol>() {
            @Override
            public HoyaClusterProtocol run() throws IOException {
                return connectToServer(serviceAddr, newUgi, conf, rpcTimeout);
            }
        });
    } else {
        return connectToServer(serviceAddr, newUgi, conf, rpcTimeout);
    }
    return realProxy;
}

From source file:org.apache.hoya.yarn.client.HoyaYarnClientImpl.java

License:Apache License

/**
 * find all instances of a specific app -if there is >1 in the cluster,
 * this returns them all/*  w  ww  .  j  a v a 2  s .c  om*/
 * @param user user
 * @param appname application name
 * @return the list of all matching application instances
 */
@VisibleForTesting
public List<ApplicationReport> findAllInstances(String user, String appname) throws IOException, YarnException {
    List<ApplicationReport> instances = listInstances(user);
    List<ApplicationReport> results = new ArrayList<ApplicationReport>(instances.size());
    for (ApplicationReport report : instances) {
        if (report.getName().equals(appname)) {
            results.add(report);
        }
    }
    return results;
}

From source file:org.apache.hoya.yarn.client.HoyaYarnClientImpl.java

License:Apache License

/**
 * find all live instances of a specific app -if there is >1 in the cluster,
 * this returns them all. State should be running or less
 * @param user user//  ww w .  ja va  2 s  .  c  o m
 * @param appname application name
 * @return the list of all matching application instances
 */
public List<ApplicationReport> findAllLiveInstances(String user, String appname)
        throws YarnException, IOException {
    List<ApplicationReport> instances = listInstances(user);
    List<ApplicationReport> results = new ArrayList<ApplicationReport>(instances.size());
    for (ApplicationReport app : instances) {
        if (app.getName().equals(appname) && isApplicationLive(app)) {
            results.add(app);
        }
    }
    return results;
}