use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method createEnv.
private EnvironmentImpl createEnv() {
// singletonMap, asList are wrapped into modifiable collections to ease env modifying by tests
EnvironmentImpl env = new EnvironmentImpl();
Map<String, ExtendedMachineImpl> machines = new HashMap<>();
Map<String, ServerConf2Impl> servers = new HashMap<>();
servers.put("ref1", new ServerConf2Impl("8080/tcp", "proto1", singletonMap("prop1", "propValue")));
servers.put("ref2", new ServerConf2Impl("8080/udp", "proto1", null));
servers.put("ref3", new ServerConf2Impl("9090", "proto1", null));
machines.put("dev-machine", new ExtendedMachineImpl(asList("org.eclipse.che.ws-agent", "someAgent"), servers, singletonMap("memoryLimitBytes", "10000")));
machines.put("machine2", new ExtendedMachineImpl(asList("someAgent2", "someAgent3"), null, singletonMap("memoryLimitBytes", "10000")));
String environmentRecipeContent = "services:\n " + "dev-machine:\n image: codenvy/ubuntu_jdk8\n mem_limit: 4294967296\n " + "machine2:\n image: codenvy/ubuntu_jdk8\n mem_limit: 100000";
env.setRecipe(new EnvironmentRecipeImpl("compose", "application/x-yaml", environmentRecipeContent, null));
env.setMachines(machines);
return env;
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnEnvironmentStart.
@Test
public void shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnEnvironmentStart() throws Exception {
// given
EnvironmentImpl env = createEnv();
String machineName = "machineWithDockerfileNotFromApi";
String contextUrl = "http://another-server.com/recipe/12345";
//prepare CheServicesEnvironmentImpl which should return compose parser
CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
cheServicesEnvironment.getServices().get(machineName).withBuild(new CheServiceBuildContextImpl().withContext(contextUrl));
// when
startEnv(env, cheServicesEnvironment);
// 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);
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironment.
@Test
public void shouldBeAbleToStartEnvironment() throws Exception {
// 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, false, messageConsumer, startedHandler);
// then
assertEquals(machines, expectedMachines);
for (Instance expectedMachine : expectedMachines) {
verify(startedHandler).started(eq(expectedMachine), any(ExtendedMachine.class));
}
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method envStartShouldThrowsExceptionIfSameEnvironmentExists.
@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Environment of workspace '.*' already exists")
public void envStartShouldThrowsExceptionIfSameEnvironmentExists() throws Exception {
// given
List<Instance> instances = startEnv();
Instance instance = instances.get(0);
EnvironmentImpl env = createEnv();
String envName = "env-1";
// when
engine.start(instance.getWorkspaceId(), envName, env, false, messageConsumer);
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class WorkspaceRuntimes method startAsync.
/**
* Asynchronously starts the environment of the workspace.
* Before executing start task checks whether all conditions
* are met and throws appropriate exceptions if not, so
* there is no way to start the same workspace twice.
*
* <p>Note that cancellation of resulting future won't
* interrupt workspace start, call {@link #stop(String)} directly instead.
*
* <p>If starting process is interrupted let's say within call
* to {@link #stop(String)} method, resulting future will
* be exceptionally completed(eventually) with an instance of
* {@link EnvironmentStartInterruptedException}. Note that clients
* don't have to cleanup runtime resources, the component
* will do necessary cleanup when interrupted.
*
* <p>Implementation notes:
* if thread which executes the task is interrupted, then the
* task is also eventually(depends on the environment engine implementation)
* interrupted as if {@link #stop(String)} is called directly.
* That helps to shutdown gracefully when thread pool is asked
* to {@link ExecutorService#shutdownNow()} and also reduces
* shutdown time when there are starting workspaces.
*
* @param workspace
* workspace containing target environment
* @param envName
* the name of the environment to start
* @param recover
* whether to recover from the snapshot
* @return completable future describing the instance of running environment
* @throws ConflictException
* when the workspace is already started
* @throws ConflictException
* when workspaces start refused {@link #refuseWorkspacesStart()} was called
* @throws ServerException
* when any other error occurs
* @throws IllegalArgumentException
* when the workspace doesn't contain the environment
* @throws NullPointerException
* when either {@code workspace} or {@code envName} is null
*/
public CompletableFuture<WorkspaceRuntimeImpl> startAsync(Workspace workspace, String envName, boolean recover) throws ConflictException, ServerException {
requireNonNull(workspace, "Non-null workspace required");
requireNonNull(envName, "Non-null environment name required");
EnvironmentImpl environment = copyEnv(workspace, envName);
String workspaceId = workspace.getId();
CompletableFuture<WorkspaceRuntimeImpl> cmpFuture;
StartTask startTask;
try (@SuppressWarnings("unused") Unlocker u = locks.writeLock(workspaceId)) {
checkIsNotTerminated("start the workspace");
if (isStartRefused.get()) {
throw new ConflictException(format("Start of the workspace '%s' is rejected by the system, " + "no more workspaces are allowed to start", workspace.getConfig().getName()));
}
RuntimeState state = states.get(workspaceId);
if (state != null) {
throw new ConflictException(format("Could not start workspace '%s' because its status is '%s'", workspace.getConfig().getName(), state.status));
}
startTask = new StartTask(workspaceId, envName, environment, recover, cmpFuture = new CompletableFuture<>());
states.put(workspaceId, new RuntimeState(WorkspaceStatus.STARTING, envName, startTask, sharedPool.submit(startTask)));
}
// publish event synchronously as the task may not be executed by
// executors service(due to legal cancellation), clients still have
// to receive STOPPED -> STARTING event
eventsService.publish(DtoFactory.newDto(WorkspaceStatusEvent.class).withWorkspaceId(workspaceId).withStatus(WorkspaceStatus.STARTING).withEventType(EventType.STARTING).withPrevStatus(WorkspaceStatus.STOPPED));
// so the start thread is free to go and start the environment
startTask.unlockStart();
return cmpFuture;
}
Aggregations