Search in sources :

Example 16 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.

the class TestSLARegistrationGetJPAExecutor method testSLARegistrationBulkConfigMap.

public void testSLARegistrationBulkConfigMap() throws Exception {
    Date current = new Date();
    String jobId = "0000000-" + current.getTime() + "-TestSLARegGetJPAExecutor-C@1";
    List<String> jobIds = new ArrayList<String>();
    jobIds.add(jobId);
    _addRecordToSLARegistrationTable(jobId, AppType.COORDINATOR_ACTION, current, new Date(), "END_MISS", "alert@example.com");
    jobId = "0000000-" + current.getTime() + "-TestSLARegGetJPAExecutor-C@2";
    jobIds.add(jobId);
    _addRecordToSLARegistrationTable(jobId, AppType.COORDINATOR_ACTION, current, new Date(), "END_MISS", "alert@example.com");
    List<SLARegistrationBean> bean = SLARegistrationQueryExecutor.getInstance().getList(SLARegQuery.GET_SLA_CONFIGS, jobIds);
    assertEquals(bean.size(), 2);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 17 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.

the class TestSLARegistrationGetJPAExecutor method _addRecordToSLARegistrationTable.

private void _addRecordToSLARegistrationTable(String jobId, AppType appType, Date start, Date end, String alertEvent, String alertContact) throws Exception {
    SLARegistrationBean reg = new SLARegistrationBean();
    reg.setId(jobId);
    reg.setAppType(appType);
    reg.setExpectedStart(start);
    reg.setExpectedEnd(end);
    reg.setAlertEvents(alertEvent);
    reg.setAlertContact(alertContact);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        List<JsonBean> insert = new ArrayList<JsonBean>();
        insert.add(reg);
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insert, null, null);
    } catch (JPAExecutorException je) {
        fail("Unable to insert the test sla registration record to table");
        throw je;
    }
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) JsonBean(org.apache.oozie.client.rest.JsonBean) ArrayList(java.util.ArrayList) JPAService(org.apache.oozie.service.JPAService)

Example 18 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.

the class TestSLARegistrationGetJPAExecutor method testSlaConfigStringToMap.

public void testSlaConfigStringToMap() {
    String slaConfig = "{alert_contact=hadoopqa@oozie.com},{alert_events=START_MISS,DURATION_MISS,END_MISS},";
    SLARegistrationBean bean = new SLARegistrationBean();
    bean.setSlaConfig(slaConfig);
    assertEquals(bean.getSLAConfigMap().size(), 2);
    assertEquals(bean.getAlertEvents(), "START_MISS,DURATION_MISS,END_MISS");
    assertEquals(bean.getAlertContact(), "hadoopqa@oozie.com");
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean)

Example 19 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.

the class XDataTestCase method addRecordToSLARegistrationTable.

/**
 * Insert sla registration for test
 * @param appName application name
 * @param status  sla status
 * @return
 * @throws Exception
 */
protected SLARegistrationBean addRecordToSLARegistrationTable(String appName, SLAStatus status) throws Exception {
    SLARegistrationBean sla = new SLARegistrationBean();
    Date today = new Date();
    sla.setId(Services.get().get(UUIDService.class).generateId(ApplicationType.COORDINATOR));
    sla.setAppName(appName);
    sla.setAppType(AppType.COORDINATOR_JOB);
    sla.setExpectedDuration(100);
    sla.setExpectedEnd(today);
    sla.setExpectedStart(today);
    sla.setJobData("test-job-data");
    sla.setCreatedTime(today);
    sla.setNominalTime(today);
    sla.setNotificationMsg("test-sla-notification-msg");
    sla.setParentId(Services.get().get(UUIDService.class).generateId(ApplicationType.BUNDLE));
    sla.setSlaConfig("alert-events");
    sla.setUpstreamApps("test-upstream-apps");
    sla.setUser("oozie");
    try {
        SLARegistrationQueryExecutor.getInstance().insert(sla);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test sla registration record to table");
        throw je;
    }
    return sla;
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) Date(java.util.Date)

Example 20 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean in project oozie by apache.

the class TestSLARegistrationQueryExecutor method testGetUpdateQuery.

public void testGetUpdateQuery() throws Exception {
    EntityManager em = jpaService.getEntityManager();
    SLARegistrationBean bean = addRecordToSLARegistrationTable("test-application", SLAStatus.MET);
    // UPDATE_SLA_REG_ALL
    Query query = SLARegistrationQueryExecutor.getInstance().getUpdateQuery(SLARegQuery.UPDATE_SLA_REG_ALL, bean, em);
    assertEquals(query.getParameterValue("jobId"), bean.getId());
    assertEquals(query.getParameterValue("nominalTime"), bean.getNominalTimestamp());
    assertEquals(query.getParameterValue("expectedStartTime"), bean.getExpectedStartTimestamp());
    assertEquals(query.getParameterValue("expectedEndTime"), bean.getExpectedEndTimestamp());
    assertEquals(query.getParameterValue("expectedDuration"), bean.getExpectedDuration());
    assertEquals(query.getParameterValue("slaConfig"), bean.getSlaConfig());
    assertEquals(query.getParameterValue("notificationMsg"), bean.getNotificationMsg());
    assertEquals(query.getParameterValue("upstreamApps"), bean.getUpstreamApps());
    assertEquals(query.getParameterValue("appType"), bean.getAppType().toString());
    assertEquals(query.getParameterValue("appName"), bean.getAppName());
    assertEquals(query.getParameterValue("user"), bean.getUser());
    assertEquals(query.getParameterValue("parentId"), bean.getParentId());
    assertEquals(query.getParameterValue("jobData"), bean.getJobData());
    em.close();
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) SLARegQuery(org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery)

Aggregations

SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)38 Date (java.util.Date)21 SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)18 ArrayList (java.util.ArrayList)8 MessageConsumer (javax.jms.MessageConsumer)8 Session (javax.jms.Session)8 TextMessage (javax.jms.TextMessage)8 MimeMessage (javax.mail.internet.MimeMessage)8 JPAService (org.apache.oozie.service.JPAService)8 SLAMessage (org.apache.oozie.client.event.message.SLAMessage)7 EntityManager (javax.persistence.EntityManager)6 Query (javax.persistence.Query)6 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)6 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)5 JsonBean (org.apache.oozie.client.rest.JsonBean)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 Test (org.junit.Test)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)3 SLARegQuery (org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery)3