qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tr...@apache.org
Subject [30/50] [abbrv] qpid-dispatch git commit: DISPATCH-179 - Added code to update router.link type Patch from Ganesh Murthy.
Date Fri, 18 Mar 2016 23:06:48 GMT
DISPATCH-179 - Added code to update router.link type
Patch from Ganesh Murthy.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/7c2d4e68
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/7c2d4e68
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/7c2d4e68

Branch: refs/heads/master
Commit: 7c2d4e681310f362668af507d08f2127851afc5e
Parents: ab2734f
Author: Ted Ross <tross@redhat.com>
Authored: Tue Mar 15 14:31:40 2016 -0400
Committer: Ted Ross <tross@redhat.com>
Committed: Tue Mar 15 14:31:40 2016 -0400

----------------------------------------------------------------------
 src/router_core/agent.c            |  30 +++++-
 src/router_core/agent_link.c       | 156 ++++++++++++++++++++++++++++++--
 src/router_core/agent_link.h       |   5 +
 src/router_core/management_agent.c |  20 +++-
 4 files changed, 198 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7c2d4e68/src/router_core/agent.c
----------------------------------------------------------------------
diff --git a/src/router_core/agent.c b/src/router_core/agent.c
index 5c20953..835030c 100644
--- a/src/router_core/agent.c
+++ b/src/router_core/agent.c
@@ -27,6 +27,7 @@
 static void qdr_manage_read_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
 static void qdr_manage_create_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
 static void qdr_manage_delete_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
+static void qdr_manage_update_CT(qdr_core_t *core, qdr_action_t *action, bool discard);
 
 //==================================================================================
 // Internal Functions
@@ -154,9 +155,15 @@ void qdr_manage_update(qdr_core_t              *core,
                        qd_field_iterator_t     *name,
                        qd_field_iterator_t     *identity,
                        qd_parsed_field_t       *in_body,
-                       qd_composed_field_t      *out_body)
+                       qd_composed_field_t     *out_body)
 {
+    qdr_action_t *action = qdr_action(qdr_manage_update_CT, "manage_update");
+    action->args.agent.query = qdr_query(core, context, type, out_body);
+    action->args.agent.name = name;
+    action->args.agent.identity = identity;
+    action->args.agent.in_body = in_body;
 
+    qdr_action_enqueue(core, action);
 }
 
 
@@ -364,6 +371,27 @@ static void qdr_manage_delete_CT(qdr_core_t *core, qdr_action_t *action,
bool di
    }
 }
 
+static void qdr_manage_update_CT(qdr_core_t *core, qdr_action_t *action, bool discard)
+{
+    qd_field_iterator_t     *identity   = action->args.agent.identity;
+    qd_field_iterator_t     *name       = action->args.agent.name;
+    qdr_query_t             *query      = action->args.agent.query;
+    qd_parsed_field_t       *in_body    = action->args.agent.in_body;
+
+    switch (query->entity_type) {
+    case QD_ROUTER_CONFIG_ADDRESS:    break;
+    case QD_ROUTER_CONFIG_LINK_ROUTE: break;
+    case QD_ROUTER_CONFIG_AUTO_LINK:  break;
+    case QD_ROUTER_CONNECTION:        break;
+    case QD_ROUTER_LINK:              qdra_link_update_CT(core, name, identity, query, in_body);
break;
+    case QD_ROUTER_ADDRESS:           break;
+    case QD_ROUTER_EXCHANGE:          break;
+    case QD_ROUTER_BINDING:           break;
+   }
+
+    qd_parse_free(in_body);
+}
+
 
 
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7c2d4e68/src/router_core/agent_link.c
----------------------------------------------------------------------
diff --git a/src/router_core/agent_link.c b/src/router_core/agent_link.c
index bfeaa89..33ed2be 100644
--- a/src/router_core/agent_link.c
+++ b/src/router_core/agent_link.c
@@ -70,23 +70,26 @@ static const char *address_key(qdr_address_t *addr)
     return addr && addr->hash_handle ? (const char*) qd_hash_key_by_handle(addr->hash_handle)
: NULL;
 }
 
