Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remote clusters] Migrate to new ES client #98747

Merged
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