Make it possible to tell IDE to use a different "wsagent" server (#7392)
* Make it possible to tell IDE to use a different "wsagent" server passing server's ref prefix through query parameter Signed-off-by: Artem Zatsarynnyi <azatsary@redhat.com>6.19.x
parent
7b1309b6b0
commit
1e4a702724
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2017 Red Hat, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.ide.api.workspace;
|
||||
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_WEBSOCKET_REFERENCE;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import org.eclipse.che.api.workspace.shared.Constants;
|
||||
import org.eclipse.che.ide.QueryParameters;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.RuntimeImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.ServerImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
|
||||
/** Helps to quickly get info related to the "wsagent" server. */
|
||||
@Singleton
|
||||
public class WsAgentServerUtil {
|
||||
|
||||
/**
|
||||
* URL's query parameter for passing the prefix of the "wsagent" server reference. Allows to tell
|
||||
* IDE to use a different "wsagent" server.
|
||||
*/
|
||||
public static final String WSAGENT_SERVER_REF_PREFIX_PARAM = "wsagent-ref-prefix";
|
||||
|
||||
private final AppContext appContext;
|
||||
private final QueryParameters queryParameters;
|
||||
|
||||
@Inject
|
||||
public WsAgentServerUtil(AppContext appContext, QueryParameters queryParameters) {
|
||||
this.appContext = appContext;
|
||||
this.queryParameters = queryParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code Optional} with a machine which contains the "wsagent" server.
|
||||
*
|
||||
* @return {@code Optional} with the machine which contains the "wsagent" server if the current
|
||||
* workspace has a runtime and there is such machine, otherwise an empty {@code Optional}
|
||||
*/
|
||||
public Optional<MachineImpl> getWsAgentServerMachine() {
|
||||
return getWorkspaceRuntime()
|
||||
.flatMap(
|
||||
runtime ->
|
||||
runtime
|
||||
.getMachines()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(this::containsWsAgentHttpServer)
|
||||
.findAny());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code Optional} with the {@link Constants#SERVER_WS_AGENT_HTTP_REFERENCE wsagent/http}
|
||||
* server.
|
||||
*
|
||||
* @return {@code Optional} with the {@link Constants#SERVER_WS_AGENT_HTTP_REFERENCE wsagent/http}
|
||||
* server if the current workspace has a runtime and there is a machine with such server,
|
||||
* otherwise an empty {@code Optional}
|
||||
*/
|
||||
public Optional<ServerImpl> getWsAgentHttpServer() {
|
||||
return getServerByRef(getWsAgentHttpServerReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code Optional} with the {@link Constants#SERVER_WS_AGENT_WEBSOCKET_REFERENCE
|
||||
* wsagent/ws} server.
|
||||
*
|
||||
* @return {@code Optional} with the {@link Constants#SERVER_WS_AGENT_WEBSOCKET_REFERENCE
|
||||
* wsagent/ws} server if the current workspace has a runtime and there is a machine with such
|
||||
* server, otherwise an empty {@code Optional}
|
||||
*/
|
||||
public Optional<ServerImpl> getWsAgentWebSocketServer() {
|
||||
return getServerByRef(getWsAgentWebSocketServerReference());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Optional<ServerImpl> getServerByRef(String ref) {
|
||||
Optional<RuntimeImpl> runtimeOpt = getWorkspaceRuntime();
|
||||
|
||||
if (runtimeOpt.isPresent()) {
|
||||
for (MachineImpl machine : runtimeOpt.get().getMachines().values()) {
|
||||
ServerImpl server = machine.getServers().get(ref);
|
||||
|
||||
if (server != null) {
|
||||
return Optional.of(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the provided {@link MachineImpl} contains the {@link
|
||||
* Constants#SERVER_WS_AGENT_HTTP_REFERENCE wsagent/http} server.
|
||||
*
|
||||
* @param machine {@link MachineImpl} to check
|
||||
* @return {@code true} if the given machine contains the {@link
|
||||
* Constants#SERVER_WS_AGENT_HTTP_REFERENCE wsagent/http} server server, otherwise {@code
|
||||
* false}
|
||||
*/
|
||||
public boolean containsWsAgentHttpServer(MachineImpl machine) {
|
||||
return machine.getServers().keySet().contains(getWsAgentHttpServerReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference of the {@link Constants#SERVER_WS_AGENT_HTTP_REFERENCE wsagent/http}
|
||||
* server.
|
||||
*
|
||||
* <p><strong>Note</strong>, the returned server reference may be prepended with the prefix passed
|
||||
* through the URL's query parameter.
|
||||
*
|
||||
* @see #WSAGENT_SERVER_REF_PREFIX_PARAM
|
||||
*/
|
||||
public String getWsAgentHttpServerReference() {
|
||||
String refPrefix = queryParameters.getByName(WSAGENT_SERVER_REF_PREFIX_PARAM);
|
||||
|
||||
return isNullOrEmpty(refPrefix)
|
||||
? SERVER_WS_AGENT_HTTP_REFERENCE
|
||||
: refPrefix + SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference of the {@link Constants#SERVER_WS_AGENT_WEBSOCKET_REFERENCE wsagent/ws}
|
||||
* server.
|
||||
*
|
||||
* <p><strong>Note</strong>, the returned server reference may be prepended with the prefix passed
|
||||
* through the URL's query parameter.
|
||||
*
|
||||
* @see #WSAGENT_SERVER_REF_PREFIX_PARAM
|
||||
*/
|
||||
public String getWsAgentWebSocketServerReference() {
|
||||
String refPrefix = queryParameters.getByName(WSAGENT_SERVER_REF_PREFIX_PARAM);
|
||||
|
||||
return isNullOrEmpty(refPrefix)
|
||||
? SERVER_WS_AGENT_WEBSOCKET_REFERENCE
|
||||
: refPrefix + SERVER_WS_AGENT_WEBSOCKET_REFERENCE;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Optional<RuntimeImpl> getWorkspaceRuntime() {
|
||||
WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
|
||||
return Optional.ofNullable(workspace.getRuntime());
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ package org.eclipse.che.ide.api.workspace.model;
|
|||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -74,18 +73,6 @@ public class RuntimeImpl implements Runtime {
|
|||
return machines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a dev-machine or an empty {@code Optional} if none. Dev-machine is a machine where
|
||||
* ws-agent server is running.
|
||||
*/
|
||||
public Optional<MachineImpl> getDevMachine() {
|
||||
return getMachines()
|
||||
.values()
|
||||
.stream()
|
||||
.filter(m -> m.getServerByName(SERVER_WS_AGENT_HTTP_REFERENCE).isPresent())
|
||||
.findAny();
|
||||
}
|
||||
|
||||
public Optional<MachineImpl> getMachineByName(String name) {
|
||||
return Optional.ofNullable(getMachines().get(name));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ package org.eclipse.che.ide.api.workspace.model;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.che.api.core.model.workspace.Workspace;
|
||||
import org.eclipse.che.api.core.model.workspace.WorkspaceConfig;
|
||||
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
|
||||
|
|
@ -169,16 +168,6 @@ public class WorkspaceImpl implements Workspace {
|
|||
return runtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand for {@link RuntimeImpl#getDevMachine()}. Allows to avoid checking whether runtime is
|
||||
* exists or not. Returns an empty {@code Optional} if workspace doesn't have a runtime.
|
||||
*
|
||||
* @see RuntimeImpl#getDevMachine()
|
||||
*/
|
||||
public Optional<MachineImpl> getDevMachine() {
|
||||
return getRuntime() != null ? getRuntime().getDevMachine() : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2017 Red Hat, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.ide.api.workspace;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_WEBSOCKET_REFERENCE;
|
||||
import static org.eclipse.che.ide.api.workspace.WsAgentServerUtil.WSAGENT_SERVER_REF_PREFIX_PARAM;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.che.ide.QueryParameters;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.RuntimeImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.ServerImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
/** Tests for the {@link WsAgentServerUtil}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WsAgentServerUtilTest {
|
||||
|
||||
static final String REF_PREFIX = "dev-";
|
||||
|
||||
@Mock AppContext appContext;
|
||||
@Mock QueryParameters queryParameters;
|
||||
|
||||
@Mock RuntimeImpl runtime;
|
||||
@Mock WorkspaceImpl workspace;
|
||||
@Mock MachineImpl machine;
|
||||
@Mock ServerImpl serverWsAgentHTTP;
|
||||
@Mock ServerImpl serverWsAgentWebSocket;
|
||||
|
||||
@InjectMocks WsAgentServerUtil util;
|
||||
|
||||
@Test
|
||||
public void shouldReturnWsAgentServerMachine() throws Exception {
|
||||
mockRuntime();
|
||||
|
||||
Optional<MachineImpl> machineOpt = util.getWsAgentServerMachine();
|
||||
|
||||
assertTrue(machineOpt.isPresent());
|
||||
assertEquals(machine, machineOpt.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnServerByRef() throws Exception {
|
||||
mockRuntime();
|
||||
|
||||
Optional<ServerImpl> serverOpt = util.getServerByRef(SERVER_WS_AGENT_HTTP_REFERENCE);
|
||||
|
||||
assertTrue(serverOpt.isPresent());
|
||||
assertEquals(serverWsAgentHTTP, serverOpt.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotReturnServerByWrongRef() throws Exception {
|
||||
mockRuntime();
|
||||
|
||||
Optional<ServerImpl> serverOpt = util.getServerByRef("wrong-ref");
|
||||
|
||||
assertFalse(serverOpt.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnWsAgentHttpServerReferenceWithPrefix() throws Exception {
|
||||
when(queryParameters.getByName(WSAGENT_SERVER_REF_PREFIX_PARAM)).thenReturn(REF_PREFIX);
|
||||
|
||||
String serverRef = util.getWsAgentHttpServerReference();
|
||||
|
||||
verify(queryParameters).getByName(WSAGENT_SERVER_REF_PREFIX_PARAM);
|
||||
assertEquals(REF_PREFIX + SERVER_WS_AGENT_HTTP_REFERENCE, serverRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnWsAgentHttpServerReferenceWithoutPrefix() throws Exception {
|
||||
when(queryParameters.getByName(WSAGENT_SERVER_REF_PREFIX_PARAM)).thenReturn("");
|
||||
|
||||
String serverRef = util.getWsAgentHttpServerReference();
|
||||
|
||||
verify(queryParameters).getByName(WSAGENT_SERVER_REF_PREFIX_PARAM);
|
||||
assertEquals(SERVER_WS_AGENT_HTTP_REFERENCE, serverRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnWsAgentWebSocketServerReferenceWithPrefix() throws Exception {
|
||||
when(queryParameters.getByName(WSAGENT_SERVER_REF_PREFIX_PARAM)).thenReturn(REF_PREFIX);
|
||||
|
||||
String serverRef = util.getWsAgentWebSocketServerReference();
|
||||
|
||||
verify(queryParameters).getByName(WSAGENT_SERVER_REF_PREFIX_PARAM);
|
||||
assertEquals(REF_PREFIX + SERVER_WS_AGENT_WEBSOCKET_REFERENCE, serverRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnWsAgentWebSocketServerReferenceWithoutPrefix() throws Exception {
|
||||
when(queryParameters.getByName(WSAGENT_SERVER_REF_PREFIX_PARAM)).thenReturn("");
|
||||
|
||||
String serverRef = util.getWsAgentWebSocketServerReference();
|
||||
|
||||
verify(queryParameters).getByName(WSAGENT_SERVER_REF_PREFIX_PARAM);
|
||||
assertEquals(SERVER_WS_AGENT_WEBSOCKET_REFERENCE, serverRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnWorkspaceRuntime() throws Exception {
|
||||
mockRuntime();
|
||||
|
||||
Optional<RuntimeImpl> runtimeOpt = util.getWorkspaceRuntime();
|
||||
|
||||
assertTrue(runtimeOpt.isPresent());
|
||||
assertEquals(runtime, runtimeOpt.get());
|
||||
}
|
||||
|
||||
private void mockRuntime() {
|
||||
Map<String, ServerImpl> servers = new HashMap<>();
|
||||
servers.put(SERVER_WS_AGENT_HTTP_REFERENCE, serverWsAgentHTTP);
|
||||
servers.put(SERVER_WS_AGENT_WEBSOCKET_REFERENCE, serverWsAgentWebSocket);
|
||||
|
||||
when(appContext.getWorkspace()).thenReturn(workspace);
|
||||
when(workspace.getRuntime()).thenReturn(runtime);
|
||||
when(runtime.getMachines()).thenReturn(singletonMap("dev-machine", machine));
|
||||
when(machine.getServers()).thenReturn(servers);
|
||||
}
|
||||
}
|
||||
|
|
@ -14,10 +14,9 @@ import com.google.inject.Inject;
|
|||
import org.eclipse.che.ide.CoreLocalizationConstant;
|
||||
import org.eclipse.che.ide.api.action.ActionEvent;
|
||||
import org.eclipse.che.ide.api.action.BaseAction;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.command.CommandExecutor;
|
||||
import org.eclipse.che.ide.api.command.CommandManager;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.util.loging.Log;
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +30,7 @@ public class RunCommandAction extends BaseAction {
|
|||
|
||||
private final CommandManager commandManager;
|
||||
private final CommandExecutor commandExecutor;
|
||||
private final AppContext appContext;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
private final CoreLocalizationConstant localizationConstant;
|
||||
|
||||
@Inject
|
||||
|
|
@ -39,11 +38,11 @@ public class RunCommandAction extends BaseAction {
|
|||
CommandManager commandManager,
|
||||
CoreLocalizationConstant localizationConstant,
|
||||
CommandExecutor commandExecutor,
|
||||
AppContext appContext) {
|
||||
WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.commandManager = commandManager;
|
||||
this.localizationConstant = localizationConstant;
|
||||
this.commandExecutor = commandExecutor;
|
||||
this.appContext = appContext;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -59,9 +58,8 @@ public class RunCommandAction extends BaseAction {
|
|||
return;
|
||||
}
|
||||
|
||||
final WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
workspace
|
||||
.getDevMachine()
|
||||
wsAgentServerUtil
|
||||
.getWsAgentServerMachine()
|
||||
.ifPresent(
|
||||
m ->
|
||||
commandManager
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ import org.eclipse.che.api.promises.client.Operation;
|
|||
import org.eclipse.che.api.promises.client.OperationException;
|
||||
import org.eclipse.che.api.promises.client.Promise;
|
||||
import org.eclipse.che.api.promises.client.PromiseError;
|
||||
import org.eclipse.che.ide.QueryParameters;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.factory.FactoryServiceClient;
|
||||
import org.eclipse.che.ide.api.theme.ThemeAgent;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.eclipse.che.ide.context.AppContextImpl;
|
||||
import org.eclipse.che.ide.context.BrowserAddress;
|
||||
import org.eclipse.che.ide.context.QueryParameters;
|
||||
import org.eclipse.che.ide.core.StandardComponentInitializer;
|
||||
import org.eclipse.che.ide.preferences.StyleInjector;
|
||||
import org.eclipse.che.ide.statepersistance.AppStateManager;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ package org.eclipse.che.ide.bootstrap;
|
|||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import org.eclipse.che.ide.context.QueryParameters;
|
||||
import org.eclipse.che.ide.QueryParameters;
|
||||
|
||||
/**
|
||||
* Provides {@link IdeInitializationStrategy} depending on the loading mode (default or factory).
|
||||
|
|
|
|||
|
|
@ -14,22 +14,20 @@ import java.util.Map.Entry;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.che.api.core.model.workspace.runtime.Server;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
|
||||
/** Represents an item for displaying in the 'Previews' list. */
|
||||
class PreviewUrl {
|
||||
|
||||
private final AppContext appContext;
|
||||
|
||||
private final String url;
|
||||
private final String displayName;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
PreviewUrl(String url, AppContext appContext) {
|
||||
PreviewUrl(String url, WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.url = url;
|
||||
this.appContext = appContext;
|
||||
this.displayName = getDisplayNameForPreviewUrl(url);
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
}
|
||||
|
||||
/** Returns actual preview URL. */
|
||||
|
|
@ -46,8 +44,7 @@ class PreviewUrl {
|
|||
}
|
||||
|
||||
private String getDisplayNameForPreviewUrl(String previewUrl) {
|
||||
final WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
final Optional<MachineImpl> devMachine = workspace.getDevMachine();
|
||||
final Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
if (!devMachine.isPresent()) {
|
||||
return previewUrl;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import com.google.inject.Singleton;
|
|||
import elemental.dom.Element;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.command.toolbar.ToolbarMessages;
|
||||
import org.eclipse.che.ide.ui.Tooltip;
|
||||
import org.eclipse.che.ide.ui.dropdown.BaseListItem;
|
||||
|
|
@ -38,14 +38,14 @@ public class PreviewsViewImpl implements PreviewsView {
|
|||
private final NoPreviewsItem noPreviewsItem;
|
||||
private final NoPreviewsItemRenderer noPreviewsItemRenderer;
|
||||
private final ToolbarMessages messages;
|
||||
private final AppContext appContext;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
private ActionDelegate delegate;
|
||||
|
||||
@Inject
|
||||
public PreviewsViewImpl(ToolbarMessages messages, AppContext appContext) {
|
||||
public PreviewsViewImpl(ToolbarMessages messages, WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.messages = messages;
|
||||
this.appContext = appContext;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
|
||||
listItems = new HashMap<>();
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ public class PreviewsViewImpl implements PreviewsView {
|
|||
return;
|
||||
}
|
||||
|
||||
final PreviewUrl displayablePreviewUrl = new PreviewUrl(previewUrl, appContext);
|
||||
final PreviewUrl displayablePreviewUrl = new PreviewUrl(previewUrl, wsAgentServerUtil);
|
||||
final BaseListItem<PreviewUrl> listItem = new BaseListItem<>(displayablePreviewUrl);
|
||||
final PreviewUrlItemRenderer renderer = new PreviewUrlItemRenderer(listItem);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ package org.eclipse.che.ide.context;
|
|||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static java.util.Collections.addAll;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.ide.api.resources.ResourceDelta.ADDED;
|
||||
import static org.eclipse.che.ide.api.resources.ResourceDelta.MOVED_FROM;
|
||||
import static org.eclipse.che.ide.api.resources.ResourceDelta.MOVED_TO;
|
||||
|
|
@ -52,10 +51,9 @@ import org.eclipse.che.ide.api.selection.Selection;
|
|||
import org.eclipse.che.ide.api.selection.SelectionChangedEvent;
|
||||
import org.eclipse.che.ide.api.selection.SelectionChangedHandler;
|
||||
import org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppingEvent;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.RuntimeImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.ServerImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.eclipse.che.ide.project.node.SyntheticNode;
|
||||
|
|
@ -82,6 +80,7 @@ public class AppContextImpl implements AppContext, SelectionChangedHandler, Reso
|
|||
private final ResourceManager.ResourceManagerFactory resourceManagerFactory;
|
||||
private final Provider<EditorAgent> editorAgentProvider;
|
||||
private final Provider<AppStateManager> appStateManager;
|
||||
private final Provider<WsAgentServerUtil> wsAgentServerUtilProvider;
|
||||
|
||||
private final List<Project> rootProjects = newArrayList();
|
||||
private final List<Resource> selectedResources = newArrayList();
|
||||
|
|
@ -107,11 +106,13 @@ public class AppContextImpl implements AppContext, SelectionChangedHandler, Reso
|
|||
EventBus eventBus,
|
||||
ResourceManager.ResourceManagerFactory resourceManagerFactory,
|
||||
Provider<EditorAgent> editorAgentProvider,
|
||||
Provider<AppStateManager> appStateManager) {
|
||||
Provider<AppStateManager> appStateManager,
|
||||
Provider<WsAgentServerUtil> wsAgentServerUtilProvider) {
|
||||
this.eventBus = eventBus;
|
||||
this.resourceManagerFactory = resourceManagerFactory;
|
||||
this.editorAgentProvider = editorAgentProvider;
|
||||
this.appStateManager = appStateManager;
|
||||
this.wsAgentServerUtilProvider = wsAgentServerUtilProvider;
|
||||
this.startAppActions = new ArrayList<>();
|
||||
|
||||
projectsInImport = new ArrayList<>();
|
||||
|
|
@ -423,19 +424,13 @@ public class AppContextImpl implements AppContext, SelectionChangedHandler, Reso
|
|||
|
||||
@Override
|
||||
public String getWsAgentServerApiEndpoint() {
|
||||
RuntimeImpl runtime = getWorkspace().getRuntime();
|
||||
Optional<MachineImpl> devMachine = runtime.getDevMachine();
|
||||
Optional<ServerImpl> server = wsAgentServerUtilProvider.get().getWsAgentHttpServer();
|
||||
|
||||
if (devMachine.isPresent()) {
|
||||
Optional<ServerImpl> wsAgentServer =
|
||||
devMachine.get().getServerByName(SERVER_WS_AGENT_HTTP_REFERENCE);
|
||||
|
||||
if (wsAgentServer.isPresent()) {
|
||||
return wsAgentServer.get().getUrl();
|
||||
}
|
||||
if (server.isPresent()) {
|
||||
return server.get().getUrl();
|
||||
}
|
||||
|
||||
throw new RuntimeException("ws-agent server doesn't exist");
|
||||
throw new RuntimeException("wsagent server doesn't exist");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -14,16 +14,17 @@ import static java.util.Collections.emptySet;
|
|||
import static java.util.Collections.singleton;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_WEBSOCKET_REFERENCE;
|
||||
import static org.eclipse.che.ide.api.jsonrpc.Constants.WS_AGENT_JSON_RPC_ENDPOINT_ID;
|
||||
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.inject.Singleton;
|
||||
import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.event.WsAgentServerRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.WsAgentServerStoppedEvent;
|
||||
import org.eclipse.che.ide.api.workspace.model.RuntimeImpl;
|
||||
|
|
@ -40,6 +41,7 @@ public class WsAgentJsonRpcInitializer {
|
|||
private final JsonRpcInitializer initializer;
|
||||
private final RequestTransmitter requestTransmitter;
|
||||
private final AgentURLModifier agentURLModifier;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
@Inject
|
||||
public WsAgentJsonRpcInitializer(
|
||||
|
|
@ -47,11 +49,13 @@ public class WsAgentJsonRpcInitializer {
|
|||
AppContext appContext,
|
||||
EventBus eventBus,
|
||||
RequestTransmitter requestTransmitter,
|
||||
AgentURLModifier agentURLModifier) {
|
||||
AgentURLModifier agentURLModifier,
|
||||
WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.appContext = appContext;
|
||||
this.initializer = initializer;
|
||||
this.requestTransmitter = requestTransmitter;
|
||||
this.agentURLModifier = agentURLModifier;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
|
||||
eventBus.addHandler(WsAgentServerRunningEvent.TYPE, event -> initializeJsonRpcService());
|
||||
eventBus.addHandler(
|
||||
|
|
@ -93,31 +97,22 @@ public class WsAgentJsonRpcInitializer {
|
|||
return; // workspace is stopped
|
||||
}
|
||||
|
||||
runtime
|
||||
.getDevMachine()
|
||||
wsAgentServerUtil
|
||||
.getWsAgentWebSocketServer()
|
||||
.ifPresent(
|
||||
devMachine -> {
|
||||
devMachine
|
||||
.getServerByName(SERVER_WS_AGENT_WEBSOCKET_REFERENCE)
|
||||
.ifPresent(
|
||||
server -> {
|
||||
String wsAgentWebSocketUrl = agentURLModifier.modify(server.getUrl());
|
||||
String separator = wsAgentWebSocketUrl.contains("?") ? "&" : "?";
|
||||
String queryParams =
|
||||
appContext
|
||||
.getApplicationWebsocketId()
|
||||
.map(id -> separator + "clientId=" + id)
|
||||
.orElse("");
|
||||
Set<Runnable> initActions =
|
||||
appContext.getApplicationWebsocketId().isPresent()
|
||||
? emptySet()
|
||||
: singleton(this::processWsId);
|
||||
server -> {
|
||||
String wsAgentWebSocketUrl = agentURLModifier.modify(server.getUrl());
|
||||
String separator = wsAgentWebSocketUrl.contains("?") ? "&" : "?";
|
||||
Optional<String> applicationWebSocketId = appContext.getApplicationWebsocketId();
|
||||
String queryParams =
|
||||
applicationWebSocketId.map(id -> separator + "clientId=" + id).orElse("");
|
||||
Set<Runnable> initActions =
|
||||
applicationWebSocketId.isPresent() ? emptySet() : singleton(this::processWsId);
|
||||
|
||||
initializer.initialize(
|
||||
WS_AGENT_JSON_RPC_ENDPOINT_ID,
|
||||
singletonMap("url", wsAgentWebSocketUrl + queryParams),
|
||||
initActions);
|
||||
});
|
||||
initializer.initialize(
|
||||
WS_AGENT_JSON_RPC_ENDPOINT_ID,
|
||||
singletonMap("url", wsAgentWebSocketUrl + queryParams),
|
||||
initActions);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import static org.eclipse.che.api.workspace.shared.Constants.MACHINE_STATUS_CHAN
|
|||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_EXEC_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_STATUS_CHANGED_METHOD;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_TERMINAL_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_STATUS_CHANGED_METHOD;
|
||||
import static org.eclipse.che.ide.api.jsonrpc.Constants.WS_MASTER_JSON_RPC_ENDPOINT_ID;
|
||||
|
||||
|
|
@ -35,6 +34,7 @@ import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter;
|
|||
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.jsonrpc.SubscriptionManagerClient;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.event.ExecAgentServerRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.ServerRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.TerminalAgentServerRunningEvent;
|
||||
|
|
@ -61,6 +61,7 @@ public class WsMasterJsonRpcInitializer {
|
|||
private final SubscriptionManagerClient subscriptionManagerClient;
|
||||
private final WorkspaceServiceClient workspaceServiceClient;
|
||||
private final SecurityTokenProvider securityTokenProvider;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
@Inject
|
||||
public WsMasterJsonRpcInitializer(
|
||||
|
|
@ -70,7 +71,8 @@ public class WsMasterJsonRpcInitializer {
|
|||
EventBus eventBus,
|
||||
SubscriptionManagerClient subscriptionManagerClient,
|
||||
WorkspaceServiceClient workspaceServiceClient,
|
||||
SecurityTokenProvider securityTokenProvider) {
|
||||
SecurityTokenProvider securityTokenProvider,
|
||||
WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.initializer = initializer;
|
||||
this.requestTransmitter = requestTransmitter;
|
||||
this.appContext = appContext;
|
||||
|
|
@ -78,6 +80,7 @@ public class WsMasterJsonRpcInitializer {
|
|||
this.subscriptionManagerClient = subscriptionManagerClient;
|
||||
this.workspaceServiceClient = workspaceServiceClient;
|
||||
this.securityTokenProvider = securityTokenProvider;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
|
||||
eventBus.addHandler(BasicIDEInitializedEvent.TYPE, e -> initialize());
|
||||
eventBus.addHandler(WorkspaceStartingEvent.TYPE, e -> initialize());
|
||||
|
|
@ -211,8 +214,9 @@ public class WsMasterJsonRpcInitializer {
|
|||
if (server.getStatus() == RUNNING) {
|
||||
eventBus.fireEvent(new ServerRunningEvent(server.getName(), machine.getName()));
|
||||
|
||||
String wsAgentHttpServerRef = wsAgentServerUtil.getWsAgentHttpServerReference();
|
||||
// fire events for the often used servers
|
||||
if (SERVER_WS_AGENT_HTTP_REFERENCE.equals(server.getName())) {
|
||||
if (wsAgentHttpServerRef.equals(server.getName())) {
|
||||
eventBus.fireEvent(new WsAgentServerRunningEvent(machine.getName()));
|
||||
} else if (SERVER_TERMINAL_REFERENCE.equals(server.getName())) {
|
||||
eventBus.fireEvent(new TerminalAgentServerRunningEvent(machine.getName()));
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@ import javax.validation.constraints.NotNull;
|
|||
import org.eclipse.che.api.promises.client.Promise;
|
||||
import org.eclipse.che.api.promises.client.js.Promises;
|
||||
import org.eclipse.che.ide.CoreLocalizationConstant;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.macro.Macro;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
|
||||
/**
|
||||
* Provides dev-machine's host name.
|
||||
|
|
@ -32,14 +31,14 @@ public class DevMachineHostNameMacro implements Macro {
|
|||
|
||||
private static final String KEY = "${machine.dev.hostname}";
|
||||
|
||||
private final AppContext appContext;
|
||||
private final CoreLocalizationConstant localizationConstants;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
@Inject
|
||||
public DevMachineHostNameMacro(
|
||||
AppContext appContext, CoreLocalizationConstant localizationConstants) {
|
||||
this.appContext = appContext;
|
||||
CoreLocalizationConstant localizationConstants, WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.localizationConstants = localizationConstants;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
@ -58,8 +57,7 @@ public class DevMachineHostNameMacro implements Macro {
|
|||
public Promise<String> expand() {
|
||||
String value = "";
|
||||
|
||||
WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
Optional<MachineImpl> devMachine = workspace.getDevMachine();
|
||||
Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
if (devMachine.isPresent()) {
|
||||
String hostName = devMachine.get().getProperties().get("config.hostname");
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ import org.eclipse.che.ide.api.app.AppContext;
|
|||
import org.eclipse.che.ide.api.macro.BaseMacro;
|
||||
import org.eclipse.che.ide.api.macro.Macro;
|
||||
import org.eclipse.che.ide.api.macro.MacroRegistry;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.event.WorkspaceRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.eclipse.che.ide.bootstrap.BasicIDEInitializedEvent;
|
||||
|
||||
/**
|
||||
|
|
@ -46,14 +46,19 @@ public class ServerAddressMacroRegistrar {
|
|||
|
||||
private final Provider<MacroRegistry> macroRegistryProvider;
|
||||
private final AppContext appContext;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
private Set<Macro> macros;
|
||||
|
||||
@Inject
|
||||
public ServerAddressMacroRegistrar(
|
||||
EventBus eventBus, Provider<MacroRegistry> macroRegistryProvider, AppContext appContext) {
|
||||
EventBus eventBus,
|
||||
Provider<MacroRegistry> macroRegistryProvider,
|
||||
AppContext appContext,
|
||||
WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.macroRegistryProvider = macroRegistryProvider;
|
||||
this.appContext = appContext;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
|
||||
eventBus.addHandler(
|
||||
BasicIDEInitializedEvent.TYPE,
|
||||
|
|
@ -74,8 +79,7 @@ public class ServerAddressMacroRegistrar {
|
|||
}
|
||||
|
||||
private void registerMacros() {
|
||||
final WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
final Optional<MachineImpl> devMachine = workspace.getDevMachine();
|
||||
final Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
if (devMachine.isPresent()) {
|
||||
macros = getMacros(devMachine.get());
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import static java.util.Collections.emptyList;
|
|||
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_SSH_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_TERMINAL_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE;
|
||||
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
|
||||
import static org.eclipse.che.ide.processes.ProcessTreeNode.ProcessNodeType.COMMAND_NODE;
|
||||
|
|
@ -72,6 +71,7 @@ import org.eclipse.che.ide.api.parts.WorkspaceAgent;
|
|||
import org.eclipse.che.ide.api.parts.base.BasePresenter;
|
||||
import org.eclipse.che.ide.api.selection.Selection;
|
||||
import org.eclipse.che.ide.api.ssh.SshServiceClient;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.event.ExecAgentServerRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.MachineRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.MachineStartingEvent;
|
||||
|
|
@ -154,6 +154,7 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
private final RuntimeInfoWidgetFactory runtimeInfoWidgetFactory;
|
||||
private final RuntimeInfoProvider runtimeInfoProvider;
|
||||
private final RuntimeInfoLocalization runtimeInfoLocalization;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
private final EventBus eventBus;
|
||||
private final Map<String, ProcessTreeNode> machineNodes;
|
||||
ProcessTreeNode rootNode;
|
||||
|
|
@ -182,7 +183,8 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
RuntimeInfoWidgetFactory runtimeInfoWidgetFactory,
|
||||
RuntimeInfoProvider runtimeInfoProvider,
|
||||
RuntimeInfoLocalization runtimeInfoLocalization,
|
||||
Provider<WorkspaceLoadingTracker> workspaceLoadingTrackerProvider) {
|
||||
Provider<WorkspaceLoadingTracker> workspaceLoadingTrackerProvider,
|
||||
WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.view = view;
|
||||
this.localizationConstant = localizationConstant;
|
||||
this.resources = resources;
|
||||
|
|
@ -203,6 +205,7 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
this.runtimeInfoWidgetFactory = runtimeInfoWidgetFactory;
|
||||
this.runtimeInfoProvider = runtimeInfoProvider;
|
||||
this.runtimeInfoLocalization = runtimeInfoLocalization;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
|
||||
machineNodes = new HashMap<>();
|
||||
machines = new HashMap<>();
|
||||
|
|
@ -244,13 +247,13 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
return;
|
||||
}
|
||||
|
||||
for (MachineImpl machine : machines) {
|
||||
if (machine.getServerByName(SERVER_WS_AGENT_HTTP_REFERENCE).isPresent()) {
|
||||
provideMachineNode(machine.getName(), true);
|
||||
machines.remove(machine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Optional<MachineImpl> wsAgentServerMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
wsAgentServerMachine.ifPresent(
|
||||
machine -> {
|
||||
provideMachineNode(machine.getName(), true);
|
||||
machines.remove(machine);
|
||||
});
|
||||
|
||||
for (MachineImpl machine : machines) {
|
||||
provideMachineNode(machine.getName(), true);
|
||||
|
|
@ -333,8 +336,7 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
public void newTerminal(TerminalOptionsJso options) {
|
||||
final ProcessTreeNode selectedTreeNode = view.getSelectedTreeNode();
|
||||
|
||||
final WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
final Optional<MachineImpl> devMachine = workspace.getDevMachine();
|
||||
final Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
if (selectedTreeNode == null && devMachine.isPresent()) {
|
||||
onAddTerminal(devMachine.get().getName(), options);
|
||||
|
|
@ -363,7 +365,7 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
|
||||
/** Selects dev machine. */
|
||||
private void selectDevMachine() {
|
||||
Optional<MachineImpl> devMachine = appContext.getWorkspace().getDevMachine();
|
||||
Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
if (!devMachine.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -598,9 +600,7 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
}
|
||||
|
||||
public void addCommandOutput(OutputConsole outputConsole) {
|
||||
final WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
final Optional<MachineImpl> devMachine = workspace.getDevMachine();
|
||||
|
||||
Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
devMachine.ifPresent(machine -> addCommandOutput(machine.getName(), outputConsole));
|
||||
}
|
||||
|
||||
|
|
@ -859,12 +859,12 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
return false;
|
||||
}
|
||||
|
||||
Server terminalServer = machine.getServers().get(serverName);
|
||||
if (terminalServer == null) {
|
||||
Server server = machine.getServers().get(serverName);
|
||||
if (server == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return terminalServer.getStatus() == ServerStatus.RUNNING;
|
||||
return server.getStatus() == ServerStatus.RUNNING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -901,22 +901,23 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
return null;
|
||||
}
|
||||
|
||||
final ProcessTreeNode newMachineNode =
|
||||
ProcessTreeNode machineNode =
|
||||
new ProcessTreeNode(MACHINE_NODE, rootNode, machineName, null, children);
|
||||
newMachineNode.setTerminalServerRunning(
|
||||
isServerRunning(machineName, SERVER_TERMINAL_REFERENCE));
|
||||
// TODO (spi ide): for now SSH server's status is always UNKNOWN.
|
||||
// So check ws-agent's status till SSH server's status fixed.
|
||||
newMachineNode.setSshServerRunning(
|
||||
isServerRunning(machineName, SERVER_WS_AGENT_HTTP_REFERENCE));
|
||||
|
||||
machineNode.setTerminalServerRunning(isServerRunning(machineName, SERVER_TERMINAL_REFERENCE));
|
||||
|
||||
// rely on "wsagent" server's status since "ssh" server's status is always UNKNOWN
|
||||
String wsAgentServerRef = wsAgentServerUtil.getWsAgentHttpServerReference();
|
||||
machineNode.setSshServerRunning(isServerRunning(machineName, wsAgentServerRef));
|
||||
|
||||
for (ProcessTreeNode child : children) {
|
||||
child.setParent(newMachineNode);
|
||||
child.setParent(machineNode);
|
||||
}
|
||||
|
||||
machineNodes.put(machineName, newMachineNode);
|
||||
machineNodes.put(machineName, machineNode);
|
||||
|
||||
// add to children
|
||||
rootNode.getChildren().add(newMachineNode);
|
||||
rootNode.getChildren().add(machineNode);
|
||||
|
||||
// update the view
|
||||
view.setProcessesData(rootNode);
|
||||
|
|
@ -924,10 +925,10 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
// add output for the machine if it is not exist
|
||||
if (!consoles.containsKey(machineName)) {
|
||||
OutputConsole outputConsole = commandConsoleFactory.create(machineName);
|
||||
addOutputConsole(machineName, newMachineNode, outputConsole, true);
|
||||
addOutputConsole(machineName, machineNode, outputConsole, true);
|
||||
}
|
||||
|
||||
return newMachineNode;
|
||||
return machineNode;
|
||||
}
|
||||
|
||||
private List<MachineImpl> getMachines() {
|
||||
|
|
@ -963,18 +964,13 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
return;
|
||||
}
|
||||
|
||||
MachineImpl devMachine = null;
|
||||
for (MachineImpl machine : wsMachines) {
|
||||
if (machine.getServerByName(SERVER_WS_AGENT_HTTP_REFERENCE).isPresent()) {
|
||||
devMachine = machine;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Optional<MachineImpl> wsAgentServerMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
ProcessTreeNode machineToSelect = null;
|
||||
if (devMachine != null) {
|
||||
machineToSelect = provideMachineNode(devMachine.getName(), true);
|
||||
wsMachines.remove(devMachine);
|
||||
if (wsAgentServerMachine.isPresent()) {
|
||||
MachineImpl machine = wsAgentServerMachine.get();
|
||||
machineToSelect = provideMachineNode(machine.getName(), true);
|
||||
wsMachines.remove(machine);
|
||||
}
|
||||
|
||||
for (MachineImpl machine : wsMachines) {
|
||||
|
|
@ -1051,7 +1047,7 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
@Override
|
||||
public void onTerminalAgentServerRunning(TerminalAgentServerRunningEvent event) {
|
||||
// open terminal automatically for dev-machine only
|
||||
Optional<MachineImpl> devMachine = appContext.getWorkspace().getDevMachine();
|
||||
Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
if (devMachine.isPresent() && event.getMachineName().equals(devMachine.get().getName())) {
|
||||
provideMachineNode(event.getMachineName(), true);
|
||||
|
|
@ -1349,13 +1345,13 @@ public class ProcessesPanelPresenter extends BasePresenter
|
|||
|
||||
@Override
|
||||
public void onDownloadWorkspaceOutput(DownloadWorkspaceOutputEvent event) {
|
||||
WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
Optional<MachineImpl> devMachine = workspace.getDevMachine();
|
||||
Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
if (!devMachine.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
String fileName =
|
||||
workspace.getNamespace()
|
||||
+ "-"
|
||||
|
|
|
|||
|
|
@ -13,17 +13,15 @@ package org.eclipse.che.ide.projectimport;
|
|||
import static org.eclipse.che.api.core.model.workspace.runtime.ServerStatus.RUNNING;
|
||||
import static org.eclipse.che.api.project.shared.Constants.EVENT_IMPORT_OUTPUT_SUBSCRIBE;
|
||||
import static org.eclipse.che.api.project.shared.Constants.EVENT_IMPORT_OUTPUT_UN_SUBSCRIBE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.ide.api.jsonrpc.Constants.WS_AGENT_JSON_RPC_ENDPOINT_ID;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.event.WsAgentServerRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.WsAgentServerStoppedEvent;
|
||||
import org.eclipse.che.ide.api.workspace.model.ServerImpl;
|
||||
import org.eclipse.che.ide.bootstrap.BasicIDEInitializedEvent;
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +36,7 @@ public class ProjectImportNotificationSubscriber {
|
|||
|
||||
@Inject
|
||||
public ProjectImportNotificationSubscriber(
|
||||
EventBus eventBus, AppContext appContext, RequestTransmitter transmitter) {
|
||||
EventBus eventBus, RequestTransmitter transmitter, WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.transmitter = transmitter;
|
||||
|
||||
eventBus.addHandler(WsAgentServerRunningEvent.TYPE, event -> subscribe());
|
||||
|
|
@ -47,13 +45,14 @@ public class ProjectImportNotificationSubscriber {
|
|||
eventBus.addHandler(
|
||||
BasicIDEInitializedEvent.TYPE,
|
||||
event ->
|
||||
appContext
|
||||
.getWorkspace()
|
||||
.getDevMachine()
|
||||
.flatMap(machine -> machine.getServerByName(SERVER_WS_AGENT_HTTP_REFERENCE))
|
||||
.map(ServerImpl::getStatus)
|
||||
.filter(RUNNING::equals)
|
||||
.ifPresent(it -> subscribe()));
|
||||
wsAgentServerUtil
|
||||
.getWsAgentHttpServer()
|
||||
.ifPresent(
|
||||
server -> {
|
||||
if (server.getStatus() == RUNNING) {
|
||||
subscribe();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void subscribe() {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import static org.eclipse.che.api.core.model.workspace.runtime.ServerStatus.STOP
|
|||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_EXEC_AGENT_HTTP_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_STATUS_CHANGED_METHOD;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_TERMINAL_REFERENCE;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.SERVER_WS_AGENT_HTTP_REFERENCE;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
|
@ -23,6 +22,7 @@ import com.google.web.bindery.event.shared.EventBus;
|
|||
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
|
||||
import org.eclipse.che.api.workspace.shared.dto.event.ServerStatusEvent;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.event.ExecAgentServerRunningEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.ExecAgentServerStoppedEvent;
|
||||
import org.eclipse.che.ide.api.workspace.event.ServerRunningEvent;
|
||||
|
|
@ -45,16 +45,19 @@ class ServerStatusEventHandler {
|
|||
private final WorkspaceServiceClient workspaceServiceClient;
|
||||
private final AppContext appContext;
|
||||
private final EventBus eventBus;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
@Inject
|
||||
ServerStatusEventHandler(
|
||||
RequestHandlerConfigurator configurator,
|
||||
WorkspaceServiceClient workspaceServiceClient,
|
||||
AppContext appContext,
|
||||
EventBus eventBus) {
|
||||
EventBus eventBus,
|
||||
WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.workspaceServiceClient = workspaceServiceClient;
|
||||
this.appContext = appContext;
|
||||
this.eventBus = eventBus;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
|
||||
configurator
|
||||
.newConfiguration()
|
||||
|
|
@ -78,12 +81,14 @@ class ServerStatusEventHandler {
|
|||
// Because AppContext always must return an actual workspace model.
|
||||
((AppContextImpl) appContext).setWorkspace(workspace);
|
||||
|
||||
String wsAgentHttpServerRef = wsAgentServerUtil.getWsAgentHttpServerReference();
|
||||
|
||||
if (event.getStatus() == RUNNING) {
|
||||
eventBus.fireEvent(
|
||||
new ServerRunningEvent(event.getServerName(), event.getMachineName()));
|
||||
|
||||
// fire events for the often used servers
|
||||
if (SERVER_WS_AGENT_HTTP_REFERENCE.equals(event.getServerName())) {
|
||||
if (wsAgentHttpServerRef.equals(event.getServerName())) {
|
||||
eventBus.fireEvent(new WsAgentServerRunningEvent(event.getMachineName()));
|
||||
} else if (SERVER_TERMINAL_REFERENCE.equals(event.getServerName())) {
|
||||
eventBus.fireEvent(new TerminalAgentServerRunningEvent(event.getMachineName()));
|
||||
|
|
@ -95,7 +100,7 @@ class ServerStatusEventHandler {
|
|||
new ServerStoppedEvent(event.getServerName(), event.getMachineName()));
|
||||
|
||||
// fire events for the often used servers
|
||||
if (SERVER_WS_AGENT_HTTP_REFERENCE.equals(event.getServerName())) {
|
||||
if (wsAgentHttpServerRef.equals(event.getServerName())) {
|
||||
eventBus.fireEvent(new WsAgentServerStoppedEvent(event.getMachineName()));
|
||||
} else if (SERVER_TERMINAL_REFERENCE.equals(event.getServerName())) {
|
||||
eventBus.fireEvent(new TerminalAgentServerStoppedEvent(event.getMachineName()));
|
||||
|
|
|
|||
|
|
@ -22,12 +22,11 @@ import java.util.Collections;
|
|||
import java.util.Optional;
|
||||
import org.eclipse.che.ide.CoreLocalizationConstant;
|
||||
import org.eclipse.che.ide.api.action.ActionEvent;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.command.CommandExecutor;
|
||||
import org.eclipse.che.ide.api.command.CommandImpl;
|
||||
import org.eclipse.che.ide.api.command.CommandManager;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -47,7 +46,7 @@ public class RunCommandActionTest {
|
|||
@Mock private CoreLocalizationConstant locale;
|
||||
@Mock private ActionEvent event;
|
||||
@Mock private CommandImpl command;
|
||||
@Mock private AppContext appContext;
|
||||
@Mock private WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
@InjectMocks private RunCommandAction action;
|
||||
|
||||
|
|
@ -68,10 +67,8 @@ public class RunCommandActionTest {
|
|||
public void actionShouldBePerformed() {
|
||||
when(event.getParameters()).thenReturn(Collections.singletonMap(NAME_PROPERTY, "MCI"));
|
||||
|
||||
WorkspaceImpl workspace = mock(WorkspaceImpl.class);
|
||||
MachineImpl machine = mock(MachineImpl.class);
|
||||
when(workspace.getDevMachine()).thenReturn(Optional.of(machine));
|
||||
when(appContext.getWorkspace()).thenReturn(workspace);
|
||||
when(wsAgentServerUtil.getWsAgentServerMachine()).thenReturn(Optional.of(machine));
|
||||
|
||||
action.actionPerformed(event);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@ import static org.mockito.Mockito.when;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.ServerImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -35,7 +34,7 @@ public class PreviewUrlTest {
|
|||
private static final String MACHINE_NAME = "dev-machine";
|
||||
private static final String SERVER_PORT = "8080";
|
||||
|
||||
@Mock private AppContext appContext;
|
||||
@Mock private WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
private PreviewUrl previewUrl;
|
||||
|
||||
|
|
@ -51,11 +50,9 @@ public class PreviewUrlTest {
|
|||
when(devMachine.getName()).thenReturn(MACHINE_NAME);
|
||||
when(devMachine.getServers()).thenReturn(servers);
|
||||
|
||||
WorkspaceImpl workspace = mock(WorkspaceImpl.class);
|
||||
when(workspace.getDevMachine()).thenReturn(Optional.of(devMachine));
|
||||
when(appContext.getWorkspace()).thenReturn(workspace);
|
||||
when(wsAgentServerUtil.getWsAgentServerMachine()).thenReturn(Optional.of(devMachine));
|
||||
|
||||
previewUrl = new PreviewUrl(PREVIEW_URL, appContext);
|
||||
previewUrl = new PreviewUrl(PREVIEW_URL, wsAgentServerUtil);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.ide.context;
|
||||
package org.eclipse.che.ide;
|
||||
|
||||
import com.google.gwt.user.client.Window;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -14,10 +14,10 @@ import com.google.gwt.core.client.JavaScriptObject;
|
|||
import com.google.gwt.http.client.RequestBuilder;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import java.util.List;
|
||||
import org.eclipse.che.ide.MimeType;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.dto.DtoFactory;
|
||||
import org.eclipse.che.ide.rest.AsyncRequest;
|
||||
import org.eclipse.che.ide.rest.HTTPHeader;
|
||||
|
|
@ -35,8 +35,8 @@ public class KeycloakAsyncRequestFactory extends MachineAsyncRequestFactory {
|
|||
KeycloakProvider keycloakProvider,
|
||||
DtoFactory dtoFactory,
|
||||
AppContext appContext,
|
||||
EventBus eventBus) {
|
||||
super(dtoFactory, appContext, eventBus);
|
||||
WsAgentServerUtil wsAgentServerUtil) {
|
||||
super(dtoFactory, appContext, wsAgentServerUtil);
|
||||
this.dtoFactory = dtoFactory;
|
||||
this.keycloakProvider = keycloakProvider;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,12 @@ import com.google.gwt.http.client.RequestBuilder;
|
|||
import com.google.gwt.http.client.Response;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.web.bindery.event.shared.EventBus;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.che.api.promises.client.Promise;
|
||||
import org.eclipse.che.api.promises.client.js.Promises;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.RuntimeImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.eclipse.che.ide.commons.exception.UnmarshallerException;
|
||||
import org.eclipse.che.ide.dto.DtoFactory;
|
||||
|
|
@ -42,13 +41,15 @@ public class MachineAsyncRequestFactory extends AsyncRequestFactory {
|
|||
private static final String CSRF_TOKEN_HEADER_NAME = "X-CSRF-Token";
|
||||
|
||||
private AppContext appContext;
|
||||
private WsAgentServerUtil wsAgentServerUtil;
|
||||
private String csrfToken;
|
||||
|
||||
@Inject
|
||||
public MachineAsyncRequestFactory(
|
||||
DtoFactory dtoFactory, AppContext appContext, EventBus eventBus) {
|
||||
DtoFactory dtoFactory, AppContext appContext, WsAgentServerUtil wsAgentServerUtil) {
|
||||
super(dtoFactory);
|
||||
this.appContext = appContext;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -73,22 +74,14 @@ public class MachineAsyncRequestFactory extends AsyncRequestFactory {
|
|||
*/
|
||||
protected boolean isWsAgentRequest(String url) {
|
||||
WorkspaceImpl currentWorkspace = appContext.getWorkspace();
|
||||
if (currentWorkspace == null || !isWsAgentStarted(currentWorkspace)) {
|
||||
if (currentWorkspace == null || !isWsAgentStarted()) {
|
||||
return false; // ws-agent not started
|
||||
}
|
||||
return url.contains(nullToEmpty(appContext.getWsAgentServerApiEndpoint()));
|
||||
}
|
||||
|
||||
private boolean isWsAgentStarted(WorkspaceImpl workspace) {
|
||||
if (workspace == null) {
|
||||
return false;
|
||||
}
|
||||
RuntimeImpl runtime = workspace.getRuntime();
|
||||
if (runtime == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<MachineImpl> devMachine = runtime.getDevMachine();
|
||||
private boolean isWsAgentStarted() {
|
||||
Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine();
|
||||
|
||||
return devMachine.isPresent();
|
||||
}
|
||||
|
|
@ -116,6 +109,12 @@ public class MachineAsyncRequestFactory extends AsyncRequestFactory {
|
|||
});
|
||||
}
|
||||
|
||||
private boolean isModifyingMethod(RequestBuilder.Method method) {
|
||||
return method == RequestBuilder.POST
|
||||
|| method == RequestBuilder.PUT
|
||||
|| method == RequestBuilder.DELETE;
|
||||
}
|
||||
|
||||
private class CsrfPreventingAsyncModifyingRequest extends AsyncRequest {
|
||||
|
||||
protected CsrfPreventingAsyncModifyingRequest(
|
||||
|
|
@ -137,10 +136,4 @@ public class MachineAsyncRequestFactory extends AsyncRequestFactory {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isModifyingMethod(RequestBuilder.Method method) {
|
||||
return method == RequestBuilder.POST
|
||||
|| method == RequestBuilder.PUT
|
||||
|| method == RequestBuilder.DELETE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.eclipse.che.api.core.model.workspace.runtime.Server;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.debug.DebugConfiguration;
|
||||
import org.eclipse.che.ide.api.debug.DebugConfigurationPage;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.eclipse.che.ide.util.Pair;
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +35,7 @@ public class JavaDebugConfigurationPagePresenter
|
|||
DebugConfigurationPage<DebugConfiguration> {
|
||||
|
||||
private final JavaDebugConfigurationPageView view;
|
||||
private final AppContext appContext;
|
||||
private final WsAgentServerUtil wsAgentServerUtil;
|
||||
|
||||
private DebugConfiguration editedConfiguration;
|
||||
private String originHost;
|
||||
|
|
@ -45,9 +44,9 @@ public class JavaDebugConfigurationPagePresenter
|
|||
|
||||
@Inject
|
||||
public JavaDebugConfigurationPagePresenter(
|
||||
JavaDebugConfigurationPageView view, AppContext appContext) {
|
||||
JavaDebugConfigurationPageView view, WsAgentServerUtil wsAgentServerUtil) {
|
||||
this.view = view;
|
||||
this.appContext = appContext;
|
||||
this.wsAgentServerUtil = wsAgentServerUtil;
|
||||
|
||||
view.setDelegate(this);
|
||||
}
|
||||
|
|
@ -74,8 +73,9 @@ public class JavaDebugConfigurationPagePresenter
|
|||
}
|
||||
|
||||
private void setPortsList() {
|
||||
WorkspaceImpl workspace = appContext.getWorkspace();
|
||||
workspace.getDevMachine().ifPresent(machine -> view.setPortsList(extractPortsList(machine)));
|
||||
wsAgentServerUtil
|
||||
.getWsAgentServerMachine()
|
||||
.ifPresent(machine -> view.setPortsList(extractPortsList(machine)));
|
||||
}
|
||||
|
||||
/** Extracts list of ports available for connecting to the remote debugger. */
|
||||
|
|
|
|||
|
|
@ -21,12 +21,11 @@ import com.google.gwt.user.client.ui.AcceptsOneWidget;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.debug.DebugConfiguration;
|
||||
import org.eclipse.che.ide.api.debug.DebugConfigurationPage;
|
||||
import org.eclipse.che.ide.api.workspace.WsAgentServerUtil;
|
||||
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.ServerImpl;
|
||||
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
|
@ -43,9 +42,8 @@ public class JavaDebugConfigurationPagePresenterTest {
|
|||
private static final int PORT = 8000;
|
||||
|
||||
@Mock private JavaDebugConfigurationPageView pageView;
|
||||
@Mock private AppContext appContext;
|
||||
@Mock private WsAgentServerUtil wsAgentServerUtil;
|
||||
@Mock private MachineImpl devMachine;
|
||||
@Mock private WorkspaceImpl workspace;
|
||||
|
||||
@Mock private DebugConfiguration configuration;
|
||||
|
||||
|
|
@ -62,8 +60,7 @@ public class JavaDebugConfigurationPagePresenterTest {
|
|||
servers.put("8000/tcp", server);
|
||||
when(devMachine.getServers()).thenReturn(servers);
|
||||
|
||||
when(workspace.getDevMachine()).thenReturn(Optional.of(devMachine));
|
||||
when(appContext.getWorkspace()).thenReturn(workspace);
|
||||
when(wsAgentServerUtil.getWsAgentServerMachine()).thenReturn(Optional.of(devMachine));
|
||||
when(devMachine.getName()).thenReturn("devMachine");
|
||||
|
||||
pagePresenter.resetFrom(configuration);
|
||||
|
|
|
|||
Loading…
Reference in New Issue