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

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


  public Response releaseLock(Lock mutableLock, LockValidation validation, SessionKey session) {
    requireNonNull(mutableLock);
    requireNonNull(validation);
    requireNonNull(session);

    ILock lock = ILock.build(mutableLock);

    try {
      sessionValidator.checkAuthenticated(
          session,
          ImmutableSet.of(getRoleFromLockKey(lock.getKey())));

      if (validation == LockValidation.CHECKED) {
        lockManager.validateIfLocked(lock.getKey(), Optional.of(lock));
      }
      lockManager.releaseLock(lock);
      return okEmptyResponse();
    } catch (AuthFailedException e) {
      return errorResponse(AUTH_FAILED, e);
View Full Code Here


        new HostAttributes("host", ImmutableSet.<Attribute>of()));
    StoredJob job = new StoredJob(
        "jobManager",
        new JobConfiguration().setKey(new JobKey("owner", "env", "name")));
    String frameworkId = "framework_id";
    ILock lock = ILock.build(new Lock()
        .setKey(LockKey.job(JobKeys.from("testRole", "testEnv", "testJob").newBuilder()))
        .setToken("lockId")
        .setUser("testUser")
        .setTimestampMs(12345L));
    SchedulerMetadata metadata = new SchedulerMetadata()
        .setFrameworkId(frameworkId)
        .setVersion(CURRENT_API_VERSION);
    final String updateId1 = "updateId1";
    final String updateId2 = "updateId2";
    IJobUpdateDetails updateDetails1 = IJobUpdateDetails.build(new JobUpdateDetails()
        .setUpdate(new JobUpdate().setSummary(new JobUpdateSummary().setUpdateId(updateId1)))
        .setUpdateEvents(ImmutableList.of(new JobUpdateEvent().setStatus(JobUpdateStatus.ERROR)))
        .setInstanceEvents(ImmutableList.of(new JobInstanceUpdateEvent().setTimestampMs(123L))));

    IJobUpdateDetails updateDetails2 = IJobUpdateDetails.build(new JobUpdateDetails()
        .setUpdate(new JobUpdate().setSummary(new JobUpdateSummary().setUpdateId(updateId2))));

    storageUtil.expectOperations();
    expect(storageUtil.taskStore.fetchTasks(Query.unscoped())).andReturn(tasks);
    expect(storageUtil.quotaStore.fetchQuotas())
        .andReturn(ImmutableMap.of("steve", ResourceAggregates.none()));
    expect(storageUtil.attributeStore.getHostAttributes())
        .andReturn(ImmutableSet.of(attribute, legacyAttribute));
    expect(storageUtil.jobStore.fetchManagerIds()).andReturn(ImmutableSet.of("jobManager"));
    expect(storageUtil.jobStore.fetchJobs("jobManager"))
        .andReturn(ImmutableSet.of(IJobConfiguration.build(job.getJobConfiguration())));
    expect(storageUtil.schedulerStore.fetchFrameworkId()).andReturn(Optional.of(frameworkId));
    expect(storageUtil.lockStore.fetchLocks()).andReturn(ImmutableSet.of(lock));
    String lockToken = "token";
    expect(storageUtil.jobUpdateStore.fetchAllJobUpdateDetails())
        .andReturn(ImmutableSet.of(
            new StoredJobUpdateDetails(updateDetails1.newBuilder(), lockToken),
            new StoredJobUpdateDetails(updateDetails2.newBuilder(), null)));

    expectDataWipe();
    storageUtil.taskStore.saveTasks(tasks);
    storageUtil.quotaStore.saveQuota("steve", ResourceAggregates.none());
    expect(storageUtil.attributeStore.saveHostAttributes(attribute)).andReturn(true);
    storageUtil.jobStore.saveAcceptedJob(
        job.getJobManagerId(),
        IJobConfiguration.build(job.getJobConfiguration()));
    storageUtil.schedulerStore.saveFrameworkId(frameworkId);
    storageUtil.lockStore.saveLock(lock);
    storageUtil.jobUpdateStore.saveJobUpdate(
        updateDetails1.getUpdate(), Optional.fromNullable(lockToken));
    storageUtil.jobUpdateStore.saveJobUpdateEvent(
        Iterables.getOnlyElement(updateDetails1.getUpdateEvents()),
        updateId1);
    storageUtil.jobUpdateStore.saveJobInstanceUpdateEvent(
        Iterables.getOnlyElement(updateDetails1.getInstanceEvents()),
        updateId1);
    storageUtil.jobUpdateStore.saveJobUpdate(
        updateDetails2.getUpdate(), Optional.<String>absent());

    control.replay();

    Snapshot expected = new Snapshot()
        .setTimestamp(NOW)
        .setTasks(IScheduledTask.toBuildersSet(tasks))
        .setQuotaConfigurations(quotas)
        .setHostAttributes(ImmutableSet.of(attribute.newBuilder(), legacyAttribute.newBuilder()))
        .setJobs(ImmutableSet.of(job))
        .setSchedulerMetadata(metadata)
        .setLocks(ImmutableSet.of(lock.newBuilder()))
        .setJobUpdateDetails(ImmutableSet.of(
            new StoredJobUpdateDetails(updateDetails1.newBuilder(), lockToken),
            new StoredJobUpdateDetails(updateDetails2.newBuilder(), null)));

    assertEquals(expected, snapshotStore.createSnapshot());
View Full Code Here

        setInstanceCount(makeJobUpdate(makeInstanceConfig(0, 1, OLD_CONFIG)), 0);

    storage.write(new NoResult.Quiet() {
      @Override
      protected void execute(Storage.MutableStoreProvider storeProvider) {
        ILock lock = saveJobUpdate(storeProvider.getJobUpdateStore(), update, ROLLING_FORWARD);
        lockManager.releaseLock(lock);
      }
    });

    subscriber.startAsync().awaitRunning();
View Full Code Here

    }.run();
  }

  @Test
  public void testSaveLock() throws Exception {
    final ILock lock = ILock.build(new Lock()
        .setKey(LockKey.job(JOB_KEY.newBuilder()))
        .setToken("testLockId")
        .setUser("testUser")
        .setTimestampMs(12345L));
    new MutationFixture() {
      @Override
      protected void setupExpectations() throws Exception {
        storageUtil.expectWriteOperation();
        storageUtil.lockStore.saveLock(lock);
        streamMatcher.expectTransaction(Op.saveLock(new SaveLock(lock.newBuilder())))
            .andReturn(position);
      }

      @Override
      protected void performMutations(MutableStoreProvider storeProvider) {
View Full Code Here

    String role = "testRole";
    String env = "testEnv";
    String job1 = "testJob1";
    String job2 = "testJob2";

    ILock lock1 = makeLock(JobKeys.from(role, env, job1).newBuilder(), "token1");
    ILock lock2 = makeLock(JobKeys.from(role, env, job2).newBuilder(), "token2");

    saveLocks(lock1, lock2);
    assertLocks(lock1, lock2);
    removeLocks(lock1);
View Full Code Here

    String role = "testRole";
    String env = "testEnv";
    String job = "testJob";

    ILock lock = makeLock(JobKeys.from(role, env, job).newBuilder(), "token1");

    saveLocks(lock);
    try {
      saveLocks(lock);
      fail("saveLock should have failed unique constraint check.");
View Full Code Here

  public void testExistingJobKey() throws Exception {
    String role = "testRole";
    String env = "testEnv";
    String job = "testJob";

    ILock lock = makeLock(JobKeys.from(role, env, job).newBuilder(), "token1");

    saveLocks(lock);
    removeLocks(lock);
    saveLocks(lock);
View Full Code Here

    String role1 = "testRole1";
    String role2 = "testRole2";
    String env = "testEnv";
    String job = "testJob";

    ILock lock1 = makeLock(JobKeys.from(role1, env, job).newBuilder(), "token1");
    ILock lock2 = makeLock(JobKeys.from(role2, env, job).newBuilder(), "token2");

    assertEquals(Optional.<ILock>absent(), getLock(lock1.getKey()));
    assertEquals(Optional.<ILock>absent(), getLock(lock2.getKey()));

    saveLocks(lock1);
    assertEquals(Optional.of(lock1), getLock(lock1.getKey()));
    assertEquals(Optional.<ILock>absent(), getLock(lock2.getKey()));
    saveLocks(lock2);
    assertEquals(Optional.of(lock1), getLock(lock1.getKey()));
    assertEquals(Optional.of(lock2), getLock(lock2.getKey()));
    removeLocks(lock1);
    assertEquals(Optional.<ILock>absent(), getLock(lock1.getKey()));
    assertEquals(Optional.of(lock2), getLock(lock2.getKey()));
  }
View Full Code Here

    String role = "testRole";
    String env = "testEnv";
    String job1 = "testJob1";
    String job2 = "testJob2";

    ILock lock1 = makeLock(JobKeys.from(role, env, job1).newBuilder(), "token1");
    ILock lock2 = makeLock(JobKeys.from(role, env, job2).newBuilder(), "token2");

    saveLocks(lock1, lock2);
    assertLocks(lock1, lock2);

    storage.write(new MutateWork.Quiet<Void>() {
View Full Code Here

    assertLocks();
  }

  @Test
  public void testDuplicateToken() throws Exception {
    ILock lock = makeLock(JobKeys.from("role", "env", "job1").newBuilder(), "token1");
    saveLocks(lock);
    try {
      saveLocks(makeLock(JobKeys.from("role", "env", "job2").newBuilder(), "token1"));
      fail();
    } catch (StorageException e) {
View Full Code Here

TOP

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

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.