Esempio n. 1
0
    def set_mx_data(self):

        src_ = net.choose_not_local(self.source_pub_addresses)[:1]
        if not src_:
            src_ = net.choose_local(self.source_pub_addresses, ip=True)[:1]
        src = src_[0]
        src = src[6:].split(':')[0]

        if src == socket.gethostname():
            sock = self.ctx.socket(zmq.REP)
            port = str(sock.bind_to_random_port("tcp://127.0.0.1",
                                                min_port=settings.PORT_RANGE[0],
                                                max_port=settings.PORT_RANGE[1]))
            sock.close()
            return ('0.0.0.0', port), ""  # empty passwd
        else:
            return None, None
Esempio n. 2
0
    def set_mx_data(self):

        src_ = net.choose_not_local(self.source_pub_addresses)[:1]
        if not src_:
            src_ = net.choose_local(self.source_pub_addresses, ip=True)[:1]
        src = src_[0]
        src = src[6:].split(':')[0]

        if src == socket.gethostname():
            sock = self.ctx.socket(zmq.REP)
            port = str(sock.bind_to_random_port("tcp://127.0.0.1",
                                            min_port=settings.PORT_RANGE[0],
                                            max_port=settings.PORT_RANGE[1]))
            sock.close()
            return ('0.0.0.0', port), "" #empty passwd
        else:
            return None, None
Esempio n. 3
0
    def net_init(self):
        self.source_sub_socket = self.ctx.socket(zmq.SUB)
        self.source_sub_socket.setsockopt(zmq.SUBSCRIBE, "")

        self._all_sockets.append(self.source_sub_socket)

        if self.source_pub_addresses:
            for addr in self.source_pub_addresses:
                self.source_sub_socket.connect(addr)

        (self.config_server_socket, self.cs_addresses) = self._init_socket([], zmq.PULL)
        # self.config_server_socket.setsockopt(zmq.SUBSCRIBE, "")

        self.cs_addr = net.choose_not_local(self.cs_addresses)
        if not self.cs_addr:
            self.cs_addr = net.choose_local(self.cs_addresses)[0]
        else:
            self.cs_addr = self.cs_addr[0]

        self._all_sockets.append(self.config_server_socket)

        super(OBCIProcessSupervisor, self).net_init()
Esempio n. 4
0
    def net_init(self):
        self.source_sub_socket = self.ctx.socket(zmq.SUB)
        self.source_sub_socket.setsockopt(zmq.SUBSCRIBE, "")

        self._all_sockets.append(self.source_sub_socket)

        if self.source_pub_addresses:
            for addr in self.source_pub_addresses:
                self.source_sub_socket.connect(addr)

        (self.config_server_socket, self.cs_addresses) = self._init_socket([], zmq.PULL)
        # self.config_server_socket.setsockopt(zmq.SUBSCRIBE, "")

        self.cs_addr = net.choose_local(self.cs_addresses)
        if not self.cs_addr:
            self.cs_addr = net.choose_not_local(self.cs_addresses)[0]
        else:
            self.cs_addr = self.cs_addr[0]

        self._all_sockets.append(self.config_server_socket)

        super(OBCIProcessSupervisor, self).net_init()
