#!/usr/ali/bin/python

import os
import re
import sys

puadmin = '/apsara/deploy/puadmin'
tmp_file = '/tmp/puadmin_meta1_result'
dir = 'pangu://localcluster/'
limit = 20

ret = os.system('%s meta1 %s 2>/dev/null > %s' % (puadmin, dir, tmp_file))
if ret != 0:
  print 'Warning: puadmin exits with code %d' % ret
  sys.exit(1)

fin = open(tmp_file)
bad_count = 0
count = 0
for m in re.findall('replica number:([0-9]*)\tminCopy:([0-9]*)\tmaxCopy:([0-9]*)\tchunk Number:([0-9]*)\tlength:([0-9]*)', fin.read()):
  current_copy = int(m[0])
  min_copy = int(m[1])
  max_copy = int(m[2])
  chunk_count = int(m[3])
  size = int(m[4])
  if current_copy > limit and current_copy > max_copy:
    bad_count += chunk_count
  count = count+1
if bad_count > 0:
  print 'Warning - Found %d chunks that have more than %d copies' % (bad_count, limit)
print 'OK - %d chunks have been scanned' % count
    
# vim: ts=2 sw=2 et

1a2f47c6ad0136de4c09e01c6d22951812751bd4
#!/usr/ali/bin/python

import os
import re
import sys

puadmin = '/apsara/deploy/puadmin'
tmp_file = '/tmp/puadmin_meta1_result'
dir = 'pangu://localcluster/'
limit = 20

ret = os.system('%s meta1 %s 2>/dev/null > %s' % (puadmin, dir, tmp_file))
if ret != 0:
  print 'Warning: puadmin exits with code %d' % ret
  sys.exit(1)

fin = open(tmp_file)
bad_count = 0
count = 0
for m in re.findall('replica number:([0-9]*)\tminCopy:([0-9]*)\tmaxCopy:([0-9]*)\tchunk Number:([0-9]*)\tlength:([0-9]*)', fin.read()):
  current_copy = int(m[0])
  min_copy = int(m[1])
  max_copy = int(m[2])
  chunk_count = int(m[3])
  size = int(m[4])
  if current_copy > limit and current_copy > max_copy:
    bad_count += chunk_count
  count = count+1
if bad_count > 0:
  print 'Warning - Found %d chunks that have more than %d copies' % (bad_count, limit)
print 'OK - %d chunks have been scanned' % count
    
# vim: ts=2 sw=2 et
