use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.
the class ProvUtil method doUnlockMailbox.
private void doUnlockMailbox(String[] args) throws ServiceException {
String accountVal = null;
if (args.length > 1) {
accountVal = args[1];
} else {
usage();
return;
}
if (accountVal != null) {
//will throw NO_SUCH_ACCOUNT if not found
Account acct = lookupAccount(accountVal);
if (!acct.getAccountStatus().isActive()) {
throw ServiceException.FAILURE(String.format("Cannot unlock mailbox for account %s. Account status must be %s. Curent account status is %s. " + "You must change the value of zimbraAccountStatus to '%s' first", accountVal, AccountStatus.active, acct.getAccountStatus(), AccountStatus.active), null);
}
String accName = acct.getName();
String server = acct.getMailHost();
try {
sendMailboxLockoutRequest(accName, server, AdminConstants.A_END);
} catch (ServiceException e) {
if (ServiceException.UNKNOWN_DOCUMENT.equals(e.getCode())) {
throw ServiceException.FAILURE("source server version does not support " + AdminConstants.E_LOCKOUT_MAILBOX_REQUEST, e);
} else if (ServiceException.NOT_FOUND.equals(e.getCode())) {
//if mailbox is not locked, move on
printOutput("Warning: " + e.getMessage());
} else {
throw e;
}
} catch (IOException e) {
throw ServiceException.FAILURE(String.format("Error sending %s (operation = %s) request for %s to %s", AdminConstants.E_LOCKOUT_MAILBOX_REQUEST, AdminConstants.A_END, accountVal, server), e);
}
//unregister moveout if hostname is provided
if (args.length > 2) {
//set account status to maintenance and lock the mailbox to avoid race conditions
acct.setAccountStatus(AccountStatus.maintenance);
try {
sendMailboxLockoutRequest(accName, server, AdminConstants.A_START);
} catch (IOException e) {
throw ServiceException.FAILURE(String.format("Error sending %s (opertion = %s) request for %s to %s.\n Warning: Account is left in maintenance state!", AdminConstants.E_LOCKOUT_MAILBOX_REQUEST, AdminConstants.A_START, accountVal, server), e);
}
//unregister moveout via SOAP
String targetServer = args[2];
try {
UnregisterMailboxMoveOutRequest unregisterReq = UnregisterMailboxMoveOutRequest.create(MailboxMoveSpec.createForNameAndTarget(accName, targetServer));
String url = URLUtil.getAdminURL(server);
ZAuthToken token = ((SoapProvisioning) prov).getAuthToken();
SoapHttpTransport transport = new SoapHttpTransport(url);
transport.setAuthToken(token);
transport.invokeWithoutSession(JaxbUtil.jaxbToElement(unregisterReq));
} catch (ServiceException e) {
if (ServiceException.UNKNOWN_DOCUMENT.equals(e.getCode())) {
throw ServiceException.FAILURE(String.format("target server version does not support %s.", BackupConstants.E_UNREGISTER_MAILBOX_MOVE_OUT_REQUEST), e);
} else {
throw ServiceException.FAILURE("Failed to unregister mailbox moveout", e);
}
} catch (IOException e) {
throw ServiceException.FAILURE(String.format("Error sending %s request for %s to %s.", BackupConstants.E_UNREGISTER_MAILBOX_MOVE_OUT_REQUEST, accountVal, server), e);
} finally {
//unlock mailbox object and end account maintenance even if failed to unregister moveout
try {
sendMailboxLockoutRequest(accName, server, AdminConstants.A_END);
} catch (ServiceException e) {
//print error messages, but don't throw any more exceptions, because we have to set account status back to 'active'
if (ServiceException.UNKNOWN_DOCUMENT.equals(e.getCode())) {
printError("source server version does not support " + AdminConstants.E_LOCKOUT_MAILBOX_REQUEST);
} else {
printError(String.format("Error: failed to unregister mailbox moveout.\n Exception: %s.", e.getMessage()));
}
} catch (IOException e) {
printError(String.format("Error sending %s (operation = %s) request for %s to %s after unregistering moveout. Exception: %s", AdminConstants.E_LOCKOUT_MAILBOX_REQUEST, AdminConstants.A_END, accountVal, server, e.getMessage()));
}
//end account maintenance
acct.setAccountStatus(AccountStatus.active);
}
}
}
}
use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.
the class ProvUtil method doGetAllAccountLoggers.
private void doGetAllAccountLoggers(AccountLoggerOptions alo) throws ServiceException {
if (!(prov instanceof SoapProvisioning)) {
throwSoapOnly();
}
SoapProvisioning sp = (SoapProvisioning) prov;
Map<String, List<AccountLogger>> allLoggers = sp.getAllAccountLoggers(alo.server);
for (String accountName : allLoggers.keySet()) {
console.printf("# name %s\n", accountName);
for (AccountLogger logger : allLoggers.get(accountName)) {
console.printf("%s=%s\n", logger.getCategory(), logger.getLevel());
}
}
}
use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.
the class ProvUtil method sendMailboxLockoutRequest.
private void sendMailboxLockoutRequest(String acctName, String server, String operation) throws ServiceException, IOException {
LockoutMailboxRequest req = LockoutMailboxRequest.create(AccountNameSelector.fromName(acctName));
req.setOperation(operation);
String url = URLUtil.getAdminURL(server);
ZAuthToken token = ((SoapProvisioning) prov).getAuthToken();
SoapHttpTransport transport = new SoapHttpTransport(url);
transport.setAuthToken(token);
transport.invokeWithoutSession(JaxbUtil.jaxbToElement(req));
}
use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.
the class BlobDeduperUtil method run.
private void run() throws Exception {
CliUtil.toolSetup();
SoapProvisioning prov = SoapProvisioning.getAdminInstance();
prov.soapZimbraAdminAuthenticate();
DedupeBlobsRequest request = new DedupeBlobsRequest(action);
for (short volumeId : volumeIds) {
request.addVolume(new IntIdAttr(volumeId));
}
Element respElem = prov.invoke(JaxbUtil.jaxbToElement(request));
DedupeBlobsResponse response = JaxbUtil.elementToJaxb(respElem);
if (action == DedupeBlobsRequest.DedupAction.start) {
System.out.println("Dedupe scheduled. Run \"zmdedupe status\" to check the status.");
} else {
System.out.println("Status = " + response.getStatus().name());
System.out.println("Total links created = " + response.getTotalCount());
System.out.println("Total size saved = " + response.getTotalSize());
VolumeIdAndProgress[] volumeBlobsProgress = response.getVolumeBlobsProgress();
if (volumeBlobsProgress != null && volumeBlobsProgress.length > 0) {
System.out.printf("%32s : %10s - %s\n", "Groups populated in volume blobs", "volumeId", "groups/total_groups");
for (VolumeIdAndProgress idAndProgress : volumeBlobsProgress) {
System.out.printf("%32s %10s - %s\n", "", idAndProgress.getVolumeId(), idAndProgress.getProgress());
}
}
VolumeIdAndProgress[] blobDigestsProgress = response.getBlobDigestsProgress();
if (blobDigestsProgress != null && blobDigestsProgress.length > 0) {
System.out.printf("%32s : %10s - %s\n", "Digests Processed", "volumeId", "digests/total_digests");
for (VolumeIdAndProgress idAndProgress : blobDigestsProgress) {
System.out.printf("%32s %10s - %s\n", "", idAndProgress.getVolumeId(), idAndProgress.getProgress());
}
}
}
}
use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.
the class BlobConsistencyUtil method run.
private void run() throws Exception {
if (unexpectedBlobList != null) {
unexpectedBlobWriter = new PrintWriter(new FileOutputStream(unexpectedBlobList), true);
}
if (usedBlobList != null) {
usedBlobWriter = new PrintWriter(new FileOutputStream(usedBlobList), true);
}
CliUtil.toolSetup();
SoapProvisioning prov = SoapProvisioning.getAdminInstance();
prov.soapZimbraAdminAuthenticate();
if (mailboxIds == null) {
mailboxIds = getAllMailboxIds(prov);
}
try {
DbPool.startup();
for (int mboxId : mailboxIds) {
System.out.println("Checking mailbox " + mboxId + ".");
checkMailbox(mboxId, prov);
}
} finally {
DbPool.shutdown();
}
if (unexpectedBlobWriter != null) {
unexpectedBlobWriter.close();
}
if (usedBlobWriter != null) {
usedBlobWriter.close();
}
}
Aggregations