Skip to content

Commit

Permalink
Fix stream template installation
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Jun 24, 2020
1 parent 7a63526 commit fe5a6ae
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions x-pack/plugins/ingest_manager/server/services/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { createStream } from './epm/agent/agent';

const SAVED_OBJECT_TYPE = DATASOURCE_SAVED_OBJECT_TYPE;

function getDataset(st: string) {
return st.split('.')[1];
}

class DatasourceService {
public async create(
soClient: SavedObjectsClientContract,
Expand Down Expand Up @@ -271,15 +275,15 @@ async function _assignPackageStreamToStream(
if (!stream.enabled) {
return { ...stream, agent_stream: undefined };
}
const dataset = stream.dataset;
const datasetPath = getDataset(stream.dataset);
const packageDatasets = pkgInfo.datasets;
if (!packageDatasets) {
throw new Error('Stream template not found, no datasets');
}

const packageDataset = packageDatasets.find((pkgDataset) => pkgDataset.name === dataset);
const packageDataset = packageDatasets.find((pkgDataset) => pkgDataset.name === stream.dataset);
if (!packageDataset) {
throw new Error(`Stream template not found, unable to find dataset ${dataset}`);
throw new Error(`Stream template not found, unable to find dataset ${datasetPath}`);
}

const streamFromPkg = (packageDataset.streams || []).find(
Expand All @@ -290,18 +294,18 @@ async function _assignPackageStreamToStream(
}

if (!streamFromPkg.template_path) {
throw new Error(`Stream template path not found for dataset ${dataset}`);
throw new Error(`Stream template path not found for dataset ${datasetPath}`);
}

const [pkgStream] = await getAssetsDataForPackageKey(
{ pkgName: pkgInfo.name, pkgVersion: pkgInfo.version },
(path: string) => path.endsWith(streamFromPkg.template_path),
dataset
datasetPath
);

if (!pkgStream || !pkgStream.buffer) {
throw new Error(
`Unable to load stream template ${streamFromPkg.template_path} for dataset ${dataset}`
`Unable to load stream template ${streamFromPkg.template_path} for dataset ${datasetPath}`
);
}

Expand Down

0 comments on commit fe5a6ae

Please sign in to comment.