I have a job created using spoon and imported to the DI repository.
Without scheduling it using PDI job scheduler how can I run PDI Job on a Data Integration Server using REST web services? So that I can call it whenever I want.
Before beginning these steps, please make sure that your Carte server (or Carte server embedded in the DI server) is configured to connect to the repository for REST calls. The process and description can be found on the wiki page. Note that the repositories.xml needs to be defined and in the appropriate location for the DI Server as well.
Method 1 : (Run Job and continue, no status checks):
Start a PDI Job (/home/admin/Job 1):
curl -L "http://admin:password#localhost:9080/pentaho-di/kettle/runJob?job=/home/admin/Job%201" 2> /dev/null | xmllint --format -
Method 2 : (Run Job and poll job status regularly):
Generate a login cookie:
curl -d "j_username=admin&j_password=password&locale=en_US" -c cookies.txt http://localhost:9080/pentaho-di/j_spring_security_check
Check DI Server status:
curl -L -b cookies.txt http://localhost:9080/pentaho-di/kettle/status?xml=Y | xmllint --format -
Result:
<?xml version="1.0" encoding="UTF-8"?>
<serverstatus>
<statusdesc>Online</statusdesc>
<memory_free>850268568</memory_free>
<memory_total>1310720000</memory_total>
<cpu_cores>4</cpu_cores>
<cpu_process_time>22822946300</cpu_process_time>
<uptime>100204</uptime>
<thread_count>59</thread_count>
<load_avg>-1.0</load_avg>
<os_name>Windows 7</os_name>
<os_version>6.1</os_version>
<os_arch>amd64</os_arch>
<transstatuslist>
<transstatus>
<transname>Row generator test</transname>
<id>de44a94e-3bf7-4369-9db1-1630640e97e2</id>
<status_desc>Waiting</status_desc>
<error_desc/>
<paused>N</paused>
<stepstatuslist>
</stepstatuslist>
<first_log_line_nr>0</first_log_line_nr>
<last_log_line_nr>0</last_log_line_nr>
<logging_string><![CDATA[]]></logging_string>
</transstatus>
</transstatuslist>
<jobstatuslist>
</jobstatuslist>
</serverstatus>
Start a PDI Job (/home/admin/Job 1):
curl -L -b cookies.txt "http://localhost:9080/pentaho-di/kettle/runJob?job=/home/admin/Job%201" | xmllint --format -
Result:
<webresult>
<result>OK</result>
<message>Job started</message>
<id>dd419628-3547-423f-9468-2cb5ffd826b2</id>
</webresult>
Check the job's status:
curl -L -b cookies.txt "http://localhost:9080/pentaho-di/kettle/jobStatus?name=/home/admin/Job%201&id=dd419628-3547-423f-9468-2cb5ffd826b2&xml=Y" | xmllint --format -
Result:
<?xml version="1.0" encoding="UTF-8"?>
<jobstatus>
<jobname>Job 1</jobname>
<id>dd419628-3547-423f-9468-2cb5ffd826b2</id>
<status_desc>Finished</status_desc>
<error_desc/>
<logging_string><![CDATA[H4sIAAAAAAAAADMyMDTRNzDUNzJSMDSxMjawMrZQ0FXwyk9SMATSwSWJRSUK+WkKWUCB1IrU5NKSzPw8LiPCmjLz0hVS80qKKhWiXUJ9fSNjSdQUXJqcnFpcTEibW2ZeZnFGagrEgahaFTSKUotLc0pso0uKSlNjNckwCuJ0Eg3yQg4rhTSosVwABykpF2oBAAA=]]></logging_string>
<first_log_line_nr>0</first_log_line_nr>
<last_log_line_nr>13</last_log_line_nr>
<result>
<lines_input>0</lines_input>
<lines_output>0</lines_output>
<lines_read>0</lines_read>
<lines_written>0</lines_written>
<lines_updated>0</lines_updated>
<lines_rejected>0</lines_rejected>
<lines_deleted>0</lines_deleted>
<nr_errors>0</nr_errors>
<nr_files_retrieved>0</nr_files_retrieved>
<entry_nr>0</entry_nr>
<result>Y</result>
<exit_status>0</exit_status>
<is_stopped>N</is_stopped>
<log_channel_id/>
<log_text>null</log_text>
<result-file/>
<result-rows/>
</result>
</jobstatus>
Get the status description from the jobStatus API:
curl -L -b cookies.txt "http://localhost:9080/pentaho-di/kettle/jobStatus?name=/home/admin/Job%201&id=dd419628-3547-423f-9468-2cb5ffd826b2&xml=Y" 2> /dev/null | xmllint --xpath "string(/jobstatus/status_desc)" -
Result:
Finished
PS : curl & libxml2-utils installed via apt-get.
The libxml2-utils package is optional, used solely for formatting XML output from the DI Server. This shows how to start a PDI job using a Bash shell.
Supported in version 5.3 and later.
Related
When my computer power downs, i would like for it to run a script that basically does an http-request to Iot devices in the network telling them that the computer has shutdown. I think i have everything needed for me to make this happen, all i need now is integrating them together.
Windows 10 has already have a feature that lets me run scripts during powerup/shutdown gpedit.msc -> computer configuration -> windows settings -> scripts -> shutdown
Windows 10 also has built in curl so i am planning on using that for the http request. I need to do 5 get requests before shutdown
curl --silent --output nul --show-error --fail 192.168.0.10/shutdown
curl --silent --output nul --show-error --fail 192.168.0.11/shutdown
curl --silent --output nul --show-error --fail 192.168.0.12/shutdown
curl --silent --output nul --show-error --fail 192.168.0.13/shutdown
curl --silent --output nul --show-error --fail 192.168.0.14/shutdown
in the gpedit.msc shutdown script there are 2 choices ordinary script and powershellscript, which one is better? although i have the commands the curl commands ready, i dont know how to save them. Create a file then just the commands above? what will the file extension be?
Batch files are the easiest.
You need two batch files
One to run the curl commands
One to open the CMD window and call the first batch file
Example. shutdown.bat is the batch that is run on shutdown
shutdown.bat open the cmd window and runs shutdowncurl.bat
shutdowncurl.bat
curl --silent --output nul --show-error --fail 192.168.0.10/shutdown
curl --silent --output nul --show-error --fail 192.168.0.11/shutdown
curl --silent --output nul --show-error --fail 192.168.0.12/shutdown
curl --silent --output nul --show-error --fail 192.168.0.13/shutdown
curl --silent --output nul --show-error --fail 192.168.0.14/shutdown
shutdown.bat
cmd /k shutdowncurl
pause
In this case the two batch files are in the same folder.
You could use the full path names as well
To test in Windows Explorer double click shutdown.bat or right click and choose open
After testing, remove the pause from shutdown.bat
I tested this where the shutdowncurl.bat looked like this:
curl --help
curl --help
curl --help
curl --help
i have a Jenkins build that work with gerrit.
i can re-trigger this job very easily throw Jenkins ui.
i wanted to re-trigger a specific build from the Linux terminal.
i manage to do it with a curl command when i input all the GERRIT parameters.
curl command:
curl "url/job/job_name/buildWithParameters?token=token&GERRIT_CHANGE_ID=id_numberb&GERRIT_PATCHSET_REVISION=gerrit_patchset...
parameters:
GERRIT_PATCHSET_UPLOADER
GERRIT_PATCHSET_REVISION
GERRIT_CHANGE_ID
GERRIT_PATCHSET_NUMBER
GERRIT_EVENT_ACCOUNT_EMAIL
GERRIT_CHANGE_NUMBER
GERRIT_CHANGE_OWNER
GERRIT_REFSPEC1
GERRIT_EVENT_TYPE
GERRIT_EVENT_ACCOUNT
GERRIT_CHANGE_SUBJECT
GERRIT_CHANGE_OWNER_NAME
GERRIT_PROJECT
GERRIT_EVENT_HASH
GERRIT_BRANCH
GERRIT_CHANGE_OWNER_EMAIL
GERRIT_PATCHSET_UPLOADER_EMAIL
GERRIT_CHANGE_URL
GERRIT_PATCHSET_UPLOADER_NAME
GERRIT_EVENT_ACCOUNT_NAME
i only need a way to send 1 parameter from the above list and get all the rest.
i tried to curl the Jenkins/gerrit_manual_trigger/ , but i don't get this parameters.
how can i get all those parameters for a specific build via terminal?
I was able to retrieve all Gerrit parameters with the following command:
curl -s -u USER:PASS --request GET "https://JENKINS-SERVER/JOB-PATHNAME/BUILD-NUMBER/api/json" | jq --raw-output '.actions[].parameters | select(length > 0) | .[] | .name + " " + .value'
GERRIT_EVENT_TYPE patchset-created
GERRIT_EVENT_HASH -1187252333
GERRIT_BRANCH master
...
GERRIT_PORT 29418
GERRIT_SCHEME ssh
GERRIT_VERSION 2.14.3
I have the following set-up:
A LibreOffice Base mybase.odb connected to an HSQLDB Split-DB named mydb
A form within with a button to open a report
A macro behind this button that basically performs:
shell(convertToUrl(Tools.Strings.DirectoryNameOutOfPath( _
ThisComponent.Parent.getURL(), "/") & "myReport.cmd"), HIDE)
myReport.cmd contains:
:: From: http://hsqldb.org/doc/2.0/guide/listeners-chapt.html#lsc_listener_types
start /min java -cp %~dp0driver/hsqldb.jar org.hsqldb.server.Server
--database.0 file:mydb --dbname.0 mydb
timeout /t 3
:: From: http://jasperstarter.cenote.de/index.html
jasperstarter -v pr %~dp0myReport.jasper -r -o . -f pdf
-H [localhost|127.0.0.1] --db-port 9001 -n mydb -u myuser
[Line breaks inserted for easier reading here.]
The HSQLDB server starts succesfully:
...
[Server#1742700]: Startup sequence completed in 382 ms.
[Server#1742700]: 2016-05-09 23:05:49.129 HSQLDB server 2.3.2 is online on port 9001
...
The subsequent JasperStarter doesn't show any error but no PDF is created.
Following the HSQLDB server output Server#1742700 I also tried (with little hope):
jasperstarter ... -H 1742700 ... -n Server
to no avail.
The following in myReport.cmd works like a charm standalone:
jasperstarter pr %~dp0myReport.jasper -r -o . -f pdf -t generic
--jdbc-dir %~dp0driver --db-driver org.hsqldb.jdbcDriver
--db-url jdbc:hsqldb:file:%~dp0database/mydb;sql.syntax_mys=true;shutdown=true
-u myuser
[Line breaks inserted for easier reading here.]
But not, of course, if mybase.odb is open:
Unable to connect to database: Database lock acquisition failure: lockFile:
org.hsqldb.persist.LockFile#68306856[file =<path>\database\mydb.lck, exists=true,
locked=false, valid=false, ] method: checkHeartbeat read: 2016-05-09 21:25:13
heartbeat - read: -6188 ms.
BTW, why locked=false when the lock file exists?
According to fredt's answer I created a myapp.cmd containing:
start "My DB Server" /min java -cp %~dp0driver/hsqldb.jar org.hsqldb.server.Server
--database.0 file:%~dp0database/mydb --dbname.0 mydb
timeout /t 2
start /b /max %~dp0mybase.odb
myReport.cmd now contains just:
jasperstarter -v pr %~dp0myReport.jasper -r -o %~dp0 -f pdf
-H localhost --db-port 9001 -n mydb -u myuser
And I realized that:
jasperstarter ... -o .
doesn't work as expected. With '.' it took C:\Program Files (x86)\LibreOffice 5\program as output directory (comprehensible if invoked from within Base). Hence I changed it to the absolute %~dp0.
Only one Java process at a time can connect to a file: database. The message indicates the second process cannot acquire a lock because the lock file has been created by the other process and does exist.
You should change the setup so that HSQLDB Server is started before you start LibreOffice. LibreOffice then connects to the server database, and your macro no longer starts the server and just starts the report generator with the Server URL.
We have a few servers that are going to be rebooted soon and I may have to restart Apache Solr manually.
How can I verify (from the command line) that Solr is running?
The proper way is to use Solr's STATUS command. You could parse its XML response, but as long as it returns something to you with an HTTP status of 200, it should be safe to assume it's running. You can perform an HTTP HEAD request using curl with:
curl -s -o /dev/null -I -w '%{http_code}' http://example.com:8983/solr/admin/cores?action=STATUS
NOTE: Also, you can add a -m <seconds> to the command to only wait so many seconds for a response.
This will make a request to the Solr admin interface, and print out 200 on success which can be used from a bash script such as:
RESULT=$(curl -s -o /dev/null -I -w '%{http_code}' http://example.com:8983/solr/admin/cores?action=STATUS)
if [ "$RESULT" -eq '200' ]; then
# Solr is running...
else
# Solr is not running...
fi
If you are on the same machine where Solr is running then this is my favourite:
$> solr status
I am trying to create a WCF REST client that will communicate to Jenkins and create a job from an XML file and then build the job. My understanding is that you can do that with Jenkins.
Can some one please provide some commands that you can type on a browser's address bar to create and build jobs? ie: http:localhost/jenkins/createItem?name=TESTJOB something along those lines.
Usually, when parsing through the documentation, it can take one or two days. It is helpful to be able to access code or curl commands to get you up and running in one hour. That is my objective with a lot of third party software.
See the post at http://scottizu.wordpress.com/2014/04/30/getting-started-with-the-jenkins-api/ which lists several of the curl commands. You will have to replace my.jenkins.com (ie JENKINS_HOST) with the your own url.
To create a job, for instance, try:
curl -X POST -H "Content-Type:application/xml" -d "<project><builders/><publishers/><buildWrappers/></project>" "http://JENKINS_HOST/createItem?name=AA_TEST_JOB2"
This uses a generic config. You can also download a config from a manually created job and then use that as a template.
curl "http://JENKINS_HOST/job/MY_JOB_NAME/config.xml" > config.xml
curl -X POST -H "Content-Type:application/xml" -d #config.xml "http://JENKINS_HOST/createItem?name=AA_TEST_JOB3"
To execute the job (and set string parameters), use:
curl "http://JENKINS_HOST/job/MY_JOB_NAME/build"
curl "http://JENKINS_HOST/job/MY_JOB_NAME/buildWithParameters?PARAMETER0=VALUE0&PARAMETER1=VALUE1"
See the Jenkins API Wiki page (including the comments at the end). You can fill in the gaps using the documentation provided by Jenkins itself; for example, http://JENKINS_HOST/api will give you the URL for creating a job and http://JENKINS_HOST/job/JOBNAME/api will give you the URL to trigger a build.
I highly recommend avoiding the custom creation of job configuration XML files and looking at something like the Job DSL plugin instead. This gives you a nice Groovy-based DSL to create jobs programmatically - much more concise and less error-prone.
Thanks to a GIST - https://gist.github.com/stuart-warren/7786892
Check if job exists
curl -XGET 'http://jenkins/checkJobName?value=yourJobFolderName' --user user.name:YourAPIToken
With folder plugin
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary #config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
Without folder plugin
curl -s -XPOST 'http://jenkins/createItem?name=yourJobName' --data-binary #config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
Create folder
curl -XPOST 'http://jenkins/createItem?name=FolderName&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22FolderName%22%2C%22mode%22%3A%22com.cloudbees.hudson.plugins.folder.Folder%22%2C%22from%22%3A%22%22%2C%22Submit%22%3A%22OK%22%7D&Submit=OK' --user user.name:YourAPIToken -H "Content-Type:application/x-www-form-urlencoded"
If you want to create a job into a view given the view exists.
curl -X POST -H "Content-Type:application/xml" -d #build.xml "http://jenkins_host/view/viewName/createItem?name=itemName"
the build.xml filetemplate could be found in the root directory of a job's workspace
if you want to create a view:
curl -X POST -H "Content-Type:application/xml" -d #view.xml "http://jenkins_host/createView?name=viewName"
the content of the file view.xml could be:
<?xml version="1.0" encoding="UTF-8"?>
<hudson.model.ListView>
<name>viewName</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
<jobNames>
<comparator class="hudson.util.CaseInsensitiveComparator"/>
</jobNames>
<jobFilters/>
<columns>
<hudson.views.StatusColumn/>
<hudson.views.WeatherColumn/>
<hudson.views.JobColumn/>
<hudson.views.LastSuccessColumn/>
<hudson.views.LastFailureColumn/>
<hudson.views.LastDurationColumn/>
<hudson.views.BuildButtonColumn/>
</columns>
</hudson.model.ListView>
and to check if a view exists:
curl -X POST -H "Content-Type:application/xml" "http://jenkins_host/checkViewName?value=viewName"
to check if a job exists:
curl -X POST -H "Content-Type:application/xml" "http://jenkins_host/checkJobName?value=jobName"
To create a job:
curl -X POST -H "Content-Type:application/xml" -d "<project><builders/><publishers/><buildWrappers/></project>" -u username: API_Token http://JENKINS_HOST/createItem?name=AA_TEST_JOB2
To build a job:
curl -X POST -u username:API_TOKEN http://JENKINS_HOST/job/MY_JOB_NAME/build
In case you need to make the same HTTP calls using the Python requests library, instead of CURL...
Download a job config:
import requests
auth = ("username", "api_token")
url = "http://" + JENKINS_HOST + "/job/" + JOB_NAME + "/config.xml"
response = requests.get(url, auth=auth)
open('config.xml', 'wt').write(response.text)
Create a new job using same config:
url = "http://" + JENKINS_HOST + "/createItem?name=" + NEW_JOB_NAME
headers = {'content-type': 'text/xml'}
data = response.text
response = requests.post(url, auth=auth, headers=headers, data=data)
Omit auth parameter when not needed.