[CalendarServer-changes] [14770] CalendarServer/trunk/txdav

source_changes at macosforge.org source_changes at macosforge.org
Thu May 7 11:57:24 PDT 2015


Revision: 14770
          http://trac.calendarserver.org//changeset/14770
Author:   cdaboo at apple.com
Date:     2015-05-07 11:57:24 -0700 (Thu, 07 May 2015)
Log Message:
-----------
pod2pod iMIP token reconcile.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/caldav/datastore/sql_external.py
    CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py
    CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_home_sync.py
    CalendarServer/trunk/txdav/common/datastore/podding/store_api.py

Added Paths:
-----------
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/token.py

Added: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/token.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/token.py	                        (rev 0)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/token.py	2015-05-07 18:57:24 UTC (rev 14770)
@@ -0,0 +1,30 @@
+# -*- test-case-name: txdav.caldav.datastore.scheduling.test.test_imip -*-
+##
+# Copyright (c) 2005-2015 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 twext.enterprise.dal.record import fromTable, SerializableRecord
+from txdav.common.datastore.sql_tables import schema
+
+"""
+Database L{Record} for iMIP tokens.
+"""
+
+class iMIPTokenRecord(SerializableRecord, fromTable(schema.IMIP_TOKENS)):
+    """
+    @DynamicAttrs
+    L{Record} for L{schema.NOTIFICATION}.
+    """
+    pass

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2015-05-06 19:22:50 UTC (rev 14769)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2015-05-07 18:57:24 UTC (rev 14770)
@@ -59,6 +59,7 @@
 from txdav.caldav.datastore.scheduling.cuaddress import calendarUserFromCalendarUserAddress
 from txdav.caldav.datastore.scheduling.icaldiff import iCalDiff
 from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
+from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
 from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
 from txdav.caldav.datastore.scheduling.utils import uidFromCalendarUserAddress
 from txdav.caldav.datastore.sql_attachment import Attachment, DropBoxAttachment, \
@@ -1034,6 +1035,10 @@
             yield inbox.notifyPropertyChanged()
 
 
+    def iMIPTokens(self):
+        return iMIPTokenRecord.query(self._txn, iMIPTokenRecord.organizer == "urn:x-uid:{}".format(self.uid()))
+
+
 CalendarHome._register(ECALENDARTYPE)
 
 

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql_external.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql_external.py	2015-05-06 19:22:50 UTC (rev 14769)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql_external.py	2015-05-07 18:57:24 UTC (rev 14770)
@@ -22,6 +22,7 @@
 
 from twext.python.log import Logger
 
+from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
 from txdav.caldav.datastore.sql import CalendarHome, Calendar, CalendarObject
 from txdav.caldav.datastore.sql_attachment import Attachment, AttachmentLink
 from txdav.caldav.datastore.sql_directory import GroupAttendeeRecord, GroupShareeRecord
@@ -189,7 +190,13 @@
         raise AssertionError("CommonHomeExternal: not supported")
 
 
+    @inlineCallbacks
+    def iMIPTokens(self):
+        results = yield self._txn.store().conduit.send_home_imip_tokens(self)
+        returnValue(map(iMIPTokenRecord.deserialize, results))
 
+
+
 class CalendarExternal(CommonHomeChildExternal, Calendar):
     """
     SQL-based implementation of L{ICalendar}.

Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py	2015-05-06 19:22:50 UTC (rev 14769)
+++ CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py	2015-05-07 18:57:24 UTC (rev 14770)
@@ -213,7 +213,7 @@
         yield self.notificationsReconcile()
 
         # TODO: iMIP tokens
-        pass
+        yield self.iMIPTokensReconcile()
 
         # TODO: work items
         pass
@@ -1358,3 +1358,47 @@
         records = yield remote_calendar.migrateBindRecords(None)
         self.accounting("    Updating remote records")
         returnValue(records)
+
+
+    @inlineCallbacks
+    def iMIPTokensReconcile(self):
+        """
+        Sync all the existing L{iMIPTokenRecord} records from the remote store.
+        """
+
+        self.accounting("Starting: iMIPTokensReconcile...")
+        records = yield self.iMIPTokenRecords()
+        self.accounting("  Found {} iMIPToken records".format(len(records)))
+
+        # Batch setting resources for the local home
+        len_records = len(records)
+        while records:
+            yield self.makeiMIPTokens(records[:50])
+            records = records[50:]
+
+        self.accounting("Completed: iMIPTokensReconcile.")
+
+        returnValue(len_records)
+
+
+    @inTransactionWrapper
+    @inlineCallbacks
+    def iMIPTokenRecords(self, txn):
+        """
+        Get all the existing L{iMIPTokenRecord}'s from the remote store.
+        """
+
+        remote_home = yield self._remoteHome(txn)
+        records = yield remote_home.iMIPTokens()
+        returnValue(records)
+
+
+    @inTransactionWrapper
+    @inlineCallbacks
+    def makeiMIPTokens(self, txn, records):
+        """
+        Create L{iMIPTokenRecord} records in the local store.
+        """
+
+        for record in records:
+            yield record.insert(txn)

Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_home_sync.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_home_sync.py	2015-05-06 19:22:50 UTC (rev 14769)
+++ CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_home_sync.py	2015-05-07 18:57:24 UTC (rev 14770)
@@ -22,6 +22,7 @@
 from twisted.python.filepath import FilePath
 from twistedcaldav.config import config
 from twistedcaldav.ical import Component, normalize_iCalStr
+from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
 from txdav.caldav.datastore.sql import ManagedAttachment
 from txdav.caldav.datastore.sql_directory import GroupShareeRecord
 from txdav.common.datastore.podding.migration.home_sync import CrossPodHomeSync
@@ -1073,7 +1074,7 @@
     @inlineCallbacks
     def test_shared_collections_reconcile(self):
         """
