Archived
This forum has been archived. Please start a new discussion on GitHub.
Simple Ice Registry Example
I have a fairly simple deployment where I want to have 2 environments, call them PROD and DEV. In ICE, seems easiest way to do this is to have 2 ICE registries, and have DEV servants register to DEV Registry, and PROD servants register to PROD registry. The location of the registry can then be placed into the ice config, and as long as we wrap that up so that the environment maps, we can use exactly same code in each environment.
Hopefully that is correct. But any best practices appreciated. Ill probably segregate DEV and PROD host by host, so no contention at port level. But that seems theoretially unnecessary.
In order to do this, Id like to just be able to create servants adapters with common names, and get proxies from the registry. I read a bunch of ice node docs, but seems overly complex for my app. I dont want to specify and configure the xml for each new servant. I want to be able to dynamically register each servant with its appropriate registry, and have clients request proxy from the same registry. What would be easiest way to accomplish this?
Hopefully that is correct. But any best practices appreciated. Ill probably segregate DEV and PROD host by host, so no contention at port level. But that seems theoretially unnecessary.
In order to do this, Id like to just be able to create servants adapters with common names, and get proxies from the registry. I read a bunch of ice node docs, but seems overly complex for my app. I dont want to specify and configure the xml for each new servant. I want to be able to dynamically register each servant with its appropriate registry, and have clients request proxy from the same registry. What would be easiest way to accomplish this?
0
Comments
-
Hi Tom,
You don't register servants with IceGrid, you register "object adapters". Object adapters are used to manage a collection of servants in the server (where each servant will incarnate an Ice object for which you can create a proxy).
I recommend you to checkout the Ice architecture chapter in the Ice manual, it's important that we use the same terminology.
To answer your question, you don't necessarily have to describe and register explicitly all your servers and object adapters in XML with the IceGrid registry. Object adapters can also be "dynamically registered" with the IceGrid registry upon startup of the server.
For this to work, you have to enable "dynamic registration" on the IceGrid registry by setting the IceGrid.Registry.DynamicRegistration property to 1. See Getting Started with IceGrid for more information on how to run a client and server using this mode.
Note that when using dynamic registration, you are responsible for manually starting the servers. You also don't have to use IceGrid nodes. You're basically just using the IceGrid registry has an "endpoint resolver" for object adapters.
Cheers,
Benoit.0 -
Thank you so much. I think I understand now.
From the point of view of the client, assume my server has this in its Ice.config file:
EncoderAdapter.AdapterId = instrument.one
EncoderAdapter.Endpoints = tcp
In python then, in the server, to activate this adapter I can do this:
ic = Ice.initialize()
adapter = ic.createObjectAdapter('instrument.one')
?? adapter.add(obj, ic.stringToIdentity('instrument.one')) ??
adapter.activate()
The client then has same registry set up, but how does it get the proxy from the registry (Python) ?
ic.stringToProxy("instrument.one")
Client Ice.config points to Ice.Default.Locator=IceGrid/Locator:tcp -h hostname -p 40610 -
It's not quite right, the following should work, for the server:
// Server configuration MyAdapter.Endpoints=tcp MyAdapter.AdapterId=Adapter1 Ice.Default.Locator=IceGrid/Locator:tcp -h hostname -p 4061 // Server code adapter = ic.createObjectAdapter("MyAdapter") adapter.add(obj1, ic.stringToIdentity("obj1")) adapter.activate()
In the above, the code creates an object adapter named "MyAdapter", the object adapter name is also the prefix for the configuration properties of the object adapter. We define 2 properties for this object adapter: its endpoints (tcp) and its AdapterId (Adapter1).
For the client:// Client configuration Ice.Default.Locator=IceGrid/Locator:tcp -h hostname -p 4061 // Client code proxy = ic.stringToProxy("obj1 @ Adapter1")
The client proxy is created from a string which specifies the Ice object identity and the adapter ID (see Proxy and Endpoint Syntax for more information on the proxy syntax).
You also need to make sure the IceGrid registry is started with IceGrid.Registry.DynamicRegistration=1 set.
Cheers,
Benoit.0 -
Thanks Benoit! Can I use the same adapter with multiple objects? Or do I need a unique adapter?
Using the same Adapter:DefaultTCPAdapter.AdapterId=DefaultTCPAdapter DefaultTCPAdapter.Endpoints=tcp
and creating:self.name = 'instruments' adapter = self.ic.createObjectAdapter('DefaultTCPAdapter') adapter.add(self, self.ic.stringToIdentity(self.name)) adapter.activate()
I get this error:ConnectionRefusedException: Ice.ConnectionRefusedException: Connection refused
What did I miss?0 -
You can register multiple servants with an object adapter to incarnate as many Ice objects. So yes, you can use a single object adapter to host many Ice objects.
Cheers,
Benoit.0 -
Thanks again Benoit. when I call adapter.activate as above, and it says Ice.ConnectionRefusedException, I can tell who is throwing that. I would think we cant have contention on the ports?0
-
Ran some more diagnostics:
-- 10/22/13 07:20:06.834 Network: listening for tcp connections at :::34308 local interfaces: 10.1.21.141, 10.1.43.30, 127.0.0.1, 0:0:0:0:0:0:0:1 -- 10/22/13 07:20:06.835 Network: published endpoints for object adapter `DefaultTCPAdapter': tcp -h 10.1.21.141 -p 34308:tcp -h 10.1.43.30 -p 34308 { name = instruments_new category = } Traceback (most recent call last): File "/home/tpologruto/workspace/ctp/trunk/ctp_python/ctp/core.py", line 175, in run adapter.activate() File "/opt/Ice-3.5.0/python/Ice.py", line 665, in activate self._impl.activate() ConnectionRefusedException: Ice.ConnectionRefusedException: Connection refused -- 10/22/13 07:20:06.839 Network: stopping to accept tcp connections at :::34308
0 -
It would seem that I cant connect to my registry? I cant even admin into it. icegridgui says permission denied as well.0
-
Hi,
Set Ice.Trace.Network=2 to see the IP address and port which is causing the Ice.ConnectionRefusedException. Most likely it's indeed failing to connect to the IceGrid registry.
Cheers,
Benoit.0 -
Ahh yes it was the registry port. Now one last error arises:
adapter = self.ic.createObjectAdapter('DefaultTCPAdapter') adapterid = self.ic.stringToIdentity(self.name) print adapterid adapter.add(self, adapterid) adapter.activate() Traceback (most recent call last): File "/home/tpologruto/workspace/ctp/trunk/ctp_python/ctp/core.py", line 175, in run adapter.activate() File "/opt/Ice-3.5.0/python/Ice.py", line 665, in activate self._impl.activate() ObjectNotExistException: exception ::Ice::ObjectNotExistException { id = { name = Locator category = IceGrid } facet = operation = getRegistry }
0 -
Can you post the configuration of your server, client and IceGrid registry?
Benoit.0 -
There is no client (yet). This is the Server where it fails to create the adapter as of now.
Server Config PropsDefaultTCPAdapter.AdapterId=TCPAdapter DefaultTCPAdapter.Endpoints=tcp Ice.BatchAutoFlush=1 Ice.CacheMessageBuffers=2 Ice.Default.CollocationOptimized=0 Ice.Default.Locator=IceGrid/Locator:tcp -h ntctp001 -p 4061 Ice.MessageSizeMax=102400 Ice.ThreadPool.Client.Size=3 Ice.ThreadPool.Client.SizeMax=5 Ice.ThreadPool.Server.Size=3 Ice.ThreadPool.Server.SizeMax=5 Ice.Trace.Locator=0 Ice.Trace.Network=0 Ice.Trace.Protocol=0 Ice.Warn.Connections=1 Ice.Warn.Dispatch=1
Ice Grid Config# Allow dynamic registration IceGrid.Registry.DynamicRegistration=1 # # The IceGrid instance name; must be unique, to distinguish several # IceGrid deployments # IceGrid.InstanceName=CTPDevIceGrid # # Client object adapter: listens on the loopback interface # IANA-registered TCP ports for the IceGrid registry: # - 4061 (insecure) # - 4062 (secure, using SSL) # # These endpoints must be accessible to Ice clients and servers as # well as the IceGrid administrative utilities. # # To listen on an additional interface add an additional endpoint with # -h <name | IP address> or remove -h localhost to listen on all # interfaces. # # IceGrid.Registry.Client.Endpoints=ssl -p 4062 # IceGrid.Registry.Client.Endpoints=tcp -p 4061 -h localhost:ssl -p 4062 -h localhost IceGrid.Registry.Client.Endpoints=tcp -p 4061 # Server and Internal object adapters: listens on the loopback # interface using an OS-assigned port number. # # The Server endpoints must be accessible to Ice servers deployed on # IceGrid nodes or to Ice servers using IceGrid dynamic # registration. The Internal endpoints must be accessible to IceGrid # nodes. # # To listen on an additional interface add an additional endpoint with # -h <name | IP address> or remove -h localhost to listen on all # interfaces. Note that access to these endpoints can pose a security # risk (remote code execution) and therefore these endpoints should be # secured. See the Ice manual for more information. # IceGrid.Registry.Server.Endpoints=tcp -h localhost IceGrid.Registry.Internal.Endpoints=tcp -h localhost # # The registry DB home; must exist when icegridregistry starts # # IceGrid.Registry.Data=/var/lib/ice/icegrid/registry IceGrid.Registry.Data=/opt/ice/registry # # Authentication/authorization # With NullPermissionsVerifier, any password is accepted (not recommended # for production) # IceGrid.Registry.PermissionsVerifier=DemoIceGrid/NullPermissionsVerifier IceGrid.Registry.AdminPermissionsVerifier=IceGrid/NullPermissionsVerifier # # Default templates # IceGrid.Registry.DefaultTemplates=/usr/share/Ice-3.5.0/templates.xml # Logging to syslog # Ice.UseSyslog=1 Ice.ProgramName=icegridregistry (DemoIceGrid Master) IceGrid.Registry.Trace.Node=1 IceGrid.Registry.Trace.Replica=1
0 -
Since you set IceGrid.InstanceName to "CTPDevIceGrid" you should set Ice.Default.Locator as follow:
Ice.Default.Locator=CTPDevIceGrid/Locator:tcp -h ntctp001 -p 4061
0 -
Ahh! That makes much more sense. I see one strange output (Unauthorized (401)) but all else seems to be working.
Many Many Thanks. ++10