Search in sources :

Example 26 with Command

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

the class ContainerConnectAction method doExecute.

protected Object doExecute() throws Exception {
    validateContainerName(container);
    String cmdStr = "";
    if (command != null) {
        StringBuilder sb = new StringBuilder();
        for (String cmd : command) {
            if (sb.length() > 0) {
                sb.append(' ');
            }
            sb.append(cmd);
        }
        sb.append("\n");
        cmdStr = sb.toString();
    }
    Container found = FabricCommand.getContainer(fabricService, container);
    String sshUrl = found.getSshUrl();
    if (sshUrl == null) {
        throw new IllegalArgumentException("Container " + container + " has no SSH URL.");
    }
    String[] ssh = sshUrl.split(":");
    if (ssh.length < 2) {
        throw new IllegalArgumentException("Container " + container + " has an invalid SSH URL '" + sshUrl + "'");
    }
    username = username != null && !username.isEmpty() ? username : ShellUtils.retrieveFabricUser(session);
    password = password != null ? password : ShellUtils.retrieveFabricUserPassword(session);
    try {
        executSshCommand(session, username, password, ssh[0], ssh[1], cmdStr);
    } catch (FabricAuthenticationException ex) {
        username = null;
        password = null;
        promptForSshCredentialsIfNeeded();
        executSshCommand(session, username, password, ssh[0], ssh[1], cmdStr);
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) FabricAuthenticationException(io.fabric8.api.FabricAuthenticationException)

Example 27 with Command

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

the class SshContainerProvider method runScriptOnHost.

protected void runScriptOnHost(Session session, String script) throws Exception {
    ChannelExec executor = null;
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ByteArrayOutputStream error = new ByteArrayOutputStream();
    try {
        executor = (ChannelExec) session.openChannel("exec");
        executor.setPty(true);
        executor.setCommand(script);
        executor.setOutputStream(output);
        executor.setErrStream(error);
        executor.connect();
        int errorStatus = -1;
        for (int i = 0; !executor.isClosed(); i++) {
            if (i > 0) {
                long delayMs = (long) (200L * Math.pow(i, 2));
                Thread.sleep(delayMs);
            }
            if ((errorStatus = executor.getExitStatus()) != -1) {
                break;
            }
        }
        LOGGER.debug("Output: {}", output.toString());
        LOGGER.debug("Error:  {}", error.toString());
        if (verbose) {
            System.out.println("Output : " + output.toString());
            System.out.println("Error : " + error.toString());
        }
        if (errorStatus != 0) {
            throw new Exception(String.format("%s@%s:%d: received exit status %d executing \n--- command ---\n%s\n--- output ---\n%s\n--- error ---\n%s\n------\n", session.getUserName(), session.getHost(), session.getPort(), executor.getExitStatus(), script, output.toString(), error.toString()));
        }
    } finally {
        if (executor != null) {
            executor.disconnect();
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ChannelExec(com.jcraft.jsch.ChannelExec) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException)

Example 28 with Command

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

the class JMXCommandActionSupport method cleanResponses.

/**
 * Even if we could make response queues persistent, I think not doing it is better idea. Each command
 * cleans after itself (and previous, failed/timed out commands)
 */
protected void cleanResponses() {
    for (Container container : fabricService.getContainers()) {
        try {
            String path = ZkPath.COMMANDS_RESPONSES.getPath(container.getId());
            List<String> responses = curator.getChildren().forPath(path);
            for (String r : responses) {
                curator.delete().forPath(path + "/" + r);
            }
        } catch (Exception ignored) {
        }
    }
}
Also used : Container(io.fabric8.api.Container) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 29 with Command

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

the class OpenwireProtocol method snoopConnectionParameters.

@Override
public void snoopConnectionParameters(final SocketWrapper socket, Buffer received, final Handler<ConnectionParameters> handler) {
    OpenwireProtocolDecoder h = new OpenwireProtocolDecoder(this);
    h.errorHandler(new Handler<String>() {

        @Override
        public void handle(String error) {
            LOG.info("Openwire protocol decoding error: " + error);
            socket.close();
        }
    });
    h.codecHandler(new Handler<Command>() {

        @Override
        public void handle(Command event) {
            if (event instanceof WireFormatInfo) {
                WireFormatInfo info = (WireFormatInfo) event;
                ConnectionParameters parameters = new ConnectionParameters();
                try {
                    parameters.protocolVirtualHost = info.getHost();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                handler.handle(parameters);
            } else {
                LOG.info("Expected a WireFormatInfo frame");
                socket.close();
            }
        }
    });
    socket.readStream().dataHandler(h);
    h.handle(received);
}
Also used : Command(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Command) WireFormatInfo(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.WireFormatInfo) ConnectionParameters(io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters) IOException(java.io.IOException)

Example 30 with Command

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

the class DeploymentAgentTest method testResolveOptionalImports.

@Test
@SuppressWarnings("unchecked")
public void testResolveOptionalImports() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
    CommandSupport.executeCommand("fabric:profile-create --parent default test-profile");
    CommandSupport.executeCommand("fabric:profile-edit --pid io.fabric8.agent/resolve.optional.imports=true test-profile");
    CommandSupport.executeCommand("fabric:profile-edit --feature spring-struts test-profile");
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = ContainerBuilder.create().withName("smoke_cnt_b").withProfiles("test-profile").assertProvisioningResult().build(fabricService);
        try {
            String command = "fabric:container-connect -u admin -p admin " + containers.iterator().next().getId() + " osgi:list -t 0 -s | grep org.apache.servicemix.bundles.struts";
            String result = CommandSupport.executeCommand(command);
            assertTrue("Result contains struts, but was: " + result, result.contains("org.apache.servicemix.bundles.struts"));
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)9 File (java.io.File)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Container (io.fabric8.api.Container)5 JMXRequest (io.fabric8.api.commands.JMXRequest)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 FabricService (io.fabric8.api.FabricService)3 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)3 Arguments (io.fabric8.maven.docker.config.Arguments)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Properties (java.util.Properties)3 TemplatedResource (com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)2 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)2 GenerateService (com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService)2 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)2 Container (io.fabric8.kubernetes.api.model.Container)2