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

[7.x] Don't make the caller do work the function can do (#83180) #83215

Merged
merged 1 commit into from
Nov 11, 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 @@ -16,12 +16,10 @@ import {
} from '../../../types';
import { installIndexPatterns } from '../kibana/index_pattern/install';
import { installTemplates } from '../elasticsearch/template/install';
import { generateESIndexPatterns } from '../elasticsearch/template/template';
import { installPipelines, deletePreviousPipelines } from '../elasticsearch/ingest_pipeline/';
import { installILMPolicy } from '../elasticsearch/ilm/install';
import { installKibanaAssets, getKibanaAssets } from '../kibana/assets/install';
import { updateCurrentWriteIndices } from '../elasticsearch/template/template';
import { isRequiredPackage } from './index';
import { deleteKibanaSavedObjectsAssets } from './remove';
import { installTransform } from '../elasticsearch/transform/install';
import { createInstallation, saveKibanaAssetsRefs, updateVersion } from './install';
Expand All @@ -47,30 +45,22 @@ export async function _installPackage({
installType: InstallType;
installSource: InstallSource;
}): Promise<AssetReference[]> {
const { internal = false, name: pkgName, version: pkgVersion } = packageInfo;
const removable = !isRequiredPackage(pkgName);
const toSaveESIndexPatterns = generateESIndexPatterns(packageInfo.data_streams);
const { name: pkgName, version: pkgVersion } = packageInfo;
// add the package installation to the saved object.
// if some installation already exists, just update install info
if (!installedPkg) {
await createInstallation({
savedObjectsClient,
pkgName,
pkgVersion,
internal,
removable,
installed_kibana: [],
installed_es: [],
toSaveESIndexPatterns,
installSource,
});
} else {
if (installedPkg) {
await savedObjectsClient.update(PACKAGES_SAVED_OBJECT_TYPE, pkgName, {
install_version: pkgVersion,
install_status: 'installing',
install_started_at: new Date().toISOString(),
install_source: installSource,
});
} else {
await createInstallation({
savedObjectsClient,
packageInfo,
installSource,
});
}

// kick off `installIndexPatterns` & `installKibanaAssets` as early as possible because they're the longest running operations
Expand Down
45 changes: 20 additions & 25 deletions x-pack/plugins/fleet/server/services/epm/packages/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObject, SavedObjectsClientContract } from 'src/core/server';
import semver from 'semver';
import Boom from '@hapi/boom';
import { UnwrapPromise } from '@kbn/utility-types';
import { BulkInstallPackageInfo, InstallSource, defaultPackages } from '../../../../common';
import { SavedObject, SavedObjectsClientContract } from 'src/core/server';
import { generateESIndexPatterns } from '../elasticsearch/template/template';
import { isRequiredPackage } from './index';
import {
BulkInstallPackageInfo,
InstallablePackage,
InstallSource,
defaultPackages,
} from '../../../../common';
import { PACKAGES_SAVED_OBJECT_TYPE, MAX_TIME_COMPLETE_INSTALL } from '../../../constants';
import {
AssetReference,
Installation,
CallESAsCurrentUser,
AssetType,
KibanaAssetReference,
EsAssetReference,
InstallType,
KibanaAssetType,
Expand Down Expand Up @@ -346,31 +352,19 @@ export const updateVersion = async (
};
export async function createInstallation(options: {
savedObjectsClient: SavedObjectsClientContract;
pkgName: string;
pkgVersion: string;
internal: boolean;
removable: boolean;
installed_kibana: KibanaAssetReference[];
installed_es: EsAssetReference[];
toSaveESIndexPatterns: Record<string, string>;
packageInfo: InstallablePackage;
installSource: InstallSource;
}) {
const {
savedObjectsClient,
pkgName,
pkgVersion,
internal,
removable,
installed_kibana: installedKibana,
installed_es: installedEs,
toSaveESIndexPatterns,
installSource,
} = options;
await savedObjectsClient.create<Installation>(
const { savedObjectsClient, packageInfo, installSource } = options;
const { internal = false, name: pkgName, version: pkgVersion } = packageInfo;
const removable = !isRequiredPackage(pkgName);
const toSaveESIndexPatterns = generateESIndexPatterns(packageInfo.data_streams);

const created = await savedObjectsClient.create<Installation>(
PACKAGES_SAVED_OBJECT_TYPE,
{
installed_kibana: installedKibana,
installed_es: installedEs,
installed_kibana: [],
installed_es: [],
es_index_patterns: toSaveESIndexPatterns,
name: pkgName,
version: pkgVersion,
Expand All @@ -383,7 +377,8 @@ export async function createInstallation(options: {
},
{ id: pkgName, overwrite: true }
);
return [...installedKibana, ...installedEs];

return created;
}

export const saveKibanaAssetsRefs = async (
Expand Down