use of com.redhat.service.bridge.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method testDeleteConnectorFailureOnExternalConnectorDestruction.
@Test
public void testDeleteConnectorFailureOnExternalConnectorDestruction() {
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);
doThrow(new InternalPlatformException(createFailureErrorMessageFor("errorDeletingConnector"), new RuntimeException("error"))).when(connectorsApiClient).deleteConnector(anyString());
processorService.deleteProcessor(bridge.getId(), processor.getId(), TestConstants.DEFAULT_CUSTOMER_ID);
reloadAssertProcessorIsInStatus(processor, DEPROVISION);
waitForProcessorAndConnectorToFail(processor);
verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(any(), any());
verify(connectorsApiClient, atLeast(1)).deleteConnector(anyString());
assertShardAsksForProcessorToBeDeletedDoesNotInclude(processor);
}
use of com.redhat.service.bridge.manager.models.ConnectorEntity 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.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorker method delegate.
private Processor delegate(Work work, Processor processor) {
// Get Processor's Connector for which work needs completing
final ConnectorEntity connectorEntity = getConnectorEntity(processor);
// Delegate to the ConnectorWorker however mimic that the Work originated from the Processor.
Work connectorEntityWork = Work.forDependentResource(connectorEntity, work);
ConnectorEntity updatedConnectorEntity = connectorWorker.handleWork(connectorEntityWork);
processor.setDependencyStatus(updatedConnectorEntity.getStatus());
return persist(processor);
}
use of com.redhat.service.bridge.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorkerTest method handleWorkProvisioningWithKnownResourceMultiplePasses.
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "ACCEPTED", "PROVISIONING" })
void handleWorkProvisioningWithKnownResourceMultiplePasses(ManagedResourceStatus status) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
ConnectorEntity connectorEntity = spy(new ConnectorEntity());
connectorEntity.setStatus(status);
Connector connector = new Connector();
connector.setStatus(new ConnectorStatusStatus().state(ConnectorState.READY));
when(connectorsDAO.findById(RESOURCE_ID)).thenReturn(connectorEntity);
when(connectorsDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(connectorEntity)).thenReturn(connectorEntity);
// Managed Connector will not be available immediately
when(connectorsApi.getConnector(connectorEntity)).thenReturn(null, connector);
worker.handleWork(work);
verify(rhoasService).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsApi).createConnector(connectorEntity);
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
// This emulates a subsequent invocation by WorkManager
worker.handleWork(work);
verify(rhoasService, times(2)).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsApi, atMostOnce()).createConnector(connectorEntity);
assertThat(connectorEntity.getPublishedAt()).isNotNull();
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.READY);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
verify(workManager, never()).complete(work);
verify(connectorEntity, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
use of com.redhat.service.bridge.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithConnector.
@ParameterizedTest
@MethodSource("srcHandleWorkProvisioningWithKnownResourceWithConnector")
void handleWorkProvisioningWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus connectorStatusWhenComplete, boolean isWorkComplete) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
Processor processor = new Processor();
processor.setStatus(status);
ConnectorEntity connector = new ConnectorEntity();
connector.setStatus(ManagedResourceStatus.ACCEPTED);
when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
when(processorDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(processor)).thenReturn(processor);
when(connectorsDAO.findByProcessorId(processor.getId())).thenReturn(connector);
doAnswer((i) -> {
// Emulate ConnectorWorker completing work
connector.setStatus(connectorStatusWhenComplete);
return connector;
}).when(connectorWorker).handleWork(any(Work.class));
worker.handleWork(work);
assertThat(processor.getDependencyStatus()).isEqualTo(connectorStatusWhenComplete);
verify(connectorWorker).handleWork(workArgumentCaptor.capture());
Work connectorWork = workArgumentCaptor.getValue();
assertThat(connectorWork).isNotNull();
assertThat(connectorWork.getId()).isEqualTo(work.getId());
assertThat(connectorWork.getManagedResourceId()).isEqualTo(connector.getId());
assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
verify(workManager, times(isWorkComplete ? 1 : 0)).complete(any(Work.class));
}
Aggregations