Skip to content

Commit

Permalink
move server code out of legacy and integrate NP license plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Feb 5, 2020
1 parent 03d8aa1 commit 0021d90
Show file tree
Hide file tree
Showing 29 changed files with 396 additions and 183 deletions.
17 changes: 1 addition & 16 deletions x-pack/legacy/plugins/remote_clusters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { Legacy } from 'kibana';
import { resolve } from 'path';
import { PLUGIN } from './common';
import { plugin } from './server';

export function remoteClusters(kibana: any) {
return new kibana.Plugin({
Expand Down Expand Up @@ -42,20 +41,6 @@ export function remoteClusters(kibana: any) {
config.get('xpack.remote_clusters.enabled') && config.get('xpack.index_management.enabled')
);
},
init(server: any) {
const { core: coreSetup } = server.newPlatform.setup;

const remoteClustersPluginInstance = plugin();

remoteClustersPluginInstance.setup(coreSetup, {
__LEGACY: {
route: server.route.bind(server),
plugins: {
xpack_main: server.plugins.xpack_main,
remote_clusters: server.plugins[PLUGIN.ID],
},
},
});
},
init(server: any) {},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const removeClusters = names => async (dispatch, getState) => {
name,
error: {
output: {
payload: { message },
payload: { msg: message },
},
},
} = errors[0];
Expand Down

This file was deleted.

53 changes: 0 additions & 53 deletions x-pack/legacy/plugins/remote_clusters/server/plugin.ts

This file was deleted.

23 changes: 23 additions & 0 deletions x-pack/plugins/remote_clusters/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { LicenseType } from '../../licensing/common/types';

const basicLicense: LicenseType = 'basic';

export const PLUGIN = {
id: 'remote_clusters',
// Remote Clusters are used in both CCS and CCR, and CCS is available for all licenses.
minimumLicenseType: basicLicense,
getI18nName: (): string => {
return i18n.translate('xpack.remoteClusters.appName', {
defaultMessage: 'Remote Clusters',
});
},
};

export const API_BASE_PATH = '/api/remote_clusters';
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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 { deserializeCluster, serializeCluster } from './cluster_serialization';

describe('cluster_serialization', () => {
describe('deserializeCluster()', () => {
it('should throw an error for invalid arguments', () => {
expect(() => deserializeCluster('foo', 'bar')).toThrowError();
});

it('should deserialize a complete cluster object', () => {
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,
},
})
).toEqual({
name: 'test_cluster',
seeds: ['localhost:9300'],
isConnected: true,
connectedNodesCount: 1,
maxConnectionsPerCluster: 3,
initialConnectTimeout: '30s',
skipUnavailable: false,
transportPingSchedule: '-1',
transportCompress: false,
});
});

it('should deserialize a cluster object without transport information', () => {
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,
})
).toEqual({
name: 'test_cluster',
seeds: ['localhost:9300'],
isConnected: true,
connectedNodesCount: 1,
maxConnectionsPerCluster: 3,
initialConnectTimeout: '30s',
skipUnavailable: false,
});
});

it('should deserialize a cluster object with arbitrary missing properties', () => {
expect(
deserializeCluster('test_cluster', {
seeds: ['localhost:9300'],
connected: true,
num_nodes_connected: 1,
initial_connect_timeout: '30s',
transport: {
compress: false,
},
})
).toEqual({
name: 'test_cluster',
seeds: ['localhost:9300'],
isConnected: true,
connectedNodesCount: 1,
initialConnectTimeout: '30s',
transportCompress: false,
});
});
});

describe('serializeCluster()', () => {
it('should throw an error for invalid arguments', () => {
expect(() => serializeCluster('foo')).toThrowError();
});

it('should serialize a complete cluster object to only dynamic properties', () => {
expect(
serializeCluster({
name: 'test_cluster',
seeds: ['localhost:9300'],
isConnected: true,
connectedNodesCount: 1,
maxConnectionsPerCluster: 3,
initialConnectTimeout: '30s',
skipUnavailable: false,
transportPingSchedule: '-1',
transportCompress: false,
})
).toEqual({
persistent: {
cluster: {
remote: {
test_cluster: {
seeds: ['localhost:9300'],
skip_unavailable: false,
},
},
},
},
});
});

it('should serialize a cluster object with missing properties', () => {
expect(
serializeCluster({
name: 'test_cluster',
seeds: ['localhost:9300'],
})
).toEqual({
persistent: {
cluster: {
remote: {
test_cluster: {
seeds: ['localhost:9300'],
skip_unavailable: null,
},
},
},
},
});
});
});
});
71 changes: 71 additions & 0 deletions x-pack/plugins/remote_clusters/common/lib/cluster_serialization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.
*/

export function deserializeCluster(name: string, esClusterObject: any): any {
if (!name || !esClusterObject || typeof esClusterObject !== 'object') {
throw new Error('Unable to deserialize cluster');
}

const {
seeds,
connected: isConnected,
num_nodes_connected: connectedNodesCount,
max_connections_per_cluster: maxConnectionsPerCluster,
initial_connect_timeout: initialConnectTimeout,
skip_unavailable: skipUnavailable,
transport,
} = esClusterObject;

let deserializedClusterObject: any = {
name,
seeds,
isConnected,
connectedNodesCount,
maxConnectionsPerCluster,
initialConnectTimeout,
skipUnavailable,
};

if (transport) {
const { ping_schedule: transportPingSchedule, compress: transportCompress } = transport;

deserializedClusterObject = {
...deserializedClusterObject,
transportPingSchedule,
transportCompress,
};
}

// It's unnecessary to send undefined values back to the client, so we can remove them.
Object.keys(deserializedClusterObject).forEach(key => {
if (deserializedClusterObject[key] === undefined) {
delete deserializedClusterObject[key];
}
});

return deserializedClusterObject;
}

export function serializeCluster(deserializedClusterObject: any): any {
if (!deserializedClusterObject || typeof deserializedClusterObject !== 'object') {
throw new Error('Unable to serialize cluster');
}

const { name, seeds, skipUnavailable } = deserializedClusterObject;

return {
persistent: {
cluster: {
remote: {
[name]: {
seeds: seeds ? seeds : null,
skip_unavailable: skipUnavailable !== undefined ? skipUnavailable : null,
},
},
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { RemoteClustersServerPlugin } from './plugin';

export const plugin = () => new RemoteClustersServerPlugin();
export { deserializeCluster, serializeCluster } from './cluster_serialization';
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"id": "remote_clusters",
"version": "kibana",
"requiredPlugins": [
"home"
"licensing"
],
"server": true,
"ui": true
"ui": false
}
9 changes: 9 additions & 0 deletions x-pack/plugins/remote_clusters/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 { PluginInitializerContext } from 'kibana/server';
import { RemoteClustersServerPlugin } from './plugin';

export const plugin = (ctx: PluginInitializerContext) => new RemoteClustersServerPlugin(ctx);
Loading

0 comments on commit 0021d90

Please sign in to comment.