def clusters_show(): request_debug(r, logger) show_type = r.args.get("type", "active") col_filter = dict((key, r.args.get(key)) for key in r.args if key != "col_name" and key != "page" and key != "type") if show_type != "released": col_name = r.args.get("col_name", "active") else: col_name = r.args.get("col_name", "released") if show_type == "inused": col_filter["user_id"] = {"$ne": ""} clusters = list(cluster_handler.list(filter_data=col_filter, col_name=col_name)) if show_type == "active": clusters.sort(key=lambda x: str(x["create_ts"]), reverse=True) elif show_type == "inused": clusters.sort(key=lambda x: str(x["apply_ts"]), reverse=True) else: clusters.sort(key=lambda x: str(x["release_ts"]), reverse=True) total_items = len(clusters) hosts = list(host_handler.list()) hosts_avail = list(filter(lambda e: e["status"] == "active" and len( e["clusters"]) < e["capacity"], hosts)) return render_template("clusters.html", type=show_type, col_name=col_name, items_count=total_items, items=clusters, hosts_available=hosts_avail, network_type=NETWORK_TYPES, consensus_plugins=CONSENSUS_PLUGINS_FABRIC_V1, consensus_modes=CONSENSUS_MODES, cluster_sizes=NETWORK_SIZE_FABRIC_V1)
def show(): request_debug(r, logger) hosts = list(host_handler.list(filter_data={})) hosts.sort(key=lambda x: x["name"], reverse=False) hosts_active = list(filter(lambda e: e["status"] == "active", hosts)) hosts_inactive = list(filter(lambda e: e["status"] != "active", hosts)) hosts_free = list( filter(lambda e: len(e["clusters"]) < e["capacity"], hosts_active)) hosts_available = hosts_free clusters_active = len(list(cluster_handler.list(col_name="active"))) clusters_released = len(list(cluster_handler.list(col_name="released"))) clusters_free = len( list( cluster_handler.list(filter_data={"user_id": ""}, col_name="active"))) clusters_inuse = clusters_active - clusters_free clusters_temp = len( list( cluster_handler.list(filter_data={"user_id": "/^__/"}, col_name="active"))) user_id, username, is_admin = \ str(current_user.id), current_user.username, current_user.isAdmin return render_template("index.html", hosts=hosts, hosts_free=hosts_free, hosts_active=hosts_active, hosts_inactive=hosts_inactive, hosts_available=hosts_available, clusters_active=clusters_active, clusters_released=clusters_released, clusters_free=clusters_free, clusters_inuse=clusters_inuse, clusters_temp=clusters_temp, cluster_sizes=NETWORK_SIZE_FABRIC_PRE_V1, network_type=NETWORK_TYPES, consensus_plugins=CONSENSUS_PLUGINS_FABRIC_V1, consensus_modes=CONSENSUS_MODES, host_types=WORKER_TYPES, log_types=CLUSTER_LOG_TYPES, log_levels=CLUSTER_LOG_LEVEL, username=username, user_id=user_id, is_admin=is_admin)
def clusters(self): """ Get clusters related statistic result :return: The stat result """ result = {'status': [], 'type': []} total_clusters = list(cluster_handler.list()) free_clusters = list(cluster_handler.list(filter_data={'user_id': ''})) total_number = len(total_clusters) free_clusters_number = len(free_clusters) result['status'] = [{ 'name': 'free', 'y': free_clusters_number }, { 'name': 'used', 'y': total_number - free_clusters_number }] for consensus_plugin in CONSENSUS_PLUGINS_FABRIC_V1: if consensus_plugin == CONSENSUS_PLUGINS_FABRIC_V1[0]: consensus_type = consensus_plugin clusters = list( cluster_handler.list( filter_data={'consensus_plugin': consensus_plugin})) result['type'].append({ 'name': consensus_type, 'y': len(clusters) }) else: for consensus_mode in CONSENSUS_MODES: consensus_type = consensus_plugin + "/" + consensus_mode clusters = list( cluster_handler.list( filter_data={ 'consensus_plugin': consensus_plugin, 'consensus_mode': consensus_mode })) result['type'].append({ 'name': consensus_type, 'y': len(clusters) }) return result
def show(): request_debug(r, logger) hosts = list(host_handler.list(filter_data={})) hosts.sort(key=lambda x: x["name"], reverse=False) hosts_active = list(filter(lambda e: e["status"] == "active", hosts)) hosts_inactive = list(filter(lambda e: e["status"] != "active", hosts)) hosts_free = list( filter(lambda e: len(e["clusters"]) < e["capacity"], hosts_active)) hosts_available = hosts_free clusters_active = len(list(cluster_handler.list(col_name="active"))) clusters_released = len(list(cluster_handler.list(col_name="released"))) clusters_free = len( list( cluster_handler.list(filter_data={"user_id": ""}, col_name="active"))) clusters_inuse = clusters_active - clusters_free clusters_temp = len( list( cluster_handler.list(filter_data={"user_id": "/^__/"}, col_name="active"))) return render_template( "index.html", hosts=hosts, hosts_free=hosts_free, hosts_active=hosts_active, hosts_inactive=hosts_inactive, hosts_available=hosts_available, clusters_active=clusters_active, clusters_released=clusters_released, clusters_free=clusters_free, clusters_inuse=clusters_inuse, clusters_temp=clusters_temp, cluster_sizes=CLUSTER_SIZES, fabric_version=FABRIC_VERSION, consensus_plugins=CONSENSUS_PLUGINS, consensus_modes=CONSENSUS_MODES, host_types=HOST_TYPES, log_types=CLUSTER_LOG_TYPES, log_levels=CLUSTER_LOG_LEVEL, )
def show(): request_debug(r, logger) hosts = list(host_handler.list(filter_data={})) hosts.sort(key=lambda x: x["name"], reverse=False) hosts_active = list(filter(lambda e: e["status"] == "active", hosts)) hosts_inactive = list(filter(lambda e: e["status"] != "active", hosts)) hosts_free = list(filter( lambda e: len(e["clusters"]) < e["capacity"], hosts_active)) hosts_available = hosts_free clusters_active = len(list(cluster_handler.list(col_name="active"))) clusters_released = len(list(cluster_handler.list(col_name="released"))) clusters_free = len(list(cluster_handler.list(filter_data={"user_id": ""}, col_name="active"))) clusters_inuse = clusters_active - clusters_free clusters_temp = len(list(cluster_handler.list(filter_data={ "user_id": "/^__/"}, col_name="active"))) username, is_admin = current_user.username, current_user.isAdmin return render_template("index.html", hosts=hosts, hosts_free=hosts_free, hosts_active=hosts_active, hosts_inactive=hosts_inactive, hosts_available=hosts_available, clusters_active=clusters_active, clusters_released=clusters_released, clusters_free=clusters_free, clusters_inuse=clusters_inuse, clusters_temp=clusters_temp, cluster_sizes=NETWORK_SIZE_FABRIC_PRE_V1, network_type=NETWORK_TYPES, consensus_plugins=CONSENSUS_PLUGINS_FABRIC_V1, consensus_modes=CONSENSUS_MODES, host_types=WORKER_TYPES, log_types=CLUSTER_LOG_TYPES, log_levels=CLUSTER_LOG_LEVEL, username=username, is_admin=is_admin )
def host_check_networks(host_id): """ Check the chain health on the host. :param host_id: :return: """ host = host_handler.get_by_id(host_id) logger.debug("Host {}/{}: checking chains".format(host.name, host_id)) clusters = cluster_handler.list(filter_data={"status": "running"}) for c in clusters: # concurrent health check is safe for multi-chains t = Thread(target=network_check_health, args=(c.get("id"), )) t.start() t.join(timeout=15)
def get(self): request_debug(r, logger) user = utils._get_user() user = user.dbUser user_id = str(user.id) args = cluster_list_parser.parse_args() page = args['pageNo'] per_page = args['pageSize'] result = cluster_handler.list(page_no=page, page_size=per_page, user=user) # result = cluster_handler.list(page_no=page, page_size=per_page, user_id=user_id) return make_ok_resp(data=result)
def clusters(self): """ Get clusters related statistic result :return: The stat result """ result = {'status': [], 'type': []} total_clusters = list(cluster_handler.list()) free_clusters = list(cluster_handler.list(filter_data={ 'user_id': ''})) total_number = len(total_clusters) free_clusters_number = len(free_clusters) result['status'] = [ {'name': 'free', 'y': free_clusters_number}, {'name': 'used', 'y': total_number - free_clusters_number} ] for consensus_plugin in CONSENSUS_PLUGINS: if consensus_plugin == CONSENSUS_PLUGINS[0]: consensus_type = consensus_plugin clusters = list(cluster_handler.list(filter_data={ 'consensus_plugin': consensus_plugin})) result['type'].append({ 'name': consensus_type, 'y': len(clusters) }) else: for consensus_mode in CONSENSUS_MODES: consensus_type = consensus_plugin + "/" + consensus_mode clusters = list(cluster_handler.list(filter_data={ 'consensus_plugin': consensus_plugin, 'consensus_mode': consensus_mode })) result['type'].append({ 'name': consensus_type, 'y': len(clusters) }) return result
def host_check_chains(host_id): """ Check the chain health on the host. :param host_id: :return: """ logger.debug("Host {}/{}: checking chains".format( host_handler.get_by_id(host_id).get('name'), host_id)) clusters = cluster_handler.list(filter_data={"host_id": host_id, "status": "running"}) for c in clusters: # concurrent health check is safe for multi-chains t = Thread(target=chain_check_health, args=(c.get("id"),)) t.start() t.join(timeout=15)
def cluster_list(): """ Return list of the clusters. """ request_debug(r, logger) user_id = request_get(r, "user_id") logger.warning("user_id={}".format(user_id)) if not user_id: logger.warning("cluster_list without user_id") response_fail["error"] = "No user_id is given" response_fail["data"] = r.args return jsonify(response_fail), CODE_BAD_REQUEST result = cluster_handler.list(filter_data={'user_id': user_id}) response_ok["data"] = result return jsonify(response_ok), CODE_OK
def cluster_list(): """List clusters with the filter e.g., GET /clusters?consensus_plugin=pbft Return objs of the clusters. """ request_debug(r, logger) f = {} if r.method == 'GET': f.update(r.args.to_dict()) elif r.method == 'POST': f.update(request_json_body(r)) logger.info(f) result = cluster_handler.list(filter_data=f) logger.error(result) return make_ok_resp(data=result)
def cluster_list(): """List clusters with the filter e.g., GET /clusters?consensus_plugin=pbft Return objs of the clusters. """ request_debug(r, logger) f = {} if r.method == 'GET': f.update(r.args.to_dict()) elif r.method == 'POST': f.update(request_json_body(r)) logger.info(f) result = cluster_handler.list(filter_data=f) logger.error(result) return make_ok_response(data=result)