250 lines
10 KiB
Java
Executable File
250 lines
10 KiB
Java
Executable File
***REMOVED***
|
|
|
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
|
|
|
***REMOVED***
|
|
import java.io.StringWriter;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
***REMOVED***
|
|
import java.util.Vector;
|
|
|
|
***REMOVED***
|
|
import org.gcube.common.resources.gcore.GenericResource;
|
|
import org.gcube.common.resources.gcore.Resources;
|
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|
***REMOVED***
|
|
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
|
|
***REMOVED***
|
|
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;
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
***REMOVED***
|
|
***REMOVED***
|
|
import org.tmatesoft.svn.core.SVNException;
|
|
|
|
public class ISClient {
|
|
***REMOVED***
|
|
|
|
public ISClient() {
|
|
this.logger = LoggerFactory.getLogger(ISClient.class);
|
|
***REMOVED***
|
|
|
|
|
|
public Host getDataminer(String hostname) {
|
|
Host h = new Host();
|
|
boolean remote2 = true;
|
|
|
|
if (!remote2) {
|
|
h.setName("dataminer1-devnext.d4science.org");
|
|
return h;
|
|
***REMOVED*** else {
|
|
***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);
|
|
***REMOVED***
|
|
return h;
|
|
***REMOVED***
|
|
|
|
|
|
***REMOVED*** return the HProxy hostname in the VRE
|
|
public static String getHProxy() {
|
|
Host h = new Host();
|
|
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
|
query.addCondition("$resource/Profile/Name/text() eq 'DataMiner'");
|
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
|
List<ServiceEndpoint> resources = client.submit(query);
|
|
h.setName(resources.get(0).profile().runtime().hostedOn());
|
|
return h.getName();
|
|
***REMOVED***
|
|
|
|
|
|
public Collection<Host> listDataminersInVRE() {
|
|
|
|
boolean remote = false;
|
|
|
|
if (!remote) {
|
|
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);
|
|
***REMOVED***
|
|
***REMOVED*** else {
|
|
|
|
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) {
|
|
Host h = new Host();
|
|
h.setName(r.profile().runtime().hostedOn());
|
|
out.add(h);
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
|
|
public void updateAlg(Algorithm algo) {
|
|
|
|
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()) {
|
|
return;
|
|
***REMOVED***
|
|
GenericResource a = ds.get(0);
|
|
a.profile().newBody(this.getAlgoBody(algo));
|
|
try {
|
|
scopedPublisher.update(a);
|
|
***REMOVED*** catch (RegistryNotFoundException e) {
|
|
e.printStackTrace();
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
|
|
private String getAlgoBody(Algorithm algo) {
|
|
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*** 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*** publishScopedResource(a, Arrays.asList(new String[] { ScopeProvider.instance.get() ***REMOVED***));
|
|
***REMOVED*** ***REMOVED*** catch (Exception e) {
|
|
***REMOVED*** e.printStackTrace();
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
|
|
|
|
|
|
public void addAlgToIs(Algorithm algo, String token) {
|
|
GenericResource a = new GenericResource();
|
|
a.newProfile().name(algo.getName()).type("StatisticalManagerAlgorithm").description(algo.getDescription());
|
|
a.profile().newBody(this.getAlgoBody(algo));
|
|
try {
|
|
SecurityTokenProvider.instance.set(token);
|
|
publishScopedResource(a, Arrays.asList(new String[] { SecurityTokenProvider.instance.get() ***REMOVED***));
|
|
***REMOVED*** catch (Exception e) {
|
|
e.printStackTrace();
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
public void unPublishScopedResource(GenericResource resource) throws RegistryNotFoundException, Exception {
|
|
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
|
AdvancedScopedPublisher advancedScopedPublisher = new AdvancedScopedPublisher(scopedPublisher);
|
|
String id = resource.id();
|
|
this.logger.info("Trying to remove {***REMOVED*** with ID {***REMOVED*** from {***REMOVED***", resource.getClass().getSimpleName(), id,
|
|
ScopeProvider.instance.get());
|
|
***REMOVED*** scopedPublisher.remove(resource, scopes);
|
|
advancedScopedPublisher.forceRemove(resource);
|
|
this.logger.info("{***REMOVED*** with ID {***REMOVED*** removed successfully", resource.getClass().getSimpleName(), id);
|
|
***REMOVED***
|
|
|
|
public void publishScopedResource(GenericResource a, List<String> scopes)
|
|
throws RegistryNotFoundException, Exception {
|
|
StringWriter stringWriter = new StringWriter();
|
|
Resources.marshal(a, stringWriter);
|
|
|
|
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
|
try {
|
|
this.logger.debug(scopes.toString());
|
|
this.logger.debug(stringWriter.toString());
|
|
scopedPublisher.create(a, scopes);
|
|
***REMOVED*** catch (RegistryNotFoundException e) {
|
|
this.logger.error("Registry not found",e);
|
|
throw e;
|
|
***REMOVED***
|
|
***REMOVED***
|
|
|
|
|
|
***REMOVED*** public Set<Algorithm> getAlgoFromIs() {
|
|
***REMOVED*** ***REMOVED*** TODO Auto-generated method stub
|
|
***REMOVED***
|
|
***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*** out.add(this.convertAlgo(a));
|
|
***REMOVED*** ***REMOVED***
|
|
***REMOVED******REMOVED***
|
|
***REMOVED******REMOVED***
|
|
|
|
|
|
***REMOVED*** private Algorithm convertAlgo(GenericResource a) {
|
|
***REMOVED*** Algorithm out = new Algorithm();
|
|
***REMOVED***
|
|
***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*** 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******REMOVED***
|
|
***REMOVED******REMOVED***
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, SVNException {
|
|
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);
|
|
|
|
***REMOVED*** a.checkSVNdep();
|
|
***REMOVED***System.out.println(a.getDataminer("dataminer1-d-d4s.d4science.org").getDomain());
|
|
***REMOVED*** System.out.println(a.listDataminersInVRE());
|
|
***REMOVED***
|
|
***REMOVED***
|