Skip to content

Commit

Permalink
Remove obsolete code
Browse files Browse the repository at this point in the history
* Remove obsolete constants and methods
* Remove obsolete code regarding setting connection-id in AMQP connection attachments. This has become obsolete since  the removal of the Hono messaging component.

Signed-off-by: Kartheeswaran Kalidass <kartheeswaran.kalidass@bosch.io>
  • Loading branch information
kaniyan committed Nov 2, 2020
1 parent b5c36d8 commit 9757242
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 93 deletions.
83 changes: 0 additions & 83 deletions core/src/main/java/org/eclipse/hono/util/Constants.java
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.hono.auth.HonoUserAdapter;

import io.vertx.proton.ProtonConnection;
import io.vertx.proton.ProtonLink;

/**
* Constants used throughout Hono.
Expand Down Expand Up @@ -98,11 +97,6 @@ public final class Constants {
*/
public static final String HEADER_QOS_LEVEL = "QoS-Level";

/**
* The AMQP capability indicating support for validating registration assertions
* issued by a Device Registration service.
*/
public static final Symbol CAP_REG_ASSERTION_VALIDATION = Symbol.valueOf("hono-reg-assertion");
/**
* The AMQP capability indicating support for routing messages as defined by
* <a href="http://docs.oasis-open.org/amqp/anonterm/v1.0/anonterm-v1.0.html">
Expand All @@ -115,16 +109,6 @@ public final class Constants {
* attachments.
*/
public static final String KEY_CLIENT_PRINCIPAL = "CLIENT_PRINCIPAL";
/**
* The key that the (surrogate) ID of a connection is stored under in a {@code ProtonConnection}'s
* and/or {@code ProtonLink}'s attachments.
*/
public static final String KEY_CONNECTION_ID = "CONNECTION_ID";

/**
* The address that the ID of a connection that has been closed by a client is published to.
*/
public static final String EVENT_BUS_ADDRESS_CONNECTION_CLOSED = "hono.connection.closed";

/**
* The vert.x event bus address that the ID of a tenant that timed out is published to.
Expand Down Expand Up @@ -153,10 +137,6 @@ public final class Constants {
* The qualifier to use for referring to AMQP based components.
*/
public static final String QUALIFIER_AMQP = "amqp";
/**
* The qualifier to use for referring to components scoped to the AMQP 1.0 messaging network.
*/
public static final String QUALIFIER_DOWNSTREAM = "downstream";
/**
* The qualifier to use for referring to HTTP based components.
*/
Expand Down Expand Up @@ -292,67 +272,4 @@ public static void setClientPrincipal(final ProtonConnection con, final HonoUser
attachments.set(KEY_CLIENT_PRINCIPAL, HonoUser.class, principal);
}

/**
* Copies properties from a connection's attachments to a link's attachments.
* <p>
* The properties copied are
* <ul>
* <li>{@link #KEY_CONNECTION_ID}</li>
* </ul>
*
* @param source The connection.
* @param target The link.
*/
public static void copyProperties(final ProtonConnection source, final ProtonLink<?> target) {
Objects.requireNonNull(source);
Objects.requireNonNull(target);
target.attachments().set(Constants.KEY_CONNECTION_ID, String.class, getConnectionId(source));
}

/**
* Gets the (surrogate) identifier of the AMQP connection that a link is part of.
*
* @param link The link to determine the connection id for.
* @return The identifier retrieved from the link's <em>attachment</em> using key {@link #KEY_CONNECTION_ID}
* or {@code null} if the attachments do not contain a value for that a key.
*/
public static String getConnectionId(final ProtonLink<?> link) {
return link.attachments().get(KEY_CONNECTION_ID, String.class);
}

/**
* Gets the (surrogate) identifier of an AMQP connection.
*
* @param connection The connection to determine the connection id for.
* @return The identifier retrieved from the connection's <em>attachments</em> using key {@link #KEY_CONNECTION_ID}
* or {@code null} if the attachments do not contain a value for that a key.
*/
public static String getConnectionId(final ProtonConnection connection) {
return connection.attachments().get(KEY_CONNECTION_ID, String.class);
}

