Search in sources :

Example 6 with UpstreamConsumer

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

the class OwnerResource method getUpstreamConsumers.

/**
 * Retrieves a list of Upstream Consumers for an Owner
 *
 * @return a list of UpstreamConsumer objects
 * @httpcode 404
 * @httpcode 200
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/upstream_consumers")
@ApiOperation(notes = " Retrieves a list of Upstream Consumers for an Owner", value = "Get Upstream Consumers")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public List<UpstreamConsumerDTO> getUpstreamConsumers(@Context Principal principal, @Verify(Owner.class) @PathParam("owner_key") String ownerKey) {
    Owner owner = this.findOwnerByKey(ownerKey);
    UpstreamConsumer consumer = owner.getUpstreamConsumer();
    UpstreamConsumerDTO dto = this.translator.translate(consumer, UpstreamConsumerDTO.class);
    // when multiples are supported.
    return Arrays.asList(dto);
}
Also used : Owner(org.candlepin.model.Owner) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with UpstreamConsumer

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

the class UndoImportsJob method toExecute.

/**
 * {@inheritDoc}
 *
 * Executes {@link PoolManager#refreshPools(org.candlepin.model.Owner)}
 * as a pinsetter job.
 *
 * @param context the job's execution context
 */
@Transactional
public void toExecute(JobExecutionContext context) throws JobExecutionException {
    try {
        JobDataMap map = context.getMergedJobDataMap();
        String ownerId = map.getString(JobStatus.TARGET_ID);
        String ownerKey = map.getString(OWNER_KEY);
        Owner owner = this.ownerCurator.lockAndLoadById(ownerId);
        Boolean lazy = map.getBoolean(LAZY_REGEN);
        Principal principal = (Principal) map.get(PinsetterJobListener.PRINCIPAL_KEY);
        if (owner == null) {
            log.debug("Owner no longer exists: {}", ownerKey);
            context.setResult("Nothing to do; owner no longer exists: " + ownerKey);
            return;
        }
        String displayName = owner.getDisplayName();
        // Remove imports
        ExporterMetadata metadata = this.exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner);
        if (metadata == null) {
            log.debug("No imports exist for owner {}", displayName);
            context.setResult("Nothing to do; imports no longer exist for owner: " + displayName);
            return;
        }
        log.info("Deleting all pools originating from manifests for owner/org: {}", displayName);
        List<Pool> pools = this.poolManager.listPoolsByOwner(owner).list();
        for (Pool pool : pools) {
            if (this.poolManager.isManaged(pool)) {
                this.poolManager.deletePool(pool);
            }
        }
        // Clear out upstream ID so owner can import from other distributors:
        UpstreamConsumer uc = owner.getUpstreamConsumer();
        owner.setUpstreamConsumer(null);
        this.exportCurator.delete(metadata);
        this.recordManifestDeletion(owner, principal.getUsername(), uc);
        context.setResult("Imported pools removed for owner " + displayName);
    } catch (PersistenceException e) {
        throw new RetryJobException("UndoImportsJob encountered a problem.", e);
    } catch (RuntimeException e) {
        Throwable cause = e.getCause();
        while (cause != null) {
            if (SQLException.class.isAssignableFrom(cause.getClass())) {
                log.warn("Caught a runtime exception wrapping an SQLException.");
                throw new RetryJobException("UndoImportsJob encountered a problem.", e);
            }
            cause = cause.getCause();
        }
        // Otherwise throw as we would normally for any generic Exception:
        log.error("UndoImportsJob encountered a problem.", e);
        context.setResult(e.getMessage());
        throw new JobExecutionException(e.getMessage(), e, false);
    }// cleaned up on failure.
     catch (Exception e) {
        log.error("UndoImportsJob encountered a problem.", e);
        context.setResult(e.getMessage());
        throw new JobExecutionException(e.getMessage(), e, false);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) SQLException(java.sql.SQLException) ExporterMetadata(org.candlepin.model.ExporterMetadata) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportUpstreamConsumer(org.candlepin.model.ImportUpstreamConsumer) RetryJobException(org.candlepin.pinsetter.core.RetryJobException) SQLException(java.sql.SQLException) JobExecutionException(org.quartz.JobExecutionException) PersistenceException(javax.persistence.PersistenceException) RetryJobException(org.candlepin.pinsetter.core.RetryJobException) JobExecutionException(org.quartz.JobExecutionException) PersistenceException(javax.persistence.PersistenceException) Pool(org.candlepin.model.Pool) Principal(org.candlepin.auth.Principal) Transactional(com.google.inject.persist.Transactional)

Example 8 with UpstreamConsumer

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

the class UpstreamConsumerTranslatorTest method initSourceObject.

