use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.
the class HypervisorUpdateJobTest method hypervisorUpdateExecCreate.
@Test
public void hypervisorUpdateExecCreate() throws JobExecutionException {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
verify(consumerCurator).create(any(Consumer.class), eq(false));
}
use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.
the class HypervisorUpdateJobTest method hypervisorUpdateExecUpdate.
@Test
public void hypervisorUpdateExecUpdate() throws JobExecutionException {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
Consumer hypervisor = new Consumer();
String hypervisorId = "uuid_999";
hypervisor.setHypervisorId(new HypervisorId(hypervisorId));
VirtConsumerMap vcm = new VirtConsumerMap();
vcm.add(hypervisorId, hypervisor);
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(vcm);
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
verify(consumerResource).checkForFactsUpdate(any(Consumer.class), any(Consumer.class));
verify(consumerCurator).update(any(Consumer.class), eq(false));
}
use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.
the class HypervisorUpdateJobTest method hypervisorUpdateIgnoresEmptyGuestIds.
@Test
public void hypervisorUpdateIgnoresEmptyGuestIds() throws Exception {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
hypervisorJson = "{\"hypervisors\":" + "[{" + "\"hypervisorId\" : {\"hypervisorId\" : \"hypervisor_999\"}," + "\"name\" : \"hypervisor_999\"," + "\"guestIds\" : [{\"guestId\" : \"guestId_1_999\"}, {\"guestId\" : \"\"}]" + "}]}";
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
}
use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.
the class GuestIdResource method updateGuests.
@ApiOperation(notes = "Updates the List of Guests on a Consumer This method should work " + "just like updating the consumer, except that it only updates GuestIds. " + " Eventually we should move All the logic here, and depricate updating guests " + "through the consumer update.", value = "updateGuests")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void updateGuests(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @ApiParam(name = "guestIds", required = true) List<GuestIdDTO> guestIdDTOs) {
Consumer toUpdate = consumerCurator.findByUuid(consumerUuid);
// Create a skeleton consumer for consumerResource.performConsumerUpdates
ConsumerDTO consumer = new ConsumerDTO();
consumer.setGuestIds(guestIdDTOs);
Set<String> allGuestIds = new HashSet<>();
for (GuestIdDTO gid : consumer.getGuestIds()) {
allGuestIds.add(gid.getGuestId());
}
VirtConsumerMap guestConsumerMap = consumerCurator.getGuestConsumersMap(toUpdate.getOwnerId(), allGuestIds);
GuestMigration guestMigration = migrationProvider.get().buildMigrationManifest(consumer, toUpdate);
if (consumerResource.performConsumerUpdates(consumer, toUpdate, guestMigration)) {
if (guestMigration.isMigrationPending()) {
guestMigration.migrate();
} else {
consumerCurator.update(toUpdate);
}
}
}
use of org.candlepin.model.VirtConsumerMap in project candlepin by candlepin.
the class HypervisorResourceTest method hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
@Test
public void hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists() throws Exception {
Owner owner = new Owner("owner-id", "Owner Id");
Map<String, List<GuestIdDTO>> hostGuestMap = new HashMap<>();
String hypervisorId = "test-host";
hostGuestMap.put(hypervisorId, new ArrayList(Arrays.asList(TestUtil.createGuestIdDTO("GUEST_B"))));
Owner o = new Owner("owner-id", "Owner ID");
o.setId("owner-id");
Consumer existing = new Consumer();
existing.setUuid("test-host");
existing.setOwner(o);
existing.addGuestId(new GuestId("GUEST_A"));
existing.setType(this.hypervisorType);
when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
// Force update
when(consumerCurator.getHostConsumersMap(any(Owner.class), any(Set.class))).thenReturn(mockHypervisorConsumerMap(hypervisorId, existing));
when(consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorCheckInResult result = hypervisorResource.hypervisorUpdate(hostGuestMap, principal, owner.getKey(), true);
List<Consumer> updated = new ArrayList<>(result.getUpdated());
assertEquals(1, updated.size());
Consumer c1 = updated.get(0);
assertEquals("test-host", c1.getUuid());
assertEquals(1, c1.getGuestIds().size());
assertEquals("GUEST_B", c1.getGuestIds().get(0).getGuestId());
}
Aggregations