[CalendarServer-changes] [4969] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jan 27 12:22:57 PST 2010
Revision: 4969
http://trac.macosforge.org/projects/calendarserver/changeset/4969
Author: cdaboo at apple.com
Date: 2010-01-27 12:22:54 -0800 (Wed, 27 Jan 2010)
Log Message:
-----------
A tool and .plists to help make setting up a partitioned server easier.
Added Paths:
-----------
CalendarServer/trunk/bin/calendarserver_make_partition
CalendarServer/trunk/calendarserver/tools/makepartition.py
CalendarServer/trunk/conf/caldavd-partitioning-primary.plist
CalendarServer/trunk/conf/caldavd-partitioning-secondary.plist
Added: CalendarServer/trunk/bin/calendarserver_make_partition
===================================================================
--- CalendarServer/trunk/bin/calendarserver_make_partition (rev 0)
+++ CalendarServer/trunk/bin/calendarserver_make_partition 2010-01-27 20:22:54 UTC (rev 4969)
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import sys
+
+#PYTHONPATH
+
+if __name__ == "__main__":
+ if "PYTHONPATH" in globals():
+ sys.path.insert(0, PYTHONPATH)
+ else:
+ from os.path import dirname, abspath, join
+ from subprocess import Popen, PIPE
+
+ home = dirname(dirname(abspath(__file__)))
+ run = join(home, "run")
+
+ child = Popen((run, "-p"), stdout=PIPE)
+ path, stderr = child.communicate()
+
+ if child.wait() == 0:
+ sys.path[0:0] = path.split(":")
+
+ from calendarserver.tools.makepartition import main
+ main()
Added: CalendarServer/trunk/calendarserver/tools/makepartition.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/makepartition.py (rev 0)
+++ CalendarServer/trunk/calendarserver/tools/makepartition.py 2010-01-27 20:22:54 UTC (rev 4969)
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from optparse import OptionParser
+from twext.python.plistlib import readPlist, writePlist
+import os
+import sys
+from twistedcaldav.config import ConfigurationError, Config
+from twistedcaldav.stdconfig import PListConfigProvider, DEFAULT_CONFIG
+from urlparse import urlparse
+
+def error(s):
+ print s
+ sys.exit(1)
+
+def createPrimary(options):
+ _createNode(options, True)
+ print "Created primary partition with node id '%s' and uri '%s'" % (options.nodeid, options.nodeurl,)
+
+def createSecondary(options):
+ _createNode(options, False)
+ print "Created secondary partition with node id '%s' and uri '%s'" % (options.nodeid, options.nodeurl,)
+
+def _createNode(options, isPrimary):
+
+ # Read in main plist
+ try:
+ dataDict = readPlist(options.conf)
+ except (IOError, OSError):
+ raise RuntimeError("Main plist file does not exist or is inaccessible: %s" % (options.conf,))
+
+ # Look for includes
+ includes = dataDict.setdefault("Includes", [])
+
+ # Make sure partitioning plist is included
+ primaryPlist = "caldavd-partitioning-primary.plist"
+ secondaryPlist = "caldavd-partitioning-secondary.plist"
+ partitioningPlistAdd = os.path.join(
+ os.path.dirname(options.conf),
+ primaryPlist if isPrimary else secondaryPlist,
+ )
+ partitioningPlistRemove = os.path.join(
+ os.path.dirname(options.conf),
+ secondaryPlist if isPrimary else primaryPlist,
+ )
+ if partitioningPlistAdd not in includes:
+ includes.append(partitioningPlistAdd)
+ if partitioningPlistRemove in includes:
+ includes.remove(partitioningPlistRemove)
+
+ # Push out main plist change
+ try:
+ writePlist(dataDict, options.conf)
+ except (IOError, OSError):
+ raise RuntimeError("Could not write main plist file: %s" % (options.conf,))
+
+ # Now edit partitioning plist
+ try:
+ dataDict = readPlist(partitioningPlistAdd)
+ except (IOError, OSError):
+ raise RuntimeError("Partitioning plist file does not exist or is inaccessible: %s" % (partitioningPlistAdd,))
+
+ # Need to adjust the node id, and host names
+ dataDict["Partitioning"]["ServerPartitionID"] = options.nodeid
+
+ if not isPrimary:
+ _ignore_scheme, netloc, _ignore_path, _ignore_params, _ignore_query, _ignore_fragment = urlparse(options.primaryurl)
+ if ':' in netloc:
+ host = netloc.split(':')[0]
+ else:
+ host = netloc
+ dataDict["ProxyDBService"]["params"]["host"] = host
+ dataDict["Memcached"]["Pools"]["CommonToAllNodes"]["BindAddress"] = host
+
+ # Push out partitioning plist change
+ try:
+ writePlist(dataDict, partitioningPlistAdd)
+ except (IOError, OSError):
+ raise RuntimeError("Could not write partitioning plist file: %s" % (partitioningPlistAdd,))
+
+def addOther(options):
+ _addOther(options.conf, options.nodeid, options.nodeurl)
+ print "Added partition with node id '%s' and uri '%s' to partitions plist" % (options.nodeid, options.nodeurl,)
+
+def _addOther(conf, nodeid, nodeurl):
+
+ # Read main plist
+ try:
+ cfg = Config(PListConfigProvider(DEFAULT_CONFIG))
+ cfg.load(conf)
+ except ConfigurationError:
+ raise RuntimeError("Could not parse as plist: '%s'" % (conf,))
+
+ # Read in the partitions plist
+ partitionsPlist = cfg.Partitioning.PartitionConfigFile
+ try:
+ dataDict = readPlist(partitionsPlist)
+ except (IOError, OSError):
+ raise RuntimeError("Partitions plist file does not exist or is inaccessible: %s" % (partitionsPlist,))
+
+ # See if node id already exists
+ if nodeid in [partition.get("uid", None) for partition in dataDict.get("partitions", ())]:
+ raise RuntimeError("Node '%s' already in partitions plist '%s'" % (nodeid, partitionsPlist,))
+
+ # Add new information and write it out
+ dataDict.setdefault("partitions", []).append(
+ {
+ "uid": nodeid,
+ "url": nodeurl,
+ }
+ )
+ try:
+ writePlist(dataDict, partitionsPlist)
+ except (IOError, OSError):
+ raise RuntimeError("Could not write partitions plist: %s" % (partitionsPlist,))
+
+def main():
+
+ usage = "%prog [options] MODE"
+ epilog = """
+MODE is one of primary|secondary|add
+
+ primary: Create a new primary node (manages main DBs)
+ secondary: Create a new secondary node
+ add: Add information for a new partition node on another machine
+"""
+ description = "Tool to setup CalendarServer partition node configuration files"
+ version = "%prog v1.0"
+ parser = OptionParser(usage=usage, description=description, version=version)
+ parser.epilog = epilog
+ parser.format_epilog = lambda _:epilog
+
+ parser.add_option("-c", "--conf", dest="conf",
+ help="Directory where .plist files are stored", metavar="CONF")
+ parser.add_option("-n", "--nodeid", dest="nodeid",
+ help="Node ID for this node", metavar="NODEID")
+ parser.add_option("-u", "--url", dest="nodeurl",
+ help="URL of node being added", metavar="NODEURL")
+ parser.add_option("-p", "--primary", dest="primaryurl",
+ help="URL of primary node", metavar="PRIMARYURL")
+
+ (options, args) = parser.parse_args()
+
+ if len(args) != 1:
+ parser.error("incorrect number of arguments")
+
+ # Make sure conf dir has the needed .plist files
+ if not os.path.exists(options.conf):
+ parser.error("Could not find '%s'" % (options.conf,))
+ confdir = os.path.dirname(options.conf)
+ if not os.path.exists(os.path.join(confdir, "caldavd-partitioning-primary.plist")):
+ parser.error("Could not find caldavd-partitioning-primary.plist in '%s'" % (confdir,))
+ if not os.path.exists(os.path.join(confdir, "caldavd-partitioning-secondary.plist")):
+ parser.error("Could not find caldavd-partitioning-secondary.plist in '%s'" % (confdir,))
+
+ # Handle each action
+ {
+ "primary" : createPrimary,
+ "secondary": createSecondary,
+ "add" : addOther,
+ }[args[0]](options)
+
+if __name__ == '__main__':
+ main()
Added: CalendarServer/trunk/conf/caldavd-partitioning-primary.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-partitioning-primary.plist (rev 0)
+++ CalendarServer/trunk/conf/caldavd-partitioning-primary.plist 2010-01-27 20:22:54 UTC (rev 4969)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+
+ <!-- Partitioning -->
+ <key>Partitioning</key>
+ <dict>
+ <key>Enabled</key>
+ <true/>
+ <key>ServerPartitionID</key>
+ <string>00001</string>
+ <key>PartitionConfigFile</key>
+ <string>/etc/caldavd/partitions.plist</string>
+ <key>MaxClients</key>
+ <integer>5</integer>
+ </dict>
+
+ <!-- PostgreSQL ProxyDB Service -->
+ <key>ProxyDBService</key>
+ <dict>
+ <key>type</key>
+ <string>twistedcaldav.directory.calendaruserproxy.ProxyPostgreSQLDB</string>
+
+ <key>params</key>
+ <dict>
+ <key>host</key>
+ <string>localhost</string>
+ <key>database</key>
+ <string>proxies</string>
+ </dict>
+ </dict>
+
+ <!-- Support for Memcached -->
+ <key>Memcached</key>
+ <dict>
+ <key>Pools</key>
+ <dict>
+ <key>CommonToAllNodes</key>
+ <dict>
+ <key>ClientEnabled</key>
+ <true/>
+ <key>ServerEnabled</key>
+ <true/>
+ <key>BindAddress</key>
+ <string>localhost</string>
+ <key>Port</key>
+ <integer>11311</integer>
+ <key>HandleCacheTypes</key>
+ <array>
+ <string>ProxyDB</string>
+ <string>PrincipalToken</string>
+ <string>DIGESTCREDENTIALS</string>
+ </array>
+ </dict>
+ </dict>
+ <key>MaxClients</key>
+ <integer>5</integer>
+ <key>memcached</key>
+ <string>../memcached/_root/bin/memcached</string> <!-- Find in PATH -->
+ <key>Options</key>
+ <array>
+ <!--<string>-vv</string>-->
+ </array>
+ </dict>
+
+ </dict>
+</plist>
Added: CalendarServer/trunk/conf/caldavd-partitioning-secondary.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-partitioning-secondary.plist (rev 0)
+++ CalendarServer/trunk/conf/caldavd-partitioning-secondary.plist 2010-01-27 20:22:54 UTC (rev 4969)
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+
+ <!-- Partitioning -->
+ <key>Partitioning</key>
+ <dict>
+ <key>Enabled</key>
+ <true/>
+ <key>ServerPartitionID</key>
+ <string>00002</string>
+ <key>PartitionConfigFile</key>
+ <string>/etc/caldavd/partitions.plist</string>
+ <key>MaxClients</key>
+ <integer>5</integer>
+ </dict>
+
+ <!-- PostgreSQL ProxyDB Service -->
+ <key>ProxyDBService</key>
+ <dict>
+ <key>type</key>
+ <string>twistedcaldav.directory.calendaruserproxy.ProxyPostgreSQLDB</string>
+
+ <key>params</key>
+ <dict>
+ <key>host</key>
+ <string>localhost</string>
+ <key>database</key>
+ <string>proxies</string>
+ </dict>
+ </dict>
+
+ <!-- Support for Memcached -->
+ <key>Memcached</key>
+ <dict>
+ <key>Pools</key>
+ <dict>
+ <key>CommonToAllNodes</key>
+ <dict>
+ <key>ClientEnabled</key>
+ <true/>
+ <key>ServerEnabled</key>
+ <false/>
+ <key>BindAddress</key>
+ <string>localhost</string>
+ <key>Port</key>
+ <integer>11311</integer>
+ <key>HandleCacheTypes</key>
+ <array>
+ <string>ProxyDB</string>
+ <string>PrincipalToken</string>
+ <string>DIGESTCREDENTIALS</string>
+ </array>
+ </dict>
+ </dict>
+ <key>MaxClients</key>
+ <integer>5</integer>
+ <key>memcached</key>
+ <string>../memcached/_root/bin/memcached</string> <!-- Find in PATH -->
+ <key>Options</key>
+ <array>
+ <!--<string>-vv</string>-->
+ </array>
+ </dict>
+
+ </dict>
+</plist>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100127/de9d8959/attachment-0001.html>
More information about the calendarserver-changes
mailing list