Exemple #1
0
def deleteModel(conn, metricId):
  """Delete the model by reseting model-specific attributes.
  This method will also make sure the data integrity is kept by removing any
  model related data when necessary, either at the model level or at the
  server/instance level

  :param conn: SQLAlchemy connection object
  :type conn: sqlalchemy.engine.Connection
  :param metricId: Metric uid
  """
  with conn.begin():
    # Save server name before deleting model
    # The server name is used later to delete server annotations if necessary
    serverRows = conn.execute((select([schema.metric.c.server])
                               .where(schema.metric.c.uid == metricId)))
    server = serverRows.scalar()

    # Defer actual deletion to htmengine deleteModel() implementation, which
    # will raise ObjectNotFound exception appropriately, terminating execution
    # of *this* function without prejudice.
    htmengineDeleteModel(conn, metricId)

    # When deleting the server's last model, also delete all annotations
    # associated with the server

    delete = (schema.annotation
              .delete()
              .where((schema.annotation.c.server == server) &
                     ~schema.annotation.c.server.in_(
                        select([schema.metric.c.server])
                        .where(schema.metric.c.server == server)
                        .where(schema.metric.c.status != 0))))
    conn.execute(delete)
Exemple #2
0
def deleteModel(conn, metricId):
    """Delete the model by reseting model-specific attributes.
  This method will also make sure the data integrity is kept by removing any
  model related data when necessary, either at the model level or at the
  server/instance level

  :param conn: SQLAlchemy connection object
  :type conn: sqlalchemy.engine.Connection
  :param metricId: Metric uid
  """
    with conn.begin():
        # Save server name before deleting model
        # The server name is used later to delete server annotations if necessary
        serverRows = conn.execute(
            (select([schema.metric.c.server
                     ]).where(schema.metric.c.uid == metricId)))
        server = serverRows.scalar()

        # Defer actual deletion to htmengine deleteModel() implementation, which
        # will raise ObjectNotFound exception appropriately, terminating execution
        # of *this* function without prejudice.
        htmengineDeleteModel(conn, metricId)

        # When deleting the server's last model, also delete all annotations
        # associated with the server

        delete = (
            schema.annotation  #pylint: disable=E1120
            .delete().where((schema.annotation.c.server == server)
                            & ~schema.annotation.c.server.in_(
                                select([schema.metric.c.server]).where(
                                    schema.metric.c.server == server).where(
                                        schema.metric.c.status != 0))))
        conn.execute(delete)