-        Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups..
+        Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups.
         """
 
         # Create home
@@ -1146,7 +1147,7 @@
     @inlineCallbacks
     def test_group_shared_collections_reconcile(self):
         """
-        Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups..
+        Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups.
         """
 
         # Create home
@@ -1305,3 +1306,111 @@
         group04 = yield self.theTransactionUnderTest(1).groupByUID(u"group04")
         self.assertEqual(record.groupID, group04.groupID)
         self.assertEqual(record.membershipHash, group04.membershipHash)
+
+
+
+class TestiMIPTokensSync(MultiStoreConduitTest):
+    """
+    Test that L{CrossPodHomeSync} iMIP token sync works.
+    """
+
+    @inlineCallbacks
+    def setUp(self):
+        self.accounts = FilePath(__file__).sibling("accounts").child("groupAccounts.xml")
+        self.augments = FilePath(__file__).sibling("accounts").child("augments.xml")
+        yield super(TestiMIPTokensSync, self).setUp()
+        yield self.populate()
+
+
+    @inlineCallbacks
+    def populate(self):
+        yield populateCalendarsFrom(self.requirements, self.theStoreUnderTest(0))
+
+    requirements = {
+        "user01" : None,
+        "user02" : None,
+        "user06" : None,
+        "user07" : None,
+        "user08" : None,
+        "user09" : None,
+        "user10" : None,
+    }
+
+
+    @inlineCallbacks
+    def _createTokens(self, txn, organizer, attendee_prefix, number):
+
+        for n in range(number):
+            yield iMIPTokenRecord.create(
+                txn,
+                token=str(uuid4()),
+                organizer=organizer,
+                attendee="mailto:{}{}@example.com".format(attendee_prefix, n + 1),
+                icaluid=str(uuid4()),
+            )
+
+
+    @inlineCallbacks
+    def test_token_sync(self):
+        """
+        Test that L{iMIPTokensReconcile} copies over the full set of iMIP tokens.
+        """
+
+        # Start with tokens on each pod for different sets of users
+        txn = self.theTransactionUnderTest(0)
+        yield self._createTokens(txn, "urn:x-uid:user01", "xyz_user01", 10)
+        yield self._createTokens(txn, "urn:x-uid:user02", "xyz_user02", 10)
+        yield self.commitTransaction(0)
+
+        txn = self.theTransactionUnderTest(1)
+        yield self._createTokens(txn, "urn:x-uid:puser01", "xyz_puser01", 10)
+        yield self._createTokens(txn, "urn:x-uid:puser02", "xyz_puser02", 10)
+        yield self.commitTransaction(1)
+
+        # Double-check tokens are there
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:user01")
+        self.assertEqual(len(records), 10)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:user02")
+        self.assertEqual(len(records), 10)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:puser01")
+        self.assertEqual(len(records), 0)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:puser02")
+        self.assertEqual(len(records), 0)
+        yield self.commitTransaction(0)
+
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:user01")
+        self.assertEqual(len(records), 0)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:user02")
+        self.assertEqual(len(records), 0)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:puser01")
+        self.assertEqual(len(records), 10)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:puser02")
+        self.assertEqual(len(records), 10)
+        yield self.commitTransaction(1)
+
+        # Do the sync
+        syncer = CrossPodHomeSync(self.theStoreUnderTest(1), "user01")
+        yield syncer.loadRecord()
+        count = yield syncer.iMIPTokensReconcile()
+        self.assertEqual(count, 10)
+
+        # Tokens have been copied - original still in place
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:user01")
+        self.assertEqual(len(records), 10)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:user02")
+        self.assertEqual(len(records), 10)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:puser01")
+        self.assertEqual(len(records), 0)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(0), iMIPTokenRecord.organizer == "urn:x-uid:puser02")
+        self.assertEqual(len(records), 0)
+        yield self.commitTransaction(0)
+
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:user01")
+        self.assertEqual(len(records), 10)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:user02")
+        self.assertEqual(len(records), 0)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:puser01")
+        self.assertEqual(len(records), 10)
+        records = yield iMIPTokenRecord.query(self.theTransactionUnderTest(1), iMIPTokenRecord.organizer == "urn:x-uid:puser02")
+        self.assertEqual(len(records), 10)
+        yield self.commitTransaction(1)

Modified: CalendarServer/trunk/txdav/common/datastore/podding/store_api.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/store_api.py	2015-05-06 19:22:50 UTC (rev 14769)
+++ CalendarServer/trunk/txdav/common/datastore/podding/store_api.py	2015-05-07 18:57:24 UTC (rev 14770)
@@ -175,6 +175,7 @@
 UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_set_status", "setStatus")
 UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_get_all_group_attendees", "getAllGroupAttendees", transform_recv_result=StoreAPIConduitMixin._to_serialize_pair_list)
 UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_shared_to_records", "sharedToBindRecords", transform_recv_result=StoreAPIConduitMixin._to_serialize_dict_list_serialized_value)
+UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_imip_tokens", "iMIPTokens", transform_recv_result=UtilityConduitMixin._to_serialize_list)
 
 # Calls on L{CommonHomeChild} objects
 UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "homechild_listobjects", "listObjects", classMethod=True)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150507/c7f44290/attachment-0001.html>


More information about the calendarserver-changes mailing list