CLI:
# Simple zip and xml import dpbuddy import -file dpconfigs/WSProxy.zip dpbuddy import -file dpconfigs/LoadBalancerGroup.xml # Save domain configuration upon import's success dpbuddy import -file dpconfigs/XMLFirewall.xml -save # Create a checkpoint before importing the file, perform the import, # validate that all services are up and running, # rollback to the checkpoint on failure. For the objects that are in the "down" state, # DPBuddy will pull and display log entries containing errors. dpbuddy import -file dpconfigs/WSProxy.zip -checkpoint "before-import" -assertObjectsUp -rollbackOnError # Quiesce the domain before importing the file, perform the import, # validate that all services are up and running, un-quiesce the domain. dpbuddy import -file dpconfigs/WSProxy.zip -quiesce -assertObjectsUp -unquiesce # Resolve template variables before the import, update domain comments after the import. dpbuddy import -file dpconfigs/WSProxy.zip -resolveVars -domainComments "release-1.0.1" # Export saved configuration of all proxies and firewalls dpbuddy export -file services.zip -persisted -classPattern "(WSGatew.*|.*Firewall.*)"
Ant:
<?xml version="1.0" encoding="UTF-8"?> <project name="dpbuddy.samples.import-export" xmlns:dp="antlib:com.myarch.dpbuddy" > <description> Samples demonstrating import and export tasks </description> <!-- Locations of DataPower config files and other XML files --> <property name="wsproxy.xml.file" value="${dpconfig.home}/WSProxy.xml" /> <property name="wsproxy.zip.file" value="${dpconfig.home}/WSProxy.zip" /> <!-- WS Proxy port --> <property name="dev.ws.port" value="8064" /> <!-- Simple import task --> <target name="import.simple"> <!-- Import zip, save domain configuration upon success --> <dp:buddyImport file="${wsproxy.zip.file}" save="true" /> <!-- Import XML --> <dp:buddyImport file="${dpconfig.home}/XMLFirewall.xml" /> <dp:buddyImport file="${dpconfig.home}/AAAPolicy.xml" /> </target> <!-- Import xml and transform it, create the checkpoint before the import, validate that all objects are up and save the configuration --> <target name="import.xml"> <dp:buddyImport file="${wsproxy.xml.file}" checkpoint="before-import" rollbackOnError="true" assertObjectsUp="true" assertPorts="${ws.port}" quiesce="true" unquiesce="true" save="true" > <transform> <!-- Set HTTPHanlder port to the value of the property --> <setText xpath="//*[@name='TestHTTPHandler']/LocalPort" value="${ws.port}" /> </transform> </dp:buddyImport> </target> <!-- Transform export.xml inside the zip file and tell DataPower to apply the deployment policy --> <target name="import.simple.transform.policy"> <dp:buddyImport file="${wsproxy.zip.file}" deploymentPolicyFile="${dpconfig.home}/TestServiceDeplPolicy.xml" > <!-- Note that transformation will be applied to "export.xml" inside zip. Use "transformFiles" if a different naming convention is used --> <transform> <setText xpath="//RemoteEndpointHostname" expression="env+'.'+currentValue" /> <dpExclude class="HTTPUserAgent" name="def.*"/> </transform> </dp:buddyImport> </target> <target name="import.lbg"> <dp:buddyImport file="${dpconfig.home}/LoadBalancerGroup.xml" /> </target> <!-- Create a checkpoint before importing the file, perform the import, validate that all services are up and running, rollback to the checkpoint on failure. For the objects that are in the "down" state, DPBuddy will pull and display log entries containing errors. --> <target name="import.checkpoint"> <dp:buddyImport file="${wsproxy.zip.file}" checkpoint="before-import" assertObjectsUp="true" rollbackOnError="true"/> </target> <!-- Quiesce the domain before importing the file, perform the import, validate that all services are up and running, un-quiesce the domain. --> <target name="import.quiesce"> <dp:buddyImport file="${wsproxy.zip.file}" quiesce="true" assertObjectsUp="true" unquiesce="true"/> </target> <!-- Resolve template variables before the import, update domain comments after the import. --> <target name="import.domain.comments"> <dp:buddyImport file="${wsproxy.zip.file}" resolveVars="true" domainComments="release-1.0.1"/> </target> <target name="import.all" depends="import.simple,import.xml, import.simple.transform.policy, import.lbg, import.checkpoint, import.quiesce, import.domain.comments"/> <!-- Export examples --> <target name="export" > <property name="export.xml.file" location="${java.io.tmpdir}/export.xml"/> <property name="export.zip.file" location="${java.io.tmpdir}/export.zip"/> <!-- Use exportObject nested element to define what to export. Both class and name values are regexps --> <!-- Export all WS proxies (to figure out the name of the class, first export manually and then look at element names in export.xml)--> <!-- Note that the XML file will be automatically cleaned (unnecessary encoded files are removed) and re-formatted with indentation. You can disable this by setting defaultTransform to false--> <dp:export file="${export.xml.file}" classPattern="WSGateway" /> <!-- Export WS proxies in XML format and set the port to use Ant variable. "import" task will automatically resolve this variable if it is defined --> <dp:export file="${export.xml.file}" classPattern="WSGateway" > <transform> <setText xpath="//LocalPort" value="$${dp.wsproxy.port}" /> </transform> </dp:export> <!-- Export all objects with names that begin with testService --> <!-- Note that the export format is determined automatically based on the file extension --> <dp:export file="${export.zip.file}" allFiles="false" namePattern="testService.*"/> <!-- Export all WS proxies with the name beginning with testService. Additional attributes, such as includeDebug, will apply to all matching objects. See DPBuddy User Guide for the list of supported attributes --> <dp:export file="${export.zip.file}" allFiles="false" > <exportObject class="WSGateway" name="testService.*" includeDebug="true"/> </dp:export> <!-- Export all proxies and firewalls Note: using OR in regexp is more efficient than multiple "exportObject" --> <dp:export file="${export.zip.file}" classPattern="(WSGatew.*|.*Firewall.*)"/> <!-- Export all proxies with referenced objects and all firewalls without referenced objects --> <dp:export file="${export.zip.file}" > <exportObject class="WSGatew.*" /> <exportObject class=".*Firewall.*" refObjects="false"/> </dp:export> </target> <!-- You can easily export all objects and files in the domain --> <target name="export.all.objects" > <property name="export.all.file" location="${java.io.tmpdir}/export.all.zip" /> <!-- Export all objects and all files from local:/ --> <dp:export file="${export.all.file}" allFiles="true" /> <!-- Export all objects and their referenced files with debug --> <dp:export file="${export.all.file}"> <exportObject includeDebug="true" /> </dp:export> </target> <!-- Using export/import to update configuration. You can also use "modifyConfig" to perform this change, however, export/import gives you more flexibility. --> <target name="update.lbg" depends="import.lbg" description="Dynamically add a new server to the load balancing group"> <property name="lbg.file" location="${java.io.tmpdir}/lbg.xml"/> <property name="new.server.name" value="new.server.com"/> <property name="new.server.port" value="8080"/> <dp:export file="${lbg.file}" classPattern="LoadBalancerGroup" namePattern="test-group" /> <dp:buddyImport file="${lbg.file}"> <transform> <add xpath="//LoadBalancerGroup" > <LBGroupMembers> <Server>${new.server.name}</Server> <Weight>1</Weight> <MappedPort>${new.server.port}</MappedPort> <Activity/> <HealthPort/> <LBMemberState>enabled</LBMemberState> </LBGroupMembers> </add> </transform> </dp:buddyImport> </target> <target name="import.export.all" depends="import.all,export,export.all.objects,update.lbg" /> </project>