Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] Remove absolute local path from esqueue payload #28741

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions x-pack/plugins/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const code = (kibana: any) =>
queue,
log,
esClient,
serverOptions,
indexWorker,
repoServiceFactory,
socketService
Expand All @@ -161,12 +162,19 @@ export const code = (kibana: any) =>
queue,
log,
esClient,
serverOptions,
cancellationService,
lspService,
repoServiceFactory,
socketService
).bind();
const updateWorker = new UpdateWorker(queue, log, esClient, repoServiceFactory).bind();
const updateWorker = new UpdateWorker(
queue,
log,
esClient,
serverOptions,
repoServiceFactory
).bind();

// Initialize schedulers.
const updateScheduler = new UpdateScheduler(updateWorker, serverOptions, esClient, log);
Expand All @@ -179,7 +187,6 @@ export const code = (kibana: any) =>
// Add server routes and initialize the plugin here
repositoryRoute(
server,
serverOptions,
cloneWorker,
deleteWorker,
indexWorker,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/code/server/__tests__/clone_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe('clone_worker_tests', () => {
esQueue as Esqueue,
log,
{} as EsClient,
serverOptions,
{} as IndexWorker,
(repoServiceFactory as any) as RepositoryServiceFactory,
{} as SocketService
Expand All @@ -123,7 +124,6 @@ describe('clone_worker_tests', () => {
await cloneWorker.executeJob({
payload: {
url: 'https://github.com/Microsoft/TypeScript-Node-Starter.git',
dataPath: serverOptions.repoPath,
},
options: {},
});
Expand Down Expand Up @@ -158,6 +158,7 @@ describe('clone_worker_tests', () => {
esQueue as Esqueue,
log,
esClient as EsClient,
serverOptions,
(indexWorker as any) as IndexWorker,
{} as RepositoryServiceFactory,
(socketService as any) as SocketService
Expand All @@ -167,7 +168,6 @@ describe('clone_worker_tests', () => {
{
payload: {
url: 'https://github.com/Microsoft/TypeScript-Node-Starter.git',
dataPath: serverOptions.repoPath,
},
options: {},
},
Expand Down Expand Up @@ -202,6 +202,7 @@ describe('clone_worker_tests', () => {
esQueue as Esqueue,
log,
(esClient as any) as EsClient,
serverOptions,
{} as IndexWorker,
{} as RepositoryServiceFactory,
{} as SocketService
Expand All @@ -210,7 +211,6 @@ describe('clone_worker_tests', () => {
await cloneWorker.onJobEnqueued({
payload: {
url: 'https://github.com/Microsoft/TypeScript-Node-Starter.git',
dataPath: serverOptions.repoPath,
},
options: {},
});
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/code/server/queue/abstract_git_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getDefaultBranch, getHeadRevision } from '../git_operations';
import { EsClient, Esqueue } from '../lib/esqueue';
import { Log } from '../log';
import { RepositoryObjectClient } from '../search';
import { ServerOptions } from '../server_options';
import { AbstractWorker } from './abstract_worker';
import { Job } from './job';

Expand All @@ -25,17 +26,17 @@ export abstract class AbstractGitWorker extends AbstractWorker {
constructor(
protected readonly queue: Esqueue,
protected readonly log: Log,
protected readonly client: EsClient
protected readonly client: EsClient,
protected readonly serverOptions: ServerOptions
) {
super(queue, log);
this.objectClient = new RepositoryObjectClient(client);
}

public async onJobCompleted(job: Job, res: CloneWorkerResult) {
// Update the default branch.
const { dataPath } = job.payload;
const repoUri = res.uri;
const localPath = RepositoryUtils.repositoryLocalPath(dataPath, repoUri);
const localPath = RepositoryUtils.repositoryLocalPath(this.serverOptions.repoPath, repoUri);
const revision = await getHeadRevision(localPath);
const defaultBranch = await getDefaultBranch(localPath);

Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/code/server/queue/clone_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { EsClient, Esqueue } from '../lib/esqueue';
import { Log } from '../log';
import { RepositoryServiceFactory } from '../repository_service_factory';
import { ServerOptions } from '../server_options';
import { SocketService } from '../socket_service';
import { AbstractGitWorker } from './abstract_git_worker';
import { IndexWorker } from './index_worker';
Expand All @@ -26,17 +27,18 @@ export class CloneWorker extends AbstractGitWorker {
protected readonly queue: Esqueue,
protected readonly log: Log,
protected readonly client: EsClient,
protected readonly serverOptions: ServerOptions,
private readonly indexWorker: IndexWorker,
private readonly repoServiceFactory: RepositoryServiceFactory,
private readonly socketService?: SocketService
) {
super(queue, log, client);
super(queue, log, client, serverOptions);
}

public async executeJob(job: Job) {
const { url, dataPath } = job.payload;
const { url } = job.payload;
this.log.info(`Execute clone job for ${url}`);
const repoService = this.repoServiceFactory.newInstance(dataPath, this.log);
const repoService = this.repoServiceFactory.newInstance(this.serverOptions.repoPath, this.log);
const repo = RepositoryUtils.buildRepository(url);
return await repoService.clone(repo, (progress: number, cloneProgress?: CloneProgress) => {
this.updateProgress(repo.uri, progress, cloneProgress);
Expand All @@ -58,11 +60,9 @@ export class CloneWorker extends AbstractGitWorker {
}

// Throw out a repository index request.
const { dataPath } = job.payload;
const payload = {
uri: res.repo.uri,
revision: res.repo.revision,
dataPath,
};
await this.indexWorker.enqueueJob(payload, {});

Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/code/server/queue/delete_worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { WorkerReservedProgress } from '../../model';
import { Log } from '../log';
import { LspService } from '../lsp/lsp_service';
import { RepositoryServiceFactory } from '../repository_service_factory';
import { ServerOptions } from '../server_options';
import { SocketService } from '../socket_service';
import { ConsoleLoggerFactory } from '../utils/console_logger_factory';
import { CancellationSerivce } from './cancellation_service';
Expand Down Expand Up @@ -77,6 +78,7 @@ test('Execute delete job.', async () => {
esQueue as Esqueue,
log,
esClient as EsClient,
{} as ServerOptions,
(cancellationService as any) as CancellationSerivce,
(lspService as any) as LspService,
(repoServiceFactory as any) as RepositoryServiceFactory,
Expand All @@ -86,7 +88,6 @@ test('Execute delete job.', async () => {
await deleteWorker.executeJob({
payload: {
uri: 'github.com/elastic/kibana',
dataPath: 'mockpath',
},
options: {},
});
Expand Down Expand Up @@ -117,6 +118,7 @@ test('On delete job enqueued.', async () => {
esQueue as Esqueue,
log,
esClient as EsClient,
{} as ServerOptions,
{} as CancellationSerivce,
{} as LspService,
{} as RepositoryServiceFactory,
Expand All @@ -126,7 +128,6 @@ test('On delete job enqueued.', async () => {
await deleteWorker.onJobEnqueued({
payload: {
uri: 'github.com/elastic/kibana',
dataPath: 'mockpath',
},
options: {},
});
Expand All @@ -146,6 +147,7 @@ test('On delete job completed.', async () => {
esQueue as Esqueue,
log,
esClient as EsClient,
{} as ServerOptions,
{} as CancellationSerivce,
{} as LspService,
{} as RepositoryServiceFactory,
Expand All @@ -156,7 +158,6 @@ test('On delete job completed.', async () => {
{
payload: {
uri: 'github.com/elastic/kibana',
dataPath: 'mockpath',
},
options: {},
},
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/code/server/queue/delete_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Log } from '../log';
import { LspService } from '../lsp/lsp_service';
import { RepositoryServiceFactory } from '../repository_service_factory';
import { RepositoryObjectClient } from '../search';
import { ServerOptions } from '../server_options';
import { SocketService } from '../socket_service';
import { AbstractWorker } from './abstract_worker';
import { CancellationSerivce } from './cancellation_service';
Expand All @@ -27,6 +28,7 @@ export class DeleteWorker extends AbstractWorker {
protected readonly queue: Esqueue,
protected readonly log: Log,
protected readonly client: EsClient,
protected readonly serverOptions: ServerOptions,
private readonly cancellationService: CancellationSerivce,
private readonly lspService: LspService,
private readonly repoServiceFactory: RepositoryServiceFactory,
Expand All @@ -37,7 +39,7 @@ export class DeleteWorker extends AbstractWorker {
}

public async executeJob(job: Job) {
const { uri, dataPath } = job.payload;
const { uri } = job.payload;

// 1. Notify repo delete start through websocket.
this.socketService.broadcastDeleteProgress(uri, WorkerReservedProgress.INIT);
Expand All @@ -47,7 +49,7 @@ export class DeleteWorker extends AbstractWorker {
this.cancellationService.cancelIndexJob(uri);

// 3. Delete repository on local fs.
const repoService = this.repoServiceFactory.newInstance(dataPath, this.log);
const repoService = this.repoServiceFactory.newInstance(this.serverOptions.repoPath, this.log);
const deleteRepoPromise = this.deletePromiseWrapper(repoService.remove(uri), 'git data', uri);

// 4. Delete ES indices and aliases
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/code/server/queue/index_worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ test('Execute index job.', async () => {
await indexWorker.executeJob({
payload: {
uri: 'github.com/elastic/kibana',
dataPath: 'mockpath',
},
options: {},
cancellationToken: cToken,
Expand Down Expand Up @@ -138,7 +137,6 @@ test('Execute index job and then cancel.', async () => {
await indexWorker.executeJob({
payload: {
uri: 'github.com/elastic/kibana',
dataPath: 'mockpath',
},
options: {},
cancellationToken: cToken,
Expand Down Expand Up @@ -179,7 +177,6 @@ test('On index job enqueued.', async () => {
await indexWorker.onJobEnqueued({
payload: {
uri: 'github.com/elastic/kibana',
dataPath: 'mockpath',
},
options: {},
});
Expand Down Expand Up @@ -208,7 +205,6 @@ test('On index job completed.', async () => {
{
payload: {
uri: 'github.com/elastic/kibana',
dataPath: 'mockpath',
},
options: {},
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/code/server/queue/update_worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import sinon from 'sinon';
import { AnyObject, EsClient, Esqueue } from '../lib/esqueue';
import { Log } from '../log';
import { RepositoryServiceFactory } from '../repository_service_factory';
import { ServerOptions } from '../server_options';
import { ConsoleLoggerFactory } from '../utils/console_logger_factory';
import { UpdateWorker } from './update_worker';

Expand Down Expand Up @@ -43,13 +44,13 @@ test('Execute update job', async () => {
esQueue as Esqueue,
log,
esClient as EsClient,
{} as ServerOptions,
(repoServiceFactory as any) as RepositoryServiceFactory
);

await updateWorker.executeJob({
payload: {
uri: 'mockrepo',
dataPath: 'mockpath',
},
options: {},
});
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/code/server/queue/update_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CloneWorkerResult } from '../../model';
import { EsClient, Esqueue } from '../lib/esqueue';
import { Log } from '../log';
import { RepositoryServiceFactory } from '../repository_service_factory';
import { ServerOptions } from '../server_options';
import { AbstractGitWorker } from './abstract_git_worker';
import { Job } from './job';

Expand All @@ -18,15 +19,16 @@ export class UpdateWorker extends AbstractGitWorker {
queue: Esqueue,
protected readonly log: Log,
protected readonly client: EsClient,
protected readonly serverOptions: ServerOptions,
protected readonly repoServiceFactory: RepositoryServiceFactory
) {
super(queue, log, client);
super(queue, log, client, serverOptions);
}

public async executeJob(job: Job) {
const { uri, dataPath } = job.payload;
const { uri } = job.payload;
this.log.info(`Execute update job for ${uri}`);
const repoService = this.repoServiceFactory.newInstance(dataPath, this.log);
const repoService = this.repoServiceFactory.newInstance(this.serverOptions.repoPath, this.log);
return await repoService.update(uri);
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/code/server/repository_service_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Log } from './log';
import { RepositoryService } from './repository_service';

export class RepositoryServiceFactory {
public newInstance(dataPath: string, log: Log): RepositoryService {
return new RepositoryService(dataPath, log);
public newInstance(repoPath: string, log: Log): RepositoryService {
return new RepositoryService(repoPath, log);
}
}
6 changes: 0 additions & 6 deletions x-pack/plugins/code/server/routes/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ import { Log } from '../log';
import { CloneWorker, DeleteWorker, IndexWorker } from '../queue';
import { RepositoryConfigController } from '../repository_config_controller';
import { RepositoryObjectClient } from '../search';
import { ServerOptions } from '../server_options';
import { EsClientWithRequest } from '../utils/esclient_with_request';

export function repositoryRoute(
server: Server,
options: ServerOptions,
cloneWorker: CloneWorker,
deleteWorker: DeleteWorker,
indexWorker: IndexWorker,
repoIndexInitializerFactory: RepositoryIndexInitializerFactory,
repoConfigController: RepositoryConfigController
) {
// Clone a git repository

server.securedRoute({
path: '/api/code/repo',
requireAdmin: true,
Expand Down Expand Up @@ -67,7 +64,6 @@ export function repositoryRoute(
// Kick off clone job
const payload = {
url: repoUrl,
dataPath: options.repoPath,
};
await cloneWorker.enqueueJob(payload, {});
return repo;
Expand Down Expand Up @@ -107,7 +103,6 @@ export function repositoryRoute(

const payload = {
uri: repoUri,
dataPath: options.repoPath,
};
await deleteWorker.enqueueJob(payload, {});

Expand Down Expand Up @@ -188,7 +183,6 @@ export function repositoryRoute(
const payload = {
uri: repoUri,
revision: cloneStatus.revision,
dataPath: options.repoPath,
};
await indexWorker.enqueueJob(payload, {});
return {};
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/code/server/scheduler/index_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class IndexScheduler extends AbstractScheduler {
const payload = {
uri: repo.uri,
revision: repo.revision,
dataPath: this.serverOptions.repoPath,
};

// Update the next repo index timestamp.
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/code/server/scheduler/update_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export class UpdateScheduler extends AbstractScheduler {
) {
const payload = {
uri: repo.uri,
dataPath: this.serverOptions.repoPath,
};

// Update the next repo update timestamp.
Expand Down