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

[Ingest Manager] Move cache functions to from registry to archive #82871

Merged
merged 5 commits into from
Nov 6, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { pkgToPkgKey } from './index';
import { pkgToPkgKey } from '../registry/index';

const cache: Map<string, Buffer> = new Map();
export const cacheGet = (key: string) => cache.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

import { ArchivePackage } from '../../../../common/types';
import { PackageInvalidArchiveError, PackageUnsupportedMediaTypeError } from '../../../errors';
import { cacheSet, setArchiveFilelist } from '../registry/cache';
import {
cacheSet,
cacheDelete,
getArchiveFilelist,
setArchiveFilelist,
deleteArchiveFilelist,
} from './cache';
import { ArchiveEntry, getBufferExtractor } from '../registry/extract';
import { parseAndVerifyArchive } from './validation';

export * from './cache';

export async function loadArchivePackage({
archiveBuffer,
contentType,
Expand Down Expand Up @@ -64,3 +72,15 @@ export async function unpackArchiveToCache(
}
return paths;
}

export const deletePackageCache = (name: string, version: string) => {
// get cached archive filelist
const paths = getArchiveFilelist(name, version);

// delete cached archive filelist
deleteArchiveFilelist(name, version);

// delete cached archive files
// this has been populated in unpackArchiveToCache()
paths?.forEach((path) => cacheDelete(path));
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../../../common/types';
import { PackageInvalidArchiveError } from '../../../errors';
import { pkgToPkgKey } from '../registry';
import { cacheGet } from '../registry/cache';
import { cacheGet } from './cache';

// TODO: everything below performs verification of manifest.yml files, and hence duplicates functionality already implemented in the
// package registry. At some point this should probably be replaced (or enhanced) with verification based on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { InstallablePackage } from '../../../types';
import { getAssets } from './assets';
import { getArchiveFilelist } from '../registry/cache';
import { getArchiveFilelist } from '../archive/cache';

jest.mock('../registry/cache', () => {
jest.mock('../archive/cache', () => {
return {
getArchiveFilelist: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { InstallablePackage } from '../../../types';
import * as Registry from '../registry';
import { getArchiveFilelist } from '../registry/cache';
import { getArchiveFilelist } from '../archive/cache';

// paths from RegistryPackage are routes to the assets on EPR
// e.g. `/package/nginx/1.2.0/data_stream/access/fields/fields.yml`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { deletePipeline } from '../elasticsearch/ingest_pipeline/';
import { installIndexPatterns } from '../kibana/index_pattern/install';
import { deleteTransforms } from '../elasticsearch/transform/remove';
import { packagePolicyService, appContextService } from '../..';
import { splitPkgKey, deletePackageCache } from '../registry';
import { splitPkgKey } from '../registry';
import { deletePackageCache } from '../archive';

export async function removeInstallation(options: {
savedObjectsClient: SavedObjectsClientContract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ import {
RegistrySearchResult,
} from '../../../types';
import { unpackArchiveToCache } from '../archive';
import {
cacheGet,
cacheDelete,
getArchiveFilelist,
setArchiveFilelist,
deleteArchiveFilelist,
} from './cache';
import { cacheGet, getArchiveFilelist, setArchiveFilelist } from '../archive';
import { ArchiveEntry } from './extract';
import { fetchUrl, getResponse, getResponseStream } from './requests';
import { streamToBuffer } from './streams';
Expand Down Expand Up @@ -247,15 +241,3 @@ export function groupPathsByService(paths: string[]): AssetsGroupedByServiceByTy
// elasticsearch: assets.elasticsearch,
};
}

export const deletePackageCache = (name: string, version: string) => {
// get cached archive filelist
const paths = getArchiveFilelist(name, version);

// delete cached archive filelist
deleteArchiveFilelist(name, version);

// delete cached archive files
// this has been populated in unpackRegistryPackageToCache()
paths?.forEach((path) => cacheDelete(path));
};