Skip to content

Commit b696b5e

Browse files
authored
introduce more /system endpoints (#4230)
Also raise connect timeout to 10 seconds. fixes #4211 fixes #4229
1 parent d56aac4 commit b696b5e

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

apiary.apib

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,25 @@ The paths are relative to source root, starting with /.
296296

297297
+ Response 204
298298

299+
## Web app version [/system/version]
300+
301+
### get web app version as string [GET]
302+
303+
+ Request (text/plain)
304+
+ Body
305+
306+
1.9.0 (a5ac05426bc5029158fedffee1cd44abf033bb61)
307+
308+
+ Response 200
309+
310+
## Ping the webapp [/system/ping]
311+
312+
This endpoint is used by the indexer when running with the -U option.
313+
314+
### Check if web app is deployed and alive [GET]
315+
316+
+ Response 200
317+
299318
## Groups [/groups]
300319

301320
### returns a list of all groups [GET]

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public Configuration() {
588588
// webappCtags is default(boolean)
589589
setXrefTimeout(30);
590590
setApiTimeout(300); // 5 minutes
591-
setConnectTimeout(3);
591+
setConnectTimeout(10);
592592
}
593593

594594
public String getRepoCmd(String clazzName) {

opengrok-indexer/src/main/java/org/opengrok/indexer/util/HostUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ private static boolean isWebAppReachable(String webappURI, int timeOutSeconds, @
7878
.target(webappURI)
7979
.path("api")
8080
.path("v1")
81-
.path("configuration")
81+
.path("system")
82+
.path("ping")
8283
.request()
8384
.headers(headers)
8485
.get();

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SystemController.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.web.api.v1.controller;
2424
import jakarta.inject.Inject;
@@ -33,6 +33,7 @@
3333
import com.fasterxml.jackson.core.JsonProcessingException;
3434
import com.fasterxml.jackson.databind.ObjectMapper;
3535
import com.fasterxml.jackson.databind.util.StdDateFormat;
36+
import org.opengrok.indexer.Info;
3637
import org.opengrok.indexer.configuration.IndexTimestamp;
3738
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3839
import org.opengrok.indexer.web.EftarFile;
@@ -81,4 +82,17 @@ public String getIndexTime() throws JsonProcessingException {
8182
mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true));
8283
return mapper.writeValueAsString(date);
8384
}
85+
86+
@GET
87+
@Path("/version")
88+
@Produces(MediaType.TEXT_PLAIN)
89+
public String getVersion() {
90+
return String.format("%s (%s)", Info.getVersion(), Info.getRevision());
91+
}
92+
93+
@GET
94+
@Path("/ping")
95+
public String ping() {
96+
return "";
97+
}
8498
}

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/SystemControllerTest.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.web.api.v1.controller;
@@ -32,6 +32,7 @@
3232
import org.glassfish.jersey.test.spi.TestContainerException;
3333
import org.glassfish.jersey.test.spi.TestContainerFactory;
3434
import org.junit.jupiter.api.Test;
35+
import org.opengrok.indexer.Info;
3536
import org.opengrok.indexer.configuration.Configuration;
3637
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3738
import org.opengrok.indexer.util.IOUtils;
@@ -70,7 +71,7 @@ protected TestContainerFactory getTestContainerFactory() throws TestContainerExc
7071

7172
/**
7273
* This method tests include files reload by testing it for one specific file out of the whole set.
73-
* @throws IOException
74+
* @throws IOException on error
7475
*/
7576
@Test
7677
public void testIncludeReload() throws IOException {
@@ -98,10 +99,11 @@ public void testIncludeReload() throws IOException {
9899
}
99100

100101
// Reload the contents via API call.
101-
Response r = target("system")
102+
try (Response r = target("system")
102103
.path("includes").path("reload")
103-
.request().put(Entity.text(""));
104-
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), r.getStatus());
104+
.request().put(Entity.text(""))) {
105+
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), r.getStatus());
106+
}
105107

106108
// Check that the content was reloaded.
107109
String after = env.getIncludeFiles().getFooterIncludeFileContent(false);
@@ -117,20 +119,20 @@ public void testDtagsEftarReload() throws IOException {
117119
// The output file will be located in a directory under data root so create it first.
118120
Path dataRoot = Files.createTempDirectory("api_dtags_test");
119121
env.setDataRoot(dataRoot.toString());
120-
Paths.get(dataRoot.toString(), "index").toFile().mkdir();
122+
assertTrue(Paths.get(dataRoot.toString(), "index").toFile().mkdir());
121123

122124
// Create path descriptions string.
123-
StringBuilder sb = new StringBuilder();
124125
PathDescription[] descriptions = {
125126
new PathDescription("/path1", "foo foo"),
126127
new PathDescription("/path2", "bar bar")
127128
};
128129

129130
// Reload the contents via API call.
130-
Response r = target("system")
131+
try (Response r = target("system")
131132
.path("pathdesc")
132-
.request().post(Entity.json(descriptions));
133-
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), r.getStatus());
133+
.request().post(Entity.json(descriptions))) {
134+
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), r.getStatus());
135+
}
134136

135137
// Check
136138
Path eftarPath = env.getDtagsEftarPath();
@@ -166,4 +168,26 @@ public void testIndexTime() throws IOException, ParseException {
166168
// Cleanup
167169
IOUtils.removeRecursive(dataRoot);
168170
}
171+
172+
@Test
173+
void testVersion() {
174+
Response r = target("system")
175+
.path("version")
176+
.request().get();
177+
String result = r.readEntity(String.class);
178+
179+
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
180+
assertEquals(String.format("%s (%s)", Info.getVersion(), Info.getRevision()), result);
181+
}
182+
183+
@Test
184+
void testPing() {
185+
Response r = target("system")
186+
.path("ping")
187+
.request().get();
188+
String result = r.readEntity(String.class);
189+
190+
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
191+
assertTrue(result.isEmpty());
192+
}
169193
}

0 commit comments

Comments
 (0)