[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "configuration-replication" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue May 17 09:13:59 CDT 2011
branch "configuration-replication" has been created
at a7f1600075e5990bbecef9f273bf8cb0af77f444 (commit)
- Log -----------------------------------------------------------------
commit a7f1600075e5990bbecef9f273bf8cb0af77f444
Author: Joshua Colp <jcolp at digium.com>
Date: Tue May 17 11:15:14 2011 -0300
Add support for replicating configuration to the SIP component.
diff --git a/config/test_sip_state_replicator.conf b/config/test_sip_state_replicator.conf
index 89af225..0a35cda 100644
--- a/config/test_sip_state_replicator.conf
+++ b/config/test_sip_state_replicator.conf
@@ -16,3 +16,11 @@ SipStateReplicator.Name=default
IceBox.InheritProperties = 1
IceBox.Service.SipStateReplicator=SipStateReplicator:create
+
+SipStateReplicatorIceStorm.InstanceName=SipStateReplicatorIceStorm
+SipStateReplicatorIceStorm.TopicManager.Endpoints=default -p 10007
+SipStateReplicatorIceStorm.Publish.Endpoints=default -p 10008
+SipStateReplicatorIceStorm.Trace.TopicManager=2
+SipStateReplicatorIceStorm.Transient=1
+SipStateReplicatorIceStorm.Flush.Timeout=2000
+SipStateReplicatorTopicManager.Proxy=SipStateReplicatorIceStorm/TopicManager:default -p 10008
diff --git a/local-slice/SipConfigurationIf.ice b/local-slice/SipConfigurationIf.ice
index 58cae24..6cd18d9 100644
--- a/local-slice/SipConfigurationIf.ice
+++ b/local-slice/SipConfigurationIf.ice
@@ -15,7 +15,9 @@
*/
#pragma once
+
#include <Ice/BuiltinSequences.ice>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice>
#include <AsteriskSCF/System/Component/ConfigurationIf.ice>
module AsteriskSCF
@@ -26,6 +28,22 @@ module SIP
module V1
{
/**
+ * Service locator category for finding the configuration service
+ */
+ const string ConfigurationDiscoveryCategory = "SipConfiguration";
+
+ /**
+ * Service locator parameters class for discovering the configuration service
+ */
+ unsliceable class SipConfigurationParams extends AsteriskSCF::Core::Discovery::V1::ServiceLocatorParams
+ {
+ /**
+ * Unique name for the configuration service
+ */
+ string name;
+ };
+
+ /**
* Local visitor class for visiting SIP configuration groups
*/
local class SipConfigurationGroupVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationGroupVisitor
diff --git a/local-slice/SipStateReplicationIf.ice b/local-slice/SipStateReplicationIf.ice
index c7d16d9..28f7c1e 100644
--- a/local-slice/SipStateReplicationIf.ice
+++ b/local-slice/SipStateReplicationIf.ice
@@ -17,9 +17,10 @@
#pragma once
#include <Ice/BuiltinSequences.ice>
#include <Ice/Identity.ice>
-#include "AsteriskSCF/Media/MediaIf.ice"
-#include "AsteriskSCF/SessionCommunications/SessionCommunicationsIf.ice"
-#include "AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice"
+#include <AsteriskSCF/Media/MediaIf.ice>
+#include <AsteriskSCF/SessionCommunications/SessionCommunicationsIf.ice>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.ice>
+#include <AsteriskSCF/System/Component/ConfigurationIf.ice>
module AsteriskSCF
{
@@ -53,11 +54,12 @@ module V1
interface SipStateReplicator
{
void addListener(SipStateReplicatorListener *listener);
- void removeListener(SipStateReplicatorListener *listener);
- void setState (SipStateItemSeq items);
- void removeState(Ice::StringSeq items);
- idempotent SipStateItemSeq getState(Ice::StringSeq itemKeys);
- idempotent SipStateItemSeq getAllState();
+ void removeListener(SipStateReplicatorListener *listener);
+ void setState (SipStateItemSeq items);
+ void removeState(Ice::StringSeq items);
+ idempotent SipStateItemSeq getState(Ice::StringSeq itemKeys);
+ idempotent SipStateItemSeq getAllState();
+ void registerConfigurationService(AsteriskSCF::System::Configuration::V1::ConfigurationService *service);
};
class SipDialogStateItem extends SipStateItem
{
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 202b875..e9acf99 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -58,9 +58,11 @@ asterisk_scf_component_add_file(SipStateReplicator SipStateReplicatorApp.cpp)
asterisk_scf_component_add_file(SipStateReplicator SipStateReplicator.h)
asterisk_scf_component_add_slice(SipStateReplicator ../local-slice/SipStateReplicationIf.ice)
asterisk_scf_component_add_slice(SipStateReplicator ../local-slice/SipIf.ice)
+asterisk_scf_component_add_slice(SipStateReplicator ../local-slice/SipConfigurationIf.ice)
asterisk_scf_component_add_ice_libraries(SipStateReplicator IceStorm)
asterisk_scf_component_add_boost_libraries(SipStateReplicator thread date_time)
asterisk_scf_component_build_icebox(SipStateReplicator)
target_link_libraries(SipStateReplicator logging-client)
target_link_libraries(SipStateReplicator asterisk-scf-api)
+target_link_libraries(SipStateReplicator ice-util-cpp)
asterisk_scf_component_install(SipStateReplicator)
diff --git a/src/SipSessionManagerApp.cpp b/src/SipSessionManagerApp.cpp
index 2644402..1db81f4 100644
--- a/src/SipSessionManagerApp.cpp
+++ b/src/SipSessionManagerApp.cpp
@@ -19,6 +19,7 @@
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
#include <IceBox/IceBox.h>
+#include <IceUtil/UUID.h>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
@@ -116,6 +117,8 @@ private:
ServiceLocatorManagementPrx mServiceLocatorManagement;
ServiceManagementPrx mComponentServiceManagement;
+ ServiceManagementPrx mConfigurationManagement;
+ std::string mConfigCompareGuid;
ReplicaPtr mReplicaService;
ComponentServicePtr mComponentService;
ConfigurationServicePtr mConfigurationService;
@@ -283,6 +286,28 @@ private:
};
/**
+ * Comparator implementation for name based configuration service locating
+ */
+class SipConfigurationCompare : public ServiceLocatorParamsCompare
+{
+public:
+ SipConfigurationCompare(const string& name) : mName(name) {}
+ bool isSupported(const ServiceLocatorParamsPtr ¶ms, const Ice::Current &)
+ {
+ SipConfigurationParamsPtr configParams = SipConfigurationParamsPtr::dynamicCast(params);
+ if (configParams->name == mName)
+ {
+ return true;
+ }
+ return false;
+ }
+private:
+ string mName;
+};
+
+typedef IceUtil::Handle<SipConfigurationCompare> SipConfigurationComparePtr;
+
+/**
* Helper function to add some parameters to one of our registered interfaces in the ServiceLocator, so that
* other components can look up our interfaces.
*/
@@ -325,6 +350,29 @@ void SipSessionManager::registerWithServiceLocator()
setCategory(mComponentServiceManagement, AsteriskSCF::SIP::V1::ComponentServiceDiscoveryCategory);
+ if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.Standalone", "false") == "true")
+ {
+ // Publish the configuration service IceStorm topic so everybody gets configuration
+ Ice::ObjectPrx configurationServicePrx =
+ mLocalAdapter->createDirectProxy(mCommunicator->stringToIdentity(ConfigurationServiceId));
+ mConfigurationManagement = ServiceManagementPrx::uncheckedCast(
+ mServiceLocatorManagement->addService(configurationServicePrx, ""));
+
+ // Populate the configuration parameters with details so we can be found
+ SipConfigurationParamsPtr configurationParams = new SipConfigurationParams();
+ configurationParams->category = ConfigurationDiscoveryCategory;
+ configurationParams->name = mCommunicator->getProperties()->getPropertyWithDefault("SipConfiguration.Name", "");
+
+ // Add our custom comparator so we can support multiple simultaneous configuration sinks
+ SipConfigurationComparePtr configNameCompare = new SipConfigurationCompare(configurationParams->name);
+ ServiceLocatorParamsComparePrx configCompareProxy = ServiceLocatorParamsComparePrx::uncheckedCast(
+ mLocalAdapter->addWithUUID(configNameCompare));
+
+ mConfigCompareGuid = IceUtil::generateUUID();
+ mServiceLocatorManagement->addCompare(mConfigCompareGuid, configCompareProxy);
+ mConfigurationManagement->addLocatorParams(configurationParams, mConfigCompareGuid);
+ }
+
// TBD... We may have other interfaces to publish to the Service Locator.
}
catch(...)
@@ -408,6 +456,15 @@ void SipSessionManager::registerWithStateReplicator()
return;
}
+ if (mCommunicator->getProperties()->getPropertyWithDefault("Rtp.Standalone", "false") == "false")
+ {
+ Ice::ObjectPrx configurationServiceObjectPrx =
+ mLocalAdapter->createDirectProxy(mCommunicator->stringToIdentity(ConfigurationServiceId));
+ ConfigurationServicePrx configurationServicePrx = ConfigurationServicePrx::uncheckedCast(
+ configurationServiceObjectPrx);
+ mStateReplicator->registerConfigurationService(configurationServicePrx);
+ }
+
if (mCommunicator->getProperties()->getPropertyWithDefault("Sip.StateReplicatorListener", "no") == "yes")
{
mStateReplicator->addListener(mReplicatorListenerProxy);
@@ -443,6 +500,10 @@ void SipSessionManager::deregisterFromServiceLocator()
try
{
mComponentServiceManagement->unregister();
+ if (mConfigurationManagement)
+ {
+ mConfigurationManagement->unregister();
+ }
}
catch(...)
{
@@ -489,6 +550,16 @@ void SipSessionManager::registerPJSipModules()
void SipSessionManager::deregisterFromStateReplicator()
{
+ if (!mConfigCompareGuid.empty())
+ {
+ mServiceLocatorManagement->removeCompare(mConfigCompareGuid);
+ }
+
+ if (mConfigurationManagement)
+ {
+ mConfigurationManagement->unregister();
+ }
+
if (mReplicaService->isActive() == true)
{
return;
@@ -549,7 +620,7 @@ void SipSessionManager::initialize(const string& appName, const Ice::Communicato
// Create and publish our Configuration interface support.
mConfigurationService = createConfigurationServant(mPJSipManager, mEndpointFactory, mRoutingId, mRoutingServiceLocatorRegistry);
- mGlobalAdapter->add(mConfigurationService, mCommunicator->stringToIdentity(ConfigurationServiceId));
+ mLocalAdapter->add(mConfigurationService, mCommunicator->stringToIdentity(ConfigurationServiceId));
lg(Debug) << "Created SIP Configuration Implementation";
// Create and configure our Endpoint Locator.
diff --git a/src/SipStateReplicatorApp.cpp b/src/SipStateReplicatorApp.cpp
index c6cb96a..09eb741 100644
--- a/src/SipStateReplicatorApp.cpp
+++ b/src/SipStateReplicatorApp.cpp
@@ -25,9 +25,12 @@
#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
#include <AsteriskSCF/logger.h>
#include <AsteriskSCF/Logger/IceLogger.h>
+#include <AsteriskSCF/CollocatedIceStorm/CollocatedIceStorm.h>
#include <SipIf.h>
+#include "SipConfigurationIf.h"
+
using namespace std;
using namespace AsteriskSCF::Core;
using namespace AsteriskSCF::Core::Discovery::V1;
@@ -35,6 +38,7 @@ using namespace AsteriskSCF::SIP::V1;
using namespace AsteriskSCF::System::Component::V1;
using namespace AsteriskSCF::System::Logging;
using namespace AsteriskSCF::SipSessionManager;
+using namespace AsteriskSCF::CollocatedIceStorm;
namespace
{
@@ -66,6 +70,10 @@ private:
ConfiguredIceLoggerPtr mIceLogger;
ComponentServicePtr mComponentService;
SipStateReplicatorIPtr mStateReplicator;
+ CollocatedIceStormPtr mIceStorm;
+ Ice::ObjectPrx mConfigurationPublisher;
+ Discovery::V1::ServiceManagementPrx mConfigurationManagement;
+ std::string mConfigCompareGuid;
};
static const string ComponentServiceId("SipStateReplicatorComponent");
@@ -119,6 +127,53 @@ private:
typedef IceUtil::Handle<SipStateReplicatorCompare> SipStateReplicatorComparePtr;
+class SipConfigurationCompare : public ServiceLocatorParamsCompare
+{
+public:
+ SipConfigurationCompare(const string& name) : mName(name) {}
+ bool isSupported(const ServiceLocatorParamsPtr ¶ms, const Ice::Current &)
+ {
+ SipConfigurationParamsPtr configParams = SipConfigurationParamsPtr::dynamicCast(params);
+ if (configParams->name == mName)
+ {
+ return true;
+ }
+ return false;
+ }
+private:
+ string mName;
+};
+
+typedef IceUtil::Handle<SipConfigurationCompare> SipConfigurationComparePtr;
+
+class SipStateReplicatorConfigI : public SipStateReplicatorI
+{
+public:
+ SipStateReplicatorConfigI(const IceStorm::TopicPrx& topic) : mConfigurationReplicationTopic(topic) { };
+ void registerConfigurationService(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx&, const Ice::Current&);
+private:
+ IceStorm::TopicPrx mConfigurationReplicationTopic;
+};
+
+void SipStateReplicatorConfigI::registerConfigurationService(const AsteriskSCF::System::Configuration::V1::ConfigurationServicePrx& service, const Ice::Current&)
+{
+ if (mConfigurationReplicationTopic)
+ {
+ IceStorm::QoS qos;
+ qos["reliability"] = "ordered";
+
+ try
+ {
+ mConfigurationReplicationTopic->subscribeAndGetPublisher(qos, service);
+ }
+ catch (const IceStorm::AlreadySubscribed&)
+ {
+ // This is perfectly okay actually, it just means what they wanted us to do
+ // is already done.
+ }
+ }
+}
+
/**
* Register this component's primary public interfaces with the Service Locator.
* This enables other Asterisk SCF components to locate our interfaces.
@@ -173,6 +228,24 @@ void SipStateReplicatorService::registerWithServiceLocator(const Ice::Communicat
mServiceLocatorManagement->addCompare(compareGuid, compareProxy);
mStateReplicationManagement->addLocatorParams(discoveryParams, compareGuid);
+ // Publish the configuration service IceStorm topic so everybody gets configuration
+ mConfigurationManagement = ServiceManagementPrx::uncheckedCast(
+ mServiceLocatorManagement->addService(mConfigurationPublisher, ""));
+
+ // Populate the configuration parameters with details so we can be found
+ SipConfigurationParamsPtr configurationParams = new SipConfigurationParams();
+ configurationParams->category = ConfigurationDiscoveryCategory;
+ configurationParams->name = ic->getProperties()->getPropertyWithDefault("SipConfiguration.Name", "");
+
+ // Add our custom comparator so we can support multiple simultaneous configuration sinks
+ SipConfigurationComparePtr configNameCompare = new SipConfigurationCompare(configurationParams->name);
+ ServiceLocatorParamsComparePrx configCompareProxy = ServiceLocatorParamsComparePrx::uncheckedCast(
+ mAdapter->addWithUUID(configNameCompare));
+
+ mConfigCompareGuid = IceUtil::generateUUID();
+ mServiceLocatorManagement->addCompare(mConfigCompareGuid, configCompareProxy);
+ mConfigurationManagement->addLocatorParams(configurationParams, mConfigCompareGuid);
+
// TBD... We may have other interfaces to publish to the Service Locator.
}
catch(...)
@@ -191,6 +264,8 @@ void SipStateReplicatorService::deregisterFromServiceLocator()
try
{
mComponentServiceManagement->unregister();
+ mConfigurationManagement->unregister();
+ mServiceLocatorManagement->removeCompare(mConfigCompareGuid);
}
catch(...)
{
@@ -200,6 +275,40 @@ void SipStateReplicatorService::deregisterFromServiceLocator()
void SipStateReplicatorService::initialize(const std::string& appName, const Ice::CommunicatorPtr& ic)
{
+ mIceStorm = new CollocatedIceStorm("SipStateReplicatorIceStorm", ic->getProperties());
+
+ IceStorm::TopicManagerPrx topicManager = IceStorm::TopicManagerPrx::checkedCast(
+ ic->propertyToProxy("SipStateReplicatorTopicManager.Proxy"));
+
+ IceStorm::TopicPrx topic;
+
+ if (topicManager)
+ {
+ try
+ {
+ topic = topicManager->retrieve("ConfigurationReplication");
+ }
+ catch (const IceStorm::NoSuchTopic&)
+ {
+ try
+ {
+ topic = topicManager->create("ConfigurationReplication");
+ }
+ catch (const IceStorm::TopicExists&)
+ {
+ lg(Error) << "Oh snap! Race condition creating topic, aborting";
+ return;
+ }
+ }
+ // There is no cast here on purpose as this is just going to get passed to
+ // the service locator which just takes a plain ol' proxy anyway.
+ mConfigurationPublisher = topic->getPublisher();
+ }
+ else
+ {
+ lg(Info) << "IceStorm topic manager proxy not present, unable to perform configuration replication.";
+ }
+
mAdapter = ic->createObjectAdapter("SipStateReplicator");
// setup logging client
@@ -210,7 +319,7 @@ void SipStateReplicatorService::initialize(const std::string& appName, const Ice
// Create and publish our ComponentService interface support.
mComponentService = new ComponentServiceImpl(*this);
mAdapter->add(mComponentService, ic->stringToIdentity(ComponentServiceId));
- mStateReplicator = new SipStateReplicatorI();
+ mStateReplicator = new SipStateReplicatorConfigI(topic);
mAdapter->add(mStateReplicator, ic->stringToIdentity(ServiceDiscoveryId));
mAdapter->activate();
@@ -228,6 +337,9 @@ void SipStateReplicatorService::stop()
{
// Remove our interfaces from the service locator.
deregisterFromServiceLocator();
+
+ // Stop our local IceStorm instance
+ mIceStorm->stop();
}
extern "C"
-----------------------------------------------------------------------
--
asterisk-scf/integration/sip.git
More information about the asterisk-scf-commits
mailing list