Skip to content

Commit

Permalink
[Task (IAC-805] Initial implementation of the vro categories lazy load.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Kantchev <akantchev@vmware.com>
  • Loading branch information
akantchev committed Jan 9, 2024
1 parent 60bd232 commit d4f578c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion extension/src/client/command/DeletePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DeletePackage extends Command<void> {

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<void> {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/command/FetchWorkflowSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class FetchWorkflowSchema extends Command<void> {

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<void> {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/command/RunAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/command/ShowActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ShowActions extends Command<void> {

constructor(environment: EnvironmentManager, private config: ConfigurationManager) {
super()
this.restClient = new VroRestClient(config, environment)
this.restClient = new VroRestClient(config)
}

async execute(context: vscode.ExtensionContext): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/command/ShowConfigurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ShowConfigurations extends Command<void> {

constructor(environment: EnvironmentManager, config: ConfigurationManager) {
super()
this.restClient = new VroRestClient(config, environment)
this.restClient = new VroRestClient(config)
}

async execute(context: vscode.ExtensionContext): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/command/ShowResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ShowResources extends Command<void> {

constructor(environment: EnvironmentManager, config: ConfigurationManager) {
super()
this.restClient = new VroRestClient(config, environment)
this.restClient = new VroRestClient(config)
}

async execute(context: vscode.ExtensionContext): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/command/ShowWorkflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ShowWorkflows extends Command<void> {

constructor(environment: EnvironmentManager, config: ConfigurationManager) {
super()
this.restClient = new VroRestClient(config, environment)
this.restClient = new VroRestClient(config)
}

async execute(context: vscode.ExtensionContext): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/provider/content/ContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/client/provider/explorer/ExplorerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ExplorerProvider implements vscode.TreeDataProvider<AbstractNode>,
readonly onDidChangeTreeData: vscode.Event<AbstractNode | undefined> = 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 {
Expand Down
44 changes: 35 additions & 9 deletions packages/node/vrdt-common/src/rest/VroRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string, unknown> | PromiseLike<Record<string, unknown>>
private hintActions: HintAction[]
private hintElements: ApiElement[]
private actions: any[]

constructor(private settings: BaseConfiguration, private environment: BaseEnvironment) {
constructor(private settings: BaseConfiguration) {
this.auth = this.getInitialAuth()
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 }[]> {
Expand Down Expand Up @@ -488,6 +498,11 @@ export class VroRestClient {
}

async getChildrenOfCategory(categoryId: string): Promise<ApiElement[]> {
// 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 => {
Expand All @@ -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<HintAction[]> {
// 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) {
Expand All @@ -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<http.IncomingMessage> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d4f578c

Please sign in to comment.