Search in sources :

Example 96 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class OrganizationDistributedResourcesDaoTest method setUp.

@BeforeMethod
private void setUp() throws Exception {
    parentOrganization = new OrganizationImpl("parentOrg", "parentOrgName", null);
    suborganizations = new OrganizationImpl[ORGANIZATION_RESOURCES_COUNT];
    distributedResources = new OrganizationDistributedResourcesImpl[ORGANIZATION_RESOURCES_COUNT];
    for (int i = 0; i < ORGANIZATION_RESOURCES_COUNT; i++) {
        suborganizations[i] = new OrganizationImpl("suborgId-" + i, "suborgName" + i, parentOrganization.getId());
        distributedResources[i] = new OrganizationDistributedResourcesImpl(suborganizations[i].getId(), singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, i, "test")));
    }
    organizationsRepository.createAll(Collections.singletonList(parentOrganization));
    organizationsRepository.createAll(Arrays.asList(suborganizations));
    distributedResourcesRepository.createAll(Arrays.asList(distributedResources));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 97 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class MultiUserWorkspaceActivityManagerTest method shouldAddNewActiveWorkspaceWithUserTimeoutIfPresent.

@Test
public void shouldAddNewActiveWorkspaceWithUserTimeoutIfPresent() throws Exception {
    final String wsId = "testWsId";
    final long activityTime = 1000L;
    doReturn(singletonList(new ResourceImpl(TimeoutResourceType.ID, USER_LIMIT_TIMEOUT / 60 / 1000, TimeoutResourceType.UNIT))).when(resourceManager).getAvailableResources(anyString());
    activityManager.update(wsId, activityTime);
    verify(workspaceActivityDao, times(1)).setExpirationTime(eq(wsId), eq(activityTime + USER_LIMIT_TIMEOUT));
    verify(resourceManager).getAvailableResources(eq("account123"));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 98 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class JpaEntitiesCascadeRemovalTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    injector = Guice.createInjector(Stage.PRODUCTION, new AbstractModule() {

        @Override
        protected void configure() {
            H2DBTestServer server = H2DBTestServer.startDefault();
            install(new JpaPersistModule("main"));
            bind(H2JpaCleaner.class).toInstance(new H2JpaCleaner(server));
            bind(EventService.class).in(Singleton.class);
            bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
            bind(DBInitializer.class).asEagerSingleton();
            install(new InitModule(PostConstruct.class));
            install(new UserJpaModule());
            install(new AccountModule());
            install(new SshJpaModule());
            install(new FactoryJpaModule());
            install(new OrganizationJpaModule());
            install(new MultiuserWorkspaceJpaModule());
            install(new MachineAuthModule());
            install(new DevfileModule());
            install(new MultiuserUserDevfileJpaModule());
            bind(ExecutorServiceWrapper.class).to(NoopExecutorServiceWrapper.class);
            bind(FreeResourcesLimitDao.class).to(JpaFreeResourcesLimitDao.class);
            bind(RemoveFreeResourcesLimitSubscriber.class).asEagerSingleton();
            // initialize empty binder
            Multibinder.newSetBinder(binder(), WorkspaceAttributeValidator.class);
            bind(WorkspaceManager.class);
            bind(WorkspaceLockService.class).to(DefaultWorkspaceLockService.class);
            bind(WorkspaceStatusCache.class).to(DefaultWorkspaceStatusCache.class);
            bind(RuntimeInfrastructure.class).toInstance(mock(RuntimeInfrastructure.class));
            MapBinder.newMapBinder(binder(), String.class, InternalEnvironmentFactory.class);
            bind(PermissionsManager.class);
            bind(PermissionChecker.class).to(PermissionCheckerImpl.class);
            bind(AccountManager.class);
            bind(Boolean.class).annotatedWith(Names.named("che.workspace.auto_snapshot")).toInstance(false);
            bind(Boolean.class).annotatedWith(Names.named("che.workspace.auto_restore")).toInstance(false);
            bind(Boolean.class).annotatedWith(Names.named("che.devworkspaces.enabled")).toInstance(false);
            bind(WorkspaceSharedPool.class).toInstance(new WorkspaceSharedPool("cached", null, null, new NoopExecutorServiceWrapper()));
            bind(String[].class).annotatedWith(Names.named("che.auth.reserved_user_names")).toInstance(new String[0]);
            bind(RemoveOrganizationOnLastUserRemovedEventSubscriber.class).asEagerSingleton();
            Multibinder.newSetBinder(binder(), ResourceLockKeyProvider.class);
            Multibinder.newSetBinder(binder(), ResourceUsageTracker.class);
            MapBinder.newMapBinder(binder(), String.class, AvailableResourcesProvider.class);
            bind(String.class).annotatedWith(Names.named("che.workspace.plugin_registry_url")).toInstance("");
            bind(String.class).annotatedWith(Names.named("che.factory.scm_file_fetcher_limit_bytes")).toInstance("1024");
            MapBinder.newMapBinder(binder(), String.class, ChePluginsApplier.class);
            Multibinder.newSetBinder(binder(), ResourceType.class).addBinding().to(RamResourceType.class);
            Multibinder.newSetBinder(binder(), ResourcesProvider.class).addBinding().toInstance((accountId) -> singletonList(new ProvidedResourcesImpl("test", null, accountId, -1L, -1L, singletonList(new ResourceImpl(RamResourceType.ID, 1024, RamResourceType.UNIT)))));
            bindConstant().annotatedWith(Names.named("che.workspace.probe_pool_size")).to(1);
            // setup bindings for the devfile that would otherwise be read from the config
            bindConstant().annotatedWith(Names.named("che.workspace.devfile.default_editor")).to("default/editor/0.0.1");
            bindConstant().annotatedWith(Names.named("che.websocket.endpoint")).to("che.websocket.endpoint");
            bind(String.class).annotatedWith(Names.named("che.workspace.devfile.default_editor.plugins")).toInstance("default/plugin/0.0.1");
            bind(String.class).annotatedWith(Names.named("che.workspace.devfile.async.storage.plugin")).toInstance("");
        }
    });
    eventService = injector.getInstance(EventService.class);
    accountDao = injector.getInstance(AccountDao.class);
    accountManager = injector.getInstance(AccountManager.class);
    userDao = injector.getInstance(UserDao.class);
    userManager = injector.getInstance(UserManager.class);
    preferenceDao = injector.getInstance(PreferenceDao.class);
    profileDao = injector.getInstance(ProfileDao.class);
    sshDao = injector.getInstance(SshDao.class);
    workspaceDao = injector.getInstance(WorkspaceDao.class);
    factoryDao = injector.getInstance(FactoryDao.class);
    workerDao = injector.getInstance(WorkerDao.class);
    userDevfileDao = injector.getInstance(UserDevfileDao.class);
    userDevfilePermissionDao = injector.getInstance(UserDevfilePermissionDao.class);
    signatureKeyDao = injector.getInstance(SignatureKeyDao.class);
    freeResourcesLimitDao = injector.getInstance(FreeResourcesLimitDao.class);
    organizationManager = injector.getInstance(OrganizationManager.class);
    memberDao = injector.getInstance(MemberDao.class);
    organizationResourcesDistributor = injector.getInstance(OrganizationResourcesDistributor.class);
    h2JpaCleaner = injector.getInstance(H2JpaCleaner.class);
}
Also used : RuntimeInfrastructure(org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure) ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ExecutorServiceWrapper(org.eclipse.che.commons.observability.ExecutorServiceWrapper) NoopExecutorServiceWrapper(org.eclipse.che.commons.observability.NoopExecutorServiceWrapper) UserDevfilePermissionDao(org.eclipse.che.multiuser.permission.devfile.server.spi.UserDevfilePermissionDao) UserJpaModule(org.eclipse.che.api.user.server.jpa.UserJpaModule) MemberDao(org.eclipse.che.multiuser.organization.spi.MemberDao) InitModule(org.eclipse.che.inject.lifecycle.InitModule) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) OrganizationManager(org.eclipse.che.multiuser.organization.api.OrganizationManager) NoopExecutorServiceWrapper(org.eclipse.che.commons.observability.NoopExecutorServiceWrapper) UserDevfileDao(org.eclipse.che.api.devfile.server.spi.UserDevfileDao) WorkspaceSharedPool(org.eclipse.che.api.workspace.server.WorkspaceSharedPool) SignatureKeyDao(org.eclipse.che.multiuser.machine.authentication.server.signature.spi.SignatureKeyDao) 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) ProfileDao(org.eclipse.che.api.user.server.spi.ProfileDao) WorkerDao(org.eclipse.che.multiuser.permission.workspace.server.spi.WorkerDao) UserDao(org.eclipse.che.api.user.server.spi.UserDao) DBInitializer(org.eclipse.che.core.db.DBInitializer) AccountModule(org.eclipse.che.account.api.AccountModule) PermissionChecker(org.eclipse.che.multiuser.api.permission.server.PermissionChecker) DevfileModule(org.eclipse.che.api.workspace.server.devfile.DevfileModule) FactoryDao(org.eclipse.che.api.factory.server.spi.FactoryDao) RemoveFreeResourcesLimitSubscriber(org.eclipse.che.multiuser.resource.spi.jpa.JpaFreeResourcesLimitDao.RemoveFreeResourcesLimitSubscriber) WorkspaceLockService(org.eclipse.che.api.workspace.server.WorkspaceLockService) DefaultWorkspaceLockService(org.eclipse.che.api.workspace.server.DefaultWorkspaceLockService) OrganizationResourcesDistributor(org.eclipse.che.multiuser.organization.api.resource.OrganizationResourcesDistributor) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) OrganizationJpaModule(org.eclipse.che.multiuser.organization.api.OrganizationJpaModule) DefaultWorkspaceStatusCache(org.eclipse.che.api.workspace.server.DefaultWorkspaceStatusCache) WorkspaceStatusCache(org.eclipse.che.api.workspace.server.WorkspaceStatusCache) MultiuserUserDevfileJpaModule(org.eclipse.che.multiuser.permission.devfile.server.jpa.MultiuserUserDevfileJpaModule) EventService(org.eclipse.che.api.core.notification.EventService) FactoryJpaModule(org.eclipse.che.api.factory.server.jpa.FactoryJpaModule) MultiuserWorkspaceJpaModule(org.eclipse.che.multiuser.permission.workspace.server.jpa.MultiuserWorkspaceJpaModule) AccountDao(org.eclipse.che.account.spi.AccountDao) PreferenceDao(org.eclipse.che.api.user.server.spi.PreferenceDao) SshDao(org.eclipse.che.api.ssh.server.spi.SshDao) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) AbstractModule(com.google.inject.AbstractModule) MachineAuthModule(org.eclipse.che.multiuser.machine.authentication.server.MachineAuthModule) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) UserManager(org.eclipse.che.api.user.server.UserManager) FreeResourcesLimitDao(org.eclipse.che.multiuser.resource.spi.FreeResourcesLimitDao) JpaFreeResourcesLimitDao(org.eclipse.che.multiuser.resource.spi.jpa.JpaFreeResourcesLimitDao) RemoveOrganizationOnLastUserRemovedEventSubscriber(org.eclipse.che.multiuser.organization.api.listener.RemoveOrganizationOnLastUserRemovedEventSubscriber) AccountManager(org.eclipse.che.account.api.AccountManager) SshJpaModule(org.eclipse.che.api.ssh.server.jpa.SshJpaModule) PostConstruct(jakarta.annotation.PostConstruct) WorkspaceDao(org.eclipse.che.api.workspace.server.spi.WorkspaceDao) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 99 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class JpaEntitiesCascadeRemovalTest method createTestData.

