Search in sources :

Example 51 with Bridge

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

the class BridgesAPI method createBridge.

@APIResponses(value = { @APIResponse(description = "Accepted.", responseCode = "202", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = BridgeResponse.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 = "Internal error.", responseCode = "500", content = @Content(mediaType = MediaType.APPLICATION_JSON)) })
@Operation(summary = "Create a Bridge instance", description = "Create a Bridge instance for the authenticated user.")
@POST
public Response createBridge(@Valid BridgeRequest bridgeRequest) {
    String customerId = identityResolver.resolve(jwt);
    String organisationId = identityResolver.resolveOrganisationId(jwt);
    String owner = identityResolver.resolveOwner(jwt);
    Bridge bridge = bridgesService.createBridge(customerId, organisationId, owner, bridgeRequest);
    return Response.accepted(bridgesService.toResponse(bridge)).build();
}
Also used : Bridge(com.redhat.service.smartevents.manager.models.Bridge) POST(javax.ws.rs.POST) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 52 with Bridge

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

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

the class BridgesServiceImpl method updateBridge.

@Transactional
@Override
public Bridge updateBridge(BridgeDTO bridgeDTO) {
    Bridge bridge = getBridge(bridgeDTO.getId(), bridgeDTO.getCustomerId());
    bridge.setStatus(bridgeDTO.getStatus());
    bridge.setEndpoint(bridgeDTO.getEndpoint());
    bridge.setModifiedAt(ZonedDateTime.now());
    if (bridgeDTO.getStatus().equals(ManagedResourceStatus.DELETED)) {
        bridgeDAO.deleteById(bridge.getId());
        metricsService.onOperationComplete(bridge, MetricsOperation.DELETE);
    } else if (bridgeDTO.getStatus().equals(ManagedResourceStatus.READY)) {
        if (Objects.isNull(bridge.getPublishedAt())) {
            bridge.setPublishedAt(ZonedDateTime.now());
            metricsService.onOperationComplete(bridge, MetricsOperation.PROVISION);
        }
    }
    LOGGER.info("Bridge with id '{}' has been updated for customer '{}'", bridge.getId(), bridge.getCustomerId());
    return bridge;
}
Also used : Bridge(com.redhat.service.smartevents.manager.models.Bridge) Transactional(javax.transaction.Transactional)

Example 54 with Bridge

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

the class ProcessorServiceImpl method createErrorHandlerProcessor.

@Override
@Transactional
public Processor createErrorHandlerProcessor(String bridgeId, String customerId, String owner, ProcessorRequest processorRequest) {
    Bridge bridge = bridgesService.getBridge(bridgeId, customerId);
    ProcessorType processorType = processorRequest.getType();
    if (processorType != ProcessorType.SINK) {
        throw new InternalPlatformException("Unable to configure error handler");
    }
    return doCreateProcessor(bridge, customerId, owner, ProcessorType.ERROR_HANDLER, processorRequest);
}
Also used : ProcessorType(com.redhat.service.smartevents.infra.models.processors.ProcessorType) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Transactional(javax.transaction.Transactional)

Example 55 with Bridge

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

the class BridgeDAO method findByCustomerId.

public ListResult<Bridge> findByCustomerId(String customerId, QueryResourceInfo queryInfo) {
    Parameters parameters = Parameters.with("customerId", customerId);
    PanacheQuery<Bridge> query = find("#BRIDGE.findByCustomerId", parameters);
    String filterName = queryInfo.getFilterInfo().getFilterName();
    Set<ManagedResourceStatus> filterStatus = queryInfo.getFilterInfo().getFilterStatus();
    if (Objects.nonNull(filterName)) {
        query.filter("byName", Parameters.with("name", filterName + "%"));
    }
    if (Objects.nonNull(filterStatus) && !filterStatus.isEmpty()) {
        query.filter("byStatus", Parameters.with("status", filterStatus));
    }
    long total = query.count();
    List<Bridge> bridges = query.page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    return new ListResult<>(bridges, queryInfo.getPageNumber(), total);
}
Also used : ListResult(com.redhat.service.smartevents.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Aggregations

Bridge (com.redhat.service.smartevents.manager.models.Bridge)99 QuarkusTest (io.quarkus.test.junit.QuarkusTest)68 Test (org.junit.jupiter.api.Test)68 Processor (com.redhat.service.smartevents.manager.models.Processor)45 Transactional (javax.transaction.Transactional)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 TestSecurity (io.quarkus.test.security.TestSecurity)14 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)13 Work (com.redhat.service.smartevents.manager.models.Work)13 QueryProcessorResourceInfo (com.redhat.service.smartevents.infra.models.QueryProcessorResourceInfo)12 QueryResourceInfo (com.redhat.service.smartevents.infra.models.QueryResourceInfo)11 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)11 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)10 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)9 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)8 ProcessorListResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse)8 Response (io.restassured.response.Response)8 Connector (com.openshift.cloud.api.connector.models.Connector)7 Action (com.redhat.service.smartevents.infra.models.gateways.Action)7 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)7