Search in sources :

Example 1 with WorkspaceActivity

use of org.eclipse.che.api.workspace.activity.WorkspaceActivity in project che-server by eclipse-che.

the class WorkspaceActivityTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(WorkspaceActivity.class, AccountImpl.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, RecipeImpl.class, MachineConfigImpl.class, SourceStorageImpl.class, ServerConfigImpl.class, CommandImpl.class, RecipeImpl.class, VolumeImpl.class, // devfile
    ActionImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class, ComponentImpl.class, DevfileImpl.class, EndpointImpl.class, EntrypointImpl.class, EnvImpl.class, ProjectImpl.class, SourceImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").addClass(SerializableConverter.class).setExceptionHandler(H2ExceptionHandler.class).build());
    bind(DBInitializer.class).asEagerSingleton();
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
    bind(WorkspaceActivityDao.class).to(JpaWorkspaceActivityDao.class);
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(new TypeLiteral<TckRepository<WorkspaceActivity>>() {
    }).toInstance(new JpaTckRepository<>(WorkspaceActivity.class));
    bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {
    }).toInstance(new WorkspaceRepository());
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(java.sql.Driver) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) WorkspaceActivity(org.eclipse.che.api.workspace.activity.WorkspaceActivity) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) ProjectImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) JpaWorkspaceActivityDao(org.eclipse.che.api.workspace.activity.JpaWorkspaceActivityDao) WorkspaceActivityDao(org.eclipse.che.api.workspace.activity.WorkspaceActivityDao) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SerializableConverter(org.eclipse.che.api.workspace.server.devfile.SerializableConverter) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) SourceImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.SourceImpl) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 2 with WorkspaceActivity

use of org.eclipse.che.api.workspace.activity.WorkspaceActivity in project che-server by eclipse-che.

the class WorkspaceActivityDaoTest method createWorkspaceActivitiesWithStatuses.

/**
 * Helper function that creates workspaces that are in the RUNNING and STOPPED state for
 * shouldExpireWorkspaceThatExceedsRunTimeout
 *
 * @return A list of WorkspaceActivity objects
 */
private List<WorkspaceActivity> createWorkspaceActivitiesWithStatuses() {
    WorkspaceActivity[] a = new WorkspaceActivity[3];
    a[0] = new WorkspaceActivity();
    a[0].setWorkspaceId("ws0");
    a[0].setStatus(WorkspaceStatus.RUNNING);
    a[0].setCreated(1_000_000);
    a[0].setLastStarting(1_000_000);
    a[0].setLastRunning(1_000_100);
    a[0].setLastStopped(0);
    a[0].setLastStopping(0);
    a[0].setExpiration(1_100_000L);
    a[1] = new WorkspaceActivity();
    a[1].setWorkspaceId("ws1");
    a[1].setStatus(WorkspaceStatus.RUNNING);
    a[1].setCreated(7_000_000);
    a[1].setLastStarting(7_000_000);
    a[1].setLastRunning(7_100_000);
    a[1].setLastStopped(0);
    a[1].setLastStopping(0);
    a[1].setExpiration(8_000_000L);
    a[2] = new WorkspaceActivity();
    a[2].setWorkspaceId("ws2");
    a[2].setStatus(WorkspaceStatus.STOPPED);
    a[2].setCreated(1_000_200);
    a[2].setLastStarting(1_000_200);
    a[2].setLastRunning(1_000_300);
    a[2].setLastStopped(1_000_400);
    a[2].setLastStopping(1_000_350);
    return asList(a);
}
Also used : WorkspaceActivity(org.eclipse.che.api.workspace.activity.WorkspaceActivity)

Example 3 with WorkspaceActivity

use of org.eclipse.che.api.workspace.activity.WorkspaceActivity in project che-server by eclipse-che.

the class WorkspaceActivityDaoTest method createdTimeMustSetLastStopped.

