Search in sources :

Example 6 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method shouldThrowExceptionWhenDownloadedPluginIsNotMatchedWitComponent.

@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "The downloaded plugin 'publisher/id/version' configuration does " + "not have the corresponding component in devfile. Devfile contains the following " + "cheEditor/chePlugins: \\[publisher/editor/1, publisher/plugin/1\\]")
public void shouldThrowExceptionWhenDownloadedPluginIsNotMatchedWitComponent() throws Exception {
    // given
    ChePlugin chePlugin = createChePlugin("publisher/id/version");
    internalEnvironment.getDevfile().getComponents().clear();
    internalEnvironment.getDevfile().getComponents().add(new ComponentImpl("cheEditor", "publisher/editor/1"));
    internalEnvironment.getDevfile().getComponents().add(new ComponentImpl("chePlugin", "publisher/plugin/1"));
    internalEnvironment.getDevfile().getComponents().add(new ComponentImpl("k8s", null));
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
}
Also used : ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 7 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method shouldResolveMachineNameForCommandsInEnvironment.

@Test
public void shouldResolveMachineNameForCommandsInEnvironment() throws Exception {
    // given
    ChePlugin chePlugin = createChePlugin(createContainer("container"));
    String pluginRef = chePlugin.getId();
    CommandImpl pluginCommand = new CommandImpl("test-command", "echo Hello World!", "custom");
    pluginCommand.getAttributes().put("plugin", pluginRef);
    internalEnvironment.getCommands().add(pluginCommand);
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    List<CommandImpl> envCommands = internalEnvironment.getCommands();
    assertEquals(envCommands.size(), 1);
    CommandImpl envCommand = envCommands.get(0);
    assertEquals(envCommand.getName(), pluginCommand.getName());
    assertEquals(envCommand.getType(), pluginCommand.getType());
    assertEquals(envCommand.getCommandLine(), pluginCommand.getCommandLine());
    assertEquals(envCommand.getAttributes().get("plugin"), pluginRef);
    validateContainerNameName(envCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE), "container");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 8 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method shouldNotExposeChePluginPortIfThereIsNoEndpoint.

@Test
public void shouldNotExposeChePluginPortIfThereIsNoEndpoint() throws Exception {
    // given
    ChePluginEndpoint endpoint1 = new ChePluginEndpoint().name(CHE_PLUGIN_ENDPOINT_NAME).targetPort(101010).setPublic(true);
    CheContainerPort cheContainerPort1 = new CheContainerPort().exposedPort(101010);
    CheContainerPort cheContainerPort2 = new CheContainerPort().exposedPort(2020);
    ChePlugin chePlugin = createChePlugin();
    chePlugin.setEndpoints(singletonList(endpoint1));
    chePlugin.getContainers().get(0).setPorts(asList(cheContainerPort1, cheContainerPort2));
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    Container container = getOneAndOnlyNonUserContainer(internalEnvironment);
    verifyPortsExposed(container, 101010);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort) Test(org.testng.annotations.Test)

Example 9 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method addToolingInitContainerWithCommand.

@Test
public void addToolingInitContainerWithCommand() throws InfrastructureException {
    List<String> command = Arrays.asList("cp", "-rf", "test-file", "/some-volume/test");
    lenient().when(podSpec.getInitContainers()).thenReturn(new ArrayList<>());
    ChePlugin chePlugin = createChePlugin();
    List<CheContainer> initContainers = singletonList(createContainer(command, null));
    chePlugin.setInitContainers(initContainers);
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    verifyPodAndInitContainersNumber(1);
    Container toolingInitContainer = getOnlyOneInitContainerFromPod(internalEnvironment);
    verifyContainer(toolingInitContainer);
    assertEquals(toolingInitContainer.getCommand(), command);
}
Also used : CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 10 with ChePlugin

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method addsMachineWithServersForContainer.

@Test
public void addsMachineWithServersForContainer() throws Exception {
    // given
    ChePlugin chePlugin = createChePlugin();
    addPortToSingleContainerPlugin(chePlugin, 80, "test-port", emptyMap(), true);
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    InternalMachineConfig machineConfig = getOneAndOnlyNonUserMachine(internalEnvironment);
    assertEquals(machineConfig.getServers(), expectedSingleServer(80, "test-port", emptyMap(), true));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Aggregations

ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)68 Test (org.testng.annotations.Test)58 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)32 Container (io.fabric8.kubernetes.api.model.Container)30 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)20 ChePluginEndpoint (org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint)12 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)10 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)10 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)10 CheContainerPort (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort)8 Beta (com.google.common.annotations.Beta)6 Service (io.fabric8.kubernetes.api.model.Service)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 ChePluginsApplier (org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier)6 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)4 Sets (com.google.common.collect.Sets)4 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 String.format (java.lang.String.format)4