Search in sources :

Example 1 with GuestId

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

the class GuestMigration method buildMigrationManifest.

/**
 * Build a manifest detailing any guest migrations occurring due to a host consumer update.
 *
 * If a consumer's guest was already reported by another host consumer, record that host in the
 * manifest as well so that the migration can be made atomically.
 *
 * @param incoming incoming consumer
 * @param existing existing consumer
 * @return guestMigration object that contains all information related to the migration
 */
public GuestMigration buildMigrationManifest(Consumer incoming, Consumer existing) {
    if (incoming.getGuestIds() == null) {
        log.debug("Guests not included in this consumer update, skipping update.");
        migrationPending = false;
        return this;
    }
    manifest = new MigrationManifest(existing);
    log.debug("Updating {} guest IDs.", incoming.getGuestIds().size());
    List<GuestId> existingGuests = existing.getGuestIds();
    List<GuestId> removedGuests = getRemovedGuestIds(existing, incoming.getGuestIds());
    List<GuestId> addedGuests = getAddedGuestIds(existing, incoming.getGuestIds());
    // remove guests that are missing.
    if (existingGuests != null) {
        for (GuestId guestId : removedGuests) {
            existingGuests.remove(guestId);
            log.debug("Guest ID removed: {}", guestId);
        }
    }
    // Check guests that are existing/added.
    for (GuestId guestId : incoming.getGuestIds()) {
        if (addedGuests.contains(guestId)) {
            manifest.addGuestId(guestId);
            log.debug("New guest ID added: {}", guestId);
        }
    }
    migrationPending = removedGuests.size() != 0 || addedGuests.size() != 0;
    return this;
}
Also used : GuestId(org.candlepin.model.GuestId)

Example 2 with GuestId

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

the class GuestIdTranslatorTest method initSourceObject.

@Override
protected GuestId initSourceObject() {
    GuestId source = new GuestId();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("attrib_1", "attrib_value_1");
    attributes.put("attrib_2", "attrib_value_2");
    attributes.put("attrib_3", "attrib_value_3");
    source.setId("test_id");
    source.setGuestId("test_guest_id");
    source.setAttributes(attributes);
    return source;
}
Also used : GuestId(org.candlepin.model.GuestId) HashMap(java.util.HashMap)

Example 3 with GuestId

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

the class QuantityRulesTest method testInsufficientGuestLimit.

/*
     * Guest limit should not have any bearing on the suggested quantity
     */
@Test
public void testInsufficientGuestLimit() {
    consumer.setFact(SOCKET_FACT, "8");
    Map<String, String> guestAttrs = new HashMap<>();
    guestAttrs.put("virtWhoType", "libvirt");
    guestAttrs.put("active", "1");
    for (int i = 0; i < 5; i++) {
        consumer.addGuestId(new GuestId("" + i, consumer, guestAttrs));
    }
    pool.getProduct().setAttribute(GUEST_LIMIT_ATTRIBUTE, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    pool.setQuantity(new Long(-1));
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(4), suggested.getSuggested());
}
Also used : HashMap(java.util.HashMap) GuestId(org.candlepin.model.GuestId) Date(java.util.Date) Test(org.junit.Test)

Example 4 with GuestId

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

the class ConsumerResourceUpdateTest method createConsumerWithGuests.

private Consumer createConsumerWithGuests(Owner owner, String... guestIds) {
    Consumer a = new Consumer();
    ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.HYPERVISOR);
    this.mockConsumerType(ctype);
    a.setType(ctype);
    a.setOwner(owner);
    for (String guestId : guestIds) {
        a.addGuestId(new GuestId(guestId));
    }
    return a;
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) ConsumerType(org.candlepin.model.ConsumerType)

Example 5 with GuestId

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

the class ConsumerResourceUpdateTest method testGuestListEquality.

@Test
public void testGuestListEquality() throws Exception {
    Consumer a = new Consumer();
    a.addGuestId(new GuestId("Guest A"));
    a.addGuestId(new GuestId("Guest B"));
    a.addGuestId(new GuestId("Guest C"));
    Consumer b = new Consumer();
    b.addGuestId(new GuestId("Guest A"));
    b.addGuestId(new GuestId("Guest B"));
    b.addGuestId(new GuestId("Guest C"));
    Consumer c = new Consumer();
    c.addGuestId(new GuestId("Guest A"));
    c.addGuestId(new GuestId("Guest C"));
    Consumer d = new Consumer();
    d.addGuestId(new GuestId("Guest A"));
    d.addGuestId(new GuestId("Guest B"));
    d.addGuestId(new GuestId("Guest D"));
    assertEquals(a.getGuestIds(), b.getGuestIds());
    assertFalse(a.getGuestIds().equals(c.getGuestIds()));
    assertFalse(a.getGuestIds().equals(d.getGuestIds()));
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Test(org.junit.Test)

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