Search in sources :

Example 1 with MachineConfig

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());
}
Also used : MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) Instance(org.eclipse.che.api.machine.server.spi.Instance) NoOpMachineInstance(org.eclipse.che.api.environment.server.NoOpMachineInstance) Test(org.testng.annotations.Test)

Example 2 with MachineConfig

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());
    }
}
Also used : MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) DefaultActionGroup(org.eclipse.che.ide.api.action.DefaultActionGroup) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) Machine(org.eclipse.che.api.core.model.machine.Machine)

Example 3 with MachineConfig

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));
        }
    }
}
Also used : MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig)

Example 4 with MachineConfig

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;
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) SpanElement(elemental.html.SpanElement) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) DivElement(elemental.html.DivElement) TreeNodeElement(org.eclipse.che.ide.ui.tree.TreeNodeElement) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) Event(elemental.events.Event) EventListener(elemental.events.EventListener) SVGImage(org.vectomatic.dom.svg.ui.SVGImage)

Example 5 with MachineConfig

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);
}
Also used : ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) Instance(org.eclipse.che.api.machine.server.spi.Instance) ConflictException(org.eclipse.che.api.core.ConflictException) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) SourceNotFoundException(org.eclipse.che.api.machine.server.exception.SourceNotFoundException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) InstanceProvider(org.eclipse.che.api.machine.server.spi.InstanceProvider)

Aggregations

MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)6 Machine (org.eclipse.che.api.core.model.machine.Machine)2 Instance (org.eclipse.che.api.machine.server.spi.Instance)2 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)2 Element (elemental.dom.Element)1 Node (elemental.dom.Node)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 DivElement (elemental.html.DivElement)1 SpanElement (elemental.html.SpanElement)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 NoOpMachineInstance (org.eclipse.che.api.environment.server.NoOpMachineInstance)1