Beispiel #1
0
def wait_for_instance(address, port=None, timeout=10.0, register_state=None):
    """Loop until timeout and check for receiving socket."""

    if port is None:
        port = 27017

    timer = gevent.Timeout(timeout)
    timer.start()

    try:
        while True:
            socket = gevent.socket.socket()
            try:
                socket.connect((address, port))
                if callable(register_state):
                    register_state((address, port), True)
                return True

            except gevent.socket.error:
                gevent.sleep(0.1)


    except gevent.Timeout:
        if callable(register_state):
            register_state((address, port), False)

        return False

    finally:
        timer.cancel()
Beispiel #2
0
 def NewChunk(self, arg):
     print type(arg)
     guids = self.registry.keys()
     x = random.choice(guids)
     print "Relay NewChunk to ", x
     ckinfo = self.registry[x]
     socket = gevent.socket.socket()
     socket.connect((ckinfo.ServiceAddress, ckinfo.ServicePort))
     try:
         ret = self.stub.callMethod("NewChunk", arg, socket)
     finally:
         socket.close()
     print "Got response: ", ret
     return ret
Beispiel #3
0
 def NewChunk(self, arg):
     print type(arg)
     guids = self.registry.keys()
     x = random.choice(guids)
     print "Relay NewChunk to ", x
     ckinfo = self.registry[x]
     socket = gevent.socket.socket()
     socket.connect((ckinfo.ServiceAddress, ckinfo.ServicePort))
     try:
         ret = self.stub.callMethod("NewChunk", arg, socket)
     finally:
         socket.close()
     print "Got response: ", ret
     return ret
Beispiel #4
0
def test():
    global PARAM
    logging.basicConfig(level=logging.DEBUG)
    socket = gevent.socket.socket()
    socket.connect((PARAM.MDS_IP, int(PARAM.MDS_PORT)))
    guid = msg.Guid()
    guid.a = 10
    guid.b = 22
    guid.c = 30
    guid.d = 40
    stub = rpc.RpcStub(guid, socket, mds.MDS)
    arg = msg.GetChunkServers_Request()
    ret = stub.callMethod('GetChunkServers', arg)

    s2 = gevent.socket.socket()
    s2.connect((ret.random[0].ServiceAddress, ret.random[0].ServicePort))
    stub2 = rpc.RpcStub(guid, s2, ChunkServer.ChunkServer)

    if raw_input('you want to NewChunk ? ') == 'y':
        arg2 = msg.NewChunk_Request()
        arg2.size = 32
        arg2.count = 2
        ret2 = stub2.callMethod('NewChunk', arg2)
        print ret2.guids

    if raw_input('you want to assembleVolume ? ') == 'y':
        req_assemble = msg.AssembleVolume_Request()
        req_assemble.volume.size = 32
        Guid.assign(req_assemble.volume.guid, ret2.guids[-1])
        res_assemble = stub2.callMethod('AssembleVolume', req_assemble)
        print 'access_point:', res_assemble.access_point

    if raw_input('you want to DisassembleVolume ? ') == 'y':
        req_disassemble = msg.DisassembleVolume_Request()
        req_disassemble.access_point = res_assemble.access_point
        print 'req_disassemble.access_point:', req_disassemble.access_point
        stub2.callMethod('DisassembleVolume', req_disassemble)

    if raw_input('you want to DeleteChunk ? ') == 'y':
        arg3 = msg.DeleteChunk_Request()
        t = arg3.guids.add()
        Guid.assign(t, ret2.guids[0])
        t = arg3.guids.add()
        Guid.assign(t, ret2.guids[1])
        ret_Del = stub2.callMethod('DeleteChunk', arg3)
