Search in sources :

Example 41 with Processor

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

the class ProcessorServiceImpl method updateProcessorStatus.

@Transactional
@Override
public Processor updateProcessorStatus(ProcessorDTO processorDTO) {
    Bridge bridge = bridgesService.getBridge(processorDTO.getBridgeId());
    Processor p = processorDAO.findById(processorDTO.getId());
    if (p == null) {
        throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist for Bridge '%s' for customer '%s'", bridge.getId(), bridge.getCustomerId(), processorDTO.getCustomerId()));
    }
    if (ManagedResourceStatus.DELETED == processorDTO.getStatus()) {
        p.setStatus(ManagedResourceStatus.DELETED);
        processorDAO.deleteById(processorDTO.getId());
        metricsService.onOperationComplete(p, MetricsOperation.DELETE);
        return p;
    }
    boolean provisioningCallback = p.getStatus() == ManagedResourceStatus.PROVISIONING;
    p.setStatus(processorDTO.getStatus());
    if (ManagedResourceStatus.READY == processorDTO.getStatus()) {
        if (provisioningCallback) {
            if (p.getPublishedAt() == null) {
                p.setPublishedAt(ZonedDateTime.now());
                metricsService.onOperationComplete(p, MetricsOperation.PROVISION);
            } else {
                metricsService.onOperationComplete(p, MetricsOperation.MODIFY);
            }
        }
    }
    return p;
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Example 42 with Processor

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

the class ProcessorServiceImpl method getProcessor.

@Transactional
@Override
public Processor getProcessor(String bridgeId, String processorId, String customerId) {
    Bridge bridge = bridgesService.getBridge(bridgeId, customerId);
    Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(bridge.getId(), processorId, bridge.getCustomerId());
    if (processor == null) {
        throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist on Bridge '%s' for customer '%s'", processorId, bridgeId, customerId));
    }
    return processor;
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ItemNotFoundException(com.redhat.service.smartevents.infra.exceptions.definitions.user.ItemNotFoundException) Transactional(javax.transaction.Transactional)

Example 43 with Processor

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

the class ProcessorsAPI method getProcessor.

@APIResponses(value = { @APIResponse(description = "Success.", responseCode = "200", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProcessorResponse.class))), @APIResponse(description = "Bad request.", responseCode = "400", content = @Content(mediaType = MediaType.APPLICATION_JSON)), @APIResponse(description = "Unauthorized.", responseCode = "401"), @APIResponse(description = "Forbidden.", responseCode = "403"), @APIResponse(description = "Not found.", responseCode = "404", content = @Content(mediaType = MediaType.APPLICATION_JSON)), @APIResponse(description = "Internal error.", responseCode = "500", content = @Content(mediaType = MediaType.APPLICATION_JSON)) })
@Operation(summary = "Get a Processor of a Bridge instance", description = "Get a Processor of a Bridge instance for the authenticated user.")
@GET
@Path("{bridgeId}/processors/{processorId}")
public Response getProcessor(@NotEmpty @PathParam("bridgeId") String bridgeId, @NotEmpty @PathParam("processorId") String processorId) {
    String customerId = identityResolver.resolve(jwt);
    Processor processor = processorService.getProcessor(bridgeId, processorId, customerId);
    return Response.ok(processorService.toResponse(processor)).build();
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 44 with Processor

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

the class ProcessorsAPI method addProcessorToBridge.

@APIResponses(value = { @APIResponse(description = "Accepted.", responseCode = "202", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ProcessorResponse.class))), @APIResponse(description = "Bad request.", responseCode = "400", content = @Content(mediaType = MediaType.APPLICATION_JSON)), @APIResponse(description = "Unauthorized.", responseCode = "401"), @APIResponse(description = "Forbidden.", responseCode = "403"), @APIResponse(description = "Not found.", responseCode = "404", content = @Content(mediaType = MediaType.APPLICATION_JSON)), @APIResponse(description = "Internal error.", responseCode = "500", content = @Content(mediaType = MediaType.APPLICATION_JSON)) })
@Operation(summary = "Create a Processor of a Bridge instance", description = "Create a Processor of a Bridge instance for the authenticated user.")
@POST
@Path("{bridgeId}/processors")
public Response addProcessorToBridge(@NotEmpty @PathParam("bridgeId") String bridgeId, @Valid ProcessorRequest processorRequest) {
    String customerId = identityResolver.resolve(jwt);
    String owner = identityResolver.resolveOwner(jwt);
    Processor processor = processorService.createProcessor(bridgeId, customerId, owner, processorRequest);
    return Response.accepted(processorService.toResponse(processor)).build();
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 45 with Processor

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

the class ProcessorDAO method findByBridgeIdAndCustomerId.

private ListResult<Processor> findByBridgeIdAndCustomerId(String bridgeId, String customerId, QueryProcessorResourceInfo queryInfo, Set<ProcessorType> restrictTypes) {
    /*
         * Unfortunately we can't rely on Panaches in-built Paging due the fetched join in our query
         * for Processor e.g. join fetch p.bridge. Instead, we simply build a list of ids to fetch and then
         * execute the join fetch as normal. So the workflow here is:
         *
         * - Count the number of Processors on a bridge. If > 0
         * - Select the ids of the Processors that need to be retrieved based on the page/size requirements
         * - Select the Processors in the list of ids, performing the fetch join of the Bridge
         */
    // We don't consider filtering here; so this could be short-cut more but the additional code doesn't really make it worthwhile
    Parameters p = Parameters.with(Bridge.CUSTOMER_ID_PARAM, customerId).and(Processor.BRIDGE_ID_PARAM, bridgeId);
    Long processorCount = countProcessorsOnBridge(p);
    if (processorCount == 0L) {
        return new ListResult<>(emptyList(), queryInfo.getPageNumber(), processorCount);
    }
    ProcessorResults results = getProcessorIds(customerId, bridgeId, queryInfo, restrictTypes);
    List<Processor> processors = find("#PROCESSOR.findByIds", Parameters.with(IDS_PARAM, results.ids)).list();
    return new ListResult<>(processors, queryInfo.getPageNumber(), results.total);
}
Also used : ListResult(com.redhat.service.smartevents.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.smartevents.manager.models.Processor)

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