[hydra-commits] hydra/servicediscovery.git branch "master" updated.

Commits to the Hydra project code repositories hydra-commits at lists.digium.com
Tue Jul 20 21:32:08 CDT 2010


branch "master" has been updated
       via  157981e3086b2a457a65c4303a18e8b0f70cd163 (commit)
       via  0391567260678f33223e86a164ec74d91bd39900 (commit)
      from  fc64060ede6548757d4a8a60f1d36684c4b9ba2a (commit)

Summary of changes:
 .gitmodules                        |    3 +
 CMakeLists.txt                     |   19 +++++++
 cmake                              |    1 +
 slice/CMakeLists.txt               |    2 +
 slice/service_discovery.ice        |   63 ++++++++++++++++++++++++
 src/CMakeLists.txt                 |    8 +++
 src/ServiceDiscoveryManagement.cpp |   92 ++++++++++++++++++++++++++++++++++++
 src/ServiceDiscoveryManagement.h   |   29 +++++++++++
 src/ServiceLocator.cpp             |   78 ++++++++++++++++++++++++++++++
 src/ServiceManagement.cpp          |   65 +++++++++++++++++++++++++
 src/ServiceManagement.h            |   30 ++++++++++++
 test.txt                           |    1 -
 12 files changed, 390 insertions(+), 1 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 CMakeLists.txt
 create mode 160000 cmake
 create mode 100644 slice/CMakeLists.txt
 create mode 100644 slice/service_discovery.ice
 create mode 100644 src/CMakeLists.txt
 create mode 100644 src/ServiceDiscoveryManagement.cpp
 create mode 100644 src/ServiceDiscoveryManagement.h
 create mode 100644 src/ServiceLocator.cpp
 create mode 100644 src/ServiceManagement.cpp
 create mode 100644 src/ServiceManagement.h
 delete mode 100644 test.txt
 create mode 100644 test/TestServiceDiscovery.cpp


