use of com.redhat.service.bridge.manager.models.Bridge 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);
}
use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgesServiceImpl method createBridge.
@Transactional
@Override
public Bridge createBridge(String customerId, BridgeRequest bridgeRequest) {
if (bridgeDAO.findByNameAndCustomerId(bridgeRequest.getName(), customerId) != null) {
throw new AlreadyExistingItemException(String.format("Bridge with name '%s' already exists for customer with id '%s'", bridgeRequest.getName(), customerId));
}
Bridge bridge = bridgeRequest.toEntity();
bridge.setStatus(ManagedResourceStatus.ACCEPTED);
bridge.setSubmittedAt(ZonedDateTime.now(ZoneOffset.UTC));
bridge.setCustomerId(customerId);
bridge.setShardId(shardService.getAssignedShardId(bridge.getId()));
bridgeDAO.persist(bridge);
rhoasService.createTopicAndGrantAccessFor(getBridgeTopicName(bridge), RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
LOGGER.info("Bridge with id '{}' has been created for customer '{}'", bridge.getId(), bridge.getCustomerId());
return bridge;
}
use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BridgesServiceImpl method deleteBridge.
@Transactional
@Override
public void deleteBridge(String id, String customerId) {
Long processorsCount = processorService.getProcessorsCount(id, customerId);
if (processorsCount > 0) {
// 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);
bridge.setStatus(ManagedResourceStatus.DEPROVISION);
LOGGER.info("Bridge with id '{}' for customer '{}' has been marked for deletion", bridge.getId(), bridge.getCustomerId());
}
use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method getProcessor.
@Transactional
@Override
public Processor getProcessor(String processorId, String bridgeId, String customerId) {
Bridge bridge = bridgesService.getBridge(bridgeId, customerId);
Processor processor = processorDAO.findByIdBridgeIdAndCustomerId(processorId, bridge.getId(), bridge.getCustomerId());
if (processor == null) {
throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist on Bridge '%s' for customer '%s'", processorId, bridgeId, customerId));
}
return processor;
}
use of com.redhat.service.bridge.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method updateProcessorStatus.
@Transactional
@Override
public Processor updateProcessorStatus(ProcessorDTO processorDTO) {
Bridge bridge = bridgesService.getBridge(processorDTO.getBridgeId());
Processor p = processorDAO.findById(processorDTO.getId());
if (p == null) {
throw new ItemNotFoundException(String.format("Processor with id '%s' does not exist for Bridge '%s' for customer '%s'", bridge.getId(), bridge.getCustomerId(), processorDTO.getCustomerId()));
}
p.setStatus(processorDTO.getStatus());
p.setModifiedAt(ZonedDateTime.now());
if (processorDTO.getStatus().equals(ManagedResourceStatus.DELETED)) {
processorDAO.deleteById(processorDTO.getId());
}
if (processorDTO.getStatus().equals(ManagedResourceStatus.READY) && Objects.isNull(p.getPublishedAt())) {
p.setPublishedAt(ZonedDateTime.now());
}
// Update metrics
meterRegistry.counter("manager.processor.status.change", Collections.singletonList(Tag.of("status", processorDTO.getStatus().toString()))).increment();
return p;
}
Aggregations