Search in sources :

Example 11 with ScheduleId

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

the class ProgramLifecycleHttpHandler method doDeleteSchedule.

private void doDeleteSchedule(HttpResponder responder, String namespaceId, String appName, String appVersion, String scheduleName) throws Exception {
    ScheduleId scheduleId = new ApplicationId(namespaceId, appName, appVersion).schedule(scheduleName);
    programScheduleService.delete(scheduleId);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 12 with ScheduleId

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

the class ProgramLifecycleHttpHandler method doUpdateSchedule.

private void doUpdateSchedule(FullHttpRequest request, HttpResponder responder, String namespaceId, String appId, String appVersion, String scheduleName) throws Exception {
    ScheduleId scheduleId = new ApplicationId(namespaceId, appId, appVersion).schedule(scheduleName);
    ScheduleDetail scheduleDetail = readScheduleDetailBody(request, scheduleName);
    programScheduleService.update(scheduleId, scheduleDetail);
    responder.sendStatus(HttpResponseStatus.OK);
}
Also used : ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId)

Example 13 with ScheduleId

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

the class ProgramScheduleStoreDataset method findSchedules.

/**
 * Find all schedules that have a trigger with a given trigger key.
 *
 * @param triggerKey the trigger key to look up
 * @return a list of all schedules that are triggered by this key; never null
 */
public Collection<ProgramScheduleRecord> findSchedules(String triggerKey) throws IOException {
    Map<ScheduleId, ProgramScheduleRecord> schedulesFound = new HashMap<>();
    Field<String> triggerField = Fields.stringField(StoreDefinition.ProgramScheduleStore.TRIGGER_KEY, triggerKey);
    try (CloseableIterator<StructuredRow> iterator = triggerStore.scan(triggerField)) {
        while (iterator.hasNext()) {
            StructuredRow triggerRow = iterator.next();
            try {
                ScheduleId scheduleId = rowToScheduleId(triggerRow);
                if (schedulesFound.containsKey(scheduleId)) {
                    continue;
                }
                Optional<StructuredRow> optional = scheduleStore.read(getScheduleKeys(scheduleId));
                if (!optional.isPresent()) {
                    throw new NotFoundException(scheduleId);
                }
                StructuredRow scheduleRow = optional.get();
                String serialized = scheduleRow.getString(StoreDefinition.ProgramScheduleStore.SCHEDULE);
                if (serialized == null) {
                    throw new NotFoundException(scheduleId);
                }
                ProgramSchedule schedule = GSON.fromJson(serialized, ProgramSchedule.class);
                ProgramScheduleMeta meta = extractMetaFromRow(scheduleId, scheduleRow);
                ProgramScheduleRecord record = new ProgramScheduleRecord(schedule, meta);
                schedulesFound.put(scheduleId, record);
            } catch (IllegalArgumentException | NotFoundException e) {
                // the only exceptions we know to be thrown here are IllegalArgumentException (ill-formed key) or
                // NotFoundException (if the schedule does not exist). Both should never happen, so we warn and ignore.
                // we will let any other exception propagate up, because it would be a DataSetException or similarly serious.
                LOG.warn("Problem with trigger '{}' found for trigger key '{}': {}. Skipping entry.", triggerRow, triggerKey, e.getMessage());
            }
        }
    }
    return schedulesFound.values();
}
Also used : ProgramScheduleMeta(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleMeta) HashMap(java.util.HashMap) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) NotFoundException(io.cdap.cdap.common.NotFoundException) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) ProgramScheduleRecord(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleRecord)

Example 14 with ScheduleId

use of io.cdap.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, @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 15 with ScheduleId

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

the class ProfileMetadataMessageProcessor method collectProfileMetadata.

private void collectProfileMetadata(EntityId entityId, MetadataMessage message, List<MetadataMutation> updates) throws IOException {
    switch(entityId.getEntityType()) {
        case INSTANCE:
            for (NamespaceMeta meta : namespaceTable.list()) {
                collectProfileMetadata(meta.getNamespaceId(), message, updates);
            }
            break;
        case NAMESPACE:
            NamespaceId namespaceId = (NamespaceId) entityId;
            // make sure namespace exists before updating
            if (namespaceTable.get(namespaceId) == null) {
                LOG.debug("Namespace {} is not found, so the profile metadata of programs or schedules in it will not get " + "updated. Ignoring the message {}", namespaceId, message);
                return;
            }
            ProfileId namespaceProfile = getResolvedProfileId(namespaceId);
            List<ApplicationMeta> applicationMetas = appMetadataStore.getAllApplications(namespaceId.getNamespace());
            for (ApplicationMeta meta : applicationMetas) {
                collectAppProfileMetadata(namespaceId.app(meta.getId()), meta.getSpec(), namespaceProfile, updates);
            }
            break;
        case APPLICATION:
            ApplicationId appId = (ApplicationId) entityId;
            // make sure app exists before updating
            ApplicationMeta meta = appMetadataStore.getApplication(appId);
            if (meta == null) {
                LOG.debug("Application {} is not found, so the profile metadata of its programs/schedules will not get " + "updated. Ignoring the message {}", appId, message);
                return;
            }
            collectAppProfileMetadata(appId, meta.getSpec(), null, updates);
            collectPluginMetadata(appId, meta.getSpec(), updates);
            break;
        case PROGRAM:
            ProgramId programId = (ProgramId) entityId;
            // make sure the app of the program exists before updating
            meta = appMetadataStore.getApplication(programId.getParent());
            if (meta == null) {
                LOG.debug("Application {} is not found, so the profile metadata of program {} will not get updated. " + "Ignoring the message {}", programId.getParent(), programId, message);
                return;
            }
            if (PROFILE_ALLOWED_PROGRAM_TYPES.contains(programId.getType())) {
                collectProgramProfileMetadata(programId, null, updates);
            }
            break;
        case SCHEDULE:
            ScheduleId scheduleId = (ScheduleId) entityId;
            // make sure the schedule exists before updating
            try {
                ProgramSchedule schedule = scheduleDataset.getSchedule(scheduleId);
                collectScheduleProfileMetadata(schedule, getResolvedProfileId(schedule.getProgramId()), updates);
            } catch (NotFoundException e) {
                LOG.debug("Schedule {} is not found, so its profile metadata will not get updated. " + "Ignoring the message {}", scheduleId, message);
                return;
            }
            break;
        default:
            // this should not happen
            LOG.warn("Type of the entity id {} cannot be used to update profile metadata. " + "Ignoring the message {}", entityId, message);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NotFoundException(io.cdap.cdap.common.NotFoundException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta)

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