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