private void createTestData() throws NotFoundException, ConflictException, ServerException, NoSuchAlgorithmException {
    userDao.create(user = createUser("bobby"));
    accountDao.create(account = createAccount("bobby"));
    // test permissions users
    userDao.create(user2 = createUser("worker"));
    userDao.create(user3 = createUser("stacker"));
    profileDao.create(profile = createProfile(user.getId()));
    preferenceDao.setPreferences(user.getId(), preferences = createPreferences());
    workspaceDao.create(workspace1 = createWorkspace("workspace1", account));
    workspaceDao.create(workspace2 = createWorkspace("workspace2", account));
    workspaceDao.create(workspace3 = createWorkspace("workspace3", account));
    sshDao.create(sshPair1 = createSshPair(user.getId(), "service", "name1"));
    sshDao.create(sshPair2 = createSshPair(user.getId(), "service", "name2"));
    factoryDao.create(factory1 = createFactory("factory1", user.getId()));
    factoryDao.create(factory2 = createFactory("factory2", user.getId()));
    workerDao.store(createWorker(user2.getId(), workspace3.getId()));
    signatureKeyDao.create(createSignatureKeyPair(workspace1.getId()));
    signatureKeyDao.create(createSignatureKeyPair(workspace2.getId()));
    // creator will have all permissions for newly created organization
    prepareCreator(user.getId());
    organization = organizationManager.create(new OrganizationImpl(null, "testOrg", null));
    organizationalAccount = accountDao.getById(organization.getId());
    workspaceDao.create(workspace4 = createWorkspace("workspace4", organizationalAccount));
    organization2 = organizationManager.create(new OrganizationImpl(null, "anotherOrg", null));
    prepareCreator(user2.getId());
    childOrganization = organizationManager.create(new OrganizationImpl(null, "childTestOrg", organization.getId()));
    memberDao.store(new MemberImpl(user2.getId(), organization2.getId(), singletonList(SET_PERMISSIONS)));
    memberDao.store(new MemberImpl(user3.getId(), organization2.getId(), singletonList(SET_PERMISSIONS)));
    freeResourcesLimitDao.store(freeResourcesLimit = createFreeResourcesLimit(account.getId()));
    freeResourcesLimitDao.store(freeResourcesLimit2 = createFreeResourcesLimit(organization.getId()));
    organizationResourcesDistributor.capResources(childOrganization.getId(), singletonList(new ResourceImpl(RamResourceType.ID, 1024, RamResourceType.UNIT)));
    userDevfileDao.create(devfile = TestObjectsFactory.createUserDevfile("id-dev1", "devfile1", account));
    userDevfilePermissionDao.store(devfilePermission = new UserDevfilePermissionImpl(devfile.getId(), user2.getId(), ImmutableList.of(READ, DELETE, UPDATE)));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) UserDevfilePermissionImpl(org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)

Example 100 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class FreeResourcesLimitDaoTest method shouldUpdateResourcesLimitWhenStoringExistentOne.

@Test
public void shouldUpdateResourcesLimitWhenStoringExistentOne() throws Exception {
    // given
    FreeResourcesLimitImpl toStore = new FreeResourcesLimitImpl(limits[0].getAccountId(), singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    // when
    limitDao.store(toStore);
    // then
    assertEquals(limitDao.get(toStore.getAccountId()), new FreeResourcesLimitImpl(toStore));
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Aggregations

ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)138 Test (org.testng.annotations.Test)116 Resource (org.eclipse.che.multiuser.resource.model.Resource)24 NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)20 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)20 ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)14 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)12 NotFoundException (org.eclipse.che.api.core.NotFoundException)10 AccountManager (org.eclipse.che.account.api.AccountManager)8 Account (org.eclipse.che.account.shared.model.Account)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)8 ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)8 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)8 Response (io.restassured.response.Response)6 Optional (java.util.Optional)6 Inject (javax.inject.Inject)6 Provider (javax.inject.Provider)6 Singleton (javax.inject.Singleton)6 Pages (org.eclipse.che.api.core.Pages)6