Skip to content

Commit

Permalink
[ILM] Change import of handleEsError to lib dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech committed Oct 15, 2020
1 parent 82c838e commit 92d703e
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 22 deletions.
4 changes: 4 additions & 0 deletions x-pack/plugins/index_lifecycle_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PluginInitializerContext,
LegacyAPICaller,
} from 'src/core/server';
import { handleEsError } from './shared_imports';

import { Index as IndexWithoutIlm } from '../../index_management/common/types';
import { PLUGIN } from '../common/constants';
Expand Down Expand Up @@ -99,6 +100,9 @@ export class IndexLifecycleManagementServerPlugin implements Plugin<void, void,
router,
config,
license: this.license,
lib: {
handleEsError,
},
});

if (config.ui.enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ElasticsearchClient } from 'kibana/server';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

async function addLifecyclePolicy(
client: ElasticsearchClient,
Expand All @@ -33,7 +32,11 @@ const bodySchema = schema.object({
alias: schema.maybe(schema.string()),
});

export function registerAddPolicyRoute({ router, license }: RouteDependencies) {
export function registerAddPolicyRoute({
router,
license,
lib: { handleEsError },
}: RouteDependencies) {
router.post(
{ path: addBasePath('/index/add'), validate: { body: bodySchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ElasticsearchClient } from 'kibana/server';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

async function removeLifecycle(client: ElasticsearchClient, indexNames: string[]) {
const options = {
Expand All @@ -27,7 +26,11 @@ const bodySchema = schema.object({
indexNames: schema.arrayOf(schema.string()),
});

export function registerRemoveRoute({ router, license }: RouteDependencies) {
export function registerRemoveRoute({
router,
license,
lib: { handleEsError },
}: RouteDependencies) {
router.post(
{ path: addBasePath('/index/remove'), validate: { body: bodySchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ElasticsearchClient } from 'kibana/server';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

async function retryLifecycle(client: ElasticsearchClient, indexNames: string[]) {
const options = {
Expand All @@ -28,7 +27,7 @@ const bodySchema = schema.object({
indexNames: schema.arrayOf(schema.string()),
});

export function registerRetryRoute({ router, license }: RouteDependencies) {
export function registerRetryRoute({ router, license, lib: { handleEsError } }: RouteDependencies) {
router.post(
{ path: addBasePath('/index/retry'), validate: { body: bodySchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { schema } from '@kbn/config-schema';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

function findMatchingNodes(stats: any, nodeAttrs: string): any {
return Object.entries(stats.nodes).reduce((accum: any[], [nodeId, nodeStats]: [any, any]) => {
Expand All @@ -30,7 +29,11 @@ const paramsSchema = schema.object({
nodeAttrs: schema.string(),
});

export function registerDetailsRoute({ router, license }: RouteDependencies) {
export function registerDetailsRoute({
router,
license,
lib: { handleEsError },
}: RouteDependencies) {
router.get(
{ path: addBasePath('/nodes/{nodeAttrs}/details'), validate: { params: paramsSchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ListNodesRouteResponse, NodeDataRole } from '../../../../common/types';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

interface Settings {
nodes: {
Expand Down Expand Up @@ -63,7 +62,12 @@ export function convertSettingsIntoLists(
);
}

export function registerListRoute({ router, config, license }: RouteDependencies) {
export function registerListRoute({
router,
config,
license,
lib: { handleEsError },
}: RouteDependencies) {
const { filteredNodeAttributes } = config;

const NODE_ATTRS_KEYS_TO_IGNORE: string[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ElasticsearchClient } from 'kibana/server';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

async function createPolicy(client: ElasticsearchClient, name: string, phases: any): Promise<any> {
const body = {
Expand Down Expand Up @@ -135,7 +134,11 @@ const bodySchema = schema.object({
}),
});

export function registerCreateRoute({ router, license }: RouteDependencies) {
export function registerCreateRoute({
router,
license,
lib: { handleEsError },
}: RouteDependencies) {
router.post(
{ path: addBasePath('/policies'), validate: { body: bodySchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ElasticsearchClient } from 'kibana/server';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

async function deletePolicies(client: ElasticsearchClient, policyName: string): Promise<any> {
const options = {
Expand All @@ -24,7 +23,11 @@ const paramsSchema = schema.object({
policyNames: schema.string(),
});

export function registerDeleteRoute({ router, license }: RouteDependencies) {
export function registerDeleteRoute({
router,
license,
lib: { handleEsError },
}: RouteDependencies) {
router.delete(
{ path: addBasePath('/policies/{policyNames}'), validate: { params: paramsSchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ApiResponse } from '@elastic/elasticsearch';
import { IndexLifecyclePolicy, PolicyFromES } from '../../../../common/types';
import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

interface PoliciesMap {
[K: string]: Omit<PolicyFromES, 'name'>;
Expand Down Expand Up @@ -58,7 +57,7 @@ const querySchema = schema.object({
withIndices: schema.boolean({ defaultValue: false }),
});

export function registerFetchRoute({ router, license }: RouteDependencies) {
export function registerFetchRoute({ router, license, lib: { handleEsError } }: RouteDependencies) {
router.get(
{ path: addBasePath('/policies'), validate: { query: querySchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import { ElasticsearchClient } from 'kibana/server';

import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

async function fetchSnapshotPolicies(client: ElasticsearchClient): Promise<any> {
const response = await client.slm.getLifecycle();
return response.body;
}

export function registerFetchRoute({ router, license }: RouteDependencies) {
export function registerFetchRoute({ router, license, lib: { handleEsError } }: RouteDependencies) {
router.get(
{ path: addBasePath('/snapshot_policies'), validate: false },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { TemplateFromEs, TemplateSerialized } from '../../../../../index_managem
import { LegacyTemplateSerialized } from '../../../../../index_management/server';
import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

async function getLegacyIndexTemplate(
client: ElasticsearchClient,
Expand Down Expand Up @@ -93,7 +92,11 @@ const querySchema = schema.object({
legacy: schema.maybe(schema.oneOf([schema.literal('true'), schema.literal('false')])),
});

export function registerAddPolicyRoute({ router, license }: RouteDependencies) {
export function registerAddPolicyRoute({
router,
license,
lib: { handleEsError },
}: RouteDependencies) {
router.post(
{ path: addBasePath('/template'), validate: { body: bodySchema, query: querySchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '../../../../../index_management/common/types';
import { RouteDependencies } from '../../../types';
import { addBasePath } from '../../../services';
import { handleEsError } from '../../../shared_imports';

function isReservedSystemTemplate(templateName: string, indexPatterns: string[]): boolean {
return (
Expand Down Expand Up @@ -81,7 +80,7 @@ const querySchema = schema.object({
legacy: schema.maybe(schema.oneOf([schema.literal('true'), schema.literal('false')])),
});

export function registerFetchRoute({ router, license }: RouteDependencies) {
export function registerFetchRoute({ router, license, lib: { handleEsError } }: RouteDependencies) {
router.get(
{ path: addBasePath('/templates'), validate: { query: querySchema } },
license.guardApiRoute(async (context, request, response) => {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/index_lifecycle_management/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LicensingPluginSetup } from '../../licensing/server';
import { IndexManagementPluginSetup } from '../../index_management/server';
import { License } from './services';
import { IndexLifecycleManagementConfig } from './config';
import { handleEsError } from './shared_imports';

export interface Dependencies {
licensing: LicensingPluginSetup;
Expand All @@ -22,4 +23,7 @@ export interface RouteDependencies {
router: IRouter;
config: IndexLifecycleManagementConfig;
license: License;
lib: {
handleEsError: typeof handleEsError;
};
}

0 comments on commit 92d703e

Please sign in to comment.