Search in sources :

Example 1 with ScheduleId

use of io.cdap.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class DataPipelineTest method deployPipelineWithSchedule.

private WorkflowManager deployPipelineWithSchedule(String pipelineName, Engine engine, String triggeringPipelineName, ArgumentMapping key1Mapping, String expectedKey1Value, PluginPropertyMapping key2Mapping, String expectedKey2Value) throws Exception {
    String tableName = "actionScheduleTable" + pipelineName + engine;
    String sourceName = "macroActionWithScheduleInput-" + pipelineName + engine;
    String sinkName = "macroActionWithScheduleOutput-" + pipelineName + engine;
    String key1 = key1Mapping.getTarget();
    String key2 = key2Mapping.getTarget();
    ETLBatchConfig etlConfig = ETLBatchConfig.builder().addStage(new ETLStage("action1", MockAction.getPlugin(tableName, "row1", "column1", String.format("${%s}", key1)))).addStage(new ETLStage("action2", MockAction.getPlugin(tableName, "row2", "column2", String.format("${%s}", key2)))).addStage(new ETLStage("source", MockSource.getPlugin(sourceName))).addStage(new ETLStage("filter1", StringValueFilterTransform.getPlugin("name", String.format("${%s}", key1)))).addStage(new ETLStage("filter2", StringValueFilterTransform.getPlugin("name", String.format("${%s}", key2)))).addStage(new ETLStage("sink", MockSink.getPlugin(sinkName))).addConnection("action1", "action2").addConnection("action2", "source").addConnection("source", "filter1").addConnection("filter1", "filter2").addConnection("filter2", "sink").setEngine(engine).build();
    AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(APP_ARTIFACT, etlConfig);
    ApplicationId appId = NamespaceId.DEFAULT.app(pipelineName);
    ApplicationManager appManager = deployApplication(appId, appRequest);
    // there should be only two programs - one workflow and one mapreduce/spark
    Schema schema = Schema.recordOf("testRecord", Schema.Field.of("name", Schema.of(Schema.Type.STRING)));
    // Use the expectedKey1Value and expectedKey2Value as values for two records, so that Only record "samuel"
    StructuredRecord recordSamuel = StructuredRecord.builder(schema).set("name", "samuel").build();
    StructuredRecord recordKey1Value = StructuredRecord.builder(schema).set("name", expectedKey1Value).build();
    StructuredRecord recordKey2Value = StructuredRecord.builder(schema).set("name", expectedKey2Value).build();
    // write one record to each source
    DataSetManager<Table> inputManager = getDataset(sourceName);
    MockSource.writeInput(inputManager, ImmutableList.of(recordSamuel, recordKey1Value, recordKey2Value));
    String defaultNamespace = NamespaceId.DEFAULT.getNamespace();
    // Use properties from the triggering pipeline as values for runtime argument key1, key2
    TriggeringPropertyMapping propertyMapping = new TriggeringPropertyMapping(ImmutableList.of(key1Mapping), ImmutableList.of(key2Mapping));
    ProgramStatusTrigger completeTrigger = new ProgramStatusTrigger(new WorkflowId(defaultNamespace, triggeringPipelineName, SmartWorkflow.NAME), ImmutableSet.of(ProgramStatus.COMPLETED));
    ScheduleId scheduleId = appId.schedule("completeSchedule");
    appManager.addSchedule(new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), "", new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, SmartWorkflow.NAME), ImmutableMap.of(SmartWorkflow.TRIGGERING_PROPERTIES_MAPPING, GSON.toJson(propertyMapping)), completeTrigger, ImmutableList.of(), Schedulers.JOB_QUEUE_TIMEOUT_MILLIS, null, null));
    appManager.enableSchedule(scheduleId);
    return appManager.getWorkflowManager(SmartWorkflow.NAME);
}
Also used : ApplicationManager(io.cdap.cdap.test.ApplicationManager) Table(io.cdap.cdap.api.dataset.table.Table) KeyValueTable(io.cdap.cdap.api.dataset.lib.KeyValueTable) Schema(io.cdap.cdap.api.data.schema.Schema) WorkflowId(io.cdap.cdap.proto.id.WorkflowId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) TriggeringPropertyMapping(io.cdap.cdap.etl.proto.v2.TriggeringPropertyMapping) ProgramStatusTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.ProgramStatusTrigger) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleProgramInfo(io.cdap.cdap.api.workflow.ScheduleProgramInfo)

