Search in sources :

Example 1 with ServiceException

use of org.apache.oozie.service.ServiceException in project oozie by apache.

the class TestMemoryLocks method testLockReentrant.

public void testLockReentrant() throws ServiceException, InterruptedException {
    final String path = UUID.randomUUID().toString();
    MemoryLocksService lockService = new MemoryLocksService();
    try {
        lockService.init(Services.get());
        LockToken lock = lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
        lock = (LockToken) lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
        lock = (LockToken) lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
        assertEquals(lockService.getMemoryLocks().size(), 1);
        lock.release();
        assertEquals(lockService.getMemoryLocks().size(), 1);
        lock.release();
        assertEquals(lockService.getMemoryLocks().size(), 1);
        lock.release();
        checkLockRelease(path, lockService);
    } catch (Exception e) {
        fail("Reentrant property, it should have acquired lock");
    } finally {
        lockService.destroy();
    }
}
Also used : ServiceException(org.apache.oozie.service.ServiceException) MemoryLocksService(org.apache.oozie.service.MemoryLocksService)

Example 2 with ServiceException

use of org.apache.oozie.service.ServiceException in project oozie by apache.

the class SLACalculatorMemory method addJobStatus.

/**
 * Triggered after receiving Job status change event, update SLA status
 * accordingly
 */
@Override
public boolean addJobStatus(String jobId, String jobStatus, JobEvent.EventStatus jobEventStatus, Date startTime, Date endTime) throws JPAExecutorException, ServiceException {
    LOG.debug("Received addJobStatus request for job  [{0}] jobStatus = [{1}], jobEventStatus = [{2}], startTime = [{3}], " + "endTime = [{4}] ", jobId, jobStatus, jobEventStatus, startTime, endTime);
    SLACalcStatus slaCalc = slaMap.get(jobId);
    boolean firstCheckAfterRetstart = checkAndUpdateSLACalcAfterRestart(slaCalc);
    if (slaCalc == null) {
        SLARegistrationBean slaRegBean = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, jobId);
        if (slaRegBean != null) {
            // filter out jobs picked by SLA job event listener
            // but not actually configured for SLA
            SLASummaryBean slaSummaryBean = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
            slaCalc = new SLACalcStatus(slaSummaryBean, slaRegBean);
            putAndIncrement(jobId, slaCalc);
        }
    } else {
        SLASummaryBean summaryBean = ((SLASummaryQueryExecutor) SLASummaryQueryExecutor.getInstance()).get(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED_LAST_MODIFIED, jobId);
        byte eventProc = summaryBean.getEventProcessed();
        if (!slaCalc.getLastModifiedTime().equals(summaryBean.getLastModifiedTime())) {
            // Update last modified time.
            slaCalc.setLastModifiedTime(summaryBean.getLastModifiedTime());
            reloadExpectedTimeAndConfig(slaCalc);
            LOG.debug("Last modified time has changed for job " + jobId + " reloading config from DB");
        }
        slaCalc.setEventProcessed(eventProc);
    }
    if (slaCalc != null) {
        try {
            SLAXCommandFactory.getSLAEventXCommand(slaCalc, ConfigurationService.getLong(SLAService.CONF_SLA_CALC_LOCK_TIMEOUT, 20 * 1000)).call();
            checkEventProc(slaCalc);
        } catch (XException e) {
            if (firstCheckAfterRetstart) {
                slaCalc.setSLARegistrationBean(null);
            }
            LOG.error(e);
            throw new ServiceException(e);
        }
        return true;
    } else {
        return false;
    }
}
Also used : ServiceException(org.apache.oozie.service.ServiceException) XException(org.apache.oozie.XException) SLASummaryQueryExecutor(org.apache.oozie.executor.jpa.SLASummaryQueryExecutor)

Example 3 with ServiceException

use of org.apache.oozie.service.ServiceException in project oozie by apache.

the class SLAOperations method createSlaRegistrationEvent.

