コード例 #1
0
#print out for testing's purpose
results = parser.parse_args()
print(results.ts_name)
print('name = {!r}'.format(results.ts_name))
print('eventChoice= {!r}'.format(results.event_type))
print('infomation = {!r}'.format(results.payload))
print(parser.parse_args())

temp_ts_name = results.ts_name
temp_event = results.event_type


users=['alice', 'bob', 'chuck']

nameS_ts = proxy.TupleSpaceAdapter(f'http://localhost:8004')

datas = {}
#get the dictionary that has alice, bob, chuck {'alice': 'start', 'alice_uri': 'http://localhost:8001'}
for user in users:
    user_uri = user + "_uri"
    try:
        ts_name = nameS_ts._rdp([user, None]) #read from namingserver tuplespace to know alice's tuplespace start
        if ts_name is not None:
            print(ts_name)
            datas[user] = ts_name[1]
        ts_uri = nameS_ts._rdp([user_uri, None]) #read from namingserver's tuplespace to know alice's uri

        if ts_uri is not None:
            print(ts_uri)
            datas[user_uri] = ts_uri[1]
コード例 #2
0
#!/usr/bin/env python3

import code
import proxy
import config

config = config.read_config()

ts_name      = config['name']
adapter_host = config['adapter']['host']
adapter_port = config['adapter']['port']

adapter_uri = f'http://{adapter_host}:{adapter_port}'

ts = proxy.TupleSpaceAdapter(adapter_uri)

print(f'Connected to tuplespace {ts_name} on {adapter_uri}')

code.interact(local=locals())
コード例 #3
0
#!/usr/bin/env python3

import proxy
import config

config = config.read_config()
ts_name= config['name']
print(ts_name)
count = -1
log = []
list_output=[['chuck', 'gtcn', 'This graph theory stuff is not easy'],['chuck', 'distsys', 'I like systems more than graphs']]
ts_server = proxy.TupleSpaceAdapter('http://localhost:8005')
ts = proxy.TupleSpaceAdapter('http://localhost:8003')

b=ts_server._rdp([None,None,None,None])
# if server is not empty
if b is not None:
    count = b[-1]
    self = ts._rdp([None,None,None,count])
    if self is None:
        log.append(b)
        ts._out(b)
        print(log)
        count += 1
    else:
        count += 1
# if server is empty
else:
    ts._out(['chuck', 'gtcn', 'This graph theory stuff is not easy'])
    ts._out(['chuck', 'distsys', 'I like systems more than graphs'])
コード例 #4
0
#!/usr/bin/env python3

import sys
import struct
import socket
from xmlrpc.server import SimpleXMLRPCServer
from threading import Thread
import proxy

naming_proxy = proxy.TupleSpaceAdapter('http://localhost:8004')

MAX_UDP_PAYLOAD = 65507

server = SimpleXMLRPCServer(("localhost", 5000), allow_none=True)
count = 1


def replicate_tuple_to_all(name, data):
    namelists = []
    for i in range(0, count):
        name_list_row = naming_proxy._rd(count)
        namelists.append(name_list_row)
    for namelist in namelists:
        if namelist[1] != name:
            replicate_proxy = proxy.TupleSpaceAdapter((int, namelist[2], str))
            replicate_proxy._out(data)
    return "Sucessfully replicated\n"


def getURI(name):
    v = naming_proxy._rd((int, name, str))
コード例 #5
0
def handleEventMain(notification, ts, procList, id, servers_ts, servers,
                    isPrimary):

    # procList = [[logFilename1, isUnique1, entityList1, None, None, ignoreEntity1, entityListFunc1], [logFilename2, isUnique2, entityList2, None, None, ignoreEntity2, entityListFunc2]]
    # procList[i][3] = notificationList
    # procList[i][4] = messageList
    message = Common.deserializeNotification(notification)
    print(message)

    entity = message[Common.MessageEntity]
    event = message[Common.MessageEvent]
    td = [entity, event, message[Common.MessageData]]

    if (event == "elect"):
        servers_ts._out(["candidate", "candidate", id])
        isPrimary = processElectionWinner(id, waitPeriod, servers_ts)
    elif isPrimary:
        if (event == "check_leader"):
            servers_ts._out(["alive", "alive", id])
        elif ((event == Common.EventStart) or (event == Common.EventAdapter)):
            if (event == Common.EventStart):

                # recovery functionality
                eri = replayHandlingInfo()
                etsList = Common.getEntityTsList(ts)
                for etsi in etsList:
                    Common.replayEvents(entity, etsi[1], procList[1][4],
                                        eri[0], eri[1], procList[1][5])

                procList[1][3].append(notification)
                procList[1][4].append(message)

            # naming functionality
            Common.logNotificationToFile(procList[0][0], notification,
                                         procList[0][3], procList[0][1])

            try:
                ts._out(td)
            except Exception as e:
                logging.error(f'_out Error {e}')

            Common.updateServerList(ts, entity)

            for backupServer in servers:
                if (backupServer["id"] != id):
                    backupTs = proxy.TupleSpaceAdapter(backupServer["ts"])
                    try:
                        backupTs._out(td)
                    except Exception as be:
                        logging.error(
                            f'_out Error {backupServer["id"]} {backupServer["ts"]} {be}'
                        )

            procList[0][3].append(notification)
            procList[0][4].append(message)

        elif ((event == Common.EventWrite) or (event == Common.EventTake)):

            # recovery functionality
            # print('recovery functionality for write, take')
            if (message[Common.MessageData]
                    not in [i[Common.MessageData] for i in procList[1][4]]):

                Common.playEventsAll(ts, [message[Common.MessageData]],
                                     lambda itd, name, ets: ets._out(itd))
                Common.logNotificationToFile(procList[1][0], notification,
                                             procList[1][3], procList[1][1])

                procList[1][3].append(notification)
                procList[1][4].append(message)

        else:
            return isPrimary
    # if isPrimary:
    else:
        return isPrimary

    return isPrimary
コード例 #6
0
    "port": 54324,
    "ts": "http://localhost:8004"
}, {
    "id": 1,
    "host": "224.0.0.1",
    "port": 54325,
    "ts": "http://localhost:8005"
}]

adapter_host = "localhost"
adapter_port = 8006
waitPeriod = 5

servers_adapter_uri = f'http://{adapter_host}:{adapter_port}'

servers_ts = proxy.TupleSpaceAdapter(servers_adapter_uri)

# ts._out(["*", 3, 4])
# res = ts._in(["result", None])

entityTupleManager = f"{Common.EntityTuplemanager}.{id}"
# entityTupleManager = f"tuplemanager.1"
g_isPrimary = False
electionEvent = f"elect elect elect"


def doEmpty(ts, searchPattern):
    isEmpty = False
    while not isEmpty:
        td = ts._inp(searchPattern)
        if (td is None):
コード例 #7
0
import proxy

#Connect naming TS.
ts = proxy.TupleSpaceAdapter('http://localhost:8003') 
users=[["alice"],["bob"],["chuck"]]

# #Manually writing the users.
# for i in users:
#     ts._out(i)
#     print(i)


# result=ts._rdp(['alice']) 
# print(result)
 
# result=ts._inp(users)
# print(result)

# def _getuser(self,u):
#      result=ts._rdp(users)
#      print(result)