sqlalchemy.sqla_exc.SQLAlchemyError

Here are the examples of the python api sqlalchemy.sqla_exc.SQLAlchemyError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

Example 1

Project: solum Source File: default.py
Function: update_assembly
    def update_assembly(self, ctxt, assembly_id, data):
        try:
            objects.registry.Assembly.update_and_save(ctxt, assembly_id, data)
        except sqla_exc.SQLAlchemyError as ex:
            LOG.error("Failed to update assembly status, ID: %s" % assembly_id)
            LOG.exception(ex)

Example 2

Project: solum Source File: default.py
Function: update_image
    def update_image(self, ctxt, image_id, status, external_ref=None,
                     docker_image_name=None):
        to_update = {'status': status}
        if external_ref:
            to_update['external_ref'] = external_ref
        if docker_image_name:
            to_update['docker_image_name'] = docker_image_name
        try:
            objects.registry.Image.update_and_save(ctxt, image_id, to_update)
        except sqla_exc.SQLAlchemyError as ex:
            LOG.error("Failed to update image, ID: %s" % image_id)
            LOG.exception(ex)

Example 3

Project: solum Source File: heat.py
def update_assembly(ctxt, assembly_id, data):
    # Here we are updating the assembly synchronously (i.e. without
    # using the conductor). This is because when using the conductor latency
    # is introduced between the update call and when assembly's state is
    # actually updated in the database. This latency leads to concurrency
    # bugs within deployers' actions when multiple deployers are present
    # in the system.
    try:
        objects.registry.Assembly.update_and_save(ctxt, assembly_id, data)
    except sqla_exc.SQLAlchemyError as ex:
        LOG.error("Failed to update assembly status, ID: %s" % assembly_id)
        LOG.exception(ex)

    try:
        update_wf_and_app(ctxt, assembly_id, data)
    except Exception as ex:
        LOG.error("Failed to update workflow and app status for assembly: %s"
                  % assembly_id)
        LOG.exception(ex)

Example 4

Project: solum Source File: shell.py
def update_wf_and_app_status(ctxt, assembly_id, status):
    # Update workflow and app objects
    status_data = dict()
    status_data['status'] = status
    try:
        wf = objects.registry.Workflow.get_by_assembly_id(assembly_id)
        objects.registry.Workflow.update_and_save(ctxt, wf.id, status_data)
    except sqla_exc.SQLAlchemyError as ex:
        LOG.error("Failed to update workflow corresponding to assembly %s"
                  % assembly_id)
        LOG.exception(ex)

    if wf is not None:
        try:
            app = objects.registry.App.get_by_id(ctxt, wf.app_id)
            objects.registry.App.update_and_save(ctxt, app.id, status_data)
        except sqla_exc.SQLAlchemyError as ex:
            LOG.error("Failed to update app status and app URL: %s" % app.id)
            LOG.exception(ex)

Example 5

Project: solum Source File: default.py
    def build_job_update(self, ctxt, build_id, status, description,
                         created_image_id, docker_image_name, assembly_id):
        to_update = {'status': status,
                     'external_ref': created_image_id,
                     'docker_image_name': docker_image_name,
                     'description': str(description)}
        try:
            objects.registry.Image.update_and_save(ctxt, build_id, to_update)
        except sqla_exc.SQLAlchemyError as ex:
            LOG.error("Failed to update image, ID: %s" % build_id)
            LOG.exception(ex)

        # create the component if needed.
        if assembly_id is None:
            return
        try:
            assem = objects.registry.Assembly.get_by_id(ctxt,
                                                        assembly_id)
            if assem.status == ASSEMBLY_STATES.DELETING:
                return
            if not any([comp for comp in assem.components
                        if 'Image_Build' in comp.description]):
                comp_name = "Heat_Stack_for_%s" % assem.name
                stack_id = None
                if assem.heat_stack_component is not None:
                    stack_id = assem.heat_stack_component.heat_stack_id
                objects.registry.Component.assign_and_create(ctxt, assem,
                                                             comp_name,
                                                             'Image_Build',
                                                             'Image Build job',
                                                             created_image_id,
                                                             stack_id)
                # update reference to image in assembly
                assem_update = {'image_id': build_id}
                objects.registry.Assembly.update_and_save(ctxt,
                                                          assembly_id,
                                                          assem_update)
        except sqla_exc.IntegrityError:
            LOG.error("IntegrityError in creating Image_Build component,"
                      " assembly %s may be deleted" % assembly_id)

Example 6

Project: solum Source File: heat.py
def save_du_ref_for_scaling(ctxt, assembly_id, du=None):

    try:
        wf = objects.registry.Workflow.get_by_assembly_id(assembly_id)
    except sqla_exc.SQLAlchemyError as ex:
        LOG.error("Failed to get workflow corresponding "
                  "to assembly %s" % assembly_id)
        LOG.exception(ex)
        return

    if wf is not None:
        try:
            app = objects.registry.App.get_by_id(ctxt, wf.app_id)
            current_scale_config = app.scale_config
            if current_scale_config:
                current_config = current_scale_config[app.name]
                current_config['du'] = du
                current_scale_config[app.name] = current_config
                scale_config = dict()
                scale_config['scale_config'] = current_scale_config
                objects.registry.App.update_and_save(ctxt, app.id,
                                                     scale_config)
        except sqla_exc.SQLAlchemyError as ex:
            LOG.error("Failed to update app scale_config: %s" % app.id)
            LOG.exception(ex)

Example 7

Project: solum Source File: heat.py
def update_wf_and_app(ctxt, assembly_id, data):
    # Update workflow and app objects
    data_dict = dict()
    if data.get('status') is not None:
        data_dict['status'] = data['status']
    if data.get('application_uri') is not None:
        data_dict['app_url'] = data['application_uri']

    wf = None
    try:
        wf = objects.registry.Workflow.get_by_assembly_id(assembly_id)
        objects.registry.Workflow.update_and_save(ctxt, wf.id, data_dict)
    except sqla_exc.SQLAlchemyError as ex:
        LOG.error("Failed to update workflow corresponding to assembly %s"
                  % assembly_id)
        LOG.exception(ex)
    except exception.ResourceNotFound as ex:
        #  This happens  if plan (deprecated) was directly created
        LOG.error("Workflow not found for assembly %s" % assembly_id)
        LOG.exception(ex)

    if wf is not None:
        try:
            app = objects.registry.App.get_by_id(ctxt, wf.app_id)
            objects.registry.App.update_and_save(ctxt, app.id, data_dict)
        except sqla_exc.SQLAlchemyError as ex:
            LOG.error("Failed to update app status and app URL: %s" % app.id)
            LOG.exception(ex)