use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class DeleteAndCreateSchedulesStage method process.
@Override
public void process(final ApplicationWithPrograms input) throws Exception {
if (!input.canUpdateSchedules()) {
// if we cant update schedules, emit and return
emit(input);
return;
}
ApplicationId appId = input.getApplicationId();
// Get a set of new schedules from the app spec
Set<ProgramSchedule> newSchedules = getProgramScheduleSet(appId, input.getSpecification());
for (ProgramSchedule schedule : programScheduler.listSchedules(appId)) {
if (newSchedules.contains(schedule)) {
// Remove the existing schedule from the newSchedules
newSchedules.remove(schedule);
continue;
}
// Delete the existing schedule if it is not present in newSchedules
programScheduler.deleteSchedule(schedule.getScheduleId());
}
// Add new schedules
programScheduler.addSchedules(newSchedules);
// Emit the input to next stage.
emit(input);
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class DefaultPreviewRequestQueue method isValid.
/**
* Check if the request is valid and not timed out yet.
*/
private static boolean isValid(PreviewRequest request, long waitTimeOut) {
ApplicationId applicationId = request.getProgram().getParent();
long submitTimeInSeconds = RunIds.getTime(applicationId.getApplication(), TimeUnit.SECONDS);
long timeInWaiting = (System.currentTimeMillis() / 1000) - submitTimeInSeconds;
return timeInWaiting <= waitTimeOut;
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class ScheduleTaskRunnerTest method testRuntimeArgumentResolution.
@Test
public void testRuntimeArgumentResolution() throws Exception {
Injector injector = Guice.createInjector(new ConfigModule(), binder -> {
binder.bind(OwnerAdmin.class).to(NoOpOwnerAdmin.class);
binder.bind(NamespaceAdmin.class).to(InMemoryNamespaceAdmin.class);
binder.bind(NamespaceQueryAdmin.class).to(InMemoryNamespaceAdmin.class);
binder.bind(PreferencesFetcher.class).toInstance(new FakePreferencesFetcher(Collections.singletonMap("key", "should-be-overridden")));
});
PropertiesResolver propertiesResolver = injector.getInstance(PropertiesResolver.class);
ApplicationId appId = NamespaceId.DEFAULT.app("app");
ProgramSchedule programSchedule = new ProgramSchedule("schedule", "desc", appId.workflow("wf2"), Collections.singletonMap("key", "val"), new ProgramStatusTrigger(appId.workflow("wf1")), Collections.emptyList());
Map<String, String> userArgs = ScheduleTaskRunner.getUserArgs(programSchedule, propertiesResolver);
Assert.assertEquals("val", userArgs.get("key"));
}
use of io.cdap.cdap.proto.id.ApplicationId in project cdap by caskdata.
the class EntityExistenceTest method testExists.
@Test
@SuppressWarnings("unchecked")
public void testExists() throws NotFoundException, UnauthorizedException {
existenceVerifier.ensureExists(new InstanceId(EXISTS));
existenceVerifier.ensureExists(NAMESPACE);
existenceVerifier.ensureExists(ARTIFACT);
ApplicationId app = NAMESPACE.app(AllProgramsApp.NAME);
existenceVerifier.ensureExists(app);
existenceVerifier.ensureExists(app.mr(AllProgramsApp.NoOpMR.NAME));
existenceVerifier.ensureExists(NAMESPACE.dataset(AllProgramsApp.DATASET_NAME));
}
use of io.cdap.cdap.proto.id.ApplicationId 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);
}
Aggregations