use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class MachineProviderImplTest method shouldAddEnvVarsFromMachineConfigToContainerOnDevInstanceCreationFromSnapshot.
@Test
public void shouldAddEnvVarsFromMachineConfigToContainerOnDevInstanceCreationFromSnapshot() throws Exception {
// given
Map<String, String> envVarsFromConfig = new HashMap<>();
envVarsFromConfig.put("ENV_VAR1", "123");
envVarsFromConfig.put("ENV_VAR2", "234");
final boolean isDev = true;
CheServiceImpl machine = createService();
machine.setEnvironment(envVarsFromConfig);
// when
createInstanceFromSnapshot(machine, isDev);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).containsAll(envVarsFromConfig.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList())));
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class CommandManager method execute.
/**
* Execute the the given command command within the workspace Docker container.
*/
public void execute(String commandLine) {
final Machine machine = appContext.getDevMachine().getDescriptor();
if (machine == null) {
return;
}
String machineID = machine.getId();
final CommandDto command = dtoFactory.createDto(CommandDto.class).withName("some-command").withCommandLine(commandLine).withType("arbitrary-type");
executeCommand(command, machineID);
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class CommandProducerActionManager method createActionsForProducer.
/** Creates actions for the given {@link CommandProducer}. */
private void createActionsForProducer(CommandProducer producer) {
Action action;
if (producer.getMachineTypes().isEmpty()) {
action = commandProducerActionFactory.create(producer.getName(), producer, appContext.getDevMachine().getDescriptor());
actionManager.registerAction(producer.getName(), action);
} else {
action = new DefaultActionGroup(producer.getName(), true, actionManager);
producersToActionGroups.put(producer, (DefaultActionGroup) action);
actionManager.registerAction(producer.getName(), action);
for (Machine machine : machines) {
createActionsForMachine(machine);
}
}
commandActionsPopUpGroup.add(action);
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class ProcessesPanelPresenter method onPreviewSsh.
@Override
public void onPreviewSsh(String machineId) {
ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId);
if (machineTreeNode == null) {
return;
}
Machine machine = (Machine) machineTreeNode.getData();
final OutputConsole defaultConsole = commandConsoleFactory.create("SSH");
addCommandOutput(machineId, defaultConsole);
final String machineName = machine.getConfig().getName();
String sshServiceAddress = getSshServerAddress(machine);
final String machineHost;
final String sshPort;
if (sshServiceAddress != null) {
String[] parts = sshServiceAddress.split(":");
machineHost = parts[0];
sshPort = (parts.length == 2) ? parts[1] : SSH_PORT;
} else {
sshPort = SSH_PORT;
machineHost = "";
}
// user
final String userName;
String user = machine.getRuntime().getProperties().get("config.user");
if (isNullOrEmpty(user)) {
userName = "root";
} else {
userName = user;
}
// ssh key
final String workspaceName = appContext.getWorkspace().getConfig().getName();
Promise<SshPairDto> sshPairDtoPromise = sshServiceClient.getPair("workspace", machine.getWorkspaceId());
sshPairDtoPromise.then(new Operation<SshPairDto>() {
@Override
public void apply(SshPairDto sshPairDto) throws OperationException {
if (defaultConsole instanceof DefaultOutputConsole) {
((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoPrivateKey(sshPairDto.getPrivateKey())));
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (defaultConsole instanceof DefaultOutputConsole) {
((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoNoPrivateKey()));
}
}
});
}
use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.
the class SelectCommandComboBox method onMachineDestroyed.
@Override
public void onMachineDestroyed(MachineStateEvent event) {
Machine machine = event.getMachine();
final String machineId = machine.getId();
if (registeredMachineMap.remove(machineId) == null) {
return;
}
if (machine.getConfig().getName().equals(machinesListWidget.getSelectedName())) {
machinesListWidget.selectElement(null, null);
}
updateMachineActions();
}
Aggregations