Examples of StandardOutReader


Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

                details.setJobDescription(execuable);

//                GFacUtils.updateJobStatus(details, JobState.SUBMITTED);
                RawCommandInfo rawCommandInfo = new RawCommandInfo("/bin/chmod 755 " + execuable + "; " + execuable);

                StandardOutReader jobIDReaderCommandOutput = new StandardOutReader();

                CommandExecutor.executeCommand(rawCommandInfo, cluster.getSession(), jobIDReaderCommandOutput);
                String stdOutputString = getOutputifAvailable(jobIDReaderCommandOutput, "Error submitting job to resource");

                log.info("stdout=" + stdOutputString);
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

        // exec 'scp -t rfile' remotely
        String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + rFile;
        Channel channel = session.openChannel("exec");

        StandardOutReader stdOutReader = new StandardOutReader();
        ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
        ((ChannelExec) channel).setCommand(command);

        // get I/O streams for remote scp
        OutputStream out = channel.getOutputStream();
        InputStream in = channel.getInputStream();

        channel.connect();

        if (checkAck(in) != 0) {
            String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }

        File _lfile = new File(lFile);

        if (ptimestamp) {
            command = "T " + (_lfile.lastModified() / 1000) + " 0";
            // The access time should be sent here,
            // but it is not accessible with JavaAPI ;-<
            command += (" " + (_lfile.lastModified() / 1000) + " 0\n");
            out.write(command.getBytes());
            out.flush();
            if (checkAck(in) != 0) {
                 String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
            }
        }

        // send "C0644 filesize filename", where filename should not include '/'
        long filesize = _lfile.length();
        command = "C0644 " + filesize + " ";
        if (lFile.lastIndexOf('/') > 0) {
            command += lFile.substring(lFile.lastIndexOf('/') + 1);
        } else {
            command += lFile;
        }
        command += "\n";
        out.write(command.getBytes());
        out.flush();
        if (checkAck(in) != 0) {
            String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }

        // send a content of lFile
        fis = new FileInputStream(lFile);
        byte[] buf = new byte[1024];
        while (true) {
            int len = fis.read(buf, 0, buf.length);
            if (len <= 0) break;
            out.write(buf, 0, len); //out.flush();
        }
        fis.close();
        fis = null;
        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();
        if (checkAck(in) != 0) {
             String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }
        out.close();

        stdOutReader.onOutput(channel);


        if (!stdOutReader.getStdErrorString().equals("")) {
            throw new SSHApiException(stdOutReader.getStdErrorString());
        }
        channel.disconnect();
        session.disconnect();
    }
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

        // exec 'scp -t rfile' remotely
        String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + remoteFile;
        Channel channel = session.openChannel("exec");

        StandardOutReader stdOutReader = new StandardOutReader();
        ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
        ((ChannelExec) channel).setCommand(command);

        // get I/O streams for remote scp
        OutputStream out = channel.getOutputStream();
        InputStream in = channel.getInputStream();

        channel.connect();

        if (checkAck(in) != 0) {
             String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }

        File _lfile = new File(localFile);

        if (ptimestamp) {
            command = "T " + (_lfile.lastModified() / 1000) + " 0";
            // The access time should be sent here,
            // but it is not accessible with JavaAPI ;-<
            command += (" " + (_lfile.lastModified() / 1000) + " 0\n");
            out.write(command.getBytes());
            out.flush();
            if (checkAck(in) != 0) {
                 String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
            }
        }

        // send "C0644 filesize filename", where filename should not include '/'
        long filesize = _lfile.length();
        command = "C0644 " + filesize + " ";
        if (localFile.lastIndexOf('/') > 0) {
            command += localFile.substring(localFile.lastIndexOf('/') + 1);
        } else {
            command += localFile;
        }
        command += "\n";
        out.write(command.getBytes());
        out.flush();
        if (checkAck(in) != 0) {
            String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }

        // send a content of lFile
        fis = new FileInputStream(localFile);
        byte[] buf = new byte[1024];
        while (true) {
            int len = fis.read(buf, 0, buf.length);
            if (len <= 0) break;
            out.write(buf, 0, len); //out.flush();
        }
        fis.close();
        fis = null;
        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();
        if (checkAck(in) != 0) {
            String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }
        out.close();
        stdOutReader.onOutput(channel);


        channel.disconnect();
        if (!stdOutReader.getStdErrorString().equals("")) {
            throw new SSHApiException(stdOutReader.getStdErrorString());
        }
        //since remote file is always a file  we just return the file
        return remoteFile;
    }
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

            // exec 'scp -f remotefile' remotely
            String command = "scp -f " + remoteFile;
            Channel channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand(command);

            StandardOutReader stdOutReader = new StandardOutReader();
            ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
            // get I/O streams for remote scp
            OutputStream out = channel.getOutputStream();
            InputStream in = channel.getInputStream();

            channel.connect();

            byte[] buf = new byte[1024];

            // send '\0'
            buf[0] = 0;
            out.write(buf, 0, 1);
            out.flush();

            while (true) {
                int c = checkAck(in);
                if (c != 'C') {
                    break;
                }

                // read '0644 '
                in.read(buf, 0, 5);

                long filesize = 0L;
                while (true) {
                    if (in.read(buf, 0, 1) < 0) {
                        // error
                        break;
                    }
                    if (buf[0] == ' ') break;
                    filesize = filesize * 10L + (long) (buf[0] - '0');
                }

                String file = null;
                for (int i = 0; ; i++) {
                    in.read(buf, i, 1);
                    if (buf[i] == (byte) 0x0a) {
                        file = new String(buf, 0, i);
                        break;
                    }
                }

                //System.out.println("filesize="+filesize+", file="+file);

                // send '\0'
                buf[0] = 0;
                out.write(buf, 0, 1);
                out.flush();

                // read a content of lfile
                fos = new FileOutputStream(prefix == null ? localFile : prefix + file);
                int foo;
                while (true) {
                    if (buf.length < filesize) foo = buf.length;
                    else foo = (int) filesize;
                    foo = in.read(buf, 0, foo);
                    if (foo < 0) {
                        // error
                        break;
                    }
                    fos.write(buf, 0, foo);
                    filesize -= foo;
                    if (filesize == 0L) break;
                }
                fos.close();
                fos = null;

                if (checkAck(in) != 0) {
                    String error = "Error transfering the file content";
                    log.error(error);
                    throw new SSHApiException(error);
                }

                // send '\0'
                buf[0] = 0;
                out.write(buf, 0, 1);
                out.flush();
            }
            stdOutReader.onOutput(channel);
            if (!stdOutReader.getStdErrorString().equals("")) {
            throw new SSHApiException(stdOutReader.getStdErrorString());
        }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

            if (new File(localFile).isDirectory()) {
                prefix = localFile + File.separator;
            }

            // exec 'scp -f remotefile' remotely
            StandardOutReader stdOutReader = new StandardOutReader();
            String command = "scp -f " + remoteFile;
            Channel channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand(command);
            ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
            // get I/O streams for remote scp
            OutputStream out = channel.getOutputStream();
            InputStream in = channel.getInputStream();

            channel.connect();

            byte[] buf = new byte[1024];

            // send '\0'
            buf[0] = 0;
            out.write(buf, 0, 1);
            out.flush();

            while (true) {
                int c = checkAck(in);
                if (c != 'C') {
                    break;
                }

                // read '0644 '
                in.read(buf, 0, 5);

                long filesize = 0L;
                while (true) {
                    if (in.read(buf, 0, 1) < 0) {
                        // error
                        break;
                    }
                    if (buf[0] == ' ') break;
                    filesize = filesize * 10L + (long) (buf[0] - '0');
                }

                String file = null;
                for (int i = 0; ; i++) {
                    in.read(buf, i, 1);
                    if (buf[i] == (byte) 0x0a) {
                        file = new String(buf, 0, i);
                        break;
                    }
                }

                //System.out.println("filesize="+filesize+", file="+file);

                // send '\0'
                buf[0] = 0;
                out.write(buf, 0, 1);
                out.flush();

                // read a content of lfile
                fos = new FileOutputStream(prefix == null ? localFile : prefix + file);
                int foo;
                while (true) {
                    if (buf.length < filesize) foo = buf.length;
                    else foo = (int) filesize;
                    foo = in.read(buf, 0, foo);
                    if (foo < 0) {
                        // error
                        break;
                    }
                    fos.write(buf, 0, foo);
                    filesize -= foo;
                    if (filesize == 0L) break;
                }
                fos.close();
                fos = null;

                if (checkAck(in) != 0) {
                    String error = "Error transfering the file content";
                    log.error(error);
                    throw new SSHApiException(error);
                }

                // send '\0'
                buf[0] = 0;
                out.write(buf, 0, 1);
                out.flush();
            }

            session.disconnect();

            stdOutReader.onOutput(channel);
            if (!stdOutReader.getStdErrorString().equals("")) {
                throw new SSHApiException(stdOutReader.getStdErrorString());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            try {
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

            // exec 'scp -f remotefile' remotely
            String command = "scp -3 " + remoteFileSource + " " + remoteFileTarget;
            Channel channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand(command);

            StandardOutReader stdOutReader = new StandardOutReader();
            ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
            // get I/O streams for remote scp
            OutputStream out = channel.getOutputStream();
            InputStream in = channel.getInputStream();

            channel.connect();

            byte[] buf = new byte[1024];

            // send '\0'
            buf[0] = 0;
            out.write(buf, 0, 1);
            out.flush();

            while (true) {
                int c = checkAck(in);
                if (c != 'C') {
                    break;
                }

                // read '0644 '
                in.read(buf, 0, 5);

                long filesize = 0L;
                while (true) {
                    if (in.read(buf, 0, 1) < 0) {
                        // error
                        break;
                    }
                    if (buf[0] == ' ') break;
                    filesize = filesize * 10L + (long) (buf[0] - '0');
                }

//                String file = null;
//                for (int i = 0; ; i++) {
//                    in.read(buf, i, 1);
//                    if (buf[i] == (byte) 0x0a) {
//                        file = new String(buf, 0, i);
//                        break;
//                    }
//                }

                //System.out.println("filesize="+filesize+", file="+file);

                // send '\0'
                buf[0] = 0;
                out.write(buf, 0, 1);
                out.flush();
               
                while (true) {
                    int len = in.read(buf, 0, buf.length);
                    if (len <= 0) break;
                    out.write(buf, 0, len);
                }
//                // read a content of lfile
//                fos = new FileOutputStream(prefix == null ? localFile : prefix + file);
//                int foo;
//                while (true) {
//                    if (buf.length < filesize) foo = buf.length;
//                    else foo = (int) filesize;
//                    foo = in.read(buf, 0, foo);
//                    if (foo < 0) {
//                        // error
//                        break;
//                    }
//                    fos.write(buf, 0, foo);
//                    filesize -= foo;
//                    if (filesize == 0L) break;
//                }
//                fos.close();
//                fos = null;

                if (checkAck(in) != 0) {
                    String error = "Error transfering the file content";
                    log.error(error);
                    throw new SSHApiException(error);
                }

                // send '\0'
                buf[0] = 0;
                out.write(buf, 0, 1);
                out.flush();
            }
            stdOutReader.onOutput(channel);
            if (!stdOutReader.getStdErrorString().equals("")) {
            throw new SSHApiException(stdOutReader.getStdErrorString());
        }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

    public static void makeDirectory(String path, Session session) throws IOException, JSchException, SSHApiException {

        // exec 'scp -t rfile' remotely
        String command = "mkdir -p " + path;
        Channel channel = session.openChannel("exec");
        StandardOutReader stdOutReader = new StandardOutReader();

        ((ChannelExec) channel).setCommand(command);


        ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
        try {
            channel.connect();
        } catch (JSchException e) {

            channel.disconnect();
            session.disconnect();

            throw new SSHApiException("Unable to retrieve command output. Command - " + command +
                    " on server - " + session.getHost() + ":" + session.getPort() +
                    " connecting user name - "
                    + session.getUserName(), e);
        }
        stdOutReader.onOutput(channel);
        if (!stdOutReader.getStdErrorString().equals("")) {
            throw new SSHApiException(stdOutReader.getStdErrorString());
        }

        channel.disconnect();
    }
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

    public static List<String> listDirectory(String path, Session session) throws IOException, JSchException, SSHApiException {

        // exec 'scp -t rfile' remotely
        String command = "ls " + path;
        Channel channel = session.openChannel("exec");
        StandardOutReader stdOutReader = new StandardOutReader();

        ((ChannelExec) channel).setCommand(command);


        ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
        try {
            channel.connect();
        } catch (JSchException e) {

            channel.disconnect();
            session.disconnect();

            throw new SSHApiException("Unable to retrieve command output. Command - " + command +
                    " on server - " + session.getHost() + ":" + session.getPort() +
                    " connecting user name - "
                    + session.getUserName(), e);
        }
        stdOutReader.onOutput(channel);
        stdOutReader.getStdOutputString();
        if (!stdOutReader.getStdErrorString().equals("")) {
            throw new SSHApiException(stdOutReader.getStdErrorString());
        }
        channel.disconnect();
        return Arrays.asList(stdOutReader.getStdOutputString().split("\n"));
    }
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

                details.setJobDescription(execuable);

//                GFacUtils.updateJobStatus(details, JobState.SUBMITTED);
                RawCommandInfo rawCommandInfo = new RawCommandInfo("/bin/chmod 755 " + execuable + "; " + execuable);

                StandardOutReader jobIDReaderCommandOutput = new StandardOutReader();
               
                CommandExecutor.executeCommand(rawCommandInfo, cluster.getSession(), jobIDReaderCommandOutput);
                String stdOutputString = getOutputifAvailable(jobIDReaderCommandOutput, "Error submitting job to resource");

                log.info("stdout=" + stdOutputString);
View Full Code Here

Examples of org.apache.airavata.gsi.ssh.impl.StandardOutReader

        // exec 'scp -t rfile' remotely
        String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + remoteFile;
        Channel channel = session.openChannel("exec");

        StandardOutReader stdOutReader = new StandardOutReader();
        ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError());
        ((ChannelExec) channel).setCommand(command);

        // get I/O streams for remote scp
        OutputStream out = channel.getOutputStream();
        InputStream in = channel.getInputStream();

        channel.connect();

        if (checkAck(in) != 0) {
             String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }

        File _lfile = new File(localFile);

        if (ptimestamp) {
            command = "T " + (_lfile.lastModified() / 1000) + " 0";
            // The access time should be sent here,
            // but it is not accessible with JavaAPI ;-<
            command += (" " + (_lfile.lastModified() / 1000) + " 0\n");
            out.write(command.getBytes());
            out.flush();
            if (checkAck(in) != 0) {
                 String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
            }
        }

        // send "C0644 filesize filename", where filename should not include '/'
        long filesize = _lfile.length();
        command = "C0644 " + filesize + " ";
        if (localFile.lastIndexOf('/') > 0) {
            command += localFile.substring(localFile.lastIndexOf('/') + 1);
        } else {
            command += localFile;
        }
        command += "\n";
        out.write(command.getBytes());
        out.flush();
        if (checkAck(in) != 0) {
            String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }

        // send a content of lFile
        fis = new FileInputStream(localFile);
        byte[] buf = new byte[1024];
        while (true) {
            int len = fis.read(buf, 0, buf.length);
            if (len <= 0) break;
            out.write(buf, 0, len); //out.flush();
        }
        fis.close();
        fis = null;
        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();
        if (checkAck(in) != 0) {
            String error = "Error Reading input Stream";
            log.error(error);
            throw new SSHApiException(error);
        }
        out.close();
        stdOutReader.onOutput(channel);


        channel.disconnect();
        if (!stdOutReader.getStdErrorString().equals("")) {
            throw new SSHApiException(stdOutReader.getStdErrorString());
        }
        //since remote file is always a file  we just return the file
        return remoteFile;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.