# Deploying Discovery

This section describes in abstract how to deploy Discovery and connect components to it.

For specific examples, see [Example deployment to a single host](discovery-example-deploying-to-single-host.md) and [Example deployment to Kubernetes](discovery-example-deploying-to-single-host.md).

## Requirements

This is the first stage in migrating a Caplin Platform deployment to Discovery:

* [ ] **Deploy Discovery server**
* [ ] Connect DataSources to Discovery
* [ ] Migrate to Discovery licensing
* [ ] Migrate to peer discovery
* [ ] Migrate to scalable data services

For information on Discovery’s software, operating system, and network requirements, see [Discovery requirements](discovery-requirements.md).

You require a Discovery licence. If you don’t have one, please contact your Caplin account manager.

DataSource applications require Discovery to be available at a fixed network location: either a static IP address or hostname.

## Deploying Discovery

To deploy Discovery, follow the steps below:

1. Unzip the Discovery ZIP to a directory:

   ```
   $ unzip -qoa Discovery-__version__.zip
   ```

   ```plantuml
   @startsalt
   scale 1.25
   {
   {T
    + <color:goldenrod><&folder></color> Discovery-//version//
    ++ <color:goldenrod><&folder></color> config
    ++ <color:goldenrod><&folder></color> lib
    ++ <color:goldenrod><&folder></color> sql
    ++ <color:goldenrod><&folder></color> static
    ++ <color:CornflowerBlue><&file></color> Discovery-server-//version//.jar
    ++ <color:CornflowerBlue><&file></color> readme.txt
    ++ <color:CornflowerBlue><&file></color> discovery.sh
   }
   }
   @endsalt
   ```
2. In the `config/application.properties` file, set a cluster name unique to this deployment of the Caplin Platform. Discovery servers with like cluster names automatically cluster together.

   ```
   hazelcast.cluster-name=caplin-platform
   ```

   For more information, see [hazelcast.cluster-name](discovery-server-configuration.md#hazelcast-cluster-name) in [Discovery server configuration](discovery-server-configuration.md).
3. If this Discovery is part of a cluster of two Discovery servers (recommended in production), then, in the `config/application.properties` file, list the network locations of the cluster nodes and disable Hazelcast multicast node discovery:

   ```
   hazelcast.tcp-ip.member-list=<hostname_or_IP>[,…]
   hazelcast.multicast.enabled=false
   ```

   For more information, see [hazelcast.tcp-ip.member-list](discovery-server-configuration.md#hazelcast-tcp-ip-member-list) and [hazelcast.multicast.enabled](discovery-server-configuration.md#hazelcast-multicast-enabled) in [Discovery server configuration](discovery-server-configuration.md).

   Do not load balance connections to a Discovery cluster. Allow DataSource clients free access to connect to both nodes.
4. Configure a connection to a relational database server. If you are deploying this Discovery server as part of a cluster, configure all nodes in the cluster to connect to the same database.

   **📌 NOTE**\
   Discovery is configured by default to connect to an example HyperSQL Database (HSQLDB) server in Discovery’s `sql/` directory. Do not use HyperSQL in production deployments.
   1. In your relational database server, create a user and database for Discovery:

      **Example: Creating a user and database in MariaDB**

      ```sql
      CREATE DATABASE discovery;
      CREATE USER 'discovery'@'%' IDENTIFIED BY 'password1234';
      GRANT ALL PRIVILEGES ON discovery.* TO 'discovery'@'%';
      ```

      Always start the relational database before starting Discovery.
   2. In Discovery’s `config/application.properties` file, comment out the default database connectivity options for the example HSQLDB database and add connectivity options for your database:

      **Example: configuring a connection to MariaDB**

      ```properties
      spring.datasource.driverClassName=org.mariadb.jdbc.Driver
      spring.datasource.url=jdbc:mariadb://192.168.1.200:3306/discovery
      spring.datasource.username=discovery
      spring.datasource.password=password1234
      ```
   3. Add the jar file for your database’s JDBC driver to Discovery’s `lib/` directory:

      **Example: Adding a JDBC driver for MariaDB**

      ```plantuml
      @startsalt
      scale 1.25
      {
      {T
       + <color:goldenrod><&folder></color> Discovery-//version//
       ++ <color:goldenrod><&folder></color> lib
       +++ <color:CornflowerBlue><&file></color> **mariadb-java-client-//version//.jar**
      }
      }
      @endsalt
      ```
5. Add your Discovery licence to the Discovery deployment directory and reference it in `config/application.properties`.

   ```plantuml
   @startsalt
   scale 1.25
   {
   {T
    + <color:goldenrod><&folder></color> Discovery-//version//
    ++ <color:CornflowerBlue><&file></color> **discovery.lic**
   }
   }
   @endsalt
   ```

   **config/application.properties**

   ```
   license.file.path=discovery.lic
   ```

   For more information, see [Discovery licensing](discovery-licensing.md).

If this is a production deployment, deploy a second Discovery server configured with the same [hazelcast/cluster-name](discovery-server-configuration.md#hazelcast-cluster-name).

To start Discovery, see [Starting and stopping Discovery](discovery-starting-stopping.md).

## Next steps

If you’re following a staged migration to Discovery, move on to the next step when you’re ready:

* [x] Deploy Discovery server
* [ ] [**Connect DataSources to Discovery**](discovery-connecting-datasources-to-discovery.md)
* [ ] Migrate to Discovery licensing
* [ ] Migrate to peer discovery
* [ ] Migrate to scalable data services
