Search in sources :

Example 21 with GuestId

use of org.candlepin.model.GuestId in project candlepin by candlepin.

the class GuestIdResourceTest method deleteGuestNoConsumer.

@Test
public void deleteGuestNoConsumer() {
    GuestId guest = new GuestId("guest-id", consumer);
    when(guestIdCurator.findByConsumerAndId(eq(consumer), eq(guest.getGuestId()))).thenReturn(guest);
    when(consumerCurator.findByVirtUuid(guest.getGuestId(), consumer.getOwnerId())).thenReturn(null);
    guestIdResource.deleteGuest(consumer.getUuid(), guest.getGuestId(), false, null);
    Mockito.verify(guestIdCurator, Mockito.times(1)).delete(eq(guest));
    Mockito.verify(consumerResource, Mockito.never()).checkForMigration(eq(consumer), any(Consumer.class));
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Test(org.junit.Test)

Example 22 with GuestId

use of org.candlepin.model.GuestId in project candlepin by candlepin.

the class AutobindRulesTest method guestLimitAutobindServerAttachedNonStackable.

/*
     * If the hypervisor is already installed, and at least partially
     * subscribed, autobind will be able to cover the server subscription
     */
@Test
public void guestLimitAutobindServerAttachedNonStackable() {
    consumer.setFact("cpu.cpu_socket(s)", "2");
    for (int i = 0; i < 5; i++) {
        consumer.addGuestId(new GuestId("" + i, consumer, activeGuestAttrs));
    }
    Product server = mockProduct(productId, "some server", "2");
    server.setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    Product hypervisor = mockProduct("hypervisor", "some hypervisor", "2");
    hypervisor.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    Pool serverPool = TestUtil.createPool(owner, server, 10);
    Pool hyperPool = TestUtil.createPool(owner, hypervisor, 10);
    serverPool.setId("POOL-ID1");
    hyperPool.setId("Pool-ID2");
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.setPool(hyperPool);
    // compliant
    entitlement.setQuantity(1);
    // The hypervisor must be installed and entitled on the system for autobind
    // to pick up the unlimited guest_limit
    compliance.addCompliantProduct(hypervisor.getId(), entitlement);
    List<Pool> pools = new LinkedList<>();
    pools.add(serverPool);
    pools.add(hyperPool);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { server.getId() }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    assertEquals(new Integer(1), bestPools.get(0).getQuantity());
    assertEquals("POOL-ID1", bestPools.get(0).getPool().getId());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 23 with GuestId

use of org.candlepin.model.GuestId in project candlepin by candlepin.

the class AutobindRulesTest method guestLimitAutobindServerAttached.

/*
     * If the hypervisor is already installed, and at least partially
     * subscribed, autobind will be able to cover the server subscription
     */
@Test
public void guestLimitAutobindServerAttached() {
    consumer.setFact("cpu.cpu_socket(s)", "8");
    for (int i = 0; i < 5; i++) {
        consumer.addGuestId(new GuestId("" + i, consumer, activeGuestAttrs));
    }
    Product server = mockStackingProduct(productId, "some server", "stackid1", "2");
    server.setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    Product hypervisor = mockStackingProduct("hypervisor", "some hypervisor", "stackid2", "2");
    hypervisor.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    Pool serverPool = TestUtil.createPool(owner, server, 10);
    Pool hyperPool = TestUtil.createPool(owner, hypervisor, 10);
    serverPool.setId("POOL-ID1");
    hyperPool.setId("Pool-ID2");
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.setPool(hyperPool);
    // compliant
    entitlement.setQuantity(4);
    // The hypervisor must be installed and entitled on the system for autobind
    // to pick up the unlimited guest_limit
    compliance.addCompliantProduct(hypervisor.getId(), entitlement);
    List<Pool> pools = new LinkedList<>();
    pools.add(serverPool);
    pools.add(hyperPool);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { server.getId() }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    assertEquals(new Integer(4), bestPools.get(0).getQuantity());
    assertEquals("POOL-ID1", bestPools.get(0).getPool().getId());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 24 with GuestId

use of org.candlepin.model.GuestId in project candlepin by candlepin.

the class ConsumerResource method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO, during consumer creation (not update).
 * This method will not set the ID, entitlementStatus, complianceStatusHash, idCert, entitlements,
 * keyPair and canActivate, because clients are not allowed to create or update those properties.
 *
 * while autoheal is populated, it is overridden in create method.
 *
 * owner is not populated because create populates it differently.
 *
 * @param entity
 *  The entity instance to populate
 *
 * @param dto
 *  The DTO containing the data with which to populate the entity
 *
 * @throws IllegalArgumentException
 *  if either entity or dto are null
 */
protected void populateEntity(Consumer entity, ConsumerDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the consumer model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the consumer dto is null");
    }
    if (dto.getCreated() != null) {
        entity.setCreated(dto.getCreated());
    }
    if (dto.getName() != null) {
        entity.setName(dto.getName());
    }
    if (dto.getUuid() != null) {
        entity.setUuid(dto.getUuid());
    }
    if (dto.getFacts() != null) {
        entity.setFacts(dto.getFacts());
    }
    if (dto.getUsername() != null) {
        entity.setUsername(dto.getUsername());
    }
    if (dto.getServiceLevel() != null) {
        entity.setServiceLevel(dto.getServiceLevel());
    }
    if (dto.getReleaseVersion() != null) {
        entity.setReleaseVer(new Release(dto.getReleaseVersion()));
    }
    if (dto.getEnvironment() != null) {
        Environment env = environmentCurator.find(dto.getEnvironment().getId());
        if (env == null) {
            throw new NotFoundException(i18n.tr("Environment \"{0}\" could not be found.", dto.getEnvironment().getId()));
        }
        entity.setEnvironment(env);
    }
    if (dto.getLastCheckin() != null) {
        entity.setLastCheckin(dto.getLastCheckin());
    }
    if (dto.getCapabilities() != null) {
        Set<ConsumerCapability> capabilities = populateCapabilities(entity, dto);
        entity.setCapabilities(capabilities);
    }
    if (dto.getGuestIds() != null) {
        List<GuestId> guestIds = new ArrayList<>();
        for (GuestIdDTO guestIdDTO : dto.getGuestIds()) {
            if (guestIdDTO != null) {
                guestIds.add(new GuestId(guestIdDTO.getGuestId(), entity, guestIdDTO.getAttributes()));
            }
        }
        entity.setGuestIds(guestIds);
    }
    if (dto.getHypervisorId() != null && entity.getOwnerId() != null) {
        HypervisorId hypervisorId = new HypervisorId(entity, ownerCurator.findOwnerById(entity.getOwnerId()), dto.getHypervisorId().getHypervisorId(), dto.getHypervisorId().getReporterId());
        entity.setHypervisorId(hypervisorId);
    }
    if (dto.getHypervisorId() == null && dto.getFact("system_uuid") != null && !"true".equals(dto.getFact("virt.is_guest")) && entity.getOwnerId() != null) {
        HypervisorId hypervisorId = new HypervisorId(entity, ownerCurator.findOwnerById(entity.getOwnerId()), dto.getFact("system_uuid"));
        entity.setHypervisorId(hypervisorId);
    }
    if (dto.getContentTags() != null) {
        entity.setContentTags(dto.getContentTags());
    }
    if (dto.getAutoheal() != null) {
        entity.setAutoheal(dto.getAutoheal());
    }
    if (dto.getContentAccessMode() != null) {
        entity.setContentAccessMode(dto.getContentAccessMode());
    }
    if (dto.getRecipientOwnerKey() != null) {
        entity.setRecipientOwnerKey(dto.getRecipientOwnerKey());
    }
    if (dto.getAnnotations() != null) {
        entity.setAnnotations(dto.getAnnotations());
    }
    if (dto.getInstalledProducts() != null) {
        Set<ConsumerInstalledProduct> installedProducts = populateInstalledProducts(entity, dto);
        entity.setInstalledProducts(installedProducts);
    }
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ConsumerCapability(org.candlepin.model.ConsumerCapability) GuestId(org.candlepin.model.GuestId) Environment(org.candlepin.model.Environment) HypervisorId(org.candlepin.model.HypervisorId) Release(org.candlepin.model.Release)

Example 25 with GuestId

use of org.candlepin.model.GuestId in project candlepin by candlepin.

the class GuestIdResource method deleteGuest.

@ApiOperation(notes = "Removes the Guest from the Consumer", value = "deleteGuest")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("/{guest_id}")
public void deleteGuest(@ApiParam("consumer who owns or hosts the guest in question") @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @PathParam("guest_id") String guestId, @QueryParam("unregister") @DefaultValue("false") boolean unregister, @Context Principal principal) {
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    GuestId toDelete = validateGuestId(guestIdCurator.findByConsumerAndId(consumer, guestId), guestId);
    if (unregister) {
        unregisterConsumer(toDelete, principal);
    }
    sink.queueEvent(eventFactory.guestIdDeleted(toDelete));
    guestIdCurator.delete(toDelete);
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

GuestId (org.candlepin.model.GuestId)49 Consumer (org.candlepin.model.Consumer)37 Test (org.junit.Test)34 LinkedList (java.util.LinkedList)15 Entitlement (org.candlepin.model.Entitlement)14 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)11 Date (java.util.Date)10 HashMap (java.util.HashMap)8 Product (org.candlepin.model.Product)8 ArrayList (java.util.ArrayList)7 Owner (org.candlepin.model.Owner)7 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 List (java.util.List)5 Pool (org.candlepin.model.Pool)5 ApiOperation (io.swagger.annotations.ApiOperation)4 Produces (javax.ws.rs.Produces)4 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4