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