Search in sources :

Example 1 with OrganizationDistributedResourcesImpl

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);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) Page(org.eclipse.che.api.core.Page) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Transactional(com.google.inject.persist.Transactional)

Example 2 with OrganizationDistributedResourcesImpl

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();
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 3 with OrganizationDistributedResourcesImpl

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());
}
Also used : OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 4 with OrganizationDistributedResourcesImpl

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));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 5 with OrganizationDistributedResourcesImpl

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();
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

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