Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import message log based on Elasticsearch. #2583

Merged
merged 6 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes = feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.csstudio.eslog.feature"
label="Elasticsearch log viewer"
version="1.0.0.qualifier">

<plugin
id="org.csstudio.logging.es"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.csstudio</groupId>
<artifactId>appunorganized-features</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.csstudio.eslog.feature</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<packaging>pom</packaging>
<modules>
<module>org.csstudio.email.feature</module>
<module>org.csstudio.eslog.feature</module>
<module>org.csstudio.graphene.feature</module>
<module>org.csstudio.utilities.feature</module>
<module>org.csstudio.utilities.rap.feature</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Message History
Bundle-SymbolicName: org.csstudio.logging.es;singleton:=true
Bundle-Description: Table viewer for CSS Message log (Elasticsearch version)
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Michael Ritzert <michael.ritzert@ziti.uni-heidelberg.de>
Bundle-Localization: plugin
Require-Bundle: org.eclipse.jface,
org.eclipse.core.runtime,
org.eclipse.gef,
org.eclipse.ui,
org.eclipse.ui.views,
com.sun.jersey.bundle,
org.csstudio.ui.util,
org.csstudio.apputil,
org.csstudio.apputil.ui,
org.csstudio.opibuilder,
org.csstudio.security,
org.csstudio.platform.libs.jms,
org.csstudio.utility.singlesource
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.csstudio.logging.es.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: org.csstudio.logging.es
Import-Package: javax.ws.rs.core,
org.csstudio.logging,
org.csstudio.opibuilder.widgets.figures,
org.csstudio.platform.utility.jms,
org.csstudio.utility.esclient;version="[1.0.0,2.0.0)",
org.json
Export-Package: org.csstudio.logging.es;version="1.0.0",
org.csstudio.logging.es.model;version="1.0.0",
org.csstudio.logging.es.util;version="1.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
.,\
plugin.xml,\
icons/,\
plugin.properties,\
preferences.ini,\
toc.xml,\
html/
src.includes = icons/,\
html/,\
preferences.ini,\
toc.xml
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MsgHist=Message History (ES)
MsgHistTT=Open Message History (ES)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="CSS"
id="org.csstudio">
</category>
<view
name="%MsgHist"
icon="icons/msg_hist.gif"
category="org.csstudio"
class="org.csstudio.logging.es.MessageHistoryView"
id="org.csstudio.logging.es.MessageHistoryView">
</view>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.csstudio.platform.ui.css.applications"
class="org.csstudio.logging.es.PreferencePage"
id="org.csstudio.logging.es.PreferencePage"
name="%MsgHist">
</page>
</extension>
<extension
point="org.eclipse.help.toc">
<toc
file="toc.xml">
</toc>
</extension>
<extension
point="org.csstudio.opibuilder.widget">
<widget
category="Others"
editpart_class="org.csstudio.logging.es.widget.LogviewEditPart"
icon="icons/logbook.png"
model_class="org.csstudio.logging.es.widget.LogviewModel"
name="Message Log Display"
typeId="org.csstudio.logging.es.widget">
</widget>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.csstudio</groupId>
<artifactId>appunorganized-plugins</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.csstudio.logging.es</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Default preferences

# jms_url=
# Database access
# es_url=
es_index=messagelog
es_mapping=jms

# Table Columns: Property Name, widths, weight
prop_cols=CREATETIME,180,10|DELTA,60,1|SEVERITY,60,1|TEXT,50,400|NAME,50,100|USER,45,10|HOST,50,40|APPLICATION-ID,40,10|CLASS,50,10

# Colors for the severity column: String, R, G, B
severity_colors=SEVERE,255,0,0|WARNING,255,255,0|INFO,255,255,255|CONFIG,255,255,255|FINE,255,255,255|FINER,255,255,255|FINEST,255,255,255

start=-1 hour
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2010 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.csstudio.logging.es;

import java.util.logging.Logger;

import org.eclipse.ui.plugin.AbstractUIPlugin;

