Skip to content

Commit

Permalink
Added Update CI property
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewinne committed Jan 23, 2016
1 parent 01938f0 commit 10d364a
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deploy:
provider: releases
api_key:
secure: aoVXZyLOBmB4Q2lLKLaqEN8zcqN3K3/3agRBA1znM1PLeqXSE3CwQe6sHkX6BrfMoDDtjqeepDMgJ9TsqJFq+lPY+HuVFzOqGlrWlIZHBUKI3hmfjgM/61CkdK2eBO42Ym4tqCQ4L1Tp42fcrB6M/a/0TGI5ENW2bJk8+ofRT8M=
file: build/libs/xlr-xldeploy-plugin-2.0.2.jar
file: build/libs/xlr-xldeploy-plugin-2.1.0.jar
skip_cleanup: true
on:
all_branches: true
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ returned package ID
* `xmlDescriptor` - XML with the fields to set on the CI, e.g. `<os>WINDOWS</os><connectionType>WINRM_NATIVE</connectionType><address>${address}</address><username>${username}</username><password>${password}</password>`
* `addToEnvironment` - Switch to decide if to add the CI to an environment
* `envID` - Environment to add the CI to.

+ Update CI property
* `server` - Server to query
* `username` - Override username
* `password` - Override password
* `ciID` - Fully qualified id from the CI to update
* `ciProperty` - Name of the property to update
* `propertyValue` - Value of the property to update


+ CLI Config (Global Configuration)
* `CLI Home` - Home directory where XL Deploy CLI is installed
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id "com.github.hierynomus.license" version "0.11.0"
}

version="2.0.2"
version="2.1.0"

apply plugin: "com.github.hierynomus.license"
apply plugin: 'java'
Expand Down
9 changes: 7 additions & 2 deletions src/main/resources/synthetic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
<property name="scriptLocation" default="xldeploy/getLatestVersionTask.py" hidden="true" />
<property name="applicationId" category="input" label="Application ID" required="true" />
<property name="stripApplications" category="input" kind="boolean" />
<property name="oldImplementation" category="input" kind="boolean" default="false" description="(DEPRECATED) When enabled the pre 2.0.0 implementation will be used. Will be removed from version 2.1.0+"/>

<property name="packageId" category="output" label="Package ID" />
</type>

Expand Down Expand Up @@ -92,6 +90,13 @@
<property name="envID" category="input" label="Env ID" />
</type>

<type type="xldeploy.UpdateCIProperty" extends="xldeploy.Task" label="Update CI property" description="Update a property from a CI">
<property name="scriptLocation" default="xldeploy/updateCIProperty.py" hidden="true" />
<property name="ciID" category="input" label="CI ID" required="true" description="Fully qualified id from the CI to update"/>
<property name="ciProperty" category="input" label="Property name" required="true" description="Name of the property to update"/>
<property name="propertyValue" category="input" label="Property value" required="true" description="Value of the property to update" />
</type>

<type type="xldeploy.CliConfig" extends="xlrelease.Configuration">
<property name="cliHome" category="input"/>
<property name="cliExecutable" category="input" default="cli" hidden="true" />
Expand Down
111 changes: 58 additions & 53 deletions src/main/resources/xldeploy/XLDeployClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#

import sys, time, ast, re
import com.xhaus.jyson.JysonCodec as json

from xml.etree import ElementTree as ET
from xlrelease.HttpRequest import HttpRequest

Expand Down Expand Up @@ -218,33 +220,22 @@ def get_latest_package_version(self, application_id, old_implementation = False)
root = ET.fromstring(query_task_response.getResponse())
items = root.findall('ci')
latest_package = ''
if old_implementation:
latest_version = 0
for item in items:
curr_nos = re.findall(r'\d+',item.attrib['ref'])
if len(curr_nos) > 0:
if int(curr_nos[0]) > latest_version:
latest_version = int(curr_nos[0])
latest_package = item.attrib['ref']

return latest_package
if len(items) > 0:
latest_package = items[-1].attrib['ref']
return latest_package

def get_latest_deployed_version(self, environment_id, applicationName):
query_task = "/deployit/repository/ci/%s/%s" % (environment_id, applicationName)
query_task_response = self.http_request.get(query_task, contentType='application/xml')
root = ET.fromstring(query_task_response.getResponse())
def get_latest_deployed_version(self, environment_id, application_name):
query_task_response = self.get_ci(self,"%s/%s" % (environment_id, application_name), 'xml')
root = ET.fromstring(query_task_response)
items = root.findall('version')
latest_package = ''
for item in items:
latest_package = item.attrib['ref']
# End for
return latest_package

def check_CI_exist(self, ciId):
queryTask = "/deployit/repository/exists/%s" % ciId
def check_CI_exist(self, ci_id):
queryTask = "/deployit/repository/exists/%s" % ci_id
queryTask_response = self.http_request.get(queryTask, contentType='application/xml')
return queryTask_response.getResponse().find('true') > 0

Expand All @@ -262,49 +253,63 @@ def createCI(self, id, ciType, xmlDescriptor):
xml = '<' + ciType + ' id="' + id + '">' + xmlDescriptor + '</' + ciType + '>'
createTask = '/deployit/repository/ci/' + id
self.http_request.post(createTask, xml, contentType='application/xml')

def deleteCI(self, id):
deleteTask = '/deployit/repository/ci/' + id
self.http_request.delete(deleteTask)

def addCIToEnvironment(self, envID, ciID):
getEnv = '/deployit/repository/ci/' + envID
getEnv_response = self.http_request.get(getEnv, contentType='application/xml')
env = getEnv_response.getResponse()
items = env.partition('</members>')
xml = items[0] + '<ci ref="' + ciID + '"/>' + items[1] + items[2]