public static SLARegistrationBean createSlaRegistrationEvent(Element eSla, String jobId, String parentId, AppType appType, String user, String appName, XLog log, boolean rerun, boolean disableAlert) throws CommandException {
    if (eSla == null || !SLAService.isEnabled()) {
        log.debug("Not registering SLA for job [{0}]. Sla-Xml null OR SLAService not enabled", jobId);
        return null;
    }
    SLARegistrationBean sla = new SLARegistrationBean();
    // Setting nominal time
    String strNominalTime = getTagElement(eSla, NOMINAL_TIME);
    Date nominalTime = setNominalTime(strNominalTime, sla);
    // Setting expected start time
    String strExpectedStart = getTagElement(eSla, SHOULD_START);
    setExpectedStart(strExpectedStart, nominalTime, sla);
    // Setting expected end time
    String strExpectedEnd = getTagElement(eSla, SHOULD_END);
    setExpectedEnd(strExpectedEnd, nominalTime, sla);
    // Setting expected duration in milliseconds
    String expectedDurationStr = getTagElement(eSla, MAX_DURATION);
    setExpectedDuration(expectedDurationStr, sla);
    // Parse desired alert-types i.e. start-miss, end-miss, start-met etc..
    String alertEvents = getTagElement(eSla, ALERT_EVENTS);
    if (alertEvents != null) {
        String[] events = alertEvents.split(",");
        StringBuilder alertsStr = new StringBuilder();
        for (int i = 0; i < events.length; i++) {
            String event = events[i].trim().toUpperCase();
            try {
                EventStatus.valueOf(event);
            } catch (IllegalArgumentException iae) {
                XLog.getLog(SLAService.class).warn("Invalid value: [" + event + "]" + " for SLA Alert-event. Should be one of " + EventStatus.values() + ". Setting it to default [" + EventStatus.END_MISS.name() + "]");
                event = EventStatus.END_MISS.name();
            }
            alertsStr.append(event).append(",");
        }
        sla.setAlertEvents(alertsStr.toString().substring(0, alertsStr.lastIndexOf(",")));
    }
    // Other sla config
    sla.setNotificationMsg(getTagElement(eSla, "notification-msg"));
    sla.setAlertContact(getTagElement(eSla, "alert-contact"));
    sla.setUpstreamApps(getTagElement(eSla, "upstream-apps"));
    // disable Alert flag in slaConfig
    if (disableAlert) {
        sla.addToSLAConfigMap(OozieClient.SLA_DISABLE_ALERT, Boolean.toString(disableAlert));
    }
    // Oozie defined
    sla.setId(jobId);
    sla.setAppType(appType);
    sla.setAppName(appName);
    sla.setUser(user);
    sla.setParentId(parentId);
    SLAService slaService = Services.get().get(SLAService.class);
    try {
        if (!rerun) {
            slaService.addRegistrationEvent(sla);
        } else {
            slaService.updateRegistrationEvent(sla);
        }
    } catch (ServiceException e) {
        throw new CommandException(ErrorCode.E1007, " id " + jobId, e.getMessage(), e);
    }
    log.debug("Job [{0}] reg for SLA. Size of Sla Xml = [{1}]", jobId, XmlUtils.prettyPrint(eSla).toString().length());
    return sla;
}
Also used : SLAService(org.apache.oozie.sla.service.SLAService) ServiceException(org.apache.oozie.service.ServiceException) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date)

Example 4 with ServiceException

use of org.apache.oozie.service.ServiceException in project oozie by apache.

the class SLAService method init.

