예제 #1
0
def schedule_get_by_id(schedule_id):
    if schedule_id not in DATA['schedules']:
        raise exception.NotFound()
    schedule = copy.deepcopy(DATA['schedules'][schedule_id])
    schedule['schedule_metadata'] = \
        copy.deepcopy(schedule_meta_get_all(schedule_id))
    return schedule
예제 #2
0
def job_update(job_id, job_values):
    global DATA
    values = job_values.copy()
    if job_id not in DATA['jobs']:
        raise exception.NotFound()

    metadata = None
    if 'job_metadata' in values:
        metadata = values['job_metadata']
        del values['job_metadata']

    if len(values) > 0:
        job = DATA['jobs'][job_id]
        #NOTE(ameade): This must come before update specified values since
        # we may be trying to manually set updated_at
        job['updated_at'] = timeutils.utcnow()
        job['version_id'] = str(uuid.uuid4())
        job.update(values)

    if metadata is not None:
        DATA['job_metadata'][job_id] = {}
        for metadatum in metadata:
            job_meta_create(job_id, metadatum)

    return job_get_by_id(job_id)
예제 #3
0
def _check_job_meta_exists(job_id, key):

    if (DATA['job_metadata'].get(job_id) is None or
            DATA['job_metadata'][job_id].get(key) is None):
        msg = (_('Meta %(key)s could not be found for Job %(job_id)s ') %
               {'key': key, 'job_id': job_id})
        raise exception.NotFound(message=msg)
예제 #4
0
def _schedule_meta_get(schedule_id, key, session=None):
    session = session or get_session()
    try:
        _schedule_get_by_id(schedule_id, session)
    except exception.NotFound:
        msg = _('Schedule %s could not be found') % schedule_id
        raise exception.NotFound(message=msg)
    try:
        meta = session.query(models.ScheduleMetadata)\
                      .filter_by(schedule_id=schedule_id)\
                      .filter_by(key=key)\
                      .one()
    except sa_orm.exc.NoResultFound:
        raise exception.NotFound()

    return meta
예제 #5
0
def schedule_test_and_set_next_run(schedule_id, expected_next_run, next_run):
    global DATA

    schedule = DATA['schedules'].get(schedule_id)

    if not schedule:
        raise exception.NotFound()

    if expected_next_run:
        expected_next_run = expected_next_run.replace(tzinfo=None)
        current_next_run = schedule.get('next_run')
        if current_next_run:
            current_next_run = current_next_run.replace(tzinfo=None)
        if expected_next_run != current_next_run:
            raise exception.NotFound()
    if next_run:
        next_run = next_run.replace(tzinfo=None)
    schedule['next_run'] = next_run
예제 #6
0
def _check_meta_exists(schedule_id, key):
    _check_schedule_exists(schedule_id)

    if (DATA['schedule_metadata'].get(schedule_id) is None or
            DATA['schedule_metadata'][schedule_id].get(key) is None):
        msg = (_('Meta %(key)s could not be found '
                 'for Schedule %(schedule_id)s ') %
               {'key': key, 'schedule_id': schedule_id})
        raise exception.NotFound(message=msg)
예제 #7
0
def _job_meta_get_all_by_job_id(job_id):
    session = get_session()
    try:
        meta = session.query(models.JobMetadata)\
                      .filter_by(job_id=job_id)\
                      .all()
    except sa_orm.exc.NoResultFound:
        raise exception.NotFound()

    return meta
예제 #8
0
def job_get_by_id(job_id):
    if job_id not in DATA['jobs']:
        raise exception.NotFound()

    job = copy.deepcopy(DATA['jobs'][job_id])

    job['job_metadata'] = \
        job_meta_get_all_by_job_id(job_id)

    return job
예제 #9
0
def schedule_metadata_update(schedule_id, values):
    global DATA
    if DATA['schedules'].get(schedule_id) is None:
        msg = _('Schedule %s could not be found') % schedule_id
        raise exception.NotFound(message=msg)

    DATA['schedule_metadata'][schedule_id] = {}
    for metadatum in values:
        schedule_meta_create(schedule_id, metadatum)

    return copy.deepcopy(DATA['schedule_metadata'][schedule_id].values())
