Search in sources :

Example 1 with Rotations

use of com.yahoo.vespa.config.server.tenant.Rotations in project vespa by vespa-engine.

the class ApplicationRepository method remove.

/**
 * Removes a previously deployed application
 *
 * @return true if the application was found and removed, false if it was not present
 * @throws RuntimeException if the remove transaction fails. This method is exception safe.
 */
public boolean remove(ApplicationId applicationId) {
    Optional<Tenant> owner = Optional.ofNullable(tenants.getTenant(applicationId.tenant()));
    if (!owner.isPresent())
        return false;
    TenantApplications tenantApplications = owner.get().getApplicationRepo();
    if (!tenantApplications.listApplications().contains(applicationId))
        return false;
    // TODO: Push lookup logic down
    long sessionId = tenantApplications.getSessionIdForApplication(applicationId);
    LocalSessionRepo localSessionRepo = owner.get().getLocalSessionRepo();
    LocalSession session = localSessionRepo.getSession(sessionId);
    if (session == null)
        return false;
    NestedTransaction transaction = new NestedTransaction();
    localSessionRepo.removeSession(session.getSessionId(), transaction);
    // TODO: Not unit tested
    session.delete(transaction);
    // TODO: Not unit tested
    transaction.add(new Rotations(owner.get().getCurator(), owner.get().getPath()).delete(applicationId));
    // (When rotations are updated in zk, we need to redeploy the zone app, on the right config server
    // this is done asynchronously in application maintenance by the node repository)
    transaction.add(tenantApplications.deleteApplication(applicationId));
    hostProvisioner.ifPresent(provisioner -> provisioner.remove(transaction, applicationId));
    transaction.onCommitted(() -> log.log(LogLevel.INFO, "Deleted " + applicationId));
    transaction.commit();
    return true;
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) LocalSessionRepo(com.yahoo.vespa.config.server.session.LocalSessionRepo) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) NestedTransaction(com.yahoo.transaction.NestedTransaction) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) Rotations(com.yahoo.vespa.config.server.tenant.Rotations)

Example 2 with Rotations

use of com.yahoo.vespa.config.server.tenant.Rotations in project vespa by vespa-engine.

the class SessionPreparerTest method require_that_rotations_are_read_from_zookeeper_and_used.

@Test
public void require_that_rotations_are_read_from_zookeeper_and_used() throws IOException {
    final Version vespaVersion = Version.fromIntValues(1, 2, 3);
    final TestModelFactory modelFactory = new TestModelFactory(vespaVersion);
    preparer = createPreparer(new ModelFactoryRegistry(Arrays.asList(modelFactory)), HostProvisionerProvider.empty());
    final String rotations = "foo.msbe.global.vespa.yahooapis.com";
    final ApplicationId applicationId = applicationId("test");
    new Rotations(curator, tenantPath).writeRotationsToZooKeeper(applicationId, Collections.singleton(new Rotation(rotations)));
    final PrepareParams params = new PrepareParams.Builder().applicationId(applicationId).build();
    final File app = new File("src/test/resources/deploy/app");
    preparer.prepare(getContext(getApplicationPackage(app)), getLogger(), params, Optional.empty(), tenantPath, Instant.now());
    // check that the rotation from zookeeper were used
    final ModelContext modelContext = modelFactory.getModelContext();
    final Set<Rotation> rotationSet = modelContext.properties().rotations();
    assertThat(rotationSet, contains(new Rotation(rotations)));
    // Check that the persisted value is still the same
    assertThat(readRotationsFromZK(applicationId), contains(new Rotation(rotations)));
}
Also used : ModelContext(com.yahoo.config.model.api.ModelContext) Version(com.yahoo.config.provision.Version) ModelFactoryRegistry(com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry) TestModelFactory(com.yahoo.vespa.config.server.model.TestModelFactory) ApplicationId(com.yahoo.config.provision.ApplicationId) Rotation(com.yahoo.config.provision.Rotation) File(java.io.File) Rotations(com.yahoo.vespa.config.server.tenant.Rotations) Test(org.junit.Test)

Aggregations

Rotations (com.yahoo.vespa.config.server.tenant.Rotations)2 ModelContext (com.yahoo.config.model.api.ModelContext)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Rotation (com.yahoo.config.provision.Rotation)1 Version (com.yahoo.config.provision.Version)1 NestedTransaction (com.yahoo.transaction.NestedTransaction)1 TenantApplications (com.yahoo.vespa.config.server.application.TenantApplications)1 TestModelFactory (com.yahoo.vespa.config.server.model.TestModelFactory)1 ModelFactoryRegistry (com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry)1 LocalSession (com.yahoo.vespa.config.server.session.LocalSession)1 LocalSessionRepo (com.yahoo.vespa.config.server.session.LocalSessionRepo)1 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)1 File (java.io.File)1 Test (org.junit.Test)1