Skip to content

Commit

Permalink
Added JSON-RPC back-end to Project API and removed deprecated VFS cla…
Browse files Browse the repository at this point in the history
…sses (#7380)
  • Loading branch information
Dmytro Kulieshov committed Nov 20, 2017
1 parent d6083f4 commit 0f635cf
Show file tree
Hide file tree
Showing 327 changed files with 11,388 additions and 27,030 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public BasicWebSocketMessageTransmitter(

@Override
public synchronized void transmit(String endpointId, String message) {
final Optional<Session> sessionOptional = registry.get(endpointId);
Optional<Session> sessionOptional = registry.get(endpointId);

if (!sessionOptional.isPresent()) {
sessionOptional = registry.getByPartialMatch(endpointId).stream().findFirst();
}

if (!sessionOptional.isPresent() || !sessionOptional.get().isOpen()) {
LOG.debug("Session is not registered or closed, adding message to pending");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public interface AppContext {
*
* @return identifier
*/
Optional<String> getApplicationWebsocketId();
Optional<String> getApplicationId();

/**
* Sets web application identifier. Most obvious use - to distinguish web applications on server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ private void internalInitialize() {
separator
+ "token="
+ token
+ appContext
.getApplicationWebsocketId()
.map(id -> "&clientId=" + id)
.orElse("");
+ appContext.getApplicationId().map(id -> "&clientId=" + id).orElse("");
Set<Runnable> initActions =
appContext.getApplicationWebsocketId().isPresent()
appContext.getApplicationId().isPresent()
? emptySet()
: singleton(WorkspaceMasterJsonRpcInitializer.this::processWsId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public String getWsAgentServerApiEndpoint() {
}

@Override
public Optional<String> getApplicationWebsocketId() {
public Optional<String> getApplicationId() {
return Optional.ofNullable(applicationWebsocketId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void internalInitialize() {
server -> {
String wsAgentWebSocketUrl = agentURLModifier.modify(server.getUrl());
String separator = wsAgentWebSocketUrl.contains("?") ? "&" : "?";
Optional<String> applicationWebSocketId = appContext.getApplicationWebsocketId();
Optional<String> applicationWebSocketId = appContext.getApplicationId();
String queryParams =
applicationWebSocketId.map(id -> separator + "clientId=" + id).orElse("");
Set<Runnable> initActions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void initialize() {
}

char separator = url.contains("?") ? '&' : '?';
Optional<String> appWebSocketId = appContext.getApplicationWebsocketId();
Optional<String> appWebSocketId = appContext.getApplicationId();
String queryParams =
separator
+ "token="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.che.ide.api.project.type.wizard.ProjectWizardRegistrar;
import org.eclipse.che.ide.api.project.wizard.ImportWizardRegistrar;
import org.eclipse.che.ide.projectimport.InitialProjectImporter;
import org.eclipse.che.ide.projectimport.ProjectImportNotificationSubscriber;
import org.eclipse.che.ide.projectimport.wizard.ImportProjectNotificationSubscriberFactory;
import org.eclipse.che.ide.projectimport.wizard.ImportWizardFactory;
import org.eclipse.che.ide.projectimport.wizard.ProjectImportOutputJsonRpcNotifier;
Expand Down Expand Up @@ -75,8 +74,6 @@ protected void configure() {
ProjectNotificationSubscriber.class, ProjectImportOutputJsonRpcNotifier.class)
.build(ImportProjectNotificationSubscriberFactory.class));

bind(ProjectImportNotificationSubscriber.class).asEagerSingleton();

bind(WorkspaceProjectsSyncer.class).asEagerSingleton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public Promise<List<SourceEstimation>> resolveSources(Path path) {
public Promise<Void> importProject(Path path, SourceStorageDto source) {
String url = getBaseUrl() + IMPORT + encodePath(path);

url += url.contains("?") ? "&" : "?";
url += "clientId=" + appContext.getApplicationId().orElse("");

return reqFactory.createPostRequest(url, source).header(CONTENT_TYPE, APPLICATION_JSON).send();
}

Expand Down Expand Up @@ -230,6 +233,7 @@ public Promise<ProjectConfigDto> createProject(
for (String key : options.keySet()) {
urlBuilder.setParameter(key, options.get(key));
}
urlBuilder.setParameter("clientId", appContext.getApplicationId().orElse(""));
return reqFactory
.createPostRequest(urlBuilder.buildString(), configuration)
.header(ACCEPT, APPLICATION_JSON)
Expand Down Expand Up @@ -259,7 +263,11 @@ public Promise<ProjectConfigDto> createProject(
*/
public Promise<List<ProjectConfigDto>> createBatchProjects(
List<NewProjectConfigDto> configurations) {
final String url = getBaseUrl() + BATCH_PROJECTS;
String url = getBaseUrl() + BATCH_PROJECTS;

url += url.contains("?") ? "&" : "?";
url += "clientId=" + appContext.getApplicationId().orElse("");

final String loaderMessage =
configurations.size() > 1 ? "Creating the batch of projects..." : "Creating project...";
return reqFactory
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import static com.google.common.base.Strings.nullToEmpty;
import static org.eclipse.che.api.project.shared.Constants.EVENT_IMPORT_OUTPUT_PROGRESS;
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.api.notification.StatusNotification.Status.PROGRESS;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.*;

import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
Expand Down Expand Up @@ -59,7 +57,7 @@ public ProjectImportOutputJsonRpcNotifier(
eventBus.addHandler(
WsAgentServerStoppedEvent.TYPE,
e -> {
requestHandlerManager.deregister(EVENT_IMPORT_OUTPUT_PROGRESS + "/" + projectName);
requestHandlerManager.deregister(EVENT_IMPORT_OUTPUT_PROGRESS);
if (singletonNotification != null) {
singletonNotification.setStatus(FAIL);
singletonNotification.setContent("");
Expand All @@ -72,17 +70,19 @@ public void subscribe(String projectName, StatusNotification notification) {
this.projectName = projectName;
this.singletonNotification = notification;

configurator
.newConfiguration()
.methodName(EVENT_IMPORT_OUTPUT_PROGRESS + "/" + projectName)
.paramsAsDto(ImportProgressRecordDto.class)
.noResult()
.withConsumer(
progressRecord -> {
singletonNotification.setTitle(
locale.importingProject(ProjectImportOutputJsonRpcNotifier.this.projectName));
singletonNotification.setContent(nullToEmpty(progressRecord.getLine()));
});
if (!requestHandlerManager.isRegistered(EVENT_IMPORT_OUTPUT_PROGRESS)) {
configurator
.newConfiguration()
.methodName(EVENT_IMPORT_OUTPUT_PROGRESS)
.paramsAsDto(ImportProgressRecordDto.class)
.noResult()
.withConsumer(
progressRecord -> {
singletonNotification.setTitle(
locale.importingProject(ProjectImportOutputJsonRpcNotifier.this.projectName));
singletonNotification.setContent(nullToEmpty(progressRecord.getLine()));
});
}
}

@Override
Expand All @@ -94,7 +94,7 @@ public void subscribe(String projectName) {

@Override
public void onSuccess() {
requestHandlerManager.deregister(EVENT_IMPORT_OUTPUT_PROGRESS + "/" + projectName);
requestHandlerManager.deregister(EVENT_IMPORT_OUTPUT_PROGRESS);

singletonNotification.setStatus(SUCCESS);
singletonNotification.setTitle(locale.importProjectMessageSuccess(projectName));
Expand All @@ -103,7 +103,7 @@ public void onSuccess() {

@Override
public void onFailure(String errorMessage) {
requestHandlerManager.deregister(EVENT_IMPORT_OUTPUT_PROGRESS + "/" + projectName);
requestHandlerManager.deregister(EVENT_IMPORT_OUTPUT_PROGRESS);

singletonNotification.setStatus(FAIL);
singletonNotification.setContent(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ public void complete(@NotNull final CompleteCallback callback) {
.then(onComplete(callback))
.catchError(onFailure(callback));
} else if (mode == UPDATE) {
String path =
dataObject.getPath().startsWith("/")
? dataObject.getPath().substring(1)
: dataObject.getPath();

appContext
.getWorkspaceRoot()
.getContainer(Path.valueOf(dataObject.getPath()))
.getContainer(Path.valueOf(path))
.then(
optContainer -> {
checkState(optContainer.isPresent(), "Failed to update non existed path");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -110,9 +110,7 @@ public void setUp() throws Exception {
new ProjectServiceClient(
loaderFactory, requestFactory, dtoFactory, unmarshaller, appContext);

when(appContext.getWsAgentServerApiEndpoint()).thenReturn("http://127.0.0.3/api");

when(loaderFactory.newLoader(any())).thenReturn(messageLoader);
when(loaderFactory.newLoader(any(String.class))).thenReturn(messageLoader);
when(asyncRequest.loader(messageLoader)).thenReturn(asyncRequest);
when(asyncRequest.data(any(String.class))).thenReturn(asyncRequest);
when(asyncRequest.send(unmarshallableItemRef)).thenReturn(itemRefPromise);
Expand Down Expand Up @@ -177,7 +175,7 @@ public void shouldReturnListProjects() {
client.getProjects();

verify(requestFactory).createGetRequest(any());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);
verify(asyncRequest).send(unmarshallablePrjsConf);
}
Expand All @@ -189,7 +187,7 @@ public void shouldEncodeUrlAndEstimateProject() {
client.estimate(resourcePath, prjType);

verify(requestFactory).createGetRequest(any());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Estimating project...");
verify(asyncRequest).loader(messageLoader);
verify(asyncRequest).send(unmarshallbleSourceEstimation);
Expand All @@ -200,7 +198,7 @@ public void shouldEncodeUrlAndResolveProjectSources() {
client.resolveSources(resourcePath);

verify(requestFactory).createGetRequest(any());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Resolving sources...");
verify(asyncRequest).loader(messageLoader);
verify(unmarshaller).newListUnmarshaller(SourceEstimation.class);
Expand Down Expand Up @@ -229,7 +227,7 @@ public void shouldEncodeUrlAndSearchResourceReferences() {
client.search(expression);

verify(requestFactory).createGetRequest(any());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Searching...");
verify(asyncRequest).loader(messageLoader);
verify(unmarshaller).newUnmarshaller(ProjectSearchResponseDto.class);
Expand All @@ -243,7 +241,7 @@ public void shouldCreateOneProjectByBatch() {
client.createBatchProjects(configs);

verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Creating project...");
verify(asyncRequest).loader(messageLoader);
verify(asyncRequest).send(unmarshallablePrjsConf);
Expand All @@ -259,7 +257,7 @@ public void shouldCreateFewProjectByBatch() {
client.createBatchProjects(configs);

verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Creating the batch of projects...");
verify(asyncRequest).loader(messageLoader);
verify(asyncRequest).send(unmarshallablePrjsConf);
Expand Down Expand Up @@ -355,7 +353,7 @@ public void shouldEncodeUrlAndGetTree() {
client.getTree(resourcePath, 2, true);

verify(requestFactory).createGetRequest(any());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(unmarshaller).newUnmarshaller(TreeElement.class);
verify(asyncRequest).send(unmarshallableTreeElem);
}
Expand All @@ -365,7 +363,7 @@ public void shouldEncodeUrlAndGetItem() {
client.getItem(resourcePath);

verify(requestFactory).createGetRequest(any());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Getting item...");
verify(unmarshaller).newUnmarshaller(ItemReference.class);
verify(asyncRequest).send(unmarshallableItemRef);
Expand All @@ -376,7 +374,7 @@ public void shouldEncodeUrlAndGetProject() {
client.getProject(Path.valueOf(TEXT));

verify(requestFactory).createGetRequest(any());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Getting project...");
verify(asyncRequest).loader(messageLoader);
verify(unmarshaller).newUnmarshaller(ProjectConfigDto.class);
Expand All @@ -393,8 +391,8 @@ public void shouldEncodeUrlAndUpdateProject() {
client.updateProject(prjConfig1);

verify(requestFactory).createRequest(eq(PUT), anyString(), eq(prjConfig1), eq(false));
verify(asyncRequest).header(CONTENT_TYPE, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(asyncRequest).header(CONTENT_TYPE, APPLICATION_JSON);
verify(asyncRequest).header(ACCEPT, APPLICATION_JSON);
verify(loaderFactory).newLoader("Updating project...");
verify(asyncRequest).loader(messageLoader);
verify(unmarshaller).newUnmarshaller(ProjectConfigDto.class);
Expand Down
Loading

0 comments on commit 0f635cf

Please sign in to comment.