[CalendarServer-changes] [14787] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu May 14 11:22:38 PDT 2015


Revision: 14787
          http://trac.calendarserver.org//changeset/14787
Author:   cdaboo at apple.com
Date:     2015-05-14 11:22:38 -0700 (Thu, 14 May 2015)
Log Message:
-----------
Add config option to support a migration-only mode of operation where HTTP requests (other than pod conduit) get a 503 response and no job processing takes place. This mode is used in the final sync pod2pod migration step.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/calendarserver/tap/util.py
    CalendarServer/trunk/twistedcaldav/simpleresource.py
    CalendarServer/trunk/twistedcaldav/stdconfig.py
    CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py
    CalendarServer/trunk/txdav/common/datastore/podding/migration/sync_metadata.py
    CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_migration.py
    CalendarServer/trunk/txdav/common/datastore/podding/migration/work.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -1303,7 +1303,8 @@
 
             pool = PeerConnectionPool(
                 reactor, store.newTransaction, ampPort,
-                useWorkerPool=False
+                useWorkerPool=False,
+                disableWorkProcessing=config.MigrationOnly,
             )
             self._initJobQueue(pool)
             store.queuer = store.queuer.transferProposalCallbacks(pool)
@@ -1873,7 +1874,8 @@
                 ampPort = None
 
             pool = PeerConnectionPool(
-                reactor, store.newTransaction, ampPort
+                reactor, store.newTransaction, ampPort,
+                disableWorkProcessing=config.MigrationOnly,
             )
             self._initJobQueue(pool)
 

Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/calendarserver/tap/util.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -72,7 +72,8 @@
 from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
 from twistedcaldav.directorybackedaddressbook import DirectoryBackedAddressBookResource
 from twistedcaldav.resource import AuthenticationWrapper
-from twistedcaldav.simpleresource import SimpleResource, SimpleRedirectResource
+from twistedcaldav.simpleresource import SimpleResource, SimpleRedirectResource, \
+    SimpleUnavailableResource
 from twistedcaldav.stdconfig import config
 from twistedcaldav.timezones import TimezoneCache
 from twistedcaldav.timezoneservice import TimezoneServiceResource
@@ -541,6 +542,11 @@
                 if e.errno != errno.ENOENT:
                     log.error("Could not delete: {path} : {error}", path=directoryPath, error=e)
 
+    if config.MigrationOnly:
+        unavailable = SimpleUnavailableResource((principalCollection,))
+    else:
+        unavailable = None
+
     log.info("Setting up root resource: {cls}", cls=rootResourceClass)
 
     root = rootResourceClass(
@@ -548,13 +554,13 @@
         principalCollections=(principalCollection,),
     )
 
-    root.putChild("principals", principalCollection)
+    root.putChild("principals", principalCollection if unavailable is None else unavailable)
     if config.EnableCalDAV:
-        root.putChild("calendars", calendarCollection)
+        root.putChild("calendars", calendarCollection if unavailable is None else unavailable)
     if config.EnableCardDAV:
-        root.putChild('addressbooks', addressBookCollection)
+        root.putChild('addressbooks', addressBookCollection if unavailable is None else unavailable)
         if config.DirectoryAddressBook.Enabled and config.EnableSearchAddressBook:
-            root.putChild(config.DirectoryAddressBook.name, directoryBackedAddressBookCollection)
+            root.putChild(config.DirectoryAddressBook.name, directoryBackedAddressBookCollection if unavailable is None else unavailable)
 
     # /.well-known
     if config.EnableWellKnown:
@@ -652,7 +658,7 @@
             newStore,
             podding=True
         )
-        root.putChild(config.Servers.InboxName, ischedule)
+        root.putChild(config.Servers.InboxName, ischedule if unavailable is None else unavailable)
 
         log.info("Setting up podding conduit resource: {cls}", cls=conduitResourceClass)
 
@@ -672,7 +678,7 @@
             root,
             newStore,
         )
-        root.putChild("ischedule", ischedule)
+        root.putChild("ischedule", ischedule if unavailable is None else unavailable)
 
         # Do DomainKey resources
         DKIMUtils.validConfiguration(config)
