From 8947a38aa3502db367a746bf7beda5d26b4e4fbf Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 20 Nov 2018 14:52:13 +0000 Subject: [PATCH] Read of "WS-SYNCH.SYNCH-STATUS" from StorageHub instead of HL Updated pom version at 1.1.0 git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portal/ws-synchronized-module-library@174254 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 5 + pom.xml | 9 +- .../thredds/WorkspaceThreddsSynchronize.java | 108 ++++++++++++++++-- 3 files changed, 112 insertions(+), 10 deletions(-) diff --git a/distro/changelog.xml b/distro/changelog.xml index fdfc066..d8d25fb 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,9 @@ + + Read of "WS-SYNCH.SYNCH-STATUS" from StorageHub instead of HL + + [Task #12302] Fix ws-thredds dependency on workspace diff --git a/pom.xml b/pom.xml index b6025b3..75b623b 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.portal ws-synchronized-module-library - 1.0.1-SNAPSHOT + 1.1.0-SNAPSHOT jar ws-synchronized-module-library @@ -92,6 +92,13 @@ provided + + org.gcube.common + storagehub-client-library + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + compile + + org.slf4j diff --git a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java index 7762085..c0380ef 100644 --- a/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java +++ b/src/main/java/org/gcube/portal/wssynclibrary/thredds/WorkspaceThreddsSynchronize.java @@ -7,11 +7,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.gcube.common.homelibrary.home.HomeLibrary; -import org.gcube.common.homelibrary.home.workspace.Properties; -import org.gcube.common.homelibrary.home.workspace.Workspace; -import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.portal.wssynclibrary.shared.ItemNotSynched; import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked; import org.gcube.portal.wssynclibrary.shared.thredds.Status; @@ -56,6 +53,8 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /** The instance. */ private static WorkspaceThreddsSynchronize instance = null; + private static StorageHubClient storageHubInstance; + public static final String WS_SYNCH_SYNCH_STATUS = "WS-SYNCH.SYNCH-STATUS"; /** The map call back. */ @@ -79,13 +78,39 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized public static WorkspaceThreddsSynchronize getInstance() { if (instance == null) { instance = new WorkspaceThreddsSynchronize(); + storageHubInstance = new StorageHubClient(); } return instance; } + /** + * Gets the storage hub instance. + * + * @return the storage hub instance + */ + public static StorageHubClient getStorageHubInstance() { + + if(storageHubInstance==null) + storageHubInstance = new StorageHubClient(); + + return storageHubInstance; + + } + + + /* (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 WorkspaceFolderLocked the workspace folder locked + * @throws Exception the exception + */ @Override public ThSyncFolderDescriptor checkItemSynched(String itemId) throws ItemNotSynched, WorkspaceFolderLocked, Exception { logger.debug("Perfoming checkItemSynched for id: "+itemId); @@ -156,6 +181,13 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#doSynchronization(java.lang.String) */ + /** + * Do sync. + * + * @param itemId the item id + * @return the th sync status + * @throws Exception the exception + */ @Override public ThSyncStatus doSync(String itemId) throws Exception { @@ -192,6 +224,14 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.DoSyncItem#getSyncStatus(java.lang.String) */ + /** + * Monitor sync status. + * + * @param itemId the item id + * @return the th sync status + * @throws ItemNotSynched the item not synched + * @throws Exception the exception + */ @Override public ThSyncStatus monitorSyncStatus(String itemId) throws ItemNotSynched, Exception { @@ -238,6 +278,12 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#removeSync(java.lang.String) */ + /** + * Removes the sync. + * + * @param itemId the item id + * @return the boolean + */ @Override public Boolean removeSync(String itemId) { return null; @@ -249,6 +295,12 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#stopSync(java.lang.String) */ + /** + * Stop sync. + * + * @param itemId the item id + * @return the boolean + */ @Override public Boolean stopSync(String itemId) { return false; @@ -259,6 +311,11 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#initRepository() */ + /** + * Inits the repository. + * + * @return the boolean + */ @Override public Boolean initRepository() { return false; @@ -269,6 +326,11 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.WorkspaceSynchronizedRepository#shutDownRepository() */ + /** + * Shut down repository. + * + * @return the boolean + */ @Override public Boolean shutDownRepository() { try { @@ -284,17 +346,21 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronizedRepository#decribeSyncRepository() */ + /** + * Decribe sync repository. + * + * @return the string + */ @Override public String decribeSyncRepository() { return "Sync repository for Thredds"; } - /** * Gets the synched status from item property. * - * @param folderId the folder id + * @param itemId the item id * @param username the username * @return the synched status from item property * @throws ItemNotSynched the item not synched @@ -309,7 +375,23 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized if(scope == null || scope.isEmpty()) throw new Exception("You must set a valid scope into ScopeProvider instance"); - WorkspaceItem wsItem = null; + String wsSyncStatus = null; + try{ + + Map map = storageHubInstance.open(itemId).asItem().get().getPropertyMap().getValues(); + wsSyncStatus = (String) map.get(WS_SYNCH_SYNCH_STATUS); + logger.info("Item id: "+itemId+" 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"); + return null; + } + + + /*WorkspaceItem wsItem = null; try { @@ -335,7 +417,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized }catch (Exception e) { logger.warn(wsSyncStatus + " is not value of "+Sync_Status.values()+", returning null"); return null; - } + }*/ } @@ -343,6 +425,7 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized * Register callback for id. * * @param itemId the item id + * @throws ProcessNotFoundException the process not found exception * @throws Exception the exception */ @Override @@ -396,7 +479,6 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized * Gets the available catalogues by token. * * @param token the token - * @return * @return the available catalogues by token * @throws Exception the exception */ @@ -431,6 +513,14 @@ public class WorkspaceThreddsSynchronize implements WorkspaceThreddsSynchronized /* (non-Javadoc) * @see org.gcube.portal.wssynclibrary.DoSyncItem#doUnSync(java.lang.String) */ + /** + * Do un sync. + * + * @param itemId the item id + * @param deleteRemoteContent the delete remote content + * @return the boolean + * @throws Exception the exception + */ @Override public Boolean doUnSync(String itemId, boolean deleteRemoteContent) throws Exception {