Class: OpenC3::InterfaceStatusModel
- Includes:
- DbShardedModel
- Defined in:
- lib/openc3/models/interface_status_model.rb
Overview
Stores the status about an interface. This class also implements logic to handle status for a router since the functionality is identical (only difference is the Redis key used).
Direct Known Subclasses
Constant Summary collapse
- INTERFACES_PRIMARY_KEY =
'openc3_interface_status'- ROUTERS_PRIMARY_KEY =
'openc3_router_status'
Instance Attribute Summary collapse
-
#clients ⇒ Object
Returns the value of attribute clients.
-
#rxbytes ⇒ Object
Returns the value of attribute rxbytes.
-
#rxcnt ⇒ Object
Returns the value of attribute rxcnt.
-
#rxsize ⇒ Object
Returns the value of attribute rxsize.
-
#state ⇒ Object
Returns the value of attribute state.
-
#txbytes ⇒ Object
Returns the value of attribute txbytes.
-
#txcnt ⇒ Object
Returns the value of attribute txcnt.
-
#txsize ⇒ Object
Returns the value of attribute txsize.
Attributes inherited from Model
#name, #plugin, #scope, #updated_at
Class Method Summary collapse
-
._collect_db_shards(scope:) ⇒ Object
Collect all unique db_shard values from InterfaceModels or RouterModels.
-
._get_key ⇒ Object
Helper method to return the correct primary key based on class name.
-
._get_type ⇒ Object
Helper method to return the correct type based on class name.
-
._lookup_db_shard(name, scope:) ⇒ Object
Look up db_shard from the corresponding InterfaceModel or RouterModel.
- .all(scope:) ⇒ Object
-
.get(name:, scope:) ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work.
- .names(scope:) ⇒ Object
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
- #create(update: false, force: false, queued: false, isoformat: false) ⇒ Object
- #destroy ⇒ Object
-
#initialize(name:, state:, clients: 0, txsize: 0, rxsize: 0, txbytes: 0, rxbytes: 0, txcnt: 0, rxcnt: 0, updated_at: nil, plugin: nil, scope:) ⇒ InterfaceStatusModel
constructor
A new instance of InterfaceStatusModel.
Methods included from DbShardedModel
#_db_sharded_create, #_db_sharded_destroy, included
Methods inherited from Model
#check_disable_erb, #deploy, #destroyed?, #diff, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, set, store, store_queued, #undeploy, #update
Constructor Details
#initialize(name:, state:, clients: 0, txsize: 0, rxsize: 0, txbytes: 0, rxbytes: 0, txcnt: 0, rxcnt: 0, updated_at: nil, plugin: nil, scope:) ⇒ InterfaceStatusModel
Returns a new instance of InterfaceStatusModel.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/openc3/models/interface_status_model.rb', line 92 def initialize( name:, state:, clients: 0, txsize: 0, rxsize: 0, txbytes: 0, rxbytes: 0, txcnt: 0, rxcnt: 0, updated_at: nil, plugin: nil, scope: ) if self.class._get_type == 'INTERFACESTATUS' super("#{scope}__#{INTERFACES_PRIMARY_KEY}", name: name, updated_at: updated_at, plugin: plugin, scope: scope) else super("#{scope}__#{ROUTERS_PRIMARY_KEY}", name: name, updated_at: updated_at, plugin: plugin, scope: scope) end @state = state @clients = clients @txsize = txsize @rxsize = rxsize @txbytes = txbytes @rxbytes = rxbytes @txcnt = txcnt @rxcnt = rxcnt end |
Instance Attribute Details
#clients ⇒ Object
Returns the value of attribute clients.
32 33 34 |
# File 'lib/openc3/models/interface_status_model.rb', line 32 def clients @clients end |
#rxbytes ⇒ Object
Returns the value of attribute rxbytes.
36 37 38 |
# File 'lib/openc3/models/interface_status_model.rb', line 36 def rxbytes @rxbytes end |
#rxcnt ⇒ Object
Returns the value of attribute rxcnt.
38 39 40 |
# File 'lib/openc3/models/interface_status_model.rb', line 38 def rxcnt @rxcnt end |
#rxsize ⇒ Object
Returns the value of attribute rxsize.
34 35 36 |
# File 'lib/openc3/models/interface_status_model.rb', line 34 def rxsize @rxsize end |
#state ⇒ Object
Returns the value of attribute state.
31 32 33 |
# File 'lib/openc3/models/interface_status_model.rb', line 31 def state @state end |
#txbytes ⇒ Object
Returns the value of attribute txbytes.
35 36 37 |
# File 'lib/openc3/models/interface_status_model.rb', line 35 def txbytes @txbytes end |
#txcnt ⇒ Object
Returns the value of attribute txcnt.
37 38 39 |
# File 'lib/openc3/models/interface_status_model.rb', line 37 def txcnt @txcnt end |
#txsize ⇒ Object
Returns the value of attribute txsize.
33 34 35 |
# File 'lib/openc3/models/interface_status_model.rb', line 33 def txsize @txsize end |
Class Method Details
._collect_db_shards(scope:) ⇒ Object
Collect all unique db_shard values from InterfaceModels or RouterModels.
49 50 51 52 53 54 55 56 57 |
# File 'lib/openc3/models/interface_status_model.rb', line 49 def self._collect_db_shards(scope:) db_shards = Set.new([0]) type = _get_type key = type == 'INTERFACESTATUS' ? "#{scope}__openc3_interfaces" : "#{scope}__openc3_routers" Store.hgetall(key).each do |_name, json| db_shards << (JSON.parse(json, allow_nan: true, create_additions: true)['db_shard'] || 0).to_i end db_shards end |
._get_key ⇒ Object
Helper method to return the correct primary key based on class name
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/openc3/models/interface_status_model.rb', line 80 def self._get_key type = _get_type case type when 'INTERFACESTATUS' INTERFACES_PRIMARY_KEY when 'ROUTERSTATUS' ROUTERS_PRIMARY_KEY else raise "Unknown type #{type} from class #{self.name}" end end |
._get_type ⇒ Object
Helper method to return the correct type based on class name
75 76 77 |
# File 'lib/openc3/models/interface_status_model.rb', line 75 def self._get_type self.name.to_s.split("Model")[0].upcase.split("::")[-1] end |
._lookup_db_shard(name, scope:) ⇒ Object
Look up db_shard from the corresponding InterfaceModel or RouterModel.
41 42 43 44 45 46 |
# File 'lib/openc3/models/interface_status_model.rb', line 41 def self._lookup_db_shard(name, scope:) type = _get_type key = type == 'INTERFACESTATUS' ? "#{scope}__openc3_interfaces" : "#{scope}__openc3_routers" json = Store.hget(key, name) json ? (JSON.parse(json, allow_nan: true, create_additions: true)['db_shard'] || 0).to_i : 0 end |
.all(scope:) ⇒ Object
69 70 71 |
# File 'lib/openc3/models/interface_status_model.rb', line 69 def self.all(scope:) _db_sharded_all("#{scope}__#{_get_key}", scope: scope) end |
.get(name:, scope:) ⇒ Object
NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work
61 62 63 |
# File 'lib/openc3/models/interface_status_model.rb', line 61 def self.get(name:, scope:) _db_sharded_get("#{scope}__#{_get_key}", name: name, scope: scope) end |
.names(scope:) ⇒ Object
65 66 67 |
# File 'lib/openc3/models/interface_status_model.rb', line 65 def self.names(scope:) _db_sharded_names("#{scope}__#{_get_key}", scope: scope) end |
Instance Method Details
#as_json(*a) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/openc3/models/interface_status_model.rb', line 129 def as_json(*a) { 'name' => @name, 'state' => @state, 'clients' => @clients, 'txsize' => @txsize, 'rxsize' => @rxsize, 'txbytes' => @txbytes, 'rxbytes' => @rxbytes, 'txcnt' => @txcnt, 'rxcnt' => @rxcnt, 'plugin' => @plugin, 'updated_at' => @updated_at } end |
#create(update: false, force: false, queued: false, isoformat: false) ⇒ Object
121 122 123 |
# File 'lib/openc3/models/interface_status_model.rb', line 121 def create(update: false, force: false, queued: false, isoformat: false) _db_sharded_create(self.class._db_shard_for_name(@name, scope: @scope, use_cache: true), update: update, force: force, queued: queued, isoformat: isoformat) end |
#destroy ⇒ Object
125 126 127 |
# File 'lib/openc3/models/interface_status_model.rb', line 125 def destroy _db_sharded_destroy(self.class._db_shard_for_name(@name, scope: @scope)) end |