Skip to content

Commit

Permalink
[Remote clusters] Migrate to new ES client (#98747) (#99220)
Browse files Browse the repository at this point in the history
* migrate add cluster route and jest tests

* migrated delete remote clusters route

* migrated the get route

* migrated the update route

* added shared types file

* reduce some test boilerplate

* fix type issues introduced by new types from ES client

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Jean-Louis Leysens <jloleysens@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people committed May 4, 2021
1 parent 87824da commit 354bcf4
Show file tree
Hide file tree
Showing 14 changed files with 917 additions and 888 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import { PROXY_MODE } from '../constants';

// Values returned from ES GET /_remote/info
/**
* TODO: This interface needs to be updated with values from {@link RemoteInfo} provided
* by the @elastic/elasticsearch client
*/
export interface ClusterInfoEs {
seeds?: string[];
mode?: 'proxy' | 'sniff';
connected?: boolean;
num_nodes_connected?: number;
max_connections_per_cluster?: number;
initial_connect_timeout?: string;
max_connections_per_cluster?: string | number;
initial_connect_timeout: string | number;
skip_unavailable?: boolean;
transport?: {
ping_schedule?: string;
Expand All @@ -39,8 +43,8 @@ export interface Cluster {
transportPingSchedule?: string;
transportCompress?: boolean;
connectedNodesCount?: number;
maxConnectionsPerCluster?: number;
initialConnectTimeout?: string;
maxConnectionsPerCluster?: string | number;
initialConnectTimeout?: string | number;
connectedSocketsCount?: number;
hasDeprecatedProxySetting?: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
* 2.0.
*/

export async function doesClusterExist(callAsCurrentUser: any, clusterName: string): Promise<any> {
import { IScopedClusterClient } from 'src/core/server';

export async function doesClusterExist(
clusterClient: IScopedClusterClient,
clusterName: string
): Promise<boolean> {
try {
const clusterInfoByName = await callAsCurrentUser('cluster.remoteInfo');
const { body: clusterInfoByName } = await clusterClient.asCurrentUser.cluster.remoteInfo();
return Boolean(clusterInfoByName && clusterInfoByName[clusterName]);
} catch (err) {
throw new Error('Unable to check if cluster already exists.');
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/remote_clusters/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
registerDeleteRoute,
} from './routes/api';

import { handleEsError } from './shared_imports';

export interface RemoteClustersPluginSetup {
isUiEnabled: boolean;
}
Expand All @@ -44,6 +46,9 @@ export class RemoteClustersServerPlugin
config: {
isCloudEnabled: Boolean(cloud?.isCloudEnabled),
},
lib: {
handleEsError,
},
};

features.registerElasticsearchFeature({
Expand Down
Loading

0 comments on commit 354bcf4

Please sign in to comment.