Ejemplo n.º 1
0
def list_resources(fabric):
    try:
        pinot_fabric = PinotFabric(config, logger, fabric)
    except PinotException as e:
        return jsonify(
            dict(success=False,
                 error_message='Failed getting fabric {0}'.format(e)))

    try:
        resources = pinot_fabric.get_resources()
    except PinotException as e:
        return jsonify(
            dict(success=False,
                 error_message='Failed getting fabric: {0}'.format(e)))

    try:
        zk = PinotZk(config, logger, fabric)
    except PinotException as e:
        return jsonify(
            dict(success=False,
                 error_message='Failed getting ZK: {0}'.format(e)))

    return jsonify(
        dict(success=True,
             clusters=resources,
             nodes=pinot_fabric.get_nodes(zk.get_handle())))
Ejemplo n.º 2
0
def create_tenant(fabric):
  try:
    pinot_fabric = PinotFabric(config, logger, fabric)
  except PinotException as e:
    return jsonify(dict(success=False, error_message='Failed getting fabric {0}'.format(e)))
  data = request.get_json(force=True)
  try:
    tenant_type = data['type']
    tenant_name = data['name']
    tenant_num_instances = data['num_instances']
  except KeyError:
    return jsonify(dict(success=False, error_message='Required fields missing'))

  if tenant_type not in ['broker', 'server']:
    return jsonify(dict(success=False, error_message='Tenant must be either server or broker'))

  if tenant_type == 'server':
    tenant_num_offline = data['num_offline']
    tenant_num_realtime = data['num_realtime']
    try:
      result = pinot_fabric.create_server_tenant(tenant_name, tenant_num_instances, tenant_num_offline, tenant_num_realtime)
    except PinotException as e:
      return jsonify(dict(success=False, error_message='Creating server tenant: {0}'.format(e)))
  elif tenant_type == 'broker':
    try:
      result = pinot_fabric.create_broker_tenant(tenant_name, tenant_num_instances)
    except PinotException as e:
      return jsonify(dict(success=False, error_message='Creating broker tenant: {0}'.format(e)))

  return jsonify(dict(success=result, error_message=''))
Ejemplo n.º 3
0
def send_pql(fabric):
  try:
    pinot_fabric = PinotFabric(config, logger, fabric)
  except PinotException as e:
    return jsonify(dict(success=False, error_message='Failed getting fabric {0}'.format(e)))

  pql = request.args.get('pql')

  try:
    return jsonify(dict(success=True, result=pinot_fabric.run_pql(pql)))
  except PinotException as e:
    return jsonify(dict(success=False, error_message='Failed running PQL: {0}'.format(e)))
Ejemplo n.º 4
0
def send_pql(fabric):
    try:
        pinot_fabric = PinotFabric(config, logger, fabric)
    except PinotException as e:
        return jsonify(
            dict(success=False,
                 error_message='Failed getting fabric {0}'.format(e)))

    pql = request.args.get('pql')

    try:
        return jsonify(dict(success=True, result=pinot_fabric.run_pql(pql)))
    except PinotException as e:
        return jsonify(
            dict(success=False,
                 error_message='Failed running PQL: {0}'.format(e)))
Ejemplo n.º 5
0
def list_resources(fabric):
  try:
    pinot_fabric = PinotFabric(config, logger, fabric)
  except PinotException as e:
    return jsonify(dict(success=False, error_message='Failed getting fabric {0}'.format(e)))

  try:
    resources = pinot_fabric.get_resources()
  except PinotException as e:
    return jsonify(dict(success=False, error_message='Failed getting fabric: {0}'.format(e)))

  try:
    zk = PinotZk(config, logger, fabric)
  except PinotException as e:
    return jsonify(dict(success=False, error_message='Failed getting ZK: {0}'.format(e)))

  return jsonify(dict(success=True, clusters=resources, nodes=pinot_fabric.get_nodes(zk.get_handle())))
Ejemplo n.º 6
0
  def get_nodes(self, zk):
    nodes_status = defaultdict(dict)
    pinot_fabric = PinotFabric(self.config, self.logger, self.fabric)
    for node in pinot_fabric.get_nodes(zk):
      match = False
      for tag in node['tags']:
        if tag.startswith(self.resource):
          match = True
          break
      if not match:
        continue
      instance_path = os.path.join(self.config.get_zk_root(self.fabric), 'LIVEINSTANCES', node['nodename'])
      host = node['host']
      nodes_status[host]['type'] = node['type']
      nodes_status[host]['helix_port'] = 0
      nodes_status[host]['online'] = zk.exists(instance_path)

    return nodes_status
Ejemplo n.º 7
0
def create_tenant(fabric):
    try:
        pinot_fabric = PinotFabric(config, logger, fabric)
    except PinotException as e:
        return jsonify(
            dict(success=False,
                 error_message='Failed getting fabric {0}'.format(e)))
    data = request.get_json(force=True)
    try:
        tenant_type = data['type']
        tenant_name = data['name']
        tenant_num_instances = data['num_instances']
    except KeyError:
        return jsonify(
            dict(success=False, error_message='Required fields missing'))

    if tenant_type not in ['broker', 'server']:
        return jsonify(
            dict(success=False,
                 error_message='Tenant must be either server or broker'))

    if tenant_type == 'server':
        tenant_num_offline = data['num_offline']
        tenant_num_realtime = data['num_realtime']
        try:
            result = pinot_fabric.create_server_tenant(tenant_name,
                                                       tenant_num_instances,
                                                       tenant_num_offline,
                                                       tenant_num_realtime)
        except PinotException as e:
            return jsonify(
                dict(success=False,
                     error_message='Creating server tenant: {0}'.format(e)))
    elif tenant_type == 'broker':
        try:
            result = pinot_fabric.create_broker_tenant(tenant_name,
                                                       tenant_num_instances)
        except PinotException as e:
            return jsonify(
                dict(success=False,
                     error_message='Creating broker tenant: {0}'.format(e)))

    return jsonify(dict(success=result, error_message=''))
Ejemplo n.º 8
0
    def get_nodes(self, zk):
        nodes_status = defaultdict(dict)
        pinot_fabric = PinotFabric(self.config, self.logger, self.fabric)
        for node in pinot_fabric.get_nodes(zk):
            match = False
            for tag in node['tags']:
                if tag.startswith(self.resource):
                    match = True
                    break
            if not match:
                continue
            instance_path = os.path.join(self.config.get_zk_root(self.fabric),
                                         'LIVEINSTANCES', node['nodename'])
            host = node['host']
            nodes_status[host]['type'] = node['type']
            nodes_status[host]['helix_port'] = 0
            nodes_status[host]['online'] = zk.exists(instance_path)

        return nodes_status