use of org.eclipse.che.api.core.model.machine.MachineConfig in project che by eclipse.
the class WorkspaceRuntimesTest method shouldBeAbleToStartMachine.
@Test
public void shouldBeAbleToStartMachine() throws Exception {
// when
setRuntime("workspace", WorkspaceStatus.RUNNING, "env-name");
MachineConfig config = newMachine("workspace", "env-name", "new", false).getConfig();
Instance instance = mock(Instance.class);
when(envEngine.startMachine(anyString(), any(MachineConfig.class), any())).thenReturn(instance);
when(instance.getConfig()).thenReturn(config);
// when
Instance actual = runtimes.startMachine("workspace", config);
// then
assertEquals(actual, instance);
verify(envEngine).startMachine(eq("workspace"), eq(config), any());
}
use of org.eclipse.che.api.core.model.machine.MachineConfig in project che by eclipse.
the class SelectCommandComboBox method updateMachineActions.
private void updateMachineActions() {
machinesActions.removeAll();
final DefaultActionGroup actionList = (DefaultActionGroup) actionManager.getAction(GROUP_MACHINES_LIST);
if (actionList != null) {
machinesActions.addAll(actionList);
}
if (registeredMachineMap.isEmpty()) {
return;
}
final List<Map.Entry<String, Machine>> machineEntryList = new LinkedList(registeredMachineMap.entrySet());
// defined MachineDto Comparator here
Collections.sort(machineEntryList, new MachineListEntryComparator());
String machineCategory = null;
for (Map.Entry<String, Machine> machineEntry : machineEntryList) {
final Machine machine = machineEntry.getValue();
final MachineConfig machineConfig = machine.getConfig();
if (!this.getMachineCategory(machineConfig).equals(machineCategory)) {
machineCategory = this.getMachineCategory(machineConfig);
machinesActions.addSeparator(machineCategory);
}
machinesActions.add(machinesListWidget.createAction(machine.getId(), machineConfig.getName()));
}
machinesListWidget.updatePopup();
if (machinesListWidget.getSelectedName() == null && machinesActions.getChildrenCount() > 0) {
Machine firstMachine = machineEntryList.get(0).getValue();
if (firstMachine == null) {
return;
}
machinesListWidget.selectElement(firstMachine.getId(), firstMachine.getConfig().getName());
}
}
use of org.eclipse.che.api.core.model.machine.MachineConfig in project che by eclipse.
the class MachinePanelPresenter method onMachineSelected.
/** {@inheritDoc} */
@Override
public void onMachineSelected(final MachineEntity selectedMachine) {
this.selectedMachine = selectedMachine;
if (cachedMachines.containsKey(selectedMachine.getId())) {
appliance.showAppliance(cachedMachines.get(selectedMachine.getId()));
return;
}
if (RUNNING == selectedMachine.getStatus()) {
isMachineRunning = true;
cachedMachines.put(selectedMachine.getId(), selectedMachine);
appliance.showAppliance(selectedMachine);
} else {
isMachineRunning = false;
final MachineConfig machineConfig = selectedMachine.getConfig();
final boolean isDevMachine = machineConfig.isDev();
final String machineName = machineConfig.getName();
// we show the loader for dev machine so this message isn't necessary for dev machine
if (!isDevMachine) {
appliance.showStub(locale.unavailableMachineStarting(machineName));
}
}
}
use of org.eclipse.che.api.core.model.machine.MachineConfig in project che by eclipse.
the class ProcessTreeRenderer method createMachineElement.
private SpanElement createMachineElement(final ProcessTreeNode node) {
final MachineEntity machine = (MachineEntity) node.getData();
final String machineId = machine.getId();
final MachineConfig machineConfig = machine.getConfig();
final String machineCategory = machineConfig.isDev() ? locale.devMachineCategory() : machineConfig.getType();
SpanElement root = Elements.createSpanElement();
root.appendChild(createMachineLabel(machineCategory));
Element statusElement = Elements.createSpanElement(resources.getCss().machineStatus());
root.appendChild(statusElement);
if (node.isRunning()) {
statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusRunning()));
} else {
statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusPausedLeft()));
statusElement.appendChild(Elements.createDivElement(resources.getCss().machineStatusPausedRight()));
}
Tooltip.create(statusElement, BOTTOM, MIDDLE, locale.viewMachineRunningTooltip());
/***************************************************************************
*
* New terminal button
*
***************************************************************************/
if (node.isRunning() && node.hasTerminalAgent()) {
SpanElement newTerminalButton = Elements.createSpanElement(resources.getCss().newTerminalButton());
newTerminalButton.appendChild((Node) new SVGImage(resources.addTerminalIcon()).getElement());
root.appendChild(newTerminalButton);
Tooltip.create(newTerminalButton, BOTTOM, MIDDLE, locale.viewNewTerminalTooltip());
newTerminalButton.addEventListener(Event.CLICK, new EventListener() {
@Override
public void handleEvent(Event event) {
event.stopPropagation();
event.preventDefault();
if (addTerminalClickHandler != null) {
addTerminalClickHandler.onAddTerminalClick(machineId);
}
}
}, true);
/**
* This listener cancels mouse events on '+' button and prevents the jitter of the selection in the tree.
*/
EventListener blockMouseListener = new EventListener() {
@Override
public void handleEvent(Event event) {
event.stopPropagation();
event.preventDefault();
}
};
/**
* Prevent jitter when pressing mouse on '+' button.
*/
newTerminalButton.addEventListener(Event.MOUSEDOWN, blockMouseListener, true);
newTerminalButton.addEventListener(Event.MOUSEUP, blockMouseListener, true);
newTerminalButton.addEventListener(Event.CLICK, blockMouseListener, true);
newTerminalButton.addEventListener(Event.DBLCLICK, blockMouseListener, true);
}
/***************************************************************************
*
* SSH button
*
***************************************************************************/
if (node.isRunning() && node.hasSSHAgent()) {
SpanElement sshButton = Elements.createSpanElement(resources.getCss().sshButton());
sshButton.setTextContent("SSH");
root.appendChild(sshButton);
sshButton.addEventListener(Event.CLICK, new EventListener() {
@Override
public void handleEvent(Event event) {
if (previewSshClickHandler != null) {
previewSshClickHandler.onPreviewSshClick(machineId);
}
}
}, true);
Tooltip.create(sshButton, BOTTOM, MIDDLE, locale.connectViaSSH());
}
Element monitorsElement = Elements.createSpanElement(resources.getCss().machineMonitors());
root.appendChild(monitorsElement);
Node monitorNode = (Node) machineMonitors.getMonitorWidget(machineId, this).getElement();
monitorsElement.appendChild(monitorNode);
Element nameElement = Elements.createSpanElement(resources.getCss().nameLabel());
nameElement.setTextContent(machineConfig.getName());
Tooltip.create(nameElement, BOTTOM, MIDDLE, machineConfig.getName());
root.appendChild(nameElement);
return root;
}
use of org.eclipse.che.api.core.model.machine.MachineConfig in project che by eclipse.
the class CheEnvironmentEngine method startMachine.
/**
* Starts machine in running environment.
*
* @param workspaceId
* ID of workspace that owns environment in which machine should be started
* @param machineConfig
* configuration of machine that should be started
* @return running machine
* @throws EnvironmentNotRunningException
* if environment is not running
* @throws NotFoundException
* if provider of machine implementation is not found
* @throws ConflictException
* if machine with the same name already exists in the environment
* @throws ServerException
* if any other error occurs
*/
public Instance startMachine(String workspaceId, MachineConfig machineConfig, List<String> agents) throws ServerException, NotFoundException, ConflictException, EnvironmentException {
MachineConfig machineConfigCopy = new MachineConfigImpl(machineConfig);
EnvironmentHolder environmentHolder;
try (@SuppressWarnings("unused") Unlocker u = stripedLocks.readLock(workspaceId)) {
environmentHolder = environments.get(workspaceId);
if (environmentHolder == null || environmentHolder.status != EnvStatus.RUNNING) {
throw new EnvironmentNotRunningException(format("Environment '%s' is not running", workspaceId));
}
for (Instance machine : environmentHolder.machines) {
if (machine.getConfig().getName().equals(machineConfigCopy.getName())) {
throw new ConflictException(format("Machine with name '%s' already exists in environment of workspace '%s'", machineConfigCopy.getName(), workspaceId));
}
}
}
final String creator = EnvironmentContext.getCurrent().getSubject().getUserId();
final String namespace = EnvironmentContext.getCurrent().getSubject().getUserName();
MachineImpl machine = MachineImpl.builder().setConfig(machineConfig).setWorkspaceId(workspaceId).setStatus(MachineStatus.CREATING).setEnvName(environmentHolder.name).setOwner(creator).build();
MachineStarter machineStarter;
if ("docker".equals(machineConfig.getType())) {
// needed to reuse startInstance method and
// create machine instances by different implementation-specific providers
CheServiceImpl service = machineConfigToService(machineConfig);
normalize(namespace, workspaceId, machineConfig.getName(), service);
machine.setId(service.getId());
machineStarter = (machineLogger, machineSource) -> {
CheServiceImpl serviceWithNormalizedSource = normalizeServiceSource(service, machineSource);
normalize(namespace, workspaceId, machineConfig.getName(), serviceWithNormalizedSource);
infrastructureProvisioner.provision(new ExtendedMachineImpl().withAgents(agents), serviceWithNormalizedSource);
return machineProvider.startService(namespace, workspaceId, environmentHolder.name, machineConfig.getName(), machineConfig.isDev(), environmentHolder.networkId, serviceWithNormalizedSource, machineLogger);
};
} else {
try {
InstanceProvider provider = machineInstanceProviders.getProvider(machineConfig.getType());
machine.setId(generateMachineId());
addAgentsProvidedServers(machine, agents);
machineStarter = (machineLogger, machineSource) -> {
Machine machineWithNormalizedSource = normalizeMachineSource(machine, machineSource);
return provider.createInstance(machineWithNormalizedSource, machineLogger);
};
} catch (NotFoundException e) {
throw new NotFoundException(format("Provider of machine type '%s' not found", machineConfig.getType()));
}
}
return startInstance(false, environmentHolder.logger, machine, machineStarter);
}
Aggregations