Skip to content
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ subprojects {
mustacheVersion = '0.9.5_1'
rabbitMqVersion = '5.1.2'
slf4jVersion = '1.7.25'
tamayaVersion = '0.3-incubating'
jwtVersion = '0.9.0'
jaxbVersion = '2.3.0'

Expand Down
3 changes: 3 additions & 0 deletions notifications/trellis-amqp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ ext {

dependencies {
api group: 'com.rabbitmq', name: 'amqp-client', version: rabbitMqVersion
api group: 'org.apache.servicemix.bundles', name: 'org.apache.servicemix.bundles.javax-inject', version: javaxInjectVersion
api project(':trellis-api')

implementation group: 'org.apache.tamaya', name: 'tamaya-api', version: tamayaVersion
implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion

testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
testImplementation group: 'org.apache.commons', name: 'commons-rdf-simple', version: commonsRdfVersion
testImplementation group: 'org.apache.tamaya', name: 'tamaya-core', version: tamayaVersion
testImplementation group: 'org.apiguardian', name: 'apiguardian-api', version: apiguardianVersion
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import java.io.IOException;
import java.util.ServiceLoader;

import javax.inject.Inject;

import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.slf4j.Logger;
import org.trellisldp.api.ActivityStreamService;
import org.trellisldp.api.Event;
Expand All @@ -34,6 +38,14 @@
*/
public class AmqpPublisher implements EventService {

public static final String AMQP_EXCHANGE_NAME = "trellis.amqp.exchangename";

public static final String AMQP_ROUTING_KEY = "trellis.amqp.routingkey";

public static final String AMQP_MANDATORY = "trellis.amqp.mandatory";

public static final String AMQP_IMMEDIATE = "trellis.amqp.immediate";

private static final Logger LOGGER = getLogger(AmqpPublisher.class);

// TODO - JDK9 ServiceLoader::findFirst
Expand All @@ -50,7 +62,22 @@ public class AmqpPublisher implements EventService {
private final Boolean immediate;

/**
* Create a an AMQP publisher.
* Create an AMQP publisher.
* @param channel the channel
*/
@Inject
public AmqpPublisher(final Channel channel) {
this(channel, ConfigurationProvider.getConfiguration());
}

private AmqpPublisher(final Channel channel, final Configuration config) {
this(channel, config.get(AMQP_EXCHANGE_NAME), config.get(AMQP_ROUTING_KEY),
config.getOrDefault(AMQP_MANDATORY, Boolean.class, true),
config.getOrDefault(AMQP_IMMEDIATE, Boolean.class, false));
}

/**
* Create an AMQP publisher.
* @param channel the channel
* @param exchangeName the exchange name
* @param routingKey the routing key
Expand All @@ -60,7 +87,7 @@ public AmqpPublisher(final Channel channel, final String exchangeName, final Str
}

/**
* Create a an AMQP publisher.
* Create an AMQP publisher.
* @param channel the channel
* @param exchangeName the exchange name
* @param routingKey the routing key
Expand All @@ -69,9 +96,9 @@ public AmqpPublisher(final Channel channel, final String exchangeName, final Str
*/
public AmqpPublisher(final Channel channel, final String exchangeName, final String routingKey,
final Boolean mandatory, final Boolean immediate) {
requireNonNull(channel);
requireNonNull(exchangeName);
requireNonNull(routingKey);
requireNonNull(channel, "AMQP Channel may not be null!");
requireNonNull(exchangeName, "AMQP exchange name may not be null!");
requireNonNull(routingKey, "AMQP routing key may not be null!");

this.channel = channel;
this.exchangeName = exchangeName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public void testAmqp() throws IOException {
any(BasicProperties.class), any(byte[].class));
}

@Test
public void testAmqpConfiguration() throws IOException {
final EventService svc = new AmqpPublisher(mockChannel);
svc.emit(mockEvent);

verify(mockChannel).basicPublish(eq(exchangeName), eq(queueName), anyBoolean(), anyBoolean(),
any(BasicProperties.class), any(byte[].class));
}

@Test
public void testError() throws IOException {
doThrow(IOException.class).when(mockChannel).basicPublish(eq(exchangeName), eq(queueName),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trellis.amqp.exchangename=exchange
trellis.amqp.routingkey=queue
3 changes: 3 additions & 0 deletions notifications/trellis-jms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ ext {

dependencies {
api group: 'javax.jms', name: 'javax.jms-api', version: jmsApiVersion
api group: 'org.apache.servicemix.bundles', name: 'org.apache.servicemix.bundles.javax-inject', version: javaxInjectVersion
api project(':trellis-api')

implementation group: 'org.apache.tamaya', name: 'tamaya-api', version: tamayaVersion
implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion

testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
testImplementation group: 'org.apache.activemq', name: 'activemq-client', version: activeMqVersion
testImplementation group: 'org.apache.commons', name: 'commons-rdf-simple', version: commonsRdfVersion
testImplementation group: 'org.apache.tamaya', name: 'tamaya-core', version: tamayaVersion
testImplementation group: 'org.apiguardian', name: 'apiguardian-api', version: apiguardianVersion
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

import java.util.ServiceLoader;

import javax.inject.Inject;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

import org.apache.tamaya.ConfigurationProvider;
import org.slf4j.Logger;
import org.trellisldp.api.ActivityStreamService;
import org.trellisldp.api.Event;
Expand All @@ -37,6 +39,8 @@
*/
public class JmsPublisher implements EventService {

public static final String JMS_QUEUE_NAME = "trellis.jms.queue";

private static final Logger LOGGER = getLogger(JmsPublisher.class);

// TODO - JDK9 ServiceLoader::findFirst
Expand All @@ -49,11 +53,12 @@ public class JmsPublisher implements EventService {
/**
* Create a new JMS Publisher.
* @param conn the connection
* @param queueName the name of the queue
* @throws JMSException when there is a JMS error
*/
public JmsPublisher(final Connection conn, final String queueName) throws JMSException {
this(conn.createSession(false, AUTO_ACKNOWLEDGE), queueName);
@Inject
public JmsPublisher(final Connection conn) throws JMSException {
this(conn.createSession(false, AUTO_ACKNOWLEDGE),
ConfigurationProvider.getConfiguration().get(JMS_QUEUE_NAME));
}

/**
Expand All @@ -63,8 +68,8 @@ public JmsPublisher(final Connection conn, final String queueName) throws JMSExc
* @throws JMSException when there is a JMS error
*/
public JmsPublisher(final Session session, final String queueName) throws JMSException {
requireNonNull(session);
requireNonNull(queueName);
requireNonNull(session, "JMS Session may not be null!");
requireNonNull(queueName, "JMS Queue name may not be null!");

this.session = session;
this.producer = session.createProducer(session.createQueue(queueName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setUp() throws JMSException {

@Test
public void testJms() throws JMSException {
final EventService svc = new JmsPublisher(mockConnection, queueName);
final EventService svc = new JmsPublisher(mockConnection);
svc.emit(mockEvent);

verify(mockProducer).send(eq(mockMessage));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trellis.jms.queue=queue
3 changes: 3 additions & 0 deletions notifications/trellis-kafka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ ext {

dependencies {
api group: 'org.apache.servicemix.bundles', name: 'org.apache.servicemix.bundles.kafka-clients', version: kafkaVersion
api group: 'org.apache.servicemix.bundles', name: 'org.apache.servicemix.bundles.javax-inject', version: javaxInjectVersion
api project(':trellis-api')

implementation group: 'org.apache.tamaya', name: 'tamaya-api', version: tamayaVersion
implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion

testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
testImplementation group: 'org.apache.commons', name: 'commons-rdf-simple', version: commonsRdfVersion
testImplementation group: 'org.apache.tamaya', name: 'tamaya-core', version: tamayaVersion
testImplementation group: 'org.apiguardian', name: 'apiguardian-api', version: apiguardianVersion
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

import java.util.ServiceLoader;

import javax.inject.Inject;

import org.apache.commons.rdf.api.IRI;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.tamaya.ConfigurationProvider;
import org.slf4j.Logger;
import org.trellisldp.api.ActivityStreamService;
import org.trellisldp.api.Event;
Expand All @@ -31,6 +34,8 @@
*/
public class KafkaPublisher implements EventService {

public static final String KAFKA_TOPIC = "trellis.kafka.topic";

private static final Logger LOGGER = getLogger(KafkaPublisher.class);

// TODO - JDK9 ServiceLoader::findFirst
Expand All @@ -42,11 +47,20 @@ public class KafkaPublisher implements EventService {
/**
* Create a new Kafka Publisher.
* @param producer the producer
* @param topicName the name of the topic
*/
@Inject
public KafkaPublisher(final Producer<String, String> producer) {
this(producer, ConfigurationProvider.getConfiguration().get(KAFKA_TOPIC));
}

/**
* Create a new Kafka Publisher.
* @param producer the producer
* @param topicName the name of the kafka topic
*/
public KafkaPublisher(final Producer<String, String> producer, final String topicName) {
requireNonNull(producer);
requireNonNull(topicName);
requireNonNull(producer, "Kafka producer may not be null!");
requireNonNull(topicName, "Kafka topic name may not be null!");

this.producer = producer;
this.topicName = topicName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void setUp() {

@Test
public void testKafka() {
final EventService svc = new KafkaPublisher(producer, queueName);
final EventService svc = new KafkaPublisher(producer);
svc.emit(mockEvent);

final List<ProducerRecord<String, String>> records = producer.history();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trellis.kafka.topic=queue
7 changes: 7 additions & 0 deletions trellis-agent/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
5 changes: 3 additions & 2 deletions trellis-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ dependencies {
compile group: 'io.dropwizard', name: 'dropwizard-metrics', version: dropwizardVersion
compile group: 'io.dropwizard', name: 'dropwizard-http2', version: dropwizardVersion
compile group: 'io.jsonwebtoken', name: 'jjwt', version: jwtVersion
compile group: 'org.apache.activemq', name: 'activemq-client', version: activeMqVersion
compile group: 'org.apache.commons', name: 'commons-rdf-jena', version: commonsRdfVersion
compile group: 'org.apache.jena', name: 'jena-osgi', version: jenaVersion
compile group: 'org.apache.jena', name: 'jena-tdb2', version: jenaVersion
compile group: 'org.apache.commons', name: 'commons-rdf-jena', version: commonsRdfVersion
compile group: 'org.apache.activemq', name: 'activemq-client', version: activeMqVersion
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion

compile project(":trellis-constraint-rules")
Expand All @@ -42,6 +42,7 @@ dependencies {
testCompile group: 'io.dropwizard', name: 'dropwizard-client', version: dropwizardVersion
testCompile group: 'io.dropwizard', name: 'dropwizard-testing', version: dropwizardVersion
testCompile group: 'org.apiguardian', name: 'apiguardian-api', version: apiguardianVersion
testImplementation group: 'org.apache.tamaya', name: 'tamaya-core', version: tamayaVersion
testImplementation group: 'org.awaitility', name: 'awaitility', version: awaitilityVersion
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: junitPlatformVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static com.google.common.cache.CacheBuilder.newBuilder;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.concurrent.TimeUnit.HOURS;
import static org.trellisldp.app.TrellisUtils.getAuthFilters;
import static org.trellisldp.app.TrellisUtils.getCorsConfiguration;
Expand Down Expand Up @@ -84,46 +83,44 @@ public void run(final TrellisConfiguration config,

final RDFConnection rdfConnection = getRDFConnection(config);

final String mementoLocation = config.getMementos();

final String baseUrl = config.getBaseUrl();

final IdentifierService idService = new UUIDGenerator();

final MementoService mementoService = new FileMementoService(mementoLocation);
final MementoService mementoService = new FileMementoService(config.getMementos());

final TriplestoreResourceService resourceService = new TriplestoreResourceService(rdfConnection, idService,
mementoService, notificationService);

final NamespaceService namespaceService = new NamespacesJsonContext(config.getNamespaces());

final BinaryService binaryService = new FileBinaryService(config.getBinaries(), idService,
final BinaryService binaryService = new FileBinaryService(idService, config.getBinaries(),
config.getBinaryHierarchyLevels(), config.getBinaryHierarchyLength());

// IO Service
final CacheService<String, String> profileCache = new TrellisCache<>(newBuilder()
.maximumSize(config.getJsonld().getCacheSize())
.expireAfterAccess(config.getJsonld().getCacheExpireHours(), HOURS).build());
final IOService ioService = new JenaIOService(namespaceService, TrellisUtils.getAssetConfiguration(config),
config.getJsonld().getContextWhitelist(), config.getJsonld().getContextDomainWhitelist(), profileCache);
final IOService ioService = new JenaIOService(namespaceService, profileCache,
TrellisUtils.getAssetConfiguration(config));

// Health checks
environment.healthChecks().register("rdfconnection", new RDFConnectionHealthCheck(rdfConnection));

getAuthFilters(config).ifPresent(filters -> environment.jersey().register(new ChainedAuthFilter<>(filters)));

// Resource matchers
environment.jersey()
.register(new LdpResource(resourceService, ioService, binaryService, resourceService, baseUrl));
environment.jersey().register(new LdpResource(resourceService, ioService, binaryService, resourceService,
config.getBaseUrl()));

// Filters
environment.jersey().register(new AgentAuthorizationFilter(new SimpleAgent(), emptyList()));
environment.jersey().register(new AgentAuthorizationFilter(new SimpleAgent()));
environment.jersey().register(new CacheControlFilter(config.getCacheMaxAge()));

// Authorization
getWebacConfiguration(config).ifPresent(webacCache ->
environment.jersey().register(new WebAcFilter(
asList("Authorization"), new WebACService(resourceService, webacCache))));
getWebacConfiguration(config).ifPresent(webacCache -> {
final WebAcFilter filter = new WebAcFilter(new WebACService(resourceService, webacCache));
filter.setChallenges(asList("Authorization"));
environment.jersey().register(filter);
});

// CORS
getCorsConfiguration(config).ifPresent(cors -> environment.jersey().register(
Expand Down
Loading