Exemplo n.º 1
0
  @Override
  public void configure() {
    try {
      setName("AppWithStreamSizeSchedule");
      setDescription("Sample application");
      ObjectStores.createObjectStore(getConfigurer(), "input", String.class);
      ObjectStores.createObjectStore(getConfigurer(), "output", String.class);
      addWorkflow(new SampleWorkflow());
      addStream(new Stream("stream"));

      Map<String, String> scheduleProperties = Maps.newHashMap();
      scheduleProperties.put("oneKey", "oneValue");
      scheduleProperties.put("anotherKey", "anotherValue");
      scheduleProperties.put("someKey", "someValue");

      scheduleWorkflow(
          Schedules.createDataSchedule("SampleSchedule1", "", Schedules.Source.STREAM, "stream", 1),
          "SampleWorkflow",
          scheduleProperties);
      scheduleWorkflow(
          Schedules.createDataSchedule("SampleSchedule2", "", Schedules.Source.STREAM, "stream", 2),
          "SampleWorkflow",
          scheduleProperties);
    } catch (UnsupportedTypeException e) {
      throw Throwables.propagate(e);
    }
  }
Exemplo n.º 2
0
  @Override
  public void addSchedule(
      Schedule schedule,
      SchedulableProgramType programType,
      String programName,
      Map<String, String> properties) {
    Preconditions.checkNotNull(schedule, "Schedule cannot be null.");
    Preconditions.checkNotNull(schedule.getName(), "Schedule name cannot be null.");
    Preconditions.checkArgument(!schedule.getName().isEmpty(), "Schedule name cannot be empty.");
    Preconditions.checkNotNull(programName, "Program name cannot be null.");
    Preconditions.checkArgument(!programName.isEmpty(), "Program name cannot be empty.");
    Preconditions.checkArgument(
        !schedules.containsKey(schedule.getName()),
        "Schedule with the name '" + schedule.getName() + "' already exists.");
    Schedule realSchedule = schedule;
    if (schedule.getClass().equals(Schedule.class)) {
      realSchedule =
          Schedules.createTimeSchedule(
              schedule.getName(), schedule.getDescription(), schedule.getCronEntry());
    }
    if (realSchedule instanceof StreamSizeSchedule) {
      Preconditions.checkArgument(
          ((StreamSizeSchedule) schedule).getDataTriggerMB() > 0,
          "Schedule data trigger must be greater than 0.");
    }

    ScheduleSpecification spec =
        new ScheduleSpecification(
            realSchedule, new ScheduleProgramInfo(programType, programName), properties);

    schedules.put(schedule.getName(), spec);
  }