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. 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). 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 ## [v1.4.0] - 2021-03-10

View File

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

View File

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

View File

@ -2,15 +2,13 @@ package org.gcube.portal.wssynclibrary.shared.thredds;
import java.io.Serializable; import java.io.Serializable;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
* The Class ThSynchFolderConfiguration. * The Class ThSynchFolderConfiguration.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 8, 2018
* Feb 8, 2018
*/ */
public class ThSynchFolderConfiguration implements Serializable{ public class ThSynchFolderConfiguration implements Serializable {
/** The Constant serialVersionUID. */ /** The Constant serialVersionUID. */
private static final long serialVersionUID = -5807533629170443212L; private static final long serialVersionUID = -5807533629170443212L;
@ -21,36 +19,47 @@ public class ThSynchFolderConfiguration implements Serializable{
/** The filter. */ /** The filter. */
private String filter; private String filter;
/** The target token. */ private String targetContext;
private String targetToken;
/** The to create catalog name. */ /** The to create catalog name. */
private String toCreateCatalogName; private String toCreateCatalogName;
/** The remote persistence. */ /** The remote persistence. */
private String remotePersistence="thredds"; private String remotePersistence = "thredds";
private String rootFolderId; private String rootFolderId;
/**
* Instantiates a new th synch folder configuration.
*/
public ThSynchFolderConfiguration() { public ThSynchFolderConfiguration() {
// TODO Auto-generated constructor stub // 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(); super();
this.remotePath = remotePath; this.remotePath = remotePath;
this.filter = filter; this.filter = filter;
this.targetToken = targetToken; this.targetContext = targetContext;
this.toCreateCatalogName = toCreateCatalogName; this.toCreateCatalogName = toCreateCatalogName;
this.remotePersistence = remotePersistence; this.remotePersistence = remotePersistence;
this.rootFolderId = rootFolderId; this.rootFolderId = rootFolderId;
} }
/** /**
* Gets the root folder id.
*
* @return the rootFolderId * @return the rootFolderId
*/ */
public String getRootFolderId() { public String getRootFolderId() {
@ -58,8 +67,9 @@ public class ThSynchFolderConfiguration implements Serializable{
return rootFolderId; return rootFolderId;
} }
/** /**
* Sets the root folder id.
*
* @param rootFolderId the rootFolderId to set * @param rootFolderId the rootFolderId to set
*/ */
public void setRootFolderId(String rootFolderId) { public void setRootFolderId(String rootFolderId) {
@ -67,87 +77,105 @@ public class ThSynchFolderConfiguration implements Serializable{
this.rootFolderId = rootFolderId; this.rootFolderId = rootFolderId;
} }
/**
* Gets the remote path.
*
* @return the remote path
*/
public String getRemotePath() { public String getRemotePath() {
return remotePath; return remotePath;
} }
/**
* Sets the remote path.
*
* @param remotePath the new remote path
*/
public void setRemotePath(String remotePath) { public void setRemotePath(String remotePath) {
this.remotePath = remotePath; this.remotePath = remotePath;
} }
/**
* Gets the filter.
*
* @return the filter
*/
public String getFilter() { public String getFilter() {
return filter; return filter;
} }
/**
* Sets the filter.
*
* @param filter the new filter
*/
public void setFilter(String filter) { public void setFilter(String filter) {
this.filter = filter; this.filter = filter;
} }
/**
* Gets the target context.
*
public String getTargetToken() { * @return the target context
return targetToken; */
public String getTargetContext() {
return targetContext;
} }
/**
* Sets the target context.
*
public void setTargetToken(String targetToken) { * @param targetContext the new target context
this.targetToken = targetToken; */
public void setTargetContext(String targetContext) {
this.targetContext = targetContext;
} }
/**
* Gets the to create catalog name.
*
* @return the to create catalog name
*/
public String getToCreateCatalogName() { public String getToCreateCatalogName() {
return toCreateCatalogName; return toCreateCatalogName;
} }
/**
* Sets the to create catalog name.
*
* @param toCreateCatalogName the new to create catalog name
*/
public void setToCreateCatalogName(String toCreateCatalogName) { public void setToCreateCatalogName(String toCreateCatalogName) {
this.toCreateCatalogName = toCreateCatalogName; this.toCreateCatalogName = toCreateCatalogName;
} }
/**
* Gets the remote persistence.
*
* @return the remote persistence
*/
public String getRemotePersistence() { public String getRemotePersistence() {
return remotePersistence; return remotePersistence;
} }
/**
* Sets the remote persistence.
*
* @param remotePersistence the new remote persistence
*/
public void setRemotePersistence(String remotePersistence) { public void setRemotePersistence(String remotePersistence) {
this.remotePersistence = remotePersistence; this.remotePersistence = remotePersistence;
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("ThSynchFolderConfiguration [remotePath="); builder.append("ThSynchFolderConfiguration [remotePath=");
builder.append(remotePath); builder.append(remotePath);
builder.append(", filter="); builder.append(", filter=");
builder.append(filter); builder.append(filter);
builder.append(", targetToken="); builder.append(", targetContext=");
builder.append(targetToken); builder.append(targetContext);
builder.append(", toCreateCatalogName="); builder.append(", toCreateCatalogName=");
builder.append(toCreateCatalogName); builder.append(toCreateCatalogName);
builder.append(", remotePersistence="); builder.append(", remotePersistence=");
@ -158,5 +186,7 @@ public class ThSynchFolderConfiguration implements Serializable{
return builder.toString(); 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/** /**
* The Class ThreddsConverter. * The Class ThreddsConverter.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
* Feb 14, 2018
*/ */
public class ThreddsConverter { public class ThreddsConverter {
@ -35,135 +30,137 @@ public class ThreddsConverter {
/** The to S sync folder descriptor. */ /** The to S sync folder descriptor. */
public static Function<SyncFolderDescriptor, ThSyncFolderDescriptor> toThSyncFolderDescriptor = new Function<SyncFolderDescriptor, ThSyncFolderDescriptor>() { public static Function<SyncFolderDescriptor, ThSyncFolderDescriptor> toThSyncFolderDescriptor = new Function<SyncFolderDescriptor, ThSyncFolderDescriptor>() {
public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) { public ThSyncFolderDescriptor apply(SyncFolderDescriptor t) {
ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor(); ThSyncFolderDescriptor mySync = new ThSyncFolderDescriptor();
if(t==null) { if (t == null) {
logger.info("Input "+SyncFolderDescriptor.class.getSimpleName()+" is null, returning empty "+ThSyncFolderDescriptor.class.getSimpleName()); logger.info("Input " + SyncFolderDescriptor.class.getSimpleName() + " is null, returning empty "
return mySync; + ThSyncFolderDescriptor.class.getSimpleName());
} return mySync;
}
mySync.setFolderId(t.getFolderId()); mySync.setFolderId(t.getFolderId());
mySync.setFolderPath(t.getFolderPath()); mySync.setFolderPath(t.getFolderPath());
mySync.setLocked(t.isLocked()); mySync.setLocked(t.isLocked());
ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor()); ThProcessDescriptor localProcessDescriptor = toThProcessDescriptor.apply(t.getLocalProcessDescriptor());
mySync.setLocalProcessDescriptor(localProcessDescriptor); mySync.setLocalProcessDescriptor(localProcessDescriptor);
ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration()); ThSynchFolderConfiguration configuration = toThSynchFolderConfiguration.apply(t.getConfiguration());
mySync.setConfiguration(configuration); mySync.setConfiguration(configuration);
return mySync; return mySync;
} }
}; };
/** The to S sync folder descriptor. */ /** The to S sync folder descriptor. */
public static Function<ThSyncFolderDescriptor, SyncFolderDescriptor> toSyncFolderDescriptor = new Function<ThSyncFolderDescriptor, SyncFolderDescriptor>() { public static Function<ThSyncFolderDescriptor, SyncFolderDescriptor> toSyncFolderDescriptor = new Function<ThSyncFolderDescriptor, SyncFolderDescriptor>() {
public SyncFolderDescriptor apply(ThSyncFolderDescriptor t) { public SyncFolderDescriptor apply(ThSyncFolderDescriptor t) {
if(t==null) { if (t == null) {
logger.warn("Input "+ThSyncFolderDescriptor.class.getSimpleName()+" is null, returning null"); logger.warn("Input " + ThSyncFolderDescriptor.class.getSimpleName() + " is null, returning null");
return null; return null;
} }
SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration()); SynchFolderConfiguration configuration = toSynchFolderConfiguration.apply(t.getConfiguration());
return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration); return new SyncFolderDescriptor(t.getFolderId(), t.getFolderPath(), configuration);
} }
}; };
/** The to synch folder configuration. */ /** The to synch folder configuration. */
public static Function<ThSynchFolderConfiguration, SynchFolderConfiguration> toSynchFolderConfiguration = new Function<ThSynchFolderConfiguration, SynchFolderConfiguration>() { public static Function<ThSynchFolderConfiguration, SynchFolderConfiguration> toSynchFolderConfiguration = new Function<ThSynchFolderConfiguration, SynchFolderConfiguration>() {
public SynchFolderConfiguration apply(ThSynchFolderConfiguration t) { public SynchFolderConfiguration apply(ThSynchFolderConfiguration t) {
if(t==null) { if (t == null) {
logger.warn("Input "+ThSynchFolderConfiguration.class.getSimpleName()+" is null, returning null"); logger.warn("Input " + ThSynchFolderConfiguration.class.getSimpleName() + " is null, returning null");
return null; return null;
} }
String filter = t.getFilter()!=null && !t.getFilter().isEmpty()?t.getFilter():THREDDS_FILTER_NC_NCML_ASC; String filter = t.getFilter() != null && !t.getFilter().isEmpty() ? t.getFilter()
return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetToken(), t.getToCreateCatalogName(), t.getRootFolderId()); : THREDDS_FILTER_NC_NCML_ASC;
} return new SynchFolderConfiguration(t.getRemotePath(), filter, t.getTargetContext(),
t.getToCreateCatalogName(), t.getRootFolderId());
}
}; };
/** The to S synch folder configuration. */ /** The to S synch folder configuration. */
public static Function<SynchFolderConfiguration, ThSynchFolderConfiguration> toThSynchFolderConfiguration = new Function<SynchFolderConfiguration, ThSynchFolderConfiguration>() { public static Function<SynchFolderConfiguration, ThSynchFolderConfiguration> toThSynchFolderConfiguration = new Function<SynchFolderConfiguration, ThSynchFolderConfiguration>() {
public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) { public ThSynchFolderConfiguration apply(SynchFolderConfiguration t) {
ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration(); ThSynchFolderConfiguration mySync = new ThSynchFolderConfiguration();
if(t==null) { if (t == null) {
logger.info("Input "+SynchFolderConfiguration.class.getSimpleName()+" is null, returning empty "+ThSynchFolderConfiguration.class.getSimpleName()); logger.info("Input " + SynchFolderConfiguration.class.getSimpleName() + " is null, returning empty "
return mySync; + ThSynchFolderConfiguration.class.getSimpleName());
} return mySync;
mySync.setFilter(t.getFilter()); }
mySync.setRemotePath(t.getRemotePath()); mySync.setFilter(t.getFilter());
mySync.setRemotePersistence(t.getRemotePersistence()); mySync.setRemotePath(t.getRemotePath());
mySync.setTargetToken(t.getTargetToken()); mySync.setRemotePersistence(t.getRemotePersistence());
mySync.setToCreateCatalogName(t.getToCreateCatalogName()); mySync.setTargetContext(t.getTargetContext());
mySync.setRootFolderId(t.getRootFolderId()); mySync.setToCreateCatalogName(t.getToCreateCatalogName());
return mySync; mySync.setRootFolderId(t.getRootFolderId());
} return mySync;
}
}; };
/** The to S sync folder descriptor. */ /** The to S sync folder descriptor. */
public static Function<ProcessDescriptor, ThProcessDescriptor> toThProcessDescriptor = new Function<ProcessDescriptor, ThProcessDescriptor>() { public static Function<ProcessDescriptor, ThProcessDescriptor> toThProcessDescriptor = new Function<ProcessDescriptor, ThProcessDescriptor>() {
public ThProcessDescriptor apply(ProcessDescriptor t) { public ThProcessDescriptor apply(ProcessDescriptor t) {
ThProcessDescriptor mySync = new ThProcessDescriptor(); ThProcessDescriptor mySync = new ThProcessDescriptor();
if(t==null) { if (t == null) {
logger.info("Input "+ProcessDescriptor.class.getSimpleName()+" is null, returning empty "+ThProcessDescriptor.class.getSimpleName()); logger.info("Input " + ProcessDescriptor.class.getSimpleName() + " is null, returning empty "
return mySync; + ThProcessDescriptor.class.getSimpleName());
} return mySync;
}
mySync.setFolderId(t.getFolderId()); mySync.setFolderId(t.getFolderId());
mySync.setFolderPath(t.getFolderPath()); mySync.setFolderPath(t.getFolderPath());
mySync.setProcessId(t.getProcessId()); mySync.setProcessId(t.getProcessId());
ThSynchFolderConfiguration fc = toThSynchFolderConfiguration.apply(t.getSynchConfiguration()); ThSynchFolderConfiguration fc = toThSynchFolderConfiguration.apply(t.getSynchConfiguration());
mySync.setSynchConfiguration(fc); mySync.setSynchConfiguration(fc);
return mySync; return mySync;
} }
}; };
/** The to th catalogue bean. */ /** The to th catalogue bean. */
public static Function<CatalogBean, ThCatalogueBean> toThCatalogueBean = new Function<CatalogBean, ThCatalogueBean>() { public static Function<CatalogBean, ThCatalogueBean> toThCatalogueBean = new Function<CatalogBean, ThCatalogueBean>() {
@Override @Override
public ThCatalogueBean apply(CatalogBean t) { public ThCatalogueBean apply(CatalogBean t) {
if(t==null) if (t == null)
return null; return null;
return new ThCatalogueBean(t.getName(), t.getPath(), t.getIsDefault()); return new ThCatalogueBean(t.getName(), t.getPath(), t.getIsDefault());
} }
}; };
/** The to th process status. */ /** The to th process status. */
public static Function<ProcessStatus, ThProcessStatus> toThProcessStatus = new Function<ProcessStatus, ThProcessStatus>() { public static Function<ProcessStatus, ThProcessStatus> toThProcessStatus = new Function<ProcessStatus, ThProcessStatus>() {
public ThProcessStatus apply(ProcessStatus t) { public ThProcessStatus apply(ProcessStatus t) {
ThProcessStatus mySync = new ThProcessStatus(); ThProcessStatus mySync = new ThProcessStatus();
if(t==null) { if (t == null) {
logger.info("Input "+ProcessStatus.class.getSimpleName()+" is null, returning empty "+ThProcessStatus.class.getSimpleName()); logger.info("Input " + ProcessStatus.class.getSimpleName() + " is null, returning empty "
return mySync; + ThProcessStatus.class.getSimpleName());
} return mySync;
}
mySync.setCurrentMessage(t.getCurrentMessage()); mySync.setCurrentMessage(t.getCurrentMessage());
mySync.setPercentCompleted(t.getPercent()); mySync.setPercentCompleted(t.getPercent());
if(t.getErrorCount()!=null) if (t.getErrorCount() != null)
mySync.setErrorCount(t.getErrorCount().get()); mySync.setErrorCount(t.getErrorCount().get());
if(t.getLogBuilder()!=null) if (t.getLogBuilder() != null)
mySync.setLogBuilder(t.getLogBuilder().toString()); mySync.setLogBuilder(t.getLogBuilder().toString());
if(t.getQueuedTransfers()!=null) if (t.getQueuedTransfers() != null)
mySync.setQueuedTransfers(t.getQueuedTransfers().get()); mySync.setQueuedTransfers(t.getQueuedTransfers().get());
if(t.getServedTransfers()!=null) if (t.getServedTransfers() != null)
mySync.setServedTransfers(t.getServedTransfers().get()); mySync.setServedTransfers(t.getServedTransfers().get());
if(t.getStatus()!=null) { if (t.getStatus() != null) {
switch (t.getStatus()) { switch (t.getStatus()) {
case COMPLETED: case COMPLETED:
mySync.setStatus(Status.COMPLETED); mySync.setStatus(Status.COMPLETED);
break; break;
@ -183,12 +180,10 @@ public class ThreddsConverter {
default: default:
break; break;
} }
} }
//mySync.setStatus(t.getStatus()); // mySync.setStatus(t.getStatus());
return mySync; return mySync;
} }
}; };
} }

View File

@ -34,21 +34,19 @@ import org.gcube.usecases.ws.thredds.model.gui.CatalogBean;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/** /**
* The Class WorkspaceThreddsSynchronize. * The Class WorkspaceThreddsSynchronize.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 14, 2018
* Feb 14, 2018
*/ */
public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronizedRepository<ThSyncStatus, ThSyncFolderDescriptor>{ public class WorkspaceThreddsSynchronize
implements WorkspaceThreddsSynchronizedRepository<ThSyncStatus, ThSyncFolderDescriptor> {
/** The logger. */ /** The logger. */
private static Logger logger = LoggerFactory.getLogger(WorkspaceThreddsSynchronize.class); private static Logger logger = LoggerFactory.getLogger(WorkspaceThreddsSynchronize.class);
/** The engine. */ /** The engine. */
private SyncEngine engine=null; private SyncEngine engine = null;
/** The instance. */ /** The instance. */
private static WorkspaceThreddsSynchronize instance = null; private static WorkspaceThreddsSynchronize instance = null;
@ -69,7 +67,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
engine = SyncEngine.get(); engine = SyncEngine.get();
} }
/** /**
* Gets the single instance of WorkspaceThreddsSynchronize. * Gets the single instance of WorkspaceThreddsSynchronize.
* *
@ -90,62 +87,68 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
*/ */
public static StorageHubClient getStorageHubInstance() { public static StorageHubClient getStorageHubInstance() {
if(storageHubInstance==null) if (storageHubInstance == null)
storageHubInstance = new StorageHubClient(); storageHubInstance = new StorageHubClient();
return storageHubInstance; return storageHubInstance;
} }
/*
* (non-Javadoc)
/* (non-Javadoc) *
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#isItemSynchronized(java.lang.String) * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
* isItemSynchronized(java.lang.String)
*/ */
/** /**
* Check item synched. * Check item synched.
* *
* @param itemId the item id * @param itemId the item id
* @return the th sync folder descriptor * @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 WorkspaceFolderLocked the workspace folder locked
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public ThSyncFolderDescriptor checkItemSynched(String itemId) throws ItemNotSynched, WorkspaceFolderLocked, Exception { public ThSyncFolderDescriptor checkItemSynched(String itemId)
logger.debug("Perfoming checkItemSynched for id: "+itemId); throws ItemNotSynched, WorkspaceFolderLocked, Exception {
logger.debug("Perfoming checkItemSynched for id: " + itemId);
try { try {
// WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS // WHEN OPENING A FOLDER, INVOKE CHECK TO UPDATE SYNCH STATUS
SyncFolderDescriptor desc = engine.check(itemId, false); 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); 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; return descr;
}catch(WorkspaceNotSynchedException e) { } catch (WorkspaceNotSynchedException e) {
String err = "The item id: "+itemId +" is not synched"; String err = "The item id: " + itemId + " is not synched";
logger.trace(err); 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.."); // System.out.println("Folder not synched, configurin it..");
//engine.setSynchronizedFolder(config, folder.getId()); // engine.setSynchronizedFolder(config, folder.getId());
}catch(WorkspaceLockedException e) { } catch (WorkspaceLockedException e) {
//logger.warn("Workspace locked, going to force unlock.."); // 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"); throw new WorkspaceFolderLocked(itemId,
//engine.forceUnlock(itemId); "The folder id: " + itemId + " is currently locked. Another sync process is in progress");
// engine.forceUnlock(itemId);
} catch (WorkspaceInteractionException | InternalException e) { } catch (WorkspaceInteractionException | InternalException e) {
logger.error("Error: ",e); logger.error("Error: ", e);
if(e instanceof WorkspaceInteractionException) if (e instanceof WorkspaceInteractionException)
throw new Exception("Sorry, an error occurred during check syncronization due to WS interection for the itemId: "+itemId); throw new Exception(
else if(e instanceof InternalException) "Sorry, an error occurred during check syncronization due to WS interection for the itemId: "
throw new Exception("Sorry, an Internal Exception occurred during check syncronization for the itemId: "+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. * Sets the synchronized folder.
* *
@ -154,32 +157,31 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
* @return the th sync folder descriptor * @return the th sync folder descriptor
* @throws Exception the exception * @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); 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"); 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"); 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 { try {
engine.setSynchronizedFolder(config, itemId); engine.setSynchronizedFolder(config, itemId);
} catch (WorkspaceInteractionException | InternalException e) { } catch (WorkspaceInteractionException | InternalException e) {
logger.error("Error on setSynchronizedFolder for config: "+thConfig); logger.error("Error on setSynchronizedFolder for config: " + thConfig);
logger.error("Using itemId: "+itemId,e); logger.error("Using itemId: " + itemId, e);
throw new Exception("Error on setSynchronizedFolder"); throw new Exception("Error on setSynchronizedFolder");
} }
return null; return null;
} }
/*
* (non-Javadoc)
/* (non-Javadoc) *
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#doSynchronization(java.lang.String) * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
* doSynchronization(java.lang.String)
*/ */
/** /**
* Do sync. * Do sync.
@ -196,7 +198,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
ProcessDescriptor descriptor = engine.doSync(itemId); ProcessDescriptor descriptor = engine.doSync(itemId);
ThSyncStatus synStatus = mapCallBack.get(itemId); ThSyncStatus synStatus = mapCallBack.get(itemId);
if(synStatus==null) { if (synStatus == null) {
registerCallbackForId(itemId); registerCallbackForId(itemId);
descriptor = engine.getProcessDescriptorByFolderId(itemId); descriptor = engine.getProcessDescriptorByFolderId(itemId);
@ -204,25 +206,31 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
updateMapCallback(itemId, status, descriptor); updateMapCallback(itemId, status, descriptor);
} }
logger.debug("DoSync returning status: "+synStatus); logger.debug("DoSync returning status: " + synStatus);
return synStatus; return synStatus;
} catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) { } catch (WorkspaceInteractionException | InternalException | ProcessNotFoundException e) {
logger.error("Error: ",e); logger.error("Error: ", e);
if(e instanceof WorkspaceInteractionException) if (e instanceof WorkspaceInteractionException)
throw new Exception("Sorry, an error occurred during syncronization due to WS interection for the itemId: "+itemId); throw new Exception(
else if(e instanceof InternalException) "Sorry, an error occurred during syncronization due to WS interection for the itemId: "
throw new Exception("Sorry, an Internal Exception occurred during syncronization for the itemId: "+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) * (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String) *
* @see
* org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String)
*/ */
/** /**
* Monitor sync status. * Monitor sync status.
@ -230,7 +238,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
* @param itemId the item id * @param itemId the item id
* @return the th sync status * @return the th sync status
* @throws ItemNotSynched the item not synched * @throws ItemNotSynched the item not synched
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public ThSyncStatus monitorSyncStatus(String itemId) throws ItemNotSynched, Exception { public ThSyncStatus monitorSyncStatus(String itemId) throws ItemNotSynched, Exception {
@ -238,8 +246,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
try { try {
ThSyncStatus synStatus = mapCallBack.get(itemId); ThSyncStatus synStatus = mapCallBack.get(itemId);
if(synStatus==null) { if (synStatus == null) {
try{ try {
registerCallbackForId(itemId); registerCallbackForId(itemId);
ProcessDescriptor descriptor = engine.getProcessDescriptorByFolderId(itemId); ProcessDescriptor descriptor = engine.getProcessDescriptorByFolderId(itemId);
@ -247,84 +255,95 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
updateMapCallback(itemId, status, descriptor); updateMapCallback(itemId, status, descriptor);
ThSyncStatus thSyncStatus = mapCallBack.get(itemId); ThSyncStatus thSyncStatus = mapCallBack.get(itemId);
if(thSyncStatus==null) if (thSyncStatus == null)
throw new Exception("No sync status found for item id: "+itemId); throw new Exception("No sync status found for item id: " + itemId);
return thSyncStatus; return thSyncStatus;
}catch(ProcessNotFoundException e){ } catch (ProcessNotFoundException e) {
throw new Exception("Monitor is not available here. The sync process is in progress on another machine"); throw new Exception(
"Monitor is not available here. The sync process is in progress on another machine");
} }
} }
if(synStatus.getProcessStatus()!=null) { if (synStatus.getProcessStatus() != null) {
if(synStatus.getProcessStatus().getStatus()!=null) { if (synStatus.getProcessStatus().getStatus() != null) {
if(synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) { if (synStatus.getProcessStatus().getStatus().equals(Status.COMPLETED)) {
//TODO NOW? // TODO NOW?
mapCallBack.put(itemId, null); mapCallBack.put(itemId, null);
} }
} }
} }
logger.trace("MonitorSyncStatus for item: "+itemId+" returning: "+synStatus); logger.trace("MonitorSyncStatus for item: " + itemId + " returning: " + synStatus);
return synStatus; return synStatus;
} catch (Exception e) { } 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) * (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(java.lang.String) *
* @see
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(
* java.lang.String)
*/ */
/** /**
* Removes the sync. * Removes the sync.
* *
* @param itemId the item id * @param itemId the item id
* @return the boolean * @return the boolean
* @throws Exception the exception
*/ */
@Override @Override
public Boolean removeSync(String itemId) { public Boolean removeSync(String itemId) throws Exception {
return null; throw new Exception("removeSync not implemented");
// TODO Auto-generated method stub
} }
/*
/* (non-Javadoc) * (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.lang.String) *
* @see
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.
* lang.String)
*/ */
/** /**
* Stop sync. * Stop sync.
* *
* @param itemId the item id * @param itemId the item id
* @return the boolean * @return the boolean
* @throws Exception the exception
*/ */
@Override @Override
public Boolean stopSync(String itemId) { public Boolean stopSync(String itemId) throws Exception {
return false; throw new Exception("stopSync not implemented");
} }
/*
/* (non-Javadoc) * (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository() *
* @see
* org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository
* ()
*/ */
/** /**
* Inits the repository. * Inits the repository.
* *
* @return the boolean * @return the boolean
* @throws Exception the exception
*/ */
@Override @Override
public Boolean initRepository() { public Boolean initRepository() throws Exception {
return false; throw new Exception("initRepository not implemented");
} }
/*
/* (non-Javadoc) * (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#shutDownRepository() *
* @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#
* shutDownRepository()
*/ */
/** /**
* Shut down repository. * Shut down repository.
@ -336,15 +355,18 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
try { try {
engine.shutDown(); engine.shutDown();
return true; return true;
}catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
} }
/*
/* (non-Javadoc) * (non-Javadoc)
* @see org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository#decribeSyncRepository() *
* @see
* org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository
* #decribeSyncRepository()
*/ */
/** /**
* Decribe sync repository. * Decribe sync repository.
@ -356,51 +378,51 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
return "Sync repository for Thredds"; return "Sync repository for Thredds";
} }
/** /**
* Gets the synched status from item property. * Gets the synched status from item property.
* *
* @param itemId the item id * @param itemId the item id
* @param username the username * @param username the username
* @return the synched status from item property * @return the synched status from item property
* @throws ItemNotSynched the item not synched * @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"); throw new Exception("Invalid parameter itemId is null");
String scope = ScopeProvider.instance.get(); 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"); throw new Exception("You must set a valid scope into ScopeProvider instance");
String wsSyncStatus = null; String wsSyncStatus = null;
try{ try {
Map<String, Object> map = storageHubInstance.open(itemId).asItem().get().getMetadata().getMap(); Map<String, Object> map = storageHubInstance.open(itemId).asItem().get().getMetadata().getMap();
wsSyncStatus = (String) map.get(WS_SYNCH_SYNCH_STATUS); 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); logger.debug("Item id: " + itemId + " read from Shub has current: " + WS_SYNCH_SYNCH_STATUS + " value at: "
if(wsSyncStatus==null) + wsSyncStatus);
if (wsSyncStatus == null)
return null; return null;
return Sync_Status.valueOf(wsSyncStatus); return Sync_Status.valueOf(wsSyncStatus);
}catch (Exception e) { } catch (Exception e) {
logger.warn(wsSyncStatus + " is not value of "+Sync_Status.values()+", returning null"); logger.warn(wsSyncStatus + " is not value of " + Sync_Status.values() + ", returning null");
return null; return null;
} }
} }
/** /**
* Register callback for id. * Register callback for id.
* *
* @param itemId the item id * @param itemId the item id
* @throws ProcessNotFoundException the process not found exception * @throws ProcessNotFoundException the process not found exception
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception{ public void registerCallbackForId(String itemId) throws ProcessNotFoundException, Exception {
try { try {
@ -408,86 +430,78 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
@Override @Override
public void onStep(ProcessStatus status, ProcessDescriptor descriptor) { public void onStep(ProcessStatus status, ProcessDescriptor descriptor) {
logger.debug("ON STEP : "+status+" "+descriptor); logger.debug("ON STEP : " + status + " " + descriptor);
logger.debug("LOG : \n"+ status.getLogBuilder().toString()); logger.debug("LOG : \n" + status.getLogBuilder().toString());
if(status.getStatus().equals(ProcessStatus.Status.COMPLETED)) { if (status.getStatus().equals(ProcessStatus.Status.COMPLETED)) {
//mapCallBack.remove(itemId); // mapCallBack.remove(itemId);
} }
updateMapCallback(itemId, status, descriptor); updateMapCallback(itemId, status, descriptor);
} }
}; };
// REGISTER CALLBACK TO MONITOR PROGRESS // REGISTER CALLBACK TO MONITOR PROGRESS
logger.debug("Registering callback on itemId: "+itemId); logger.debug("Registering callback on itemId: " + itemId);
engine.registerCallBack(itemId, callback); engine.registerCallBack(itemId, callback);
}catch (ProcessNotFoundException e) { } catch (ProcessNotFoundException e) {
logger.error("Register callback for id: "+itemId+" threw ProcessNotFoundException: ", e); logger.error("Register callback for id: " + itemId + " threw ProcessNotFoundException: ", e);
throw e; throw e;
}catch (Exception e) { } catch (Exception e) {
logger.error("Register callback exception: ",e); logger.error("Register callback exception: ", e);
throw new Exception("An error occurred on registering callback for: "+itemId, e); throw new Exception("An error occurred on registering callback for: " + itemId, e);
} }
} }
/** /**
* Update map callback. * Update map callback.
* *
* @param itemId the item id * @param itemId the item id
* @param status the status * @param status the status
* @param descriptor the descriptor * @param descriptor the descriptor
*/ */
private void updateMapCallback(String itemId, ProcessStatus status, ProcessDescriptor descriptor) { private void updateMapCallback(String itemId, ProcessStatus status, ProcessDescriptor descriptor) {
ThProcessDescriptor thDesc = ThreddsConverter.toThProcessDescriptor.apply(descriptor); ThProcessDescriptor thDesc = ThreddsConverter.toThProcessDescriptor.apply(descriptor);
ThProcessStatus thStatus = ThreddsConverter.toThProcessStatus.apply(status); ThProcessStatus thStatus = ThreddsConverter.toThProcessStatus.apply(status);
mapCallBack.put(itemId, new ThSyncStatus(thDesc, thStatus)); 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. * Gets the available catalogues. you need to set the context caller.
* *
* @param token the token * @return the available catalogues
* @return the available catalogues by token
* @throws Exception the exception * @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()) if (ctlgs == null || ctlgs.size() == 0) {
throw new Exception("Invalid parameter token null or empty"); logger.info("No Catalogue available in the current context, returning empty list");
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");
return new ArrayList<ThCatalogueBean>(1); return new ArrayList<ThCatalogueBean>(1);
} }
List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(ctlgs.size()); List<ThCatalogueBean> listCtlgs = new ArrayList<ThCatalogueBean>(ctlgs.size());
for(CatalogBean bean: ctlgs){ for (CatalogBean bean : ctlgs) {
System.out.println(bean.getName()+" in "+bean.getPath()+" Default : "+bean.getIsDefault()); logger.debug(bean.getName() + " in " + bean.getPath() + " Default : " + bean.getIsDefault());
ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean); ThCatalogueBean toBean = ThreddsConverter.toThCatalogueBean.apply(bean);
if(toBean!=null) if (toBean != null)
listCtlgs.add(toBean); listCtlgs.add(toBean);
} }
Collections.sort(listCtlgs); 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; return listCtlgs;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String) * @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String)
*/ */
/** /**
* Do un sync. * Do un sync.
* *
* @param itemId the item id * @param itemId the item id
* @param deleteRemoteContent the delete remote content * @param deleteRemoteContent the delete remote content
* @return the boolean * @return the boolean
* @throws Exception the exception * @throws Exception the exception
@ -495,15 +509,15 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized
@Override @Override
public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception { public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception {
if(itemId==null) if (itemId == null)
throw new Exception("Invalid parameter: itemId is null"); throw new Exception("Invalid parameter: itemId is null");
try{ try {
engine.unsetSynchronizedFolder(itemId, deleteRemoteContent); engine.unsetSynchronizedFolder(itemId, deleteRemoteContent);
return true; return true;
}catch(Exception e){ } catch (Exception e) {
logger.error("Unset Syncronized folder exception: ",e); logger.error("Unset Syncronized folder exception: ", e);
throw new Exception("An error occurred on deleting configuration to the item id: "+itemId, 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.DoConnectRepository;
import org.gcube.portal.wssynclibrary.DoSyncItem; import org.gcube.portal.wssynclibrary.DoSyncItem;
// TODO: Auto-generated Javadoc
/** /**
* The Interface WorkspaceThreddsSynchronizedRepository. * The Interface WorkspaceThreddsSynchronizedRepository.
* *