@Override public ConstraintProgramScheduleBuilder withConcurrency(int max) { constraints.add(new ConcurrencyConstraint(max)); return this; }
SimpleJob job = new SimpleJob(schedule, now, Collections.emptyList(), Job.State.PENDING_TRIGGER, 0L); ConcurrencyConstraint concurrencyConstraint = new ConcurrencyConstraint(2); ConstraintContext constraintContext = new ConstraintContext(job, now, store); assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext)); assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext)); assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext)); assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext)); assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext)); assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext)); store.setResume(pid3, AppFabricTestHelper.createSourceId(++sourceId), -1); assertSatisfied(false, concurrencyConstraint.check(schedule, constraintContext)); assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext)); assertSatisfied(true, concurrencyConstraint.check(schedule, constraintContext));
@Override public ConstraintResult check(ProgramSchedule schedule, ConstraintContext context) { int numRunning = context.getProgramRuns(schedule.getProgramId(), ProgramRunStatus.RUNNING, maxConcurrency).size(); if (numRunning >= maxConcurrency) { LOG.debug("Skipping run of program {} from schedule {} because there are at least {} running runs.", schedule.getProgramId(), schedule.getName(), maxConcurrency); return notSatisfied(context); } int numSuspended = context.getProgramRuns(schedule.getProgramId(), ProgramRunStatus.SUSPENDED, maxConcurrency).size(); if (numRunning + numSuspended >= maxConcurrency) { LOG.debug("Skipping run of program {} from schedule {} because there are at least" + "{} running runs and at least {} suspended runs.", schedule.getProgramId(), schedule.getName(), numRunning, numSuspended); return notSatisfied(context); } return ConstraintResult.SATISFIED; }
@Override public ConstraintResult check(ProgramSchedule schedule, ConstraintContext context) { int numRunning = context.getProgramRuns(schedule.getProgramId(), ProgramRunStatus.RUNNING, maxConcurrency).size(); if (numRunning >= maxConcurrency) { LOG.debug("Skipping run of program {} from schedule {} because there are at least {} running runs.", schedule.getProgramId(), schedule.getName(), maxConcurrency); return notSatisfied(context); } int numSuspended = context.getProgramRuns(schedule.getProgramId(), ProgramRunStatus.SUSPENDED, maxConcurrency).size(); if (numRunning + numSuspended >= maxConcurrency) { LOG.debug("Skipping run of program {} from schedule {} because there are at least" + "{} running runs and at least {} suspended runs.", schedule.getProgramId(), schedule.getName(), numRunning, numSuspended); return notSatisfied(context); } return ConstraintResult.SATISFIED; }
@Override public ConstraintProgramScheduleBuilder withConcurrency(int max) { constraints.add(new ConcurrencyConstraint(max)); return this; }
@Test public void testConstraintCodec() { testSerDeser(new ProtoConstraint.ConcurrencyConstraint(3), new ConcurrencyConstraint(3)); testSerDeser(new ProtoConstraint.DelayConstraint(300000L, TimeUnit.MILLISECONDS), new DelayConstraint(300000L, TimeUnit.MILLISECONDS)); testSerDeser(new ProtoConstraint.LastRunConstraint(3600000L, TimeUnit.MILLISECONDS), new LastRunConstraint(3600000L, TimeUnit.MILLISECONDS)); testSerDeser(new ProtoConstraint.TimeRangeConstraint("02:00", "06:00", TimeZone.getDefault()), new TimeRangeConstraint("02:00", "06:00", TimeZone.getDefault())); }
ImmutableMap.of("twoKey", "twoValue", "someKey", "newValue"), new TimeTrigger("0 4 * * *"), ImmutableList.of(new ConcurrencyConstraint(5)), null); ImmutableMap.of("twoKey", "twoValue"), new TimeTrigger("0 4 * * *"), ImmutableList.of(new ConcurrencyConstraint(5)), null); response = updateSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null, "NonExistingSchedule", nonExistingSchedule);