Search in sources :

Example 51 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ConsumerResource method logNewConsumerDebugInfo.

private void logNewConsumerDebugInfo(Consumer consumer, List<ActivationKey> keys, ConsumerType type) {
    if (log.isDebugEnabled()) {
        log.debug("Got consumerTypeLabel of: {}", type.getLabel());
        if (consumer.getFacts() != null) {
            log.debug("incoming facts:");
            for (String key : consumer.getFacts().keySet()) {
                log.debug("   {} = {}", key, consumer.getFact(key));
            }
        }
        log.debug("Activation keys:");
        for (ActivationKey activationKey : keys) {
            log.debug("   {}", activationKey.getName());
        }
    }
}
Also used : ActivationKey(org.candlepin.model.activationkeys.ActivationKey)

Example 52 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class OwnerResource method createActivationKey.

/**
 * Creates an Activation Key for the Owner
 *
 * @param ownerKey id of the owner whose keys are sought.
 * @return an Activation Key object
 * @httpcode 400
 * @httpcode 404
 * @httpcode 200
 */
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("{owner_key}/activation_keys")
@ApiOperation(notes = "Creates an Activation Key for the Owner", value = "Create Activation Key")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "Invalid activation key") })
public ActivationKeyDTO createActivationKey(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @ApiParam(name = "activation_key", required = true) ActivationKeyDTO dto) {
    if (StringUtils.isBlank(dto.getName())) {
        throw new BadRequestException(i18n.tr("Must provide a name for activation key."));
    }
    String testName = dto.getName().replace("-", "0").replace("_", "0");
    if (!testName.matches("[a-zA-Z0-9]*")) {
        throw new BadRequestException(i18n.tr("The activation key name \"{0}\" must be alphanumeric or " + "include the characters \"-\" or \"_\"", dto.getName()));
    }
    if (dto.getContentOverrides() != null) {
        contentOverrideValidator.validateDTOs(dto.getContentOverrides());
    }
    Owner owner = findOwnerByKey(ownerKey);
    if (activationKeyCurator.lookupForOwner(dto.getName(), owner) != null) {
        throw new BadRequestException(i18n.tr("The activation key name \"{0}\" is already in use for owner {1}", dto.getName(), ownerKey));
    }
    serviceLevelValidator.validate(owner.getId(), dto.getServiceLevel());
    ActivationKey key = new ActivationKey();
    this.populateEntity(key, dto);
    key.setOwner(owner);
    ActivationKey newKey = activationKeyCurator.create(key);
    sink.emitActivationKeyCreated(newKey);
    return translator.translate(newKey, ActivationKeyDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) 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)

Example 53 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class OwnerResource method ownerActivationKeys.

/**
 * Retrieves a list of Activation Keys for an Owner
 *
 * @param ownerKey id of the owner whose keys are sought.
 * @return a list of Activation Key objects
 * @httpcode 404
 * @httpcode 200
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/activation_keys")
@ApiOperation(notes = "Retrieves a list of Activation Keys for an Owner", value = "Owner Activation Keys")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public CandlepinQuery<ActivationKeyDTO> ownerActivationKeys(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @QueryParam("name") String keyName) {
    Owner owner = findOwnerByKey(ownerKey);
    CandlepinQuery<ActivationKey> keys = this.activationKeyCurator.listByOwner(owner, keyName);
    return translator.translateQuery(keys, ActivationKeyDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) 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 54 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ConsumerBindUtil method handleActivationKeys.

public void handleActivationKeys(Consumer consumer, List<ActivationKey> keys, boolean autoattachDisabledForOwner) throws AutobindDisabledForOwnerException {
    // Process activation keys.
    boolean listSuccess = false;
    for (ActivationKey key : keys) {
        boolean keySuccess = true;
        handleActivationKeyOverrides(consumer, key.getContentOverrides());
        handleActivationKeyRelease(consumer, key.getReleaseVer());
        keySuccess &= handleActivationKeyServiceLevel(consumer, key.getServiceLevel(), key.getOwner());
        if (key.isAutoAttach() != null && key.isAutoAttach()) {
            if (autoattachDisabledForOwner) {
                log.warn("Auto-attach is disabled for owner. Skipping auto-attach for consumer/key: {}/{}", consumer.getUuid(), key.getName());
            } else {
                handleActivationKeyAutoBind(consumer, key);
            }
        } else {
            keySuccess &= handleActivationKeyPools(consumer, key);
        }
        listSuccess |= keySuccess;
    }
    if (!listSuccess) {
        throw new BadRequestException(i18n.tr("None of the subscriptions on the activation key were available for attaching."));
    }
}
Also used : BadRequestException(org.candlepin.common.exceptions.BadRequestException) ActivationKey(org.candlepin.model.activationkeys.ActivationKey)

Example 55 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyResource method updateActivationKey.

@ApiOperation(notes = "Updates an Activation Key", value = "Update Activation Key")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@PUT
@Path("{activation_key_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ActivationKeyDTO updateActivationKey(@PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @ApiParam(name = "update", required = true) ActivationKeyDTO update) {
    ActivationKey toUpdate = activationKeyCurator.verifyAndLookupKey(activationKeyId);
    if (update.getName() != null) {
        toUpdate.setName(update.getName());
    }
    String serviceLevel = update.getServiceLevel();
    if (serviceLevel != null) {
        serviceLevelValidator.validate(toUpdate.getOwner().getId(), serviceLevel);
        toUpdate.setServiceLevel(serviceLevel);
    }
    if (update.getReleaseVersion() != null) {
        toUpdate.setReleaseVer(new Release(update.getReleaseVersion()));
    }
    if (update.getDescription() != null) {
        toUpdate.setDescription(update.getDescription());
    }
    if (update.isAutoAttach() != null) {
        toUpdate.setAutoAttach(update.isAutoAttach());
    }
    toUpdate = activationKeyCurator.merge(toUpdate);
    return this.translator.translate(toUpdate, ActivationKeyDTO.class);
}
Also used : ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Release(org.candlepin.model.Release) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Aggregations

ActivationKey (org.candlepin.model.activationkeys.ActivationKey)76 Test (org.junit.Test)55 Pool (org.candlepin.model.Pool)38 Product (org.candlepin.model.Product)16 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)15 ArrayList (java.util.ArrayList)14 ValidationResult (org.candlepin.policy.ValidationResult)14 Consumer (org.candlepin.model.Consumer)13 ActivationKeyCurator (org.candlepin.model.activationkeys.ActivationKeyCurator)13 PoolManager (org.candlepin.controller.PoolManager)11 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)10 Owner (org.candlepin.model.Owner)10 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 BadRequestException (org.candlepin.common.exceptions.BadRequestException)9 Date (java.util.Date)8 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)8 HashSet (java.util.HashSet)6