@@ -178,6 +178,10 @@ module PoolRequestParser
178178 storage_units[" replica" ].size,
179179 storage_units[" mirror" ].size
180180 )
181+ elsif storage_units[" arbiter" ].size == 3
182+ grp_storage_units = storage_units[" arbiter" ]
183+ dist_group.replica_count = 3
184+ dist_group.arbiter_count = 1
181185 elsif storage_units[" disperse" ].size > 0 ||
182186 storage_units[" data" ].size > 0
183187 grp_storage_units = storage_units[" disperse" ] +
@@ -284,30 +288,49 @@ module PoolRequestParser
284288 req
285289 end
286290
287- # Validate the Pool create request after parsing
288291 def self.validate (req )
292+ validate_pool_name(req)
293+ validate_storage_units(req.distribute_groups)
294+ end
295+
296+ def self.validate_pool_name (req )
297+ # TODO: Pool name validations
289298 raise InvalidPoolRequest .new(" Pool name not specified (Example: mypool)" ) if req.name == " "
290299 raise InvalidPoolRequest .new(" Atleast one Storage unit is required" ) if req.distribute_groups.size == 0
300+ end
291301
292- # TODO: Pool name validations
302+ def self.validate_storage_units (distribute_groups )
303+ distribute_groups.each do |dist_grp |
304+ validate_storage_units_match_replica_count(dist_grp)
305+ validate_storage_units_match_disperse_count(dist_grp)
306+ validate_storage_units_node_names(dist_grp.storage_units)
307+ end
308+ end
293309
294- req.distribute_groups.each do |dist_grp |
295- if dist_grp.replica_count > 0 && dist_grp.storage_units.size != dist_grp.replica_count
296- raise InvalidPoolRequest .new(
297- " Number of Storage units not matching #{ dist_grp.replica_keyword } count"
298- )
299- end
300- if dist_grp.disperse_count > 0 && dist_grp.storage_units.size != dist_grp.disperse_count
301- raise InvalidPoolRequest .new(
302- " Number of Storage units not matching disperse count"
303- )
304- end
310+ def self.validate_storage_units_match_replica_count (dist_grp )
311+ replica_arbiter_dist_grp_size = dist_grp.replica_count
312+ replica_arbiter_dist_grp_size += 1 if dist_grp.arbiter_count > 0 && dist_grp.replica_count == 2
305313
306- dist_grp.storage_units.each do |storage_unit |
307- msg = storage_unit.port > 0 ? " #{ storage_unit.port } :" : " "
308- msg += storage_unit.path
309- raise InvalidPoolRequest .new(" Node name is not specified for #{ msg } " ) if storage_unit.node.name == " "
310- end
314+ if dist_grp.replica_count > 0 && dist_grp.storage_units.size != replica_arbiter_dist_grp_size
315+ raise InvalidPoolRequest .new(
316+ " Number of Storage units not matching #{ dist_grp.replica_keyword } count"
317+ )
318+ end
319+ end
320+
321+ def self.validate_storage_units_match_disperse_count (dist_grp )
322+ if dist_grp.disperse_count > 0 && dist_grp.storage_units.size != dist_grp.disperse_count
323+ raise InvalidPoolRequest .new(
324+ " Number of Storage units not matching disperse count"
325+ )
326+ end
327+ end
328+
329+ def self.validate_storage_units_node_names (storage_units )
330+ storage_units.each do |storage_unit |
331+ msg = storage_unit.port > 0 ? " #{ storage_unit.port } :" : " "
332+ msg += storage_unit.path
333+ raise InvalidPoolRequest .new(" Node name is not specified for #{ msg } " ) if storage_unit.node.name == " "
311334 end
312335 end
313336end
0 commit comments