private void collectScheduleProfileMetadata(ProgramSchedule schedule, ProfileId programProfile, Map<MetadataEntity, Map<String, String>> updates) { ScheduleId scheduleId = schedule.getScheduleId(); LOG.trace("Updating profile metadata for {}", scheduleId); // if we are able to get profile from preferences or schedule properties, use it // otherwise default profile will be used Optional<ProfileId> scheduleProfileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), schedule.getProperties()); programProfile = scheduleProfileId.orElse(programProfile); addProfileMetadataUpdate(scheduleId, programProfile, updates); }
private void updateScheduleProfileMetadata(ProgramSchedule schedule, ProfileId profileId) { ScheduleId scheduleId = schedule.getScheduleId(); Optional<ProfileId> scheduleProfileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), schedule.getProperties()); profileId = scheduleProfileId.orElse(profileId); setProfileMetadata(scheduleId, profileId); }
public void suspend(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s/suspend", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
@Override public void deleteSchedules(Iterable<? extends ScheduleId> scheduleIds) throws NotFoundException { checkStarted(); execute((StoreQueueAndProfileTxRunnable<Void, NotFoundException>) (store, queue, profileDataset) -> { long deleteTime = System.currentTimeMillis(); for (ScheduleId scheduleId : scheduleIds) { ProgramSchedule schedule = store.getSchedule(scheduleId); deleteScheduleInScheduler(schedule); queue.markJobsForDeletion(scheduleId, deleteTime); adminEventPublisher.publishScheduleDeletion(scheduleId, schedule); // if the deleted schedule has properties with profile assignment, remove the assignment Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), schedule.getProperties()); if (profileId.isPresent()) { try { profileDataset.removeProfileAssignment(profileId.get(), scheduleId); } catch (NotFoundException e) { // this should not happen since the profile cannot be deleted if there is a schedule who is using it LOG.warn("Unable to find the profile {} when deleting schedule {}, " + "skipping assignment deletion.", profileId.get(), scheduleId); } } } store.deleteSchedules(scheduleIds); return null; }, NotFoundException.class); }
@Override public void deleteSchedules(Iterable<? extends ScheduleId> scheduleIds) throws NotFoundException { checkStarted(); execute((StoreQueueAndProfileTxRunnable<Void, NotFoundException>) (store, queue, profileDataset) -> { long deleteTime = System.currentTimeMillis(); for (ScheduleId scheduleId : scheduleIds) { ProgramSchedule schedule = store.getSchedule(scheduleId); deleteScheduleInScheduler(schedule); queue.markJobsForDeletion(scheduleId, deleteTime); adminEventPublisher.publishScheduleDeletion(scheduleId, schedule); // if the deleted schedule has properties with profile assignment, remove the assignment Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), schedule.getProperties()); if (profileId.isPresent()) { try { profileDataset.removeProfileAssignment(profileId.get(), scheduleId); } catch (NotFoundException e) { // this should not happen since the profile cannot be deleted if there is a schedule who is using it LOG.warn("Unable to find the profile {} when deleting schedule {}, " + "skipping assignment deletion.", profileId.get(), scheduleId); } } } store.deleteSchedules(scheduleIds); return null; }, NotFoundException.class); }
public void resume(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s/resume", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
@Override public void deleteSchedules(ProgramId programId) { checkStarted(); execute((StoreQueueAndProfileTxRunnable<Void, RuntimeException>) (store, queue, profileDataset) -> { long deleteTime = System.currentTimeMillis(); List<ProgramSchedule> schedules = store.listSchedules(programId); deleteSchedulesInScheduler(schedules); List<ScheduleId> deleted = store.deleteSchedules(programId); for (ScheduleId scheduleId : deleted) { queue.markJobsForDeletion(scheduleId, deleteTime); } for (ProgramSchedule programSchedule : schedules) { ScheduleId scheduleId = programSchedule.getScheduleId(); adminEventPublisher.publishScheduleDeletion(scheduleId, programSchedule); // if the deleted schedule has properties with profile assignment, remove the assignment Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), programSchedule.getProperties()); if (profileId.isPresent()) { try { profileDataset.removeProfileAssignment(profileId.get(), scheduleId); } catch (NotFoundException e) { // this should not happen since the profile cannot be deleted if there is a schedule who is using it LOG.warn("Unable to find the profile {} when deleting schedule {}, " + "skipping assignment deletion.", profileId.get(), scheduleId); } } } return null; }, RuntimeException.class); }
@Override public void deleteSchedules(ApplicationId appId) { checkStarted(); execute((StoreQueueAndProfileTxRunnable<Void, RuntimeException>) (store, queue, profileDataset) -> { long deleteTime = System.currentTimeMillis(); List<ProgramSchedule> schedules = store.listSchedules(appId); deleteSchedulesInScheduler(schedules); List<ScheduleId> deleted = store.deleteSchedules(appId); for (ScheduleId scheduleId : deleted) { queue.markJobsForDeletion(scheduleId, deleteTime); } for (ProgramSchedule programSchedule : schedules) { ScheduleId scheduleId = programSchedule.getScheduleId(); adminEventPublisher.publishScheduleDeletion(scheduleId, programSchedule); // if the deleted schedule has properties with profile assignment, remove the assignment Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), programSchedule.getProperties()); if (profileId.isPresent()) { try { profileDataset.removeProfileAssignment(profileId.get(), scheduleId); } catch (NotFoundException e) { // this should not happen since the profile cannot be deleted if there is a schedule who is using it LOG.warn("Unable to find the profile {} when deleting schedule {}, " + "skipping assignment deletion.", profileId.get(), scheduleId); } } } return null; }, RuntimeException.class); }
@Override public void deleteSchedules(ApplicationId appId) { checkStarted(); execute((StoreQueueAndProfileTxRunnable<Void, RuntimeException>) (store, queue, profileDataset) -> { long deleteTime = System.currentTimeMillis(); List<ProgramSchedule> schedules = store.listSchedules(appId); deleteSchedulesInScheduler(schedules); List<ScheduleId> deleted = store.deleteSchedules(appId); for (ScheduleId scheduleId : deleted) { queue.markJobsForDeletion(scheduleId, deleteTime); } for (ProgramSchedule programSchedule : schedules) { ScheduleId scheduleId = programSchedule.getScheduleId(); adminEventPublisher.publishScheduleDeletion(scheduleId, programSchedule); // if the deleted schedule has properties with profile assignment, remove the assignment Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), programSchedule.getProperties()); if (profileId.isPresent()) { try { profileDataset.removeProfileAssignment(profileId.get(), scheduleId); } catch (NotFoundException e) { // this should not happen since the profile cannot be deleted if there is a schedule who is using it LOG.warn("Unable to find the profile {} when deleting schedule {}, " + "skipping assignment deletion.", profileId.get(), scheduleId); } } } return null; }, RuntimeException.class); }
@Override public void deleteSchedules(ProgramId programId) { checkStarted(); execute((StoreQueueAndProfileTxRunnable<Void, RuntimeException>) (store, queue, profileDataset) -> { long deleteTime = System.currentTimeMillis(); List<ProgramSchedule> schedules = store.listSchedules(programId); deleteSchedulesInScheduler(schedules); List<ScheduleId> deleted = store.deleteSchedules(programId); for (ScheduleId scheduleId : deleted) { queue.markJobsForDeletion(scheduleId, deleteTime); } for (ProgramSchedule programSchedule : schedules) { ScheduleId scheduleId = programSchedule.getScheduleId(); adminEventPublisher.publishScheduleDeletion(scheduleId, programSchedule); // if the deleted schedule has properties with profile assignment, remove the assignment Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), programSchedule.getProperties()); if (profileId.isPresent()) { try { profileDataset.removeProfileAssignment(profileId.get(), scheduleId); } catch (NotFoundException e) { // this should not happen since the profile cannot be deleted if there is a schedule who is using it LOG.warn("Unable to find the profile {} when deleting schedule {}, " + "skipping assignment deletion.", profileId.get(), scheduleId); } } } return null; }, RuntimeException.class); }
/** * Delete an existing schedule. * * @param scheduleId the ID of the schedule to be deleted */ public void delete(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
private void doUpdate(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException { String path = String.format("apps/%s/versions/%s/schedules/%s/update", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpRequest request = HttpRequest.post(url).withBody(json).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
private void doAdd(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException { String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpRequest request = HttpRequest.put(url).withBody(json).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } else if (HttpURLConnection.HTTP_CONFLICT == response.getResponseCode()) { throw new AlreadyExistsException(scheduleId); } }
Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), schedule.getProperties()); if (profileId.isPresent()) {
Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), schedule.getProperties()); if (profileId.isPresent()) {