Esempio n. 1
0
def get_bi_db(config_dir=None):
    # require runner config
    if not config_dir: config_dir = sky_cfg.CONFIG_DIR
    runner_cfg = sky_cfg.SkyConfig.init_from_file('runner', config_dir=config_dir)

    # find service state before image object store
    service_state_bi_dir = runner_cfg.data['service_state']['bi_dir']
    service_state_bi_file = runner_cfg.data['service_state']['bi_file']

    # DECISION-TODO: push path creation into role so that path existence is guaranteed
    # idempotently make BI directory path if not exists
    mkdir_path(service_state_bi_dir)

    # prepare bi database file fullpath
    service_state_bi = os.path.join(service_state_bi_dir, service_state_bi_file)

    return service_state_bi
Esempio n. 2
0
def get_bi_db(config_dir=None):
    # require runner config
    if not config_dir: config_dir = sky_cfg.CONFIG_DIR
    runner_cfg = sky_cfg.SkyConfig.init_from_file('runner',
                                                  config_dir=config_dir)

    # find service state before image object store
    service_state_bi_dir = runner_cfg.data['service_state']['bi_dir']
    service_state_bi_file = runner_cfg.data['service_state']['bi_file']

    # DECISION-TODO: push path creation into role so that path existence is guaranteed
    # idempotently make BI directory path if not exists
    mkdir_path(service_state_bi_dir)

    # prepare bi database file fullpath
    service_state_bi = os.path.join(service_state_bi_dir,
                                    service_state_bi_file)

    return service_state_bi
Esempio n. 3
0
def write_service_state_record(planet_name, service_name, tag, registration, provider, stacks):

    from skybase.service.state import ServiceRegistryMetadata, ServiceRegistryBlueprint, ServiceRegistryLog

    # connect to database
    db = PlanetStateDb()

    # define record format as list of directory names based on deployment
    planetdb_basepath = os.path.join(
        db.db,
        planet_name,
        service_name,
        tag,
    )

    response = dict()

    # make unique service directory and write service information to files
    mkdir_path(planetdb_basepath)

    # write service metadata (manifest + artiball source)
    metadata_path = os.path.join(planetdb_basepath, ServiceRegistryMetadata.FILENAME)
    with open(metadata_path, 'w') as f:
        f.write(yaml.safe_dump(registration.get('metadata'), default_flow_style=False))

    # write original main deployment yaml contents as 'blueprint'
    blueprint_path = os.path.join(planetdb_basepath, ServiceRegistryBlueprint.FILENAME)
    with open(blueprint_path, 'w') as f:
        f.write(yaml.safe_dump(registration.get('blueprint'), default_flow_style=False))

    # write first log entry with deployment details
    log_path = os.path.join(planetdb_basepath, ServiceRegistryLog.FILENAME)

    with open(log_path, 'a') as service_log:

        # create planet state record for each stack in db
        for stack_name, stack_info in stacks.items():

            # create unique path
            planetdb_stack_path = os.path.join(planetdb_basepath, stack_name)

            # make unique stack directory
            mkdir_path(planetdb_stack_path)

            # create planet state DB record filename
            planetdb_record = os.path.join(
                planetdb_stack_path, db.resources
            )

            # template for cloud resource file contents
            cloud_resource = {
                'cloud': {
                    'provider': provider,
                }
            }

            # merge stack information into template
            cloud_resource['cloud'].update(stack_info)

            # write stack launch information to resource file
            with open(planetdb_record, 'w') as f:
                f.write(yaml.safe_dump(
                    cloud_resource,
                    default_flow_style=False))

            # planet state response points to file
            response[stack_name] = prepare_record_id(db.db, db.resources, planetdb_record)

            # write service log entry for stack deployment
            service_log.write('{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\n'.format(
                basic_timestamp(),
                'DEPLOY',
                service_name,
                registration.get('metadata', {}).get('app_version'),
                registration.get('metadata', {}).get('build_id'),
                tag,
                stack_info['name'],
                registration.get('metadata', {}).get('source_artiball')))

    return response