use of com.redhat.service.bridge.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorDAOTest method findProcessorsToBeDeployedOrDeleteWithConnectors.
@Test
@Transactional
public void findProcessorsToBeDeployedOrDeleteWithConnectors() {
Bridge b = createBridge();
// To be provisioned
Processor withProvisionedConnectors = createProcessor(b, "withProvisionedConnectors");
withProvisionedConnectors.setStatus(ManagedResourceStatus.ACCEPTED);
withProvisionedConnectors.setDependencyStatus(ManagedResourceStatus.READY);
processorDAO.getEntityManager().merge(withProvisionedConnectors);
ConnectorEntity provisionedConnector = Fixtures.createConnector(withProvisionedConnectors, "connectorProvisioned", ManagedResourceStatus.READY, "");
processorDAO.getEntityManager().merge(provisionedConnector);
// Not to be provisioned as Connector is not ready
Processor nonProvisioned = createProcessor(b, "withUnprovisionedConnector");
nonProvisioned.setStatus(ManagedResourceStatus.ACCEPTED);
nonProvisioned.setDependencyStatus(ManagedResourceStatus.PROVISIONING);
processorDAO.getEntityManager().merge(nonProvisioned);
ConnectorEntity nonProvisionedConnector = Fixtures.createConnector(nonProvisioned, "nonProvisionedConnector", ManagedResourceStatus.READY, "");
processorDAO.getEntityManager().merge(nonProvisionedConnector);
// Not to be de-provisioned as there's a connector yet to be deleted
Processor toBeDeleted = createProcessor(b, "notToBeDeletedYet");
toBeDeleted.setStatus(ManagedResourceStatus.DEPROVISION);
toBeDeleted.setDependencyStatus(ManagedResourceStatus.READY);
processorDAO.getEntityManager().merge(nonProvisioned);
ConnectorEntity toBeDeletedConnector = Fixtures.createConnector(toBeDeleted, "toBeDeletedConnector", ManagedResourceStatus.ACCEPTED, "");
processorDAO.getEntityManager().merge(toBeDeletedConnector);
List<Processor> processors = processorDAO.findByShardIdWithReadyDependencies(TestConstants.SHARD_ID);
assertThat(processors.stream().map(Processor::getName)).contains("withProvisionedConnectors");
}
use of com.redhat.service.bridge.manager.models.ConnectorEntity 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.redhat.service.bridge.manager.models.ConnectorEntity in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithConnector.
@ParameterizedTest
@MethodSource("srcHandleWorkDeletingWithKnownResourceWithConnector")
void handleWorkDeletingWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus connectorStatusWhenComplete, boolean isWorkComplete) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
Processor processor = spy(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));
verify(processor, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
use of com.redhat.service.bridge.manager.models.ConnectorEntity 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.redhat.service.bridge.manager.models.ConnectorEntity 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);
}
Aggregations