Search in sources :

Example 21 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project strimzi by strimzi.

the class ConfigMapWatcher method eventReceived.

public void eventReceived(Action action, ConfigMap configMap) {
    ObjectMeta metadata = configMap.getMetadata();
    Map<String, String> labels = metadata.getLabels();
    if (cmPredicate.test(configMap)) {
        String name = metadata.getName();
        LOGGER.info("ConfigMap watch received event {} on map {} with labels {}", action, name, labels);
        Handler<AsyncResult<Void>> resultHandler = ar -> {
            if (ar.succeeded()) {
                LOGGER.info("Success processing ConfigMap watch event {} on map {} with labels {}", action, name, labels);
            } else {
                String message;
                if (ar.cause() instanceof InvalidConfigMapException) {
                    message = "ConfigMap " + name + " has an invalid 'data' section: " + ar.cause().getMessage();
                    LOGGER.error("{}", message);
                } else {
                    message = "Failure processing ConfigMap watch event " + action + " on map " + name + " with labels " + labels + ": " + ar.cause().getMessage();
                    LOGGER.error("{}", message, ar.cause());
                }
                controller.enqueue(controller.new Event(configMap, message, Controller.EventType.WARNING, errorResult -> {
                }));
            }
        };
        switch(action) {
            case ADDED:
                controller.onConfigMapAdded(configMap, resultHandler);
                break;
            case MODIFIED:
                controller.onConfigMapModified(configMap, resultHandler);
                break;
            case DELETED:
                controller.onConfigMapDeleted(configMap, resultHandler);
                break;
            case ERROR:
                LOGGER.error("Watch received action=ERROR for ConfigMap " + name);
        }
    }
}
Also used : KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Logger(org.slf4j.Logger) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Map(java.util.Map) LoggerFactory(org.slf4j.LoggerFactory) Watcher(io.fabric8.kubernetes.client.Watcher) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) AsyncResult(io.vertx.core.AsyncResult)

Example 22 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by fabric8io.

the class KubernetesAssert method deployments.

/**
 * Finds all the resources that create pod selections (Deployment, DeploymentConfig, ReplicaSet, ReplicationController)
 * and create a {@link HasPodSelectionAssert} to make assertions on their pods that they startup etc.
 *
 * @return the assertion object for the deployment
 */
