use of com.gitblit.manager.IRuntimeManager in project gitblit by gitblit.
the class MigrateTickets method migrate.
/**
* Migrate all tickets
*
* @param baseFolder
* @param settings
* @param outputServiceName
*/
protected void migrate(File baseFolder, IStoredSettings settings, String outputServiceName) {
// disable some services
settings.overrideSetting(Keys.web.allowLuceneIndexing, false);
settings.overrideSetting(Keys.git.enableGarbageCollection, false);
settings.overrideSetting(Keys.git.enableMirroring, false);
settings.overrideSetting(Keys.web.activityCacheDays, 0);
settings.overrideSetting(ITicketService.SETTING_UPDATE_DIFFSTATS, false);
XssFilter xssFilter = new AllowXssFilter();
IRuntimeManager runtimeManager = new RuntimeManager(settings, xssFilter, baseFolder).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, null, null).start();
String inputServiceName = settings.getString(Keys.tickets.service, BranchTicketService.class.getSimpleName());
if (StringUtils.isEmpty(inputServiceName)) {
System.err.println(MessageFormat.format("Please define a ticket service in \"{0}\"", Keys.tickets.service));
System.exit(1);
}
ITicketService inputService = null;
ITicketService outputService = null;
try {
inputService = getService(inputServiceName, runtimeManager, repositoryManager);
outputService = getService(outputServiceName, runtimeManager, repositoryManager);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
if (!inputService.isReady()) {
System.err.println(String.format("%s INPUT service is not ready, check config.", inputService.getClass().getSimpleName()));
System.exit(1);
}
if (!outputService.isReady()) {
System.err.println(String.format("%s OUTPUT service is not ready, check config.", outputService.getClass().getSimpleName()));
System.exit(1);
}
// migrate tickets
long start = System.nanoTime();
long totalTickets = 0;
long totalChanges = 0;
for (RepositoryModel repository : repositoryManager.getRepositoryModels()) {
Set<Long> ids = inputService.getIds(repository);
if (ids == null || ids.isEmpty()) {
// nothing to migrate
continue;
}
// delete any tickets we may have in the output ticket service
outputService.deleteAll(repository);
for (long id : ids) {
List<Change> journal = inputService.getJournal(repository, id);
if (journal == null || journal.size() == 0) {
continue;
}
TicketModel ticket = outputService.createTicket(repository, id, journal.get(0));
if (ticket == null) {
System.err.println(String.format("Failed to migrate %s #%s", repository.name, id));
System.exit(1);
}
totalTickets++;
System.out.println(String.format("%s #%s: %s", repository.name, ticket.number, ticket.title));
for (int i = 1; i < journal.size(); i++) {
TicketModel updated = outputService.updateTicket(repository, ticket.number, journal.get(i));
if (updated != null) {
System.out.println(String.format(" applied change %d", i));
totalChanges++;
} else {
System.err.println(String.format("Failed to apply change %d:\n%s", i, journal.get(i)));
System.exit(1);
}
}
}
}
inputService.stop();
outputService.stop();
repositoryManager.stop();
runtimeManager.stop();
long end = System.nanoTime();
System.out.println(String.format("Migrated %d tickets composed of %d journal entries in %d seconds", totalTickets, totalTickets + totalChanges, TimeUnit.NANOSECONDS.toSeconds(end - start)));
}
use of com.gitblit.manager.IRuntimeManager in project gitblit by gitblit.
the class ReindexTickets method reindex.
/**
* Reindex all tickets
*
* @param settings
*/
protected void reindex(File baseFolder, IStoredSettings settings) {
// disable some services
settings.overrideSetting(Keys.web.allowLuceneIndexing, false);
settings.overrideSetting(Keys.git.enableGarbageCollection, false);
settings.overrideSetting(Keys.git.enableMirroring, false);
settings.overrideSetting(Keys.web.activityCacheDays, 0);
XssFilter xssFilter = new AllowXssFilter();
IRuntimeManager runtimeManager = new RuntimeManager(settings, xssFilter, baseFolder).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, null, null).start();
String serviceName = settings.getString(Keys.tickets.service, BranchTicketService.class.getSimpleName());
if (StringUtils.isEmpty(serviceName)) {
System.err.println(MessageFormat.format("Please define a ticket service in \"{0}\"", Keys.tickets.service));
System.exit(1);
}
ITicketService ticketService = null;
try {
Class<?> serviceClass = Class.forName(serviceName);
if (RedisTicketService.class.isAssignableFrom(serviceClass)) {
// Redis ticket service
ticketService = new RedisTicketService(runtimeManager, null, null, null, repositoryManager).start();
} else if (BranchTicketService.class.isAssignableFrom(serviceClass)) {
// Branch ticket service
ticketService = new BranchTicketService(runtimeManager, null, null, null, repositoryManager).start();
} else if (FileTicketService.class.isAssignableFrom(serviceClass)) {
// File ticket service
ticketService = new FileTicketService(runtimeManager, null, null, null, repositoryManager).start();
} else {
System.err.println("Unknown ticket service " + serviceName);
System.exit(1);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
ticketService.reindex();
ticketService.stop();
repositoryManager.stop();
runtimeManager.stop();
}
use of com.gitblit.manager.IRuntimeManager in project gitblit by gitblit.
the class RedisTicketServiceTest method getService.
@Override
protected ITicketService getService(boolean deleteAll) throws Exception {
IStoredSettings settings = getSettings(deleteAll);
XssFilter xssFilter = new AllowXssFilter();
IRuntimeManager runtimeManager = new RuntimeManager(settings, xssFilter).start();
IPluginManager pluginManager = new PluginManager(runtimeManager).start();
INotificationManager notificationManager = new NotificationManager(settings).start();
IUserManager userManager = new UserManager(runtimeManager, pluginManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, pluginManager, userManager).start();
RedisTicketService service = (RedisTicketService) new RedisTicketService(runtimeManager, pluginManager, notificationManager, userManager, repositoryManager).start();
if (deleteAll) {
service.deleteAll(getRepository());
}
return service;
}
use of com.gitblit.manager.IRuntimeManager in project gitblit by gitblit.
the class UITicketTest method getService.
protected ITicketService getService(boolean deleteAll) throws Exception {
IStoredSettings settings = getSettings(deleteAll);
XssFilter xssFilter = new AllowXssFilter();
IRuntimeManager runtimeManager = new RuntimeManager(settings, xssFilter).start();
IPluginManager pluginManager = new PluginManager(runtimeManager).start();
INotificationManager notificationManager = new NotificationManager(settings).start();
IUserManager userManager = new UserManager(runtimeManager, pluginManager).start();
IRepositoryManager repositoryManager = new RepositoryManager(runtimeManager, pluginManager, userManager).start();
BranchTicketService service = (BranchTicketService) new BranchTicketService(runtimeManager, pluginManager, notificationManager, userManager, repositoryManager).start();
if (deleteAll) {
service.deleteAll(repo);
}
return service;
}
use of com.gitblit.manager.IRuntimeManager in project gitblit by gitblit.
the class GitblitContext method startCore.
/**
* Prepare runtime settings and start all manager instances.
*/
protected void startCore(ServletContext context) {
Injector injector = (Injector) context.getAttribute(Injector.class.getName());
// create the runtime settings object
IStoredSettings runtimeSettings = injector.getInstance(IStoredSettings.class);
final File baseFolder;
if (goSettings != null) {
// Gitblit GO
baseFolder = configureGO(context, goSettings, goBaseFolder, runtimeSettings);
} else {
// servlet container
WebXmlSettings webxmlSettings = new WebXmlSettings(context);
String contextRealPath = context.getRealPath("/");
File contextFolder = (contextRealPath != null) ? new File(contextRealPath) : null;
// if the base folder dosen't match the default assume they don't want to use express,
// this allows for other containers to customise the basefolder per context.
String defaultBase = Constants.contextFolder$ + "/WEB-INF/data";
String base = getBaseFolderPath(defaultBase);
if (!StringUtils.isEmpty(System.getenv("OPENSHIFT_DATA_DIR")) && defaultBase.equals(base)) {
// RedHat OpenShift
baseFolder = configureExpress(context, webxmlSettings, contextFolder, runtimeSettings);
} else {
// standard WAR
baseFolder = configureWAR(context, webxmlSettings, contextFolder, runtimeSettings);
}
// Test for Tomcat forward-slash/%2F issue and auto-adjust settings
ContainerUtils.CVE_2007_0450.test(runtimeSettings);
}
// Manually configure IRuntimeManager
logManager(IRuntimeManager.class);
IRuntimeManager runtime = injector.getInstance(IRuntimeManager.class);
runtime.setBaseFolder(baseFolder);
runtime.getStatus().isGO = goSettings != null;
runtime.getStatus().servletContainer = context.getServerInfo();
runtime.start();
managers.add(runtime);
// create the plugin manager instance but do not start it
loadManager(injector, IPluginManager.class);
// start all other managers
startManager(injector, INotificationManager.class);
startManager(injector, IUserManager.class);
startManager(injector, IAuthenticationManager.class);
startManager(injector, IPublicKeyManager.class);
startManager(injector, IRepositoryManager.class);
startManager(injector, IProjectManager.class);
startManager(injector, IFederationManager.class);
startManager(injector, ITicketService.class);
startManager(injector, IGitblit.class);
startManager(injector, IServicesManager.class);
startManager(injector, IFilestoreManager.class);
// start the plugin manager last so that plugins can depend on
// deterministic access to all other managers in their start() methods
startManager(injector, IPluginManager.class);
logger.info("");
logger.info("All managers started.");
logger.info("");
IPluginManager pluginManager = injector.getInstance(IPluginManager.class);
for (LifeCycleListener listener : pluginManager.getExtensions(LifeCycleListener.class)) {
try {
listener.onStartup();
} catch (Throwable t) {
logger.error(null, t);
}
}
}
Aggregations