use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project strimzi by strimzi.
the class Controller method update3Way.
private void update3Way(HasMetadata involvedObject, Topic k8sTopic, Topic kafkaTopic, Topic privateTopic, Handler<AsyncResult<Void>> reconciliationResultHandler) {
if (!privateTopic.getMapName().equals(k8sTopic.getMapName())) {
reconciliationResultHandler.handle(Future.failedFuture(new ControllerException(involvedObject, "Topic '" + kafkaTopic.getTopicName() + "' is already managed via ConfigMap '" + privateTopic.getMapName() + "' it cannot also be managed via the ConfiMap '" + k8sTopic.getMapName() + "'")));
return;
}
TopicDiff oursKafka = TopicDiff.diff(privateTopic, kafkaTopic);
LOGGER.debug("topicStore->kafkaTopic: {}", oursKafka);
TopicDiff oursK8s = TopicDiff.diff(privateTopic, k8sTopic);
LOGGER.debug("topicStore->k8sTopic: {}", oursK8s);
String conflict = oursKafka.conflict(oursK8s);
if (conflict != null) {
final String message = "ConfigMap and Topic both changed in a conflicting way: " + conflict;
LOGGER.error(message);
enqueue(new Event(involvedObject, message, EventType.INFO, eventResult -> {
}));
reconciliationResultHandler.handle(Future.failedFuture(new Exception(message)));
} else {
TopicDiff merged = oursKafka.merge(oursK8s);
LOGGER.debug("Diffs do not conflict, merged diff: {}", merged);
if (merged.isEmpty()) {
LOGGER.info("All three topics are identical");
reconciliationResultHandler.handle(Future.succeededFuture());
} else {
Topic result = merged.apply(privateTopic);
int partitionsDelta = merged.numPartitionsDelta();
if (partitionsDelta < 0) {
final String message = "Number of partitions cannot be decreased";
LOGGER.error(message);
enqueue(new Event(involvedObject, message, EventType.INFO, eventResult -> {
}));
reconciliationResultHandler.handle(Future.failedFuture(new Exception(message)));
} else {
if (merged.changesReplicationFactor()) {
LOGGER.error("Changes replication factor");
enqueue(new ChangeReplicationFactor(result, involvedObject, null));
}
// TODO What if we increase min.in.sync.replicas and the number of replicas,
// such that the old number of replicas < the new min isr? But likewise
// we could decrease, so order of tasks in the queue will need to change
// depending on what the diffs are.
LOGGER.debug("Updating cm, kafka topic and topicStore");
// TODO replace this with compose
enqueue(new UpdateConfigMap(result, ar -> {
Handler<Void> topicStoreHandler = ignored -> enqueue(new UpdateInTopicStore(result, involvedObject, reconciliationResultHandler));
Handler<Void> partitionsHandler;
if (partitionsDelta > 0) {
partitionsHandler = ar4 -> enqueue(new IncreaseKafkaPartitions(result, involvedObject, ar2 -> topicStoreHandler.handle(null)));
} else {
partitionsHandler = topicStoreHandler;
}
if (merged.changesConfig()) {
enqueue(new UpdateKafkaConfig(result, involvedObject, ar2 -> partitionsHandler.handle(null)));
} else {
enqueue(partitionsHandler);
}
}));
}
}
}
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method applyResourceObjects.
private void applyResourceObjects(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder) throws Exception {
// Adding a workaround to handle intermittent Socket closed errors while
// building on OpenShift. See https://github.com/fabric8io/fabric8-maven-plugin/issues/1133
// for more details.
int nTries = 0;
boolean bResourcesCreated = false;
Exception buildException = null;
do {
try {
if (config.getEnricherTask() != null) {
config.getEnricherTask().execute(builder);
}
if (builder.hasItems()) {
KubernetesList k8sList = builder.build();
client.lists().create(k8sList);
}
// If we are here, it means resources got created successfully.
bResourcesCreated = true;
} catch (Exception aException) {
// Retry only when Exception is of socket closed message.
if (aException.getMessage() != null && aException.getMessage().contains("Socket closed")) {
log.warn("Problem encountered while applying resource objects, retrying..");
buildException = aException;
nTries++;
Thread.sleep(RESOURCE_CREATION_RETRY_TIMEOUT_IN_MILLIS);
// Make a connection to cluster again.
client = clusterAccess.createDefaultClient(log);
} else {
// and simply throw as it is.
throw new MojoExecutionException(aException.getMessage());
}
}
} while (nTries < RESOURCE_CREATION_RETRIES && !bResourcesCreated);
if (!bResourcesCreated)
throw new MojoExecutionException(buildException.getMessage());
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project kubernetes by ballerinax.
the class DockerHandler method buildImage.
/**
* Create docker image.
*
* @param dockerModel dockerModel object
* @param dockerDir dockerfile directory
* @throws InterruptedException When error with docker build process
* @throws IOException When error with docker build process
*/
public void buildImage(DockerModel dockerModel, String dockerDir) throws InterruptedException, IOException, KubernetesPluginException {
Config dockerClientConfig = new ConfigBuilder().withDockerUrl(dockerModel.getDockerHost()).build();
DockerClient client = new io.fabric8.docker.client.DefaultDockerClient(dockerClientConfig);
final DockerError dockerError = new DockerError();
OutputHandle buildHandle = client.image().build().withRepositoryName(dockerModel.getName()).withNoCache().alwaysRemovingIntermediate().usingListener(new EventListener() {
@Override
public void onSuccess(String message) {
buildDone.countDown();
}
@Override
public void onError(String message) {
dockerError.setErrorMsg("error building docker image: " + message);
buildDone.countDown();
}
@Override
public void onError(Throwable t) {
dockerError.setErrorMsg("error building docker image: " + t.getMessage());
buildDone.countDown();
}
@Override
public void onEvent(String event) {
printDebug(event);
}
}).fromFolder(dockerDir);
buildDone.await();
buildHandle.close();
client.close();
handleError(dockerError);
}
use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by fabric8io.
the class KubernetesHelper method summaryText.
/**
* Returns a short summary text message for the given kubernetes resource
*/
public static String summaryText(DeploymentConfig entity) {
StringBuilder buffer = new StringBuilder();
DeploymentConfigSpec spec = entity.getSpec();
if (spec != null) {
buffer.append("replicas: " + spec.getReplicas());
PodTemplateSpec podTemplateSpec = spec.getTemplate();
if (podTemplateSpec != null) {
appendSummaryText(buffer, podTemplateSpec);
}
}
return buffer.toString();
}
Aggregations