@@ -697,7 +703,7 @@
             config.WebCalendarRoot,
             principalCollections=(principalCollection,),
         )
-        root.putChild("webcal", webCalendar)
+        root.putChild("webcal", webCalendar if unavailable is None else unavailable)
 
     #
     # WebAdmin

Modified: CalendarServer/trunk/twistedcaldav/simpleresource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/simpleresource.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/twistedcaldav/simpleresource.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -26,9 +26,10 @@
     "SimpleDataResource",
 ]
 
-from txweb2 import http
+from txweb2 import http, server
+from txweb2 import responsecode
 from txweb2.dav.noneprops import NonePropertyStore
-from txweb2.http import Response
+from txweb2.http import Response, HTTPError
 
 from twisted.internet.defer import succeed
 
@@ -36,6 +37,8 @@
 
 from txdav.xml import element as davxml
 
+import time
+
 class SimpleResource (
     CalDAVResource,
 ):
@@ -108,6 +111,38 @@
 
 
 
+class SimpleUnavailableResource(SimpleResource):
+    """
+    A L{SimpleResource} which always generates a 503 Service Unavailable response with an optional Retry-After value.
+    """
+
+    def __init__(self, principalCollections, retryafter=300, defaultACL=SimpleResource.authReadACL, **kwargs):
+        """
+        Parameters are URL components and are the same as those for
+        L{urlparse.urlunparse}.  URL components which are not specified will
+        default to the corresponding component of the URL of the request being
+        redirected.
+
+        @param retryafter: time in seconds to use in Retry-After header, or -1 for no header
+        @type retryafter: L{int}
+        """
+        SimpleResource.__init__(self, principalCollections=principalCollections, isdir=False, defaultACL=defaultACL)
+        self.retryAfter = retryafter
+        self._kwargs = kwargs
+
+
+    def locateChild(self, request, segments):
+        return self, server.StopTraversal
+
+
+    def renderHTTP(self, request):
+        response = http.StatusResponse(responsecode.SERVICE_UNAVAILABLE, responsecode.RESPONSES[responsecode.SERVICE_UNAVAILABLE])
+        if self.retryAfter > 0:
+            response.headers.setHeader("Retry-After", time.time() + self.retryAfter)
+        raise HTTPError(response)
+
+
+
 class SimpleDataResource(SimpleResource):
     """
     A L{SimpleResource} which returns fixed content.

Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -262,6 +262,7 @@
     #
     "EnableCalDAV": True, # Enable CalDAV service
     "EnableCardDAV": True, # Enable CardDAV service
+    "MigrationOnly": False, # When True override all other services and set the server into podding-only mode
 
     #
     # Data store

Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -24,9 +24,8 @@
 from txdav.caldav.datastore.sql import ManagedAttachment, CalendarBindRecord
 from txdav.caldav.icalendarstore import ComponentUpdateState
 from txdav.common.datastore.podding.migration.sync_metadata import CalendarMigrationRecord, \
-    CalendarObjectMigrationRecord, AttachmentMigrationRecord, \
-    MigrationCleanupWork
-from txdav.common.datastore.podding.migration.work import HomeCleanupWork
+    CalendarObjectMigrationRecord, AttachmentMigrationRecord
+from txdav.common.datastore.podding.migration.work import HomeCleanupWork, MigrationCleanupWork
 from txdav.common.datastore.sql_external import NotificationCollectionExternal
 from txdav.common.datastore.sql_notification import NotificationCollection
 from txdav.common.datastore.sql_tables import _HOME_STATUS_MIGRATING, _HOME_STATUS_DISABLED, \

Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/sync_metadata.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/migration/sync_metadata.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/txdav/common/datastore/podding/migration/sync_metadata.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -16,7 +16,6 @@
 
 from twext.enterprise.dal.record import Record, fromTable
 from twext.enterprise.dal.syntax import Parameter, Delete
-from twext.enterprise.jobqueue import WorkItem
 from twisted.internet.defer import inlineCallbacks
 from txdav.common.datastore.sql_tables import schema
 
@@ -57,30 +56,3 @@
     L{Record} for L{schema.ATTACHMENT_MIGRATION}.
     """
     pass
