Skip to content

Commit

Permalink
Use Workdspace's and Factory's model objects in IDE (#5221)
Browse files Browse the repository at this point in the history
  • Loading branch information
azatsarynnyy committed May 29, 2017
1 parent 87105ec commit ad3bc4d
Show file tree
Hide file tree
Showing 159 changed files with 3,206 additions and 2,316 deletions.
Expand Up @@ -12,15 +12,15 @@

import com.google.common.annotations.Beta;

import org.eclipse.che.api.core.model.factory.Factory;
import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
import org.eclipse.che.ide.api.factory.model.FactoryImpl;
import org.eclipse.che.ide.api.machine.ActiveRuntime;
import org.eclipse.che.ide.api.machine.DevMachine;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.api.workspace.model.WorkspaceConfigImpl;
import org.eclipse.che.ide.api.workspace.model.WorkspaceImpl;
import org.eclipse.che.ide.resource.Path;

import java.util.List;
Expand Down Expand Up @@ -112,8 +112,9 @@ public interface AppContext {
* @return the workspace name
* @see WorkspaceConfigDto#getName()
* @since 4.3.0
* @deprecated use {@link WorkspaceConfigImpl#getName()}
*/
@Beta
@Deprecated
String getWorkspaceName();

/**
Expand Down Expand Up @@ -142,7 +143,7 @@ public interface AppContext {
List<StartUpAction> getStartAppActions();

/**
* Returns current user.
* Returns the current user.
*
* @return current user
*/
Expand Down Expand Up @@ -172,22 +173,20 @@ public interface AppContext {
void removeProjectFromImporting(String pathToProject);

/**
* Returns {@link Factory} instance which id was set on startup,
* Returns {@link FactoryImpl} instance which id was set on startup,
* or {@code null} if no factory was specified.
*
* @return loaded factory or {@code null}
*/
FactoryDto getFactory();
FactoryImpl getFactory();

String getWorkspaceId();

/**
* Returns {@link Workspace} instance of current workspace.
*
* @return current workspace
*/
Workspace getWorkspace();
/** Returns the current workspace. */
WorkspaceImpl getWorkspace();

/** @deprecated use {@link #getWorkspace()} and {@link WorkspaceImpl#getRuntime()} */
@Deprecated
ActiveRuntime getActiveRuntime();

String getMasterEndpoint();
Expand Down
Expand Up @@ -10,57 +10,12 @@
*******************************************************************************/
package org.eclipse.che.ide.api.app;

import org.eclipse.che.api.user.shared.dto.ProfileDto;

import com.google.inject.Singleton;
import java.util.Map;

/**
* Describes current state of user.
*
* @author Vitaly Parfonov
*/
@Singleton
public class CurrentUser {

private ProfileDto profileDescriptor;
private Map<String, String> preferences;

public CurrentUser() {
}

public CurrentUser(ProfileDto profileDescriptor) {
this(profileDescriptor, null);
}

public CurrentUser(ProfileDto profileDescriptor, Map<String, String> preferences) {
this.profileDescriptor = profileDescriptor;
this.preferences = preferences;
}

/**
* Return current ProfileDescriptor
*
* @return
*/
public ProfileDto getProfile() {
return profileDescriptor;
}

public void setProfile(ProfileDto profileDescriptor) {
this.profileDescriptor = profileDescriptor;
}
/** Describes the current user. */
public interface CurrentUser {

/**
* Return current preferences
*
* @return
*/
public Map<String, String> getPreferences() {
return preferences;
}
String getId();

public void setPreferences(Map<String, String> preferences) {
this.preferences = preferences;
}
Map<String, String> getPreferences();
}

This file was deleted.

This file was deleted.

Expand Up @@ -11,14 +11,10 @@
package org.eclipse.che.ide.api.command;

import org.eclipse.che.api.core.model.workspace.config.Command;
import org.eclipse.che.ide.api.machine.MachineEntity;
import org.eclipse.che.ide.api.macro.Macro;
import org.eclipse.che.ide.api.workspace.model.MachineImpl;

/**
* Allows to execute a command.
*
* @author Artem Zatsarynnyi
*/
/** Allows to execute a command. */
public interface CommandExecutor {

/**
Expand All @@ -32,7 +28,7 @@ public interface CommandExecutor {
* machine to execute the command
* @see Macro
*/
void executeCommand(Command command, MachineEntity machine);
void executeCommand(Command command, MachineImpl machine);

/**
* Sends the the given {@code command} for execution.
Expand Down
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.che.ide.api.command;

import org.eclipse.che.ide.api.machine.MachineEntity;

/**
* Defines the requirements for a component which can produce the commands from the current context.
* <p>For every registered {@link CommandProducer} an appropriate action
Expand All @@ -34,8 +32,7 @@ public interface CommandProducer {

/**
* Creates a command from the current context.
* Target for command execution will be provided through {@code machine} parameter.
* Called when user performs corresponded action.
*/
CommandImpl createCommand(MachineEntity machine);
CommandImpl createCommand();
}
Expand Up @@ -187,7 +187,7 @@ public Promise<String> evaluate(String id, String expression) {
}

private String getBaseUrl(String id) {
final String url = appContext.getDevMachine().getWsAgentBaseUrl() + "/debugger";
final String url = appContext.getDevAgentEndpoint() + "/debugger";
if (id != null) {
return url + "/" + id;
}
Expand Down
Expand Up @@ -20,18 +20,24 @@
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.machine.DevMachine;
import org.eclipse.che.ide.api.machine.ExecAgentCommandManager;
import org.eclipse.che.ide.api.machine.MachineEntity;
import org.eclipse.che.ide.api.machine.events.WsAgentStateEvent;
import org.eclipse.che.ide.api.machine.events.WsAgentStateHandler;
import org.eclipse.che.ide.api.workspace.event.EnvironmentOutputEvent;
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.dto.DtoFactory;
import org.eclipse.che.ide.jsonrpc.JsonRpcInitializer;
import org.eclipse.che.ide.util.loging.Log;

import javax.inject.Singleton;
import java.util.Optional;
import java.util.function.Consumer;

import static java.util.Collections.singletonMap;
import static org.eclipse.che.api.machine.shared.Constants.EXEC_AGENT_REFERENCE;
import static org.eclipse.che.api.machine.shared.Constants.WSAGENT_REFERENCE;
import static org.eclipse.che.api.project.shared.dto.event.ProjectTreeTrackingOperationDto.Type.START;

/**
Expand Down Expand Up @@ -85,26 +91,37 @@ public void run() {
}

private void internalInitialize() {
DevMachine devMachine = appContext.getDevMachine();
String devMachineId = devMachine.getId();
String wsAgentWebSocketUrl = devMachine.getWsAgentWebSocketUrl();
final WorkspaceImpl workspace = appContext.getWorkspace();
final RuntimeImpl runtime = workspace.getRuntime();

if (runtime == null) {
return;
}

for (MachineImpl machine : runtime.getMachines().values()) {
machine.getServerByName(EXEC_AGENT_REFERENCE)
.ifPresent(server -> {
String execAgentServerURL = server.getUrl();
execAgentServerURL = execAgentServerURL.replaceFirst("http", "ws") + "/connect"; // FIXME: spi
initializer.initialize(machine.getName(), singletonMap("url", execAgentServerURL));
});

String wsAgentUrl = wsAgentWebSocketUrl.replaceFirst("(api)(/)(ws)", "websocket" + "$2" + appContext.getAppId());
String execAgentUrl = devMachine.getExecAgentUrl();
final Optional<ServerImpl> wsAgentServer = machine.getServerByName(WSAGENT_REFERENCE);

initializer.initialize("ws-agent", singletonMap("url", wsAgentUrl));
initializer.initialize(devMachineId, singletonMap("url", execAgentUrl));
if (wsAgentServer.isPresent()) {
final String wsAgentBaseUrl = wsAgentServer.get().getUrl() + "/api"; // FIXME: spi
final String wsAgentWebSocketUrl = wsAgentBaseUrl.replaceFirst("http", "ws") + "/ws"; // FIXME: spi
final String wsAgentUrl = wsAgentWebSocketUrl.replaceFirst("(api)(/)(ws)", "websocket" + "$2" + appContext.getAppId());

for (MachineEntity machineEntity : appContext.getActiveRuntime().getMachines()) {
if (!machineEntity.isDev()) {
initializer.initialize(machineEntity.getId(), singletonMap("url", machineEntity.getExecAgentUrl()));
execAgentCommandManager.getProcesses(machineEntity.getId(), false)
initializer.initialize("ws-agent", singletonMap("url", wsAgentUrl));
} else {
execAgentCommandManager.getProcesses(machine.getName(), false)
.onSuccess(processes -> {
Consumer<Integer> pidConsumer = pid -> execAgentCommandManager
.getProcessLogs(machineEntity.getId(), pid, null, null, 50, 0)
.getProcessLogs(machine.getName(), pid, null, null, 50, 0)
.onSuccess(logs -> logs.forEach(log -> {
String fixedLog = log.getText().replaceAll("\\[STDOUT\\] ", "");
String machineName = machineEntity.getDisplayName();
String machineName = machine.getName();
eventBus.fireEvent(new EnvironmentOutputEvent(fixedLog, machineName));
}));

Expand Down
Expand Up @@ -12,7 +12,7 @@

import com.google.gwt.event.shared.GwtEvent;

import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.ide.api.factory.model.FactoryImpl;


/**
Expand All @@ -22,9 +22,9 @@
*/
public class FactoryAcceptedEvent extends GwtEvent<FactoryAcceptedHandler> {

private FactoryDto factory;
private FactoryImpl factory;

public FactoryAcceptedEvent(FactoryDto factory) {
public FactoryAcceptedEvent(FactoryImpl factory) {
this.factory = factory;
}

Expand All @@ -41,7 +41,7 @@ protected void dispatch(FactoryAcceptedHandler handler) {

}

public FactoryDto getFactory() {
public FactoryImpl getFactory() {
return factory;
}
}

0 comments on commit ad3bc4d

Please sign in to comment.