提交 095fccd4 编写于 作者: J jinhai

Update Group handle


Former-commit-id: 763ec1587990a4c47ee52e1e255ca75e1b91320a
上级 c40c2172
......@@ -27,8 +27,14 @@ class MetaManager(object):
else:
return ErrorCode.FAULT_CODE, None
# def DeleteGroup(group_id):
# group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
# if(group):
# db.session.delete(group)
# else:
\ No newline at end of file
@staticmethod
def DeleteGroup(group):
db.session.delete(group)
@staticmethod
def DeleteGroupFiles(group_name):
records = FileTable.query.filter(FileTable.group_name == group_name).all()
for record in records:
print("record.group_name: ", record.group_name)
db.session.delete(record)
\ No newline at end of file
......@@ -14,6 +14,14 @@ class StorageManager(object):
def GetGroupDirectory(group_name):
return DATABASE_DIRECTORY + '/' + group_name
@staticmethod
def DeleteGroup(group_id):
path = StorageManager.GetGroupDirectory(group_id)
path = path.strip()
path=path.rstrip("\\")
if os.path.exists(path):
shutil.rmtree(path)
def Read():
pass
......
......@@ -21,10 +21,9 @@ class TestVectorEngine:
def test_group(self):
# Make sure there is no group
code, group_id, file_number = VectorEngine.DeleteGroup('test_group')
code, group_id = VectorEngine.DeleteGroup('test_group')
assert code == VectorEngine.SUCCESS_CODE
assert group_id == 'test_group'
assert file_number == 0
# Add a group
code, group_id = VectorEngine.AddGroup('test_group', 8)
......@@ -32,10 +31,9 @@ class TestVectorEngine:
assert group_id == 'test_group'
# Check the group existing
code, group_id, file_number = VectorEngine.GetGroup('test_group')
code, group_id = VectorEngine.GetGroup('test_group')
assert code == VectorEngine.SUCCESS_CODE
assert group_id == 'test_group'
assert file_number == 0
# Check the group list
code, group_list = VectorEngine.GetGroupList()
......@@ -63,16 +61,14 @@ class TestVectorEngine:
assert code == VectorEngine.SUCCESS_CODE
# Remove the group
code, group_id, file_number = VectorEngine.DeleteGroup('test_group')
code, group_id = VectorEngine.DeleteGroup('test_group')
assert code == VectorEngine.SUCCESS_CODE
assert group_id == 'test_group'
assert file_number == 0
# Check the group is disppeared
code, group_id, file_number = VectorEngine.GetGroup('test_group')
code, group_id = VectorEngine.GetGroup('test_group')
assert code == VectorEngine.FAULT_CODE
assert group_id == 'test_group'
assert file_number == 0
# Check SearchVector interface
code, vector_ids = VectorEngine.SearchVector('test_group', self.__vector, self.__limit)
......
......@@ -24,41 +24,35 @@ class VectorEngine(object):
@staticmethod
def AddGroup(group_name, dimension):
error, group = MetaManager.GetGroup(group_name)
if(error == ErrorCode.SUCCESS_CODE):
if error == ErrorCode.SUCCESS_CODE:
return ErrorCode.FAULT_CODE, group_name
else:
StorageManager.AddGroup(group_name)
MetaManager.AddGroup(group_name, dimension)
return VectorEngine.SUCCESS_CODE, group_name
return ErrorCode.SUCCESS_CODE, group_name
@staticmethod
def GetGroup(group_id):
group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
if group:
return VectorEngine.SUCCESS_CODE, group_id, group.file_number
else:
return VectorEngine.FAULT_CODE, group_id, 0
def GetGroup(group_name):
error, _ = MetaManager.GetGroup(group_name)
return error, group_name
@staticmethod
def DeleteGroup(group_id):
group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
def DeleteGroup(group_name):
group = GroupTable.query.filter(GroupTable.group_name==group_name).first()
if(group):
# old_group = GroupTable(group_id)
db.session.delete(group)
db.session.commit()
GroupHandler.DeleteGroupDirectory(group_id)
MetaManager.DeleteGroup(group)
StorageManager.DeleteGroup(group_name)
records = FileTable.query.filter(FileTable.group_name == group_id).all()
records = FileTable.query.filter(FileTable.group_name == group_name).all()
for record in records:
print("record.group_name: ", record.group_name)
db.session.delete(record)
db.session.commit()
return VectorEngine.SUCCESS_CODE, group_id, group.file_number
return VectorEngine.SUCCESS_CODE, group_name
else:
return VectorEngine.SUCCESS_CODE, group_id, 0
return VectorEngine.SUCCESS_CODE, group_name
@staticmethod
......@@ -78,7 +72,7 @@ class VectorEngine(object):
@staticmethod
def AddVector(group_id, vectors):
print(group_id, vectors)
code, _, _ = VectorEngine.GetGroup(group_id)
code, _, = VectorEngine.GetGroup(group_id)
if code == VectorEngine.FAULT_CODE:
return VectorEngine.GROUP_NOT_EXIST, 'invalid'
......@@ -140,7 +134,7 @@ class VectorEngine(object):
@staticmethod
def SearchVector(group_id, vector, limit):
# Check the group exist
code, _, _ = VectorEngine.GetGroup(group_id)
code, _ = VectorEngine.GetGroup(group_id)
if code == VectorEngine.FAULT_CODE:
return VectorEngine.GROUP_NOT_EXIST, {}
......@@ -168,7 +162,7 @@ class VectorEngine(object):
@staticmethod
def CreateIndex(group_id):
# Check the group exist
code, _, _ = VectorEngine.GetGroup(group_id)
code, _ = VectorEngine.GetGroup(group_id)
if code == VectorEngine.FAULT_CODE:
return VectorEngine.GROUP_NOT_EXIST
......
......@@ -63,11 +63,11 @@ class Group(Resource):
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
def get(self, group_id):
code, group_id, file_number = VectorEngine.GetGroup(group_id)
code, group_id = VectorEngine.GetGroup(group_id)
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
def delete(self, group_id):
code, group_id, file_number = VectorEngine.DeleteGroup(group_id)
code, group_id = VectorEngine.DeleteGroup(group_id)
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册