public class Activator extends AbstractUIPlugin
{
public static final String ID = "org.csstudio.logging.es"; //$NON-NLS-1$

/** @return Logger for plugin ID */
public static Logger getLogger()
{
return Logger.getLogger(ID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.csstudio.logging.es;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.logging.Level;

import org.csstudio.logging.JMSLogMessage;
import org.csstudio.logging.es.archivedjmslog.ElasticsearchModel;
import org.csstudio.logging.es.archivedjmslog.JMSReceiver;
import org.csstudio.logging.es.archivedjmslog.JMSReceiverPool;
import org.csstudio.logging.es.archivedjmslog.LiveModel;
import org.csstudio.logging.es.model.EventLogMessage;
import org.csstudio.logging.es.model.LogArchiveModel;
import org.csstudio.security.preferences.SecurePreferences;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.swt.widgets.Shell;
import org.json.JSONException;
import org.json.JSONObject;

public class Helpers
{
public final static String[] LOG_LEVELS = new String[] {
Level.FINEST.getLocalizedName(), Level.FINER.getLocalizedName(),
Level.FINE.getLocalizedName(), Level.CONFIG.getLocalizedName(),
Level.INFO.getLocalizedName(), Level.WARNING.getLocalizedName(),
Level.SEVERE.getLocalizedName() };

public static LogArchiveModel createModel(Shell shell)
{
// Read settings from preferences
final IPreferencesService service = Platform.getPreferencesService();
final String url = service.getString(Activator.ID, Preferences.ES_URL,
null, null);
final String index = SecurePreferences.get(Activator.ID,
Preferences.ES_INDEX, null);
final String mapping = SecurePreferences.get(Activator.ID,
Preferences.ES_MAPPING, null);
final String jms_url = service.getString(Activator.ID,
Preferences.JMS_URL, null, null);
final String jms_user = SecurePreferences.get(Activator.ID,
Preferences.JMS_USER, null);
final String jms_password = SecurePreferences.get(Activator.ID,
Preferences.JMS_PASSWORD, null);
final String jms_topic = SecurePreferences.get(Activator.ID,
Preferences.JMS_TOPIC, JMSLogMessage.DEFAULT_TOPIC);

ElasticsearchModel<EventLogMessage> archive = null;
if (null != url)
{
archive = new ElasticsearchModel<EventLogMessage>(url,
index + "/" + mapping, JMSLogMessage.CREATETIME, //$NON-NLS-1$
EventLogMessage::fromElasticsearch)
{
@SuppressWarnings("nls")
@Override
protected JSONObject getTimeQuery(Instant from, Instant to)
throws JSONException
{
SimpleDateFormat df = new SimpleDateFormat(
JMSLogMessage.DATE_FORMAT);
JSONObject timematch = new JSONObject();
timematch.put("gte", df.format(from.toEpochMilli()));
timematch.put("lte", df.format(to.toEpochMilli()));
return new JSONObject().put("range",
new JSONObject().put(this.dateField, timematch));
}

@Override
public EventLogMessage[] getMessages()
{
EventLogMessage[] result = super.getMessages();
Long lastTime = null;
for (EventLogMessage msg : result)
{
Long thisTime = msg.getTime();
if (null != lastTime)
{
msg.setDelta(thisTime - lastTime);
}
lastTime = thisTime;
}
return result;
}
};
}
else
{
Activator.getLogger().config("No archive URL configured."); //$NON-NLS-1$
}

LiveModel<EventLogMessage> live = null;
if (null != jms_url)
{
JMSReceiver receiver = JMSReceiverPool.getReceiver(jms_url,
jms_user, jms_password, jms_topic);
live = new LiveModel<>(receiver, jms_topic,
JMSLogMessage.CREATETIME, EventLogMessage::fromJMS);
}
else
{
Activator.getLogger().config("No JMS URL configured."); //$NON-NLS-1$
}

return new LogArchiveModel(shell, archive, live);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2010 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.csstudio.logging.es;

import org.csstudio.logging.es.archivedjmslog.PropertyFilter;
import org.csstudio.logging.es.gui.GUI;
import org.csstudio.logging.es.model.LogArchiveModel;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

/**
* Eclipse View for the Message History
*
* @author Kay Kasemir
* @author Xihui Chen
*/
public class MessageHistoryView extends ViewPart
{
/** ID under which this view is registered in plugin.xml */
public static final String ID = "org.csstudio.logging.es.MessageHistoryView"; //$NON-NLS-1$

private LogArchiveModel model;

@Override
public void createPartControl(final Composite parent)
{
try
{
this.model = Helpers.createModel(parent.getShell());
final GUI gui = new GUI(getSite(), parent, this.model);
this.model.updateFromArchive();

getSite().setSelectionProvider(gui.getSelectionProvider());
}
catch (Throwable ex)
{
MessageDialog.openError(parent.getShell(), Messages.Error,
ex.getMessage());
}
}

public void setFilters(PropertyFilter[] filters) throws Exception
{
this.model.setFilters(filters);
}

@Override
public void setFocus()
{
// NOP
}

public void setTimeRange(String from, String to) throws Exception
{
this.model.setTimerange(from, to);
}
}
Loading