Skip to content

Commit 0021d90

Browse files
move server code out of legacy and integrate NP license plugin
1 parent 03d8aa1 commit 0021d90

29 files changed

Lines changed: 396 additions & 183 deletions

x-pack/legacy/plugins/remote_clusters/index.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import { Legacy } from 'kibana';
88
import { resolve } from 'path';
99
import { PLUGIN } from './common';
10-
import { plugin } from './server';
1110

1211
export function remoteClusters(kibana: any) {
1312
return new kibana.Plugin({
@@ -42,20 +41,6 @@ export function remoteClusters(kibana: any) {
4241
config.get('xpack.remote_clusters.enabled') && config.get('xpack.index_management.enabled')
4342
);
4443
},
45-
init(server: any) {
46-
const { core: coreSetup } = server.newPlatform.setup;
47-
48-
const remoteClustersPluginInstance = plugin();
49-
50-
remoteClustersPluginInstance.setup(coreSetup, {
51-
__LEGACY: {
52-
route: server.route.bind(server),
53-
plugins: {
54-
xpack_main: server.plugins.xpack_main,
55-
remote_clusters: server.plugins[PLUGIN.ID],
56-
},
57-
},
58-
});
59-
},
44+
init(server: any) {},
6045
});
6146
}

x-pack/legacy/plugins/remote_clusters/public/app/store/actions/remove_clusters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const removeClusters = names => async (dispatch, getState) => {
6464
name,
6565
error: {
6666
output: {
67-
payload: { message },
67+
payload: { msg: message },
6868
},
6969
},
7070
} = errors[0];

x-pack/legacy/plugins/remote_clusters/server/lib/license_pre_routing_factory/license_pre_routing_factory.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

