Search in sources :

Example 6 with ImportRecord

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

the class ImportRecordJobTest method singleOwner.

@Test
public void singleOwner() throws Exception {
    Owner owner = new Owner("owner");
    ownerCurator.create(owner);
    for (int i = 0; i < 13; i++) {
        ImportRecord record = new ImportRecord(owner);
        record.recordStatus(ImportRecord.Status.SUCCESS, "great!");
        this.importRecordCurator.create(record);
    }
    this.job.execute(null);
    List<ImportRecord> records = this.importRecordCurator.findRecords(owner).list();
    Assert.assertEquals(10, records.size());
}
Also used : Owner(org.candlepin.model.Owner) ImportRecord(org.candlepin.model.ImportRecord) Test(org.junit.Test)

Example 7 with ImportRecord

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

the class ImportRecordJobTest method multipleOwners.

@Test
public void multipleOwners() throws Exception {
    Owner owner1 = new Owner("owner1");
    Owner owner2 = new Owner("owner2");
    ownerCurator.create(owner1);
    ownerCurator.create(owner2);
    for (int i = 0; i < 23; i++) {
        ImportRecord record = new ImportRecord(owner1);
        record.recordStatus(ImportRecord.Status.FAILURE, "Bad bad");
        this.importRecordCurator.create(record);
    }
    for (int i = 0; i < 4; i++) {
        ImportRecord record = new ImportRecord(owner2);
        record.recordStatus(ImportRecord.Status.SUCCESS, "Excellent");
        this.importRecordCurator.create(record);
    }
    this.job.execute(null);
    Assert.assertEquals(10, importRecordCurator.findRecords(owner1).list().size());
    Assert.assertEquals(4, importRecordCurator.findRecords(owner2).list().size());
}
Also used : Owner(org.candlepin.model.Owner) ImportRecord(org.candlepin.model.ImportRecord) Test(org.junit.Test)

Example 8 with ImportRecord

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

the class UndoImportsJobTest method testUndoImport.

@Test
public void testUndoImport() throws JobExecutionException, IOException, ImporterException {
    // We need proper curators for this test
    this.poolManager = this.poolManagerBase;
    this.ownerCurator = super.ownerCurator;
    this.exportCurator = this.exportCuratorBase;
    this.undoImportsJob = new UndoImportsJob(this.i18n, this.ownerCurator, this.poolManager, this.subAdapter, this.exportCurator, this.importRecordCurator);
    // Create owner w/upstream consumer
    Owner owner1 = TestUtil.createOwner();
    Owner owner2 = TestUtil.createOwner();
    ConsumerType type = this.createConsumerType();
    UpstreamConsumer uc1 = new UpstreamConsumer("uc1", null, type, "uc1");
    UpstreamConsumer uc2 = new UpstreamConsumer("uc2", null, type, "uc2");
    this.ownerCurator.create(owner1);
    this.ownerCurator.create(owner2);
    owner1.setUpstreamConsumer(uc1);
    owner1.setUpstreamConsumer(uc2);
    this.ownerCurator.merge(owner1);
    this.ownerCurator.merge(owner2);
    // Create metadata
    ExporterMetadata metadata1 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner1);
    ExporterMetadata metadata2 = new ExporterMetadata(ExporterMetadata.TYPE_PER_USER, new Date(), owner2);
    this.exportCurator.create(metadata1);
    this.exportCurator.create(metadata2);
    // Create pools w/upstream pool IDs
    Pool pool1 = this.createPool("pool1", owner1, true, PoolType.NORMAL);
    Pool pool2 = this.createPool("pool2", owner1, true, PoolType.BONUS);
    Pool pool3 = this.createPool("pool3", owner1, false, PoolType.NORMAL);
    Pool pool4 = this.createPool("pool4", owner1, false, PoolType.BONUS);
    Pool pool5 = this.createPool("pool5", owner1, true, PoolType.ENTITLEMENT_DERIVED);
    Pool pool6 = this.createPool("pool6", owner1, false, PoolType.ENTITLEMENT_DERIVED);
    Pool pool7 = this.createPool("pool7", owner2, true, PoolType.NORMAL);
    Pool pool8 = this.createPool("pool8", owner2, true, PoolType.BONUS);
    Pool pool9 = this.createPool("pool9", owner2, true, PoolType.ENTITLEMENT_DERIVED);
    // Create an ueber certificate for the owner.
    UeberCertificate uebercert = ueberCertGenerator.generate(owner1.getKey(), this.setupAdminPrincipal("test_admin"));
    assertNotNull(uebercert);
    // Verify initial state
    assertEquals(Arrays.asList(pool1, pool2, pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
    assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
    assertEquals(metadata1, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
    assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
    assertEquals(0, this.importRecordCurator.findRecords(owner1).list().size());
    assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
    // Execute job
    Principal principal = new UserPrincipal("JarJarBinks", null, true);
    this.jobDataMap.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
    this.jobDataMap.put(JobStatus.TARGET_ID, owner1.getId());
    this.jobDataMap.put(UndoImportsJob.OWNER_KEY, owner1.getKey());
    this.jobDataMap.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
    // since we locking owner we need start transaction
    beginTransaction();
    this.undoImportsJob.toExecute(this.jobContext);
    commitTransaction();
    // Verify deletions -- Ueber pools should not get deleted.
    assertEquals(Arrays.asList(pool3, pool4, pool5, pool6), this.poolManager.listPoolsByOwner(owner1).list());
    assertEquals(Arrays.asList(pool7, pool8, pool9), this.poolManager.listPoolsByOwner(owner2).list());
    assertNull(exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner1));
    assertEquals(metadata2, exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner2));
    assertNull(owner1.getUpstreamConsumer());
    List<ImportRecord> records = this.importRecordCurator.findRecords(owner1).list();
    assertEquals(1, records.size());
    assertEquals(ImportRecord.Status.DELETE, records.get(0).getStatus());
    assertEquals(0, this.importRecordCurator.findRecords(owner2).list().size());
}
Also used : Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ExporterMetadata(org.candlepin.model.ExporterMetadata) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 9 with ImportRecord

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

