Browse code

TryFix: some emails are not migrated and the task does not report anything when running from CLI

Thomas Cataldo authored on 08/01/2019 14:12:12
Showing 1 changed files
... ...
@@ -81,7 +81,7 @@ public class MailboxHsmMigrationMaintenanceOperation extends MailboxMaintenanceO
81 81
 		}
82 82
 
83 83
 		if (!hsmCompleted(domainUid)) {
84
-			execute(domainUid);
84
+			traverseFolders(mailbox, domainUid, monitor);
85 85
 			markAsFinished(domainUid);
86 86
 		}
87 87
 
... ...
@@ -112,11 +112,8 @@ public class MailboxHsmMigrationMaintenanceOperation extends MailboxMaintenanceO
112 112
 				String.format("/var/spool/bm-hsm/snappy/user/%s/%s/hsm.promote.completed", domain, mailbox.uid));
113 113
 	}
114 114
 
115
-	private void execute(String domainUid) {
116
-		traverseFolders(mailbox, domainUid);
117
-	}
118
-
119
-	private void traverseFolders(ItemValue<Mailbox> mailbox, String domainUid) throws ServerFault {
115
+	private void traverseFolders(ItemValue<Mailbox> mailbox, String domainUid, IServerTaskMonitor monitor)
116
+			throws ServerFault {
120 117
 		logger.info("Traversing folders of mailbox {} type {}, routing: {}", mailbox.displayName, mailbox.value.type,
121 118
 				mailbox.value.routing);
122 119
 		ItemValue<Server> server = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
... ...
@@ -127,20 +124,21 @@ public class MailboxHsmMigrationMaintenanceOperation extends MailboxMaintenanceO
127 124
 					mailbox.value.type.nsPrefix + mailbox.value.name.replace(".", "^"));
128 125
 			List<ItemValue<MailboxFolder>> folders = mbService.all();
129 126
 
127
+			monitor.log("Found " + folders.size() + " for " + mailbox.value.name.replace(".", "^"));
130 128
 			logger.info("Found {} folders for ns {}{} on domain {}", folders.size(), mailbox.value.type.nsPrefix,
131 129
 					mailbox.value.name.replace(".", "^"), domainUid);
132 130
 
133 131
 			try (Sudo pass = new Sudo(mailbox.value.name, domainUid)) {
134 132
 				IHSM hsm = ServerSideServiceProvider.getProvider(pass.context).instance(IHSM.class, domainUid);
135 133
 				for (ItemValue<MailboxFolder> folder : folders) {
136
-					promote(domainUid, folder, hsm, pass, server);
134
+					promote(domainUid, folder, hsm, pass, server, monitor);
137 135
 				}
138 136
 			}
139 137
 		}
140 138
 	}
141 139
 
142 140
 	private void promote(String domainUid, ItemValue<MailboxFolder> folder, IHSM hsm, Sudo pass,
143
-			ItemValue<Server> server) {
141
+			ItemValue<Server> server, IServerTaskMonitor monitor) {
144 142
 		logger.info("Checking folder {} ", folder.value.fullName);
145 143
 
146 144
 		SearchQuery sq = new SearchQuery();
... ...
@@ -159,14 +157,15 @@ public class MailboxHsmMigrationMaintenanceOperation extends MailboxMaintenanceO
159 157
 				IDSet idset = IDSet.create(archived.iterator());
160 158
 
161 159
 				logger.info("Found {} archived entries in folder {} ", archived.size(), folder.displayName);
160
+				monitor.log(archived.size() + " archived messages in folder " + folder.value.fullName);
162 161
 
163 162
 				if (!archived.isEmpty()) {
164 163
 					idset.forEach(idRange -> {
165 164
 
166 165
 						logger.info("Promoting from {}  to {}", idRange.from(), idRange.to());
167 166
 
168
-						if (idRange.from() > 0 && idRange.to() > idRange.from()) {
169
-							String smallerRange = idRange.from() + ":" + idRange.to();
167
+						if (idRange.from() > 0) {
168
+							String smallerRange = idRange.toString();
170 169
 							Collection<Summary> imapSummaries = sc.uidFetchSummary(smallerRange);
171 170
 
172 171
 							logger.info("Promoting sums {}", imapSummaries.size());