Class: GoApiClient::Api::Pipeline

Inherits:
AbstractApi show all
Defined in:
lib/go_api_client/api/pipeline.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Pipeline

Returns a new instance of Pipeline.



7
8
9
10
# File 'lib/go_api_client/api/pipeline.rb', line 7

def initialize(attributes = {})
  attributes = ({:pipeline_cache => {}, :stage_cache => {}}).merge(attributes)
  super(attributes)
end

Instance Method Details

#pause(options = {}) ⇒ Object

This API provides the ability to pause a pipeline.



39
40
41
42
43
44
45
46
47
48
# File 'lib/go_api_client/api/pipeline.rb', line 39

def pause(options = {})
  options = ({:pause_uri => nil, :pipeline_name => nil}).merge(options)
  if options[:pause_uri]
    uri = options[:pause_uri]
  else
    raise 'Insufficient arguments' unless options[:pipeline_name]
    uri = "#{@base_uri}/api/pipelines/#{options[:pipeline_name]}/pause"
  end
  @http_fetcher.post!(uri)
end

#pipeline(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/go_api_client/api/pipeline.rb', line 62

def pipeline(options = {})
  options = ({:pipeline_uri => nil, :pipeline_name => nil, :pipeline_id => nil, :eager_parser => []}).merge(options)
  if options[:pipeline_uri]
    uri = options[:pipeline_uri]
  else
    raise 'Insufficient arguments' unless options[:pipeline_name] && options[:pipeline_id]
    uri = "#{@base_uri}/api/pipelines/#{options[:pipeline_name]}/#{options[:pipeline_id]}.xml"
  end
  pipeline = GoApiClient::Parsers::Pipeline.parse(Nokogiri::XML(@http_fetcher.get!(uri)).root)
  @pipeline_cache[GoApiClient::Domain::InternalCache.new(pipeline.self_uri, options)] ||= pipeline
  if options[:eager_parser] && options[:eager_parser].include?(:stage)
    stage_api = GoApiClient::Api::Stage.new({:base_uri => @base_uri, :http_fetcher => @http_fetcher, :pipeline_cache => @pipeline_cache, :stage_cache => @stage_cache})
    pipeline.parsed_stages = pipeline.stages.collect do |stage_uri|
      stage = @stage_cache[GoApiClient::Domain::InternalCache.new(stage_uri, options)] || stage_api.stage(options.merge({:stage_uri => stage_uri}))
      @stage_cache[GoApiClient::Domain::InternalCache.new(stage_uri, options)] ||= stage
      stage
    end
  end
  pipeline
end

#release_lock(options = {}) ⇒ Object

This API allows you to release a lock on a pipeline so that you can start up a new instance without having to wait for the earlier instance to finish.



27
28
29
30
31
32
33
34
35
36
# File 'lib/go_api_client/api/pipeline.rb', line 27

def release_lock(options = {})
  options = ({:release_lock_uri => nil, :pipeline_name => nil}).merge(options)
  if options[:release_lock_uri]
    uri = options[:release_lock_uri]
  else
    raise 'Insufficient arguments' unless options[:pipeline_name]
    uri = "#{@base_uri}/api/pipelines/#{options[:pipeline_name]}/releaseLock"
  end
  @http_fetcher.post!(uri)
end

#schedule(options = {}) ⇒ Object

Schedule a particular pipeline with the latest available materials.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/go_api_client/api/pipeline.rb', line 13

def schedule(options = {})
  # options {:materials => nil, :variables => nil, :secure_variables => nil}
  options = ({:schedule_uri => nil, :pipeline_name => nil}).merge(options)
  if options[:schedule_uri]
    uri = options[:schedule_uri]
  else
    raise 'Insufficient arguments' unless options[:pipeline_name]
    uri = "#{@base_uri}/api/pipelines/#{options[:pipeline_name]}/schedule"
  end
  @http_fetcher.post!(uri)
end

#unpause(options = {}) ⇒ Object

This API provides the ability to unpause a pipeline.



51
52
53
54
55
56
57
58
59
60
# File 'lib/go_api_client/api/pipeline.rb', line 51

def unpause(options={})
  options = ({:unpause_uri => nil, :pipeline_name => nil}).merge(options)
  if options[:unpause_uri]
    uri = options[:unpause_uri]
  else
    raise 'Insufficient arguments' unless options[:pipeline_name]
    uri = "#{@base_uri}/api/pipelines/#{options[:pipeline_name]}/unpause"
  end
  @http_fetcher.post!(uri)
end