use of io.strimzi.controller.cluster.model.KafkaConnectS2ICluster in project strimzi by strimzi.
the class KafkaConnectS2IAssemblyOperator method createOrUpdate.
@Override
public void createOrUpdate(Reconciliation reconciliation, ConfigMap assemblyCm, Handler<AsyncResult<Void>> handler) {
String namespace = reconciliation.namespace();
if (isOpenShift) {
KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(assemblyCm);
Future<Void> chainFuture = Future.future();
deploymentConfigOperations.scaleDown(namespace, connect.getName(), connect.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, connect.getName(), connect.generateService())).compose(i -> deploymentConfigOperations.reconcile(namespace, connect.getName(), connect.generateDeploymentConfig())).compose(i -> imagesStreamOperations.reconcile(namespace, connect.getSourceImageStreamName(), connect.generateSourceImageStream())).compose(i -> imagesStreamOperations.reconcile(namespace, connect.getName(), connect.generateTargetImageStream())).compose(i -> buildConfigOperations.reconcile(namespace, connect.getName(), connect.generateBuildConfig())).compose(i -> deploymentConfigOperations.scaleUp(namespace, connect.getName(), connect.getReplicas()).map((Void) null)).compose(chainFuture::complete, chainFuture);
chainFuture.setHandler(handler);
} else {
handler.handle(Future.failedFuture("S2I only available on OpenShift"));
}
}
use of io.strimzi.controller.cluster.model.KafkaConnectS2ICluster in project strimzi by strimzi.
the class KafkaConnectS2IAssemblyOperatorTest method testDeleteCluster.
@Test
public void testDeleteCluster(TestContext context) {
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentConfigOperator mockDcOps = mock(DeploymentConfigOperator.class);
BuildConfigOperator mockBcOps = mock(BuildConfigOperator.class);
ImageStreamOperator mockIsOps = mock(ImageStreamOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(ResourceUtils.createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName));
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeploymentConfig());
when(mockIsOps.get(clusterCmNamespace, connect.getSourceImageStreamName())).thenReturn(connect.generateSourceImageStream());
ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> isNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> isNameCaptor = ArgumentCaptor.forClass(String.class);
when(mockIsOps.reconcile(isNamespaceCaptor.capture(), isNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> bcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> bcNameCaptor = ArgumentCaptor.forClass(String.class);
when(mockBcOps.reconcile(bcNamespaceCaptor.capture(), bcNameCaptor.capture(), isNull())).thenReturn(Future.succeededFuture());
KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
Async async = context.async();
ops.delete(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), createResult -> {
context.assertTrue(createResult.succeeded());
// Verify service
context.assertEquals(1, serviceNameCaptor.getAllValues().size());
context.assertEquals(clusterCmNamespace, serviceNamespaceCaptor.getValue());
context.assertEquals(connect.getName(), serviceNameCaptor.getValue());
// Vertify deployment Config
context.assertEquals(1, dcNameCaptor.getAllValues().size());
context.assertEquals(clusterCmNamespace, dcNamespaceCaptor.getValue());
context.assertEquals(connect.getName(), dcNameCaptor.getValue());
// Vertify BuildConfig
context.assertEquals(1, bcNameCaptor.getAllValues().size());
context.assertEquals(clusterCmNamespace, bcNamespaceCaptor.getValue());
context.assertEquals(connect.getName(), bcNameCaptor.getValue());
// Vertify ImageStreams
int sisIndex = (connect.getSourceImageStreamName()).equals(isNameCaptor.getAllValues().get(0)) ? 0 : 1;
int tisIndex = (connect.getName()).equals(isNameCaptor.getAllValues().get(0)) ? 0 : 1;
context.assertEquals(2, isNameCaptor.getAllValues().size());
context.assertEquals(clusterCmNamespace, isNamespaceCaptor.getAllValues().get(sisIndex));
context.assertEquals(connect.getSourceImageStreamName(), isNameCaptor.getAllValues().get(sisIndex));
context.assertEquals(clusterCmNamespace, isNamespaceCaptor.getAllValues().get(tisIndex));
context.assertEquals(connect.getName(), isNameCaptor.getAllValues().get(tisIndex));
async.complete();
});
}
use of io.strimzi.controller.cluster.model.KafkaConnectS2ICluster in project strimzi by strimzi.
the class KafkaConnectS2IAssemblyOperatorTest method testUpdateClusterScaleUp.
@Test
public void testUpdateClusterScaleUp(TestContext context) {
int scaleTo = 4;
String newReplicas = String.valueOf(scaleTo);
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentConfigOperator mockDcOps = mock(DeploymentConfigOperator.class);
BuildConfigOperator mockBcOps = mock(BuildConfigOperator.class);
ImageStreamOperator mockIsOps = mock(ImageStreamOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
// Change replicas to create ScaleUp
clusterCm.getData().put(KafkaConnectCluster.KEY_REPLICAS, newReplicas);
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeploymentConfig());
when(mockIsOps.get(clusterCmNamespace, connect.getSourceImageStreamName())).thenReturn(connect.generateSourceImageStream());
when(mockIsOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateTargetImageStream());
when(mockBcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateBuildConfig());
when(mockServiceOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
when(mockDcOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleDown(clusterCmNamespace, connect.getName(), scaleTo);
when(mockIsOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
when(mockBcOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertTrue(createResult.succeeded());
verify(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), scaleTo);
async.complete();
});
}
Aggregations