Search in sources :

Example 6 with Machine

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())));
}
Also used : RemoveContainerParams(org.eclipse.che.plugin.docker.client.params.RemoveContainerParams) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) InspectContainerParams(org.eclipse.che.plugin.docker.client.params.InspectContainerParams) DockerConnectorProvider(org.eclipse.che.plugin.docker.client.DockerConnectorProvider) Volume(org.eclipse.che.plugin.docker.client.json.Volume) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) DOCKER_FILE_TYPE(org.eclipse.che.plugin.docker.machine.DockerInstanceProvider.DOCKER_FILE_TYPE) Mockito.doThrow(org.mockito.Mockito.doThrow) Collections.singleton(java.util.Collections.singleton) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) Assert.assertFalse(org.testng.Assert.assertFalse) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) BeforeMethod(org.testng.annotations.BeforeMethod) RecipeRetriever(org.eclipse.che.api.machine.server.util.RecipeRetriever) Set(java.util.Set) Collectors(java.util.stream.Collectors) WindowsPathEscaper(org.eclipse.che.commons.lang.os.WindowsPathEscaper) MACHINE_SNAPSHOT_PREFIX(org.eclipse.che.plugin.docker.machine.DockerInstanceProvider.MACHINE_SNAPSHOT_PREFIX) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Stream(java.util.stream.Stream) ContainerConfig(org.eclipse.che.plugin.docker.client.json.ContainerConfig) TagParams(org.eclipse.che.plugin.docker.client.params.TagParams) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) UserSpecificDockerRegistryCredentialsProvider(org.eclipse.che.plugin.docker.client.UserSpecificDockerRegistryCredentialsProvider) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) PullParams(org.eclipse.che.plugin.docker.client.params.PullParams) DockerConnectorConfiguration(org.eclipse.che.plugin.docker.client.DockerConnectorConfiguration) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) ContainerCreated(org.eclipse.che.plugin.docker.client.json.ContainerCreated) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) StartContainerParams(org.eclipse.che.plugin.docker.client.params.StartContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) RemoveImageParams(org.eclipse.che.plugin.docker.client.params.RemoveImageParams) HashSet(java.util.HashSet) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ProgressMonitor(org.eclipse.che.plugin.docker.client.ProgressMonitor) ArgumentCaptor(org.mockito.ArgumentCaptor) ContainerState(org.eclipse.che.plugin.docker.client.json.ContainerState) Collections.singletonMap(java.util.Collections.singletonMap) ContainerInfo(org.eclipse.che.plugin.docker.client.json.ContainerInfo) Collections.emptySet(java.util.Collections.emptySet) DockerNode(org.eclipse.che.plugin.docker.machine.node.DockerNode) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Machine(org.eclipse.che.api.core.model.machine.Machine) Mockito.never(org.mockito.Mockito.never) ServerException(org.eclipse.che.api.core.ServerException) DockerConnector(org.eclipse.che.plugin.docker.client.DockerConnector) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) Assert.assertEqualsNoOrder(org.testng.Assert.assertEqualsNoOrder) HashMap(java.util.HashMap) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 7 with Machine

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

Example 8 with Machine

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);
}
Also used : Action(org.eclipse.che.ide.api.action.Action) DefaultActionGroup(org.eclipse.che.ide.api.action.DefaultActionGroup) Machine(org.eclipse.che.api.core.model.machine.Machine)

Example 9 with Machine

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()));
            }
        }
    });
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) ProcessTreeNode(org.eclipse.che.ide.extension.machine.client.processes.ProcessTreeNode) Operation(org.eclipse.che.api.promises.client.Operation) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) DefaultOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole) DefaultOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.DefaultOutputConsole) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 10 with Machine

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

Aggregations

Machine (org.eclipse.che.api.core.model.machine.Machine)32 ArrayList (java.util.ArrayList)15 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)13 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)12 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)12 Matchers.anyString (org.mockito.Matchers.anyString)11 Test (org.testng.annotations.Test)11 Map (java.util.Map)9 Instance (org.eclipse.che.api.machine.server.spi.Instance)9 HashMap (java.util.HashMap)8 List (java.util.List)8 ServerConfImpl (org.eclipse.che.api.machine.server.model.impl.ServerConfImpl)8 ServerException (org.eclipse.che.api.core.ServerException)7 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)7 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)7 Arrays.asList (java.util.Arrays.asList)6 Collections (java.util.Collections)6 Collections.singletonMap (java.util.Collections.singletonMap)6 NotFoundException (org.eclipse.che.api.core.NotFoundException)6 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)6