-
-
-
-class MigrationCleanupWork(WorkItem, fromTable(schema.MIGRATION_CLEANUP_WORK)):
-
-    group = "homeResourceID"
-
-    notBeforeDelay = 300    # 5 minutes
-
-    @inlineCallbacks
-    def doWork(self):
-        """
-        Delete all the corresponding migration records.
-        """
-
-        yield CalendarMigrationRecord.deletesome(
-            self.transaction,
-            CalendarMigrationRecord.calendarHomeResourceID == self.homeResourceID,
-        )
-        yield CalendarObjectMigrationRecord.deletesome(
-            self.transaction,
-            CalendarObjectMigrationRecord.calendarHomeResourceID == self.homeResourceID,
-        )
-        yield AttachmentMigrationRecord.deletesome(
-            self.transaction,
-            AttachmentMigrationRecord.calendarHomeResourceID == self.homeResourceID,
-        )

Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_migration.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_migration.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_migration.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -31,9 +31,8 @@
 from txdav.caldav.datastore.test.common import CaptureProtocol
 from txdav.common.datastore.podding.migration.home_sync import CrossPodHomeSync
 from txdav.common.datastore.podding.migration.sync_metadata import CalendarMigrationRecord, \
-    AttachmentMigrationRecord, CalendarObjectMigrationRecord, \
-    MigrationCleanupWork
-from txdav.common.datastore.podding.migration.work import HomeCleanupWork, MigratedHomeCleanupWork
+    AttachmentMigrationRecord, CalendarObjectMigrationRecord
+from txdav.common.datastore.podding.migration.work import HomeCleanupWork, MigratedHomeCleanupWork, MigrationCleanupWork
 from txdav.common.datastore.podding.test.util import MultiStoreConduitTest
 from txdav.common.datastore.sql_directory import DelegateRecord,\
     DelegateGroupsRecord, ExternalDelegateGroupsRecord

Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/work.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/migration/work.py	2015-05-14 18:17:39 UTC (rev 14786)
+++ CalendarServer/trunk/txdav/common/datastore/podding/migration/work.py	2015-05-14 18:22:38 UTC (rev 14787)
@@ -21,6 +21,8 @@
 
 from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
 from txdav.caldav.datastore.scheduling.work import allScheduleWork
+from txdav.common.datastore.podding.migration.sync_metadata import CalendarMigrationRecord, \
+    CalendarObjectMigrationRecord, AttachmentMigrationRecord
 from txdav.common.datastore.sql_directory import DelegateRecord, \
     DelegateGroupsRecord, ExternalDelegateGroupsRecord
 from txdav.common.datastore.sql_tables import schema, _HOME_STATUS_DISABLED
@@ -99,3 +101,30 @@
         yield DelegateRecord.deletesome(self.transaction, DelegateRecord.delegator == self.ownerUID)
         yield DelegateGroupsRecord.deletesome(self.transaction, DelegateGroupsRecord.delegator == self.ownerUID)
         yield ExternalDelegateGroupsRecord.deletesome(self.transaction, ExternalDelegateGroupsRecord.delegator == self.ownerUID)
+
+
+
+class MigrationCleanupWork(WorkItem, fromTable(schema.MIGRATION_CLEANUP_WORK)):
+
+    group = "homeResourceID"
+
+    notBeforeDelay = 300    # 5 minutes
+
+    @inlineCallbacks
+    def doWork(self):
+        """
+        Delete all the corresponding migration records.
+        """
+
+        yield CalendarMigrationRecord.deletesome(
+            self.transaction,
+            CalendarMigrationRecord.calendarHomeResourceID == self.homeResourceID,
+        )
+        yield CalendarObjectMigrationRecord.deletesome(
+            self.transaction,
+            CalendarObjectMigrationRecord.calendarHomeResourceID == self.homeResourceID,
+        )
+        yield AttachmentMigrationRecord.deletesome(
+            self.transaction,
+            AttachmentMigrationRecord.calendarHomeResourceID == self.homeResourceID,
+        )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150514/3439713a/attachment-0001.html>


More information about the calendarserver-changes mailing list