Post

6 followers Follow
0
Avatar

XLD 5.0.1: Skip deployment steps using the CLI

I'm using the CLI in XLD 5.0.1 to perform a deployment. I would like to know how to identify and skip a step in the deployment, and I cannot figure it out.

Any help would be greatly appreciated.

Josh Figler Answered

Please sign in to leave a comment.

12 comments

0
Avatar

More information -- I'm starting to think it's broken. Not sure though -- I might be doing something wrong.

jfigler > task.id
a4e89fc9-00e0-4d7b-94d4-5b4ce031252d
jfigler > task.state
TaskExecutionState: PENDING
jfigler > mystep = task2.step( task.id, '0_1_1_1_1' )
jfigler > mystep.description
Upload queue_engineServicePackage on azure_stg-gateway_n0
jfigler > mystep.state
StepExecutionState: PENDING
jfigler > task2.skip( task.id, ['0_1_1_1_1'] )
org.jboss.resteasy.client.ClientResponseFailure: Error status 500 Internal Server Error returned
jfigler > task2.help()
task2: Access to the task block engine of XL Deploy.

The methods available are:
* task2.abort(String taskId) : void
* task2.addPause(String taskId, String stepPath) : StepBlockState
* task2.archive(String taskId) : void
* task2.assign(String taskId, String owner) : TaskWithBlock
* task2.block(String taskId, String blockId) : BlockState
* task2.cancel(String taskId) : void
* task2.export(String beginDate, String endDate) : List
* task2.get(String taskId) : TaskWithBlock
* task2.getAllCurrentTasks() : List
* task2.getMyCurrentTasks() : List
* task2.query(String beginDate, String endDate) : List
* task2.schedule(String taskId, DateTime dateTime) : void
* task2.skip(String taskId, List stepIds) : TaskWithBlock
* task2.start(String taskId) : void
* task2.step(String taskId, String stepId) : StepState
* task2.steps(String taskId, String blockId) : StepBlockState
* task2.stop(String taskId) : void
* task2.takeover(String taskId, String currentOwner) : TaskWithBlock
* task2.unskip(String taskId, List stepIds) : TaskWithBlock

Josh Figler 0 votes
0
Avatar

The task ID i'm using is 0 1 1 1 1, with underscores between all the integers. It looks like some interpreter (markdown?) formatted my text.

Josh Figler 0 votes
0
Avatar

Using tasks object i am able to identify the steps of the particular and able to change the state to skip.

admin > print task.id
b90e4aab-5919-4171-b9ce-d6428e0cda5a

admin > taskWithSteps = tasks.steps(task.id)
admin > print taskWithSteps
b90e4aab-5919-4171-b9ce-d6428e0cda5a

admin > stepIds = [x for x in xrange(1, taskWithSteps.nrSteps + 1)]
admin > print stepIds
[1, 2, 3]

admin > mystep = tasks.step('b90e4aab-5919-4171-b9ce-d6428e0cda5a',2)
admin > print mystep
Synchronize vagrantNode01
admin > print mystep.state
PENDING

admin > tasks.skip('b90e4aab-5919-4171-b9ce-d6428e0cda5a',[2])
RemoteTaskState: b90e4aab-5919-4171-b9ce-d6428e0cda5a

admin > mystep = tasks.step('b90e4aab-5919-4171-b9ce-d6428e0cda5a',2)
admin > print mystep.state
SKIP

-Seshidhar

XebiaLabs Support 0 votes
1
Avatar

In previous versions of XLD, it was pretty easy to skip all steps in a deployment as demonstrated with the following function,

def deployAndSkipSteps(app, env):
   print "Preparing to deploy and skip steps for app [%s] to env [%s]" % (app, env)
   newDep = deployment.prepareInitial(app,env)
   newDep = deployment.generateAllDeployeds(newDep)
   taskInfo = deployment.deploy(newDep)
   stepsToSkip = range(1,taskInfo.nrOfSteps+1)
   deployit.skipSteps(taskInfo.id, stepsToSkip)
   deployit.startTaskAndWait(taskInfo.id)
   print "Deployment of %s to %s finished with state %s" % (app, env, deployit.retrieveTaskInfo(taskInfo.id).state)

In XLD 5.0.0, many deprecated functions have been removed from the CLI. To achieve the same as above, extra CLI code is needed to navigate the Task’s block structure to find and generate step ids that can be in turn used in the task2.skip function.

def gather_steps_from_block(b, tid):
 if hasattr(b, "blocks") and len(b.blocks):
   for i in b.blocks:
     return gather_steps_from_block(i, tid)
 else:
   step_block_state = task2.steps(tid, b.id)
   step_index = 0
   step_ids = []
   for st in step_block_state.steps:
     step_index += 1
     step_ids.append("%s_%s" % (b.id,step_index))
   return step_ids

