use of org.candlepin.model.Environment in project candlepin by candlepin.
the class EntitlementCertificateGeneratorTest method testNonLazyRegnerateForEnvironmentContent.
@Test
public void testNonLazyRegnerateForEnvironmentContent() throws Exception {
Environment environment = new Environment();
List<Entitlement> entitlements = this.generateEntitlements();
HashMap<String, EntitlementCertificate> ecMap = new HashMap<>();
for (Entitlement entitlement : entitlements) {
ecMap.put(entitlement.getPool().getId(), new EntitlementCertificate());
}
CandlepinQuery<Entitlement> cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(entitlements.iterator());
when(this.mockEntitlementCurator.listByEnvironment(environment)).thenReturn(cqmock);
when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), any(Map.class), any(Map.class), any(Map.class), eq(true))).thenReturn(ecMap);
this.ecGenerator.regenerateCertificatesOf(environment, Arrays.asList("c1", "c2", "c4"), false);
assertFalse(entitlements.get(0).isDirty());
assertFalse(entitlements.get(1).isDirty());
assertFalse(entitlements.get(2).isDirty());
verify(this.mockEntCertAdapter, times(2)).generateEntitlementCerts(any(Consumer.class), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
verify(this.mockEventSink, times(2)).queueEvent(any(Event.class));
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class EntitlementCertificateGeneratorTest method testLazyRegnerateForEnvironmentContent.
@Test
public void testLazyRegnerateForEnvironmentContent() {
Environment environment = new Environment();
List<Entitlement> entitlements = this.generateEntitlements();
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(entitlements.iterator());
when(this.mockEntitlementCurator.listByEnvironment(environment)).thenReturn(cqmock);
this.ecGenerator.regenerateCertificatesOf(environment, Arrays.asList("c1", "c2", "c4"), true);
assertTrue(entitlements.get(0).isDirty());
assertTrue(entitlements.get(1).isDirty());
assertFalse(entitlements.get(2).isDirty());
verifyZeroInteractions(this.mockEntCertAdapter);
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class EnvironmentTranslatorTest method initSourceObject.
@Override
protected Environment initSourceObject() {
Environment source = new Environment();
source.setId("test_id");
source.setName("test_name");
source.setDescription("test_description");
source.setOwner(ownerTranslatorTest.initSourceObject());
Set<EnvironmentContent> environmentContents = new HashSet<>();
for (int i = 0; i < 3; ++i) {
Content content = TestUtil.createContent("content-" + i);
content.setUuid(content.getId() + "_uuid");
EnvironmentContent environmentContent = new EnvironmentContent(source, content, true);
environmentContents.add(environmentContent);
}
source.setEnvironmentContent(environmentContents);
return source;
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class ConsumerTranslatorTest method initSourceObject.
@Override
protected Consumer initSourceObject() {
ConsumerType ctype = this.consumerTypeTranslatorTest.initSourceObject();
Environment environment = this.environmentTranslatorTest.initSourceObject();
Owner owner = this.ownerTranslatorTest.initSourceObject();
when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
Consumer consumer = new Consumer();
consumer.setId("consumer_id");
consumer.setUuid("consumer_uuid");
consumer.setName("consumer_name");
consumer.setUsername("consumer_user_name");
consumer.setEntitlementStatus("consumer_ent_status");
consumer.setServiceLevel("consumer_service_level");
consumer.setReleaseVer(new Release("releaseVer"));
consumer.setOwner(owner);
consumer.setEnvironment(environment);
consumer.setEntitlementCount(0L);
consumer.setLastCheckin(new Date());
consumer.setCanActivate(Boolean.TRUE);
consumer.setHypervisorId(hypervisorIdTranslatorTest.initSourceObject());
consumer.setAutoheal(Boolean.TRUE);
consumer.setRecipientOwnerKey("test_recipient_owner_key");
consumer.setAnnotations("test_annotations");
consumer.setContentAccessMode("test_content_access_mode");
consumer.setIdCert((IdentityCertificate) this.certificateTranslatorTest.initSourceObject());
consumer.setType(ctype);
Map<String, String> facts = new HashMap<>();
for (int i = 0; i < 5; ++i) {
facts.put("fact-" + i, "value-" + i);
}
consumer.setFacts(facts);
Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerInstalledProduct installedProduct = cipTranslatorTest.initSourceObject();
installedProduct.setId("installedProduct-" + i);
installedProducts.add(installedProduct);
}
consumer.setInstalledProducts(installedProducts);
Set<ConsumerCapability> capabilities = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerCapability capability = capabilityTranslatorTest.initSourceObject();
capability.setName("capability-" + i);
capabilities.add(capability);
}
consumer.setCapabilities(capabilities);
Set<String> contentTags = new HashSet<>();
for (int i = 0; i < 5; ++i) {
contentTags.add("contentTag-" + i);
}
consumer.setContentTags(contentTags);
List<GuestId> guestIds = new LinkedList<>();
for (int i = 0; i < 5; ++i) {
GuestId guestId = guestIdTranslatorTest.initSourceObject();
guestId.setId("guestId-" + i);
guestIds.add(guestId);
}
consumer.setGuestIds(guestIds);
when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
when(mockEnvironmentCurator.find(eq(environment.getId()))).thenReturn(environment);
when(mockEnvironmentCurator.getConsumerEnvironment(eq(consumer))).thenReturn(environment);
return consumer;
}
use of org.candlepin.model.Environment in project candlepin by candlepin.
the class EnvironmentResource method promoteContent.
@ApiOperation(notes = "Promotes a Content into an Environment. This call accepts multiple " + "content sets to promote at once, after which all affected certificates for consumers" + " in the environment will be regenerated. Consumers registered to this environment " + "will now receive this content in their entitlement certificates. Because the" + " certificate regeneraiton can be quite time consuming, this is done as an " + "asynchronous job. The content will be promoted and immediately available for new " + "entitlements, but existing entitlements could take some time to be regenerated and " + "sent down to clients as they check in.", value = "promoteContent")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{env_id}/content")
public JobDetail promoteContent(@PathParam("env_id") @Verify(Environment.class) String envId, @ApiParam(name = "contentToPromote", required = true) List<org.candlepin.model.dto.EnvironmentContent> contentToPromote, @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen) {
Environment env = lookupEnvironment(envId);
// there be a problem with the request.
for (org.candlepin.model.dto.EnvironmentContent promoteMe : contentToPromote) {
log.debug("EnvironmentContent to promote: {}:{}", promoteMe.getEnvironmentId(), promoteMe.getContentId());
EnvironmentContent existing = this.envContentCurator.lookupByEnvironmentAndContent(env, promoteMe.getContentId());
if (existing != null) {
throw new ConflictException(i18n.tr("The content with id {0} has already been promoted in this environment.", promoteMe.getContentId()));
}
}
Set<String> contentIds = new HashSet<>();
try {
contentIds = batchCreate(contentToPromote, env);
clearContentAccessCerts(env);
} catch (PersistenceException pe) {
if (rdbmsExceptionTranslator.isConstraintViolationDuplicateEntry(pe)) {
log.info("Concurrent content promotion will cause this request to fail.", pe);
throw new ConflictException(i18n.tr("Some of the content is already associated with Environment: {0}", contentToPromote));
} else {
throw pe;
}
}
JobDataMap map = new JobDataMap();
map.put(RegenEnvEntitlementCertsJob.ENV, env);
map.put(RegenEnvEntitlementCertsJob.CONTENT, contentIds);
map.put(RegenEnvEntitlementCertsJob.LAZY_REGEN, lazyRegen);
JobDetail detail = newJob(RegenEnvEntitlementCertsJob.class).withIdentity("regen_entitlement_cert_of_env" + Util.generateUUID()).usingJobData(map).build();
return detail;
}
Aggregations