# Migrating to peer discovery

Enable Discovery’s peer discovery in your Caplin Platform deployment to simplify peer-connectivity configuration.

To allow new instances of Transformer and adapters to be recognised by [data services](../datasource/datasource-data-services.md), follow this migration step with [Configuring scalable data services](discovery-migrating-scalable-data-services.md).

## Requirements

The instructions on this page assume that you have already completed the first three stages in the migration path below:

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

## Overview

Plan to migrate all components in a deployment from `add-peer` to peer discovery together. Mixed peer connectivity configuration is not supported.

In a Discovery deployment with peer discovery, DataSources that provide data initiate connections to DataSources that request data. If your current deployment follows the reverse convention, you may need to reconfigure internal firewalls to accommodate Discovery’s approach.

**With Discovery’s peer discovery, providing DataSources connect outwards to requesting DataSources**

```plantuml
component Adapter
component Transformer
component Liberator

Liberator <-right- Transformer : Connects
Transformer <-right- Adapter : Connects
Liberator <-right- Adapter : Connects
```

Connections between DataSource components created by peer-discovery are unencrypted.

To migrate a deployment to peer discovery, you may need to make significant changes to configuration. How much configuration you need to change, and where you need to change it, depends on whether your deployment’s configuration is under manual control or under the management of the Deployment Framework.

