Search in sources :

Example 51 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO 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 in DTO form
 * @param existing existing consumer in model form
 * @return guestMigration object that contains all information related to the migration
 */
public GuestMigration buildMigrationManifest(ConsumerDTO 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();
    // Transform incoming GuestIdDTOs to GuestIds
    List<GuestId> incomingGuestIds = incoming.getGuestIds().stream().filter(Objects::nonNull).map(guestIdDTO -> new GuestId(guestIdDTO.getGuestId(), existing, guestIdDTO.getAttributes())).collect(Collectors.toList());
    List<GuestId> removedGuests = getRemovedGuestIds(existing, incomingGuestIds);
    List<GuestId> addedGuests = getAddedGuestIds(existing, incomingGuestIds);
    // 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 : incomingGuestIds) {
        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 : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects(java.util.Objects) Inject(javax.inject.Inject) ConsumerCurator(org.candlepin.model.ConsumerCurator) List(java.util.List) Map(java.util.Map) Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) GuestId(org.candlepin.model.GuestId) Objects(java.util.Objects)

Example 52 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceCreationTest method registerWithNoReleaseVer.

@Test
public void registerWithNoReleaseVer() {
    Principal p = new TrustedUserPrincipal("anyuser");
    ConsumerDTO consumer = TestUtil.createConsumerDTO("consumername", null, null, systemDto);
    resource.create(consumer, p, USER, owner.getKey(), null, true);
}
Also used : TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Example 53 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceCreationTest method registerWithNoInstalledProducts.

@Test
public void registerWithNoInstalledProducts() {
    Principal p = new TrustedUserPrincipal("anyuser");
    ConsumerDTO consumer = TestUtil.createConsumerDTO("consumerName", null, null, systemDto);
    resource.create(consumer, p, USER, owner.getKey(), null, true);
}
Also used : TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Example 54 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceCreationTest method setStatusOnCreate.

@Test
public void setStatusOnCreate() {
    Principal p = new TrustedUserPrincipal("anyuser");
    ConsumerDTO consumer = TestUtil.createConsumerDTO("consumername", null, null, systemDto);
    resource.create(consumer, p, USER, owner.getKey(), null, true);
    // Should be called with the consumer, null date (now),
    // no compliantUntil, and not update the consumer record
    verify(complianceRules).getStatus(any(Consumer.class), eq((Date) null), eq(false), eq(false));
}
Also used : TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Date(java.util.Date) Test(org.junit.Test)

Example 55 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceCreationTest method failIfOnlyActivationKeyDoesNotExistForOrg.

@Test(expected = BadRequestException.class)
public void failIfOnlyActivationKeyDoesNotExistForOrg() {
    Principal p = new NoAuthPrincipal();
    List<String> keys = new ArrayList<>();
    keys.add("NoSuchKey");
    ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, systemDto);
    resource.create(consumer, p, null, owner.getKey(), createKeysString(keys), true);
}
Also used : NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)70 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)64 Consumer (org.candlepin.model.Consumer)37 UserPrincipal (org.candlepin.auth.UserPrincipal)19 Owner (org.candlepin.model.Owner)19 ConsumerType (org.candlepin.model.ConsumerType)16 HashSet (java.util.HashSet)15 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)15 Principal (org.candlepin.auth.Principal)14 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)13 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)12 Set (java.util.Set)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)8 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)7 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)7 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)7 Entitlement (org.candlepin.model.Entitlement)5