/**
* Sets the (surrogate) identifier of an AMQP connection.
* <p>
* The identifier will be added to the connection's <em>attachments</em> under key
* {@link #KEY_CONNECTION_ID}.
*
* @param connection The connection to set id for.
* @param id The identifier to set.
* @throws NullPointerException if any of the parameters is {@code null}.
*/
public static void setConnectionId(final ProtonConnection connection, final String id) {
Objects.requireNonNull(connection).attachments().set(Constants.KEY_CONNECTION_ID, String.class, Objects.requireNonNull(id));

}

/**
* Checks if a given tenant identifier is the {@code DEFAULT_TENANT}.
*
* @param tenantId The identifier to check.
* @return {@code true} if the given identifier is equal to {@link #DEFAULT_TENANT}.
*/
public static boolean isDefaultTenant(final String tenantId) {
return DEFAULT_TENANT.equals(tenantId);
}
}
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.transport.AmqpError;
Expand Down Expand Up @@ -499,7 +498,6 @@ protected void handleReceiverOpen(final ProtonConnection con, final ProtonReceiv
final HonoUser user = Constants.getClientPrincipal(con);
getAuthorizationService().isAuthorized(user, targetResource, Activity.WRITE).onComplete(authAttempt -> {
if (authAttempt.succeeded() && authAttempt.result()) {
Constants.copyProperties(con, receiver);
receiver.setSource(receiver.getRemoteSource());
receiver.setTarget(receiver.getRemoteTarget());
endpoint.onLinkAttach(con, receiver, targetResource);
Expand Down Expand Up @@ -535,7 +533,6 @@ protected void handleSenderOpen(final ProtonConnection con, final ProtonSender s
final HonoUser user = Constants.getClientPrincipal(con);
getAuthorizationService().isAuthorized(user, targetResource, Activity.READ).onComplete(authAttempt -> {
if (authAttempt.succeeded() && authAttempt.result()) {
Constants.copyProperties(con, sender);
sender.setSource(sender.getRemoteSource());
sender.setTarget(sender.getRemoteTarget());
endpoint.onLinkAttach(con, sender, targetResource);
Expand Down Expand Up @@ -598,8 +595,6 @@ protected void setRemoteConnectionOpenHandler(final ProtonConnection connection)
* <p>
* This default implementation
* <ol>
* <li>adds a unique connection identifier to the connection's attachments
* under key {@link Constants#KEY_CONNECTION_ID}</li>
* <li>invokes {@link #processDesiredCapabilities(ProtonConnection, Symbol[])}</li>
* <li>sets a timer that closes the connection once the client's token
* has expired</li>
Expand All @@ -612,8 +607,6 @@ protected void processRemoteOpen(final ProtonConnection connection) {

log.debug("processing open frame from client container [{}]", connection.getRemoteContainer());
final HonoUser clientPrincipal = Constants.getClientPrincipal(connection);
// attach an ID so that we can later inform downstream components when connection is closed
connection.attachments().set(Constants.KEY_CONNECTION_ID, String.class, UUID.randomUUID().toString());
processDesiredCapabilities(connection, connection.getRemoteDesiredCapabilities());
final Duration delay = Duration.between(Instant.now(), clientPrincipal.getExpirationTime());
final WeakReference<ProtonConnection> conRef = new WeakReference<>(connection);
Expand Down
Expand Up @@ -41,7 +41,6 @@
*/
public class AmqpServiceBaseTest {

private static final String CON_ID = "connection-id";
private static final String ENDPOINT = "anEndpoint";

private Vertx vertx;
Expand Down Expand Up @@ -174,7 +173,6 @@ private static Target getTarget(final ResourceIdentifier targetAddress) {

private static ProtonConnection newConnection(final HonoUser user) {
final Record attachments = new RecordImpl();
attachments.set(Constants.KEY_CONNECTION_ID, String.class, CON_ID);
attachments.set(Constants.KEY_CLIENT_PRINCIPAL, HonoUser.class, user);
final ProtonConnection con = mock(ProtonConnection.class);
when(con.attachments()).thenReturn(attachments);
Expand Down
Expand Up @@ -134,7 +134,6 @@ protected void handleSenderOpen(final ProtonConnection con, final ProtonSender s
if (Constants.SUBJECT_ANONYMOUS.equals(user.getName())) {
con.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS, "client must authenticate using SASL")).close();
} else {
Constants.copyProperties(con, sender);
sender.setSource(sender.getRemoteSource());
endpoint.onLinkAttach(con, sender, targetResource);
}
Expand Down

0 comments on commit 9757242

Please sign in to comment.