Search in sources :

Example 21 with Machine

use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.

the class MachinePanelPresenter method onMachineDestroyed.

/**
     * {@inheritDoc}
     */
@Override
public void onMachineDestroyed(MachineStateEvent event) {
    Machine machine = event.getMachine();
    MachineTreeNode deletedNode = existingMachineNodes.get(machine.getId());
    machineNodes.remove(deletedNode);
    existingMachineNodes.remove(machine.getId());
    view.setData(rootNode);
    selectFirstNode();
}
Also used : Machine(org.eclipse.che.api.core.model.machine.Machine)

Example 22 with Machine

use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.

the class CheEnvironmentEngineTest method devMachineStopShouldThrowException.

@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Stop of dev machine is not allowed. Please, stop whole environment")
public void devMachineStopShouldThrowException() throws Exception {
    // given
    List<Instance> instances = startEnv();
    Optional<Instance> instanceOpt = instances.stream().filter(machine -> machine.getConfig().isDev()).findAny();
    assertTrue(instanceOpt.isPresent(), "Required for test dev machine is not found");
    Instance instance = instanceOpt.get();
    // when
    engine.stopMachine(instance.getWorkspaceId(), instance.getId());
}
Also used : Agent(org.eclipse.che.api.agent.shared.model.Agent) MachineStatusEvent(org.eclipse.che.api.machine.shared.dto.event.MachineStatusEvent) Listeners(org.testng.annotations.Listeners) MachineStatus(org.eclipse.che.api.core.model.machine.MachineStatus) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) MachineLimitsImpl(org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl) Test(org.testng.annotations.Test) WorkspaceSharedPool(org.eclipse.che.api.workspace.server.WorkspaceSharedPool) AfterMethod(org.testng.annotations.AfterMethod) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) Collections.singletonList(java.util.Collections.singletonList) Mockito.doThrow(org.mockito.Mockito.doThrow) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) MessageConsumer(org.eclipse.che.api.core.util.MessageConsumer) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) Mockito.doReturn(org.mockito.Mockito.doReturn) EventService(org.eclipse.che.api.core.notification.EventService) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) Collections.emptyList(java.util.Collections.emptyList) BeforeMethod(org.testng.annotations.BeforeMethod) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) UUID(java.util.UUID) String.format(java.lang.String.format) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.inOrder(org.mockito.Mockito.inOrder) Optional(java.util.Optional) AgentKey(org.eclipse.che.api.agent.shared.model.AgentKey) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) AgentRegistry(org.eclipse.che.api.agent.server.AgentRegistry) Mockito.mock(org.mockito.Mockito.mock) MachineInstanceProviders(org.eclipse.che.api.machine.server.MachineInstanceProviders) Assert.assertNull(org.testng.Assert.assertNull) Size(org.eclipse.che.commons.lang.Size) Mock(org.mockito.Mock) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) Mockito.spy(org.mockito.Mockito.spy) Captor(org.mockito.Captor) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) InstanceProvider(org.eclipse.che.api.machine.server.spi.InstanceProvider) ArgumentCaptor(org.mockito.ArgumentCaptor) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2) ConflictException(org.eclipse.che.api.core.ConflictException) Collections.singletonMap(java.util.Collections.singletonMap) InstanceStateEvent(org.eclipse.che.api.machine.server.event.InstanceStateEvent) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) SnapshotDao(org.eclipse.che.api.machine.server.spi.SnapshotDao) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) Collections.emptyMap(java.util.Collections.emptyMap) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) InOrder(org.mockito.InOrder) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Assert.fail(org.testng.Assert.fail) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) MachineLogMessage(org.eclipse.che.api.core.model.machine.MachineLogMessage) NotFoundException(org.eclipse.che.api.core.NotFoundException) Mockito.verify(org.mockito.Mockito.verify) Machine(org.eclipse.che.api.core.model.machine.Machine) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Mockito.never(org.mockito.Mockito.never) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) RecipeDownloader(org.eclipse.che.api.machine.server.util.RecipeDownloader) ServerException(org.eclipse.che.api.core.ServerException) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) Instance(org.eclipse.che.api.machine.server.spi.Instance) Test(org.testng.annotations.Test)

Example 23 with Machine

use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.

the class CheEnvironmentEngineTest method shouldBeAbleToStopMachine.

