Search in sources :

Example 51 with CheServicesEnvironmentImpl

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

the class DefaultServicesStartStrategyTest method shouldOrderServicesWithComplementaryDependenciesInDependsOnLinksAndVolumesFrom.

@Test
public void shouldOrderServicesWithComplementaryDependenciesInDependsOnLinksAndVolumesFrom() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl().withVolumesFrom(singletonList("first")));
    composeEnvironment.getServices().put("third", new CheServiceImpl().withVolumesFrom(singletonList("second")).withDependsOn(singletonList("first")));
    composeEnvironment.getServices().put("first", new CheServiceImpl());
    composeEnvironment.getServices().put("forth", new CheServiceImpl().withVolumesFrom(singletonList("third")).withDependsOn(singletonList("second")).withLinks(singletonList("first:alias")));
    composeEnvironment.getServices().put("fifth", new CheServiceImpl().withVolumesFrom(singletonList("first")).withLinks(singletonList("forth")).withDependsOn(singletonList("second")));
    List<String> expected = asList("first", "second", "third", "forth", "fifth");
    // when
    List<String> actual = strategy.order(composeEnvironment);
    // then
    assertEquals(actual, expected);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 52 with CheServicesEnvironmentImpl

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

the class DefaultServicesStartStrategyTest method shouldOrderServicesWithLinks.

@Test
public void shouldOrderServicesWithLinks() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl().withLinks(singletonList("first:alias")));
    composeEnvironment.getServices().put("third", new CheServiceImpl().withLinks(asList("first", "second")));
    composeEnvironment.getServices().put("first", new CheServiceImpl().withLinks(emptyList()));
    composeEnvironment.getServices().put("forth", new CheServiceImpl().withLinks(singletonList("third")));
    composeEnvironment.getServices().put("fifth", new CheServiceImpl().withLinks(asList("forth:alias", "first:alias")));
    List<String> expected = asList("first", "second", "third", "forth", "fifth");
    // when
    List<String> actual = strategy.order(composeEnvironment);
    // then
    assertEquals(actual, expected);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 53 with CheServicesEnvironmentImpl

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

the class DefaultServicesStartStrategyTest method shouldFailIfCircularDependencyFound.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Launch order of machines '.*, .*' can't be evaluated. Circular dependency.")
public void shouldFailIfCircularDependencyFound() throws Exception {
    // given
    CheServicesEnvironmentImpl composeEnvironment = new CheServicesEnvironmentImpl();
    composeEnvironment.getServices().put("second", new CheServiceImpl().withDependsOn(singletonList("third")));
    composeEnvironment.getServices().put("third", new CheServiceImpl().withDependsOn(singletonList("second")));
    composeEnvironment.getServices().put("first", new CheServiceImpl());
    // when
    strategy.order(composeEnvironment);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Test(org.testng.annotations.Test)

Example 54 with CheServicesEnvironmentImpl

use of org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl 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

CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)54 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)44 Test (org.testng.annotations.Test)38 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)15 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)8 HashMap (java.util.HashMap)7 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)7 Environment (org.eclipse.che.api.core.model.workspace.Environment)6 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)6 Map (java.util.Map)3 EnvironmentRecipe (org.eclipse.che.api.core.model.workspace.EnvironmentRecipe)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3 EnvironmentRecipeImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)3 Joiner (com.google.common.base.Joiner)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2