def parse_messege(serverNode, sender_index, messege): deleteDatabase(serverNode.coreDB) deleteDatabase(serverNode.middlewareDB) client = pymongo.MongoClient() source = 'CRDT-DisCS_Node_Middleware_' + str(sender_index) dst = 'CRDT-DisCS_Node_Middleware_' + str(serverNode.index) client.admin.command('copydb', fromdb=source, todb=dst) source = 'CRDT-DisCS_Node_Core_' + str(sender_index) dst = 'CRDT-DisCS_Node_Core_' + str(serverNode.index) client.admin.command('copydb', fromdb=source, todb=dst)
def __init__(self, fellow, my_ip, index): self.addr = my_ip self.fellow = fellow self.lock = threading.Lock() self.DB = {} self.dbName = 'RAFT_DB_' + str(index) print("Databasename : ", self.dbName) manageDatabases.deleteDatabase(dbName=self.dbName) mongoengine.register_connection(alias='core', name=self.dbName) self.log = [] self.staged = None self.term = 0 self.status = FOLLOWER self.majority = ((len(self.fellow) + 1) // 2) + 1 self.voteCount = 0 self.commitIdx = 0 self.timeout_thread = None self.init_timeout()
users = readUsers(dbName=dbName) print_users(users) post_ids = [] for _ in range(NUM_FAKE_POSTS): post = get_fake_post() author_index = random.randint(0, len(users) - 1) post.author = users[0].username post_id = add_post(author=post.author, creation_time=post.creation_time, content=post.content, dbName=dbName) post_ids.append(post_id) myPostID = post_ids[0] posts = readPosts(dbName=dbName) print_posts(posts) print(f'--------Deleting post {myPostID}---------') deletePost(post_id=myPostID, dbName=dbName) posts = readPosts(dbName=dbName) print_posts(posts) # print_users(users) deleteDatabase(dbName=dbName)
dbName=dbName) if msg["type"] == "deletePost": args = msg["args"] deletePost(postid=args["postid"], dbName=dbName) def add_user_with_consensus(): pass def dashboard(): pass if __name__ == "__main__": deleteDatabase(dbName=dbName) deleteDatabase(dbName='CRDT-DisCS_Test') # print(listDatabases()) # parsemessage(msg, dbName=dbName) # users = readUsers(dbName=dbName) # print_users(users) # print(listDatabases()) # print(listDatabases()) from client import put, get
**kwargs): user = User() user.full_name = name user.username = username user.nationality = nationality user.age = age user.save() @connect_with_database def readUsers(**kwargs): users = User.objects() return users if __name__ == "__main__": print(listDatabases()) add_user(username='******', age=45, dbName=DB_NAME) users = readUsers(dbName=DB_NAME) print(users) print(users[0].name) print(users[0].username) print(users[0].age) print(users[0].nationality) print(users[0].followers) print(users[0].following) print(listDatabases()) deleteDatabase(dbName=DB_NAME) print(listDatabases())
import sys sys.path.append('..') import mongoengine from discs.data.underlying.users import User from discs.services.underlying import databaseWrite from discs.settings import connect_with_database from discs.manageDatabases import listDatabases, deleteDatabase, delete_project_databases from discs.services.underlying.databaseRead import * if __name__ == "__main__": print("Before Running the Code :", listDatabases()) deleteDatabase(dbName='CRDT-DisCS__DB1') deleteDatabase(dbName='CRDT-DisCS__DB2') print(listDatabases()) databaseWrite.add_user("Shyam", "newUser", "Indian", 34, dbName="CRDT-DisCS__DB1") databaseWrite.add_user("Rohith", "newUser1", "Pakistani", 32, dbName="CRDT-DisCS__DB2") databaseWrite.add_user("Jose", "newUser2", "African", 30, dbName="CRDT-DisCS__DB2") print(listDatabases()) print("In database CRDT-DisCS__DB1 : ")
populate.add_fake_users(10, dbName=database) populate.add_fake_posts(15, dbName=database) populate.add_random_likes(100, dbName=database) populate.add_random_followers(50, dbName=database) if __name__ == "__main__": BASE_DIR = settings.BASE_DIR if os.path.exists(os.path.join(settings.BASE_DIR, "db.sqlite3")): os.remove(os.path.join(settings.BASE_DIR, "db.sqlite3")) else: print("The file does not exist") if os.path.exists(os.path.join(BASE_DIR, "sage", "migrations")): shutil.rmtree(os.path.join(BASE_DIR, "sage", "migrations")) if os.path.exists(os.path.join(BASE_DIR, "scarf", "__pycache__")): shutil.rmtree(os.path.join(BASE_DIR, "scarf", "__pycache__")) if os.path.exists(os.path.join(BASE_DIR, "sage", "__pycache__")): shutil.rmtree(os.path.join(BASE_DIR, "sage", "__pycache__")) databases = listDatabases() for database in databases: if 'CRDT-DisCS__DB' in database: deleteDatabase(database) os.system("python manage.py makemigrations") os.system("python manage.py migrate --run-syncdb") add_data()
from discs.services.underlying.databaseRead import readPosts, print_posts, print_post from discs.data.underlying.users import User from discs.data.underlying.posts import Post from discs.manageDatabases import deleteDatabase from discs.data.middleware.users_update import Users_update from discs.data.middleware.fullname_update import Fullname_update from crdt.CRDT.src.gset import GSet from crdt.CRDT.src.twopset import TwoPSet from crdt.CRDT.src.lww import LWW import random import mongoengine import json deleteDatabase(dbName='CRDT-DisCS_Test_UDB') deleteDatabase(dbName='CRDT-DisCS_Test_Middle_UDB') mongoengine.register_connection(alias='core', name='CRDT-DisCS_Test_UDB') mongoengine.register_connection(alias='middle', name='CRDT-DisCS_Test_Middle_UDB') NUM_FAKE_USERS = 2 NUM_FAKE_POSTS = 2 dbName = None dbName_middleware = None for _ in range(NUM_FAKE_USERS): user = get_fake_user() add_user(name=user.name,