Beispiel #5
0
def test():
	global PARAM
	logging.basicConfig(level=logging.DEBUG)
	socket=gevent.socket.socket()
	socket.connect((PARAM.MDS_IP, int(PARAM.MDS_PORT)))
	guid=msg.Guid()
	guid.a=10
	guid.b=22
	guid.c=30
	guid.d=40
	stub=rpc.RpcStub(guid, socket, mds.MDS)
	arg=msg.GetChunkServers_Request()
	ret=stub.callMethod('GetChunkServers', arg)

	s2=gevent.socket.socket()
	s2.connect((ret.random[0].ServiceAddress, ret.random[0].ServicePort))
	stub2=rpc.RpcStub(guid, s2, ChunkServer.ChunkServer)

	if raw_input('you want to NewChunk ? ')=='y':
		arg2=msg.NewChunk_Request()
		arg2.size=32		
		arg2.count=2
		ret2=stub2.callMethod('NewChunk', arg2)
		print ret2.guids

	if raw_input('you want to assembleVolume ? ')=='y':
		req_assemble = msg.AssembleVolume_Request()
		req_assemble.volume.size = 32
		Guid.assign(req_assemble.volume.guid,ret2.guids[-1])
		res_assemble = stub2.callMethod('AssembleVolume', req_assemble)
		print 'access_point:', res_assemble.access_point

	if raw_input('you want to DisassembleVolume ? ')=='y':
		req_disassemble = msg.DisassembleVolume_Request()
		req_disassemble.access_point = res_assemble.access_point
		print 'req_disassemble.access_point:', req_disassemble.access_point
		stub2.callMethod('DisassembleVolume', req_disassemble)

	if raw_input('you want to DeleteChunk ? ')=='y':
		arg3=msg.DeleteChunk_Request()
		t = arg3.guids.add()
		Guid.assign(t, ret2.guids[0])
		t = arg3.guids.add()
		Guid.assign(t, ret2.guids[1])
		ret_Del=stub2.callMethod('DeleteChunk', arg3)
Beispiel #6
0
import rpc, logging
import messages_pb2 as msg
import client_messages_pb2 as clmsg
import mds, ChkSvr_mock
import gevent.socket
from Client_test import Client
import guid as Guid
import scandev
import block.dm as dm

logging.basicConfig(level=logging.DEBUG)

socket = gevent.socket.socket()
socket.connect(('192.168.0.12', 6767))

guid = msg.Guid()
guid.a = 10
guid.b = 22
guid.c = 30
guid.d = 40
MI = {}
req = getattr(clmsg, 'NewVolume_Request', None)
res = getattr(clmsg, 'NewVolume_Response', type(None))
MI['NewVolume'] = (req, res)
req = getattr(clmsg, 'DeleteVolume_Request', None)
res = getattr(clmsg, 'DeleteVolume_Response', type(None))
MI['DeleteVolume'] = (req, res)
print MI
stub = rpc.RpcStub(guid, socket, Client, MI)
arg = clmsg.NewVolume_Request()
arg.volume_name = 'ssVolume2'
Beispiel #7
0
import rpc, logging
import messages_pb2 as msg
import mds_mock
import gevent.socket

MDS_IP = '192.168.0.149'
MDS_PORT = 6789

logging.basicConfig(level=logging.DEBUG)

socket = gevent.socket.socket()
socket.connect((MDS_IP, MDS_PORT))

# guid=msg.Guid()
# guid.a=10
# guid.b=22
# guid.c=30
# guid.d=40
# stub=rpc.RpcStub(guid, socket, mds_mock.MDS)

# arg=msg.NewChunk_Request()
# arg.size=32
# arg.count=1
# ret=stub.callMethod('NewChunk', arg)
# print ret

# arg=msg.DeleteChunk_Request()
# arg.guids.add()
# x=arg.guids[0]
# x.a=10
# x.b=10
Beispiel #8
0
import rpc, logging
import messages_pb2 as msg
import client_messages_pb2 as clmsg
import mds, ChkSvr_mock
import gevent.socket
from Client_test import Client
import guid as Guid
import scandev
import block.dm as dm

logging.basicConfig(level=logging.DEBUG)

socket=gevent.socket.socket()
socket.connect(('192.168.0.12', 6767))


guid=msg.Guid()
guid.a=10
guid.b=22
guid.c=30
guid.d=40
MI = {}
req = getattr(clmsg, 'NewVolume_Request', None)
res = getattr(clmsg, 'NewVolume_Response', type(None))
MI['NewVolume'] = (req, res)
req = getattr(clmsg, 'DeleteVolume_Request', None)
res = getattr(clmsg, 'DeleteVolume_Response', type(None))
MI['DeleteVolume'] = (req, res)
print MI
stub=rpc.RpcStub(guid, socket, Client, MI)
arg = clmsg.NewVolume_Request()
Beispiel #9
0
import rpc, logging
import messages_pb2 as msg
import mds_mock
import gevent.socket


MDS_IP = '192.168.0.149'
MDS_PORT = 6789

logging.basicConfig(level=logging.DEBUG)

socket=gevent.socket.socket()
socket.connect((MDS_IP, MDS_PORT))


# guid=msg.Guid()
# guid.a=10
# guid.b=22
# guid.c=30
# guid.d=40
# stub=rpc.RpcStub(guid, socket, mds_mock.MDS)

# arg=msg.NewChunk_Request()
# arg.size=32
# arg.count=1
# ret=stub.callMethod('NewChunk', arg)
# print ret

# arg=msg.DeleteChunk_Request()
# arg.guids.add()
# x=arg.guids[0]