Search in sources :

Example 6 with Tenant

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

the class ListApplicationsHandler method listApplicationIds.

private List<ApplicationId> listApplicationIds(TenantName tenantName) {
    Utils.checkThatTenantExists(tenants, tenantName);
    Tenant tenant = tenants.getTenant(tenantName);
    TenantApplications applicationRepo = tenant.getApplicationRepo();
    return applicationRepo.listApplications();
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications)

Example 7 with Tenant

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

the class SessionCreateHandler method handlePOST.

@Override
protected HttpResponse handlePOST(HttpRequest request) {
    Slime deployLog = createDeployLog();
    final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request);
    Utils.checkThatTenantExists(tenants, tenantName);
    Tenant tenant = tenants.getTenant(tenantName);
    TimeoutBudget timeoutBudget = SessionHandler.getTimeoutBudget(request, zookeeperBarrierTimeout);
    DeployLogger logger = createLogger(request, deployLog, tenantName);
    long sessionId;
    if (request.hasProperty("from")) {
        ApplicationId applicationId = getFromApplicationId(request);
        sessionId = applicationRepository.createSessionFromExisting(tenant, logger, timeoutBudget, applicationId);
    } else {
        validateDataAndHeader(request);
        String name = getNameProperty(request, logger);
        sessionId = applicationRepository.createSession(tenant, timeoutBudget, request.getData(), request.getHeader(ApplicationApiHandler.contentTypeHeader), name);
    }
    return createResponse(request, tenantName, deployLog, sessionId);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) DeployLogger(com.yahoo.config.application.api.DeployLogger) Slime(com.yahoo.slime.Slime) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 8 with Tenant

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

the class ApplicationHandlerTest method testDelete.

@Test
public void testDelete() throws Exception {
    Clock clock = Clock.systemUTC();
    ApplicationId defaultId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
    assertApplicationExists(mytenantName, null, Zone.defaultZone());
    long sessionId = 1;
    {
        // This block is a real test of the interplay of (most of) the components of the config server
        // TODO: Extract it to ApplicationRepositoryTest, rewrite to bypass the HTTP layer and extend
        // as login is moved from the HTTP layer into ApplicationRepository
        Tenants tenants = addApplication(defaultId, sessionId);
        ApplicationHandler handler = createApplicationHandler(tenants);
        Tenant mytenant = tenants.getTenant(defaultId.tenant());
        LocalSession applicationData = mytenant.getLocalSessionRepo().getSession(sessionId);
        assertNotNull(applicationData);
        assertNotNull(applicationData.getApplicationId());
        assertFalse(provisioner.removed);
        deleteAndAssertOKResponse(handler, mytenant, defaultId);
        assertTrue(provisioner.removed);
        assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
        assertThat(provisioner.lastApplicationId, is(defaultId));
        assertNull(mytenant.getLocalSessionRepo().getSession(sessionId));
        assertNull(mytenant.getRemoteSessionRepo().getSession(sessionId));
    }
    sessionId++;
    {
        addMockApplication(tenants.getTenant(mytenantName), defaultId, sessionId, clock);
        deleteAndAssertOKResponseMocked(defaultId, true);
        ApplicationId fooId = new ApplicationId.Builder().tenant(mytenantName).applicationName("foo").instanceName("quux").build();
        sessionId++;
        addMockApplication(tenants.getTenant(mytenantName), fooId, sessionId, clock);
        addMockApplication(tenants.getTenant(foobar), fooId, sessionId, clock);
        assertApplicationExists(mytenantName, fooId, Zone.defaultZone());
        assertApplicationExists(foobar, fooId, Zone.defaultZone());
        deleteAndAssertOKResponseMocked(fooId, true);
        assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
        assertThat(provisioner.lastApplicationId, is(fooId));
        assertApplicationExists(mytenantName, null, Zone.defaultZone());
        assertApplicationExists(foobar, fooId, Zone.defaultZone());
    }
    sessionId++;
    {
        ApplicationId baliId = new ApplicationId.Builder().tenant(mytenantName).applicationName("bali").instanceName("quux").build();
        addMockApplication(tenants.getTenant(mytenantName), baliId, sessionId, clock);
        deleteAndAssertOKResponseMocked(baliId, true);
        assertApplicationExists(mytenantName, null, Zone.defaultZone());
    }
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) Tenants(com.yahoo.vespa.config.server.tenant.Tenants) Clock(java.time.Clock) ApplicationId(com.yahoo.config.provision.ApplicationId) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) Test(org.junit.Test)

Example 9 with Tenant

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

the class ApplicationHandlerTest method addApplication.

