From 256508478c830acce99bfec3b2991cbd221e46b4 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Sun, 29 Mar 2020 17:44:12 -0400 Subject: [PATCH] [Remote clusters] Add cloud-specific logic to remote clusters (#61639) --- .../common/lib/cluster_serialization.test.ts | 34 ++++++++ .../common/lib/cluster_serialization.ts | 7 +- x-pack/plugins/remote_clusters/kibana.json | 3 +- .../public/application/app_context.tsx | 22 +++++ .../public/application/index.d.ts | 5 +- .../public/application/index.js | 11 ++- .../remote_cluster_form.test.js.snap | 15 +++- .../remote_cluster_form.js | 67 ++++++++++++--- .../remote_cluster_form/validators/index.js | 1 + .../validators/validate_server_name.js | 21 +++++ .../plugins/remote_clusters/public/plugin.ts | 6 +- .../plugins/remote_clusters/public/types.ts | 2 + .../plugins/remote_clusters/server/plugin.ts | 5 +- .../server/routes/api/add_route.test.ts | 3 + .../server/routes/api/delete_route.test.ts | 3 + .../server/routes/api/get_route.test.ts | 3 + .../server/routes/api/get_route.ts | 8 +- .../server/routes/api/update_route.test.ts | 82 +++++++++++++++++++ .../server/routes/api/update_route.ts | 1 + .../plugins/remote_clusters/server/types.ts | 5 ++ 20 files changed, 276 insertions(+), 28 deletions(-) create mode 100644 x-pack/plugins/remote_clusters/public/application/app_context.tsx create mode 100644 x-pack/plugins/remote_clusters/public/application/sections/components/remote_cluster_form/validators/validate_server_name.js diff --git a/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.test.ts b/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.test.ts index 7fd8b4a894989..a204bd44901b7 100644 --- a/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.test.ts +++ b/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.test.ts @@ -112,6 +112,40 @@ describe('cluster_serialization', () => { }, 'localhost:9300' ) + ).toEqual({ + name: 'test_cluster', + proxyAddress: 'localhost:9300', + mode: 'proxy', + hasDeprecatedProxySetting: true, + isConnected: true, + connectedNodesCount: 1, + maxConnectionsPerCluster: 3, + initialConnectTimeout: '30s', + skipUnavailable: false, + transportPingSchedule: '-1', + transportCompress: false, + }); + }); + + it('should deserialize a cluster that contains a deprecated proxy address and is in cloud', () => { + expect( + deserializeCluster( + 'test_cluster', + { + seeds: ['localhost:9300'], + connected: true, + num_nodes_connected: 1, + max_connections_per_cluster: 3, + initial_connect_timeout: '30s', + skip_unavailable: false, + transport: { + ping_schedule: '-1', + compress: false, + }, + }, + 'localhost:9300', + true + ) ).toEqual({ name: 'test_cluster', proxyAddress: 'localhost:9300', diff --git a/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.ts b/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.ts index 3d8ffa13b8218..07dbe8da28d8a 100644 --- a/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.ts +++ b/x-pack/plugins/remote_clusters/common/lib/cluster_serialization.ts @@ -68,7 +68,8 @@ export interface ClusterSettingsPayloadEs { export function deserializeCluster( name: string, esClusterObject: ClusterInfoEs, - deprecatedProxyAddress?: string | undefined + deprecatedProxyAddress?: string | undefined, + isCloudEnabled?: boolean | undefined ): Cluster { if (!name || !esClusterObject || typeof esClusterObject !== 'object') { throw new Error('Unable to deserialize cluster'); @@ -117,7 +118,7 @@ export function deserializeCluster( // If a user has a remote cluster with the deprecated proxy setting, // we transform the data to support the new implementation and also flag the deprecation if (deprecatedProxyAddress) { - // Create server name (address, without port), since field doesn't exist in deprecated implementation + // Cloud-specific logic: Create default server name, since field doesn't exist in deprecated implementation const defaultServerName = deprecatedProxyAddress.split(':')[0]; deserializedClusterObject = { @@ -126,7 +127,7 @@ export function deserializeCluster( seeds: undefined, hasDeprecatedProxySetting: true, mode: PROXY_MODE, - serverName: defaultServerName, + serverName: isCloudEnabled ? defaultServerName : undefined, }; } diff --git a/x-pack/plugins/remote_clusters/kibana.json b/x-pack/plugins/remote_clusters/kibana.json index 8922bf621aa03..f1b9d20f762d3 100644 --- a/x-pack/plugins/remote_clusters/kibana.json +++ b/x-pack/plugins/remote_clusters/kibana.json @@ -11,7 +11,8 @@ "indexManagement" ], "optionalPlugins": [ - "usageCollection" + "usageCollection", + "cloud" ], "server": true, "ui": true diff --git a/x-pack/plugins/remote_clusters/public/application/app_context.tsx b/x-pack/plugins/remote_clusters/public/application/app_context.tsx new file mode 100644 index 0000000000000..86c0b401d416d --- /dev/null +++ b/x-pack/plugins/remote_clusters/public/application/app_context.tsx @@ -0,0 +1,22 @@ +/* + * 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 React, { createContext } from 'react'; + +export interface Context { + isCloudEnabled: boolean; +} + +export const AppContext = createContext({} as any); + +export const AppContextProvider = ({ + children, + context, +}: { + children: React.ReactNode; + context: Context; +}) => { + return {children}; +}; diff --git a/x-pack/plugins/remote_clusters/public/application/index.d.ts b/x-pack/plugins/remote_clusters/public/application/index.d.ts index b5c5ad5522134..b021dca51bacd 100644 --- a/x-pack/plugins/remote_clusters/public/application/index.d.ts +++ b/x-pack/plugins/remote_clusters/public/application/index.d.ts @@ -8,5 +8,8 @@ import { RegisterManagementAppArgs, I18nStart } from '../types'; export declare const renderApp: ( elem: HTMLElement | null, - I18nContext: I18nStart['Context'] + I18nContext: I18nStart['Context'], + appDependencies: { + isCloudEnabled?: boolean; + } ) => ReturnType; diff --git a/x-pack/plugins/remote_clusters/public/application/index.js b/x-pack/plugins/remote_clusters/public/application/index.js index 0b8b26ace5daa..f2d788c741342 100644 --- a/x-pack/plugins/remote_clusters/public/application/index.js +++ b/x-pack/plugins/remote_clusters/public/application/index.js @@ -11,14 +11,17 @@ import { Provider } from 'react-redux'; import { App } from './app'; import { remoteClustersStore } from './store'; +import { AppContextProvider } from './app_context'; -export const renderApp = (elem, I18nContext) => { +export const renderApp = (elem, I18nContext, appDependencies) => { render( - - - + + + + + , elem diff --git a/x-pack/plugins/remote_clusters/public/application/sections/components/remote_cluster_form/__snapshots__/remote_cluster_form.test.js.snap b/x-pack/plugins/remote_clusters/public/application/sections/components/remote_cluster_form/__snapshots__/remote_cluster_form.test.js.snap index 6ff8c538ca89c..4c109c557fdb0 100644 --- a/x-pack/plugins/remote_clusters/public/application/sections/components/remote_cluster_form/__snapshots__/remote_cluster_form.test.js.snap +++ b/x-pack/plugins/remote_clusters/public/application/sections/components/remote_cluster_form/__snapshots__/remote_cluster_form.test.js.snap @@ -5,7 +5,6 @@ exports[`RemoteClusterForm proxy mode renders correct connection settings when u disabledFields={Object {}} fields={ Object { - "mode": "sniff", "name": "", "nodeConnections": 3, "proxyAddress": "", @@ -805,6 +804,7 @@ exports[`RemoteClusterForm proxy mode renders correct connection settings when u data-test-subj="remoteClusterFormServerNameFormRow" describedByIds={Array []} display="row" + error={null} fullWidth={true} hasChildLabel={true} hasEmptyLabelSpace={false} @@ -827,10 +827,11 @@ exports[`RemoteClusterForm proxy mode renders correct connection settings when u } /> } + isInvalid={false} label={ } @@ -845,18 +846,21 @@ exports[`RemoteClusterForm proxy mode renders correct connection settings when u className="euiFormRow__labelWrapper" >