Search in sources :

Example 1 with DedupeBlobsResponse

use of com.zimbra.soap.admin.message.DedupeBlobsResponse in project zm-mailbox by Zimbra.

the class DedupeBlobs method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
    StoreManager sm = StoreManager.getInstance();
    if (!(sm instanceof FileBlobStore)) {
        throw ServiceException.INVALID_REQUEST(sm.getClass().getName() + " is not supported", null);
    }
    DedupeBlobsRequest req = JaxbUtil.elementToJaxb(request);
    BlobDeduper deduper = BlobDeduper.getInstance();
    DedupeBlobsResponse resp = new DedupeBlobsResponse();
    // Assemble the list of volumes.
    List<IntIdAttr> volumeList = req.getVolumes();
    List<Short> volumeIds = new ArrayList<Short>();
    if ((req.getAction() == DedupeBlobsRequest.DedupAction.start) || (req.getAction() == DedupeBlobsRequest.DedupAction.reset)) {
        if (volumeList.isEmpty()) {
            // Get all message volume id's.
            for (Volume vol : VolumeManager.getInstance().getAllVolumes()) {
                switch(vol.getType()) {
                    case Volume.TYPE_MESSAGE:
                    case Volume.TYPE_MESSAGE_SECONDARY:
                        volumeIds.add(vol.getId());
                        break;
                }
            }
        } else {
            // Read volume id's from the request.
            for (IntIdAttr attr : volumeList) {
                short volumeId = (short) attr.getId();
                Volume vol = VolumeManager.getInstance().getVolume(volumeId);
                if (vol.getType() == Volume.TYPE_INDEX) {
                    throw ServiceException.INVALID_REQUEST("Index volume " + volumeId + " is not supported", null);
                } else {
                    volumeIds.add(volumeId);
                }
            }
        }
    }
    if (req.getAction() == DedupeBlobsRequest.DedupAction.start) {
        try {
            deduper.process(volumeIds);
        } catch (IOException e) {
            throw ServiceException.FAILURE("error while deduping", e);
        }
    } else if (req.getAction() == DedupeBlobsRequest.DedupAction.stop) {
        deduper.stopProcessing();
    } else if (req.getAction() == DedupeBlobsRequest.DedupAction.reset) {
        if (volumeList.isEmpty()) {
            deduper.resetVolumeBlobs(new ArrayList<Short>());
        } else {
            deduper.resetVolumeBlobs(volumeIds);
        }
    }
    // return the stats for all actions.
    boolean isRunning = deduper.isRunning();
    if (isRunning) {
        resp.setStatus(DedupStatus.running);
    } else {
        resp.setStatus(DedupStatus.stopped);
    }
    Map<Short, String> volumeBlobsProgress = deduper.getVolumeBlobsProgress();
    VolumeIdAndProgress[] blobProgress = new VolumeIdAndProgress[volumeBlobsProgress.size()];
    int i = 0;
    for (Map.Entry<Short, String> entry : volumeBlobsProgress.entrySet()) {
        blobProgress[i++] = new VolumeIdAndProgress(String.valueOf(entry.getKey()), entry.getValue());
    }
    resp.setVolumeBlobsProgress(blobProgress);
    Map<Short, String> blobDigestsProgress = deduper.getBlobDigestsProgress();
    VolumeIdAndProgress[] digestProgress = new VolumeIdAndProgress[blobDigestsProgress.size()];
    i = 0;
    for (Map.Entry<Short, String> entry : blobDigestsProgress.entrySet()) {
        digestProgress[i++] = new VolumeIdAndProgress(String.valueOf(entry.getKey()), entry.getValue());
    }
    resp.setBlobDigestsProgress(digestProgress);
    Pair<Integer, Long> pair = deduper.getCountAndSize();
    resp.setTotalCount(pair.getFirst());
    resp.setTotalSize(pair.getSecond());
    return JaxbUtil.jaxbToElement(resp);
}
Also used : DedupeBlobsRequest(com.zimbra.soap.admin.message.DedupeBlobsRequest) BlobDeduper(com.zimbra.cs.store.file.BlobDeduper) ArrayList(java.util.ArrayList) StoreManager(com.zimbra.cs.store.StoreManager) IntIdAttr(com.zimbra.soap.admin.type.IntIdAttr) DedupeBlobsResponse(com.zimbra.soap.admin.message.DedupeBlobsResponse) FileBlobStore(com.zimbra.cs.store.file.FileBlobStore) VolumeIdAndProgress(com.zimbra.soap.admin.type.VolumeIdAndProgress) IOException(java.io.IOException) Volume(com.zimbra.cs.volume.Volume) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Map(java.util.Map)

Example 2 with DedupeBlobsResponse

use of com.zimbra.soap.admin.message.DedupeBlobsResponse 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)

Aggregations

DedupeBlobsRequest (com.zimbra.soap.admin.message.DedupeBlobsRequest)2 DedupeBlobsResponse (com.zimbra.soap.admin.message.DedupeBlobsResponse)2 IntIdAttr (com.zimbra.soap.admin.type.IntIdAttr)2 VolumeIdAndProgress (com.zimbra.soap.admin.type.VolumeIdAndProgress)2 Element (com.zimbra.common.soap.Element)1 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)1 StoreManager (com.zimbra.cs.store.StoreManager)1 BlobDeduper (com.zimbra.cs.store.file.BlobDeduper)1 FileBlobStore (com.zimbra.cs.store.file.FileBlobStore)1 Volume (com.zimbra.cs.volume.Volume)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1