-
-static void qdr_agent_write_link_CT(qdr_query_t *query,  qdr_link_t *link)
+static void qdr_agent_write_column_CT(qd_composed_field_t *body, int col, qdr_link_t *link)
 {
-    qd_composed_field_t *body = query->body;
+    switch(col) {
 
-    qd_compose_start_list(body);
-    int i = 0;
-    while (query->columns[i] >= 0) {
-        switch(query->columns[i]) {
-        case QDR_LINK_IDENTITY:
         case QDR_LINK_NAME: {
+            if (link->name)
+                qd_compose_insert_string(body, link->name);
+            else
+                qd_compose_insert_null(body);
+            break;
+        }
+
+        case QDR_LINK_IDENTITY: {
             char id[100];
-            snprintf(id, 100, "link.%ld", link->identifier);
+            snprintf(id, 100, "%ld", link->identifier);
             qd_compose_insert_string(body, id);
             break;
         }
 
+
         case QDR_LINK_TYPE:
             qd_compose_insert_string(body, "org.apache.qpid.dispatch.router.link");
             break;
@@ -141,7 +144,17 @@ static void qdr_agent_write_link_CT(qdr_query_t *query,  qdr_link_t *link)
         default:
             qd_compose_insert_null(body);
             break;
-        }
+    }
+}
+
+static void qdr_agent_write_link_CT(qdr_query_t *query,  qdr_link_t *link)
+{
+    qd_composed_field_t *body = query->body;
+
+    qd_compose_start_list(body);
+    int i = 0;
+    while (query->columns[i] >= 0) {
+        qdr_agent_write_column_CT(body, query->columns[i], link);
         i++;
     }
     qd_compose_end_list(body);
@@ -229,3 +242,126 @@ void qdra_link_get_next_CT(qdr_core_t *core, qdr_query_t *query)
     //
     qdr_agent_enqueue_response_CT(core, query);
 }
+
+
+static void qdr_manage_write_response_map_CT(qd_composed_field_t *body, qdr_link_t *link)
+{
+    qd_compose_start_map(body);
+
+    for(int i = 0; i < QDR_LINK_COLUMN_COUNT; i++) {
+        qd_compose_insert_string(body, qdr_link_columns[i]);
+        qdr_agent_write_column_CT(body, i, link);
+    }
+
+    qd_compose_end_map(body);
+}
+
+
+static qdr_link_t *qdr_link_find_by_identity(qdr_core_t *core, qd_field_iterator_t *identity)
+{
+    if (!identity)
+        return 0;
+
+    qdr_link_t *link = DEQ_HEAD(core->open_links);
+
+    while(link) {
+        char id[100];
+        if (link->identifier) {
+            snprintf(id, 100, "%ld", link->identifier);
+            if (qd_field_iterator_equal(identity, (const unsigned char *)id))
+                break;
+        }
+        link = DEQ_NEXT(link);
+    }
+
+    return link;
+
+}
+
+
+static qdr_link_t *qdr_link_find_by_name(qdr_core_t *core, qd_field_iterator_t *name)
+{
+    if(!name)
+        return 0;
+
+    qdr_link_t *link = DEQ_HEAD(core->open_links);
+
+    while(link) {
+        if (link->name && qd_field_iterator_equal(name, (const unsigned char *)link->name))
+            break;
+        link = DEQ_NEXT(link);
+    }
+
+    return link;
+}
+
+
+static void qdra_link_update_set_status(qdr_core_t *core, qdr_query_t *query, qdr_link_t
*link)
+{
+    if (link) {
+        //link->admin_state = qd_field_iterator_copy(adm_state);
+        qdr_manage_write_response_map_CT(query->body, link);
+        query->status = QD_AMQP_OK;
+    }
+    else {
+        query->status = QD_AMQP_NOT_FOUND;
+        qd_compose_start_map(query->body);
+        qd_compose_end_map(query->body);
+    }
+}
+
+static void qdra_link_set_bad_request(qdr_query_t *query)
+{
+    query->status = QD_AMQP_BAD_REQUEST;
+    qd_compose_start_map(query->body);
+    qd_compose_end_map(query->body);
+}
+
+void qdra_link_update_CT(qdr_core_t              *core,
+                             qd_field_iterator_t *name,
+                             qd_field_iterator_t *identity,
+                             qdr_query_t         *query,
+                             qd_parsed_field_t   *in_body)
+
+{
+    // If the request was successful then the statusCode MUST contain 200 (OK) and the body
of the message
+    // MUST contain a map containing the actual attributes of the entity updated. These MAY
differ from those
+    // requested.
+    // A map containing attributes that are not applicable for the entity being created,
or invalid values for a
+    // given attribute, MUST result in a failure response with a statusCode of 400 (Bad Request).
+    if (qd_parse_is_map(in_body)) {
+        // The absence of an attribute name implies that the entity should retain its existing
value.
+        // If the map contains a key-value pair where the value is null then the updated
entity should have no value
+        // for that attribute, removing any previous value.
+
+        qd_parsed_field_t *admin_state = qd_parse_value_by_key(in_body, qdr_link_columns[QDR_LINK_ADMIN_STATE]);
+        if (admin_state) { //admin state is the only field that can be updated via the update
management request
+            //qd_field_iterator_t *adm_state = qd_parse_raw(admin_state);
+
+            if (identity) {
+                qdr_link_t *link = qdr_link_find_by_identity(core, identity);
+                // TODO - set the adm_state on the link
+                qdra_link_update_set_status(core, query, link);
+            }
+            else if (name) {
+                qdr_link_t *link = qdr_link_find_by_name(core, name);
+                // TODO - set the adm_state on the link
+                qdra_link_update_set_status(core, query, link);
+            }
+            else {
+                qdra_link_set_bad_request(query);
+            }
+        }
+        else
+            qdra_link_set_bad_request(query);
+
+    }
+    else
+        query->status = QD_AMQP_BAD_REQUEST;
+
+    //
+    // Enqueue the response.
+    //
+    qdr_agent_enqueue_response_CT(core, query);
+}
+

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7c2d4e68/src/router_core/agent_link.h
----------------------------------------------------------------------
diff --git a/src/router_core/agent_link.h b/src/router_core/agent_link.h
index 2448aad..9cdf391 100644
--- a/src/router_core/agent_link.h
+++ b/src/router_core/agent_link.h
@@ -23,6 +23,11 @@
 
 void qdra_link_get_first_CT(qdr_core_t *core, qdr_query_t *query, int offset);
 void qdra_link_get_next_CT(qdr_core_t *core, qdr_query_t *query);
+void qdra_link_update_CT(qdr_core_t          *core,
+                         qd_field_iterator_t *name,
+                         qd_field_iterator_t *identity,
+                         qdr_query_t         *query,
+                         qd_parsed_field_t   *in_body);
 
 #define QDR_LINK_COLUMN_COUNT  14
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7c2d4e68/src/router_core/management_agent.c
----------------------------------------------------------------------
diff --git a/src/router_core/management_agent.c b/src/router_core/management_agent.c
index 6a8e1a3..4755f13 100644
--- a/src/router_core/management_agent.c
+++ b/src/router_core/management_agent.c
@@ -26,6 +26,7 @@
 #include <qpid/dispatch/dispatch.h>
 #include "router_core_private.h"
 #include "dispatch_private.h"
+#include "agent_link.h"
 #include "alloc.h"
 
 const char *ENTITY = "entityType";
@@ -303,8 +304,23 @@ static void qd_core_agent_create_handler(qdr_core_t                 *core,
 }
 
 
-static void qd_core_agent_update_handler()
+static void qd_core_agent_update_handler(qdr_core_t                 *core,
+                                         qd_message_t               *msg,
+                                         qd_router_entity_type_t     entity_type,
+                                         qd_router_operation_type_t  operation_type,
+                                         qd_field_iterator_t        *identity_iter,
+                                         qd_field_iterator_t        *name_iter)
 {
+    qd_composed_field_t *out_body = qd_compose(QD_PERFORMATIVE_BODY_AMQP_VALUE, 0);
+
+    // Set the callback function.
+    qdr_manage_handler(core, qd_manage_response_handler);
+
+    qd_management_context_t *ctx = qd_management_context(qd_message(), msg, out_body, 0,
core, operation_type, 0);
+
+    qd_parsed_field_t *in_body= qd_parse(qd_message_field_iterator(msg, QD_FIELD_BODY));
+
+    qdr_manage_update(core, ctx, entity_type, name_iter, identity_iter, in_body, out_body);
 
 }
 
@@ -454,7 +470,7 @@ void qdr_management_agent_on_message(void *context, qd_message_t *msg,
int unuse
             qd_core_agent_read_handler(core, msg, entity_type, operation_type, identity_iter,
name_iter);
             break;
         case QD_ROUTER_OPERATION_UPDATE:
-            qd_core_agent_update_handler();
+            qd_core_agent_update_handler(core, msg, entity_type, operation_type, identity_iter,
name_iter);
             break;
         case QD_ROUTER_OPERATION_DELETE:
             qd_core_agent_delete_handler(core, msg, entity_type, operation_type, identity_iter,
name_iter);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message