mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 18:12:35 +01:00
Added more changes to the api
This commit is contained in:
parent
d4207060b4
commit
d5d8f27cad
@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.cloud.exception;
|
||||||
|
|
||||||
|
import com.cloud.utils.SerialVersionUID;
|
||||||
|
|
||||||
|
public class ResourceUnavailableException extends Exception {
|
||||||
|
private static final long serialVersionUID = SerialVersionUID.ResourceUnavailableException;
|
||||||
|
|
||||||
|
public ResourceUnavailableException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceUnavailableException(String msg, Throwable cause) {
|
||||||
|
super(msg, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,7 +26,7 @@ import com.cloud.utils.SerialVersionUID;
|
|||||||
* problem with.
|
* problem with.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class StorageUnavailableException extends Exception {
|
public class StorageUnavailableException extends ResourceUnavailableException {
|
||||||
Object _obj;
|
Object _obj;
|
||||||
|
|
||||||
private static final long serialVersionUID = SerialVersionUID.StorageUnavailableException;
|
private static final long serialVersionUID = SerialVersionUID.StorageUnavailableException;
|
||||||
|
|||||||
@ -3,6 +3,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.network.element;
|
package com.cloud.network.element;
|
||||||
|
|
||||||
|
import com.cloud.exception.ConcurrentOperationException;
|
||||||
|
import com.cloud.exception.InsufficientCapacityException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.network.NetworkConfiguration;
|
import com.cloud.network.NetworkConfiguration;
|
||||||
import com.cloud.offering.NetworkOffering;
|
import com.cloud.offering.NetworkOffering;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
@ -20,18 +23,11 @@ public interface NetworkElement extends Adapter {
|
|||||||
* @param offering network offering that originated the network configuration.
|
* @param offering network offering that originated the network configuration.
|
||||||
* @return true if network configuration is now usable; false if not; null if not handled by this element.
|
* @return true if network configuration is now usable; false if not; null if not handled by this element.
|
||||||
*/
|
*/
|
||||||
Boolean implement(NetworkConfiguration config, NetworkOffering offering, Account user);
|
Boolean implement(NetworkConfiguration config, NetworkOffering offering, Account user) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||||
|
|
||||||
/**
|
Boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||||
* Prepare the nic profile to be used within the network.
|
|
||||||
* @param config
|
|
||||||
* @param nic
|
|
||||||
* @param offering
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user);
|
|
||||||
|
|
||||||
Boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user);
|
Boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||||
|
|
||||||
Boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user);
|
Boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,11 +35,16 @@ public class VirtualMachineProfile {
|
|||||||
List<DiskProfile> _disks;
|
List<DiskProfile> _disks;
|
||||||
List<NicProfile> _nics;
|
List<NicProfile> _nics;
|
||||||
String _os;
|
String _os;
|
||||||
|
String _password;
|
||||||
|
|
||||||
public VirtualMachineProfile(VirtualMachine.Type type) {
|
public VirtualMachineProfile(VirtualMachine.Type type) {
|
||||||
this._type = type;
|
this._type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return _password;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return _vm.getInstanceName();
|
return _vm.getInstanceName();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
package com.cloud.user;
|
package com.cloud.user;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.utils.ProcessUtil;
|
import com.cloud.utils.ProcessUtil;
|
||||||
|
|
||||||
@ -32,7 +32,8 @@ public class UserContext {
|
|||||||
private Long accountId;
|
private Long accountId;
|
||||||
private Long domainId;
|
private Long domainId;
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
private Object accountObject;
|
private Account accountObject;
|
||||||
|
private Long eventId;
|
||||||
|
|
||||||
private boolean apiServer;
|
private boolean apiServer;
|
||||||
|
|
||||||
@ -41,13 +42,14 @@ public class UserContext {
|
|||||||
public UserContext() {
|
public UserContext() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserContext(Long userId, Object accountObject, String accountName, Long accountId, Long domainId, String sessionId, boolean apiServer) {
|
public UserContext(Long userId, Account accountObject, String accountName, Long accountId, Long domainId, String sessionId, boolean apiServer) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.accountObject = accountObject;
|
this.accountObject = accountObject;
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
this.domainId = domainId;
|
this.domainId = domainId;
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
this.apiServer = apiServer;
|
this.apiServer = apiServer;
|
||||||
|
this.eventId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getUserId() {
|
public Long getUserId() {
|
||||||
@ -60,6 +62,14 @@ public class UserContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEventId(long eventId) {
|
||||||
|
this.eventId = eventId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getEventId() {
|
||||||
|
return eventId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserId(Long userId) {
|
public void setUserId(Long userId) {
|
||||||
@ -102,11 +112,11 @@ public class UserContext {
|
|||||||
return sessionId;
|
return sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getAccountObject() {
|
public Account getAccount() {
|
||||||
return accountObject;
|
return accountObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccountObject(Object accountObject) {
|
public void setAccount(Account accountObject) {
|
||||||
this.accountObject = accountObject;
|
this.accountObject = accountObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,19 +140,19 @@ public class UserContext {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateContext(Long userId, Object accountObject, String accountName, Long accountId, Long domainId, String sessionId) {
|
public static void updateContext(Long userId, Account accountObject, String accountName, Long accountId, Long domainId, String sessionId) {
|
||||||
UserContext context = current();
|
UserContext context = current();
|
||||||
assert(context != null) : "Context should be already setup before you can call this one";
|
assert(context != null) : "Context should be already setup before you can call this one";
|
||||||
|
|
||||||
context.setUserId(userId);
|
context.setUserId(userId);
|
||||||
context.setAccountObject(accountObject);
|
context.setAccount(accountObject);
|
||||||
context.setAccountName(accountName);
|
context.setAccountName(accountName);
|
||||||
context.setAccountId(accountId);
|
context.setAccountId(accountId);
|
||||||
context.setDomainId(domainId);
|
context.setDomainId(domainId);
|
||||||
context.setSessionKey(sessionId);
|
context.setSessionKey(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerContext(Long userId, Object accountObject, String accountName, Long accountId, Long domainId, String sessionId, boolean apiServer) {
|
public static void registerContext(Long userId, Account accountObject, String accountName, Long accountId, Long domainId, String sessionId, boolean apiServer) {
|
||||||
s_currentContext.set(new UserContext(userId, accountObject, accountName, accountId, domainId, sessionId, apiServer));
|
s_currentContext.set(new UserContext(userId, accountObject, accountName, accountId, domainId, sessionId, apiServer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
server/src/com/cloud/account/SecurityManager.java
Normal file
25
server/src/com/cloud/account/SecurityManager.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.cloud.account;
|
||||||
|
|
||||||
|
import com.cloud.utils.component.Manager;
|
||||||
|
|
||||||
|
public interface SecurityManager extends Manager {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.agent;
|
package com.cloud.agent;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -156,7 +155,7 @@ public interface AgentManager extends Manager {
|
|||||||
* @return HostStats
|
* @return HostStats
|
||||||
* @throws InternalErrorException
|
* @throws InternalErrorException
|
||||||
*/
|
*/
|
||||||
HostStats getHostStatistics(long hostId) throws InternalErrorException;
|
HostStats getHostStatistics(long hostId);
|
||||||
|
|
||||||
Long getGuestOSCategoryId(long hostId);
|
Long getGuestOSCategoryId(long hostId);
|
||||||
|
|
||||||
|
|||||||
@ -97,7 +97,6 @@ import com.cloud.dc.dao.VlanDao;
|
|||||||
import com.cloud.event.dao.EventDao;
|
import com.cloud.event.dao.EventDao;
|
||||||
import com.cloud.exception.AgentUnavailableException;
|
import com.cloud.exception.AgentUnavailableException;
|
||||||
import com.cloud.exception.DiscoveryException;
|
import com.cloud.exception.DiscoveryException;
|
||||||
import com.cloud.exception.InternalErrorException;
|
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.OperationTimedoutException;
|
import com.cloud.exception.OperationTimedoutException;
|
||||||
import com.cloud.exception.UnsupportedVersionException;
|
import com.cloud.exception.UnsupportedVersionException;
|
||||||
@ -1246,8 +1245,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HostStats getHostStatistics(long hostId) throws InternalErrorException
|
public HostStats getHostStatistics(long hostId) {
|
||||||
{
|
|
||||||
Answer answer = easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(),hostId));
|
Answer answer = easySend(hostId, new GetHostStatsCommand(_hostDao.findById(hostId).getGuid(), _hostDao.findById(hostId).getName(),hostId));
|
||||||
|
|
||||||
if (answer != null && (answer instanceof UnsupportedAnswer)) {
|
if (answer != null && (answer instanceof UnsupportedAnswer)) {
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import com.cloud.configuration.ConfigurationManager;
|
|||||||
import com.cloud.consoleproxy.ConsoleProxyManager;
|
import com.cloud.consoleproxy.ConsoleProxyManager;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
|
import com.cloud.network.DomainRouterService;
|
||||||
import com.cloud.network.NetworkManager;
|
import com.cloud.network.NetworkManager;
|
||||||
import com.cloud.network.security.NetworkGroupManager;
|
import com.cloud.network.security.NetworkGroupManager;
|
||||||
import com.cloud.server.ManagementServer;
|
import com.cloud.server.ManagementServer;
|
||||||
@ -65,6 +66,7 @@ public class ApiDispatcher {
|
|||||||
private StorageManager _storageMgr;
|
private StorageManager _storageMgr;
|
||||||
private TemplateManager _templateMgr;
|
private TemplateManager _templateMgr;
|
||||||
private UserVmManager _userVmMgr;
|
private UserVmManager _userVmMgr;
|
||||||
|
private DomainRouterService _domainRouterService;
|
||||||
|
|
||||||
// singleton class
|
// singleton class
|
||||||
private static ApiDispatcher s_instance = new ApiDispatcher();
|
private static ApiDispatcher s_instance = new ApiDispatcher();
|
||||||
@ -86,6 +88,7 @@ public class ApiDispatcher {
|
|||||||
_storageMgr = locator.getManager(StorageManager.class);
|
_storageMgr = locator.getManager(StorageManager.class);
|
||||||
_templateMgr = locator.getManager(TemplateManager.class);
|
_templateMgr = locator.getManager(TemplateManager.class);
|
||||||
_userVmMgr = locator.getManager(UserVmManager.class);
|
_userVmMgr = locator.getManager(UserVmManager.class);
|
||||||
|
_domainRouterService = locator.getManager(DomainRouterService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map<String, String> params) {
|
public Long dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map<String, String> params) {
|
||||||
@ -129,6 +132,9 @@ public class ApiDispatcher {
|
|||||||
case UserVmManager:
|
case UserVmManager:
|
||||||
mgr = _userVmMgr;
|
mgr = _userVmMgr;
|
||||||
break;
|
break;
|
||||||
|
case DomainRouterService:
|
||||||
|
mgr = _domainRouterService;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -201,6 +207,9 @@ public class ApiDispatcher {
|
|||||||
case UserVmManager:
|
case UserVmManager:
|
||||||
mgr = _userVmMgr;
|
mgr = _userVmMgr;
|
||||||
break;
|
break;
|
||||||
|
case DomainRouterService:
|
||||||
|
mgr = _domainRouterService;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -363,7 +363,7 @@ public class ApiServer implements HttpRequestHandler {
|
|||||||
|
|
||||||
UserContext ctx = UserContext.current();
|
UserContext ctx = UserContext.current();
|
||||||
Long userId = ctx.getUserId();
|
Long userId = ctx.getUserId();
|
||||||
Account account = (Account)ctx.getAccountObject();
|
Account account = (Account)ctx.getAccount();
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
params.put("ctxUserId", userId.toString());
|
params.put("ctxUserId", userId.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,8 @@ public class ApiServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
try {
|
try {
|
||||||
processRequest(req, resp);
|
processRequest(req, resp);
|
||||||
} finally {
|
} finally {
|
||||||
@ -60,6 +61,7 @@ public class ApiServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
try {
|
try {
|
||||||
processRequest(req, resp);
|
processRequest(req, resp);
|
||||||
@ -198,7 +200,7 @@ public class ApiServlet extends HttpServlet {
|
|||||||
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "no command specified");
|
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "no command specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserContext.updateContext(userId, accountObj, account, ((Account)accountObj).getId(), domainId, session.getId());
|
UserContext.updateContext(userId, (Account)accountObj, account, ((Account)accountObj).getId(), domainId, session.getId());
|
||||||
} else {
|
} else {
|
||||||
// Invalidate the session to ensure we won't allow a request across management server restarts if the userId was serialized to the
|
// Invalidate the session to ensure we won't allow a request across management server restarts if the userId was serialized to the
|
||||||
// stored session
|
// stored session
|
||||||
|
|||||||
@ -42,7 +42,7 @@ public abstract class BaseCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Manager {
|
public enum Manager {
|
||||||
AccountManager, AgentManager, ConfigManager, ManagementServer, NetworkGroupManager, NetworkManager, StorageManager, UserVmManager, SnapshotManager, TemplateManager, ConsoleProxyManager
|
AccountManager, AgentManager, ConfigManager, ManagementServer, NetworkGroupManager, NetworkManager, StorageManager, UserVmManager, SnapshotManager, TemplateManager, ConsoleProxyManager, DomainRouterService
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Extract these out into a separate file
|
// FIXME: Extract these out into a separate file
|
||||||
|
|||||||
@ -106,7 +106,7 @@ public class AssociateIPAddrCmd extends BaseCmd {
|
|||||||
ipResponse.setForVirtualNetwork(forVirtualNetworks);
|
ipResponse.setForVirtualNetwork(forVirtualNetworks);
|
||||||
|
|
||||||
//show this info to admin only
|
//show this info to admin only
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || isAdmin(account.getType())) {
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
ipResponse.setVlanId(ipAddress.getVlanDbId());
|
ipResponse.setVlanId(ipAddress.getVlanDbId());
|
||||||
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanDbId()).getVlanId());
|
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanDbId()).getVlanId());
|
||||||
|
|||||||
@ -153,7 +153,7 @@ public class AuthorizeNetworkGroupIngressCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || isAdmin(account.getType())) {
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
if ((domainId != null) && (accountName != null)) {
|
if ((domainId != null) && (accountName != null)) {
|
||||||
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
||||||
|
|||||||
@ -82,7 +82,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,7 +71,7 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -139,7 +139,7 @@ public class CopyIsoCmd extends BaseAsyncCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//set status
|
//set status
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
boolean isAdmin = false;
|
boolean isAdmin = false;
|
||||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||||
isAdmin = true;
|
isAdmin = true;
|
||||||
|
|||||||
@ -142,7 +142,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//set status
|
//set status
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
boolean isAdmin = false;
|
boolean isAdmin = false;
|
||||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||||
isAdmin = true;
|
isAdmin = true;
|
||||||
|
|||||||
@ -112,7 +112,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || isAdmin(account.getType())) {
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
if ((domainId != null) && (accountName != null)) {
|
if ((domainId != null) && (accountName != null)) {
|
||||||
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
||||||
|
|||||||
@ -68,7 +68,7 @@ public class DeleteUserCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,7 +163,7 @@ public class DeployVMCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || isAdmin(account.getType())) {
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
if ((domainId != null) && (accountName != null)) {
|
if ((domainId != null) && (accountName != null)) {
|
||||||
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
||||||
|
|||||||
299
server/src/com/cloud/api/commands/DeployVmCmd.java
Normal file
299
server/src/com/cloud/api/commands/DeployVmCmd.java
Normal file
@ -0,0 +1,299 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.BaseAsyncCmd;
|
||||||
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
|
import com.cloud.api.Parameter;
|
||||||
|
import com.cloud.api.response.UserVmResponse;
|
||||||
|
import com.cloud.event.EventTypes;
|
||||||
|
import com.cloud.offering.ServiceOffering;
|
||||||
|
import com.cloud.storage.VMTemplateVO;
|
||||||
|
import com.cloud.user.Account;
|
||||||
|
import com.cloud.user.User;
|
||||||
|
import com.cloud.user.UserContext;
|
||||||
|
import com.cloud.uservm.UserVm;
|
||||||
|
import com.cloud.vm.InstanceGroupVO;
|
||||||
|
|
||||||
|
@Implementation(createMethod="createVirtualMachine", method="startVirtualMachine", manager=Manager.UserVmManager, description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.")
|
||||||
|
public class DeployVmCmd extends BaseAsyncCmd {
|
||||||
|
public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName());
|
||||||
|
|
||||||
|
private static final String s_name = "deployvirtualmachineresponse";
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
//////////////// API parameters /////////////////////
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Parameter(name="account", type=CommandType.STRING, description="an optional account for the virtual machine. Must be used with domainId.")
|
||||||
|
private String accountName;
|
||||||
|
|
||||||
|
@Parameter(name="diskofferingid", type=CommandType.LONG, description="the ID of the disk offering for the virtual machine. If the template is of ISO format, the diskOfferingId is for the root disk volume. Otherwise this parameter is used to dinidcate the offering for the data disk volume. If the templateId parameter passed is from a Template object, the diskOfferingId refers to a DATA Disk Volume created. If the templateId parameter passed is from an ISO object, the diskOfferingId refers to a ROOT Disk Volume created.")
|
||||||
|
private Long diskOfferingId;
|
||||||
|
|
||||||
|
@Parameter(name="displayname", type=CommandType.STRING, description="an optional user generated name for the virtual machine")
|
||||||
|
private String displayName;
|
||||||
|
|
||||||
|
@Parameter(name="domainid", type=CommandType.LONG, description="an optional domainId for the virtual machine. If the account parameter is used, domainId must also be used.")
|
||||||
|
private Long domainId;
|
||||||
|
|
||||||
|
@Parameter(name="group", type=CommandType.STRING, description="an optional group for the virtual machine")
|
||||||
|
private String group;
|
||||||
|
|
||||||
|
@Parameter(name="hypervisor", type=CommandType.STRING, description="the hypervisor on which to deploy the virtual machine")
|
||||||
|
private String hypervisor;
|
||||||
|
|
||||||
|
@Parameter(name="networkgrouplist", type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of network groups that going to be applied to the virtual machine. Should be passed only when vm is created from service offering with Direct Attach Network support")
|
||||||
|
private List<String> networkGroupList;
|
||||||
|
|
||||||
|
@Parameter(name="serviceofferingid", type=CommandType.LONG, required=true, description="the ID of the service offering for the virtual machine")
|
||||||
|
private Long serviceOfferingId;
|
||||||
|
|
||||||
|
@Parameter(name="size", type=CommandType.LONG, description="the arbitrary size for the DATADISK volume. Mutually exclusive with diskOfferingId")
|
||||||
|
private Long size;
|
||||||
|
|
||||||
|
@Parameter(name="templateid", type=CommandType.LONG, required=true, description="the ID of the template for the virtual machine")
|
||||||
|
private Long templateId;
|
||||||
|
|
||||||
|
@Parameter(name="userdata", type=CommandType.STRING, description="an optional binary data that can be sent to the virtual machine upon a successful deployment. This binary data must be base64 encoded before adding it to the request. Currently only HTTP GET is supported. Using HTTP GET (via querystring), you can send up to 2KB of data after base64 encoding.")
|
||||||
|
private String userData;
|
||||||
|
|
||||||
|
@Parameter(name="zoneid", type=CommandType.LONG, required=true, description="availability zone for the virtual machine")
|
||||||
|
private Long zoneId;
|
||||||
|
|
||||||
|
// unexposed parameter needed for serializing/deserializing the command
|
||||||
|
@Parameter(name="password", type=CommandType.STRING, expose=false)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
/////////////////// Accessors ///////////////////////
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getAccountName() {
|
||||||
|
return accountName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDiskOfferingId() {
|
||||||
|
return diskOfferingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDomainId() {
|
||||||
|
return domainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroup() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHypervisor() {
|
||||||
|
return hypervisor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getNetworkGroupList() {
|
||||||
|
return networkGroupList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getServiceOfferingId() {
|
||||||
|
return serviceOfferingId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTemplateId() {
|
||||||
|
return templateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserData() {
|
||||||
|
return userData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getZoneId() {
|
||||||
|
return zoneId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not exposed parameter
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
/////////////// API Implementation///////////////////
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return s_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getResultObjectName() {
|
||||||
|
return "virtualmachine";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getAccountId() {
|
||||||
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
|
if ((domainId != null) && (accountName != null)) {
|
||||||
|
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
||||||
|
if (userAccount != null) {
|
||||||
|
return userAccount.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account != null) {
|
||||||
|
return account.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEventType() {
|
||||||
|
return EventTypes.EVENT_VM_CREATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEventDescription() {
|
||||||
|
return "deploying Vm";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @SuppressWarnings("unchecked")
|
||||||
|
public UserVmResponse getResponse() {
|
||||||
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
|
|
||||||
|
UserVmResponse response = new UserVmResponse();
|
||||||
|
response.setId(userVm.getId());
|
||||||
|
response.setName(userVm.getName());
|
||||||
|
response.setCreated(userVm.getCreated());
|
||||||
|
response.setZoneId(userVm.getDataCenterId());
|
||||||
|
response.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
||||||
|
response.setIpAddress(userVm.getPrivateIpAddress());
|
||||||
|
response.setServiceOfferingId(userVm.getServiceOfferingId());
|
||||||
|
response.setHaEnable(userVm.isHaEnabled());
|
||||||
|
|
||||||
|
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId());
|
||||||
|
if (group != null) {
|
||||||
|
response.setGroup(group.getName());
|
||||||
|
response.setGroupId(group.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userVm.getDisplayName() == null || userVm.getDisplayName().length() == 0) {
|
||||||
|
response.setDisplayName(userVm.getName());
|
||||||
|
} else {
|
||||||
|
response.setDisplayName(userVm.getDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userVm.getState() != null) {
|
||||||
|
response.setState(userVm.getState().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
VMTemplateVO template = ApiDBUtils.findTemplateById(userVm.getTemplateId());
|
||||||
|
|
||||||
|
Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
|
||||||
|
if (acct != null) {
|
||||||
|
response.setAccountName(acct.getAccountName());
|
||||||
|
response.setDomainId(acct.getDomainId());
|
||||||
|
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
Long userId = UserContext.current().getUserId();
|
||||||
|
if (userId == null) {
|
||||||
|
userId = User.UID_SYSTEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
//this is for the case where the admin deploys a vm for a normal user
|
||||||
|
User userExecutingCmd = ApiDBUtils.findUserById(userId);
|
||||||
|
Account acctForUserExecutingCmd = ApiDBUtils.findAccountById(Long.valueOf(userExecutingCmd.getAccountId()));
|
||||||
|
if ((BaseCmd.isAdmin(acctForUserExecutingCmd.getType()) && (userVm.getHostId() != null)) || (BaseCmd.isAdmin(acct.getType()) && (userVm.getHostId() != null))) {
|
||||||
|
response.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
|
||||||
|
response.setHostId(userVm.getHostId());
|
||||||
|
}
|
||||||
|
|
||||||
|
String templateName = "none";
|
||||||
|
boolean templatePasswordEnabled = false;
|
||||||
|
String templateDisplayText = null;
|
||||||
|
|
||||||
|
if (template != null) {
|
||||||
|
templateName = template.getName();
|
||||||
|
templatePasswordEnabled = template.getEnablePassword();
|
||||||
|
templateDisplayText = template.getDisplayText();
|
||||||
|
if (templateDisplayText == null) {
|
||||||
|
templateDisplayText = templateName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (templatePasswordEnabled) { // FIXME: where will the password come from in this case?
|
||||||
|
response.setPassword(getPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ISO Info
|
||||||
|
Long isoId = userVm.getIsoId();
|
||||||
|
if (isoId != null) {
|
||||||
|
VMTemplateVO iso = ApiDBUtils.findTemplateById(isoId.longValue());
|
||||||
|
if (iso != null) {
|
||||||
|
response.setIsoId(isoId.longValue());
|
||||||
|
response.setIsoName(iso.getName());
|
||||||
|
response.setTemplateId(isoId.longValue());
|
||||||
|
response.setTemplateName(iso.getName());
|
||||||
|
|
||||||
|
templateDisplayText = iso.getDisplayText();
|
||||||
|
if(templateDisplayText == null)
|
||||||
|
templateDisplayText = iso.getName();
|
||||||
|
response.setIsoDisplayText(templateDisplayText);
|
||||||
|
response.setTemplateDisplayText(templateDisplayText);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response.setTemplateId(userVm.getTemplateId());
|
||||||
|
response.setTemplateName(templateName);
|
||||||
|
response.setTemplateDisplayText(templateDisplayText);
|
||||||
|
response.setPasswordEnabled(templatePasswordEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
|
||||||
|
response.setServiceOfferingId(userVm.getServiceOfferingId());
|
||||||
|
response.setServiceOfferingName(offering.getName());
|
||||||
|
|
||||||
|
response.setCpuNumber(offering.getCpu());
|
||||||
|
response.setCpuSpeed(offering.getSpeed());
|
||||||
|
response.setMemory(offering.getRamSize());
|
||||||
|
|
||||||
|
response.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId()));
|
||||||
|
|
||||||
|
response.setResponseName(getName());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -63,7 +63,7 @@ public class DestroyConsoleProxyCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,7 +71,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class DisableUserCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -215,7 +215,7 @@ public class ListAccountsCmd extends BaseListCmd {
|
|||||||
acctResponse.setVmRunning(vmRunning);
|
acctResponse.setVmRunning(vmRunning);
|
||||||
|
|
||||||
//show this info to admins only
|
//show this info to admins only
|
||||||
Account ctxAccount = (Account)UserContext.current().getAccountObject();
|
Account ctxAccount = (Account)UserContext.current().getAccount();
|
||||||
if ((ctxAccount == null) || isAdmin(ctxAccount.getType())) {
|
if ((ctxAccount == null) || isAdmin(ctxAccount.getType())) {
|
||||||
acctResponse.setState(account.getState());
|
acctResponse.setState(account.getState());
|
||||||
acctResponse.setCleanupRequired(account.getNeedsCleanup());
|
acctResponse.setCleanupRequired(account.getNeedsCleanup());
|
||||||
|
|||||||
@ -157,7 +157,7 @@ public class ListIsosCmd extends BaseListCmd {
|
|||||||
|
|
||||||
boolean isAdmin = false;
|
boolean isAdmin = false;
|
||||||
boolean isAccountSpecific = true;
|
boolean isAccountSpecific = true;
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||||
isAdmin = true;
|
isAdmin = true;
|
||||||
if ((accountName == null) || (domainId == null)) {
|
if ((accountName == null) || (domainId == null)) {
|
||||||
|
|||||||
@ -137,7 +137,7 @@ public class ListPublicIpAddressesCmd extends BaseListCmd {
|
|||||||
ipResponse.setForVirtualNetwork(forVirtualNetworks);
|
ipResponse.setForVirtualNetwork(forVirtualNetworks);
|
||||||
|
|
||||||
//show this info to admin only
|
//show this info to admin only
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || isAdmin(account.getType())) {
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
ipResponse.setVlanId(ipAddress.getVlanDbId());
|
ipResponse.setVlanId(ipAddress.getVlanDbId());
|
||||||
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanDbId()).getVlanId());
|
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanDbId()).getVlanId());
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public class ListTemplateOrIsoPermissionsCmd extends BaseListCmd {
|
|||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public TemplatePermissionsResponse getResponse() {
|
public TemplatePermissionsResponse getResponse() {
|
||||||
List<String> accountNames = (List<String>)getResponseObject();
|
List<String> accountNames = (List<String>)getResponseObject();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
boolean isAdmin = ((account == null) || isAdmin(account.getType()));
|
boolean isAdmin = ((account == null) || isAdmin(account.getType()));
|
||||||
Long templateOwnerDomain = null;
|
Long templateOwnerDomain = null;
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(id);
|
VMTemplateVO template = ApiDBUtils.findTemplateById(id);
|
||||||
|
|||||||
@ -129,7 +129,7 @@ public class ListTemplatesCmd extends BaseListCmd {
|
|||||||
|
|
||||||
boolean isAdmin = false;
|
boolean isAdmin = false;
|
||||||
boolean isAccountSpecific = true;
|
boolean isAccountSpecific = true;
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||||
isAdmin = true;
|
isAdmin = true;
|
||||||
if ((accountName == null) || (domainId == null)) {
|
if ((accountName == null) || (domainId == null)) {
|
||||||
|
|||||||
@ -164,7 +164,7 @@ public class ListVMsCmd extends BaseListCmd {
|
|||||||
userVmResponse.setZoneId(userVm.getDataCenterId());
|
userVmResponse.setZoneId(userVm.getDataCenterId());
|
||||||
userVmResponse.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
userVmResponse.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
//if user is an admin, display host id
|
//if user is an admin, display host id
|
||||||
if (((account == null) || isAdmin(account.getType())) && (userVm.getHostId() != null)) {
|
if (((account == null) || isAdmin(account.getType())) && (userVm.getHostId() != null)) {
|
||||||
userVmResponse.setHostId(userVm.getHostId());
|
userVmResponse.setHostId(userVm.getHostId());
|
||||||
|
|||||||
@ -64,7 +64,7 @@ public class ListZonesByCmd extends BaseListCmd {
|
|||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public ListResponse<ZoneResponse> getResponse() {
|
public ListResponse<ZoneResponse> getResponse() {
|
||||||
List<DataCenterVO> dataCenters = (List<DataCenterVO>)getResponseObject();
|
List<DataCenterVO> dataCenters = (List<DataCenterVO>)getResponseObject();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
|
|
||||||
ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
|
ListResponse<ZoneResponse> response = new ListResponse<ZoneResponse>();
|
||||||
List<ZoneResponse> zoneResponses = new ArrayList<ZoneResponse>();
|
List<ZoneResponse> zoneResponses = new ArrayList<ZoneResponse>();
|
||||||
|
|||||||
@ -64,7 +64,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,7 +80,7 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,7 +127,7 @@ public class RevokeNetworkGroupIngressCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if ((account == null) || isAdmin(account.getType())) {
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
if ((domainId != null) && (accountName != null)) {
|
if ((domainId != null) && (accountName != null)) {
|
||||||
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
Account userAccount = ApiDBUtils.findAccountByNameDomain(accountName, domainId);
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import com.cloud.uservm.UserVm;
|
|||||||
import com.cloud.vm.DomainRouterVO;
|
import com.cloud.vm.DomainRouterVO;
|
||||||
|
|
||||||
|
|
||||||
@Implementation(method="startRouter", manager=Manager.NetworkManager, description="Starts a router.")
|
@Implementation(method="startRouter", manager=Manager.DomainRouterService, description="Starts a router.")
|
||||||
public class StartRouterCmd extends BaseAsyncCmd {
|
public class StartRouterCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(StartRouterCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(StartRouterCmd.class.getName());
|
||||||
private static final String s_name = "startrouterresponse";
|
private static final String s_name = "startrouterresponse";
|
||||||
@ -57,6 +57,7 @@ public class StartRouterCmd extends BaseAsyncCmd {
|
|||||||
/////////////// API Implementation///////////////////
|
/////////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import com.cloud.uservm.UserVm;
|
|||||||
import com.cloud.vm.DomainRouterVO;
|
import com.cloud.vm.DomainRouterVO;
|
||||||
|
|
||||||
|
|
||||||
@Implementation(method="stopRouter", manager=Manager.NetworkManager, description="Stops a router.")
|
@Implementation(method="stopRouter", manager=Manager.DomainRouterService, description="Stops a router.")
|
||||||
public class StopRouterCmd extends BaseAsyncCmd {
|
public class StopRouterCmd extends BaseAsyncCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(StopRouterCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(StopRouterCmd.class.getName());
|
||||||
private static final String s_name = "stoprouterresponse";
|
private static final String s_name = "stoprouterresponse";
|
||||||
@ -56,6 +56,7 @@ public class StopRouterCmd extends BaseAsyncCmd {
|
|||||||
/////////////// API Implementation///////////////////
|
/////////////// API Implementation///////////////////
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAccountId() {
|
public long getAccountId() {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
return account.getId();
|
return account.getId();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,6 +93,7 @@ import com.cloud.exception.AgentUnavailableException;
|
|||||||
import com.cloud.exception.ConcurrentOperationException;
|
import com.cloud.exception.ConcurrentOperationException;
|
||||||
import com.cloud.exception.InsufficientCapacityException;
|
import com.cloud.exception.InsufficientCapacityException;
|
||||||
import com.cloud.exception.OperationTimedoutException;
|
import com.cloud.exception.OperationTimedoutException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.ha.HighAvailabilityManager;
|
import com.cloud.ha.HighAvailabilityManager;
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
@ -537,7 +538,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsoleProxyVO start2(long proxyVmId, long startEventId) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
|
public ConsoleProxyVO start2(long proxyVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
|
||||||
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
|
ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId);
|
||||||
DeploymentPlan plan = new DataCenterDeployment(proxy.getDataCenterId(), 1);
|
DeploymentPlan plan = new DataCenterDeployment(proxy.getDataCenterId(), 1);
|
||||||
AccountVO systemAcct = _accountMgr.getSystemAccount();
|
AccountVO systemAcct = _accountMgr.getSystemAccount();
|
||||||
|
|||||||
43
server/src/com/cloud/network/DomainRouterService.java
Normal file
43
server/src/com/cloud/network/DomainRouterService.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.cloud.network;
|
||||||
|
|
||||||
|
import com.cloud.api.commands.StartRouterCmd;
|
||||||
|
import com.cloud.api.commands.StopRouterCmd;
|
||||||
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
|
import com.cloud.utils.component.Manager;
|
||||||
|
import com.cloud.vm.DomainRouterVO;
|
||||||
|
|
||||||
|
public interface DomainRouterService extends Manager {
|
||||||
|
/**
|
||||||
|
* Starts domain router
|
||||||
|
* @param cmd the command specifying router's id
|
||||||
|
* @return DomainRouter object
|
||||||
|
* @throws InvalidParameterValueException, PermissionDeniedException
|
||||||
|
*/
|
||||||
|
DomainRouterVO startRouter(StartRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops domain router
|
||||||
|
* @param cmd the command specifying router's id
|
||||||
|
* @return router if successful, null otherwise
|
||||||
|
* @throws InvalidParameterValueException, PermissionDeniedException
|
||||||
|
*/
|
||||||
|
DomainRouterVO stopRouter(StopRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||||
|
}
|
||||||
@ -50,6 +50,7 @@ import com.cloud.exception.InvalidParameterValueException;
|
|||||||
import com.cloud.exception.NetworkRuleConflictException;
|
import com.cloud.exception.NetworkRuleConflictException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.offerings.NetworkOfferingVO;
|
import com.cloud.offerings.NetworkOfferingVO;
|
||||||
import com.cloud.service.ServiceOfferingVO;
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
@ -305,7 +306,7 @@ public interface NetworkManager extends Manager {
|
|||||||
|
|
||||||
List<NicProfile> allocate(VirtualMachineProfile vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException;
|
List<NicProfile> allocate(VirtualMachineProfile vm, List<Pair<NetworkConfigurationVO, NicProfile>> networks) throws InsufficientCapacityException;
|
||||||
|
|
||||||
NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException;
|
NicTO[] prepare(VirtualMachineProfile profile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||||
void release(VirtualMachineProfile vmProfile);
|
void release(VirtualMachineProfile vmProfile);
|
||||||
|
|
||||||
<K extends VMInstanceVO> List<NicVO> getNics(K vm);
|
<K extends VMInstanceVO> List<NicVO> getNics(K vm);
|
||||||
|
|||||||
@ -90,6 +90,7 @@ import com.cloud.exception.NetworkRuleConflictException;
|
|||||||
import com.cloud.exception.OperationTimedoutException;
|
import com.cloud.exception.OperationTimedoutException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
import com.cloud.host.dao.HostDao;
|
import com.cloud.host.dao.HostDao;
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
@ -156,8 +157,8 @@ import com.cloud.vm.dao.UserVmDao;
|
|||||||
/**
|
/**
|
||||||
* NetworkManagerImpl implements NetworkManager.
|
* NetworkManagerImpl implements NetworkManager.
|
||||||
*/
|
*/
|
||||||
@Local(value={NetworkManager.class})
|
@Local(value={NetworkManager.class, DomainRouterService.class})
|
||||||
public class NetworkManagerImpl implements NetworkManager {
|
public class NetworkManagerImpl implements NetworkManager, DomainRouterService {
|
||||||
private static final Logger s_logger = Logger.getLogger(NetworkManagerImpl.class);
|
private static final Logger s_logger = Logger.getLogger(NetworkManagerImpl.class);
|
||||||
|
|
||||||
String _name;
|
String _name;
|
||||||
@ -493,7 +494,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Long zoneId = cmd.getZoneId();
|
Long zoneId = cmd.getZoneId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
|
|
||||||
@ -823,7 +824,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if an admin account was passed in, or no account was passed in, make sure we honor the accountName/domainId parameters
|
// if an admin account was passed in, or no account was passed in, make sure we honor the accountName/domainId parameters
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if ((account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
if ((account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||||
if (!_domainDao.isChildDomain(account.getDomainId(), userVM.getDomainId())) {
|
if (!_domainDao.isChildDomain(account.getDomainId(), userVM.getDomainId())) {
|
||||||
@ -916,7 +917,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
@Override
|
@Override
|
||||||
public List<FirewallRuleVO> listPortForwardingRules(ListPortForwardingRulesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<FirewallRuleVO> listPortForwardingRules(ListPortForwardingRulesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
String ipAddress = cmd.getIpAddress();
|
String ipAddress = cmd.getIpAddress();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
IPAddressVO ipAddressVO = _ipAddressDao.findById(ipAddress);
|
IPAddressVO ipAddressVO = _ipAddressDao.findById(ipAddress);
|
||||||
if (ipAddressVO == null) {
|
if (ipAddressVO == null) {
|
||||||
@ -971,7 +972,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
cmd.synchronizeCommand("Router", syncObject.getId());
|
cmd.synchronizeCommand("Router", syncObject.getId());
|
||||||
|
|
||||||
// Permission check...
|
// Permission check...
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if ((account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)) {
|
if ((account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)) {
|
||||||
if (!_domainDao.isChildDomain(account.getDomainId(), loadBalancer.getDomainId())) {
|
if (!_domainDao.isChildDomain(account.getDomainId(), loadBalancer.getDomainId())) {
|
||||||
@ -1213,7 +1214,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
throw new InvalidParameterValueException("Unable to create load balancer rule, cannot find account owner for ip " + publicIp);
|
throw new InvalidParameterValueException("Unable to create load balancer rule, cannot find account owner for ip " + publicIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if ((account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
if ((account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||||
if (!_domainDao.isChildDomain(account.getDomainId(), ipAddr.getDomainId())) {
|
if (!_domainDao.isChildDomain(account.getDomainId(), ipAddr.getDomainId())) {
|
||||||
@ -1773,7 +1774,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException {
|
public NicTO[] prepare(VirtualMachineProfile vmProfile, DeployDestination dest, Account user) throws InsufficientAddressCapacityException, InsufficientVirtualNetworkCapcityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||||
List<NicVO> nics = _nicDao.listBy(vmProfile.getId());
|
List<NicVO> nics = _nicDao.listBy(vmProfile.getId());
|
||||||
NicTO[] nicTos = new NicTO[nics.size()];
|
NicTO[] nicTos = new NicTO[nics.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -1856,7 +1857,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
public boolean removeFromLoadBalancer(RemoveFromLoadBalancerRuleCmd cmd) throws InvalidParameterValueException {
|
public boolean removeFromLoadBalancer(RemoveFromLoadBalancerRuleCmd cmd) throws InvalidParameterValueException {
|
||||||
|
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long loadBalancerId = cmd.getId();
|
Long loadBalancerId = cmd.getId();
|
||||||
Long vmInstanceId = cmd.getVirtualMachineId();
|
Long vmInstanceId = cmd.getVirtualMachineId();
|
||||||
List<Long> instanceIds = cmd.getVirtualMachineIds();
|
List<Long> instanceIds = cmd.getVirtualMachineIds();
|
||||||
@ -1968,7 +1969,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
public boolean deleteLoadBalancerRule(DeleteLoadBalancerRuleCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
public boolean deleteLoadBalancerRule(DeleteLoadBalancerRuleCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||||
Long loadBalancerId = cmd.getId();
|
Long loadBalancerId = cmd.getId();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
///verify input parameters
|
///verify input parameters
|
||||||
LoadBalancerVO loadBalancer = _loadBalancerDao.findById(loadBalancerId);
|
LoadBalancerVO loadBalancer = _loadBalancerDao.findById(loadBalancerId);
|
||||||
@ -2084,7 +2085,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
String algorithm = cmd.getAlgorithm();
|
String algorithm = cmd.getAlgorithm();
|
||||||
String name = cmd.getName();
|
String name = cmd.getName();
|
||||||
String description = cmd.getDescription();
|
String description = cmd.getDescription();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//Verify input parameters
|
//Verify input parameters
|
||||||
LoadBalancerVO loadBalancer = _loadBalancerDao.findById(loadBalancerId);
|
LoadBalancerVO loadBalancer = _loadBalancerDao.findById(loadBalancerId);
|
||||||
@ -2172,7 +2173,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
public boolean deleteNetworkRuleConfig(DeletePortForwardingServiceRuleCmd cmd) throws PermissionDeniedException {
|
public boolean deleteNetworkRuleConfig(DeletePortForwardingServiceRuleCmd cmd) throws PermissionDeniedException {
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long netRuleId = cmd.getId();
|
Long netRuleId = cmd.getId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//If command is executed via 8096 port, set userId to the id of System account (1)
|
//If command is executed via 8096 port, set userId to the id of System account (1)
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
@ -2259,7 +2260,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
|
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
String ipAddress = cmd.getIpAddress();
|
String ipAddress = cmd.getIpAddress();
|
||||||
|
|
||||||
// Verify input parameters
|
// Verify input parameters
|
||||||
@ -2349,7 +2350,7 @@ public class NetworkManagerImpl implements NetworkManager {
|
|||||||
public boolean deleteIpForwardingRule(DeleteIPForwardingRuleCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
|
public boolean deleteIpForwardingRule(DeleteIPForwardingRuleCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
|
||||||
Long ruleId = cmd.getId();
|
Long ruleId = cmd.getId();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//verify input parameters here
|
//verify input parameters here
|
||||||
FirewallRuleVO rule = _firewallRulesDao.findById(ruleId);
|
FirewallRuleVO rule = _firewallRulesDao.findById(ruleId);
|
||||||
|
|||||||
@ -23,6 +23,9 @@ import javax.ejb.Local;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import com.cloud.exception.ConcurrentOperationException;
|
||||||
|
import com.cloud.exception.InsufficientCapacityException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.network.Network.TrafficType;
|
import com.cloud.network.Network.TrafficType;
|
||||||
import com.cloud.network.NetworkConfiguration;
|
import com.cloud.network.NetworkConfiguration;
|
||||||
import com.cloud.network.NetworkConfiguration.State;
|
import com.cloud.network.NetworkConfiguration.State;
|
||||||
@ -35,8 +38,14 @@ import com.cloud.offering.NetworkOffering.GuestIpType;
|
|||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.utils.component.AdapterBase;
|
import com.cloud.utils.component.AdapterBase;
|
||||||
import com.cloud.utils.component.Inject;
|
import com.cloud.utils.component.Inject;
|
||||||
|
import com.cloud.vm.DomainRouterVO;
|
||||||
import com.cloud.vm.NicProfile;
|
import com.cloud.vm.NicProfile;
|
||||||
|
import com.cloud.vm.UserVmManager;
|
||||||
|
import com.cloud.vm.UserVmVO;
|
||||||
|
import com.cloud.vm.VirtualMachine.Type;
|
||||||
import com.cloud.vm.VirtualMachineProfile;
|
import com.cloud.vm.VirtualMachineProfile;
|
||||||
|
import com.cloud.vm.dao.DomainRouterDao;
|
||||||
|
import com.cloud.vm.dao.UserVmDao;
|
||||||
|
|
||||||
|
|
||||||
@Local(value=NetworkElement.class)
|
@Local(value=NetworkElement.class)
|
||||||
@ -46,9 +55,12 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||||||
@Inject NetworkConfigurationDao _networkConfigDao;
|
@Inject NetworkConfigurationDao _networkConfigDao;
|
||||||
@Inject NetworkManager _networkMgr;
|
@Inject NetworkManager _networkMgr;
|
||||||
@Inject DomainRouterManager _routerMgr;
|
@Inject DomainRouterManager _routerMgr;
|
||||||
|
@Inject UserVmManager _userVmMgr;
|
||||||
|
@Inject UserVmDao _userVmDao;
|
||||||
|
@Inject DomainRouterDao _routerDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean implement(NetworkConfiguration config, NetworkOffering offering, Account user) {
|
public Boolean implement(NetworkConfiguration config, NetworkOffering offering, Account user) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException {
|
||||||
if (offering.getGuestIpType() != GuestIpType.Virtualized) {
|
if (offering.getGuestIpType() != GuestIpType.Virtualized) {
|
||||||
s_logger.trace("Not handling guest ip type = " + offering.getGuestIpType());
|
s_logger.trace("Not handling guest ip type = " + offering.getGuestIpType());
|
||||||
return null;
|
return null;
|
||||||
@ -79,25 +91,50 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DomainRouterVO router;
|
||||||
|
router = _routerMgr.deploy(publicConfig, guestConfig, offering, user);
|
||||||
|
if (router == null) {
|
||||||
|
s_logger.debug("Unable to deploy the router for " + guestConfig);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) {
|
public Boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) throws ConcurrentOperationException {
|
||||||
// TODO Auto-generated method stub
|
if (config.getTrafficType() != TrafficType.Guest || vm.getType() != Type.User) {
|
||||||
return false;
|
s_logger.trace("Domain Router only cares about guest network and User VMs");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserVmVO userVm = _userVmDao.findById(vm.getId());
|
||||||
|
|
||||||
|
return _routerMgr.addVirtualMachineToGuestNetwork(userVm, vm.getPassword(), 1) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) {
|
public Boolean release(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering, Account user) {
|
||||||
// TODO Auto-generated method stub
|
if (config.getTrafficType() != TrafficType.Guest || vm.getType() != Type.User) {
|
||||||
return false;
|
s_logger.trace("Domain Router only cares about guest network and User VMs");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user) {
|
public Boolean shutdown(NetworkConfiguration config, NetworkOffering offering, Account user) throws ConcurrentOperationException {
|
||||||
// TODO Auto-generated method stub
|
if (config.getTrafficType() != TrafficType.Guest) {
|
||||||
return false;
|
s_logger.trace("Domain Router only cares about guet network.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DomainRouterVO router = _routerDao.findByNetworkConfiguration(config.getId());
|
||||||
|
if (router == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return _routerMgr.stopRouter(router.getId(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DomainRouterElement() {
|
protected DomainRouterElement() {
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||||||
import com.cloud.exception.InsufficientCapacityException;
|
import com.cloud.exception.InsufficientCapacityException;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.network.NetworkConfiguration;
|
import com.cloud.network.NetworkConfiguration;
|
||||||
import com.cloud.offering.NetworkOffering;
|
import com.cloud.offering.NetworkOffering;
|
||||||
import com.cloud.service.ServiceOfferingVO;
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
@ -167,5 +167,5 @@ public interface DomainRouterManager extends Manager {
|
|||||||
DomainRouterVO getRouter(long accountId, long zoneId);
|
DomainRouterVO getRouter(long accountId, long zoneId);
|
||||||
DomainRouterVO getRouter(String publicIpAddress);
|
DomainRouterVO getRouter(String publicIpAddress);
|
||||||
|
|
||||||
DomainRouterVO deploy(NetworkConfiguration publicConfig, NetworkConfiguration virtualConfig, NetworkOffering offering, Account owner) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException;
|
DomainRouterVO deploy(NetworkConfiguration publicConfig, NetworkConfiguration virtualConfig, NetworkOffering offering, Account owner) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -95,6 +95,7 @@ import com.cloud.exception.InsufficientCapacityException;
|
|||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.OperationTimedoutException;
|
import com.cloud.exception.OperationTimedoutException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.ha.HighAvailabilityManager;
|
import com.cloud.ha.HighAvailabilityManager;
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
@ -657,7 +658,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||||||
public boolean upgradeRouter(UpgradeRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public boolean upgradeRouter(UpgradeRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Long routerId = cmd.getId();
|
Long routerId = cmd.getId();
|
||||||
Long serviceOfferingId = cmd.getServiceOfferingId();
|
Long serviceOfferingId = cmd.getServiceOfferingId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
DomainRouterVO router = _routerDao.findById(routerId);
|
DomainRouterVO router = _routerDao.findById(routerId);
|
||||||
if (router == null) {
|
if (router == null) {
|
||||||
@ -747,7 +748,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||||||
@Override
|
@Override
|
||||||
public DomainRouterVO startRouter(StartRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
public DomainRouterVO startRouter(StartRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||||
Long routerId = cmd.getId();
|
Long routerId = cmd.getId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//verify parameters
|
//verify parameters
|
||||||
DomainRouterVO router = _routerDao.findById(routerId);
|
DomainRouterVO router = _routerDao.findById(routerId);
|
||||||
@ -1226,7 +1227,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||||||
@Override
|
@Override
|
||||||
public DomainRouterVO stopRouter(StopRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
public DomainRouterVO stopRouter(StopRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||||
Long routerId = cmd.getId();
|
Long routerId = cmd.getId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
// verify parameters
|
// verify parameters
|
||||||
DomainRouterVO router = _routerDao.findById(routerId);
|
DomainRouterVO router = _routerDao.findById(routerId);
|
||||||
@ -1374,7 +1375,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||||||
@Override
|
@Override
|
||||||
public boolean rebootRouter(RebootRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
public boolean rebootRouter(RebootRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||||
Long routerId = cmd.getId();
|
Long routerId = cmd.getId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//verify parameters
|
//verify parameters
|
||||||
DomainRouterVO router = _routerDao.findById(routerId);
|
DomainRouterVO router = _routerDao.findById(routerId);
|
||||||
@ -1995,7 +1996,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, VirtualMach
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
public DomainRouterVO deploy(NetworkConfiguration publicConfig, NetworkConfiguration virtualConfig, NetworkOffering offering, Account owner) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException {
|
public DomainRouterVO deploy(NetworkConfiguration publicConfig, NetworkConfiguration virtualConfig, NetworkOffering offering, Account owner) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException, ResourceUnavailableException {
|
||||||
long dcId = publicConfig.getDataCenterId();
|
long dcId = publicConfig.getDataCenterId();
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
|||||||
@ -428,7 +428,7 @@ public class NetworkGroupManagerImpl implements NetworkGroupManager {
|
|||||||
Integer icmpCode = cmd.getIcmpCode();
|
Integer icmpCode = cmd.getIcmpCode();
|
||||||
List<String> cidrList = cmd.getCidrList();
|
List<String> cidrList = cmd.getCidrList();
|
||||||
Map groupList = cmd.getUserNetworkGroupList();
|
Map groupList = cmd.getUserNetworkGroupList();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Integer startPortOrType = null;
|
Integer startPortOrType = null;
|
||||||
@ -638,7 +638,7 @@ public class NetworkGroupManagerImpl implements NetworkGroupManager {
|
|||||||
public boolean revokeNetworkGroupIngress(RevokeNetworkGroupIngressCmd cmd) {
|
public boolean revokeNetworkGroupIngress(RevokeNetworkGroupIngressCmd cmd) {
|
||||||
|
|
||||||
//input validation
|
//input validation
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Integer startPort = cmd.getStartPort();
|
Integer startPort = cmd.getStartPort();
|
||||||
@ -855,7 +855,7 @@ public class NetworkGroupManagerImpl implements NetworkGroupManager {
|
|||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if ((account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
if ((account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||||
if ((domainId != null) && (accountName != null)) {
|
if ((domainId != null) && (accountName != null)) {
|
||||||
@ -1115,7 +1115,7 @@ public class NetworkGroupManagerImpl implements NetworkGroupManager {
|
|||||||
String name = cmd.getName();
|
String name = cmd.getName();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
|
|
||||||
if (!_enabled) {
|
if (!_enabled) {
|
||||||
return ;
|
return ;
|
||||||
@ -1193,7 +1193,7 @@ public class NetworkGroupManagerImpl implements NetworkGroupManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<NetworkGroupRulesVO> searchForNetworkGroupRules(ListNetworkGroupsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
|
public List<NetworkGroupRulesVO> searchForNetworkGroupRules(ListNetworkGroupsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
|
|||||||
@ -998,7 +998,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
@Override
|
@Override
|
||||||
public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
public boolean enableUser(EnableUserCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||||
Long userId = cmd.getId();
|
Long userId = cmd.getId();
|
||||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
Account adminAccount = UserContext.current().getAccount();
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
//Check if user exists in the system
|
//Check if user exists in the system
|
||||||
@ -1028,7 +1028,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
public boolean lockUser(LockUserCmd cmd) {
|
public boolean lockUser(LockUserCmd cmd) {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
Account adminAccount = UserContext.current().getAccount();
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
|
|
||||||
// Check if user with id exists in the system
|
// Check if user with id exists in the system
|
||||||
@ -1088,7 +1088,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
|
|
||||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
Account adminAccount = UserContext.current().getAccount();
|
||||||
if ((adminAccount != null) && !_domainDao.isChildDomain(adminAccount.getDomainId(), domainId)) {
|
if ((adminAccount != null) && !_domainDao.isChildDomain(adminAccount.getDomainId(), domainId)) {
|
||||||
throw new PermissionDeniedException("Failed to disable account " + accountName + " in domain " + domainId + ", permission denied.");
|
throw new PermissionDeniedException("Failed to disable account " + accountName + " in domain " + domainId + ", permission denied.");
|
||||||
}
|
}
|
||||||
@ -1148,7 +1148,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check if user performing the action is allowed to modify this account
|
//Check if user performing the action is allowed to modify this account
|
||||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
Account adminAccount = UserContext.current().getAccount();
|
||||||
if ((adminAccount != null) && isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
|
if ((adminAccount != null) && isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
|
||||||
throw new PermissionDeniedException("Invalid account " + accountName + " in domain " + domainId + " given, permission denied");
|
throw new PermissionDeniedException("Invalid account " + accountName + " in domain " + domainId + " given, permission denied");
|
||||||
}
|
}
|
||||||
@ -1211,7 +1211,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check if user performing the action is allowed to modify this account
|
//Check if user performing the action is allowed to modify this account
|
||||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
Account adminAccount = UserContext.current().getAccount();
|
||||||
if ((adminAccount != null) && isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
|
if ((adminAccount != null) && isChildDomain(adminAccount.getDomainId(), account.getDomainId())) {
|
||||||
throw new PermissionDeniedException("Invalid account " + accountName + " in domain " + domainId + " given, permission denied");
|
throw new PermissionDeniedException("Invalid account " + accountName + " in domain " + domainId + " given, permission denied");
|
||||||
}
|
}
|
||||||
@ -1265,7 +1265,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the account is an admin type, return an error. We do not allow this
|
// If the account is an admin type, return an error. We do not allow this
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
if (account != null && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
|
if (account != null && (account.getId() == Account.ACCOUNT_ID_SYSTEM)) {
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "user id : " + id + " is system account, update is not allowed");
|
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "user id : " + id + " is system account, update is not allowed");
|
||||||
@ -1756,7 +1756,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
public UserVm deployVirtualMachine(DeployVMCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, ResourceAllocationException,
|
public UserVm deployVirtualMachine(DeployVMCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, ResourceAllocationException,
|
||||||
InternalErrorException, InsufficientStorageCapacityException, ExecutionException,
|
InternalErrorException, InsufficientStorageCapacityException, ExecutionException,
|
||||||
StorageUnavailableException, ConcurrentOperationException {
|
StorageUnavailableException, ConcurrentOperationException {
|
||||||
Account ctxAccount = (Account)UserContext.current().getAccountObject();
|
Account ctxAccount = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
@ -1962,7 +1962,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
public List<DataCenterVO> listDataCenters(ListZonesByCmd cmd) {
|
public List<DataCenterVO> listDataCenters(ListZonesByCmd cmd) {
|
||||||
List<DataCenterVO> dcs = _dcDao.listAll();
|
List<DataCenterVO> dcs = _dcDao.listAll();
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Boolean available = cmd.isAvailable();
|
Boolean available = cmd.isAvailable();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if ((available != null) && Boolean.FALSE.equals(available)) {
|
if ((available != null) && Boolean.FALSE.equals(available)) {
|
||||||
@ -2019,7 +2019,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
public void assignSecurityGroup(AssignPortForwardingServiceCmd cmd) throws PermissionDeniedException,
|
public void assignSecurityGroup(AssignPortForwardingServiceCmd cmd) throws PermissionDeniedException,
|
||||||
NetworkRuleConflictException, InvalidParameterValueException, InternalErrorException {
|
NetworkRuleConflictException, InvalidParameterValueException, InternalErrorException {
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long securityGroupId = cmd.getId();
|
Long securityGroupId = cmd.getId();
|
||||||
List<Long> sgIdList = cmd.getIds();
|
List<Long> sgIdList = cmd.getIds();
|
||||||
String publicIp = cmd.getPublicIp();
|
String publicIp = cmd.getPublicIp();
|
||||||
@ -2305,7 +2305,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
@Override
|
@Override
|
||||||
public void removeSecurityGroup(RemovePortForwardingServiceCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
public void removeSecurityGroup(RemovePortForwardingServiceCmd cmd) throws InvalidParameterValueException, PermissionDeniedException{
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long securityGroupId = cmd.getId();
|
Long securityGroupId = cmd.getId();
|
||||||
String publicIp = cmd.getPublicIp();
|
String publicIp = cmd.getPublicIp();
|
||||||
@ -2659,7 +2659,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserAccountVO> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException {
|
public List<UserAccountVO> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
if (domainId != null) {
|
if (domainId != null) {
|
||||||
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
||||||
@ -2754,7 +2754,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||||
} else if (vmId != null) {
|
} else if (vmId != null) {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
UserVmVO vmInstance = _userVmDao.findById(vmId);
|
UserVmVO vmInstance = _userVmDao.findById(vmId);
|
||||||
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
|
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
|
||||||
@ -3106,7 +3106,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
public List<VMTemplateVO> listIsos(ListIsosCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
public List<VMTemplateVO> listIsos(ListIsosCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||||
TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter());
|
TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter());
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
|
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
|
||||||
@ -3137,7 +3137,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
public List<VMTemplateVO> listTemplates(ListTemplatesCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
public List<VMTemplateVO> listTemplates(ListTemplatesCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||||
TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
|
TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
|
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
|
||||||
@ -3254,7 +3254,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AccountVO> searchForAccounts(ListAccountsCmd cmd) {
|
public List<AccountVO> searchForAccounts(ListAccountsCmd cmd) {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Long accountId = cmd.getId();
|
Long accountId = cmd.getId();
|
||||||
String accountName = null;
|
String accountName = null;
|
||||||
@ -3436,7 +3436,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
Long guestOSId = cmd.getOsTypeId();
|
Long guestOSId = cmd.getOsTypeId();
|
||||||
Boolean passwordEnabled = cmd.isPasswordEnabled();
|
Boolean passwordEnabled = cmd.isPasswordEnabled();
|
||||||
Boolean bootable = cmd.isBootable();
|
Boolean bootable = cmd.isBootable();
|
||||||
Account account= (Account)UserContext.current().getAccountObject();
|
Account account= UserContext.current().getAccount();
|
||||||
|
|
||||||
//verify that template exists
|
//verify that template exists
|
||||||
VMTemplateVO template = findTemplateById(id);
|
VMTemplateVO template = findTemplateById(id);
|
||||||
@ -3531,7 +3531,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -3734,7 +3734,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
String protocol = cmd.getProtocol();
|
String protocol = cmd.getProtocol();
|
||||||
Long vmId = cmd.getVirtualMachineId();
|
Long vmId = cmd.getVirtualMachineId();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
UserVmVO userVM = null;
|
UserVmVO userVM = null;
|
||||||
|
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
@ -3820,7 +3820,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
@Override
|
@Override
|
||||||
public List<NetworkRuleConfigVO> searchForNetworkRules(ListPortForwardingServiceRulesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<NetworkRuleConfigVO> searchForNetworkRules(ListPortForwardingServiceRulesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long groupId = cmd.getPortForwardingServiceId();
|
Long groupId = cmd.getPortForwardingServiceId();
|
||||||
@ -3894,7 +3894,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EventVO> searchForEvents(ListEventsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
|
public List<EventVO> searchForEvents(ListEventsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
boolean isAdmin = false;
|
boolean isAdmin = false;
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
@ -4018,7 +4018,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
// validate domainId before proceeding
|
// validate domainId before proceeding
|
||||||
if (domainId != null) {
|
if (domainId != null) {
|
||||||
@ -4147,7 +4147,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VolumeVO> searchForVolumes(ListVolumesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<VolumeVO> searchForVolumes(ListVolumesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -4312,7 +4312,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IPAddressVO> searchForIPAddresses(ListPublicIpAddressesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<IPAddressVO> searchForIPAddresses(ListPublicIpAddressesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -4560,7 +4560,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validate permissions
|
// validate permissions
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if (isAdmin(account.getType())) {
|
if (isAdmin(account.getType())) {
|
||||||
if (!_domainDao.isChildDomain(account.getDomainId(), sg.getDomainId())) {
|
if (!_domainDao.isChildDomain(account.getDomainId(), sg.getDomainId())) {
|
||||||
@ -4738,7 +4738,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
@Override
|
@Override
|
||||||
public List<DomainVO> searchForDomains(ListDomainsCmd cmd) throws PermissionDeniedException {
|
public List<DomainVO> searchForDomains(ListDomainsCmd cmd) throws PermissionDeniedException {
|
||||||
Long domainId = cmd.getId();
|
Long domainId = cmd.getId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if (domainId != null) {
|
if (domainId != null) {
|
||||||
if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
||||||
@ -4793,7 +4793,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
String domainName = cmd.getDomainName();
|
String domainName = cmd.getDomainName();
|
||||||
Object keyword = cmd.getKeyword();
|
Object keyword = cmd.getKeyword();
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if (domainId != null) {
|
if (domainId != null) {
|
||||||
if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
||||||
@ -4829,7 +4829,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
String name = cmd.getDomainName();
|
String name = cmd.getDomainName();
|
||||||
Long parentId = cmd.getParentDomainId();
|
Long parentId = cmd.getParentDomainId();
|
||||||
Long ownerId = UserContext.current().getAccountId();
|
Long ownerId = UserContext.current().getAccountId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
if (ownerId == null) {
|
if (ownerId == null) {
|
||||||
ownerId = Long.valueOf(1);
|
ownerId = Long.valueOf(1);
|
||||||
@ -4873,7 +4873,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteDomain(DeleteDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public boolean deleteDomain(DeleteDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getId();
|
Long domainId = cmd.getId();
|
||||||
Boolean cleanup = cmd.getCleanup();
|
Boolean cleanup = cmd.getCleanup();
|
||||||
|
|
||||||
@ -4967,7 +4967,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if ((account != null) && !isChildDomain(account.getDomainId(), domain.getId())) {
|
if ((account != null) && !isChildDomain(account.getDomainId(), domain.getId())) {
|
||||||
throw new PermissionDeniedException("Unable to update domain " + domainId + ", permission denied");
|
throw new PermissionDeniedException("Unable to update domain " + domainId + ", permission denied");
|
||||||
}
|
}
|
||||||
@ -5107,7 +5107,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
checkAccountPermissions(volume.getAccountId(), volume.getDomainId(), "volume", volumeId);
|
checkAccountPermissions(volume.getAccountId(), volume.getDomainId(), "volume", volumeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -5229,7 +5229,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
//Input validation
|
//Input validation
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
Account account = (Account) UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
List<String> accountNames = cmd.getAccountNames();
|
List<String> accountNames = cmd.getAccountNames();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Boolean isFeatured = cmd.isFeatured();
|
Boolean isFeatured = cmd.isFeatured();
|
||||||
@ -5374,7 +5374,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> listTemplatePermissions(ListTemplateOrIsoPermissionsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<String> listTemplatePermissions(ListTemplateOrIsoPermissionsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String acctName = cmd.getAccountName();
|
String acctName = cmd.getAccountName();
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
@ -5510,7 +5510,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
s_logger.debug("Mismatched account id in job and user context, perform further securty check. job id: "
|
s_logger.debug("Mismatched account id in job and user context, perform further securty check. job id: "
|
||||||
+ jobId + ", job owner account: " + job.getAccountId() + ", accound id in current context: " + UserContext.current().getAccountId());
|
+ jobId + ", job owner account: " + job.getAccountId() + ", accound id in current context: " + UserContext.current().getAccountId());
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if (isAdmin(account.getType())) {
|
if (isAdmin(account.getType())) {
|
||||||
Account jobAccount = _accountDao.findById(job.getAccountId());
|
Account jobAccount = _accountDao.findById(job.getAccountId());
|
||||||
@ -5550,7 +5550,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SecurityGroupVO createPortForwardingService(CreatePortForwardingServiceCmd cmd) throws InvalidParameterValueException {
|
public SecurityGroupVO createPortForwardingService(CreatePortForwardingServiceCmd cmd) throws InvalidParameterValueException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -5596,7 +5596,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
public boolean deleteSecurityGroup(DeletePortForwardingServiceCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public boolean deleteSecurityGroup(DeletePortForwardingServiceCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Long securityGroupId = cmd.getId();
|
Long securityGroupId = cmd.getId();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//Verify input parameters
|
//Verify input parameters
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
@ -5666,7 +5666,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
@Override
|
@Override
|
||||||
public List<SecurityGroupVO> searchForSecurityGroups(ListPortForwardingServicesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<SecurityGroupVO> searchForSecurityGroups(ListPortForwardingServicesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
// if an admin account was passed in, or no account was passed in, make sure we honor the accountName/domainId parameters
|
// if an admin account was passed in, or no account was passed in, make sure we honor the accountName/domainId parameters
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
@ -5730,7 +5730,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
if (accountId != null) {
|
if (accountId != null) {
|
||||||
sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
|
sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
|
||||||
} else if (domainId != null) {
|
} else if (domainId != null) {
|
||||||
DomainVO domain = _domainDao.findById((Long)domainId);
|
DomainVO domain = _domainDao.findById(domainId);
|
||||||
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
|
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5739,7 +5739,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<SecurityGroupVO>> searchForSecurityGroupsByVM(ListPortForwardingServicesByVmCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public Map<String, List<SecurityGroupVO>> searchForSecurityGroupsByVM(ListPortForwardingServicesByVmCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -5846,7 +5846,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserVmVO> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd) throws PermissionDeniedException {
|
public List<UserVmVO> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd) throws PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long loadBalancerId = cmd.getId();
|
Long loadBalancerId = cmd.getId();
|
||||||
Boolean applied = cmd.isApplied();
|
Boolean applied = cmd.isApplied();
|
||||||
|
|
||||||
@ -5915,7 +5915,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
@Override
|
@Override
|
||||||
public List<LoadBalancerVO> searchForLoadBalancers(ListLoadBalancerRulesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<LoadBalancerVO> searchForLoadBalancers(ListLoadBalancerRulesCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
// do some parameter validation
|
// do some parameter validation
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -6010,7 +6010,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
if (accountId != null) {
|
if (accountId != null) {
|
||||||
sc.setParameters("accountId", accountId);
|
sc.setParameters("accountId", accountId);
|
||||||
} else if (domainId != null) {
|
} else if (domainId != null) {
|
||||||
DomainVO domain = _domainDao.findById((Long)domainId);
|
DomainVO domain = _domainDao.findById(domainId);
|
||||||
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
|
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6189,7 +6189,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
Object accountId = null;
|
Object accountId = null;
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if ((account == null) || isAdmin(account.getType())) {
|
if ((account == null) || isAdmin(account.getType())) {
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
|
|
||||||
@ -6337,7 +6337,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
systemVMs.addAll(searchForConsoleProxy(c));
|
systemVMs.addAll(searchForConsoleProxy(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (List<? extends VMInstanceVO>)systemVMs;
|
return systemVMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -6432,6 +6432,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ArrayList<String> getCloudIdentifierResponse(GetCloudIdentifierCmd cmd) throws InvalidParameterValueException{
|
public ArrayList<String> getCloudIdentifierResponse(GetCloudIdentifierCmd cmd) throws InvalidParameterValueException{
|
||||||
Long userId = cmd.getUserId();
|
Long userId = cmd.getUserId();
|
||||||
|
|
||||||
@ -6544,7 +6545,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean lockAccount(LockAccountCmd cmd) {
|
public boolean lockAccount(LockAccountCmd cmd) {
|
||||||
Account adminAccount = (Account)UserContext.current().getAccountObject();
|
Account adminAccount = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
|
|
||||||
@ -6744,7 +6745,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) {
|
public InstanceGroupVO updateVmGroup(UpdateVMGroupCmd cmd) {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long groupId = cmd.getId();
|
Long groupId = cmd.getId();
|
||||||
String groupName = cmd.getGroupName();
|
String groupName = cmd.getGroupName();
|
||||||
|
|
||||||
@ -6779,7 +6780,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<InstanceGroupVO> searchForVmGroups(ListVMGroupsCmd cmd) {
|
public List<InstanceGroupVO> searchForVmGroups(ListVMGroupsCmd cmd) {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -6840,7 +6841,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
if (accountId != null) {
|
if (accountId != null) {
|
||||||
sc.setParameters("accountId", accountId);
|
sc.setParameters("accountId", accountId);
|
||||||
} else if (domainId != null) {
|
} else if (domainId != null) {
|
||||||
DomainVO domain = _domainDao.findById((Long)domainId);
|
DomainVO domain = _domainDao.findById(domainId);
|
||||||
if (domain != null){
|
if (domain != null){
|
||||||
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
|
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
|
||||||
}
|
}
|
||||||
@ -6902,7 +6903,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
private Long checkAccountPermissions(long targetAccountId, long targetDomainId, String targetDesc, long targetId) throws ServerApiException {
|
private Long checkAccountPermissions(long targetAccountId, long targetDomainId, String targetDesc, long targetId) throws ServerApiException {
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if (!isAdmin(account.getType())) {
|
if (!isAdmin(account.getType())) {
|
||||||
if (account.getId() != targetAccountId) {
|
if (account.getId() != targetAccountId) {
|
||||||
|
|||||||
@ -1635,7 +1635,7 @@ public class StorageManagerImpl implements StorageManager {
|
|||||||
@Override
|
@Override
|
||||||
public VolumeVO createVolumeDB(CreateVolumeCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, ResourceAllocationException {
|
public VolumeVO createVolumeDB(CreateVolumeCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, ResourceAllocationException {
|
||||||
// FIXME: some of the scheduled event stuff might be missing here...
|
// FIXME: some of the scheduled event stuff might be missing here...
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Account targetAccount = null;
|
Account targetAccount = null;
|
||||||
@ -2438,7 +2438,7 @@ public class StorageManagerImpl implements StorageManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteVolume(DeleteVolumeCmd cmd) throws InvalidParameterValueException {
|
public boolean deleteVolume(DeleteVolumeCmd cmd) throws InvalidParameterValueException {
|
||||||
Account account = (Account) UserContext.current().getAccountObject();
|
Account account = (Account) UserContext.current().getAccount();
|
||||||
Long volumeId = cmd.getId();
|
Long volumeId = cmd.getId();
|
||||||
|
|
||||||
boolean isAdmin;
|
boolean isAdmin;
|
||||||
|
|||||||
@ -653,7 +653,7 @@ public class SnapshotManagerImpl implements SnapshotManager {
|
|||||||
private Long checkAccountPermissions(long targetAccountId, long targetDomainId, String targetDesc, long targetId) throws ServerApiException {
|
private Long checkAccountPermissions(long targetAccountId, long targetDomainId, String targetDesc, long targetId) throws ServerApiException {
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if (!isAdmin(account.getType())) {
|
if (!isAdmin(account.getType())) {
|
||||||
if (account.getId() != targetAccountId) {
|
if (account.getId() != targetAccountId) {
|
||||||
@ -1073,7 +1073,7 @@ public class SnapshotManagerImpl implements SnapshotManager {
|
|||||||
public List<SnapshotScheduleVO> findRecurringSnapshotSchedule(ListRecurringSnapshotScheduleCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public List<SnapshotScheduleVO> findRecurringSnapshotSchedule(ListRecurringSnapshotScheduleCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Long volumeId = cmd.getVolumeId();
|
Long volumeId = cmd.getVolumeId();
|
||||||
Long policyId = cmd.getSnapshotPolicyId();
|
Long policyId = cmd.getSnapshotPolicyId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
|
|
||||||
//Verify parameters
|
//Verify parameters
|
||||||
VolumeVO volume = _volsDao.findById(volumeId);
|
VolumeVO volume = _volsDao.findById(volumeId);
|
||||||
|
|||||||
@ -18,18 +18,14 @@
|
|||||||
|
|
||||||
package com.cloud.storage.upload;
|
package com.cloud.storage.upload;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.cloud.async.AsyncJobManager;
|
import com.cloud.async.AsyncJobManager;
|
||||||
import com.cloud.exception.InternalErrorException;
|
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
|
import com.cloud.storage.Upload.Status;
|
||||||
|
import com.cloud.storage.Upload.Type;
|
||||||
import com.cloud.storage.UploadVO;
|
import com.cloud.storage.UploadVO;
|
||||||
import com.cloud.storage.VMTemplateHostVO;
|
import com.cloud.storage.VMTemplateHostVO;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.storage.VolumeVO;
|
import com.cloud.storage.VolumeVO;
|
||||||
import com.cloud.storage.Upload.Status;
|
|
||||||
import com.cloud.storage.Upload.Type;
|
|
||||||
import com.cloud.storage.template.TemplateInfo;
|
|
||||||
import com.cloud.utils.component.Manager;
|
import com.cloud.utils.component.Manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,6 +53,6 @@ public interface UploadMonitor extends Manager{
|
|||||||
long asyncJobId, AsyncJobManager asyncMgr);
|
long asyncJobId, AsyncJobManager asyncMgr);
|
||||||
|
|
||||||
UploadVO createEntityDownloadURL(VMTemplateVO template,
|
UploadVO createEntityDownloadURL(VMTemplateVO template,
|
||||||
VMTemplateHostVO vmTemplateHost, Long dataCenterId, long eventId) throws InternalErrorException;
|
VMTemplateHostVO vmTemplateHost, Long dataCenterId, long eventId);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -29,19 +29,18 @@ import com.cloud.configuration.dao.ConfigurationDao;
|
|||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.event.EventVO;
|
import com.cloud.event.EventVO;
|
||||||
import com.cloud.event.dao.EventDao;
|
import com.cloud.event.dao.EventDao;
|
||||||
import com.cloud.exception.InternalErrorException;
|
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
import com.cloud.host.dao.HostDao;
|
import com.cloud.host.dao.HostDao;
|
||||||
|
import com.cloud.storage.Storage.ImageFormat;
|
||||||
import com.cloud.storage.Upload;
|
import com.cloud.storage.Upload;
|
||||||
|
import com.cloud.storage.Upload.Mode;
|
||||||
|
import com.cloud.storage.Upload.Status;
|
||||||
|
import com.cloud.storage.Upload.Type;
|
||||||
import com.cloud.storage.UploadVO;
|
import com.cloud.storage.UploadVO;
|
||||||
import com.cloud.storage.VMTemplateHostVO;
|
import com.cloud.storage.VMTemplateHostVO;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.storage.VolumeVO;
|
import com.cloud.storage.VolumeVO;
|
||||||
import com.cloud.storage.Storage.ImageFormat;
|
|
||||||
import com.cloud.storage.Upload.Mode;
|
|
||||||
import com.cloud.storage.Upload.Status;
|
|
||||||
import com.cloud.storage.Upload.Type;
|
|
||||||
import com.cloud.storage.dao.UploadDao;
|
import com.cloud.storage.dao.UploadDao;
|
||||||
import com.cloud.storage.dao.VMTemplateDao;
|
import com.cloud.storage.dao.VMTemplateDao;
|
||||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||||
@ -49,6 +48,7 @@ import com.cloud.utils.NumbersUtil;
|
|||||||
import com.cloud.utils.component.Inject;
|
import com.cloud.utils.component.Inject;
|
||||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||||
import com.cloud.utils.db.GlobalLock;
|
import com.cloud.utils.db.GlobalLock;
|
||||||
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.vm.SecondaryStorageVmVO;
|
import com.cloud.vm.SecondaryStorageVmVO;
|
||||||
import com.cloud.vm.State;
|
import com.cloud.vm.State;
|
||||||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||||
@ -176,11 +176,11 @@ public class UploadMonitorImpl implements UploadMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadVO createEntityDownloadURL(VMTemplateVO template, VMTemplateHostVO vmTemplateHost, Long dataCenterId, long eventId) throws InternalErrorException{
|
public UploadVO createEntityDownloadURL(VMTemplateVO template, VMTemplateHostVO vmTemplateHost, Long dataCenterId, long eventId) {
|
||||||
|
|
||||||
List<HostVO> storageServers = _serverDao.listByTypeDataCenter(Host.Type.SecondaryStorage, dataCenterId);
|
List<HostVO> storageServers = _serverDao.listByTypeDataCenter(Host.Type.SecondaryStorage, dataCenterId);
|
||||||
if(storageServers == null )
|
if(storageServers == null )
|
||||||
throw new InternalErrorException("No Storage Server found at the datacenter - " +dataCenterId);
|
throw new CloudRuntimeException("No Storage Server found at the datacenter - " +dataCenterId);
|
||||||
|
|
||||||
Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE ;
|
Type type = (template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE ;
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
|||||||
long result = send(sserver.getId(), cmd, null);
|
long result = send(sserver.getId(), cmd, null);
|
||||||
if (result == -1){
|
if (result == -1){
|
||||||
s_logger.warn("Unable to create a link for the template/iso ");
|
s_logger.warn("Unable to create a link for the template/iso ");
|
||||||
throw new InternalErrorException("Unable to create a link at the SSVM");
|
throw new CloudRuntimeException("Unable to create a link at the SSVM");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Construct actual URL locally now that the symlink exists at SSVM
|
//Construct actual URL locally now that the symlink exists at SSVM
|
||||||
@ -210,7 +210,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
|||||||
SecondaryStorageVmVO ssVm = ssVms.get(0);
|
SecondaryStorageVmVO ssVm = ssVms.get(0);
|
||||||
if (ssVm.getPublicIpAddress() == null) {
|
if (ssVm.getPublicIpAddress() == null) {
|
||||||
s_logger.warn("A running secondary storage vm has a null public ip?");
|
s_logger.warn("A running secondary storage vm has a null public ip?");
|
||||||
throw new InternalErrorException("SSVM has null public IP - couldnt create the URL");
|
throw new CloudRuntimeException("SSVM has null public IP - couldnt create the URL");
|
||||||
}
|
}
|
||||||
String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), vmTemplateHost.getInstallPath());
|
String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), vmTemplateHost.getInstallPath());
|
||||||
UploadVO vo = _uploadDao.createForUpdate();
|
UploadVO vo = _uploadDao.createForUpdate();
|
||||||
@ -225,7 +225,7 @@ public class UploadMonitorImpl implements UploadMonitor {
|
|||||||
_uploadDao.update(uploadTemplateObj.getId(), vo);
|
_uploadDao.update(uploadTemplateObj.getId(), vo);
|
||||||
return _uploadDao.findById(uploadTemplateObj.getId(), true);
|
return _uploadDao.findById(uploadTemplateObj.getId(), true);
|
||||||
}
|
}
|
||||||
throw new InternalErrorException("Couldnt find a running SSVM in the zone" + dataCenterId+ ".couldnt create the extraction URL.");
|
throw new CloudRuntimeException("Couldnt find a running SSVM in the zone" + dataCenterId+ ".couldnt create the extraction URL.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -79,8 +79,8 @@ import com.cloud.storage.StoragePool;
|
|||||||
import com.cloud.storage.StoragePoolHostVO;
|
import com.cloud.storage.StoragePoolHostVO;
|
||||||
import com.cloud.storage.StoragePoolVO;
|
import com.cloud.storage.StoragePoolVO;
|
||||||
import com.cloud.storage.Upload;
|
import com.cloud.storage.Upload;
|
||||||
import com.cloud.storage.UploadVO;
|
|
||||||
import com.cloud.storage.Upload.Type;
|
import com.cloud.storage.Upload.Type;
|
||||||
|
import com.cloud.storage.UploadVO;
|
||||||
import com.cloud.storage.VMTemplateHostVO;
|
import com.cloud.storage.VMTemplateHostVO;
|
||||||
import com.cloud.storage.VMTemplateStoragePoolVO;
|
import com.cloud.storage.VMTemplateStoragePoolVO;
|
||||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||||
@ -160,7 +160,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VMTemplateVO registerIso(RegisterIsoCmd cmd) throws InvalidParameterValueException, IllegalArgumentException, ResourceAllocationException{
|
public VMTemplateVO registerIso(RegisterIsoCmd cmd) throws InvalidParameterValueException, IllegalArgumentException, ResourceAllocationException{
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
String name = cmd.getName();
|
String name = cmd.getName();
|
||||||
String displayText = cmd.getDisplayText();
|
String displayText = cmd.getDisplayText();
|
||||||
@ -231,7 +231,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
@Override
|
@Override
|
||||||
public VMTemplateVO registerTemplate(RegisterTemplateCmd cmd) throws InvalidParameterValueException, URISyntaxException, ResourceAllocationException{
|
public VMTemplateVO registerTemplate(RegisterTemplateCmd cmd) throws InvalidParameterValueException, URISyntaxException, ResourceAllocationException{
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
String name = cmd.getName();
|
String name = cmd.getName();
|
||||||
String displayText = cmd.getDisplayText();
|
String displayText = cmd.getDisplayText();
|
||||||
@ -411,8 +411,8 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long extract(ExtractIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, InternalErrorException {
|
public Long extract(ExtractIsoCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long templateId = cmd.getId();
|
Long templateId = cmd.getId();
|
||||||
Long zoneId = cmd.getZoneId();
|
Long zoneId = cmd.getZoneId();
|
||||||
String url = cmd.getUrl();
|
String url = cmd.getUrl();
|
||||||
@ -423,8 +423,8 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long extract(ExtractTemplateCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, InternalErrorException {
|
public Long extract(ExtractTemplateCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long templateId = cmd.getId();
|
Long templateId = cmd.getId();
|
||||||
Long zoneId = cmd.getZoneId();
|
Long zoneId = cmd.getZoneId();
|
||||||
String url = cmd.getUrl();
|
String url = cmd.getUrl();
|
||||||
@ -434,7 +434,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
return extract(account, templateId, url, zoneId, mode, eventId, false, cmd.getJob(), cmd.getAsyncJobManager());
|
return extract(account, templateId, url, zoneId, mode, eventId, false, cmd.getJob(), cmd.getAsyncJobManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long extract(Account account, Long templateId, String url, Long zoneId, String mode, Long eventId, boolean isISO, AsyncJobVO job, AsyncJobManager mgr) throws InvalidParameterValueException, PermissionDeniedException, InternalErrorException {
|
private Long extract(Account account, Long templateId, String url, Long zoneId, String mode, Long eventId, boolean isISO, AsyncJobVO job, AsyncJobManager mgr) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
String desc = "template";
|
String desc = "template";
|
||||||
if (isISO) {
|
if (isISO) {
|
||||||
desc = "ISO";
|
desc = "ISO";
|
||||||
@ -779,7 +779,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long sourceZoneId = cmd.getSourceZoneId();
|
Long sourceZoneId = cmd.getSourceZoneId();
|
||||||
Long destZoneId = cmd.getDestinationZoneId();
|
Long destZoneId = cmd.getDestinationZoneId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//Verify parameters
|
//Verify parameters
|
||||||
VMTemplateVO iso = _tmpltDao.findById(isoId);
|
VMTemplateVO iso = _tmpltDao.findById(isoId);
|
||||||
@ -813,7 +813,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long sourceZoneId = cmd.getSourceZoneId();
|
Long sourceZoneId = cmd.getSourceZoneId();
|
||||||
Long destZoneId = cmd.getDestinationZoneId();
|
Long destZoneId = cmd.getDestinationZoneId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
//Verify parameters
|
//Verify parameters
|
||||||
VMTemplateVO template = _tmpltDao.findById(templateId);
|
VMTemplateVO template = _tmpltDao.findById(templateId);
|
||||||
@ -1132,7 +1132,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean detachIso(DetachIsoCmd cmd) throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException {
|
public boolean detachIso(DetachIsoCmd cmd) throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account) UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long vmId = cmd.getVirtualMachineId();
|
Long vmId = cmd.getVirtualMachineId();
|
||||||
|
|
||||||
@ -1166,7 +1166,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean attachIso(AttachIsoCmd cmd) throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException {
|
public boolean attachIso(AttachIsoCmd cmd) throws InternalErrorException, InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account) UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long vmId = cmd.getVirtualMachineId();
|
Long vmId = cmd.getVirtualMachineId();
|
||||||
Long isoId = cmd.getId();
|
Long isoId = cmd.getId();
|
||||||
@ -1272,7 +1272,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
public boolean deleteTemplate(DeleteTemplateCmd cmd) throws InvalidParameterValueException, InternalErrorException, PermissionDeniedException {
|
public boolean deleteTemplate(DeleteTemplateCmd cmd) throws InvalidParameterValueException, InternalErrorException, PermissionDeniedException {
|
||||||
Long templateId = cmd.getId();
|
Long templateId = cmd.getId();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long zoneId = cmd.getZoneId();
|
Long zoneId = cmd.getZoneId();
|
||||||
|
|
||||||
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
|
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
|
||||||
@ -1305,7 +1305,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
|||||||
public boolean deleteIso(DeleteIsoCmd cmd) throws InvalidParameterValueException, InternalErrorException, PermissionDeniedException {
|
public boolean deleteIso(DeleteIsoCmd cmd) throws InvalidParameterValueException, InternalErrorException, PermissionDeniedException {
|
||||||
Long templateId = cmd.getId();
|
Long templateId = cmd.getId();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long zoneId = cmd.getZoneId();
|
Long zoneId = cmd.getZoneId();
|
||||||
|
|
||||||
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
|
VMTemplateVO template = _tmpltDao.findById(templateId.longValue());
|
||||||
|
|||||||
@ -342,7 +342,7 @@ public class AccountManagerImpl implements AccountManager {
|
|||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
|
|
||||||
if ((account == null) ||
|
if ((account == null) ||
|
||||||
(account.getType() == Account.ACCOUNT_TYPE_ADMIN) ||
|
(account.getType() == Account.ACCOUNT_TYPE_ADMIN) ||
|
||||||
@ -409,7 +409,7 @@ public class AccountManagerImpl implements AccountManager {
|
|||||||
@Override
|
@Override
|
||||||
public ResourceLimitVO updateResourceLimit(UpdateResourceLimitCmd cmd) throws InvalidParameterValueException {
|
public ResourceLimitVO updateResourceLimit(UpdateResourceLimitCmd cmd) throws InvalidParameterValueException {
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
Long max = cmd.getMax();
|
Long max = cmd.getMax();
|
||||||
Integer type = cmd.getResourceType();
|
Integer type = cmd.getResourceType();
|
||||||
|
|||||||
@ -45,6 +45,7 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||||||
import com.cloud.exception.InsufficientCapacityException;
|
import com.cloud.exception.InsufficientCapacityException;
|
||||||
import com.cloud.exception.InsufficientServerCapacityException;
|
import com.cloud.exception.InsufficientServerCapacityException;
|
||||||
import com.cloud.exception.OperationTimedoutException;
|
import com.cloud.exception.OperationTimedoutException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.network.NetworkConfigurationVO;
|
import com.cloud.network.NetworkConfigurationVO;
|
||||||
import com.cloud.network.NetworkManager;
|
import com.cloud.network.NetworkManager;
|
||||||
@ -211,7 +212,7 @@ public class MauriceMoss implements VmManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends VMInstanceVO> T start(T vm, DeploymentPlan plan, Account acct, VirtualMachineGuru<T> guru) throws InsufficientCapacityException, ConcurrentOperationException {
|
public <T extends VMInstanceVO> T start(T vm, DeploymentPlan plan, Account acct, VirtualMachineGuru<T> guru) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||||
State state = vm.getState();
|
State state = vm.getState();
|
||||||
if (state == State.Starting || state == State.Running) {
|
if (state == State.Starting || state == State.Running) {
|
||||||
s_logger.debug("VM is already started: " + vm);
|
s_logger.debug("VM is already started: " + vm);
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import com.cloud.api.commands.AttachVolumeCmd;
|
|||||||
import com.cloud.api.commands.CreateTemplateCmd;
|
import com.cloud.api.commands.CreateTemplateCmd;
|
||||||
import com.cloud.api.commands.CreateVMGroupCmd;
|
import com.cloud.api.commands.CreateVMGroupCmd;
|
||||||
import com.cloud.api.commands.DeleteVMGroupCmd;
|
import com.cloud.api.commands.DeleteVMGroupCmd;
|
||||||
|
import com.cloud.api.commands.DeployVmCmd;
|
||||||
import com.cloud.api.commands.DestroyVMCmd;
|
import com.cloud.api.commands.DestroyVMCmd;
|
||||||
import com.cloud.api.commands.DetachVolumeCmd;
|
import com.cloud.api.commands.DetachVolumeCmd;
|
||||||
import com.cloud.api.commands.RebootVMCmd;
|
import com.cloud.api.commands.RebootVMCmd;
|
||||||
@ -48,6 +49,7 @@ import com.cloud.exception.InternalErrorException;
|
|||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.network.security.NetworkGroupVO;
|
import com.cloud.network.security.NetworkGroupVO;
|
||||||
import com.cloud.offerings.NetworkOfferingVO;
|
import com.cloud.offerings.NetworkOfferingVO;
|
||||||
@ -250,4 +252,8 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||||||
void removeInstanceFromGroup(long vmId);
|
void removeInstanceFromGroup(long vmId);
|
||||||
|
|
||||||
void updateVirtualMachine(UpdateVMCmd cmd);
|
void updateVirtualMachine(UpdateVMCmd cmd);
|
||||||
|
|
||||||
|
UserVm createVirtualMachine(DeployVmCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||||
|
|
||||||
|
UserVm startVirtualMachine(DeployVmCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,6 +69,7 @@ import com.cloud.api.commands.AttachVolumeCmd;
|
|||||||
import com.cloud.api.commands.CreateTemplateCmd;
|
import com.cloud.api.commands.CreateTemplateCmd;
|
||||||
import com.cloud.api.commands.CreateVMGroupCmd;
|
import com.cloud.api.commands.CreateVMGroupCmd;
|
||||||
import com.cloud.api.commands.DeleteVMGroupCmd;
|
import com.cloud.api.commands.DeleteVMGroupCmd;
|
||||||
|
import com.cloud.api.commands.DeployVmCmd;
|
||||||
import com.cloud.api.commands.DestroyVMCmd;
|
import com.cloud.api.commands.DestroyVMCmd;
|
||||||
import com.cloud.api.commands.DetachVolumeCmd;
|
import com.cloud.api.commands.DetachVolumeCmd;
|
||||||
import com.cloud.api.commands.RebootVMCmd;
|
import com.cloud.api.commands.RebootVMCmd;
|
||||||
@ -117,6 +118,7 @@ import com.cloud.exception.InvalidParameterValueException;
|
|||||||
import com.cloud.exception.OperationTimedoutException;
|
import com.cloud.exception.OperationTimedoutException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.ha.HighAvailabilityManager;
|
import com.cloud.ha.HighAvailabilityManager;
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
@ -302,7 +304,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
|
|
||||||
private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd) {
|
private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd) {
|
||||||
//Input validation
|
//Input validation
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
|
|
||||||
@ -359,7 +361,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
Long vmId = command.getVirtualMachineId();
|
Long vmId = command.getVirtualMachineId();
|
||||||
Long volumeId = command.getId();
|
Long volumeId = command.getId();
|
||||||
Long deviceId = command.getDeviceId();
|
Long deviceId = command.getDeviceId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
|
|
||||||
// Check that the volume ID is valid
|
// Check that the volume ID is valid
|
||||||
VolumeVO volume = _volsDao.findById(volumeId);
|
VolumeVO volume = _volsDao.findById(volumeId);
|
||||||
@ -588,7 +590,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException {
|
public void detachVolumeFromVM(DetachVolumeCmd cmmd) throws InternalErrorException, InvalidParameterValueException {
|
||||||
Account account = (Account) UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
if ((cmmd.getId() == null && cmmd.getDeviceId() == null && cmmd.getVirtualMachineId() == null) ||
|
if ((cmmd.getId() == null && cmmd.getDeviceId() == null && cmmd.getVirtualMachineId() == null) ||
|
||||||
(cmmd.getId() != null && (cmmd.getDeviceId() != null || cmmd.getVirtualMachineId() != null)) ||
|
(cmmd.getId() != null && (cmmd.getDeviceId() != null || cmmd.getVirtualMachineId() != null)) ||
|
||||||
(cmmd.getId() == null && (cmmd.getDeviceId()==null || cmmd.getVirtualMachineId() == null))) {
|
(cmmd.getId() == null && (cmmd.getDeviceId()==null || cmmd.getVirtualMachineId() == null))) {
|
||||||
@ -1327,7 +1329,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ServerApiException, InvalidParameterValueException {
|
public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ServerApiException, InvalidParameterValueException {
|
||||||
Long virtualMachineId = cmd.getId();
|
Long virtualMachineId = cmd.getId();
|
||||||
Long serviceOfferingId = cmd.getServiceOfferingId();
|
Long serviceOfferingId = cmd.getServiceOfferingId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
|
|
||||||
// Verify input parameters
|
// Verify input parameters
|
||||||
@ -2034,7 +2036,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
public boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, InternalErrorException {
|
public boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, InternalErrorException {
|
||||||
|
|
||||||
Long vmId = cmd.getId();
|
Long vmId = cmd.getId();
|
||||||
Account accountHandle = (Account)UserContext.current().getAccountObject();
|
Account accountHandle = UserContext.current().getAccount();
|
||||||
|
|
||||||
//if account is removed, return error
|
//if account is removed, return error
|
||||||
if(accountHandle!=null && accountHandle.getRemoved() != null)
|
if(accountHandle!=null && accountHandle.getRemoved() != null)
|
||||||
@ -2667,7 +2669,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
userId = User.UID_SYSTEM;
|
userId = User.UID_SYSTEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
boolean isAdmin = ((account == null) || isAdmin(account.getType()));
|
boolean isAdmin = ((account == null) || isAdmin(account.getType()));
|
||||||
|
|
||||||
VMTemplateVO privateTemplate = null;
|
VMTemplateVO privateTemplate = null;
|
||||||
@ -3403,7 +3405,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
String displayName = cmd.getDisplayName();
|
String displayName = cmd.getDisplayName();
|
||||||
Boolean ha = cmd.getHaEnable();
|
Boolean ha = cmd.getHaEnable();
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
|
|
||||||
//Input validation
|
//Input validation
|
||||||
@ -3460,7 +3462,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
public UserVmVO stopVirtualMachine(StopVMCmd cmd) throws ServerApiException{
|
public UserVmVO stopVirtualMachine(StopVMCmd cmd) throws ServerApiException{
|
||||||
|
|
||||||
//Input validation
|
//Input validation
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
|
|
||||||
@ -3488,7 +3490,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
@Override
|
@Override
|
||||||
public UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException {
|
public UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException {
|
||||||
//Input validation
|
//Input validation
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
|
|
||||||
@ -3511,7 +3513,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean rebootVirtualMachine(RebootVMCmd cmd) {
|
public boolean rebootVirtualMachine(RebootVMCmd cmd) {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long vmId = cmd.getId();
|
Long vmId = cmd.getId();
|
||||||
|
|
||||||
@ -3542,7 +3544,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean destroyVm(DestroyVMCmd cmd) {
|
public boolean destroyVm(DestroyVMCmd cmd) {
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
Long vmId = cmd.getId();
|
Long vmId = cmd.getId();
|
||||||
|
|
||||||
@ -3572,7 +3574,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
public InstanceGroupVO createVmGroup(CreateVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public InstanceGroupVO createVmGroup(CreateVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long domainId = cmd.getDomainId();
|
Long domainId = cmd.getDomainId();
|
||||||
String accountName = cmd.getAccountName();
|
String accountName = cmd.getAccountName();
|
||||||
Long accountId = null;
|
Long accountId = null;
|
||||||
@ -3641,7 +3643,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteVmGroup(DeleteVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
public boolean deleteVmGroup(DeleteVMGroupCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||||
Account account = (Account)UserContext.current().getAccountObject();
|
Account account = UserContext.current().getAccount();
|
||||||
Long groupId = cmd.getId();
|
Long groupId = cmd.getId();
|
||||||
|
|
||||||
// Verify input parameters
|
// Verify input parameters
|
||||||
@ -3761,4 +3763,194 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
s_logger.warn("Error trying to remove vm from group: "+e);
|
s_logger.warn("Error trying to remove vm from group: "+e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserVm createVirtualMachine(DeployVmCmd cmd)
|
||||||
|
throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, InvalidParameterValueException, PermissionDeniedException {
|
||||||
|
// Account ctxAccount = UserContext.current().getAccount();
|
||||||
|
// Long userId = UserContext.current().getUserId();
|
||||||
|
// String accountName = cmd.getAccountName();
|
||||||
|
// Long domainId = cmd.getDomainId();
|
||||||
|
// Long accountId = null;
|
||||||
|
// long dataCenterId = cmd.getZoneId();
|
||||||
|
// long serviceOfferingId = cmd.getServiceOfferingId();
|
||||||
|
// long templateId = cmd.getTemplateId();
|
||||||
|
// Long diskOfferingId = cmd.getDiskOfferingId();
|
||||||
|
// String domain = null; // FIXME: this was hardcoded to null in DeployVMCmd in the old framework, do we need it?
|
||||||
|
// String password = generateRandomPassword();
|
||||||
|
// String displayName = cmd.getDisplayName();
|
||||||
|
// String group = cmd.getGroup();
|
||||||
|
// String userData = cmd.getUserData();
|
||||||
|
// String[] networkGroups = null;
|
||||||
|
// Long sizeObj = cmd.getSize();
|
||||||
|
// long size = (sizeObj == null) ? 0 : sizeObj;
|
||||||
|
//
|
||||||
|
// if ((ctxAccount == null) || isAdmin(ctxAccount.getType())) {
|
||||||
|
// if (domainId != null) {
|
||||||
|
// if ((ctxAccount != null) && !_domainDao.isChildDomain(ctxAccount.getDomainId(), domainId)) {
|
||||||
|
// throw new PermissionDeniedException("Failed to deploy VM, invalid domain id (" + domainId + ") given.");
|
||||||
|
// }
|
||||||
|
// if (accountName != null) {
|
||||||
|
// Account userAccount = _accountDao.findActiveAccount(accountName, domainId);
|
||||||
|
// if (userAccount == null) {
|
||||||
|
// throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
|
||||||
|
// }
|
||||||
|
// accountId = userAccount.getId();
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// accountId = ((ctxAccount != null) ? ctxAccount.getId() : null);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// accountId = ctxAccount.getId();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (accountId == null) {
|
||||||
|
// throw new InvalidParameterValueException("No valid account specified for deploying a virtual machine.");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// List<String> netGrpList = cmd.getNetworkGroupList();
|
||||||
|
// if ((netGrpList != null) && !netGrpList.isEmpty()) {
|
||||||
|
// networkGroups = netGrpList.toArray(new String[netGrpList.size()]);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// AccountVO account = _accountDao.findById(accountId);
|
||||||
|
// if (account == null) {
|
||||||
|
// throw new InvalidParameterValueException("Unable to find account: " + accountId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// DataCenterVO dc = _dcDao.findById(dataCenterId);
|
||||||
|
// if (dc == null) {
|
||||||
|
// throw new InvalidParameterValueException("Unable to find zone: " + dataCenterId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// ServiceOfferingVO offering = _offeringsDao.findById(serviceOfferingId);
|
||||||
|
// if (offering == null) {
|
||||||
|
// throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// VMTemplateVO template = _templateDao.findById(templateId);
|
||||||
|
// // Make sure a valid template ID was specified
|
||||||
|
// if (template == null) {
|
||||||
|
// throw new InvalidParameterValueException("Please specify a valid template or ISO ID.");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// boolean isIso = Storage.ImageFormat.ISO.equals(template.getFormat());
|
||||||
|
//
|
||||||
|
// if (isIso && !template.isBootable()) {
|
||||||
|
// throw new InvalidParameterValueException("Please specify a bootable ISO.");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // If the template represents an ISO, a disk offering must be passed in, and will be used to create the root disk
|
||||||
|
// // Else, a disk offering is optional, and if present will be used to create the data disk
|
||||||
|
// DiskOfferingVO diskOffering = null;
|
||||||
|
//
|
||||||
|
// if (diskOfferingId != null) {
|
||||||
|
// diskOffering = _diskOfferingDao.findById(diskOfferingId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (isIso && diskOffering == null) {
|
||||||
|
// throw new InvalidParameterValueException("Please specify a valid disk offering ID.");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // validate that the template is usable by the account
|
||||||
|
// if (!template.isPublicTemplate()) {
|
||||||
|
// Long templateOwner = template.getAccountId();
|
||||||
|
// if (!BaseCmd.isAdmin(account.getType()) && ((templateOwner == null) || (templateOwner.longValue() != accountId))) {
|
||||||
|
// // since the current account is not the owner of the template, check the launch permissions table to see if the
|
||||||
|
// // account can launch a VM from this template
|
||||||
|
// LaunchPermissionVO permission = _launchPermissionDao.findByTemplateAndAccount(templateId, account.getId());
|
||||||
|
// if (permission == null) {
|
||||||
|
// throw new PermissionDeniedException("Account " + account.getAccountName() + " does not have permission to launch instances from template " + template.getName());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// byte [] decodedUserData = null;
|
||||||
|
// if (userData != null) {
|
||||||
|
// if (userData.length() >= 2* UserVmManager.MAX_USER_DATA_LENGTH_BYTES) {
|
||||||
|
// throw new InvalidParameterValueException("User data is too long");
|
||||||
|
// }
|
||||||
|
// decodedUserData = org.apache.commons.codec.binary.Base64.decodeBase64(userData.getBytes());
|
||||||
|
// if (decodedUserData.length > UserVmManager.MAX_USER_DATA_LENGTH_BYTES){
|
||||||
|
// throw new InvalidParameterValueException("User data is too long");
|
||||||
|
// }
|
||||||
|
// if (decodedUserData.length < 1) {
|
||||||
|
// throw new InvalidParameterValueException("User data is too short");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// if (offering.getGuestIpType() != NetworkOffering.GuestIpType.Virtualized) {
|
||||||
|
// _networkGroupMgr.createDefaultNetworkGroup(accountId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (networkGroups != null) {
|
||||||
|
// if (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized) {
|
||||||
|
// throw new InvalidParameterValueException("Network groups are not compatible with service offering " + offering.getName());
|
||||||
|
// }
|
||||||
|
// Set<String> nameSet = new HashSet<String>(); //handle duplicate names -- allowed
|
||||||
|
// nameSet.addAll(Arrays.asList(networkGroups));
|
||||||
|
// nameSet.add(NetworkGroupManager.DEFAULT_GROUP_NAME);
|
||||||
|
// networkGroups = nameSet.toArray(new String[nameSet.size()]);
|
||||||
|
// List<NetworkGroupVO> networkGroupVOs = _networkSecurityGroupDao.findByAccountAndNames(accountId, networkGroups);
|
||||||
|
// if (networkGroupVOs.size() != nameSet.size()) {
|
||||||
|
// throw new InvalidParameterValueException("Some network group names do not exist");
|
||||||
|
// }
|
||||||
|
// } else { //create a default group if necessary
|
||||||
|
// if (offering.getGuestIpType() != NetworkOffering.GuestIpType.Virtualized && _networkGroupsEnabled) {
|
||||||
|
// networkGroups = new String[]{NetworkGroupManager.DEFAULT_GROUP_NAME};
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Long eventId = cmd.getStartEventId();
|
||||||
|
// try {
|
||||||
|
// return deployVirtualMachineImpl(userId, accountId, dataCenterId, serviceOfferingId, templateId, diskOfferingId, domain, password, displayName, group, userData, networkGroups, eventId, size);
|
||||||
|
// } catch (ResourceAllocationException e) {
|
||||||
|
// if(s_logger.isDebugEnabled())
|
||||||
|
// s_logger.debug("Unable to deploy VM: " + e.getMessage());
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: VM_INSUFFICIENT_CAPACITY", null, eventId);
|
||||||
|
// throw e;
|
||||||
|
// } catch (ExecutionException e) {
|
||||||
|
// if(s_logger.isDebugEnabled())
|
||||||
|
// s_logger.debug("Unable to deploy VM: " + e.getMessage());
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: VM_HOST_LICENSE_EXPIRED", null, eventId);
|
||||||
|
// throw e;
|
||||||
|
// } catch (InvalidParameterValueException e) {
|
||||||
|
// if(s_logger.isDebugEnabled())
|
||||||
|
// s_logger.debug("Unable to deploy VM: " + e.getMessage());
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: VM_INVALID_PARAM_ERROR", null, eventId);
|
||||||
|
// throw e;
|
||||||
|
// } catch (InternalErrorException e) {
|
||||||
|
// if(s_logger.isDebugEnabled())
|
||||||
|
// s_logger.debug("Unable to deploy VM: " + e.getMessage());
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: INTERNAL_ERROR", null, eventId);
|
||||||
|
// throw e;
|
||||||
|
// } catch (InsufficientStorageCapacityException e) {
|
||||||
|
// if(s_logger.isDebugEnabled())
|
||||||
|
// s_logger.debug("Unable to deploy VM: " + e.getMessage());
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: VM_INSUFFICIENT_CAPACITY", null, eventId);
|
||||||
|
// throw e;
|
||||||
|
// } catch (PermissionDeniedException e) {
|
||||||
|
// if(s_logger.isDebugEnabled())
|
||||||
|
// s_logger.debug("Unable to deploy VM: " + e.getMessage());
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: ACCOUNT_ERROR", null, eventId);
|
||||||
|
// throw e;
|
||||||
|
// } catch (ConcurrentOperationException e) {
|
||||||
|
// if(s_logger.isDebugEnabled())
|
||||||
|
// s_logger.debug("Unable to deploy VM: " + e.getMessage());
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: INTERNAL_ERROR", null, eventId);
|
||||||
|
// throw e;
|
||||||
|
// } catch(Exception e) {
|
||||||
|
// s_logger.warn("Unable to deploy VM : " + e.getMessage(), e);
|
||||||
|
// EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_CREATE, "Unable to deploy VM: INTERNAL_ERROR", null, eventId);
|
||||||
|
// throw new CloudRuntimeException("Unable to deploy VM : " + e.getMessage());
|
||||||
|
// }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserVm startVirtualMachine(DeployVmCmd cmd) {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import com.cloud.deploy.DeploymentPlan;
|
|||||||
import com.cloud.exception.AgentUnavailableException;
|
import com.cloud.exception.AgentUnavailableException;
|
||||||
import com.cloud.exception.ConcurrentOperationException;
|
import com.cloud.exception.ConcurrentOperationException;
|
||||||
import com.cloud.exception.InsufficientCapacityException;
|
import com.cloud.exception.InsufficientCapacityException;
|
||||||
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.network.NetworkConfigurationVO;
|
import com.cloud.network.NetworkConfigurationVO;
|
||||||
import com.cloud.service.ServiceOfferingVO;
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
@ -62,7 +63,7 @@ public interface VmManager extends Manager {
|
|||||||
DeploymentPlan plan,
|
DeploymentPlan plan,
|
||||||
Account owner) throws InsufficientCapacityException, StorageUnavailableException;
|
Account owner) throws InsufficientCapacityException, StorageUnavailableException;
|
||||||
|
|
||||||
<T extends VMInstanceVO> T start(T vm, DeploymentPlan plan, Account user, VirtualMachineGuru<T> checker) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException;
|
<T extends VMInstanceVO> T start(T vm, DeploymentPlan plan, Account user, VirtualMachineGuru<T> checker) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException, ResourceUnavailableException;
|
||||||
|
|
||||||
<T extends VMInstanceVO> T stop(T vm) throws AgentUnavailableException, ConcurrentOperationException;
|
<T extends VMInstanceVO> T stop(T vm) throws AgentUnavailableException, ConcurrentOperationException;
|
||||||
|
|
||||||
|
|||||||
@ -58,4 +58,5 @@ public interface SerialVersionUID {
|
|||||||
public static final long ConflictingNetworkSettingException = Base | 0x1c;
|
public static final long ConflictingNetworkSettingException = Base | 0x1c;
|
||||||
public static final long CloudAuthenticationException = Base | 0x1d;
|
public static final long CloudAuthenticationException = Base | 0x1d;
|
||||||
public static final long AsyncCommandQueued = Base | 0x1e;
|
public static final long AsyncCommandQueued = Base | 0x1e;
|
||||||
|
public static final long ResourceUnavailableException = Base | 0x1f;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,6 +72,8 @@ import com.cloud.utils.mgmt.ManagementBean;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
||||||
protected static final Logger s_logger = Logger.getLogger(ComponentLocator.class);
|
protected static final Logger s_logger = Logger.getLogger(ComponentLocator.class);
|
||||||
|
|
||||||
|
protected static HashMap<String, Object> s_singletons = new HashMap<String, Object>(111);
|
||||||
|
|
||||||
protected HashMap<String, Adapters<? extends Adapter>> _adapterMap;
|
protected HashMap<String, Adapters<? extends Adapter>> _adapterMap;
|
||||||
protected HashMap<String, Info<Manager>> _managerMap;
|
protected HashMap<String, Info<Manager>> _managerMap;
|
||||||
@ -103,11 +105,11 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
public synchronized void run() {
|
public synchronized void run() {
|
||||||
Iterator<Adapters<? extends Adapter>> itAdapters = _adapterMap.values().iterator();
|
Iterator<Adapters<? extends Adapter>> itAdapters = _adapterMap.values().iterator();
|
||||||
while (itAdapters.hasNext()) {
|
while (itAdapters.hasNext()) {
|
||||||
Adapters adapters = itAdapters.next();
|
Adapters<? extends Adapter> adapters = itAdapters.next();
|
||||||
itAdapters.remove();
|
itAdapters.remove();
|
||||||
Enumeration it = adapters.enumeration();
|
Enumeration<? extends Adapter> it = adapters.enumeration();
|
||||||
while (it.hasMoreElements()) {
|
while (it.hasMoreElements()) {
|
||||||
Adapter adapter = (Adapter)it.nextElement();
|
Adapter adapter = it.nextElement();
|
||||||
adapter.stop();
|
adapter.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,7 +184,7 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
Info<GenericDao<?, ?>> info = entry.getValue();
|
Info<GenericDao<?, ?>> info = entry.getValue();
|
||||||
s_logger.info("Starting DAO: " + info.name);
|
s_logger.info("Starting DAO: " + info.name);
|
||||||
try {
|
try {
|
||||||
info.instance = (GenericDao<?, ?>)createInstance(info.clazz, true);
|
info.instance = (GenericDao<?, ?>)createInstance(info.clazz, true, info.singleton);
|
||||||
inject(info.clazz, info.instance);
|
inject(info.clazz, info.instance);
|
||||||
if (!info.instance.configure(info.name, info.params)) {
|
if (!info.instance.configure(info.name, info.params)) {
|
||||||
s_logger.error("Unable to configure DAO: " + info.name);
|
s_logger.error("Unable to configure DAO: " + info.name);
|
||||||
@ -201,9 +203,17 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object createInstance(Class<?> clazz, boolean inject, Object... args) {
|
private static Object createInstance(Class<?> clazz, boolean inject, boolean singleton, Object... args) {
|
||||||
Factory factory = null;
|
Factory factory = null;
|
||||||
|
Object entity = null;
|
||||||
synchronized(s_factories) {
|
synchronized(s_factories) {
|
||||||
|
if (singleton) {
|
||||||
|
entity = s_singletons.get(clazz.toString());
|
||||||
|
if (entity != null) {
|
||||||
|
s_logger.debug("Found singleton instantiation for " + clazz.toString());
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
InjectInfo info = s_factories.get(clazz);
|
InjectInfo info = s_factories.get(clazz);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
Enhancer enhancer = new Enhancer();
|
Enhancer enhancer = new Enhancer();
|
||||||
@ -219,11 +229,10 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Class[] argTypes = null;
|
Class<?>[] argTypes = null;
|
||||||
Object entity;
|
|
||||||
if (args != null && args.length > 0) {
|
if (args != null && args.length > 0) {
|
||||||
Constructor<?>[] constructors = clazz.getConstructors();
|
Constructor<?>[] constructors = clazz.getConstructors();
|
||||||
for (Constructor constructor : constructors) {
|
for (Constructor<?> constructor : constructors) {
|
||||||
Class<?>[] paramTypes = constructor.getParameterTypes();
|
Class<?>[] paramTypes = constructor.getParameterTypes();
|
||||||
if (paramTypes.length == args.length) {
|
if (paramTypes.length == args.length) {
|
||||||
boolean found = true;
|
boolean found = true;
|
||||||
@ -253,6 +262,12 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
inject(clazz, entity);
|
inject(clazz, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (singleton) {
|
||||||
|
synchronized(s_factories) {
|
||||||
|
s_singletons.put(clazz.toString(), entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,13 +290,13 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized Object getComponent(Class clazz) {
|
private static synchronized Object getComponent(Class<?> clazz) {
|
||||||
String name = clazz.getName();
|
String name = clazz.getName();
|
||||||
try {
|
try {
|
||||||
Object component = _componentMap.get(name);
|
Object component = _componentMap.get(name);
|
||||||
if (component == null) {
|
if (component == null) {
|
||||||
Class<?> impl = Class.forName(name);
|
Class<?> impl = Class.forName(name);
|
||||||
component = createInstance(impl, true);
|
component = createInstance(impl, true, true);
|
||||||
_componentMap.put(name, component);
|
_componentMap.put(name, component);
|
||||||
}
|
}
|
||||||
return component;
|
return component;
|
||||||
@ -300,7 +315,7 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
String implementationClass = _implementationClassMap.get(componentName);
|
String implementationClass = _implementationClassMap.get(componentName);
|
||||||
if (implementationClass != null) {
|
if (implementationClass != null) {
|
||||||
try {
|
try {
|
||||||
Class clazz = Class.forName(implementationClass);
|
Class<?> clazz = Class.forName(implementationClass);
|
||||||
return getComponent(clazz);
|
return getComponent(clazz);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
s_logger.error("Failed to get component " + componentName + ", caused by exception " + ex, ex);
|
s_logger.error("Failed to get component " + componentName + ", caused by exception " + ex, ex);
|
||||||
@ -322,7 +337,7 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
Info<Manager> info = entry.getValue();
|
Info<Manager> info = entry.getValue();
|
||||||
if (info.instance == null) {
|
if (info.instance == null) {
|
||||||
s_logger.info("Instantiating Manager: " + info.name);
|
s_logger.info("Instantiating Manager: " + info.name);
|
||||||
info.instance = (Manager)createInstance(info.clazz, false);
|
info.instance = (Manager)createInstance(info.clazz, false, info.singleton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,7 +449,7 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (info.instance == null) {
|
if (info.instance == null) {
|
||||||
info.instance = (Manager)createInstance(info.clazz, false);
|
info.instance = (Manager)createInstance(info.clazz, false, info.singleton);
|
||||||
}
|
}
|
||||||
return (T)info.instance;
|
return (T)info.instance;
|
||||||
}
|
}
|
||||||
@ -446,7 +461,7 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
List<Adapter> lst = new ArrayList<Adapter>();
|
List<Adapter> lst = new ArrayList<Adapter>();
|
||||||
for (Info<Adapter> info : entry.getValue()) {
|
for (Info<Adapter> info : entry.getValue()) {
|
||||||
s_logger.info("Instantiating Adapter: " + info.name);
|
s_logger.info("Instantiating Adapter: " + info.name);
|
||||||
info.instance = (Adapter)createInstance(info.clazz, true);
|
info.instance = (Adapter)createInstance(info.clazz, true, info.singleton);
|
||||||
try {
|
try {
|
||||||
if (!info.instance.configure(info.name, info.params)) {
|
if (!info.instance.configure(info.name, info.params)) {
|
||||||
s_logger.error("Unable to configure adapter: " + info.name);
|
s_logger.error("Unable to configure adapter: " + info.name);
|
||||||
@ -496,11 +511,11 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T inject(Class<T> clazz) {
|
public static <T> T inject(Class<T> clazz) {
|
||||||
return (T)createInstance(clazz, true);
|
return (T)createInstance(clazz, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T inject(Class<T> clazz, Object... args) {
|
public static <T> T inject(Class<T> clazz, Object... args) {
|
||||||
return (T)createInstance(clazz, true, args);
|
return (T)createInstance(clazz, true, false, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -621,8 +636,9 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
Class<?> clazz;
|
Class<?> clazz;
|
||||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||||
String name;
|
String name;
|
||||||
String key;
|
List<String> keys = new ArrayList<String>();
|
||||||
T instance;
|
T instance;
|
||||||
|
boolean singleton = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -634,7 +650,6 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
public HashMap<String, Info<Manager>> managers;
|
public HashMap<String, Info<Manager>> managers;
|
||||||
public LinkedHashMap<String, Info<GenericDao<?, ?>>> daos;
|
public LinkedHashMap<String, Info<GenericDao<?, ?>>> daos;
|
||||||
public String parent;
|
public String parent;
|
||||||
public
|
|
||||||
|
|
||||||
List<Info<Adapter>> lst;
|
List<Info<Adapter>> lst;
|
||||||
String paramName;
|
String paramName;
|
||||||
@ -680,13 +695,14 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
Class<?>[] classes = local.value();
|
Class<?>[] classes = local.value();
|
||||||
for (int i = 0; i < classes.length; i++) {
|
for (int i = 0; i < classes.length; i++) {
|
||||||
if (findInterfaceInHierarchy(classes[i].getInterfaces(), interphace)) {
|
if (findInterfaceInHierarchy(classes[i].getInterfaces(), interphace)) {
|
||||||
info.key = classes[i].getName();
|
info.keys.add(classes[i].getName());
|
||||||
s_logger.info("Found component: " + interphace.getName() + " - " + clazzName + " - " + info.name);
|
s_logger.info("Found component: " + interphace.getName() + " - " + clazzName + " - " + info.name);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CloudRuntimeException("Class " + clazzName + " does not implement " + interphace.getName());
|
if (info.keys.size() != classes.length) {
|
||||||
|
throw new CloudRuntimeException("Class " + clazzName + " does not implement " + interphace.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean findInterfaceInHierarchy(Class<?>[] interphaces, Class<?> interphace) {
|
protected boolean findInterfaceInHierarchy(Class<?>[] interphaces, Class<?> interphace) {
|
||||||
@ -732,7 +748,9 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
Info<Manager> info = new Info<Manager>();
|
Info<Manager> info = new Info<Manager>();
|
||||||
fillInfo(atts, Manager.class, info);
|
fillInfo(atts, Manager.class, info);
|
||||||
s_logger.info("Adding Manager: " + info.name);
|
s_logger.info("Adding Manager: " + info.name);
|
||||||
managers.put(info.key, info);
|
for (String key : info.keys) {
|
||||||
|
managers.put(key, info);
|
||||||
|
}
|
||||||
currentInfo = info;
|
currentInfo = info;
|
||||||
} else if (qName.equals("param")) {
|
} else if (qName.equals("param")) {
|
||||||
paramName = getAttribute(atts, "name");
|
paramName = getAttribute(atts, "name");
|
||||||
@ -740,7 +758,9 @@ public class ComponentLocator extends Thread implements ComponentLocatorMBean {
|
|||||||
} else if (qName.equals("dao")) {
|
} else if (qName.equals("dao")) {
|
||||||
Info<GenericDao<?, ?>> info = new Info<GenericDao<?, ?>>();
|
Info<GenericDao<?, ?>> info = new Info<GenericDao<?, ?>>();
|
||||||
fillInfo(atts, GenericDao.class, info);
|
fillInfo(atts, GenericDao.class, info);
|
||||||
daos.put(info.key, info);
|
for (String key : info.keys) {
|
||||||
|
daos.put(key, info);
|
||||||
|
}
|
||||||
currentInfo = info;
|
currentInfo = info;
|
||||||
} else {
|
} else {
|
||||||
// ignore
|
// ignore
|
||||||
|
|||||||
@ -1031,15 +1031,15 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
|
|||||||
str.insert(fromIndex, onClause);
|
str.insert(fromIndex, onClause);
|
||||||
str.append(" (").append(join.getT().getWhereClause()).append(") AND ");
|
str.append(" (").append(join.getT().getWhereClause()).append(") AND ");
|
||||||
fromIndex+=onClause.length();
|
fromIndex+=onClause.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JoinBuilder<SearchCriteria<?>> join : joins) {
|
str.delete(str.length() - 4, str.length());
|
||||||
if (join.getT().getJoins() != null) {
|
for (JoinBuilder<SearchCriteria<?>> join : joins) {
|
||||||
addJoins(str, join.getT().getJoins());
|
if (join.getT().getJoins() != null) {
|
||||||
|
addJoins(str, join.getT().getJoins());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
str.delete(str.length() - 4, str.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @DB(txn=false)
|
@Override @DB(txn=false)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user