Skip to content

Commit

Permalink
Refactoring migrate task
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris De Winne committed Nov 29, 2016
1 parent 2e4c6d5 commit da1aaad
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ This plugin (2.x.x+) requires XLR 4.8
* `numberOfPollingTrials` (Number of times to poll for task status)
* `failOnPause` (If checked task will fail if the deployment enters a STOPPED state, for example if the xld-pause-plugin is in use. Set to True by default for backwards compatibility)

+ Migrate Package
+ Migrate Package (compatible with XL Deploy 6.0.0 and up)
* `server` - Server to pull a package from
* `username` - Override source username
* `password` - Override source password
* `destinationServer` - Server to pull package to
* `destinationUsername` - Override destination username
* `destinationPassword` - Override destination password
* `deploymentPackage` - ID of the package to migrate
* `deploymentPackage` - ID of the package to migrate (starting with `Applications/`)
* `autoCreatePath` - If set the task will automatically create the path and application if it doesn't exist in the destination

+ Import Package
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/synthetic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
<type type="xldeploy.MigrateTask" extends="xldeploy.Task" description="Migrates a package from one XL Deploy server to another XL Deploy server">
<property name="scriptLocation" default="xldeploy/migrateTask.py" hidden="true" />
<property name="destinationXLDeployServer" category="input" label="Destination server" referenced-type="xldeploy.Server" kind="ci"/>
<property name="destinationUsername" category="input" label="Destination username" required="true" />
<property name="destinationPassword" password="true" category="input" label="Destination password" required="true" />
<property name="deploymentPackage" category="input" label="Deployment Package" required="true" />
<property name="destinationUsername" category="input" label="Destination username" required="false" />
<property name="destinationPassword" password="true" category="input" label="Destination password" required="false" />
<property name="deploymentPackage" category="input" label="Deployment Package" required="true" description="ID of the package to migrate (starting `with `Applications/`)"/>
<property name="autoCreatePath" category="input" kind="boolean" />
</type>

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/xldeploy/XLDVersionsTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
raise Exception("XL Deploy server ID must be provided")

xld_client = XLDeployClientUtil.create_xldeploy_client(xldeployServer, username, password)
if xld_client.check_CI_exist(environment):
if xld_client.check_ci_exist(environment):
if date:
data = xld_client.get_deployed_applications_for_environment(environment, date)
else:
Expand Down
10 changes: 3 additions & 7 deletions src/main/resources/xldeploy/XLDeployClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ def get_download_uuid(self, deployment_package):
export_task_response = self.http_request.get(export_task, contentType='application/xml')
return export_task_response.getResponse()

def fetch_package(self, fetch_url):
fetch_task = "/deployit/package/fetch"
self.http_request.post(fetch_task, fetch_url, contentType='application/xml')

def fetch_package2(self, url, user_name, password):
fetch_task = "/deployit/package/fetch2"
params = {
Expand Down Expand Up @@ -268,15 +264,15 @@ def get_latest_deployed_version(self, environment_id, application_name):
# End for
return latest_package

def check_CI_exist(self, ci_id):
def check_ci_exist(self, ci_id):
query_task = "/deployit/repository/exists/%s" % ci_id
query_task_response = self.http_request.get(query_task, contentType='application/xml')
if not query_task_response.isSuccessful():
raise Exception("Failed to check ci [%s]. Server return [%s], with content [%s]" % (ci_id, query_task_response.status, query_task_response.response))
return query_task_response.getResponse().find('true') > 0

def create_directory(self, ci_id):
self.create_ci(ci_id, 'udm.Directory')
self.create_ci(ci_id, 'core.Directory')

def create_application(self, app_id):
self.create_ci(app_id, 'udm.Application')
Expand All @@ -289,7 +285,7 @@ def create_ci(self, id, ci_type, xml_descriptor = ''):
raise Exception("Failed to create ci [%s]. Server return [%s], with content [%s]" % (id, response.status, response.response))

def update_ci_property(self, ci_id, ci_property, property_value):
if self.check_CI_exist(ci_id):
if self.check_ci_exist(ci_id):
ci = self.get_ci(ci_id, 'json')
data = json.loads(ci)
data[ci_property] = property_value
Expand Down
44 changes: 27 additions & 17 deletions src/main/resources/xldeploy/migrateTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,36 @@

from xldeploy.XLDeployClientUtil import XLDeployClientUtil

def createPath(path):
def create_path(path):
parent = path.rpartition('/')[0]
if not xldDestinationClient.check_CI_exist(parent):
createPath(parent)
xldDestinationClient.create_directory(path)
if parent and not xld_destination_client.check_ci_exist(parent):
create_path(parent)
xld_destination_client.create_directory(path)

xldSourceClient = XLDeployClientUtil.create_xldeploy_client(xldeployServer, username, password)
xldDestinationClient = XLDeployClientUtil.create_xldeploy_client(destinationXLDeployServer, destinationUsername, destinationPassword)
def get_username():
if username:
return username
return xldeployServer['username']

def get_password():
if username:
return password
return xldeployServer['password']

xld_source_client = XLDeployClientUtil.create_xldeploy_client(xldeployServer, username, password)
xld_destination_client = XLDeployClientUtil.create_xldeploy_client(destinationXLDeployServer, destinationUsername, destinationPassword)

if autoCreatePath:
appPath = deploymentPackage.rpartition('/')[0]
if not xldDestinationClient.check_CI_exist(appPath):
parent = appPath.rpartition('/')[0]
if not xldDestinationClient.check_CI_exist(parent):
createPath(parent)
xldDestinationClient.create_application(appPath)

packageUUID = xldSourceClient.get_download_uuid(deploymentPackage)
fetchURL = xldeployServer['url'] + '/deployit/internal/download/' + packageUUID
print(fetchURL)
xldDestinationClient.fetch_package(fetchURL)
app_path = deploymentPackage.rpartition('/')[0]
if not xld_destination_client.check_ci_exist(app_path):
parent = app_path.rpartition('/')[0]
if not xld_destination_client.check_ci_exist(parent):
create_path(parent)
xld_destination_client.create_application(app_path)

package_uuid = xld_source_client.get_download_uuid(deploymentPackage)
fetch_url = xldeployServer['url'] + '/deployit/internal/download/' + package_uuid
print(fetch_url)
xld_destination_client.fetch_package2(fetch_url, get_username(), get_password())


16 changes: 13 additions & 3 deletions src/test/resources/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@
# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
#

xld:
xld1:
image: xebialabs/xl-docker-demo-xld:v6.0.0.1
volumes:
- ~/xl-licenses:/license
ports:
- "4516:4516"
- "14516:4516"

xld2:
image: xebialabs/xl-docker-demo-xld:v6.0.0.1
volumes:
- ~/xl-licenses:/license
links:
- xld1
ports:
- "24516:4516"

xlr:
image: xebialabs/xlr_dev_run:v6.0.0.1
volumes:
- ~/xl-licenses:/license
- ./../../../../:/data
links:
- xld
- xld1
- xld2
ports:
- "15516:5516"

0 comments on commit da1aaad

Please sign in to comment.