Example 2 with ScheduleId

use of io.cdap.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class ResumeScheduleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String[] programIdParts = arguments.get(ElementType.SCHEDULE.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    String scheduleName = programIdParts[1];
    ScheduleId schedule = cliConfig.getCurrentNamespace().app(appId).schedule(scheduleName);
    scheduleClient.resume(schedule);
    printStream.printf("Successfully resumed schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Example 3 with ScheduleId

use of io.cdap.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);
    String description = scheduleDescription == null ? null : scheduleDescription;
    ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, programIdParts[1]);
    List<Constraint> constraints = scheduleRunConcurrencyString == null ? ImmutableList.of() : ImmutableList.of(new ProtoConstraint.ConcurrencyConstraint(Integer.valueOf(scheduleRunConcurrencyString)));
    Map<String, String> propertiesMap = ArgumentParser.parseMap(schedulePropertiesString, ArgumentName.SCHEDULE_PROPERTIES.toString());
    ScheduleDetail scheduleDetail = new ScheduleDetail(scheduleName, description, programInfo, propertiesMap, new ProtoTrigger.TimeTrigger(cronExpression), constraints, null);
    scheduleClient.update(scheduleId, scheduleDetail);
    printStream.printf("Successfully updated schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ProtoConstraint(io.cdap.cdap.proto.ProtoConstraint) Constraint(io.cdap.cdap.internal.schedule.constraint.Constraint) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ProtoTrigger(io.cdap.cdap.proto.ProtoTrigger) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleProgramInfo(io.cdap.cdap.api.workflow.ScheduleProgramInfo)

Example 4 with ScheduleId

use of io.cdap.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class DeleteScheduleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String[] programIdParts = arguments.get(ElementType.SCHEDULE.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    String scheduleName = programIdParts[1];
    ScheduleId schedule = cliConfig.getCurrentNamespace().app(appId).schedule(scheduleName);
    scheduleClient.delete(schedule);
    printStream.printf("Successfully deleted schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Example 5 with ScheduleId

use of io.cdap.cdap.proto.id.ScheduleId in project cdap by caskdata.

the class SuspendScheduleCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream printStream) throws Exception {
    String[] programIdParts = arguments.get(ElementType.SCHEDULE.getArgumentName().toString()).split("\\.");
    if (programIdParts.length < 2) {
        throw new CommandInputError(this);
    }
    String appId = programIdParts[0];
    String scheduleName = programIdParts[1];
    ScheduleId scheduleId = cliConfig.getCurrentNamespace().app(appId).schedule(scheduleName);
    scheduleClient.suspend(scheduleId);
    printStream.printf("Successfully suspended schedule '%s' in app '%s'\n", scheduleName, appId);
}
Also used : CommandInputError(io.cdap.cdap.cli.exception.CommandInputError) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Aggregations

ScheduleId (io.cdap.cdap.proto.id.ScheduleId)33 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)18 ProgramId (io.cdap.cdap.proto.id.ProgramId)10 ScheduleDetail (io.cdap.cdap.proto.ScheduleDetail)9 Test (org.junit.Test)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)7 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)6 NotFoundException (io.cdap.cdap.common.NotFoundException)6 ScheduleProgramInfo (io.cdap.cdap.api.workflow.ScheduleProgramInfo)5 ProgramSchedule (io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule)5 ProfileId (io.cdap.cdap.proto.id.ProfileId)5 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)4 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)4 ProgramType (io.cdap.cdap.proto.ProgramType)3 ApplicationManager (io.cdap.cdap.test.ApplicationManager)3 Config (io.cdap.cdap.api.Config)2 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 Constants (io.cdap.cdap.common.conf.Constants)2 Id (io.cdap.cdap.common.id.Id)2