use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorkerTest method handleWorkProvisioningWithKnownResourceMultiplePasses.
@Transactional
@ParameterizedTest
@MethodSource("provideArgsForCreateTest")
void handleWorkProvisioningWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType, ManagedResourceStatus expectedResourceStatus) {
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.setId(TEST_CONNECTOR_EXTERNAL_ID);
connector.setStatus(new ConnectorStatusStatus().state(connectorState));
when(connectorsApi.getConnector(TEST_CONNECTOR_EXTERNAL_ID)).thenReturn(null, connector);
when(connectorsApi.createConnector(connectorEntity)).thenReturn(connector);
ConnectorEntity refreshed = worker.handleWork(work);
verify(rhoasService).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
verify(connectorsApi).createConnector(connectorEntity);
assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.PREPARING);
assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
// This emulates a subsequent invocation by WorkManager
refreshed = worker.handleWork(work);
verify(rhoasService, times(2)).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
verify(connectorsApi, atMostOnce()).createConnector(connectorEntity);
assertThat(refreshed.getStatus()).isEqualTo(expectedResourceStatus);
assertThat(refreshed.getDependencyStatus()).isEqualTo(expectedResourceStatus);
if (expectedResourceStatus == ManagedResourceStatus.READY) {
assertThat(refreshed.getPublishedAt()).isNotNull();
} else {
assertThat(refreshed.getPublishedAt()).isNull();
}
assertThat(workManager.exists(work)).isTrue();
}
use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorkerTest method handleWorkDeletingWithKnownResourceMultiplePasses.
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "DEPROVISION", "DELETING" })
void handleWorkDeletingWithKnownResourceMultiplePasses(ManagedResourceStatus status) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
ConnectorEntity connectorEntity = spy(new ConnectorEntity());
connectorEntity.setStatus(status);
connectorEntity.setTopicName("topicName");
connectorEntity.setConnectorExternalId("connectorExternalId");
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 initially be available before it is deleted
when(connectorsApi.getConnector(connectorEntity)).thenReturn(connector, null);
worker.handleWork(work);
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.DELETING);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETING);
verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsApi).deleteConnector(connectorEntity.getConnectorExternalId());
// This emulates a subsequent invocation by WorkManager
worker.handleWork(work);
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.DELETED);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
verify(rhoasService).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsDAO).deleteById(connectorEntity.getId());
verify(workManager, never()).complete(work);
verify(connectorEntity, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method createConnectorSuccess.
@Test
void createConnectorSuccess() {
Bridge b = createPersistBridge(ManagedResourceStatus.READY);
BaseAction 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);
// Emulate the connector not being found when first looked up, to force provisioning
when(connectorsApiClient.getConnector(any())).thenReturn(null, 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(), 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(), String.format("OpenBridge-slack_sink_0.1-%s", processor.getId()));
assertThat(connector).isNotNull();
assertThat(connector.getError()).isNullOrEmpty();
assertThat(connector.getStatus()).isEqualTo(ManagedResourceStatus.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 ProcessorServiceTest method testDeleteRequestedConnectorSuccess.
@Test
public void testDeleteRequestedConnectorSuccess() {
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());
processorService.deleteProcessor(bridge.getId(), processor.getId(), TestConstants.DEFAULT_CUSTOMER_ID);
reloadAssertProcessorIsInStatus(processor, DEPROVISION);
waitForConnectorToBeDeleted(bridge, processor);
verify(rhoasService).deleteTopicAndRevokeAccessFor(eq("topicName"), eq(RhoasTopicAccessType.PRODUCER));
verify(connectorsApiClient).deleteConnector("connectorExternalId");
assertShardAsksForProcessorToBeDeletedIncludes(processor);
}
use of com.openshift.cloud.api.connector.models.ConnectorStatusStatus in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorker method createDependencies.
@Override
public ConnectorEntity createDependencies(Work work, ConnectorEntity connectorEntity) {
LOGGER.info("Creating dependencies for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
// This is idempotent as it gets overridden later depending on actual state
connectorEntity.setStatus(ManagedResourceStatus.PROVISIONING);
connectorEntity.setDependencyStatus(ManagedResourceStatus.PROVISIONING);
connectorEntity = persist(connectorEntity);
// Step 1 - Create Kafka Topic
LOGGER.debug("Creating Kafka Topic for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
rhoasService.createTopicAndGrantAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
// Step 2 - Create Connector
LOGGER.debug("Creating Managed Connector for '{}' [{}]", connectorEntity.getName(), connectorEntity.getId());
Connector connector = connectorsApi.getConnector(connectorEntity);
if (Objects.isNull(connector)) {
LOGGER.debug("Managed Connector for '{}' [{}] not found. Provisioning...", connectorEntity.getName(), connectorEntity.getId());
// This is an asynchronous operation so exit and wait for it's READY state to be detected on the next poll.
return deployConnector(connectorEntity);
}
// Step 3 - Check it has been provisioned
ConnectorStatusStatus status = connector.getStatus();
if (Objects.isNull(status)) {
LOGGER.debug("Managed Connector status for '{}' [{}] is undetermined.", connectorEntity.getName(), connectorEntity.getId());
return connectorEntity;
}
if (status.getState() == ConnectorState.READY) {
LOGGER.debug("Managed Connector for '{}' [{}] is ready.", connectorEntity.getName(), connectorEntity.getId());
// Connector is ready. We can proceed with the deployment of the Processor in the Shard
// The Processor will be provisioned by the Shard when it is in ACCEPTED state *and* Connectors are READY (or null).
connectorEntity.setStatus(ManagedResourceStatus.READY);
connectorEntity.setPublishedAt(ZonedDateTime.now(ZoneOffset.UTC));
connectorEntity.setDependencyStatus(ManagedResourceStatus.READY);
return persist(connectorEntity);
}
if (status.getState() == ConnectorState.FAILED) {
LOGGER.debug("Creating Managed Connector for '{}' [{}] failed.", connectorEntity.getName(), connectorEntity.getId());
// Deployment of the Connector has failed. Bubble FAILED state up to ProcessorWorker.
connectorEntity.setStatus(ManagedResourceStatus.FAILED);
return persist(connectorEntity);
}
return connectorEntity;
}
Aggregations