@Test
public void createdTimeMustSetLastStopped() throws TckRepositoryException, ServerException {
    // given new workspace with created activity
    AccountImpl newAccount = new AccountImpl("new_account", "new_account", "test");
    WorkspaceImpl workspace = createWorkspace("new_ws", newAccount, "new_ws");
    accountTckRepository.createAll(singletonList(newAccount));
    wsTckRepository.createAll(singletonList(workspace));
    Page<String> stopped = workspaceActivityDao.findInStatusSince(Instant.now().toEpochMilli(), STOPPED, 100, 0);
    assertTrue(stopped.isEmpty());
    // when created workspace activity
    workspaceActivityDao.setCreatedTime("new_ws", Instant.now().toEpochMilli());
    // then find STOPPED must return it and activity must have set last_stopped timestamp
    stopped = workspaceActivityDao.findInStatusSince(Instant.now().toEpochMilli(), STOPPED, 100, 0);
    assertFalse(stopped.isEmpty());
    assertEquals(stopped.getItemsCount(), 1);
    WorkspaceActivity activity = workspaceActivityDao.findActivity("new_ws");
    assertNotNull(activity.getLastStopped());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) WorkspaceActivity(org.eclipse.che.api.workspace.activity.WorkspaceActivity) Test(org.testng.annotations.Test)

Example 4 with WorkspaceActivity

use of org.eclipse.che.api.workspace.activity.WorkspaceActivity in project devspaces-images by redhat-developer.

the class WorkspaceActivityDaoTest method setUp.

@BeforeMethod
private void setUp() throws TckRepositoryException {
    for (int i = 0; i < COUNT; i++) {
        accounts[i] = new AccountImpl("accountId" + i, "accountName" + i, "test");
        // 2 workspaces share 1 namespace
        workspaces[i] = createWorkspace("ws" + i, accounts[i / 2], "name-" + i);
        long base = (long) i + 1;
        WorkspaceActivity a = new WorkspaceActivity();
        a.setWorkspaceId("ws" + i);
        a.setCreated(base);
        a.setLastStarting(base * 10);
        a.setLastRunning(base * 100);
        a.setLastStopping(base * 1_000);
        a.setLastStopped(base * 10_000);
        a.setExpiration(base * 1_000_000);
        activities[i] = a;
    }
    accountTckRepository.createAll(asList(accounts));
    wsTckRepository.createAll(asList(workspaces));
    activityTckRepository.createAll(asList(activities));
}
Also used : AccountImpl(org.eclipse.che.account.spi.AccountImpl) WorkspaceActivity(org.eclipse.che.api.workspace.activity.WorkspaceActivity) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with WorkspaceActivity

use of org.eclipse.che.api.workspace.activity.WorkspaceActivity in project che-server by eclipse-che.

the class WorkspaceActivityDaoTest method setUp.

@BeforeMethod
private void setUp() throws TckRepositoryException {
    for (int i = 0; i < COUNT; i++) {
        accounts[i] = new AccountImpl("accountId" + i, "accountName" + i, "test");
        // 2 workspaces share 1 namespace
        workspaces[i] = createWorkspace("ws" + i, accounts[i / 2], "name-" + i);
        long base = (long) i + 1;
        WorkspaceActivity a = new WorkspaceActivity();
        a.setWorkspaceId("ws" + i);
        a.setCreated(base);
        a.setLastStarting(base * 10);
        a.setLastRunning(base * 100);
        a.setLastStopping(base * 1_000);
        a.setLastStopped(base * 10_000);
        a.setExpiration(base * 1_000_000);
        activities[i] = a;
    }
    accountTckRepository.createAll(asList(accounts));
    wsTckRepository.createAll(asList(workspaces));
    activityTckRepository.createAll(asList(activities));
}
Also used : AccountImpl(org.eclipse.che.account.spi.AccountImpl) WorkspaceActivity(org.eclipse.che.api.workspace.activity.WorkspaceActivity) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

WorkspaceActivity (org.eclipse.che.api.workspace.activity.WorkspaceActivity)8 AccountImpl (org.eclipse.che.account.spi.AccountImpl)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 TypeLiteral (com.google.inject.TypeLiteral)2 Driver (java.sql.Driver)2 JpaWorkspaceActivityDao (org.eclipse.che.api.workspace.activity.JpaWorkspaceActivityDao)2 WorkspaceActivityDao (org.eclipse.che.api.workspace.activity.WorkspaceActivityDao)2 SerializableConverter (org.eclipse.che.api.workspace.server.devfile.SerializableConverter)2 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)2 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)2 MachineConfigImpl (org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl)2 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)2 RecipeImpl (org.eclipse.che.api.workspace.server.model.impl.RecipeImpl)2 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)2 SourceStorageImpl (org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl)2 VolumeImpl (org.eclipse.che.api.workspace.server.model.impl.VolumeImpl)2 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)2 ActionImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl)2 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)2 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)2