use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorsApiClientTest method doCreateConnectorApi.
@Test
void doCreateConnectorApi() throws ApiException {
when(connectorsApi.createConnector(any(), any())).thenReturn(testConnector());
Connector connector = connectorsApiClient.createConnector(testConnectorEntity());
assertThat(connector).isNotNull();
assertThat(connector.getId()).isEqualTo(TEST_CONNECTOR_EXTERNAL_ID);
ArgumentCaptor<ConnectorRequest> requestArgumentCaptor = ArgumentCaptor.forClass(ConnectorRequest.class);
verify(connectorsApi).createConnector(eq(true), requestArgumentCaptor.capture());
ConnectorRequest connectorRequest = requestArgumentCaptor.getValue();
assertThat(connectorRequest).isNotNull();
assertThat(connectorRequest.getName()).isEqualTo(TEST_CONNECTOR_NAME);
assertThat(connectorRequest.getDeploymentLocation().getKind()).isEqualTo("addon");
assertThat(connectorRequest.getDeploymentLocation().getClusterId()).isEqualTo(mcClusterId);
assertThat(connectorRequest.getConnectorTypeId()).isEqualTo(TEST_CONNECTOR_TYPE);
assertThat(connectorRequest.getServiceAccount().getClientId()).isEqualTo(serviceAccountId);
assertThat(connectorRequest.getServiceAccount().getClientSecret()).isEqualTo(serviceAccountSecret);
}
use of com.openshift.cloud.api.connector.models.Connector 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.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ManagedConnectorServiceApplication method createSlackConnector.
private Connector createSlackConnector() throws Exception {
ConnectorsApi apiInstance = createConnectorsAPI();
// Boolean | Perform the action in an asynchronous manner
// Connector | Connector data
Connector createConnectorRequest = new Connector();
ConnectorAllOfMetadata metadata = new ConnectorAllOfMetadata();
metadata.setName("openbridge-slack-connector");
metadata.setKafkaId("kafkaId-ignored");
createConnectorRequest.setMetadata(metadata);
AddonClusterTarget deploymentLocation = new AddonClusterTarget();
deploymentLocation.setKind("addon");
deploymentLocation.setClusterId("c4ovtrsldcav5gaeqkn0");
createConnectorRequest.setDeploymentLocation(deploymentLocation);
createConnectorRequest.setConnectorTypeId("slack_sink_0.1");
KafkaConnectionSettings kafka = new KafkaConnectionSettings();
kafka.setBootstrapServer(kafkaUrl);
kafka.setClientId(serviceAccountId);
kafka.setClientSecret(serviceAccountSecret);
createConnectorRequest.setKafka(kafka);
ConnectorSpec connectorSpec = new ConnectorSpec();
ConnectorSpecKafka connectorSpecKafka = new ConnectorSpecKafka();
connectorSpecKafka.setTopic("slacktopic");
connectorSpec.setConnectorSpecKafka(connectorSpecKafka);
SlackConnector connector = new SlackConnector();
connector.setChannel("mc");
connector.setWebhookUrl(webhookUrl);
connectorSpec.setConnector(connector);
createConnectorRequest.setConnectorSpec(connectorSpec);
try {
Connector connectorResult = apiInstance.createConnector(true, createConnectorRequest);
System.out.println("Connector created: " + connectorResult);
return connectorResult;
} catch (WebApplicationException e) {
Response response = e.getResponse();
System.out.println("Error code: " + response.getStatus());
ByteArrayInputStream arrayInputStream = (ByteArrayInputStream) response.getEntity();
Scanner scanner = new Scanner(arrayInputStream);
// To read all scanner content in one String
scanner.useDelimiter("\\Z");
String data = "";
if (scanner.hasNext()) {
data = scanner.next();
}
System.out.println(data);
throw e;
}
}
use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceTest method createConnectorFailureOnKafkaTopicCreation.
@Test
public void createConnectorFailureOnKafkaTopicCreation() {
Bridge b = createPersistBridge(ManagedResourceStatus.READY);
BaseAction slackAction = createSlackAction();
ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenThrow(new InternalPlatformException(createFailureErrorMessageFor("errorTopic"), new RuntimeException("error")));
when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(new Connector());
Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), processorRequest);
waitForProcessorAndConnectorToFail(processor);
verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
verify(connectorsApiClient, never()).createConnector(any(ConnectorRequest.class));
}
use of com.openshift.cloud.api.connector.models.Connector 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();
}
Aggregations