Search in sources :

Example 56 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class ProvUtil method doReIndexMailbox.

private void doReIndexMailbox(String[] args) throws ServiceException {
    if (!(prov instanceof SoapProvisioning)) {
        throwSoapOnly();
    }
    SoapProvisioning sp = (SoapProvisioning) prov;
    Account acct = lookupAccount(args[1]);
    ReIndexBy by = null;
    String[] values = null;
    if (args.length > 3) {
        try {
            by = ReIndexBy.valueOf(args[3]);
        } catch (IllegalArgumentException e) {
            throw ServiceException.INVALID_REQUEST("invalid reindex-by", null);
        }
        if (args.length > 4) {
            values = new String[args.length - 4];
            System.arraycopy(args, 4, values, 0, args.length - 4);
        } else {
            throw ServiceException.INVALID_REQUEST("missing reindex-by values", null);
        }
    }
    ReIndexInfo info = sp.reIndex(acct, args[2], by, values);
    ReIndexInfo.Progress progress = info.getProgress();
    console.printf("status: %s\n", info.getStatus());
    if (progress != null) {
        console.printf("progress: numSucceeded=%d, numFailed=%d, numRemaining=%d\n", progress.getNumSucceeded(), progress.getNumFailed(), progress.getNumRemaining());
    }
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) ReIndexBy(com.zimbra.cs.account.soap.SoapProvisioning.ReIndexBy) ReIndexInfo(com.zimbra.cs.account.soap.SoapProvisioning.ReIndexInfo)

Example 57 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class ProvUtil method doGetShareInfo.

private void doGetShareInfo(String[] args) throws ServiceException {
    if (!(prov instanceof SoapProvisioning)) {
        throwSoapOnly();
    }
    Account owner = lookupAccount(args[1]);
    ShareInfoVisitor.printHeadings();
    prov.getShareInfo(owner, new ShareInfoVisitor());
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) PublishedShareInfoVisitor(com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)

Example 58 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class ProvUtil method doGetQuotaUsage.

private void doGetQuotaUsage(String[] args) throws ServiceException {
    if (!(prov instanceof SoapProvisioning)) {
        throwSoapOnly();
    }
    SoapProvisioning sp = (SoapProvisioning) prov;
    List<QuotaUsage> result = sp.getQuotaUsage(args[1]);
    for (QuotaUsage u : result) {
        console.printf("%s %d %d\n", u.getName(), u.getLimit(), u.getUsed());
    }
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) QuotaUsage(com.zimbra.cs.account.soap.SoapProvisioning.QuotaUsage)

Example 59 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class ProvUtil method doRemoveAccountLogger.

private void doRemoveAccountLogger(AccountLoggerOptions alo) throws ServiceException {
    if (!(prov instanceof SoapProvisioning)) {
        throwSoapOnly();
    }
    SoapProvisioning sp = (SoapProvisioning) prov;
    Account acct = null;
    String category = null;
    if (alo.args.length == 2) {
        // Hack: determine if it's an account or category, based on the name.
        String arg = alo.args[1];
        if (arg.startsWith("zimbra.") || arg.startsWith("com.zimbra")) {
            category = arg;
        } else {
            acct = lookupAccount(alo.args[1]);
        }
    }
    if (alo.args.length == 3) {
        acct = lookupAccount(alo.args[1]);
        category = alo.args[2];
    }
    sp.removeAccountLoggers(acct, category, alo.server);
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Example 60 with SoapProvisioning

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);
            }
        }
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) UnregisterMailboxMoveOutRequest(com.zimbra.soap.admin.message.UnregisterMailboxMoveOutRequest) IOException(java.io.IOException) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Aggregations

SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)78 Test (org.junit.Test)18 SoapFaultException (com.zimbra.common.soap.SoapFaultException)14 Account (com.zimbra.cs.account.Account)13 Attr (com.zimbra.soap.admin.type.Attr)10 ServiceException (com.zimbra.common.service.ServiceException)9 CreateDistributionListRequest (com.zimbra.soap.admin.message.CreateDistributionListRequest)6 CreateDistributionListResponse (com.zimbra.soap.admin.message.CreateDistributionListResponse)6 AccountLogger (com.zimbra.common.util.AccountLogger)5 Server (com.zimbra.cs.account.Server)5 CreateCalendarResourceRequest (com.zimbra.soap.admin.message.CreateCalendarResourceRequest)4 CreateCalendarResourceResponse (com.zimbra.soap.admin.message.CreateCalendarResourceResponse)4 DeleteCalendarResourceRequest (com.zimbra.soap.admin.message.DeleteCalendarResourceRequest)4 List (java.util.List)4 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 Provisioning (com.zimbra.cs.account.Provisioning)3 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)3 DeleteAccountRequest (com.zimbra.soap.admin.message.DeleteAccountRequest)3 DeleteAccountResponse (com.zimbra.soap.admin.message.DeleteAccountResponse)3