http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/security/CertificateHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/security/CertificateHelper.java 
b/utils/src/com/cloud/utils/security/CertificateHelper.java
deleted file mode 100644
index d43542f..0000000
--- a/utils/src/com/cloud/utils/security/CertificateHelper.java
+++ /dev/null
@@ -1,166 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.security;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringReader;
-import java.security.Key;
-import java.security.KeyFactory;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.cloud.utils.exception.CloudRuntimeException;
-import org.apache.commons.codec.binary.Base64;
-
-import com.cloud.utils.Ternary;
-import org.bouncycastle.openssl.PEMReader;
-
-public class CertificateHelper {
-    public static byte[] buildAndSaveKeystore(String alias, String cert, 
String privateKey, String storePassword) throws KeyStoreException, 
CertificateException,
-        NoSuchAlgorithmException, InvalidKeySpecException, IOException {
-        KeyStore ks = buildKeystore(alias, cert, privateKey, storePassword);
-
-        ByteArrayOutputStream os = new ByteArrayOutputStream();
-        ks.store(os, storePassword != null ? storePassword.toCharArray() : 
null);
-        os.close();
-        return os.toByteArray();
-    }
-
-    public static byte[] buildAndSaveKeystore(List<Ternary<String, String, 
String>> certs, String storePassword) throws KeyStoreException, 
NoSuchAlgorithmException,
-        CertificateException, IOException, InvalidKeySpecException {
-        KeyStore ks = KeyStore.getInstance("JKS");
-        ks.load(null, storePassword != null ? storePassword.toCharArray() : 
null);
-
-        //name,cert,key
-        for (Ternary<String, String, String> cert : certs) {
-            if (cert.third() == null) {
-                Certificate c = buildCertificate(cert.second());
-                ks.setCertificateEntry(cert.first(), c);
-            } else {
-                Certificate[] c = new Certificate[certs.size()];
-                int i = certs.size();
-                for (Ternary<String, String, String> ct : certs) {
-                    c[i - 1] = buildCertificate(ct.second());
-                    i--;
-                }
-                ks.setKeyEntry(cert.first(), buildPrivateKey(cert.third()), 
storePassword != null ? storePassword.toCharArray() : null, c);
-            }
-        }
-
-        ByteArrayOutputStream os = new ByteArrayOutputStream();
-        ks.store(os, storePassword != null ? storePassword.toCharArray() : 
null);
-        os.close();
-        return os.toByteArray();
-    }
-
-    public static KeyStore loadKeystore(byte[] ksData, String storePassword) 
throws KeyStoreException, CertificateException, NoSuchAlgorithmException, 
IOException {
-        assert (ksData != null);
-        KeyStore ks = KeyStore.getInstance("JKS");
-        ks.load(new ByteArrayInputStream(ksData), storePassword != null ? 
storePassword.toCharArray() : null);
-
-        return ks;
-    }
-
-    public static KeyStore buildKeystore(String alias, String cert, String 
privateKey, String storePassword) throws KeyStoreException, 
CertificateException,
-        NoSuchAlgorithmException, InvalidKeySpecException, IOException {
-
-        KeyStore ks = KeyStore.getInstance("JKS");
-        ks.load(null, storePassword != null ? storePassword.toCharArray() : 
null);
-        Certificate[] certs = new Certificate[1];
-        certs[0] = buildCertificate(cert);
-        ks.setKeyEntry(alias, buildPrivateKey(privateKey), storePassword != 
null ? storePassword.toCharArray() : null, certs);
-        return ks;
-    }
-
-    public static Certificate buildCertificate(String content) throws 
CertificateException {
-        assert (content != null);
-
-        BufferedInputStream bis = new BufferedInputStream(new 
ByteArrayInputStream(content.getBytes()));
-        CertificateFactory cf = CertificateFactory.getInstance("X.509");
-        return cf.generateCertificate(bis);
-    }
-
-    public static Key buildPrivateKey(String base64EncodedKeyContent) throws 
NoSuchAlgorithmException, InvalidKeySpecException, IOException {
-        KeyFactory kf = KeyFactory.getInstance("RSA");
-        PKCS8EncodedKeySpec keysp = new 
PKCS8EncodedKeySpec(Base64.decodeBase64(base64EncodedKeyContent));
-        return kf.generatePrivate(keysp);
-    }
-
-    public static List<Certificate> parseChain(String chain) throws 
IOException {
-
-        List<Certificate> certs = new ArrayList<Certificate>();
-        PEMReader reader = new PEMReader(new StringReader(chain));
-
-        Certificate crt = null;
-
-        while ((crt = (Certificate)reader.readObject()) != null) {
-            if (crt instanceof X509Certificate) {
-                certs.add(crt);
-            }
-        }
-        if (certs.size() == 0)
-            throw new IllegalArgumentException("Unable to decode certificate 
chain");
-
-        return certs;
-    }
-
-    public static String generateFingerPrint(Certificate cert) {
-
-        final char[] HEX = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
'A', 'B', 'C', 'D', 'E', 'F'};
-
-        StringBuilder buffer = new StringBuilder(60);
-        try {
-
-            MessageDigest md = MessageDigest.getInstance("SHA-1");
-            byte[] data = md.digest(cert.getEncoded());
-
-            for (int i = 0; i < data.length; i++) {
-                if (buffer.length() > 0) {
-                    buffer.append(":");
-                }
-
-                buffer.append(HEX[(0xF0 & data[i]) >>> 4]);
-                buffer.append(HEX[0x0F & data[i]]);
-            }
-
-        } catch (CertificateEncodingException e) {
-            throw new CloudRuntimeException("Bad certificate encoding");
-        } catch (NoSuchAlgorithmException e) {
-            throw new CloudRuntimeException("Bad certificate algorithm");
-        }
-
-        return buffer.toString();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java 
b/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java
deleted file mode 100644
index e35a3ea..0000000
--- a/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java
+++ /dev/null
@@ -1,179 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.ssh;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.log4j.Logger;
-
-import com.trilead.ssh2.ChannelCondition;
-import com.trilead.ssh2.Session;
-
-public class SSHCmdHelper {
-    private static final Logger s_logger = 
Logger.getLogger(SSHCmdHelper.class);
-
-    public static com.trilead.ssh2.Connection 
acquireAuthorizedConnection(String ip, String username, String password) {
-        return acquireAuthorizedConnection(ip, 22, username, password);
-    }
-
-    public static com.trilead.ssh2.Connection 
acquireAuthorizedConnection(String ip, int port, String username, String 
password) {
-        com.trilead.ssh2.Connection sshConnection = new 
com.trilead.ssh2.Connection(ip, port);
-        try {
-            sshConnection.connect(null, 60000, 60000);
-            if (!sshConnection.authenticateWithPassword(username, password)) {
-                String[] methods = 
sshConnection.getRemainingAuthMethods(username);
-                StringBuffer mStr = new StringBuffer();
-                for (int i = 0; i < methods.length; i++) {
-                    mStr.append(methods[i]);
-                }
-                s_logger.warn("SSH authorizes failed, support authorized 
methods are " + mStr);
-                return null;
-            }
-            return sshConnection;
-        } catch (IOException e) {
-            s_logger.warn("Get SSH connection failed", e);
-            return null;
-        }
-    }
-
-    public static void releaseSshConnection(com.trilead.ssh2.Connection 
sshConnection) {
-        if (sshConnection != null) {
-            sshConnection.close();
-        }
-    }
-
-    public static boolean sshExecuteCmd(com.trilead.ssh2.Connection 
sshConnection, String cmd, int nTimes) {
-        for (int i = 0; i < nTimes; i++) {
-            try {
-                if (sshExecuteCmdOneShot(sshConnection, cmd))
-                    return true;
-            } catch (SshException e) {
-                continue;
-            }
-        }
-        return false;
-    }
-
-    public static int sshExecuteCmdWithExitCode(com.trilead.ssh2.Connection 
sshConnection, String cmd) {
-        return sshExecuteCmdWithExitCode(sshConnection, cmd, 3);
-    }
-
-    public static int sshExecuteCmdWithExitCode(com.trilead.ssh2.Connection 
sshConnection, String cmd, int nTimes) {
-        for (int i = 0; i < nTimes; i++) {
-            try {
-                return sshExecuteCmdOneShotWithExitCode(sshConnection, cmd);
-            } catch (SshException e) {
-                continue;
-            }
-        }
-        return -1;
-    }
-
-    public static boolean sshExecuteCmd(com.trilead.ssh2.Connection 
sshConnection, String cmd) {
-        return sshExecuteCmd(sshConnection, cmd, 3);
-    }
-
-    public static int 
sshExecuteCmdOneShotWithExitCode(com.trilead.ssh2.Connection sshConnection, 
String cmd) throws SshException {
-        s_logger.debug("Executing cmd: " + cmd);
-        Session sshSession = null;
-        try {
-            sshSession = sshConnection.openSession();
-            // There is a bug in Trilead library, wait a second before
-            // starting a shell and executing commands, from 
http://spci.st.ewi.tudelft.nl/chiron/xref/nl/tudelft/swerl/util/SSHConnection.html
-            Thread.sleep(1000);
-
-            if (sshSession == null) {
-                throw new SshException("Cannot open ssh session");
-            }
-
-            sshSession.execCommand(cmd);
-
-            InputStream stdout = sshSession.getStdout();
-            InputStream stderr = sshSession.getStderr();
-
-            byte[] buffer = new byte[8192];
-            StringBuffer sbResult = new StringBuffer();
-
-            int currentReadBytes = 0;
-            while (true) {
-                if (stdout == null || stderr == null) {
-                    throw new SshException("stdout or stderr of ssh session is 
null");
-                }
-                if ((stdout.available() == 0) && (stderr.available() == 0)) {
-                    int conditions = 
sshSession.waitForCondition(ChannelCondition.STDOUT_DATA
-                                | ChannelCondition.STDERR_DATA | 
ChannelCondition.EOF | ChannelCondition.EXIT_STATUS,
-                                120000);
-
-                    if ((conditions & ChannelCondition.TIMEOUT) != 0) {
-                        String msg = "Timed out in waiting SSH execution 
result";
-                        s_logger.error(msg);
-                        throw new Exception(msg);
-                    }
-
-                    if ((conditions & ChannelCondition.EXIT_STATUS) != 0) {
-                        if ((conditions & (ChannelCondition.STDOUT_DATA | 
ChannelCondition.STDERR_DATA)) == 0) {
-                            break;
-                        }
-                    }
-
-                    if ((conditions & ChannelCondition.EOF) != 0) {
-                        if ((conditions & (ChannelCondition.STDOUT_DATA | 
ChannelCondition.STDERR_DATA)) == 0) {
-                            break;
-                        }
-                    }
-                }
-
-                while (stdout.available() > 0) {
-                    currentReadBytes = stdout.read(buffer);
-                    sbResult.append(new String(buffer, 0, currentReadBytes));
-                }
-
-                while (stderr.available() > 0) {
-                    currentReadBytes = stderr.read(buffer);
-                    sbResult.append(new String(buffer, 0, currentReadBytes));
-                }
-            }
-
-            String result = sbResult.toString();
-            if (result != null && !result.isEmpty())
-                s_logger.debug(cmd + " output:" + result);
-            // exit status delivery might get delayed
-            for(int i = 0 ; i<10 ; i++ ) {
-                Integer status = sshSession.getExitStatus();
-                if( status != null ) {
-                    return status;
-                }
-                Thread.sleep(100);
-            }
-            return -1;
-        } catch (Exception e) {
-            s_logger.debug("Ssh executed failed", e);
-            throw new SshException("Ssh executed failed " + e.getMessage());
-        } finally {
-            if (sshSession != null)
-                sshSession.close();
-        }
-    }
-
-    public static boolean sshExecuteCmdOneShot(com.trilead.ssh2.Connection 
sshConnection, String cmd) throws SshException {
-        return sshExecuteCmdOneShotWithExitCode(sshConnection, cmd) == 0;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java 
b/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java
deleted file mode 100644
index 39db5c4..0000000
--- a/utils/src/com/cloud/utils/ssh/SSHKeysHelper.java
+++ /dev/null
@@ -1,115 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.ssh;
-
-import java.io.ByteArrayOutputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import org.apache.commons.codec.binary.Base64;
-
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.KeyPair;
-
-public class SSHKeysHelper {
-
-    private KeyPair keyPair;
-    private static final char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', 
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
-    private static String toHexString(byte[] b) {
-        StringBuffer sb = new StringBuffer();
-        for (int i = 0; i < b.length; i++) {
-            sb.append(hexChars[(b[i] >> 4) & 0x0f]);
-            sb.append(hexChars[(b[i]) & 0x0f]);
-        }
-        return sb.toString();
-    }
-
-    public SSHKeysHelper() {
-        try {
-            keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.RSA);
-        } catch (JSchException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public String getPublicKeyFingerPrint() {
-        return getPublicKeyFingerprint(getPublicKey());
-    }
-
-    public static String getPublicKeyFingerprint(String publicKey) {
-        String key[] = publicKey.split(" ");
-        if (key.length < 2) {
-            throw new RuntimeException("Incorrect public key is passed in");
-        }
-        byte[] keyBytes = Base64.decodeBase64(key[1]);
-
-        MessageDigest md5 = null;
-        try {
-            md5 = MessageDigest.getInstance("MD5");
-        } catch (NoSuchAlgorithmException e) {
-            e.printStackTrace();
-        }
-
-        String rString = "";
-        String sumString = "";
-        if (md5 != null) {
-            sumString = toHexString(md5.digest(keyBytes));
-        }
-
-        for (int i = 2; i <= sumString.length(); i += 2) {
-            rString += sumString.substring(i - 2, i);
-            if (i != sumString.length())
-                rString += ":";
-        }
-
-        return rString;
-    }
-
-    public static String getPublicKeyFromKeyMaterial(String keyMaterial) {
-        if (!keyMaterial.contains(" "))
-            keyMaterial = new 
String(Base64.decodeBase64(keyMaterial.getBytes()));
-
-        if ((!keyMaterial.startsWith("ssh-rsa") && 
!keyMaterial.startsWith("ssh-dss")) || !keyMaterial.contains(" "))
-            return null;
-
-        String[] key = keyMaterial.split(" ");
-        if (key.length < 2)
-            return null;
-
-        return key[0].concat(" ").concat(key[1]);
-    }
-
-    public String getPublicKey() {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        keyPair.writePublicKey(baos, "");
-
-        return baos.toString();
-    }
-
-    public String getPrivateKey() {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        keyPair.writePrivateKey(baos);
-
-        return baos.toString();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/ssh/SshException.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ssh/SshException.java 
b/utils/src/com/cloud/utils/ssh/SshException.java
deleted file mode 100644
index a9d9ed8..0000000
--- a/utils/src/com/cloud/utils/ssh/SshException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.ssh;
-
-import com.cloud.utils.SerialVersionUID;
-
-public class SshException extends Exception {
-    private static final long serialVersionUID = SerialVersionUID.sshException;
-
-    public SshException(String msg) {
-        super(msg);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/ssh/SshHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ssh/SshHelper.java 
b/utils/src/com/cloud/utils/ssh/SshHelper.java
deleted file mode 100644
index 3aac427..0000000
--- a/utils/src/com/cloud/utils/ssh/SshHelper.java
+++ /dev/null
@@ -1,209 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.ssh;
-
-import java.io.File;
-import java.io.InputStream;
-
-import org.apache.log4j.Logger;
-
-import com.trilead.ssh2.ChannelCondition;
-
-import com.cloud.utils.Pair;
-
-public class SshHelper {
-    private static final int DEFAULT_CONNECT_TIMEOUT = 60000;
-    private static final int DEFAULT_KEX_TIMEOUT = 60000;
-
-    private static final Logger s_logger = Logger.getLogger(SshHelper.class);
-
-    public static Pair<Boolean, String> sshExecute(String host, int port, 
String user, File pemKeyFile, String password, String command) throws Exception 
{
-
-        return sshExecute(host, port, user, pemKeyFile, password, command, 
60000, 60000, 120000);
-    }
-
-    public static void scpTo(String host, int port, String user, File 
pemKeyFile, String password, String remoteTargetDirectory, String localFile, 
String fileMode)
-        throws Exception {
-
-        scpTo(host, port, user, pemKeyFile, password, remoteTargetDirectory, 
localFile, fileMode, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT);
-    }
-
-    public static void scpTo(String host, int port, String user, File 
pemKeyFile, String password, String remoteTargetDirectory, byte[] data, String 
remoteFileName,
-        String fileMode) throws Exception {
-
-        scpTo(host, port, user, pemKeyFile, password, remoteTargetDirectory, 
data, remoteFileName, fileMode, DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT);
-    }
-
-    public static void scpTo(String host, int port, String user, File 
pemKeyFile, String password, String remoteTargetDirectory, String localFile, 
String fileMode,
-        int connectTimeoutInMs, int kexTimeoutInMs) throws Exception {
-
-        com.trilead.ssh2.Connection conn = null;
-        com.trilead.ssh2.SCPClient scpClient = null;
-
-        try {
-            conn = new com.trilead.ssh2.Connection(host, port);
-            conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
-
-            if (pemKeyFile == null) {
-                if (!conn.authenticateWithPassword(user, password)) {
-                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
-                    s_logger.error(msg);
-                    throw new Exception(msg);
-                }
-            } else {
-                if (!conn.authenticateWithPublicKey(user, pemKeyFile, 
password)) {
-                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
-                    s_logger.error(msg);
-                    throw new Exception(msg);
-                }
-            }
-
-            scpClient = conn.createSCPClient();
-
-            if (fileMode != null)
-                scpClient.put(localFile, remoteTargetDirectory, fileMode);
-            else
-                scpClient.put(localFile, remoteTargetDirectory);
-        } finally {
-            if (conn != null)
-                conn.close();
-        }
-    }
-
-    public static void scpTo(String host, int port, String user, File 
pemKeyFile, String password, String remoteTargetDirectory, byte[] data, String 
remoteFileName,
-        String fileMode, int connectTimeoutInMs, int kexTimeoutInMs) throws 
Exception {
-
-        com.trilead.ssh2.Connection conn = null;
-        com.trilead.ssh2.SCPClient scpClient = null;
-
-        try {
-            conn = new com.trilead.ssh2.Connection(host, port);
-            conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
-
-            if (pemKeyFile == null) {
-                if (!conn.authenticateWithPassword(user, password)) {
-                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
-                    s_logger.error(msg);
-                    throw new Exception(msg);
-                }
-            } else {
-                if (!conn.authenticateWithPublicKey(user, pemKeyFile, 
password)) {
-                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
-                    s_logger.error(msg);
-                    throw new Exception(msg);
-                }
-            }
-
-            scpClient = conn.createSCPClient();
-            if (fileMode != null)
-                scpClient.put(data, remoteFileName, remoteTargetDirectory, 
fileMode);
-            else
-                scpClient.put(data, remoteFileName, remoteTargetDirectory);
-        } finally {
-            if (conn != null)
-                conn.close();
-        }
-    }
-
-    public static Pair<Boolean, String> sshExecute(String host, int port, 
String user, File pemKeyFile, String password, String command, int 
connectTimeoutInMs,
-        int kexTimeoutInMs, int waitResultTimeoutInMs) throws Exception {
-
-        com.trilead.ssh2.Connection conn = null;
-        com.trilead.ssh2.Session sess = null;
-        try {
-            conn = new com.trilead.ssh2.Connection(host, port);
-            conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
-
-            if (pemKeyFile == null) {
-                if (!conn.authenticateWithPassword(user, password)) {
-                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
-                    s_logger.error(msg);
-                    throw new Exception(msg);
-                }
-            } else {
-                if (!conn.authenticateWithPublicKey(user, pemKeyFile, 
password)) {
-                    String msg = "Failed to authentication SSH user " + user + 
" on host " + host;
-                    s_logger.error(msg);
-                    throw new Exception(msg);
-                }
-            }
-            sess = conn.openSession();
-
-            sess.execCommand(command);
-
-            InputStream stdout = sess.getStdout();
-            InputStream stderr = sess.getStderr();
-
-            byte[] buffer = new byte[8192];
-            StringBuffer sbResult = new StringBuffer();
-
-            int currentReadBytes = 0;
-            while (true) {
-                if ((stdout.available() == 0) && (stderr.available() == 0)) {
-                    int conditions =
-                        sess.waitForCondition(ChannelCondition.STDOUT_DATA | 
ChannelCondition.STDERR_DATA | ChannelCondition.EOF | 
ChannelCondition.EXIT_STATUS,
-                            waitResultTimeoutInMs);
-
-                    if ((conditions & ChannelCondition.TIMEOUT) != 0) {
-                        String msg = "Timed out in waiting SSH execution 
result";
-                        s_logger.error(msg);
-                        throw new Exception(msg);
-                    }
-
-                    if ((conditions & ChannelCondition.EXIT_STATUS) != 0) {
-                        if ((conditions & (ChannelCondition.STDOUT_DATA | 
ChannelCondition.STDERR_DATA)) == 0) {
-                            break;
-                        }
-                    }
-                }
-
-                while (stdout.available() > 0) {
-                    currentReadBytes = stdout.read(buffer);
-                    sbResult.append(new String(buffer, 0, currentReadBytes));
-                }
-
-                while (stderr.available() > 0) {
-                    currentReadBytes = stderr.read(buffer);
-                    sbResult.append(new String(buffer, 0, currentReadBytes));
-                }
-            }
-
-            String result = sbResult.toString();
-
-            if (sess.getExitStatus() == null) {
-                //Exit status is NOT available. Returning failure result.
-                return new Pair<Boolean, String>(false, result);
-            }
-
-            if (sess.getExitStatus() != null && 
sess.getExitStatus().intValue() != 0) {
-                s_logger.error("SSH execution of command " + command + " has 
an error status code in return. result output: " + result);
-                return new Pair<Boolean, String>(false, result);
-            }
-
-            return new Pair<Boolean, String>(true, result);
-        } finally {
-            if (sess != null)
-                sess.close();
-
-            if (conn != null)
-                conn.close();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/storage/encoding/DecodedDataObject.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/storage/encoding/DecodedDataObject.java 
b/utils/src/com/cloud/utils/storage/encoding/DecodedDataObject.java
deleted file mode 100644
index 56be699..0000000
--- a/utils/src/com/cloud/utils/storage/encoding/DecodedDataObject.java
+++ /dev/null
@@ -1,56 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.storage.encoding;
-
-public class DecodedDataObject {
-    private String objType;
-    private Long size;
-    private String name;
-    private String path;
-    private DecodedDataStore store;
-
-    public DecodedDataObject(String objType, Long size, String name, String 
path, DecodedDataStore store) {
-        this.objType = objType;
-        this.size = size;
-        this.name = name;
-        this.path = path;
-        this.store = store;
-    }
-
-    public String getObjType() {
-        return objType;
-    }
-
-    public Long getSize() {
-        return size;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public String getPath() {
-        return path;
-    }
-
-    public DecodedDataStore getStore() {
-        return store;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/storage/encoding/DecodedDataStore.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/storage/encoding/DecodedDataStore.java 
b/utils/src/com/cloud/utils/storage/encoding/DecodedDataStore.java
deleted file mode 100644
index ac8af8b..0000000
--- a/utils/src/com/cloud/utils/storage/encoding/DecodedDataStore.java
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.storage.encoding;
-
-public class DecodedDataStore {
-    private final String role;
-    private final String uuid;
-    private final String providerName;
-    private final String scheme;
-    private final String url;
-    private final String server;
-    private final String path;
-
-    public DecodedDataStore(String role, String uuid, String providerName, 
String scheme, String url, String server, String path) {
-        this.role = role;
-        this.uuid = uuid;
-        this.providerName = providerName;
-        this.scheme = scheme;
-        this.url = url;
-        this.server = server;
-        this.path = path;
-    }
-
-    public String getRole() {
-        return role;
-    }
-
-    public String getUuid() {
-        return uuid;
-    }
-
-    public String getProviderName() {
-        return providerName;
-    }
-
-    public String getScheme() {
-        return scheme;
-    }
-
-    public String getUrl() {
-        return url;
-    }
-
-    public String getServer() {
-        return server;
-    }
-
-    public String getPath() {
-        return path;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/storage/encoding/Decoder.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/storage/encoding/Decoder.java 
b/utils/src/com/cloud/utils/storage/encoding/Decoder.java
deleted file mode 100644
index c7c61d3..0000000
--- a/utils/src/com/cloud/utils/storage/encoding/Decoder.java
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.storage.encoding;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-public class Decoder {
-    private static final Logger s_logger = Logger.getLogger(Decoder.class);
-
-    private static Map<String, String> getParameters(URI uri) {
-        String parameters = uri.getQuery();
-        Map<String, String> params = new HashMap<String, String>();
-        List<String> paraLists = Arrays.asList(parameters.split("&"));
-        for (String para : paraLists) {
-            String[] pair = para.split("=");
-            if (!pair[1].equalsIgnoreCase("null")) {
-                params.put(pair[0], pair[1]);
-            }
-
-        }
-        return params;
-    }
-
-    public static DecodedDataObject decode(String url) throws 
URISyntaxException {
-        URI uri = new URI(url);
-        Map<String, String> params = getParameters(uri);
-        DecodedDataStore store =
-            new DecodedDataStore(params.get(EncodingType.ROLE.toString()), 
params.get(EncodingType.STOREUUID.toString()),
-                params.get(EncodingType.PROVIDERNAME.toString()), 
uri.getScheme(), uri.getScheme() + uri.getHost() + uri.getPath(), 
uri.getHost(), uri.getPath());
-
-        Long size = null;
-        try {
-            size = Long.parseLong(params.get(EncodingType.SIZE.toString()));
-        } catch (NumberFormatException e) {
-            s_logger.info("[ignored] number not recognised",e);
-        }
-        DecodedDataObject obj =
-            new DecodedDataObject(params.get(EncodingType.OBJTYPE.toString()), 
size, params.get(EncodingType.NAME.toString()), 
params.get(EncodingType.PATH.toString()),
-                store);
-        return obj;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/storage/encoding/EncodingType.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/storage/encoding/EncodingType.java 
b/utils/src/com/cloud/utils/storage/encoding/EncodingType.java
deleted file mode 100644
index f40f4f9..0000000
--- a/utils/src/com/cloud/utils/storage/encoding/EncodingType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.storage.encoding;
-
-public enum EncodingType {
-    //object
-    OBJTYPE,
-    SIZE,
-    NAME,
-    PATH,
-    //dataStore
-    ROLE,
-    STOREUUID,
-    PROVIDERNAME
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/time/InaccurateClock.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/time/InaccurateClock.java 
b/utils/src/com/cloud/utils/time/InaccurateClock.java
deleted file mode 100644
index 2a22853..0000000
--- a/utils/src/com/cloud/utils/time/InaccurateClock.java
+++ /dev/null
@@ -1,102 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.time;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import javax.management.StandardMBean;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.utils.concurrency.NamedThreadFactory;
-import com.cloud.utils.mgmt.JmxUtil;
-
-/**
- */
-
-public class InaccurateClock extends StandardMBean implements 
InaccurateClockMBean {
-    private static final Logger s_logger = 
Logger.getLogger(InaccurateClock.class);
-    static ScheduledExecutorService s_executor = null;
-    static final InaccurateClock s_timer = new InaccurateClock();
-    private static long time;
-
-    public InaccurateClock() {
-        super(InaccurateClockMBean.class, false);
-        time = System.currentTimeMillis();
-        restart();
-        try {
-            JmxUtil.registerMBean("InaccurateClock", "InaccurateClock", this);
-        } catch (Exception e) {
-            s_logger.warn("Unable to initialize inaccurate clock", e);
-        }
-    }
-
-    @Override
-    public long[] getCurrentTimes() {
-        long[] results = new long[2];
-        results[0] = time;
-        results[1] = System.currentTimeMillis();
-
-        return results;
-    }
-
-    @Override
-    public synchronized String restart() {
-        turnOff();
-        s_executor = Executors.newScheduledThreadPool(1, new 
NamedThreadFactory("InaccurateClock"));
-        s_executor.scheduleAtFixedRate(new SetTimeTask(), 0, 60, 
TimeUnit.SECONDS);
-        return "Restarted";
-    }
-
-    @Override
-    public String turnOff() {
-        if (s_executor != null) {
-            try {
-                s_executor.shutdown();
-            } catch (Throwable th) {
-                s_logger.error("Unable to shutdown the Executor", th);
-                return "Unable to turn off check logs";
-            }
-        }
-        s_executor = null;
-        return "Off";
-    }
-
-    public static long getTime() {
-        return s_executor != null ? time : System.currentTimeMillis();
-    }
-
-    public static long getTimeInSeconds() {
-        return time / 1000;
-    }
-
-    protected class SetTimeTask implements Runnable {
-        @Override
-        public void run() {
-            try {
-                time = System.currentTimeMillis();
-            } catch (Throwable th) {
-                s_logger.error("Unable to time", th);
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/time/InaccurateClockMBean.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/time/InaccurateClockMBean.java 
b/utils/src/com/cloud/utils/time/InaccurateClockMBean.java
deleted file mode 100644
index acc4615..0000000
--- a/utils/src/com/cloud/utils/time/InaccurateClockMBean.java
+++ /dev/null
@@ -1,28 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.time;
-
-public interface InaccurateClockMBean {
-    String restart();
-
-    String turnOff();
-
-    long[] getCurrentTimes();
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/xmlobject/XmlObject.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/xmlobject/XmlObject.java 
b/utils/src/com/cloud/utils/xmlobject/XmlObject.java
deleted file mode 100644
index 42af945..0000000
--- a/utils/src/com/cloud/utils/xmlobject/XmlObject.java
+++ /dev/null
@@ -1,214 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.xmlobject;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import com.cloud.utils.exception.CloudRuntimeException;
-
-public class XmlObject {
-    private final Logger logger = Logger.getLogger(XmlObject.class.getName());
-    private final Map<String, Object> elements = new HashMap<String, Object>();
-    private String text;
-    private String tag;
-
-    XmlObject() {
-    }
-
-    public void removeAllChildren() {
-        elements.clear();
-    }
-
-    public XmlObject(String tag) {
-        this.tag = tag;
-    }
-
-    public XmlObject putElement(String key, Object e) {
-        if (e == null) {
-            throw new IllegalArgumentException(String.format("element[%s] can 
not be null", key));
-        }
-        Object old = elements.get(key);
-        if (old == null) {
-            //System.out.println(String.format("no %s, add new", key));
-            elements.put(key, e);
-        } else {
-            if (old instanceof List) {
-                //System.out.println(String.format("already list %s, add", 
key));
-                ((List)old).add(e);
-            } else {
-                //System.out.println(String.format("not list list %s, add 
list", key));
-                List lst = new ArrayList();
-                lst.add(old);
-                lst.add(e);
-                elements.put(key, lst);
-            }
-        }
-
-        return this;
-    }
-
-    public void removeElement(String key) {
-        elements.remove(key);
-    }
-
-    private Object recurGet(XmlObject obj, Iterator<String> it) {
-        String key = it.next();
-        Object e = obj.elements.get(key);
-        if (e == null) {
-            return null;
-        }
-
-        if (!it.hasNext()) {
-            return e;
-        } else {
-            if (!(e instanceof XmlObject)) {
-                throw new CloudRuntimeException(String.format("%s doesn't 
reference to a XmlObject", it.next()));
-            }
-            return recurGet((XmlObject)e, it);
-        }
-    }
-
-    public <T> T get(String elementStr) {
-        String[] strs = elementStr.split("\\.");
-        List<String> lst = new ArrayList<String>(strs.length);
-        Collections.addAll(lst, strs);
-        return (T)recurGet(this, lst.iterator());
-    }
-
-    public <T> List<T> getAsList(String elementStr) {
-        Object e = get(elementStr);
-        if (e instanceof List) {
-            return (List<T>)e;
-        }
-
-        List lst = new ArrayList(1);
-        if (e != null) {
-            lst.add(e);
-        }
-
-        return lst;
-    }
-
-    public String getText() {
-        return text;
-    }
-
-    public XmlObject setText(String text) {
-        this.text = text;
-        return this;
-    }
-
-    public String getTag() {
-        return tag;
-    }
-
-    public XmlObject setTag(String tag) {
-        this.tag = tag;
-        return this;
-    }
-
-    public String dump() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("<").append(tag);
-        List<XmlObject> children = new ArrayList<XmlObject>();
-        for (Map.Entry<String, Object> e : elements.entrySet()) {
-            String key = e.getKey();
-            Object val = e.getValue();
-            if (val instanceof String) {
-                sb.append(String.format(" %s=\"%s\"", key, val.toString()));
-            } else if (val instanceof XmlObject) {
-                children.add((XmlObject)val);
-            } else if (val instanceof List) {
-                children.addAll((Collection<? extends XmlObject>)val);
-            } else {
-                throw new CloudRuntimeException(String.format("unsupported 
element type[tag:%s, class: %s], only allowed type of [String, List<XmlObject>, 
Object]", key,
-                    val.getClass().getName()));
-            }
-        }
-
-        if (!children.isEmpty() && text != null) {
-            logger.info(String.format("element %s cannot have both text[%s] 
and child elements, set text to null", tag, text));
-            text = null;
-        }
-
-        if (!children.isEmpty()) {
-            sb.append(">");
-            for (XmlObject x : children) {
-                sb.append(x.dump());
-            }
-            sb.append(String.format("</%s>", tag));
-        } else {
-            if (text != null) {
-                sb.append(">");
-                sb.append(text);
-                sb.append(String.format("</%s>", tag));
-            } else {
-                sb.append(" />");
-            }
-        }
-        return sb.toString();
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder("<" + tag);
-        for (Map.Entry<String, Object> e : elements.entrySet()) {
-            String key = e.getKey();
-            Object value = e.getValue();
-            if (!(value instanceof String)) {
-                continue;
-            }
-            sb.append(String.format(" %s=\"%s\"", key, value.toString()));
-        }
-
-        if (text == null || "".equals(text.trim())) {
-            sb.append(" />");
-        } else {
-            sb.append(">").append(text).append(String.format("</ %s>", tag));
-        }
-        return sb.toString();
-    }
-
-    public <T> T evaluateObject(T obj) {
-        Class<?> clazz = obj.getClass();
-        try {
-            do {
-                Field[] fs = clazz.getDeclaredFields();
-                for (Field f : fs) {
-                    f.setAccessible(true);
-                    Object value = get(f.getName());
-                    f.set(obj, value);
-                }
-                clazz = clazz.getSuperclass();
-            } while (clazz != null && clazz != Object.class);
-            return obj;
-        } catch (Exception e) {
-            throw new CloudRuntimeException(e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/xmlobject/XmlObjectParser.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/xmlobject/XmlObjectParser.java 
b/utils/src/com/cloud/utils/xmlobject/XmlObjectParser.java
deleted file mode 100644
index f0e8ce3..0000000
--- a/utils/src/com/cloud/utils/xmlobject/XmlObjectParser.java
+++ /dev/null
@@ -1,128 +0,0 @@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-
-package com.cloud.utils.xmlobject;
-
-import com.cloud.utils.exception.CloudRuntimeException;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.Stack;
-
-public class XmlObjectParser {
-    final private InputStream is;
-
-    private class XmlHandler extends DefaultHandler {
-        private Stack<XmlObject> stack;
-        private String currentValue;
-        private XmlObject root;
-
-        XmlHandler() {
-            stack = new Stack<XmlObject>();
-        }
-
-        @Override
-        public void startElement(String namespaceURI, String localName, String 
qName, Attributes atts) throws SAXException {
-            //System.out.println(String.format("startElement: namespaceURI:%s, 
localName:%s, qName:%s", namespaceURI, localName, qName));
-            currentValue = null;
-            XmlObject obj = new XmlObject();
-            for (int i = 0; i < atts.getLength(); i++) {
-                obj.putElement(atts.getQName(i), atts.getValue(i));
-            }
-            obj.setTag(qName);
-            if (!stack.isEmpty()) {
-                XmlObject parent = stack.peek();
-                parent.putElement(qName, obj);
-            }
-            stack.push(obj);
-        }
-
-        @Override
-        public void endElement(String namespaceURI, String localName, String 
qName) throws SAXException {
-            XmlObject currObj = stack.pop();
-            if (currentValue != null) {
-                currObj.setText(currentValue);
-            }
-
-            if (stack.isEmpty()) {
-                root = currObj;
-            }
-
-            //System.out.println(String.format("endElement: namespaceURI:%s, 
localName:%s, qName:%s", namespaceURI, localName, qName));
-        }
-
-        @Override
-        public void characters(char[] ch, int start, int length) throws 
SAXException {
-            StringBuilder str = new StringBuilder();
-            str.append(ch, start, length);
-            currentValue = str.toString();
-            //System.out.println(String.format("characters: %s", 
str.toString()));
-        }
-
-        XmlObject getRoot() {
-            return root;
-        }
-    }
-
-    private XmlObjectParser(InputStream is) {
-        super();
-        this.is = is;
-    }
-
-    public static XmlObject parseFromFile(String filePath) {
-        FileInputStream fs;
-        try {
-            fs = new FileInputStream(new File(filePath));
-            XmlObjectParser p = new XmlObjectParser(fs);
-            return p.parse();
-        } catch (FileNotFoundException e) {
-            throw new CloudRuntimeException(e);
-        }
-    }
-
-    public static XmlObject parseFromString(String xmlString) {
-        InputStream stream = new ByteArrayInputStream(xmlString.getBytes());
-        XmlObjectParser p = new XmlObjectParser(stream);
-        XmlObject obj = p.parse();
-        if (obj.getText() != null && obj.getText().replaceAll("\\n", 
"").replaceAll("\\r", "").replaceAll(" ", "").isEmpty()) {
-            obj.setText(null);
-        }
-        return obj;
-    }
-
-    private XmlObject parse() {
-        SAXParserFactory spfactory = SAXParserFactory.newInstance();
-        try {
-            SAXParser saxParser = spfactory.newSAXParser();
-            XmlHandler handler = new XmlHandler();
-            saxParser.parse(is, handler);
-            return handler.getRoot();
-        } catch (Exception e) {
-            throw new CloudRuntimeException(e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/maint/Version.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/maint/Version.java 
b/utils/src/main/java/com/cloud/maint/Version.java
new file mode 100644
index 0000000..925806e
--- /dev/null
+++ b/utils/src/main/java/com/cloud/maint/Version.java
@@ -0,0 +1,77 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.maint;
+
+public class Version {
+    /**
+     * Compares two version strings and see which one is higher version.
+     * @param ver1
+     * @param ver2
+     * @return positive if ver1 is higher.  negative if ver1 is lower; zero if 
the same.
+     */
+    public static int compare(String ver1, String ver2) {
+        String[] tokens1 = ver1.split("[.]");
+        String[] tokens2 = ver2.split("[.]");
+//        assert(tokens1.length <= tokens2.length);
+
+        int compareLength = Math.min(tokens1.length, tokens2.length);
+        for (int i = 0; i < compareLength; i++) {
+            long version1 = Long.parseLong(tokens1[i]);
+            long version2 = Long.parseLong(tokens2[i]);
+            if (version1 != version2) {
+                return version1 < version2 ? -1 : 1;
+            }
+        }
+
+        if (tokens1.length > tokens2.length) {
+            return 1;
+        } else if (tokens1.length < tokens2.length) {
+            return -1;
+        }
+
+        return 0;
+    }
+
+    public static String trimToPatch(String version) {
+        int index = version.indexOf("-");
+
+        if (index > 0)
+            version = version.substring(0, index);
+
+        String[] tokens = version.split("[.]");
+
+        if (tokens.length < 3)
+            return "0";
+        return tokens[0] + "." + tokens[1] + "." + tokens[2];
+    }
+
+    public static String trimRouterVersion(String version) {
+        String[] tokens = version.split(" ");
+        if (tokens.length >= 3 && tokens[2].matches("[0-9]+(\\.[0-9]+)*")) {
+            return tokens[2];
+        }
+        return "0";
+    }
+
+    public static void main(String[] args) {
+        System.out.println("Result is " + compare(args[0], args[1]));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/ActionDelegate.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/ActionDelegate.java 
b/utils/src/main/java/com/cloud/utils/ActionDelegate.java
new file mode 100644
index 0000000..02f76d9
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/ActionDelegate.java
@@ -0,0 +1,24 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils;
+
+public interface ActionDelegate<T> {
+    void action(T param);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/AutoCloseableUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/AutoCloseableUtil.java 
b/utils/src/main/java/com/cloud/utils/AutoCloseableUtil.java
new file mode 100644
index 0000000..f93265b
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/AutoCloseableUtil.java
@@ -0,0 +1,36 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.utils;
+
+import org.apache.log4j.Logger;
+
+public class AutoCloseableUtil {
+    private final static Logger s_logger = 
Logger.getLogger(AutoCloseableUtil.class);
+
+    public static void closeAutoCloseable(AutoCloseable ac, String message) {
+        try {
+
+            if (ac != null) {
+                ac.close();
+            }
+
+        } catch (Exception e) {
+            s_logger.warn("[ignored] " + message, e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/CloudResourceBundle.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/CloudResourceBundle.java 
b/utils/src/main/java/com/cloud/utils/CloudResourceBundle.java
new file mode 100644
index 0000000..cf27d79
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/CloudResourceBundle.java
@@ -0,0 +1,48 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+public class CloudResourceBundle {
+
+    private ResourceBundle _bundle;
+
+    public CloudResourceBundle(ResourceBundle bundle) {
+        _bundle = bundle;
+    }
+
+    public static CloudResourceBundle getBundle(String baseName, Locale 
locale) {
+        return new CloudResourceBundle(ResourceBundle.getBundle(baseName, 
locale));
+    }
+
+    private String getString(String key) {
+        try {
+            return _bundle.getString(key);
+        } catch (Exception e) {
+            return key; //if translation is not found, just return original 
word (i.e. English).
+        }
+    }
+
+    public String t(String key) {
+        return getString(key);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/ConstantTimeComparator.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/ConstantTimeComparator.java 
b/utils/src/main/java/com/cloud/utils/ConstantTimeComparator.java
new file mode 100644
index 0000000..baf2bc2
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/ConstantTimeComparator.java
@@ -0,0 +1,42 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils;
+
+import java.nio.charset.Charset;
+
+public class ConstantTimeComparator {
+
+    public static boolean compareBytes(byte[] b1, byte[] b2) {
+        if (b1.length != b2.length) {
+            return false;
+        }
+
+        int result = 0;
+        for (int i = 0; i < b1.length; i++) {
+            result |= b1[i] ^ b2[i];
+        }
+        return result == 0;
+    }
+
+    public static boolean compareStrings(String s1, String s2) {
+        final Charset encoding = Charset.forName("UTF-8");
+        return compareBytes(s1.getBytes(encoding), s2.getBytes(encoding));
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/DateUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/DateUtil.java 
b/utils/src/main/java/com/cloud/utils/DateUtil.java
new file mode 100644
index 0000000..7787e1b
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/DateUtil.java
@@ -0,0 +1,274 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class DateUtil {
+    public static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
+    public static final String YYYYMMDD_FORMAT = "yyyyMMddHHmmss";
+    private static final DateFormat s_outputFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+
+    public static Date currentGMTTime() {
+        // Date object always stores miliseconds offset based on GMT internally
+        return new Date();
+    }
+
+    // yyyy-MM-ddTHH:mm:ssZxxxx
+    public static Date parseTZDateString(String str) throws ParseException {
+        DateFormat dfParse = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'Z");
+        return dfParse.parse(str);
+    }
+
+    public static Date parseDateString(TimeZone tz, String dateString) {
+        return parseDateString(tz, dateString, "yyyy-MM-dd HH:mm:ss");
+    }
+
+    public static Date parseDateString(TimeZone tz, String dateString, String 
formatString) {
+        DateFormat df = new SimpleDateFormat(formatString);
+        df.setTimeZone(tz);
+
+        try {
+            return df.parse(dateString);
+        } catch (ParseException e) {
+            throw new CloudRuntimeException("why why ", e);
+        }
+    }
+
+    public static String displayDateInTimezone(TimeZone tz, Date time) {
+        return getDateDisplayString(tz, time, "yyyy-MM-dd HH:mm:ss z");
+    }
+
+    public static String getDateDisplayString(TimeZone tz, Date time) {
+        return getDateDisplayString(tz, time, "yyyy-MM-dd HH:mm:ss");
+    }
+
+    public static String getDateDisplayString(TimeZone tz, Date time, String 
formatString) {
+        DateFormat df = new SimpleDateFormat(formatString);
+        df.setTimeZone(tz);
+
+        return df.format(time);
+    }
+
+    public static String getOutputString(Date date) {
+        if (date == null) {
+            return "";
+        }
+        String formattedString = null;
+        synchronized (s_outputFormat) {
+            formattedString = s_outputFormat.format(date);
+        }
+        return formattedString;
+    }
+
+    public static Date now() {
+        return new Date(System.currentTimeMillis());
+    }
+
+    public enum IntervalType {
+        HOURLY, DAILY, WEEKLY, MONTHLY;
+
+        boolean equals(String intervalType) {
+            return super.toString().equalsIgnoreCase(intervalType);
+        }
+
+        public static IntervalType getIntervalType(String intervalTypeStr) {
+            for (IntervalType intervalType : IntervalType.values()) {
+                if (intervalType.equals(intervalTypeStr)) {
+                    return intervalType;
+                }
+            }
+            return null;
+        }
+    }
+
+    public static IntervalType getIntervalType(short type) {
+        if (type < 0 || type >= IntervalType.values().length) {
+            return null;
+        }
+        return IntervalType.values()[type];
+    }
+
+    /**
+     * Return next run time
+     * @param intervalType  hourly/daily/weekly/monthly
+     * @param schedule MM[:HH][:DD] format. DD is day of week for weekly and 
day of month for monthly
+     * @param timezone The timezone in which the schedule string is specified
+     * @param startDate if specified, returns next run time after the 
specified startDate
+     * @return
+     */
+    public static Date getNextRunTime(IntervalType type, String schedule, 
String timezone, Date startDate) {
+
+        String[] scheduleParts = schedule.split(":"); //MM:HH:DAY
+
+        final Calendar scheduleTime = Calendar.getInstance();
+        scheduleTime.setTimeZone(TimeZone.getTimeZone(timezone));
+
+        if (startDate == null) {
+            startDate = new Date();
+        }
+        scheduleTime.setTime(startDate);
+        // Throw an ArrayIndexOutOfBoundsException if schedule is badly 
formatted.
+        scheduleTime.setLenient(false);
+        int minutes = 0;
+        int hour = 0;
+        int day = 0;
+        Date execDate = null;
+
+        switch (type) {
+            case HOURLY:
+                if (scheduleParts.length < 1) {
+                    throw new CloudRuntimeException("Incorrect schedule 
format: " + schedule + " for interval type:" + type.toString());
+                }
+                minutes = Integer.parseInt(scheduleParts[0]);
+                scheduleTime.set(Calendar.MINUTE, minutes);
+                scheduleTime.set(Calendar.SECOND, 0);
+                scheduleTime.set(Calendar.MILLISECOND, 0);
+                try {
+                    execDate = scheduleTime.getTime();
+                } catch (IllegalArgumentException ex) {
+                    scheduleTime.setLenient(true);
+                    execDate = scheduleTime.getTime();
+                    scheduleTime.setLenient(false);
+                }
+                // XXX: !execDate.after(startDate) is strictly for testing.
+                // During testing we use a test clock which runs much faster 
than the real clock
+                // So startDate and execDate will always be ahead in the future
+                // and we will never increase the time here
+                if (execDate.before(new Date()) || !execDate.after(startDate)) 
{
+                    scheduleTime.add(Calendar.HOUR_OF_DAY, 1);
+                }
+                break;
+            case DAILY:
+                if (scheduleParts.length < 2) {
+                    throw new CloudRuntimeException("Incorrect schedule 
format: " + schedule + " for interval type:" + type.toString());
+                }
+                minutes = Integer.parseInt(scheduleParts[0]);
+                hour = Integer.parseInt(scheduleParts[1]);
+
+                scheduleTime.set(Calendar.HOUR_OF_DAY, hour);
+                scheduleTime.set(Calendar.MINUTE, minutes);
+                scheduleTime.set(Calendar.SECOND, 0);
+                scheduleTime.set(Calendar.MILLISECOND, 0);
+                try {
+                    execDate = scheduleTime.getTime();
+                } catch (IllegalArgumentException ex) {
+                    scheduleTime.setLenient(true);
+                    execDate = scheduleTime.getTime();
+                    scheduleTime.setLenient(false);
+                }
+                // XXX: !execDate.after(startDate) is strictly for testing.
+                // During testing we use a test clock which runs much faster 
than the real clock
+                // So startDate and execDate will always be ahead in the future
+                // and we will never increase the time here
+                if (execDate.before(new Date()) || !execDate.after(startDate)) 
{
+                    scheduleTime.add(Calendar.DAY_OF_YEAR, 1);
+                }
+                break;
+            case WEEKLY:
+                if (scheduleParts.length < 3) {
+                    throw new CloudRuntimeException("Incorrect schedule 
format: " + schedule + " for interval type:" + type.toString());
+                }
+                minutes = Integer.parseInt(scheduleParts[0]);
+                hour = Integer.parseInt(scheduleParts[1]);
+                day = Integer.parseInt(scheduleParts[2]);
+                scheduleTime.set(Calendar.DAY_OF_WEEK, day);
+                scheduleTime.set(Calendar.HOUR_OF_DAY, hour);
+                scheduleTime.set(Calendar.MINUTE, minutes);
+                scheduleTime.set(Calendar.SECOND, 0);
+                scheduleTime.set(Calendar.MILLISECOND, 0);
+                try {
+                    execDate = scheduleTime.getTime();
+                } catch (IllegalArgumentException ex) {
+                    scheduleTime.setLenient(true);
+                    execDate = scheduleTime.getTime();
+                    scheduleTime.setLenient(false);
+                }
+                // XXX: !execDate.after(startDate) is strictly for testing.
+                // During testing we use a test clock which runs much faster 
than the real clock
+                // So startDate and execDate will always be ahead in the future
+                // and we will never increase the time here
+                if (execDate.before(new Date()) || !execDate.after(startDate)) 
{
+                    scheduleTime.add(Calendar.DAY_OF_WEEK, 7);
+                }
+                ;
+                break;
+            case MONTHLY:
+                if (scheduleParts.length < 3) {
+                    throw new CloudRuntimeException("Incorrect schedule 
format: " + schedule + " for interval type:" + type.toString());
+                }
+                minutes = Integer.parseInt(scheduleParts[0]);
+                hour = Integer.parseInt(scheduleParts[1]);
+                day = Integer.parseInt(scheduleParts[2]);
+                if (day > 28) {
+                    throw new CloudRuntimeException("Day cannot be greater 
than 28 for monthly schedule");
+                }
+                scheduleTime.set(Calendar.DAY_OF_MONTH, day);
+                scheduleTime.set(Calendar.HOUR_OF_DAY, hour);
+                scheduleTime.set(Calendar.MINUTE, minutes);
+                scheduleTime.set(Calendar.SECOND, 0);
+                scheduleTime.set(Calendar.MILLISECOND, 0);
+                try {
+                    execDate = scheduleTime.getTime();
+                } catch (IllegalArgumentException ex) {
+                    scheduleTime.setLenient(true);
+                    execDate = scheduleTime.getTime();
+                    scheduleTime.setLenient(false);
+                }
+                // XXX: !execDate.after(startDate) is strictly for testing.
+                // During testing we use a test clock which runs much faster 
than the real clock
+                // So startDate and execDate will always be ahead in the future
+                // and we will never increase the time here
+                if (execDate.before(new Date()) || !execDate.after(startDate)) 
{
+                    scheduleTime.add(Calendar.MONTH, 1);
+                }
+                break;
+            default:
+                throw new CloudRuntimeException("Incorrect interval: " + 
type.toString());
+        }
+
+        try {
+            return scheduleTime.getTime();
+        } catch (IllegalArgumentException ex) {
+            scheduleTime.setLenient(true);
+            Date nextScheduledDate = scheduleTime.getTime();
+            scheduleTime.setLenient(false);
+            return nextScheduledDate;
+        }
+    }
+
+    public static long getTimeDifference(Date date1, Date date2){
+
+        Calendar dateCalendar1 = Calendar.getInstance();
+        dateCalendar1.setTime(date1);
+        Calendar dateCalendar2 = Calendar.getInstance();
+        dateCalendar2.setTime(date2);
+
+        return (dateCalendar1.getTimeInMillis() - 
dateCalendar2.getTimeInMillis() )/1000;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/EncryptionUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/EncryptionUtil.java 
b/utils/src/main/java/com/cloud/utils/EncryptionUtil.java
new file mode 100644
index 0000000..b82842e
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/EncryptionUtil.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.cloud.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+import org.jasypt.encryption.pbe.PBEStringEncryptor;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class EncryptionUtil {
+    public static final Logger s_logger = 
Logger.getLogger(EncryptionUtil.class.getName());
+    private static PBEStringEncryptor encryptor;
+
+    private static void initialize(String key) {
+        StandardPBEStringEncryptor standardPBEStringEncryptor = new 
StandardPBEStringEncryptor();
+        standardPBEStringEncryptor.setAlgorithm("PBEWITHSHA1ANDDESEDE");
+        standardPBEStringEncryptor.setPassword(key);
+        encryptor = standardPBEStringEncryptor;
+    }
+
+    public static String encodeData(String data, String key) {
+        if (encryptor == null) {
+            initialize(key);
+        }
+        return encryptor.encrypt(data);
+    }
+
+    public static String decodeData(String encodedData, String key) {
+        if (encryptor == null) {
+            initialize(key);
+        }
+        return encryptor.decrypt(encodedData);
+    }
+
+    public static String generateSignature(String data, String key) {
+        try {
+            final Mac mac = Mac.getInstance("HmacSHA1");
+            final SecretKeySpec keySpec = new 
SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA1");
+            mac.init(keySpec);
+            mac.update(data.getBytes("UTF-8"));
+            final byte[] encryptedBytes = mac.doFinal();
+            return Base64.encodeBase64String(encryptedBytes);
+        } catch (NoSuchAlgorithmException | InvalidKeyException | 
UnsupportedEncodingException e) {
+            s_logger.error("exception occurred which encoding the data." + 
e.getMessage());
+            throw new CloudRuntimeException("unable to generate signature", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/EnumUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/EnumUtils.java 
b/utils/src/main/java/com/cloud/utils/EnumUtils.java
new file mode 100644
index 0000000..02b6a25
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/EnumUtils.java
@@ -0,0 +1,58 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils;
+
+public class EnumUtils {
+    public static String listValues(Enum<?>[] enums) {
+        StringBuilder b = new StringBuilder("[");
+
+        for (Enum<?> e : enums) {
+            b.append(e).append(", ");
+        }
+        b.append("]");
+        return b.toString();
+    }
+
+    public static <T extends Enum<T>> T fromString(Class<T> clz, String value, 
T defaultVal) {
+        assert (clz != null);
+
+        if (value != null) {
+            try {
+                return Enum.valueOf(clz, value.trim());
+            } catch (IllegalArgumentException ex) {
+                assert (false);
+            }
+        }
+        return defaultVal;
+    }
+
+    public static <T extends Enum<T>> T fromString(Class<T> clz, String value) 
{
+        assert (clz != null);
+
+        if (value != null) {
+            try {
+                return Enum.valueOf(clz, value.trim());
+            } catch (IllegalArgumentException ex) {
+                assert (false);
+            }
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/ExecutionResult.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/ExecutionResult.java 
b/utils/src/main/java/com/cloud/utils/ExecutionResult.java
new file mode 100644
index 0000000..c8b620a
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/ExecutionResult.java
@@ -0,0 +1,46 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils;
+
+public class ExecutionResult {
+    private Boolean success;
+    private String details;
+
+    public ExecutionResult(Boolean success, String details) {
+        this.success = success;
+        this.details = details;
+    }
+
+    public Boolean isSuccess() {
+        return success;
+    }
+
+    public void setSuccess(Boolean success) {
+        this.success = success;
+    }
+
+    public String getDetails() {
+        return details;
+    }
+
+    public void setDetails(String details) {
+        this.details = details;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/main/java/com/cloud/utils/FileUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/FileUtil.java 
b/utils/src/main/java/com/cloud/utils/FileUtil.java
new file mode 100644
index 0000000..c55dd74
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/FileUtil.java
@@ -0,0 +1,32 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+
+public class FileUtil {
+
+    public static void copyfile(File source, File destination) throws 
IOException {
+        FileUtils.copyFile(source, destination);
+    }
+}

Reply via email to