Neo4j Server¶
Neo4j Server is an implementation of the server side of the community version of the Neo4j Graph Database Management System (DMS).
The official Neo4j documentation can be found here.
Initialization¶
The user can pass an initialization bash (.sh
) script to the job. The script will be executed before the Neo4j server is started.
For information on how to use the Initialization parameter, please refer to the Initialization - Bash script section of the documentation.
Starting a New or Existing Database¶
When starting a job, the user must specify the Database path parameter to either launch an existing database or create a new database.
If the user wants to launch an existing database, the Database path should point to the top-level folder in a Neo4j DBMS instance, i.e., the folder which contains subfolders /databases
, /dbms
, /transactions
, and the file server_id
.
The name of one of the databases in /databases
must be set as the Default database.
If the user wants to create a new, empty database, an empty folder should be mounted as the Database path. The new default database will be given the name provided in the Default database parameter.
Note
It is only possible to create one database in a running server instance.
Credentials¶
If an existing database is mounted, the credentials of that database must be used when connecting to the server.
If a new database in created, the user can choose to set a password for the DBMS using the Password optional parameter. If no password is provided, the password is set as ucloud
. The default username is always neo4j
.
The password can be changed e.g., with the following Cypher
query:
ALTER USER neo4j SET PASSWORD '<new-password>'
Important
If the credentials are changed, the user should remember these for future use of the database.
Importing Data¶
To make data files available for import into a Neo4j database, the folder containing the data files must be mounted using the Import path optional parameter.
Different data file formats are supported: .csv
files can be imported using Cypher. Other, common file formats can be imported using the APOC
core plugin.
Periodic Data Dumps¶
Data dumps are disabled by default, but it is possible to schedule periodic dumps of the data in the database. To enable periodic data dumps, the user must set the Dump frequency optional parameter. This should be set to the desired number of minutes from the start of the job to the first data dump, and after that, between consecutive dumps.
Each data dump is stored in a dedicated folder in /work/backups
and is named as <timestamp>_dump
.
Note
Only data in the Default database
(nodes, relationshipts etc.) are dumped. Metadata about e.g., transactions are not parts of the data dump.
If the user mounts an existing DBMS in Database path and also enables data dumps, the Default database and Password optional parameters must be set with the values of the mounted DBMS for the the data dumping procedure to work.
Restoring a database from a data dump¶
It is possible to populate an empty database instance with the data from a data dump using the following steps:
Start a job with the following parameter values:
An empty folder mounted as the Database path.
The folder containing the data dump mounted using the Add folder option.
Other optional parameters can be set as needed.
Start the job.
Open a terminal window inside the running job and run the Python script
import_from_dump.py
located in/usr/bin/
:
$ import_from_dump.py -o <port> -u <username> -p <password> -d <database> -f <dump_dir>
Note
Fill in the parameter values in angle brackets with the values in the given job. Set <database>
to Default database
and <dump_dir>
to the path of the of the data dump, which will be available in /work/
.
Plugins¶
It is possible to extend Neo4j's built-in functionality using plugins.
Plugins are implemented as standalone .jar
files. To make plugins available inside the job, a folder containing the plugin (i.e., .jar
) files must be mounted to the job using the Plugins path optional parameter.
The APOC core
plugin is included per default.
Some plugins require specific configurations of the Neo4j server instance. Such changes can be made using an initialization script or with a custom configuration file.
Note
The primary configuration file is located in /var/lib/neo4j/conf/neo4j.conf
.
Custom Configuration¶
The user can provide a custom configuration file using the Custom configuration file
optional parameter. If provided, this file will fully replaces the existing configuration file.
In any custom configuration file, the user should be aware of the following:
The server should listen on
0.0.0.0
.The mountpoint for folders is
/work
which should be taken into consideration when setting the different server directories.
A custom configuration file will take precedence over other optional parameters. This means that if the user provides a custom configuration file, other optional parameters (e.g., Default database
, Password
etc.) may not be used even if the user sets them from the job submission page.
Furthermore, if a custom configuration file is provided, its validity is tested before starting the server. A unsuccessful validation will lead to termination of the job. Aside from that, fewer correctness checks on the configurations are done prior to starting the DBMS compared to when this optional parameter is not used.
Use Cypher Shell from the Job Terminal¶
The database can be accessed with a Cypher Shell from inside a running Neo4j job. To do this, click the Open terminal button to access the job's terminal interface.
From the job terminal, enter
$ cypher-shell
The user will then be prompted for the credentials for the DBMS. Once the correct credentials have been provided, the Cypher Shell will start and the user can interact with the DBMS using Cypher queries.
Note
If the Port optional parameter has been set, the user must specify the address of the server (using -a
) when calling cypher-shell
.
Connect to a Server Instance¶
If a Neo4j client application runs within another app available on UCloud, the user can connect directly to the Neo4j server as described here. In this case, the server hostname is configured as an external parameter via the Connect to jobs optional parameter.
On the other hand, if the Neo4j client is a third-party application not running on UCloud, it is necessary to assign a static IP address to the server, using the App public IP option.
Note
By default, remote access to the Neo4j server is established via a TCD/IP connection over port 7687 (or the port number specified in the Port optional parameter). The static IP address must listen to the same port to establish connection.
Examples of client applications¶
From a client job, the Neo4j server can be queried e.g., via a Cypher Shell. To do this, the user must set up Cypher Shell inside the client job, and use the -a
option to specify the address of the server when starting the Cypher Shell.
Furthermore, Neo4j has officially- and community-supported drivers for many common programming languages such as Python, Javascript, and Go (see this list). In addition, IDEs such as Coder have extensions for Cypher language support and server connection management.
Visualizations with Gephi¶
Data from a Neo4j database can be visualized by means of the Gephi app. In this case, Gephi should be connected to the to the Neo4j instance using the optional parameter Connect to other jobs.
Open the Gephi interface and install the Neo4j plugin. This plugin can be found under Tools > Plugins > Avaliable Plugins.
To import data from a running Neo4j Server instance, click File > Import... and select Neo4j - Import networks from a Neo4j database as the Wizard type.
Set neo4j://<neo4j-servername>
as the URL, Default database as Database and fill in the credentials. Here, <neo4j-servername>
is the hostname chosen when connecting Gephi to the Neo4j instance. The connection can be checked by clicking on Verify after filling in the different fields.
The final step is to choose what data to import. Here, the user can either select one or more Labels and/or Relationships, or filter the data with Cypher queries for the nodes and edges.
The following video demonstrates the procedure:
Note
This approach does not establish a lasting connection from Gephi to the Neo4j server instance. Therefore, changes made to the data in one job do not propagate to the other job. Hence, if the database is updated in the Neo4j server, the data must be re-imported to Gephi to get the changes.
Contents