use of org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole in project che by eclipse.
the class CommandManagerImpl method executeCommand.
@Override
public void executeCommand(final CommandImpl command, final Machine machine) {
final String name = command.getName();
final String type = command.getType();
final String commandLine = command.getCommandLine();
final Map<String, String> attributes = command.getAttributes();
macroProcessor.expandMacros(commandLine).then(new Operation<String>() {
@Override
public void apply(String expandedCommandLine) throws OperationException {
CommandImpl expandedCommand = new CommandImpl(name, expandedCommandLine, type, attributes);
final CommandOutputConsole console = commandConsoleFactory.create(expandedCommand, machine);
final String machineId = machine.getId();
processesPanelPresenter.addCommandOutput(machineId, console);
execAgentCommandManager.startProcess(machineId, expandedCommand).thenIfProcessStartedEvent(console.getProcessStartedOperation()).thenIfProcessDiedEvent(console.getProcessDiedOperation()).thenIfProcessStdOutEvent(console.getStdOutOperation()).thenIfProcessStdErrEvent(console.getStdErrOperation());
}
});
}
use of org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole in project che by eclipse.
the class TestServiceClient method runTestsAfterCompilation.
Promise<TestResult> runTestsAfterCompilation(String projectPath, String testFramework, Map<String, String> parameters, StatusNotification statusNotification, Promise<CommandImpl> compileCommand) {
return compileCommand.thenPromise(command -> {
final Machine machine;
if (command == null) {
machine = null;
} else {
machine = appContext.getDevMachine().getDescriptor();
}
if (machine == null) {
if (statusNotification != null) {
statusNotification.setContent("Executing the tests without preliminary compilation.");
}
return sendTests(projectPath, testFramework, parameters);
}
if (statusNotification != null) {
statusNotification.setContent("Compiling the project before starting the test session.");
}
return promiseFromExecutorBody(new ExecutorBody<TestResult>() {
boolean compiled = false;
@Override
public void apply(final ResolveFunction<TestResult> resolve, RejectFunction reject) {
macroProcessor.expandMacros(command.getCommandLine()).then(new Operation<String>() {
@Override
public void apply(String expandedCommandLine) throws OperationException {
CommandImpl expandedCommand = new CommandImpl(command.getName(), expandedCommandLine, command.getType(), command.getAttributes());
final CommandOutputConsole console = commandConsoleFactory.create(expandedCommand, machine);
final String machineId = machine.getId();
processesPanelPresenter.addCommandOutput(machineId, console);
execAgentCommandManager.startProcess(machineId, expandedCommand).then(startResonse -> {
if (!startResonse.getAlive()) {
reject.apply(promiseFromThrowable(new Throwable(PROJECT_BUILD_NOT_STARTED_MESSAGE)));
}
}).thenIfProcessStartedEvent(console.getProcessStartedOperation()).thenIfProcessStdErrEvent(evt -> {
if (evt.getText().contains("BUILD SUCCESS")) {
compiled = true;
}
console.getStdErrOperation().apply(evt);
}).thenIfProcessStdOutEvent(evt -> {
if (evt.getText().contains("BUILD SUCCESS")) {
compiled = true;
}
console.getStdOutOperation().apply(evt);
}).thenIfProcessDiedEvent(evt -> {
console.getProcessDiedOperation().apply(evt);
if (compiled) {
if (statusNotification != null) {
statusNotification.setContent(EXECUTING_TESTS_MESSAGE);
}
sendTests(projectPath, testFramework, parameters).then(new Operation<TestResult>() {
@Override
public void apply(TestResult result) throws OperationException {
resolve.apply(result);
}
});
} else {
reject.apply(promiseFromThrowable(new Throwable(PROJECT_BUILD_FAILED_MESSAGE)));
}
});
}
});
}
});
});
}
use of org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole in project che by eclipse.
the class ProcessesPanelPresenterTest method commandShouldBeRestoredWhenWsAgentIsStarted.
@Test
public void commandShouldBeRestoredWhenWsAgentIsStarted() throws Exception {
WsAgentStateEvent event = mock(WsAgentStateEvent.class);
MachineEntity machineEntity = mock(MachineEntity.class);
MachineDto machine = mock(MachineDto.class);
when(machineEntity.getId()).thenReturn(MACHINE_ID);
when(machineEntity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(entityFactory.createMachine(machine)).thenReturn(machineEntity);
MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
when(machine.getConfig()).thenReturn(machineConfigDto);
when(machineConfigDto.isDev()).thenReturn(true);
when(machine.getStatus()).thenReturn(MachineStatus.RUNNING);
List<MachineDto> machines = new ArrayList<>(2);
machines.add(machine);
when(workspaceRuntime.getMachines()).thenReturn(machines);
MachineProcessDto machineProcessDto = mock(MachineProcessDto.class);
when(machineProcessDto.getOutputChannel()).thenReturn(OUTPUT_CHANNEL);
when(machineProcessDto.getPid()).thenReturn(PID);
List<MachineProcessDto> processes = new ArrayList<>(1);
processes.add(machineProcessDto);
CommandOutputConsole outputConsole = mock(CommandOutputConsole.class);
CommandType commandType = mock(CommandType.class);
when(commandTypeRegistry.getCommandTypeById(anyString())).thenReturn(commandType);
when(commandConsoleFactory.create(anyObject(), any(org.eclipse.che.api.core.model.machine.Machine.class))).thenReturn(outputConsole);
presenter.onWsAgentStarted(event);
}
use of org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole in project che by eclipse.
the class TestServiceClientTest method initMocks.
@Before
public void initMocks() {
MockitoAnnotations.initMocks(this);
testServiceClient = spy(new TestServiceClient(appContext, asyncRequestFactory, dtoUnmarshallerFactory, dtoFactory, commandManager, execAgentCommandManager, promiseProvider, macroProcessor, commandConsoleFactory, processesPanelPresenter));
doReturn(new PromiseMocker<TestResult>().getPromise()).when(testServiceClient).sendTests(anyString(), anyString(), anyMapOf(String.class, String.class));
doAnswer(new FunctionAnswer<Executor.ExecutorBody<TestResult>, Promise<TestResult>>(executorBody -> {
ExecutorPromiseMocker<TestResult> mocker = new ExecutorPromiseMocker<TestResult>(executorBody, (testResult, thisMocker) -> {
thisMocker.applyOnThenOperation(testResult);
return null;
}, (promiseError, thisMocker) -> {
thisMocker.applyOnCatchErrorOperation(promiseError);
return null;
});
executorBody.apply(mocker.getResolveFunction(), mocker.getRejectFunction());
return mocker.getPromise();
})).when(testServiceClient).promiseFromExecutorBody(Matchers.<Executor.ExecutorBody<TestResult>>any());
doAnswer(new FunctionAnswer<Throwable, PromiseError>(throwable -> {
PromiseError promiseError = mock(PromiseError.class);
when(promiseError.getCause()).thenReturn(throwable);
return promiseError;
})).when(testServiceClient).promiseFromThrowable(any(Throwable.class));
when(appContext.getDevMachine()).thenReturn(devMachine);
when(machine.getId()).thenReturn("DevMachineId");
doAnswer(new FunctionAnswer<String, Promise<String>>(commandLine -> {
String processedCommandLine = commandLine.replace("${current.project.path}", rootOfProjects + "/" + projectPath);
return new PromiseMocker<String>().applyOnThenOperation(processedCommandLine).getPromise();
})).when(macroProcessor).expandMacros(anyString());
when(commandConsoleFactory.create(any(CommandImpl.class), any(Machine.class))).then(createCall -> {
CommandOutputConsole commandOutputConsole = mock(CommandOutputConsole.class);
when(commandOutputConsole.getProcessStartedOperation()).thenReturn(processStartedEvent -> {
consoleEvents.add(processStartedEvent);
});
when(commandOutputConsole.getProcessDiedOperation()).thenReturn(processDiedEvent -> {
consoleEvents.add(processDiedEvent);
});
when(commandOutputConsole.getStdErrOperation()).thenReturn(processStdErrEvent -> {
consoleEvents.add(processStdErrEvent);
});
when(commandOutputConsole.getStdOutOperation()).thenReturn(processStdOutEvent -> {
consoleEvents.add(processStdOutEvent);
});
return commandOutputConsole;
});
consoleEvents.clear();
when(execAgentCommandManager.startProcess(anyString(), any(Command.class))).then(startProcessCall -> {
@SuppressWarnings("unchecked") ExecAgentPromise<ProcessStartResponseDto> execAgentPromise = (ExecAgentPromise<ProcessStartResponseDto>) mock(ExecAgentPromise.class);
class ProcessEventForward<DtoType> extends FunctionAnswer<Operation<DtoType>, ExecAgentPromise<ProcessStartResponseDto>> {
public ProcessEventForward(Class<DtoType> dtoClass) {
super(new java.util.function.Function<Operation<DtoType>, ExecAgentPromise<ProcessStartResponseDto>>() {
@Override
public ExecAgentPromise<ProcessStartResponseDto> apply(Operation<DtoType> op) {
operationsOnProcessEvents.put(dtoClass, op);
return execAgentPromise;
}
});
}
}
when(execAgentPromise.then(any())).then(new ProcessEventForward<>(ProcessStartResponseDto.class));
when(execAgentPromise.thenIfProcessStartedEvent(any())).then(new ProcessEventForward<>(ProcessStartedEventDto.class));
when(execAgentPromise.thenIfProcessDiedEvent(any())).then(new ProcessEventForward<>(ProcessDiedEventDto.class));
when(execAgentPromise.thenIfProcessStdErrEvent(any())).then(new ProcessEventForward<>(ProcessStdErrEventDto.class));
when(execAgentPromise.thenIfProcessStdOutEvent(any())).then(new ProcessEventForward<>(ProcessStdOutEventDto.class));
return execAgentPromise;
});
operationsOnProcessEvents.clear();
}
use of org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole in project che by eclipse.
the class ProcessesPanelPresenter method restoreState.
private void restoreState(final MachineEntity machine) {
execAgentCommandManager.getProcesses(machine.getId(), false).then(new Operation<List<GetProcessesResponseDto>>() {
@Override
public void apply(List<GetProcessesResponseDto> processes) throws OperationException {
for (GetProcessesResponseDto process : processes) {
final int pid = process.getPid();
final String type = process.getType();
/*
* Do not show the process if the command line has prefix #hidden
*/
if (!isNullOrEmpty(process.getCommandLine()) && process.getCommandLine().startsWith("#hidden")) {
continue;
}
/*
* Hide the processes which are launched by command of unknown type
*/
if (isProcessLaunchedByCommandOfKnownType(type)) {
final String processName = process.getName();
final CommandImpl commandByName = getWorkspaceCommandByName(processName);
if (commandByName == null) {
final String commandLine = process.getCommandLine();
final CommandImpl command = new CommandImpl(processName, commandLine, type);
final CommandOutputConsole console = commandConsoleFactory.create(command, machine);
getAndPrintProcessLogs(console, pid);
subscribeToProcess(console, pid);
addCommandOutput(machine.getId(), console);
} else {
macroProcessor.expandMacros(commandByName.getCommandLine()).then(new Operation<String>() {
@Override
public void apply(String expandedCommandLine) throws OperationException {
final CommandImpl command = new CommandImpl(commandByName.getName(), expandedCommandLine, commandByName.getType(), commandByName.getAttributes());
final CommandOutputConsole console = commandConsoleFactory.create(command, machine);
getAndPrintProcessLogs(console, pid);
subscribeToProcess(console, pid);
addCommandOutput(machine.getId(), console);
}
});
}
}
}
}
private void getAndPrintProcessLogs(final CommandOutputConsole console, final int pid) {
String from = null;
String till = null;
int limit = 50;
int skip = 0;
execAgentCommandManager.getProcessLogs(machine.getId(), pid, from, till, limit, skip).then(new Operation<List<GetProcessLogsResponseDto>>() {
@Override
public void apply(List<GetProcessLogsResponseDto> logs) throws OperationException {
for (GetProcessLogsResponseDto log : logs) {
String text = log.getText();
console.printOutput(text);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
String error = "Error trying to get process log with pid: " + pid + ". " + arg.getMessage();
Log.error(getClass(), error);
}
});
}
private void subscribeToProcess(CommandOutputConsole console, int pid) {
String stderr = "stderr";
String stdout = "stdout";
String processStatus = "process_status";
String after = null;
execAgentCommandManager.subscribe(machine.getId(), pid, asList(stderr, stdout, processStatus), after).thenIfProcessStartedEvent(console.getProcessStartedOperation()).thenIfProcessDiedEvent(console.getProcessDiedOperation()).thenIfProcessStdOutEvent(console.getStdOutOperation()).thenIfProcessStdErrEvent(console.getStdErrOperation()).then(console.getProcessSubscribeOperation());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(localizationConstant.failedToGetProcesses(machine.getId()));
}
});
}
Aggregations