Search in sources :

Example 11 with Processor

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

the class ProcessorServiceTest method getProcessor_bridgeDoesNotExist.

@Test
public void getProcessor_bridgeDoesNotExist() {
    Bridge b = createPersistBridge(ManagedResourceStatus.READY);
    ProcessorRequest r = new ProcessorRequest("My Processor", createKafkaAction());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), r);
    await().atMost(5, SECONDS).untilAsserted(() -> {
        Processor p = processorDAO.findById(processor.getId());
        assertThat(p).isNotNull();
        assertThat(p.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
    });
    assertThatExceptionOfType(ItemNotFoundException.class).isThrownBy(() -> processorService.getProcessor(processor.getId(), "doesNotExist", b.getCustomerId()));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.bridge.manager.models.Bridge) ItemNotFoundException(com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 12 with Processor

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

the class ProcessorServiceTest method testDeleteConnectorFailureOnKafkaTopicDeletion.

@Test
public void testDeleteConnectorFailureOnKafkaTopicDeletion() {
    Bridge bridge = createPersistBridge(ManagedResourceStatus.READY);
    Processor processor = Fixtures.createProcessor(bridge, "bridgeTestDelete", ManagedResourceStatus.READY);
    ConnectorEntity connector = Fixtures.createConnector(processor, "connectorToBeDeleted", ManagedResourceStatus.READY, "topicName");
    processorDAO.persist(processor);
    connectorsDAO.persist(connector);
    // Emulate successful External Connector creation
    Connector externalConnector = new Connector();
    final ConnectorStatusStatus externalConnectorStatus = new ConnectorStatusStatus();
    externalConnectorStatus.setState(ConnectorState.READY);
    externalConnector.setStatus(externalConnectorStatus);
    when(connectorsApiClient.getConnector(any())).thenReturn(externalConnector);
    // Emulate successful External Connector deletion
    doAnswer(i -> {
        externalConnectorStatus.setState(ConnectorState.DELETED);
        return null;
    }).when(connectorsApiClient).deleteConnector(any());
    doThrow(new InternalPlatformException(createFailureErrorMessageFor("errorTopic"), new RuntimeException("error"))).when(rhoasService).deleteTopicAndRevokeAccessFor(anyString(), any());
    processorService.deleteProcessor(bridge.getId(), processor.getId(), TestConstants.DEFAULT_CUSTOMER_ID);
    reloadAssertProcessorIsInStatus(processor, DEPROVISION);
    waitForProcessorAndConnectorToFail(processor);
    verify(rhoasService, atLeast(1)).deleteTopicAndRevokeAccessFor(eq("topicName"), eq(RhoasTopicAccessType.PRODUCER));
    verify(connectorsApiClient, atLeast(1)).deleteConnector(anyString());
    assertShardAsksForProcessorToBeDeletedDoesNotInclude(processor);
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.bridge.manager.models.Processor) InternalPlatformException(com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) Bridge(com.redhat.service.bridge.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 13 with Processor

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

the class ProcessorServiceTest method updateProcessorStatus_processorDoesNotExist.

@Test
public void updateProcessorStatus_processorDoesNotExist() {
    Processor p = new Processor();
    p.setBridge(createPersistBridge(ManagedResourceStatus.READY));
    p.setId("foo");
    ProcessorDTO processor = processorService.toDTO(p);
    assertThatExceptionOfType(ItemNotFoundException.class).isThrownBy(() -> processorService.updateProcessorStatus(processor));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ItemNotFoundException(com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 14 with Processor

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

the class ProcessorsAPI method getProcessor.

@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(processorId, bridgeId, customerId);
    return Response.ok(processorService.toResponse(processor)).build();
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 15 with Processor

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

the class ProcessorDAO method findByBridgeIdAndCustomerId.

public ListResult<Processor> findByBridgeIdAndCustomerId(String bridgeId, String customerId, QueryInfo queryInfo) {
    /*
         * 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
         */
    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);
    }
    int firstResult = getFirstResult(queryInfo.getPageNumber(), queryInfo.getPageSize());
    TypedQuery<String> idsQuery = getEntityManager().createNamedQuery("PROCESSOR.idsByBridgeIdAndCustomerId", String.class);
    addParamsToNamedQuery(p, idsQuery);
    List<String> ids = idsQuery.setMaxResults(queryInfo.getPageSize()).setFirstResult(firstResult).getResultList();
    List<Processor> processors = getEntityManager().createNamedQuery("PROCESSOR.findByIds", Processor.class).setParameter(IDS_PARAM, ids).getResultList();
    return new ListResult<>(processors, queryInfo.getPageNumber(), processorCount);
}
Also used : ListResult(com.redhat.service.bridge.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.bridge.manager.models.Processor)

Aggregations

Processor (com.redhat.service.bridge.manager.models.Processor)52 Bridge (com.redhat.service.bridge.manager.models.Bridge)34 QuarkusTest (io.quarkus.test.junit.QuarkusTest)32 Test (org.junit.jupiter.api.Test)32 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)14 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)9 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)7 ItemNotFoundException (com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException)6 QueryInfo (com.redhat.service.bridge.infra.models.QueryInfo)6 Transactional (javax.transaction.Transactional)6 Connector (com.openshift.cloud.api.connector.models.Connector)5 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)5 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)4 Work (com.redhat.service.bridge.manager.models.Work)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ZonedDateTime (java.time.ZonedDateTime)3 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)2 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)2