Search in sources :

Example 1 with RemoteSession

use of com.yahoo.vespa.config.server.session.RemoteSession in project vespa by vespa-engine.

the class ApplicationRepository method getCurrentActiveApplicationSet.

private Optional<ApplicationSet> getCurrentActiveApplicationSet(Tenant tenant, ApplicationId appId) {
    Optional<ApplicationSet> currentActiveApplicationSet = Optional.empty();
    TenantApplications applicationRepo = tenant.getApplicationRepo();
    try {
        long currentActiveSessionId = applicationRepo.getSessionIdForApplication(appId);
        RemoteSession currentActiveSession = getRemoteSession(tenant, currentActiveSessionId);
        if (currentActiveSession != null) {
            currentActiveApplicationSet = Optional.ofNullable(currentActiveSession.ensureApplicationLoaded());
        }
    } catch (IllegalArgumentException e) {
    // Do nothing if we have no currently active session
    }
    return currentActiveApplicationSet;
}
Also used : RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) TenantApplications(com.yahoo.vespa.config.server.application.TenantApplications) ApplicationSet(com.yahoo.vespa.config.server.application.ApplicationSet)

Example 2 with RemoteSession

use of com.yahoo.vespa.config.server.session.RemoteSession in project vespa by vespa-engine.

the class ApplicationRepository method getApplication.

private Application getApplication(Tenant tenant, ApplicationId applicationId) {
    long sessionId = getSessionIdForApplication(tenant, applicationId);
    RemoteSession session = tenant.getRemoteSessionRepo().getSession(sessionId, 0);
    return session.ensureApplicationLoaded().getForVersionOrLatest(Optional.empty(), clock.instant());
}
Also used : RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession)

Example 3 with RemoteSession

use of com.yahoo.vespa.config.server.session.RemoteSession 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 RemoteSession

use of com.yahoo.vespa.config.server.session.RemoteSession in project vespa by vespa-engine.

the class ApplicationHandlerTest method addMockApplication.

static void addMockApplication(Tenant tenant, ApplicationId applicationId, long sessionId, Clock clock) {
    tenant.getApplicationRepo().createPutApplicationTransaction(applicationId, sessionId).commit();
    ApplicationPackage app = FilesApplicationPackage.fromFile(testApp);
    tenant.getLocalSessionRepo().addSession(new SessionHandlerTest.MockSession(sessionId, app, applicationId));
    TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry())))).build();
    tenant.getRemoteSessionRepo().addSession(new RemoteSession(tenant.getName(), sessionId, componentRegistry, new MockSessionZKClient(app), clock));
}
Also used : VespaModelFactory(com.yahoo.vespa.model.VespaModelFactory) MockSessionZKClient(com.yahoo.vespa.config.server.session.MockSessionZKClient) NullConfigModelRegistry(com.yahoo.config.model.NullConfigModelRegistry) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) TestComponentRegistry(com.yahoo.vespa.config.server.TestComponentRegistry) ModelFactoryRegistry(com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry) RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage)

Example 5 with RemoteSession

use of com.yahoo.vespa.config.server.session.RemoteSession in project vespa by vespa-engine.

the class SessionActiveHandlerTest method testActivationOfUnpreparedSession.

@Test
public void testActivationOfUnpreparedSession() throws Exception {
    Clock clock = Clock.systemUTC();
    // Needed so we can test that previous active session is still active after a failed activation
    RemoteSession firstSession = activateAndAssertOK(90l, 0l, clock);
    long sessionId = 91L;
    ActivateRequest activateRequest = new ActivateRequest(sessionId, 0l, Session.Status.NEW, "", clock).invoke();
    HttpResponse actResponse = activateRequest.getActResponse();
    RemoteSession session = activateRequest.getSession();
    assertThat(actResponse.getStatus(), is(Response.Status.BAD_REQUEST));
    assertThat(getRenderedString(actResponse), is("{\"error-code\":\"BAD_REQUEST\",\"message\":\"tenant:" + tenant + " app:default:default Session " + sessionId + " is not prepared\"}"));
    assertThat(session.getStatus(), is(not(Session.Status.ACTIVATE)));
    assertThat(firstSession.getStatus(), is(Session.Status.ACTIVATE));
}
Also used : RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Clock(java.time.Clock) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) SessionTest(com.yahoo.vespa.config.server.session.SessionTest) Test(org.junit.Test)

Aggregations

RemoteSession (com.yahoo.vespa.config.server.session.RemoteSession)12 SessionZooKeeperClient (com.yahoo.vespa.config.server.session.SessionZooKeeperClient)5 HttpResponse (com.yahoo.container.jdisc.HttpResponse)3 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)3 Test (org.junit.Test)3 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)2 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)2 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)2 TestComponentRegistry (com.yahoo.vespa.config.server.TestComponentRegistry)2 TestConfigDefinitionRepo (com.yahoo.vespa.config.server.TestConfigDefinitionRepo)2 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)2 ModelFactoryRegistry (com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry)2 SessionTest (com.yahoo.vespa.config.server.session.SessionTest)2 VespaModelFactory (com.yahoo.vespa.model.VespaModelFactory)2 Clock (java.time.Clock)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)1 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)1 MockFileRegistry (com.yahoo.config.model.application.provider.MockFileRegistry)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1