dataminer-pool-manager/src/main/java/org/gcube/dataanalysis/dataminer/poolmanager/util/CheckMethod.java

168 lines
5.4 KiB
Java

package org.gcube.dataanalysis.dataminer.poolmanager.util;
***REMOVED***
import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
***REMOVED***
***REMOVED***
import java.util.Vector;
import javax.jms.ServerSession;
import org.gcube.dataanalysis.dataminer.poolmanager.datamodel.Algorithm;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException;
public class CheckMethod {
public CheckMethod() {
***REMOVED***
public boolean checkMethod(String machine, String token) throws Exception {
try {
System.out.println("Machine: " + machine);
String getCapabilitesRequest = new String();
String getCapabilitesResponse = new String();
System.out.println(" Token: " + token);
String request = "http:***REMOVED***" + machine
+ "/wps/WebProcessingService?Request=GetCapabilities&Service=WPS&gcube-token=" + token;
String response = machine + "___" + token + ".xml";
getCapabilitesRequest = request;
getCapabilitesResponse = response;
String baseDescriptionRequest = "http:***REMOVED***" + machine
+ "/wps/WebProcessingService?Request=DescribeProcess&Service=WPS&Version=1.0.0" + "&gcube-token="
+ token + "&Identifier=";
URL requestURL = new URL(request);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(requestURL.openStream()));
FileWriter fileWriter = new FileWriter(response);
String line;
boolean flag = true;
while (flag && (line = bufferedReader.readLine()) != null) {
fileWriter.write(line);
fileWriter.write(System.lineSeparator());
if (line.contains("ows:Identifier")) {
String operatorName = line.substring(line.indexOf(">") + 1);
operatorName = operatorName.substring(0, operatorName.indexOf("<"));
System.out.println(" " + operatorName);
URL innerRequestURL = new URL(baseDescriptionRequest + operatorName);
BufferedReader innerBufferedReader = new BufferedReader(
new InputStreamReader(innerRequestURL.openStream()));
String innerLine = innerBufferedReader.readLine();
boolean innerFlag = true;
while (innerFlag && (innerLine = innerBufferedReader.readLine()) != null) {
if (innerLine.contains("ows:Abstract")) {
String operatorDescription = innerLine.substring(innerLine.indexOf(">") + 1);
operatorDescription = operatorDescription.substring(0, operatorDescription.indexOf("<"));
System.out.println(" " + operatorDescription);
innerFlag = false;
***REMOVED*** else if (innerLine.contains("ows:ExceptionText")) {
System.out.println(" " + "error retrieving operator description");
innerFlag = false;
flag = false;
***REMOVED*** else
innerLine = innerBufferedReader.readLine();
***REMOVED***
***REMOVED***
***REMOVED***
fileWriter.close();
***REMOVED*** catch (Exception a) {
a.getMessage();
return false;
***REMOVED***
return true;
***REMOVED***
public boolean algoExists(Algorithm a) throws Exception{
File file = new File("/home/gcube/wps_algorithms/algorithms/"+a.getName()+".jar");
File file2 = new File("/home/gcube/wps_algorithms/algorithms/"+a.getName()+"_interface.jar");
System.out.println("First file is located to: "+file.getPath());
System.out.println("Second file is located to: "+file2.getPath());
if ((this.doesExist(file.getPath())) && (this.doesExist(file2.getPath()))){
return true;
***REMOVED***
else
System.out.println("Algorithm "+a.getName()+".jar"+ " and "+a.getName()+"_interface.jar files are not present at the expected path");
return false;
***REMOVED***
public boolean doesExist(String path) throws Exception {
JSch jsch = new JSch();
Session session = null;
Channel channel = null;
ChannelSftp c = null;
boolean success = false;
jsch.setKnownHosts("~/.ssh/known_hosts");
String privateKey = "~/.ssh/id_rsa";
jsch.addIdentity(privateKey);
System.out.println("Private Key Added.");
session = jsch.getSession("root", "dataminer1-devnext.d4science.org");
System.out.println("session created.");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
System.out.println("shell channel connected....");
c = (ChannelSftp) channel;
SftpATTRS is = null;
System.out.println(path);
try {
is = c.lstat(path);
success = true;
***REMOVED*** catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
***REMOVED*** file doesn't exist
success = false;
***REMOVED***
***REMOVED***success = true; ***REMOVED*** something else went wrong
***REMOVED***
c.disconnect();
session.disconnect();
return success;
***REMOVED***
public static void main(String[] args) throws Exception {
***REMOVED*** ServiceConfiguration a = new ServiceConfiguration();
***REMOVED*** System.out.println(a.getStagingHost());
CheckMethod a = new CheckMethod();
***REMOVED*** if (a.checkMethod("dataminer1-devnext.d4science.org", "708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548")){
***REMOVED*** System.out.println("ciao");***REMOVED***
***REMOVED***
if (a.doesExist("/home/gcube/wps_algorithms/algorithms/XMEANS_interface.jar")){
System.out.println("ciao");
***REMOVED***
***REMOVED***
***REMOVED***