コード例 #1
0
    def update(self, session_id, session_update_doc):
        # remove _version from the document
        session_update_doc.pop('_version', 0)
        update_doc = {"doc": session_update_doc}
        try:
            res = self.es.update(index=self.index,
                                 doc_type=self.doc_type,
                                 id=session_id,
                                 body=update_doc)
            version = res['_version']
            self.es.indices.refresh(index=self.index)
        except elasticsearch.TransportError as e:
            if e.status_code == 409:
                raise freezer_api_exc.DocumentExists(message=e.error)
            raise freezer_api_exc.DocumentNotFound(
                message=_i18n._('Unable to update session '
                                '%(id)s %(e)s') % {
                                    'id': session_id,
                                    'e': e
                                })

        except Exception:
            raise freezer_api_exc.StorageEngineError(
                message=_i18n._('Unable to update session with id %s') %
                session_id)
        return version
コード例 #2
0
ファイル: api.py プロジェクト: bopopescu/OpenStack-Stein
def add_backup(user_id, user_name, doc, project_id=None):
    if CONF.enable_v1_api:
        metadatadoc = utilsv1.BackupMetadataDoc(user_id, user_name, doc)
    else:
        metadatadoc = utilsv2.BackupMetadataDoc(project_id, user_id, user_name,
                                                doc)
    if not metadatadoc.is_valid():
        raise freezer_api_exc.BadDataFormat(message='Bad Data Format')
    backup_id = metadatadoc.backup_id
    backupjson = metadatadoc.serialize()
    backup_metadata = backupjson.get('backup_metadata')

    existing = get_backup(project_id=project_id,
                          user_id=user_id,
                          backup_id=backup_id)
    if existing:
        raise freezer_api_exc.DocumentExists(
            message='Backup already registered with ID'
            ' {0}'.format(backup_id))

    backup = models.Backup()
    backupvalue = {}
    backupvalue['project_id'] = project_id
    backupvalue['id'] = backup_id
    backupvalue['user_id'] = user_id
    backupvalue['user_name'] = user_name
    backupvalue['job_id'] = backup_metadata.get('job_id')
    # The field backup_metadata is json, including :
    # hostname , backup_name , container etc
    backupvalue['backup_metadata'] = json_utils.json_encode(backup_metadata)
    backup.update(backupvalue)

    add_tuple(tuple=backup)
    LOG.info('Backup registered, backup_id: {0}'.format(backup_id))
    return backup_id
コード例 #3
0
ファイル: api.py プロジェクト: bopopescu/OpenStack-Stein
def add_client(user_id, doc, project_id=None):
    if CONF.enable_v1_api:
        client_doc = utilsv1.ClientDoc.create(doc, user_id)
    else:
        client_doc = utilsv2.ClientDoc.create(doc, project_id, user_id)
    client_id = client_doc['client']['client_id']
    values = {}
    client_json = client_doc.get('client', {})

    existing = get_client(project_id=project_id,
                          user_id=user_id,
                          client_id=client_id)
    if existing:
        raise freezer_api_exc.DocumentExists(
            message='Client already registered with ID'
            ' {0}'.format(client_id))

    client = models.Client()
    values['project_id'] = project_id
    values['client_id'] = client_id
    values['id'] = client_json.get('uuid', None)
    values['user_id'] = user_id
    values['hostname'] = client_json.get('hostname', None)
    values['uuid'] = client_json.get('uuid', None)
    values['description'] = client_json.get('description', None)
    client.update(values)

    add_tuple(tuple=client)

    LOG.info('Client registered, client_id: {0}'.format(client_id))
    return client_id
コード例 #4
0
 def add_client(self, user_id, doc):
     client_doc = utils.ClientDoc.create(doc, user_id)
     client_id = client_doc['client']['client_id']
     existing = self.client_manager.search(user_id, client_id)
     if existing:
         raise freezer_api_exc.DocumentExists(
             message=_i18n._('Client already registered with ID %s') %
             client_id)
     self.client_manager.insert(client_doc)
     logging.info('Client registered, client_id: %s' % client_id)
     return client_id
