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

DISPATCH-476: Add support for groupId property for matching link routes and auto links #111

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions include/qpid/dispatch/amqp.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ extern const char * const QD_CONNECTION_PROPERTY_PRODUCT_KEY;
extern const char * const QD_CONNECTION_PROPERTY_PRODUCT_VALUE;
extern const char * const QD_CONNECTION_PROPERTY_VERSION_KEY;
extern const char * const QD_CONNECTION_PROPERTY_COST_KEY;
extern const char * const QD_CONNECTION_PROPERTY_GROUP_KEY;
/// @}

/** @name AMQP error codes. */
Expand Down
1 change: 1 addition & 0 deletions include/qpid/dispatch/router_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ qdr_connection_t *qdr_connection_opened(qdr_core_t *core,
uint64_t management_id,
const char *label,
const char *remote_container_id,
pn_bytes_t group_id,
bool strip_annotations_in,
bool strip_annotations_out,
int link_capacity);
Expand Down
12 changes: 12 additions & 0 deletions python/qpid_dispatch/management/qdrouter.json
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,12 @@
"create": true,
"required": false
},
"groupId": {
"type": "string",
"description": "GroupID for the target container",
"create": true,
"required": false
},
"connection": {
"type": "string",
"description": "The name from a connector or listener",
Expand Down Expand Up @@ -958,6 +964,12 @@
"create": true,
"required": false
},
"groupId": {
"type": "string",
"description": "GroupID for the target container",
"create": true,
"required": false
},
"connection": {
"type": "string",
"description": "The name from a connector or listener",
Expand Down
1 change: 1 addition & 0 deletions src/amqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const char * const QD_CONNECTION_PROPERTY_PRODUCT_KEY = "product";
const char * const QD_CONNECTION_PROPERTY_PRODUCT_VALUE = "qpid-dispatch-router";
const char * const QD_CONNECTION_PROPERTY_VERSION_KEY = "version";
const char * const QD_CONNECTION_PROPERTY_COST_KEY = "qd.inter-router-cost";
const char * const QD_CONNECTION_PROPERTY_GROUP_KEY = "qd.route-container-group";

const qd_amqp_error_t QD_AMQP_OK = { 200, "OK" };
const qd_amqp_error_t QD_AMQP_CREATED = { 201, "Created" };
Expand Down
16 changes: 16 additions & 0 deletions src/router_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ qd_error_t qd_router_configure_link_route(qd_router_t *router, qd_entity_t *enti
char *name = 0;
char *prefix = 0;
char *container = 0;
char *group = 0;
char *c_name = 0;
char *distrib = 0;
char *dir = 0;
Expand All @@ -314,6 +315,7 @@ qd_error_t qd_router_configure_link_route(qd_router_t *router, qd_entity_t *enti
name = qd_entity_opt_string(entity, "name", 0); QD_ERROR_BREAK();
prefix = qd_entity_get_string(entity, "prefix"); QD_ERROR_BREAK();
container = qd_entity_opt_string(entity, "containerId", 0); QD_ERROR_BREAK();
group = qd_entity_opt_string(entity, "groupId", 0); QD_ERROR_BREAK();
c_name = qd_entity_opt_string(entity, "connection", 0); QD_ERROR_BREAK();
distrib = qd_entity_opt_string(entity, "distribution", 0); QD_ERROR_BREAK();
dir = qd_entity_opt_string(entity, "dir", 0); QD_ERROR_BREAK();
Expand All @@ -339,6 +341,11 @@ qd_error_t qd_router_configure_link_route(qd_router_t *router, qd_entity_t *enti
qd_compose_insert_string(body, container);
}

if (group) {
qd_compose_insert_string(body, "groupId");
qd_compose_insert_string(body, group);
}

if (c_name) {
qd_compose_insert_string(body, "connection");
qd_compose_insert_string(body, c_name);
Expand Down Expand Up @@ -386,6 +393,7 @@ qd_error_t qd_router_configure_link_route(qd_router_t *router, qd_entity_t *enti
free(name);
free(prefix);
free(container);
free(group);
free(c_name);
free(distrib);
free(dir);
Expand All @@ -400,6 +408,7 @@ qd_error_t qd_router_configure_auto_link(qd_router_t *router, qd_entity_t *entit
char *addr = 0;
char *dir = 0;
char *container = 0;
char *group = 0;
char *c_name = 0;
char *ext_addr = 0;

Expand All @@ -408,6 +417,7 @@ qd_error_t qd_router_configure_auto_link(qd_router_t *router, qd_entity_t *entit
addr = qd_entity_get_string(entity, "addr"); QD_ERROR_BREAK();
dir = qd_entity_get_string(entity, "dir"); QD_ERROR_BREAK();
container = qd_entity_opt_string(entity, "containerId", 0); QD_ERROR_BREAK();
group = qd_entity_opt_string(entity, "groupId", 0); QD_ERROR_BREAK();
c_name = qd_entity_opt_string(entity, "connection", 0); QD_ERROR_BREAK();
ext_addr = qd_entity_opt_string(entity, "externalAddr", 0); QD_ERROR_BREAK();
long phase = qd_entity_opt_long(entity, "phase", -1); QD_ERROR_BREAK();
Expand Down Expand Up @@ -443,6 +453,11 @@ qd_error_t qd_router_configure_auto_link(qd_router_t *router, qd_entity_t *entit
qd_compose_insert_string(body, container);
}

if (group) {
qd_compose_insert_string(body, "groupId");
qd_compose_insert_string(body, group);
}

if (c_name) {
qd_compose_insert_string(body, "connection");
qd_compose_insert_string(body, c_name);
Expand Down Expand Up @@ -486,6 +501,7 @@ qd_error_t qd_router_configure_auto_link(qd_router_t *router, qd_entity_t *entit
free(addr);
free(dir);
free(container);
free(group);
free(c_name);
free(ext_addr);

Expand Down
22 changes: 19 additions & 3 deletions src/router_core/agent_config_auto_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define QDR_CONFIG_AUTO_LINK_LINK_REF 9
#define QDR_CONFIG_AUTO_LINK_OPER_STATUS 10
#define QDR_CONFIG_AUTO_LINK_LAST_ERROR 11
#define QDR_CONFIG_AUTO_LINK_GROUP_ID 12

const char *qdr_config_auto_link_columns[] =
{"name",
Expand All @@ -49,6 +50,7 @@ const char *qdr_config_auto_link_columns[] =
"linkRef",
"operStatus",
"lastError",
"groupId",
0};

const char *CONFIG_AUTOLINK_TYPE = "org.apache.qpid.dispatch.router.config.autoLink";
Expand Down Expand Up @@ -98,6 +100,7 @@ static void qdr_config_auto_link_insert_column_CT(qdr_auto_link_t *al, int col,

case QDR_CONFIG_AUTO_LINK_CONNECTION:
case QDR_CONFIG_AUTO_LINK_CONTAINER_ID:
case QDR_CONFIG_AUTO_LINK_GROUP_ID:
if (al->conn_id) {
key = (const char*) qd_hash_key_by_handle(al->conn_id->hash_handle);
if (key && key[0] == 'L' && col == QDR_CONFIG_AUTO_LINK_CONNECTION) {
Expand All @@ -108,6 +111,10 @@ static void qdr_config_auto_link_insert_column_CT(qdr_auto_link_t *al, int col,
qd_compose_insert_string(body, &key[1]);
break;
}
if (key && key[0] == 'G' && col == QDR_CONFIG_AUTO_LINK_GROUP_ID) {
qd_compose_insert_string(body, &key[1]);
break;
}
}
qd_compose_insert_null(body);
break;
Expand Down Expand Up @@ -369,6 +376,7 @@ void qdra_config_auto_link_create_CT(qdr_core_t *core,
qd_parsed_field_t *phase_field = qd_parse_value_by_key(in_body, qdr_config_auto_link_columns[QDR_CONFIG_AUTO_LINK_PHASE]);
qd_parsed_field_t *connection_field = qd_parse_value_by_key(in_body, qdr_config_auto_link_columns[QDR_CONFIG_AUTO_LINK_CONNECTION]);
qd_parsed_field_t *container_field = qd_parse_value_by_key(in_body, qdr_config_auto_link_columns[QDR_CONFIG_AUTO_LINK_CONTAINER_ID]);
qd_parsed_field_t *group_field = qd_parse_value_by_key(in_body, qdr_config_auto_link_columns[QDR_CONFIG_AUTO_LINK_GROUP_ID]);
qd_parsed_field_t *external_addr = qd_parse_value_by_key(in_body, qdr_config_auto_link_columns[QDR_CONFIG_AUTO_LINK_EXT_ADDR]);

//
Expand Down Expand Up @@ -409,10 +417,18 @@ void qdra_config_auto_link_create_CT(qdr_core_t *core,
//
// The request is good. Create the entity.
//
bool is_container = !!container_field;
qd_parsed_field_t *in_use_conn = is_container ? container_field : connection_field;
int matcher = QDR_CONN_ID_MATCHER_CONN_LABEL;
qd_parsed_field_t *in_use_conn = connection_field;

if (!!container_field) {
matcher = QDR_CONN_ID_MATCHER_CONTAINER_ID;
in_use_conn = container_field;
} else if (!!group_field) {
matcher = QDR_CONN_ID_MATCHER_GROUP_ID;
in_use_conn = group_field;
}

al = qdr_route_add_auto_link_CT(core, name, addr_field, dir, phase, in_use_conn, is_container, external_addr);
al = qdr_route_add_auto_link_CT(core, name, addr_field, dir, phase, in_use_conn, matcher, external_addr);

//
// Compose the result map for the response.
Expand Down
2 changes: 1 addition & 1 deletion src/router_core/agent_config_auto_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void qdra_config_auto_link_get_CT(qdr_core_t *core,
qd_field_iterator_t *identity,
qdr_query_t *query,
const char *qdr_config_auto_link_columns[]);
#define QDR_CONFIG_AUTO_LINK_COLUMN_COUNT 12
#define QDR_CONFIG_AUTO_LINK_COLUMN_COUNT 13

const char *qdr_config_auto_link_columns[QDR_CONFIG_AUTO_LINK_COLUMN_COUNT + 1];

Expand Down
22 changes: 19 additions & 3 deletions src/router_core/agent_config_link_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define QDR_CONFIG_LINK_ROUTE_CONTAINER_ID 6
#define QDR_CONFIG_LINK_ROUTE_DIR 7
#define QDR_CONFIG_LINK_ROUTE_OPER_STATUS 8
#define QDR_CONFIG_LINK_ROUTE_GROUP_ID 9

const char *qdr_config_link_route_columns[] =
{"name",
Expand All @@ -43,6 +44,7 @@ const char *qdr_config_link_route_columns[] =
"containerId",
"dir",
"operStatus",
"groupId",
0};

const char *CONFIG_LINKROUTE_TYPE = "org.apache.qpid.dispatch.router.config.linkRoute";
Expand Down Expand Up @@ -100,6 +102,7 @@ static void qdr_config_link_route_insert_column_CT(qdr_link_route_t *lr, int col

case QDR_CONFIG_LINK_ROUTE_CONNECTION:
case QDR_CONFIG_LINK_ROUTE_CONTAINER_ID:
case QDR_CONFIG_LINK_ROUTE_GROUP_ID:
if (lr->conn_id) {
key = (const char*) qd_hash_key_by_handle(lr->conn_id->hash_handle);
if (key && key[0] == 'L' && col == QDR_CONFIG_LINK_ROUTE_CONNECTION) {
Expand All @@ -110,6 +113,10 @@ static void qdr_config_link_route_insert_column_CT(qdr_link_route_t *lr, int col
qd_compose_insert_string(body, &key[1]);
break;
}
if (key && key[0] == 'G' && col == QDR_CONFIG_LINK_ROUTE_GROUP_ID) {
qd_compose_insert_string(body, &key[1]);
break;
}
}
qd_compose_insert_null(body);
break;
Expand Down Expand Up @@ -375,6 +382,7 @@ void qdra_config_link_route_create_CT(qdr_core_t *core,
qd_parsed_field_t *distrib_field = qd_parse_value_by_key(in_body, qdr_config_link_route_columns[QDR_CONFIG_LINK_ROUTE_DISTRIBUTION]);
qd_parsed_field_t *connection_field = qd_parse_value_by_key(in_body, qdr_config_link_route_columns[QDR_CONFIG_LINK_ROUTE_CONNECTION]);
qd_parsed_field_t *container_field = qd_parse_value_by_key(in_body, qdr_config_link_route_columns[QDR_CONFIG_LINK_ROUTE_CONTAINER_ID]);
qd_parsed_field_t *group_field = qd_parse_value_by_key(in_body, qdr_config_link_route_columns[QDR_CONFIG_LINK_ROUTE_GROUP_ID]);
qd_parsed_field_t *dir_field = qd_parse_value_by_key(in_body, qdr_config_link_route_columns[QDR_CONFIG_LINK_ROUTE_DIR]);

//
Expand Down Expand Up @@ -408,10 +416,18 @@ void qdra_config_link_route_create_CT(qdr_core_t *core,
//
// The request is good. Create the entity.
//
bool is_container = !!container_field;
qd_parsed_field_t *in_use_conn = is_container ? container_field : connection_field;
int matcher = QDR_CONN_ID_MATCHER_CONN_LABEL;
qd_parsed_field_t *in_use_conn = connection_field;

if (!!container_field) {
matcher = QDR_CONN_ID_MATCHER_CONTAINER_ID;
in_use_conn = container_field;
} else if (!!group_field) {
matcher = QDR_CONN_ID_MATCHER_GROUP_ID;
in_use_conn = group_field;
}

lr = qdr_route_add_link_route_CT(core, name, prefix_field, in_use_conn, is_container, trt, dir);
lr = qdr_route_add_link_route_CT(core, name, prefix_field, in_use_conn, matcher, trt, dir);

//
// Compose the result map for the response.
Expand Down
2 changes: 1 addition & 1 deletion src/router_core/agent_config_link_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void qdra_config_link_route_get_CT(qdr_core_t *core,
qdr_query_t *query,
const char *qdr_config_link_route_columns[]);

#define QDR_CONFIG_LINK_ROUTE_COLUMN_COUNT 9
#define QDR_CONFIG_LINK_ROUTE_COLUMN_COUNT 10

const char *qdr_config_link_route_columns[QDR_CONFIG_LINK_ROUTE_COLUMN_COUNT + 1];

Expand Down
25 changes: 20 additions & 5 deletions src/router_core/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ qdr_connection_t *qdr_connection_opened(qdr_core_t *core,
uint64_t management_id,
const char *label,
const char *remote_container_id,
pn_bytes_t group_id,
bool strip_annotations_in,
bool strip_annotations_out,
int link_capacity)
Expand All @@ -87,6 +88,7 @@ qdr_connection_t *qdr_connection_opened(qdr_core_t *core,
action->args.connection.conn = conn;
action->args.connection.connection_label = qdr_field(label);
action->args.connection.container_id = qdr_field(remote_container_id);
action->args.connection.group_id = qdr_field_with_length(group_id.start, group_id.size);
qdr_action_enqueue(core, action);

return conn;
Expand Down Expand Up @@ -895,6 +897,7 @@ static void qdr_connection_opened_CT(qdr_core_t *core, qdr_action_t *action, boo
//
qdr_field_free(action->args.connection.connection_label);
qdr_field_free(action->args.connection.container_id);
qdr_field_free(action->args.connection.group_id);
return;
}

Expand All @@ -910,6 +913,7 @@ static void qdr_connection_opened_CT(qdr_core_t *core, qdr_action_t *action, boo
conn->role = QDR_ROLE_NORMAL;
qdr_field_free(action->args.connection.connection_label);
qdr_field_free(action->args.connection.container_id);
qdr_field_free(action->args.connection.group_id);
return;
}

Expand All @@ -932,18 +936,29 @@ static void qdr_connection_opened_CT(qdr_core_t *core, qdr_action_t *action, boo
//

//
// If there's a connection label, use it as the identifier. Otherwise, use the remote
// container id.
// The connection identifier is matched in the following order:
// 1. Remote group id property
// 2. Connection label
// 3. Remote container id
//
qdr_field_t *cid = action->args.connection.connection_label ?
action->args.connection.connection_label : action->args.connection.container_id;
qdr_field_t *cid = action->args.connection.group_id;
int matcher = QDR_CONN_ID_MATCHER_GROUP_ID;
if (!cid) {
cid = action->args.connection.connection_label;
matcher = QDR_CONN_ID_MATCHER_CONN_LABEL;
}
if (!cid) {
cid = action->args.connection.container_id;
matcher = QDR_CONN_ID_MATCHER_CONTAINER_ID;
}
if (cid)
qdr_route_connection_opened_CT(core, conn, cid, action->args.connection.connection_label == 0);
qdr_route_connection_opened_CT(core, conn, cid, matcher);
}
}

qdr_field_free(action->args.connection.connection_label);
qdr_field_free(action->args.connection.container_id);
qdr_field_free(action->args.connection.group_id);
}


Expand Down