rundeck / rundeck-api-java-client

Java client for the Rundeck REST API
http://rundeck.github.com/rundeck-api-java-client
Apache License 2.0
13 stars 17 forks source link

importJobs utilizing java rundeck api and JRuby fails #31

Closed russroy closed 9 years ago

russroy commented 9 years ago

A simple JRuby script to import jobs to my rundeck instance....

require 'java'
require 'rundeck-api-java-client-13.1-SNAPSHOT-jar-with-dependencies.jar'
import org.rundeck.api.RundeckClient
import org.rundeck.api.FileType

rundeck = RundeckClient.builder().url("http://10.0.2.15:4440").login("****", "************").build()

Dir["./*.yml"].each do | filename |
  puts "Processing filename=#{filename}"
  result = rundeck.importJobs(filename, Java::OrgRundeckApi::FileType::YAML)
  puts "#{result.succeededJobs.size} jobs successfully imported, #{result.skippedJobs.size} jobs skipped, and #{result.failedJobs.size} jobs failed"
end

Fails with:

Processing filename=./03e6693f-1b44-4f8e-9083-4ae48863ecfb.yml
foo.rb:8:in `each': no importJobs with arguments matching [class org.jruby.RubyString, class org.rundeck.api.FileType] on object #<Java::OrgRundeckApi::RundeckClient:0x7e374aac> (NameError)
    from foo.rb:8

Apparently the api has changed. The examples document here http://vincent.behar.name/rundeck-api-java-client/ are out of date.

Looks as though the importJobs api has changed to use a RundeckJobsImport object (??)

Not being a java programmer I'm unclear as to how to properly build the args in JRuby to do my import.

russroy commented 9 years ago

Ok ... I figured it out:

require 'java'
require 'rundeck-api-java-client-13.1-SNAPSHOT-jar-with-dependencies.jar'
import org.rundeck.api.RundeckClient
import org.rundeck.api.RundeckJobsImportBuilder
import org.rundeck.api.FileType

rundeck  = RundeckClient.builder().url("http://10.0.2.15:4440").login("*****", "********").build()
importer = RundeckJobsImportBuilder.builder().setFileType(Java::OrgRundeckApi::FileType::YAML).build()

Dir["./*.yml"].each do | filename |
  puts "Processing filename=#{filename}"
  result = rundeck.importJobs(filename, importer)
  puts "#{result.succeededJobs.size} jobs successfully imported, #{result.skippedJobs.size} jobs skipped, and #{result.failedJobs.size} jobs failed"
end
gschueler commented 9 years ago

thanks, we should update the jruby examples