Ejemplo n.º 1
0
    def handle(self):

        # Let's prepare as much as we can upfront.
        sec_def = self.worker_store.basic_auth_get('admin.invoke').config
        channel = self.worker_store.get_channel_plain_http('admin.invoke.json')
        out = {}

        with closing(self.odb.session()) as session:
            for item in server_list(session, self.server.cluster_id, False):
                server_info = out.setdefault(item.name, {})
                server_info['cluster_name'] = item.cluster_name

                server_info['up_mod_date'] = item.up_mod_date.isoformat() if item.up_status == SERVER_UP_STATUS.RUNNING else None
                server_info['last_join_mod_date'] = item.last_join_mod_date.isoformat() if \
                    item.last_join_status == SERVER_JOIN_STATUS.ACCEPTED else None

                for name in 'id', 'name', 'bind_host', 'bind_port', 'last_join_status', 'last_join_mod_by', 'up_status':
                    server_info[name] = getattr(item, name)

                if item.up_status == SERVER_UP_STATUS.RUNNING:

                    client = AnyServiceInvoker(
                        'http://{}:{}'.format(item.bind_host, item.bind_port),
                        channel.url_path, (sec_def.username, sec_def.password))
                    response = client.invoke('zato.info.get-server-info')
                    if response.ok:
                        response = loads(response.inner.text)['zato_service_invoke_response']['response'].decode('base64')
                        response = loads(response)['response']
                        server_info['info'] = loads(response['info'])
                    else:
                        self.logger.warn(response)

        self.response.content_type = 'application/json'
        self.response.payload = dumps(out)
Ejemplo n.º 2
0
    def handle(self):

        # Let's prepare as much as we can upfront.
        sec_def = self.worker_store.basic_auth_get('admin.invoke').config
        channel = self.worker_store.get_channel_plain_http('admin.invoke.json')
        out = {}

        with closing(self.odb.session()) as session:
            for item in server_list(session, self.server.cluster_id, None, None, False):
                server_info = out.setdefault(item.name, {})
                server_info['cluster_name'] = item.cluster_name

                server_info['up_mod_date'] = item.up_mod_date.isoformat() if item.up_status == SERVER_UP_STATUS.RUNNING else None
                server_info['last_join_mod_date'] = item.last_join_mod_date.isoformat() if \
                    item.last_join_status == SERVER_JOIN_STATUS.ACCEPTED else None

                for name in 'id', 'name', 'bind_host', 'bind_port', 'last_join_status', 'last_join_mod_by', 'up_status':
                    server_info[name] = getattr(item, name)

                if item.up_status == SERVER_UP_STATUS.RUNNING:

                    client = AnyServiceInvoker(
                        'http://{}:{}'.format(item.bind_host, item.bind_port),
                        channel.url_path, (sec_def.username, sec_def.password))
                    response = client.invoke('zato.info.get-server-info')
                    if response.ok:
                        response = loads(response.inner.text)['zato_service_invoke_response']['response'].decode('base64')
                        response = loads(response)['response']
                        server_info['info'] = loads(response['info'])
                    else:
                        self.logger.warn(response)

        self.response.content_type = 'application/json'
        self.response.payload = dumps(out)
Ejemplo n.º 3
0
    def _add_server(self, address):

        # It must be server@cluster
        if '@' in address:
            server_name, cluster_name = address.split('@')
        else:
            server_name = address
            cluster_name = self.cluster_name

        with closing(self.odb.session()) as session:

            for item in server_list(session, None, cluster_name, False):
                if item.name == server_name and item.cluster_name == cluster_name:

                    for sec_item in self.odb.get_basic_auth_list(None, cluster_name):
                        if sec_item.name == sec_def_name:
                            return _RemoteServer(
                                item.cluster_id, self.cluster_name, item.name, item.preferred_address, item.bind_port,
                                item.crypto_use_tls, sec_item.password)

            else:
                msg = 'No such server or cluster {}@{}'.format(server_name, cluster_name)
                logger.warn(msg)
                raise ValueError(msg)

# ################################################################################################################################
Ejemplo n.º 4
0
    def _get_servers_from_odb(self, session, cluster_name=None):
        """ Returns a list of servers in ODB.
        """
        # Used by all servers
        invoke_sec_def = self._get_invoke_sec_def(session, cluster_name)

        for item in server_list(session, None, cluster_name, None, False):
            yield _RemoteServer(
                item.cluster_id, self.cluster_name, item.name, item.preferred_address, item.bind_port,
                item.crypto_use_tls, self.decrypt_func(invoke_sec_def.password), item.up_status)