Skip to content
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
10 changes: 10 additions & 0 deletions x-pack/plugins/ingest_manager/server/routes/setup/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,22 @@ export const createFleetSetupHandler: RequestHandler<
export const ingestManagerSetupHandler: RequestHandler = async (context, request, response) => {
const soClient = context.core.savedObjects.client;
const callCluster = context.core.elasticsearch.adminClient.callAsCurrentUser;
const logger = appContextService.getLogger();
try {
await setupIngestManager(soClient, callCluster);
return response.ok({
body: { isInitialized: true },
});
} catch (e) {
if (e.isBoom) {
logger.error(e.output.payload.message);
return response.customError({
statusCode: e.output.statusCode,
body: { message: e.output.payload.message },
});
}
logger.error(e.message);
logger.error(e.stack);
return response.customError({
statusCode: 500,
body: { message: e.message },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import Boom from 'boom';
import { Dataset, RegistryPackage, ElasticsearchAssetType, TemplateRef } from '../../../../types';
import { CallESAsCurrentUser } from '../../../../types';
import { Field, loadFieldsFromYaml, processFields } from '../../fields/field';
Expand All @@ -20,8 +21,8 @@ export const installTemplates = async (
// install any pre-built index template assets,
// atm, this is only the base package's global index templates
// Install component templates first, as they are used by the index templates
installPreBuiltComponentTemplates(pkgName, pkgVersion, callCluster);
installPreBuiltTemplates(pkgName, pkgVersion, callCluster);
await installPreBuiltComponentTemplates(pkgName, pkgVersion, callCluster);
await installPreBuiltTemplates(pkgName, pkgVersion, callCluster);

// build templates per dataset from yml files
const datasets = registryPackage.datasets;
Expand Down Expand Up @@ -53,16 +54,7 @@ const installPreBuiltTemplates = async (
pkgVersion,
(entry: Registry.ArchiveEntry) => isTemplate(entry)
);
// templatePaths.forEach(async path => {
// const { file } = Registry.pathParts(path);
// const templateName = file.substr(0, file.lastIndexOf('.'));
// const content = JSON.parse(Registry.getAsset(path).toString('utf8'));
// await callCluster('indices.putTemplate', {
// name: templateName,
// body: content,
// });
// });
templatePaths.forEach(async path => {
const templateInstallPromises = templatePaths.map(async path => {
const { file } = Registry.pathParts(path);
const templateName = file.substr(0, file.lastIndexOf('.'));
const content = JSON.parse(Registry.getAsset(path).toString('utf8'));
Expand Down Expand Up @@ -91,8 +83,15 @@ const installPreBuiltTemplates = async (
// The existing convenience endpoint `indices.putTemplate` only sends to _template,
// which does not support v2 templates.
// See src/core/server/elasticsearch/api_types.ts for available endpoints.
await callCluster('transport.request', callClusterParams);
return callCluster('transport.request', callClusterParams);
});
try {
return await Promise.all(templateInstallPromises);
} catch (e) {
throw new Boom(`Error installing prebuilt index templates ${e.message}`, {
statusCode: 400,
});
}
};

const installPreBuiltComponentTemplates = async (
Expand All @@ -105,7 +104,7 @@ const installPreBuiltComponentTemplates = async (
pkgVersion,
(entry: Registry.ArchiveEntry) => isComponentTemplate(entry)
);
templatePaths.forEach(async path => {
const templateInstallPromises = templatePaths.map(async path => {
const { file } = Registry.pathParts(path);
const templateName = file.substr(0, file.lastIndexOf('.'));
const content = JSON.parse(Registry.getAsset(path).toString('utf8'));
Expand All @@ -124,8 +123,15 @@ const installPreBuiltComponentTemplates = async (
// This uses the catch-all endpoint 'transport.request' because there is no
// convenience endpoint for component templates yet.
// See src/core/server/elasticsearch/api_types.ts for available endpoints.
await callCluster('transport.request', callClusterParams);
return callCluster('transport.request', callClusterParams);
});
try {
return await Promise.all(templateInstallPromises);
} catch (e) {
throw new Boom(`Error installing prebuilt component templates ${e.message}`, {
statusCode: 400,
});
}
};

const isTemplate = ({ path }: Registry.ArchiveEntry) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,13 @@ export async function ensureInstalledPackage(options: {
if (installedPackage) {
return installedPackage;
}
// if the requested packaged was not found to be installed, try installing
try {
await installLatestPackage({
savedObjectsClient,
pkgName,
callCluster,
});
return await getInstallation({ savedObjectsClient, pkgName });
} catch (err) {
throw new Error(err.message);
}
// if the requested packaged was not found to be installed, install
await installLatestPackage({
savedObjectsClient,
pkgName,
callCluster,
});
return await getInstallation({ savedObjectsClient, pkgName });
}

export async function installPackage(options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function getResponse(url: string): Promise<Response> {
throw new Boom(response.statusText, { statusCode: response.status });
}
} catch (e) {
throw Boom.boomify(e);
throw new Boom(`Error connecting to package registry: ${e.message}`, { statusCode: 502 });
}
}

Expand Down