def gather_steps_from_task(t):
 step_ids = []
 for phase_block in t.block.blocks:
   step_ids.extend(gather_steps_from_block(phase_block.block, t.id))
 return step_ids

def deployAndSkipSteps(app, env):
  print "Preparing to deploy and skip steps for app [%s] to env [%s]" % (app, env)
  newDep = deployment.prepareInitial(app,env)
  newDep = deployment.prepareAutoDeployeds(newDep)
  taskInfo = deployment.createDeployTask(newDep)
  stepsToSkip = gather_steps_from_task(taskInfo)
  task2.skip(taskInfo.id, stepsToSkip)
  deployit.startTaskAndWait(taskInfo.id)
  print "Deployment of %s to %s finished with state %s" % (app, env, task2.get(taskInfo.id).state)

Using the same tranversal of the Task’s block, you can also create a pretty print of the task.

def print_block(b, tab, tid):
  print tab + b.id + " " + b.description
 if hasattr(b, "blocks") and len(b.blocks):
   new_tab = tab + "\t"
   for i in b.blocks:
     print_block(i, new_tab, tid)
 else:
   step_block_state = task2.steps(tid, b.id)
   step_index = 0
   for st in step_block_state.steps:
     step_index += 1
     print "%s\t%s_%s %s" % (tab,b.id,step_index, st.description)

def print_task(t):
 for pb in t.block.blocks:
   print pb.id + " " + pb.description
   print_block(pb.block, "\t", tid)

I hope these code snippets will be useful to you

cheers,
Ravan

Ravan Naidoo 1 vote
0
Avatar

Thanks Ravan -- that is exactly what I need to do with skipping ALL the steps.

Josh

Josh Figler 0 votes
0
Avatar

Ravan and Seshidhar -- I'm trying to do this using a jython step inserted into the deployment by an XL Rule. The jython objects for deployment service, task service, etc appear to be different than the CLI?

I'm doing this for 2 version of XLD, 4.5.3 and 5.0.1.

In the 4.5.3 version I'm getting stuck on creating a task -- it just throws a null pointer exception. The deployment, task, and repository objects are the deploymentService, repositoryService, and taskBlockService (respectively) passed in by the XL Rule. Here's the code:

stagingSlotApp = repository.read( productionSlotApp.replace( 'prd-slot', 'stg-slot' ) )
undeployApp = deployment.prepareUndeploy( stagingSlotApp.id )
taskId = deployment.createTask( undeployApp )
taskInfo = task.getTask( taskId )
skip_steps_from_task( taskInfo )
task.start( taskId )

Any idea what I'm doing wrong? Thanks!

Josh

Josh Figler 0 votes
0
Avatar

More information -- here is the exception:

Caused by: java.lang.NullPointerException
at com.xebialabs.deployit.core.rest.resteasy.WorkDirTemplate.cleanOnException(WorkDirTemplate.java:12)
at com.xebialabs.deployit.core.rest.api.DeploymentResource.createTask(DeploymentResource.java:468)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:186)
... 47 more

Hope this helps -- and I also hope this formats to a block quote correctly.

Josh Figler 0 votes
0
Avatar

Hi Josh

Thanks for all the info on this one. It looks like the

at com.xebialabs.deployit.core.rest.resteasy.WorkDirTemplate.cleanOnException(WorkDirTemplate.java:12)
...

error is masking the underlying error, which I would guess is something to do with validation of the deployment we're trying to execute. Let me see what I can do to get us past this first error so we can find out what's actually going on...

Regards

Andrew

Andrew Phillips 0 votes
0
Avatar

Hi Ravan,

Do you have the same code to skip all steps for the Jython API?

 

Coert van den Thillart 0 votes
0
Avatar

The code below of Ravan was just what I was looking for, because sometimes you need to do a 'registration of a deploy' without actually deploying.

However I found a small problem in the code. In our case, the gather_steps_from_block method only returned the steps of the first 'subblock'. I made a small change, so the steps are saved in a variable and the return is done after the loop, instead of inside the loop.

def gather_steps_from_block(b, tid):
   if hasattr(b, "blocks") and len(b.blocks):
      step_ids = []
      for i in b.blocks:
         step_ids.extend(gather_steps_from_block(i, tid))
      return step_ids
   else:
      step_block_state = task2.steps(tid, b.id)
      step_index = 0
      step_ids = []
      for st in step_block_state.steps:
         step_index += 1
         step_ids.append("%s_%s" % (b.id,step_index))
      return step_ids
William de Vries 0 votes
0
Avatar

>  I made a small change, so the steps are saved in a variable and the return is done after the loop, instead of inside the loop.

Thanks for the fix, William!

Regards


Andrew

Andrew Phillips 0 votes