@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.add(scheduleId, scheduleDetail); printStream.printf("Successfully added schedule '%s' in app '%s'\n", scheduleName, appId); }
@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); }
@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.add(scheduleId, scheduleDetail); printStream.printf("Successfully added schedule '%s' in app '%s'\n", scheduleName, appId); }
private void testAddSchedule(String scheduleName) throws Exception { String partitionScheduleName = scheduleName + "Partition"; String orScheduleName = scheduleName + "Or"; ProtoTrigger.TimeTrigger protoTime = new ProtoTrigger.TimeTrigger("0 * * * ?"); ProtoTrigger.PartitionTrigger protoPartition = new ProtoTrigger.PartitionTrigger(NamespaceId.DEFAULT.dataset("data"), 5);
new ProtoTrigger.TimeTrigger("0 4 * * *"), null, null); response = updateSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null, AppWithSchedule.SCHEDULE, scheduleDetail); Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode());
@Test public void testTimeTriggerValidation() { // Cron with wrong number of parts assertDeserializeFail(new ProtoTrigger.TimeTrigger("* * * ?"), "Cron entry must contain 5 or 6 fields."); assertDeserializeFail(new ProtoTrigger.TimeTrigger("* * * * 1 ? *"), "Cron entry must contain 5 or 6 fields."); // Quartz doesn't support '?' in both day-of-the-month and day-of-the-week assertDeserializeFail(new ProtoTrigger.TimeTrigger("* * * ? 1 ?"), "'?' can only be specfied for Day-of-Month -OR- Day-of-Week."); // Quartz doesn't support '0' in day-of-the-week assertDeserializeFail(new ProtoTrigger.TimeTrigger("2 6 ? * 0,1,4,5"), "Day-of-Week values must be between 1 and 7"); // Quartz doesn't support wild-card '*' in day-of-the-month or day-of-the-week if neither of them is '?' // Cron entry with resolution in minutes will have wild-card '*' in day-of-the-month or day-of-the-week // replaced by '?' if neither of them is '?', before it's parsed by Quartz GSON.toJson(new ProtoTrigger.TimeTrigger("* * * 1 *"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * 1 1 *"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * * 1 1"), Trigger.class); // Cron entry with resolution in seconds will be parsed directly by Quartz assertDeserializeFail(new ProtoTrigger.TimeTrigger("* * * * 1 *")); assertDeserializeFail(new ProtoTrigger.TimeTrigger("* * * * 1 1")); assertDeserializeFail(new ProtoTrigger.TimeTrigger("* * * 1 1 *")); GSON.toJson(new ProtoTrigger.TimeTrigger("2 6 ? * 1,4,5"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * ? 1 1"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * * 1 ?"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * ? 1 *"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * * ? 1 1"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * * * 1 ?"), Trigger.class); GSON.toJson(new ProtoTrigger.TimeTrigger("* * * ? 1 *"), Trigger.class); }
@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); }
@Test public void testTriggerCodec() { ProtoTrigger.PartitionTrigger protoPartition = new ProtoTrigger.PartitionTrigger(new DatasetId("test", "myds"), 4); PartitionTrigger partitionTrigger = new PartitionTrigger(new DatasetId("test", "myds"), 4); testSerDeserYieldsTrigger(protoPartition, partitionTrigger); ProtoTrigger.TimeTrigger protoTime = new ProtoTrigger.TimeTrigger("* * * * *"); TimeTrigger timeTrigger = new TimeTrigger("* * * * *"); testSerDeserYieldsTrigger(protoTime, timeTrigger); ProtoTrigger.ProgramStatusTrigger protoProgramStatus = new ProtoTrigger.ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.COMPLETED)); ProgramStatusTrigger programStatusTrigger = new ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.COMPLETED)); testSerDeserYieldsTrigger(protoProgramStatus, programStatusTrigger); ProtoTrigger.OrTrigger protoOr = ProtoTrigger.or(protoPartition, ProtoTrigger.and(protoTime, protoProgramStatus)); OrTrigger orTrigger = new OrTrigger(partitionTrigger, new AndTrigger(timeTrigger, programStatusTrigger)); testSerDeserYieldsTrigger(protoOr, orTrigger); ProtoTrigger.AndTrigger protoAnd = ProtoTrigger.and(protoOr, protoTime, ProtoTrigger.or(protoPartition, protoProgramStatus)); AndTrigger andTrigger = new AndTrigger(orTrigger, timeTrigger, new OrTrigger(partitionTrigger, programStatusTrigger)); testSerDeserYieldsTrigger(protoAnd, andTrigger); }
@Test public void testObjectContainingTrigger() { testContainingTrigger(new ProtoTrigger.PartitionTrigger(new DatasetId("test1", "pdfs1"), 1), new PartitionTrigger(new DatasetId("test1", "pdfs1"), 1)); testContainingTrigger(new ProtoTrigger.TimeTrigger("* * * 1 1"), new TimeTrigger("* * * 1 1")); testContainingTrigger(new ProtoTrigger.ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.FAILED)), new ProgramStatusTrigger(new ProgramId("test", "myapp", ProgramType.SERVICE, "myprog"), ImmutableSet.of(ProgramStatus.FAILED))); }