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 2204202
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 19 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.StoreManagerRegistrar;
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(StoreManagerRegistrar.getSMList());
return zsc.jaxbToElement(resp);
}
}
17 changes: 2 additions & 15 deletions store/src/java/com/zimbra/cs/store/StoreManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@
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;


public abstract class StoreManager {

private static StoreManager sInstance;

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

private static List<String> smList;

/**
* Current Volume Id
*/
Expand Down Expand Up @@ -536,16 +535,4 @@ public abstract boolean deleteStore(Mailbox mbox, Iterable<MailboxBlob.MailboxBl
public IncomingBlob newIncomingBlob(String id, Object ctxt) throws IOException, ServiceException {
return new BufferingIncomingBlob(id, getBlobBuilder(), ctxt);
}

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

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

public static List<String> getSMList() {
return smList;
}
}
36 changes: 36 additions & 0 deletions store/src/java/com/zimbra/cs/store/StoreManagerRegistrar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* ***** 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.store;
import com.zimbra.common.util.ZimbraLog;

import java.util.Set;

public abstract class StoreManagerRegistrar {

private static Set<String> smList;

public static void registerStoreManager(Class<? extends StoreManager> smTypeClass) {
String smName = smTypeClass.getClass().getSimpleName();
smList.add(smName);
System.out.print("Register store manager : " + smName);
ZimbraLog.misc.info("Register store manager : " + smName);
}

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 @@ -37,7 +38,6 @@
*
*/
public class ImapTransientStoreManager extends ExternalStoreManager {

protected File baseDirectory;

@Override
Expand Down Expand Up @@ -85,5 +85,4 @@ private File createBlobFile(Mailbox mbox) throws IOException {
return File.createTempFile(mbox.getAccountId(), ".msg", baseDirectory);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
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
* This is intended for illustration purposes only; it should *never* be used in a production environment
*
*/
public class SimpleStoreManager extends ExternalStoreManager {

String directory = null;

@Override
public void startup() throws IOException, ServiceException {
super.startup();
Expand Down
3 changes: 2 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 Down Expand Up @@ -443,7 +444,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 Down
9 changes: 9 additions & 0 deletions store/src/java/com/zimbra/cs/util/Zimbra.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
import com.zimbra.cs.session.WaitSetMgr;
import com.zimbra.cs.stats.ZimbraPerf;
import com.zimbra.cs.store.StoreManager;
import com.zimbra.cs.store.StoreManagerRegistrar;
import com.zimbra.cs.store.file.FileBlobStore;
import com.zimbra.cs.store.triton.TritonBlobStoreManager;
import com.zimbra.cs.store.external.ImapTransientStoreManager;
import com.zimbra.cs.store.external.ExternalStoreManager;
import com.zimbra.cs.zookeeper.CuratorManager;
import com.zimbra.znative.Util;

Expand Down Expand Up @@ -270,6 +275,10 @@ private static synchronized void startup(boolean forMailboxd) throws ServiceExce
} catch (IOException e) {
throw ServiceException.FAILURE("Unable to initialize StoreManager.", e);
}
StoreManagerRegistrar.registerStoreManager(FileBlobStore.class);
StoreManagerRegistrar.registerStoreManager(ExternalStoreManager.class);
StoreManagerRegistrar.registerStoreManager(TritonBlobStoreManager.class);
StoreManagerRegistrar.registerStoreManager(ImapTransientStoreManager.class);

MailboxManager.getInstance();

Expand Down

0 comments on commit 2204202

Please sign in to comment.