Esempio n. 1
0
def GetVC(userName, vcName):
    ret = None  

    clusterStatus, dummy = DataManager.GetClusterStatus()
    clusterTotalRes = ResourceInfo(clusterStatus["gpu_capacity"])
    clusterReservedRes = ResourceInfo(clusterStatus["gpu_unschedulable"])

    user_status = {}

    vcList =  DataManager.ListVCs()
    for vc in vcList:
        if vc["vcName"] == vcName and AuthorizationManager.HasAccess(userName, ResourceType.VC, vcName, Permission.User):
            vcTotalRes = ResourceInfo(json.loads(vc["quota"]))
            vcConsumedRes = ResourceInfo()
            jobs = DataManager.GetAllPendingJobs(vcName)
            for job in jobs:
                if job["jobStatus"] == "running":
                    username = job["userName"]
                    jobParam = json.loads(base64.b64decode(job["jobParams"]))
                    if "gpuType" in jobParam and not jobParam["preemptionAllowed"]:
                        vcConsumedRes.Add(ResourceInfo({jobParam["gpuType"] : GetJobTotalGpu(jobParam)}))
                        if username not in user_status:
                            user_status[username] = ResourceInfo()
                        user_status[username].Add(ResourceInfo({jobParam["gpuType"] : GetJobTotalGpu(jobParam)}))

            vcReservedRes = clusterReservedRes.GetFraction(vcTotalRes, clusterTotalRes)
            vcAvailableRes = ResourceInfo.Difference(ResourceInfo.Difference(vcTotalRes, vcConsumedRes), vcReservedRes)

            vc["gpu_capacity"] = vcTotalRes.ToSerializable()
            vc["gpu_used"] = vcConsumedRes.ToSerializable()
            vc["gpu_unschedulable"] = vcReservedRes.ToSerializable()
            vc["gpu_avaliable"] = vcAvailableRes.ToSerializable()
            vc["AvaliableJobNum"] = len(jobs)          
            vc["node_status"] = clusterStatus["node_status"]
            vc["user_status"] = []
            for user_name, user_gpu in user_status.iteritems():
                # TODO: job_manager.getAlias should be put in a util file
                user_name = user_name.split("@")[0].strip()
                vc["user_status"].append({"userName":user_name, "userGPU":user_gpu.ToSerializable()})

            ret = vc
            break
    return ret
Esempio n. 2
0
def GetClusterStatus():
    cluster_status,last_update_time =  DataManager.GetClusterStatus()
    return cluster_status,last_update_time