From ae4b66283a834521ec61fde8cd395bf01a361da8 Mon Sep 17 00:00:00 2001 From: David Nalley Date: Mon, 2 Jul 2012 09:50:28 -0400 Subject: [PATCH] cleaning up some line endings --- .../servlet/ConsoleProxyClientParam.java | 204 +++++------ .../ConsoleProxyPasswordBasedEncryptor.java | 242 ++++++------- .../cloud/servlet/ConsoleProxyServlet.java | 258 +++++++------- .../com/cloud/storage/dao/VolumeHostDao.java | 42 +-- .../cloud/storage/dao/VolumeHostDaoImpl.java | 196 +++++------ .../cloud/uuididentity/dao/IdentityDao.java | 22 +- .../uuididentity/dao/IdentityDaoImpl.java | 328 +++++++++--------- 7 files changed, 646 insertions(+), 646 deletions(-) diff --git a/server/src/com/cloud/servlet/ConsoleProxyClientParam.java b/server/src/com/cloud/servlet/ConsoleProxyClientParam.java index a53ab398148..fad19d092a5 100644 --- a/server/src/com/cloud/servlet/ConsoleProxyClientParam.java +++ b/server/src/com/cloud/servlet/ConsoleProxyClientParam.java @@ -1,102 +1,102 @@ -// Copyright 2012 Citrix Systems, Inc. Licensed under the -// Apache License, Version 2.0 (the "License"); you may not use this -// file except in compliance with the License. Citrix Systems, Inc. -// reserves all rights not expressly granted by 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. -// -// Automatically generated by addcopyright.py at 04/03/2012 -package com.cloud.servlet; - -// To maintain independency of console proxy project, we duplicate this class from console proxy project -public class ConsoleProxyClientParam { - private String clientHostAddress; - private int clientHostPort; - private String clientHostPassword; - private String clientTag; - private String ticket; - - private String clientTunnelUrl; - private String clientTunnelSession; - - private String ajaxSessionId; - - public ConsoleProxyClientParam() { - clientHostPort = 0; - } - - public String getClientHostAddress() { - return clientHostAddress; - } - - public void setClientHostAddress(String clientHostAddress) { - this.clientHostAddress = clientHostAddress; - } - - public int getClientHostPort() { - return clientHostPort; - } - - public void setClientHostPort(int clientHostPort) { - this.clientHostPort = clientHostPort; - } - - public String getClientHostPassword() { - return clientHostPassword; - } - - public void setClientHostPassword(String clientHostPassword) { - this.clientHostPassword = clientHostPassword; - } - - public String getClientTag() { - return clientTag; - } - - public void setClientTag(String clientTag) { - this.clientTag = clientTag; - } - - public String getTicket() { - return ticket; - } - - public void setTicket(String ticket) { - this.ticket = ticket; - } - - public String getClientTunnelUrl() { - return clientTunnelUrl; - } - - public void setClientTunnelUrl(String clientTunnelUrl) { - this.clientTunnelUrl = clientTunnelUrl; - } - - public String getClientTunnelSession() { - return clientTunnelSession; - } - - public void setClientTunnelSession(String clientTunnelSession) { - this.clientTunnelSession = clientTunnelSession; - } - - public String getAjaxSessionId() { - return this.ajaxSessionId; - } - - public void setAjaxSessionId(String ajaxSessionId) { - this.ajaxSessionId = ajaxSessionId; - } - - public String getClientMapKey() { - if(clientTag != null && !clientTag.isEmpty()) - return clientTag; - - return clientHostAddress + ":" + clientHostPort; - } -} +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by 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. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.servlet; + +// To maintain independency of console proxy project, we duplicate this class from console proxy project +public class ConsoleProxyClientParam { + private String clientHostAddress; + private int clientHostPort; + private String clientHostPassword; + private String clientTag; + private String ticket; + + private String clientTunnelUrl; + private String clientTunnelSession; + + private String ajaxSessionId; + + public ConsoleProxyClientParam() { + clientHostPort = 0; + } + + public String getClientHostAddress() { + return clientHostAddress; + } + + public void setClientHostAddress(String clientHostAddress) { + this.clientHostAddress = clientHostAddress; + } + + public int getClientHostPort() { + return clientHostPort; + } + + public void setClientHostPort(int clientHostPort) { + this.clientHostPort = clientHostPort; + } + + public String getClientHostPassword() { + return clientHostPassword; + } + + public void setClientHostPassword(String clientHostPassword) { + this.clientHostPassword = clientHostPassword; + } + + public String getClientTag() { + return clientTag; + } + + public void setClientTag(String clientTag) { + this.clientTag = clientTag; + } + + public String getTicket() { + return ticket; + } + + public void setTicket(String ticket) { + this.ticket = ticket; + } + + public String getClientTunnelUrl() { + return clientTunnelUrl; + } + + public void setClientTunnelUrl(String clientTunnelUrl) { + this.clientTunnelUrl = clientTunnelUrl; + } + + public String getClientTunnelSession() { + return clientTunnelSession; + } + + public void setClientTunnelSession(String clientTunnelSession) { + this.clientTunnelSession = clientTunnelSession; + } + + public String getAjaxSessionId() { + return this.ajaxSessionId; + } + + public void setAjaxSessionId(String ajaxSessionId) { + this.ajaxSessionId = ajaxSessionId; + } + + public String getClientMapKey() { + if(clientTag != null && !clientTag.isEmpty()) + return clientTag; + + return clientHostAddress + ":" + clientHostPort; + } +} diff --git a/server/src/com/cloud/servlet/ConsoleProxyPasswordBasedEncryptor.java b/server/src/com/cloud/servlet/ConsoleProxyPasswordBasedEncryptor.java index 4fbd82ccb71..71233657cf6 100644 --- a/server/src/com/cloud/servlet/ConsoleProxyPasswordBasedEncryptor.java +++ b/server/src/com/cloud/servlet/ConsoleProxyPasswordBasedEncryptor.java @@ -1,121 +1,121 @@ -package com.cloud.servlet; - -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -import javax.crypto.BadPaddingException; -import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.spec.SecretKeySpec; - -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -// To maintain independency of console proxy project, we duplicate this class from console proxy project -public class ConsoleProxyPasswordBasedEncryptor { - private static final Logger s_logger = Logger.getLogger(ConsoleProxyPasswordBasedEncryptor.class); - - private String password; - private Gson gson; - - public ConsoleProxyPasswordBasedEncryptor(String password) { - this.password = password; - gson = new GsonBuilder().create(); - } - - public String encryptText(String text) { - if(text == null || text.isEmpty()) - return text; - - assert(password != null); - assert(!password.isEmpty()); - - try { - Cipher cipher = Cipher.getInstance("DES"); - int maxKeySize = 8; - SecretKeySpec keySpec = new SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES"); - cipher.init(Cipher.ENCRYPT_MODE, keySpec); - byte[] encryptedBytes = cipher.doFinal(text.getBytes()); - return Base64.encodeBase64URLSafeString(encryptedBytes); - } catch (NoSuchAlgorithmException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (NoSuchPaddingException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (IllegalBlockSizeException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (BadPaddingException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (InvalidKeyException e) { - s_logger.error("Unexpected exception ", e); - return null; - } - } - - public String decryptText(String encryptedText) { - if(encryptedText == null || encryptedText.isEmpty()) - return encryptedText; - - assert(password != null); - assert(!password.isEmpty()); - - try { - Cipher cipher = Cipher.getInstance("DES"); - int maxKeySize = 8; - SecretKeySpec keySpec = new SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES"); - cipher.init(Cipher.DECRYPT_MODE, keySpec); - - byte[] encryptedBytes = Base64.decodeBase64(encryptedText); - return new String(cipher.doFinal(encryptedBytes)); - } catch (NoSuchAlgorithmException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (NoSuchPaddingException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (IllegalBlockSizeException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (BadPaddingException e) { - s_logger.error("Unexpected exception ", e); - return null; - } catch (InvalidKeyException e) { - s_logger.error("Unexpected exception ", e); - return null; - } - } - - public String encryptObject(Class clz, T obj) { - if(obj == null) - return null; - - String json = gson.toJson(obj); - return encryptText(json); - } - - @SuppressWarnings("unchecked") - public T decryptObject(Class clz, String encrypted) { - if(encrypted == null || encrypted.isEmpty()) - return null; - - String json = decryptText(encrypted); - return (T)gson.fromJson(json, clz); - } - - private static byte[] normalizeKey(byte[] keyBytes, int keySize) { - assert(keySize > 0); - byte[] key = new byte[keySize]; - - for(int i = 0; i < keyBytes.length; i++) - key[i%keySize] ^= keyBytes[i]; - - return key; - } -} +package com.cloud.servlet; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +// To maintain independency of console proxy project, we duplicate this class from console proxy project +public class ConsoleProxyPasswordBasedEncryptor { + private static final Logger s_logger = Logger.getLogger(ConsoleProxyPasswordBasedEncryptor.class); + + private String password; + private Gson gson; + + public ConsoleProxyPasswordBasedEncryptor(String password) { + this.password = password; + gson = new GsonBuilder().create(); + } + + public String encryptText(String text) { + if(text == null || text.isEmpty()) + return text; + + assert(password != null); + assert(!password.isEmpty()); + + try { + Cipher cipher = Cipher.getInstance("DES"); + int maxKeySize = 8; + SecretKeySpec keySpec = new SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES"); + cipher.init(Cipher.ENCRYPT_MODE, keySpec); + byte[] encryptedBytes = cipher.doFinal(text.getBytes()); + return Base64.encodeBase64URLSafeString(encryptedBytes); + } catch (NoSuchAlgorithmException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (NoSuchPaddingException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (IllegalBlockSizeException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (BadPaddingException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (InvalidKeyException e) { + s_logger.error("Unexpected exception ", e); + return null; + } + } + + public String decryptText(String encryptedText) { + if(encryptedText == null || encryptedText.isEmpty()) + return encryptedText; + + assert(password != null); + assert(!password.isEmpty()); + + try { + Cipher cipher = Cipher.getInstance("DES"); + int maxKeySize = 8; + SecretKeySpec keySpec = new SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES"); + cipher.init(Cipher.DECRYPT_MODE, keySpec); + + byte[] encryptedBytes = Base64.decodeBase64(encryptedText); + return new String(cipher.doFinal(encryptedBytes)); + } catch (NoSuchAlgorithmException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (NoSuchPaddingException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (IllegalBlockSizeException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (BadPaddingException e) { + s_logger.error("Unexpected exception ", e); + return null; + } catch (InvalidKeyException e) { + s_logger.error("Unexpected exception ", e); + return null; + } + } + + public String encryptObject(Class clz, T obj) { + if(obj == null) + return null; + + String json = gson.toJson(obj); + return encryptText(json); + } + + @SuppressWarnings("unchecked") + public T decryptObject(Class clz, String encrypted) { + if(encrypted == null || encrypted.isEmpty()) + return null; + + String json = decryptText(encrypted); + return (T)gson.fromJson(json, clz); + } + + private static byte[] normalizeKey(byte[] keyBytes, int keySize) { + assert(keySize > 0); + byte[] key = new byte[keySize]; + + for(int i = 0; i < keyBytes.length; i++) + key[i%keySize] ^= keyBytes[i]; + + return key; + } +} diff --git a/server/src/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/com/cloud/servlet/ConsoleProxyServlet.java index 31320d3f69a..7ff69b03683 100644 --- a/server/src/com/cloud/servlet/ConsoleProxyServlet.java +++ b/server/src/com/cloud/servlet/ConsoleProxyServlet.java @@ -10,8 +10,8 @@ // limitations under the License. // // Automatically generated by addcopyright.py at 04/03/2012 -package com.cloud.servlet; - +package com.cloud.servlet; + import java.io.IOException; import java.net.URLEncoder; import java.util.ArrayList; @@ -47,29 +47,29 @@ import com.cloud.utils.db.Transaction; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineManager; - -/** - * Thumbnail access : /console?cmd=thumbnail&vm=xxx&w=xxx&h=xxx - * Console access : /conosole?cmd=access&vm=xxx - * Authentication : /console?cmd=auth&vm=xxx&sid=xxx - */ -public class ConsoleProxyServlet extends HttpServlet { - private static final long serialVersionUID = -5515382620323808168L; - public static final Logger s_logger = Logger.getLogger(ConsoleProxyServlet.class.getName()); - private static final int DEFAULT_THUMBNAIL_WIDTH = 144; - private static final int DEFAULT_THUMBNAIL_HEIGHT = 110; - + +/** + * Thumbnail access : /console?cmd=thumbnail&vm=xxx&w=xxx&h=xxx + * Console access : /conosole?cmd=access&vm=xxx + * Authentication : /console?cmd=auth&vm=xxx&sid=xxx + */ +public class ConsoleProxyServlet extends HttpServlet { + private static final long serialVersionUID = -5515382620323808168L; + public static final Logger s_logger = Logger.getLogger(ConsoleProxyServlet.class.getName()); + private static final int DEFAULT_THUMBNAIL_WIDTH = 144; + private static final int DEFAULT_THUMBNAIL_HEIGHT = 110; + private final static AccountManager _accountMgr = ComponentLocator.getLocator(ManagementServer.Name).getManager(AccountManager.class); private final static VirtualMachineManager _vmMgr = ComponentLocator.getLocator(ManagementServer.Name).getManager(VirtualMachineManager.class); private final static ManagementServer _ms = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name); private final static IdentityService _identityService = (IdentityService)ComponentLocator.getLocator(ManagementServer.Name).getManager(IdentityService.class); - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) { - doGet(req, resp); - } - - @Override + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) { + doGet(req, resp); + } + + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { try { @@ -120,14 +120,14 @@ public class ConsoleProxyServlet extends HttpServlet { sendResponse(resp, "Access denied. Invalid or inconsistent account is found"); return; } - - String cmd = req.getParameter("cmd"); - if(cmd == null || !isValidCmd(cmd)) { - s_logger.debug("invalid console servlet command: " + cmd); - sendResponse(resp, ""); - return; - } - + + String cmd = req.getParameter("cmd"); + if(cmd == null || !isValidCmd(cmd)) { + s_logger.debug("invalid console servlet command: " + cmd); + sendResponse(resp, ""); + return; + } + String vmIdString = req.getParameter("vm"); Long vmId = _identityService.getIdentityId("vm_instance", vmIdString); if(vmId == null) { @@ -135,102 +135,102 @@ public class ConsoleProxyServlet extends HttpServlet { sendResponse(resp, ""); return; } - - if(!checkSessionPermision(req, vmId, accountObj)) { - sendResponse(resp, "Permission denied"); - return; - } - + + if(!checkSessionPermision(req, vmId, accountObj)) { + sendResponse(resp, "Permission denied"); + return; + } + if(cmd.equalsIgnoreCase("thumbnail")) { handleThumbnailRequest(req, resp, vmId); } else if(cmd.equalsIgnoreCase("access")) { handleAccessRequest(req, resp, vmId); } else { handleAuthRequest(req, resp, vmId); - } - } catch (Throwable e) { - s_logger.error("Unexepected exception in ConsoleProxyServlet", e); - sendResponse(resp, "Server Internal Error"); - } - } - + } + } catch (Throwable e) { + s_logger.error("Unexepected exception in ConsoleProxyServlet", e); + sendResponse(resp, "Server Internal Error"); + } + } + private void handleThumbnailRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) { - VMInstanceVO vm = _vmMgr.findById(vmId); - if(vm == null) { - s_logger.warn("VM " + vmId + " does not exist, sending blank response for thumbnail request"); - sendResponse(resp, ""); - return; - } - - if(vm.getHostId() == null) { - s_logger.warn("VM " + vmId + " lost host info, sending blank response for thumbnail request"); - sendResponse(resp, ""); - return; - } - - HostVO host = _ms.getHostBy(vm.getHostId()); - if(host == null) { - s_logger.warn("VM " + vmId + "'s host does not exist, sending blank response for thumbnail request"); - sendResponse(resp, ""); - return; - } - - String rootUrl = _ms.getConsoleAccessUrlRoot(vmId); - if(rootUrl == null) { - sendResponse(resp, ""); - return; - } - - int w = DEFAULT_THUMBNAIL_WIDTH; - int h = DEFAULT_THUMBNAIL_HEIGHT; - - String value = req.getParameter("w"); - try { - w = Integer.parseInt(value); - } catch(NumberFormatException e) { - } - - value = req.getParameter("h"); - try { - h = Integer.parseInt(value); - } catch(NumberFormatException e) { - } - - try { - resp.sendRedirect(composeThumbnailUrl(rootUrl, vm, host, w, h)); - } catch (IOException e) { + VMInstanceVO vm = _vmMgr.findById(vmId); + if(vm == null) { + s_logger.warn("VM " + vmId + " does not exist, sending blank response for thumbnail request"); + sendResponse(resp, ""); + return; + } + + if(vm.getHostId() == null) { + s_logger.warn("VM " + vmId + " lost host info, sending blank response for thumbnail request"); + sendResponse(resp, ""); + return; + } + + HostVO host = _ms.getHostBy(vm.getHostId()); + if(host == null) { + s_logger.warn("VM " + vmId + "'s host does not exist, sending blank response for thumbnail request"); + sendResponse(resp, ""); + return; + } + + String rootUrl = _ms.getConsoleAccessUrlRoot(vmId); + if(rootUrl == null) { + sendResponse(resp, ""); + return; + } + + int w = DEFAULT_THUMBNAIL_WIDTH; + int h = DEFAULT_THUMBNAIL_HEIGHT; + + String value = req.getParameter("w"); + try { + w = Integer.parseInt(value); + } catch(NumberFormatException e) { + } + + value = req.getParameter("h"); + try { + h = Integer.parseInt(value); + } catch(NumberFormatException e) { + } + + try { + resp.sendRedirect(composeThumbnailUrl(rootUrl, vm, host, w, h)); + } catch (IOException e) { if(s_logger.isInfoEnabled()) { s_logger.info("Client may already close the connection"); - } - } - } - - private void handleAccessRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) { - VMInstanceVO vm = _vmMgr.findById(vmId); - if(vm == null) { - s_logger.warn("VM " + vmId + " does not exist, sending blank response for console access request"); - sendResponse(resp, ""); - return; - } - - if(vm.getHostId() == null) { - s_logger.warn("VM " + vmId + " lost host info, sending blank response for console access request"); - sendResponse(resp, ""); - return; - } - - HostVO host = _ms.getHostBy(vm.getHostId()); - if(host == null) { - s_logger.warn("VM " + vmId + "'s host does not exist, sending blank response for console access request"); - sendResponse(resp, ""); - return; - } - - String rootUrl = _ms.getConsoleAccessUrlRoot(vmId); - if(rootUrl == null) { - sendResponse(resp, "