@Override
public void init(Services services) throws ServiceException {
    try {
        Configuration conf = services.getConf();
        Class<? extends SLACalculator> calcClazz = (Class<? extends SLACalculator>) ConfigurationService.getClass(conf, CONF_CALCULATOR_IMPL);
        calcImpl = calcClazz == null ? new SLACalculatorMemory() : (SLACalculator) calcClazz.newInstance();
        calcImpl.init(conf);
        eventHandler = Services.get().get(EventHandlerService.class);
        if (eventHandler == null) {
            throw new ServiceException(ErrorCode.E0103, "EventHandlerService", "Add it under config " + Services.CONF_SERVICE_EXT_CLASSES + " or declare it BEFORE SLAService");
        }
        LOG = XLog.getLog(getClass());
        java.util.Set<String> appTypes = eventHandler.getAppTypes();
        appTypes.add("workflow_action");
        eventHandler.setAppTypes(appTypes);
        Runnable slaThread = new SLAWorker(calcImpl);
        // schedule runnable by default every 30 sec
        int slaCheckInterval = ConfigurationService.getInt(conf, CONF_SLA_CHECK_INTERVAL);
        int slaCheckInitialDelay = ConfigurationService.getInt(conf, CONF_SLA_CHECK_INITIAL_DELAY);
        services.get(SchedulerService.class).schedule(slaThread, slaCheckInitialDelay, slaCheckInterval, SchedulerService.Unit.SEC);
        slaEnabled = true;
        LOG.info("SLAService initialized with impl [{0}] capacity [{1}]", calcImpl.getClass().getName(), conf.get(SLAService.CONF_CAPACITY));
    } catch (Exception ex) {
        throw new ServiceException(ErrorCode.E0102, ex.getMessage(), ex);
    }
}
Also used : SchedulerService(org.apache.oozie.service.SchedulerService) Configuration(org.apache.hadoop.conf.Configuration) SLACalculatorMemory(org.apache.oozie.sla.SLACalculatorMemory) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ServiceException(org.apache.oozie.service.ServiceException) EventHandlerService(org.apache.oozie.service.EventHandlerService) SLACalculator(org.apache.oozie.sla.SLACalculator) ServiceException(org.apache.oozie.service.ServiceException)

Example 5 with ServiceException

use of org.apache.oozie.service.ServiceException in project oozie by apache.

the class CoordSLAChangeXCommand method executeSlaCommand.

@Override
protected boolean executeSlaCommand() throws ServiceException, CommandException {
    try {
        List<Pair<String, Map<String, String>>> idSlaDefinitionList = new ArrayList<Pair<String, Map<String, String>>>();
        List<CoordinatorActionBean> coordinatorActionBeanList = getNotTerminatedActions();
        Configuration conf = getJobConf();
        for (CoordinatorActionBean coordAction : coordinatorActionBeanList) {
            Map<String, String> slaDefinitionMap = new HashMap<String, String>(newParams);
            for (String key : slaDefinitionMap.keySet()) {
                Element eAction = XmlUtils.parseXml(coordAction.getActionXml().toString());
                ELEvaluator evalSla = CoordELEvaluator.createSLAEvaluator(eAction, coordAction, conf);
                String updateValue = CoordELFunctions.evalAndWrap(evalSla, slaDefinitionMap.get(key));
                slaDefinitionMap.put(key, updateValue);
            }
            idSlaDefinitionList.add(new Pair<String, Map<String, String>>(coordAction.getId(), slaDefinitionMap));
        }
        return Services.get().get(SLAService.class).changeDefinition(idSlaDefinitionList);
    } catch (Exception e) {
        throw new CommandException(ErrorCode.E1027, e.getMessage(), e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SLAService(org.apache.oozie.sla.service.SLAService) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) Element(org.jdom.Element) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ServiceException(org.apache.oozie.service.ServiceException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.oozie.util.Pair)

Aggregations

ServiceException (org.apache.oozie.service.ServiceException)9 Date (java.util.Date)3 CommandException (org.apache.oozie.command.CommandException)3 SLAService (org.apache.oozie.sla.service.SLAService)3 Configuration (org.apache.hadoop.conf.Configuration)2 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)2 Services (org.apache.oozie.service.Services)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 XException (org.apache.oozie.XException)1 PreconditionException (org.apache.oozie.command.PreconditionException)1 CoordELEvaluator (org.apache.oozie.coord.CoordELEvaluator)1 SLASummaryQueryExecutor (org.apache.oozie.executor.jpa.SLASummaryQueryExecutor)1 EventHandlerService (org.apache.oozie.service.EventHandlerService)1 HadoopAccessorService (org.apache.oozie.service.HadoopAccessorService)1 MemoryLocksService (org.apache.oozie.service.MemoryLocksService)1 SchedulerService (org.apache.oozie.service.SchedulerService)1 SLACalculator (org.apache.oozie.sla.SLACalculator)1