Esempio n. 5
0
    def _info_amplified(self, exp_desc):
        amp_options = []
        LOGGER.info("Processing experiment " + str(exp_desc['name']) +
                    "w/ addr: " + str(exp_desc['rep_addrs']))
        tcp_addrs = exp_desc['tcp_addrs']
        rep_addrs = net.choose_not_local(exp_desc['rep_addrs'])

        if not rep_addrs:
            rep_addrs = net.choose_local(exp_desc['rep_addrs'], ip=True)

        rep_addr = rep_addrs.pop()

        pub_addrs = net.choose_not_local(exp_desc['pub_addrs'])
        if not pub_addrs:
            pub_addrs = net.choose_local(exp_desc['pub_addrs'], ip=True)
        pub_addr = pub_addrs.pop()
        tcp_addr = tcp_addrs.pop()

        LOGGER.info("Chosen experiment addresses: REP -- " +
                    str(rep_addr) + ", PUB -- " + str(pub_addr))

        req_sock = self.ctx.socket(zmq.REQ)
        try:
            req_sock.connect(rep_addr)

            send_msg(req_sock, self.mtool.fill_msg('get_experiment_info'))
            res, details = self.poll_recv(req_sock, 4000)
        finally:
            req_sock.close()

        if not res:
            LOGGER.error("Connection failed (experiment " + exp_desc['name'] +
                         "), get_experiment_info")
            return None
        exp_info = res.dict()  # json.loads(res)
        for field in ["peers_status", "details"]:
            del exp_info["experiment_status"][field]

        peer_list = exp_info["peers"]
        if not self._has_mx(peer_list):
            LOGGER.info("Experiment " + exp_desc['name'] +
                        " does not have a multiplexer.")
            return None

        maybe_amps = self._amp_like_peers(peer_list)
        if not maybe_amps:
            LOGGER.info("Experiment " + exp_desc['name'] +
                        " -- no amplifier.")
            return None

        req_sock = self.ctx.socket(zmq.REQ)
        try:
            req_sock.connect(rep_addr)
            for peer in maybe_amps:
                info, params = self._get_amp_info(req_sock, peer)
                if not self._is_amplifier(info, params):
                    LOGGER.info("Experiment " + exp_desc['name'] +
                                " -- peer " + str(peer) + "is not an amplifier.")
                    continue
                else:
                    exp_data = self._create_exp_data(exp_info, info, params['param_values'],
                                                     rep_addr, pub_addr, tcp_addr)
                    amp_options.append(exp_data)
        finally:
            req_sock.close()

        return amp_options
Esempio n. 6
0
    def _info_amplified(self, exp_desc):
        amp_options = []
        LOGGER.info("Processing experiment "+ str(exp_desc['name']) +\
                                     "w/ addr: " + str(exp_desc['rep_addrs']))
        tcp_addrs = exp_desc['tcp_addrs']
        rep_addrs = net.choose_not_local(exp_desc['rep_addrs'])

        if not rep_addrs:
            rep_addrs = net.choose_local(exp_desc['rep_addrs'], ip=True)

        rep_addr = rep_addrs.pop()

        pub_addrs = net.choose_not_local(exp_desc['pub_addrs'])
        if not pub_addrs:
            pub_addrs = net.choose_local(exp_desc['pub_addrs'], ip=True)
        pub_addr = pub_addrs.pop()
        tcp_addr = tcp_addrs.pop()

        LOGGER.info("Chosen experiment addresses: REP -- " + \
                                str(rep_addr) + ", PUB -- " + str(pub_addr))

        req_sock = self.ctx.socket(zmq.REQ)
        try:
            req_sock.connect(rep_addr)

            send_msg(req_sock, self.mtool.fill_msg('get_experiment_info'))
            res, details = self.poll_recv(req_sock, 4000)
        finally:
            req_sock.close()

        if not res:
            LOGGER.error("Connection failed (experiment " + exp_desc['name'] + \
                                                    "), get_experiment_info")
            return None
        exp_info = res.dict()  #json.loads(res)
        for field in ["peers_status", "details"]:
            del exp_info["experiment_status"][field]

        peer_list = exp_info["peers"]
        if not self._has_mx(peer_list):
            LOGGER.info("Experiment " + exp_desc['name'] + \
                                                " does not have a multiplexer.")
            return None

        maybe_amps = self._amp_like_peers(peer_list)
        if not maybe_amps:
            LOGGER.info("Experiment "+ exp_desc['name'] + \
                                                " -- no amplifier.")
            return None

        req_sock = self.ctx.socket(zmq.REQ)
        try:
            req_sock.connect(rep_addr)
            for peer in maybe_amps:
                info, params = self._get_amp_info(req_sock, peer)
                if not self._is_amplifier(info, params):
                    LOGGER.info("Experiment "+ exp_desc['name'] + \
                                    " -- peer " + str(peer) + "is not an amplifier.")
                    continue
                else:
                    exp_data = self._create_exp_data(exp_info, info,
                                                     params['param_values'],
                                                     rep_addr, pub_addr,
                                                     tcp_addr)
                    amp_options.append(exp_data)
        finally:
            req_sock.close()

        return amp_options