Search in sources :

Example 46 with Message

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);
                    }
                }));
            }
        }
    }
}
Also used : Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) LoggerFactory(org.slf4j.LoggerFactory) Collections.disjoint(java.util.Collections.disjoint) HashMap(java.util.HashMap) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) CompositeFuture(io.vertx.core.CompositeFuture) EventBuilder(io.fabric8.kubernetes.api.model.EventBuilder) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) Map(java.util.Map) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Handler(io.vertx.core.Handler) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) Collections.disjoint(java.util.Collections.disjoint)

Example 47 with Message

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());
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 48 with Message

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);
}
Also used : DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) DockerClient(io.fabric8.docker.client.DockerClient) Config(io.fabric8.docker.client.Config) AuthConfig(io.fabric8.docker.api.model.AuthConfig) DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) AuthConfigBuilder(io.fabric8.docker.api.model.AuthConfigBuilder) ConfigBuilder(io.fabric8.docker.client.ConfigBuilder) OutputHandle(io.fabric8.docker.dsl.OutputHandle) EventListener(io.fabric8.docker.dsl.EventListener)

Example 49 with Message

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();
}
Also used : DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec)

Aggregations

IOException (java.io.IOException)12 HashMap (java.util.HashMap)9 File (java.io.File)8 Profile (io.fabric8.api.Profile)7 Map (java.util.Map)7 Message (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message)6 ArrayList (java.util.ArrayList)5 PatchException (io.fabric8.patch.management.PatchException)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 Container (io.fabric8.api.Container)3 Version (io.fabric8.api.Version)3 Date (java.util.Date)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Git (org.eclipse.jgit.api.Git)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Test (org.junit.Test)3