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());
}
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;
}
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);
}
}
}
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);
}
}
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;
}
Aggregations