How to use rsp-client - 10 common examples

To help you get started, we’ve selected a few rsp-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github redhat-developer / vscode-rsp-ui / src / serverExplorer.ts View on Github external
return;
            }

            // var fileUrl = require('file-url');
            // const filePath : string = fileUrl(file[0].fsPath);
            const deployableRef: Protocol.DeployableReference = {
                label: file[0].fsPath,
                path: file[0].fsPath,
                options: options
            };
            const req: Protocol.ServerDeployableReference = {
                server: state.server,
                deployableReference : deployableRef
            };
            const status = await client.getOutgoingHandler().addDeployable(req);
            if (!StatusSeverity.isOk(status)) {
                return Promise.reject(status.message);
            }
            return status;
        }
    }
github redhat-developer / vscode-rsp-ui / src / serverExplorer.ts View on Github external
const state: RSPState = item as RSPState;
            const id1: string = state.type.visibilename;
            const serverState = `${this.runStateEnum.get(state.state)}`;
            const depStr = `${id1} (${serverState})`;
            const icon = await Utils.getIcon(state.type.id, state.type.id);
            return { label: `${depStr}`,
                iconPath: icon,
                contextValue: `RSP${serverState}`,
                collapsibleState: TreeItemCollapsibleState.Expanded
            };
        } else if (this.isServerElement(item)) {
            // item is a serverState
            const state: ServerStateNode = item as ServerStateNode;
            const handle: Protocol.ServerHandle = state.server;
            const id1: string = handle.id;
            const serverState: string = (state.state === ServerState.STARTED && state.runMode === ServerState.RUN_MODE_DEBUG) ?
                                    'Debugging' :
                                    this.runStateEnum.get(state.state);
            const pubState: string = this.publishStateEnum.get(state.publishState);
            const depStr = `${id1} (${serverState}) (${pubState})`;
            const icon = await Utils.getIcon(state.rsp, handle.type.id);
            return { label: `${depStr}`,
                iconPath: icon,
                contextValue: serverState,
                collapsibleState: TreeItemCollapsibleState.Expanded,
                command: {
                    command: 'server.saveSelectedNode',
                    title: '',
                    tooltip: '',
                    arguments: [ state ]
                }
            };
github redhat-developer / vscode-rsp-ui / src / extensionApi.ts View on Github external
await rspProvider.stopRSP().catch(err => {
                    // if stopRSP fails, server is still running
                    this.explorer.updateRSPServer(context.type.id, ServerState.STARTED);
                    return Promise.reject(`Failed to terminate ${context.type.visibilename} - ${err}`);
                });
            }
