Skip to content

Commit

Permalink
Merge pull request #7 from SuZhou-Joe/feature/workspace-service-imple…
Browse files Browse the repository at this point in the history
…ment

Workspace service implement
  • Loading branch information
SuZhou-Joe authored Jun 13, 2023
2 parents 3c5df9d + 666bb2f commit 9c8b378
Show file tree
Hide file tree
Showing 12 changed files with 644 additions and 34 deletions.
9 changes: 9 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,12 @@ export {
};

export { __osdBootstrap__ } from './osd_bootstrap';

export {
WorkspacesClientContract,
WorkspacesClient,
WorkspacesStart,
WorkspacesService,
WorkspaceAttribute,
WorkspaceFindOptions,
} from './workspace';
62 changes: 28 additions & 34 deletions src/core/public/workspace/workspaces_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,33 @@ export class WorkspacesClient {
}

public async enterWorkspace(id: string): Promise<IResponse<null>> {
return {
success: false,
error: 'Unimplement',
};
return this.http.post(this.getPath(['_enter', id]));
}

public async exitWorkspace(): Promise<IResponse<null>> {
return {
success: false,
error: 'Unimplement',
};
return this.http.post(this.getPath(['_exit']));
}

public async getCurrentWorkspaceId(): Promise<IResponse<WorkspaceAttribute['id']>> {
return {
success: false,
error: 'Unimplement',
};
const currentWorkspaceIdResp = await this.http.get(this.getPath(['_current']));
if (currentWorkspaceIdResp.success && !currentWorkspaceIdResp.result) {
return {
success: false,
error: 'You are not in any workspace yet.',
};
}

return currentWorkspaceIdResp;
}

public async getCurrentWorkspace(): Promise<IResponse<WorkspaceAttribute>> {
return {
success: false,
error: 'Unimplement',
};
const currentWorkspaceIdResp = await this.getCurrentWorkspaceId();
if (currentWorkspaceIdResp.success) {
const currentWorkspaceResp = await this.get(currentWorkspaceIdResp.result);
return currentWorkspaceResp;
} else {
return currentWorkspaceIdResp;
}
}

/**
Expand Down Expand Up @@ -127,13 +129,12 @@ export class WorkspacesClient {
public list = (
options?: WorkspaceFindOptions
): Promise<
IResponse<
WorkspaceAttribute & {
total: number;
perPage: number;
page: number;
}
>
IResponse<{
workspaces: WorkspaceAttribute[];
total: number;
per_page: number;
page: number;
}>
> => {
const path = this.getPath(['_list']);
return this.http.fetch(path, {
Expand Down Expand Up @@ -176,16 +177,9 @@ export class WorkspacesClient {
attributes,
};

return this.http
.fetch(path, {
method: 'PUT',
body: JSON.stringify(body),
})
.then((resp: WorkspaceAttribute) => {
return {
result: true,
success: true,
};
});
return this.http.fetch(path, {
method: 'PUT',
body: JSON.stringify(body),
});
}
}
3 changes: 3 additions & 0 deletions src/core/server/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { InternalStatusServiceSetup } from './status';
import { AuditTrailSetup, AuditTrailStart } from './audit_trail';
import { InternalLoggingServiceSetup } from './logging';
import { CoreUsageDataStart } from './core_usage_data';
import { InternalWorkspacesServiceSetup, InternalWorkspacesServiceStart } from './workspaces';

/** @internal */
export interface InternalCoreSetup {
Expand All @@ -64,6 +65,7 @@ export interface InternalCoreSetup {
auditTrail: AuditTrailSetup;
logging: InternalLoggingServiceSetup;
metrics: InternalMetricsServiceSetup;
workspaces: InternalWorkspacesServiceSetup;
}

/**
Expand All @@ -78,6 +80,7 @@ export interface InternalCoreStart {
uiSettings: InternalUiSettingsServiceStart;
auditTrail: AuditTrailStart;
coreUsageData: CoreUsageDataStart;
workspaces: InternalWorkspacesServiceStart;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { RequestHandlerContext } from '.';
import { InternalCoreSetup, InternalCoreStart, ServiceConfigDescriptor } from './internal_types';
import { CoreUsageDataService } from './core_usage_data';
import { CoreRouteHandlerContext } from './core_route_handler_context';
import { WorkspacesService } from './workspaces';

const coreId = Symbol('core');
const rootConfigPath = '';
Expand All @@ -86,6 +87,7 @@ export class Server {
private readonly coreApp: CoreApp;
private readonly auditTrail: AuditTrailService;
private readonly coreUsageData: CoreUsageDataService;
private readonly workspaces: WorkspacesService;

#pluginsInitialized?: boolean;
private coreStart?: InternalCoreStart;
Expand Down Expand Up @@ -118,6 +120,7 @@ export class Server {
this.auditTrail = new AuditTrailService(core);
this.logging = new LoggingService(core);
this.coreUsageData = new CoreUsageDataService(core);
this.workspaces = new WorkspacesService(core);
}

public async setup() {
Expand Down Expand Up @@ -172,6 +175,11 @@ export class Server {

const metricsSetup = await this.metrics.setup({ http: httpSetup });

const workspacesSetup = await this.workspaces.setup({
http: httpSetup,
savedObject: savedObjectsSetup,
});

const statusSetup = await this.status.setup({
opensearch: opensearchServiceSetup,
pluginDependencies: pluginTree.asNames,
Expand Down Expand Up @@ -212,6 +220,7 @@ export class Server {
auditTrail: auditTrailSetup,
logging: loggingSetup,
metrics: metricsSetup,
workspaces: workspacesSetup,
};

const pluginsSetup = await this.plugins.setup(coreSetup);
Expand Down Expand Up @@ -253,6 +262,9 @@ export class Server {
opensearch: opensearchStart,
savedObjects: savedObjectsStart,
});
const workspacesStart = await this.workspaces.start({
savedObjects: savedObjectsStart,
});

this.coreStart = {
capabilities: capabilitiesStart,
Expand All @@ -263,6 +275,7 @@ export class Server {
uiSettings: uiSettingsStart,
auditTrail: auditTrailStart,
coreUsageData: coreUsageDataStart,
workspaces: workspacesStart,
};

const pluginsStart = await this.plugins.start(this.coreStart);
Expand Down Expand Up @@ -295,6 +308,7 @@ export class Server {
await this.status.stop();
await this.logging.stop();
await this.auditTrail.stop();
await this.workspaces.stop();
}

private registerCoreContext(coreSetup: InternalCoreSetup) {
Expand Down
1 change: 1 addition & 0 deletions src/core/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ export * from './ui_settings/types';
export * from './legacy/types';
export type { EnvironmentMode, PackageInfo } from '@osd/config';
export { Branding } from '../../core/types';
export * from './workspaces/types';
13 changes: 13 additions & 0 deletions src/core/server/workspaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
export {
WorkspacesService,
InternalWorkspacesServiceSetup,
WorkspacesServiceStart,
WorkspacesServiceSetup,
InternalWorkspacesServiceStart,
} from './workspaces_service';

export { WorkspaceAttribute, WorkspaceFindOptions, WORKSPACES_API_BASE_URL } from './types';
Loading

0 comments on commit 9c8b378

Please sign in to comment.