Search in sources :

Example 46 with Processor

use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAO method getProcessorIds.

private ProcessorResults getProcessorIds(String customerId, String bridgeId, QueryProcessorResourceInfo queryInfo, Set<ProcessorType> restrictTypes) {
    Parameters parameters = Parameters.with("customerId", customerId).and("bridgeId", bridgeId);
    PanacheQuery<Processor> query = find("#PROCESSOR.findByBridgeIdAndCustomerIdNoFilter", parameters);
    // filter by name
    String filterName = queryInfo.getFilterInfo().getFilterName();
    if (Objects.nonNull(filterName)) {
        query.filter("byName", Parameters.with("name", filterName + "%"));
    }
    // filter by status
    Set<ManagedResourceStatus> filterStatus = queryInfo.getFilterInfo().getFilterStatus();
    if (Objects.nonNull(filterStatus) && !filterStatus.isEmpty()) {
        query.filter("byStatus", Parameters.with("status", filterStatus));
    }
    // filter by type, considering onlyUserVisible flag
    ProcessorType filterType = queryInfo.getFilterInfo().getFilterType();
    if (restrictTypes != null) {
        if (Objects.isNull(filterType)) {
            query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, restrictTypes));
        } else {
            if (restrictTypes.contains(filterType)) {
                query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, Set.of(filterType)));
            } else {
                return new ProcessorResults(emptyList(), 0);
            }
        }
    } else {
        if (Objects.nonNull(filterType)) {
            query.filter(BY_TYPE_FILTER_NAME, Parameters.with(BY_TYPE_FILTER_PARAM, Set.of(filterType)));
        }
    }
    long total = query.count();
    List<Processor> processors = query.page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    List<String> ids = processors.stream().map(Processor::getId).collect(Collectors.toList());
    return new ProcessorResults(ids, total);
}
Also used : Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorType(com.redhat.service.smartevents.infra.models.processors.ProcessorType) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus)

Example 47 with Processor

use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesServiceImpl method deleteBridge.

@Override
@Transactional
public void deleteBridge(String id, String customerId) {
    Long processorsCount = processorService.getProcessorsCount(id, customerId);
    ListResult<Processor> hiddenProcessors = processorService.getHiddenProcessors(id, customerId);
    if (processorsCount != hiddenProcessors.getTotal()) {
        // See https://issues.redhat.com/browse/MGDOBR-43
        throw new BridgeLifecycleException("It is not possible to delete a Bridge instance with active Processors.");
    }
    Bridge bridge = findByIdAndCustomerId(id, customerId);
    if (!isBridgeDeletable(bridge)) {
        throw new BridgeLifecycleException("Bridge could only be deleted if its in READY/FAILED state.");
    }
    hiddenProcessors.getItems().forEach(p -> processorService.deleteProcessor(id, p.getId(), customerId));
    LOGGER.info("Bridge with id '{}' for customer '{}' has been marked for deletion", bridge.getId(), bridge.getCustomerId());
    // Bridge deletion and related Work creation should always be in the same transaction
    bridge.setStatus(ManagedResourceStatus.DEPROVISION);
    bridge.setDeletionRequestedAt(ZonedDateTime.now());
    workManager.schedule(bridge);
    metricsService.onOperationStart(bridge, MetricsOperation.DELETE);
    LOGGER.info("Bridge with id '{}' for customer '{}' has been marked for deletion", bridge.getId(), bridge.getCustomerId());
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) BridgeLifecycleException(com.redhat.service.smartevents.infra.exceptions.definitions.user.BridgeLifecycleException) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Transactional(javax.transaction.Transactional)

Example 48 with Processor

use of com.redhat.service.smartevents.manager.models.Processor 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 49 with Processor

use of com.redhat.service.smartevents.manager.models.Processor 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)

Example 50 with Processor

use of com.redhat.service.smartevents.manager.models.Processor in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceImpl method doCreateProcessor.

private Processor doCreateProcessor(Bridge bridge, String customerId, String owner, ProcessorType processorType, ProcessorRequest processorRequest) {
    String bridgeId = bridge.getId();
    if (processorDAO.findByBridgeIdAndName(bridgeId, processorRequest.getName()) != null) {
        throw new AlreadyExistingItemException("Processor with name '" + processorRequest.getName() + "' already exists for bridge with id '" + bridgeId + "' for customer '" + customerId + "'");
    }
    Processor newProcessor = new Processor();
    newProcessor.setType(processorType);
    newProcessor.setName(processorRequest.getName());
    newProcessor.setSubmittedAt(ZonedDateTime.now());
    newProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    newProcessor.setBridge(bridge);
    newProcessor.setShardId(shardService.getAssignedShardId(newProcessor.getId()));
    newProcessor.setOwner(owner);
    Set<BaseFilter> requestedFilters = processorRequest.getFilters();
    String requestedTransformationTemplate = processorRequest.getTransformationTemplate();
    Action resolvedAction = processorType == ProcessorType.SOURCE ? resolveSource(processorRequest.getSource(), customerId, bridge.getId(), newProcessor.getId()) : resolveAction(processorRequest.getAction(), customerId, bridge.getId(), newProcessor.getId());
    ProcessorDefinition definition = processorType == ProcessorType.SOURCE ? new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, processorRequest.getSource(), resolvedAction) : new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, processorRequest.getAction(), resolvedAction);
    newProcessor.setDefinition(definition);
    // Processor, Connector and Work should always be created in the same transaction
    processorDAO.persist(newProcessor);
    connectorService.createConnectorEntity(newProcessor);
    workManager.schedule(newProcessor);
    metricsService.onOperationStart(newProcessor, MetricsOperation.PROVISION);
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for creation", newProcessor.getId(), newProcessor.getBridge().getCustomerId(), newProcessor.getBridge().getId());
    return newProcessor;
}
Also used : 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) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) AlreadyExistingItemException(com.redhat.service.smartevents.infra.exceptions.definitions.user.AlreadyExistingItemException)

Aggregations

Processor (com.redhat.service.smartevents.manager.models.Processor)82 Bridge (com.redhat.service.smartevents.manager.models.Bridge)45 QuarkusTest (io.quarkus.test.junit.QuarkusTest)36 Test (org.junit.jupiter.api.Test)36 Transactional (javax.transaction.Transactional)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 Action (com.redhat.service.smartevents.infra.models.gateways.Action)13 QueryProcessorResourceInfo (com.redhat.service.smartevents.infra.models.QueryProcessorResourceInfo)12 ProcessorDefinition (com.redhat.service.smartevents.infra.models.processors.ProcessorDefinition)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)8 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)8 Connector (com.openshift.cloud.api.connector.models.Connector)7 Work (com.redhat.service.smartevents.manager.models.Work)7 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)6 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)6 KafkaTopicAction (com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction)6 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)5 BaseFilter (com.redhat.service.smartevents.infra.models.filters.BaseFilter)5 SlackAction (com.redhat.service.smartevents.processor.actions.slack.SlackAction)5