Skip to content

Commit

Permalink
ZCS-11861 SOAP API: Need soap API to get the list of Available StoreM…
Browse files Browse the repository at this point in the history
…anagers for the volume
  • Loading branch information
inpati committed Aug 12, 2022
1 parent ae60c7c commit de947c9
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* ***** BEGIN LICENSE BLOCK *****
* Zimbra Collaboration Suite Server
* Copyright (C) 2022 Synacor, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software Foundation,
* version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
* ***** END LICENSE BLOCK *****
*/

package com.zimbra.soap.admin.message;

import javax.xml.bind.annotation.XmlRootElement;

import com.zimbra.common.soap.AdminConstants;

/**
* @zm-api-command-auth-required true
* @zm-api-command-admin-auth-required true
* @zm-api-command-description Get all store managers
*/
@XmlRootElement(name=AdminConstants.E_GET_ALL_STORE_MANAGERS_REQUEST)
public class GetAllStoreManagersRequest {

public GetAllStoreManagersRequest() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* ***** BEGIN LICENSE BLOCK *****
* Zimbra Collaboration Suite Server
* Copyright (C) 2022 Synacor, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software Foundation,
* version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
* ***** END LICENSE BLOCK *****
*/

package com.zimbra.soap.admin.message;

import com.google.common.collect.Lists;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.zimbra.common.soap.AdminConstants;

@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name=AdminConstants.E_GET_ALL_STORE_MANAGERS_RESPONSE)
public final class GetAllStoreManagersResponse {

/**
* @zm-api-field-description Information about volumes
*/
@XmlElement(name=AdminConstants.E_STORE_MANAGER, required=true)
private final Set<String> smList = new HashSet<String>();


public void setSMList(Set<String> list) {
smList.clear();
if (list != null) {
smList.addAll(list);
}
}

public void addStoreManager(String smName) {
smList.add(smName);
}

public Set<String> getSMList() {
return smList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* ***** BEGIN LICENSE BLOCK *****
* Zimbra Collaboration Suite Server
* Copyright (C) 2022 Synacor, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software Foundation,
* version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
* ***** END LICENSE BLOCK *****
*/
package com.zimbra.cs.service.admin;

import com.zimbra.common.service.ServiceException;
import com.zimbra.common.soap.Element;
import com.zimbra.cs.store.StoreManager;
import com.zimbra.soap.admin.message.GetAllStoreManagersRequest;
import com.zimbra.soap.admin.message.GetAllStoreManagersResponse;
import com.zimbra.soap.JaxbUtil;
import com.zimbra.soap.ZimbraSoapContext;
import java.util.Map;

public final class GetAllStoreManagers extends AdminDocumentHandler {

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
GetAllStoreManagersRequest req = zsc.elementToJaxb(request);
GetAllStoreManagersResponse resp = new GetAllStoreManagersResponse();
resp.setSMList(StoreManager.getSMList());
return zsc.jaxbToElement(resp);
}
}
13 changes: 5 additions & 8 deletions store/src/java/com/zimbra/cs/store/StoreManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@
import com.zimbra.cs.mailbox.util.MailItemHelper;
import com.zimbra.cs.store.file.FileBlobStore;
import com.zimbra.cs.store.helper.ClassHelper;
import com.zimbra.cs.store.StoreManagerRegistrar;
import com.zimbra.cs.util.Zimbra;
import com.zimbra.cs.volume.VolumeManager;

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import java.util.List;
import java.util.Set;

public abstract class StoreManager {

private static StoreManager sInstance;

private static String currentZimbraClassStore = LC.zimbra_class_store.value();

private static List<String> smList;
private static Set<String> smList;

/**
* Current Volume Id
Expand Down Expand Up @@ -537,15 +538,11 @@ public IncomingBlob newIncomingBlob(String id, Object ctxt) throws IOException,
return new BufferingIncomingBlob(id, getBlobBuilder(), ctxt);
}

public static void registerStoreManager(StoreManager storeManager) {
String smName = storeManager.getClass().getSimpleName();
}

public static void addToSMList(String smName) {
protected static void addToSMList(String smName) {
smList.add(smName);
}

public static List<String> getSMList() {
public static Set<String> getSMList() {
return smList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.google.common.annotations.VisibleForTesting;
import com.zimbra.common.localconfig.LC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.zimbra.common.service.ServiceException;
import com.zimbra.common.util.FileUtil;
import com.zimbra.cs.mailbox.Mailbox;
import com.zimbra.cs.store.StoreManagerRegistrar;

/**
* Simple ExternalStoreManager implementation that is intended for use in storing
Expand All @@ -40,6 +41,10 @@ public class ImapTransientStoreManager extends ExternalStoreManager {

protected File baseDirectory;

public ImapTransientStoreManager() {
StoreManagerRegistrar.registerStoreManager(this);
}

@Override
public void startup() throws IOException, ServiceException {
startup(LC.imapd_tmp_directory.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.zimbra.common.util.FileUtil;
import com.zimbra.common.util.ZimbraLog;
import com.zimbra.cs.mailbox.Mailbox;
import com.zimbra.cs.store.StoreManagerRegistrar;

/**
* Example implementation of ExternalStoreManager which writes to a flat directory structure
Expand All @@ -42,6 +43,12 @@
public class SimpleStoreManager extends ExternalStoreManager {

String directory = null;

public SimpleStoreManager() {
StoreManagerRegistrar.registerStoreManager(this);
addToSMList("x");
}

@Override
public void startup() throws IOException, ServiceException {
super.startup();
Expand Down
7 changes: 6 additions & 1 deletion store/src/java/com/zimbra/cs/store/file/FileBlobStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.zimbra.cs.store.MailboxBlob;
import com.zimbra.cs.store.StagedBlob;
import com.zimbra.cs.store.StoreManager;
import com.zimbra.cs.store.StoreManagerRegistrar;
import com.zimbra.cs.volume.Volume;
import com.zimbra.cs.volume.VolumeManager;
import com.zimbra.znative.IO;
Expand All @@ -46,6 +47,10 @@
public final class FileBlobStore extends StoreManager {
private static final VolumeManager MANAGER = VolumeManager.getInstance();

public FileBlobStore() {
StoreManagerRegistrar.registerStoreManager(this);
}

@Override
public void startup() throws IOException, ServiceException {
IncomingDirectory.startSweeper();
Expand Down Expand Up @@ -443,7 +448,7 @@ private static void ensureParentDirExists(File file) throws IOException {
* specified by dest* parameters. Note this method is not part of the
* StoreManager interface It is only to be used for FileBlobStore specific code
* such as ExternalToInternal
*
*
* @param in
* @param storeAsIs
* @param mbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.zimbra.cs.store.external.ExternalResumableUpload;
import com.zimbra.cs.store.external.ExternalUploadedBlob;
import com.zimbra.cs.store.external.SisStore;
import com.zimbra.cs.store.StoreManagerRegistrar;

/**
* StoreManager implementation which uses the TDS Blob API for storing and retrieving blobs
Expand All @@ -68,10 +69,12 @@ public TritonBlobStoreManager(String url, HashType hashType) {
super();
this.url = url;
this.hashType = hashType;
StoreManagerRegistrar.registerStoreManager(this);
}

public TritonBlobStoreManager() {
super();
StoreManagerRegistrar.registerStoreManager(this);
}

@Override
Expand Down

0 comments on commit de947c9

Please sign in to comment.