2018-03-05 17:51:05 +01:00
|
|
|
package org.gcube.portal.wssynclibrary.thredds;
|
|
|
|
|
2018-03-08 11:55:32 +01:00
|
|
|
import java.util.ArrayList;
|
2018-03-05 17:51:05 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
2018-03-08 11:55:32 +01:00
|
|
|
import java.util.List;
|
2018-03-05 17:51:05 +01:00
|
|
|
import java.util.Map;
|
2018-03-08 11:55:32 +01:00
|
|
|
import java.util.Set;
|
2018-03-05 17:51:05 +01:00
|
|
|
|
2018-11-20 15:52:13 +01:00
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
2018-03-05 17:51:05 +01:00
|
|
|
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched;
|
2018-03-13 12:04:23 +01:00
|
|
|
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked;
|
2018-03-05 17:51:05 +01:00
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.Status;
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
|
2018-03-08 11:55:32 +01:00
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThCatalogueBean;
|
2018-03-05 17:51:05 +01:00
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessDescriptor;
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThProcessStatus;
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor;
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncStatus;
|
|
|
|
import org.gcube.portal.wssynclibrary.shared.thredds.ThSynchFolderConfiguration;
|
|
|
|
import org.gcube.usecases.ws.thredds.SyncEngine;
|
|
|
|
import org.gcube.usecases.ws.thredds.engine.impl.ProcessDescriptor;
|
|
|
|
import org.gcube.usecases.ws.thredds.engine.impl.ProcessStatus;
|
|
|
|
import org.gcube.usecases.ws.thredds.faults.InternalException;
|
|
|
|
import org.gcube.usecases.ws.thredds.faults.ProcessNotFoundException;
|
|
|
|
import org.gcube.usecases.ws.thredds.faults.WorkspaceInteractionException;
|
|
|
|
import org.gcube.usecases.ws.thredds.faults.WorkspaceLockedException;
|
|
|
|
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException;
|
|
|
|
import org.gcube.usecases.ws.thredds.model.SyncFolderDescriptor;
|
|
|
|
import org.gcube.usecases.ws.thredds.model.SyncOperationCallBack;
|
|
|
|
import org.gcube.usecases.ws.thredds.model.SynchFolderConfiguration;
|
2021-05-11 12:04:27 +02:00
|
|
|
import org.gcube.usecases.ws.thredds.model.SynchronizedElementInfo;
|
2018-03-08 11:55:32 +01:00
|
|
|
import org.gcube.usecases.ws.thredds.model.gui.CatalogBean;
|
2018-03-05 17:51:05 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2021-05-11 12:04:27 +02:00
|
|
|
// TODO: Auto-generated Javadoc
|
2018-03-05 17:51:05 +01:00
|
|
|
/**
|
|
|
|
* The Class WorkspaceThreddsSynchronize.
|
|
|
|
*
|
2021-05-07 18:30:40 +02:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
|
2018-03-05 17:51:05 +01:00
|
|
|
*/
|
2021-05-07 18:30:40 +02:00
|
|
|
public class WorkspaceThreddsSynchronize
|
|
|
|
implements WorkspaceThreddsSynchronizedRepository<ThSyncStatus, ThSyncFolderDescriptor> {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/** The logger. */
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(WorkspaceThreddsSynchronize.class);
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/** The engine. */
|
2021-05-07 18:30:40 +02:00
|
|
|
private SyncEngine engine = null;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/** The instance. */
|
|
|
|
private static WorkspaceThreddsSynchronize instance = null;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-11-20 15:52:13 +01:00
|
|
|
private static StorageHubClient storageHubInstance;
|
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/** The map call back. */
|
|
|
|
// Fully synchronized HashMap
|
|
|
|
private Map<String, ThSyncStatus> mapCallBack = Collections.synchronizedMap(new HashMap<>());
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/**
|
|
|
|
* Instantiates a new workspace thredds synchronize.
|
|
|
|
*/
|
|
|
|
private WorkspaceThreddsSynchronize() {
|
|
|
|
// GET ENGINE : SINGLETON INSTANCE
|
|
|
|
engine = SyncEngine.get();
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/**
|
|
|
|
* Gets the single instance of WorkspaceThreddsSynchronize.
|
|
|
|
*
|
|
|
|
* @return single instance of WorkspaceThreddsSynchronize
|
|
|
|
*/
|
|
|
|
public static WorkspaceThreddsSynchronize getInstance() {
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new WorkspaceThreddsSynchronize();
|
2018-11-20 15:52:13 +01:00
|
|
|
storageHubInstance = new StorageHubClient();
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Gets the storage hub instance.
|
|
|
|
*
|
|
|
|
* @return the storage hub instance
|
|
|
|
*/
|
|
|
|
public static StorageHubClient getStorageHubInstance() {
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (storageHubInstance == null)
|
2018-11-20 15:52:13 +01:00
|
|
|
storageHubInstance = new StorageHubClient();
|
|
|
|
|
|
|
|
return storageHubInstance;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check item synched.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the th sync folder descriptor
|
2021-05-07 18:30:40 +02:00
|
|
|
* @throws ItemNotSynched the item not synched
|
2018-11-20 15:52:13 +01:00
|
|
|
* @throws WorkspaceFolderLocked the workspace folder locked
|
2021-05-07 18:30:40 +02:00
|
|
|
* @throws Exception the exception
|
2018-11-20 15:52:13 +01:00
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
2021-05-07 18:30:40 +02:00
|
|
|
public ThSyncFolderDescriptor checkItemSynched(String itemId)
|
|
|
|
throws ItemNotSynched, WorkspaceFolderLocked, Exception {
|
|
|
|
logger.debug("Perfoming checkItemSynched for id: " + itemId);
|
2018-03-05 17:51:05 +01:00
|
|
|
try {
|
2018-03-08 11:55:32 +01:00
|
|
|
// WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS
|
2018-03-05 17:51:05 +01:00
|
|
|
SyncFolderDescriptor desc = engine.check(itemId, false);
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.debug("The item id: " + itemId + " is synched");
|
2018-03-05 17:51:05 +01:00
|
|
|
ThSyncFolderDescriptor descr = ThreddsConverter.toThSyncFolderDescriptor.apply(desc);
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.trace("CheckItemSynched for id: " + itemId + " returning descriptor: " + descr);
|
2018-03-05 17:51:05 +01:00
|
|
|
return descr;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
} catch (WorkspaceNotSynchedException e) {
|
|
|
|
String err = "The item id: " + itemId + " is not synched";
|
2018-03-05 17:51:05 +01:00
|
|
|
logger.trace(err);
|
2021-05-07 18:30:40 +02:00
|
|
|
throw new ItemNotSynched("The item id: " + itemId + " is not synched");
|
2018-03-05 17:51:05 +01:00
|
|
|
// System.out.println("Folder not synched, configurin it..");
|
2021-05-07 18:30:40 +02:00
|
|
|
// engine.setSynchronizedFolder(config, folder.getId());
|
|
|
|
} catch (WorkspaceLockedException e) {
|
|
|
|
// logger.warn("Workspace locked, going to force unlock..");
|
|
|
|
throw new WorkspaceFolderLocked(itemId,
|
|
|
|
"The folder id: " + itemId + " is currently locked. Another sync process is in progress");
|
|
|
|
// engine.forceUnlock(itemId);
|
2018-03-05 17:51:05 +01:00
|
|
|
} catch (WorkspaceInteractionException | InternalException e) {
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.error("Error: ", e);
|
|
|
|
if (e instanceof WorkspaceInteractionException)
|
|
|
|
throw new Exception(
|
|
|
|
"Sorry, an error occurred during check syncronization due to WS interection for the itemId: "
|
|
|
|
+ itemId);
|
|
|
|
else if (e instanceof InternalException)
|
|
|
|
throw new Exception(
|
|
|
|
"Sorry, an Internal Exception occurred during check syncronization for the itemId: " + itemId);
|
|
|
|
|
|
|
|
throw new Exception(
|
|
|
|
"Sorry, an error occurred server side during chck syncronization for the itemId: " + itemId);
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the synchronized folder.
|
|
|
|
*
|
|
|
|
* @param thConfig the th config
|
2021-05-11 12:04:27 +02:00
|
|
|
* @param itemId the item id
|
2018-03-05 17:51:05 +01:00
|
|
|
* @return the th sync folder descriptor
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-05-07 18:30:40 +02:00
|
|
|
public ThSyncFolderDescriptor setSynchronizedFolder(ThSynchFolderConfiguration thConfig, String itemId)
|
|
|
|
throws Exception {
|
2018-03-05 17:51:05 +01:00
|
|
|
SynchFolderConfiguration config = ThreddsConverter.toSynchFolderConfiguration.apply(thConfig);
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (thConfig.getRemotePath() == null || thConfig.getRemotePath().isEmpty())
|
2018-03-05 17:51:05 +01:00
|
|
|
throw new Exception("A valid remote path must be provided");
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (thConfig.getToCreateCatalogName() == null || thConfig.getToCreateCatalogName().isEmpty())
|
2018-03-05 17:51:05 +01:00
|
|
|
throw new Exception("A valid Catalogue Name must be provided");
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
try {
|
|
|
|
engine.setSynchronizedFolder(config, itemId);
|
|
|
|
} catch (WorkspaceInteractionException | InternalException e) {
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.error("Error on setSynchronizedFolder for config: " + thConfig);
|
|
|
|
logger.error("Using itemId: " + itemId, e);
|
2018-03-05 17:51:05 +01:00
|
|
|
throw new Exception("Error on setSynchronizedFolder");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Do sync.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the th sync status
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public ThSyncStatus doSync(String itemId) throws Exception {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
try {
|
|
|
|
// INVOKE SYNCHRONIZATION ON FOLDER
|
|
|
|
ProcessDescriptor descriptor = engine.doSync(itemId);
|
|
|
|
ThSyncStatus synStatus = mapCallBack.get(itemId);
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (synStatus == null) {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
registerCallbackForId(itemId);
|
|
|
|
descriptor = engine.getProcessDescriptorByFolderId(itemId);
|
|
|
|
ProcessStatus status = engine.getProcessStatusByFolderId(itemId);
|
|
|
|
updateMapCallback(itemId, status, descriptor);
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.debug("DoSync returning status: " + synStatus);
|
2018-03-05 17:51:05 +01:00
|
|
|
return synStatus;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
} catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) {
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.error("Error: ", e);
|
|
|
|
|
|
|
|
if (e instanceof WorkspaceInteractionException)
|
|
|
|
throw new Exception(
|
|
|
|
"Sorry, an error occurred during syncronization due to WS interection for the itemId: "
|
|
|
|
+ itemId);
|
|
|
|
else if (e instanceof InternalException)
|
|
|
|
throw new Exception(
|
|
|
|
"Sorry, an Internal Exception occurred during syncronization for the itemId: " + itemId);
|
|
|
|
|
|
|
|
throw new Exception(
|
|
|
|
"Sorry, an error occurred server side during syncronization for the itemId: " + itemId);
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Monitor sync status.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the th sync status
|
|
|
|
* @throws ItemNotSynched the item not synched
|
2021-05-07 18:30:40 +02:00
|
|
|
* @throws Exception the exception
|
2018-11-20 15:52:13 +01:00
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public ThSyncStatus monitorSyncStatus(String itemId) throws ItemNotSynched, Exception {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
try {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
ThSyncStatus synStatus = mapCallBack.get(itemId);
|
2021-05-07 18:30:40 +02:00
|
|
|
if (synStatus == null) {
|
|
|
|
try {
|
2018-03-13 15:10:41 +01:00
|
|
|
|
|
|
|
registerCallbackForId(itemId);
|
|
|
|
ProcessDescriptor descriptor = engine.getProcessDescriptorByFolderId(itemId);
|
|
|
|
ProcessStatus status = engine.getProcessStatusByFolderId(itemId);
|
|
|
|
updateMapCallback(itemId, status, descriptor);
|
|
|
|
ThSyncStatus thSyncStatus = mapCallBack.get(itemId);
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (thSyncStatus == null)
|
|
|
|
throw new Exception("No sync status found for item id: " + itemId);
|
2018-03-13 15:10:41 +01:00
|
|
|
|
|
|
|
return thSyncStatus;
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
} catch (ProcessNotFoundException e) {
|
|
|
|
throw new Exception(
|
|
|
|
"Monitor is not available here. The sync process is in progress on another machine");
|
2018-03-13 15:10:41 +01:00
|
|
|
}
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (synStatus.getProcessStatus() != null) {
|
|
|
|
if (synStatus.getProcessStatus().getStatus() != null) {
|
|
|
|
if (synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) {
|
|
|
|
// TODO NOW?
|
2018-03-05 17:51:05 +01:00
|
|
|
mapCallBack.put(itemId, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.trace("MonitorSyncStatus for item: " + itemId + " returning: " + synStatus);
|
2018-03-05 17:51:05 +01:00
|
|
|
return synStatus;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
} catch (Exception e) {
|
2021-05-07 18:30:40 +02:00
|
|
|
throw new Exception("Sorry, an error occurred during getting sync status for itemId: " + itemId, e);
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see
|
|
|
|
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(
|
|
|
|
* java.lang.String)
|
2018-03-05 17:51:05 +01:00
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Removes the sync.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the boolean
|
2021-05-07 18:30:40 +02:00
|
|
|
* @throws Exception the exception
|
2018-11-20 15:52:13 +01:00
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
2021-05-07 18:30:40 +02:00
|
|
|
public Boolean removeSync(String itemId) throws Exception {
|
|
|
|
throw new Exception("removeSync not implemented");
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see
|
|
|
|
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.
|
|
|
|
* lang.String)
|
2018-03-05 17:51:05 +01:00
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Stop sync.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the boolean
|
2021-05-07 18:30:40 +02:00
|
|
|
* @throws Exception the exception
|
2018-11-20 15:52:13 +01:00
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
2021-05-07 18:30:40 +02:00
|
|
|
public Boolean stopSync(String itemId) throws Exception {
|
|
|
|
throw new Exception("stopSync not implemented");
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see
|
|
|
|
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository
|
|
|
|
* ()
|
2018-03-05 17:51:05 +01:00
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Inits the repository.
|
|
|
|
*
|
|
|
|
* @return the boolean
|
2021-05-07 18:30:40 +02:00
|
|
|
* @throws Exception the exception
|
2018-11-20 15:52:13 +01:00
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
2021-05-07 18:30:40 +02:00
|
|
|
public Boolean initRepository() throws Exception {
|
|
|
|
throw new Exception("initRepository not implemented");
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
|
|
|
|
* shutDownRepository()
|
2018-03-05 17:51:05 +01:00
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Shut down repository.
|
|
|
|
*
|
|
|
|
* @return the boolean
|
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public Boolean shutDownRepository() {
|
|
|
|
try {
|
|
|
|
engine.shutDown();
|
|
|
|
return true;
|
2021-05-07 18:30:40 +02:00
|
|
|
} catch (Exception e) {
|
2018-03-05 17:51:05 +01:00
|
|
|
return null;
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see
|
|
|
|
* org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository
|
|
|
|
* #decribeSyncRepository()
|
2018-03-05 17:51:05 +01:00
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Decribe sync repository.
|
|
|
|
*
|
|
|
|
* @return the string
|
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public String decribeSyncRepository() {
|
|
|
|
return "Sync repository for Thredds";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register callback for id.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
2018-11-20 15:52:13 +01:00
|
|
|
* @throws ProcessNotFoundException the process not found exception
|
2021-05-07 18:30:40 +02:00
|
|
|
* @throws Exception the exception
|
2018-03-05 17:51:05 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2021-05-07 18:30:40 +02:00
|
|
|
public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
try {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
SyncOperationCallBack callback = new SyncOperationCallBack() {
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public void onStep(ProcessStatus status, ProcessDescriptor descriptor) {
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.debug("ON STEP : " + status + " " + descriptor);
|
|
|
|
logger.debug("LOG : \n" + status.getLogBuilder().toString());
|
|
|
|
if (status.getStatus().equals(ProcessStatus.Status.COMPLETED)) {
|
|
|
|
// mapCallBack.remove(itemId);
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
updateMapCallback(itemId, status, descriptor);
|
|
|
|
}
|
|
|
|
};
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
// REGISTER CALLBACK TO MONITOR PROGRESS
|
2021-05-11 12:04:27 +02:00
|
|
|
logger.debug("Registering callback for itemId: " + itemId);
|
2018-03-05 17:51:05 +01:00
|
|
|
engine.registerCallBack(itemId, callback);
|
2021-05-07 18:30:40 +02:00
|
|
|
} catch (ProcessNotFoundException e) {
|
|
|
|
logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e);
|
2018-03-13 15:10:41 +01:00
|
|
|
throw e;
|
2021-05-07 18:30:40 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Register callback exception: ", e);
|
|
|
|
throw new Exception("An error occurred on registering callback for: " + itemId, e);
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/**
|
|
|
|
* Update map callback.
|
|
|
|
*
|
2021-05-07 18:30:40 +02:00
|
|
|
* @param itemId the item id
|
|
|
|
* @param status the status
|
2018-03-05 17:51:05 +01:00
|
|
|
* @param descriptor the descriptor
|
|
|
|
*/
|
|
|
|
private void updateMapCallback(String itemId, ProcessStatus status, ProcessDescriptor descriptor) {
|
|
|
|
ThProcessDescriptor thDesc = ThreddsConverter.toThProcessDescriptor.apply(descriptor);
|
|
|
|
ThProcessStatus thStatus = ThreddsConverter.toThProcessStatus.apply(status);
|
|
|
|
mapCallBack.put(itemId, new ThSyncStatus(thDesc, thStatus));
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.debug("Update map for " + itemId + " with new " + thStatus);
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-05-07 18:30:40 +02:00
|
|
|
* Gets the available catalogues. you need to set the context caller.
|
|
|
|
*
|
|
|
|
* @return the available catalogues
|
2018-03-08 11:55:32 +01:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-05-07 18:30:40 +02:00
|
|
|
public List<ThCatalogueBean> getAvailableCatalogues() throws Exception {
|
|
|
|
logger.debug("called Get Available Catalogues");
|
|
|
|
Set<CatalogBean> ctlgs = engine.getAvailableCatalogs();
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (ctlgs == null || ctlgs.size() == 0) {
|
|
|
|
logger.info("No Catalogue available in the current context, returning empty list");
|
2018-03-08 11:55:32 +01:00
|
|
|
return new ArrayList<ThCatalogueBean>(1);
|
2018-03-08 17:57:35 +01:00
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
|
|
|
List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(ctlgs.size());
|
2021-05-07 18:30:40 +02:00
|
|
|
for (CatalogBean bean : ctlgs) {
|
|
|
|
logger.debug(bean.getName() + " in " + bean.getPath() + " Default : " + bean.getIsDefault());
|
|
|
|
ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean);
|
|
|
|
if (toBean != null)
|
|
|
|
listCtlgs.add(toBean);
|
2018-03-08 11:55:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(listCtlgs);
|
2021-05-07 18:30:40 +02:00
|
|
|
logger.info("Returning sorted Catalogue list with: " + listCtlgs.size() + " item/s");
|
2018-03-08 11:55:32 +01:00
|
|
|
return listCtlgs;
|
|
|
|
}
|
2018-03-13 16:50:59 +01:00
|
|
|
|
2021-05-11 12:04:27 +02:00
|
|
|
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Do un sync.
|
|
|
|
*
|
2021-05-11 12:04:27 +02:00
|
|
|
* @param itemId the item id
|
2018-11-20 15:52:13 +01:00
|
|
|
* @param deleteRemoteContent the delete remote content
|
|
|
|
* @return the boolean
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-03-13 16:50:59 +01:00
|
|
|
@Override
|
|
|
|
public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception {
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
if (itemId == null)
|
2018-03-13 16:50:59 +01:00
|
|
|
throw new Exception("Invalid parameter: itemId is null");
|
|
|
|
|
2021-05-07 18:30:40 +02:00
|
|
|
try {
|
2018-03-13 16:50:59 +01:00
|
|
|
engine.unsetSynchronizedFolder(itemId, deleteRemoteContent);
|
|
|
|
return true;
|
2021-05-07 18:30:40 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Unset Syncronized folder exception: ", e);
|
|
|
|
throw new Exception("An error occurred on deleting configuration to the item id: " + itemId, e);
|
2018-03-13 16:50:59 +01:00
|
|
|
}
|
|
|
|
}
|
2021-05-10 10:12:46 +02:00
|
|
|
|
2021-05-11 12:04:27 +02:00
|
|
|
/**
|
|
|
|
* Gets the configuration.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the configuration
|
|
|
|
* @throws WorkspaceInteractionException the workspace interaction exception
|
|
|
|
* @throws WorkspaceNotSynchedException the workspace not synched exception
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2021-05-10 10:12:46 +02:00
|
|
|
@Override
|
|
|
|
public ThSyncFolderDescriptor getConfiguration(String itemId)
|
|
|
|
throws WorkspaceInteractionException, WorkspaceNotSynchedException, Exception {
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
throw new Exception("Invalid parameter: itemId is null");
|
|
|
|
|
|
|
|
try {
|
|
|
|
SynchFolderConfiguration syncFolderConfig = engine.getConfig(itemId);
|
|
|
|
ThSynchFolderConfiguration toFolderConfig = ThreddsConverter.toThSynchFolderConfiguration
|
|
|
|
.apply(syncFolderConfig);
|
|
|
|
|
|
|
|
return new ThSyncFolderDescriptor(itemId, null, toFolderConfig, false, null);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
2021-05-11 12:04:27 +02:00
|
|
|
logger.error("GetConfig error on folder: " + itemId, e);
|
2021-05-10 10:12:46 +02:00
|
|
|
throw new Exception("An error occurred on getting (sync) configuration for the item id: " + itemId, e);
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 12:04:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the info.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the info
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public Sync_Status getInfo(String itemId) throws Exception {
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
throw new Exception("Invalid parameter: itemId is null");
|
|
|
|
|
|
|
|
SynchronizedElementInfo infoStatus = engine.getInfo(itemId);
|
|
|
|
Sync_Status infoSyncStatus = ThreddsConverter.toSyncStatus.apply(infoStatus);
|
|
|
|
|
|
|
|
return infoSyncStatus;
|
|
|
|
}
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|