Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 31664DC2E for ; Wed, 8 Aug 2012 18:55:30 +0000 (UTC) Received: (qmail 54829 invoked by uid 500); 8 Aug 2012 18:55:25 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 54765 invoked by uid 500); 8 Aug 2012 18:55:25 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 54389 invoked by uid 99); 8 Aug 2012 18:55:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2012 18:55:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9B4933C770; Wed, 8 Aug 2012 18:55:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: alena1108@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [29/43] Removed Base64 file and use the apache version Message-Id: <20120808185524.9B4933C770@tyr.zones.apache.org> Date: Wed, 8 Aug 2012 18:55:24 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6a864a1/test/src/com/cloud/test/stress/TestClientWithAPI.java ---------------------------------------------------------------------- diff --git a/test/src/com/cloud/test/stress/TestClientWithAPI.java b/test/src/com/cloud/test/stress/TestClientWithAPI.java index 84cb087..9d21927 100644 --- a/test/src/com/cloud/test/stress/TestClientWithAPI.java +++ b/test/src/com/cloud/test/stress/TestClientWithAPI.java @@ -49,7 +49,6 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import com.cloud.utils.encoding.Base64; import com.cloud.utils.exception.CloudRuntimeException; import com.trilead.ssh2.ChannelCondition; import com.trilead.ssh2.Connection; @@ -182,7 +181,7 @@ public class TestClientWithAPI { if (arg.equals("-no")) { networkOfferingId = iter.next(); } - + if (arg.equals("-pass")) { vmPassword = iter.next(); } @@ -210,6 +209,7 @@ public class TestClientWithAPI { for (int i = 0; i < numThreads; i++) { new Thread(new Runnable() { + @Override public void run() { do { String username = null; @@ -440,7 +440,7 @@ public class TestClientWithAPI { for (int j = 0; j < childNodes.getLength(); j++) { Node n = childNodes.item(j); if ("id".equals(n.getNodeName())) { - // if ("ipaddress".equals(n.getNodeName())) { + // if ("ipaddress".equals(n.getNodeName())) { ipAddress = n.getTextContent(); } else if ("issourcenat".equals(n.getNodeName())) { isSourceNat = Boolean.parseBoolean(n.getTextContent()); @@ -478,7 +478,7 @@ public class TestClientWithAPI { } else if("ipaddress".equals(n.getNodeName())) { - ipAddress = n.getTextContent(); + ipAddress = n.getTextContent(); } else if ("issourcenat".equals(n.getNodeName())) { isSourceNat = Boolean.parseBoolean(n.getTextContent()); @@ -609,7 +609,7 @@ public class TestClientWithAPI { s_logger.error("Create virtual network failed for account " + username + " with error code :" + responseCode + ", aborting deployment test. The command was sent with url " + url); return -1; } -/* + /* // --------------------------------- // CREATE DIRECT NETWORK // --------------------------------- @@ -629,9 +629,9 @@ public class TestClientWithAPI { s_logger.error("Create direct network failed for account " + username + " with error code :" + responseCode + ", aborting deployment test. The command was sent with url " + url); return -1; } -*/ - - + */ + + // --------------------------------- // DEPLOY LINUX VM // --------------------------------- @@ -706,7 +706,7 @@ public class TestClientWithAPI { } else { - s_logger.info("Associate IP Address response code: " + responseCode); + s_logger.info("Associate IP Address response code: " + responseCode); long publicIpId = Long.parseLong(values.get("id")); s_logger.info("Associate IP's Id: " + publicIpId); _publicIpId.set(values.get("id")); @@ -715,13 +715,13 @@ public class TestClientWithAPI { s_logger.error("associate ip address for windows vm failed with error code: " + responseCode + ". Following URL was sent: " + url); return responseCode; } - + String encodedPublicIpId = URLEncoder.encode(_publicIpId.get(), "UTF-8"); requestToSign = "apikey=" + encodedApiKey + "&command=listPublicIpAddresses"+"&id="+ encodedPublicIpId; requestToSign = requestToSign.toLowerCase(); signature = signRequest(requestToSign, _secretKey.get()); encodedSignature = URLEncoder.encode(signature, "UTF-8"); - + url = developerServer + "?command=listPublicIpAddresses&apikey=" + encodedApiKey + "&id=" + encodedPublicIpId + "&signature=" + encodedSignature; client = new HttpClient(); method = new GetMethod(url); @@ -730,9 +730,9 @@ public class TestClientWithAPI { s_logger.info("list ip addresses for user " + userId + " response code: " + responseCode); if (responseCode == 200) { InputStream is = method.getResponseBodyAsStream(); - // InputStream ips = method.getResponseBodyAsStream(); + // InputStream ips = method.getResponseBodyAsStream(); List ipAddressValues = getIPs(is, false); - // List ipAddressVals = getIPs(is, false, true); + // List ipAddressVals = getIPs(is, false, true); if ((ipAddressValues != null) && !ipAddressValues.isEmpty()) { _windowsIpId.set(ipAddressValues.get(0)); _windowsIP.set(ipAddressValues.get(1)); @@ -743,7 +743,7 @@ public class TestClientWithAPI { s_logger.error("list ip addresses failed with error code: " + responseCode + ". Following URL was sent: " + url); return responseCode; } - + // --------------------------------- // Use the SourceNat IP for linux // --------------------------------- @@ -776,17 +776,17 @@ public class TestClientWithAPI { return responseCode; } } - + //-------------------------------------------- // Enable Static NAT for the Source NAT Ip //-------------------------------------------- String encodedSourceNatPublicIpId = URLEncoder.encode(_linuxIpId.get(), "UTF-8"); - - /* requestToSign = "apikey=" + encodedApiKey + "&command=enableStaticNat"+"&id=" + encodedSourceNatPublicIpId + "&virtualMachineId=" + encodedVmId;; + + /* requestToSign = "apikey=" + encodedApiKey + "&command=enableStaticNat"+"&id=" + encodedSourceNatPublicIpId + "&virtualMachineId=" + encodedVmId;; requestToSign = requestToSign.toLowerCase(); signature = signRequest(requestToSign, _secretKey.get()); encodedSignature = URLEncoder.encode(signature, "UTF-8"); - + url = developerServer + "?command=enableStaticNat&apikey=" + encodedApiKey + "&signature=" + encodedSignature + "&id=" + encodedSourceNatPublicIpId + "&virtualMachineId=" + encodedVmId; client = new HttpClient(); method = new GetMethod(url); @@ -801,7 +801,7 @@ public class TestClientWithAPI { s_logger.error("Enable Static NAT failed with error code: " + responseCode + ". Following URL was sent: " + url); return responseCode; } - */ + */ // ------------------------------------------------------------- // CREATE IP FORWARDING RULE -- Linux VM // ------------------------------------------------------------- @@ -825,7 +825,7 @@ public class TestClientWithAPI { long ipfwdid = Long.parseLong(values.get("id")); s_logger.info("got Port Forwarding Rule's Id:" + ipfwdid); _linipfwdid.set(values.get("id")); - + } else { s_logger.error("Port forwarding rule creation failed with error code: " + responseCode + ". Following URL was sent: " + url); return responseCode; @@ -882,7 +882,7 @@ public class TestClientWithAPI { String encodedTemplateId = URLEncoder.encode("" + templateId, "UTF-8"); encodedApiKey = URLEncoder.encode(_apiKey.get(), "UTF-8"); String encodedNetworkIds = URLEncoder.encode(_networkId.get()+",206","UTF-8"); - + requestToSign = "apikey=" + encodedApiKey + "&command=deployVirtualMachine&diskofferingid=" + diskOfferingId + "&networkids=" + encodedNetworkIds + "&serviceofferingid=" + encodedServiceOfferingId + "&templateid=" + encodedTemplateId + "&zoneid=" + encodedZoneId; requestToSign = requestToSign.toLowerCase(); @@ -918,14 +918,14 @@ public class TestClientWithAPI { //-------------------------------------------- // Enable Static NAT for the Non Source NAT Ip //-------------------------------------------- - + encodedVmId = URLEncoder.encode(_windowsVmId.get(), "UTF-8"); encodedPublicIpId = URLEncoder.encode(_publicIpId.get(), "UTF-8"); requestToSign = "apikey=" + encodedApiKey + "&command=enableStaticNat"+"&ipaddressid="+ encodedPublicIpId + "&virtualMachineId=" + encodedVmId; requestToSign = requestToSign.toLowerCase(); signature = signRequest(requestToSign, _secretKey.get()); encodedSignature = URLEncoder.encode(signature, "UTF-8"); - + url = developerServer + "?command=enableStaticNat&apikey=" + encodedApiKey + "&ipaddressid=" + encodedPublicIpId + "&signature=" + encodedSignature + "&virtualMachineId=" + encodedVmId; client = new HttpClient(); method = new GetMethod(url); @@ -941,7 +941,7 @@ public class TestClientWithAPI { return responseCode; } - + // ------------------------------------------------------------- // CREATE IP FORWARDING RULE -- Windows VM // ------------------------------------------------------------- @@ -972,7 +972,7 @@ public class TestClientWithAPI { s_logger.error("Port forwarding rule creation failed with error code: " + responseCode + ". Following URL was sent: " + url); return responseCode; } - } + } } return responseCode; } @@ -1178,7 +1178,7 @@ public class TestClientWithAPI { } // Create volume from the snapshot created on the previous step and attach it to the running vm - /* encodedApiKey = URLEncoder.encode(_apiKey.get(), "UTF-8"); + /* encodedApiKey = URLEncoder.encode(_apiKey.get(), "UTF-8"); requestToSign = "apikey=" + encodedApiKey + "&command=createVolume&name=" + _account.get() + "&snapshotid=" + _snapshot.get(); requestToSign = requestToSign.toLowerCase(); signature = signRequest(requestToSign, _secretKey.get()); @@ -1222,7 +1222,7 @@ public class TestClientWithAPI { return responseCode; } } -*/ + */ // ----------------------------- // Execute reboot/stop/start commands for the VMs before deleting the account - made to exercise xen // ----------------------------- @@ -1896,7 +1896,7 @@ public class TestClientWithAPI { InputStream input = method.getResponseBodyAsStream(); Element el = queryAsyncJobResult(server, input); s_logger.info("IP forwarding rule was successfully deleted"); - + } else { s_logger.error("IP forwarding rule creation failed with error code: " + responseCode + ". Following URL was sent: " + url); return responseCode; @@ -1911,7 +1911,7 @@ public class TestClientWithAPI { requestToSign = requestToSign.toLowerCase(); signature = signRequest(requestToSign, _secretKey.get()); encodedSignature = URLEncoder.encode(signature, "UTF-8"); - + url = developerServer + "?command=disableStaticNat&apikey=" + encodedApiKey + "&id=" + encodedPublicIpId + "&signature=" + encodedSignature ; client = new HttpClient(); method = new GetMethod(url); @@ -1926,7 +1926,7 @@ public class TestClientWithAPI { s_logger.error("Disable Static NAT failed with error code: " + responseCode + ". Following URL was sent: " + url); return responseCode; } - + // ----------------------------------------- // DISASSOCIATE IP ADDRESSES // ----------------------------------------- @@ -1946,7 +1946,7 @@ public class TestClientWithAPI { InputStream input = method.getResponseBodyAsStream(); Element disassocipel = queryAsyncJobResult(server, input); Map success = getSingleValueFromXML(disassocipel, new String[] {"success"}); - // Map success = getSingleValueFromXML(input, new String[] { "success" }); + // Map success = getSingleValueFromXML(input, new String[] { "success" }); s_logger.info("disassociate ip address..success? " + success.get("success")); } else { s_logger.error("disassociate ip address failed with error code: " + responseCode + ". Following URL was sent: " + url); @@ -1977,7 +1977,7 @@ public class TestClientWithAPI { mac.init(keySpec); mac.update(request.getBytes()); byte[] encryptedBytes = mac.doFinal(); - return Base64.encodeBytes(encryptedBytes); + return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(encryptedBytes); } catch (Exception ex) { s_logger.error("unable to sign request", ex); } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6a864a1/test/src/com/cloud/test/utils/UtilsForTest.java ---------------------------------------------------------------------- diff --git a/test/src/com/cloud/test/utils/UtilsForTest.java b/test/src/com/cloud/test/utils/UtilsForTest.java index 500cea5..6414c0b 100644 --- a/test/src/com/cloud/test/utils/UtilsForTest.java +++ b/test/src/com/cloud/test/utils/UtilsForTest.java @@ -30,208 +30,208 @@ import javax.crypto.spec.SecretKeySpec; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import org.apache.commons.codec.binary.Base64; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import com.cloud.utils.encoding.Base64; import com.cloud.utils.exception.CloudRuntimeException; public class UtilsForTest { - - private static DocumentBuilderFactory factory = DocumentBuilderFactory - .newInstance(); - - public static boolean verifyTags (Map params) { - boolean result = true; - for (String value : params.keySet()) { - if (params.get(value) == null) { - result=false; - } - } - return result; - } - - public static boolean verifyTagValues (Map params, Map pattern) { - boolean result = true; - - if (pattern != null) { - for (String value : pattern.keySet()) { - if (!pattern.get(value).equals(params.get(value))) { - result=false; - System.out.println("Tag " + value + " has " + params.get(value) + " while expected value is: " + pattern.get(value)); - } - } - } - return result; - } - - - public static Map parseXML(InputStream is, - String[] tagNames) { - Map returnValues = new HashMap(); - try { - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - Document doc = docBuilder.parse(is); - Element rootElement = doc.getDocumentElement(); - - for (int i = 0; i < tagNames.length; i++) { - NodeList targetNodes = rootElement - .getElementsByTagName(tagNames[i]); - if (targetNodes.getLength() <= 0) { - System.out.println("no " + tagNames[i] - + " tag in the response"); - returnValues.put(tagNames[i], null); - } else { - returnValues.put(tagNames[i], targetNodes.item(0) - .getTextContent()); - } - } - } catch (Exception ex) { - System.out.println("error processing XML"); - ex.printStackTrace(); - } - return returnValues; - } - - - public static ArrayList> parseMulXML (InputStream is, String[] tagNames){ - ArrayList> returnValues = new ArrayList>(); - - try { - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - Document doc = docBuilder.parse(is); - Element rootElement = doc.getDocumentElement(); - for (int i = 0; i < tagNames.length; i++) { - NodeList targetNodes = rootElement - .getElementsByTagName(tagNames[i]); - if (targetNodes.getLength() <= 0) { - System.out.println("no " + tagNames[i] - + " tag in XML response...returning null"); - } else { - for (int j = 0; j < targetNodes.getLength(); j++) { - HashMap valueList = new HashMap (); - Node node = targetNodes.item(j); - //parse child nodes - NodeList child = node.getChildNodes(); - for (int c=0; c getSingleValueFromXML(InputStream is, - String[] tagNames) { - Map returnValues = new HashMap(); - try { - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - Document doc = docBuilder.parse(is); - Element rootElement = doc.getDocumentElement(); - - for (int i = 0; i < tagNames.length; i++) { - NodeList targetNodes = rootElement - .getElementsByTagName(tagNames[i]); - if (targetNodes.getLength() <= 0) { - System.out.println("no " + tagNames[i] - + " tag in XML response...returning null"); - } else { - returnValues.put(tagNames[i], targetNodes.item(0) - .getTextContent()); - } - } - } catch (Exception ex) { - System.out.println("error processing XML"); - ex.printStackTrace(); - } - return returnValues; - } - - - public static Map> getMultipleValuesFromXML( - InputStream is, String[] tagNames) { - Map> returnValues = new HashMap>(); - try { - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - Document doc = docBuilder.parse(is); - Element rootElement = doc.getDocumentElement(); - for (int i = 0; i < tagNames.length; i++) { - NodeList targetNodes = rootElement - .getElementsByTagName(tagNames[i]); - if (targetNodes.getLength() <= 0) { - System.out.println("no " + tagNames[i] - + " tag in XML response...returning null"); - } else { - List valueList = new ArrayList(); - for (int j = 0; j < targetNodes.getLength(); j++) { - Node node = targetNodes.item(j); - valueList.add(node.getTextContent()); - } - returnValues.put(tagNames[i], valueList); - } - } - } catch (Exception ex) { - System.out.println(ex); - } - return returnValues; - } - - - - public static String signRequest(String request, String key) { - try { - Mac mac = Mac.getInstance("HmacSHA1"); - SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), - "HmacSHA1"); - mac.init(keySpec); - mac.update(request.getBytes()); - byte[] encryptedBytes = mac.doFinal(); - //System.out.println("HmacSHA1 hash: " + encryptedBytes); - return Base64.encodeBytes(encryptedBytes); - } catch (Exception ex) { - System.out.println("unable to sign request"); - ex.printStackTrace(); - } - return null; - } - + + private static DocumentBuilderFactory factory = DocumentBuilderFactory + .newInstance(); + + public static boolean verifyTags (Map params) { + boolean result = true; + for (String value : params.keySet()) { + if (params.get(value) == null) { + result=false; + } + } + return result; + } + + public static boolean verifyTagValues (Map params, Map pattern) { + boolean result = true; + + if (pattern != null) { + for (String value : pattern.keySet()) { + if (!pattern.get(value).equals(params.get(value))) { + result=false; + System.out.println("Tag " + value + " has " + params.get(value) + " while expected value is: " + pattern.get(value)); + } + } + } + return result; + } + + + public static Map parseXML(InputStream is, + String[] tagNames) { + Map returnValues = new HashMap(); + try { + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + Document doc = docBuilder.parse(is); + Element rootElement = doc.getDocumentElement(); + + for (int i = 0; i < tagNames.length; i++) { + NodeList targetNodes = rootElement + .getElementsByTagName(tagNames[i]); + if (targetNodes.getLength() <= 0) { + System.out.println("no " + tagNames[i] + + " tag in the response"); + returnValues.put(tagNames[i], null); + } else { + returnValues.put(tagNames[i], targetNodes.item(0) + .getTextContent()); + } + } + } catch (Exception ex) { + System.out.println("error processing XML"); + ex.printStackTrace(); + } + return returnValues; + } + + + public static ArrayList> parseMulXML (InputStream is, String[] tagNames){ + ArrayList> returnValues = new ArrayList>(); + + try { + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + Document doc = docBuilder.parse(is); + Element rootElement = doc.getDocumentElement(); + for (int i = 0; i < tagNames.length; i++) { + NodeList targetNodes = rootElement + .getElementsByTagName(tagNames[i]); + if (targetNodes.getLength() <= 0) { + System.out.println("no " + tagNames[i] + + " tag in XML response...returning null"); + } else { + for (int j = 0; j < targetNodes.getLength(); j++) { + HashMap valueList = new HashMap (); + Node node = targetNodes.item(j); + //parse child nodes + NodeList child = node.getChildNodes(); + for (int c=0; c getSingleValueFromXML(InputStream is, + String[] tagNames) { + Map returnValues = new HashMap(); + try { + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + Document doc = docBuilder.parse(is); + Element rootElement = doc.getDocumentElement(); + + for (int i = 0; i < tagNames.length; i++) { + NodeList targetNodes = rootElement + .getElementsByTagName(tagNames[i]); + if (targetNodes.getLength() <= 0) { + System.out.println("no " + tagNames[i] + + " tag in XML response...returning null"); + } else { + returnValues.put(tagNames[i], targetNodes.item(0) + .getTextContent()); + } + } + } catch (Exception ex) { + System.out.println("error processing XML"); + ex.printStackTrace(); + } + return returnValues; + } + + + public static Map> getMultipleValuesFromXML( + InputStream is, String[] tagNames) { + Map> returnValues = new HashMap>(); + try { + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + Document doc = docBuilder.parse(is); + Element rootElement = doc.getDocumentElement(); + for (int i = 0; i < tagNames.length; i++) { + NodeList targetNodes = rootElement + .getElementsByTagName(tagNames[i]); + if (targetNodes.getLength() <= 0) { + System.out.println("no " + tagNames[i] + + " tag in XML response...returning null"); + } else { + List valueList = new ArrayList(); + for (int j = 0; j < targetNodes.getLength(); j++) { + Node node = targetNodes.item(j); + valueList.add(node.getTextContent()); + } + returnValues.put(tagNames[i], valueList); + } + } + } catch (Exception ex) { + System.out.println(ex); + } + return returnValues; + } + + + + public static String signRequest(String request, String key) { + try { + Mac mac = Mac.getInstance("HmacSHA1"); + SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), + "HmacSHA1"); + mac.init(keySpec); + mac.update(request.getBytes()); + byte[] encryptedBytes = mac.doFinal(); + //System.out.println("HmacSHA1 hash: " + encryptedBytes); + return Base64.encodeBase64URLSafeString(encryptedBytes); + } catch (Exception ex) { + System.out.println("unable to sign request"); + ex.printStackTrace(); + } + return null; + } + }