use of org.eclipse.che.api.core.model.workspace.Environment in project che by eclipse.
the class ProcessesPanelPresenter method hasAgent.
/**
* Determines the agent is injected in the specified machine.
*
* @param machineName
* machine name
* @param agent
* agent
* @return
* <b>true</b> is the agent is injected, otherwise return <b>false</b>
*/
private boolean hasAgent(String machineName, String agent) {
Workspace workspace = appContext.getWorkspace();
if (workspace == null) {
return false;
}
WorkspaceConfig workspaceConfig = workspace.getConfig();
if (workspaceConfig == null) {
return false;
}
Map<String, ? extends Environment> environments = workspaceConfig.getEnvironments();
if (environments == null) {
return false;
}
for (Environment environment : environments.values()) {
ExtendedMachine extendedMachine = environment.getMachines().get(machineName);
if (extendedMachine != null) {
if (extendedMachine.getAgents() != null && extendedMachine.getAgents().contains(agent)) {
return true;
}
}
}
return false;
}
use of org.eclipse.che.api.core.model.workspace.Environment 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);
}
Aggregations