* If your deployment’s configuration is under manual control, follow instructions in [Manually configured deployments](#manually-configured-deployments).
* If your deployment’s configuration is managed by the Deployment Framework, follow the instructions in [Deployment Framework deployments](#deployment-framework-deployments).

## Manually configured deployments

Follow the instructions in this section if you manage the configuration of Liberator, Transformer, and adapters separately and manually.

The instructions in this section are also relevant for manual reconfiguration of Deployment Framework blades not yet adapted for Discovery deployments.

Follow the steps below:

1. Remove [`add-peer`](../datasource/datasource-datasource-peers-configuration-part-1.md#add-peer) items.

   **List configuration files containing `__add-peer__`**

   ```
   $ grep -RIl --include='*.conf' 'add-peer'
   ```
2. Remove [`peer-thread-pool-size`](../datasource/datasource-datasource-peers-configuration-part-2.md#peer-thread-pool-size) (if present).

   **List configuration files containing `__peer-thread-pool-size__`**

   ```
   $ grep -RIl --include='*.conf' 'peer-thread-pool-size'
   ```
3. Examine the `add-data-service` configuration items in your deployment, and rename any [`service-name`](../datasource/datasource-data-services-configuration.md#service-name) options that are not unique.

   **List configuration files containing `__add-data-service__`**

   ```
   $ grep -RIl --include='*.conf' 'add-data-service'
   ```
4. For each configured data service in your deployment, follow the steps below:
   1. Identify the providing DataSource(s) of the data service:

      ```
      add-data-service
        service-name __service_name__ ①
        …
        add-source-group
          add-priority-group
            remote-label __label__ ②
          end-priority-group
        end-source-group
      end-data-service
      ```
      1. Data service name
      2. Providing DataSource label
   2. Add the following configuration to the providing DataSource’s configuration file:

      ```
      discovery-provide-service __service_name__ ①
      ```
      1. Data service name (identical to the `service-name` value in the corresponding data service)

## Deployment Framework deployments

Follow the instructions in this section if your deployment is managed by the Deployment Framework.

With the exception of the TransformerToLiberatorConnection and TransformerToLiberatorConnectionSSL configuration blades, static peer connectivity configuration (`add-peer`) is most likely to be found in adapter blades.

Follow the steps below:

1. Deactivate the TransformerToLiberatorConnection and TransformerToLiberatorConnectionSSL blades:

   ```
   $ ./dfw deactivate TransformerToLiberatorConnection
   $ ./dfw deactivate TransformerToLiberatorConnectionSSL
   ```
2. Remove [`peer-thread-pool-size`](../datasource/datasource-datasource-peers-configuration-part-2.md#peer-thread-pool-size) configuration (if present):

   **List configuration files containing `__peer-thread-pool-size__`**

   ```
   $ grep -RIl --include='*.conf' 'peer-thread-pool-size' active_blades global_config/overrides
   ```
3. If a deployed adapter provides a configuration blade for Discovery deployments, activate it.

   **List available blades in your deployment**

   ```
   $ ./dfw versions
   ```
4. If a deployed adapter does not provide a configuration blade for Discovery deployments, follow the instructions in [Reconfiguring an adapter blade manually](#reconfiguring-an-adapter-blade-manually).

### Reconfiguring an adapter blade manually

Adapters without conditional configuration for Discovery deployments require manual reconfiguration to enable peer discovery. This is a temporary requirement until the adapter’s developers provide adaptations for Discovery deployments.

Configuration file locations for a deployed adapter (__blade_name__) are illustrated below for your reference:

**Location of configuration files for a deployed adapter**

```plantuml
@startsalt
scale 1.25
{
{T
 + <color:goldenrod><&folder></color> DeploymentFramework-//version//
 ++ <color:goldenrod><&folder></color> active_blades
 +++ <color:goldenrod><&folder></color> <color:blue>//blade_name//</color> | <color:gray><&share> ../kits///blade_name///Latest</color>
 ++ <color:goldenrod><&folder></color> global_config
 +++ <color:goldenrod><&folder></color> overrides  
 ++++ <color:goldenrod><&folder></color> <color:blue>//blade_name//</color>
 +++++ <color:goldenrod><&folder></color> **etc** | <color:gray>Configuration overrides</color>
 +++++ <color:goldenrod><&folder></color> Liberator
 ++++++ <color:goldenrod><&folder></color> **etc** | <color:gray>Configuration overrides</color>
 +++++ <color:goldenrod><&folder></color> Transformer
 ++++++ <color:goldenrod><&folder></color> **etc** | <color:gray>Configuration overrides</color>
 ++ <color:goldenrod><&folder></color> kits
 +++ <color:goldenrod><&folder></color> <color:blue>//blade_name//</color>
 ++++ <color:goldenrod><&folder></color> Latest | <color:gray><&share> .///blade_name-version//
 ++++ <color:goldenrod><&folder></color> //<color:blue>blade_name</color>-version//
 +++++ <color:goldenrod><&folder></color> DataSource
 ++++++ <color:goldenrod><&folder></color> **etc** | <color:gray>Core configuration</color>
 +++++ <color:goldenrod><&folder></color> Liberator
 ++++++ <color:goldenrod><&folder></color> **etc** | <color:gray>Core configuration</color>
 +++++ <color:goldenrod><&folder></color> Transformer
 ++++++ <color:goldenrod><&folder></color> **etc** | <color:gray>Core configuration</color>
}
}
@endsalt
```

Follow the steps below:

1. Remove [`add-peer`](../datasource/datasource-datasource-peers-configuration-part-1.md#add-peer) items from the adapter’s configuration files.

   **List configuration files containing `__add-peer__`**

   ```
   $ grep -RIl --include='*.conf' 'add-peer' active_blades global_config/overrides
   ```
2. Remove [`peer-thread-pool-size`](../datasource/datasource-datasource-peers-configuration-part-2.md#peer-thread-pool-size) from the adapter’s configuration (if present).

   **List configuration files containing `__peer-thread-pool-size__`**

   ```
   $ grep -RIl --include='*.conf' 'peer-thread-pool-size' active_blades global_config/overrides
   ```
3. Examine the `add-data-service` configuration items in the adapter’s configuration. Rename any [`service-name`](../datasource/datasource-data-services-configuration.md#service-name) options that are not unique. Data services in Liberator and Transformer, for example, should not share the same `service-name`, for example.

   **List configuration files containing `__add-data-service__`**

   ```
   $ grep -RIl --include='*.conf' 'add-data-service' active_blades global_config/overrides
   ```
4. For each configured data service in the adapter’s configuration, follow the steps below:
   1. Identify the providing DataSource(s) of the data service (`remote-label` below):

      ```
      add-data-service
        service-name __service_name__ ①
        …
        add-source-group
          add-priority-group
            remote-label __label__ ②
          end-priority-group
        end-source-group
      end-data-service
      ```
      1. Data service name
      2. Providing DataSource label
   2. Add the following configuration to the providing DataSource’s configuration file packaged in the adapter’s blade:

      ```
      discovery-provide-service __service_name__ ①
      ```
      1. Data service name (identical to the `service-name` value in the corresponding data service)

**Manual reconfiguration of an adapter for peer-discovery**

Consider an adapter, TradeAdapter, that serves trade channels direct to Liberator and blotter data to Liberator via Transformer.

In this specific adapter, `add-peer` and `add-data-service` configuration items are included in the adapter’s core configuration files and deployed under `kits/TradeAdapter/Latest`:

```plantuml
@startsalt
scale 1.25
{
{T
 + <color:goldenrod><&folder></color> DeploymentFramework-//version//
 ++ <color:goldenrod><&folder></color> kits
 +++ <color:goldenrod><&folder></color> TradeAdapter
 ++++ <color:goldenrod><&folder></color> Latest | <color:gray><&share> ./TradeAdapter-//version//
 ++++ <color:goldenrod><&folder></color> TradeAdapter-//version//
 +++++ <color:goldenrod><&folder></color> DataSource
 ++++++ <color:goldenrod><&folder></color> etc
 +++++++ <color:cornflowerblue><&cog></color> **datasource.conf** | <color:gray>Core configuration file</color>
 +++++ <color:goldenrod><&folder></color> Liberator
 ++++++ <color:goldenrod><&folder></color> etc
 +++++++ <color:cornflowerblue><&cog></color> **rttpd.conf** | <color:gray>Core configuration file</color>
 +++++ <color:goldenrod><&folder></color> Transformer
 ++++++ <color:goldenrod><&folder></color> etc
 +++++++ <color:cornflowerblue><&cog></color> **transformer.conf** | <color:gray>Core configuration file</color>
}
}
@endsalt
```

All three configuration files above require changes, illustrated in DIFF format below:

**kits/TradeAdapter/Latest/Liberator/etc/rttpd.conf**

```diff
- add-peer
-   remote-label Transformer ①
- end-peer

- add-peer
-   remote-label TradeAdapter ①
- end-peer

add-data-service
  service-name trade-channel
  ...
  add-source-group
    add-priority
      remote-label TradeAdapter
    end-priority
  end-source-group
end-data-service

add-data-service
-  service-name trade-blotter
+  service-name transformer-trade-blotter ②
  ...
  add-source-group
    add-priority
      remote-label Transformer
    end-priority
  end-source-group
end-data-service
```
1. Remove `add-peer` configuration
2. Rename the `trade-blotter` service -- it clashes with the name of the related data service in Transformer.

**kits/TradeAdapter/Latest/Transformer/etc/transformer.conf**

```diff
- add-peer
-   remote-label Liberator ①
-   addr 192.168.1.100
-   port 15001
- end-peer

- add-peer
-   remote-label TradeAdapter ①
- end-peer

add-data-service
  service-name trade-blotter
  ...
  add-source-group
    add-priority
      remote-label TradeAdapter
    end-priority
  end-source-group
end-data-service

+ discovery-provide-service transformer-trade-blotter ②
```
1. Remove `add-peer` configuration
2. Add `discovery-provide-service`

**kits/TradeAdapter/Latest/etc/datasource.conf**

```diff
- add-peer
-   remote-label Transformer ①
-   addr 192.168.1.200
-   port 15002
- end-peer

- add-peer
-   remote-label Liberator ①
-   addr 192.168.1.100
-   port 15001
- end-peer

+ discovery-provide-service trade-channel ②
+ discovery-provide-service trade-blotter ②
```
1. Remove `add-peer` configuration
2. Add `discovery-provide-service`

## 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
* [x] Connect DataSources to Discovery
* [x] Migrate to Discovery licensing
* [x] Migrate to peer discovery
* [ ] [**Migrate to scalable data services**](discovery-migrating-scalable-data-services.md)
