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

GH-2092: Fuseki server #2903

Merged
merged 8 commits into from
Jan 1, 2025
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
Expand Up @@ -65,6 +65,7 @@ public static void delete(File f, boolean reportExistsAfter) {

/**
* Delete all files in a directory.
* Does not recurse in the direction.
* Does nothing if the path name does not exist or is not a directory.
*
* @param dir
Expand All @@ -84,7 +85,7 @@ public static void clearAll(String d) {
clearAll(new File(d)) ;
}

/** Delete all files and directories (recursively) in a directory */
/** Delete all files and directories (recursively) in a directory; does not delete the directory argument. */
public static void clearAll(File d) {
if ( ! d.exists() )
return ;
Expand Down
23 changes: 0 additions & 23 deletions jena-base/src/main/java/org/apache/jena/atlas/net/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,4 @@ public static InetAddress getLocalHostLANAddress() {
throw unknownHostException;
}
}

// @formatter:off
// public static void main(String ... arg) throws UnknownHostException {
// try {
// for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements();) {
// NetworkInterface iface = ifaces.nextElement();
// // Iterate all IP addresses assigned to each card...
// for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
// InetAddress inetAddr = inetAddrs.nextElement();
// System.out.println("IP Address : '" +inetAddr.getHostAddress()+"'");
// }
// }
// System.out.println();
//
// InetAddress inetAddr = getLocalHostLANAddress();
// //InetAddress localhost = InetAddress.getLocalHost();
// System.out.println("System IP Address : '" +inetAddr.getHostAddress()+"'");
// } catch (Exception ex) {
// ex.printStackTrace();
// System.exit(0);
// }
// }
// @formatter:on
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -27,34 +27,33 @@
* @author Neeraj Bajaj, Sun Microsystems
* @version $Id: DatatypeMessageFormatter.java 813087 2009-09-09 19:35:27Z mrglavas $
*/
@SuppressWarnings("unused")
public class DatatypeMessageFormatter {

private static final String BASE_NAME = "org.apache.jena.ext.xerces.impl.msg.DatatypeMessages";

/**
* Formats a message with the specified arguments using the given
* locale information.
*
*
* @param locale The locale of the message.
* @param key The message key.
* @param arguments The message replacement text arguments. The order
* of the arguments must match that of the placeholders
* in the actual message.
*
*
* @return the formatted message.
*
* @throws MissingResourceException Thrown if the message with the
* specified key cannot be found.
*/
public static String formatMessage(Locale locale,
public static String formatMessage(Locale locale,
String key, Object[] arguments)
throws MissingResourceException {

if (locale == null) {
locale = Locale.getDefault();
}
final ResourceBundle resourceBundle =
final ResourceBundle resourceBundle =
ResourceBundle.getBundle(BASE_NAME, locale);

// format message
Expand All @@ -64,14 +63,14 @@ public static String formatMessage(Locale locale,
if (arguments != null) {
try {
msg = java.text.MessageFormat.format(msg, arguments);
}
}
catch (Exception e) {
msg = resourceBundle.getString("FormatFailed");
msg += " " + resourceBundle.getString(key);
}
}
}
}

// error
catch (MissingResourceException e) {
msg = resourceBundle.getString("BadMessageKey");
Expand Down
6 changes: 6 additions & 0 deletions jena-fuseki2/jena-fuseki-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>

<!-- micrometer -->
<dependency>
<groupId>io.micrometer</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ public static void initConsts() {}
public static final String attrNameRegistry = "org.apache.jena.fuseki:DataAccessPointRegistry";
public static final String attrOperationRegistry = "org.apache.jena.fuseki:OperationRegistry";
public static final String attrAuthorizationService = "org.apache.jena.fuseki:AuthorizationService";
// The Fuseki Server
public static final String attrFusekiServer = "org.apache.jena.fuseki:Server";
// The FusekiServerCtl object for the admin area; may be null
public static final String attrFusekiServerCtl = "org.apache.jena.fuseki:ServerCtl";
public static final String attrMetricsProvider = "org.apache.jena.fuseki:MetricsProvider";

public static void setVerbose(ServletContext cxt, boolean verbose) {
cxt.setAttribute(attrVerbose, Boolean.valueOf(verbose));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public static AuthPolicy allowedUsers(Graph graph, Node resource) {
public static List<DataAccessPoint> processServerConfiguration(Graph configuration, Context context) {
Node server = findServer(configuration);
if ( server != null ) {
// XXX Temporary
Resource rServer = resource(configuration, server);
mergeContext(configuration,server, context);
processLoadClass(configuration,server);
Expand All @@ -213,8 +212,6 @@ public static List<DataAccessPoint> processServerConfiguration(Graph configurati
public static List<DataAccessPoint> processServerConfiguration(Model configuration, Context context) {
return processServerConfiguration(configuration.getGraph(), context);
}

// XXX Adapter
/*package*/ static Resource resource(Graph graph, Node node) {
Model m = ModelFactory.createModelForGraph(graph);
RDFNode rNode = m.asRDFNode(node);
Expand Down Expand Up @@ -271,7 +268,7 @@ private static void mergeContext(Graph configuration, Node resource, Context con
}

/**
* Process any {@code ja:loadClass}
* Legacy support for {@code ja:loadClass}
*/
public static void processLoadClass(Graph configuration, Node server) {
if ( server == null )
Expand Down Expand Up @@ -633,7 +630,7 @@ else if ( isResource(ep) ) {
if ( named.size() > 1 )
throw new FusekiConfigException("Multiple property values for <"+FusekiVocabG.pEndpointName+"> with <"+endpointProperty.getURI()+"> for "+BuildLib.displayStr(configuration, svc));
endpointName = named.get(0).getLiteralLexicalForm();
// XXX Necessary? check
// Check for multiple
List<Node> x = G.listSP(configuration, ep, FusekiVocabG.pAllowedUsers);
if ( x.size() > 1 )
throw new FusekiConfigException("Multiple fuseki:"+FusekiVocabG.pAllowedUsers.getLocalName()+" for "+displayStr(configuration, ep));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
package org.apache.jena.fuseki.ctl;

import org.apache.jena.fuseki.metrics.MetricsProviderRegistry;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.metrics.MetricsProvider;
import org.apache.jena.fuseki.servlets.ActionLib;
import org.apache.jena.fuseki.servlets.HttpAction;
import org.apache.jena.fuseki.servlets.ServletOps;
Expand All @@ -42,7 +44,12 @@ public void validate(HttpAction action) {}

@Override
public void execute(HttpAction action) {
MetricsProviderRegistry.get().scrape( action );
MetricsProvider metricsProvider = MetricsProvider.getMetricsProvider(getServletContext());
if ( metricsProvider == null ) {
Log.warn(Fuseki.actionLog, "No metrics provider");
ServletOps.errorOccurred("No metrics provider");
}
metricsProvider.scrape( action );
ServletOps.success(action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,52 @@
*/
package org.apache.jena.fuseki.metrics;

import java.util.Objects;

import io.micrometer.core.instrument.MeterRegistry;
import jakarta.servlet.ServletContext;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.fuseki.Fuseki;
import org.apache.jena.fuseki.server.DataAccessPoint;
import org.apache.jena.fuseki.server.DataAccessPointRegistry;
import org.apache.jena.fuseki.servlets.HttpAction;

/** Micrometer registry and output generator. */
public interface MetricsProvider {
public MeterRegistry getMeterRegistry();
public void scrape(HttpAction action);

/** Bind each data access point in a DataAccessPointRegistry to the system Micrometer {@link MeterRegistry}. */
public default void dataAccessPointMetrics(MetricsProvider metricsProvider, DataAccessPointRegistry dapRegistry) {
try {
dapRegistry.accessPoints().forEach(dap->addDataAccessPointMetrics(dap));
} catch (Throwable th) {
Fuseki.configLog.error("Failed to bind all data access points to netrics provider", th);
}
}

public default void addDataAccessPointMetrics(DataAccessPoint dataAccessPoint) {
MeterRegistry meterRegistry = this.getMeterRegistry();
if (meterRegistry != null )
addDataAccessPointMetrics(meterRegistry, dataAccessPoint);
}

private static void addDataAccessPointMetrics(MeterRegistry meterRegistry, DataAccessPoint dataAccessPoint) {
if ( dataAccessPoint == null )
Log.warn(MetricsProvider.class, "addDataAccessPointMetrics: Null DataAccessPoint");
new FusekiRequestsMetrics(dataAccessPoint).bindTo(meterRegistry);
}

MeterRegistry getMeterRegistry();
void scrape(HttpAction action);
public static void setMetricsProvider(ServletContext servletContext, MetricsProvider provider) {
Objects.requireNonNull(servletContext);
if ( provider == null )
servletContext.removeAttribute(Fuseki.attrMetricsProvider);
else
servletContext.setAttribute(Fuseki.attrMetricsProvider, provider);
}

public static MetricsProvider getMetricsProvider(ServletContext servletContext) {
Objects.requireNonNull(servletContext);
return (MetricsProvider)servletContext.getAttribute(Fuseki.attrMetricsProvider);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jena.fuseki.metrics;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusConfig;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import jakarta.servlet.ServletOutputStream;
import org.apache.jena.fuseki.servlets.HttpAction;
import org.apache.jena.fuseki.servlets.ServletOps;
import org.apache.jena.riot.WebContent;

/**
* Prometheus setup.
*/
public class PrometheusMetricsProvider implements MetricsProvider {

private PrometheusMeterRegistry meterRegistry;

public PrometheusMetricsProvider() {
meterRegistry = new PrometheusMeterRegistry( PrometheusConfig.DEFAULT );
meterRegistry.config().commonTags( "application", "fuseki" );
FusekiMetrics.registerMetrics(meterRegistry);
}

@Override
public MeterRegistry getMeterRegistry() {
return meterRegistry;
}

@Override
public void scrape(HttpAction action) {
try (ServletOutputStream out = action.getResponseOutputStream()) {
ServletOps.success(action);
action.setResponseContentType( WebContent.contentTypeTextPlain );
action.setResponseCharacterEncoding( WebContent.charsetUTF8 );

out.write( meterRegistry.scrape().getBytes() );
} catch (Throwable t) {
ServletOps.errorOccurred( t );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ private void output(StringBuilder sbuff, String fmt, Object...args) {
if ( ! str.endsWith("\n") )
sbuff.append("\n");
}

}
Loading
Loading