Data::AnyXfer::Elastic::ServerDefinition - Stores node and cluster information
use Data::AnyXfer::Elastic::ServerDefinition (); # Load definitions... # from a path my @definitions = Data::AnyXfer::Elastic::ServerDefinition ->load_json_file('servers.json'); # or from an open handle open(my $open_fh, '<:encoding(UTF-8)', 'servers.json') || croak "Failed to open server definitions file ($!)"; my @definitions = Data::AnyXfer::Elastic::ServerDefinition ->load_json_handle($open_fh); # Or define them programatically... my $definition = Data::AnyXfer::Elastic::ServerDefinition->new( name => 'testserver', env => 'live', installed_version => '6.4.0', silos => ["public_data"], standalone_nodes => ["test-es-1.example.com:9200"], cluser_nodes => ["test-es-1.example.com:9201"], } );
The class represents the information required to interact with an Elasticsearch server.
This can consist of a traditional cluster, or a number of seperate instances acting as a cluster.
These definitions will usually be "load" in loaded from a JSON file.
ENV_VARNAME
This is the ENV variable name which "load_env" will use to source and load as a server definition JSON file.
name
E.g. -> 'my-test-name'
Type: SLUG/SIMPLE STRING
The name of the server cluster or standalone server group.
env
E.g. -> 'production'
An environment value for the definition. This will be used by calling code to find the correct definition for the runtime environment.
installed_version
E.g. -> '6.4.0'
Type: VERSION STRING
The installed elasticsearch version for the cluster or standalone server group.
This will be used to adjust queries and API calls to allow support for both the ES 3.5.x range and ES 6+ as there were major API and ABI breakages between these versions.
cluser_nodes
E.g. -> [ 'localhost:9200' ]
Type: ARRAY
An array of URI strings for each node in the cluster, without the protocol.
standalone_nodes
An array of URI strings for each node in the standalone cluster, without the protocol.
These nodes should be kept in sync with the same data, and will act as multipel 1x1 node clusters operating as a single group for high availability without clustering and recovery overheads (and associated pitfalls).
silos
E.g. -> [ 'public_data', 'sensitive_data' ]
An array of silo strings, used to "zone" servers and allow different servers to contain different datasets.
my $def = Data::AnyXfer::Elastic::ServerDefinition->new; # extra validation errors thrown
Extra validation of some attributes happens during the Moo (MOP) BUILD hook / phase.
my @definitions = Data::AnyXfer::Elastic::ServerDefinition->load_json_handle($fh);
Loads the server definition from the supplied JSON file handle.
my @definitions = Data::AnyXfer::Elastic::ServerDefinition->load_json_file($file);
Loads the server definition from the supplied JSON file path.
# Launched with DATA_ANYXFER_SERVERS_FILE="~/servers.json" perl my @definitions = Data::AnyXfer::Elastic::ServerDefinition->load_from_env;
if ($server->belongs_to('public_data')) { # do something with it }
Checks if a server definition belongs to the supplied silo.
Return 1 if it does, otherwise returns 0.
1
0
This will return the primary node information for data importing.
In an environment with standalone node clusters, it will return just these nodes, as these should be your heavy read nodes.
['node1'], ['node2'], ['node3']
A definition without standalone nodes will return the clustered nodes as such:
['node1', 'node2', 'node3']
Each element in the array returned by this method will be treated as a single target for population, this is why a multi-dimensional array is used, signifingy that all nodes in a real multicast ES cluster should be used for a single transport (they will be round-robined in the case connection failure).
This software is copyright (c) 2019, Anthony Lucas.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::AnyXfer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::AnyXfer
CPAN shell
perl -MCPAN -e shell install Data::AnyXfer
For more information on module installation, please visit the detailed CPAN module installation guide.