Search in sources :

Example 46 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)

Example 47 with SoapProvisioning

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());
        }
    }
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) AccountLogger(com.zimbra.common.util.AccountLogger) ArrayList(java.util.ArrayList) List(java.util.List)

Example 48 with SoapProvisioning

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

Example 49 with SoapProvisioning

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());
            }
        }
    }
}
Also used : DedupeBlobsRequest(com.zimbra.soap.admin.message.DedupeBlobsRequest) IntIdAttr(com.zimbra.soap.admin.type.IntIdAttr) DedupeBlobsResponse(com.zimbra.soap.admin.message.DedupeBlobsResponse) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) VolumeIdAndProgress(com.zimbra.soap.admin.type.VolumeIdAndProgress) Element(com.zimbra.common.soap.Element)

Example 50 with SoapProvisioning

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();
    }
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter)

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