use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class WebappListener method contextInitialized.
/**
* {@inheritDoc}
*/
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
Instant start = Instant.now();
ServletContext context = servletContextEvent.getServletContext();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
LOGGER.log(Level.INFO, "Starting webapp with version {0} ({1})", new Object[] { Info.getVersion(), Info.getRevision() });
String config = context.getInitParameter("CONFIGURATION");
if (config == null) {
throw new Error("CONFIGURATION parameter missing in the web.xml file");
} else {
try {
env.readConfiguration(new File(config), CommandTimeoutType.WEBAPP_START);
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Configuration error. Failed to read config file: ", ex);
}
}
/*
* Create a new instance of authorization framework. If the code above
* (reading the configuration) failed then the plugin directory is
* possibly {@code null} causing the framework to allow every request.
*/
env.setAuthorizationFramework(new AuthorizationFramework(env.getPluginDirectory(), env.getPluginStack()));
env.getAuthorizationFramework().reload();
if (env.isWebappCtags() && !env.validateUniversalCtags()) {
LOGGER.warning("Didn't find Universal Ctags for --webappCtags");
}
String pluginDirectory = env.getPluginDirectory();
if (pluginDirectory != null && env.isAuthorizationWatchdog()) {
env.getWatchDog().start(new File(pluginDirectory));
}
// Check index(es).
checkIndex(env);
env.startExpirationTimer();
ApiTaskManager.getInstance().setContextPath(context.getContextPath());
// register API task queues
ApiTaskManager.getInstance().addPool(ProjectsController.PROJECTS_PATH, 1);
// Used by ConfigurationController#reloadAuthorization()
ApiTaskManager.getInstance().addPool("authorization", 1);
ApiTaskManager.getInstance().addPool(ConfigurationController.PATH, 1);
startupTimer.record(Duration.between(start, Instant.now()));
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class WebappListener method contextDestroyed.
/**
* {@inheritDoc}
*/
@Override
public void contextDestroyed(final ServletContextEvent servletContextEvent) {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.getIndexerParallelizer().bounce();
env.getWatchDog().stop();
env.stopExpirationTimer();
try {
env.shutdownRevisionExecutor();
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Could not shutdown revision executor", e);
}
// need to explicitly close the suggester service because it might have scheduled rebuild which could prevent
// the web application from closing
SuggesterServiceFactory.getDefault().close();
// destroy queue(s) of API tasks
try {
ApiTaskManager.getInstance().shutdown();
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "could not shutdown API task manager cleanly", e);
}
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class Indexer method doIndexerExecution.
/**
* This is the second phase of the indexer which generates Lucene index
* by passing source code files through ctags, generating xrefs
* and storing data from the source files in the index (along with history,
* if any).
*
* @param update if set to true, index database is updated, otherwise optimized
* @param subFiles index just some subdirectories
* @param progress object to receive notifications as indexer progress is made
* @throws IOException if I/O exception occurred
*/
public void doIndexerExecution(final boolean update, List<String> subFiles, IndexChangedListener progress) throws IOException {
Statistics elapsed = new Statistics();
LOGGER.info("Starting indexing");
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
IndexerParallelizer parallelizer = env.getIndexerParallelizer();
final CountDownLatch latch;
if (subFiles == null || subFiles.isEmpty()) {
if (update) {
latch = IndexDatabase.updateAll(progress);
} else if (env.isOptimizeDatabase()) {
latch = IndexDatabase.optimizeAll();
} else {
latch = new CountDownLatch(0);
}
} else {
List<IndexDatabase> dbs = new ArrayList<>();
for (String path : subFiles) {
Project project = Project.getProject(path);
if (project == null && env.hasProjects()) {
LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
} else {
IndexDatabase db;
if (project == null) {
db = new IndexDatabase();
} else {
db = new IndexDatabase(project);
}
int idx = dbs.indexOf(db);
if (idx != -1) {
db = dbs.get(idx);
}
if (db.addDirectory(path)) {
if (idx == -1) {
dbs.add(db);
}
} else {
LOGGER.log(Level.WARNING, "Directory does not exist \"{0}\"", path);
}
}
}
latch = new CountDownLatch(dbs.size());
for (final IndexDatabase db : dbs) {
final boolean optimize = env.isOptimizeDatabase();
db.addIndexChangedListener(progress);
parallelizer.getFixedExecutor().submit(() -> {
try {
if (update) {
db.update();
} else if (optimize) {
db.optimize();
}
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, "An error occurred while " + (update ? "updating" : "optimizing") + " index", e);
} finally {
latch.countDown();
}
});
}
}
// Wait forever for the executors to finish.
try {
LOGGER.info("Waiting for the executors to finish");
latch.await();
} catch (InterruptedException exp) {
LOGGER.log(Level.WARNING, "Received interrupt while waiting" + " for executor to finish", exp);
}
elapsed.report(LOGGER, "Done indexing data of all repositories", "indexer.repository.indexing");
CtagsUtil.deleteTempFiles();
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class IndexDatabase method initialize.
@SuppressWarnings("PMD.CollapsibleIfStatements")
private void initialize() throws IOException {
synchronized (INSTANCE_LOCK) {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
File indexDir = new File(env.getDataRootFile(), INDEX_DIR);
if (project != null) {
indexDir = new File(indexDir, project.getPath());
}
if (!indexDir.exists() && !indexDir.mkdirs()) {
// to avoid race conditions, just recheck..
if (!indexDir.exists()) {
throw new FileNotFoundException("Failed to create root directory [" + indexDir.getAbsolutePath() + "]");
}
}
lockfact = pickLockFactory(env);
indexDirectory = FSDirectory.open(indexDir.toPath(), lockfact);
pathAccepter = env.getPathAccepter();
analyzerGuru = new AnalyzerGuru();
xrefDir = new File(env.getDataRootFile(), XREF_DIR);
listeners = new CopyOnWriteArrayList<>();
dirtyFile = new File(indexDir, "dirty");
dirty = dirtyFile.exists();
directories = new ArrayList<>();
}
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class IndexDatabase method listFrequentTokens.
static void listFrequentTokens(List<String> subFiles) throws IOException {
final int limit = 4;
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.hasProjects()) {
if (subFiles == null || subFiles.isEmpty()) {
for (Project project : env.getProjectList()) {
IndexDatabase db = new IndexDatabase(project);
db.listTokens(limit);
}
} else {
for (String path : subFiles) {
Project project = Project.getProject(path);
if (project == null) {
LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
} else {
IndexDatabase db = new IndexDatabase(project);
db.listTokens(limit);
}
}
}
} else {
IndexDatabase db = new IndexDatabase();
db.listTokens(limit);
}
}
Aggregations