From d4f578c55a347a93e80614599a0a702f2917c8b0 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Tue, 9 Jan 2024 12:24:54 +0200 Subject: [PATCH] [Task (IAC-805] Initial implementation of the vro categories lazy load. Signed-off-by: Alexander Kantchev --- extension/src/client/command/DeletePackage.ts | 2 +- .../src/client/command/FetchWorkflowSchema.ts | 2 +- extension/src/client/command/RunAction.ts | 2 +- extension/src/client/command/ShowActions.ts | 2 +- .../src/client/command/ShowConfigurations.ts | 2 +- extension/src/client/command/ShowResources.ts | 2 +- extension/src/client/command/ShowWorkflows.ts | 2 +- .../provider/content/ContentProvider.ts | 2 +- .../provider/explorer/ExplorerProvider.ts | 2 +- .../vrdt-common/src/rest/VroRestClient.ts | 44 +++++++++++++++---- .../request/collection/ServerCollection.ts | 2 +- 11 files changed, 45 insertions(+), 19 deletions(-) diff --git a/extension/src/client/command/DeletePackage.ts b/extension/src/client/command/DeletePackage.ts index 2d18c55d..665ee657 100644 --- a/extension/src/client/command/DeletePackage.ts +++ b/extension/src/client/command/DeletePackage.ts @@ -26,7 +26,7 @@ export class DeletePackage extends Command { constructor(config: ConfigurationManager, environment: EnvironmentManager) { super() - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } async execute(context: vscode.ExtensionContext, node: PackageNode): Promise { diff --git a/extension/src/client/command/FetchWorkflowSchema.ts b/extension/src/client/command/FetchWorkflowSchema.ts index 2e11a507..df631eb3 100644 --- a/extension/src/client/command/FetchWorkflowSchema.ts +++ b/extension/src/client/command/FetchWorkflowSchema.ts @@ -25,7 +25,7 @@ export class FetchWorkflowSchema extends Command { constructor(config: ConfigurationManager, environment: EnvironmentManager) { super() - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } async execute(context: vscode.ExtensionContext, node: WorkflowNode): Promise { diff --git a/extension/src/client/command/RunAction.ts b/extension/src/client/command/RunAction.ts index 4feb246a..88062709 100644 --- a/extension/src/client/command/RunAction.ts +++ b/extension/src/client/command/RunAction.ts @@ -225,7 +225,7 @@ class ActionRunner { private executionToken: string constructor(config: ConfigurationManager, private environment: EnvironmentManager) { - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) this.mavenProxy = new MavenCliProxy(environment, config.vrdev.maven, this.logger) } diff --git a/extension/src/client/command/ShowActions.ts b/extension/src/client/command/ShowActions.ts index 192b51f4..80b6e0c6 100644 --- a/extension/src/client/command/ShowActions.ts +++ b/extension/src/client/command/ShowActions.ts @@ -22,7 +22,7 @@ export class ShowActions extends Command { constructor(environment: EnvironmentManager, private config: ConfigurationManager) { super() - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } async execute(context: vscode.ExtensionContext): Promise { diff --git a/extension/src/client/command/ShowConfigurations.ts b/extension/src/client/command/ShowConfigurations.ts index 21f75cbd..21bcd403 100644 --- a/extension/src/client/command/ShowConfigurations.ts +++ b/extension/src/client/command/ShowConfigurations.ts @@ -22,7 +22,7 @@ export class ShowConfigurations extends Command { constructor(environment: EnvironmentManager, config: ConfigurationManager) { super() - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } async execute(context: vscode.ExtensionContext): Promise { diff --git a/extension/src/client/command/ShowResources.ts b/extension/src/client/command/ShowResources.ts index 93527eb0..c68e8cef 100644 --- a/extension/src/client/command/ShowResources.ts +++ b/extension/src/client/command/ShowResources.ts @@ -22,7 +22,7 @@ export class ShowResources extends Command { constructor(environment: EnvironmentManager, config: ConfigurationManager) { super() - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } async execute(context: vscode.ExtensionContext): Promise { diff --git a/extension/src/client/command/ShowWorkflows.ts b/extension/src/client/command/ShowWorkflows.ts index 966521d0..67727907 100644 --- a/extension/src/client/command/ShowWorkflows.ts +++ b/extension/src/client/command/ShowWorkflows.ts @@ -22,7 +22,7 @@ export class ShowWorkflows extends Command { constructor(environment: EnvironmentManager, config: ConfigurationManager) { super() - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } async execute(context: vscode.ExtensionContext): Promise { diff --git a/extension/src/client/provider/content/ContentProvider.ts b/extension/src/client/provider/content/ContentProvider.ts index 449b4d95..22d74bd7 100644 --- a/extension/src/client/provider/content/ContentProvider.ts +++ b/extension/src/client/provider/content/ContentProvider.ts @@ -24,7 +24,7 @@ export class ContentProvider implements vscode.TextDocumentContentProvider, Regi private readonly logger = Logger.get("ContentProvider") constructor(environment: EnvironmentManager, config: ConfigurationManager) { - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } dispose() { diff --git a/extension/src/client/provider/explorer/ExplorerProvider.ts b/extension/src/client/provider/explorer/ExplorerProvider.ts index 8d3bfcb5..c885e95f 100644 --- a/extension/src/client/provider/explorer/ExplorerProvider.ts +++ b/extension/src/client/provider/explorer/ExplorerProvider.ts @@ -33,7 +33,7 @@ export class ExplorerProvider implements vscode.TreeDataProvider, readonly onDidChangeTreeData: vscode.Event = this.onDidChangeTreeDataEmitter.event constructor(environment: EnvironmentManager, private config: ConfigurationManager) { - this.restClient = new VroRestClient(config, environment) + this.restClient = new VroRestClient(config) } register(context: vscode.ExtensionContext): void { diff --git a/packages/node/vrdt-common/src/rest/VroRestClient.ts b/packages/node/vrdt-common/src/rest/VroRestClient.ts index 5a455151..84698c5c 100644 --- a/packages/node/vrdt-common/src/rest/VroRestClient.ts +++ b/packages/node/vrdt-common/src/rest/VroRestClient.ts @@ -9,7 +9,7 @@ import * as fs from "fs-extra" import * as request from "request-promise-native" import { ApiCategoryType } from "../types" -import { BaseConfiguration, BaseEnvironment } from "../platform" +import { BaseConfiguration } from "../platform" import { Auth, BasicAuth, VraSsoAuth } from "./auth" import { ApiElement, @@ -22,14 +22,17 @@ import { WorkflowParam, WorkflowState } from "./vro-model" -import { Logger, MavenCliProxy, promise, sleep } from ".." +import { Logger, promise, sleep } from ".." import { HintAction, HintModule } from "../types/hint" export class VroRestClient { private readonly logger = Logger.get("VroRestClient") - private auth + private auth: Record | PromiseLike> + private hintActions: HintAction[] + private hintElements: ApiElement[] + private actions: any[] - constructor(private settings: BaseConfiguration, private environment: BaseEnvironment) { + constructor(private settings: BaseConfiguration) { this.auth = this.getInitialAuth() } @@ -80,7 +83,6 @@ export class VroRestClient { switch (this.authMethod.toLowerCase()) { case "vra": this.logger.info(`Token authentication chosen...`) - new MavenCliProxy(this.environment, this.settings.vrdev.maven, this.logger) if (this.vroUsername && this.vroPassword) { refreshToken = await this.getRefreshToken(this.vroUsername, this.vroPassword) } @@ -367,6 +369,10 @@ export class VroRestClient { } async getActions(): Promise<{ fqn: string; id: string; version: string }[]> { + // return the cached actions (if any) + if (this.actions && Array.isArray(this.actions) && this.actions.length) { + return this.actions + } const responseJson: ContentLinksResponse = await this.send("GET", "actions") const actions: { fqn: string; id: string; version: string }[] = responseJson.link .map(action => { @@ -388,7 +394,11 @@ export class VroRestClient { return !!val && val.fqn !== undefined && val.id !== undefined }) as { fqn: string; id: string; version: string }[] - return actions.sort((x, y) => x.fqn.localeCompare(y.fqn)) + actions.sort((x, y) => x.fqn.localeCompare(y.fqn)) + // cache the actions in order not to overload vRO + this.actions = actions + + return this.actions } async getWorkflows(): Promise<{ name: string; id: string; version: string }[]> { @@ -488,6 +498,11 @@ export class VroRestClient { } async getChildrenOfCategory(categoryId: string): Promise { + // return cached hint elements (if any) in order to not overload vRO + if (this.hintElements && Array.isArray(this.hintElements) && this.hintElements.length) { + return this.hintElements + } + const responseJson: ContentChildrenResponse = await this.send("GET", `categories/${categoryId}`) const children = responseJson.relations.link .map(child => { @@ -510,16 +525,24 @@ export class VroRestClient { return !!val && val.name !== undefined && val.id !== undefined && val.type !== undefined }) as ApiElement[] - return children.sort((x, y) => x.name.localeCompare(y.name)) + children.sort((x, y) => x.name.localeCompare(y.name)) + // cache the hint elements in order not to overload vRO REST API + this.hintElements = children + + return this.hintElements } async getChildrenOfCategoryWithDetails(categoryId: string): Promise { + // return cached hint actions (if any) in order to not overload vRO REST API + if (this.hintActions && Array.isArray(this.hintActions) && this.hintActions.length) { + return this.hintActions + } + let responseJson: HintModule = { id: "", name: "", actions: [] } - try { responseJson = await this.send("GET", `server-configuration/api/category/${categoryId}`) } catch (error) { @@ -541,8 +564,11 @@ export class VroRestClient { parameters: child.parameters || [] } as HintAction }) + children.sort((x, y) => x.name.localeCompare(y.name)) + // cache the hint actions in order not to overload vRO REST API + this.hintActions = children - return children.sort((x, y) => x.name.localeCompare(y.name)) + return this.hintActions } async getResource(id: string): Promise { diff --git a/packages/node/vro-language-server/src/server/request/collection/ServerCollection.ts b/packages/node/vro-language-server/src/server/request/collection/ServerCollection.ts index 6483be89..31682c5b 100644 --- a/packages/node/vro-language-server/src/server/request/collection/ServerCollection.ts +++ b/packages/node/vro-language-server/src/server/request/collection/ServerCollection.ts @@ -47,7 +47,7 @@ export class ServerCollection { connectionLocator.connection.onRequest(remote.server.triggerVroCollection, this.triggerCollection.bind(this)) - this.restClient = new VroRestClient(settings, environment) + this.restClient = new VroRestClient(settings) } giveCollectionStatus(): CollectionStatus {