use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.
the class JpaOrganizationDistributedResourcesDao method getByParent.
@Override
@Transactional
public Page<OrganizationDistributedResourcesImpl> getByParent(String organizationId, int maxItems, long skipCount) throws ServerException {
requireNonNull(organizationId, "Required non-null organization id");
checkArgument(skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE);
try {
final EntityManager manager = managerProvider.get();
final List<OrganizationDistributedResourcesImpl> distributedResources = manager.createNamedQuery("OrganizationDistributedResources.getByParent", OrganizationDistributedResourcesImpl.class).setParameter("parent", organizationId).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList();
final Long distributedResourcesCount = manager.createNamedQuery("OrganizationDistributedResources.getCountByParent", Long.class).setParameter("parent", organizationId).getSingleResult();
return new Page<>(distributedResources.stream().map(OrganizationDistributedResourcesImpl::new).collect(Collectors.toList()), skipCount, maxItems, distributedResourcesCount);
} catch (RuntimeException e) {
throw new ServerException(e.getMessage(), e);
}
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.
the class OrganizationResourcesDistributorTest method shouldCapResources.
@Test
public void shouldCapResources() throws Exception {
List<ResourceImpl> toCap = singletonList(createTestResource(1000));
// when
manager.capResources(ORG_ID, toCap);
// then
verify(manager).checkResourcesAvailability(ORG_ID, toCap);
verify(distributedResourcesDao).store(new OrganizationDistributedResourcesImpl(ORG_ID, toCap));
verify(resourcesLocks).lock(ORG_ID);
verify(lock).close();
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.
the class OrganizationDistributedResourcesDaoTest method shouldRemoveDistributedResources.
@Test(expectedExceptions = NotFoundException.class)
public void shouldRemoveDistributedResources() throws Exception {
// given
OrganizationDistributedResourcesImpl distributedResource = distributedResources[0];
// when
distributedResourcesDao.remove(distributedResource.getOrganizationId());
// then
distributedResourcesDao.get(distributedResource.getOrganizationId());
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project che-server by eclipse-che.
the class OrganizationDistributedResourcesDaoTest method shouldUpdateDistributedResourcesWhenStoringExistentOne.
@Test
public void shouldUpdateDistributedResourcesWhenStoringExistentOne() throws Exception {
// given
OrganizationDistributedResourcesImpl toStore = new OrganizationDistributedResourcesImpl(distributedResources[0].getOrganizationId(), singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
// when
distributedResourcesDao.store(toStore);
// then
assertEquals(distributedResourcesDao.get(toStore.getOrganizationId()), copy(toStore));
}
use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl in project devspaces-images by redhat-developer.
the class OrganizationResourcesDistributorTest method shouldRemoveResourceFromListWhenItsAmountEqualsToMinusOne.
@Test
public void shouldRemoveResourceFromListWhenItsAmountEqualsToMinusOne() throws Exception {
ResourceImpl toCap = new ResourceImpl("test1", 1000, "init");
ResourceImpl toReset = new ResourceImpl("test2", -1, "init");
List<ResourceImpl> resourcesToCap = asList(toCap, toReset);
// when
manager.capResources(ORG_ID, resourcesToCap);
// then
verify(manager).checkResourcesAvailability(ORG_ID, singletonList(toCap));
verify(distributedResourcesDao).store(new OrganizationDistributedResourcesImpl(ORG_ID, singletonList(toCap)));
verify(resourcesLocks).lock(ORG_ID);
verify(lock).close();
}
Aggregations