[File upload] Move File Upload to New Platform (#58550) (#59300)

* Move file upload to np. Some additional mods & removals

* Consume file upload from NP in maps and pass to kibana services

* Register telemetry mappings

* Init indexPatternService in start method

* Fix type check issues. Add missing prop to telemetry

* Update i18n path

* Review feedback
This commit is contained in:
Aaron Caldwell 2020-03-04 11:16:44 -07:00 committed by GitHub
parent 862a42fad7
commit ce8df3b5cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 77 additions and 70 deletions

View file

@ -14,7 +14,7 @@
"xpack.drilldowns": "plugins/drilldowns",
"xpack.endpoint": "plugins/endpoint",
"xpack.features": "plugins/features",
"xpack.fileUpload": "legacy/plugins/file_upload",
"xpack.fileUpload": "plugins/file_upload",
"xpack.graph": ["legacy/plugins/graph", "plugins/graph"],
"xpack.grokDebugger": "legacy/plugins/grokdebugger",
"xpack.idxMgmt": "plugins/index_management",

View file

@ -30,7 +30,6 @@ import { remoteClusters } from './legacy/plugins/remote_clusters';
import { crossClusterReplication } from './legacy/plugins/cross_cluster_replication';
import { upgradeAssistant } from './legacy/plugins/upgrade_assistant';
import { uptime } from './legacy/plugins/uptime';
import { fileUpload } from './legacy/plugins/file_upload';
import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects';
import { snapshotRestore } from './legacy/plugins/snapshot_restore';
import { transform } from './legacy/plugins/transform';
@ -68,7 +67,6 @@ module.exports = function(kibana) {
crossClusterReplication(kibana),
upgradeAssistant(kibana),
uptime(kibana),
fileUpload(kibana),
encryptedSavedObjects(kibana),
lens(kibana),
snapshotRestore(kibana),

View file

@ -1,36 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { FileUploadPlugin } from './server/plugin';
import { mappings } from './mappings';
export const fileUpload = kibana => {
return new kibana.Plugin({
require: ['elasticsearch'],
name: 'file_upload',
id: 'file_upload',
// TODO: uiExports and savedObjectSchemas to be removed on migration
uiExports: {
mappings,
},
savedObjectSchemas: {
'file-upload-telemetry': {
isNamespaceAgnostic: true,
},
},
init(server) {
const coreSetup = server.newPlatform.setup.core;
const coreStart = server.newPlatform.start.core;
const { usageCollection } = server.newPlatform.setup.plugins;
const pluginsStart = {
usageCollection,
};
const fileUploadPlugin = new FileUploadPlugin();
fileUploadPlugin.setup(coreSetup);
fileUploadPlugin.start(coreStart, pluginsStart);
},
});
};

View file

@ -28,6 +28,12 @@ export const getInspector = () => {
return inspector;
};
let fileUploadPlugin;
export const setFileUpload = fileUpload => (fileUploadPlugin = fileUpload);
export const getFileUploadComponent = () => {
return fileUploadPlugin.JsonUploadAndParse;
};
export async function fetchSearchSourceAndRecordWithInspector({
searchSource,
requestId,

View file

@ -5,7 +5,7 @@
*/
import React from 'react';
import { start as fileUpload } from '../../../../../file_upload/public/legacy';
import { getFileUploadComponent } from '../../../kibana_services';
export function ClientFileCreateSourceEditor({
previewGeojsonFile,
@ -14,8 +14,9 @@ export function ClientFileCreateSourceEditor({
onRemove,
onIndexReady,
}) {
const FileUpload = getFileUploadComponent();
return (
<fileUpload.JsonUploadAndParse
<FileUpload
appName={'Maps'}
isIndexingTriggered={isIndexingTriggered}
onFileUpload={previewGeojsonFile}

View file

@ -10,7 +10,7 @@ import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { MapListing } from './components/map_listing';
// @ts-ignore
import { setLicenseId, setInspector } from './kibana_services';
import { setLicenseId, setInspector, setFileUpload } from './kibana_services';
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { featureCatalogueEntry } from './feature_catalogue_entry';
@ -52,5 +52,6 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {
public start(core: CoreStart, plugins: any) {
setInspector(plugins.np.inspector);
setFileUpload(plugins.np.file_upload);
}
}

View file

@ -0,0 +1,9 @@
{
"id": "file_upload",
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["xpack", "file_upload"],
"server": true,
"ui": true,
"requiredPlugins": ["data", "usageCollection"]
}

View file

@ -4,19 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { npStart } from 'ui/new_platform';
import { DEFAULT_KBN_VERSION } from '../common/constants/file_import';
export const indexPatternService = npStart.plugins.data.indexPatterns;
export let indexPatternService;
export let savedObjectsClient;
export let basePath;
export let kbnVersion;
export let kbnFetch;
export const initServicesAndConstants = ({ savedObjects, http, injectedMetadata }) => {
savedObjectsClient = savedObjects.client;
export const setupInitServicesAndConstants = ({ http }) => {
basePath = http.basePath.basePath;
kbnVersion = injectedMetadata.getKibanaVersion(DEFAULT_KBN_VERSION);
kbnFetch = http.fetch;
};
export const startInitServicesAndConstants = ({ savedObjects }, { data }) => {
indexPatternService = data.indexPatterns;
savedObjectsClient = savedObjects.client;
};

View file

@ -4,26 +4,36 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { Plugin, CoreStart } from 'src/core/public';
// @ts-ignore
import { CoreSetup, CoreStart, Plugin } from 'kibana/server';
// @ts-ignore
import { JsonUploadAndParse } from './components/json_upload_and_parse';
// @ts-ignore
import { initServicesAndConstants } from './kibana_services';
import { setupInitServicesAndConstants, startInitServicesAndConstants } from './kibana_services';
import { IDataPluginServices } from '../../../../src/plugins/data/public';
/**
* These are the interfaces with your public contracts. You should export these
* for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces.
* @public
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface FileUploadPluginSetupDependencies {}
export interface FileUploadPluginStartDependencies {
data: IDataPluginServices;
}
export type FileUploadPluginSetup = ReturnType<FileUploadPlugin['setup']>;
export type FileUploadPluginStart = ReturnType<FileUploadPlugin['start']>;
/** @internal */
export class FileUploadPlugin implements Plugin<FileUploadPluginSetup, FileUploadPluginStart> {
public setup() {}
public setup(core: CoreSetup, plugins: FileUploadPluginSetupDependencies) {
setupInitServicesAndConstants(core);
}
public start(core: CoreStart) {
initServicesAndConstants(core);
public start(core: CoreStart, plugins: FileUploadPluginStartDependencies) {
startInitServicesAndConstants(core, plugins);
return {
JsonUploadAndParse,
};

View file

@ -3,10 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { FileUploadPlugin } from './plugin';
import { npStart } from 'ui/new_platform';
import { plugin } from '.';
export * from './plugin';
const pluginInstance = plugin();
export const start = pluginInstance.start(npStart.core);
export const plugin = () => new FileUploadPlugin();

View file

@ -6,22 +6,22 @@
import { initRoutes } from './routes/file_upload';
import { setElasticsearchClientServices, setInternalRepository } from './kibana_server_services';
import { registerFileUploadUsageCollector } from './telemetry';
import { registerFileUploadUsageCollector, fileUploadTelemetryMappingsType } from './telemetry';
export class FileUploadPlugin {
constructor() {
this.router = null;
}
setup(core) {
setup(core, plugins) {
core.savedObjects.registerType(fileUploadTelemetryMappingsType);
setElasticsearchClientServices(core.elasticsearch);
this.router = core.http.createRouter();
}
start(core, plugins) {
initRoutes(this.router, core.savedObjects.getSavedObjectsRepository);
setInternalRepository(core.savedObjects.createInternalRepository);
registerFileUploadUsageCollector(plugins.usageCollection);
}
start(core) {
initRoutes(this.router, core.savedObjects.getSavedObjectsRepository);
setInternalRepository(core.savedObjects.createInternalRepository);
}
}

View file

@ -5,3 +5,4 @@
*/
export { registerFileUploadUsageCollector } from './file_upload_usage_collector';
export { fileUploadTelemetryMappingsType } from './mappings';

View file

@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { SavedObjectsType } from 'src/core/server';
import { TELEMETRY_DOC_ID } from './telemetry';
export const fileUploadTelemetryMappingsType: SavedObjectsType = {
name: TELEMETRY_DOC_ID,
hidden: false,
namespaceAgnostic: true,
mappings: {
properties: {
filesUploadedTotalCount: {
type: 'long',
},
},
},
};