Class: CfdpApi

Inherits:
OpenC3::JsonApi
  • Object
show all
Defined in:
lib/cfdp_api.rb

Overview

Usage:

Note: Recommend using the methods in cfdp.rb rather than this file directly

In ScriptRunner: require ‘cfdp_api’ api = CfdpApi.new() api.put(…)

Outside cluster - Open Source: $openc3_scope = ‘DEFAULT’ ENV = ‘password’ require ‘cfdp_api’ api = CfdpApi.new(url: “127.0.0.1:2900/cfdp”) api.put(…)

Outside cluster - Enterprise $openc3_scope = ‘DEFAULT’ ENV = ‘127.0.0.1:2900/authENV = ‘operator’ ENV = ‘operator’ require ‘cfdp_api’ api = CfdpApi.new(url: “127.0.0.1:2900/cfdp”) api.put(…)

Instance Method Summary collapse

Instance Method Details

#cancel(transaction_id:, remote_entity_id: nil, scope: $openc3_scope) ⇒ Object



90
91
92
# File 'lib/cfdp_api.rb', line 90

def cancel(transaction_id:, remote_entity_id: nil, scope: $openc3_scope)
  transaction_id_post(method_name: "cancel", transaction_id: transaction_id, remote_entity_id: remote_entity_id, scope: $openc3_scope)
end

#directory_listing(remote_entity_id:, directory_name:, directory_file_name:, scope: $openc3_scope) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/cfdp_api.rb', line 146

def directory_listing(remote_entity_id:, directory_name:, directory_file_name:, scope: $openc3_scope)
  begin
    endpoint = "/directorylisting"
    data = { "remote_entity_id" => remote_entity_id, "directory_name" => directory_name, "directory_file_name" => directory_file_name }
    response = _request('post', endpoint, data: data, scope: scope)
    if response.nil? || response.code != 200
      if response
        raise "CFDP directory listing error: #{response.code}: #{response.body}"
      else
        raise "CFDP  directory listing failed"
      end
    end
    return response.body
  rescue => error
    raise "CFDP  directory listing failed due to #{error.formatted}"
  end
end

#indications(transaction_id: nil, continuation: nil, limit: 100, scope: $openc3_scope) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cfdp_api.rb', line 124

def indications(transaction_id: nil, continuation: nil, limit: 100, scope: $openc3_scope)
  begin
    endpoint = "/indications"
    endpoint << ('/' + transaction_id.to_s) if transaction_id
    query = {}
    query[:continuation] = continuation if continuation
    query[:limit] = limit if limit
    response = _request('get', endpoint, query: query, scope: scope)
    if response.nil? || response.code != 200
      if response
        raise "CFDP indications error: #{response.code}: #{response.body}"
      else
        raise "CFDP indications failed"
      end
    end
    # Hash of continuation, and indications array
    return JSON.parse(response.body)
  rescue => error
    raise "CFDP indications failed due to #{error.formatted}"
  end
end

#put(destination_entity_id:, source_file_name:, destination_file_name:, transmission_mode: nil, closure_requested: nil, filestore_requests: [], fault_handler_overrides: [], flow_label: nil, segmentation_control: "NOT_PRESERVED", messages_to_user: [], remote_entity_id: nil, scope: $openc3_scope) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cfdp_api.rb', line 47

def put(
  destination_entity_id:,
  source_file_name:,
  destination_file_name:,
  transmission_mode: nil,
  closure_requested: nil,
  filestore_requests: [],
  fault_handler_overrides: [],
  flow_label: nil,
  segmentation_control: "NOT_PRESERVED",
  messages_to_user: [],
  remote_entity_id: nil, # Used to indicate proxy put
  scope: $openc3_scope)

  begin
    endpoint = "/put"
    data = {
      "destination_entity_id" => destination_entity_id.to_i,
      "source_file_name" => source_file_name,
      "destination_file_name" => destination_file_name,
      "transmission_mode" => transmission_mode,
      "closure_requested" => closure_requested,
      "filestore_requests" => filestore_requests,
      "fault_handler_overrides" => fault_handler_overrides,
      "messages_to_user" => messages_to_user,
      "flow_label" => flow_label,
      "segmentation_control" => segmentation_control
    }
    data["remote_entity_id"] = remote_entity_id.to_i if remote_entity_id
    response = _request('post', endpoint, data: data, scope: scope)
    if response.nil? || response.code != 200
      if response
        raise "CFDP put error: #{response.code}: #{response.body}"
      else
        raise "CFDP put failed"
      end
    end
    return response.body
  rescue => error
    raise "CFDP put failed due to #{error.formatted}"
  end
