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