protected addCodeCoverageNodes(buildJsonContent: any): Q.Promise<any> { let _this = this; let isMultiModule = false; if (!buildJsonContent.project) { return Q.reject(tl.loc("InvalidBuildFile")); } if (buildJsonContent.project.modules) { tl.debug("Multimodule project detected"); isMultiModule = true; } if (!buildJsonContent.project.build) { tl.debug("Build tag is not present"); buildJsonContent.project.build = {}; } let buildNode = _this.getBuildDataNode(buildJsonContent); let pluginsNode = _this.getPluginDataNode(buildNode); let reportPluginsNode = _this.getReportingPluginNode(buildJsonContent.project.reporting); let ccPluginData = ccc.coberturaMavenEnable(_this.includeFilter, _this.excludeFilter, String(isMultiModule)); let reportContent = ccc.coberturaMavenReport(); return Q.allSettled([ccPluginData, reportContent]) .then(function (resp) { util.addPropToJson(pluginsNode, "plugin", resp[0].value.plugin); util.addPropToJson(reportPluginsNode, "plugin", resp[1].value.plugin); tl.debug("Final buildContent: " + buildJsonContent); return Q.resolve(buildJsonContent); }); }
}).then((ds: string[]) => { if (!Array.isArray(ds)) throw new Error('invalid result from data source list'); var unknownDataSourceNames: string[] = []; var nonQueryableDataSources: DataSource[] = []; ds.forEach((d: string) => { var existingDataSources = myDataSources.filter((dataSource) => { return dataSource.engine === 'druid' && dataSource.source === d; }); if (existingDataSources.length === 0) { unknownDataSourceNames.push(d); } else { nonQueryableDataSources = nonQueryableDataSources.concat(existingDataSources.filter((dataSource) => { return !dataSource.isQueryable(); })); } }); nonQueryableDataSources = nonQueryableDataSources.concat(unknownDataSourceNames.map((name) => { var newDataSource = dataSourceStubFactory(name); log(`Adding Druid data source: '${name}'`); addOrUpdateDataSource(newDataSource); return newDataSource; })); // Nothing to do if (!nonQueryableDataSources.length) return Q(null); return Q.allSettled(nonQueryableDataSources.map((dataSource) => { return introspectDataSource(dataSource); })); }).catch((e: Error) => {
export function dataSourceManagerFactory(options: DataSourceManagerOptions): DataSourceManager { var { dataSources, dataSourceStubFactory, druidRequester, dataSourceFiller, sourceListScan, sourceListRefreshOnLoad, sourceListRefreshInterval, log } = options; if (!sourceListScan) sourceListScan = 'auto'; if (sourceListScan !== 'disable' && sourceListScan !== 'auto') { throw new Error(`sourceListScan must be disabled or auto is ('${sourceListScan}')`); } if (!dataSourceStubFactory) { dataSourceStubFactory = (name: string) => { return DataSource.fromJS({ name, engine: 'druid', source: name, timeAttribute: 'time', refreshRule: RefreshRule.query().toJS() }); }; } if (!log) log = function() {}; var myDataSources: DataSource[] = dataSources || []; function findDataSource(name: string): DataSource { for (var myDataSource of myDataSources) { if (myDataSource.name === name) return myDataSource; } return null; } function getQueryable(): DataSource[] { return myDataSources.filter((dataSource) => dataSource.isQueryable()); } // Updates the correct datasource (by name) in myDataSources function addOrUpdateDataSource(dataSource: DataSource): void { var updated = false; myDataSources = myDataSources.map((myDataSource) => { if (myDataSource.name === dataSource.name) { updated = true; return dataSource; } else { return myDataSource; } }); if (!updated) { myDataSources.push(dataSource); } } function introspectDataSource(dataSource: DataSource): Q.Promise<any> { return dataSourceFiller(dataSource).then((filledDataSource) => { addOrUpdateDataSource(filledDataSource); }).catch((e) => { log(`Failed to introspect data source: '${dataSource.name}' because ${e.message}`); }); } function loadDruidDataSources(): Q.Promise<any> { if (!druidRequester) return Q(null); return druidRequester({ query: { queryType: 'sourceList' } as any }).then((ds: string[]) => { if (!Array.isArray(ds)) throw new Error('invalid result from data source list'); var unknownDataSourceNames: string[] = []; var nonQueryableDataSources: DataSource[] = []; ds.forEach((d: string) => { var existingDataSources = myDataSources.filter((dataSource) => { return dataSource.engine === 'druid' && dataSource.source === d; }); if (existingDataSources.length === 0) { unknownDataSourceNames.push(d); } else { nonQueryableDataSources = nonQueryableDataSources.concat(existingDataSources.filter((dataSource) => { return !dataSource.isQueryable(); })); } }); nonQueryableDataSources = nonQueryableDataSources.concat(unknownDataSourceNames.map((name) => { var newDataSource = dataSourceStubFactory(name); log(`Adding Druid data source: '${name}'`); addOrUpdateDataSource(newDataSource); return newDataSource; })); // Nothing to do if (!nonQueryableDataSources.length) return Q(null); return Q.allSettled(nonQueryableDataSources.map((dataSource) => { return introspectDataSource(dataSource); })); }).catch((e: Error) => { log(`Could not get druid source list: '${e.message}'`); }); } var initialTasks: Array<Q.Promise<any>> = []; myDataSources.forEach((dataSource) => { initialTasks.push(introspectDataSource(dataSource)); }); if (sourceListScan === 'auto' && druidRequester) { initialTasks.push(loadDruidDataSources()); } var initialLoad: Q.Promise<any> = Q.allSettled(initialTasks); initialLoad.then(() => { var queryableDataSources = getQueryable(); log(`Initial introspection complete. Got ${myDataSources.length} data sources, ${queryableDataSources.length} queryable`); }); if (sourceListScan === 'auto' && druidRequester && sourceListRefreshInterval) { log(`Will refresh data sources every ${sourceListRefreshInterval}ms`); setInterval(loadDruidDataSources, sourceListRefreshInterval).unref(); } // Periodically check if max time needs to be updated setInterval(() => { myDataSources.forEach((dataSource) => { if (dataSource.refreshRule.isQuery() && dataSource.shouldUpdateMaxTime()) { DataSource.updateMaxTime(dataSource).then((updatedDataSource) => { log(`Getting the latest MaxTime for '${updatedDataSource.name}'`); addOrUpdateDataSource(updatedDataSource); }); } }); }, 1000).unref(); return { getDataSources: () => { return initialLoad.then(() => { if (myDataSources.length && !sourceListRefreshOnLoad) return myDataSources; // There are no data sources... lets try to load some: return loadDruidDataSources().then(() => { return myDataSources; // we tried }); }); }, getQueryableDataSources: () => { return initialLoad.then(() => { var queryableDataSources = getQueryable(); if (queryableDataSources.length && !sourceListRefreshOnLoad) return queryableDataSources; // There are no data sources... lets try to load some: return loadDruidDataSources().then(() => { return getQueryable(); // we tried }); }); }, getQueryableDataSource: (name: string) => { return initialLoad.then(() => { var myDataSource = findDataSource(name); if (myDataSource) { if (myDataSource.isQueryable()) return myDataSource; return introspectDataSource(myDataSource).then(() => { var queryableDataSource = findDataSource(name); return (queryableDataSource && queryableDataSource.isQueryable()) ? queryableDataSource : null; }); } // There are no data sources... lets try to load some: return loadDruidDataSources().then(() => { var queryableDataSource = findDataSource(name); return (queryableDataSource && queryableDataSource.isQueryable()) ? queryableDataSource : null; }); }); } }; }
.then(function(csv) { return Q.allSettled([ connectDB(), transformCSV(csv) ]); })