Пример #1
0
def get_container_create_event(cpus,
                               workload_type=STATIC,
                               name=str(uuid.uuid4()).replace("-", ""),
                               id=str(uuid.uuid4()).replace("-", "")):
    attributes = {NAME: name, WORKLOAD_TYPE_LABEL_KEY: workload_type}
    MOCK_TITUS_ENVIRONMENT.add_workload(
        LegacyWorkload(
            launch_time=int(time.time()),
            identifier=name,
            thread_count=cpus,
            job_id=DEFAULT_TEST_JOB_ID,
            mem=DEFAULT_TEST_MEM,
            disk=DEFAULT_TEST_DISK,
            network=DEFAULT_TEST_NETWORK,
            app_name=DEFAULT_TEST_APP_NAME,
            owner_email=DEFAULT_TEST_OWNER_EMAIL,
            image=DEFAULT_TEST_IMAGE,
            command=DEFAULT_TEST_CMD,
            entrypoint=DEFAULT_TEST_ENTRYPOINT,
            job_type=DEFAULT_TEST_JOB_TYPE,
            workload_type=workload_type,
            opportunistic_thread_count=DEFAULT_TEST_OPPORTUNISTIC_THREAD_COUNT,
            duration_predictions=[]))

    return get_event(CONTAINER, START, id, attributes)
Пример #2
0
def get_test_opportunistic_workload(identifier, thread_count, opportunistic_thread_count, workload_type) -> Workload:
    return LegacyWorkload(
        launch_time=int(time.time()),
        identifier=identifier,
        thread_count=thread_count,
        mem=DEFAULT_TEST_MEM,
        disk=DEFAULT_TEST_DISK,
        network=DEFAULT_TEST_NETWORK,
        app_name=DEFAULT_TEST_APP_NAME,
        owner_email=DEFAULT_TEST_OWNER_EMAIL,
        image=DEFAULT_TEST_IMAGE,
        command=DEFAULT_TEST_CMD,
        entrypoint=DEFAULT_TEST_ENTRYPOINT,
        job_type=DEFAULT_TEST_JOB_TYPE,
        workload_type=workload_type,
        opportunistic_thread_count=opportunistic_thread_count,
        duration_predictions=[])
Пример #3
0
def get_test_workload(identifier,
                      thread_count,
                      workload_type,
                      launch_time=None) -> Workload:
    if launch_time is None:
        launch_time = int(time.time())

    return LegacyWorkload(
        launch_time=launch_time,
        identifier=identifier,
        thread_count=thread_count,
        job_id=DEFAULT_TEST_JOB_ID,
        mem=DEFAULT_TEST_MEM,
        disk=DEFAULT_TEST_DISK,
        network=DEFAULT_TEST_NETWORK,
        app_name=DEFAULT_TEST_APP_NAME,
        owner_email=DEFAULT_TEST_OWNER_EMAIL,
        image=DEFAULT_TEST_IMAGE,
        command=DEFAULT_TEST_CMD,
        entrypoint=DEFAULT_TEST_ENTRYPOINT,
        job_type=DEFAULT_TEST_JOB_TYPE,
        workload_type=workload_type,
        opportunistic_thread_count=DEFAULT_TEST_OPPORTUNISTIC_THREAD_COUNT,
        duration_predictions=[])
Пример #4
0
def get_workload_from_disk(identifier) -> LegacyWorkload:
    # In theory these files could go away if the task dies. that is ok.  A failure here will only result in the workload
    # not being created which is fine because it is dead anyway.
    json_data = __get_workload_json(identifier)
    passthrough_data = json_data[WORKLOAD_JSON_PASSTHROUGH_KEY]
    env_data = __get_workload_env(
        identifier)  # note that this is string -> string

    launch_time = int(
        json_data[WORKLOAD_JSON_RUNSTATE_KEY][WORKLOAD_JSON_LAUNCHTIME_KEY])
    cpus = int(env_data[WORKLOAD_ENV_CPU_KEY])
    mem = int(env_data[WORKLOAD_ENV_MEM_KEY])
    disk = int(env_data[WORKLOAD_ENV_DISK_KEY])
    network = int(env_data[WORKLOAD_ENV_NETWORK_KEY])
    app_name = json_data[WORKLOAD_JSON_APP_NAME_KEY]
    owner_email = passthrough_data[WORKLOAD_JSON_OWNER_KEY]
    image = '{}@{}'.format(json_data[WORKLOAD_JSON_IMAGE_KEY],
                           json_data[WORKLOAD_JSON_IMAGE_DIGEST_KEY])
    job_id = env_data[WORKLOAD_ENV_JOB_ID]

    command = None
    if WORKLOAD_JSON_COMMAND_KEY in json_data[WORKLOAD_JSON_PROCESS_KEY]:
        command = json_data[WORKLOAD_JSON_PROCESS_KEY][
            WORKLOAD_JSON_COMMAND_KEY]

    entrypoint = None
    if WORKLOAD_JSON_ENTRYPOINT_KEY in json_data[WORKLOAD_JSON_PROCESS_KEY]:
        entrypoint = json_data[WORKLOAD_JSON_PROCESS_KEY][
            WORKLOAD_JSON_ENTRYPOINT_KEY]

    job_type = passthrough_data[WORKLOAD_JSON_JOB_TYPE_KEY]

    workload_type = STATIC
    if json_data[WORKLOAD_JSON_CPU_BURST_KEY]:
        workload_type = BURST

    opportunistic_cpus = 0
    if FENZO_WORKLOAD_JSON_OPPORTUNISTIC_CPU_KEY in passthrough_data:
        opportunistic_cpus = passthrough_data[
            FENZO_WORKLOAD_JSON_OPPORTUNISTIC_CPU_KEY]

    duration_predictions = []
    if WORKLOAD_JSON_RUNTIME_PREDICTIONS_KEY in passthrough_data:
        duration_predictions = get_duration_predictions(
            passthrough_data[WORKLOAD_JSON_RUNTIME_PREDICTIONS_KEY])

    return LegacyWorkload(launch_time=launch_time,
                          identifier=identifier,
                          thread_count=cpus,
                          job_id=job_id,
                          mem=mem,
                          disk=disk,
                          network=network,
                          app_name=app_name,
                          owner_email=owner_email,
                          image=image,
                          command=command,
                          entrypoint=entrypoint,
                          job_type=job_type,
                          workload_type=workload_type,
                          opportunistic_thread_count=opportunistic_cpus,
                          duration_predictions=duration_predictions)