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

⬆️ [Dependencies] Upgrade Artemis from 2.31.2 to 2.38.0 #4087

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
27 changes: 27 additions & 0 deletions assembly/broker-artemis/configurations/broker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@
-->
<!-- allowLinkStealing=true -->

<!-- CLUSTER CONFIGURATION NOTES -->
<!-- The current Kapua deployment deploys a broker with 2 consumers (Lifecycle and Telemetry) plus the Authentication service.
If a cluster is needed, the following steps could be followed:
- change the run-broker script, section "/opt/artemis/bin/artemis create \", (of the broker container) to create the cluster simply adding "-clustered" option and changing cluster username and password.
(see https://activemq.apache.org/components/artemis/documentation/latest/using-server.html#creating-a-broker-instance)
- change this configuration file adding the cluster connectors as per cluster topology
(see https://activemq.apache.org/components/artemis/documentation/latest/clusters.html)
- change the consumer/service connection string according to the documentation
(see section 3.2.2 of the link https://activemq.apache.org/components/artemis/documentation/latest/clusters.html)
NOTE: The consumers/service could be scaled up also and independently each from the others.
IMPORTANT NOTE: while clustering pay attention to the performances as described in chapter 2 of the link https://activemq.apache.org/components/artemis/documentation/latest/clusters.html.
-->
<!-- disable caching at all, otherwise we'll have issues while managing stealing link:
the remove connection (ServerPlugin#afterDestroyConnection) is called without calling the authenticate (SecurityPlugin#authenticate).
TODO do further tests to check the performance impact and try to enable authorization cache only -->
Expand Down Expand Up @@ -162,5 +174,20 @@
</anycast>
</address>
</addresses>

<!-- Uncomment the following if you want to use the Standard LoggingActiveMQServerPlugin pluging to log in events
<broker-plugins>
<broker-plugin class-name="org.apache.activemq.artemis.core.server.plugin.impl.LoggingActiveMQServerPlugin">
<property key="LOG_ALL_EVENTS" value="true"/>
<property key="LOG_CONNECTION_EVENTS" value="true"/>
<property key="LOG_SESSION_EVENTS" value="true"/>
<property key="LOG_CONSUMER_EVENTS" value="true"/>
<property key="LOG_DELIVERING_EVENTS" value="true"/>
<property key="LOG_SENDING_EVENTS" value="true"/>
<property key="LOG_INTERNAL_EVENTS" value="true"/>
</broker-plugin>
</broker-plugins>
-->

</core>
</configuration>
31 changes: 31 additions & 0 deletions assembly/broker-artemis/configurations/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2020, 2022 Red Hat Inc and others

This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

Contributors:
Red Hat Inc - initial API and implementation
Eurotech
-->
<!DOCTYPE xml>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<logger name="liquibase" level="WARN"/>
<logger name="org.apache.activemq.audit.base" level="WARN"/>
<logger name="org.apache.activemq.audit.message" level="WARN"/>
<logger name="org.apache.activemq.audit.resource" level="WARN"/>

<root level="INFO">
<appender-ref ref="console"/>
</root>
</configuration>
13 changes: 9 additions & 4 deletions assembly/broker-artemis/descriptors/kapua-broker-artemis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
<outputDirectory>/opt/artemis</outputDirectory>
<directory>${project.build.directory}/dependencies/artemis/apache-artemis-${artemis.version}</directory>
<fileMode>0644</fileMode>
<!-- <excludes>
<excludes>
<exclude>lib/log4j-over-slf4j-*.jar</exclude>
<exclude>lib/log4j-core-*.jar</exclude>
<exclude>lib/log4j-slf4j-impl-*.jar</exclude>
<exclude>lib/log4j-slf4j2-impl-*.jar</exclude>
<!--
<exclude>activemq-all-*</exclude>
<exclude>webapps-demo/</exclude>
</excludes> -->
-->
</excludes>
</fileSet>

<fileSet>
Expand All @@ -65,8 +71,7 @@
<includes>
<include>ch.qos.logback:logback-core</include>
<include>ch.qos.logback:logback-classic</include>
<include>org.slf4j:log4j-over-slf4j</include>
<include>org.slf4j:slf4j-api</include>
<include>org.apache.logging.log4j:log4j-to-slf4j</include>
<include>commons-io:commons-io</include>
<include>commons-configuration:commons-configuration</include>
<include>commons-lang:commons-lang</include>
Expand Down
4 changes: 0 additions & 4 deletions assembly/broker-artemis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2022 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kapua.broker.artemis.plugin.security;

import org.eclipse.kapua.broker.artemis.plugin.security.connector.AcceptorHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Class to intercept Broker lifecycle events
*/
public class ActivateCallback implements org.apache.activemq.artemis.core.server.ActivateCallback {

private final Logger logger = LoggerFactory.getLogger(ActivateCallback.class);

Check warning on line 24 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java#L24

Added line #L24 was not covered by tests

private final AcceptorHandler acceptorHandler;

public ActivateCallback(AcceptorHandler acceptorHandler) {
this.acceptorHandler = acceptorHandler;
}

Check warning on line 30 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java#L28-L30

Added lines #L28 - L30 were not covered by tests

@Override
/**
* Use this callback to start Acceptors for now (but could be used to do whatever needs to have a fully running broker
*/
public void activationComplete() {
logger.info("Broker activation completed!");
org.apache.activemq.artemis.core.server.ActivateCallback.super.activationComplete();
logger.info("Creating acceptors...");

Check warning on line 39 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java#L37-L39

Added lines #L37 - L39 were not covered by tests
try {
acceptorHandler.syncAcceptors();
} catch (Exception e) {
logger.error("Creating acceptors... ERROR: {}", e.getMessage(), e);

Check warning on line 43 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java#L41-L43

Added lines #L41 - L43 were not covered by tests
//TODO throw runtime? the broker doesn't work properly if not all the acceptors are created
}
logger.info("Creating acceptors... DONE");
}

Check warning on line 47 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ActivateCallback.java#L45-L47

Added lines #L45 - L47 were not covered by tests

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@
username, connectionInfo.getClientId(), connectionInfo.getClientIp(), remotingConnection.getID(),
remotingConnection.getTransportConnection().getRemoteAddress(), remotingConnection.getTransportConnection().isOpen());
//TODO double check why the client id is null once coming from AMQP connection (the Kapua connection factory with custom client id generation is called)
KapuaPrincipal kapuaPrincipal = buildInternalKapuaPrincipal(getAdminAccountInfo().getId(), username, connectionInfo.getClientId());
//auto generate client id if null. It shouldn't be null but in some case the one from JMS connection is.
String clientId = connectionInfo.getClientId();
//set a random client id value if not set by the client
//from JMS 2 specs "Although setting client ID remains mandatory when creating an unshared durable subscription, it is optional when creating a shared durable subscription."
if (Strings.isNullOrEmpty(clientId)) {
clientId = clientIdPrefix + INDEX.getAndIncrement();
logger.info("Updated empty client id to: {}", clientId);
}
KapuaPrincipal kapuaPrincipal = buildInternalKapuaPrincipal(getAdminAccountInfo().getId(), username, clientId);

Check warning on line 160 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/SecurityPlugin.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/SecurityPlugin.java#L160

Added line #L160 was not covered by tests
//auto generate client id if null. It shouldn't be null but in some case the one from JMS connection is.
//update client id with account|clientId (see pattern)
String fullClientId = Utils.getFullClientId(getAdminAccountInfo().getId(), clientId);
remotingConnection.setClientID(fullClientId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
serverContext.init(server);
acceptorHandler = new AcceptorHandler(server,
brokerSetting.getMap(String.class, BrokerSettingKey.ACCEPTORS));
//init acceptors
acceptorHandler.syncAcceptors();
//init activateCallback to handle acceptor initialization instead of calling it from here
server.registerActivateCallback(new ActivateCallback(acceptorHandler));

Check warning on line 141 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ServerPlugin.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ServerPlugin.java#L141

Added line #L141 was not covered by tests

deviceConnectionEventListenerService.addReceiver(serviceEvent -> processDeviceConnectionEvent(serviceEvent));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,29 @@
* @throws Exception
*/
public void syncAcceptors() throws Exception {
logger.info("Init acceptors... server started: {} - {}", server.isStarted(), server.getState());
if (server.isStarted()) {
List<String> acceptorToRemove = new ArrayList<>();
server.getConfiguration().getAcceptorConfigurations().forEach(tc -> {
String acceptorName = tc.getName();
logger.info("Checking acceptor {}", acceptorName);
if (definedAcceptors.get(acceptorName) == null) {
acceptorToRemove.add(acceptorName);
logger.info("Adding acceptor {} to the remove list", acceptorName);
} else {
logger.info("Leaving acceptor {} running", acceptorName);
}
});
acceptorToRemove.forEach(acceptorName -> {
logger.info("Stopping acceptor {}...", acceptorName);
try {
server.getRemotingService().getAcceptor(acceptorName).stop();
server.getRemotingService().destroyAcceptor(acceptorName);
TransportConfiguration tc = getByName(acceptorName);
server.getConfiguration().getAcceptorConfigurations().remove(tc);
} catch (Exception e) {
logger.error("Error stopping acceptor {}... Error: {}", acceptorName, e.getMessage(), e);
}
logger.info("Stopping acceptor {}... DONE", acceptorName);
});
}
List<String> acceptorToRemove = new ArrayList<>();
server.getConfiguration().getAcceptorConfigurations().forEach(tc -> {
String acceptorName = tc.getName();
logger.info("Checking acceptor {}", acceptorName);

Check warning on line 89 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java#L86-L89

Added lines #L86 - L89 were not covered by tests
if (definedAcceptors.get(acceptorName) == null) {
acceptorToRemove.add(acceptorName);
logger.info("Adding acceptor {} to the remove list", acceptorName);

Check warning on line 92 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java#L91-L92

Added lines #L91 - L92 were not covered by tests
} else {
logger.info("Leaving acceptor {} running", acceptorName);

Check warning on line 94 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java#L94

Added line #L94 was not covered by tests
}
});
acceptorToRemove.forEach(acceptorName -> {
logger.info("Stopping acceptor {}...", acceptorName);

Check warning on line 98 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java#L96-L98

Added lines #L96 - L98 were not covered by tests
try {
server.getRemotingService().getAcceptor(acceptorName).stop();
server.getRemotingService().destroyAcceptor(acceptorName);
TransportConfiguration tc = getByName(acceptorName);
server.getConfiguration().getAcceptorConfigurations().remove(tc);
} catch (Exception e) {
logger.error("Error stopping acceptor {}... Error: {}", acceptorName, e.getMessage(), e);
}
logger.info("Stopping acceptor {}... DONE", acceptorName);
});

Check warning on line 108 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/connector/AcceptorHandler.java#L100-L108

Added lines #L100 - L108 were not covered by tests
// server.getConfiguration().clearAcceptorConfigurations();

definedAcceptors.forEach((name, uri) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@
private static final char ANY_WORDS = '#';
private static final char SEPARATOR = '/';

private final LoginMetric loginMetric;
private final WildcardConfiguration wildcardConfiguration;
private final HierarchicalRepository<KapuaPrincipal> read;
private final HierarchicalRepository<KapuaPrincipal> write;
private final HierarchicalRepository<KapuaPrincipal> admin;

public Acl(LoginMetric loginMetric, KapuaPrincipal principal, List<AuthAcl> authAcls) throws KapuaIllegalArgumentException {
this.loginMetric = loginMetric;
wildcardConfiguration = new WildcardConfiguration();
wildcardConfiguration.setSingleWord(SINGLE_WORD);
wildcardConfiguration.setAnyWords(ANY_WORDS);
wildcardConfiguration.setDelimiter(SEPARATOR);
wildcardConfiguration = new WildcardConfiguration().
setSingleWord(SINGLE_WORD).
setAnyWords(ANY_WORDS).
setDelimiter(SEPARATOR);

Check warning on line 45 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/context/Acl.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/context/Acl.java#L42-L45

Added lines #L42 - L45 were not covered by tests
if (principal == null) {
throw new KapuaIllegalArgumentException("principal", null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
*
* @since 1.0
*/
public class KapuaPrincipalImpl implements KapuaPrincipal {
public class KapuaPrincipalImpl extends org.apache.activemq.artemis.spi.core.security.jaas.UserPrincipal implements KapuaPrincipal {

private static final long serialVersionUID = -2120917772921438176L;

private String name;
private String clientId;
private boolean internal;
/**
Expand All @@ -45,7 +44,7 @@
* @param authResponse
*/
public KapuaPrincipalImpl(AuthResponse authResponse) {
name = authResponse.getUsername() + "@" + authResponse.getClientId();
super(authResponse.getUsername() + "@" + authResponse.getClientId());

Check warning on line 47 in client/security/src/main/java/org/eclipse/kapua/client/security/bean/KapuaPrincipalImpl.java

View check run for this annotation

Codecov / codecov/patch

client/security/src/main/java/org/eclipse/kapua/client/security/bean/KapuaPrincipalImpl.java#L47

Added line #L47 was not covered by tests
clientId = authResponse.getClientId();
accessTokenId = authResponse.getAccessTokenId();
userId = KapuaEid.parseCompactId(authResponse.getUserId());
Expand All @@ -61,17 +60,12 @@
* @param clientId
*/
public KapuaPrincipalImpl(KapuaId accountId, String username, String clientId) {
super(username + "@" + clientId);

Check warning on line 63 in client/security/src/main/java/org/eclipse/kapua/client/security/bean/KapuaPrincipalImpl.java

View check run for this annotation

Codecov / codecov/patch

client/security/src/main/java/org/eclipse/kapua/client/security/bean/KapuaPrincipalImpl.java#L63

Added line #L63 was not covered by tests
internal = true;
this.accountId = accountId;
name = username + "@" + clientId;
this.clientId = clientId;
}

@Override
public String getName() {
return name;
}

@Override
public String getTokenId() {
return accessTokenId;
Expand Down Expand Up @@ -110,7 +104,7 @@
@Override
public int hashCode() {
//name is unique so let's use it for hashing
return (name == null ? 0 : name.hashCode());
return (getName() == null ? 0 : getName().hashCode());
}

@Override
Expand All @@ -125,11 +119,11 @@
return false;
}
KapuaPrincipalImpl other = (KapuaPrincipalImpl) obj;
if (name == null) {
if (other.name != null) {
if (getName() == null) {
if (other.getName() != null) {
return false;
}
} else if (!name.equals(other.name)) {
} else if (!getName().equals(other.getName())) {
return false;
}
return true;
Expand Down
15 changes: 8 additions & 7 deletions consumer/lifecycle-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,6 @@
</filter>
</filters>
<transformers>
<!-- added by 2.7 -->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
<resource>META-INF/persistence.xml</resource>
</transformer>
Expand Down Expand Up @@ -507,6 +500,14 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/org.eclipse.kapua.translator.Translator</resource>
</transformer>

<!-- add by 2.7 -->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports</resource>
</transformer>
<!--
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</bean>

<bean id="connectionFactory" class="org.eclipse.kapua.service.client.amqp.ServiceConnectionFactoryImpl">
<constructor-arg name="schema" type="java.lang.String" value="amqp"/>
<constructor-arg name="host" type="java.lang.String" value="${BROKER_HOST}"/>
<constructor-arg name="port" type="int" value="${BROKER_PORT}"/>
<constructor-arg name="username" type="java.lang.String" value="${BROKER_INTERNAL_USERNAME}"/>
Expand Down
Loading
Loading