Search in sources :

Example 1 with DefaultTimeTriggerInfo

use of io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo in project cdap by caskdata.

the class OperationsDashboardHttpHandlerTest method testDashboardReadWithScheduledRuns.

@Test
public void testDashboardReadWithScheduledRuns() throws Exception {
    long startTime1 = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    RunId runId1 = RunIds.generate();
    NamespaceId ns3 = new NamespaceId("ns3");
    List<TriggerInfo> triggerInfos = new ArrayList<>();
    triggerInfos.add(new DefaultTimeTriggerInfo("*/5 * * * *", startTime1));
    TriggeringScheduleInfo triggeringScheduleInfo = new DefaultTriggeringScheduleInfo("test", "test", triggerInfos, new HashMap<>());
    RunRecordDetail.Builder metaBuilder = getMockRunRecordMeta(ns3, runId1);
    metaBuilder.setRunTime(startTime1);
    metaBuilder.setStatus(ProgramRunStatus.RUNNING);
    Map<String, String> systemArgs = ImmutableMap.of(ProgramOptionConstants.TRIGGERING_SCHEDULE_INFO, GSON.toJson(triggeringScheduleInfo));
    metaBuilder.setSystemArgs(systemArgs);
    RunRecordDetail meta = metaBuilder.build();
    writeRunRecordMeta(meta, startTime1);
    // write heart beat messages for 10 minutes (every minute) for this program run.
    long endTime = startTime1 + TimeUnit.MINUTES.toSeconds(5);
    long interval = TimeUnit.MINUTES.toSeconds(1);
    setUpProgramHeartBeats(meta, startTime1, endTime, interval);
    String opsDashboardQueryPath = String.format("%s/dashboard?start=%s&duration=%s&namespace=%s", BASE_PATH, String.valueOf(startTime1), String.valueOf(endTime), ns3.getNamespace());
    // get ops dashboard query results
    HttpResponse response = doGet(opsDashboardQueryPath);
    Assert.assertEquals(200, response.getResponseCode());
    String content = response.getResponseBodyAsString();
    List<DashboardProgramRunRecord> dashboardDetail = GSON.fromJson(content, DASHBOARD_DETAIL_TYPE);
    // assert the result contains 1 entry
    Assert.assertEquals(1, dashboardDetail.size());
    Assert.assertEquals(OperationsDashboardHttpHandler.runRecordToDashboardRecord(meta), dashboardDetail.iterator().next());
}
Also used : DefaultTriggeringScheduleInfo(io.cdap.cdap.internal.app.runtime.schedule.DefaultTriggeringScheduleInfo) DefaultTimeTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) DefaultTimeTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) TriggerInfo(io.cdap.cdap.api.schedule.TriggerInfo) ArrayList(java.util.ArrayList) DashboardProgramRunRecord(io.cdap.cdap.proto.ops.DashboardProgramRunRecord) DefaultTriggeringScheduleInfo(io.cdap.cdap.internal.app.runtime.schedule.DefaultTriggeringScheduleInfo) TriggeringScheduleInfo(io.cdap.cdap.api.schedule.TriggeringScheduleInfo) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) RunId(org.apache.twill.api.RunId) Test(org.junit.Test)

Example 2 with DefaultTimeTriggerInfo

use of io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo in project cdap by caskdata.

the class TriggeringScheduleInfoAdapterTest method testSerDeserScheduleInfo.

@Test
public void testSerDeserScheduleInfo() {
    BasicWorkflowToken token = new BasicWorkflowToken(1);
    token.setCurrentNode("node");
    token.put("tokenKey", "tokenVal");
    List<TriggerInfo> triggerInfos = ImmutableList.of(new DefaultProgramStatusTriggerInfo("ns", Specifications.from(new WorkflowAppWithFork()).getName(), ProgramType.WORKFLOW, WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName(), RunIds.generate(), ProgramStatus.COMPLETED, token, Collections.emptyMap()), new DefaultPartitionTriggerInfo("ns", "ds", 10, 11), new DefaultTimeTriggerInfo("1 * * * *", 0L));
    TriggeringScheduleInfo scheduleInfo = new DefaultTriggeringScheduleInfo("schedule", "description", triggerInfos, ImmutableMap.of("key", "value"));
    String scheduleInfoJson = GSON.toJson(scheduleInfo);
    TriggeringScheduleInfo deserializedScheduleInfo = GSON.fromJson(scheduleInfoJson, TriggeringScheduleInfo.class);
    Assert.assertEquals(scheduleInfoJson, GSON.toJson(deserializedScheduleInfo));
    DefaultProgramStatusTriggerInfo expectedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) triggerInfos.get(0);
    DefaultProgramStatusTriggerInfo deserializedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) deserializedScheduleInfo.getTriggerInfos().get(0);
    Assert.assertEquals(expectedProgramStatusTriggerInfo.getApplicationName(), deserializedProgramStatusTriggerInfo.getApplicationName());
    Assert.assertEquals(expectedProgramStatusTriggerInfo.getWorkflowToken().getAll(), deserializedProgramStatusTriggerInfo.getWorkflowToken().getAll());
}
Also used : DefaultPartitionTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo) WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) DefaultTimeTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) TriggerInfo(io.cdap.cdap.api.schedule.TriggerInfo) DefaultProgramStatusTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo) DefaultPartitionTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo) DefaultTimeTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) TriggeringScheduleInfo(io.cdap.cdap.api.schedule.TriggeringScheduleInfo) BasicWorkflowToken(io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken) DefaultProgramStatusTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo) Test(org.junit.Test)

Aggregations

TriggerInfo (io.cdap.cdap.api.schedule.TriggerInfo)2 TriggeringScheduleInfo (io.cdap.cdap.api.schedule.TriggeringScheduleInfo)2 DefaultTimeTriggerInfo (io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo)2 Test (org.junit.Test)2 WorkflowAppWithFork (io.cdap.cdap.WorkflowAppWithFork)1 DefaultTriggeringScheduleInfo (io.cdap.cdap.internal.app.runtime.schedule.DefaultTriggeringScheduleInfo)1 DefaultPartitionTriggerInfo (io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo)1 DefaultProgramStatusTriggerInfo (io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo)1 BasicWorkflowToken (io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken)1 RunRecordDetail (io.cdap.cdap.internal.app.store.RunRecordDetail)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1 DashboardProgramRunRecord (io.cdap.cdap.proto.ops.DashboardProgramRunRecord)1 HttpResponse (io.cdap.common.http.HttpResponse)1 ArrayList (java.util.ArrayList)1 RunId (org.apache.twill.api.RunId)1