moved to 1.5.0-SNAPSHOT. Starting migration to ws-thredds.1.x

This commit is contained in:
Francesco Mangiacrapa 2021-05-07 18:30:40 +02:00
parent 59498cd6b3
commit 38c4012194
7 changed files with 344 additions and 305 deletions

View File

@ -4,6 +4,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.5.0-SNAPSHOT] - 2021-05-07
[#21374] Moved to ws-thredds 1.x
## [v1.4.0] - 2021-03-10

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>ws-synchronized-module-library</artifactId>
<version>1.4.0</version>
<version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ws-synchronized-module-library</name>
<description>
@ -37,7 +37,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.0</version>
<version>3.6.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -49,7 +49,7 @@
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>ws-thredds</artifactId>
<version>[0.1.0, 1.0.0-SNAPSHOT)</version>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>

View File

@ -1,21 +1,19 @@
package org.gcube.portal.wssynclibrary;
// TODO: Auto-generated Javadoc
/**
* The Interface DoConnectRepository.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 14, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
*/
public interface DoConnectRepository {
/**
* Inits the repository.
*
* @return true, if successful
* @throws Exception
*/
Boolean initRepository();
Boolean initRepository() throws Exception;
/**
* Shutdown repository.

View File

@ -2,15 +2,13 @@ package org.gcube.portal.wssynclibrary.shared.thredds;
import java.io.Serializable;
// TODO: Auto-generated Javadoc
/**
* The Class ThSynchFolderConfiguration.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 8, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 8, 2018
*/
public class ThSynchFolderConfiguration implements Serializable{
public class ThSynchFolderConfiguration implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -5807533629170443212L;
@ -21,36 +19,47 @@ public class ThSynchFolderConfiguration implements Serializable{
/** The filter. */
private String filter;
/** The target token. */
private String targetToken;
private String targetContext;
/** The to create catalog name. */
private String toCreateCatalogName;
/** The remote persistence. */
private String remotePersistence="thredds";
private String remotePersistence = "thredds";
private String rootFolderId;
/**
* Instantiates a new th synch folder configuration.
*/
public ThSynchFolderConfiguration() {
// TODO Auto-generated constructor stub
}
public ThSynchFolderConfiguration(String remotePath, String filter, String targetToken, String toCreateCatalogName,
String remotePersistence, String rootFolderId) {
/**
* Instantiates a new th synch folder configuration.
*
* @param remotePath the remote path
* @param filter the filter
* @param targetContext the target context
* @param toCreateCatalogName the to create catalog name
* @param remotePersistence the remote persistence
* @param rootFolderId the root folder id
*/
public ThSynchFolderConfiguration(String remotePath, String filter, String targetContext,
String toCreateCatalogName, String remotePersistence, String rootFolderId) {
super();
this.remotePath = remotePath;
this.filter = filter;
this.targetToken = targetToken;
this.targetContext = targetContext;
this.toCreateCatalogName = toCreateCatalogName;
this.remotePersistence = remotePersistence;
this.rootFolderId = rootFolderId;
}
/**
* Gets the root folder id.
*
* @return the rootFolderId
*/
public String getRootFolderId() {
@ -58,8 +67,9 @@ public class ThSynchFolderConfiguration implements Serializable{
return rootFolderId;
}
/**
* Sets the root folder id.
*
* @param rootFolderId the rootFolderId to set
*/
public void setRootFolderId(String rootFolderId) {
@ -67,87 +77,105 @@ public class ThSynchFolderConfiguration implements Serializable{
this.rootFolderId = rootFolderId;
}
/**
* Gets the remote path.
*
* @return the remote path
*/
public String getRemotePath() {
return remotePath;
}
/**
* Sets the remote path.
*
* @param remotePath the new remote path
*/
public void setRemotePath(String remotePath) {
this.remotePath = remotePath;
}
/**
* Gets the filter.
*
* @return the filter
*/
public String getFilter() {
return filter;
}
/**
* Sets the filter.
*
* @param filter the new filter
*/
public void setFilter(String filter) {
this.filter = filter;
}
public String getTargetToken() {
return targetToken;
/**
* Gets the target context.
*
* @return the target context
*/
public String getTargetContext() {
return targetContext;
}
public void setTargetToken(String targetToken) {
this.targetToken = targetToken;
/**
* Sets the target context.
*
* @param targetContext the new target context
*/
public void setTargetContext(String targetContext) {
this.targetContext = targetContext;
}
/**
* Gets the to create catalog name.
*
* @return the to create catalog name
*/
public String getToCreateCatalogName() {
return toCreateCatalogName;
}
/**
* Sets the to create catalog name.
*
* @param toCreateCatalogName the new to create catalog name
*/
public void setToCreateCatalogName(String toCreateCatalogName) {
this.toCreateCatalogName = toCreateCatalogName;
}
/**
* Gets the remote persistence.
*
* @return the remote persistence
*/
public String getRemotePersistence() {
return remotePersistence;
}
/**
* Sets the remote persistence.
*
* @param remotePersistence the new remote persistence
*/
public void setRemotePersistence(String remotePersistence) {
this.remotePersistence = remotePersistence;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ThSynchFolderConfiguration [remotePath=");
builder.append(remotePath);
builder.append(", filter=");
builder.append(filter);
builder.append(", targetToken=");
builder.append(targetToken);
builder.append(", targetContext=");
builder.append(targetContext);
builder.append(", toCreateCatalogName=");
builder.append(toCreateCatalogName);
builder.append(", remotePersistence=");
@ -158,5 +186,7 @@ public class ThSynchFolderConfiguration implements Serializable{
return builder.toString();
}
}

View File

@ -16,15 +16,10 @@ import org.gcube.usecases.ws.thredds.model.gui.CatalogBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The Class ThreddsConverter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 14, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
*/
public class ThreddsConverter {
@ -35,135 +30,137 @@ public class ThreddsConverter {
/** The to S sync folder descriptor. */
public static Function<SyncFolderDescriptor, ThSyncFolderDescriptor> toThSyncFolderDescriptor = new Function<SyncFolderDescriptor, ThSyncFolderDescriptor>() {
public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) {
ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor();
if(t==null) {
logger.info("Input "+SyncFolderDescriptor.class.getSimpleName()+" is null, returning empty "+ThSyncFolderDescriptor.class.getSimpleName());
return mySync;
}
public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) {
ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor();
if (t == null) {
logger.info("Input " + SyncFolderDescriptor.class.getSimpleName() + " is null, returning empty "
+ ThSyncFolderDescriptor.class.getSimpleName());
return mySync;
}
mySync.setFolderId(t.getFolderId());
mySync.setFolderPath(t.getFolderPath());
mySync.setLocked(t.isLocked());
ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor());
mySync.setFolderId(t.getFolderId());
mySync.setFolderPath(t.getFolderPath());
mySync.setLocked(t.isLocked());
ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor());
mySync.setLocalProcessDescriptor(localProcessDescriptor);
ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration());
mySync.setConfiguration(configuration);
return mySync;
}
return mySync;
}
};
/** The to S sync folder descriptor. */
public static Function<ThSyncFolderDescriptor, SyncFolderDescriptor> toSyncFolderDescriptor = new Function<ThSyncFolderDescriptor, SyncFolderDescriptor>() {
public SyncFolderDescriptor apply(ThSyncFolderDescriptor t) {
public SyncFolderDescriptor apply(ThSyncFolderDescriptor t) {
if(t==null) {
logger.warn("Input "+ThSyncFolderDescriptor.class.getSimpleName()+" is null, returning null");
return null;
}
if (t == null) {
logger.warn("Input " + ThSyncFolderDescriptor.class.getSimpleName() + " is null, returning null");
return null;
}
SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration());
SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration());
return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration);
}
}
};
/** The to synch folder configuration. */
public static Function<ThSynchFolderConfiguration, SynchFolderConfiguration> toSynchFolderConfiguration = new Function<ThSynchFolderConfiguration, SynchFolderConfiguration>() {
public SynchFolderConfiguration apply(ThSynchFolderConfiguration t) {
public SynchFolderConfiguration apply(ThSynchFolderConfiguration t) {
if(t==null) {
logger.warn("Input "+ThSynchFolderConfiguration.class.getSimpleName()+" is null, returning null");
return null;
}
if (t == null) {
logger.warn("Input " + ThSynchFolderConfiguration.class.getSimpleName() + " is null, returning null");
return null;
}
String filter = t.getFilter()!=null && !t.getFilter().isEmpty()?t.getFilter():THREDDS_FILTER_NC_NCML_ASC;
return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetToken(), t.getToCreateCatalogName(), t.getRootFolderId());
}
String filter = t.getFilter() != null && !t.getFilter().isEmpty() ? t.getFilter()
: THREDDS_FILTER_NC_NCML_ASC;
return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetContext(),
t.getToCreateCatalogName(), t.getRootFolderId());
}
};
/** The to S synch folder configuration. */
public static Function<SynchFolderConfiguration, ThSynchFolderConfiguration> toThSynchFolderConfiguration = new Function<SynchFolderConfiguration, ThSynchFolderConfiguration>() {
public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) {
ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration();
if(t==null) {
logger.info("Input "+SynchFolderConfiguration.class.getSimpleName()+" is null, returning empty "+ThSynchFolderConfiguration.class.getSimpleName());
return mySync;
}
mySync.setFilter(t.getFilter());
mySync.setRemotePath(t.getRemotePath());
mySync.setRemotePersistence(t.getRemotePersistence());
mySync.setTargetToken(t.getTargetToken());
mySync.setToCreateCatalogName(t.getToCreateCatalogName());
mySync.setRootFolderId(t.getRootFolderId());
return mySync;
}
public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) {
ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration();
if (t == null) {
logger.info("Input " + SynchFolderConfiguration.class.getSimpleName() + " is null, returning empty "
+ ThSynchFolderConfiguration.class.getSimpleName());
return mySync;
}
mySync.setFilter(t.getFilter());
mySync.setRemotePath(t.getRemotePath());
mySync.setRemotePersistence(t.getRemotePersistence());
mySync.setTargetContext(t.getTargetContext());
mySync.setToCreateCatalogName(t.getToCreateCatalogName());
mySync.setRootFolderId(t.getRootFolderId());
return mySync;
}
};
/** The to S sync folder descriptor. */
public static Function<ProcessDescriptor, ThProcessDescriptor> toThProcessDescriptor = new Function<ProcessDescriptor, ThProcessDescriptor>() {
public ThProcessDescriptor apply(ProcessDescriptor t) {
ThProcessDescriptor mySync = new ThProcessDescriptor();
if(t==null) {
logger.info("Input "+ProcessDescriptor.class.getSimpleName()+" is null, returning empty "+ThProcessDescriptor.class.getSimpleName());
return mySync;
}
public ThProcessDescriptor apply(ProcessDescriptor t) {
ThProcessDescriptor mySync = new ThProcessDescriptor();
if (t == null) {
logger.info("Input " + ProcessDescriptor.class.getSimpleName() + " is null, returning empty "
+ ThProcessDescriptor.class.getSimpleName());
return mySync;
}
mySync.setFolderId(t.getFolderId());
mySync.setFolderPath(t.getFolderPath());
mySync.setProcessId(t.getProcessId());
ThSynchFolderConfiguration fc = toThSynchFolderConfiguration.apply(t.getSynchConfiguration());
mySync.setSynchConfiguration(fc);
return mySync;
}
mySync.setFolderId(t.getFolderId());
mySync.setFolderPath(t.getFolderPath());
mySync.setProcessId(t.getProcessId());
ThSynchFolderConfiguration fc = toThSynchFolderConfiguration.apply(t.getSynchConfiguration());
mySync.setSynchConfiguration(fc);
return mySync;
}
};
/** The to th catalogue bean. */
public static Function<CatalogBean, ThCatalogueBean> toThCatalogueBean = new Function<CatalogBean, ThCatalogueBean>() {
@Override
public ThCatalogueBean apply(CatalogBean t) {
if(t==null)
if (t == null)
return null;
return new ThCatalogueBean(t.getName(), t.getPath(), t.getIsDefault());
}
};
/** The to th process status. */
public static Function<ProcessStatus, ThProcessStatus> toThProcessStatus = new Function<ProcessStatus, ThProcessStatus>() {
public ThProcessStatus apply(ProcessStatus t) {
ThProcessStatus mySync = new ThProcessStatus();
if(t==null) {
logger.info("Input "+ProcessStatus.class.getSimpleName()+" is null, returning empty "+ThProcessStatus.class.getSimpleName());
return mySync;
}
public ThProcessStatus apply(ProcessStatus t) {
ThProcessStatus mySync = new ThProcessStatus();
if (t == null) {
logger.info("Input " + ProcessStatus.class.getSimpleName() + " is null, returning empty "
+ ThProcessStatus.class.getSimpleName());
return mySync;
}
mySync.setCurrentMessage(t.getCurrentMessage());
mySync.setPercentCompleted(t.getPercent());
mySync.setCurrentMessage(t.getCurrentMessage());
mySync.setPercentCompleted(t.getPercent());
if(t.getErrorCount()!=null)
mySync.setErrorCount(t.getErrorCount().get());
if(t.getLogBuilder()!=null)
mySync.setLogBuilder(t.getLogBuilder().toString());
if(t.getQueuedTransfers()!=null)
mySync.setQueuedTransfers(t.getQueuedTransfers().get());
if(t.getServedTransfers()!=null)
mySync.setServedTransfers(t.getServedTransfers().get());
if (t.getErrorCount() != null)
mySync.setErrorCount(t.getErrorCount().get());
if (t.getLogBuilder() != null)
mySync.setLogBuilder(t.getLogBuilder().toString());
if (t.getQueuedTransfers() != null)
mySync.setQueuedTransfers(t.getQueuedTransfers().get());
if (t.getServedTransfers() != null)
mySync.setServedTransfers(t.getServedTransfers().get());
if(t.getStatus()!=null) {
if (t.getStatus() != null) {
switch (t.getStatus()) {
switch (t.getStatus()) {
case COMPLETED:
mySync.setStatus(Status.COMPLETED);
break;
@ -183,12 +180,10 @@ public class ThreddsConverter {
default:
break;
}
}
//mySync.setStatus(t.getStatus());
return mySync;
}
}
// mySync.setStatus(t.getStatus());
return mySync;
}
};
}

View File

@ -34,21 +34,19 @@ import org.gcube.usecases.ws.thredds.model.gui.CatalogBean;
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
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
*/
public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronizedRepository<ThSyncStatus, ThSyncFolderDescriptor>{
public class WorkspaceThreddsSynchronize
implements WorkspaceThreddsSynchronizedRepository<ThSyncStatus, ThSyncFolderDescriptor> {
/** The logger. */
private static Logger logger = LoggerFactory.getLogger(WorkspaceThreddsSynchronize.class);
/** The engine. */
private SyncEngine engine=null;
private SyncEngine engine = null;
/** The instance. */
private static WorkspaceThreddsSynchronize instance = null;
@ -69,7 +67,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
engine = SyncEngine.get();
}
/**
* Gets the single instance of WorkspaceThreddsSynchronize.
*
@ -90,62 +87,68 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
*/
public static StorageHubClient getStorageHubInstance() {
if(storageHubInstance==null)
if (storageHubInstance == null)
storageHubInstance = new StorageHubClient();
return storageHubInstance;
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#isItemSynchronized(java.lang.String)
/*
* (non-Javadoc)
*
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
* isItemSynchronized(java.lang.String)
*/
/**
* Check item synched.
*
* @param itemId the item id
* @return the th sync folder descriptor
* @throws ItemNotSynched the item not synched
* @throws ItemNotSynched the item not synched
* @throws WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception
* @throws Exception the exception
*/
@Override
public ThSyncFolderDescriptor checkItemSynched(String itemId) throws ItemNotSynched, WorkspaceFolderLocked, Exception {
logger.debug("Perfoming checkItemSynched for id: "+itemId);
public ThSyncFolderDescriptor checkItemSynched(String itemId)
throws ItemNotSynched, WorkspaceFolderLocked, Exception {
logger.debug("Perfoming checkItemSynched for id: " + itemId);
try {
// WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS
SyncFolderDescriptor desc = engine.check(itemId, false);
logger.debug("The item id: "+itemId +" is synched");
logger.debug("The item id: " + itemId + " is synched");
ThSyncFolderDescriptor descr = ThreddsConverter.toThSyncFolderDescriptor.apply(desc);
logger.trace("CheckItemSynched for id: "+itemId+" returning descriptor: "+descr);
logger.trace("CheckItemSynched for id: " + itemId + " returning descriptor: " + descr);
return descr;
}catch(WorkspaceNotSynchedException e) {
String err = "The item id: "+itemId +" is not synched";
} 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");
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) {
//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);
// 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);
} 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);
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);
throw new Exception(
"Sorry, an error occurred server side during chck syncronization for the itemId: " + itemId);
}
}
/**
* Sets the synchronized folder.
*
@ -154,32 +157,31 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
* @return the th sync folder descriptor
* @throws Exception the exception
*/
public ThSyncFolderDescriptor setSynchronizedFolder(ThSynchFolderConfiguration thConfig, String itemId) throws Exception {
public ThSyncFolderDescriptor setSynchronizedFolder(ThSynchFolderConfiguration thConfig, String itemId)
throws Exception {
SynchFolderConfiguration config = ThreddsConverter.toSynchFolderConfiguration.apply(thConfig);
if(thConfig.getRemotePath()==null || thConfig.getRemotePath().isEmpty())
if (thConfig.getRemotePath() == null || thConfig.getRemotePath().isEmpty())
throw new Exception("A valid remote path must be provided");
if(thConfig.getToCreateCatalogName()==null || thConfig.getToCreateCatalogName().isEmpty())
if (thConfig.getToCreateCatalogName() == null || thConfig.getToCreateCatalogName().isEmpty())
throw new Exception("A valid Catalogue Name must be provided");
if(thConfig.getTargetToken()==null || thConfig.getTargetToken().isEmpty())
throw new Exception("A valid Target Token must be provided");
try {
engine.setSynchronizedFolder(config, itemId);
} catch (WorkspaceInteractionException | InternalException e) {
logger.error("Error on setSynchronizedFolder for config: "+thConfig);
logger.error("Using itemId: "+itemId,e);
logger.error("Error on setSynchronizedFolder for config: " + thConfig);
logger.error("Using itemId: " + itemId, e);
throw new Exception("Error on setSynchronizedFolder");
}
return null;
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#doSynchronization(java.lang.String)
/*
* (non-Javadoc)
*
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
* doSynchronization(java.lang.String)
*/
/**
* Do sync.
@ -196,7 +198,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
ProcessDescriptor descriptor = engine.doSync(itemId);
ThSyncStatus synStatus = mapCallBack.get(itemId);
if(synStatus==null) {
if (synStatus == null) {
registerCallbackForId(itemId);
descriptor = engine.getProcessDescriptorByFolderId(itemId);
@ -204,25 +206,31 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
updateMapCallback(itemId, status, descriptor);
}
logger.debug("DoSync returning status: "+synStatus);
logger.debug("DoSync returning status: " + synStatus);
return synStatus;
} catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) {
logger.error("Error: ",e);
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);
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);
throw new Exception(
"Sorry, an error occurred server side during syncronization for the itemId: " + itemId);
}
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String)
/*
* (non-Javadoc)
*
* @see
* org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String)
*/
/**
* Monitor sync status.
@ -230,7 +238,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
* @param itemId the item id
* @return the th sync status
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
* @throws Exception the exception
*/
@Override
public ThSyncStatus monitorSyncStatus(String itemId) throws ItemNotSynched, Exception {
@ -238,8 +246,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
try {
ThSyncStatus synStatus = mapCallBack.get(itemId);
if(synStatus==null) {
try{
if (synStatus == null) {
try {
registerCallbackForId(itemId);
ProcessDescriptor descriptor = engine.getProcessDescriptorByFolderId(itemId);
@ -247,84 +255,95 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
updateMapCallback(itemId, status, descriptor);
ThSyncStatus thSyncStatus = mapCallBack.get(itemId);
if(thSyncStatus==null)
throw new Exception("No sync status found for item id: "+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");
} catch (ProcessNotFoundException e) {
throw new Exception(
"Monitor is not available here. The sync process is in progress on another machine");
}
}
if(synStatus.getProcessStatus()!=null) {
if(synStatus.getProcessStatus().getStatus()!=null) {
if(synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) {
//TODO NOW?
if (synStatus.getProcessStatus() != null) {
if (synStatus.getProcessStatus().getStatus() != null) {
if (synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) {
// TODO NOW?
mapCallBack.put(itemId, null);
}
}
}
logger.trace("MonitorSyncStatus for item: "+itemId+" returning: "+synStatus);
logger.trace("MonitorSyncStatus for item: " + itemId + " returning: " + synStatus);
return synStatus;
} catch (Exception e) {
throw new Exception("Sorry, an error occurred during getting sync status for itemId: "+itemId, e);
throw new Exception("Sorry, an error occurred during getting sync status for itemId: " + itemId, e);
}
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(java.lang.String)
/*
* (non-Javadoc)
*
* @see
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(
* java.lang.String)
*/
/**
* Removes the sync.
*
* @param itemId the item id
* @return the boolean
* @throws Exception the exception
*/
@Override
public Boolean removeSync(String itemId) {
return null;
// TODO Auto-generated method stub
public Boolean removeSync(String itemId) throws Exception {
throw new Exception("removeSync not implemented");
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.lang.String)
/*
* (non-Javadoc)
*
* @see
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.
* lang.String)
*/
/**
* Stop sync.
*
* @param itemId the item id
* @return the boolean
* @throws Exception the exception
*/
@Override
public Boolean stopSync(String itemId) {
return false;
public Boolean stopSync(String itemId) throws Exception {
throw new Exception("stopSync not implemented");
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository()
/*
* (non-Javadoc)
*
* @see
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository
* ()
*/
/**
* Inits the repository.
*
* @return the boolean
* @throws Exception the exception
*/
@Override
public Boolean initRepository() {
return false;
public Boolean initRepository() throws Exception {
throw new Exception("initRepository not implemented");
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#shutDownRepository()
/*
* (non-Javadoc)
*
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
* shutDownRepository()
*/
/**
* Shut down repository.
@ -336,15 +355,18 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
try {
engine.shutDown();
return true;
}catch (Exception e) {
} catch (Exception e) {
return null;
}
}
/* (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository#decribeSyncRepository()
/*
* (non-Javadoc)
*
* @see
* org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository
* #decribeSyncRepository()
*/
/**
* Decribe sync repository.
@ -356,51 +378,51 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
return "Sync repository for Thredds";
}
/**
* Gets the synched status from item property.
*
* @param itemId the item id
* @param itemId the item id
* @param username the username
* @return the synched status from item property
* @throws ItemNotSynched the item not synched
* @throws Exception the exception
* @throws Exception the exception
*/
public Sync_Status getSynchedStatusFromItemProperty(String itemId, String username) throws ItemNotSynched, Exception{
public Sync_Status getSynchedStatusFromItemProperty(String itemId, String username)
throws ItemNotSynched, Exception {
if(itemId==null)
if (itemId == null)
throw new Exception("Invalid parameter itemId is null");
String scope = ScopeProvider.instance.get();
if(scope == null || scope.isEmpty())
if (scope == null || scope.isEmpty())
throw new Exception("You must set a valid scope into ScopeProvider instance");
String wsSyncStatus = null;
try{
try {
Map<String, Object> map = storageHubInstance.open(itemId).asItem().get().getMetadata().getMap();
wsSyncStatus = (String) map.get(WS_SYNCH_SYNCH_STATUS);
logger.debug("Item id: "+itemId+" read from Shub has current: "+WS_SYNCH_SYNCH_STATUS +" value at: "+wsSyncStatus);
if(wsSyncStatus==null)
logger.debug("Item id: " + itemId + " read from Shub has current: " + WS_SYNCH_SYNCH_STATUS + " value at: "
+ wsSyncStatus);
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");
} catch (Exception e) {
logger.warn(wsSyncStatus + " is not value of " + Sync_Status.values() + ", returning null");
return null;
}
}
/**
* Register callback for id.
*
* @param itemId the item id
* @throws ProcessNotFoundException the process not found exception
* @throws Exception the exception
* @throws Exception the exception
*/
@Override
public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception{
public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception {
try {
@ -408,86 +430,78 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
@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);
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);
}
};
// REGISTER CALLBACK TO MONITOR PROGRESS
logger.debug("Registering callback on itemId: "+itemId);
logger.debug("Registering callback on itemId: " + itemId);
engine.registerCallBack(itemId, callback);
}catch (ProcessNotFoundException e) {
logger.error("Register callback for id: "+itemId+" threw ProcessNotFoundException: ", e);
} catch (ProcessNotFoundException e) {
logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e);
throw e;
}catch (Exception e) {
logger.error("Register callback exception: ",e);
throw new Exception("An error occurred on registering callback for: "+itemId, e);
} catch (Exception e) {
logger.error("Register callback exception: ", e);
throw new Exception("An error occurred on registering callback for: " + itemId, e);
}
}
/**
* Update map callback.
*
* @param itemId the item id
* @param status the status
* @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);
logger.debug("Update map for " + itemId + " with new " + thStatus);
}
/**
* Gets the available catalogues by token.
*
* @param token the token
* @return the available catalogues by token
* Gets the available catalogues. you need to set the context caller.
*
* @return the available catalogues
* @throws Exception the exception
*/
public List<ThCatalogueBean> getAvailableCataloguesByToken(String token) throws Exception{
public List<ThCatalogueBean> getAvailableCatalogues() throws Exception {
logger.debug("called Get Available Catalogues");
Set<CatalogBean> ctlgs = engine.getAvailableCatalogs();
if(token==null || token.isEmpty())
throw new Exception("Invalid parameter token null or empty");
String printToken = token.substring(0, token.length()-5)+"XXXXX";
logger.debug("Get Available Catalogues by token: "+printToken);
Set<CatalogBean> ctlgs = engine.getAvailableCatalogsByToken(token);
if(ctlgs==null || ctlgs.size()==0){
logger.debug("No Catalogue available for token: "+printToken +" returning empty list");
if (ctlgs == null || ctlgs.size() == 0) {
logger.info("No Catalogue available in the current context, returning empty list");
return new ArrayList<ThCatalogueBean>(1);
}
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);
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);
}
Collections.sort(listCtlgs);
logger.debug("Returning sorted Catalogue list with: "+listCtlgs.size() +" item/s");
logger.info("Returning sorted Catalogue list with: " + listCtlgs.size() + " item/s");
return listCtlgs;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String)
*/
/**
* Do un sync.
*
* @param itemId the item id
* @param itemId the item id
* @param deleteRemoteContent the delete remote content
* @return the boolean
* @throws Exception the exception
@ -495,15 +509,15 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
@Override
public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception {
if(itemId==null)
if (itemId == null)
throw new Exception("Invalid parameter: itemId is null");
try{
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);
} 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);
}
}
}

View File

@ -4,8 +4,6 @@ import org.gcube.portal.wssynclibrary.DoCheckSyncItem;
import org.gcube.portal.wssynclibrary.DoConnectRepository;
import org.gcube.portal.wssynclibrary.DoSyncItem;
// TODO: Auto-generated Javadoc
/**
* The Interface WorkspaceThreddsSynchronizedRepository.
*