def update_ci_property(self, ci_id, ci_property, property_value):
if self.check_CI_exist(ci_id):
ci = self.get_ci(ci_id, 'json')
data = json.loads(ci)
data[ci_property] = property_value
self.update_ci(ci_id, json.dumps(data), 'json')

def add_ci_to_environment(self, env_id, ci_id):
get_env_response = self.get_ci(self,env_id, 'xml')
items = get_env_response.partition('</members>')
xml = items[0] + '<ci ref="' + ci_id + '"/>' + items[1] + items[2]
print(xml)
self.http_request.put(getEnv, xml, contentType='application/xml')

def removeCIFromEnvironment(self, envID, ciID):
getEnv = '/deployit/repository/ci/' + envID
getEnv_response = self.http_request.get(getEnv, contentType='application/xml')
print getEnv_response.getResponse()
envRoot = ET.fromstring(getEnv_response.getResponse())
memberToRemove = None
for child in envRoot:
self.update_ci(env_id, xml, 'xml')

def remove_ci_from_environment(self, env_id, ci_id):
get_env_response = self.get_ci(self,env_id, 'xml')
print get_env_response
env_root = ET.fromstring(get_env_response)
member_to_remove = None
for child in env_root:
if child.tag == 'members':
for member in child:
if member.attrib['ref'] == ciID:
print 'Found ' + ciID + ' in ' + envID
envMembers = child
memberToRemove = member
if memberToRemove is not None:
print 'Removing ' + ciID + ' from ' + envID
envMembers.remove(memberToRemove)
self.http_request.put(getEnv, ET.tostring(envRoot), contentType='application/xml')

def displayStepLogs(self, taskId):
getTaskSteps = '/deployit/task/' + taskId + '/step'
getTaskSteps_response = self.http_request.get(getTaskSteps, contentType='application/xml')
taskStepsRoot = ET.fromstring(getTaskSteps_response.getResponse())
for child in taskStepsRoot:
if member.attrib['ref'] == ci_id:
print 'Found ' + ci_id + ' in ' + env_id
env_members = child
member_to_remove = member
if member_to_remove is not None:
print 'Removing ' + ci_id + ' from ' + env_id
env_members.remove(member_to_remove)
self.update_ci(env_id, ET.tostring(env_root), 'xml')

def get_ci(self, ci_id, accept):
get_ci = "/deployit/repository/ci/%s" % (ci_id)
headers = {'Accept': 'application/%s' % accept}
return self.http_request.get(get_ci, headers = headers).getResponse()

def update_ci(self, ci_id, data, content_type):
update_ci = "/deployit/repository/ci/%s" % ci_id
content_type_header = "application/%s" % content_type
self.http_request.put(update_ci, data, contentType=content_type_header)

def delete_ci(self, ci_id):
delete_task = '/deployit/repository/ci/' + ci_id
self.http_request.delete(delete_task)

def display_step_logs(self, task_id):
get_task_steps = '/deployit/task/' + task_id + '/step'
get_task_steps_response = self.http_request.get(get_task_steps, contentType='application/xml')
task_steps_root = ET.fromstring(get_task_steps_response.getResponse())
for child in task_steps_root:
if child.tag == 'steps':
stepCounter = 0
step_counter = 0
for grandchild in child:
if grandchild.tag == 'step':
stepCounter = stepCounter + 1
print 'DEPLOYMENT STEP %d: Failures=%s State=%s\n' % (stepCounter, str(grandchild.attrib['failures']), str(grandchild.attrib['state']))
step_counter = step_counter + 1
print 'DEPLOYMENT STEP %d: Failures=%s State=%s\n' % (step_counter, str(grandchild.attrib['failures']), str(grandchild.attrib['state']))
for item in grandchild:
if item.tag in ('description', 'startDate', 'completionDate'):
print '%s %s\n' % (str(item.tag), str(item.text))
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/xldeploy/createCITask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

xldClient.createCI(ciID, ciType, xmlDescriptor)
if addToEnvironment:
xldClient.addCIToEnvironment(envID, ciID)
xldClient.add_ci_to_environment(envID, ciID)
4 changes: 2 additions & 2 deletions src/main/resources/xldeploy/deleteCITask.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
xldClient = XLDeployClientUtil.createXLDeployClient(xldeployServer, username, password)

if envID:
xldClient.removeCIFromEnvironment(envID,ciID)
xldClient.remove_ci_from_environment(envID,ciID)

xldClient.deleteCI(ciID)
xldClient.delete_ci(ciID)
2 changes: 1 addition & 1 deletion src/main/resources/xldeploy/deployTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
print "Execute task with id: %s" % taskId
taskState = xldClient.invoke_task_and_wait_for_result(taskId, pollingInterval, numberOfPollingTrials, continueIfStepFails, numberOfContinueRetrials, failOnPause)

xldClient.displayStepLogs(taskId)
xldClient.display_step_logs(taskId)

if taskState in ('DONE','EXECUTED'):
print "Deployment ended in %s \n" % taskState
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/xldeploy/getLatestVersionTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

xld_client = XLDeployClientUtil.createXLDeployClient(xldeployServer, username, password)

packageId = xld_client.get_latest_package_version(applicationId, oldImplementation)
packageId = xld_client.get_latest_package_version(applicationId)

if stripApplications:
packageId = packageId.partition('/')[2]
12 changes: 12 additions & 0 deletions src/main/resources/xldeploy/updateCIProperty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
#

from xldeploy.XLDeployClientUtil import XLDeployClientUtil


xld_client = XLDeployClientUtil.createXLDeployClient(xldeployServer, username, password)

xld_client.update_ci_property(ciID, ciProperty, propertyValue)

0 comments on commit 10d364a

Please sign in to comment.