Search in sources :

Example 21 with ScheduleId

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

the class SparkTest method testSparkProgramStatusSchedule.

@Test
public void testSparkProgramStatusSchedule() throws Exception {
    ApplicationManager appManager = deploy(TestSparkApp.class);
    ScheduleId scheduleId = new ScheduleId(NamespaceId.DEFAULT.getNamespace(), TestSparkApp.class.getSimpleName(), "schedule");
    appManager.enableSchedule(scheduleId);
    WorkflowManager workflowManager = appManager.getWorkflowManager(TestSparkApp.TriggeredWorkflow.class.getSimpleName());
    int numRuns = workflowManager.getHistory(ProgramRunStatus.COMPLETED).size();
    // Start the upstream program
    SparkManager sparkManager = appManager.getSparkManager(TestSparkApp.ScalaClassicSpark.class.getSimpleName());
    sparkManager.start();
    // Wait for the downstream to complete
    workflowManager.waitForRun(ProgramRunStatus.COMPLETED, 5, TimeUnit.MINUTES);
    // Run again with the kryo serializer
    sparkManager.start(Collections.singletonMap("spark.serializer", "org.apache.spark.serializer.KryoSerializer"));
    // Wait for the downstream to complete again
    workflowManager.waitForRuns(ProgramRunStatus.COMPLETED, numRuns + 2, 5, TimeUnit.MINUTES);
}
Also used : ApplicationManager(io.cdap.cdap.test.ApplicationManager) SparkManager(io.cdap.cdap.test.SparkManager) WorkflowManager(io.cdap.cdap.test.WorkflowManager) TestSparkApp(io.cdap.cdap.spark.app.TestSparkApp) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Test(org.junit.Test)

Example 22 with ScheduleId

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

the class ProgramScheduleStoreDataset method deleteSchedules.

/**
 * Removes all schedules for a specific application from the store.
 *
 * @param appId the application id for which to delete the schedules
 * @return the IDs of the schedules that were deleted
 */
// TODO: fix the bug that this method will return fake schedule id https://issues.cask.co/browse/CDAP-13626
public List<ScheduleId> deleteSchedules(ApplicationId appId, long deleteTime) throws IOException {
    List<ScheduleId> deleted = new ArrayList<>();
    Collection<Field<?>> scanKeys = getScheduleKeysForApplicationScan(appId);
    Range range = Range.singleton(scanKeys);
    // First collect all the schedules that are going to be deleted
    try (CloseableIterator<StructuredRow> iterator = scheduleStore.scan(range, Integer.MAX_VALUE)) {
        while (iterator.hasNext()) {
            StructuredRow row = iterator.next();
            if (row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE) != null) {
                markScheduleAsDeleted(row, deleteTime);
                deleted.add(rowToScheduleId(row));
            }
        }
    }
    // Then delete all triggers for the app
    triggerStore.deleteAll(range);
    return deleted;
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 23 with ScheduleId

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

the class ProgramScheduleStoreDataset method deleteSchedules.

/**
 * Removes all schedules for a specific program from the store.
 *
 * @param programId the program id for which to delete the schedules
 * @return the IDs of the schedules that were deleted
 */
// TODO: fix the bug that this method will return fake schedule id https://issues.cask.co/browse/CDAP-13626
public List<ScheduleId> deleteSchedules(ProgramId programId, long deleteTime) throws IOException {
    List<ScheduleId> deleted = new ArrayList<>();
    Collection<Field<?>> scanKeys = getScheduleKeysForApplicationScan(programId.getParent());
    Range range = Range.singleton(scanKeys);
    // First collect all the schedules that are going to be deleted
    try (CloseableIterator<StructuredRow> iterator = scheduleStore.scan(range, Integer.MAX_VALUE)) {
        while (iterator.hasNext()) {
            StructuredRow row = iterator.next();
            String serializedSchedule = row.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE);
            if (serializedSchedule != null) {
                ProgramSchedule schedule = GSON.fromJson(serializedSchedule, ProgramSchedule.class);
                if (programId.equals(schedule.getProgramId())) {
                    markScheduleAsDeleted(row, deleteTime);
                    Collection<Field<?>> deleteKeys = getScheduleKeys(row);
                    triggerStore.deleteAll(Range.singleton(deleteKeys));
                    deleted.add(rowToScheduleId(row));
                }
            }
        }
    }
    return deleted;
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) ArrayList(java.util.ArrayList) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 24 with ScheduleId

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

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, @Nullable Long deleteTime) throws NotFoundException, IOException {
    if (deleteTime == null) {
        deleteTime = System.currentTimeMillis();
    }
    for (ScheduleId scheduleId : scheduleIds) {
        StructuredRow existingRow = readExistingScheduleRow(scheduleId);
        markScheduleAsDeleted(existingRow, deleteTime);
        Collection<Field<?>> scheduleKeys = getScheduleKeys(scheduleId);
        triggerStore.deleteAll(Range.singleton(scheduleKeys));
    }
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Example 25 with ScheduleId

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

the class ProgramScheduleRecord method toScheduleDetail.

public ScheduleDetail toScheduleDetail() {
    ScheduleProgramInfo programInfo = new ScheduleProgramInfo(schedule.getProgramId().getType().getSchedulableType(), schedule.getProgramId().getProgram());
    ScheduleId scheduleId = schedule.getScheduleId();
    return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), schedule.getDescription(), programInfo, schedule.getProperties(), schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis(), meta.getStatus().name(), meta.getLastUpdated());
}
Also used : ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ScheduleProgramInfo(io.cdap.cdap.api.workflow.ScheduleProgramInfo) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Aggregations

ScheduleId (io.cdap.cdap.proto.id.ScheduleId)66 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)36 ProgramId (io.cdap.cdap.proto.id.ProgramId)20 ScheduleDetail (io.cdap.cdap.proto.ScheduleDetail)18 Test (org.junit.Test)16 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)14 CommandInputError (io.cdap.cdap.cli.exception.CommandInputError)12 NotFoundException (io.cdap.cdap.common.NotFoundException)12 ScheduleProgramInfo (io.cdap.cdap.api.workflow.ScheduleProgramInfo)10 ProgramSchedule (io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule)10 ProfileId (io.cdap.cdap.proto.id.ProfileId)10 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)8 ProgramType (io.cdap.cdap.proto.ProgramType)8 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)8 TimeTrigger (io.cdap.cdap.internal.app.runtime.schedule.trigger.TimeTrigger)6 Constraint (io.cdap.cdap.internal.schedule.constraint.Constraint)6 ProtoTrigger (io.cdap.cdap.proto.ProtoTrigger)6 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)6 ApplicationManager (io.cdap.cdap.test.ApplicationManager)5 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)4