Search in sources :

Example 1 with ProcessorLifecycleException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method updateProcessor.

@Override
@Transactional
public Processor updateProcessor(String bridgeId, String processorId, String customerId, ProcessorRequest processorRequest) {
    // Attempt to load the Bridge. We cannot update a Processor if the Bridge is not available.
    bridgesService.getReadyBridge(bridgeId, customerId);
    // Extract existing definition
    Processor existingProcessor = getProcessor(bridgeId, processorId, customerId);
    if (existingProcessor.getType() == ProcessorType.ERROR_HANDLER) {
        throw new BadRequestException("It is not possible to update this Processor.");
    }
    if (!isProcessorActionable(existingProcessor)) {
        throw new ProcessorLifecycleException(String.format("Processor with id '%s' for customer '%s' is not in an actionable state.", processorId, customerId));
    }
    ProcessorDefinition existingDefinition = existingProcessor.getDefinition();
    Action existingAction = existingDefinition.getRequestedAction();
    Action existingResolvedAction = existingDefinition.getResolvedAction();
    Source existingSource = existingDefinition.getRequestedSource();
    // Name cannot be updated.
    if (!Objects.equals(existingProcessor.getName(), processorRequest.getName())) {
        throw new BadRequestException("It is not possible to update the Processor's name.");
    }
    if (!Objects.equals(existingProcessor.getType(), processorRequest.getType())) {
        throw new BadRequestException("It is not possible to update the Processor's Type.");
    }
    // See https://issues.redhat.com/browse/MGDOBR-516 for updating Action support
    if (!Objects.equals(existingAction, processorRequest.getAction())) {
        throw new BadRequestException("It is not possible to update the Processor's Action.");
    }
    if (!Objects.equals(existingSource, processorRequest.getSource())) {
        throw new BadRequestException("It is not possible to update the Processor's Source.");
    }
    // Construct updated definition
    Set<BaseFilter> updatedFilters = processorRequest.getFilters();
    String updatedTransformationTemplate = processorRequest.getTransformationTemplate();
    ProcessorDefinition updatedDefinition = existingProcessor.getType() == ProcessorType.SOURCE ? new ProcessorDefinition(updatedFilters, updatedTransformationTemplate, existingSource, existingResolvedAction) : new ProcessorDefinition(updatedFilters, updatedTransformationTemplate, existingAction, existingResolvedAction);
    // No need to update CRD if the definition is unchanged
    if (existingDefinition.equals(updatedDefinition)) {
        return existingProcessor;
    }
    // Create new definition copying existing properties
    existingProcessor.setModifiedAt(ZonedDateTime.now());
    existingProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    existingProcessor.setDefinition(updatedDefinition);
    // Processor and Work should always be created in the same transaction
    // Since updates to the Action are unsupported we do not need to update the Connector record.
    workManager.schedule(existingProcessor);
    metricsService.onOperationStart(existingProcessor, MetricsOperation.MODIFY);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for update", existingProcessor.getId(), existingProcessor.getBridge().getCustomerId(), existingProcessor.getBridge().getId());
    return existingProcessor;
}
Also used : ProcessorLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException) Action(com.redhat.service.smartevents.infra.models.gateways.Action) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorDefinition(com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition) BadRequestException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BadRequestException) Source(com.redhat.service.smartevents.infra.models.gateways.Source) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) Transactional(javax.transaction.Transactional)

Example 2 with ProcessorLifecycleException

use of com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method deleteProcessor.

@Override
@Transactional
public void deleteProcessor(String bridgeId, String processorId, String customerId) {
    Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(bridgeId, processorId, customerId);
    if (processor == null) {
        throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist on bridge '%s' for customer '%s'", processorId, bridgeId, customerId));
    }
    if (!isProcessorActionable(processor)) {
        throw new ProcessorLifecycleException("Processor could only be deleted if its in READY/FAILED state.");
    }
    // Processor and Connector deletion and related Work creation should always be in the same transaction
    processor.setStatus(ManagedResourceStatus.DEPROVISION);
    processor.setDeletionRequestedAt(ZonedDateTime.now());
    connectorService.deleteConnectorEntity(processor);
    workManager.schedule(processor);
    metricsService.onOperationStart(processor, MetricsOperation.DELETE);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for deletion", processor.getId(), processor.getBridge().getCustomerId(), processor.getBridge().getId());
}
Also used : ProcessorLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException) Processor(com.redhat.service.smartevents.manager.models.Processor) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Aggregations

ProcessorLifecycleException (com.redhat.service.smartevents.infra.exceptions.definitions.user.ProcessorLifecycleException)2 Processor (com.redhat.service.smartevents.manager.models.Processor)2 Transactional (javax.transaction.Transactional)2 BadRequestException (com.redhat.service.smartevents.infra.exceptions.definitions.user.BadRequestException)1 ItemNotFoundException (com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException)1 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)1 Action (com.redhat.service.smartevents.infra.models.gateways.Action)1 Source (com.redhat.service.smartevents.infra.models.gateways.Source)1 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)1