Example usage for org.apache.hadoop.service ServiceStateException convert

List of usage examples for org.apache.hadoop.service ServiceStateException convert

Introduction

In this page you can find the example usage for org.apache.hadoop.service ServiceStateException convert.

Prototype

public static RuntimeException convert(Throwable fault) 

Source Link

Document

Convert any exception into a RuntimeException .

Usage

From source file:MRAppMaster.CompositeService.java

License:Apache License

/**
 * Stop the services in reverse order/*from   w  w w .j  a va2  s.  c  om*/
 *
 * @param numOfServicesStarted index from where the stop should work
 * @param stopOnlyStartedServices flag to say "only start services that are
 * started, not those that are NOTINITED or INITED.
 * @throws RuntimeException the first exception raised during the
 * stop process -<i>after all services are stopped</i>
 */
private void stop(int numOfServicesStarted, boolean stopOnlyStartedServices) {
    // stop in reverse order of start
    Exception firstException = null;
    List<Service> services = getServices();
    for (int i = numOfServicesStarted - 1; i >= 0; i--) {
        Service service = services.get(i);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stopping service #" + i + ": " + service);
        }
        STATE state = service.getServiceState();
        //depending on the stop police
        if (state == STATE.STARTED || (!stopOnlyStartedServices && state == STATE.INITED)) {
            Exception ex = ServiceOperations.stopQuietly(LOG, service);
            if (ex != null && firstException == null) {
                firstException = ex;
            }
        }
    }
    //after stopping all services, rethrow the first exception raised
    if (firstException != null) {
        throw ServiceStateException.convert(firstException);
    }
}

From source file:org.apache.tez.dag.app.DAGAppMaster.java

License:Apache License

void startServices() {
    try {/*from   www. ja  v  a2s. co  m*/
        Throwable firstError = null;
        List<ServiceThread> threads = new ArrayList<ServiceThread>();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Begin parallel start");
        }
        for (ServiceWithDependency sd : services.values()) {
            // start the service. If this fails that service
            // will be stopped and an exception raised
            ServiceThread st = new ServiceThread(sd);
            threads.add(st);
        }

        for (ServiceThread st : threads) {
            st.start();
        }
        for (ServiceThread st : threads) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Waiting for service thread to join for " + st.getName());
            }
            st.join();
            if (st.error != null && firstError == null) {
                firstError = st.error;
            }
        }

        if (firstError != null) {
            throw ServiceStateException.convert(firstError);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("End parallel start");
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.tez.dag.app.DAGAppMaster.java

License:Apache License

void stopServices() {
    // stop in reverse order of start
    List<Service> serviceList = new ArrayList<Service>(services.size());
    for (ServiceWithDependency sd : services.values()) {
        serviceList.add(sd.service);/* w w w.  j  av  a2 s . com*/
    }
    Exception firstException = null;
    for (int i = services.size() - 1; i >= 0; i--) {
        Service service = serviceList.get(i);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stopping service : " + service);
        }
        Exception ex = ServiceOperations.stopQuietly(LOG, service);
        if (ex != null && firstException == null) {
            LOG.warn("Failed to stop service, name=" + service.getName(), ex);
            firstException = ex;
        }
    }
    //after stopping all services, rethrow the first exception raised
    if (firstException != null) {
        throw ServiceStateException.convert(firstException);
    }
}