コード例 #5
0
ファイル: simpledict.py プロジェクト: stannie42/freezer
 def add_backup(self, user_id, user_name, data):
     backup_metadata_doc = BackupMetadataDoc(user_id, user_name, data)
     if not backup_metadata_doc.is_valid():
         raise exceptions.BadDataFormat(message='Bad Data Format')
     backup_id = backup_metadata_doc.backup_id
     if (user_id, backup_id) in self._map:
         raise exceptions.DocumentExists(
             message='Backup data already existing ({0})'.format(backup_id),
             resp_body={'backup_id': backup_id})
     self._map[(user_id, backup_id)] = backup_metadata_doc.serialize()
     logging.info('Adding backup data with backup_id {0}'.format(backup_id))
     return backup_id
コード例 #6
0
 def add_client(self, project_id, user_id, doc):
     client_doc = utils.ClientDoc.create(doc, project_id, user_id)
     client_id = client_doc['client']['client_id']
     existing = self.client_manager.search(project_id=project_id,
                                           user_id=user_id,
                                           doc_id=client_id)
     if existing:
         raise freezer_api_exc.DocumentExists(
             message='Client already registered with ID'
             ' {0}'.format(client_id))
     self.client_manager.insert(client_doc)
     logging.info('Client registered, client_id: {0}'.format(client_id))
     return client_id
コード例 #7
0
 def insert(self, doc, doc_id=None):
     try:
         # remove _version from the document
         doc.pop('_version', None)
         res = self.es.index(index=self.index, doc_type=self.doc_type,
                             body=doc, id=doc_id)
         created = res['created']
         version = res['_version']
         self.es.indices.refresh(index=self.index)
     except elasticsearch.TransportError as e:
         if e.status_code == 409:
             raise freezer_api_exc.DocumentExists(message=e.error)
         raise freezer_api_exc.StorageEngineError(
             message=_i18n._('index operation failed %s') % e)
     except Exception as e:
         raise freezer_api_exc.StorageEngineError(
             message=_i18n._('index operation failed %s') % e)
     return (created, version)
コード例 #8
0
 def add_backup(self, user_id, user_name, data):
     # raises if data is malformed (HTTP_400) or already present (HTTP_409)
     backup_metadata_doc = BackupMetadataDoc(user_id, user_name, data)
     if not backup_metadata_doc.is_valid():
         raise exceptions.BadDataFormat(message='Bad Data Format')
     backup_id = backup_metadata_doc.backup_id
     existing_data = self._get_backup(user_id, backup_id)
     if existing_data:
         raise exceptions.DocumentExists(
             message='Backup data already existing ({0})'.format(backup_id),
             resp_body={'backup_id': backup_id})
     if not self._index(backup_metadata_doc.serialize()):
         # should never happen
         raise exceptions.StorageEngineError(
             message='index operation failed',
             resp_body={'backup_id': backup_id})
     logging.info('Backup metadata indexed, backup_id: {0}'.
                  format(backup_id))
     return backup_id
コード例 #9
0
ファイル: elasticv2.py プロジェクト: dara-t/freezer-api
 def update(self, job_id, job_update_doc):
     # remove _version from the document
     job_update_doc.pop('_version', 0)
     update_doc = {"doc": job_update_doc}
     try:
         res = self.es.update(index=self.index, doc_type=self.doc_type,
                              id=job_id, body=update_doc)
         version = res['_version']
         self.es.indices.refresh(index=self.index)
     except elasticsearch.TransportError as e:
         if e.status_code == 409:
             raise freezer_api_exc.DocumentExists(message=e.error)
         raise freezer_api_exc.DocumentNotFound(
             message='Unable to find job to update with id'
                     ' {0} {1}'.format(job_id, e))
     except Exception:
         raise freezer_api_exc.StorageEngineError(
             message='Unable to update job with id {0}'.format(job_id))
     return version
