Search in sources :

Example 6 with ScheduleId

use of co.cask.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class ProgramScheduleStoreDataset method deleteSchedules.

/**
   * Removes one or more schedules from the store. Succeeds whether the schedules exist or not.
   *
   * @param scheduleIds the schedules to delete
   * @throws NotFoundException if one of the schedules does not exist in the store
   */
public void deleteSchedules(Iterable<? extends ScheduleId> scheduleIds) throws NotFoundException {
    for (ScheduleId scheduleId : scheduleIds) {
        String scheduleKey = rowKeyForSchedule(scheduleId);
        if (store.get(new Get(scheduleKey)).isEmpty()) {
            throw new NotFoundException(scheduleId);
        }
        store.delete(new Delete(scheduleKey));
        byte[] prefix = keyPrefixForTriggerScan(scheduleKey);
        try (Scanner scanner = store.scan(new Scan(prefix, Bytes.stopKeyForPrefix(prefix)))) {
            Row row;
            while ((row = scanner.next()) != null) {
                store.delete(row.getRow());
            }
        }
    }
}
Also used : Delete(co.cask.cdap.api.dataset.table.Delete) Scanner(co.cask.cdap.api.dataset.table.Scanner) Get(co.cask.cdap.api.dataset.table.Get) NotFoundException(co.cask.cdap.common.NotFoundException) Scan(co.cask.cdap.api.dataset.table.Scan) Row(co.cask.cdap.api.dataset.table.Row) ScheduleId(co.cask.cdap.proto.id.ScheduleId)

Example 7 with ScheduleId

use of co.cask.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method doGetSchedule.

private void doGetSchedule(HttpResponder responder, String namespace, String app, String version, String scheduleName, String format) throws NotFoundException, BadRequestException {
    boolean asScheduleSpec = returnScheduleAsSpec(format);
    ScheduleId scheduleId = new ApplicationId(namespace, app, version).schedule(scheduleName);
    ProgramSchedule schedule = programScheduler.getSchedule(scheduleId);
    ScheduleDetail detail = schedule.toScheduleDetail();
    if (asScheduleSpec) {
        ScheduleSpecification spec = detail.toScheduleSpec();
        if (spec == null) {
            // then this application must be using new APIs and the schedule can't be returned in old form.
            throw new NotFoundException(scheduleId);
        }
        responder.sendJson(HttpResponseStatus.OK, spec, ScheduleSpecification.class, GSON);
    } else {
        responder.sendJson(HttpResponseStatus.OK, detail, ScheduleDetail.class, GSON);
    }
}
Also used : ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) ScheduleId(co.cask.cdap.proto.id.ScheduleId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification)

Example 8 with ScheduleId

use of co.cask.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method doUpdateSchedule.

