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
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,50 @@
* <p>Typical usage:
* <ul>
* <li>Management services call update methods when import/export configuration documents change</li>
* <li>Cleanup paths call {@link #killExistingRoute(String, boolean)} to drop routes whose configs were removed</li>
* <li>Cleanup paths call {@link #killExistingRoute(String, String, boolean)} to drop the route of a tenant's
* removed config; Camel route ids are built by {@link RouteIds}</li>
* </ul>
*
* @since 1.0
*/
public interface IRouterCamelContext {

/**
* Stops and removes an existing Camel route by id, if it is currently registered in the context.
* Stops and removes the Camel route of a tenant's import/export configuration, if it is currently
* registered in the context. A configuration of the same id in another tenant keeps its route.
*
* @param routeId Camel route identifier (usually aligned with import/export configuration id)
* @param tenantId tenant owning the configuration
* @param configId identifier of the import/export configuration whose route is removed
* @param fireEvent when {@code true}, signals that router lifecycle events may be emitted; the concrete
* implementation defines whether events are fired (reserved hook for observability)
* @throws Exception if Camel fails to remove the route definition
*/
void killExistingRoute(String routeId, boolean fireEvent) throws Exception;
void killExistingRoute(String tenantId, String configId, boolean fireEvent) throws Exception;

/**
* Refreshes the profile import reader route for the given configuration: removes any existing route with the
* same id, loads the {@link org.apache.unomi.router.api.ImportConfiguration}, and—for recurrent configs—
* registers a new route built from current settings.
* Refreshes the profile import reader route for the given configuration: removes the existing route of that
* tenant's configuration, loads the {@link org.apache.unomi.router.api.ImportConfiguration}, and—for recurrent
* configs—registers a new route built from current settings. Must be called in the tenant's execution context.
*
* @param tenantId tenant owning the configuration
* @param configId identifier of the import configuration whose reader route should be updated
* @param fireEvent when {@code true}, signals that router lifecycle events may be emitted after the update
* @throws Exception if route removal or registration fails
*/
void updateProfileImportReaderRoute(String configId, boolean fireEvent) throws Exception;
void updateProfileImportReaderRoute(String tenantId, String configId, boolean fireEvent) throws Exception;

/**
* Refreshes the profile export reader (collect) route for the given configuration: removes any existing route
* with the same id, loads the {@link org.apache.unomi.router.api.ExportConfiguration}, and—for recurrent
* configs—registers a new collect route built from current settings.
* Refreshes the profile export reader (collect) route for the given configuration: removes the existing route
* of that tenant's configuration, loads the {@link org.apache.unomi.router.api.ExportConfiguration}, and—for
* recurrent configs—registers a new collect route built from current settings. Must be called in the tenant's
* execution context.
*
* @param tenantId tenant owning the configuration
* @param configId identifier of the export configuration whose reader route should be updated
* @param fireEvent when {@code true}, signals that router lifecycle events may be emitted after the update
* @throws Exception if route removal or registration fails
*/
void updateProfileExportReaderRoute(String configId, boolean fireEvent) throws Exception;
void updateProfileExportReaderRoute(String tenantId, String configId, boolean fireEvent) throws Exception;

/**
* Enables or disables Camel route tracing on the underlying {@code CamelContext} for debugging (message flow,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.unomi.router.api;

import org.apache.unomi.api.ExecutionContext;

import java.util.Objects;

/**
* Identifiers of the Camel routes built from recurrent import/export configurations.
* <p>A configuration identifier is only unique within its tenant, while Camel route identifiers are
* global, so a route is identified by {@code <tenantId>:<configId>}. Tenant identifiers cannot
* contain a colon, which keeps the configuration identifier recoverable whatever it contains.</p>
*/
public final class RouteIds {

private static final char SEPARATOR = ':';

private RouteIds() {
}

/**
* Returns the identifier of the route of a configuration.
*
* @param tenantId the tenant owning the configuration, the system tenant when {@code null}
* @param configId the configuration identifier
* @return the Camel route identifier
* @throws IllegalArgumentException if the tenant identifier contains a colon, which would make the
* configuration identifier impossible to recover from the route identifier
*/
public static String of(String tenantId, String configId) {
Objects.requireNonNull(configId, "configId");
String owner = tenantId != null ? tenantId : ExecutionContext.SYSTEM_TENANT;
if (owner.indexOf(SEPARATOR) >= 0) {
throw new IllegalArgumentException("Tenant identifier must not contain '" + SEPARATOR + "': " + owner);
}
return owner + SEPARATOR + configId;
}

/**
* Returns the identifier of the configuration a route was built from.
*
* @param routeId a Camel route identifier
* @return the configuration identifier, or the route identifier itself for a route that is not
* built from a configuration
*/
public static String configId(String routeId) {
int separator = routeId.indexOf(SEPARATOR);
return separator < 0 ? routeId : routeId.substring(separator + 1);
}
}
Loading
Loading