Search in sources :

Example 1 with MachineRuntimeInfoImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl in project che by eclipse.

the class SshMachineInstance method getRuntime.

public MachineRuntimeInfoImpl getRuntime() {
    // lazy initialization
    if (machineRuntime == null) {
        synchronized (this) {
            if (machineRuntime == null) {
                UriBuilder uriBuilder = UriBuilder.fromUri("http://" + sshClient.getHost());
                final Map<String, ServerImpl> servers = new HashMap<>();
                for (ServerConf serverConf : machinesServers) {
                    servers.put(serverConf.getPort(), serverConfToServer(serverConf, uriBuilder.clone()));
                }
                machineRuntime = new MachineRuntimeInfoImpl(emptyMap(), emptyMap(), servers);
            }
        }
    // todo get env from client
    }
    return machineRuntime;
}
Also used : MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) ServerConf(org.eclipse.che.api.core.model.machine.ServerConf) ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 2 with MachineRuntimeInfoImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl in project che by eclipse.

the class CheEnvironmentEngineTest method createMachine.

private static MachineImpl createMachine(String workspaceId, String envName, CheServiceImpl service, String serviceName, boolean isDev) {
    MachineSourceImpl machineSource;
    if (service.getBuild() != null && service.getBuild().getContext() != null) {
        machineSource = new MachineSourceImpl("dockerfile").setLocation(service.getBuild().getContext());
    } else if (service.getImage() != null) {
        machineSource = new MachineSourceImpl("image").setLocation(service.getImage());
    } else if (service.getBuild() != null && service.getBuild().getContext() == null && service.getBuild().getDockerfileContent() != null) {
        machineSource = new MachineSourceImpl("dockerfile").setContent(service.getBuild().getDockerfileContent());
    } else {
        throw new IllegalArgumentException("Build context or image should contain non empty value");
    }
    MachineLimitsImpl limits = new MachineLimitsImpl((int) Size.parseSizeToMegabytes(service.getMemLimit() + "b"));
    return MachineImpl.builder().setConfig(MachineConfigImpl.builder().setDev(isDev).setName(serviceName).setSource(machineSource).setLimits(limits).setType("docker").build()).setId(service.getId()).setOwner("userName").setStatus(MachineStatus.RUNNING).setWorkspaceId(workspaceId).setEnvName(envName).setRuntime(new MachineRuntimeInfoImpl(emptyMap(), emptyMap(), emptyMap())).build();
}
Also used : MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) MachineLimitsImpl(org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl)

Example 3 with MachineRuntimeInfoImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl in project che by eclipse.

the class WorkspaceServiceTest method testWorkspaceLinks.

@Test
public void testWorkspaceLinks() throws Exception {
    // given
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    EnvironmentImpl environment = workspace.getConfig().getEnvironments().get(workspace.getConfig().getDefaultEnv());
    assertNotNull(environment);
    final WorkspaceRuntimeImpl runtime = new WorkspaceRuntimeImpl(workspace.getConfig().getDefaultEnv(), null);
    MachineConfigImpl devMachineConfig = MachineConfigImpl.builder().setDev(true).setEnvVariables(emptyMap()).setServers(emptyList()).setLimits(new MachineLimitsImpl(1024)).setSource(new MachineSourceImpl("type").setContent("content")).setName(environment.getMachines().keySet().iterator().next()).setType("type").build();
    runtime.setDevMachine(new MachineImpl(devMachineConfig, "machine123", workspace.getId(), workspace.getConfig().getDefaultEnv(), USER_ID, MachineStatus.RUNNING, new MachineRuntimeInfoImpl(emptyMap(), emptyMap(), singletonMap("8080/https", new ServerImpl("wsagent", "https", "address", "url", new ServerPropertiesImpl("path", "internaladdress", "internalurl"))))));
    runtime.getMachines().add(runtime.getDevMachine());
    workspace.setStatus(RUNNING);
    workspace.setRuntime(runtime);
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    final WorkspaceDto workspaceDto = unwrapDto(response, WorkspaceDto.class);
    final Set<String> actualRels = workspaceDto.getLinks().stream().map(Link::getRel).collect(toSet());
    final Set<String> expectedRels = new HashSet<>(asList(LINK_REL_START_WORKSPACE, LINK_REL_REMOVE_WORKSPACE, GET_ALL_USER_WORKSPACES, LINK_REL_GET_SNAPSHOT, LINK_REL_GET_WORKSPACE_EVENTS_CHANNEL, LINK_REL_IDE_URL, LINK_REL_SELF, LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL, LINK_REL_ENVIRONMENT_STATUS_CHANNEL));
    assertTrue(actualRels.equals(expectedRels), format("Links difference: '%s'. \n" + "Returned links: '%s', \n" + "Expected links: '%s'.", Sets.symmetricDifference(actualRels, expectedRels), actualRels.toString(), expectedRels.toString()));
    assertNotNull(workspaceDto.getRuntime().getLink(LINK_REL_STOP_WORKSPACE), "Runtime doesn't contain stop link");
    assertNotNull(workspaceDto.getRuntime().getLink(WSAGENT_REFERENCE), "Runtime doesn't contain wsagent link");
    assertNotNull(workspaceDto.getRuntime().getLink(WSAGENT_WEBSOCKET_REFERENCE), "Runtime doesn't contain wsagent.websocket link");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) MachineLimitsImpl(org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Matchers.anyString(org.mockito.Matchers.anyString) MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) Response(com.jayway.restassured.response.Response) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) ServerPropertiesImpl(org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

MachineRuntimeInfoImpl (org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl)3 MachineLimitsImpl (org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl)2 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)2 ServerImpl (org.eclipse.che.api.machine.server.model.impl.ServerImpl)2 Response (com.jayway.restassured.response.Response)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 ServerConf (org.eclipse.che.api.core.model.machine.ServerConf)1 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)1 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)1 ServerPropertiesImpl (org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl)1 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)1 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)1 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)1 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)1 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Test (org.testng.annotations.Test)1