Search in sources :

Example 1 with Offline

use of io.fabric8.patch.impl.Offline in project fabric8 by jboss-fuse.

the class ApplyPatchMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info("Applyings patches to " + outputDirectory);
    Offline offline = new Offline(outputDirectory, new Offline.Logger() {

        @Override
        public void log(int level, String message) {
            switch(level) {
                case Offline.DEBUG:
                    getLog().debug(message);
                    break;
                case Offline.INFO:
                    getLog().info(message);
                    break;
                case Offline.WARN:
                    getLog().warn(message);
                    break;
                case Offline.ERROR:
                    getLog().error(message);
                    break;
            }
        }
    });
    try {
        for (File patch : patches) {
            getLog().info("Applying patch: " + patch);
            offline.apply(patch);
        }
    } catch (Exception e) {
        throw new MojoFailureException("Error processing patches", e);
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) Offline(io.fabric8.patch.impl.Offline) File(java.io.File) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 2 with Offline

use of io.fabric8.patch.impl.Offline in project fabric8 by jboss-fuse.

the class ArchetypeTest method assertArchetypeCreated.

private void assertArchetypeCreated(String artifactId, String groupId, String version) throws Exception {
    Hashtable<String, String> props = new Hashtable<>();
    props.put("offline", "true");
    MavenResolver resolver = MavenResolvers.createMavenResolver(props, null);
    File archetypejar = resolver.resolveFile(new DefaultArtifact(groupId, artifactId, null, null, version));
    assertTrue("archetype jar does not exist", archetypejar.exists());
    assertArchetypeCreated(artifactId, groupId, version, archetypejar);
}
Also used : Hashtable(java.util.Hashtable) MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 3 with Offline

use of io.fabric8.patch.impl.Offline in project fabric8 by jboss-fuse.

the class Main method main.

public static void main(String[] args) throws Exception {
    File patch;
    File base;
    if (args.length < 1) {
        help();
        return;
    }
    patch = new File(args[0]);
    if (!patch.isFile()) {
        System.err.println("Invalid patch file");
        return;
    }
    if (args.length > 1) {
        base = new File(args[1]);
    } else {
        base = new File(System.getProperty("karaf.base"));
    }
    if (!new File(base, "system").isDirectory() || !new File(base, "etc").isDirectory()) {
        System.err.println("Invalid karaf-base parameter");
        return;
    }
    new Offline(base).apply(patch);
}
Also used : Offline(io.fabric8.patch.impl.Offline) File(java.io.File)

Example 4 with Offline

use of io.fabric8.patch.impl.Offline in project fabric8-maven-plugin by fabric8io.

the class AbstractLiveEnricher method getExternalServiceURL.

/**
 * Returns the external access to the given service name
 *
 * @param serviceName name of the service
 * @param protocol URL protocol such as <code>http</code>
 */
protected String getExternalServiceURL(String serviceName, String protocol) {
    if (!isOnline()) {
        getLog().info("Not looking for service " + serviceName + " as we are in offline mode");
        return null;
    } else {
        try {
            KubernetesClient kubernetes = getKubernetes();
            String ns = kubernetes.getNamespace();
            if (Strings.isNullOrBlank(ns)) {
                ns = getNamespace();
            }
            Service service = kubernetes.services().inNamespace(ns).withName(serviceName).get();
            return service != null ? KubernetesHelper.getServiceURL(kubernetes, serviceName, ns, protocol, true) : null;
        } catch (Throwable e) {
            Throwable cause = e;
            boolean notFound = false;
            boolean connectError = false;
            Stack<Throwable> stack = unfoldExceptions(e);
            while (!stack.isEmpty()) {
                Throwable t = stack.pop();
                if (t instanceof ConnectException || "No route to host".equals(t.getMessage())) {
                    getLog().warn("Cannot connect to Kubernetes to find URL for service %s : %s", serviceName, cause.getMessage());
                    return null;
                } else if (t instanceof IllegalArgumentException || t.getMessage() != null && t.getMessage().matches("^No.*found.*$")) {
                    getLog().warn("%s", cause.getMessage());
                    return null;
                }
                ;
            }
            getLog().warn("Cannot find URL for service %s : %s", serviceName, cause.getMessage());
            return null;
        }
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Service(io.fabric8.kubernetes.api.model.Service) Stack(java.util.Stack) ConnectException(java.net.ConnectException)

Aggregations

File (java.io.File)3 Offline (io.fabric8.patch.impl.Offline)2 Service (io.fabric8.kubernetes.api.model.Service)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 MavenResolver (io.fabric8.maven.MavenResolver)1 ConnectException (java.net.ConnectException)1 Hashtable (java.util.Hashtable)1 Stack (java.util.Stack)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)1