-
Notifications
You must be signed in to change notification settings - Fork 1
/
mongo_test.py
92 lines (73 loc) · 2.6 KB
/
mongo_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
88
89
90
91
92
from pymongo import MongoClient
from bson import json_util
import sys
# client = MongoClient("localhost",27222)
# print(client.database_names())
# db = client.USEHASKELLDB
# cursor = db.Directory_RECORD.find({})
# for document in cursor:
# print(document)
# print("filservers")
# cursor = db.DirHealth_RECORD.find({})
# for document in cursor:
# print(document)
# cursor = db.Files_RECORD.find({})
# for document in cursor:
# print(document)
# client = MongoClient("localhost",27890)
# print(client.database_names())
# db = client.USEHASKELLDB
# cursor = db.LockService_RECORD.find({})
# for document in cursor:
# print(document)
# print("client record")
def print_contents():
allports = {"authserver": 27000,"directoryservice":27222 ,"lock": 27890,"fileserver_0":27090, "fileserver_1": 27091, "fileserver_2":27092, "transactionservice":27984}
for x in allports:
print("printing contents from " + x)
client = MongoClient("localhost",allports[x])
db = client.USEHASKELLDB
for collection in db.collection_names()[:-1]:
print("collection: " + collection)
cursor = db[collection].find({})
for document in cursor:
print(document)
print("\n \n \n")
print("\n checking client1 db")
client = MongoClient("localhost",27223)
db = client.USEHASKELLDB
for collection in db.collection_names():
print("collection: " + collection)
cursor = db[collection].find({})
for document in cursor:
print(document)
def drop_all():
"""
This drops all the contents including directory services'
As a result fileserver registration will also be deleted
and there wont be any filserver information
"""
allports = {"authserver": 27000,"directoryservice":27222 ,"lock": 27890,"fileserver_0":27090, "fileserver_1": 27091, "fileserver_2":27092, "transactionservice":27984}
for x in allports:
client = MongoClient("localhost",allports[x])
db = client.USEHASKELLDB
for collection in db.collection_names()[:-1]:
print(" Droppingcollection: " + collection)
cursor = db[collection].drop()
# cursor = db.jobs.find({"completed": False,})
# print("\n \n \n")
# for document in cursor:
# print(document)
# print(db.jobs.find({}).count())
# print("left to do {}". format(list(db.jobs.find({"completed": False,}))))
# print("left to do {}". format(db.jobs.find({"completed": False,}).count()))
# res = db.jobs.aggregate([
# { "$group": { "_id": {},"max": { "$max": "$assigned_time" },"min": { "$min": "$assigned_time" }
# }}
# ])
# print(list(res))
if __name__=="__main__":
if len(sys.argv) <2:
print_contents()
else:
drop_all()