private void doUpdateSchedule(HttpRequest request, HttpResponder responder, String namespaceId, String appId, String appVersion, String scheduleName) throws BadRequestException, IOException, NotFoundException {
    ScheduleId scheduleId = new ApplicationId(namespaceId, appId, appVersion).schedule(scheduleName);
    final ProgramSchedule existingSchedule = programScheduler.getSchedule(scheduleId);
    ScheduleDetail scheduleDetail = readScheduleDetailBody(request, scheduleName, true, new Function<JsonElement, ScheduleDetail>() {

        @Override
        public ScheduleDetail apply(@Nullable JsonElement input) {
            ScheduleUpdateDetail updateDetail = GSON.fromJson(input, ScheduleUpdateDetail.class);
            return toScheduleDetail(updateDetail, existingSchedule);
        }
    });
    ProgramSchedule updatedSchedule = combineForUpdate(scheduleDetail, existingSchedule);
    programScheduler.updateSchedule(updatedSchedule);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) JsonElement(com.google.gson.JsonElement) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) ScheduleId(co.cask.cdap.proto.id.ScheduleId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ScheduleUpdateDetail(co.cask.cdap.proto.ScheduleUpdateDetail)

Example 9 with ScheduleId

use of co.cask.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class CoreSchedulerServiceTest method disableSchedule.

private void disableSchedule(String name) throws NotFoundException, ConflictException {
    ScheduleId scheduleId = APP_ID.schedule(name);
    scheduler.disableSchedule(scheduleId);
    Assert.assertEquals(ProgramScheduleStatus.SUSPENDED, scheduler.getScheduleStatus(scheduleId));
}
Also used : ScheduleId(co.cask.cdap.proto.id.ScheduleId)

Example 10 with ScheduleId

use of co.cask.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class CoreSchedulerServiceTest method testScheduleUpdate.

private void testScheduleUpdate(String howToUpdate) throws Exception {
    int runs = getRuns(WORKFLOW_2);
    ScheduleId scheduleId2 = APP_ID.schedule(AppWithFrequentScheduledWorkflows.DATASET_PARTITION_SCHEDULE_2);
    // send one notification to it, that will not start the workflow
    publishNotification(dataEventTopic, WORKFLOW_2, AppWithFrequentScheduledWorkflows.DATASET_NAME2);
    // give it enough time to create the job
    TimeUnit.SECONDS.sleep(5);
    Assert.assertEquals(runs, getRuns(WORKFLOW_2));
    if ("disable".equals(howToUpdate)) {
        // disabling and enabling the schedule should remove the job
        disableSchedule(AppWithFrequentScheduledWorkflows.DATASET_PARTITION_SCHEDULE_2);
        enableSchedule(AppWithFrequentScheduledWorkflows.DATASET_PARTITION_SCHEDULE_2);
    } else {
        ProgramSchedule schedule = scheduler.getSchedule(scheduleId2);
        Map<String, String> updatedProperties = ImmutableMap.<String, String>builder().putAll(schedule.getProperties()).put(howToUpdate, howToUpdate).build();
        ProgramSchedule updatedSchedule = new ProgramSchedule(schedule.getName(), schedule.getDescription(), schedule.getProgramId(), updatedProperties, schedule.getTrigger(), schedule.getConstraints());
        if ("update".equals(howToUpdate)) {
            scheduler.updateSchedule(updatedSchedule);
            Assert.assertEquals(ProgramScheduleStatus.SCHEDULED, scheduler.getScheduleStatus(scheduleId2));
        } else if ("delete".equals(howToUpdate)) {
            scheduler.deleteSchedule(scheduleId2);
            scheduler.addSchedule(updatedSchedule);
            enableSchedule(scheduleId2.getSchedule());
        } else {
            Assert.fail("invalid howToUpdate: " + howToUpdate);
        }
    }
    // single notification should not trigger workflow 2 yet (if it does, then the job was not removed)
    publishNotification(dataEventTopic, WORKFLOW_2, AppWithFrequentScheduledWorkflows.DATASET_NAME2);
    // give it enough time to create the job, but should not start
    TimeUnit.SECONDS.sleep(10);
    Assert.assertEquals(runs, getRuns(WORKFLOW_2));
    // now this should kick off the workflow
    publishNotification(dataEventTopic, WORKFLOW_2, AppWithFrequentScheduledWorkflows.DATASET_NAME2);
    waitForCompleteRuns(runs + 1, WORKFLOW_2);
}
Also used : ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) ScheduleId(co.cask.cdap.proto.id.ScheduleId) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint)

Aggregations

ScheduleId (co.cask.cdap.proto.id.ScheduleId)18 ApplicationId (co.cask.cdap.proto.id.ApplicationId)7 CommandInputError (co.cask.cdap.cli.exception.CommandInputError)6 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)5 Row (co.cask.cdap.api.dataset.table.Row)4 Scanner (co.cask.cdap.api.dataset.table.Scanner)4 NotFoundException (co.cask.cdap.common.NotFoundException)4 Scan (co.cask.cdap.api.dataset.table.Scan)3 Get (co.cask.cdap.api.dataset.table.Get)2 Schedule (co.cask.cdap.api.schedule.Schedule)2 Schedules (co.cask.cdap.api.schedule.Schedules)2 BadRequestException (co.cask.cdap.common.BadRequestException)2 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 ProgramType (co.cask.cdap.proto.ProgramType)2 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)2 ScheduleInstanceConfiguration (co.cask.cdap.proto.ScheduleInstanceConfiguration)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 ArrayList (java.util.ArrayList)2 Delete (co.cask.cdap.api.dataset.table.Delete)1