private static Tenants addApplication(ApplicationId applicationId, long sessionId) throws Exception {
    // This method is a good illustration of the spaghetti wiring resulting from no design
    // TODO: When this setup looks sane we have refactored sufficiently that there is a design
    TenantName tenantName = applicationId.tenant();
    Path tenantPath = Tenants.getTenantPath(tenantName);
    Path sessionPath = tenantPath.append(Tenant.SESSIONS).append(String.valueOf(sessionId));
    MockCurator curator = new MockCurator();
    GlobalComponentRegistry componentRegistry = new TestComponentRegistry.Builder().curator(curator).modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry())))).build();
    // Creates the application path element in zk
    Tenants tenants = new Tenants(componentRegistry);
    tenants.addTenant(tenantName);
    Tenant tenant = tenants.getTenant(tenantName);
    tenant.getApplicationRepo().createPutApplicationTransaction(applicationId, sessionId).commit();
    ApplicationPackage app = FilesApplicationPackage.fromFile(testApp);
    SessionZooKeeperClient sessionClient = new SessionZooKeeperClient(curator, sessionPath);
    SessionContext context = new SessionContext(app, sessionClient, new File("/serverDb"), tenant.getApplicationRepo(), null, new SuperModelGenerationCounter(curator));
    tenant.getLocalSessionRepo().addSession(new LocalSession(tenantName, sessionId, null, context));
    // TODO: Instead, use ApplicationRepository to deploy the application
    sessionClient.writeApplicationId(applicationId);
    tenant.getRemoteSessionRepo().addSession(new RemoteSession(tenantName, sessionId, componentRegistry, sessionClient, Clock.systemUTC()));
    return tenants;
}
Also used : Path(com.yahoo.path.Path) TenantName(com.yahoo.config.provision.TenantName) ModelFactoryRegistry(com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) Tenants(com.yahoo.vespa.config.server.tenant.Tenants) GlobalComponentRegistry(com.yahoo.vespa.config.server.GlobalComponentRegistry) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) VespaModelFactory(com.yahoo.vespa.model.VespaModelFactory) NullConfigModelRegistry(com.yahoo.config.model.NullConfigModelRegistry) Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TestComponentRegistry(com.yahoo.vespa.config.server.TestComponentRegistry) RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) SessionContext(com.yahoo.vespa.config.server.session.SessionContext) SuperModelGenerationCounter(com.yahoo.vespa.config.server.SuperModelGenerationCounter) File(java.io.File) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) SessionZooKeeperClient(com.yahoo.vespa.config.server.session.SessionZooKeeperClient)

Example 10 with Tenant

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

the class ApplicationRepository method deployFromLocalActive.

/**
 * Creates a new deployment from the active application, if available.
 *
 * @param application the active application to be redeployed
 * @param timeout the timeout to use for each individual deployment operation
 * @return a new deployment from the local active, or empty if a local active application
 *         was not present for this id (meaning it either is not active or active on another
 *         node in the config server cluster)
 */
@Override
public Optional<com.yahoo.config.provision.Deployment> deployFromLocalActive(ApplicationId application, Duration timeout) {
    Tenant tenant = tenants.getTenant(application.tenant());
    if (tenant == null)
        return Optional.empty();
    LocalSession activeSession = getActiveSession(tenant, application);
    if (activeSession == null)
        return Optional.empty();
    TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout);
    LocalSession newSession = tenant.getSessionFactory().createSessionFromExisting(activeSession, logger, timeoutBudget);
    tenant.getLocalSessionRepo().addSession(newSession);
    // Keep manually deployed applications on the latest version, don't change version otherwise
    Version version = environment.isManuallyDeployed() ? Vtag.currentVersion : newSession.getVespaVersion();
    return Optional.of(Deployment.unprepared(newSession, this, hostProvisioner, tenant, timeout, clock, // don't validate as this is already deployed
    false, version));
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) Version(com.yahoo.component.Version) LocalSession(com.yahoo.vespa.config.server.session.LocalSession)

Aggregations

Tenant (com.yahoo.vespa.config.server.tenant.Tenant)21 ApplicationId (com.yahoo.config.provision.ApplicationId)10 TenantName (com.yahoo.config.provision.TenantName)10 LocalSession (com.yahoo.vespa.config.server.session.LocalSession)6 TenantApplications (com.yahoo.vespa.config.server.application.TenantApplications)5 PrepareParams (com.yahoo.vespa.config.server.session.PrepareParams)5 TimeoutBudget (com.yahoo.vespa.config.server.TimeoutBudget)4 DeployLogger (com.yahoo.config.application.api.DeployLogger)3 Slime (com.yahoo.slime.Slime)3 Test (org.junit.Test)3 Version (com.yahoo.component.Version)2 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)2 ApplicationMetaData (com.yahoo.config.application.api.ApplicationMetaData)2 Path (com.yahoo.path.Path)2 NestedTransaction (com.yahoo.transaction.NestedTransaction)2 TestComponentRegistry (com.yahoo.vespa.config.server.TestComponentRegistry)2 BadRequestException (com.yahoo.vespa.config.server.http.BadRequestException)2 Tenants (com.yahoo.vespa.config.server.tenant.Tenants)2 Files (com.google.common.io.Files)1 Inject (com.google.inject.Inject)1