Esempio n. 1
0
    def testCacheObjects(self):
        node1 = Node("testhost", 8080, 9090)
        node2 = Node("testhost", 8081, 9091)

        nodes = Nodes()
        nodes.addNode(node1)
        nodes.addNode(node2)

        Cache().add("network-topology", nodes)
        cachedNodes = Cache().get("network-topology")

        self.assertEquals(2, cachedNodes.size())
Esempio n. 2
0
    def run(self, serverState, request, response):
        conf = ServerConf()
        sentConnectRequests = conf.getSentNodeConnectRequests()
        node = json.loads(request.getParam('connectRequest'),
                          object_hook=json_serializer.fromJson)
        if (sentConnectRequests.exists(node.getId())):
            nodeToAdd = sentConnectRequests.get(node.getId())
            conf.addNode(
                Node(node.server_id, node.getClientSecurePort(),
                     node.getServerSecurePort(), node.getQualifiedName(),
                     nodeToAdd.getHostname()))
            #conf.addNode(nodeToAdd)
            openssl = OpenSSL(conf)
            openssl.addCa(node.key)
            sentConnectRequests.removeNode(node.getId())
            conf.set('sent_node_connect_requests', sentConnectRequests)
            # need to send back a status in the data notifying ok
            response.add('Connection to node %s established' % node.toString())

            log.info("Node connection accepted")
            #add it to the node list
        else:
            response.add('No previous node request sent for host %s' %
                         node.toString())

            log.info("Node connection not accepted")
Esempio n. 3
0
    def grant(key):  #key is server-id
        conf = ServerConf()
        nodeConnectRequests = conf.getNodeConnectRequests()

        if nodeConnectRequests.exists(key):
            nodeToAdd = nodeConnectRequests.get(
                key)  #this returns a nodeConnectRequest object

            serv = RawServerMessage(nodeToAdd.getHostname(),
                                    nodeToAdd.getClientSecurePort())

            #letting the requesting node know that it is accepted
            #also sending this servers connection parameters
            resp = serv.addNodeAccepted()

            conf.addNode(
                Node(nodeToAdd.server_id, nodeToAdd.getClientSecurePort(),
                     nodeToAdd.getServerSecurePort(),
                     nodeToAdd.getQualifiedName(), nodeToAdd.getHostname()))

            #trust the key
            openssl = OpenSSL(conf)
            openssl.addCa(nodeToAdd.key)

            nodeConnectRequests.removeNode(nodeToAdd.getId())
            conf.set('node_connect_requests', nodeConnectRequests)
            return True
        else:
            return False
Esempio n. 4
0
def fromJson(jsonObj):
    if 'class' in jsonObj:
        if jsonObj['class'] == 'Node':
            node = Node(jsonObj['server_id'],
                        int(jsonObj['client_secure_port']),
                        int(jsonObj['server_secure_port']),
                        jsonObj['qualified_name'], jsonObj['hostname'])
            if "nodes" in jsonObj:
                node.setNodes(jsonObj['nodes'])
            if "priority" in jsonObj:
                node.setPriority(jsonObj['priority'])
            if "workerStates" in jsonObj:
                node.workerStates = jsonObj['workerStates']
            return node

        if jsonObj['class'] == 'WorkerState':
            return WorkerState(jsonObj['host'], jsonObj['state'],
                               jsonObj['workerId'])

        if jsonObj['class'] == 'Nodes':
            nodes = Nodes()
            for node in jsonObj['nodes'].itervalues():
                nodes.addNode(node)
            return nodes

        if jsonObj['class'] == 'NodeConnectRequest':
            return NodeConnectRequest(jsonObj['server_id'],
                                      jsonObj['client_secure_port'],
                                      jsonObj['server_secure_port'],
                                      jsonObj['key'],
                                      jsonObj['qualified_name'],
                                      jsonObj['hostname'])
    return jsonObj