Example #1
0
    def ensure_exists(self):
        """
        creates a resource pool if it doesn't exist based on the config
        :return: resource pool ID
        """
        respool_name = self.config.respool_config.name
        request = respool.LookupRequest(
            path=respool.ResourcePoolPath(value=RESPOOL_ROOT + respool_name)
        )
        resp = self.client.respool_svc.LookupResourcePoolID(
            request,
            metadata=self.client.resmgr_metadata,
            timeout=self.config.rpc_timeout_sec,
        )
        if resp.id.value is None or resp.id.value == u"":
            request = respool.CreateRequest(config=self.config.respool_config)
            attempts = 0
            while attempts < self.config.max_retry_attempts:
                attempts += 1
                resp = self.client.respool_svc.CreateResourcePool(
                    request,
                    metadata=self.client.resmgr_metadata,
                    timeout=self.config.rpc_timeout_sec,
                )
                if resp.HasField("error"):
                    log.debug(
                        "failed to create respool %s (%s)",
                        respool_name,
                        resp.error,
                    )
                    time.sleep(self.config.sleep_time_sec)
                    continue
                break
            else:
                assert False, resp
            id = resp.result.value
            log.info("created respool %s (%s)", respool_name, id)
        else:
            id = resp.id.value
            log.info("found respool %s (%s)", respool_name, id)

        assert id
        self.id = id
        return self.id
Example #2
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
Example #3
0
    def ensure_exists(self):
        """
        creates a resource pool if it doesn't exist based on the config
        :return: resource pool ID
        """
        respool_name = self.config.respool_config.name
        request = respool.LookupRequest(
            path=respool.ResourcePoolPath(value=RESPOOL_ROOT + respool_name), )
        resp = self.client.respool_svc.LookupResourcePoolID(
            request,
            metadata=self.client.resmgr_metadata,
            timeout=self.config.rpc_timeout_sec,
        )
        if resp.id.value is None or resp.id.value == u'':
            request = respool.CreateRequest(
                config=self.config.respool_config, )
            deadline = time.time() + self.config.rpc_timeout_sec
            while time.time() < deadline:
                resp = self.client.respool_svc.CreateResourcePool(
                    request,
                    metadata=self.client.resmgr_metadata,
                    timeout=self.config.rpc_timeout_sec,
                )
                if resp.HasField('error'):
                    time.sleep(0.5)
                    continue
                break
            else:
                assert False, resp
            id = resp.result.value
            log.info('created respool %s (%s)', respool_name, id)
        else:
            id = resp.id.value
            log.info('found respool %s (%s)', respool_name, id)

        assert id
        self.id = id
        return self.id