Search in sources :

Example 56 with Bridge

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

the class ProcessorServiceTest method getProcessorByStatuses.

@Test
@Transactional
public void getProcessorByStatuses() {
    Bridge b = createPersistBridge(ManagedResourceStatus.READY);
    final Processor processor1 = new Processor();
    processor1.setName("My Processor");
    processor1.setBridge(b);
    processor1.setShardId(TestConstants.SHARD_ID);
    processor1.setStatus(ManagedResourceStatus.ACCEPTED);
    processor1.setDependencyStatus(ManagedResourceStatus.READY);
    processor1.setSubmittedAt(ZonedDateTime.now());
    processor1.setDefinition(new TextNode("definition"));
    processorDAO.persist(processor1);
    final Processor processor2 = new Processor();
    processor2.setName("My Processor 2");
    processor2.setBridge(b);
    processor2.setShardId(TestConstants.SHARD_ID);
    processor2.setStatus(ManagedResourceStatus.READY);
    processor2.setDependencyStatus(ManagedResourceStatus.READY);
    processor2.setSubmittedAt(ZonedDateTime.now());
    processor2.setDefinition(new TextNode("definition"));
    processorDAO.persist(processor2);
    final Processor processor3 = new Processor();
    processor3.setName("My Processor 3");
    processor3.setBridge(b);
    processor3.setShardId(TestConstants.SHARD_ID);
    processor3.setStatus(ManagedResourceStatus.DEPROVISION);
    processor3.setDependencyStatus(ManagedResourceStatus.DELETED);
    processor3.setSubmittedAt(ZonedDateTime.now());
    processor3.setDefinition(new TextNode("definition"));
    processorDAO.persist(processor3);
    List<Processor> processors = processorService.findByShardIdWithReadyDependencies(TestConstants.SHARD_ID);
    assertThat(processors.size()).isEqualTo(2);
    processors.forEach((px) -> assertThat(px.getName()).isIn("My Processor", "My Processor 3"));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) TextNode(com.fasterxml.jackson.databind.node.TextNode) Bridge(com.redhat.service.bridge.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Transactional(javax.transaction.Transactional)

Example 57 with Bridge

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

the class ProcessorServiceTest method testUpdateProcessorStatusReadyPublishedAt.

@Test
public void testUpdateProcessorStatusReadyPublishedAt() {
    Bridge b = createPersistBridge(ManagedResourceStatus.READY);
    ProcessorRequest r = new ProcessorRequest("My Processor", createKafkaAction());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), r);
    processor.setStatus(ManagedResourceStatus.PROVISIONING);
    processorService.updateProcessorStatus(processorService.toDTO(processor));
    Processor retrievedProcessor = processorService.getProcessor(processor.getId(), b.getId(), b.getCustomerId());
    assertThat(retrievedProcessor.getStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
    assertThat(retrievedProcessor.getPublishedAt()).isNull();
    // Once ready it should have its published date set
    processor.setStatus(ManagedResourceStatus.READY);
    processorService.updateProcessorStatus(processorService.toDTO(processor));
    Processor publishedProcessor = processorService.getProcessor(processor.getId(), b.getId(), b.getCustomerId());
    assertThat(publishedProcessor.getStatus()).isEqualTo(ManagedResourceStatus.READY);
    ZonedDateTime publishedAt = publishedProcessor.getPublishedAt();
    assertThat(publishedAt).isNotNull();
    // Check calls to set PublishedAt at idempotent
    processorService.updateProcessorStatus(processorService.toDTO(processor));
    Processor publishedProcessor2 = processorService.getProcessor(processor.getId(), b.getId(), b.getCustomerId());
    assertThat(publishedProcessor2.getStatus()).isEqualTo(ManagedResourceStatus.READY);
    assertThat(publishedProcessor2.getPublishedAt()).isEqualTo(publishedAt);
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ZonedDateTime(java.time.ZonedDateTime) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.bridge.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 58 with Bridge

use of com.redhat.service.bridge.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());
        rhoasService.deleteTopicAndRevokeAccessFor(getBridgeTopicName(bridge), RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
    }
    if (bridgeDTO.getStatus().equals(ManagedResourceStatus.READY) && Objects.isNull(bridge.getPublishedAt())) {
        bridge.setPublishedAt(ZonedDateTime.now());
    }
    // Update metrics
    meterRegistry.counter("manager.bridge.status.change", Collections.singletonList(Tag.of("status", bridgeDTO.getStatus().toString()))).increment();
    LOGGER.info("Bridge with id '{}' has been updated for customer '{}'", bridge.getId(), bridge.getCustomerId());
    return bridge;
}
Also used : Bridge(com.redhat.service.bridge.manager.models.Bridge) Transactional(javax.transaction.Transactional)