the class UndoImportsJob method recordManifestDeletion.

private void recordManifestDeletion(Owner owner, String username, UpstreamConsumer uc) {
    ImportRecord record = new ImportRecord(owner);
    record.setGeneratedBy(username);
    record.setGeneratedDate(new Date());
    String msg = this.i18n.tr("Subscriptions deleted by {0}", username);
    record.recordStatus(ImportRecord.Status.DELETE, msg);
    record.setUpstreamConsumer(this.createImportUpstreamConsumer(owner, uc));
    this.importRecordCurator.create(record);
}
Also used : ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date)

Example 10 with ImportRecord

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

the class OwnerManager method cleanupAndDelete.

@Transactional
public void cleanupAndDelete(Owner owner, boolean revokeCerts) {
    log.info("Cleaning up owner: {}", owner);
    Collection<String> consumerIds = this.ownerCurator.getConsumerIds(owner).list();
    Collection<Consumer> consumers = this.consumerCurator.lockAndLoadByIds(consumerIds);
    consumers.addAll(consumerCurator.listByRecipientOwner(owner).list());
    for (Consumer consumer : consumers) {
        log.info("Removing all entitlements for consumer: {}", consumer);
        // We're about to delete these consumers; no need to regen/dirty their dependent
        // entitlements or recalculate status.
        poolManager.revokeAllEntitlements(consumer, false);
    }
    // FIXME Perhaps this can be handled a little better.
    for (Consumer consumer : consumers) {
        // need to check if this has been removed due to a
        // parent being deleted
        // TODO: There has to be a more efficient way to do this...
        log.info("Deleting consumer: {}", consumer);
        Consumer next = consumerCurator.find(consumer.getId());
        if (next != null) {
            consumerCurator.delete(next);
        }
    }
    for (ActivationKey key : activationKeyCurator.listByOwner(owner)) {
        log.info("Deleting activation key: {}", key);
        activationKeyCurator.delete(key);
    }
    log.debug("Deleting environments for owner: {}", owner);
    envCurator.deleteEnvironmentsForOwner(owner);
    // Delete the ueber certificate for this owner, if one exists.
    log.debug("Deleting uber certificate for owner: {}", owner);
    this.uberCertificateCurator.deleteForOwner(owner);
    for (Pool p : poolManager.listPoolsByOwner(owner)) {
        log.info("Deleting pool: {}", p);
        poolManager.deletePool(p);
    }
    ExporterMetadata m = exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner);
    if (m != null) {
        log.info("Deleting export metadata: {}", m);
        exportCurator.delete(m);
    }
    for (ImportRecord record : importRecordCurator.findRecords(owner)) {
        log.info("Deleting import record:  {}", record);
        importRecordCurator.delete(record);
    }
    for (PermissionBlueprint perm : permissionCurator.findByOwner(owner)) {
        log.info("Deleting permission: {}", perm.getAccess());
        perm.getRole().getPermissions().remove(perm);
        permissionCurator.delete(perm);
    }
    log.info("Deleting all products...");
    this.productManager.removeAllProducts(owner);
    log.info("Deleting all content...");
    this.contentManager.removeAllContent(owner, false);
    log.info("Deleting owner: {}", owner);
    ownerCurator.delete(owner);
    ownerCurator.flush();
}
Also used : Consumer(org.candlepin.model.Consumer) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) Pool(org.candlepin.model.Pool) ExporterMetadata(org.candlepin.model.ExporterMetadata) ImportRecord(org.candlepin.model.ImportRecord) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Transactional(com.google.inject.persist.Transactional)

Aggregations

ImportRecord (org.candlepin.model.ImportRecord)17 Test (org.junit.Test)11 Owner (org.candlepin.model.Owner)10 Date (java.util.Date)7 EventSink (org.candlepin.audit.EventSink)6 Subscription (org.candlepin.model.dto.Subscription)6 HashMap (java.util.HashMap)5 ImportRecordCurator (org.candlepin.model.ImportRecordCurator)5 ArrayList (java.util.ArrayList)4 ConflictOverrides (org.candlepin.sync.ConflictOverrides)3 Transactional (com.google.inject.persist.Transactional)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 ConsumerType (org.candlepin.model.ConsumerType)2 ExporterMetadata (org.candlepin.model.ExporterMetadata)2 Pool (org.candlepin.model.Pool)2 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Principal (org.candlepin.auth.Principal)1