/** * 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)); }
public String toString() { return "(Event: Level = " + (getLevel() == null ? "" : getLevel() + " ") + ", Key = " + (getKey() == null ? "" : getKey() + " ") + ", Desc = " + (getDesc() == null ? "" : getDesc() + " ") + ", Exception = " + (getException() == null ? "" : getException() + ")"); }
@Override public void makeProgress(long taskProgress, String currentSubTask, String message) { event.setProgress((int) taskProgress); } }
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);
LOG.debug("Searching Johnson for previous {} errors", EventLevel.FATAL); for (Event event : container.getEvents()) { EventLevel level = event.getLevel(); if (EventLevel.FATAL.equals(level.getLevel())) { LOG.error("Bypassing Spring ApplicationContext initialisation; a previous {} error was found: {}", level.getLevel(), event.getDesc()); servletContext.setAttribute(ATTR_BYPASSED, Boolean.TRUE); String message = "The Spring WebApplicationContext will not be started due to a previous " + level.getLevel() + " error"; container.addEvent(new Event(EventType.get(eventType), message, level));
@Override protected boolean matchesSafely(Event item, Description mismatchDescription) { if (item.getDesc() == null || !item.getDesc().contains(eventDescription)) { mismatchDescription.appendValue("Expected to contain description ").appendValue(eventDescription) .appendText(" but was ").appendValue(item.getDesc()); return false; } else { return true; } }
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(); }
@Override protected boolean matchesSafely(Event item, Description mismatchDescription) { return level.equals(item.getLevel().getLevel()); }
private static boolean isLicenseEvent(Event event) { return ImmutableList.of(LICENSE_TOO_OLD, CLUSTERING_UNLICENSED, SUBSCRIPTION_EXPIRED) .stream() .map(EventType::get) .anyMatch(key -> event.getKey().equals(key)); }
startupLog.printMessage(messages, Level.ERROR); final Event event = new Event(EventType.get("index-lock-already-exists"), "An existing index lock was found.", EventLevel.get(EventLevel.ERROR)); event.addAttribute("lockfiles", sb.toString()); addJohnsonEvent(event);
/** * Matches events which have the specified value for a given attribute. If the specified value is {@code null}, * the predicate returns {@code true} iff the event has a {@code null} value for that attribute, which includes * not having any value for that attribute. * * @param name the name of the attribute to check * @param value the expected value, compared with {@code Object.equals} * @return a {@code Predicate} which returns {@code true} for {@link Event events} which have matching values * for the specified attribute, and {@code false} for all others */ @Nonnull public static Predicate<Event> attributeEquals(String name, @Nullable Object value) { requireNonNull(name, "name"); return event -> Objects.equals(value, event.getAttribute(name)); }
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); }
String message = "SpringMVC dispatcher [" + getServletName() + "] will not be started because the Spring WebApplicationContext was not started"; container.addEvent(new Event(EventType.get(eventType), message, EventLevel.get(EventLevel.FATAL))); getServletName(), event.getDesc()); servletContext.setAttribute(getBypassedAttributeName(), Boolean.TRUE); String message = "SpringMVC dispatcher [" + getServletName() + "] will not be started because the Spring WebApplicationContext failed to start"; container.addEvent(new Event(EventType.get(eventType), message, event.getLevel()));
@Override protected boolean matchesSafely(Event item, Description mismatchDescription) { if (!eventDescription.equals(item.getDesc())) { mismatchDescription.appendValue("Expected description ").appendValue(eventDescription) .appendText(" but was ").appendValue(item.getDesc()); return false; } else { return true; } }
/** * Matches events which have any of the specified {@link EventLevel levels}. If no levels are provided, the * predicate will always return {@code false}. * * @param levels the levels to compare against * @return a {@code Predicate} which returns {@code true} for {@link Event events} with one of the specified * levels, and {@code false} for all others */ @Nonnull public static Predicate<Event> level(EventLevel... levels) { requireNonNull(levels, "levels"); if (levels.length == 0) { //Shortcut: If no levels were specified, Set.contains will never be true return event -> false; } Set<EventLevel> acceptedLevels = ImmutableSet.copyOf(levels); return event -> acceptedLevels.contains(event.getLevel()); }
@Override protected boolean matchesSafely(Event item, Description mismatchDescription) { return key.equals(item.getKey().getType()); }
public int hashCode() { return Objects.hash(getKey(), getDesc(), getException(), getLevel(), getDate()); }
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()); }
protected String getStringForEvents(Collection<Event> events) { StringBuilder message = new StringBuilder(); for (Event event : events) { if (message.length() > 0) { message.append("\n"); } message.append(event.getDesc()); } return message.toString(); }
/** * We go through all the johnson events and see if we find any ERROR or FATAL message. * * @return true if the server is reporting errors, false if not */ public boolean hasErrors() { final JohnsonEventContainer johnsonEventContainer = getJohnsonContainer(); if (johnsonEventContainer != null && johnsonEventContainer.hasEvents()) { final Collection<Event> events = johnsonEventContainer.getEvents(); for (Event event : events) { if (event.getLevel() != null) { final String level = event.getLevel().getLevel(); if (EventLevel.ERROR.equals(level) || EventLevel.FATAL.equals(level)) { return true; } } } } return false; }