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"));
}
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);
}
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;
}
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;
}
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);
}
Aggregations