x-pack/legacy/plugins/remote_clusters/server/plugin.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
import { LicenseType } from '../../licensing/common/types';
9+
10+
const basicLicense: LicenseType = 'basic';
11+
12+
export const PLUGIN = {
13+
id: 'remote_clusters',
14+
// Remote Clusters are used in both CCS and CCR, and CCS is available for all licenses.
15+
minimumLicenseType: basicLicense,
16+
getI18nName: (): string => {
17+
return i18n.translate('xpack.remoteClusters.appName', {
18+
defaultMessage: 'Remote Clusters',
19+
});
20+
},
21+
};
22+
23+
export const API_BASE_PATH = '/api/remote_clusters';
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { deserializeCluster, serializeCluster } from './cluster_serialization';
8+
9+
describe('cluster_serialization', () => {
10+
describe('deserializeCluster()', () => {
11+
it('should throw an error for invalid arguments', () => {
12+
expect(() => deserializeCluster('foo', 'bar')).toThrowError();
13+
});
14+
15+
it('should deserialize a complete cluster object', () => {
16+
expect(
17+
deserializeCluster('test_cluster', {
18+
seeds: ['localhost:9300'],
19+
connected: true,
20+
num_nodes_connected: 1,
21+
max_connections_per_cluster: 3,
22+
initial_connect_timeout: '30s',
23+
skip_unavailable: false,
24+
transport: {
25+
ping_schedule: '-1',
26+
compress: false,
27+
},
28+
})
29+
).toEqual({
30+
name: 'test_cluster',
31+
seeds: ['localhost:9300'],
32+
isConnected: true,
33+
connectedNodesCount: 1,
34+
maxConnectionsPerCluster: 3,
35+
initialConnectTimeout: '30s',
36+
skipUnavailable: false,
37+
transportPingSchedule: '-1',
38+
transportCompress: false,
39+
});
40+
});
41+
42+
it('should deserialize a cluster object without transport information', () => {
43+
expect(
44+
deserializeCluster('test_cluster', {
45+
seeds: ['localhost:9300'],
46+
connected: true,
47+
num_nodes_connected: 1,
48+
max_connections_per_cluster: 3,
49+
initial_connect_timeout: '30s',
50+
skip_unavailable: false,
51+
})
52+
).toEqual({
53+
name: 'test_cluster',
54+
seeds: ['localhost:9300'],
55+
isConnected: true,
56+
connectedNodesCount: 1,
57+
maxConnectionsPerCluster: 3,
58+
initialConnectTimeout: '30s',
59+
skipUnavailable: false,
60+
});
61+
});
62+
63+
it('should deserialize a cluster object with arbitrary missing properties', () => {
64+
expect(
65+
deserializeCluster('test_cluster', {
66+
seeds: ['localhost:9300'],
67+
connected: true,
68+
num_nodes_connected: 1,
69+
initial_connect_timeout: '30s',
70+
transport: {
71+
compress: false,
72+
},
73+
})
74+
).toEqual({
75+
name: 'test_cluster',
76+
seeds: ['localhost:9300'],
77+
isConnected: true,
78+
connectedNodesCount: 1,
79+
initialConnectTimeout: '30s',
80+
transportCompress: false,
81+
});
82+
});
83+
});
84+
85+
describe('serializeCluster()', () => {
86+
it('should throw an error for invalid arguments', () => {
87+
expect(() => serializeCluster('foo')).toThrowError();
88+
});
89+
90+
it('should serialize a complete cluster object to only dynamic properties', () => {
91+
expect(
92+
serializeCluster({
93+
name: 'test_cluster',
94+
seeds: ['localhost:9300'],
95+
isConnected: true,
96+
connectedNodesCount: 1,
97+
maxConnectionsPerCluster: 3,
98+
initialConnectTimeout: '30s',
99+
skipUnavailable: false,
100+
transportPingSchedule: '-1',
101+
transportCompress: false,
102+
})
103+
).toEqual({
104+
persistent: {
105+
cluster: {
106+
remote: {
107+
test_cluster: {
108+
seeds: ['localhost:9300'],
109+
skip_unavailable: false,
110+
},
111+
},
112+
},
113+
},
114+
});
115+
});
116+
117+
it('should serialize a cluster object with missing properties', () => {
118+
expect(
119+
serializeCluster({
120+
name: 'test_cluster',
121+
seeds: ['localhost:9300'],
122+
})
123+
).toEqual({
124+
persistent: {
125+
cluster: {
126+
remote: {
127+
test_cluster: {
128+
seeds: ['localhost:9300'],
129+
skip_unavailable: null,
130+
},
131+
},
132+
},
133+
},
134+
});
135+
});
136+
});
137+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export function deserializeCluster(name: string, esClusterObject: any): any {
8+
if (!name || !esClusterObject || typeof esClusterObject !== 'object') {
9+
throw new Error('Unable to deserialize cluster');
10+
}
11+
12+
const {
13+
seeds,
14+
connected: isConnected,
15+
num_nodes_connected: connectedNodesCount,
16+
max_connections_per_cluster: maxConnectionsPerCluster,
17+
initial_connect_timeout: initialConnectTimeout,
18+
skip_unavailable: skipUnavailable,
19+
transport,
20+
} = esClusterObject;
21+
22+
let deserializedClusterObject: any = {
23+
name,
24+
seeds,
25+
isConnected,
26+
connectedNodesCount,
27+
maxConnectionsPerCluster,
28+
initialConnectTimeout,
29+
skipUnavailable,
30+
};
31+
32+
if (transport) {
33+
const { ping_schedule: transportPingSchedule, compress: transportCompress } = transport;
34+
35+
deserializedClusterObject = {
36+
...deserializedClusterObject,
37+
transportPingSchedule,
38+
transportCompress,
39+
};
40+
}
41+
42+
// It's unnecessary to send undefined values back to the client, so we can remove them.
43+
Object.keys(deserializedClusterObject).forEach(key => {
44+
if (deserializedClusterObject[key] === undefined) {
45+
delete deserializedClusterObject[key];
46+
}
47+
});
48+
49+
return deserializedClusterObject;
50+
}
51+
52+
export function serializeCluster(deserializedClusterObject: any): any {
53+
if (!deserializedClusterObject || typeof deserializedClusterObject !== 'object') {
54+
throw new Error('Unable to serialize cluster');
55+
}
56+
57+
const { name, seeds, skipUnavailable } = deserializedClusterObject;
58+
59+
return {
60+
persistent: {
61+
cluster: {
62+
remote: {
63+
[name]: {
64+
seeds: seeds ? seeds : null,
65+
skip_unavailable: skipUnavailable !== undefined ? skipUnavailable : null,
66+
},
67+
},
68+
},
69+
},
70+
};
71+
}

x-pack/legacy/plugins/remote_clusters/server/index.ts renamed to x-pack/plugins/remote_clusters/common/lib/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import { RemoteClustersServerPlugin } from './plugin';
76

8-
export const plugin = () => new RemoteClustersServerPlugin();
7+
export { deserializeCluster, serializeCluster } from './cluster_serialization';

x-pack/legacy/plugins/remote_clusters/kibana.json renamed to x-pack/plugins/remote_clusters/kibana.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"id": "remote_clusters",
33
"version": "kibana",
44
"requiredPlugins": [
5-
"home"
5+
"licensing"
66
],
77
"server": true,
8-
"ui": true
8+
"ui": false
99
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { PluginInitializerContext } from 'kibana/server';
7+
import { RemoteClustersServerPlugin } from './plugin';
8+
9+
export const plugin = (ctx: PluginInitializerContext) => new RemoteClustersServerPlugin(ctx);

0 commit comments

Comments
 (0)