Search in sources :

Example 6 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnMachineStart.

@Test
public void shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnMachineStart() throws Exception {
    // given
    List<Instance> instances = startEnv();
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
    MachineConfigImpl config = createConfig(false);
    String machineName = "extraMachine";
    config.setName(machineName);
    String contextUrl = "http://another-server.com/recipe/12345";
    config.setSource(new MachineSourceImpl("docker").setLocation(contextUrl));
    // when
    engine.startMachine(workspaceId, config, emptyList());
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertNull(actualService.getBuild().getDockerfilePath());
    assertNull(actualService.getBuild().getDockerfileContent());
    assertEquals(actualService.getBuild().getContext(), contextUrl);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 7 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldSetDefaultRamToMachineWithoutRamOnMachineStart.

@Test
public void shouldSetDefaultRamToMachineWithoutRamOnMachineStart() throws Exception {
    // given
    List<Instance> instances = startEnv();
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
    MachineConfigImpl config = createConfig(false);
    String machineName = "extraMachine";
    config.setName(machineName);
    config.setLimits(null);
    // when
    engine.startMachine(workspaceId, config, emptyList());
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals((long) actualService.getMemLimit(), DEFAULT_MACHINE_MEM_LIMIT_MB * 1024L * 1024L);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 8 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldApplyAgentsOnDockerMachineStart.

@Test
public void shouldApplyAgentsOnDockerMachineStart() throws Exception {
    // given
    List<Instance> instances = startEnv();
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
    MachineConfigImpl config = createConfig(false);
    List<String> agents = asList("agent1", "agent2");
    // when
    engine.startMachine(workspaceId, config, agents);
    // then
    verify(infrastructureProvisioner).provision(any(ExtendedMachineImpl.class), any(CheServiceImpl.class));
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 9 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldBeAbleToStartNonDockerMachine.

@Test
public void shouldBeAbleToStartNonDockerMachine() throws Exception {
    // given
    ServerConf2 serverConf2 = mock(ServerConf2.class);
    when(serverConf2.getPort()).thenReturn("1111/tcp");
    when(serverConf2.getProtocol()).thenReturn("http");
    when(serverConf2.getProperties()).thenReturn(singletonMap("path", "some path"));
    when(agent.getServers()).thenAnswer(invocation -> singletonMap("ssh", serverConf2));
    List<Instance> instances = startEnv();
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineInstanceProviders.getProvider("anotherType")).thenReturn(instanceProvider);
    doReturn(newMachine).when(instanceProvider).createInstance(any(Machine.class), any(LineConsumer.class));
    MachineConfigImpl config = MachineConfigImpl.builder().fromConfig(createConfig(false)).setType("anotherType").build();
    // when
    Instance actualInstance = engine.startMachine(workspaceId, config, singletonList("agent"));
    // then
    assertEquals(actualInstance, newMachine);
    ArgumentCaptor<Machine> argumentCaptor = ArgumentCaptor.forClass(Machine.class);
    verify(instanceProvider).createInstance(argumentCaptor.capture(), any(LineConsumer.class));
    MachineConfigImpl newConfig = new MachineConfigImpl(config);
    newConfig.setServers(singletonList(new ServerConfImpl("ssh", "1111/tcp", "http", "some path")));
    assertEquals(argumentCaptor.getValue().getConfig(), newConfig);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) Matchers.anyString(org.mockito.Matchers.anyString) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) Test(org.testng.annotations.Test)

Example 10 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method machineStartShouldPublishEvents.

@Test
public void machineStartShouldPublishEvents() throws Exception {
    // given
    List<Instance> instances = startEnv();
    Instance instance = instances.get(0);
    MachineConfigImpl config = createConfig(false);
    when(engine.generateMachineId()).thenReturn("newMachineId");
    // when
    engine.startMachine(instance.getWorkspaceId(), config, emptyList());
    // then
    verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.CREATING).withDev(config.isDev()).withMachineName(config.getName()).withMachineId("newMachineId").withWorkspaceId(instance.getWorkspaceId()));
    verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withDev(config.isDev()).withMachineName(config.getName()).withMachineId("newMachineId").withWorkspaceId(instance.getWorkspaceId()));
}
Also used : MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) Test(org.testng.annotations.Test)

Aggregations

MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)16 Test (org.testng.annotations.Test)14 Instance (org.eclipse.che.api.machine.server.spi.Instance)12 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)8 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)8 Matchers.anyString (org.mockito.Matchers.anyString)8 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 Machine (org.eclipse.che.api.core.model.machine.Machine)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)3 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)3 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)3 ConflictException (org.eclipse.che.api.core.ConflictException)2 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)2 MachineLimitsImpl (org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl)2 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)2 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)2 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)2 Response (com.jayway.restassured.response.Response)1 HashSet (java.util.HashSet)1