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);
}
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);
}
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();
}
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));
}
}
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);
}
}
Aggregations