Skip to content

Commit 2559ec0

Browse files
author
Dmitry Kuleshov
authored
Exec agent IDE client adaptation (eclipse-che#3383)
exec-agent command manager replacement, several improvements to JSOR RPC
1 parent 7bad057 commit 2559ec0

124 files changed

Lines changed: 9057 additions & 1153 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor;
2121
import org.eclipse.che.api.machine.shared.Constants;
2222
import org.eclipse.che.api.user.server.TokenValidator;
23-
import org.eclipse.che.api.workspace.server.TemporaryWorkspaceRemover;
2423
import org.eclipse.che.api.workspace.server.WorkspaceConfigMessageBodyAdapter;
2524
import org.eclipse.che.api.workspace.server.WorkspaceMessageBodyAdapter;
2625
import org.eclipse.che.api.workspace.server.stack.StackMessageBodyAdapter;
@@ -105,7 +104,11 @@ protected void configure() {
105104
bindConstant().annotatedWith(Names.named("machine.ws_agent.run_command"))
106105
.to("export JPDA_ADDRESS=\"4403\" && ~/che/ws-agent/bin/catalina.sh jpda run");
107106
bindConstant().annotatedWith(Names.named("machine.terminal_agent.run_command"))
108-
.to("$HOME/che/terminal/che-websocket-terminal -addr :4411 -cmd ${SHELL_INTERPRETER} -static $HOME/che/terminal/");
107+
.to("$HOME/che/terminal/che-websocket-terminal " +
108+
"-addr :4411 " +
109+
"-cmd ${SHELL_INTERPRETER} " +
110+
"-static $HOME/che/terminal/ " +
111+
"-logs-dir $HOME/che/exec-agent/logs");
109112
bind(org.eclipse.che.api.workspace.server.WorkspaceValidator.class)
110113
.to(org.eclipse.che.api.workspace.server.DefaultWorkspaceValidator.class);
111114

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/event/ng/ClientServerEventService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
*/
2626
@Singleton
2727
public class ClientServerEventService {
28-
private final RequestTransmitter transmitter;
2928
private final DtoFactory dtoFactory;
29+
private final RequestTransmitter requestTransmitter;
3030

3131
@Inject
32-
public ClientServerEventService(RequestTransmitter transmitter, EventBus eventBus, DtoFactory dtoFactory) {
33-
this.transmitter = transmitter;
32+
public ClientServerEventService(EventBus eventBus, DtoFactory dtoFactory,
33+
RequestTransmitter requestTransmitter) {
3434
this.dtoFactory = dtoFactory;
35+
this.requestTransmitter = requestTransmitter;
3536

3637
Log.debug(getClass(), "Adding file event listener");
3738
eventBus.addHandler(FileTrackingEvent.TYPE, new FileTrackingEvent.FileTrackingEventHandler() {
@@ -54,6 +55,7 @@ private void transmit(String path, String oldPath, FileTrackingOperationDto.Type
5455
.withType(type)
5556
.withOldPath(oldPath);
5657

57-
transmitter.transmitNotification(endpointId, method, dto);
58+
59+
requestTransmitter.transmitOneToNone(endpointId, method, dto);
5860
}
5961
}

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/event/ng/EditorFileStatusNotificationHandler.java renamed to ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/event/ng/EditorFileStatusNotificationOperation.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import org.eclipse.che.ide.api.event.FileContentUpdateEvent;
2020
import org.eclipse.che.ide.api.notification.NotificationManager;
2121
import org.eclipse.che.ide.api.resources.ExternalResourceDelta;
22-
import org.eclipse.che.ide.jsonrpc.RequestHandler;
22+
import org.eclipse.che.ide.jsonrpc.JsonRpcRequestBiOperation;
23+
import org.eclipse.che.ide.jsonrpc.RequestHandlerConfigurator;
2324
import org.eclipse.che.ide.resource.Path;
2425
import org.eclipse.che.ide.util.loging.Log;
2526

@@ -39,7 +40,7 @@
3940
* @author Dmitry Kuleshov
4041
*/
4142
@Singleton
42-
public class EditorFileStatusNotificationHandler extends RequestHandler<VfsFileStatusUpdateDto, Void> {
43+
public class EditorFileStatusNotificationOperation implements JsonRpcRequestBiOperation<VfsFileStatusUpdateDto> {
4344

4445
private final EventBus eventBus;
4546
private final DeletedFilesController deletedFilesController;
@@ -48,22 +49,26 @@ public class EditorFileStatusNotificationHandler extends RequestHandler<VfsFileS
4849
private NotificationManager notificationManager;
4950

5051
@Inject
51-
public EditorFileStatusNotificationHandler(EventBus eventBus,
52-
DeletedFilesController deletedFilesController,
53-
AppContext appContext) {
54-
super(VfsFileStatusUpdateDto.class, Void.class);
52+
public EditorFileStatusNotificationOperation(EventBus eventBus, DeletedFilesController deletedFilesController, AppContext appContext) {
5553
this.eventBus = eventBus;
5654
this.deletedFilesController = deletedFilesController;
5755
this.appContext = appContext;
56+
}
5857

58+
@Inject
59+
public void configureHandler(RequestHandlerConfigurator configurator) {
60+
configurator.newConfiguration()
61+
.methodName("event:file-in-vfs-status-changed")
62+
.paramsAsDto(VfsFileStatusUpdateDto.class)
63+
.noResult()
64+
.withOperation(this);
5965
}
6066

6167
public void inject(NotificationManager notificationManager) {
6268
this.notificationManager = notificationManager;
6369
}
6470

65-
@Override
66-
public void handleNotification(String endpointId, VfsFileStatusUpdateDto params) {
71+
public void apply(String endpointId, VfsFileStatusUpdateDto params) {
6772
final FileWatcherEventType status = params.getType();
6873
final String stringPath = params.getPath();
6974
final String name = stringPath.substring(stringPath.lastIndexOf("/") + 1);

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/event/ng/JsonRpcWebSocketAgentEventListener.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,25 @@ public void run() {
6262

6363
private void internalInitialize() {
6464
DevMachine devMachine = appContext.getDevMachine();
65+
String devMachineId = devMachine.getId();
6566
String wsAgentWebSocketUrl = devMachine.getWsAgentWebSocketUrl();
6667

6768
String wsAgentUrl = wsAgentWebSocketUrl.replaceFirst("(api)(/)(ws)", "websocket" + "$2" + ENDPOINT_ID);
69+
String execAgentUrl = devMachine.getExecAgentUrl();
70+
6871

6972
initializer.initialize("ws-agent", singletonMap("url", wsAgentUrl));
73+
initializer.initialize(devMachineId, singletonMap("url", execAgentUrl));
7074
}
7175

7276
@Override
7377
public void onWsAgentStopped(WsAgentStateEvent event) {
78+
DevMachine devMachine = appContext.getDevMachine();
79+
String devMachineId = devMachine.getId();
80+
7481
Log.debug(JsonRpcWebSocketAgentEventListener.class, "Web socket agent stopped event caught.");
7582

7683
initializer.terminate("ws-agent");
84+
initializer.terminate(devMachineId);
7785
}
7886
}

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/event/ng/ProjectTreeStatusNotificationHandler.java renamed to ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/event/ng/ProjectTreeStatusNotificationOperation.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import org.eclipse.che.ide.api.app.AppContext;
1717
import org.eclipse.che.ide.api.resources.Container;
1818
import org.eclipse.che.ide.api.resources.ExternalResourceDelta;
19-
import org.eclipse.che.ide.jsonrpc.RequestHandler;
19+
import org.eclipse.che.ide.jsonrpc.JsonRpcException;
20+
import org.eclipse.che.ide.jsonrpc.JsonRpcRequestBiOperation;
21+
import org.eclipse.che.ide.jsonrpc.RequestHandlerConfigurator;
2022
import org.eclipse.che.ide.resource.Path;
2123
import org.eclipse.che.ide.util.loging.Log;
2224

@@ -35,18 +37,25 @@
3537
* @author Dmitry Kuleshov
3638
*/
3739
@Singleton
38-
public class ProjectTreeStatusNotificationHandler extends RequestHandler<ProjectTreeStatusUpdateDto, Void> {
40+
public class ProjectTreeStatusNotificationOperation implements JsonRpcRequestBiOperation<ProjectTreeStatusUpdateDto> {
3941
private final AppContext appContext;
4042

4143
@Inject
42-
public ProjectTreeStatusNotificationHandler(AppContext appContext) {
43-
super(ProjectTreeStatusUpdateDto.class, Void.class);
44+
public ProjectTreeStatusNotificationOperation(AppContext appContext) {
4445
this.appContext = appContext;
4546
}
4647

48+
@Inject
49+
public void configureHandler(RequestHandlerConfigurator configurator) {
50+
configurator.newConfiguration()
51+
.methodName("event:project-tree-status-changed")
52+
.paramsAsDto(ProjectTreeStatusUpdateDto.class)
53+
.noResult()
54+
.withOperation(this);
55+
}
4756

4857
@Override
49-
public void handleNotification(String endpointId, ProjectTreeStatusUpdateDto params) {
58+
public void apply(String endpointId, ProjectTreeStatusUpdateDto params) throws JsonRpcException {
5059
final String path = params.getPath();
5160
final FileWatcherEventType type = params.getType();
5261

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/machine/DevMachine.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public boolean isDev() {
6969
return true;
7070
}
7171

72-
@Override
7372
public String getType() {
7473
return devMachineDescriptor.getConfig().getType();
7574
}
@@ -96,7 +95,6 @@ public String getWsAgentWebSocketUrl() {
9695
throw new RuntimeException(message);
9796
}
9897

99-
@Override
10098
public String getTerminalUrl() {
10199
for (Link link : devMachineLinks) {
102100
if (Constants.TERMINAL_REFERENCE.equals(link.getRel())) {
@@ -109,6 +107,18 @@ public String getTerminalUrl() {
109107
throw new RuntimeException(message);
110108
}
111109

110+
public String getExecAgentUrl() {
111+
for (Link link : devMachineLinks) {
112+
if (Constants.EXEC_AGENT_REFERENCE.equals(link.getRel())) {
113+
return link.getHref();
114+
}
115+
}
116+
//should not be
117+
final String message = "Reference " + Constants.EXEC_AGENT_REFERENCE + " not found in DevMachine description";
118+
Log.error(getClass(), message);
119+
throw new RuntimeException(message);
120+
}
121+
112122
/**
113123
*
114124
* @return return base URL to the ws agent REST services. URL will be always without trailing slash
@@ -155,7 +165,6 @@ public MachineConfig getConfig() {
155165
return machineConfig;
156166
}
157167

158-
@Override
159168
public String getId() {
160169
return devMachineDescriptor.getId();
161170
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012-2016 Codenvy, S.A.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Codenvy, S.A. - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.che.ide.api.machine;
12+
13+
import org.eclipse.che.api.core.model.machine.Command;
14+
import org.eclipse.che.api.machine.shared.dto.execagent.GetProcessLogsResponseDto;
15+
import org.eclipse.che.api.machine.shared.dto.execagent.GetProcessResponseDto;
16+
import org.eclipse.che.api.machine.shared.dto.execagent.GetProcessesResponseDto;
17+
import org.eclipse.che.api.machine.shared.dto.execagent.ProcessKillResponseDto;
18+
import org.eclipse.che.api.machine.shared.dto.execagent.ProcessStartResponseDto;
19+
import org.eclipse.che.api.machine.shared.dto.execagent.ProcessSubscribeResponseDto;
20+
import org.eclipse.che.api.machine.shared.dto.execagent.ProcessUnSubscribeResponseDto;
21+
import org.eclipse.che.api.machine.shared.dto.execagent.UpdateSubscriptionResponseDto;
22+
import org.eclipse.che.api.promises.client.Promise;
23+
import org.eclipse.che.ide.api.machine.execagent.ExecAgentPromise;
24+
25+
import java.util.List;
26+
27+
/**
28+
* Manages calls to exec agent that are related to processes, subscription, etc.
29+
*
30+
* @author Dmitry Kuleshov
31+
*/
32+
public interface ExecAgentCommandManager {
33+
/**
34+
* Call to exec agent to start a process with specified command parameters
35+
*
36+
* @param endpointId
37+
* endpoint identifier
38+
* @param command
39+
* command
40+
*
41+
* @return exec agent promise with appropriate dto
42+
*/
43+
ExecAgentPromise<ProcessStartResponseDto> startProcess(String endpointId, Command command);
44+
45+
/**
46+
* Call exec agent to kill a process with specified identifier
47+
*
48+
* @param endpointId
49+
* endpoint identifier
50+
* @param pid
51+
* process identifier
52+
*
53+
* @return promise with appropriate dto
54+
*/
55+
Promise<ProcessKillResponseDto> killProcess(String endpointId, int pid);
56+
57+
/**
58+
* Call for a subscription to events related to a specified process after defined timestamp
59+
* represented by a corresponding string (RFC3339Nano e.g. "2016-07-26T09:36:44.920890113+03:00").
60+
*
61+
* @param endpointId
62+
* endpoint identifier
63+
* @param pid
64+
* process identifier
65+
* @param eventTypes
66+
* event types (e.g. stderr, stdout)
67+
* @param after
68+
* after timestamp
69+
*
70+
* @return exec agent promise with appropriate dto
71+
*/
72+
ExecAgentPromise<ProcessSubscribeResponseDto> subscribe(String endpointId, int pid, List<String> eventTypes, String after);
73+
74+
/**
75+
* Call for a cancellation of a subscription to events related to a specific process after defined
76+
* timestamp represented by a corresponding string (RFC3339Nano e.g. "2016-07-26T09:36:44.920890113+03:00").
77+
*
78+
* @param endpointId
79+
* endpoint identifier
80+
* @param pid
81+
* process identifier
82+
* @param eventTypes
83+
* event types (e.g. stderr, stdout)
84+
* @param after
85+
* after timestamp
86+
*
87+
* @return promise with appropriate dto
88+
*/
89+
Promise<ProcessUnSubscribeResponseDto> unsubscribe(String endpointId, int pid, List<String> eventTypes, String after);
90+
91+
/**
92+
* Call for an update of a subscription to events related to a specific process.
93+
*
94+
* @param endpointId
95+
* endpoint identifier
96+
* @param pid
97+
* process identifier
98+
* @param eventTypes
99+
* event types (e.g. stderr, stdout)
100+
*
101+
* @return promise with appropriate dto
102+
*/
103+
Promise<UpdateSubscriptionResponseDto> updateSubscription(String endpointId, int pid, List<String> eventTypes);
104+
105+
/**
106+
* Call for a report on proess logs of a specific process.
107+
*
108+
* @param endpointId
109+
* endpoint identifier
110+
* @param pid
111+
* process identifier
112+
* @param from
113+
* string represented timestamp the beginning of a time
114+
* segment (RFC3339Nano e.g. "2016-07-26T09:36:44.920890113+03:00")
115+
* @param till
116+
* string represented timestamp the ending of a time
117+
* segment (RFC3339Nano e.g. "2016-07-26T09:36:44.920890113+03:00")
118+
* @param limit
119+
* the limit of logs in result, the default value is 50
120+
* @param skip
121+
* the logs to skip, default value is 0
122+
*
123+
* @return promise with appropriate dto
124+
*/
125+
Promise<List<GetProcessLogsResponseDto>> getProcessLogs(String endpointId, int pid, String from, String till, int limit, int skip);
126+
127+
/**
128+
* Call for a process info
129+
*
130+
* @param endpointId
131+
* endpoint identifier
132+
* @param pid
133+
* process identifier
134+
*
135+
* @return promise with appropriate dto
136+
*/
137+
Promise<GetProcessResponseDto> getProcess(String endpointId, int pid);
138+
139+
/**
140+
* Call for a process info
141+
*
142+
* @param endpointId
143+
* endpoint identifier
144+
* @param all
145+
* defines if include already stopped processes, true for all,
146+
* processes and false for running processes
147+
*
148+
* @return promise with appropriate dto
149+
*/
150+
Promise<List<GetProcessesResponseDto>> getProcesses(String endpointId, boolean all);
151+
}

0 commit comments

Comments
 (0)