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
|
|
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
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;
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
/**
|
|
|
|
* The Class WorkspaceThreddsSynchronize.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Feb 14, 2018
|
|
|
|
*/
|
|
|
|
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. */
|
|
|
|
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
|
|
|
public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS";
|
2018-03-08 11:55:32 +01:00
|
|
|
|
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() {
|
|
|
|
|
|
|
|
if(storageHubInstance==null)
|
|
|
|
storageHubInstance = new StorageHubClient();
|
|
|
|
|
|
|
|
return storageHubInstance;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#isItemSynchronized(java.lang.String)
|
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Check item synched.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the th sync folder descriptor
|
|
|
|
* @throws ItemNotSynched the item not synched
|
|
|
|
* @throws WorkspaceFolderLocked the workspace folder locked
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
2018-03-13 12:04:23 +01:00
|
|
|
public ThSyncFolderDescriptor checkItemSynched(String itemId) throws ItemNotSynched, WorkspaceFolderLocked, Exception {
|
2018-03-05 17:51:05 +01:00
|
|
|
logger.debug("Perfoming checkItemSynched for id: "+itemId);
|
|
|
|
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);
|
|
|
|
|
|
|
|
logger.debug("The item id: "+itemId +" is synched");
|
|
|
|
ThSyncFolderDescriptor descr = ThreddsConverter.toThSyncFolderDescriptor.apply(desc);
|
|
|
|
logger.trace("CheckItemSynched for id: "+itemId+" returning descriptor: "+descr);
|
|
|
|
return descr;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
}catch(WorkspaceNotSynchedException e) {
|
|
|
|
String err = "The item id: "+itemId +" is not synched";
|
|
|
|
logger.trace(err);
|
|
|
|
throw new ItemNotSynched("The item id: "+itemId +" is not synched");
|
|
|
|
// System.out.println("Folder not synched, configurin it..");
|
|
|
|
//engine.setSynchronizedFolder(config, folder.getId());
|
|
|
|
}catch(WorkspaceLockedException e) {
|
2018-03-28 18:51:45 +02:00
|
|
|
//logger.warn("Workspace locked, going to force unlock..");
|
2018-03-13 12:04:23 +01:00
|
|
|
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) {
|
|
|
|
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);
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
throw new Exception("Sorry, an error occurred server side during chck syncronization for the itemId: "+itemId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 11:55:32 +01:00
|
|
|
|
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/**
|
|
|
|
* Sets the synchronized folder.
|
|
|
|
*
|
|
|
|
* @param thConfig the th config
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the th sync folder descriptor
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public ThSyncFolderDescriptor setSynchronizedFolder(ThSynchFolderConfiguration thConfig, String itemId) throws Exception {
|
|
|
|
SynchFolderConfiguration config = ThreddsConverter.toSynchFolderConfiguration.apply(thConfig);
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
if(thConfig.getRemotePath()==null || thConfig.getRemotePath().isEmpty())
|
|
|
|
throw new Exception("A valid remote path must be provided");
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
if(thConfig.getToCreateCatalogName()==null || thConfig.getToCreateCatalogName().isEmpty())
|
|
|
|
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
|
|
|
if(thConfig.getTargetToken()==null || thConfig.getTargetToken().isEmpty())
|
|
|
|
throw new Exception("A valid Target Token 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) {
|
|
|
|
logger.error("Error on setSynchronizedFolder for config: "+thConfig);
|
|
|
|
logger.error("Using itemId: "+itemId,e);
|
|
|
|
throw new Exception("Error on setSynchronizedFolder");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#doSynchronization(java.lang.String)
|
|
|
|
*/
|
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
|
|
|
|
2018-03-05 17:51:05 +01: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
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
logger.debug("DoSync returning status: "+synStatus);
|
|
|
|
return synStatus;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
} catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) {
|
|
|
|
logger.error("Error: ",e);
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
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);
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
throw new Exception("Sorry, an error occurred server side during syncronization for the itemId: "+itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String)
|
|
|
|
*/
|
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
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
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);
|
|
|
|
if(synStatus==null) {
|
2018-03-13 15:10:41 +01:00
|
|
|
try{
|
|
|
|
|
|
|
|
registerCallbackForId(itemId);
|
|
|
|
ProcessDescriptor descriptor = engine.getProcessDescriptorByFolderId(itemId);
|
|
|
|
ProcessStatus status = engine.getProcessStatusByFolderId(itemId);
|
|
|
|
updateMapCallback(itemId, status, descriptor);
|
|
|
|
ThSyncStatus thSyncStatus = mapCallBack.get(itemId);
|
|
|
|
|
|
|
|
if(thSyncStatus==null)
|
|
|
|
throw new Exception("No sync status found for item id: "+itemId);
|
|
|
|
|
|
|
|
return thSyncStatus;
|
|
|
|
|
|
|
|
}catch(ProcessNotFoundException e){
|
|
|
|
throw new Exception("Monitor is not available here. The sync process is in progress on another machine");
|
|
|
|
}
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
if(synStatus.getProcessStatus()!=null) {
|
|
|
|
if(synStatus.getProcessStatus().getStatus()!=null) {
|
|
|
|
if(synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) {
|
|
|
|
//TODO NOW?
|
|
|
|
mapCallBack.put(itemId, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
logger.trace("MonitorSyncStatus for item: "+itemId+" returning: "+synStatus);
|
|
|
|
return synStatus;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
} catch (Exception e) {
|
2018-03-13 15:10:41 +01:00
|
|
|
throw new Exception("Sorry, an error occurred during getting sync status for itemId: "+itemId, e);
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(java.lang.String)
|
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Removes the sync.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the boolean
|
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public Boolean removeSync(String itemId) {
|
|
|
|
return null;
|
|
|
|
// TODO Auto-generated method stub
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.lang.String)
|
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Stop sync.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return the boolean
|
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public Boolean stopSync(String itemId) {
|
|
|
|
return false;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository()
|
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Inits the repository.
|
|
|
|
*
|
|
|
|
* @return the boolean
|
|
|
|
*/
|
2018-03-05 17:51:05 +01:00
|
|
|
@Override
|
|
|
|
public Boolean initRepository() {
|
|
|
|
return false;
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#shutDownRepository()
|
|
|
|
*/
|
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;
|
|
|
|
}catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository#decribeSyncRepository()
|
|
|
|
*/
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the synched status from item property.
|
|
|
|
*
|
2018-11-20 15:52:13 +01:00
|
|
|
* @param itemId the item id
|
2018-03-05 17:51:05 +01:00
|
|
|
* @param username the username
|
|
|
|
* @return the synched status from item property
|
|
|
|
* @throws ItemNotSynched the item not synched
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-03-14 14:24:17 +01:00
|
|
|
public Sync_Status getSynchedStatusFromItemProperty(String itemId, String username) throws ItemNotSynched, Exception{
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-14 14:24:17 +01:00
|
|
|
if(itemId==null)
|
2018-03-13 16:50:59 +01:00
|
|
|
throw new Exception("Invalid parameter itemId is null");
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
String scope = ScopeProvider.instance.get();
|
|
|
|
if(scope == null || scope.isEmpty())
|
|
|
|
throw new Exception("You must set a valid scope into ScopeProvider instance");
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-11-20 15:52:13 +01:00
|
|
|
String wsSyncStatus = null;
|
|
|
|
try{
|
|
|
|
|
2018-12-03 12:15:33 +01:00
|
|
|
Map<String, Object> map = storageHubInstance.open(itemId).asItem().get().getMetadata().getMap();
|
2018-11-20 15:52:13 +01:00
|
|
|
wsSyncStatus = (String) map.get(WS_SYNCH_SYNCH_STATUS);
|
2018-11-20 17:44:08 +01:00
|
|
|
logger.debug("Item id: "+itemId+" read from Shub has current: "+WS_SYNCH_SYNCH_STATUS +" value at: "+wsSyncStatus);
|
2018-11-20 15:52:13 +01:00
|
|
|
if(wsSyncStatus==null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return Sync_Status.valueOf(wsSyncStatus);
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.warn(wsSyncStatus + " is not value of "+Sync_Status.values()+", returning null");
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-05 17:51:05 +01:00
|
|
|
}
|
|
|
|
|
2018-03-08 11:55:32 +01:00
|
|
|
|
2018-03-05 17:51:05 +01:00
|
|
|
/**
|
|
|
|
* Register callback for id.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
2018-11-20 15:52:13 +01:00
|
|
|
* @throws ProcessNotFoundException the process not found exception
|
2018-03-05 17:51:05 +01:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
2018-03-13 15:10:41 +01: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) {
|
|
|
|
logger.debug("ON STEP : "+status+" "+descriptor);
|
|
|
|
logger.debug("LOG : \n"+ status.getLogBuilder().toString());
|
|
|
|
if(status.getStatus().equals(ProcessStatus.Status.COMPLETED)) {
|
|
|
|
//mapCallBack.remove(itemId);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
logger.debug("Registering callback on itemId: "+itemId);
|
|
|
|
engine.registerCallBack(itemId, callback);
|
|
|
|
}catch (ProcessNotFoundException e) {
|
2018-03-13 15:10:41 +01:00
|
|
|
logger.error("Register callback for id: "+itemId+" threw ProcessNotFoundException: ", e);
|
|
|
|
throw e;
|
|
|
|
}catch (Exception e) {
|
2018-03-05 17:51:05 +01:00
|
|
|
logger.error("Register callback exception: ",e);
|
2018-03-13 15:10:41 +01:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @param status the status
|
|
|
|
* @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));
|
|
|
|
logger.debug("Update map for "+itemId +" with new "+thStatus);
|
|
|
|
}
|
2018-03-08 11:55:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the available catalogues by token.
|
|
|
|
*
|
|
|
|
* @param token the token
|
|
|
|
* @return the available catalogues by token
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public List<ThCatalogueBean> getAvailableCataloguesByToken(String token) throws Exception{
|
|
|
|
|
|
|
|
if(token==null || token.isEmpty())
|
|
|
|
throw new Exception("Invalid parameter token null or empty");
|
|
|
|
|
2018-03-08 17:57:35 +01:00
|
|
|
String printToken = token.substring(0, token.length()-5)+"XXXXX";
|
|
|
|
logger.debug("Get Available Catalogues by token: "+printToken);
|
2018-03-08 11:55:32 +01:00
|
|
|
Set<CatalogBean> ctlgs = engine.getAvailableCatalogsByToken(token);
|
|
|
|
|
2018-03-08 17:57:35 +01:00
|
|
|
if(ctlgs==null || ctlgs.size()==0){
|
|
|
|
logger.debug("No Catalogue available for token: "+printToken +" 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());
|
|
|
|
for(CatalogBean bean: ctlgs){
|
|
|
|
System.out.println(bean.getName()+" in "+bean.getPath()+" Default : "+bean.getIsDefault());
|
|
|
|
ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean);
|
|
|
|
if(toBean!=null)
|
|
|
|
listCtlgs.add(toBean);
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(listCtlgs);
|
2018-03-08 11:56:33 +01:00
|
|
|
logger.debug("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
|
|
|
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String)
|
|
|
|
*/
|
2018-11-20 15:52:13 +01:00
|
|
|
/**
|
|
|
|
* Do un sync.
|
|
|
|
*
|
|
|
|
* @param itemId the item id
|
|
|
|
* @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 {
|
|
|
|
|
|
|
|
if(itemId==null)
|
|
|
|
throw new Exception("Invalid parameter: itemId is null");
|
|
|
|
|
|
|
|
try{
|
|
|
|
engine.unsetSynchronizedFolder(itemId, deleteRemoteContent);
|
|
|
|
return true;
|
|
|
|
}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-05 17:51:05 +01:00
|
|
|
}
|