Search in sources :

Example 6 with VirtConsumerMap

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));
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) JobExecutionContext(org.quartz.JobExecutionContext) Test(org.junit.Test)

Example 7 with VirtConsumerMap

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));
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) HypervisorId(org.candlepin.model.HypervisorId) JobExecutionContext(org.quartz.JobExecutionContext) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 8 with VirtConsumerMap

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);
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) JobExecutionContext(org.quartz.JobExecutionContext) Test(org.junit.Test)

Example 9 with VirtConsumerMap

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);
        }
    }
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) GuestMigration(org.candlepin.resource.util.GuestMigration) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 10 with VirtConsumerMap

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());
}
Also used : Owner(org.candlepin.model.Owner) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) GuestId(org.candlepin.model.GuestId) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) HypervisorCheckInResult(org.candlepin.resource.dto.HypervisorCheckInResult) Test(org.junit.Test)

Aggregations

VirtConsumerMap (org.candlepin.model.VirtConsumerMap)23 Set (java.util.Set)18 Consumer (org.candlepin.model.Consumer)18 Test (org.junit.Test)18 Owner (org.candlepin.model.Owner)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 List (java.util.List)8 HypervisorCheckInResult (org.candlepin.resource.dto.HypervisorCheckInResult)8 HashSet (java.util.HashSet)7 GuestId (org.candlepin.model.GuestId)7 JobDetail (org.quartz.JobDetail)7 JobExecutionContext (org.quartz.JobExecutionContext)7 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)6 IdentityCertificate (org.candlepin.model.IdentityCertificate)6 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)4 Transactional (com.google.inject.persist.Transactional)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2