Search in sources :

Example 1 with Tenants

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

the class ApplicationRepositoryTest method setup.

@Before
public void setup() {
    Curator curator = new MockCurator();
    Tenants tenants = new Tenants(new TestComponentRegistry.Builder().curator(curator).build());
    tenants.addTenant(tenantName);
    tenant = tenants.getTenant(tenantName);
    Provisioner provisioner = new SessionHandlerTest.MockProvisioner();
    applicationRepository = new ApplicationRepository(tenants, provisioner, clock);
    timeoutBudget = new TimeoutBudget(clock, Duration.ofSeconds(60));
}
Also used : Provisioner(com.yahoo.config.provision.Provisioner) Tenants(com.yahoo.vespa.config.server.tenant.Tenants) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Before(org.junit.Before)

Example 2 with Tenants

use of com.yahoo.vespa.config.server.tenant.Tenants 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 3 with Tenants

use of com.yahoo.vespa.config.server.tenant.Tenants 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 4 with Tenants

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

the class ListApplicationsHandlerTest method setup.

@Before
public void setup() throws Exception {
    TestTenantBuilder testBuilder = new TestTenantBuilder();
    TenantName mytenant = TenantName.from("mytenant");
    TenantName foobar = TenantName.from("foobar");
    testBuilder.createTenant(mytenant);
    testBuilder.createTenant(foobar);
    applicationRepo = testBuilder.tenants().get(mytenant).getApplicationRepo();
    applicationRepo2 = testBuilder.tenants().get(foobar).getApplicationRepo();
    Tenants tenants = testBuilder.createTenants();
    handler = new ListApplicationsHandler(ListApplicationsHandler.testOnlyContext(), tenants, new Zone(Environment.dev, RegionName.from("us-east")));
}
Also used : Tenants(com.yahoo.vespa.config.server.tenant.Tenants) Before(org.junit.Before)

Example 5 with Tenants

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

the class HttpListConfigsHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    mockRequestHandler = new MockRequestHandler();
    mockRequestHandler.setAllConfigs(new HashSet<ConfigKey<?>>() {

        {
            add(new ConfigKey<>("bar", "conf/id", "foo"));
        }
    });
    TestTenantBuilder tb = new TestTenantBuilder();
    tb.createTenant(TenantName.from("mytenant")).withRequestHandler(mockRequestHandler).build();
    Tenants tenants = tb.createTenants();
    handler = new HttpListConfigsHandler(HttpListConfigsHandler.testOnlyContext(), tenants, Zone.defaultZone());
    namedHandler = new HttpListNamedConfigsHandler(HttpListConfigsHandler.testOnlyContext(), tenants, Zone.defaultZone());
}
Also used : MockRequestHandler(com.yahoo.vespa.config.server.rpc.MockRequestHandler) ConfigKey(com.yahoo.vespa.config.ConfigKey) Tenants(com.yahoo.vespa.config.server.tenant.Tenants) Before(org.junit.Before)

Aggregations

Tenants (com.yahoo.vespa.config.server.tenant.Tenants)6 Before (org.junit.Before)4 ConfigKey (com.yahoo.vespa.config.ConfigKey)2 MockRequestHandler (com.yahoo.vespa.config.server.rpc.MockRequestHandler)2 LocalSession (com.yahoo.vespa.config.server.session.LocalSession)2 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)2 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)2 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)1 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)1 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 Provisioner (com.yahoo.config.provision.Provisioner)1 TenantName (com.yahoo.config.provision.TenantName)1 Path (com.yahoo.path.Path)1 GlobalComponentRegistry (com.yahoo.vespa.config.server.GlobalComponentRegistry)1 SuperModelGenerationCounter (com.yahoo.vespa.config.server.SuperModelGenerationCounter)1 TestComponentRegistry (com.yahoo.vespa.config.server.TestComponentRegistry)1 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)1 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)1 ModelFactoryRegistry (com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry)1