Example 59 with Bridge

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

the class ProcessorServiceImpl method createProcessor.

@Override
public Processor createProcessor(String bridgeId, String customerId, ProcessorRequest processorRequest) {
    /* We cannot deploy Processors to a Bridge that is not Available */
    Bridge bridge = bridgesService.getReadyBridge(bridgeId, customerId);
    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();
    Set<BaseFilter> requestedFilters = processorRequest.getFilters();
    String requestedTransformationTemplate = processorRequest.getTransformationTemplate();
    BaseAction requestedAction = processorRequest.getAction();
    ActionProvider actionProvider = actionProviderFactory.getActionProvider(requestedAction.getType());
    BaseAction resolvedAction = actionProviderFactory.resolve(requestedAction, bridge.getId(), customerId, newProcessor.getId());
    newProcessor.setName(processorRequest.getName());
    newProcessor.setSubmittedAt(ZonedDateTime.now());
    newProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
    newProcessor.setBridge(bridge);
    newProcessor.setShardId(shardService.getAssignedShardId(newProcessor.getId()));
    ProcessorDefinition definition = new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, requestedAction, resolvedAction);
    newProcessor.setDefinition(definitionToJsonNode(definition));
    LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for creation", newProcessor.getId(), newProcessor.getBridge().getCustomerId(), newProcessor.getBridge().getId());
    createProcessorConnectorEntity(newProcessor, actionProvider, resolvedAction);
    workManager.schedule(newProcessor);
    return newProcessor;
}
Also used : ActionProvider(com.redhat.service.bridge.actions.ActionProvider) Processor(com.redhat.service.bridge.manager.models.Processor) ProcessorDefinition(com.redhat.service.bridge.infra.models.processors.ProcessorDefinition) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Bridge(com.redhat.service.bridge.manager.models.Bridge) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) AlreadyExistingItemException(com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)

Example 60 with Bridge

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

the class BridgeDAO method findByCustomerId.

public ListResult<Bridge> findByCustomerId(String customerId, QueryInfo queryInfo) {
    Parameters parameters = Parameters.with("customerId", customerId);
    long total = find("#BRIDGE.findByCustomerId", parameters).count();
    List<Bridge> bridges = find("#BRIDGE.findByCustomerId", parameters).page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    return new ListResult<>(bridges, queryInfo.getPageNumber(), total);
}
Also used : ListResult(com.redhat.service.bridge.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) Bridge(com.redhat.service.bridge.manager.models.Bridge)

Aggregations

Bridge (com.redhat.service.bridge.manager.models.Bridge)60 QuarkusTest (io.quarkus.test.junit.QuarkusTest)46 Test (org.junit.jupiter.api.Test)46 Processor (com.redhat.service.bridge.manager.models.Processor)34 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)15 QueryInfo (com.redhat.service.bridge.infra.models.QueryInfo)11 Transactional (javax.transaction.Transactional)8 BridgeRequest (com.redhat.service.bridge.manager.api.models.requests.BridgeRequest)7 ItemNotFoundException (com.redhat.service.bridge.infra.exceptions.definitions.user.ItemNotFoundException)6 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)6 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)6 Connector (com.openshift.cloud.api.connector.models.Connector)5 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)4 AlreadyExistingItemException (com.redhat.service.bridge.infra.exceptions.definitions.user.AlreadyExistingItemException)3 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)3 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2 BridgeLifecycleException (com.redhat.service.bridge.infra.exceptions.definitions.user.BridgeLifecycleException)2 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)2 ZonedDateTime (java.time.ZonedDateTime)2