Search in sources :

Example 91 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class DockerfileEnvironmentParserTest method shouldBeAbleToParseDockerfileEnvironmentFromContent.

@Test
public void shouldBeAbleToParseDockerfileEnvironmentFromContent() throws ServerException {
    Environment environment = createDockerfileEnvConfig(DEFAULT_DOCKERFILE, null, DEFAULT_MACHINE_NAME);
    CheServicesEnvironmentImpl expected = new CheServicesEnvironmentImpl();
    expected.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withBuild(new CheServiceBuildContextImpl().withDockerfileContent(DEFAULT_DOCKERFILE)));
    // when
    CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
    // then
    assertEquals(cheServicesEnvironment, expected);
}
Also used : CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Environment(org.eclipse.che.api.core.model.workspace.Environment) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 92 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class MachineProviderImplTest method shouldNotRemoveImageWhenCreatingInstanceFromLocalImage.

@Test
public void shouldNotRemoveImageWhenCreatingInstanceFromLocalImage() throws Exception {
    String repo = "repo1";
    String tag = "latest";
    MachineProviderImpl provider = spy(new MachineProviderBuilder().setSnapshotUseRegistry(false).build());
    CheServiceImpl machine = createService();
    machine.setBuild(null);
    machine.setImage(repo + ":" + tag + "@digest");
    provider.startService(USER_NAME, WORKSPACE_ID, ENV_NAME, MACHINE_NAME, false, NETWORK_NAME, machine, LineConsumer.DEV_NULL);
    verify(dockerConnector, never()).removeImage(any(RemoveImageParams.class));
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Matchers.anyString(org.mockito.Matchers.anyString) RemoveImageParams(org.eclipse.che.plugin.docker.client.params.RemoveImageParams) Test(org.testng.annotations.Test)

Example 93 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class WorkspaceRuntimeIntegrationTest method environmentEngineShouldDestroyAllMachinesBeforeRemovalOfEnvironmentRecord.

// Check for https://github.com/codenvy/codenvy/issues/593
@Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "Workspace with id '" + WORKSPACE_ID + "' is not running")
public void environmentEngineShouldDestroyAllMachinesBeforeRemovalOfEnvironmentRecord() throws Exception {
    // given
    EnvironmentDto environment = newDto(EnvironmentDto.class);
    environment.withMachines(singletonMap("service1", newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent"))));
    WorkspaceConfigDto config = newDto(WorkspaceConfigDto.class).withDefaultEnv(ENV_NAME).withName("ws1").withEnvironments(singletonMap(ENV_NAME, environment));
    WorkspaceDto workspace = newDto(WorkspaceDto.class).withId(WORKSPACE_ID).withNamespace("namespace").withConfig(config);
    Instance instance = mock(Instance.class);
    MachineConfigImpl machineConfig = new MachineConfigImpl();
    machineConfig.setDev(true);
    machineConfig.setName("service1");
    when(instance.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(instance.getId()).thenReturn("machineId");
    when(instance.getConfig()).thenReturn(machineConfig);
    CheServicesEnvironmentImpl internalEnv = new CheServicesEnvironmentImpl();
    internalEnv.getServices().put("service1", new CheServiceImpl().withId("machineId"));
    when(environmentParser.parse(any(Environment.class))).thenReturn(internalEnv);
    when(instanceProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(instance);
    runtimes.startAsync(workspace, ENV_NAME, false);
    verify(sharedPool).submit(taskCaptor.capture());
    taskCaptor.getValue().call();
    WaitingAnswer<Void> waitingAnswer = new WaitingAnswer<>();
    doAnswer(waitingAnswer).when(instance).destroy();
    // when
    executor.execute(() -> {
        try {
            runtimes.stop(WORKSPACE_ID);
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    });
    waitingAnswer.waitAnswerCall(1, TimeUnit.SECONDS);
    // then
    // no exception - environment and workspace are still running
    runtimes.getRuntime(WORKSPACE_ID);
    // let instance removal proceed
    waitingAnswer.completeAnswer();
    // verify destroying was called
    verify(instance, timeout(1000)).destroy();
    verify(instanceProvider, timeout(1000)).destroyNetwork(anyString());
    // wait to ensure that removal of runtime is finished
    Thread.sleep(500);
    // runtime is removed - now getting of it should throw an exception
    runtimes.getRuntime(WORKSPACE_ID);
}
Also used : WaitingAnswer(org.eclipse.che.commons.test.mockito.answer.WaitingAnswer) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) NotFoundException(org.eclipse.che.api.core.NotFoundException) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Environment(org.eclipse.che.api.core.model.workspace.Environment) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Test(org.testng.annotations.Test)

Aggregations

CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)93 Test (org.testng.annotations.Test)63 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)46 Matchers.anyString (org.mockito.Matchers.anyString)32 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)28 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)24 Map (java.util.Map)18 Machine (org.eclipse.che.api.core.model.machine.Machine)17 CreateContainerParams (org.eclipse.che.plugin.docker.client.params.CreateContainerParams)17 ServerException (org.eclipse.che.api.core.ServerException)16 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)16 IOException (java.io.IOException)14 List (java.util.List)14 ServerConf (org.eclipse.che.api.core.model.machine.ServerConf)14 Collections.singletonMap (java.util.Collections.singletonMap)13 Set (java.util.Set)13 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)13 Instance (org.eclipse.che.api.machine.server.spi.Instance)13 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)13