Skip to content

Commit

Permalink
ARTIK-217: kill a process from ssh session (eclipse-che#3293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Svydenko authored Dec 8, 2016
1 parent fba2bb0 commit 1461b99
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

import com.google.common.annotations.Beta;
import com.google.gwt.core.client.JsArrayMixed;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.ImplementedBy;

import org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper;
import org.eclipse.che.api.promises.client.js.Executor;
import org.eclipse.che.api.promises.client.js.JsPromiseProvider;

Expand All @@ -40,6 +42,17 @@ public interface PromiseProvider {
*/
<V> Promise<V> create(Executor<V> executor);

/**
* Creates a new promise using the {@link AsyncCallback}.
*
* @param call
* the request caller
* @param <V>
* the type of the promised value
* @return a promise
*/
<V> Promise<V> create(AsyncPromiseHelper.RequestCall<V> call);

/**
* Creates a promise that resolves as soon as all the promises used as parameters are resolved or
* rejected as soon as the first rejection happens on one of the included promises.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.api.promises.client.PromiseProvider;
import org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper;

/**
* Default implementation of {@link PromiseProvider}.
Expand All @@ -35,6 +36,12 @@ public native <V> Promise<V> create(Executor<V> executor) /*-{
return new Promise(executor);
}-*/;

/** {@inheritDoc} */
@Override
public <V> Promise<V> create(AsyncPromiseHelper.RequestCall<V> call) {
return AsyncPromiseHelper.createFromAsyncRequest(call);
}

/** {@inheritDoc} */
@Override
public native Promise<JsArrayMixed> all(ArrayOf<Promise<?>> promises) /*-{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public JschSshProcess createProcess(String commandLine) throws MachineException
try {
ChannelExec exec = (ChannelExec)session.openChannel("exec");
exec.setCommand(commandLine);
exec.setPty(true);
envVars.entrySet()
.stream()
.forEach(envVariableEntry -> exec.setEnv(envVariableEntry.getKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public int getExitCode() {

@Override
public void kill() throws MachineException {
exec.disconnect();
try {
exec.sendSignal("KILL");
} catch (Exception e) {
throw new MachineException("Ssh machine signal sending error:" + e.getLocalizedMessage());
} finally {
exec.disconnect();
}
}
}

0 comments on commit 1461b99

Please sign in to comment.