Examples of SLARegistrationBean


Examples of org.apache.oozie.sla.SLARegistrationBean

            AppType appType, String user, String appName, XLog log, boolean rerun) 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);
        if (strNominalTime == null || strNominalTime.length() == 0) {
            throw new CommandException(ErrorCode.E1101, NOMINAL_TIME);
        }
        Date nominalTime;
        try {
            nominalTime = DateUtils.parseDateOozieTZ(strNominalTime);
            sla.setNominalTime(nominalTime);
        }
        catch (ParseException pex) {
            throw new CommandException(ErrorCode.E0302, strNominalTime, pex);
        }

        // Setting expected start time
        String strExpectedStart = getTagElement(eSla, SHOULD_START);
        if (strExpectedStart != null) {
            float expectedStart = Float.parseFloat(strExpectedStart);
            if (expectedStart < 0) {
                throw new CommandException(ErrorCode.E0302, strExpectedStart, "for SLA Expected start time");
            }
            else {
                Date expectedStartTime = new Date(nominalTime.getTime() + (long) (expectedStart * 60 * 1000));
                sla.setExpectedStart(expectedStartTime);
            }
        }

        // Setting expected end time
        String strExpectedEnd = getTagElement(eSla, SHOULD_END);
        if (strExpectedEnd == null || strExpectedEnd.length() == 0) {
            throw new CommandException(ErrorCode.E1101, SHOULD_END);
        }
        float expectedEnd = Float.parseFloat(strExpectedEnd);
        if (expectedEnd < 0) {
            throw new CommandException(ErrorCode.E0302, strExpectedEnd, "for SLA Expected end time");
        }
        else {
            Date expectedEndTime = new Date(nominalTime.getTime() + (long) (expectedEnd * 60 * 1000));
            sla.setExpectedEnd(expectedEndTime);
        }

        // Setting expected duration in milliseconds
        String expectedDurationStr = getTagElement(eSla, MAX_DURATION);
        if (expectedDurationStr != null && expectedDurationStr.length() > 0) {
            float expectedDuration = Float.parseFloat(expectedDurationStr);
            if (expectedDuration > 0) {
                sla.setExpectedDuration((long) (expectedDuration * 60 * 1000));
            }
        }
        else if (sla.getExpectedStart() != null) {
            sla.setExpectedDuration(sla.getExpectedEnd().getTime() - sla.getExpectedStart().getTime());
        }

        // 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"));

        // 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);
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

     */
    public static void updateRegistrationEvent(String jobId) throws CommandException, JPAExecutorException {
        JPAService jpaService = Services.get().get(JPAService.class);
        SLAService slaService = Services.get().get(SLAService.class);
        try {
            SLARegistrationBean reg = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, jobId);
            if (reg != null) { //handle coord rerun with different config without sla
                slaService.updateRegistrationEvent(reg);
            }
        }
        catch (ServiceException e) {
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

        _addRecordToSLARegistrationTable(jobId, AppType.WORKFLOW_JOB, current, new Date(), "END_MISS",
                "alert@example.com");
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);

        SLARegistrationBean bean = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, jobId);
        assertEquals(jobId, bean.getId());
        assertEquals(AppType.WORKFLOW_JOB, bean.getAppType());
        assertEquals(current, bean.getExpectedStart());
        assertEquals(2, bean.getSlaConfigMap().size());
        assertEquals("END_MISS", bean.getAlertEvents());
        assertEquals("alert@example.com", bean.getAlertContact());
    }
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

        CoordinatorActionBean ca3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING,
                "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T03:00Z"));
        CoordinatorActionBean ca4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING,
                "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T04:00Z"));

        SLARegistrationBean slaRegBean1 = new SLARegistrationBean();
        slaRegBean1.setId(ca1.getId());
        SLARegistrationBean slaRegBean2 = new SLARegistrationBean();
        slaRegBean2.setId(ca2.getId());
        SLARegistrationBean slaRegBean3 = new SLARegistrationBean();
        slaRegBean3.setId(ca3.getId());
        SLARegistrationBean slaRegBean4 = new SLARegistrationBean();
        slaRegBean4.setId(ca4.getId());
        SLASummaryBean slaSummaryBean1 = new SLASummaryBean();
        slaSummaryBean1.setId(ca1.getId());
        SLASummaryBean slaSummaryBean3 = new SLASummaryBean();
        slaSummaryBean3.setId(ca3.getId());
        List<JsonBean> insertList = new ArrayList<JsonBean>();
        insertList.add(slaRegBean1);
        insertList.add(slaRegBean2);
        insertList.add(slaRegBean3);
        insertList.add(slaRegBean4);
        insertList.add(slaSummaryBean1);
        insertList.add(slaSummaryBean3);

        JPAService jpaService = Services.get().get(JPAService.class);
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);

        new CoordChangeXCommand(job.getId(), pauseTimeChangeStr).call();

        CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
        CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
        assertEquals(DateUtils.formatDateOozieTZ(coordJob.getPauseTime()), DateUtils.formatDateOozieTZ(pauseTime));
        assertEquals(Job.Status.RUNNING, coordJob.getStatus());
        assertEquals(2, coordJob.getLastActionNumber());
        try {
            jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 3));
            fail("Expected to fail as action 3 should have been deleted");
        }
        catch (JPAExecutorException jpae) {
            assertEquals(ErrorCode.E0603, jpae.getErrorCode());
        }

        try {
            jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 4));
            fail("Expected to fail as action 4 should have been deleted");
        }
        catch (JPAExecutorException jpae) {
            assertEquals(ErrorCode.E0603, jpae.getErrorCode());
        }

        slaRegBean1 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean1.getId());
        assertNotNull(slaRegBean1);
        slaRegBean2 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean2.getId());
        assertNotNull(slaRegBean2);
        slaRegBean3 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean3.getId());
        assertNull(slaRegBean3);
        slaRegBean4 = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, slaRegBean4.getId());
        assertNull(slaRegBean4);
        slaSummaryBean3 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean3.getId());
        assertNull(slaSummaryBean3);
        slaSummaryBean1 = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean1.getId());
        assertNotNull(slaSummaryBean1);
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

    @Test
    public void testOnSLAStartMissEvent() throws Exception {
        JMSSLAEventListener slaListener = new JMSSLAEventListener();
        slaListener.init(conf);
        SLACalcStatus startMiss = new SLACalcStatus(new SLARegistrationBean());
        SLARegistrationBean startMissBean = startMiss.getSLARegistrationBean();
        Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
        startMiss.setId("0000000-000000000000001-oozie-wrkf-C@1");
        startMissBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
        startMissBean.setAppName("Test-SLA-Start-Miss");
        startMissBean.setUser("dummyuser");
        startMissBean.setExpectedStart(startDate);
        startMissBean.setNotificationMsg("notification of start miss");
        startMissBean.setJobData("random job data");
        startMiss.setEventStatus(EventStatus.START_MISS);
        startMiss.setSLAStatus(SLAStatus.NOT_STARTED);
        startMissBean.setAppType(AppType.COORDINATOR_ACTION);
        startMiss.setActualStart(DateUtils.parseDateUTC("2013-01-01T01:00Z"));

        ConnectionContext jmsContext = getConnectionContext();

        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

    }

    public void testOnSLAEndMissEvent() throws Exception {
        JMSSLAEventListener slaListener = new JMSSLAEventListener();
        slaListener.init(conf);
        SLACalcStatus endMiss = new SLACalcStatus(new SLARegistrationBean());
        SLARegistrationBean endMissBean = endMiss.getSLARegistrationBean();
        Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
        Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
        endMiss.setId("0000000-000000000000001-oozie-wrkf-C@1");
        endMissBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
        endMissBean.setAppName("Test-SLA-End-Miss");
        endMiss.setEventStatus(EventStatus.END_MISS);
        endMiss.setSLAStatus(SLAStatus.IN_PROCESS);
        endMissBean.setAppType(AppType.COORDINATOR_ACTION);
        endMissBean.setUser("dummyuser");
        endMissBean.setNotificationMsg("notification of end miss");
        endMissBean.setExpectedEnd(expectedEndDate);
        endMiss.setActualEnd(actualEndDate);

        ConnectionContext jmsContext = getConnectionContext();

        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

    }

    public void testOnSLADurationMissEvent() throws Exception {
        JMSSLAEventListener slaListener = new JMSSLAEventListener();
        slaListener.init(conf);
        SLACalcStatus durationMiss = new SLACalcStatus(new SLARegistrationBean());
        SLARegistrationBean durationMissBean = durationMiss.getSLARegistrationBean();
        Date expectedStartDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
        Date actualStartDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
        Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T12:00Z");
        Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T14:00Z");
        long expectedDuration = ( expectedEndDate.getTime() - actualStartDate.getTime() ) / (1000 * 60);
        durationMiss.setId("0000000-000000000000001-oozie-wrkf-C@1");
        durationMissBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
        durationMissBean.setAppName("Test-SLA-Duration-Miss");
        durationMiss.setEventStatus(EventStatus.DURATION_MISS);
        durationMiss.setSLAStatus(SLAStatus.IN_PROCESS);
        durationMissBean.setAppType(AppType.COORDINATOR_ACTION);
        durationMissBean.setUser("dummyuser");
        durationMissBean.setNotificationMsg("notification of duration miss");
        durationMissBean.setExpectedStart(expectedStartDate);
        durationMiss.setActualStart(actualStartDate);
        durationMissBean.setExpectedEnd(expectedEndDate);
        durationMiss.setActualEnd(actualEndDate);
        durationMissBean.setExpectedDuration(expectedDuration);
        long actualDuration = actualEndDate.getTime() - actualStartDate.getTime();
        durationMiss.setActualDuration(actualDuration);

        ConnectionContext jmsContext = getConnectionContext();
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

    @Test
    public void testSLAJobSelectors() throws Exception {
        JMSSLAEventListener slaListener = new JMSSLAEventListener();
        slaListener.init(conf);
        SLACalcStatus startMiss = new SLACalcStatus(new SLARegistrationBean());
        SLARegistrationBean startMissBean = startMiss.getSLARegistrationBean();
        startMiss.setId("0000000-000000000000001-oozie-wrkf-C@1");
        startMissBean.setAppName("Test-SLA-Start-Miss");
        startMissBean.setAppType(AppType.COORDINATOR_ACTION);
        startMissBean.setUser("dummyuser");
        startMiss.setEventStatus(EventStatus.START_MISS);
        startMiss.setSLAStatus(SLAStatus.NOT_STARTED);
        startMiss.setMsgType(MessageType.SLA);

        ConnectionContext jmsContext = getConnectionContext();
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

    @Test
    public void testSLAJobSelectorsNegative() throws Exception {
        JMSSLAEventListener slaListener = new JMSSLAEventListener();
        slaListener.init(conf);
        SLACalcStatus startMiss = new SLACalcStatus(new SLARegistrationBean());
        SLARegistrationBean startMissBean = startMiss.getSLARegistrationBean();

        startMiss.setId("0000000-000000000000001-oozie-wrkf-C@1");
        startMissBean.setAppName("Test-SLA-Start-Miss");
        startMissBean.setAppType(AppType.COORDINATOR_ACTION);
        startMissBean.setUser("dummyuser");
        startMiss.setEventStatus(EventStatus.START_MISS);
        startMiss.setSLAStatus(SLAStatus.NOT_STARTED);
        startMiss.setMsgType(MessageType.SLA);

        ConnectionContext jmsContext = getConnectionContext();
View Full Code Here

Examples of org.apache.oozie.sla.SLARegistrationBean

    @Test
    public void testOnSLAStartMetEvent() throws Exception {
        JMSSLAEventListener slaListener = new JMSSLAEventListener();
        slaListener.init(conf);
        SLACalcStatus startMet = new SLACalcStatus(new SLARegistrationBean());
        SLARegistrationBean startMetBean = startMet.getSLARegistrationBean();
        Date expectedStartDate = DateUtils.parseDateUTC("2013-01-01T10:00Z");
        Date actualStartDate = DateUtils.parseDateUTC("2013-01-01T09:55Z");
        startMetBean.setAppName("Test-SLA-Start-Met");
        startMet.setEventStatus(EventStatus.START_MET);
        startMet.setSLAStatus(SLAStatus.IN_PROCESS);
        startMetBean.setAppType(AppType.COORDINATOR_ACTION);
        startMet.setId("0000000-000000000000001-oozie-wrkf-C@1");
        startMetBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
        startMetBean.setUser("dummyuser");
        startMetBean.setNotificationMsg("notification of start miss");
        startMetBean.setJobData("random job data");
        startMetBean.setExpectedStart(expectedStartDate);
        startMet.setActualStart(actualStartDate);

        ConnectionContext jmsContext = getConnectionContext();
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(startMet));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.