Skip to content

Commit

Permalink
[7.0] Add reindex feature to Upgrade Assistant (#27457) (#29516)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover authored Jan 29, 2019
1 parent 89733ae commit 908db0d
Show file tree
Hide file tree
Showing 64 changed files with 4,806 additions and 125 deletions.
157 changes: 151 additions & 6 deletions src/legacy/core_plugins/elasticsearch/index.d.ts

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/server/kbn_server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/

import { Server } from 'hapi';

import { CallClusterWithRequest, ElasticsearchPlugin } from '../legacy/core_plugins/elasticsearch';
import { IndexPatternsServiceFactory } from './index_patterns';
import { SavedObjectsService } from './saved_objects';
import { SavedObjectsClient, SavedObjectsService } from './saved_objects';

export interface KibanaConfig {
get<T>(key: string): T;
Expand All @@ -31,6 +32,7 @@ declare module 'hapi' {
interface PluginProperties {
elasticsearch: ElasticsearchPlugin;
kibana: any;
spaces: any;
// add new plugin types here
}

Expand All @@ -41,11 +43,9 @@ declare module 'hapi' {
}

interface Request {
getBasePath: () => string;
}

interface Request {
getUiSettingsService: () => any;
getSavedObjectsClient(): SavedObjectsClient;
getBasePath(): string;
getUiSettingsService(): any;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
* under the License.
*/

import { SavedObjectsRepository, ScopedSavedObjectsClientProvider } from './lib';
import { ScopedSavedObjectsClientProvider } from './lib';
import { SavedObjectsClient } from './saved_objects_client';

export interface SavedObjectsService<Request = any> {
// ATTENTION: these types are incomplete

addScopedSavedObjectsClientWrapperFactory: ScopedSavedObjectsClientProvider<
Request
>['addClientWrapperFactory'];
getSavedObjectsRepository: (
callCluster: (endpoint: string, clientParams: any, options: any) => Promise<any>
) => SavedObjectsRepository;
getScopedSavedObjectsClient: ScopedSavedObjectsClientProvider<Request>['getClient'];
SavedObjectsClient: typeof SavedObjectsClient;
types: string[];
getSavedObjectsRepository(...rest: any[]): any;
}
2 changes: 1 addition & 1 deletion src/server/saved_objects/service/lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export class SavedObjectsRepository {
}

if (fields && !Array.isArray(fields)) {
throw new TypeError('options.searchFields must be an array');
throw new TypeError('options.fields must be an array');
}

const esOptions = {
Expand Down
65 changes: 39 additions & 26 deletions src/server/saved_objects/service/saved_objects_client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,32 @@ export interface CreateOptions extends BaseOptions {
override?: boolean;
}

export interface BulkCreateObject {
export interface BulkCreateObject<T extends SavedObjectAttributes = any> {
id?: string;
type: string;
attributes: SavedObjectAttributes;
attributes: T;
extraDocumentProperties?: string[];
}

export interface BulkCreateResponse {
savedObjects: SavedObject[];
export interface BulkCreateResponse<T extends SavedObjectAttributes = any> {
savedObjects: Array<SavedObject<T>>;
}

export interface FindOptions extends BaseOptions {
type?: string | string[];
page?: number;
perPage?: number;
sortField?: string;
sortOrder?: string;
fields?: string[];
type?: string | string[];
search?: string;
searchFields?: string[];
}

export interface FindResponse {
saved_objects: SavedObject[];
export interface FindResponse<T extends SavedObjectAttributes = any> {
saved_objects: Array<SavedObject<T>>;
total: number;
perPage: number;
per_page: number;
page: number;
}

Expand All @@ -65,46 +67,57 @@ export interface BulkGetObject {
}
export type BulkGetObjects = BulkGetObject[];

export interface BulkGetResponse {
savedObjects: SavedObject[];
export interface BulkGetResponse<T extends SavedObjectAttributes = any> {
savedObjects: Array<SavedObject<T>>;
}

export interface SavedObjectAttributes {
[key: string]: SavedObjectAttributes | string | number | boolean | null;
}

export interface SavedObject {
export interface SavedObject<T extends SavedObjectAttributes = any> {
id: string;
type: string;
version?: number;
updated_at?: string;
error?: {
message: string;
};
attributes: SavedObjectAttributes;
attributes: T;
}

export declare class SavedObjectsClient {
public static errors: typeof errors;
public errors: typeof errors;
public create: (

constructor(repository: SavedObjectsRepository);

public create<T extends SavedObjectAttributes = any>(
type: string,
attributes: SavedObjectAttributes,
attributes: T,
options?: CreateOptions
) => Promise<SavedObject>;
public bulkCreate: (
objects: BulkCreateObject[],
): Promise<SavedObject<T>>;
public bulkCreate<T extends SavedObjectAttributes = any>(
objects: Array<BulkCreateObject<T>>,
options?: CreateOptions
) => Promise<BulkCreateResponse>;
public delete: (type: string, id: string, options?: BaseOptions) => Promise<{}>;
public find: (options: FindOptions) => Promise<FindResponse>;
public bulkGet: (objects: BulkGetObjects, options?: BaseOptions) => Promise<BulkGetResponse>;
public get: (type: string, id: string, options?: BaseOptions) => Promise<SavedObject>;
public update: (
): Promise<BulkCreateResponse<T>>;
public delete(type: string, id: string, options?: BaseOptions): Promise<{}>;
public find<T extends SavedObjectAttributes = any>(
options: FindOptions
): Promise<FindResponse<T>>;
public bulkGet<T extends SavedObjectAttributes = any>(
objects: BulkGetObjects,
options?: BaseOptions
): Promise<BulkGetResponse<T>>;
public get<T extends SavedObjectAttributes = any>(
type: string,
id: string,
options?: BaseOptions
): Promise<SavedObject<T>>;
public update<T extends SavedObjectAttributes = any>(
type: string,
id: string,
attributes: SavedObjectAttributes,
attributes: Partial<T>,
options?: UpdateOptions
) => Promise<SavedObject>;
constructor(repository: SavedObjectsRepository);
): Promise<SavedObject<T>>;
}
2 changes: 2 additions & 0 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"@scant/router": "^0.1.0",
"@slack/client": "^4.8.0",
"@turf/boolean-contains": "6.0.1",
"@types/json-stable-stringify": "^1.0.32",
"angular-resource": "1.4.9",
"angular-sanitize": "1.6.5",
"angular-ui-ace": "0.2.3",
Expand Down Expand Up @@ -187,6 +188,7 @@
"io-ts": "^1.4.2",
"joi": "^13.5.2",
"jquery": "^3.3.1",
"json-stable-stringify": "^1.0.1",
"jsonwebtoken": "^8.3.0",
"lodash": "npm:@elastic/[email protected]",
"lodash.keyby": "^4.6.0",
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/__mocks__/ui/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ function getInjected(key) {
}
}

function getXsrfToken() {
return 'kbn';
}

export default {
getInjected,
addBasePath,
getUiSettingsClient
getUiSettingsClient,
getXsrfToken
};
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export class SpacesSavedObjectsClient implements SavedObjectsClient {
* @property {string} [options.namespace]
* @returns {promise} - { id, type, version, attributes }
*/
public async create(type: string, attributes = {}, options: CreateOptions = {}) {
public async create<T extends SavedObjectAttributes>(
type: string,
attributes: T = {} as T,
options: CreateOptions = {}
) {
throwErrorIfTypeIsSpace(type);
throwErrorIfNamespaceSpecified(options);

Expand Down Expand Up @@ -215,10 +219,10 @@ export class SpacesSavedObjectsClient implements SavedObjectsClient {
* @property {string} [options.namespace]
* @returns {promise}
*/
public async update(
public async update<T extends SavedObjectAttributes>(
type: string,
id: string,
attributes: SavedObjectAttributes,
attributes: Partial<T>,
options: UpdateOptions = {}
) {
throwErrorIfTypeIsSpace(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

// @ts-ignore
import { PluginProperties, Server } from 'hapi';
import { Server } from 'hapi';
import { Legacy } from 'kibana';
import { SpacesClient } from '../../../lib/spaces_client';
import { createSpaces } from './create_spaces';

interface KibanaServer extends Server {
interface KibanaServer extends Legacy.Server {
savedObjects: any;
}

Expand Down Expand Up @@ -46,13 +47,6 @@ const baseConfig: TestConfig = {
'xpack.spaces.maxSpaces': 1000,
};

// Merge / extend default interfaces for hapi. This is all faked out below.
declare module 'hapi' {
interface PluginProperties {
spaces: any;
}
}

export function createTestHandler(initApiFn: (server: any, preCheckLicenseImpl: any) => void) {
const teardowns: TeardownFn[] = [];

Expand Down
52 changes: 52 additions & 0 deletions x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 {
SavedObject,
SavedObjectAttributes,
} from 'src/server/saved_objects/service/saved_objects_client';

export enum ReindexStep {
// Enum values are spaced out by 10 to give us room to insert steps in between.
created = 0,
indexConsumersStopped = 10,
readonly = 20,
newIndexCreated = 30,
reindexStarted = 40,
reindexCompleted = 50,
aliasCreated = 60,
indexConsumersStarted = 70,
}

export enum ReindexStatus {
inProgress,
completed,
failed,
paused,
}

export const REINDEX_OP_TYPE = 'upgrade-assistant-reindex-operation';
export interface ReindexOperation extends SavedObjectAttributes {
indexName: string;
newIndexName: string;
status: ReindexStatus;
lastCompletedStep: ReindexStep;
locked: string | null;
reindexTaskId: string | null;
reindexTaskPercComplete: number | null;
errorMessage: string | null;
mlReindexCount: number | null;
}

export type ReindexSavedObject = SavedObject<ReindexOperation>;

export enum ReindexWarning {
// 6.0 -> 7.0 warnings, now unused
allField = 0,
booleanFields = 1,

// 7.0 -> 8.0 warnings
}
1 change: 1 addition & 0 deletions x-pack/plugins/upgrade_assistant/common/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ const matches = currentVersionNum.match(/^([1-9]+)\.([0-9]+)\.([0-9]+)$/)!;

export const CURRENT_MAJOR_VERSION = matches[1];
export const NEXT_MAJOR_VERSION = (parseInt(CURRENT_MAJOR_VERSION, 10) + 1).toString();
export const PREV_MAJOR_VERSION = (parseInt(CURRENT_MAJOR_VERSION, 10) - 1).toString();
6 changes: 6 additions & 0 deletions x-pack/plugins/upgrade_assistant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export function upgradeAssistant(kibana: any) {
uiExports: {
managementSections: ['plugins/upgrade_assistant'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings: require('./mappings.json'),
savedObjectSchemas: {
'upgrade-assistant-reindex-operation': {
isNamespaceAgnostic: true,
},
},
},
publicDir: resolve(__dirname, 'public'),

Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/upgrade_assistant/mappings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"upgrade-assistant-reindex-operation": {
"dynamic": true,
"properties": {
"indexName": {
"type": "keyword"
},
"status": {
"type": "integer"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers';

jest.mock('axios', () => ({
get: jest.fn(),
create: jest.fn(),
}));

import { UpgradeAssistantTabs } from './tabs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import './cell';
@import './reindex/index';

.upgDeprecations {
// Pull the container through the padding of EuiPageContent
Expand Down
Loading

0 comments on commit 908db0d

Please sign in to comment.