Skip to content

Commit a904b83

Browse files
Vladimir Kotalahornace
authored andcommitted
introduce CommandTimeoutType
fixes #3146
1 parent 524aa98 commit a904b83

33 files changed

+357
-233
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
24+
package org.opengrok.indexer.configuration;
25+
26+
public enum CommandTimeoutType {
27+
INTERACTIVE,
28+
INDEXER,
29+
RESTFUL,
30+
WEBAPP_START;
31+
}

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

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ public final class Configuration {
210210
private boolean chattyStatusPage;
211211
private final Map<String, String> cmds; // repository type -> command
212212
private int tabSize;
213-
private int commandTimeout; // in seconds
213+
private int indexerCommandTimeout; // in seconds
214214
private int interactiveCommandTimeout; // in seconds
215+
private int webappStartCommandTimeout; // in seconds
216+
private int restfulCommandTimeout; // in seconds
215217
private long ctagsTimeout; // in seconds
216218
private boolean scopesEnabled;
217219
private boolean projectsEnabled;
@@ -373,22 +375,58 @@ public void setNestingMaximum(int nestingMaximum) throws IllegalArgumentExceptio
373375
this.nestingMaximum = nestingMaximum;
374376
}
375377

376-
public int getCommandTimeout() {
377-
return commandTimeout;
378+
public int getIndexerCommandTimeout() {
379+
return indexerCommandTimeout;
378380
}
379381

380382
/**
381383
* Set the command timeout to a new value.
382384
*
383-
* @param commandTimeout the new value
385+
* @param timeout the new value
386+
* @throws IllegalArgumentException when the timeout is negative
387+
*/
388+
public void setIndexerCommandTimeout(int timeout) throws IllegalArgumentException {
389+
if (timeout < 0) {
390+
throw new IllegalArgumentException(
391+
String.format(NEGATIVE_NUMBER_ERROR, "commandTimeout", timeout));
392+
}
393+
this.indexerCommandTimeout = timeout;
394+
}
395+
396+
public int getRestfulCommandTimeout() {
397+
return restfulCommandTimeout;
398+
}
399+
400+
/**
401+
* Set the command timeout to a new value.
402+
*
403+
* @param timeout the new value
384404
* @throws IllegalArgumentException when the timeout is negative
385405
*/
386-
public void setCommandTimeout(int commandTimeout) throws IllegalArgumentException {
387-
if (commandTimeout < 0) {
406+
public void setRestfulCommandTimeout(int timeout) throws IllegalArgumentException {
407+
if (timeout < 0) {
388408
throw new IllegalArgumentException(
389-
String.format(NEGATIVE_NUMBER_ERROR, "commandTimeout", commandTimeout));
409+
String.format(NEGATIVE_NUMBER_ERROR, "restfulCommandTimeout", timeout));
390410
}
391-
this.commandTimeout = commandTimeout;
411+
this.restfulCommandTimeout = timeout;
412+
}
413+
414+
public int getWebappStartCommandTimeout() {
415+
return webappStartCommandTimeout;
416+
}
417+
418+
/**
419+
* Set the command timeout to a new value.
420+
*
421+
* @param timeout the new value
422+
* @throws IllegalArgumentException when the timeout is negative
423+
*/
424+
public void setWebappStartCommandTimeout(int timeout) throws IllegalArgumentException {
425+
if (timeout < 0) {
426+
throw new IllegalArgumentException(
427+
String.format(NEGATIVE_NUMBER_ERROR, "webappStartCommandTimeout", timeout));
428+
}
429+
this.webappStartCommandTimeout = timeout;
392430
}
393431

394432
public int getInteractiveCommandTimeout() {
@@ -398,15 +436,15 @@ public int getInteractiveCommandTimeout() {
398436
/**
399437
* Set the interactive command timeout to a new value.
400438
*
401-
* @param commandTimeout the new value
439+
* @param timeout the new value
402440
* @throws IllegalArgumentException when the timeout is negative
403441
*/
404-
public void setInteractiveCommandTimeout(int commandTimeout) throws IllegalArgumentException {
405-
if (commandTimeout < 0) {
442+
public void setInteractiveCommandTimeout(int timeout) throws IllegalArgumentException {
443+
if (timeout < 0) {
406444
throw new IllegalArgumentException(
407-
String.format(NEGATIVE_NUMBER_ERROR, "interactiveCommandTimeout", commandTimeout));
445+
String.format(NEGATIVE_NUMBER_ERROR, "interactiveCommandTimeout", timeout));
408446
}
409-
this.interactiveCommandTimeout = commandTimeout;
447+
this.interactiveCommandTimeout = timeout;
410448
}
411449

412450
public long getCtagsTimeout() {
@@ -420,7 +458,7 @@ public long getCtagsTimeout() {
420458
* @throws IllegalArgumentException when the timeout is negative
421459
*/
422460
public void setCtagsTimeout(long timeout) throws IllegalArgumentException {
423-
if (commandTimeout < 0) {
461+
if (timeout < 0) {
424462
throw new IllegalArgumentException(
425463
String.format(NEGATIVE_NUMBER_ERROR, "ctagsTimeout", timeout));
426464
}
@@ -466,8 +504,10 @@ public Configuration() {
466504
setBugPattern("\\b([12456789][0-9]{6})\\b");
467505
setCachePages(5);
468506
setCanonicalRoots(new HashSet<>());
469-
setCommandTimeout(600); // 10 minutes
507+
setIndexerCommandTimeout(600); // 10 minutes
508+
setRestfulCommandTimeout(60);
470509
setInteractiveCommandTimeout(30);
510+
setWebappStartCommandTimeout(5);
471511
setCompressXref(true);
472512
setContextLimit((short) 10);
473513
//contextSurround is default(short)

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

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.FileNotFoundException;
3030
import java.io.IOException;
3131
import java.nio.file.Path;
32+
import java.security.InvalidParameterException;
3233
import java.util.ArrayList;
3334
import java.util.Arrays;
3435
import java.util.Collections;
@@ -170,7 +171,7 @@ private ExecutorService newRevisionExecutor() {
170171

171172
public void shutdownRevisionExecutor() throws InterruptedException {
172173
getRevisionExecutor().shutdownNow();
173-
getRevisionExecutor().awaitTermination(getCommandTimeout(), TimeUnit.SECONDS);
174+
getRevisionExecutor().awaitTermination(getIndexerCommandTimeout(), TimeUnit.SECONDS);
174175
}
175176

176177
/**
@@ -225,29 +226,59 @@ public void setNestingMaximum(int nestingMaximum) {
225226
syncWriteConfiguration(nestingMaximum, Configuration::setNestingMaximum);
226227
}
227228

228-
public int getCommandTimeout() {
229-
return syncReadConfiguration(Configuration::getCommandTimeout);
229+
public int getCommandTimeout(CommandTimeoutType cmdType) {
230+
switch (cmdType) {
231+
case INDEXER:
232+
return getIndexerCommandTimeout();
233+
case INTERACTIVE:
234+
return getInteractiveCommandTimeout();
235+
case WEBAPP_START:
236+
return getWebappStartCommandTimeout();
237+
case RESTFUL:
238+
return getRestfulCommandTimeout();
239+
}
240+
241+
throw new InvalidParameterException("invalid command timeout type");
242+
}
243+
244+
public int getRestfulCommandTimeout() {
245+
return syncReadConfiguration(Configuration::getRestfulCommandTimeout);
246+
}
247+
248+
public void setRestfulCommandTimeout(int timeout) {
249+
syncWriteConfiguration(timeout, Configuration::setWebappStartCommandTimeout);
250+
}
251+
252+
public int getWebappStartCommandTimeout() {
253+
return syncReadConfiguration(Configuration::getWebappStartCommandTimeout);
254+
}
255+
256+
public void setWebappStartCommandTimeout(int timeout) {
257+
syncWriteConfiguration(timeout, Configuration::setWebappStartCommandTimeout);
258+
}
259+
260+
public int getIndexerCommandTimeout() {
261+
return syncReadConfiguration(Configuration::getIndexerCommandTimeout);
230262
}
231263

232-
public void setCommandTimeout(int commandTimeout) {
233-
syncWriteConfiguration(commandTimeout, Configuration::setCommandTimeout);
264+
public void setIndexerCommandTimeout(int timeout) {
265+
syncWriteConfiguration(timeout, Configuration::setIndexerCommandTimeout);
234266
}
235267

236268
public int getInteractiveCommandTimeout() {
237269
return syncReadConfiguration(Configuration::getInteractiveCommandTimeout);
238270
}
239271

240-
public void setInteractiveCommandTimeout(int interactiveCommandTimeout) {
241-
syncWriteConfiguration(interactiveCommandTimeout,
242-
Configuration::setInteractiveCommandTimeout);
272+
public void setInteractiveCommandTimeout(int timeout) {
273+
syncWriteConfiguration(timeout, Configuration::setInteractiveCommandTimeout);
243274
}
244275

245276
public long getCtagsTimeout() {
246277
return syncReadConfiguration(Configuration::getCtagsTimeout);
247278
}
248279

249-
public void setCtagsTimeout(long ctagsTimeout) {
250-
syncWriteConfiguration(ctagsTimeout, Configuration::setCtagsTimeout);
280+
public void setCtagsTimeout(long timeout) {
281+
syncWriteConfiguration(timeout, Configuration::setCtagsTimeout);
251282
}
252283

253284
public void setLastEditedDisplayMode(boolean lastEditedDisplayMode) {
@@ -1326,12 +1357,12 @@ public void readConfiguration(File file) throws IOException {
13261357
/**
13271358
* Read configuration from a file and put it into effect.
13281359
* @param file the file to read
1329-
* @param interactive true if run in interactive mode
1360+
* @param cmdType command timeout type
13301361
* @throws IOException I/O
13311362
*/
1332-
public void readConfiguration(File file, boolean interactive) throws IOException {
1363+
public void readConfiguration(File file, CommandTimeoutType cmdType) throws IOException {
13331364
// The following method handles the locking.
1334-
setConfiguration(Configuration.read(file), null, interactive);
1365+
setConfiguration(Configuration.read(file), null, cmdType);
13351366
}
13361367

13371368
/**
@@ -1478,26 +1509,26 @@ public void populateGroups(Set<Group> groups, Set<Project> projects) {
14781509
* @param configuration what configuration to use
14791510
*/
14801511
public void setConfiguration(Configuration configuration) {
1481-
setConfiguration(configuration, null, false);
1512+
setConfiguration(configuration, null, CommandTimeoutType.INDEXER);
14821513
}
14831514

14841515
/**
14851516
* Sets the configuration and performs necessary actions.
14861517
* @param configuration new configuration
1487-
* @param interactive true if in interactive mode
1518+
* @param cmdType command timeout type
14881519
*/
1489-
public void setConfiguration(Configuration configuration, boolean interactive) {
1490-
setConfiguration(configuration, null, interactive);
1520+
public void setConfiguration(Configuration configuration, CommandTimeoutType cmdType) {
1521+
setConfiguration(configuration, null, cmdType);
14911522
}
14921523

14931524
/**
14941525
* Sets the configuration and performs necessary actions.
14951526
*
14961527
* @param configuration new configuration
14971528
* @param subFileList list of repositories
1498-
* @param interactive true if in interactive mode
1529+
* @param cmdType command timeout type
14991530
*/
1500-
public synchronized void setConfiguration(Configuration configuration, List<String> subFileList, boolean interactive) {
1531+
public synchronized void setConfiguration(Configuration configuration, List<String> subFileList, CommandTimeoutType cmdType) {
15011532
try (ResourceLock resourceLock = configLock.writeLockAsResource()) {
15021533
//noinspection ConstantConditions to avoid warning of no reference to auto-closeable
15031534
assert resourceLock != null;
@@ -1509,11 +1540,9 @@ public synchronized void setConfiguration(Configuration configuration, List<Stri
15091540

15101541
// Set the working repositories in HistoryGuru.
15111542
if (subFileList != null) {
1512-
histGuru.invalidateRepositories(
1513-
getRepositories(), subFileList, interactive);
1543+
histGuru.invalidateRepositories(getRepositories(), subFileList, cmdType);
15141544
} else {
1515-
histGuru.invalidateRepositories(getRepositories(),
1516-
interactive);
1545+
histGuru.invalidateRepositories(getRepositories(), cmdType);
15171546
}
15181547

15191548
// The invalidation of repositories above might have excluded some
@@ -1569,10 +1598,10 @@ public void setAuthorizationFramework(AuthorizationFramework fw) {
15691598
/**
15701599
* Re-apply the configuration.
15711600
* @param reindex is the message result of reindex
1572-
* @param interactive true if in interactive mode
1601+
* @param cmdType command timeout type
15731602
*/
1574-
public void applyConfig(boolean reindex, boolean interactive) {
1575-
applyConfig(configuration, reindex, interactive);
1603+
public void applyConfig(boolean reindex, CommandTimeoutType cmdType) {
1604+
applyConfig(configuration, reindex, cmdType);
15761605
}
15771606

15781607
/**
@@ -1582,11 +1611,11 @@ public void applyConfig(boolean reindex, boolean interactive) {
15821611
*
15831612
* @param configuration XML configuration
15841613
* @param reindex is the message result of reindex
1585-
* @param interactive true if in interactive mode
1614+
* @param cmdType command timeout type
15861615
* @see #applyConfig(org.opengrok.indexer.configuration.Configuration,
1587-
* boolean, boolean) applyConfig(config, reindex, interactive)
1616+
* boolean, CommandTimeoutType) applyConfig(config, reindex, cmdType)
15881617
*/
1589-
public void applyConfig(String configuration, boolean reindex, boolean interactive) {
1618+
public void applyConfig(String configuration, boolean reindex, CommandTimeoutType cmdType) {
15901619
Configuration config;
15911620
try {
15921621
config = makeXMLStringAsConfiguration(configuration);
@@ -1595,7 +1624,7 @@ public void applyConfig(String configuration, boolean reindex, boolean interacti
15951624
return;
15961625
}
15971626

1598-
applyConfig(config, reindex, interactive);
1627+
applyConfig(config, reindex, cmdType);
15991628
}
16001629

16011630
/**
@@ -1605,10 +1634,10 @@ public void applyConfig(String configuration, boolean reindex, boolean interacti
16051634
*
16061635
* @param config the incoming configuration
16071636
* @param reindex is the message result of reindex
1608-
* @param interactive true if in interactive mode
1637+
* @param cmdType command timeout type
16091638
*/
1610-
public void applyConfig(Configuration config, boolean reindex, boolean interactive) {
1611-
setConfiguration(config, interactive);
1639+
public void applyConfig(Configuration config, boolean reindex, CommandTimeoutType cmdType) {
1640+
setConfiguration(config, cmdType);
16121641
LOGGER.log(Level.INFO, "Configuration updated");
16131642

16141643
if (reindex) {

0 commit comments

Comments
 (0)