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));
}
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);
}
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();
}
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();
}
}
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));
}
}
}
Aggregations