Search in sources :

Example 1 with Message

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

the class BuildJsonResponseHandler method process.

@Override
public void process(JSONObject json) throws DockerAccessException {
    if (json.has("error")) {
        String msg = json.getString("error");
        String detailMsg = "";
        if (json.has("errorDetail")) {
            JSONObject details = json.getJSONObject("errorDetail");
            detailMsg = details.getString("message");
        }
        throw new DockerAccessException("%s %s", json.get("error"), (msg.equals(detailMsg) || "".equals(detailMsg) ? "" : "(" + detailMsg + ")"));
    } else if (json.has("stream")) {
        String message = json.getString("stream");
        log.verbose("%s", message.trim());
    } else if (json.has("status")) {
        String status = json.getString("status").trim();
        String id = json.has("id") ? json.getString("id") : null;
        if (status.matches("^.*(Download|Pulling).*")) {
            log.info("  %s%s", id != null ? id + " " : "", status);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException)

Example 2 with Message

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

the class AutoScaleStatusListAction method printStatus.

protected void printStatus(PrintStream out, AutoScaleStatus status) {
    TablePrinter table = new TablePrinter();
    table.columns("auto scale profile", "status", "message");
    List<AutoScaleProfileStatus> profileStatuses = status.getProfileStatuses();
    for (AutoScaleProfileStatus profile : profileStatuses) {
        table.row(getStringOrBlank(profile.getProfile()), getStringOrBlank(profile.getStatus()), getStringOrBlank(profile.getMessage()));
    }
    table.print();
}
Also used : TablePrinter(io.fabric8.utils.TablePrinter) AutoScaleProfileStatus(io.fabric8.api.AutoScaleProfileStatus)

Example 3 with Message

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

the class ContainerEditJvmOptionsAction method doExecute.

protected Object doExecute() throws Exception {
    validateContainerName(container);
    if (!FabricCommand.doesContainerExist(fabricService, container)) {
        System.out.println("Container " + container + " does not exists!");
        return null;
    }
    Container containerInstance = FabricCommand.getContainerIfExists(fabricService, container);
    String type = containerInstance.getType();
    if (!"karaf".equals(type)) {
        System.out.println("Sorry, currently only \"karaf\" type container are supported");
        return null;
    }
    // read current jvm values
    FabricManager fabricManager = new FabricManager(fabricService);
    if (full) {
        String jmxUrl = null;
        JMXConnector connector = null;
        MBeanServerConnection remote = null;
        HashMap<String, String[]> authenticationData = null;
        jmxUrl = containerInstance.getJmxUrl();
        authenticationData = prepareAuthenticationData();
        try {
            connector = connectOrRetry(authenticationData, jmxUrl);
        } catch (Exception e) {
            username = null;
            password = null;
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to connect to JMX Server", e);
            return null;
        }
        ObjectName objName = new ObjectName(JAVA_LANG_OBJECT_NAME);
        try {
            remote = connector.getMBeanServerConnection();
            String[] arguments = (String[]) remote.getAttribute(objName, "InputArguments");
            String output = Arrays.toString(arguments);
            output = output.replaceAll(",", "");
            output = output.substring(1, output.length() - 1);
            System.out.println(output);
        } catch (Exception e) {
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to fetch child jvm opts", e);
        }
        try {
            connector.close();
        } catch (IOException e) {
            log.error("Errors closing remote MBean connection", e);
        }
    } else {
        try {
            String output = fabricManager.getJvmOpts(container);
            if ("Inapplicable".equals(output)) {
                String message = container + " jvmOpts cannot be handled within Fabric. You have to set required values directly in startup scripts.";
                System.out.println(message);
                log.error(message);
                return null;
            }
            if (jvmOptions == null) {
                System.out.println(output);
            } else {
                fabricManager.setJvmOpts(container, jvmOptions);
                System.out.println("Operation succeeded. New JVM flags will be loaded at the next start of " + container + " container");
                log.info("Updated JVM flags for container {}", container);
            }
        } catch (Exception e) {
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to set ssh jvm opts", e);
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) FabricManager(io.fabric8.core.jmx.FabricManager) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) FabricAuthenticationException(io.fabric8.api.FabricAuthenticationException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Example 4 with Message

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

the class DeploymentUpdater method updateDeployment.

public void updateDeployment(Git git, File baseDir, CredentialsProvider credentials) throws Exception {
    Set<String> bundles = new LinkedHashSet<String>();
    Set<Feature> features = new LinkedHashSet<Feature>();
    Profile overlayProfile = container.getOverlayProfile();
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
    bundles.addAll(effectiveProfile.getBundles());
    AgentUtils.addFeatures(features, fabricService, downloadManager, effectiveProfile);
    if (copyFilesIntoGit) {
        copyDeploymentsIntoGit(git, baseDir, bundles, features);
    } else {
        addDeploymentsIntoPom(git, baseDir, effectiveProfile, bundles, features);
    }
    // now lets do a commit
    String message = "updating deployment";
    git.commit().setMessage(message).call();
    enableDeployDirectory(git, baseDir);
    String branch = GitHelpers.currentBranch(git);
    LOG.info("Pushing deployment changes to branch " + branch + " credentials " + credentials + " for container " + container.getId());
    try {
        Iterable<PushResult> results = git.push().setCredentialsProvider(credentials).setRefSpecs(new RefSpec(branch)).setOutputStream(new LoggingOutputStream(LOG)).call();
        /*
            for (PushResult result : results) {
                LOG.info(result.getMessages());
            }
*/
        LOG.info("Pushed deployment changes to branch " + branch + " for container " + container.getId());
    } catch (GitAPIException e) {
        LOG.error("Failed to push deployment changes to branch " + branch + " for container " + container.getId() + ". Reason: " + e, e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RefSpec(org.eclipse.jgit.transport.RefSpec) LoggingOutputStream(io.fabric8.common.util.LoggingOutputStream) PushResult(org.eclipse.jgit.transport.PushResult) Feature(io.fabric8.agent.model.Feature) Profile(io.fabric8.api.Profile)

Example 5 with Message

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

the class ProfileEditAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(profileName);
        if (!(delete || remove)) {
            FabricValidations.validatePidProperties(pidProperties);
        }
    } 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;
    }
    if (delete) {
        set = false;
    }
    Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
    Profile profile = version.getProfile(profileName);
    if (profile != null) {
        editProfile(profile);
    } else {
        System.out.println("Profile " + profileName + " does not exists!");
        return 1;
    }
    return null;
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

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