You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2013/10/08 21:26:45 UTC
svn commit: r1530401 - in /incubator/celix/trunk/remote_services:
discovery_bonjour/private/src/ example_endpoint/private/src/
example_proxy/private/src/ example_service/public/include/
remote_service_admin/private/src/
Author: pnoltes
Date: Tue Oct 8 19:26:44 2013
New Revision: 1530401
URL: http://svn.apache.org/r1530401
Log:
CELIX-89:
- Aligned RSA, endpoint,proxy, example service and discovery with amdatu remote services.
- Updated discovery to that added endpoint listeners will be informed about existing discovered endpoints.
Modified:
incubator/celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c
incubator/celix/trunk/remote_services/example_endpoint/private/src/example_endpoint_impl.c
incubator/celix/trunk/remote_services/example_proxy/private/src/example_proxy_impl.c
incubator/celix/trunk/remote_services/example_service/public/include/example_service.h
incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c
Modified: incubator/celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c?rev=1530401&r1=1530400&r2=1530401&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c (original)
+++ incubator/celix/trunk/remote_services/discovery_bonjour/private/src/discovery.c Tue Oct 8 19:26:44 2013
@@ -126,7 +126,7 @@ celix_status_t discovery_create(apr_pool
char *port = NULL;
bundleContext_getProperty(context, "DISCOVERY_PORT", &port);
if (port == NULL) {
- (*discovery)->discoveryPort = DEFAULT_DISCOVERY_PORT;
+ (*discovery)->discoveryPort = (char *)DEFAULT_DISCOVERY_PORT;
} else {
(*discovery)->discoveryPort = apr_pstrdup(pool, port);
}
@@ -316,6 +316,27 @@ celix_status_t discovery_endpointListene
printf("DISCOVERY: EndpointListener Ignored - Discovery listener\n");
} else {
printf("DISCOVERY: EndpointListener Added - Add Scope\n");
+
+ apr_thread_mutex_lock(discovery->discoveredServicesMutex);
+ if (discovery->discoveredServices != NULL) {
+ hash_map_iterator_pt iter = hashMapIterator_create(discovery->discoveredServices);
+ while (hashMapIterator_hasNext(iter)) {
+ endpoint_description_pt endpoint = hashMapIterator_nextKey(iter);
+ endpoint_listener_pt listener = service;
+
+ char *scope = properties_get(serviceProperties,
+ (char *) ENDPOINT_LISTENER_SCOPE);
+ filter_pt filter = filter_create(scope, discovery->pool); //FIXME memory leak
+ bool matchResult = false;
+ filter_match(filter, endpoint->properties, &matchResult);
+ if (matchResult) {
+ listener->endpointAdded(listener, endpoint, NULL);
+ }
+ }
+ hashMapIterator_destroy(iter);
+ }
+ apr_thread_mutex_unlock(discovery->discoveredServicesMutex);
+
apr_thread_mutex_lock(discovery->listenerReferencesMutex);
if (discovery->listenerReferences != NULL) {
hashMap_put(discovery->listenerReferences, reference, NULL /*TODO is the scope value needed?*/);
@@ -441,21 +462,21 @@ static void discovery_resolveAddCallback
properties_set(props, key, valueBuf);
}
- //check if framework uuid is not this framework uuid
- char *endpointUuid = properties_get(props, (char *)ENDPOINT_FRAMEWORK_UUID);
+ char *endpointFrameworkUuid = properties_get(props, (char *)ENDPOINT_FRAMEWORK_UUID);
- if (endpointUuid == NULL) {
+ if (endpointFrameworkUuid == NULL) {
printf("DISCOVERY: Cannot process endpoint, no %s property\n", ENDPOINT_FRAMEWORK_UUID);
- } else if (strcmp(endpointUuid, discovery->frameworkUuid) != 0) {
+ } else if (strcmp(endpointFrameworkUuid, discovery->frameworkUuid) != 0) {
apr_pool_t *childPool = NULL;
apr_pool_create(&childPool, discovery->pool);
discovered_endpoint_entry_pt entry = apr_palloc(childPool, sizeof(*entry));
endpoint_description_pt endpoint = apr_palloc(childPool, sizeof(*endpoint));
- //FIXME endpoint id for http should be the url
-// endpoint->id = apr_pstrdup(childPool, fullname);
- endpoint->id = properties_get(props, "url");
- endpoint->serviceId = 0 /*TODO*/;
- endpoint->service = properties_get(props, "service");
+
+ char *serviceId = properties_get(props, "endpoint.service.id");
+
+ endpoint->id = properties_get(props, "endpoint.id");
+ endpoint->serviceId = serviceId == NULL? 0 : atol(serviceId);
+ endpoint->service = properties_get(props, "objectClass");
endpoint->properties = props;
entry->pool = childPool;
Modified: incubator/celix/trunk/remote_services/example_endpoint/private/src/example_endpoint_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/example_endpoint/private/src/example_endpoint_impl.c?rev=1530401&r1=1530400&r2=1530401&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/example_endpoint/private/src/example_endpoint_impl.c (original)
+++ incubator/celix/trunk/remote_services/example_endpoint/private/src/example_endpoint_impl.c Tue Oct 8 19:26:44 2013
@@ -85,14 +85,14 @@ celix_status_t exampleEndpoint_add(remot
} else {
double a;
double b;
- json_unpack(root, "{s:f, s:f}", "a", &a, "b", &b);
+ json_unpack(root, "{s:f, s:f}", "arg0", &a, "arg1", &b);
if (ep->service != NULL) {
double result;
json_t *resultRoot;
example_service_pt service = ep->service;
service->add(service->example, a, b, &result);
- resultRoot = json_pack("{s:f}", "result", result);
+ resultRoot = json_pack("[f]", result);
char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
*reply = c;
@@ -116,14 +116,14 @@ celix_status_t exampleEndpoint_sub(remot
} else {
double a;
double b;
- json_unpack(root, "{s:f, s:f}", "a", &a, "b", &b);
+ json_unpack(root, "{s:f, s:f}", "arg0", &a, "arg1", &b);
if (ep->service != NULL) {
double result;
json_t *resultRoot;
example_service_pt service = ep->service;
service->sub(service->example, a, b, &result);
- resultRoot = json_pack("{s:f}", "result", result);
+ resultRoot = json_pack("[f]", result);
char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
*reply = c;
@@ -146,14 +146,14 @@ celix_status_t exampleEndpoint_sqrt(remo
status = CELIX_ILLEGAL_ARGUMENT;
} else {
double a;
- json_unpack(root, "{s:f}", "a", &a);
+ json_unpack(root, "{s:f}", "arg0", &a);
if (ep->service != NULL) {
double result;
json_t *resultRoot;
example_service_pt service = ep->service;
service->sqrt(service->example, a, &result);
- resultRoot = json_pack("{s:f}", "result", result);
+ resultRoot = json_pack("[f]", result);
char *c = json_dumps(resultRoot, JSON_ENCODE_ANY);
*reply = c;
Modified: incubator/celix/trunk/remote_services/example_proxy/private/src/example_proxy_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/example_proxy/private/src/example_proxy_impl.c?rev=1530401&r1=1530400&r2=1530401&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/example_proxy/private/src/example_proxy_impl.c (original)
+++ incubator/celix/trunk/remote_services/example_proxy/private/src/example_proxy_impl.c Tue Oct 8 19:26:44 2013
@@ -67,12 +67,12 @@ celix_status_t exampleProxy_add(example_
celix_status_t status = CELIX_SUCCESS;
if (example->endpoint != NULL) {
- char *serviceUrl = properties_get(example->endpoint->properties, "url");
+ char *serviceUrl = properties_get(example->endpoint->properties, ".ars.alias");
printf("CALCULATOR_PROXY: URL: %s\n", serviceUrl);
char *url = apr_pstrcat(example->pool, serviceUrl, "/add", NULL);
json_t *root;
- root = json_pack("{s:f, s:f}", "a", a, "b", b);
+ root = json_pack("{s:f, s:f}", "arg0", a, "arg1", b);
struct post post;
char *data = json_dumps(root, 0);
@@ -87,7 +87,7 @@ celix_status_t exampleProxy_add(example_
if (status == CELIX_SUCCESS) {
json_error_t jsonError;
json_t *reply = json_loads(get.writeptr, 0, &jsonError);
- json_unpack(reply, "{s:f}", "result", result);
+ json_unpack(reply, "[f]", result);
}
} else {
printf("CALCULATOR_PROXY: No endpoint information available\n");
@@ -103,7 +103,7 @@ celix_status_t exampleProxy_sub(example_
char *url = apr_pstrcat(example->pool, example->endpoint->id, "/sub", NULL);
json_t *root;
- root = json_pack("{s:f, s:f}", "a", a, "b", b);
+ root = json_pack("{s:f, s:f}", "arg0", a, "arg1", b);
struct post post;
char *data = json_dumps(root, 0);
@@ -118,7 +118,7 @@ celix_status_t exampleProxy_sub(example_
if (status == CELIX_SUCCESS) {
json_error_t jsonError;
json_t *reply = json_loads(get.writeptr, 0, &jsonError);
- json_unpack(reply, "{s:f}", "result", result);
+ json_unpack(reply, "[f]", "result", result);
}
} else {
printf("CALCULATOR_PROXY: No endpoint information available\n");
@@ -134,7 +134,7 @@ celix_status_t exampleProxy_sqrt(example
char *url = apr_pstrcat(example->pool, example->endpoint->id, "/sqrt", NULL);
json_t *root;
- root = json_pack("{s:f}", "a", a);
+ root = json_pack("{s:f}", "arg0", a);
struct post post;
char *data = json_dumps(root, 0);
@@ -149,7 +149,7 @@ celix_status_t exampleProxy_sqrt(example
if (status == CELIX_SUCCESS) {
json_error_t jsonError;
json_t *reply = json_loads(get.writeptr, 0, &jsonError);
- json_unpack(reply, "{s:f}", "result", result);
+ json_unpack(reply, "[f]", "result", result);
}
} else {
printf("CALCULATOR_PROXY: No endpoint information available\n");
Modified: incubator/celix/trunk/remote_services/example_service/public/include/example_service.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/example_service/public/include/example_service.h?rev=1530401&r1=1530400&r2=1530401&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/example_service/public/include/example_service.h (original)
+++ incubator/celix/trunk/remote_services/example_service/public/include/example_service.h Tue Oct 8 19:26:44 2013
@@ -27,7 +27,7 @@
#ifndef EXAMPLE_SERVICE_H_
#define EXAMPLE_SERVICE_H_
-#define EXAMPLE_SERVICE "example"
+#define EXAMPLE_SERVICE "org.example.api.Calculator"
typedef struct example *example_pt;
Modified: incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c?rev=1530401&r1=1530400&r2=1530401&view=diff
==============================================================================
--- incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c (original)
+++ incubator/celix/trunk/remote_services/remote_service_admin/private/src/remote_service_admin_impl.c Tue Oct 8 19:26:44 2013
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <apr_strings.h>
+#include <apr_uuid.h>
#include "remote_service_admin_impl.h"
#include "export_registration_impl.h"
@@ -125,20 +126,22 @@ static int remoteServiceAdmin_callback(s
printf("REMOTE_SERVICE_ADMIN: Handle request: %s\n", request_info->uri);
remote_service_admin_pt rsa = request_info->user_data;
- if (strncmp(request_info->uri, "/services/", 10) == 0) {
+ if (strncmp(request_info->uri, "/service/", 9) == 0) {
// uri = /services/myservice/call
const char *uri = request_info->uri;
// rest = myservice/call
- const char *rest = uri+10;
+ const char *rest = uri+9;
int length = strlen(rest);
- char *callStart = strchr(rest, '/');
- int pos = callStart - rest;
+ char *interfaceStart = strchr(rest, '/');
+ char *callStart = strchr(interfaceStart+1, '/');
+ int pos = interfaceStart - rest;
char service[pos+1];
strncpy(service, rest, pos);
service[pos] = '\0';
- char request[length - pos];
- strncpy(request, rest + pos + 1, length - pos);
+// printf("Got service %s, interfaceStart is %s and callStart is %s\n", service, interfaceStart, callStart);
+
+ char *request = callStart+1;
const char *lengthStr = mg_get_header(conn, (const char *) "Content-Length");
int datalength = apr_atoi64(lengthStr);
@@ -153,7 +156,8 @@ static int remoteServiceAdmin_callback(s
int expIt = 0;
for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
export_registration_pt export = arrayList_get(exports, expIt);
- if (strcmp(service, export->endpointDescription->service) == 0) {
+ long serviceId = atol(service);
+ if (serviceId == export->endpointDescription->serviceId) {
char *reply = NULL;
export->endpoint->handleRequest(export->endpoint->endpoint, request, data, &reply);
if (reply != NULL) {
@@ -286,18 +290,23 @@ celix_status_t remoteServiceAdmin_instal
properties_set(endpointProperties, key, value);
}
char *serviceId = (char *) hashMap_remove(endpointProperties, (void *) SERVICE_ID);
- properties_set(endpointProperties, (char *) OBJECTCLASS, interface);
- properties_set(endpointProperties, (char *) ENDPOINT_SERVICE_ID, serviceId);
char *uuid = NULL;
bundleContext_getProperty(admin->context, FRAMEWORK_UUID, &uuid);
+ properties_set(endpointProperties, (char *) OBJECTCLASS, interface);
+ properties_set(endpointProperties, (char *) ENDPOINT_SERVICE_ID, serviceId);
+ properties_set(endpointProperties, "service.imported", "true");
properties_set(endpointProperties, (char *) ENDPOINT_FRAMEWORK_UUID, uuid);
- char *service = "/services/example";
- properties_set(endpointProperties, (char *) SERVICE_LOCATION, apr_pstrdup(admin->pool, service));
-
+
+// properties_set(endpointProperties, ".ars.path", buf);
+// properties_set(endpointProperties, ".ars.port", admin->port);
+
+ char buf[512];
+ sprintf(buf, "/service/%s/%s", serviceId, interface);
char *url = NULL;
- constructServiceUrl(admin,interface, &url);
- printf("url is %s\n", url);
- properties_set(endpointProperties, "url", url);
+ constructServiceUrl(admin,buf, &url);
+ properties_set(endpointProperties, ".ars.alias", url);
+
+ properties_set(endpointProperties, "service.imported.configs", ".ars");
endpoint_description_pt endpointDescription = NULL;
remoteServiceAdmin_createEndpointDescription(admin, serviceProperties, endpointProperties, interface, &endpointDescription);
@@ -328,7 +337,7 @@ static celix_status_t constructServiceUr
if (stat != APR_SUCCESS) {
status = CELIX_BUNDLE_EXCEPTION;
} else {
- *serviceUrl = apr_pstrcat(admin->pool, "http://", ip, ":", admin->port, "/services/", service, NULL );
+ *serviceUrl = apr_pstrcat(admin->pool, "http://", ip, ":", admin->port, service, NULL );
}
}
}
@@ -344,7 +353,7 @@ celix_status_t remoteServiceAdmin_create
celix_status_t status = CELIX_SUCCESS;
apr_pool_t *childPool = NULL;
- apr_pool_create(&childPool, admin->pool);
+ apr_pool_create(&childPool, admin->pool); //TODO pool should be destroyed after when endpoint is removed
*description = apr_palloc(childPool, sizeof(*description));
// *description = malloc(sizeof(*description));
@@ -357,7 +366,7 @@ celix_status_t remoteServiceAdmin_create
(*description)->properties = endpointProperties;
(*description)->frameworkUUID = uuid;
(*description)->serviceId = apr_atoi64(properties_get(serviceProperties, (char *) SERVICE_ID));
- (*description)->id = properties_get(endpointProperties, (char *) SERVICE_LOCATION);
+ (*description)->id = apr_pstrdup(childPool, "TODO"); // does not work, txt record to big ?? --> apr_pstrcat(childPool, uuid, "-", (*description)->serviceId, NULL);
(*description)->service = interface;
}
}