44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7+ import Boom from 'boom' ;
78import { Dataset , RegistryPackage , ElasticsearchAssetType , TemplateRef } from '../../../../types' ;
89import { CallESAsCurrentUser } from '../../../../types' ;
910import { Field , loadFieldsFromYaml , processFields } from '../../fields/field' ;
@@ -20,8 +21,8 @@ export const installTemplates = async (
2021 // install any pre-built index template assets,
2122 // atm, this is only the base package's global index templates
2223 // Install component templates first, as they are used by the index templates
23- installPreBuiltComponentTemplates ( pkgName , pkgVersion , callCluster ) ;
24- installPreBuiltTemplates ( pkgName , pkgVersion , callCluster ) ;
24+ await installPreBuiltComponentTemplates ( pkgName , pkgVersion , callCluster ) ;
25+ await installPreBuiltTemplates ( pkgName , pkgVersion , callCluster ) ;
2526
2627 // build templates per dataset from yml files
2728 const datasets = registryPackage . datasets ;
@@ -53,16 +54,7 @@ const installPreBuiltTemplates = async (
5354 pkgVersion ,
5455 ( entry : Registry . ArchiveEntry ) => isTemplate ( entry )
5556 ) ;
56- // templatePaths.forEach(async path => {
57- // const { file } = Registry.pathParts(path);
58- // const templateName = file.substr(0, file.lastIndexOf('.'));
59- // const content = JSON.parse(Registry.getAsset(path).toString('utf8'));
60- // await callCluster('indices.putTemplate', {
61- // name: templateName,
62- // body: content,
63- // });
64- // });
65- templatePaths . forEach ( async path => {
57+ const templateInstallPromises = templatePaths . map ( async path => {
6658 const { file } = Registry . pathParts ( path ) ;
6759 const templateName = file . substr ( 0 , file . lastIndexOf ( '.' ) ) ;
6860 const content = JSON . parse ( Registry . getAsset ( path ) . toString ( 'utf8' ) ) ;
@@ -91,8 +83,15 @@ const installPreBuiltTemplates = async (
9183 // The existing convenience endpoint `indices.putTemplate` only sends to _template,
9284 // which does not support v2 templates.
9385 // See src/core/server/elasticsearch/api_types.ts for available endpoints.
94- await callCluster ( 'transport.request' , callClusterParams ) ;
86+ return callCluster ( 'transport.request' , callClusterParams ) ;
9587 } ) ;
88+ try {
89+ return await Promise . all ( templateInstallPromises ) ;
90+ } catch ( e ) {
91+ throw new Boom ( `Error installing prebuilt index templates ${ e . message } ` , {
92+ statusCode : 400 ,
93+ } ) ;
94+ }
9695} ;
9796
9897const installPreBuiltComponentTemplates = async (
@@ -105,7 +104,7 @@ const installPreBuiltComponentTemplates = async (
105104 pkgVersion ,
106105 ( entry : Registry . ArchiveEntry ) => isComponentTemplate ( entry )
107106 ) ;
108- templatePaths . forEach ( async path => {
107+ const templateInstallPromises = templatePaths . map ( async path => {
109108 const { file } = Registry . pathParts ( path ) ;
110109 const templateName = file . substr ( 0 , file . lastIndexOf ( '.' ) ) ;
111110 const content = JSON . parse ( Registry . getAsset ( path ) . toString ( 'utf8' ) ) ;
@@ -124,8 +123,15 @@ const installPreBuiltComponentTemplates = async (
124123 // This uses the catch-all endpoint 'transport.request' because there is no
125124 // convenience endpoint for component templates yet.
126125 // See src/core/server/elasticsearch/api_types.ts for available endpoints.
127- await callCluster ( 'transport.request' , callClusterParams ) ;
126+ return callCluster ( 'transport.request' , callClusterParams ) ;
128127 } ) ;
128+ try {
129+ return await Promise . all ( templateInstallPromises ) ;
130+ } catch ( e ) {
131+ throw new Boom ( `Error installing prebuilt component templates ${ e . message } ` , {
132+ statusCode : 400 ,
133+ } ) ;
134+ }
129135} ;
130136
131137const isTemplate = ( { path } : Registry . ArchiveEntry ) => {
0 commit comments