use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceConnectorTest method testDeleteConnectorFailureOnKafkaTopicDeletion.
@Test
void testDeleteConnectorFailureOnKafkaTopicDeletion() {
Bridge bridge = createPersistBridge(READY);
Processor processor = createPersistProcessor(bridge, READY);
createPersistentConnector(processor, READY);
// 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(RhoasServiceImpl.createFailureErrorMessageFor("errorTopic"), new RuntimeException("error"))).when(rhoasService).deleteTopicAndRevokeAccessFor(anyString(), any());
processorService.deleteProcessor(bridge.getId(), processor.getId(), DEFAULT_CUSTOMER_ID);
reloadAssertProcessorIsInStatus(processor, DEPROVISION);
waitForProcessorAndConnectorToFail(processor);
verify(rhoasService, atLeast(1)).deleteTopicAndRevokeAccessFor(TestConstants.DEFAULT_KAFKA_TOPIC, RhoasTopicAccessType.PRODUCER);
verify(connectorsApiClient, atLeast(1)).deleteConnector(anyString());
assertShardAsksForProcessorToBeDeletedDoesNotInclude(processor);
}
use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceConnectorTest method testDeleteConnectorFailureOnExternalConnectorDestruction.
@Test
void testDeleteConnectorFailureOnExternalConnectorDestruction() {
Bridge bridge = createPersistBridge(READY);
Processor processor = createPersistProcessor(bridge, READY);
createPersistentConnector(processor, READY);
// 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(RhoasServiceImpl.createFailureErrorMessageFor("errorDeletingConnector"), new RuntimeException("error"))).when(connectorsApiClient).deleteConnector(anyString());
processorService.deleteProcessor(bridge.getId(), processor.getId(), 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.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceConnectorTest method createConnectorSuccess.
@Test
void createConnectorSuccess() {
Bridge b = createPersistBridge(READY);
Action slackAction = createSlackAction();
ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
// Emulate successful External Connector creation
Connector externalConnector = stubbedExternalConnector("connectorExternalId");
ConnectorStatusStatus externalConnectorStatus = new ConnectorStatusStatus();
externalConnectorStatus.setState(ConnectorState.READY);
externalConnector.setStatus(externalConnectorStatus);
when(connectorsApiClient.getConnector(any())).thenReturn(externalConnector);
when(connectorsApiClient.createConnector(any(ConnectorEntity.class))).thenCallRealMethod();
when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(externalConnector);
when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenReturn(new Topic());
Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), b.getOwner(), processorRequest);
// There will be 2 re-tries at 5s each. Add 5s to be certain everything completes.
await().atMost(15, SECONDS).untilAsserted(() -> {
ConnectorEntity connector = connectorsDAO.findByProcessorIdAndName(processor.getId(), resourceNamesProvider.getProcessorConnectorName(processor.getId()));
assertThat(connector).isNotNull();
assertThat(connector.getError()).isNullOrEmpty();
assertThat(connector.getStatus()).isEqualTo(READY);
});
verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
ArgumentCaptor<ConnectorRequest> connectorCaptor = ArgumentCaptor.forClass(ConnectorRequest.class);
verify(connectorsApiClient).createConnector(connectorCaptor.capture());
ConnectorRequest calledConnector = connectorCaptor.getValue();
assertThat(calledConnector.getKafka()).isNotNull();
}
use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceConnectorTest method testDeleteRequestedConnectorSuccess.
@Test
void testDeleteRequestedConnectorSuccess() {
Bridge bridge = createPersistBridge(READY);
Processor processor = createPersistProcessor(bridge, READY);
createPersistentConnector(processor, READY);
// 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());
processorService.deleteProcessor(bridge.getId(), processor.getId(), DEFAULT_CUSTOMER_ID);
reloadAssertProcessorIsInStatus(processor, DEPROVISION);
waitForConnectorToBeDeleted(bridge, processor);
verify(rhoasService).deleteTopicAndRevokeAccessFor(TestConstants.DEFAULT_KAFKA_TOPIC, RhoasTopicAccessType.PRODUCER);
verify(connectorsApiClient).deleteConnector("connectorExternalId");
assertShardAsksForProcessorToBeDeletedIncludes(processor);
}
use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorkerTest method handleWorkDeletingWithKnownResourceMultiplePasses.
@Transactional
@ParameterizedTest
@MethodSource("provideArgsForDeleteTest")
void handleWorkDeletingWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType) {
Bridge bridge = Fixtures.createBridge();
Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
ConnectorEntity connectorEntity = useSourceConnectorEntity ? Fixtures.createSourceConnector(processor, resourceStatus) : Fixtures.createSinkConnector(processor, resourceStatus);
// The publishedAt date is set by the Worker so reset that set by the Fixture
connectorEntity.setPublishedAt(null);
bridgeDAO.persist(bridge);
processorDAO.persist(processor);
connectorsDAO.persist(connectorEntity);
Work work = workManager.schedule(connectorEntity);
Connector connector = new Connector();
connector.setStatus(new ConnectorStatusStatus().state(connectorState));
// Managed Connector will initially be available before it is deleted
when(connectorsApi.getConnector(connectorEntity.getConnectorExternalId())).thenReturn(connector, (Connector) null);
ConnectorEntity refreshed = worker.handleWork(work);
if (connectorState != ConnectorState.DELETED) {
assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETING);
assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETING);
verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsApi).deleteConnector(connectorEntity.getConnectorExternalId());
// This emulates a subsequent invocation by WorkManager
refreshed = worker.handleWork(work);
}
verify(rhoasService).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
assertThat(connectorsDAO.findById(connectorEntity.getId())).isNull();
assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETED);
assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
assertThat(workManager.exists(work)).isTrue();
}
Aggregations