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:org.apache.hoya.yarn.client.HoyaYarnClientImpl.java

License:Apache License

public ApplicationReport findClusterInInstanceList(List<ApplicationReport> instances, String appname) {
    ApplicationReport found = null;/* www .  j a  v  a  2 s  .c o m*/
    ApplicationReport foundAndLive = null;
    for (ApplicationReport app : instances) {
        if (app.getName().equals(appname)) {
            found = app;
            if (isApplicationLive(app)) {
                foundAndLive = app;
            }
        }
    }
    if (foundAndLive != null) {
        found = foundAndLive;
    }
    return found;
}

From source file:org.apache.samza.validation.TestYarnJobValidationTool.java

License:Apache License

@Test
public void testValidateAppId() throws Exception {
    ApplicationReport appReport = mock(ApplicationReport.class);
    when(appReport.getName()).thenReturn(jobName + "_" + jobId);
    when(appReport.getApplicationId()).thenReturn(appId);
    when(client.getApplications()).thenReturn(Collections.singletonList(appReport));
    assertTrue(tool.validateAppId().equals(appId));

    when(appReport.getName()).thenReturn("dummy");
    exception.expect(SamzaException.class);
    tool.validateAppId();//from  ww w. j  a v  a  2 s. c o  m
}

From source file:org.apache.samza.validation.YarnJobValidationTool.java

License:Apache License

public ApplicationId validateAppId() throws Exception {
    // fetch only the last created application with the job name and id
    // i.e. get the application with max appId
    ApplicationId appId = null;/*from  ww w . java2s.  c  o m*/
    for (ApplicationReport applicationReport : this.client.getApplications()) {
        if (applicationReport.getName().equals(this.jobName)) {
            ApplicationId id = applicationReport.getApplicationId();
            if (appId == null || appId.compareTo(id) < 0) {
                appId = id;
            }
        }
    }
    if (appId != null) {
        log.info("Job lookup success. ApplicationId " + appId.toString());
        return appId;
    } else {
        throw new SamzaException("Job lookup failure " + this.jobName);
    }
}

From source file:org.apache.slider.client.SliderYarnClientImpl.java

License:Apache License

/**
 * Find a cluster in the instance list; biased towards live instances
 * @param instances list of instances//w  w  w. j av a  2 s  .  c  om
 * @param appname application name
 * @return the first found instance, else a failed/finished instance, or null
 * if there are none of those
 */
public ApplicationReport findClusterInInstanceList(List<ApplicationReport> instances, String appname) {
    // sort by most recent
    SliderUtils.sortApplicationsByMostRecent(instances);
    ApplicationReport found = null;
    for (ApplicationReport app : instances) {
        if (app.getName().equals(appname)) {
            if (isApplicationLive(app)) {
                return app;
            }
            // set the found value if not set
            found = found != null ? found : app;
        }
    }
    return found;
}

From source file:org.apache.slider.client.SliderYarnClientImpl.java

License:Apache License

/**
 * Find an app in the instance list in the desired state 
 * @param instances instance list// w  w  w  . j ava  2  s  .  co m
 * @param appname application name
 * @param desiredState yarn state desired
 * @return the match or null for none
 */
public ApplicationReport findAppInInstanceList(List<ApplicationReport> instances, String appname,
        YarnApplicationState desiredState) {
    ApplicationReport found = null;
    ApplicationReport foundAndLive = null;
    log.debug("Searching {} records for instance name {} in state '{}'", instances.size(), appname,
            desiredState);
    for (ApplicationReport app : instances) {
        if (app.getName().equals(appname)) {

            YarnApplicationState appstate = app.getYarnApplicationState();
            log.debug("app ID {} is in state {}", app.getApplicationId(), appstate);
            if (appstate.equals(desiredState)) {
                log.debug("match");
                return app;
            }
        }
    }
    // nothing found in desired state
    log.debug("No match");
    return null;
}

