Search in sources :

Example 16 with Environment

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));
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Environment(org.candlepin.model.Environment) Event(org.candlepin.audit.Event) Entitlement(org.candlepin.model.Entitlement) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 17 with Environment

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);
}
Also used : Environment(org.candlepin.model.Environment) CandlepinQuery(org.candlepin.model.CandlepinQuery) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 18 with Environment

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;
}
Also used : EnvironmentContent(org.candlepin.model.EnvironmentContent) Content(org.candlepin.model.Content) Environment(org.candlepin.model.Environment) EnvironmentContent(org.candlepin.model.EnvironmentContent) HashSet(java.util.HashSet)

Example 19 with Environment

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;
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerCapability(org.candlepin.model.ConsumerCapability) Date(java.util.Date) LinkedList(java.util.LinkedList) Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Environment(org.candlepin.model.Environment) ConsumerType(org.candlepin.model.ConsumerType) Release(org.candlepin.model.Release) HashSet(java.util.HashSet)

Example 20 with Environment

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;
}
Also used : JobDataMap(org.quartz.JobDataMap) ConflictException(org.candlepin.common.exceptions.ConflictException) EnvironmentContent(org.candlepin.model.EnvironmentContent) JobDetail(org.quartz.JobDetail) RegenEnvEntitlementCertsJob(org.candlepin.pinsetter.tasks.RegenEnvEntitlementCertsJob) PersistenceException(javax.persistence.PersistenceException) Environment(org.candlepin.model.Environment) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Environment (org.candlepin.model.Environment)29 EnvironmentContent (org.candlepin.model.EnvironmentContent)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 Owner (org.candlepin.model.Owner)7 ApiOperation (io.swagger.annotations.ApiOperation)6 HashMap (java.util.HashMap)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Content (org.candlepin.model.Content)6 ApiResponses (io.swagger.annotations.ApiResponses)5 Date (java.util.Date)5 Consumer (org.candlepin.model.Consumer)5 NotFoundException (org.candlepin.common.exceptions.NotFoundException)4 ConsumerCapability (org.candlepin.model.ConsumerCapability)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4 ConsumerType (org.candlepin.model.ConsumerType)4 Release (org.candlepin.model.Release)4 Matchers.anyString (org.mockito.Matchers.anyString)4 KeyPair (java.security.KeyPair)3