コード例 #10
0
ファイル: api.py プロジェクト: bopopescu/OpenStack-Stein
def add_session(user_id, doc, project_id=None):
    if CONF.enable_v1_api:
        session_doc = utilsv1.SessionDoc.create(doc=doc, user_id=user_id)
    else:
        session_doc = utilsv2.SessionDoc.create(doc=doc,
                                                user_id=user_id,
                                                project_id=project_id)
    session_id = session_doc['session_id']
    schedulingjson = session_doc.get('schedule')
    existing = get_session(project_id=project_id,
                           user_id=user_id,
                           session_id=session_id)
    if existing:
        raise freezer_api_exc.DocumentExists(
            message='Session already registered with ID'
            ' {0}'.format(session_id))

    sessiont = models.Session()
    sessionvalue = {}
    sessionvalue['project_id'] = project_id
    sessionvalue['id'] = session_id
    sessionvalue['user_id'] = user_id
    sessionvalue['description'] = session_doc.get('description', None)
    sessionvalue['hold_off'] = session_doc.get('hold_off', 30)
    sessionvalue['session_tag'] = session_doc.get('session_tag', 0)
    sessionvalue['status'] = session_doc.get('status')
    sessionvalue['time_ended'] = session_doc.get('time_ended', -1)
    sessionvalue['time_started'] = session_doc.get('time_started', -1)
    sessionvalue['time_end'] = session_doc.get('time_end', -1)
    sessionvalue['time_start'] = session_doc.get('time_start', -1)
    sessionvalue['result'] = session_doc.get('result', None)

    # The field scheduling is json
    sessionvalue['schedule'] = json_utils.json_encode(schedulingjson)
    sessiont.update(sessionvalue)

    add_tuple(tuple=sessiont)
    LOG.info('Session registered, session_id: {0}'.format(session_id))

    return session_id
コード例 #11
0
 def test_DocumentExists(self):
     e = exceptions.DocumentExists(message='testing')
     self.assertRaises(falcon.HTTPConflict, e.handle, self.ex,
                       self.mock_req, self.mock_req, None)
コード例 #12
0
ファイル: api.py プロジェクト: bopopescu/OpenStack-Stein
def add_action(user_id, doc, project_id=None):
    if CONF.enable_v1_api:
        action_doc = utilsv1.ActionDoc.create(doc, user_id)
    else:
        action_doc = utilsv2.ActionDoc.create(doc, user_id, project_id)

    keyt = [
        'action', 'backup_name', 'container', 'src_file', 'timeout',
        'priority', 'mandatory', 'log_file'
    ]
    freezer_action = action_doc.get('freezer_action', {})

    action_id = action_doc.get('action_id')
    existing = get_action(project_id=project_id,
                          user_id=user_id,
                          action_id=action_id)
    if existing:
        raise freezer_api_exc.DocumentExists(
            message='Action already registered with ID'
            ' {0}'.format(action_id))

    action = models.Action()

    actionvalue = {}
    actionreportvalue = {}
    actionvalue['project_id'] = project_id
    actionvalue['id'] = action_id
    actionvalue['user_id'] = user_id
    actionvalue['max_retries'] = action_doc.get('max_retries', 5)
    actionvalue['max_retries_interval'] = action_doc.\
        get('max_retries_interval', 6)
    actionvalue['actionmode'] = freezer_action.get('mode', None)

    for key in freezer_action.keys():
        if key in keyt:
            actionvalue[key] = freezer_action.get(key)

    actionreportvalue['result'] = freezer_action.get('result', None)
    actionreportvalue['time_elapsed'] = freezer_action.\
        get('time_elapsed', None)
    actionreportvalue['report_date'] = freezer_action.\
        get('report_date', None)
    actionvalue['backup_metadata'] = json_utils.json_encode(freezer_action)

    action.update(actionvalue)

    add_tuple(tuple=action)

    LOG.info('Action registered, action_id: {0}'.format(action_id))

    actionReport = models.ActionReport()

    actionreportvalue['project_id'] = project_id
    actionreportvalue['id'] = action_id
    actionreportvalue['user_id'] = user_id

    actionReport.update(actionreportvalue)

    add_tuple(tuple=actionReport)
    LOG.info('Action Reports registered, action_id: {0}'.format(action_id))
    return action_id