Class: CfdpApi
- Inherits:
-
OpenC3::JsonApi
- Object
- OpenC3::JsonApi
- CfdpApi
- 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: require ‘cfdp_api’ $openc3_scope = ‘DEFAULT’ ENV = ‘password’ api = CfdpApi.new(hostname: ‘127.0.0.1’, port: 2900) api.put(…)
Outside cluster - Enterprise require ‘cfdp_api’ $openc3_scope = ‘DEFAULT’ ENV = ‘127.0.0.1:2900’ ENV = ‘operator’ ENV = ‘operator’ api = CfdpApi.new(hostname: ‘127.0.0.1’, port: 2900) api.put(…)
Instance Method Summary collapse
- #cancel(transaction_id:, remote_entity_id: nil, scope: $openc3_scope) ⇒ Object
- #directory_listing(remote_entity_id:, directory_name:, directory_file_name:, scope: $openc3_scope) ⇒ Object
- #indications(transaction_id: nil, continuation: nil, limit: 100, scope: $openc3_scope) ⇒ Object
- #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
- #report(transaction_id:, remote_entity_id: nil, report_file_name: nil, scope: $openc3_scope) ⇒ Object
- #resume(transaction_id:, remote_entity_id: nil, scope: $openc3_scope) ⇒ Object
- #subscribe(scope: $openc3_scope) ⇒ Object
- #suspend(transaction_id:, remote_entity_id: nil, scope: $openc3_scope) ⇒ Object
-
#transaction_id_post(method_name:, transaction_id:, remote_entity_id: nil, report_file_name: nil, scope: $openc3_scope) ⇒ Object
private.
- #transactions(active: true, scope: $openc3_scope) ⇒ Object
Instance Method Details
#cancel(transaction_id:, remote_entity_id: nil, scope: $openc3_scope) ⇒ Object
89 90 91 |
# File 'lib/cfdp_api.rb', line 89 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
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cfdp_api.rb', line 145 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
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cfdp_api.rb', line 123 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
46 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 |
# File 'lib/cfdp_api.rb', line 46 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" => , "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
101 102 103 |
# File 'lib/cfdp_api.rb', line 101 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
97 98 99 |
# File 'lib/cfdp_api.rb', line 97 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
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cfdp_api.rb', line 105 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
93 94 95 |
# File 'lib/cfdp_api.rb', line 93 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
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/cfdp_api.rb', line 185 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
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/cfdp_api.rb', line 163 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 |