Skip to content

Commit

Permalink
Clean-up WorkspaceServiceClient: (#6721)
Browse files Browse the repository at this point in the history
* remove useless for IDE method for creating a workspace;
* remove obsolete parameters related to snapshots.
  • Loading branch information
azatsarynnyy authored Oct 13, 2017
1 parent 1a12850 commit 1450590
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,6 @@ public interface CoreLocalizationConstant extends Messages {
@Key("workspace.recovering.dialog.title")
String workspaceRecoveringDialogTitle();

@Key("workspace.recovering.dialog.text")
String workspaceRecoveringDialogText();

@Key("workspace.restore.snapshot")
String restoreWorkspaceFromSnapshot();

@Key("workspace.subscribe.on.events.failed")
String workspaceSubscribeOnEventsFailed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class CurrentWorkspaceManager {
}

/** Start the current workspace with a default environment. */
Promise<Void> startWorkspace(boolean restoreFromSnapshot) {
Promise<Void> startWorkspace() {
WorkspaceImpl workspace = appContext.getWorkspace();
String defEnvName = workspace.getConfig().getDefaultEnv();

return workspaceServiceClient
.startById(workspace.getId(), defEnvName, restoreFromSnapshot)
.startById(workspace.getId(), defEnvName)
.then(
ws -> {
((AppContextImpl) appContext).setWorkspace(ws);
Expand Down Expand Up @@ -108,7 +108,7 @@ private void handleWorkspaceStatus() {
.then(
settings -> {
if (parseBoolean(settings.getOrDefault(CHE_WORKSPACE_AUTO_START, "true"))) {
startWorkspace(false);
startWorkspace();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Provider;
Expand All @@ -43,7 +42,6 @@ class StartWorkspaceNotification {
private final Provider<CurrentWorkspaceManager> currentWorkspaceManagerProvider;

@UiField Button button;
@UiField CheckBox restore;

@Inject
StartWorkspaceNotification(
Expand Down Expand Up @@ -84,7 +82,7 @@ private void hide() {
void startClicked(ClickEvent e) {
hide();

currentWorkspaceManagerProvider.get().startWorkspace(restore.getValue());
currentWorkspaceManagerProvider.get().startWorkspace();
}

interface StartWorkspaceNotificationUiBinder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,10 @@
line-height: 18px;
float: left;
}

.check {
width: 100%;
height: 20px;
position: absolute;
left: 0px;
top: 25px;
}

.checkbox {
position: absolute;
left: 0px;
top: 5px;
transform: scale(0.85) translateX(-10px);
}

.checkbox label {
color: popupLoaderTextColor;
}

</ui:style>

<g:FlowPanel addStyleNames="{style.main}">
<g:Button ui:field="button" addStyleNames="{res.windowCss.button} {res.windowCss.primaryButton} {style.button}" text="{locale.startWsButton}"></g:Button>
<g:FlowPanel styleName="{style.check}">
<g:CheckBox ui:field="restore" checked="true" addStyleNames="{style.checkbox}" text="{locale.restoreWorkspaceFromSnapshot}"></g:CheckBox>
</g:FlowPanel>
</g:FlowPanel>

</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
import com.google.gwt.http.client.URL;
import com.google.inject.Inject;
import java.util.Map;
import javax.validation.constraints.NotNull;
import org.eclipse.che.api.promises.client.Function;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.workspace.shared.dto.CommandDto;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.command.CommandImpl;
Expand Down Expand Up @@ -56,37 +54,15 @@ private WorkspaceServiceClient(
this.baseHttpUrl = appContext.getMasterApiEndpoint() + "/workspace";
}

/**
* Creates new workspace.
*
* @param newWorkspace the configuration to create the new workspace
* @param account the account id related to this operation
* @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error
*/
@Deprecated
public Promise<WorkspaceImpl> create(
final WorkspaceConfigDto newWorkspace, final String accountId) {
String url = baseHttpUrl;
if (accountId != null) {
url += "?account=" + accountId;
}
return asyncRequestFactory
.createPostRequest(url, newWorkspace)
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.loader(loaderFactory.newLoader("Creating workspace..."))
.send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class))
.then((Function<WorkspaceDto, WorkspaceImpl>) WorkspaceImpl::new);
}

/**
* Gets users workspace by key.
*
* @param key composite key can be just workspace ID or in the namespace/workspace_name form
* @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error
*/
public Promise<WorkspaceImpl> getWorkspace(final String key) {
public Promise<WorkspaceImpl> getWorkspace(String key) {
final String url = baseHttpUrl + '/' + key;

return asyncRequestFactory
.createGetRequest(url)
.header(ACCEPT, APPLICATION_JSON)
Expand All @@ -95,43 +71,25 @@ public Promise<WorkspaceImpl> getWorkspace(final String key) {
.then((Function<WorkspaceDto, WorkspaceImpl>) WorkspaceImpl::new);
}

/**
* Gets workspace by namespace and name
*
* @param namespace namespace
* @param workspaceName workspace name
* @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error
*/
public Promise<WorkspaceImpl> getWorkspace(
@NotNull final String namespace, @NotNull final String workspaceName) {
final String url = baseHttpUrl + '/' + namespace + "/" + workspaceName;
/** Get workspace related server configuration values defined in che.properties */
Promise<Map<String, String>> getSettings() {
return asyncRequestFactory
.createGetRequest(url)
.createGetRequest(baseHttpUrl + "/settings")
.header(ACCEPT, APPLICATION_JSON)
.loader(loaderFactory.newLoader("Getting info about workspace..."))
.send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class))
.then((Function<WorkspaceDto, WorkspaceImpl>) WorkspaceImpl::new);
.header(CONTENT_TYPE, APPLICATION_JSON)
.send(new StringMapUnmarshaller());
}

/**
* Starts workspace based on workspace id and environment.
*
* @param id workspace ID
* @param envName the name of the workspace environment that should be used for start
* @param restore if <code>true</code> workspace will be restored from snapshot if snapshot
* exists, if <code>false</code> workspace will not be restored from snapshot even if
* auto-restore is enabled and snapshot exists
* @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error
*/
public Promise<WorkspaceImpl> startById(
@NotNull final String id, final String envName, final Boolean restore) {
String url = baseHttpUrl + "/" + id + "/runtime";
if (restore != null) {
url += "?restore=" + restore;
}
if (envName != null) {
url += (url.contains("?") ? '&' : '?') + "environment=" + envName;
}
Promise<WorkspaceImpl> startById(String id, String envName) {
String url = baseHttpUrl + "/" + id + "/runtime" + "?environment=" + envName;

return asyncRequestFactory
.createPostRequest(url, null)
.header(ACCEPT, APPLICATION_JSON)
Expand All @@ -148,24 +106,8 @@ public Promise<WorkspaceImpl> startById(
* @return a promise that will resolve when the workspace has been stopped, or rejects with an
* error
*/
public Promise<Void> stop(String wsId) {
Promise<Void> stop(String wsId) {
final String url = baseHttpUrl + "/" + wsId + "/runtime";
return asyncRequestFactory
.createDeleteRequest(url)
.loader(loaderFactory.newLoader("Stopping workspace..."))
.send();
}

/**
* Stops currently run runtime with ability to create snapshot.
*
* @param wsId workspace ID
* @param createSnapshot create snapshot during the stop operation
* @return a promise that will resolve when the workspace has been stopped, or rejects with an
* error
*/
public Promise<Void> stop(String wsId, boolean createSnapshot) {
final String url = baseHttpUrl + "/" + wsId + "/runtime?create-snapshot=" + createSnapshot;

return asyncRequestFactory
.createDeleteRequest(url)
Expand All @@ -180,7 +122,7 @@ public Promise<Void> stop(String wsId, boolean createSnapshot) {
* @param newCommand the new workspace command
* @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error
*/
public Promise<WorkspaceImpl> addCommand(final String wsId, final CommandImpl newCommand) {
public Promise<WorkspaceImpl> addCommand(String wsId, CommandImpl newCommand) {
final String url = baseHttpUrl + '/' + wsId + "/command";

final CommandDto commandDto =
Expand All @@ -206,7 +148,7 @@ public Promise<WorkspaceImpl> addCommand(final String wsId, final CommandImpl ne
* @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error
*/
public Promise<WorkspaceImpl> updateCommand(
final String wsId, final String commandName, final CommandImpl commandUpdate) {
String wsId, String commandName, CommandImpl commandUpdate) {
final String url = baseHttpUrl + '/' + wsId + "/command/" + URL.encodePathSegment(commandName);

final CommandDto commandDto =
Expand All @@ -233,20 +175,12 @@ public Promise<WorkspaceImpl> updateCommand(
* @param commandName the name of the command to remove
* @return a promise that will resolve when the command has been stopped, or rejects with an error
*/
public Promise<Void> deleteCommand(final String wsId, final String commandName) {
public Promise<Void> deleteCommand(String wsId, String commandName) {
final String url = baseHttpUrl + '/' + wsId + "/command/" + URL.encodePathSegment(commandName);

return asyncRequestFactory
.createDeleteRequest(url)
.loader(loaderFactory.newLoader("Deleting command..."))
.send();
}

/** Get workspace related server configuration values defined in che.properties */
public Promise<Map<String, String>> getSettings() {
return asyncRequestFactory
.createGetRequest(baseHttpUrl + "/settings")
.header(ACCEPT, APPLICATION_JSON)
.header(CONTENT_TYPE, APPLICATION_JSON)
.send(new StringMapUnmarshaller());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ started.ws=Workspace is running
ext.server.started=Workspace agent started
ext.server.stopped=Workspace agent stopped
workspace.recovering.dialog.title = Workspace recovering
workspace.recovering.dialog.text = Do you want to recover the workspace from snapshot?
workspace.restore.snapshot = Use latest snapshot
workspace.subscribe.on.events.failed = Can't subscribe on workspace events. \
Probably Workspace will works fine but application can't handle state events
workspace.start.failed=Failed to start workspace
Expand Down

0 comments on commit 1450590

Please sign in to comment.