github redhat-developer / vscode-rsp-ui / src / extensionApi.ts View on Github external
private async handleWorkflow(response: Protocol.WorkflowResponse, workflowMap?: { [index: string]: any } ): Promise {
        if (StatusSeverity.isError(response.status)
                    || StatusSeverity.isCancel(response.status)) {
            // error
            return Promise.reject(response.status);
        }

        // not complete, not an error.
        if (!workflowMap) {
            workflowMap = {};
        }
        if (response.items) {
            for (const item of response.items) {
                const strategy: WorkflowResponseStrategy = new WorkflowResponseStrategyManager().getStrategy(item.itemType);
                const canceled: boolean = await strategy.handler(item, workflowMap);
                if (canceled) {
                    return;
                }
            }
github redhat-developer / vscode-rsp-ui / src / extensionApi.ts View on Github external
private async handleWorkflow(response: Protocol.WorkflowResponse, workflowMap?: { [index: string]: any } ): Promise {
        if (StatusSeverity.isError(response.status)
                    || StatusSeverity.isCancel(response.status)) {
            // error
            return Promise.reject(response.status);
        }

        // not complete, not an error.
        if (!workflowMap) {
            workflowMap = {};
        }
        if (response.items) {
            for (const item of response.items) {
                const strategy: WorkflowResponseStrategy = new WorkflowResponseStrategyManager().getStrategy(item.itemType);
                const canceled: boolean = await strategy.handler(item, workflowMap);
                if (canceled) {
                    return;
                }
github redhat-developer / vscode-rsp-ui / src / extensionApi.ts View on Github external
actionId: action.id,
            data: workflowMap,
            requestId: null,
            serverId: context.server.id
        };

        let response: Protocol.WorkflowResponse = await client.getOutgoingHandler().executeServerAction(actionRequest);
        if (!response) {
            return;
        }
        while (true) {
            const workflowMap = {};
            const status = await this.handleWorkflow(response, workflowMap);
            if (!status) {
                return;
            } else if (!StatusSeverity.isInfo(status)) {
                return status;
            }

            actionRequest.requestId = response.requestId;
            actionRequest.data = workflowMap;
            // Now we have a data map
            response = await client.getOutgoingHandler().executeServerAction(actionRequest);
        }
    }
github redhat-developer / vscode-rsp-ui / src / extensionApi.ts View on Github external
}

        const rtId: string = await this.promptDownloadableRuntimes(client);
        if (!rtId) {
            return;
        }
        let response: Protocol.WorkflowResponse = await this.initEmptyDownloadRuntimeRequest(rtId, client);
        if (!response) {
            return;
        }
        while (true) {
            const workflowMap = {};
            const status = await this.handleWorkflow(response, workflowMap);
            if (!status) {
                return;
            } else if (!StatusSeverity.isInfo(status)) {
                return status;
            }
            // Now we have a data map
            response = await this.initDownloadRuntimeRequest(rtId, workflowMap, response.requestId, client);
        }
    }
github redhat-developer / vscode-rsp-ui / src / extensionApi.ts View on Github external
if (!forced) {
                filterRSPPredicate = serverR => serverR.state.state === ServerState.STARTED;
            } else {
                filterRSPPredicate = serverR => serverR.state.state === ServerState.STARTED ||
                                             serverR.state.state === ServerState.STARTING ||
                                             serverR.state.state === ServerState.STOPPING;
            }
            const rsp = await this.selectRSP('Select RSP provider you want to start', filterRSPPredicate);
            if (!rsp || !rsp.id) return null;
            context = this.explorer.RSPServersStatus.get(rsp.id).state;
        }

        if (context.state === ServerState.STARTED
            || context.state === ServerState.STARTING
            || context.state === ServerState.STOPPING) {
            this.explorer.updateRSPServer(context.type.id, ServerState.STOPPING);

            if (!forced) {
                const client: RSPClient = this.explorer.getClientByRSP(context.type.id);
                if (!client) {
                    return Promise.reject(`Failed to contact the RSP server ${context.type.visibilename}.`);
                }
                client.shutdownServer();
            } else {
                const rspProvider: RSPController = await Utils.activateExternalProvider(context.type.id);
                await rspProvider.stopRSP().catch(err => {
                    // if stopRSP fails, server is still running
                    this.explorer.updateRSPServer(context.type.id, ServerState.STARTED);
                    return Promise.reject(`Failed to terminate ${context.type.visibilename} - ${err}`);
                });
            }
github redhat-developer / vscode-rsp-ui / test / protocolstubs.ts View on Github external
public static readonly rspState: RSPState = {
        serverStates: [ProtocolStubs.startedServerState],
        state: ServerState.UNKNOWN,
        type: ProtocolStubs.rspType
    };

    public static readonly rspProperties: RSPProperties = {
        client: undefined,
        rspserverstderr: undefined,
        rspserverstdout: undefined,
        state: ProtocolStubs.rspState
    };

    public static readonly rspStateStarted: RSPState = {
        serverStates: [],
        state: ServerState.STARTED,
        type: ProtocolStubs.rspType
    };

    public static readonly createResponseOK: Protocol.CreateServerResponse = {
        status: ProtocolStubs.okStatus,
        invalidKeys: []
    };

    public static readonly createResponseKO: Protocol.CreateServerResponse = {
        status: ProtocolStubs.errorStatus,
        invalidKeys: []
    };

    public static readonly updateServerResponse: Protocol.UpdateServerResponse = {
        handle: ProtocolStubs.serverHandle,
        validation: ProtocolStubs.createResponseOK,
github redhat-developer / vscode-rsp-ui / test / protocolstubs.ts View on Github external
public static readonly unknownServerState: ServerStateNode =  {
        server: ProtocolStubs.serverHandle,
        deployableStates: [],
        publishState: ServerState.PUBLISH_STATE_UNKNOWN,
        runMode: ServerState.RUN_MODE_RUN,
        state: ServerState.UNKNOWN,
        rsp: 'id'
    };

    public static readonly startedServerStateProtocol: Protocol.ServerState = {
        deployableStates: [],
        publishState: ServerState.PUBLISH_STATE_UNKNOWN,
        server: ProtocolStubs.serverHandle,
        runMode: ServerState.RUN_MODE_RUN,
        state: ServerState.STARTED
    };

    public static readonly deployableReference: Protocol.DeployableReference = {
        label: 'fake',
        path: 'fakepath'
    };

    public static readonly deployableStateNode: DeployableStateNode = {
        rsp: 'id',
        publishState: ServerState.PUBLISH_STATE_UNKNOWN,
        server: ProtocolStubs.serverHandle,
        state: ServerState.STARTED,
        reference: ProtocolStubs.deployableReference
    };

    public static readonly startedServerState: ServerStateNode = {