public HasPodSelectionAssert deployments() {
    List<HasPodSelectionAssert> asserters = new ArrayList<>();
    List<HasMetadata> resources = new ArrayList<>();
    try {
        resources = KubernetesHelper.findKubernetesResourcesOnClasspath(new Controller(client));
    } catch (IOException e) {
        fail("Failed to load kubernetes resources on the classpath: " + e, e);
    }
    for (HasMetadata resource : resources) {
        HasPodSelectionAssert asserter = createPodSelectionAssert(resource);
        if (asserter != null) {
            asserters.add(asserter);
        }
    }
    String message = "No pod selection kinds found on the classpath such as Deployment, DeploymentConfig, ReplicaSet, ReplicationController";
    // TODO we don't yet support size > 1
    assertThat(asserters).describedAs(message).isNotEmpty();
    if (asserters.size() == 1) {
        return asserters.get(0);
    }
    return new MultiHasPodSelectionAssert(asserters);
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Controller(io.fabric8.kubernetes.api.Controller) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Example 23 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(Template entity) {
    StringBuilder buffer = new StringBuilder();
    List<Parameter> parameters = entity.getParameters();
    if (parameters != null) {
        for (Parameter parameter : parameters) {
            String name = parameter.getName();
            appendText(buffer, name);
        }
    }
    return "parameters: " + buffer;
}
Also used : Parameter(io.fabric8.openshift.api.model.Parameter)

Example 24 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by fabric8io.

the class BuildConfigHelper method importNewGitProject.

public static CreateGitProjectResults importNewGitProject(KubernetesClient kubernetesClient, UserDetails userDetails, File basedir, String namespace, String projectName, String origin, String message, boolean apply, boolean useLocalGitAddress) throws GitAPIException, JsonProcessingException {
    GitUtils.disableSslCertificateChecks();
    InitCommand initCommand = Git.init();
    initCommand.setDirectory(basedir);
    Git git = initCommand.call();
    LOG.info("Initialised an empty git configuration repo at {}", basedir.getAbsolutePath());
    PersonIdent personIdent = userDetails.createPersonIdent();
    String user = userDetails.getUser();
    String address = userDetails.getAddress();
    String internalAddress = userDetails.getInternalAddress();
    String branch = userDetails.getBranch();
    // lets create the repository
    GitRepoClient repoClient = userDetails.createRepoClient();
    CreateRepositoryDTO createRepository = new CreateRepositoryDTO();
    createRepository.setName(projectName);
    String fullName = null;
    RepositoryDTO repository = repoClient.createRepository(createRepository);
    if (repository != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Got repository: " + toJson(repository));
        }
        fullName = repository.getFullName();
    }
    if (Strings.isNullOrBlank(fullName)) {
        fullName = user + "/" + projectName;
    }
    String htmlUrl = URLUtils.pathJoin(resolveToRoot(address), user, projectName);
    String localCloneUrl = URLUtils.pathJoin(resolveToRoot(internalAddress), user, projectName + ".git");
    String cloneUrl = htmlUrl + ".git";
    String defaultCloneUrl = cloneUrl;
    // lets default to using the local git clone URL
    if (useLocalGitAddress && Strings.isNotBlank(internalAddress)) {
        defaultCloneUrl = localCloneUrl;
    }
    // now lets import the code and publish
    GitUtils.configureBranch(git, branch, origin, defaultCloneUrl);
    GitUtils.addDummyFileToEmptyFolders(basedir);
    LOG.info("About to git commit and push to: " + defaultCloneUrl + " and remote name " + origin);
    GitUtils.doAddCommitAndPushFiles(git, userDetails, personIdent, branch, origin, message, true);
    Map<String, String> annotations = new HashMap<>();
    annotations.put(Annotations.Builds.GIT_CLONE_URL, cloneUrl);
    annotations.put(Annotations.Builds.LOCAL_GIT_CLONE_URL, localCloneUrl);
    BuildConfig buildConfig;
    if (apply) {
        buildConfig = createAndApplyBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
    } else {
        buildConfig = createBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
    }
    return new CreateGitProjectResults(buildConfig, fullName, htmlUrl, localCloneUrl, cloneUrl);
}
Also used : Git(org.eclipse.jgit.api.Git) CreateRepositoryDTO(io.fabric8.repo.git.CreateRepositoryDTO) PersonIdent(org.eclipse.jgit.lib.PersonIdent) HashMap(java.util.HashMap) InitCommand(org.eclipse.jgit.api.InitCommand) GitRepoClient(io.fabric8.repo.git.GitRepoClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) RepositoryDTO(io.fabric8.repo.git.RepositoryDTO) CreateRepositoryDTO(io.fabric8.repo.git.CreateRepositoryDTO)

Example 25 with Message

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message in project fabric8 by jboss-fuse.

the class ProfileCopyAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // but validate the target name
    try {
        FabricValidations.validateProfileName(target);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    Version version = versionParam != null ? profileService.getRequiredVersion(versionParam) : fabricService.getRequiredDefaultVersion();
    String versionId = version.getId();
    if (!version.hasProfile(source)) {
        System.out.println("Source profile " + source + " not found.");
        return 1;
    } else if (version.hasProfile(target)) {
        if (!force) {
            System.out.println("Target profile " + target + " already exists. Use --force if you want to overwrite.");
            return null;
        }
    }
    Profiles.copyProfile(fabricService, versionId, source, target, force);
    return null;
}
Also used : Version(io.fabric8.api.Version)

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