Last updated Nov 8, 2023

Migrate atlassian-app-cloud-migration-osgi to discoverable listener

Introduction

This tutorial shows you how to migrate your app from atlassian-app-cloud-migration-osgi to the discoverable listener in the atlassian-app-cloud-migration-listener library.

See a sample app

This section provides a sample app that you can use to verify your implementation. You can clone the repository that contains the source code of the sample app from Bitbucket.

Getting started

There are three main steps to change your app code to using the discoverable listener in the atlassian-app-cloud-migration-listener library.

Step 1: Update dependency management

Step 2: Change to the DiscoverableListener interface

Step 3: Atlassian Spring Scanner and atlassian-plugin.xml

Detailed steps

Step 1: Update dependency management

These examples are for your pom.xml and maven, but the steps are similar for other dependency management systems.

Remove the package com.atlassian.migration.app.* from your <Import-Package> instruction.

Change the atlassian-app-cloud-migration-osgi library from pom.xml

1
2
<dependency>
    <groupId>com.atlassian</groupId>
    <artifactId>atlassian-app-cloud-migration-osgi</artifactId>
    <version>1.0.0</version>
    <scope>provided</scope>
</dependency>

to the atlassian-app-cloud-migration-listener library

1
2
<dependency>
    <groupId>com.atlassian</groupId>
    <artifactId>atlassian-app-cloud-migration-listener</artifactId>
    <version>1.2.1</version>
</dependency>

Step 2: Change to the DiscoverableListener interface

Change your class to implement only DiscoverableListener. It no longer needs to implement DisposableBean.

1
2
public class MyPluginComponentImpl implements DiscoverableListener { }

You will no longer need AppCloudMigrationGateway migrationGateway in your class constructor, so you do not need to call migrationGateway.registerListener(this); to register your class.

The first argument of onStartAppMigration() is now AppCloudMigrationGateway. You do not need to store a reference to it.

1
2
 public void onStartAppMigration(AppCloudMigrationGateway gateway, String transferId, MigrationDetailsV1 migrationDetails) { }

If your app key is different to your OSGi bundle name then you will need to implement getServerAppKey() from DiscoverableListener.

1
2
@Override
public String getServerAppKey() {
    return "my-server-app-key";
}

If your app key is the same as your OSGi bundle name, then you don't need to implement getServerAppKey() as we provide a default implementation.

Step 3: Atlassian Spring Scanner and atlassian-plugin.xml

From atlassian-plugin.xml remove

1
2
<component-import key="cloudMigrationListener" interface="com.atlassian.migration.app.AppCloudMigrationGateway"/>

<component key="myPlugin" class="com.vendor.impl.MyPluginComponentImpl">
    <interface>com.vendor.MyPluginComponent</interface>
</component>

Atlassian Spring Scanner 1.0

If you are using Spring Scanner 1.0, then in your atlassian-plugin.xml add

1
2
<component key="myPlugin" class="com.vendor.impl.MyPluginComponentImpl" public="true">
    <interface>com.atlassian.migration.app.listener.DiscoverableListener</interface>
</component>

Atlassian Spring Scanner 2.0

If you are using Spring Scanner 2.0, then add the @ExportAsService annotation to your class along with Spring's @Component.

1
2
@ExportAsService
@Component
public class MyPluginComponentImpl implements DiscoverableListener { }

Rate this page: