diff --git a/src/org/gcube/application/framework/core/cache/HarvestersManager.java b/src/org/gcube/application/framework/core/cache/HarvestersManager.java index a643f3e..08de916 100644 --- a/src/org/gcube/application/framework/core/cache/HarvestersManager.java +++ b/src/org/gcube/application/framework/core/cache/HarvestersManager.java @@ -79,6 +79,8 @@ public class HarvestersManager { modes.add(HarvestIS.MODE.PERSONALIZATION_USER); modes.add(HarvestIS.MODE.SEARCHMASTER); modes.add(HarvestIS.MODE.THUMBNAILER); + modes.add(HarvestIS.MODE.VREMANAGEMENT); + try { System.out.println("There is no harvester for the DL: " + scope.getName() + ". Creating a new harvester."); returnedThread = new HarvestIS(isInfo, modes, scope); @@ -93,7 +95,7 @@ public class HarvestersManager { /* Start harvester */ returnedThread.start(); try { - Thread.sleep(10000); + Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); } diff --git a/src/org/gcube/application/framework/core/cache/factories/ProfileCacheEntryFactory.java b/src/org/gcube/application/framework/core/cache/factories/ProfileCacheEntryFactory.java index dbbdc1c..3ada9f6 100644 --- a/src/org/gcube/application/framework/core/cache/factories/ProfileCacheEntryFactory.java +++ b/src/org/gcube/application/framework/core/cache/factories/ProfileCacheEntryFactory.java @@ -56,12 +56,22 @@ public class ProfileCacheEntryFactory implements CacheEntryFactory { System.out.println("Scope=" + GCUBEScope.getScope(query.get(CacheEntryConstants.dl))); ProfileService profileService = new ProfileService(query.get(CacheEntryConstants.username), GCUBEScope.getScope(query.get(CacheEntryConstants.dl))); ExtendedGSSCredential cred = (new PortalSecurityManager(GCUBEScope.getScope(query.get(CacheEntryConstants.dl))).isSecurityEnabled())?ApplicationCredentials.getInstance().getCredential(CacheEntryConstants.dl):null; - UserProfileAccessPortType port = profileService.getUserProfileAccess(cred); - profile = port.getUserProfile(new VOID()); // this is the profile!!! - System.out.println(profile); - InputSource profileIn = new InputSource(new ByteArrayInputStream(profile.getBytes())); - Document profileDoc = dfactory.newDocumentBuilder().parse(profileIn); - return profileDoc; + for(int i=0; i < 10; i++) + { + try + { + UserProfileAccessPortType port = profileService.getUserProfileAccess(cred); + profile = port.getUserProfile(new VOID()); // this is the profile!!! + System.out.println(profile); + InputSource profileIn = new InputSource(new ByteArrayInputStream(profile.getBytes())); + Document profileDoc = dfactory.newDocumentBuilder().parse(profileIn); + return profileDoc; + } + catch(Exception e) + { + + } + } } return null; } diff --git a/src/org/gcube/application/framework/core/vremanagement/impl/SoftwareRepository.java b/src/org/gcube/application/framework/core/vremanagement/impl/SoftwareRepository.java index 9a99e4e..7b76054 100644 --- a/src/org/gcube/application/framework/core/vremanagement/impl/SoftwareRepository.java +++ b/src/org/gcube/application/framework/core/vremanagement/impl/SoftwareRepository.java @@ -1,7 +1,28 @@ package org.gcube.application.framework.core.vremanagement.impl; +import java.rmi.RemoteException; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.axis.message.addressing.Address; +import org.apache.axis.message.addressing.EndpointReferenceType; +import org.gcube.application.framework.core.cache.HarvestersManager; +import org.gcube.application.framework.core.security.PortalSecurityManager; import org.gcube.application.framework.core.session.D4ScienceSession; import org.gcube.application.framework.core.vremanagement.SoftwareRepositoryI; +import org.gcube.common.core.contexts.GCUBERemotePortTypeContext; +import org.gcube.common.core.faults.GCUBEFault; +import org.gcube.common.core.security.GCUBESecurityManager; +import org.gcube.common.core.types.VOID; +import org.gcube.personalization.userprofileaccess.stubs.UserProfileAccessFactoryPortType; +import org.gcube.personalization.userprofileaccess.stubs.service.UserProfileAccessFactoryServiceAddressingLocator; +import org.gcube.vremanagement.softwarerepository.stubs.GetMessage; +import org.gcube.vremanagement.softwarerepository.stubs.ListScopedPackagesMessage; +import org.gcube.vremanagement.softwarerepository.stubs.ListScopedPackagesMessageScope; +import org.gcube.vremanagement.softwarerepository.stubs.SoftwareRepositoryPortType; +import org.gcube.vremanagement.softwarerepository.stubs.StoreMessage; +import org.gcube.vremanagement.softwarerepository.stubs.service.SoftwareRepositoryServiceAddressingLocator; + +import com.sun.org.omg.SendingContext.CodeBasePackage.URLSeqHelper; /** * @author Valia Tsagkalidou (KNUA) @@ -14,7 +35,11 @@ public class SoftwareRepository implements SoftwareRepositoryI{ */ protected D4ScienceSession session; - + + /** + * An atomic integer to get the Profile EPRs round-robin + */ + protected static AtomicInteger srId = new AtomicInteger(0); /** * @param session the D4Science Session to use @@ -24,13 +49,87 @@ public class SoftwareRepository implements SoftwareRepositoryI{ this.session = session; } + protected int getSRUrlsSize() + { + try { + return HarvestersManager.getInstance().getISInfo(session.getScope()).getEndPointForSoftwareRepositoryService().length; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return 0; + } + } + protected SoftwareRepositoryPortType getSRPortType() + { + String[] urls = null; + try { + urls = HarvestersManager.getInstance().getISInfo(session.getScope()).getEndPointForSoftwareRepositoryService(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + EndpointReferenceType serviceEPR = new EndpointReferenceType(); + SoftwareRepositoryPortType srPort = null; + + try + { + serviceEPR.setAddress(new Address(urls[srId.getAndIncrement()%urls.length])); + SoftwareRepositoryServiceAddressingLocator srLocator = new SoftwareRepositoryServiceAddressingLocator(); + srPort = srLocator.getSoftwareRepositoryPortTypePort(serviceEPR); + + GCUBESecurityManager secManager = new PortalSecurityManager(session); + if(secManager.isSecurityEnabled()) + { + try { + secManager.useCredentials(session.getCredential()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + try { + srPort = GCUBERemotePortTypeContext.getProxy(srPort, session.getScope(), secManager); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return srPort; + } + catch (Exception e) { + e.printStackTrace(); + } + return null; + + } /** * @inheritDoc */ public String store(String serviceClass, String serviceName, String serviceVersion, String URL, String description) { - // TODO Auto-generated method stub + int n = getSRUrlsSize(); + for(int i=0; i < n ; i++) + { + SoftwareRepositoryPortType srPort = getSRPortType(); + String[] scopes = new String[1]; + scopes[0] = session.getScopeName(); + StoreMessage storeMsg = new StoreMessage(); + storeMsg.setDescription(description); + storeMsg.setScopes(scopes); + storeMsg.setServiceClass(serviceClass); + storeMsg.setServiceName(serviceName); + storeMsg.setServiceVersion(serviceVersion); + try { + return srPort.store(storeMsg); + } catch (GCUBEFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } return null; } @@ -38,7 +137,22 @@ public class SoftwareRepository implements SoftwareRepositoryI{ * @inheritDoc */ public String listPending() { - // TODO Auto-generated method stub + int n = getSRUrlsSize(); + for(int i=0; i < n ; i++) + { + SoftwareRepositoryPortType srPort = getSRPortType(); + String[] scopes = new String[1]; + scopes[0] = session.getScopeName(); + try { + return srPort.listPending(new VOID()); + } catch (GCUBEFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } return null; } @@ -46,7 +160,22 @@ public class SoftwareRepository implements SoftwareRepositoryI{ * @see org.gcube.application.framework.SoftwareRepositoryI#approve(java.lang.String) */ public String approve(String id) { - // TODO Auto-generated method stub + int n = getSRUrlsSize(); + for(int i=0; i < n ; i++) + { + SoftwareRepositoryPortType srPort = getSRPortType(); + String[] scopes = new String[1]; + scopes[0] = session.getScopeName(); + try { + return srPort.approve(id); + } catch (GCUBEFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } return null; } @@ -54,7 +183,25 @@ public class SoftwareRepository implements SoftwareRepositoryI{ * @see org.gcube.application.framework.SoftwareRepositoryI#listScopedPackages(java.lang.String, java.lang.String) */ public String[] listScopedPackages(String scope, String serviceID) { - // TODO Auto-generated method stub + int n = getSRUrlsSize(); + for(int i=0; i < n ; i++) + { + SoftwareRepositoryPortType srPort = getSRPortType(); + String[] scopes = new String[1]; + scopes[0] = session.getScopeName(); + ListScopedPackagesMessage scopePacks = new ListScopedPackagesMessage(); + scopePacks.setScope(ListScopedPackagesMessageScope.fromString(scope)); + scopePacks.setServiceID(serviceID); + try { + srPort.listScopedPackages(scopePacks); + } catch (GCUBEFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } return null; } @@ -62,7 +209,22 @@ public class SoftwareRepository implements SoftwareRepositoryI{ * @see org.gcube.application.framework.SoftwareRepositoryI#isDeployable(java.lang.String) */ public String[] isDeployable(String serviceID) { - // TODO Auto-generated method stub + int n = getSRUrlsSize(); + for(int i=0; i < n ; i++) + { + SoftwareRepositoryPortType srPort = getSRPortType(); + String[] scopes = new String[1]; + scopes[0] = session.getScopeName(); + try { + srPort.isDeployable(serviceID); + } catch (GCUBEFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } return null; } @@ -71,7 +233,28 @@ public class SoftwareRepository implements SoftwareRepositoryI{ */ public String get(String packageName, String serviceClass, String serviceName, String serviceVersion, String version) { - // TODO Auto-generated method stub + int n = getSRUrlsSize(); + for(int i=0; i < n ; i++) + { + SoftwareRepositoryPortType srPort = getSRPortType(); + String[] scopes = new String[1]; + scopes[0] = session.getScopeName(); + try { + GetMessage getMsg = new GetMessage(); + getMsg.setPackageName(packageName); + getMsg.setServiceClass(serviceClass); + getMsg.setServiceName(serviceName); + getMsg.setServiceVersion(serviceVersion); + getMsg.setVersion(version); + srPort.get(getMsg ); + } catch (GCUBEFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } return null; } @@ -79,8 +262,22 @@ public class SoftwareRepository implements SoftwareRepositoryI{ * @see org.gcube.application.framework.SoftwareRepositoryI#delete(java.lang.String) */ public String delete(String vo) { - return vo; - // TODO Auto-generated method stub - + int n = getSRUrlsSize(); + for(int i=0; i < n ; i++) + { + SoftwareRepositoryPortType srPort = getSRPortType(); + String[] scopes = new String[1]; + scopes[0] = session.getScopeName(); + try { + return srPort.delete(vo); + } catch (GCUBEFault e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return null; } }