Skip to content

Commit

Permalink
IDE code refactoring and clean-up (#5177)
Browse files Browse the repository at this point in the history
  • Loading branch information
azatsarynnyy committed May 23, 2017
1 parent 808144b commit 3ab6246
Show file tree
Hide file tree
Showing 57 changed files with 926 additions and 1,958 deletions.
Expand Up @@ -179,8 +179,6 @@ public interface AppContext {
*/
FactoryDto getFactory();

void setFactory(FactoryDto factory);

String getWorkspaceId();

/**
Expand All @@ -190,20 +188,10 @@ public interface AppContext {
*/
Workspace getWorkspace();

/**
* Sets current workspace.
*
* @param workspace
* current workspace or {@code null}
*/
void setWorkspace(Workspace workspace);

ActiveRuntime getActiveRuntime();


String getMasterEndpoint();


String getDevAgentEndpoint();

/**
Expand Down
Expand Up @@ -18,16 +18,19 @@
import org.eclipse.che.api.workspace.shared.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

/**
* @author Vitalii Parfonov
*/
public class ActiveRuntime {

private DevMachine devMachine;
private List<MachineEntity> machines;
private DevMachine devMachine;
private Map<String, MachineEntity> machines;

public ActiveRuntime(Workspace workspace) {
Runtime workspaceRuntime = workspace.getRuntime();
Expand All @@ -40,10 +43,10 @@ public ActiveRuntime(Workspace workspace) {
Machine devMachine = workspaceRuntime.getMachines().get(devMachineName);

this.devMachine = new DevMachine(devMachineName, devMachine);
machines = new ArrayList<>();
machines = new HashMap<>();

for (Entry<String, ? extends Machine> entry : workspaceRuntime.getMachines().entrySet()) {
machines.add(new MachineEntityImpl(entry.getKey(), entry.getValue()));
machines.put(entry.getKey(), new MachineEntityImpl(entry.getKey(), entry.getValue()));
}
}

Expand All @@ -52,6 +55,10 @@ public DevMachine getDevMachine() {
}

public List<MachineEntity> getMachines() {
return machines;
return new ArrayList<>(machines.values());
}

public Optional<MachineEntity> getMachineByName(String name) {
return Optional.ofNullable(machines.get(name));
}
}
Expand Up @@ -16,22 +16,16 @@
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;

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.api.promises.client.callback.AsyncPromiseHelper;
import org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.dialogs.ConfirmCallback;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
import org.eclipse.che.ide.api.machine.events.WsAgentStateEvent;
import org.eclipse.che.ide.api.workspace.WorkspaceServiceClient;
import org.eclipse.che.ide.commons.exception.ServerDisconnectedException;
import org.eclipse.che.ide.rest.AsyncRequestFactory;
import org.eclipse.che.ide.ui.loaders.LoaderPresenter;
import org.eclipse.che.ide.util.browser.BrowserUtils;
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.ide.websocket.MessageBus;
import org.eclipse.che.ide.websocket.MessageBusProvider;
import org.eclipse.che.ide.websocket.events.ConnectionClosedHandler;
Expand All @@ -43,7 +37,6 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;
import static org.eclipse.che.ide.api.machine.WsAgentState.STARTED;
import static org.eclipse.che.ide.api.machine.WsAgentState.STOPPED;

Expand All @@ -63,7 +56,6 @@ public class WsAgentStateController implements ConnectionOpenedHandler, Connecti
private final DialogFactory dialogFactory;
private final AppContext appContext;
private final AsyncRequestFactory asyncRequestFactory;
private final WorkspaceServiceClient workspaceServiceClient;
private final LoaderPresenter loader;
private DevMachine devMachine;
private MessageBus messageBus;
Expand All @@ -72,14 +64,12 @@ public class WsAgentStateController implements ConnectionOpenedHandler, Connecti
private List<AsyncCallback<DevMachine>> devMachineCallbacks = newArrayList();

@Inject
public WsAgentStateController(WorkspaceServiceClient workspaceServiceClient,
EventBus eventBus,
public WsAgentStateController(EventBus eventBus,
LoaderPresenter loader,
MessageBusProvider messageBusProvider,
AsyncRequestFactory asyncRequestFactory,
DialogFactory dialogFactory,
AppContext appContext) {
this.workspaceServiceClient = workspaceServiceClient;
this.loader = loader;
this.eventBus = eventBus;
this.messageBusProvider = messageBusProvider;
Expand All @@ -100,7 +90,7 @@ public void initialize(DevMachine devMachine) {
@Override
public void onClose(WebSocketClosedEvent event) {
if (STARTED.equals(state)) {
checkWsAgentHealth();
// checkWsAgentHealth();
}
}

Expand Down Expand Up @@ -218,23 +208,23 @@ private void checkWsConnection() {
messageBus.addOnOpenHandler(this);
}

private void checkWsAgentHealth() {
workspaceServiceClient.getWsAgentState(appContext.getWorkspaceId(), devMachine.getName()).then(agentHealthState -> {
if (RUNNING.equals(agentHealthState.getWorkspaceStatus())) {
checkStateOfWsAgent(agentHealthState);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (arg.getCause() instanceof ServerDisconnectedException) {
dialogFactory.createMessageDialog("Server Unavailable",
"Server is not responding. Your admin must restart it.",
null).show();
}
Log.error(getClass(), arg.getMessage());
}
});
}
// private void checkWsAgentHealth() {
// workspaceServiceClient.getWsAgentState(appContext.getWorkspaceId(), devMachine.getName()).then(agentHealthState -> {
// if (RUNNING.equals(agentHealthState.getWorkspaceStatus())) {
// checkStateOfWsAgent(agentHealthState);
// }
// }).catchError(new Operation<PromiseError>() {
// @Override
// public void apply(PromiseError arg) throws OperationException {
// if (arg.getCause() instanceof ServerDisconnectedException) {
// dialogFactory.createMessageDialog("Server Unavailable",
// "Server is not responding. Your admin must restart it.",
// null).show();
// }
// Log.error(getClass(), arg.getMessage());
// }
// });
// }

private class StopCallback implements ConfirmCallback {

Expand All @@ -248,11 +238,11 @@ private StopCallback(boolean reloadPage, boolean createSnapshot) {

@Override
public void accepted() {
workspaceServiceClient.stop(appContext.getWorkspaceId(), createSnapshot).then(ignored -> {
if (reloadPage) {
BrowserUtils.reloadPage(false);
}
});
// workspaceServiceClient.stop(appContext.getWorkspaceId(), createSnapshot).then(ignored -> {
// if (reloadPage) {
// BrowserUtils.reloadPage(false);
// }
// });
}
}

Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 3ab6246

Please sign in to comment.