Search in sources :

Example 51 with Processor

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

the class ProcessorsAPI method updateProcessor.

@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 = "Update a Processor instance Filter definition or Transformation template.", description = "Update a Processor instance Filter definition or Transformation template for the authenticated user.")
@PUT
@Path("{bridgeId}/processors/{processorId}")
public Response updateProcessor(@NotEmpty @PathParam("bridgeId") String bridgeId, @NotEmpty @PathParam("processorId") String processorId, @Valid ProcessorRequest processorRequest) {
    String customerId = identityResolver.resolve(jwt);
    Processor processor = processorService.updateProcessor(bridgeId, processorId, customerId, processorRequest);
    return Response.accepted(processorService.toResponse(processor)).build();
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Path(javax.ws.rs.Path) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) PUT(javax.ws.rs.PUT)

Example 52 with Processor

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

the class ProcessorAPITest method setProcessorStatus.

@Transactional
protected void setProcessorStatus(String processorId, ManagedResourceStatus status) {
    Processor processor = processorDAO.findById(processorId);
    processor.setStatus(status);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) Transactional(javax.transaction.Transactional)

Example 53 with Processor

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

the class ProcessorAPITest method testDeleteProcessor.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void testDeleteProcessor() {
    Bridge bridge = Fixtures.createBridge();
    bridge.setStatus(READY);
    bridgeDAO.persist(bridge);
    Processor processor = Fixtures.createProcessor(bridge, READY);
    processorDAO.persist(processor);
    TestUtils.deleteProcessor(bridge.getId(), processor.getId()).then().statusCode(202);
    ProcessorResponse processorResponse = TestUtils.getProcessor(bridge.getId(), processor.getId()).as(ProcessorResponse.class);
    assertThat(processorResponse.getStatus()).isEqualTo(ManagedResourceStatus.DEPROVISION);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) Bridge(com.redhat.service.smartevents.manager.models.Bridge) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 54 with Processor

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

the class ProcessorAPITest method updateProcessorWithFilter.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void updateProcessorWithFilter() {
    Bridge bridge = Fixtures.createBridge();
    bridgeDAO.persist(bridge);
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("key", "value"));
    Response createResponse = TestUtils.addProcessorToBridge(bridge.getId(), new ProcessorRequest("myProcessor", filters, null, TestUtils.createKafkaAction()));
    ProcessorResponse processor = TestUtils.getProcessor(bridge.getId(), createResponse.as(ProcessorResponse.class).getId()).as(ProcessorResponse.class);
    setProcessorAsReady(processor.getId());
    Set<BaseFilter> updatedFilters = Set.of(new StringEquals("key1", "value1"), new StringEquals("key2", "value2"));
    Response response = TestUtils.updateProcessor(bridge.getId(), processor.getId(), new ProcessorRequest(processor.getName(), updatedFilters, processor.getTransformationTemplate(), processor.getAction()));
    assertThat(response.getStatusCode()).isEqualTo(202);
    ProcessorResponse updated = TestUtils.getProcessor(bridge.getId(), createResponse.as(ProcessorResponse.class).getId()).as(ProcessorResponse.class);
    assertThat(updated.getName()).isEqualTo("myProcessor");
    assertThat(updated.getFilters().size()).isEqualTo(2);
    assertThat(updated.getFilters().stream().filter(f -> f.getKey().equals("key1") && f.getValue().equals("value1")).count()).isEqualTo(1);
    assertThat(updated.getFilters().stream().filter(f -> f.getKey().equals("key2") && f.getValue().equals("value2")).count()).isEqualTo(1);
    assertThat(updated.getTransformationTemplate()).isNull();
    assertRequestedAction(updated);
}
Also used : StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ProcessorListResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) Response(io.restassured.response.Response) BeforeEach(org.junit.jupiter.api.BeforeEach) Action(com.redhat.service.smartevents.infra.models.gateways.Action) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BridgeDAO(com.redhat.service.smartevents.manager.dao.BridgeDAO) DatabaseManagerUtils(com.redhat.service.smartevents.manager.utils.DatabaseManagerUtils) SOURCE(com.redhat.service.smartevents.infra.models.processors.ProcessorType.SOURCE) TestUtils(com.redhat.service.smartevents.manager.utils.TestUtils) DEFAULT_USER_NAME(com.redhat.service.smartevents.manager.TestConstants.DEFAULT_USER_NAME) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) Map(java.util.Map) TypeRef(io.restassured.common.mapper.TypeRef) Awaitility.await(org.awaitility.Awaitility.await) Transactional(javax.transaction.Transactional) TestProfile(io.quarkus.test.junit.TestProfile) Set(java.util.Set) Test(org.junit.jupiter.api.Test) APIConstants(com.redhat.service.smartevents.infra.api.APIConstants) List(java.util.List) BridgeDTO(com.redhat.service.smartevents.infra.models.dto.BridgeDTO) Fixtures(com.redhat.service.smartevents.manager.utils.Fixtures) StringIn(com.redhat.service.smartevents.infra.models.filters.StringIn) ACCEPTED(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus.ACCEPTED) TestSecurity(io.quarkus.test.security.TestSecurity) ProcessorDAO(com.redhat.service.smartevents.manager.dao.ProcessorDAO) READY(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus.READY) TestConstants(com.redhat.service.smartevents.manager.TestConstants) KafkaTopicAction(com.redhat.service.smartevents.processor.actions.kafkatopic.KafkaTopicAction) HashMap(java.util.HashMap) ProcessorListResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse) ArrayList(java.util.ArrayList) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) Processor(com.redhat.service.smartevents.manager.models.Processor) SlackAction(com.redhat.service.smartevents.processor.actions.slack.SlackAction) USER_NAME_ATTRIBUTE_CLAIM(com.redhat.service.smartevents.infra.api.APIConstants.USER_NAME_ATTRIBUTE_CLAIM) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) StringEquals(com.redhat.service.smartevents.infra.models.filters.StringEquals) InjectMock(io.quarkus.test.junit.mockito.InjectMock) Mockito.when(org.mockito.Mockito.when) WorkerSchedulerProfile(com.redhat.service.smartevents.manager.WorkerSchedulerProfile) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Response(io.restassured.response.Response) JsonWebToken(org.eclipse.microprofile.jwt.JsonWebToken) RhoasService(com.redhat.service.smartevents.manager.RhoasService) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) BridgeRequest(com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest) SendToBridgeAction(com.redhat.service.smartevents.processor.actions.sendtobridge.SendToBridgeAction) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.smartevents.manager.models.Bridge) BaseFilter(com.redhat.service.smartevents.infra.models.filters.BaseFilter) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 55 with Processor

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

the class ProcessorAPITest method updateProcessorWhenProcessorNotInReadyState.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void updateProcessorWhenProcessorNotInReadyState() {
    Bridge bridge = Fixtures.createBridge();
    bridgeDAO.persist(bridge);
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.PROVISIONING);
    processorDAO.persist(processor);
    Response response = TestUtils.updateProcessor(bridge.getId(), processor.getId(), new ProcessorRequest(processor.getName(), Collections.emptySet(), null, TestUtils.createKafkaAction()));
    assertThat(response.getStatusCode()).isEqualTo(400);
}
Also used : ProcessorResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse) ProcessorListResponse(com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) Response(io.restassured.response.Response) Processor(com.redhat.service.smartevents.manager.models.Processor) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.smartevents.manager.models.Bridge) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

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