mirror of https://github.com/apache/cloudstack.git
cleaning up some line endings
This commit is contained in:
parent
91fd3b772e
commit
ae4b66283a
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <T> String encryptObject(Class<?> clz, T obj) {
|
||||
if(obj == null)
|
||||
return null;
|
||||
|
||||
String json = gson.toJson(obj);
|
||||
return encryptText(json);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> 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 <T> String encryptObject(Class<?> clz, T obj) {
|
||||
if(obj == null)
|
||||
return null;
|
||||
|
||||
String json = gson.toJson(obj);
|
||||
return encryptText(json);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, "<html><body><p>Console access will be ready in a few minutes. Please try it again later.</p></body></html>");
|
||||
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, "<html><body><p>Console access will be ready in a few minutes. Please try it again later.</p></body></html>");
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, Long> {
|
||||
|
||||
VolumeHostVO findByHostVolume(long hostId, long volumeId);
|
||||
|
||||
VolumeHostVO findByVolumeId(long volumeId);
|
||||
|
||||
List<VolumeHostVO> listBySecStorage(long sserverId);
|
||||
|
||||
List<VolumeHostVO> 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, Long> {
|
||||
|
||||
VolumeHostVO findByHostVolume(long hostId, long volumeId);
|
||||
|
||||
VolumeHostVO findByVolumeId(long volumeId);
|
||||
|
||||
List<VolumeHostVO> listBySecStorage(long sserverId);
|
||||
|
||||
List<VolumeHostVO> listDestroyed(long hostId);
|
||||
|
||||
VolumeHostVO findVolumeByZone(long zoneId, long volumeId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<VolumeHostVO, Long> implements VolumeHostDao {
|
||||
|
||||
protected final SearchBuilder<VolumeHostVO> HostVolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> ZoneVolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> VolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> HostSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> 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<VolumeHostVO> 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<VolumeHostVO> 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<VolumeHostVO> sc = VolumeSearch.create();
|
||||
sc.setParameters("volume_id", volumeId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<VolumeHostVO> listBySecStorage(long ssHostId) {
|
||||
SearchCriteria<VolumeHostVO> sc = HostSearch.create();
|
||||
sc.setParameters("host_id", ssHostId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return listAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeHostVO> listDestroyed(long hostId){
|
||||
SearchCriteria<VolumeHostVO> 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<VolumeHostVO, Long> implements VolumeHostDao {
|
||||
|
||||
protected final SearchBuilder<VolumeHostVO> HostVolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> ZoneVolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> VolumeSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> HostSearch;
|
||||
protected final SearchBuilder<VolumeHostVO> 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<VolumeHostVO> 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<VolumeHostVO> 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<VolumeHostVO> sc = VolumeSearch.create();
|
||||
sc.setParameters("volume_id", volumeId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<VolumeHostVO> listBySecStorage(long ssHostId) {
|
||||
SearchCriteria<VolumeHostVO> sc = HostSearch.create();
|
||||
sc.setParameters("host_id", ssHostId);
|
||||
sc.setParameters("destroyed", false);
|
||||
return listAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeHostVO> listDestroyed(long hostId){
|
||||
SearchCriteria<VolumeHostVO> sc = HostDestroyedSearch.create();
|
||||
sc.setParameters("host_id", hostId);
|
||||
sc.setParameters("destroyed", true);
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<IdentityVO, Long> {
|
||||
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<IdentityVO, Long> {
|
||||
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<Long, Long> getAccountDomainInfo(String tableName, Long identityId);
|
||||
}
|
||||
Pair<Long, Long> getAccountDomainInfo(String tableName, Long identityId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<IdentityVO, Long> 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<IdentityVO, Long> 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<IdentityVO, Long> 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<IdentityVO, Long> 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<Long> 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<Long> getNullUuidRecords(String tableName) {
|
||||
List<Long> l = new ArrayList<Long>();
|
||||
|
||||
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<Long> 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<Long> getNullUuidRecords(String tableName) {
|
||||
List<Long> l = new ArrayList<Long>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue