Package org.apache.aurora.scheduler.storage.entities

Examples of org.apache.aurora.scheduler.storage.entities.IJobConfiguration


    final Map<IJobKey, IJobConfiguration> jobs = getJobs(ownerRole, tasks);

    Function<IJobKey, JobSummary> makeJobSummary = new Function<IJobKey, JobSummary>() {
      @Override
      public JobSummary apply(IJobKey jobKey) {
        IJobConfiguration job = jobs.get(jobKey);
        JobSummary summary = new JobSummary()
            .setJob(job.newBuilder())
            .setStats(Jobs.getJobStats(tasks.get(jobKey)).newBuilder());

        return Strings.isNullOrEmpty(job.getCronSchedule())
            ? summary
            : summary.setNextCronRunMs(
                cronPredictor.predictNextRun(CrontabEntry.parse(job.getCronSchedule())).getTime());
      }
    };

    ImmutableSet<JobSummary> jobSummaries =
        FluentIterable.from(jobs.keySet()).transform(makeJobSummary).toSet();
View Full Code Here


      }
    });
  }

  private Optional<String> rewriteJob(JobConfigRewrite jobRewrite, JobStore.Mutable jobStore) {
    IJobConfiguration existingJob = IJobConfiguration.build(jobRewrite.getOldJob());
    IJobConfiguration rewrittenJob;
    Optional<String> error = Optional.absent();
    try {
      rewrittenJob = ConfigurationManager.validateAndPopulate(
          IJobConfiguration.build(jobRewrite.getRewrittenJob()));
    } catch (TaskDescriptionException e) {
      // We could add an error here, but this is probably a hint of something wrong in
      // the client that's causing a bad configuration to be applied.
      throw Throwables.propagate(e);
    }

    if (existingJob.getKey().equals(rewrittenJob.getKey())) {
      Multimap<String, IJobConfiguration> matches = jobsByKey(jobStore, existingJob.getKey());
      switch (matches.size()) {
        case 0:
          error = Optional.of(
              "No jobs found for key " + JobKeys.canonicalString(existingJob.getKey()));
          break;

        case 1:
          Map.Entry<String, IJobConfiguration> match =
              Iterables.getOnlyElement(matches.entries());
          IJobConfiguration storedJob = match.getValue();
          if (storedJob.equals(existingJob)) {
            jobStore.saveAcceptedJob(match.getKey(), rewrittenJob);
          } else {
            error = Optional.of(
                "CAS compare failed for " + JobKeys.canonicalString(storedJob.getKey()));
          }
          break;

        default:
          error = Optional.of("Multiple jobs found for key "
View Full Code Here

    this(SanitizedConfiguration.fromUnsanitized(unsanitized));
  }

  private SanitizedCronJob(SanitizedConfiguration config) throws CronException {
    final IJobConfiguration job = config.getJobConfig();
    if (!hasCronSchedule(job)) {
      throw new CronException(String.format(
          "Not a valid cron job, %s has no cron schedule", JobKeys.canonicalString(job.getKey())));
    }

    Optional<CrontabEntry> entry = CrontabEntry.tryParse(job.getCronSchedule());
    if (!entry.isPresent()) {
      throw new CronException("Invalid cron schedule: " + job.getCronSchedule());
    }

    this.config = config;
    this.crontabEntry = entry.get();
  }
View Full Code Here

      }
    });

    backfill();

    IJobConfiguration actual = Iterables.getOnlyElement(
        storage.consistentRead(new Storage.Work.Quiet<Iterable<IJobConfiguration>>() {
          @Override
          public Iterable<IJobConfiguration> apply(Storage.StoreProvider storeProvider) {
            return storeProvider.getJobStore().fetchJobs("CRON");
          }
View Full Code Here

    assertOkResponse(thrift.createJob(jobConfig, DEFAULT_LOCK, SESSION));
  }

  @Test
  public void testCreateJobWithLock() throws Exception {
    IJobConfiguration job = IJobConfiguration.build(makeProdJob());
    SanitizedConfiguration sanitized = SanitizedConfiguration.fromUnsanitized(job);
    expectAuth(ROLE, true);
    lockManager.validateIfLocked(LOCK_KEY, Optional.of(LOCK));
    storageUtil.expectTaskFetch(Query.jobScoped(JOB_KEY).active());
    expect(cronJobManager.hasJob(JOB_KEY)).andReturn(false);
    expect(taskIdGenerator.generate(sanitized.getJobConfig().getTaskConfig(), 1))
        .andReturn(TASK_ID);
    expect(quotaManager.checkInstanceAddition(sanitized.getJobConfig().getTaskConfig(), 1))
        .andReturn(ENOUGH_QUOTA);

    stateManager.insertPendingTasks(
        storageUtil.mutableStoreProvider,
        sanitized.getJobConfig().getTaskConfig(),
        sanitized.getInstanceIds());

    control.replay();

    assertOkResponse(thrift.createJob(job.newBuilder(), LOCK.newBuilder(), SESSION));
  }
View Full Code Here

    assertOkResponse(thrift.createJob(job.newBuilder(), LOCK.newBuilder(), SESSION));
  }

  @Test
  public void testCreateCronJob() throws Exception {
    IJobConfiguration job = IJobConfiguration.build(makeProdJob().setCronSchedule(CRON_SCHEDULE));
    SanitizedConfiguration sanitized = SanitizedConfiguration.fromUnsanitized(job);
    expectAuth(ROLE, true);
    lockManager.validateIfLocked(LOCK_KEY, Optional.of(LOCK));
    storageUtil.expectTaskFetch(Query.jobScoped(JOB_KEY).active());
    expect(cronJobManager.hasJob(JOB_KEY)).andReturn(false);
    expect(taskIdGenerator.generate(sanitized.getJobConfig().getTaskConfig(), 1))
        .andReturn(TASK_ID);
    expect(quotaManager.checkInstanceAddition(sanitized.getJobConfig().getTaskConfig(), 1))
        .andReturn(ENOUGH_QUOTA);

    cronJobManager.createJob(anyObject(SanitizedCronJob.class));

    control.replay();

    assertOkResponse(thrift.createJob(job.newBuilder(), LOCK.newBuilder(), SESSION));
  }
View Full Code Here

  }

  @Test
  public void testCreateCronJobEmptyCronSchedule() throws Exception {
    // TODO(maxim): Deprecate this as part of AURORA-423.
    IJobConfiguration job = IJobConfiguration.build(makeProdJob().setCronSchedule(""));
    SanitizedConfiguration sanitized = SanitizedConfiguration.fromUnsanitized(job);
    expectAuth(ROLE, true);
    lockManager.validateIfLocked(LOCK_KEY, Optional.of(LOCK));
    storageUtil.expectTaskFetch(Query.jobScoped(JOB_KEY).active());
    expect(cronJobManager.hasJob(JOB_KEY)).andReturn(false);
    expect(taskIdGenerator.generate(sanitized.getJobConfig().getTaskConfig(), 1))
        .andReturn(TASK_ID);
    expect(quotaManager.checkInstanceAddition(sanitized.getJobConfig().getTaskConfig(), 1))
        .andReturn(ENOUGH_QUOTA);

    stateManager.insertPendingTasks(
        storageUtil.mutableStoreProvider,
        sanitized.getJobConfig().getTaskConfig(),
        sanitized.getInstanceIds());

    control.replay();

    assertOkResponse(thrift.createJob(job.newBuilder(), LOCK.newBuilder(), SESSION));
  }
View Full Code Here

    assertOkResponse(thrift.createJob(job.newBuilder(), LOCK.newBuilder(), SESSION));
  }

  @Test
  public void testCreateJobFailsAuth() throws Exception {
    IJobConfiguration job = IJobConfiguration.build(makeJob());
    expectAuth(ROLE, false);
    control.replay();

    assertResponse(
        AUTH_FAILED,
        thrift.createJob(job.newBuilder(), DEFAULT_LOCK, SESSION));
  }
View Full Code Here

        thrift.createJob(job.newBuilder(), DEFAULT_LOCK, SESSION));
  }

  @Test
  public void testCreateJobFailsConfigCheck() throws Exception {
    IJobConfiguration job = IJobConfiguration.build(makeJob(null));
    expectAuth(ROLE, true);
    control.replay();

    assertResponse(
        INVALID_REQUEST,
        thrift.createJob(job.newBuilder(), DEFAULT_LOCK, SESSION));
  }
View Full Code Here

        thrift.createJob(job.newBuilder(), DEFAULT_LOCK, SESSION));
  }

  @Test
  public void testCreateJobFailsLockCheck() throws Exception {
    IJobConfiguration job = IJobConfiguration.build(makeJob());
    expectAuth(ROLE, true);
    lockManager.validateIfLocked(LOCK_KEY, Optional.of(LOCK));
    expectLastCall().andThrow(new LockException("Invalid lock"));

    control.replay();

    assertResponse(LOCK_ERROR, thrift.createJob(job.newBuilder(), LOCK.newBuilder(), SESSION));
  }
View Full Code Here

TOP

Related Classes of org.apache.aurora.scheduler.storage.entities.IJobConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.