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;
}
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();
}
}
}
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) {
}
}
}
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);
}
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();
}
}
Aggregations