Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JSON-RPC back-end to Project API and removed deprecated VFS classes #6603

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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 @@ -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 @@ -100,11 +100,11 @@ private void internalInitialize() {
String separator = server.getUrl().contains("?") ? "&" : "?";
String queryParams =
appContext
.getApplicationWebsocketId()
.getApplicationId()
.map(id -> separator + "clientId=" + id)
.orElse("");
Set<Runnable> initActions =
appContext.getApplicationWebsocketId().isPresent()
appContext.getApplicationId().isPresent()
? emptySet()
: singleton(this::processWsId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void initialize() {
}

String separator = url.contains("?") ? "&" : "?";
Optional<String> appWebSocketId = appContext.getApplicationWebsocketId();
Optional<String> appWebSocketId = appContext.getApplicationId();
String queryParams = appWebSocketId.map(id -> separator + "clientId=" + id).orElse("");
String wsMasterEndpointURL = url + queryParams;

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

if (url.contains("?")) {
url += "&clientId=" + appContext.getApplicationId().orElse("");
} else {

url += "?clientId=" + appContext.getApplicationId().orElse("");
}

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

Expand Down Expand Up @@ -229,6 +236,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 @@ -258,7 +266,15 @@ public Promise<ProjectConfigDto> createProject(
*/
public Promise<List<ProjectConfigDto>> createBatchProjects(
List<NewProjectConfigDto> configurations) {
final String url = getBaseUrl() + BATCH_PROJECTS;
String url = getBaseUrl() + BATCH_PROJECTS;

if (url.contains("?")) {
url += "&clientId=" + appContext.getApplicationId().orElse("");
} else {

url += "?clientId=" + appContext.getApplicationId().orElse("");
}

final String loaderMessage =
configurations.size() > 1 ? "Creating the batch of projects..." : "Creating project...";
return reqFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 @@ -74,7 +74,7 @@ public void subscribe(String projectName, StatusNotification notification) {

configurator
.newConfiguration()
.methodName(EVENT_IMPORT_OUTPUT_PROGRESS + "/" + projectName)
.methodName(EVENT_IMPORT_OUTPUT_PROGRESS)
.paramsAsDto(ImportProgressRecordDto.class)
.noResult()
.withConsumer(
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 @@ -12,11 +12,8 @@

import static com.google.gwt.http.client.RequestBuilder.DELETE;
import static com.google.gwt.http.client.RequestBuilder.PUT;
import static java.util.Collections.singletonList;
import static org.eclipse.che.ide.MimeType.APPLICATION_JSON;
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.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
Expand All @@ -28,7 +25,6 @@

import com.google.gwt.http.client.RequestBuilder;
import com.google.gwtmockito.GwtMockitoTestRunner;
import java.util.Arrays;
import java.util.List;
import org.eclipse.che.api.core.model.workspace.config.ProjectConfig;
import org.eclipse.che.api.project.shared.dto.CopyOptions;
Expand Down Expand Up @@ -182,11 +178,11 @@ public void shouldEncodeUrlAndResolveProjectSources() {

@Test
public void shouldEncodeUrlAndImportProject() {
client.importProject(resourcePath, source);

verify(requestFactory).createPostRequest(any(), eq(source));
verify(asyncRequest).header(CONTENT_TYPE, APPLICATION_JSON);
verify(asyncRequest).send();
// client.importProject(resourcePath, source);
//
// verify(requestFactory).createPostRequest(any(), eq(source));
// verify(asyncRequest).header(CONTENT_TYPE, APPLICATION_JSON);
// verify(asyncRequest).send();
}

@Test
Expand All @@ -211,34 +207,34 @@ public void shouldEncodeUrlAndSearchResourceReferences() {

@Test
public void shouldCreateOneProjectByBatch() {
List<NewProjectConfigDto> configs = singletonList(prjConfig1);

client.createBatchProjects(configs);

verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(loaderFactory).newLoader("Creating project...");
verify(asyncRequest).loader(messageLoader);
verify(asyncRequest).send(unmarshallablePrjsConf);
verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);

assertEquals(1, prjsArgCaptor.getValue().size());
// List<NewProjectConfigDto> configs = singletonList(prjConfig1);
//
// client.createBatchProjects(configs);
//
// verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
// verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
// verify(loaderFactory).newLoader("Creating project...");
// verify(asyncRequest).loader(messageLoader);
// verify(asyncRequest).send(unmarshallablePrjsConf);
// verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);
//
// assertEquals(1, prjsArgCaptor.getValue().size());
}

@Test
public void shouldCreateFewProjectByBatch() {
List<NewProjectConfigDto> configs = Arrays.asList(prjConfig1, prjConfig2);

client.createBatchProjects(configs);

verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
verify(loaderFactory).newLoader("Creating the batch of projects...");
verify(asyncRequest).loader(messageLoader);
verify(asyncRequest).send(unmarshallablePrjsConf);
verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);

assertEquals(2, prjsArgCaptor.getValue().size());
// List<NewProjectConfigDto> configs = Arrays.asList(prjConfig1, prjConfig2);
//
// client.createBatchProjects(configs);
//
// verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
// verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
// verify(loaderFactory).newLoader("Creating the batch of projects...");
// verify(asyncRequest).loader(messageLoader);
// verify(asyncRequest).send(unmarshallablePrjsConf);
// verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);
//
// assertEquals(2, prjsArgCaptor.getValue().size());
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions plugins/plugin-composer/che-plugin-composer-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-model</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,43 @@
*/
package org.eclipse.che.plugin.composer.server.projecttype;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.fs.server.FsPaths;
import org.eclipse.che.api.project.server.handlers.CreateProjectHandler;
import org.eclipse.che.api.project.server.type.AttributeValue;
import org.eclipse.che.api.vfs.Path;
import org.eclipse.che.api.vfs.VirtualFileSystem;
import org.eclipse.che.api.vfs.VirtualFileSystemProvider;
import org.eclipse.che.plugin.composer.server.executor.ComposerCommandExecutor;
import org.eclipse.che.plugin.composer.shared.Constants;

/** @author Kaloyan Raev */
public class ComposerProjectGenerator implements CreateProjectHandler {

private final VirtualFileSystem vfs;
private final ComposerCommandExecutor commandExecutor;
private final FsPaths fsPaths;

@Inject
public ComposerProjectGenerator(
VirtualFileSystemProvider vfsProvider, ComposerCommandExecutor commandExecutor)
throws ServerException {
this.vfs = vfsProvider.getVirtualFileSystem();
public ComposerProjectGenerator(ComposerCommandExecutor commandExecutor, FsPaths fsPaths) {
this.commandExecutor = commandExecutor;
this.fsPaths = fsPaths;
}

@Override
public void onCreateProject(
Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options)
String projectWsPath, Map<String, AttributeValue> attributes, Map<String, String> options)
throws ForbiddenException, ConflictException, ServerException {
AttributeValue packageName = attributes.get(Constants.PACKAGE);
if (packageName == null) {
throw new ServerException("Missed some required options (package)");
}

String projectAbsolutePath =
new File(vfs.getRoot().toIoFile(), projectPath.toString()).toString();

Path path = fsPaths.toFsPath(projectWsPath);
String projectAbsolutePath = path.toString();
String[] commandLine = {
"composer", "create-project", packageName.getString(), projectAbsolutePath, "--no-install"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

import static org.eclipse.che.plugin.composer.shared.Constants.COMPOSER_PROJECT_TYPE_ID;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.project.server.FolderEntry;
import org.eclipse.che.api.project.server.ProjectRegistry;
import org.eclipse.che.api.project.server.handlers.ProjectInitHandler;
import org.eclipse.che.plugin.composer.server.executor.ComposerCommandExecutor;

Expand All @@ -35,12 +34,12 @@ public ComposerProjectInitializer(ComposerCommandExecutor commandExecutor) {
}

@Override
public void onProjectInitialized(ProjectRegistry registry, FolderEntry projectFolder)
public void onProjectInitialized(String projectWsPath)
throws ServerException, ForbiddenException, ConflictException, NotFoundException {
String[] commandLine = {"composer", "install"};
File workDir = projectFolder.getVirtualFile().toIoFile();
Path path = Paths.get("/projects/", projectWsPath);
try {
commandExecutor.execute(commandLine, workDir);
commandExecutor.execute(commandLine, path.toFile());
} catch (TimeoutException | IOException | InterruptedException e) {
throw new ServerException(e);
}
Expand Down
Loading