forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix eclipse-che#3967 : replace WSMaster Machine API by Exec Agent calls
Change-Id: I67e9d668516bf634c47e72653086e93ef34d5fe9 Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
- Loading branch information
Showing
15 changed files
with
431 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
dockerfiles/lib/src/api/exec-agent/exec-agent-service-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2016-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*/ | ||
import {org} from "../../api/dto/che-dto"; | ||
import {ProcessTerminatedEventPromiseMessageBusSubscriber} from "./process-terminated-event-promise-subscriber"; | ||
import {AuthData} from "../wsmaster/auth/auth-data"; | ||
import {Websocket} from "../../spi/websocket/websocket"; | ||
import {Workspace} from "../wsmaster/workspace/workspace"; | ||
import {CheFileStructWorkspaceCommand} from "../../internal/dir/chefile-struct/che-file-struct"; | ||
import {Log} from "../../spi/log/log"; | ||
import {JsonRpcBus} from "../../spi/websocket/json-rpc-bus"; | ||
import {ProcessAckPromiseMessageBusSubscriber} from "./process-ack-event-promise-subscriber"; | ||
|
||
/** | ||
* Exec Agent service allowing to start/stop processes | ||
* @author Florent Benoit | ||
*/ | ||
export class ExecAgentServiceClientImpl { | ||
|
||
/** | ||
* Authentication data | ||
*/ | ||
authData : AuthData; | ||
|
||
/** | ||
* websocket. | ||
*/ | ||
websocket : Websocket; | ||
|
||
workspace : Workspace; | ||
|
||
constructor(workspace : Workspace, authData : AuthData) { | ||
this.workspace = workspace; | ||
this.authData = authData; | ||
this.websocket = new Websocket(); | ||
} | ||
|
||
getJsonRpcBus(workspaceDto : org.eclipse.che.api.workspace.shared.dto.WorkspaceDto): Promise<JsonRpcBus> { | ||
var protocol:string; | ||
if (this.authData.isSecured()) { | ||
protocol = 'wss'; | ||
} else { | ||
protocol = 'ws'; | ||
} | ||
|
||
// get links for WS | ||
var link:string = protocol + '://' + this.authData.hostname + ":" + this.authData.port + '/connect'; | ||
|
||
return this.websocket.getJsonRpcBus(link + '?token=' + this.authData.getToken()); | ||
} | ||
|
||
/** | ||
* Create a workspace and return a promise with content of WorkspaceDto in case of success | ||
*/ | ||
executeCommand(workspaceDto : org.eclipse.che.api.workspace.shared.dto.WorkspaceDto, | ||
machineId:string, | ||
cheFileStructWorkspaceCommand:CheFileStructWorkspaceCommand, | ||
uuid:string, | ||
asynchronous : boolean = true):Promise<boolean> { | ||
|
||
let rpcCommand: any = | ||
{ | ||
"jsonrpc": "2.0", | ||
"method": "process.start", | ||
"id": uuid, | ||
"params": { | ||
"commandLine": cheFileStructWorkspaceCommand.commandLine, | ||
"name": !cheFileStructWorkspaceCommand.name ? "custom-command" : cheFileStructWorkspaceCommand.name, | ||
"type": !cheFileStructWorkspaceCommand.type ? "custom" : cheFileStructWorkspaceCommand.type | ||
} | ||
}; | ||
|
||
// get JSON RPC Bus | ||
let processTerminatedEventPromiseMessageBusSubscriber : ProcessTerminatedEventPromiseMessageBusSubscriber; | ||
let userJsonRpcBus : JsonRpcBus; | ||
return this.getJsonRpcBus(workspaceDto).then((jsonRpcBus:JsonRpcBus) => { | ||
userJsonRpcBus = jsonRpcBus; | ||
processTerminatedEventPromiseMessageBusSubscriber = new ProcessTerminatedEventPromiseMessageBusSubscriber(jsonRpcBus); | ||
let processAckPromiseMessageBusSubscriber : ProcessAckPromiseMessageBusSubscriber = new ProcessAckPromiseMessageBusSubscriber(uuid, jsonRpcBus, asynchronous, processTerminatedEventPromiseMessageBusSubscriber); | ||
jsonRpcBus.subscribe(processAckPromiseMessageBusSubscriber); | ||
jsonRpcBus.send(rpcCommand); | ||
return processAckPromiseMessageBusSubscriber.promise; | ||
}).then(() => { | ||
// subscribe to pid event end | ||
if (asynchronous) { | ||
return processTerminatedEventPromiseMessageBusSubscriber.promise; | ||
} else { | ||
// do not wait the end | ||
userJsonRpcBus.close(); | ||
return Promise.resolve(true); | ||
} | ||
}).then(() => { | ||
return true; | ||
}); | ||
|
||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
dockerfiles/lib/src/api/exec-agent/process-ack-event-promise-subscriber.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2016-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*/ | ||
|
||
import {MessageBusSubscriber} from "../../spi/websocket/messagebus-subscriber"; | ||
import {ProcessTerminatedEventPromiseMessageBusSubscriber} from "./process-terminated-event-promise-subscriber"; | ||
import {JsonRpcBus} from "../../spi/websocket/json-rpc-bus"; | ||
import {ProcesLogOutputMessageBusSubscriber} from "./process-log-output-subscriber"; | ||
import {Log} from "../../spi/log/log"; | ||
/** | ||
* Handle a promise that will be resolved when process/command is finished. | ||
* If process has error, promise will be rejected | ||
* @author Florent Benoit | ||
*/ | ||
export class ProcessAckPromiseMessageBusSubscriber implements MessageBusSubscriber { | ||
|
||
resolve : any; | ||
reject : any; | ||
promise: Promise<boolean>; | ||
private id : string; | ||
private processTerminatedEventPromiseMessageBusSubscriber : ProcessTerminatedEventPromiseMessageBusSubscriber; | ||
private asynchronous : boolean; | ||
private jsonRpcBus : JsonRpcBus; | ||
|
||
constructor(id: string, jsonRpcBus : JsonRpcBus, asynchronous : boolean, processTerminatedEventPromiseMessageBusSubscriber : ProcessTerminatedEventPromiseMessageBusSubscriber) { | ||
this.id = id; | ||
this.jsonRpcBus = jsonRpcBus; | ||
this.asynchronous = asynchronous; | ||
this.processTerminatedEventPromiseMessageBusSubscriber = processTerminatedEventPromiseMessageBusSubscriber; | ||
this.promise = new Promise<boolean>((resolve, reject) => { | ||
this.resolve = resolve; | ||
this.reject = reject; | ||
}); | ||
} | ||
|
||
handleMessage(event: any) { | ||
if (event.id && event.id === this.id) { | ||
if (event.result) { | ||
this.processTerminatedEventPromiseMessageBusSubscriber.setPid(event.result.pid); | ||
// subscribe to websocket | ||
if (this.asynchronous) { | ||
this.jsonRpcBus.subscribe(new ProcesLogOutputMessageBusSubscriber(event.result.pid)); | ||
this.jsonRpcBus.subscribe(this.processTerminatedEventPromiseMessageBusSubscriber); | ||
} | ||
this.resolve(true); | ||
} else if (event.error) { | ||
this.reject(event.error); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
dockerfiles/lib/src/api/exec-agent/process-terminated-event-promise-subscriber.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2016-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*/ | ||
|
||
import {MessageBusSubscriber} from "../../spi/websocket/messagebus-subscriber"; | ||
import {Log} from "../../spi/log/log"; | ||
import {JsonRpcBus} from "../../spi/websocket/json-rpc-bus"; | ||
/** | ||
* Handle a promise that will be resolved when process/command is finished. | ||
* If process has error, promise will be rejected | ||
* @author Florent Benoit | ||
*/ | ||
export class ProcessTerminatedEventPromiseMessageBusSubscriber implements MessageBusSubscriber { | ||
|
||
resolve : any; | ||
reject : any; | ||
promise: Promise<boolean>; | ||
private pid : number; | ||
private jsonRpcBus; | ||
|
||
constructor(jsonRpcBus : JsonRpcBus) { | ||
this.jsonRpcBus = jsonRpcBus; | ||
this.promise = new Promise<boolean>((resolve, reject) => { | ||
this.resolve = resolve; | ||
this.reject = reject; | ||
}); | ||
} | ||
|
||
handleMessage(event: any) { | ||
if (this.pid) { | ||
if ('process_died' === event.method && event.params && event.params.pid === this.pid) { | ||
this.jsonRpcBus.close(); | ||
this.resolve(true); | ||
} | ||
} | ||
} | ||
|
||
setPid(pid : number) { | ||
this.pid = pid; | ||
} | ||
|
||
} |
104 changes: 0 additions & 104 deletions
104
dockerfiles/lib/src/api/wsmaster/machine/machine-service-client.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.