- Log -----------------------------------------------------------------
commit 157981e3086b2a457a65c4303a18e8b0f70cd163
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Jul 20 23:27:44 2010 -0300

    Add the basic service discovery implementation. This still needs some hammering out, nice documentation, probably some name changes,
    events, some configuration details, and testing but overall it's rather simple.
    
    Additional note: Now that I've gotten familiar with git and how we are using it don't expect to see a big commit like this ever again.

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..0f6d7db
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "cmake"]
+	path = cmake
+	url = git at git.asterisk.org:hydra/cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..b3ed5e5
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,19 @@
+# Service locator build system
+
+# Minimum we require is 2.6, any lower and stuff would fail horribly
+cmake_minimum_required(VERSION 2.6)
+
+# Include common Hydra build infrastructure
+include(cmake/Hydra_v3.cmake)
+
+# This project is C++ based and requires a minimum of 3.4
+hydra_project(service_locator 3.4 CXX)
+
+# Take care of slice definitions
+add_subdirectory(slice)
+
+# Take care of the source code for this project
+add_subdirectory(src)
+
+# Finally take care of the test suite
+#add_subdirectory(test)
diff --git a/cmake b/cmake
new file mode 160000
index 0000000..8a93352
--- /dev/null
+++ b/cmake
@@ -0,0 +1 @@
+Subproject commit 8a9335238af711324d93ca91c799a37545647fa3
diff --git a/slice/CMakeLists.txt b/slice/CMakeLists.txt
new file mode 100644
index 0000000..d8a4479
--- /dev/null
+++ b/slice/CMakeLists.txt
@@ -0,0 +1,2 @@
+# Compile our service discovery slice definition so we can then use it
+hydra_compile_slice(service_discovery.ice)
diff --git a/slice/service_discovery.ice b/slice/service_discovery.ice
new file mode 100644
index 0000000..e216dd3
--- /dev/null
+++ b/slice/service_discovery.ice
@@ -0,0 +1,63 @@
+#include <Ice/BuiltinSequences.ice>
+
+module Hydra {
+
+	module Discovery {
+
+		/* This exception is used for service discovery requests to indicate that no service could be found */
+		exception ServiceNotFound {
+		};
+
+		/* This exception is used for indicating that a comparator is already registered with a given guid */
+		exception DuplicateCompare {
+		};
+
+		/* This exception is used for indicating that a compare service was not found */
+		exception CompareNotFound {
+		};
+
+		/* This is a generic service discovery class that more specific parameter classes can extend */
+		class ServiceDiscoveryParams {
+			/* Basic category, bridge/channel service/etc */
+			string category;
+		};
+
+		/* Interface to do service discovery requests */
+		interface ServiceDiscovery {
+			/* Perform a service discovery request using provided parameters and return a single result */
+			idempotent Object *locate(ServiceDiscoveryParams params) throws ServiceNotFound;
+			/* Perform a service discovery request using provided parameters and return all results */
+			idempotent Ice::ObjectProxySeq locateAll(ServiceDiscoveryParams params) throws ServiceNotFound;
+		};
+
+		/* Interface to the service discovery component to manipulate service related things */
+		interface ServiceManagement {
+			/* API call which adds parameters so that this service can be discovered */
+			void addDiscoveryParams(ServiceDiscoveryParams params, string compareguid);
+			/* API call which suspends this service from being discovered */
+			void suspend();
+			/* API call which unsuspends this service from being discovered */
+			void unsuspend();
+			/* API call which unregisters a service from service discovery */
+			void unregister();
+		};
+
+		/* Interface to an external component to perform discovery parameter comparison */
+		interface ServiceDiscoveryParamsCompare {
+			/* API call which determines whether parameters are accepted or not */
+			bool isSupported(ServiceDiscoveryParams params);
+		};
+
+		/* Interface to do service discovery management (adding of services and compare components) */
+		interface ServiceDiscoveryManagement {
+			/* API call which adds a service to service discovery, still requires parameters to be added though */
+			ServiceManagement *addService(Object *service);
+			/* API call which adds a comparison service to service discovery */
+			void addCompare(string compareguid, ServiceDiscoveryParamsCompare *compare) throws DuplicateCompare;
+			/* API call which removes a comparison service from service discovery */
+			void removeCompare(string compareguid) throws CompareNotFound;
+		};
+
+	};
+
+};
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..3b4a6d5
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Create the actual standalone service locator component
+hydra_component_init(service_locator CXX)
+hydra_component_add_slice(service_locator service_discovery)
+hydra_component_add_file(service_locator ServiceLocator.cpp)
+hydra_component_add_file(service_locator ServiceDiscoveryManagement.cpp)
+hydra_component_add_file(service_locator ServiceManagement.cpp)
+hydra_component_build_standalone(service_locator)
+hydra_component_install(service_locator)
diff --git a/src/ServiceDiscoveryManagement.cpp b/src/ServiceDiscoveryManagement.cpp
new file mode 100644
index 0000000..34e952a
--- /dev/null
+++ b/src/ServiceDiscoveryManagement.cpp
@@ -0,0 +1,92 @@
+#include <Ice/Ice.h>
+
+#include "service_discovery.h"
+
+using namespace std;
+using namespace Hydra::Discovery;
+
+#include "ServiceDiscoveryManagement.h"
+#include "ServiceManagement.h"
+
+Ice::ObjectPrx ServiceDiscoveryManagementImpl::locate(const ServiceDiscoveryParamsPtr& params)
+{
+	vector<ServiceManagementImpl*>::iterator service;
+
+	for (vector<ServiceManagementImpl*>::iterator service = services.begin(); service != services.end(); ++service) {
+		if ((*service)->isSupported(params) == true) {
+			return (*service)->GetService();
+		}
+	}
+
+	throw ServiceNotFound();
+}
+
+Ice::ObjectProxySeq ServiceDiscoveryManagementImpl::locateAll(const ServiceDiscoveryParamsPtr& params)
+{
+	Ice::ObjectProxySeq applicable_services;
+	vector<ServiceManagementImpl*>::iterator service;
+
+	for (vector<ServiceManagementImpl*>::iterator service = services.begin(); service != services.end(); ++service) {
+		if ((*service)->isSupported(params) == true) {
+			applicable_services.push_back((*service)->GetService());
+		}
+	}
+
+	if (!applicable_services.empty()) {
+		return applicable_services;
+	} else {
+		throw ServiceNotFound();
+	}
+}
+
+ServiceManagementPrx ServiceDiscoveryManagementImpl::addService(const Ice::ObjectPrx& service, const Ice::Current&)
+{
+	ServiceManagementImpl* new_service = new ServiceManagementImpl(this, service, _adapter);
+
+	return new_service->GetServiceManagementPrx();
+}
+
+void ServiceDiscoveryManagementImpl::addCompare(const string& guid, const ServiceDiscoveryParamsComparePrx& service, const Ice::Current&)
+{
+	map<string, ServiceDiscoveryComparator>::iterator comparator = compares.find(guid);
+
+	if (comparator != compares.end()) {
+		throw DuplicateCompare();
+	}
+
+	ServiceDiscoveryComparator new_comparator(service);
+	compares[guid] = new_comparator;
+};
+
+void ServiceDiscoveryManagementImpl::removeCompare(const string& guid, const Ice::Current&)
+{
+	map<string, ServiceDiscoveryComparator>::iterator comparator = compares.find(guid);
+
+	if (comparator == compares.end()) {
+		throw CompareNotFound();
+	}
+
+	compares.erase(guid);
+};
+
+bool ServiceDiscoveryManagementImpl::isSupported(const string& compare_guid, const ServiceDiscoveryParamsPtr& params)
+{
+	map<string, ServiceDiscoveryComparator>::iterator comparator = compares.find(compare_guid);
+
+	if (comparator == compares.end()) {
+		return false;
+	}
+
+	return (comparator->second).isSupported(params);
+}
+
+void ServiceDiscoveryManagementImpl::removeService(ServiceManagementImpl* service)
+{
+	vector<ServiceManagementImpl*>::iterator existing_service;
+	for (vector<ServiceManagementImpl*>::iterator existing_service = services.begin(); existing_service != services.end(); ++existing_service) {
+		if ((*existing_service) == service) {
+			services.erase(existing_service);
+			return;
+		}
+	}
+}
diff --git a/src/ServiceDiscoveryManagement.h b/src/ServiceDiscoveryManagement.h
new file mode 100644
index 0000000..98d1dc6
--- /dev/null
+++ b/src/ServiceDiscoveryManagement.h
@@ -0,0 +1,29 @@
+class ServiceManagementImpl;
+
+/* This is a small data structure which wraps the comparator a bit, but really it just passes the isSupported call onwards */
+class ServiceDiscoveryComparator
+{
+public:
+	ServiceDiscoveryComparator() { };
+        ServiceDiscoveryComparator(ServiceDiscoveryParamsComparePrx compare) : _compare(compare) { };
+	bool isSupported(const ServiceDiscoveryParamsPtr& params) { return _compare->isSupported(params); };
+private:
+	ServiceDiscoveryParamsComparePrx _compare;
+};
+
+class ServiceDiscoveryManagementImpl : public ServiceDiscoveryManagement
+{
+public:
+        ServiceDiscoveryManagementImpl(Ice::ObjectAdapterPtr adapter) : _adapter(adapter) { };
+	Ice::ObjectPrx locate(const ServiceDiscoveryParamsPtr&);
+	Ice::ObjectProxySeq locateAll(const ServiceDiscoveryParamsPtr&);
+	ServiceManagementPrx addService(const Ice::ObjectPrx&, const Ice::Current&);
+	void addCompare(const string&, const ServiceDiscoveryParamsComparePrx&, const Ice::Current&);
+	void removeCompare(const string&, const Ice::Current&);
+	bool isSupported(const string&, const ServiceDiscoveryParamsPtr&);
+	void removeService(ServiceManagementImpl*);
+private:
+	Ice::ObjectAdapterPtr _adapter;
+	map<string, ServiceDiscoveryComparator> compares;
+	vector<ServiceManagementImpl*> services;
+};
diff --git a/src/ServiceLocator.cpp b/src/ServiceLocator.cpp
new file mode 100644
index 0000000..d23d6ea
--- /dev/null
+++ b/src/ServiceLocator.cpp
@@ -0,0 +1,78 @@
+#include <Ice/Ice.h>
+
+#include "service_discovery.h"
+
+using namespace std;
+using namespace Hydra::Discovery;
+
+#include "ServiceDiscoveryManagement.h"
+#include "ServiceManagement.h"
+
+class ServiceLocatorApp : public Ice::Application
+{
+public:
+	virtual int run(int, char*[]);
+	virtual void interruptCallback(int);
+
+private:
+};
+
+class ServiceDiscoveryImpl : public ServiceDiscovery
+{
+public:
+	ServiceDiscoveryImpl(ServiceDiscoveryManagementImpl* DiscoveryServiceManagement) : _DiscoveryServiceManagement(DiscoveryServiceManagement) { };
+	Ice::ObjectPrx locate(const ServiceDiscoveryParamsPtr&, const Ice::Current&);
+	Ice::ObjectProxySeq locateAll(const ServiceDiscoveryParamsPtr&, const Ice::Current&);
+private:
+	ServiceDiscoveryManagementImpl* _DiscoveryServiceManagement;
+};
+
+static ServiceLocatorApp app;
+
+int main(int argc, char* argv[])
+{
+	app.callbackOnInterrupt();
+	return app.main(argc, argv);
+}
+
+/* Implementation of the locate method for service discovery */
+Ice::ObjectPrx ServiceDiscoveryImpl::locate(const ServiceDiscoveryParamsPtr& params, const Ice::Current&)
+{
+	/* This API call forwards into the management implementation, it is separated to provide a level of security */
+	return _DiscoveryServiceManagement->locate(params);
+}
+
+/* Implementation of the locateAll method for service discovery */
+Ice::ObjectProxySeq ServiceDiscoveryImpl::locateAll(const ServiceDiscoveryParamsPtr& params, const Ice::Current&)
+{
+	/* This API call forwards into the management implementation, it is separated to provide a level of security */
+	return _DiscoveryServiceManagement->locateAll(params);
+}
+
+/**
+ * Overload of the Ice::Application::run method. 
+ */
+int ServiceLocatorApp::run(int argc, char* argv[])
+{
+	/* TODO: Place these on separate adapters for security reasons */
+	Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("ServiceLocatorAdapter");
+
+	ServiceDiscoveryManagementImpl* DiscoveryServiceManagement = new ServiceDiscoveryManagementImpl(adapter);
+
+	adapter->add(DiscoveryServiceManagement, communicator()->stringToIdentity("DiscoveryServiceManagement"));
+
+	ServiceDiscoveryPtr DiscoveryService = new ServiceDiscoveryImpl(DiscoveryServiceManagement);
+
+	adapter->add(DiscoveryService, communicator()->stringToIdentity("DiscoveryService"));
+
+	adapter->activate();
+
+	communicator()->waitForShutdown();
+
+	return EXIT_SUCCESS;
+}
+
+void ServiceLocatorApp::interruptCallback(int val)
+{
+	_exit(EXIT_SUCCESS);
+}
diff --git a/src/ServiceManagement.cpp b/src/ServiceManagement.cpp
new file mode 100644
index 0000000..7729b71
--- /dev/null
+++ b/src/ServiceManagement.cpp
@@ -0,0 +1,65 @@
+#include <Ice/Ice.h>
+
+#include "service_discovery.h"
+
+using namespace std;
+using namespace Hydra::Discovery;
+
+#include "ServiceDiscoveryManagement.h"
+#include "ServiceManagement.h"
+
+ServiceManagementImpl::ServiceManagementImpl(ServiceDiscoveryManagementImpl* management, Ice::ObjectPrx service, Ice::ObjectAdapterPtr adapter)
+	: _management(management), _service(service), _adapter(adapter)
+{
+	managementprx = ServiceManagementPrx::uncheckedCast(adapter->addWithUUID(this));
+}
+
+/* This is the isSupported implementation for the service itself */
+bool ServiceManagementImpl::isSupported(const ServiceDiscoveryParamsPtr& params)
+{
+	/* If this service is suspended we can just skip the entire check and return false now, easy as pie */
+	if (suspended) {
+		return false;
+	}
+
+	vector<ServiceDiscoveryParamsSpec>::iterator spec;
+
+	for (vector<ServiceDiscoveryParamsSpec>::iterator spec = supported_discovery_params.begin(); spec != supported_discovery_params.end(); ++spec) {
+		if ((*spec).isSupported(params) == true) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+/* This is the isSupported implementation for the discovery parameters, a bit more specific */
+bool ServiceDiscoveryParamsSpec::isSupported(const ServiceDiscoveryParamsPtr& params)
+{
+	/* This is just a simple comparison that acts as a preliminary, and perhaps final, check */
+	if (*_params == *params) {
+		/* If a comparator was provided then yield to it for a final yay or nay */
+		if (!_compare_guid.empty()) {
+			return _management->isSupported(_compare_guid, params);
+		}
+		return true;
+	}
+
+	return false;
+}
+
+void ServiceManagementImpl::addDiscoveryParams(const ServiceDiscoveryParamsPtr& params, const std::string& compare_guid, const Ice::Current&)
+{
+	ServiceDiscoveryParamsSpec spec(params, compare_guid, _management);
+
+	supported_discovery_params.push_back(spec);
+}
+
+void ServiceManagementImpl::unregister(const Ice::Current&)
+{
+	_adapter->remove(managementprx->ice_getIdentity());
+
+	_management->removeService(this);
+}
+
+
diff --git a/src/ServiceManagement.h b/src/ServiceManagement.h
new file mode 100644
index 0000000..a2faf0b
--- /dev/null
+++ b/src/ServiceManagement.h
@@ -0,0 +1,30 @@
+class ServiceDiscoveryParamsSpec {
+public:
+        ServiceDiscoveryParamsSpec(const ServiceDiscoveryParamsPtr& params, const string& compare_guid, ServiceDiscoveryManagementImpl* management)
+		: _params(params), _compare_guid(compare_guid), _management(management) { };
+	bool isSupported(const ServiceDiscoveryParamsPtr&);
+private:
+	ServiceDiscoveryParamsPtr _params;
+	string _compare_guid;
+	ServiceDiscoveryManagementImpl* _management;
+};
+
+class ServiceManagementImpl : public ServiceManagement
+{
+public:
+        ServiceManagementImpl(ServiceDiscoveryManagementImpl* management, Ice::ObjectPrx service, Ice::ObjectAdapterPtr adapter);
+	void addDiscoveryParams(const ServiceDiscoveryParamsPtr&, const std::string&, const Ice::Current&);
+	void suspend(const Ice::Current&) { suspended = true; };
+	void unsuspend(const Ice::Current&) { suspended = false; };
+	void unregister(const Ice::Current&);
+	Ice::ObjectPrx GetService(void) { return _service; };
+	ServiceManagementPrx GetServiceManagementPrx(void) { return managementprx; };
+	bool isSupported(const ServiceDiscoveryParamsPtr&);
+private:
+	bool suspended;
+	ServiceDiscoveryManagementImpl* _management;
+	Ice::ObjectPrx _service;
+	Ice::ObjectAdapterPtr _adapter;
+	ServiceManagementPrx managementprx;
+	vector<ServiceDiscoveryParamsSpec> supported_discovery_params;
+};
diff --git a/test/TestServiceDiscovery.cpp b/test/TestServiceDiscovery.cpp
new file mode 100644
index 0000000..e69de29

commit 0391567260678f33223e86a164ec74d91bd39900
Author: Joshua Colp <jcolp at digium.com>
Date:   Tue Jul 20 23:22:05 2010 -0300

    Remove test file, just played with this new repo a bit.

diff --git a/test.txt b/test.txt
deleted file mode 100644
index fd6614c..0000000
--- a/test.txt
+++ /dev/null
@@ -1 +0,0 @@
-Kablamo

-----------------------------------------------------------------------


-- 
hydra/servicediscovery.git




More information about the asterisk-scf-commits mailing list