예제 #10
0
def _job_get_by_id(job_id, session=None):
    session = session or get_session()
    try:
        job = session.query(models.Job)\
                     .options(sa_orm.subqueryload('job_metadata'))\
                     .filter_by(id=job_id)\
                     .one()
    except sa_orm.exc.NoResultFound:
        raise exception.NotFound()

    return job
예제 #11
0
def _schedule_get_by_id(schedule_id, session=None):
    session = session or get_session()
    try:
        schedule = session.query(models.Schedule)\
                          .options(sa_orm.joinedload_all('schedule_metadata'))\
                          .filter_by(id=schedule_id)\
                          .one()
    except sa_orm.exc.NoResultFound:
        raise exception.NotFound()

    return schedule
예제 #12
0
def schedule_test_and_set_next_run(schedule_id, expected_next_run, next_run):
    session = get_session()
    if expected_next_run:
        query = session.query(models.Schedule).filter_by(id=schedule_id)\
                       .filter_by(next_run=expected_next_run)\
                       .update(dict(next_run=next_run))
    else:
        query = session.query(models.Schedule).filter_by(id=schedule_id)\
                       .update(dict(next_run=next_run))

    if not query:
        raise exception.NotFound()
예제 #13
0
def schedule_meta_create(schedule_id, values):
    global DATA
    if DATA['schedules'].get(schedule_id) is None:
        msg = _('Schedule %s could not be found') % schedule_id
        raise exception.NotFound(message=msg)

    _schedule_meta_init(schedule_id)

    try:
        _check_meta_exists(schedule_id, values['key'])
    except exception.NotFound:
        pass
    else:
        raise exception.Duplicate()

    meta = {}
    values['schedule_id'] = schedule_id
    meta.update(values)
    meta.update(_gen_base_attributes())
    DATA['schedule_metadata'][schedule_id][values['key']] = meta
    return copy.deepcopy(meta)
예제 #14
0
def schedule_update(schedule_id, schedule_values):
    global DATA
    values = schedule_values.copy()

    if schedule_id not in DATA['schedules']:
        raise exception.NotFound()

    metadata = None
    if 'schedule_metadata' in values:
        metadata = values['schedule_metadata']
        del values['schedule_metadata']

    if len(values) > 0:
        schedule = DATA['schedules'][schedule_id]
        schedule['updated_at'] = timeutils.utcnow()
        schedule.update(values)

    if metadata is not None:
        DATA['schedule_metadata'][schedule_id] = {}
        for metadatum in metadata:
            schedule_meta_create(schedule_id, metadatum)

    return schedule_get_by_id(schedule_id)
예제 #15
0
def _do_pagination(items, marker, limit):
    """
    This method mimics the behavior of sqlalchemy paginate_query.
    It takes items and pagination parameters - 'limit' and 'marker'
    to filter out the items to be returned. Items are sorted in
    lexicographical order based on the sort key - 'id'.
    """
    items = sorted(items, key=itemgetter('id'))
    start = 0
    end = -1
    if marker is None:
        start = 0
    else:
        for i, item in enumerate(items):
            if item['id'] == marker:
                start = i + 1
                break
        else:
            msg = _('Marker %s not found') % marker
            raise exception.NotFound(explanation=msg)

    end = start + limit if limit is not None else None
    return items[start:end]
예제 #16
0
def schedule_delete(schedule_id):
    global DATA
    if schedule_id not in DATA['schedules']:
        raise exception.NotFound()
    del DATA['schedules'][schedule_id]
예제 #17
0
def _check_job_exists(job_id):
    if not job_id in DATA['jobs']:
        msg = _('Job %s could not be found') % job_id
        raise exception.NotFound(message=msg)
예제 #18
0
def job_delete(job_id):
    global DATA
    if job_id not in DATA['jobs']:
        raise exception.NotFound()
    del DATA['jobs'][job_id]
예제 #19
0
def _check_schedule_exists(schedule_id):
    if DATA['schedules'].get(schedule_id) is None:
        msg = _('Schedule %s could not be found') % schedule_id
        raise exception.NotFound(message=msg)
예제 #20
0
def worker_get_by_id(worker_id):
    if worker_id not in DATA['workers']:
        raise exception.NotFound()
    return copy.deepcopy(DATA['workers'][worker_id])
예제 #21
0
def worker_delete(worker_id):
    global DATA
    if worker_id not in DATA['workers']:
        raise exception.NotFound()
    del DATA['workers'][worker_id]