Esempio n. 1
0
 def __new__(class_, *args, **kwargs):
     global _client
     if not class_._client:
         config = load_config('config.yaml')['client']
         cluster = os.getenv('CLUSTER')
         if cluster is not None and cluster != 'local':
             cluster = os.getenv('CLUSTER')
             if os.getenv('ELECTION_ZK_SERVERS', ''):
                 zk_servers = os.getenv('ELECTION_ZK_SERVERS').split(":")[0]
             elif cluster in config['cluster_zk_servers']:
                 zk_servers = config['cluster_zk_servers'][cluster]
             else:
                 raise Exception('Unsupported cluster %s' % cluster)
             _client = PelotonClient(
                 name=config['name'],
                 zk_servers=zk_servers,
             )
         else:
             # TODO: remove url overrides once T839783 is resolved
             _client = PelotonClient(
                 name=config['name'],
                 jm_url=config['jobmgr_url'],
                 rm_url=config['resmgr_url'],
                 hm_url=config['hostmgr_url'],
             )
     return _client
Esempio n. 2
0
 def __new__(class_, *args, **kwargs):
     global _client
     if not class_._client:
         config = load_config("config.yaml")["client"]
         cluster = os.getenv("CLUSTER")
         use_apiserver = False
         if os.getenv("USE_APISERVER") == 'True':
             use_apiserver = True
         if cluster is not None and cluster != "local":
             cluster = os.getenv("CLUSTER")
             if os.getenv("ELECTION_ZK_SERVERS", ""):
                 zk_servers = os.getenv("ELECTION_ZK_SERVERS").split(":")[0]
             elif cluster in config["cluster_zk_servers"]:
                 zk_servers = config["cluster_zk_servers"][cluster]
             else:
                 raise Exception("Unsupported cluster %s" % cluster)
             _client = PelotonClient(
                 name=config["name"],
                 enable_apiserver=use_apiserver,
                 zk_servers=zk_servers,
             )
         else:
             # TODO: remove url overrides once T839783 is resolved
             _client = PelotonClient(
                 name=config["name"],
                 enable_apiserver=use_apiserver,
                 api_url=config["apiserver_url"],
                 jm_url=config["jobmgr_url"],
                 rm_url=config["resmgr_url"],
                 hm_url=config["hostmgr_url"],
             )
     return _client
Esempio n. 3
0
    def __init__(
            self,
            zk_servers,
            respool_path=None,
            auth_type='NOOP',
            auth_file=''):
        """
        :param zk_servers: dns address of the physical zk dns
        :type client: PelotonClient
        """
        self.zk_servers = zk_servers

        auth_config = AuthConfig()
        if auth_type == 'BASIC':
            auth_config.auth_type = AuthType.basic
            with open(auth_file, "r") as f:
                config = yaml.load(f, Loader=yaml.FullLoader)
                auth_config.data = config

        # Generate PelotonClient
        self.client = PelotonClient(
            name="peloton-client", zk_servers=zk_servers, auth=auth_config,
        )
        if not respool_path:
            return

        # Get resource pool id
        self.respool_id = self.lookup_pool(respool_path)
Esempio n. 4
0
    def __init__(self, zk_servers, respool_path=None):
        """
        :param zk_servers: dns address of the physical zk dns
        :type client: PelotonClient
        """
        self.zk_servers = zk_servers
        # Generate PelotonClient
        self.client = PelotonClient(name="peloton-client",
                                    zk_servers=zk_servers)
        if not respool_path:
            return

        # Get resource pool id
        self.respool_id = self.lookup_pool(respool_path)
Esempio n. 5
0
    def __init__(self, zk_server, agent_num, version):
        self.zk_server = zk_server
        self.agent_num = agent_num
        self.version = version

        self.m3_client = M3(application_identifier='vcluster-monitor',
                            emitter=DirectEmitter(),
                            environment='production',
                            default_tags={
                                'peloton_version': self.version,
                                'agent_num': str(self.agent_num),
                            })

        self.client = PelotonClient(
            name='peloton-client',
            zk_servers=zk_server,
        )
        self.respool_id = self.ensure_respool()
Esempio n. 6
0
    def __init__(self, zk_server, agent_num, version):
        self.zk_server = zk_server
        self.agent_num = agent_num
        self.version = version

        self.m3_client = M3(
            application_identifier="vcluster-monitor",
            emitter=DirectEmitter(),
            environment="production",
            default_tags={
                "peloton_version": self.version,
                "agent_num": str(self.agent_num),
            },
        )

        self.client = PelotonClient(
            name="peloton-client", zk_servers=zk_server
        )
        self.respool_id = self.ensure_respool()
Esempio n. 7
0
def create_respool_for_new_peloton(config,
                                   zk_server,
                                   agent_num,
                                   respool_name=RESPOOL_PATH):
    """
    Create A respool for a cluster according the cluster size
    type config: dict
    type zk_server: string
    type agent_num: int
    type respool_name: string
    rtype: string

    """
    client = PelotonClient(name='peloton-client', zk_servers=zk_server)

    # Respool size should be 90% of the cluster size
    # CPU, Memory and Disk values are the announced
    # resource value of every Mesos slave
    resource_config = config.get('mesos-slave').get('resource')

    respool_config = create_pool_config(
        name=respool_name,
        cpu=agent_num * resource_config.get('cpuLimit') * 0.9,
        memory=agent_num * resource_config.get('memLimitMb') * 0.9,
        disk=agent_num * resource_config.get('diskLimitMb') * 0.9,
    )

    request = respool.CreateRequest(config=respool_config, )
    resp = client.respool_svc.CreateResourcePool(
        request,
        metadata=client.resmgr_metadata,
        timeout=default_timeout,
    )
    if resp.HasField('error'):
        print_fail('Failed to create resource pool %s: %s' %
                   (respool_name, resp))
        raise Exception("Resource pool creation failed")
    print_okblue('Created resource pool %s' % respool_name)
    return resp.result.value
Esempio n. 8
0
 def get_peloton_client(self, name):
     return PelotonClient(name=name,
                          zk_servers=self.vcluster.virtual_zookeeper)