2017-03-03 19:10:02 +01:00
package org.gcube.dataanalysis.dataminer.poolmanager.clients ;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor ;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor ;
2017-04-04 19:32:53 +02:00
* * * REMOVED * * *
2017-05-11 12:58:38 +02:00
import java.io.StringWriter ;
2017-04-05 17:14:18 +02:00
import java.util.Arrays ;
2017-03-03 19:10:02 +01:00
import java.util.Collection ;
* * * REMOVED * * *
import java.util.Vector ;
2017-05-11 12:58:38 +02:00
* * * REMOVED * * *
import org.gcube.common.resources.gcore.GenericResource ;
import org.gcube.common.resources.gcore.Resources ;
2017-03-03 19:10:02 +01:00
import org.gcube.common.resources.gcore.ServiceEndpoint ;
* * * REMOVED * * *
2017-05-11 12:58:38 +02:00
* * * REMOVED * * *
2017-03-03 19:10:02 +01:00
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Host ;
2017-05-11 12:58:38 +02:00
import org.gcube.informationsystem.publisher.AdvancedScopedPublisher ;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory ;
import org.gcube.informationsystem.publisher.ScopedPublisher ;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException ;
2017-03-03 19:10:02 +01:00
import org.gcube.resources.discovery.client.api.DiscoveryClient ;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery ;
2017-05-11 12:58:38 +02:00
* * * REMOVED * * *
* * * REMOVED * * *
2017-04-05 17:14:18 +02:00
* * * REMOVED * * *
2017-04-04 19:32:53 +02:00
2017-03-03 19:10:02 +01:00
public class ISClient * * * REMOVED * * *
2017-12-20 12:01:01 +01:00
private Logger logger ;
2017-03-03 19:10:02 +01:00
2017-12-20 12:01:01 +01:00
public ISClient ( ) * * * REMOVED * * *
this . logger = LoggerFactory . getLogger ( ISClient . class ) ;
* * * REMOVED * * *
2017-04-04 19:32:53 +02:00
2017-03-03 19:10:02 +01:00
public Host getDataminer ( String hostname ) * * * REMOVED * * *
Host h = new Host ( ) ;
boolean remote2 = true ;
if ( ! remote2 ) * * * REMOVED * * *
h . setName ( " dataminer1-devnext.d4science.org " ) ;
return h ;
* * * REMOVED * * * else * * * REMOVED * * *
2017-04-20 11:15:11 +02:00
* * * REMOVED * * * SimpleQuery query = queryFor ( ServiceEndpoint . class ) ;
* * * REMOVED * * * query . addCondition ( " $resource/Profile/RunTime/HostedOn/text() eq ' " + hostname + " ' " ) ;
* * * REMOVED * * * DiscoveryClient < ServiceEndpoint > client = clientFor ( ServiceEndpoint . class ) ;
* * * REMOVED * * * List < ServiceEndpoint > resources = client . submit ( query ) ;
* * * REMOVED * * * ServiceEndpoint a = resources . get ( 0 ) ;
* * * REMOVED * * * h . setName ( a . profile ( ) . runtime ( ) . hostedOn ( ) ) ;
h . setName ( hostname ) ;
2017-03-03 19:10:02 +01:00
* * * REMOVED * * *
return h ;
* * * REMOVED * * *
2017-05-09 17:10:03 +02:00
2017-04-19 17:01:13 +02:00
* * * REMOVED * * * return the HProxy hostname in the VRE
public static String getHProxy ( ) * * * REMOVED * * *
Host h = new Host ( ) ;
SimpleQuery query = queryFor ( ServiceEndpoint . class ) ;
2017-04-19 18:20:29 +02:00
query . addCondition ( " $resource/Profile/Name/text() eq 'DataMiner' " ) ;
2017-04-19 17:01:13 +02:00
DiscoveryClient < ServiceEndpoint > client = clientFor ( ServiceEndpoint . class ) ;
List < ServiceEndpoint > resources = client . submit ( query ) ;
h . setName ( resources . get ( 0 ) . profile ( ) . runtime ( ) . hostedOn ( ) ) ;
return h . getName ( ) ;
* * * REMOVED * * *
2017-06-19 18:34:44 +02:00
2017-04-19 17:01:13 +02:00
public Collection < Host > listDataminersInVRE ( ) * * * REMOVED * * *
boolean remote = false ;
if ( ! remote ) * * * REMOVED * * *
Collection < Host > out = new Vector < > ( ) ;
Host h = new Host ( ) ;
* * * REMOVED * * * h . setName ( " bb-dataminer.res.eng.it " ) ;
* * * REMOVED * * * h . setName ( " vm101.ui.savba.sk " ) ;
h . setName ( " dataminer1-devnext.d4science.org " ) ;
out . add ( h ) ;
return out ;
* * * REMOVED * * * else * * * REMOVED * * *
SimpleQuery query = queryFor ( ServiceEndpoint . class ) ;
* * * REMOVED * * * old version
* * * REMOVED * * * query . addCondition ( " $resource/Profile/Category/text() eq
* * * REMOVED * * * ' DataAnalysis ' " )
* * * REMOVED * * * . addCondition ( " $resource/Profile/Name/text() eq 'DataMiner' " ) ;
query . addCondition ( " $resource/Profile/Platform/Name/text() eq 'DataMiner' " ) ;
DiscoveryClient < ServiceEndpoint > client = clientFor ( ServiceEndpoint . class ) ;
List < ServiceEndpoint > resources = client . submit ( query ) ;
Collection < Host > out = new Vector < > ( ) ;
for ( ServiceEndpoint r : resources ) * * * REMOVED * * *
Host h = new Host ( ) ;
h . setName ( r . profile ( ) . runtime ( ) . hostedOn ( ) ) ;
out . add ( h ) ;
* * * REMOVED * * *
return out ;
* * * REMOVED * * *
* * * REMOVED * * *
2017-05-11 12:58:38 +02:00
public void updateAlg ( Algorithm algo ) * * * REMOVED * * *
ScopedPublisher scopedPublisher = RegistryPublisherFactory . scopedPublisher ( ) ;
SimpleQuery query = queryFor ( GenericResource . class ) ;
query . addCondition ( " $resource/Profile/Name/text() eq ' " + algo . getName ( ) + " ' " ) . setResult ( " $resource " ) ;
DiscoveryClient < GenericResource > client = clientFor ( GenericResource . class ) ;
List < GenericResource > ds = client . submit ( query ) ;
if ( ds . isEmpty ( ) ) * * * REMOVED * * *
return ;
* * * REMOVED * * *
GenericResource a = ds . get ( 0 ) ;
a . profile ( ) . newBody ( this . getAlgoBody ( algo ) ) ;
try * * * REMOVED * * *
scopedPublisher . update ( a ) ;
* * * REMOVED * * * catch ( RegistryNotFoundException e ) * * * REMOVED * * *
e . printStackTrace ( ) ;
* * * REMOVED * * *
* * * REMOVED * * *
private String getAlgoBody ( Algorithm algo ) * * * REMOVED * * *
return " <category> " + algo . getCategory ( ) + " </category> " + " \ n " + " <clazz> " + algo . getClazz ( ) + " </clazz> "
+ " \ n " + " <algorithmType> " + algo . getAlgorithmType ( ) + " </algorithmType> " + " \ n " + " <skipJava> "
+ algo . getSkipJava ( ) + " </skipJava> " + " \ n " + " <packageURL> " + algo . getPackageURL ( ) + " </packageURL> "
+ " \ n " + " <dependencies> " + algo . getDependencies ( ) + " </dependencies> " ;
* * * REMOVED * * *
* * * REMOVED * * * public void addAlgToIs ( Algorithm algo ) * * * REMOVED * * *
* * * REMOVED * * * GenericResource a = new GenericResource ( ) ;
* * * REMOVED * * * a . newProfile ( ) . name ( algo . getName ( ) ) . type ( " StatisticalManagerAlgorithm " ) . description ( algo . getDescription ( ) ) ;
* * * REMOVED * * * a . profile ( ) . newBody ( this . getAlgoBody ( algo ) ) ;
* * * REMOVED * * * try * * * REMOVED * * *
* * * REMOVED * * * publishScopedResource ( a , Arrays . asList ( new String [ ] * * * REMOVED * * * ScopeProvider . instance . get ( ) * * * REMOVED * * * ) ) ;
* * * REMOVED * * * * * * REMOVED * * * catch ( Exception e ) * * * REMOVED * * *
* * * REMOVED * * * e . printStackTrace ( ) ;
* * * REMOVED * * * * * * REMOVED * * *
* * * REMOVED * * * * * * REMOVED * * *
public void addAlgToIs ( Algorithm algo , String token ) * * * REMOVED * * *
GenericResource a = new GenericResource ( ) ;
a . newProfile ( ) . name ( algo . getName ( ) ) . type ( " StatisticalManagerAlgorithm " ) . description ( algo . getDescription ( ) ) ;
a . profile ( ) . newBody ( this . getAlgoBody ( algo ) ) ;
try * * * REMOVED * * *
SecurityTokenProvider . instance . set ( token ) ;
2017-05-11 17:03:59 +02:00
publishScopedResource ( a , Arrays . asList ( new String [ ] * * * REMOVED * * * SecurityTokenProvider . instance . get ( ) * * * REMOVED * * * ) ) ;
2017-05-11 12:58:38 +02:00
* * * REMOVED * * * catch ( Exception e ) * * * REMOVED * * *
e . printStackTrace ( ) ;
* * * REMOVED * * *
* * * REMOVED * * *
public void unPublishScopedResource ( GenericResource resource ) throws RegistryNotFoundException , Exception * * * REMOVED * * *
ScopedPublisher scopedPublisher = RegistryPublisherFactory . scopedPublisher ( ) ;
AdvancedScopedPublisher advancedScopedPublisher = new AdvancedScopedPublisher ( scopedPublisher ) ;
String id = resource . id ( ) ;
2017-12-20 12:01:01 +01:00
this . logger . info ( " Trying to remove ***REMOVED******REMOVED*** with ID ***REMOVED******REMOVED*** from ***REMOVED******REMOVED*** " , resource . getClass ( ) . getSimpleName ( ) , id ,
2017-05-11 12:58:38 +02:00
ScopeProvider . instance . get ( ) ) ;
* * * REMOVED * * * scopedPublisher . remove ( resource , scopes ) ;
advancedScopedPublisher . forceRemove ( resource ) ;
2017-12-20 12:01:01 +01:00
this . logger . info ( " ***REMOVED******REMOVED*** with ID ***REMOVED******REMOVED*** removed successfully " , resource . getClass ( ) . getSimpleName ( ) , id ) ;
2017-05-11 12:58:38 +02:00
* * * REMOVED * * *
public void publishScopedResource ( GenericResource a , List < String > scopes )
throws RegistryNotFoundException , Exception * * * REMOVED * * *
StringWriter stringWriter = new StringWriter ( ) ;
Resources . marshal ( a , stringWriter ) ;
ScopedPublisher scopedPublisher = RegistryPublisherFactory . scopedPublisher ( ) ;
try * * * REMOVED * * *
2017-12-20 12:01:01 +01:00
this . logger . debug ( scopes . toString ( ) ) ;
this . logger . debug ( stringWriter . toString ( ) ) ;
2017-05-11 12:58:38 +02:00
scopedPublisher . create ( a , scopes ) ;
* * * REMOVED * * * catch ( RegistryNotFoundException e ) * * * REMOVED * * *
2017-12-20 12:01:01 +01:00
this . logger . error ( " Registry not found " , e ) ;
2017-05-11 12:58:38 +02:00
throw e ;
* * * REMOVED * * *
* * * REMOVED * * *
2017-10-30 22:38:11 +01:00
2017-09-07 18:46:26 +02:00
* * * REMOVED * * * public Set < Algorithm > getAlgoFromIs ( ) * * * REMOVED * * *
* * * REMOVED * * * * * * REMOVED * * *
2017-05-11 12:58:38 +02:00
* * * REMOVED * * *
2017-09-07 18:46:26 +02:00
* * * REMOVED * * * Set < Algorithm > out = new HashSet < Algorithm > ( ) ;
* * * REMOVED * * * SimpleQuery query = queryFor ( GenericResource . class ) ;
* * * REMOVED * * * query . addCondition ( " $resource/Profile/SecondaryType/text() eq 'StatisticalManagerAlgorithm' " )
* * * REMOVED * * * . setResult ( " $resource " ) ;
* * * REMOVED * * * DiscoveryClient < GenericResource > client = clientFor ( GenericResource . class ) ;
* * * REMOVED * * * List < GenericResource > ds = client . submit ( query ) ;
* * * REMOVED * * * for ( GenericResource a : ds ) * * * REMOVED * * *
* * * REMOVED * * * out . add ( this . convertAlgo ( a ) ) ;
* * * REMOVED * * * * * * REMOVED * * *
* * * REMOVED * * * return out ;
* * * REMOVED * * * * * * REMOVED * * *
2017-05-11 12:58:38 +02:00
2017-09-07 18:46:26 +02:00
* * * REMOVED * * * private Algorithm convertAlgo ( GenericResource a ) * * * REMOVED * * *
* * * REMOVED * * * Algorithm out = new Algorithm ( ) ;
2017-05-11 12:58:38 +02:00
* * * REMOVED * * *
2017-09-07 18:46:26 +02:00
* * * REMOVED * * * * * * REMOVED * * * out . setId ( a . profile ( ) . body ( ) . getElementsByTagName ( " id " ) . item ( 0 ) . getTextContent ( ) ) ;
* * * REMOVED * * * out . setAlgorithmType ( a . profile ( ) . body ( ) . getElementsByTagName ( " algorithmType " ) . item ( 0 ) . getTextContent ( ) ) ;
* * * REMOVED * * * out . setCategory ( a . profile ( ) . body ( ) . getElementsByTagName ( " category " ) . item ( 0 ) . getTextContent ( ) ) ;
* * * REMOVED * * * out . setClazz ( a . profile ( ) . body ( ) . getElementsByTagName ( " clazz " ) . item ( 0 ) . getTextContent ( ) ) ;
* * * REMOVED * * * out . setName ( a . profile ( ) . name ( ) ) ;
* * * REMOVED * * * out . setPackageURL ( a . profile ( ) . body ( ) . getElementsByTagName ( " packageURL " ) . item ( 0 ) . getTextContent ( ) ) ;
* * * REMOVED * * * out . setSkipJava ( a . profile ( ) . body ( ) . getElementsByTagName ( " skipJava " ) . item ( 0 ) . getTextContent ( ) ) ;
* * * REMOVED * * * out . setDescription ( a . profile ( ) . description ( ) ) ;
* * * REMOVED * * *
* * * REMOVED * * * Set < org . gcube . dataanalysis . dataminer . poolmanager . datamodel . Dependency > deps = new HashSet < org . gcube . dataanalysis . dataminer . poolmanager . datamodel . Dependency > ( ) ;
* * * REMOVED * * * for ( int i = 0 ; i < a . profile ( ) . body ( ) . getElementsByTagName ( " dependencies " ) . getLength ( ) ; i + + ) * * * REMOVED * * *
* * * REMOVED * * * org . gcube . dataanalysis . dataminer . poolmanager . datamodel . Dependency d1 = new org . gcube . dataanalysis . dataminer . poolmanager . datamodel . Dependency ( ) ;
* * * REMOVED * * * d1 . setName ( a . profile ( ) . body ( ) . getElementsByTagName ( " dependencies " ) . item ( i ) . getTextContent ( ) ) ;
* * * REMOVED * * * deps . add ( d1 ) ;
* * * REMOVED * * * * * * REMOVED * * *
* * * REMOVED * * * out . setDependencies ( deps ) ;
* * * REMOVED * * * return out ;
* * * REMOVED * * * * * * REMOVED * * *
2017-05-11 12:58:38 +02:00
2017-10-30 22:38:11 +01:00
2017-05-11 12:58:38 +02:00
2017-04-19 17:01:13 +02:00
public static void main ( String [ ] args ) throws IOException , SVNException * * * REMOVED * * *
ISClient a = new ISClient ( ) ;
ScopeProvider . instance . set ( " /gcube/devNext/NextNext " ) ;
* * * REMOVED * * * System . out . println ( a . getHProxy ( ) ) ;
* * * REMOVED * * * System . out . println ( a . MapCluster ( ) ) ;
* * * REMOVED * * * System . out . println ( a . listDataMinersByCluster ( ) ) ;
* * * REMOVED * * * System . out . println ( a . listDataMinersByCluster ( ) ) ;
* * * REMOVED * * * List < Dependency > list = new LinkedList < Dependency > ( ) ;
* * * REMOVED * * * Dependency aa = new Dependency ( ) ;
* * * REMOVED * * * aa . setName ( " testnunzio " ) ;
* * * REMOVED * * * aa . setType ( " cran: " ) ;
* * * REMOVED * * * list . add ( aa ) ;
2017-04-04 19:32:53 +02:00
2017-04-19 17:01:13 +02:00
* * * REMOVED * * * a . checkSVNdep ( ) ;
2017-10-30 22:38:11 +01:00
* * * REMOVED * * * System . out . println ( a . getDataminer ( " dataminer1-d-d4s.d4science.org " ) . getDomain ( ) ) ;
2017-04-19 17:01:13 +02:00
* * * REMOVED * * * System . out . println ( a . listDataminersInVRE ( ) ) ;
2017-03-03 19:10:02 +01:00
* * * REMOVED * * *
* * * REMOVED * * *