@Test
public void shouldBeAbleToStopMachine() throws Exception {
    // given
    List<Instance> instances = startEnv();
    Optional<Instance> instanceOpt = instances.stream().filter(machine -> !machine.getConfig().isDev()).findAny();
    assertTrue(instanceOpt.isPresent(), "Required for test non-dev machine is not found");
    Instance instance = instanceOpt.get();
    // when
    engine.stopMachine(instance.getWorkspaceId(), instance.getId());
    // then
    verify(instance).destroy();
}
Also used : Agent(org.eclipse.che.api.agent.shared.model.Agent) MachineStatusEvent(org.eclipse.che.api.machine.shared.dto.event.MachineStatusEvent) Listeners(org.testng.annotations.Listeners) MachineStatus(org.eclipse.che.api.core.model.machine.MachineStatus) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) MachineLimitsImpl(org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl) Test(org.testng.annotations.Test) WorkspaceSharedPool(org.eclipse.che.api.workspace.server.WorkspaceSharedPool) AfterMethod(org.testng.annotations.AfterMethod) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) Collections.singletonList(java.util.Collections.singletonList) Mockito.doThrow(org.mockito.Mockito.doThrow) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Arrays.asList(java.util.Arrays.asList) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) MessageConsumer(org.eclipse.che.api.core.util.MessageConsumer) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) Mockito.doReturn(org.mockito.Mockito.doReturn) EventService(org.eclipse.che.api.core.notification.EventService) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) EventSubscriber(org.eclipse.che.api.core.notification.EventSubscriber) Collections.emptyList(java.util.Collections.emptyList) BeforeMethod(org.testng.annotations.BeforeMethod) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) UUID(java.util.UUID) String.format(java.lang.String.format) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Mockito.inOrder(org.mockito.Mockito.inOrder) Optional(java.util.Optional) AgentKey(org.eclipse.che.api.agent.shared.model.AgentKey) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) AgentRegistry(org.eclipse.che.api.agent.server.AgentRegistry) Mockito.mock(org.mockito.Mockito.mock) MachineInstanceProviders(org.eclipse.che.api.machine.server.MachineInstanceProviders) Assert.assertNull(org.testng.Assert.assertNull) Size(org.eclipse.che.commons.lang.Size) Mock(org.mockito.Mock) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) Mockito.spy(org.mockito.Mockito.spy) Captor(org.mockito.Captor) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) InstanceProvider(org.eclipse.che.api.machine.server.spi.InstanceProvider) ArgumentCaptor(org.mockito.ArgumentCaptor) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2) ConflictException(org.eclipse.che.api.core.ConflictException) Collections.singletonMap(java.util.Collections.singletonMap) InstanceStateEvent(org.eclipse.che.api.machine.server.event.InstanceStateEvent) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) SnapshotDao(org.eclipse.che.api.machine.server.spi.SnapshotDao) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) Collections.emptyMap(java.util.Collections.emptyMap) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) InOrder(org.mockito.InOrder) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Assert.fail(org.testng.Assert.fail) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) MachineLogMessage(org.eclipse.che.api.core.model.machine.MachineLogMessage) NotFoundException(org.eclipse.che.api.core.NotFoundException) Mockito.verify(org.mockito.Mockito.verify) Machine(org.eclipse.che.api.core.model.machine.Machine) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Mockito.never(org.mockito.Mockito.never) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) RecipeDownloader(org.eclipse.che.api.machine.server.util.RecipeDownloader) ServerException(org.eclipse.che.api.core.ServerException) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) Instance(org.eclipse.che.api.machine.server.spi.Instance) Test(org.testng.annotations.Test)

Example 24 with Machine

use of org.eclipse.che.api.core.model.machine.Machine 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 25 with Machine

use of org.eclipse.che.api.core.model.machine.Machine in project che by eclipse.

the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironmentWithRecover.

@Test
public void shouldBeAbleToStartEnvironmentWithRecover() throws Exception {
    // given
    SnapshotImpl snapshot = mock(SnapshotImpl.class);
    MachineSourceImpl machineSource = new MachineSourceImpl("image", "registry.com/snapshot123:latest@sha256:abc1234567890", null);
    when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenReturn(snapshot);
    when(snapshot.getMachineSource()).thenReturn(machineSource);
    // given
    EnvironmentImpl env = createEnv();
    String envName = "env-1";
    String workspaceId = "wsId";
    List<Instance> expectedMachines = new ArrayList<>();
    when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
        Object[] arguments = invocationOnMock.getArguments();
        String machineName = (String) arguments[3];
        boolean isDev = (boolean) arguments[4];
        CheServiceImpl service = (CheServiceImpl) arguments[6];
        Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
        NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
        expectedMachines.add(instance);
        return instance;
    });
    when(environmentParser.parse(env)).thenReturn(createCheServicesEnv());
    // when
    List<Instance> machines = engine.start(workspaceId, envName, env, true, messageConsumer);
    // then
    assertEquals(machines, expectedMachines);
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), anyString(), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals(actualService.getImage(), "registry.com/snapshot123:latest");
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ArrayList(java.util.ArrayList) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) Test(org.testng.annotations.Test)

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