-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move server code out of legacy and integrate NP license plugin
- Loading branch information
1 parent
03d8aa1
commit 0021d90
Showing
29 changed files
with
396 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
...ins/remote_clusters/server/lib/license_pre_routing_factory/license_pre_routing_factory.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
137 changes: 137 additions & 0 deletions
137
x-pack/plugins/remote_clusters/common/lib/cluster_serialization.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
71
x-pack/plugins/remote_clusters/common/lib/cluster_serialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.