Skip to content

Commit

Permalink
Get plugins metadata wait until all plugins processed
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Apr 16, 2019
1 parent bed0eae commit a388fc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { injectable, inject } from 'inversify';
import { ILogger } from '@theia/core';
import { PluginDeployerHandler, PluginDeployerEntry, PluginMetadata } from '../../common/plugin-protocol';
import { HostedPluginReader } from './plugin-reader';
import { Deferred } from '@theia/core/lib/common/promise-util';

@injectable()
export class HostedPluginDeployerHandler implements PluginDeployerHandler {
Expand All @@ -31,47 +32,63 @@ export class HostedPluginDeployerHandler implements PluginDeployerHandler {
/**
* Managed plugin metadata backend entries.
*/
private readonly currentBackendPluginsMetadata: PluginMetadata[] = [];
private currentBackendPluginsMetadata: PluginMetadata[] = [];

/**
* Managed plugin metadata frontend entries.
*/
private readonly currentFrontendPluginsMetadata: PluginMetadata[] = [];
private currentFrontendPluginsMetadata: PluginMetadata[] = [];

getDeployedFrontendMetadata(): PluginMetadata[] {
private backendPluginsMetadataDeferred = new Deferred<void>();

private frontendPluginsMetadataDeferred = new Deferred<void>();

async getDeployedFrontendMetadata(): Promise<PluginMetadata[]> {
// await first deploy
await this.frontendPluginsMetadataDeferred.promise;
// fetch the last deployed state
return this.currentFrontendPluginsMetadata;
}

getDeployedBackendMetadata(): PluginMetadata[] {
async getDeployedBackendMetadata(): Promise<PluginMetadata[]> {
// await first deploy
await this.backendPluginsMetadataDeferred.promise;
// fetch the last deployed state
return this.currentBackendPluginsMetadata;
}

async deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[]): Promise<void> {
for (const plugin of frontendPlugins) {
const metadata = await this.reader.getPluginMetadata(plugin.path());
if (metadata) {
if (this.getDeployedFrontendMetadata().some(value => value.model.id === metadata.model.id)) {
if (this.currentFrontendPluginsMetadata.some(value => value.model.id === metadata.model.id)) {
continue;
}

this.currentFrontendPluginsMetadata.push(metadata);
this.logger.info(`Deploying frontend plugin "${metadata.model.name}@${metadata.model.version}" from "${metadata.model.entryPoint.frontend || plugin.path()}"`);
}
}

// resolve on first deploy
this.frontendPluginsMetadataDeferred.resolve(undefined);
}

async deployBackendPlugins(backendPlugins: PluginDeployerEntry[]): Promise<void> {
for (const plugin of backendPlugins) {
const metadata = await this.reader.getPluginMetadata(plugin.path());
if (metadata) {
if (this.getDeployedBackendMetadata().some(value => value.model.id === metadata.model.id)) {
if (this.currentBackendPluginsMetadata.some(value => value.model.id === metadata.model.id)) {
continue;
}

this.currentBackendPluginsMetadata.push(metadata);
this.logger.info(`Deploying backend plugin "${metadata.model.name}@${metadata.model.version}" from "${metadata.model.entryPoint.backend || plugin.path()}"`);
}
}

// resolve on first deploy
this.backendPluginsMetadataDeferred.resolve(undefined);
}

}
6 changes: 3 additions & 3 deletions packages/plugin-ext/src/hosted/node/plugin-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ export class HostedPluginServerImpl implements HostedPluginServer {
}

getDeployedFrontendMetadata(): Promise<PluginMetadata[]> {
return Promise.resolve(this.deployerHandler.getDeployedFrontendMetadata());
return this.deployerHandler.getDeployedFrontendMetadata();
}

async getDeployedMetadata(): Promise<PluginMetadata[]> {
const backendMetadata = this.deployerHandler.getDeployedBackendMetadata();
const backendMetadata = await this.deployerHandler.getDeployedBackendMetadata();
if (backendMetadata.length > 0) {
this.hostedPlugin.runPluginServer();
}
const allMetadata: PluginMetadata[] = [];
allMetadata.push(...this.deployerHandler.getDeployedFrontendMetadata());
allMetadata.push(...await this.deployerHandler.getDeployedFrontendMetadata());
allMetadata.push(...backendMetadata);

// ask remote as well
Expand Down

0 comments on commit a388fc5

Please sign in to comment.