Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Handle arbitrary exceptions during migration by logging the error and…

… continuing.

git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk@8033 e27351fd-9f3e-4f54-a53b-843176b1656c
  • Loading branch information
cyrusdaboo committed Aug 31, 2011
1 parent cb1ad47 commit 37da63ce9c20cffdc62940a1b8dded227c661c1d
@@ -0,0 +1,31 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//iCal 4.0.1//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:US/Pacific
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
DTSTART:20070311T020000
TZNAME:PDT
TZOFFSETTO:-0700
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
DTSTART:20071104T020000
TZNAME:PST
TZOFFSETTO:-0800
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTEND;TZID=US/Pacific:20070324T124500
UID:uid1
DTSTAMP:20090326T145447Z
SUMMARY:Busted
DTSTART;TZID=US/Pacific:20070324T121500
CREATED:20090326T145440Z
RRULE:FREQ=DAILY
END:VEVENT
END:VCALENDAR
@@ -0,0 +1,48 @@
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//Cyrusoft International\, Inc.//Mulberry v4.0//EN
BEGIN:VTIMEZONE
TZID:US/Eastern
LAST-MODIFIED:20040110T032845Z
BEGIN:STANDARD
DTSTART:20001026T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:EST
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20000404T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
TZNAME:EDT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
UID:uid2
DTSTART;TZID=US/Eastern:20060102T140000
DURATION:PT1H
CREATED:20060102T190000Z
DTSTAMP:20051222T210507Z
RRULE:FREQ=DAILY;COUNT=5
SUMMARY:event 6-%ctr
END:VEVENT
BEGIN:VEVENT
UID:uid2
RECURRENCE-ID;TZID=US/Eastern:20060104T140000
DTSTART;TZID=US/Eastern:20060104T160000
DURATION:PT1H
CREATED:20060102T190000Z
DESCRIPTION:Some notes
DTSTAMP:20051222T210507Z
SUMMARY:event 6-%ctr changed again
BEGIN:VALARM
ACTION:AUDIO
TRIGGER;RELATED=START:-PT10M
X-MULBERRY-ALARM-STATUS:PENDING
X-MULBERRY-SPEAK-TEXT:
END:VALARM
END:VEVENT
END:VCALENDAR
@@ -1854,6 +1854,7 @@ def test_eachCalendarHome(self):
uid for uid in self.requirements
if self.requirements[uid] is not None
])
additionalUIDs.add("home_bad")
expectedUIDs = additionalUIDs.union(requiredUIDs)
self.assertEquals(foundUIDs, expectedUIDs)

@@ -152,6 +152,23 @@ def test_migrateCalendarFromFile(self):
yield self.assertCalendarsSimilar(fromCalendar, toCalendar)


@inlineCallbacks
def test_migrateBadCalendarFromFile(self):
"""
C{_migrateCalendar()} can migrate a file-backed calendar to a database-
backed calendar.
"""
fromCalendar = yield (yield self.fileTransaction().calendarHomeWithUID(
"home_bad")).calendarWithName("calendar_bad")
toHome = yield self.transactionUnderTest().calendarHomeWithUID(
"new-home", create=True)
toCalendar = yield toHome.calendarWithName("calendar")
ok, bad = (yield _migrateCalendar(fromCalendar, toCalendar,
lambda x: x.component()))
self.assertEqual(ok, 1)
self.assertEqual(bad, 1)


@inlineCallbacks
def test_migrateHomeFromFile(self):
"""
@@ -129,8 +129,11 @@ def _migrateCalendar(inCalendar, outCalendar, getComponent):
@param outCalendar: the L{ICalendar} to store calendar objects to.
@param getComponent: a 1-argument callable; see L{migrateHome}.
@return: a L{Deferred} which fires when the calendar has migrated.
@return: a tuple of (ok count, bad count)
"""

ok_count = 0
bad_count = 0
outCalendar.properties().update(inCalendar.properties())
for calendarObject in (yield inCalendar.calendarObjects()):

@@ -164,15 +167,27 @@ def _migrateCalendar(inCalendar, outCalendar, getComponent):
proto =_AttachmentMigrationProto(transport)
attachment.retrieve(proto)
yield proto.done

ok_count += 1

except InternalDataStoreError:
log.error(" Failed to migrate calendar object: %s/%s/%s" % (
log.error(" InternalDataStoreError: Failed to migrate calendar object: %s/%s/%s" % (
inCalendar.ownerHome().name(),
inCalendar.name(),
calendarObject.name(),
))
bad_count += 1

except Exception, e:
log.error(" %s: Failed to migrate calendar object: %s/%s/%s" % (
str(e),
inCalendar.ownerHome().name(),
inCalendar.name(),
calendarObject.name(),
))
bad_count += 1

returnValue((ok_count, bad_count,))

class _AttachmentMigrationProto(Protocol, object):
def __init__(self, storeTransport):
@@ -18,7 +18,7 @@
"""
Utility logic common to multiple backend implementations.
"""
from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import inlineCallbacks, returnValue

from twistedcaldav.vcard import Component as VCard
from twistedcaldav.vcard import InvalidVCardDataError
@@ -76,6 +76,9 @@ def _migrateAddressbook(inAddressbook, outAddressbook, getComponent):
@param outAddressbook: the L{IAddressbook} to store addressbook objects to.
@param getComponent: a 1-argument callable; see L{migrateHome}.
"""

ok_count = 0
bad_count = 0
outAddressbook.properties().update(inAddressbook.properties())
inObjects = yield inAddressbook.addressbookObjects()
for addressbookObject in inObjects:
@@ -95,14 +98,26 @@ def _migrateAddressbook(inAddressbook, outAddressbook, getComponent):
if outAddressbook.objectResourcesHaveProperties():
outObject.properties().update(addressbookObject.properties())

ok_count += 1

except InternalDataStoreError:
log.error(" Failed to migrate adress book object: %s/%s/%s" % (
log.error(" InternalDataStoreError: Failed to migrate address book object: %s/%s/%s" % (
inAddressbook.ownerHome().name(),
inAddressbook.name(),
addressbookObject.name(),
))
bad_count += 1

except Exception, e:
log.error(" %s: Failed to migrate address book object: %s/%s/%s" % (
str(e),
inAddressbook.ownerHome().name(),
inAddressbook.name(),
addressbookObject.name(),
))
bad_count += 1

returnValue((ok_count, bad_count,))


@inlineCallbacks

0 comments on commit 37da63c

Please sign in to comment.
You can’t perform that action at this time.