Skip to content

Commit 48fba7d

Browse files
authored
Merge pull request #2129 from ControlSystemStudio/CSSTUDIO-1511
Olog client information HTTP header
2 parents fbf7fd6 + ff2def6 commit 48fba7d

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@
5555
*/
5656
public class OlogClient implements LogClient {
5757
private static final Logger logger = Logger.getLogger(OlogClient.class.getName());
58-
5958
private final WebResource service;
6059

60+
private static final String OLOG_CLIENT_INFO_HEADER = "X-Olog-Client-Info";
61+
private static final String CLIENT_INFO =
62+
"CS Studio " + org.phoebus.ui.application.Messages.AppVersion + " on " + System.getProperty("os.name");
63+
6164
/**
6265
* Builder Class to help create a olog client.
6366
*
@@ -206,6 +209,7 @@ private LogEntry save(LogEntry log, LogEntry inReplyTo) throws LogbookException
206209
clientResponse = service.path("logs")
207210
.queryParams(queryParams)
208211
.type(MediaType.APPLICATION_JSON)
212+
.header(OLOG_CLIENT_INFO_HEADER, CLIENT_INFO)
209213
.accept(MediaType.APPLICATION_XML)
210214
.accept(MediaType.APPLICATION_JSON)
211215
.put(ClientResponse.class, OlogObjectMappers.logEntrySerializer.writeValueAsString(log));
@@ -303,6 +307,7 @@ private SearchResult findLogs(MultivaluedMap<String, String> searchParams) throw
303307
// Convert List<XmlLog> into List<LogEntry>
304308
final OlogSearchResult ologSearchResult = OlogObjectMappers.logEntryDeserializer.readValue(
305309
service.path("logs/search").queryParams(searchParams)
310+
.header(OLOG_CLIENT_INFO_HEADER, CLIENT_INFO)
306311
.accept(MediaType.APPLICATION_JSON)
307312
.get(String.class),
308313
OlogSearchResult.class);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2020 European Spallation Source ERIC.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
*/
18+
19+
package org.phoebus.logbook.olog.ui.propertyproviders;
20+
21+
import org.phoebus.logbook.Property;
22+
import org.phoebus.logbook.olog.ui.write.LogPropertyProvider;
23+
import org.phoebus.olog.es.api.model.OlogProperty;
24+
import org.phoebus.ui.application.Messages;
25+
26+
import java.net.InetAddress;
27+
import java.net.UnknownHostException;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
import java.util.logging.Level;
31+
import java.util.logging.Logger;
32+
33+
public class ClientEnvironmentPropertyProvider implements LogPropertyProvider {
34+
35+
@Override
36+
public Property getProperty() {
37+
String hostname = "N/A";
38+
try {
39+
hostname = InetAddress.getLocalHost().getHostName();
40+
} catch (UnknownHostException e) {
41+
Logger.getLogger(ClientEnvironmentPropertyProvider.class.getName())
42+
.log(Level.INFO, "Unable to determine hostname", e);
43+
}
44+
Map<String, String> attributes = new HashMap<>();
45+
attributes.put("Hostname", hostname);
46+
attributes.put("Client", "Phoebus " + Messages.AppVersion);
47+
Property property = new OlogProperty("Client Environment", attributes);
48+
return property;
49+
}
50+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (C) 2020 European Spallation Source ERIC.
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
#
18+
19+
org.phoebus.logbook.olog.ui.propertyproviders.ClientEnvironmentPropertyProvider

0 commit comments

Comments
 (0)