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
This commit is contained in:
Francesco Mangiacrapa 2018-11-20 14:52:13 +00:00
parent a3c6a49b6e
commit 8947a38aa3
3 changed files with 112 additions and 10 deletions

View File

@ -1,4 +1,9 @@
<ReleaseNotes>
<Changeset component="org.gcube.portal.ws-synchronized-module-library.1-1-0"
date="2018-11-20">
<Change>Read of "WS-SYNCH.SYNCH-STATUS" from StorageHub instead of HL
</Change>
</Changeset>
<Changeset component="org.gcube.portal.ws-synchronized-module-library.1-0-1"
date="2018-09-04">
<Change>[Task #12302] Fix ws-thredds dependency on workspace

View File

@ -11,7 +11,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>ws-synchronized-module-library</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ws-synchronized-module-library</name>
@ -92,6 +92,13 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -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<String, Object> 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 {