Search in sources :

Example 16 with OrganizationDistributedResourcesImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.

the class OrganizationDistributedResourcesDaoTest method shouldGetDistributedResourcesForSpecifiedOrganizationId.

@Test
public void shouldGetDistributedResourcesForSpecifiedOrganizationId() throws Exception {
    // given
    OrganizationDistributedResourcesImpl stored = distributedResources[0];
    // when
    OrganizationDistributedResourcesImpl fetched = distributedResourcesDao.get(stored.getOrganizationId());
    // then
    assertEquals(fetched, copy(stored));
}
Also used : OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 17 with OrganizationDistributedResourcesImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.

the class OrganizationJpaTckModule method configure.

@Override
protected void configure() {
    install(new JpaPersistModule("main"));
    H2DBTestServer server = H2DBTestServer.startDefault();
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(DBInitializer.class).asEagerSingleton();
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
    bind(new TypeLiteral<AbstractPermissionsDomain<MemberImpl>>() {
    }).to(OrganizationDomain.class);
    bind(new TypeLiteral<TckRepository<OrganizationImpl>>() {
    }).to(JpaOrganizationImplTckRepository.class);
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).toInstance(new JpaTckRepository<>(UserImpl.class));
    bind(new TypeLiteral<TckRepository<MemberImpl>>() {
    }).toInstance(new JpaTckRepository<>(MemberImpl.class));
    bind(new TypeLiteral<TckRepository<OrganizationDistributedResourcesImpl>>() {
    }).toInstance(new JpaTckRepository<>(OrganizationDistributedResourcesImpl.class));
    bind(OrganizationDao.class).to(JpaOrganizationDao.class);
    bind(MemberDao.class).to(JpaMemberDao.class);
    bind(OrganizationDistributedResourcesDao.class).to(JpaOrganizationDistributedResourcesDao.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) MemberImpl(org.eclipse.che.multiuser.organization.spi.impl.MemberImpl) OrganizationDistributedResourcesDao(org.eclipse.che.multiuser.organization.spi.OrganizationDistributedResourcesDao) JpaOrganizationDistributedResourcesDao(org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDistributedResourcesDao) MemberDao(org.eclipse.che.multiuser.organization.spi.MemberDao) JpaMemberDao(org.eclipse.che.multiuser.organization.spi.jpa.JpaMemberDao) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) 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) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) JpaOrganizationDao(org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDao) OrganizationDao(org.eclipse.che.multiuser.organization.spi.OrganizationDao)

Example 18 with OrganizationDistributedResourcesImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.

the class JpaOrganizationDistributedResourcesDao method doStore.

@Transactional
protected void doStore(OrganizationDistributedResourcesImpl distributedResources) throws ServerException {
    EntityManager manager = managerProvider.get();
    final OrganizationDistributedResourcesImpl existingDistributedResources = manager.find(OrganizationDistributedResourcesImpl.class, distributedResources.getOrganizationId());
    if (existingDistributedResources == null) {
        manager.persist(distributedResources);
    } else {
        existingDistributedResources.getResourcesCap().clear();
        existingDistributedResources.getResourcesCap().addAll(distributedResources.getResourcesCap());
    }
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Transactional(com.google.inject.persist.Transactional)

Example 19 with OrganizationDistributedResourcesImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.

the class JpaOrganizationDistributedResourcesDao method doRemove.

@Transactional
protected void doRemove(String id) {
    EntityManager manager = managerProvider.get();
    OrganizationDistributedResourcesImpl distributedResources = manager.find(OrganizationDistributedResourcesImpl.class, id);
    if (distributedResources != null) {
        manager.remove(distributedResources);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Transactional(com.google.inject.persist.Transactional)

Example 20 with OrganizationDistributedResourcesImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.

the class OrganizationResourcesDistributor method capResources.

/**
 * Cap usage of shared resources.
 *
 * <p>By default suborganization is able to use all parent organization resources Cap allow to
 * limit usage of shared resources by suborganization.
 *
 * @param suborganizationId suborganization id
 * @param resourcesCaps resources to capped
 * @throws NotFoundException when specified suborganization was not found
 * @throws ConflictException when organization with specified id is root organization
 * @throws ConflictException when suborganization is currently using more shared resources than
 *     should be capped
 * @throws ServerException when any other error occurs
 */
public void capResources(String suborganizationId, List<? extends Resource> resourcesCaps) throws NotFoundException, ConflictException, ServerException {
    requireNonNull(suborganizationId, "Required non-null suborganization id");
    requireNonNull(resourcesCaps, "Required non-null resources to capResources");
    checkIsSuborganization(suborganizationId);
    // remove caps with amount -1
    resourcesCaps = resourcesCaps.stream().filter(res -> res.getAmount() != -1).collect(toList());
    // so we can check resource availability for suborganization organization
    try (@SuppressWarnings("unused") Unlocker u = resourcesLocks.lock(suborganizationId)) {
        if (resourcesCaps.isEmpty()) {
            organizationDistributedResourcesDao.remove(suborganizationId);
        } else {
            checkResourcesAvailability(suborganizationId, resourcesCaps);
            organizationDistributedResourcesDao.store(new OrganizationDistributedResourcesImpl(suborganizationId, resourcesCaps));
        }
    }
}
Also used : Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)

Aggregations

OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)32 Test (org.testng.annotations.Test)16 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)8 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)8 TypeLiteral (com.google.inject.TypeLiteral)6 Transactional (com.google.inject.persist.Transactional)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)6 DBInitializer (org.eclipse.che.core.db.DBInitializer)6 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)6 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)6 MemberDao (org.eclipse.che.multiuser.organization.spi.MemberDao)6 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)6 OrganizationDistributedResourcesDao (org.eclipse.che.multiuser.organization.spi.OrganizationDistributedResourcesDao)6 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)6 JpaMemberDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaMemberDao)6 JpaOrganizationDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDao)6 JpaOrganizationDistributedResourcesDao (org.eclipse.che.multiuser.organization.spi.jpa.JpaOrganizationDistributedResourcesDao)6 HashMap (java.util.HashMap)4