<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14770] CalendarServer/trunk/txdav</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14770">14770</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-05-07 11:57:24 -0700 (Thu, 07 May 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>pod2pod iMIP token reconcile.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresql_externalpy">CalendarServer/trunk/txdav/caldav/datastore/sql_external.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastorepoddingmigrationhome_syncpy">CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastorepoddingmigrationtesttest_home_syncpy">CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_home_sync.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastorepoddingstore_apipy">CalendarServer/trunk/txdav/common/datastore/podding/store_api.py</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingimiptokenpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/token.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingimiptokenpy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/caldav/datastore/scheduling/imip/token.py (0 => 14770)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,30 @@
</span><ins>+# -*- 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
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (14769 => 14770)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx"> from txdav.caldav.datastore.scheduling.cuaddress import calendarUserFromCalendarUserAddress
</span><span class="cx"> from txdav.caldav.datastore.scheduling.icaldiff import iCalDiff
</span><span class="cx"> from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
</span><ins>+from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
</ins><span class="cx"> from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
</span><span class="cx"> from txdav.caldav.datastore.scheduling.utils import uidFromCalendarUserAddress
</span><span class="cx"> from txdav.caldav.datastore.sql_attachment import Attachment, DropBoxAttachment, \
</span><span class="lines">@@ -1034,6 +1035,10 @@
</span><span class="cx"> yield inbox.notifyPropertyChanged()
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def iMIPTokens(self):
+ return iMIPTokenRecord.query(self._txn, iMIPTokenRecord.organizer == "urn:x-uid:{}".format(self.uid()))
+
+
</ins><span class="cx"> CalendarHome._register(ECALENDARTYPE)
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresql_externalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql_external.py (14769 => 14770)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -22,6 +22,7 @@
</span><span class="cx">
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx">
</span><ins>+from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
</ins><span class="cx"> from txdav.caldav.datastore.sql import CalendarHome, Calendar, CalendarObject
</span><span class="cx"> from txdav.caldav.datastore.sql_attachment import Attachment, AttachmentLink
</span><span class="cx"> from txdav.caldav.datastore.sql_directory import GroupAttendeeRecord, GroupShareeRecord
</span><span class="lines">@@ -189,7 +190,13 @@
</span><span class="cx"> raise AssertionError("CommonHomeExternal: not supported")
</span><span class="cx">
</span><span class="cx">
</span><ins>+ @inlineCallbacks
+ def iMIPTokens(self):
+ results = yield self._txn.store().conduit.send_home_imip_tokens(self)
+ returnValue(map(iMIPTokenRecord.deserialize, results))
</ins><span class="cx">
</span><ins>+
+
</ins><span class="cx"> class CalendarExternal(CommonHomeChildExternal, Calendar):
</span><span class="cx"> """
</span><span class="cx"> SQL-based implementation of L{ICalendar}.
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastorepoddingmigrationhome_syncpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/home_sync.py (14769 => 14770)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -213,7 +213,7 @@
</span><span class="cx"> yield self.notificationsReconcile()
</span><span class="cx">
</span><span class="cx"> # TODO: iMIP tokens
</span><del>- pass
</del><ins>+ yield self.iMIPTokensReconcile()
</ins><span class="cx">
</span><span class="cx"> # TODO: work items
</span><span class="cx"> pass
</span><span class="lines">@@ -1358,3 +1358,47 @@
</span><span class="cx"> records = yield remote_calendar.migrateBindRecords(None)
</span><span class="cx"> self.accounting(" Updating remote records")
</span><span class="cx"> returnValue(records)
</span><ins>+
+
+ @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)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastorepoddingmigrationtesttest_home_syncpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/podding/migration/test/test_home_sync.py (14769 => 14770)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -22,6 +22,7 @@
</span><span class="cx"> from twisted.python.filepath import FilePath
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.ical import Component, normalize_iCalStr
</span><ins>+from txdav.caldav.datastore.scheduling.imip.token import iMIPTokenRecord
</ins><span class="cx"> from txdav.caldav.datastore.sql import ManagedAttachment
</span><span class="cx"> from txdav.caldav.datastore.sql_directory import GroupShareeRecord
</span><span class="cx"> from txdav.common.datastore.podding.migration.home_sync import CrossPodHomeSync
</span><span class="lines">@@ -1073,7 +1074,7 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def test_shared_collections_reconcile(self):
</span><span class="cx"> """
</span><del>- Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups..
</del><ins>+ Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups.
</ins><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> # Create home
</span><span class="lines">@@ -1146,7 +1147,7 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def test_group_shared_collections_reconcile(self):
</span><span class="cx"> """
</span><del>- Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups..
</del><ins>+ Test that L{sharedCollectionsReconcile} copies over the full set of delegates and caches associated groups.
</ins><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> # Create home
</span><span class="lines">@@ -1305,3 +1306,111 @@
</span><span class="cx"> group04 = yield self.theTransactionUnderTest(1).groupByUID(u"group04")
</span><span class="cx"> self.assertEqual(record.groupID, group04.groupID)
</span><span class="cx"> self.assertEqual(record.membershipHash, group04.membershipHash)
</span><ins>+
+
+
+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)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastorepoddingstore_apipy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/podding/store_api.py (14769 => 14770)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -175,6 +175,7 @@
</span><span class="cx"> UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_set_status", "setStatus")
</span><span class="cx"> UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_get_all_group_attendees", "getAllGroupAttendees", transform_recv_result=StoreAPIConduitMixin._to_serialize_pair_list)
</span><span class="cx"> UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_shared_to_records", "sharedToBindRecords", transform_recv_result=StoreAPIConduitMixin._to_serialize_dict_list_serialized_value)
</span><ins>+UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "home_imip_tokens", "iMIPTokens", transform_recv_result=UtilityConduitMixin._to_serialize_list)
</ins><span class="cx">
</span><span class="cx"> # Calls on L{CommonHomeChild} objects
</span><span class="cx"> UtilityConduitMixin._make_simple_action(StoreAPIConduitMixin, "homechild_listobjects", "listObjects", classMethod=True)
</span></span></pre>
</div>
</div>
</body>
</html>