@Override
protected UpstreamConsumer initSourceObject() {
    UpstreamConsumer consumer = new UpstreamConsumer();
    consumer.setId("consumer_id");
    consumer.setUuid("consumer_uuid");
    consumer.setName("consumer_name");
    consumer.setApiUrl("http://www.url.com");
    consumer.setWebUrl("http://www.url.com");
    consumer.setOwnerId("owner_id");
    consumer.setType(this.consumerTypeTranslatorTest.initSourceObject());
    consumer.setIdCert((IdentityCertificate) this.certificateTranslatorTest.initSourceObject());
    return consumer;
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer)

Example 9 with UpstreamConsumer

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

the class ImporterTest method testRecordImportSetsUpstreamConsumerFromOwner.

@Test
public void testRecordImportSetsUpstreamConsumerFromOwner() {
    String expectedOwnerKey = "TEST_OWNER";
    Owner owner = new Owner(expectedOwnerKey);
    UpstreamConsumer uc = new UpstreamConsumer("uc", owner, new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN), "uuid");
    uc.setContentAccessMode("mode");
    owner.setUpstreamConsumer(uc);
    EventSink eventSinkMock = mock(EventSink.class);
    ImportRecordCurator importRecordCurator = mock(ImportRecordCurator.class);
    Importer importer = new Importer(null, null, null, null, null, null, null, null, config, null, null, eventSinkMock, i18n, null, null, su, importRecordCurator, this.mockSubReconciler, this.ec, this.translator);
    Meta meta = new Meta("1.0", new Date(), "test-user", "candlepin", "testcdn");
    Map<String, Object> data = new HashMap<>();
    data.put("meta", meta);
    data.put("subscriptions", new ArrayList<Subscription>());
    ImportRecord record = importer.recordImportSuccess(owner, data, new ConflictOverrides(), "test.zip");
    ImportUpstreamConsumer iuc = record.getUpstreamConsumer();
    assertNotNull(iuc);
    assertEquals(uc.getOwnerId(), iuc.getOwnerId());
    assertEquals(uc.getName(), iuc.getName());
    assertEquals(uc.getUuid(), iuc.getUuid());
    assertEquals(uc.getType(), iuc.getType());
    assertEquals(uc.getWebUrl(), iuc.getWebUrl());
    assertEquals(uc.getApiUrl(), iuc.getApiUrl());
    assertEquals(uc.getContentAccessMode(), iuc.getContentAccessMode());
    verify(importRecordCurator).create(eq(record));
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ImportUpstreamConsumer(org.candlepin.model.ImportUpstreamConsumer) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ImportUpstreamConsumer(org.candlepin.model.ImportUpstreamConsumer) ImportRecord(org.candlepin.model.ImportRecord) Date(java.util.Date) ImportRecordCurator(org.candlepin.model.ImportRecordCurator) ConsumerType(org.candlepin.model.ConsumerType) EventSink(org.candlepin.audit.EventSink) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 10 with UpstreamConsumer

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

the class ConsumerImporterTest method importConsumerWithNullUuidOnOwnerShouldSetUuid.

@Test
public void importConsumerWithNullUuidOnOwnerShouldSetUuid() throws ImporterException {
    OwnerDTO ownerDTO = mock(OwnerDTO.class);
    Owner owner = mock(Owner.class);
    ConsumerDTO consumer = mock(ConsumerDTO.class);
    ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
    when(ownerDTO.getId()).thenReturn("test-owner-id");
    when(consumer.getUuid()).thenReturn("test-uuid");
    when(consumer.getOwner()).thenReturn(ownerDTO);
    when(consumer.getType()).thenReturn(type);
    IdentityCertificate idCert = new IdentityCertificate();
    idCert.setSerial(new CertificateSerial());
    importer.store(owner, consumer, new ConflictOverrides(), idCert);
    // now verify that the owner has the upstream consumer set
    ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
    verify(owner).setUpstreamConsumer(arg.capture());
    assertEquals("test-uuid", arg.getValue().getUuid());
    verify(curator).merge(owner);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) CertificateSerial(org.candlepin.model.CertificateSerial) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Aggregations

UpstreamConsumer (org.candlepin.model.UpstreamConsumer)14 Owner (org.candlepin.model.Owner)12 Test (org.junit.Test)7 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)4 Principal (org.candlepin.auth.Principal)3 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)3 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)3 CertificateSerial (org.candlepin.model.CertificateSerial)3 ConsumerType (org.candlepin.model.ConsumerType)3 Date (java.util.Date)2 UserPrincipal (org.candlepin.auth.UserPrincipal)2 UpstreamConsumerDTO (org.candlepin.dto.api.v1.UpstreamConsumerDTO)2 ExporterMetadata (org.candlepin.model.ExporterMetadata)2 IdentityCertificate (org.candlepin.model.IdentityCertificate)2 ImportRecord (org.candlepin.model.ImportRecord)2 ImportUpstreamConsumer (org.candlepin.model.ImportUpstreamConsumer)2 Pool (org.candlepin.model.Pool)2 Transactional (com.google.inject.persist.Transactional)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1