use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class CheEnvironmentEngine method replaceMachine.
private void replaceMachine(Instance machine) throws ServerException {
try (@SuppressWarnings("unused") Unlocker u = stripedLocks.writeLock(machine.getWorkspaceId())) {
ensurePreDestroyIsNotExecuted();
EnvironmentHolder environmentHolder = environments.get(machine.getWorkspaceId());
if (environmentHolder != null) {
for (int i = 0; i < environmentHolder.machines.size(); i++) {
if (environmentHolder.machines.get(i).getId().equals(machine.getId())) {
environmentHolder.machines.set(i, machine);
return;
}
}
}
}
// if this area is reachable then environment/machine is not found and machine should be stopped
try {
machine.destroy();
} catch (MachineException e) {
LOG.error(e.getLocalizedMessage(), e);
}
// should not happen
throw new ServerException(format("Machine with ID '%s' and name '%s' has been stopped because its configuration is not found in the environment of workspace '%s'", machine.getId(), machine.getConfig().getName(), machine.getWorkspaceId()));
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class CheEnvironmentEngine method getMachineLogger.
private LineConsumer getMachineLogger(MessageConsumer<MachineLogMessage> environmentLogger, String machineId, String machineName) throws ServerException {
createMachineLogsDir(machineId);
LineConsumer lineConsumer = new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
environmentLogger.consume(new MachineLogMessageImpl(machineName, line));
}
};
try {
return new ConcurrentCompositeLineConsumer(new ConcurrentFileLineConsumer(getMachineLogsFile(machineId)), lineConsumer);
} catch (IOException e) {
throw new MachineException(format("Unable create log file '%s' for machine '%s'.", e.getLocalizedMessage(), machineId));
}
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class AbstractAgentLauncher method launch.
@Override
public void launch(Instance machine, Agent agent) throws ServerException {
if (isNullOrEmpty(agent.getScript())) {
return;
}
ListLineConsumer agentLogger = new ListLineConsumer();
LineConsumer lineConsumer = new AbstractLineConsumer() {
@Override
public void writeLine(String line) throws IOException {
machine.getLogger().writeLine(line);
agentLogger.writeLine(line);
}
};
try {
final InstanceProcess process = start(machine, agent, lineConsumer);
LOG.debug("Waiting for agent {} is launched. Workspace ID:{}", agent.getId(), machine.getWorkspaceId());
final long pingStartTimestamp = System.currentTimeMillis();
while (System.currentTimeMillis() - pingStartTimestamp < agentMaxStartTimeMs) {
if (agentLaunchingChecker.isLaunched(agent, process, machine)) {
return;
} else {
Thread.sleep(agentPingDelayMs);
}
}
process.kill();
} catch (MachineException e) {
logAsErrorAgentStartLogs(agent.getName(), agentLogger.getText());
throw new ServerException(e.getServiceError());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ServerException(format("Launching agent %s is interrupted", agent.getName()));
} finally {
try {
lineConsumer.close();
} catch (IOException ignored) {
}
agentLogger.close();
}
logAsErrorAgentStartLogs(agent.getName(), agentLogger.getText());
throw new ServerException(format("Fail launching agent %s. Workspace ID:%s", agent.getName(), machine.getWorkspaceId()));
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class AbstractAgentLauncherTest method shouldThrowServerExceptionIfMachineExceptionIsThrownByAgentCheck.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "agent launcher test exception")
public void shouldThrowServerExceptionIfMachineExceptionIsThrownByAgentCheck() throws Exception {
// given
when(agentChecker.isLaunched(any(Agent.class), any(InstanceProcess.class), any(Instance.class))).thenThrow(new MachineException("agent launcher test exception"));
// when
launcher.launch(machine, agent);
}
use of org.eclipse.che.api.machine.server.exception.MachineException in project che by eclipse.
the class SshMachineInstanceProvider method createInstance.
/**
* Creates instance from scratch or by reusing a previously one by using specified {@link MachineSource}
* data in {@link MachineConfig}.
*
* @param machine
* machine description
* @param lineConsumer
* output for instance creation logs
* @return newly created {@link SshMachineInstance}
* @throws UnsupportedRecipeException
* if specified {@code recipe} is not supported
* @throws InvalidRecipeException
* if {@code recipe} is invalid
* @throws NotFoundException
* if instance described by {@link MachineSource} doesn't exists
* @throws MachineException
* if other error occurs
*/
public SshMachineInstance createInstance(Machine machine, LineConsumer lineConsumer) throws NotFoundException, MachineException {
requireNonNull(machine, "Non null machine required");
requireNonNull(lineConsumer, "Non null logs consumer required");
requireNonNull(machine.getConfig().getSource().getLocation(), "Location in machine source is required");
if (machine.getConfig().isDev()) {
throw new MachineException("Dev machine is not supported for Ssh machine implementation");
}
Recipe recipe = recipeDownloader.getRecipe(machine.getConfig());
SshMachineRecipe sshMachineRecipe = GSON.fromJson(recipe.getScript(), SshMachineRecipe.class);
SshClient sshClient = sshMachineFactory.createSshClient(sshMachineRecipe, machine.getConfig().getEnvVariables());
sshClient.start();
SshMachineInstance instance = sshMachineFactory.createInstance(machine, sshClient, lineConsumer);
instance.setStatus(MachineStatus.RUNNING);
return instance;
}
Aggregations