Search in sources :

Example 16 with ScheduleId

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

the class UpdateTimeScheduleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String scheduleName = arguments.get(ArgumentName.SCHEDULE_NAME.toString());
    String[] programIdParts = arguments.get(ArgumentName.PROGRAM.toString()).split("\\.");
    String version = arguments.getOptional(ArgumentName.APP_VERSION.toString());
    String scheduleDescription = arguments.getOptional(ArgumentName.DESCRIPTION.toString(), "");
    String cronExpression = arguments.get(ArgumentName.CRON_EXPRESSION.toString());
    String schedulePropertiesString = arguments.getOptional(ArgumentName.SCHEDULE_PROPERTIES.toString(), "");
    String scheduleRunConcurrencyString = arguments.getOptional(ArgumentName.CONCURRENCY.toString(), null);
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    NamespaceId namespaceId = cliConfig.getCurrentNamespace();
    ApplicationId applicationId = (version == null) ? namespaceId.app(appId) : namespaceId.app(appId, version);
    ScheduleId scheduleId = applicationId.schedule(scheduleName);
    Schedules.Builder builder = Schedules.builder(scheduleName);
    if (scheduleRunConcurrencyString != null) {
        builder.setMaxConcurrentRuns(Integer.valueOf(scheduleRunConcurrencyString));
    }
    if (scheduleDescription != null) {
        builder.setDescription(scheduleDescription);
    }
    Schedule schedule = builder.createTimeSchedule(cronExpression);
    Map<String, String> programMap = ImmutableMap.of("programName", programIdParts[1], "programType", ElementType.WORKFLOW.name().toUpperCase());
    Map<String, String> propertiesMap = ArgumentParser.parseMap(schedulePropertiesString, ArgumentName.SCHEDULE_PROPERTIES.toString());
    ScheduleInstanceConfiguration configuration = new ScheduleInstanceConfiguration("TIME", schedule, programMap, propertiesMap);
    scheduleClient.update(scheduleId, configuration);
    printStream.printf("Successfully updated schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(co.cask.cdap.cli.exception.CommandInputError) Schedules(co.cask.cdap.api.schedule.Schedules) Schedule(co.cask.cdap.api.schedule.Schedule) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ScheduleInstanceConfiguration(co.cask.cdap.proto.ScheduleInstanceConfiguration) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ScheduleId(co.cask.cdap.proto.id.ScheduleId)

Example 17 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 18 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)

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