Search in sources :

Example 56 with Validate

use of org.folio.rest.annotations.Validate in project raml-module-builder by folio-org.

the class AdminAPI method getAdminSlowQueries.

@Validate
@Override
public void getAdminSlowQueries(int querytimerunning, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * the queries returned are of this backend's most recent query. If state is active this field shows the currently
     * executing query. In all other states, it shows the last query that was executed.
     */
    PostgresClient.getInstance(vertxContext.owner()).select("SELECT EXTRACT(EPOCH FROM now() - query_start) as runtime, client_addr, usename, datname, state, query " + "FROM  pg_stat_activity " + "WHERE now() - query_start > '" + querytimerunning + " seconds'::interval " + "ORDER BY runtime DESC;", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminSlowQueriesResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 57 with Validate

use of org.folio.rest.annotations.Validate in project raml-module-builder by folio-org.

the class AdminAPI method getAdminListLockingQueries.

@Validate
@Override
public void getAdminListLockingQueries(String dbname, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner()).select("SELECT blockedq.pid AS blocked_pid, blockedq.query as blocked_query, " + "blockingq.pid AS blocking_pid, blockingq.query as blocking_query FROM pg_catalog.pg_locks blocked " + "JOIN pg_stat_activity blockedq ON blocked.pid = blockedq.pid " + "JOIN pg_catalog.pg_locks blocking ON (blocking.transactionid=blocked.transactionid AND blocked.pid != blocking.pid) " + "JOIN pg_stat_activity blockingq ON blocking.pid = blockingq.pid " + "WHERE NOT blocked.granted AND blockingq.datname='" + dbname + "';", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getResults());
            System.out.println("locking q -> " + new io.vertx.core.json.JsonArray(reply.result().getResults()).encode());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminListLockingQueriesResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 58 with Validate

use of org.folio.rest.annotations.Validate in project raml-module-builder by folio-org.

the class AdminAPI method getAdminTotalDbSize.

@Validate
@Override
public void getAdminTotalDbSize(String dbname, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner()).select("select pg_size_pretty(pg_database_size('" + dbname + "')) as db_size", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminTotalDbSizeResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 59 with Validate

use of org.folio.rest.annotations.Validate in project raml-module-builder by folio-org.

the class AdminAPI method getAdminPostgresTableSize.

@Validate
@Override
public void getAdminPostgresTableSize(String dbname, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    PostgresClient.getInstance(vertxContext.owner()).select("SELECT relname as \"Table\", pg_size_pretty(pg_relation_size(relid)) As \" Table Size\"," + " pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as \"Index Size\"" + " FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;", reply -> {
        if (reply.succeeded()) {
            OutStream stream = new OutStream();
            stream.setData(reply.result().getRows());
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminPostgresTableAccessStatsResponse.withJsonOK(stream)));
        } else {
            log.error(reply.cause().getMessage(), reply.cause());
            asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 60 with Validate

use of org.folio.rest.annotations.Validate in project raml-module-builder by folio-org.

the class AdminAPI method postAdminUploadmultipart.

@Validate
@Override
public void postAdminUploadmultipart(PersistMethod persistMethod, String busAddress, String fileName, MimeMultipart entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    if (entity != null) {
        int parts = entity.getCount();
        for (int i = 0; i < parts; i++) {
            BodyPart bp = entity.getBodyPart(i);
            System.out.println(bp.getFileName());
        // System.out.println(bp.getContent());
        // System.out.println("-----------------------------------------");
        }
        String name = "";
        try {
            if (fileName == null) {
                name = entity.getBodyPart(0).getFileName();
            } else {
                name = fileName;
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminUploadmultipartResponse.withOK("TODO")));
}
Also used : BodyPart(javax.mail.BodyPart) Validate(org.folio.rest.annotations.Validate)

Aggregations

Validate (org.folio.rest.annotations.Validate)66 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)42 CQLParseException (org.z3950.zing.cql.CQLParseException)32 List (java.util.List)27 OutStream (org.folio.rest.tools.utils.OutStream)27 Criteria (org.folio.rest.persist.Criteria.Criteria)16 Criterion (org.folio.rest.persist.Criteria.Criterion)16 PostgresClient (org.folio.rest.persist.PostgresClient)16 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)13 JsonObject (io.vertx.core.json.JsonObject)4 Map (java.util.Map)4 Response (javax.ws.rs.core.Response)4 TenantTool (org.folio.rest.tools.utils.TenantTool)4 InputStream (java.io.InputStream)3 BodyPart (javax.mail.BodyPart)3 io.vertx.core (io.vertx.core)2 AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Handler (io.vertx.core.Handler)2 Logger (io.vertx.core.logging.Logger)2