/** * A fail-safe event creator with reliable semantics to fall back on when a more specific {@link Event event} is * not available. * * @param eventType the event type to use * @param message the message to use * @param t the exception thrown while attempting to initialise the WebApplicationContext * @return the event to add to Johnson, which will never be {@code null} */ @Nonnull public static Event createDefaultEvent(@Nonnull String eventType, @Nonnull String message, @Nonnull Throwable t) { return new Event(EventType.get(eventType), message, Event.toString(t), EventLevel.get(EventLevel.FATAL)); }
final Event event = new Event(EventType.get("database"), "Could not connect to database", e.getMessage(), EventLevel.get(EventLevel.ERROR)); addJohnsonEvent(event); final Event event = new Event(EventType.get("database"), "Could not connect to database.", databaseConnectionTestException.getMessage(), EventLevel.get(EventLevel.ERROR)); addJohnsonEvent(event);
void addErrors( final Set<Plugin> outdatedPlugins) { final String description = "Plugins found that are not compatible with JIRA v" + buildUtilsInfo.getVersion() + ". " + "The following plugins need to be either removed or updated in order for JIRA to start successfully:"; final StringBuilder pluginNames = new StringBuilder(); for (Plugin outdatedPlugin : outdatedPlugins) { pluginNames.append(pluginsToCheck.get(outdatedPlugin.getKey()).getErrorMessage(outdatedPlugin)).append("\n"); } final String cacMessage = "Please visit " + PAC_LINK + " to download the latest versions of these plugins."; final List<String> messages = CollectionBuilder.newBuilder("", description, "", pluginNames.toString().trim(), "", cacMessage, "").asList(); startupLog.printMessage(messages, Level.ERROR); final Event event = new Event(EventType.get("outdated-plugins-installed"), description + "<p/>" + TextUtils.plainTextToHtml(pluginNames.toString()) + "<p/>" + TextUtils.plainTextToHtml(cacMessage), EventLevel.get(EventLevel.ERROR)); final JohnsonEventContainer eventCont = johnsonProvider.getContainer(); eventCont.addEvent(event); }
private void panicAndShutdown(Throwable t, LifecycleContext context, LifecyclePluginModuleDescriptor descriptor) { final String errorString = "Unable to start up Confluence. Fatal error during startup sequence: " + descriptor + " - " + t; log.error(errorString, t); context.getAgentJohnson().addEvent(new Event(EventType.get("startup"), errorString, EventLevel.FATAL)); shutDown(context.getServletContext(), descriptor.getCompleteKey()); }
private static void addEventsForErrors(final JohnsonEventContainer cont, final UpgradeManager.Status status) { if (cont != null && status != null && !status.successful()) { for (final String exception : status.getErrors()) { final Event errorEvent = new Event(EventType.get("upgrade"), "An error occurred performing JIRA upgrade", exception, EventLevel.get(EventLevel.ERROR)); cont.addEvent(errorEvent); } } }
final Event appEvent = new Event(EventType.get("reindex"), johnsonMessage, EventLevel.get(EventLevel.WARNING)); try
private void raiseJohnson(final StartupCheck failedCheck) { String desc = failedCheck.getFaultDescription(); log.error(failedCheck.getName() + " failed: " + desc); log.error("Clustering startup check failed."); final EventType eventType; if (failedCheck instanceof ClusterLicenseStartupCheck) { eventType = EventType.get(LicenseJohnsonEventRaiser.CLUSTERING_UNLICENSED); } else { eventType = EventType.get(LicenseJohnsonEventRaiser.CLUSTERING); } Event event = new Event(eventType, failedCheck.getHTMLFaultDescription(), EventLevel.get(ERROR)); johnsonProvider.getContainer().addEvent(event); }
final Event event = new Event(eventType, "Please restart JIRA to complete the HSQL to H2 database migration", EventLevel.get(FATAL)); johnsonProvider.getContainer().addEvent(event);
johnsonProvider.getContainer().addEvent(new Event( EventType.get(STARTUP_UNEXPECTED), "Unexpected exception during JIRA startup. This JIRA instance " + "will not be able to recover. Please check the logs for details",
@Override public void start() { final JiraDatabaseConfigChecklist jiraPostDatabaseChecklist = new JiraDatabaseConfigChecklist(dbcm, jiraSystemProperties, buildUtilsInfo); if (jiraPostDatabaseChecklist.startupOK()) { log.info("JIRA database startup checks completed successfully."); } else { final StartupCheck failedCheck = jiraPostDatabaseChecklist.getFailedStartupCheck(); final String desc = failedCheck.getFaultDescription(); log.error(failedCheck.getName() + " failed: " + desc); log.error("Database startup check failed - this is FATAL - JIRA will not be in a working state."); final EventType eventType = EventType.get("database"); final Event event = new Event(eventType, failedCheck.getHTMLFaultDescription(), EventLevel.get(ERROR)); johnsonProvider.getContainer().addEvent(event); } }
public IndexCommandResult call() { // We use a null user here to get the Johnson message in the default language for this JIRA instance. final String johnsonMessage = i18nBeanFactory.getInstance((ApplicationUser) null).getText("admin.reindex.in.progress.johnson.summary"); final Event appEvent = new Event(EventType.get("reindex"), johnsonMessage, EventLevel.get(EventLevel.WARNING)); if (eventCont != null) { eventCont.addEvent(appEvent); } try { final Context context = Contexts.percentageReporter(indexManager, taskProgressSink, i18nHelper, log, appEvent); log.info("Re-indexing started"); return doReindex(context, indexManager); } finally { if (eventCont != null) { eventCont.removeEvent(appEvent); } log.info("Re-indexing finished"); } }
@Override public IndexCommandResult call() throws Exception { final Event appEvent = new Event(EventType.get("reindex"), JIRA_INDEX_RECOVERY_MSG, EventLevel.get(EventLevel.WARNING)); try { final Context context = Contexts.builder() .sized(indexRecoveryService) .event(appEvent) .progress(taskProgressSink, i18nHelper, REINDEX_PERCENT, REINDEX_CURRENT) .log(log, "Index Recovery: {0}%") .build(); log.info("Re-indexing started"); return indexRecoveryService.recoverIndexFromBackup(user, context, i18nHelper, recoveryFilename, taskProgressSink); } finally { log.info("Index Recovery finished"); } }
/** * If the Perforce Plugin is on the classpath, we need to log it, raise a JohnsonEvent to lock JIRA and prevent the previously * existing Perforce data from being automatically upgraded. * * @return true if the Perforce plugin was detected, false otherwise */ protected boolean detectPerforcePlugin() { if (isPerforcePluginOnClasspath()) { log.error( "You can not have the JIRA Perforce plugin and JIRA FishEye plugin v1.6 or above installed at the " + "same time. Please remove atlassian-jira-perforce-plugin-x.x.jar from WEB-INF/lib and restart JIRA"); final EventType type = new EventType(i18nHelper.getText("perforce.check.event.type.category"), i18nHelper.getText("perforce.check.event.type.description")); final JohnsonEventContainer johnsonEventContainer = johnsonProvider.getContainer(); johnsonEventContainer.addEvent(new Event(type, i18nHelper.getText("perforce.check.event.description"), EventLevel.get(EventLevel.FATAL))); return true; } else { return false; } }
private void runStartupChecks(final ServletContext servletContext) { JiraStartupLogger.log().info("Running JIRA startup checks."); if (JiraStartupChecklist.startupOK()) { JiraStartupLogger.log().info("JIRA pre-database startup checks completed successfully."); } else { JiraStartupLogger.log().fatal("Startup check failed. JIRA will be locked."); // Lock the DB for ANY of the checks failing. GenericDelegator.lock(); // TODO: Do we really need to raise a Johnson Event? We use our own filter to stop HTTP access. // This code was copied from the original "DatabaseCompatibilityEnforcer" Listener // Add a Johnson event to stop any other ServletContextListener's from trying to do anything. final Event event = new Event( EventType.get(JiraStartupChecklist.getFailedStartupCheck().getName()), JiraStartupChecklist.getFailedStartupCheck().getFaultDescription(), EventLevel.get(EventLevel.ERROR)); johnsonProvider.getContainer().addEvent(event); } }
@Override public boolean checkLicenseIsTooOldForBuild() { LicenseCheck.Result result = buildVersionLicenseCheck.evaluate(); if (!result.isPass()) { // then user needs to update their license(s) or confirm the installation under // the Evaluation Terms (Note: the user can always fall back to their previous release of JIRA) String failureMessage = result.getFailureMessage(); log.error(failureMessage); JohnsonEventContainer cont = johnsonProvider.getContainer(); for (LicenseDetails license : result.getFailedLicenses()) { String eventString = license.isEnterpriseLicenseAgreement() ? SUBSCRIPTION_EXPIRED : LICENSE_TOO_OLD; Event newEvent = new Event(EventType.get(eventString), failureMessage, EventLevel.get(EventLevel.ERROR)); cont.addEvent(newEvent); } return true; } else { // licenses are valid for current build or user is in grace (evaluation) period return false; } } }
/** * Checks that the index path exists, and the IndexingListener exists */ private void checkIndexingSetup() throws Exception { final String indexPath = ComponentAccessor.getIndexPathManager().getIndexRootPath(); if (!directoryExists(indexPath)) { log.error("Indexing is turned on, but index path [" + indexPath + "] invalid - disabling indexing"); removeListeners(IssueIndexListener.class); // Mark the index as disabled ComponentAccessor.getComponent(IndexingConfiguration.class).disableIndex(); if (JiraUtils.isSetup()) { final Event event = new Event(EventType.get("reindex"), "The JIRA search index is missing.", EventLevel.get(EventLevel.ERROR)); addJohnsonEvent(event); } return; } // ensure the indexing listener is there ensureSingleListener(IssueIndexListener.class, "Issue Index Listener"); }
final DataImportService.ImportValidationResult result = dataImportService.validateImport(getLoggedInUser(), params); final DataImportAsyncCommand importCallable = new DataImportAsyncCommand(eventCont, dataImportService, getLoggedInUser(), result, new Event(get("setup"), "JIRA is currently being set up", EventLevel.get(WARNING)), velocityRequestContextFactory.getJiraVelocityRequestContext(), getRequest().getSession(false)); Locale locale = getComponentInstanceOfType(JiraAuthenticationContext.class).getLocale();
protected String doExecute() throws Exception { OfBizDelegator ofBizDelegator = ComponentAccessor.getComponent(OfBizDelegator.class); ApplicationProperties applicationProperties = ComponentAccessor.getComponent(ApplicationProperties.class); DataCleaner dataCleaner = new DataCleaner(applicationProperties, ofBizDelegator); dataCleaner.clean(); // Lock JIRA so the server has to be restarted and JohnsonEventContainer cont = johnsonProvider.getContainer(); for (final Object o : cont.getEvents()) { Event event = (Event) o; if (event != null && event.getKey().equals(EventType.get("export-illegal-xml"))) { cont.removeEvent(event); } } Event newEvent = new Event(EventType.get("restart"), "The illegal XML characters have been removed. The server needs to be restarted.", EventLevel.get(EventLevel.ERROR)); cont.addEvent(newEvent); setDataCleaned(true); return getResult(); }
public boolean handleErrorResult(DataImportService.ImportResult lastResult, I18nHelper i18n, ErrorCollection errorCollection) { switch (lastResult.getImportError()) { case UPGRADE_EXCEPTION: final JohnsonEventContainer eventCont = johnsonProvider.getContainer(); final Event errorEvent = new Event(EventType.get("upgrade"), "An error occurred performing JIRA upgrade task", lastResult.getSpecificErrorMessage(), EventLevel.get(EventLevel.ERROR)); if (eventCont != null) { // Use licenseJohnsonEventRaiser to check for specific license errors; if it's not a Johnson problem // report it normally. if (!licenseJohnsonEventRaiser.checkLicenseIsTooOldForBuild()) { eventCont.addEvent(errorEvent); } } return true; case CUSTOM_PATH_EXCEPTION: errorCollection.addErrorMessage(i18n.getText("admin.errors.custom.path", "<a id=\"reimport\" href=\"#\">", "</a>")); return false; case DOWNGRADE_FROM_ONDEMAND: errorCollection.addErrorMessage(i18n.getText("admin.errors.import.downgrade.error", lastResult.getSpecificErrorMessage(), "<a id='acknowledgeDowngradeError' href='#'>", "</a>")); return false; default: return !lastResult.getErrorCollection().hasAnyErrors() && checkLicenseIsInvalidOrTooOldForBuild(); } }