Skip to content

Commit

Permalink
CHE-3616 Remove Machine API (server part) (#4331)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaposhnik committed Mar 7, 2017
1 parent 37275d3 commit 11ec789
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 629 deletions.
Expand Up @@ -17,7 +17,6 @@
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;

import org.eclipse.che.api.environment.server.MachineService;
import org.eclipse.che.api.machine.server.spi.Instance;
import org.eclipse.che.api.machine.server.spi.InstanceProcess;
import org.eclipse.che.plugin.docker.client.DockerConnector;
Expand All @@ -42,8 +41,6 @@ public class LocalDockerModule extends AbstractModule {

@Override
protected void configure() {
bind(MachineService.class);

install(new FactoryModuleBuilder()
.implement(Instance.class, DockerInstance.class)
.implement(InstanceProcess.class, DockerProcess.class)
Expand Down
Expand Up @@ -10,28 +10,20 @@
*******************************************************************************/
package org.eclipse.che.api.environment.server;

import com.google.common.collect.Lists;

import org.eclipse.che.api.core.rest.ServiceContext;
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.api.core.rest.shared.dto.LinkParameter;
import org.eclipse.che.api.machine.shared.Constants;
import org.eclipse.che.api.machine.shared.dto.MachineDto;
import org.eclipse.che.api.machine.shared.dto.MachineProcessDto;
import org.eclipse.che.api.machine.shared.dto.ServerDto;

import javax.inject.Singleton;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static org.eclipse.che.api.core.util.LinksHelper.createLink;
import static org.eclipse.che.api.machine.shared.Constants.ENVIRONMENT_OUTPUT_CHANNEL_TEMPLATE;
import static org.eclipse.che.api.machine.shared.Constants.ENVIRONMENT_STATUS_CHANNEL_TEMPLATE;
Expand All @@ -42,64 +34,26 @@
import static org.eclipse.che.dto.server.DtoFactory.newDto;

/**
* Helps to inject {@link MachineService} related links.
* Helps to inject Machine related links.
*
* @author Anton Korneta
*/
@Singleton
public class MachineServiceLinksInjector {
public class MachineLinksInjector {

public MachineDto injectLinks(MachineDto machine, ServiceContext serviceContext) {
final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder();
final List<Link> links = new ArrayList<>();

links.add(createLink(HttpMethod.GET,
uriBuilder.clone()
.path(MachineService.class, "getMachineById")
.build(machine.getWorkspaceId(), machine.getId())
.toString(),
APPLICATION_JSON,
"self link"));
links.add(createLink(HttpMethod.GET,
uriBuilder.clone()
.path(MachineService.class, "getMachines")
.build(machine.getWorkspaceId())
.toString(),
null,
APPLICATION_JSON,
Constants.LINK_REL_GET_MACHINES));
links.add(createLink(HttpMethod.DELETE,
uriBuilder.clone()
.path(MachineService.class, "stopMachine")
.build(machine.getWorkspaceId(), machine.getId())
.toString(),
Constants.LINK_REL_DESTROY_MACHINE));
links.add(createLink(HttpMethod.POST,
uriBuilder.clone()
.path(MachineService.class, "executeCommandInMachine")
.build(machine.getWorkspaceId(), machine.getId())
.toString(),
APPLICATION_JSON,
APPLICATION_JSON,
Constants.LINK_REL_EXECUTE_COMMAND,
newDto(LinkParameter.class).withName("outputChannel")
.withRequired(false)));
URI getProcessesUri = uriBuilder.clone()
.path(MachineService.class, "getProcesses")
.build(machine.getWorkspaceId(), machine.getId());
links.add(createLink(HttpMethod.GET,
getProcessesUri.toString(),
APPLICATION_JSON,
Constants.LINK_REL_GET_PROCESSES));

injectTerminalLink(machine, serviceContext, links);
injectExecAgentLink(machine, serviceContext, links);

// add workspace channel links
final Link workspaceChannelLink = createLink("GET",
serviceContext.getBaseUriBuilder()
.path("ws")
.scheme("https".equals(getProcessesUri.getScheme()) ? "wss" : "ws")
.scheme("https".equals(
serviceContext.getBaseUriBuilder().build().getScheme()) ? "wss"
: "ws")
.build()
.toString(),
null);
Expand Down Expand Up @@ -154,40 +108,4 @@ protected void injectExecAgentLink(MachineDto machine, ServiceContext serviceCon
EXEC_AGENT_REFERENCE)));
}
}

public MachineProcessDto injectLinks(MachineProcessDto process,
String workspaceId,
String machineId,
ServiceContext serviceContext) {
final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder();
final List<Link> links = Lists.newArrayListWithExpectedSize(3);

links.add(createLink(HttpMethod.DELETE,
uriBuilder.clone()
.path(MachineService.class, "stopProcess")
.build(workspaceId,
machineId,
process.getPid())
.toString(),
Constants.LINK_REL_STOP_PROCESS));
links.add(createLink(HttpMethod.GET,
uriBuilder.clone()
.path(MachineService.class, "getProcessLogs")
.build(workspaceId,
machineId,
process.getPid())
.toString(),
TEXT_PLAIN,
Constants.LINK_REL_GET_PROCESS_LOGS));
links.add(createLink(HttpMethod.GET,
uriBuilder.clone()
.path(MachineService.class, "getProcesses")
.build(workspaceId,
machineId)
.toString(),
APPLICATION_JSON,
Constants.LINK_REL_GET_PROCESSES));

return process.withLinks(links);
}
}

0 comments on commit 11ec789

Please sign in to comment.