Console access will be ready in a few minutes. Please try it again later.

"); - return; - } + } + } + } + + private void handleAccessRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) { + VMInstanceVO vm = _vmMgr.findById(vmId); + if(vm == null) { + s_logger.warn("VM " + vmId + " does not exist, sending blank response for console access request"); + sendResponse(resp, ""); + return; + } + + if(vm.getHostId() == null) { + s_logger.warn("VM " + vmId + " lost host info, sending blank response for console access request"); + sendResponse(resp, ""); + return; + } + + HostVO host = _ms.getHostBy(vm.getHostId()); + if(host == null) { + s_logger.warn("VM " + vmId + "'s host does not exist, sending blank response for console access request"); + sendResponse(resp, ""); + return; + } + + String rootUrl = _ms.getConsoleAccessUrlRoot(vmId); + if(rootUrl == null) { + sendResponse(resp, "

Console access will be ready in a few minutes. Please try it again later.

"); + return; + } String vmName = vm.getHostName(); if(vm.getType() == VirtualMachine.Type.User) { @@ -412,14 +412,14 @@ public class ConsoleProxyServlet extends HttpServlet { private void sendResponse(HttpServletResponse resp, String content) { try { resp.setContentType("text/html"); - resp.getWriter().print(content); - } catch(IOException e) { + resp.getWriter().print(content); + } catch(IOException e) { if(s_logger.isInfoEnabled()) { s_logger.info("Client may already close the connection"); - } - } - } - + } + } + } + private boolean checkSessionPermision(HttpServletRequest req, long vmId, Account accountObj) { VMInstanceVO vm = _vmMgr.findById(vmId); @@ -463,15 +463,15 @@ public class ConsoleProxyServlet extends HttpServlet { return false; } - return true; - } - - private boolean isValidCmd(String cmd) { + return true; + } + + private boolean isValidCmd(String cmd) { if(cmd.equalsIgnoreCase("thumbnail") || cmd.equalsIgnoreCase("access") || cmd.equalsIgnoreCase("auth")) { return true; - } - - return false; + } + + return false; } public boolean verifyUser(Long userId) { @@ -605,4 +605,4 @@ public class ConsoleProxyServlet extends HttpServlet { } return sb.toString(); } -} +} diff --git a/server/src/com/cloud/storage/dao/VolumeHostDao.java b/server/src/com/cloud/storage/dao/VolumeHostDao.java index 5dfe2674680..76911f05b52 100755 --- a/server/src/com/cloud/storage/dao/VolumeHostDao.java +++ b/server/src/com/cloud/storage/dao/VolumeHostDao.java @@ -1,21 +1,21 @@ -package com.cloud.storage.dao; - -import java.util.List; - -import com.cloud.host.HostVO; -import com.cloud.storage.VolumeHostVO; -import com.cloud.utils.db.GenericDao; - -public interface VolumeHostDao extends GenericDao { - - VolumeHostVO findByHostVolume(long hostId, long volumeId); - - VolumeHostVO findByVolumeId(long volumeId); - - List listBySecStorage(long sserverId); - - List listDestroyed(long hostId); - - VolumeHostVO findVolumeByZone(long zoneId, long volumeId); - -} +package com.cloud.storage.dao; + +import java.util.List; + +import com.cloud.host.HostVO; +import com.cloud.storage.VolumeHostVO; +import com.cloud.utils.db.GenericDao; + +public interface VolumeHostDao extends GenericDao { + + VolumeHostVO findByHostVolume(long hostId, long volumeId); + + VolumeHostVO findByVolumeId(long volumeId); + + List listBySecStorage(long sserverId); + + List listDestroyed(long hostId); + + VolumeHostVO findVolumeByZone(long zoneId, long volumeId); + +} diff --git a/server/src/com/cloud/storage/dao/VolumeHostDaoImpl.java b/server/src/com/cloud/storage/dao/VolumeHostDaoImpl.java index 95c6efa8e9d..e28f5d59a49 100755 --- a/server/src/com/cloud/storage/dao/VolumeHostDaoImpl.java +++ b/server/src/com/cloud/storage/dao/VolumeHostDaoImpl.java @@ -1,98 +1,98 @@ -package com.cloud.storage.dao; - - -import java.util.List; - -import javax.ejb.Local; - -import com.cloud.host.HostVO; -import com.cloud.storage.VMTemplateHostVO; -import com.cloud.storage.VolumeHostVO; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -@Local(value={VolumeHostDao.class}) -public class VolumeHostDaoImpl extends GenericDaoBase implements VolumeHostDao { - - protected final SearchBuilder HostVolumeSearch; - protected final SearchBuilder ZoneVolumeSearch; - protected final SearchBuilder VolumeSearch; - protected final SearchBuilder HostSearch; - protected final SearchBuilder HostDestroyedSearch; - - VolumeHostDaoImpl(){ - HostVolumeSearch = createSearchBuilder(); - HostVolumeSearch.and("host_id", HostVolumeSearch.entity().getHostId(), SearchCriteria.Op.EQ); - HostVolumeSearch.and("volume_id", HostVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - HostVolumeSearch.and("destroyed", HostVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); - HostVolumeSearch.done(); - - ZoneVolumeSearch = createSearchBuilder(); - ZoneVolumeSearch.and("zone_id", ZoneVolumeSearch.entity().getZoneId(), SearchCriteria.Op.EQ); - ZoneVolumeSearch.and("volume_id", ZoneVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - ZoneVolumeSearch.and("destroyed", ZoneVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); - ZoneVolumeSearch.done(); - - HostSearch = createSearchBuilder(); - HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); - HostSearch.and("destroyed", HostSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); - HostSearch.done(); - - VolumeSearch = createSearchBuilder(); - VolumeSearch.and("volume_id", VolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeSearch.and("destroyed", VolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); - VolumeSearch.done(); - - HostDestroyedSearch = createSearchBuilder(); - HostDestroyedSearch.and("host_id", HostDestroyedSearch.entity().getHostId(), SearchCriteria.Op.EQ); - HostDestroyedSearch.and("destroyed", HostDestroyedSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); - HostDestroyedSearch.done(); - } - - - - @Override - public VolumeHostVO findByHostVolume(long hostId, long volumeId) { - SearchCriteria sc = HostVolumeSearch.create(); - sc.setParameters("host_id", hostId); - sc.setParameters("volume_id", volumeId); - sc.setParameters("destroyed", false); - return findOneIncludingRemovedBy(sc); - } - - @Override - public VolumeHostVO findVolumeByZone(long volumeId, long zoneId) { - SearchCriteria sc = ZoneVolumeSearch.create(); - sc.setParameters("zone_id", zoneId); - sc.setParameters("volume_id", volumeId); - sc.setParameters("destroyed", false); - return findOneIncludingRemovedBy(sc); - } - - @Override - public VolumeHostVO findByVolumeId(long volumeId) { - SearchCriteria sc = VolumeSearch.create(); - sc.setParameters("volume_id", volumeId); - sc.setParameters("destroyed", false); - return findOneBy(sc); - } - - - - @Override - public List listBySecStorage(long ssHostId) { - SearchCriteria sc = HostSearch.create(); - sc.setParameters("host_id", ssHostId); - sc.setParameters("destroyed", false); - return listAll(); - } - - @Override - public List listDestroyed(long hostId){ - SearchCriteria sc = HostDestroyedSearch.create(); - sc.setParameters("host_id", hostId); - sc.setParameters("destroyed", true); - return listIncludingRemovedBy(sc); - } - -} +package com.cloud.storage.dao; + + +import java.util.List; + +import javax.ejb.Local; + +import com.cloud.host.HostVO; +import com.cloud.storage.VMTemplateHostVO; +import com.cloud.storage.VolumeHostVO; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +@Local(value={VolumeHostDao.class}) +public class VolumeHostDaoImpl extends GenericDaoBase implements VolumeHostDao { + + protected final SearchBuilder HostVolumeSearch; + protected final SearchBuilder ZoneVolumeSearch; + protected final SearchBuilder VolumeSearch; + protected final SearchBuilder HostSearch; + protected final SearchBuilder HostDestroyedSearch; + + VolumeHostDaoImpl(){ + HostVolumeSearch = createSearchBuilder(); + HostVolumeSearch.and("host_id", HostVolumeSearch.entity().getHostId(), SearchCriteria.Op.EQ); + HostVolumeSearch.and("volume_id", HostVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); + HostVolumeSearch.and("destroyed", HostVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); + HostVolumeSearch.done(); + + ZoneVolumeSearch = createSearchBuilder(); + ZoneVolumeSearch.and("zone_id", ZoneVolumeSearch.entity().getZoneId(), SearchCriteria.Op.EQ); + ZoneVolumeSearch.and("volume_id", ZoneVolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); + ZoneVolumeSearch.and("destroyed", ZoneVolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); + ZoneVolumeSearch.done(); + + HostSearch = createSearchBuilder(); + HostSearch.and("host_id", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); + HostSearch.and("destroyed", HostSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); + HostSearch.done(); + + VolumeSearch = createSearchBuilder(); + VolumeSearch.and("volume_id", VolumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); + VolumeSearch.and("destroyed", VolumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); + VolumeSearch.done(); + + HostDestroyedSearch = createSearchBuilder(); + HostDestroyedSearch.and("host_id", HostDestroyedSearch.entity().getHostId(), SearchCriteria.Op.EQ); + HostDestroyedSearch.and("destroyed", HostDestroyedSearch.entity().getDestroyed(), SearchCriteria.Op.EQ); + HostDestroyedSearch.done(); + } + + + + @Override + public VolumeHostVO findByHostVolume(long hostId, long volumeId) { + SearchCriteria sc = HostVolumeSearch.create(); + sc.setParameters("host_id", hostId); + sc.setParameters("volume_id", volumeId); + sc.setParameters("destroyed", false); + return findOneIncludingRemovedBy(sc); + } + + @Override + public VolumeHostVO findVolumeByZone(long volumeId, long zoneId) { + SearchCriteria sc = ZoneVolumeSearch.create(); + sc.setParameters("zone_id", zoneId); + sc.setParameters("volume_id", volumeId); + sc.setParameters("destroyed", false); + return findOneIncludingRemovedBy(sc); + } + + @Override + public VolumeHostVO findByVolumeId(long volumeId) { + SearchCriteria sc = VolumeSearch.create(); + sc.setParameters("volume_id", volumeId); + sc.setParameters("destroyed", false); + return findOneBy(sc); + } + + + + @Override + public List listBySecStorage(long ssHostId) { + SearchCriteria sc = HostSearch.create(); + sc.setParameters("host_id", ssHostId); + sc.setParameters("destroyed", false); + return listAll(); + } + + @Override + public List listDestroyed(long hostId){ + SearchCriteria sc = HostDestroyedSearch.create(); + sc.setParameters("host_id", hostId); + sc.setParameters("destroyed", true); + return listIncludingRemovedBy(sc); + } + +} diff --git a/server/src/com/cloud/uuididentity/dao/IdentityDao.java b/server/src/com/cloud/uuididentity/dao/IdentityDao.java index 769aebfe403..de0a07852ce 100644 --- a/server/src/com/cloud/uuididentity/dao/IdentityDao.java +++ b/server/src/com/cloud/uuididentity/dao/IdentityDao.java @@ -11,21 +11,21 @@ // // Automatically generated by addcopyright.py at 04/03/2012 -package com.cloud.uuididentity.dao; - -import com.cloud.api.IdentityMapper; +package com.cloud.uuididentity.dao; + +import com.cloud.api.IdentityMapper; import com.cloud.utils.Pair; -import com.cloud.utils.db.GenericDao; - -public interface IdentityDao extends GenericDao { - Long getIdentityId(IdentityMapper mapper, String identityString); - Long getIdentityId(String tableName, String identityString); - String getIdentityUuid(String tableName, String identityString); +import com.cloud.utils.db.GenericDao; + +public interface IdentityDao extends GenericDao { + Long getIdentityId(IdentityMapper mapper, String identityString); + Long getIdentityId(String tableName, String identityString); + String getIdentityUuid(String tableName, String identityString); void initializeDefaultUuid(String tableName); /** * @param tableName * @param identityId * @return */ - Pair getAccountDomainInfo(String tableName, Long identityId); -} + Pair getAccountDomainInfo(String tableName, Long identityId); +} diff --git a/server/src/com/cloud/uuididentity/dao/IdentityDaoImpl.java b/server/src/com/cloud/uuididentity/dao/IdentityDaoImpl.java index a86dbcb0447..9f2f2fbb42a 100644 --- a/server/src/com/cloud/uuididentity/dao/IdentityDaoImpl.java +++ b/server/src/com/cloud/uuididentity/dao/IdentityDaoImpl.java @@ -10,8 +10,8 @@ // limitations under the License. // // Automatically generated by addcopyright.py at 04/03/2012 -package com.cloud.uuididentity.dao; - +package com.cloud.uuididentity.dao; + import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -29,28 +29,28 @@ import com.cloud.utils.Pair; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.Transaction; - -@Local(value={IdentityDao.class}) -public class IdentityDaoImpl extends GenericDaoBase implements IdentityDao { - private static final Logger s_logger = Logger.getLogger(IdentityDaoImpl.class); - - public IdentityDaoImpl() { - } - - @DB - public Long getIdentityId(IdentityMapper mapper, String identityString) { - assert(mapper.entityTableName() != null); - return getIdentityId(mapper.entityTableName(), identityString); - } - - @DB - public Long getIdentityId(String tableName, String identityString) { - assert(tableName != null); - assert(identityString != null); - - PreparedStatement pstmt = null; - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { + +@Local(value={IdentityDao.class}) +public class IdentityDaoImpl extends GenericDaoBase implements IdentityDao { + private static final Logger s_logger = Logger.getLogger(IdentityDaoImpl.class); + + public IdentityDaoImpl() { + } + + @DB + public Long getIdentityId(IdentityMapper mapper, String identityString) { + assert(mapper.entityTableName() != null); + return getIdentityId(mapper.entityTableName(), identityString); + } + + @DB + public Long getIdentityId(String tableName, String identityString) { + assert(tableName != null); + assert(identityString != null); + + PreparedStatement pstmt = null; + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { try { try { pstmt = txn.prepareAutoCloseStatement(String.format("SELECT uuid FROM `%s`", tableName)); @@ -58,41 +58,41 @@ public class IdentityDaoImpl extends GenericDaoBase implements } catch (SQLException e) { throw new InvalidParameterValueException("uuid field doesn't exist in table " + tableName); } - - pstmt = txn.prepareAutoCloseStatement( - String.format("SELECT id FROM `%s` WHERE id=? OR uuid=?", tableName) - - // TODO : after graceful period, use following line turn on more secure check - // String.format("SELECT id FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", mapper.entityTableName()) - ); - - long id = 0; - try { - // TODO : use regular expression to determine - id = Long.parseLong(identityString); - } catch(NumberFormatException e) { - // this could happen when it is a uuid string, so catch and ignore it - } - - pstmt.setLong(1, id); - pstmt.setString(2, identityString); - - ResultSet rs = pstmt.executeQuery(); - if(rs.next()) { - return rs.getLong(1); - } else { - if(id == -1L) - return id; - - throw new InvalidParameterValueException("Object " + tableName + "(uuid: " + identityString + ") does not exist."); - } - } catch (SQLException e) { - s_logger.error("Unexpected exception ", e); - } - } finally { - txn.close(); - } - return null; + + pstmt = txn.prepareAutoCloseStatement( + String.format("SELECT id FROM `%s` WHERE id=? OR uuid=?", tableName) + + // TODO : after graceful period, use following line turn on more secure check + // String.format("SELECT id FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", mapper.entityTableName()) + ); + + long id = 0; + try { + // TODO : use regular expression to determine + id = Long.parseLong(identityString); + } catch(NumberFormatException e) { + // this could happen when it is a uuid string, so catch and ignore it + } + + pstmt.setLong(1, id); + pstmt.setString(2, identityString); + + ResultSet rs = pstmt.executeQuery(); + if(rs.next()) { + return rs.getLong(1); + } else { + if(id == -1L) + return id; + + throw new InvalidParameterValueException("Object " + tableName + "(uuid: " + identityString + ") does not exist."); + } + } catch (SQLException e) { + s_logger.error("Unexpected exception ", e); + } + } finally { + txn.close(); + } + return null; } @DB @@ -130,109 +130,109 @@ public class IdentityDaoImpl extends GenericDaoBase implements } finally { txn.close(); } - } - + } + @DB - @Override - public String getIdentityUuid(String tableName, String identityString) { - assert(tableName != null); - assert(identityString != null); - - PreparedStatement pstmt = null; - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - try { - pstmt = txn.prepareAutoCloseStatement( - String.format("SELECT uuid FROM `%s` WHERE id=? OR uuid=?", tableName) - // String.format("SELECT uuid FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", tableName) - ); - - long id = 0; - try { - // TODO : use regular expression to determine - id = Long.parseLong(identityString); - } catch(NumberFormatException e) { - // this could happen when it is a uuid string, so catch and ignore it - } - - pstmt.setLong(1, id); - pstmt.setString(2, identityString); - - ResultSet rs = pstmt.executeQuery(); - if(rs.next()) { - String uuid = rs.getString(1); - if(uuid != null && !uuid.isEmpty()) - return uuid; - return identityString; - } - } catch (SQLException e) { - s_logger.error("Unexpected exception ", e); - } - } finally { - txn.close(); - } - - return identityString; - } - - @DB - public void initializeDefaultUuid(String tableName) { - assert(tableName != null); - List l = getNullUuidRecords(tableName); - - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - try { - txn.start(); - for(Long id : l) { - setInitialUuid(tableName, id); - } - txn.commit(); - } catch (SQLException e) { - txn.rollback(); - s_logger.error("Unexpected exception ", e); - } - } finally { - txn.close(); - } - } - - @DB - List getNullUuidRecords(String tableName) { - List l = new ArrayList(); - - PreparedStatement pstmt = null; - Transaction txn = Transaction.open(Transaction.CLOUD_DB); - try { - try { - pstmt = txn.prepareAutoCloseStatement( - String.format("SELECT id FROM `%s` WHERE uuid IS NULL", tableName) - ); - - ResultSet rs = pstmt.executeQuery(); - while(rs.next()) { - l.add(rs.getLong(1)); - } - } catch (SQLException e) { - s_logger.error("Unexpected exception ", e); - } - } finally { - txn.close(); - } - return l; - } - - @DB - void setInitialUuid(String tableName, long id) throws SQLException { - Transaction txn = Transaction.currentTxn(); - - PreparedStatement pstmtUpdate = null; - pstmtUpdate = txn.prepareAutoCloseStatement( - String.format("UPDATE `%s` SET uuid=? WHERE id=?", tableName) - ); - - pstmtUpdate.setString(1, UUID.randomUUID().toString()); - pstmtUpdate.setLong(2, id); - pstmtUpdate.executeUpdate(); - } -} + @Override + public String getIdentityUuid(String tableName, String identityString) { + assert(tableName != null); + assert(identityString != null); + + PreparedStatement pstmt = null; + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + try { + pstmt = txn.prepareAutoCloseStatement( + String.format("SELECT uuid FROM `%s` WHERE id=? OR uuid=?", tableName) + // String.format("SELECT uuid FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", tableName) + ); + + long id = 0; + try { + // TODO : use regular expression to determine + id = Long.parseLong(identityString); + } catch(NumberFormatException e) { + // this could happen when it is a uuid string, so catch and ignore it + } + + pstmt.setLong(1, id); + pstmt.setString(2, identityString); + + ResultSet rs = pstmt.executeQuery(); + if(rs.next()) { + String uuid = rs.getString(1); + if(uuid != null && !uuid.isEmpty()) + return uuid; + return identityString; + } + } catch (SQLException e) { + s_logger.error("Unexpected exception ", e); + } + } finally { + txn.close(); + } + + return identityString; + } + + @DB + public void initializeDefaultUuid(String tableName) { + assert(tableName != null); + List l = getNullUuidRecords(tableName); + + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + try { + txn.start(); + for(Long id : l) { + setInitialUuid(tableName, id); + } + txn.commit(); + } catch (SQLException e) { + txn.rollback(); + s_logger.error("Unexpected exception ", e); + } + } finally { + txn.close(); + } + } + + @DB + List getNullUuidRecords(String tableName) { + List l = new ArrayList(); + + PreparedStatement pstmt = null; + Transaction txn = Transaction.open(Transaction.CLOUD_DB); + try { + try { + pstmt = txn.prepareAutoCloseStatement( + String.format("SELECT id FROM `%s` WHERE uuid IS NULL", tableName) + ); + + ResultSet rs = pstmt.executeQuery(); + while(rs.next()) { + l.add(rs.getLong(1)); + } + } catch (SQLException e) { + s_logger.error("Unexpected exception ", e); + } + } finally { + txn.close(); + } + return l; + } + + @DB + void setInitialUuid(String tableName, long id) throws SQLException { + Transaction txn = Transaction.currentTxn(); + + PreparedStatement pstmtUpdate = null; + pstmtUpdate = txn.prepareAutoCloseStatement( + String.format("UPDATE `%s` SET uuid=? WHERE id=?", tableName) + ); + + pstmtUpdate.setString(1, UUID.randomUUID().toString()); + pstmtUpdate.setLong(2, id); + pstmtUpdate.executeUpdate(); + } +}