Search in sources :

Example 1 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class Services method init.

/**
 * Initialize all services define in the {@link #CONF_SERVICE_CLASSES} configuration property.
 *
 * @throws ServiceException thrown if any of the services could not initialize.
 */
public void init() throws ServiceException {
    XLog log = new XLog(LogFactory.getLog(getClass()));
    log.trace("Initializing");
    SERVICES = this;
    try {
        loadServices();
    } catch (RuntimeException rex) {
        XLog.getLog(getClass()).fatal(rex.getMessage(), rex);
        throw rex;
    } catch (ServiceException ex) {
        XLog.getLog(getClass()).fatal(ex.getMessage(), ex);
        SERVICES = null;
        throw ex;
    }
    InstrumentationService instrService = get(InstrumentationService.class);
    if (instrService != null) {
        Instrumentation instr = instrService.get();
        for (Service service : services.values()) {
            if (service instanceof Instrumentable) {
                ((Instrumentable) service).instrument(instr);
            }
        }
        instr.addVariable("oozie", "version", new Instrumentation.Variable<String>() {

            @Override
            public String getValue() {
                return BuildInfo.getBuildInfo().getProperty(BuildInfo.BUILD_VERSION);
            }
        });
        instr.addVariable("oozie", "mode", new Instrumentation.Variable<String>() {

            @Override
            public String getValue() {
                return getSystemMode().toString();
            }
        });
    }
    log.info("Initialized");
    log.info("Running with JARs for Hadoop version [{0}]", VersionInfo.getVersion());
    log.info("Oozie System ID [{0}] started!", getSystemId());
}
Also used : XLog(org.apache.oozie.util.XLog) Instrumentation(org.apache.oozie.util.Instrumentation) Instrumentable(org.apache.oozie.util.Instrumentable)

Example 2 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class Services method setSystemMode.

/**
 * Set and set system mode.
 *
 * @param sysMode system mode
 */
public synchronized void setSystemMode(SYSTEM_MODE sysMode) {
    if (this.systemMode != sysMode) {
        XLog log = XLog.getLog(getClass());
        log.info(XLog.OPS, "Exiting " + this.systemMode + " Entering " + sysMode);
    }
    this.systemMode = sysMode;
}
Also used : XLog(org.apache.oozie.util.XLog)

Example 3 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class Services method loadServices.

/**
 * Loads the specified services.
 *
 * @param classes services classes to load.
 * @param list    list of loaded service in order of appearance in the
 *                configuration.
 * @throws ServiceException thrown if a service class could not be loaded.
 */
private void loadServices(Class<?>[] classes, List<Service> list) throws ServiceException {
    XLog log = new XLog(LogFactory.getLog(getClass()));
    for (Class<?> klass : classes) {
        try {
            Service service = (Service) klass.newInstance();
            log.debug("Loading service [{0}] implementation [{1}]", service.getInterface(), service.getClass());
            if (!service.getInterface().isInstance(service)) {
                throw new ServiceException(ErrorCode.E0101, klass, service.getInterface().getName());
            }
            list.add(service);
        } catch (ServiceException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new ServiceException(ErrorCode.E0102, klass, ex.getMessage(), ex);
        }
    }
}
Also used : XLog(org.apache.oozie.util.XLog) IOException(java.io.IOException)

Example 4 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class Services method loadServices.

/**
 * Loads services defined in <code>services</code> and
 * <code>services.ext</code> and de-dups them.
 *
 * @return List of final services to initialize.
 * @throws ServiceException throw if the services could not be loaded.
 */
private void loadServices() throws ServiceException {
    XLog log = new XLog(LogFactory.getLog(getClass()));
    try {
        Map<Class<?>, Service> map = new LinkedHashMap<Class<?>, Service>();
        Class<?>[] classes = ConfigurationService.getClasses(conf, CONF_SERVICE_CLASSES);
        log.debug("Services list obtained from property '" + CONF_SERVICE_CLASSES + "'");
        Class<?>[] classesExt = ConfigurationService.getClasses(conf, CONF_SERVICE_EXT_CLASSES);
        log.debug("Services list obtained from property '" + CONF_SERVICE_EXT_CLASSES + "'");
        List<Service> list = new ArrayList<Service>();
        loadServices(classes, list);
        loadServices(classesExt, list);
        // removing duplicate services, strategy: last one wins
        for (Service service : list) {
            if (map.containsKey(service.getInterface())) {
                log.debug("Replacing service [{0}] implementation [{1}]", service.getInterface(), service.getClass());
            }
            map.put(service.getInterface(), service);
        }
        for (Map.Entry<Class<?>, Service> entry : map.entrySet()) {
            setService(entry.getValue().getClass());
        }
    } catch (RuntimeException rex) {
        log.fatal("Runtime Exception during Services Load. Check your list of [{0}] or [{1}]", CONF_SERVICE_CLASSES, CONF_SERVICE_EXT_CLASSES, rex);
        throw new ServiceException(ErrorCode.E0103, rex.getMessage(), rex);
    }
}
Also used : XLog(org.apache.oozie.util.XLog) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with XLog

use of org.apache.oozie.util.XLog in project oozie by apache.

the class Services method destroy.

/**
 * Destroy all services.
 */
public void destroy() {
    XLog log = new XLog(LogFactory.getLog(getClass()));
    log.trace("Shutting down");
    boolean deleteRuntimeDir = false;
    if (conf != null) {
        deleteRuntimeDir = conf.getBoolean(CONF_DELETE_RUNTIME_DIR, false);
    }
    if (services != null) {
        List<Service> list = new ArrayList<Service>(services.values());
        Collections.reverse(list);
        for (Service service : list) {
            try {
                log.trace("Destroying service[{0}]", service.getInterface());
                if (service.getInterface() == XLogService.class) {
                    log.info("Shutdown");
                }
                service.destroy();
            } catch (Throwable ex) {
                log.error("Error destroying service[{0}], {1}", service.getInterface(), ex.getMessage(), ex);
            }
        }
    }
    if (deleteRuntimeDir) {
        try {
            IOUtils.delete(new File(runtimeDir));
        } catch (IOException ex) {
            log.error("Error deleting runtime directory [{0}], {1}", runtimeDir, ex.getMessage(), ex);
        }
    }
    services = null;
    conf = null;
    SERVICES = null;
}
Also used : XLog(org.apache.oozie.util.XLog) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Aggregations

XLog (org.apache.oozie.util.XLog)21 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)5 URI (java.net.URI)4 URIHandlerService (org.apache.oozie.service.URIHandlerService)4 File (java.io.File)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Configuration (org.apache.hadoop.conf.Configuration)3 CommandException (org.apache.oozie.command.CommandException)3 URIHandler (org.apache.oozie.dependency.URIHandler)3 ELEvaluator (org.apache.oozie.util.ELEvaluator)3 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 Context (org.apache.oozie.dependency.URIHandler.Context)2 Instrumentation (org.apache.oozie.util.Instrumentation)2 WorkflowException (org.apache.oozie.workflow.WorkflowException)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 StringReader (java.io.StringReader)1