I hope everyone finds the first blog in this series XL Deploy Variables Demystified : Part 1 useful for understanding how Freemarker exposes variables
In continuation of that, this one will talk about how to view all such objects and methods available inside Jython Step using XL-Rules
Jython Step has been introduced as a part of the latest XL-Rules feature that enables user to quickly develop plugins using Rules DSL and scripting. Jython step is specifically useful for interacting back with the XL-deploy server APIs and objects. It exposes jython services and custom objects which can be manipulated to perform all sorts of work items on XLD repository.
Jython API reference can be found here Jython API ManualWithout further delay, here’s the code snippet that you can put in your script to expose all the variables and methods available. Again, there are many more objects and methods available since these are all java and python objects but i am not exposing them all. You are free to modify the script to expose them further at your convenience.
import inspect def dig(i,obj): if not inspect.ismodule(obj) and not inspect.isclass(obj) and not inspect.isroutine(obj): if isinstance(obj, str) or isinstance(obj, unicode): print "STRING OBJECT : " + i + " || VALUE : " + str(obj) else: print "COMPLEX OBJECT : " + i + " || TYPE : " + str(type(obj)) if dir(obj).__contains__("_delegate"): try: for item in inspect.getmembers(obj._delegate): if not inspect.isroutine(item[1]) and not inspect.isclass(item[1]) and (str(item[0]) not in ["__doc__"]): print "Property : " + i + "." + item[0] + " || VALUE : " + str(item[1]) if inspect.ismethod(item[1]) and (str(item[0]) not in ["hashCode","getClass","notify","notifyAll","equals","toString","wait","__init__","compareTo"]): print "Method : " + i + "." + item[0] + "(...)" except : print "ERROR : Can't review properties on object " + i + " due to exception" for i in globals(): dig(i, globals()[i])
The snippet like i said can be copied into any python script that you associate with a jython step.IMPORTANT: The only major difference in getting the output is that you will see the output as the execution log captured as a part of deployment. This is different from free marker context since that shows up in plan Analyzer. If you’ll open this in Plan Analyzer, you’ll only see the python script.This also showcases an important point that Freemarker templates are resolved much earlier in the process while generating a deployment plan whereas a python/Jython script is executed only during deployment.The output of executing this is relatively long due to so many things being exposed so i’ll show it at the end.
Now, an example for how to run this:
- In synthetic.xml, create a new type or use an existing one like,
- Then write a rule in xl-rules.xml using jython step
test.mytesttype CREATE MODIFY DESTROY script/myscript.py XebiaLabs
- Now create a folder script under XLD_HOME/ext folder and create a file myscript.py
- Copy the code snippet in that file.
- Now restart XLD Server
- Create a new Application package and have an artifact added of type test.mytesttype
- Create infrastructure for localhost or you may change the type to use one of your existing ones and add that infrastructure to a new environment
- Finally perform a deployment using the application package and environment
- On successful deployment, take a look at the log captured for the step that’s shown on clicking the step
- You’ll see the listing of all variables captured for jython step
The code for this is also available at https://github.com/amitmohleji/XLDScripts/blob/master/exposeJythonVariables.py in case the formatting gets corrupted while copying snippet from the blog
Here’s the output from a sample run.
COMPLEX OBJECT : _unwrapper || TYPE :COMPLEX OBJECT : _wrapper || TYPE : COMPLEX OBJECT : context || TYPE : COMPLEX OBJECT : controlService || TYPE : Method : controlService.createTask(...) Method : controlService.prepare(...) COMPLEX OBJECT : deployed || TYPE : Property : deployed.$ciAttributes || VALUE : com.xebialabs.XL Deploy.plugin.api.udm.CiAttributes@5e280808 Property : deployed.$token || VALUE : None Property : deployed.CONTAINER_FIELD || VALUE : container Property : deployed.DEPLOYABLE_FIELD || VALUE : deployable Property : deployed.SYNTHETIC_PROPERTIES_FIELD || VALUE : syntheticProperties Property : deployed.TYPE_FIELD || VALUE : type Property : deployed.container || VALUE : Infrastructure/local Property : deployed.deployable || VALUE : Applications/asasd/1.0 Copy/test Method : deployed.get$ciAttributes(...) Method : deployed.get$token(...) Method : deployed.getContainer(...) Method : deployed.getDeployable(...) Method : deployed.getId(...) Method : deployed.getName(...) Method : deployed.getProperty(...) Method : deployed.getSyntheticProperties(...) Method : deployed.getSyntheticProperty(...) Method : deployed.getType(...) Method : deployed.hasProperty(...) Method : deployed.hasSyntheticProperty(...) Property : deployed.id || VALUE : Infrastructure/local/test Property : deployed.name || VALUE : test Method : deployed.putSyntheticProperties(...) Method : deployed.putSyntheticProperty(...) Method : deployed.set$ciAttributes(...) Method : deployed.set$token(...) Method : deployed.setContainer(...) Method : deployed.setDeployable(...) Method : deployed.setId(...) Method : deployed.setProperty(...) Method : deployed.setSyntheticProperties(...) Method : deployed.setType(...) Property : deployed.syntheticProperties || VALUE : {} Property : deployed.type || VALUE : test.mytesttype COMPLEX OBJECT : deploymentService || TYPE : Method : deploymentService.createTask(...) Method : deploymentService.effectiveDictionary(...) Method : deploymentService.generateAllDeployeds(...) Method : deploymentService.generateSelectedDeployeds(...) Method : deploymentService.generateSingleDeployed(...) Method : deploymentService.isDeployed(...) Method : deploymentService.prepareAutoDeployeds(...) Method : deploymentService.prepareInitial(...) Method : deploymentService.prepareUndeploy(...) Method : deploymentService.prepareUpdate(...) Method : deploymentService.rollback(...) Method : deploymentService.stepPreview(...) Method : deploymentService.taskPreview(...) Method : deploymentService.taskPreviewBlock(...) Method : deploymentService.validate(...) COMPLEX OBJECT : inspectionService || TYPE : Method : inspectionService.createTask(...) Method : inspectionService.prepare(...) Method : inspectionService.retrieveInspectionResults(...) COMPLEX OBJECT : metadataService || TYPE : Method : metadataService.findDescriptor(...) Method : metadataService.listDescriptors(...) Method : metadataService.listOrchestrators(...) Method : metadataService.listPermissions(...) COMPLEX OBJECT : packageService || TYPE : Method : packageService.fetch(...) Method : packageService.importPackage(...) Method : packageService.list(...) Method : packageService.upload(...) COMPLEX OBJECT : permissionService || TYPE : Method : permissionService.checkMyPermission(...) Method : permissionService.getGrantedPermissions(...) Method : permissionService.getMyGrantedPermissions(...) Method : permissionService.grant(...) Method : permissionService.isGranted(...) Method : permissionService.isGrantedToMe(...) Property : permissionService.myGrantedPermissions || VALUE : {Infrastructure/PROD=[controltask#execute, read], global=[task#takeover, report#view, controltask#execute, task#preview_step, admin, task#skip_step, task#assign, login, task#move_step, discovery, security#edit], Infrastructure/QA=[controltask#execute, repo#edit, read], Environments/heydir=[task#takeover, controltask#execute, deploy#undeploy, deploy#initial, repo#edit, task#skip_step, read, deploy#upgrade, task#move_step], Environments/mydir=[controltask#execute, deploy#initial, deploy#undeploy, deploy#upgrade]} Method : permissionService.revoke(...) COMPLEX OBJECT : repositoryService || TYPE : Property : repositoryService.canEdit || VALUE : com.xebialabs.XL Deploy.core.rest.api.RepositoryResource$3@4e2dcd62 Property : repositoryService.canRead || VALUE : com.xebialabs.XL Deploy.core.rest.api.RepositoryResource$1@53db1f81 Method : repositoryService.candidateValues(...) Method : repositoryService.copy(...) Method : repositoryService.create(...) Method : repositoryService.delete(...) Method : repositoryService.deleteList(...) Method : repositoryService.exists(...) Property : repositoryService.hasReadRight || VALUE : com.xebialabs.XL Deploy.core.rest.api.RepositoryResource$2@7499f57 Method : repositoryService.move(...) Method : repositoryService.query(...) Method : repositoryService.read(...) Method : repositoryService.rename(...) Method : repositoryService.update(...) Method : repositoryService.validate(...) COMPLEX OBJECT : roleService || TYPE : Method : roleService.assign(...) Method : roleService.create(...) Method : roleService.delete(...) Method : roleService.list(...) Method : roleService.listMyRoles(...) Method : roleService.listRoles(...) Method : roleService.rename(...) Method : roleService.unassign(...) COMPLEX OBJECT : serverService || TYPE : Method : serverService.gc(...) Method : serverService.getInfo(...) Property : serverService.info || VALUE : ServerInfo[version=4.5.2,pluginsInfo=[ServerPluginInfo[plugin=command-plugin,version=4.5.2], ServerPluginInfo[plugin=trigger-plugin,version=4.5.2], ServerPluginInfo[plugin=database-plugin,version=4.5.2], ServerPluginInfo[plugin=file-plugin,version=4.5.2], ServerPluginInfo[plugin=jee-plugin,version=4.5.2], ServerPluginInfo[plugin=webserver-plugin,version=4.5.2], ServerPluginInfo[plugin=powershell-plugin,version=4.5.2], ServerPluginInfo[plugin=deployment-checklist-plugin,version=4.5.2], ServerPluginInfo[plugin=python-plugin,version=4.5.2], ServerPluginInfo[plugin=base-plugin,version=4.5.2], ServerPluginInfo[plugin=remoting-plugin,version=4.5.2], ServerPluginInfo[plugin=generic-plugin,version=4.5.2], ServerPluginInfo[plugin=group-orchestrator-plugin,version=4.5.2]],classpathEntries=[conf, ext, lib/activation-1.1.jar, lib/akka-actor_2.10-2.3.5.jar, lib/akka-slf4j_2.10-2.3.5.jar, lib/annotations-1.0.0.jar, lib/aopalliance-1.0.jar, lib/apache-mime4j-0.6.jar, lib/appserver-api-2014.7.4.jar, lib/appserver-api-impl-2014.7.4.jar, lib/appserver-core-2014.7.4.jar, lib/appserver-main-2014.7.4.jar, lib/args4j-2.0.16.jar, lib/asm-3.3.1.jar, lib/aspectjrt-1.7.3.jar, lib/base-plugin-4.5.2.jar, lib/bcpkix-jdk15on-1.49.jar, lib/bcprov-jdk15on-1.49.jar, lib/cglib-2.2.2.jar, lib/commons-codec-1.7.jar, lib/commons-collections-3.2.1.jar, lib/commons-compress-1.4.1.jar, lib/commons-dbcp-1.3.jar, lib/commons-httpclient-3.1.jar, lib/commons-io-2.4.jar, lib/commons-lang-2.6.jar, lib/commons-net-2.0.jar, lib/commons-pool-1.5.4.jar, lib/concurrent-1.3.4.jar, lib/config-1.2.1.jar, lib/derby-10.5.3.0_1.jar, lib/dom4j-1.6.1.jar, lib/engine-api-2014.7.4.jar, lib/engine-spi-2014.7.4.jar, lib/engine-xml-2014.7.4.jar, lib/framework-7.1.2.jar, lib/freemarker-2.3.19.jar, lib/generic-plugin-4.5.2.jar, lib/grizzled-slf4j_2.10-1.0.1.jar, lib/guava-16.0.1.jar, lib/httpclient-4.2.1.jar, lib/httpcore-4.2.1.jar, lib/isoparser-1.0.1.jar, lib/jackrabbit-api-2.6.5.jar, lib/jackrabbit-core-2.6.5.jar, lib/jackrabbit-jcr-commons-2.6.5.jar, lib/jackrabbit-spi-2.6.5.jar, lib/jackrabbit-spi-commons-2.6.5.jar, lib/javassist-3.17.1-GA.jar, lib/javax.servlet-api-3.1.0.jar, lib/jaxb-api-2.2.3.jar, lib/jaxb-impl-2.2.4.jar, lib/jaxen-1.1.6.jar, lib/jaxrs-api-2.3.5.Final.jar, lib/jcifs-1.3.17.jar, lib/jcip-annotations-1.0.jar, lib/jcl-over-slf4j-1.7.7.jar, lib/jcr-2.0.jar, lib/jdom-2.0.2.jar, lib/jee-plugin-4.5.2.jar, lib/jettison-1.3.1.jar, lib/jetty-continuation-9.1.2.v20140210.jar, lib/jetty-http-9.1.2.v20140210.jar, lib/jetty-io-9.1.2.v20140210.jar, lib/jetty-security-9.1.2.v20140210.jar, lib/jetty-server-9.1.2.v20140210.jar, lib/jetty-servlet-9.1.2.v20140210.jar, lib/jetty-servlets-9.1.2.v20140210.jar, lib/jetty-util-9.1.2.v20140210.jar, lib/jetty-webapp-9.1.2.v20140210.jar, lib/jetty-xml-9.1.2.v20140210.jar, lib/jmustache-1.8.jar, lib/joda-convert-1.3.jar, lib/joda-time-2.3.jar, lib/jsr250-api-1.0.jar, lib/jsr305-3.0.0.jar, lib/jython-standalone-2.5.3.jar, lib/jzlib-1.0.7.jar, lib/license-2014.7.4.jar, lib/local-booter-2014.7.4.jar, lib/log4j-over-slf4j-1.7.7.jar, lib/logback-access-1.1.2.jar, lib/logback-classic-1.1.2.jar, lib/logback-core-1.1.2.jar, lib/lucene-core-3.6.0.jar, lib/mail-1.4.5.jar, lib/mimepull-1.9.4.jar, lib/nscala-time_2.10-0.6.0.jar, lib/overthere-2.4.5.jar, lib/owasp-java-html-sanitizer-r239.jar, lib/packager-4.5.2.jar, lib/parboiled-core-1.1.6.jar, lib/parboiled-scala_2.10-1.1.6.jar, lib/planner-4.5.2.jar, lib/platform-4.5.2.jar, lib/powershell-plugin-4.5.2.jar, lib/python-plugin-4.5.2.jar, lib/remoting-plugin-4.5.2.jar, lib/replacer-2014.7.4.jar, lib/resteasy-jaxb-provider-2.3.5.Final.jar, lib/resteasy-jaxrs-2.3.5.Final.jar, lib/resteasy-jettison-provider-2.3.5.Final.jar, lib/resteasy-multipart-provider-2.3.5.Final.jar, lib/resteasy-spring-2.3.5.Final.jar, lib/scala-arm_2.10-1.3.jar, lib/scala-compiler-2.10.3.jar, lib/scala-io-core_2.10-0.4.2.jar, lib/scala-io-file_2.10-0.4.2.jar, lib/scala-library-2.10.4.jar, lib/scala-reflect-2.10.3.jar, lib/scannit-1.2.1.jar, lib/scannotation-1.0.3.jar, lib/server-4.5.2.jar, lib/server-api-4.5.2.jar, lib/server-api-impl-4.5.2.jar, lib/server-core-4.5.2.jar, lib/shapeless_2.10-1.2.4.jar, lib/slf4j-api-1.7.7.jar, lib/spray-http-1.3.1.jar, lib/spray-httpx-1.3.1.jar, lib/spray-json_2.10-1.2.5.jar, lib/spray-routing-1.3.1.jar, lib/spray-servlet-1.3.1.jar, lib/spray-util-1.3.1.jar, lib/spring-aop-3.2.11.RELEASE.jar, lib/spring-beans-3.2.11.RELEASE.jar, lib/spring-context-3.2.11.RELEASE.jar, lib/spring-core-3.2.11.RELEASE.jar, lib/spring-expression-3.2.11.RELEASE.jar, lib/spring-jdbc-3.2.11.RELEASE.jar, lib/spring-ldap-core-1.3.2.RELEASE.jar, lib/spring-security-config-3.2.5.RELEASE.jar, lib/spring-security-core-3.2.5.RELEASE.jar, lib/spring-security-ldap-3.2.5.RELEASE.jar, lib/spring-security-web-3.2.5.RELEASE.jar, lib/spring-tx-3.2.11.RELEASE.jar, lib/spring-web-3.2.11.RELEASE.jar, lib/spring-webmvc-3.2.11.RELEASE.jar, lib/sshj-0.9.0.jar, lib/t2-bus-1.2.1.jar, lib/tasker-akka-2014.7.4.jar, lib/tika-core-1.3.jar, lib/truezip-driver-file-7.4.3.jar, lib/truezip-driver-tar-7.4.3.jar, lib/truezip-driver-zip-7.4.3.jar, lib/truezip-file-7.4.3.jar, lib/truezip-kernel-7.4.3.jar, lib/truezip-swing-7.4.3.jar, lib/type-parser-0.2.0.jar, lib/udm-plugin-api-2014.7.4.jar, lib/xl-endpoints-api-2014.7.4.jar, lib/xl-endpoints-routes-2014.7.4.jar, lib/xl-script-engine-2014.7.4.jar, lib/xl-ui-components-api-2014.7.4.jar, lib/xl-ui-components-rest-2014.7.4.jar, lib/xl-utils-2014.7.4.jar, lib/xmlpull-1.1.3.1.jar, lib/xpp3_min-1.1.4c.jar, lib/xstream-1.4.7.jar, lib/xz-1.0.jar, plugins/command-plugin-4.5.2.jar, plugins/compare-plugin-1.0.1-alpha-1.jar, plugins/database-plugin-4.5.2.jar, plugins/deployment-checklist-plugin-4.5.2.jar, plugins/file-plugin-4.5.2.jar, plugins/group-orchestrator-plugin-4.5.2.jar, plugins/trigger-plugin-4.5.2.jar, plugins/ui-permissions.jar, plugins/webserver-plugin-4.5.2.jar]] Method : serverService.logout(...) Method : serverService.shutdown(...) COMPLEX OBJECT : taskBlockService || TYPE : ERROR : Can't review properties on object taskBlockService due to exception COMPLEX OBJECT : taskService || TYPE : ERROR : Can't review properties on object taskService due to exception STRING OBJECT : user || VALUE : XebiaLabs COMPLEX OBJECT : userService || TYPE : Method : userService.create(...) Method : userService.delete(...) Method : userService.modifyPassword(...) Method : userService.read(...) COMPLEX OBJECT : util || TYPE :
Are you ready to scale your enterprise?
Explore
What's New In The World of Digital.ai
Why Financial Services Need DevSecOps More Than Ever
With Digital.ai DevSecOps solutions, financial organizations can improve their security posture, meet regulatory requirements and focus on delivering innovative financial products.
Governance and Compliance for DevOps at Scale
Implement a Software Chain of Custody in DevOps for compliance, traceability, and cost reduction. Gain visibility and automate processes with Digital.ai Release & Deploy.
Continuous Delivery Implementation Done Right: Learn from National Broadband Ireland Story
Through NBI’s approach to be the best open-access operator in telecom, they have been supported by key technology partners, with automation capabilities provided by Digital.ai Release and Deploy underpinning integral aspects.