Search in sources :

Example 6 with CacheInfo

use of com.google.gerrit.server.config.ListCaches.CacheInfo in project gerrit by GerritCodeReview.

the class ShowCaches method run.

@Override
protected void run() throws UnloggedFailure {
    nw = columns - 50;
    Date now = new Date();
    stdout.format("%-25s %-20s      now  %16s\n", "Gerrit Code Review", Version.getVersion() != null ? Version.getVersion() : "", new SimpleDateFormat("HH:mm:ss   zzz").format(now));
    stdout.format("%-25s %-20s   uptime %16s\n", "", "", uptime(now.getTime() - serverStarted));
    stdout.print('\n');
    stdout.print(//
    String.format(//
    "%1s %-" + nw + "s|%-21s|  %-5s |%-9s|\n", //
    "", //
    "Name", //
    "Entries", //
    "AvgGet", //
    "Hit Ratio"));
    stdout.print(//
    String.format(//
    "%1s %-" + nw + "s|%6s %6s %7s|  %-5s  |%-4s %-4s|\n", //
    "", //
    "", //
    "Mem", //
    "Disk", //
    "Space", //
    "", //
    "Mem", //
    "Disk"));
    stdout.print("--");
    for (int i = 0; i < nw; i++) {
        stdout.print('-');
    }
    stdout.print("+---------------------+---------+---------+\n");
    Collection<CacheInfo> caches = getCaches();
    printMemoryCoreCaches(caches);
    printMemoryPluginCaches(caches);
    printDiskCaches(caches);
    stdout.print('\n');
    boolean showJvm;
    try {
        permissionBackend.user(self).check(GlobalPermission.MAINTAIN_SERVER);
        showJvm = true;
    } catch (AuthException | PermissionBackendException e) {
        // Silently ignore and do not display detailed JVM information.
        showJvm = false;
    }
    if (showJvm) {
        sshSummary();
        SummaryInfo summary = getSummary.setGc(gc).setJvm(showJVM).apply(new ConfigResource());
        taskSummary(summary.taskSummary);
        memSummary(summary.memSummary);
        threadSummary(summary.threadSummary);
        if (showJVM && summary.jvmSummary != null) {
            jvmSummary(summary.jvmSummary);
        }
    }
    stdout.flush();
}
Also used : AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CacheInfo(com.google.gerrit.server.config.ListCaches.CacheInfo) ThreadSummaryInfo(com.google.gerrit.server.config.GetSummary.ThreadSummaryInfo) JvmSummaryInfo(com.google.gerrit.server.config.GetSummary.JvmSummaryInfo) MemSummaryInfo(com.google.gerrit.server.config.GetSummary.MemSummaryInfo) TaskSummaryInfo(com.google.gerrit.server.config.GetSummary.TaskSummaryInfo) SummaryInfo(com.google.gerrit.server.config.GetSummary.SummaryInfo) ConfigResource(com.google.gerrit.server.config.ConfigResource)

Example 7 with CacheInfo

use of com.google.gerrit.server.config.ListCaches.CacheInfo in project gerrit by GerritCodeReview.

the class GetCacheIT method getCache.

@Test
public void getCache() throws Exception {
    RestResponse r = adminRestSession.get("/config/server/caches/accounts");
    r.assertOK();
    CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(result.name).isEqualTo("accounts");
    assertThat(result.type).isEqualTo(CacheType.MEM);
    assertThat(result.entries.mem).isAtLeast(1L);
    assertThat(result.averageGet).isNotNull();
    assertThat(result.averageGet).endsWith("s");
    assertThat(result.entries.disk).isNull();
    assertThat(result.entries.space).isNull();
    assertThat(result.hitRatio.mem).isAtLeast(0);
    assertThat(result.hitRatio.mem).isAtMost(100);
    assertThat(result.hitRatio.disk).isNull();
    userRestSession.get("/config/server/version").consume();
    r = adminRestSession.get("/config/server/caches/accounts");
    r.assertOK();
    result = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(result.entries.mem).isEqualTo(2);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) CacheInfo(com.google.gerrit.server.config.ListCaches.CacheInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with CacheInfo

use of com.google.gerrit.server.config.ListCaches.CacheInfo in project gerrit by GerritCodeReview.

the class CacheOperationsIT method flush.

@Test
public void flush() throws Exception {
    RestResponse r = adminRestSession.getOK("/config/server/caches/project_list");
    CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0);
    r = adminRestSession.getOK("/config/server/caches/projects");
    cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(cacheInfo.entries.mem).isGreaterThan((long) 1);
    r = adminRestSession.postOK("/config/server/caches/", new PostCaches.Input(FLUSH, Arrays.asList("accounts", "project_list")));
    r.consume();
    r = adminRestSession.getOK("/config/server/caches/project_list");
    cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(cacheInfo.entries.mem).isNull();
    r = adminRestSession.getOK("/config/server/caches/projects");
    cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(cacheInfo.entries.mem).isGreaterThan((long) 1);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) CacheInfo(com.google.gerrit.server.config.ListCaches.CacheInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CacheInfo (com.google.gerrit.server.config.ListCaches.CacheInfo)8 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 RestResponse (com.google.gerrit.acceptance.RestResponse)6 Test (org.junit.Test)6 ConfigResource (com.google.gerrit.server.config.ConfigResource)2 Map (java.util.Map)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 JvmSummaryInfo (com.google.gerrit.server.config.GetSummary.JvmSummaryInfo)1 MemSummaryInfo (com.google.gerrit.server.config.GetSummary.MemSummaryInfo)1 SummaryInfo (com.google.gerrit.server.config.GetSummary.SummaryInfo)1 TaskSummaryInfo (com.google.gerrit.server.config.GetSummary.TaskSummaryInfo)1 ThreadSummaryInfo (com.google.gerrit.server.config.GetSummary.ThreadSummaryInfo)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 TypeToken (com.google.gson.reflect.TypeToken)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1