From source file:org.apache.slider.common.tools.SliderUtils.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())
            .append(separator);//from  w ww .  jav a 2  s  . c  o  m
    Set<String> tags = r.getApplicationTags();
    if (!tags.isEmpty()) {
        for (String tag : tags) {
            builder.append(tag).append(separator);
        }
    }
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
    dateFormat.setTimeZone(TimeZone.getDefault());
    builder.append("state: ").append(r.getYarnApplicationState());
    String trackingUrl = r.getTrackingUrl();
    if (isSet(trackingUrl)) {
        builder.append(separator).append("URL: ").append(trackingUrl);
    }
    builder.append(separator).append("Started: ").append(dateFormat.format(new Date(r.getStartTime())));
    long finishTime = r.getFinishTime();
    if (finishTime > 0) {
        builder.append(separator).append("Finished: ").append(dateFormat.format(new Date(finishTime)));
    }
    String rpcHost = r.getHost();
    if (!isSet(rpcHost)) {
        builder.append(separator).append("RPC :").append(rpcHost).append(':').append(r.getRpcPort());
    }
    String diagnostics = r.getDiagnostics();
    if (!isSet(diagnostics)) {
        builder.append(separator).append("Diagnostics :").append(diagnostics);
    }
    return builder.toString();
}

From source file:org.apache.slider.common.tools.SliderUtils.java

License:Apache License

/**
 * Built a (sorted) map of application reports, mapped to the instance name
 * The list is sorted, and the addition process does not add a report
 * if there is already one that exists. If the list handed in is sorted,
 * those that are listed first form the entries returned
 * @param instances list of intances/*from w  w  w.ja v  a 2 s .co m*/
 * @param minState minimum YARN state to be included
 * @param maxState maximum YARN state to be included
 * @return all reports in the list whose state &gt;= minimum and &lt;= maximum
 */
public static Map<String, ApplicationReport> buildApplicationReportMap(List<ApplicationReport> instances,
        YarnApplicationState minState, YarnApplicationState maxState) {
    TreeMap<String, ApplicationReport> map = new TreeMap<String, ApplicationReport>();
    for (ApplicationReport report : instances) {
        YarnApplicationState state = report.getYarnApplicationState();
        if (state.ordinal() >= minState.ordinal() && state.ordinal() <= maxState.ordinal()
                && map.get(report.getName()) == null) {
            map.put(report.getName(), report);
        }
    }
    return map;
}

From source file:org.apache.slider.common.tools.SliderUtils.java

License:Apache License

/**
 * convert an AM report to a string for diagnostics
 * @param report the report//  w w  w . ja  va 2 s  . co m
 * @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() + " URL" + report.getOriginalTrackingUrl();
}

From source file:org.apache.slider.core.launch.SerializedApplicationReport.java

License:Apache License

public SerializedApplicationReport(ApplicationReport report) {
    this.applicationId = report.getApplicationId().toString();
    this.applicationAttemptId = report.getCurrentApplicationAttemptId().toString();
    this.name = report.getName();
    this.applicationType = report.getApplicationType();
    this.user = report.getUser();
    this.queue = report.getQueue();
    this.host = report.getHost();
    this.rpcPort = report.getRpcPort();
    this.state = report.getYarnApplicationState().toString();
    this.diagnostics = report.getDiagnostics();
    this.startTime = report.getStartTime();
    this.finishTime = report.getFinishTime();
    this.finalStatus = report.getFinalApplicationStatus().toString();
    this.progress = report.getProgress();
}

From source file:org.apache.slider.server.appmaster.rpc.RpcBinder.java

License:Apache License

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

    String host = application.getHost();
    int port = application.getRpcPort();
    String address = host + ":" + port;
    if (host == null || 0 == port) {
        throw new SliderException(SliderExitCodes.EXIT_CONNECTIVITY_PROBLEM,
                "Slider instance " + application.getName() + " isn't providing a valid address for the"
                        + " Slider RPC protocol: " + address);
    }/*from  ww w . j a  va 2s. com*/

    UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
    final UserGroupInformation newUgi = UserGroupInformation.createRemoteUser(currentUser.getUserName());
    final InetSocketAddress serviceAddr = NetUtils.createSocketAddrForHost(application.getHost(),
            application.getRpcPort());
    SliderClusterProtocol 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<SliderClusterProtocol>() {
            @Override
            public SliderClusterProtocol run() throws IOException {
                return connectToServer(serviceAddr, newUgi, conf, rpcTimeout);
            }
        });
    } else {
        return connectToServer(serviceAddr, newUgi, conf, rpcTimeout);
    }
    return realProxy;
}