end

#report(transaction_id:, remote_entity_id: nil, report_file_name: nil, scope: $openc3_scope) ⇒ Object



102
103
104
# File 'lib/cfdp_api.rb', line 102

def report(transaction_id:, remote_entity_id: nil, report_file_name: nil, scope: $openc3_scope)
  transaction_id_post(method_name: "report", transaction_id: transaction_id, remote_entity_id: remote_entity_id, report_file_name: report_file_name, scope: $openc3_scope)
end

#resume(transaction_id:, remote_entity_id: nil, scope: $openc3_scope) ⇒ Object



98
99
100
# File 'lib/cfdp_api.rb', line 98

def resume(transaction_id:, remote_entity_id: nil, scope: $openc3_scope)
  transaction_id_post(method_name: "resume", transaction_id: transaction_id, remote_entity_id: remote_entity_id, scope: $openc3_scope)
end

#subscribe(scope: $openc3_scope) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cfdp_api.rb', line 106

def subscribe(scope: $openc3_scope)
  begin
    endpoint = "/subscribe"
    response = _request('get', endpoint, scope: scope)
    if response.nil? || response.code != 200
      if response
        raise "CFDP subscribe error: #{response.code}: #{response.body}"
      else
        raise "CFDP subscribe failed"
      end
    end
    # Most recent topic id
    return response.body
  rescue => error
    raise "CFDP subscribe failed due to #{error.formatted}"
  end
end

#suspend(transaction_id:, remote_entity_id: nil, scope: $openc3_scope) ⇒ Object



94
95
96
# File 'lib/cfdp_api.rb', line 94

def suspend(transaction_id:, remote_entity_id: nil, scope: $openc3_scope)
  transaction_id_post(method_name: "suspend", transaction_id: transaction_id, remote_entity_id: remote_entity_id, scope: $openc3_scope)
end

#transaction_id_post(method_name:, transaction_id:, remote_entity_id: nil, report_file_name: nil, scope: $openc3_scope) ⇒ Object

private



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/cfdp_api.rb', line 186

def transaction_id_post(method_name:, transaction_id:, remote_entity_id: nil, report_file_name: nil, scope: $openc3_scope)
  begin
    endpoint = "/#{method_name}"
    data = { "transaction_id" => transaction_id.to_s }
    data['remote_entity_id'] = remote_entity_id if remote_entity_id
    data['report_file_name'] = report_file_name if report_file_name
    response = _request('post', endpoint, data: data, scope: scope)
    if response.nil? || response.code != 200
      if response
        raise "CFDP #{method_name} error: #{response.code}: #{response.body}"
      else
        raise "CFDP #{method_name} failed"
      end
    end
    return response.body
  rescue => error
    raise "CFDP #{method_name} failed due to #{error.formatted}"
  end
end

#transactions(active: true, scope: $openc3_scope) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/cfdp_api.rb', line 164

def transactions(active: true, scope: $openc3_scope)
  begin
    endpoint = "/transactions"
    query = {}
    query[:active] = active if active
    response = _request('get', endpoint, query: query, scope: scope)
    if response.nil? || response.code != 200
      if response
        raise "CFDP transactions error: #{response.code}: #{response.body}"
      else
        raise "CFDP transactions failed"
      end
    end
    # Array of Transaction Hashes
    return JSON.parse(response.body)
  rescue => error
    raise "CFDP transactions failed due to #{error.formatted}"
  end
end