You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2012/12/20 08:50:15 UTC
[1/3] git commit: Remove IdentityProxy from CloudException and
ExceptionResponse.
Updated Branches:
refs/heads/api_refactoring eb2a7dedd -> a88ce6bb7
Remove IdentityProxy from CloudException and ExceptionResponse.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/a88ce6bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/a88ce6bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/a88ce6bb
Branch: refs/heads/api_refactoring
Commit: a88ce6bb7f495dddeb954d1fc7826176646b3590
Parents: eb2a7de
Author: Min Chen <mi...@citrix.com>
Authored: Wed Dec 19 23:49:44 2012 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Dec 19 23:49:44 2012 -0800
----------------------------------------------------------------------
api/src/com/cloud/exception/CloudException.java | 17 +-
.../api/command/admin/cluster/AddClusterCmd.java | 5 +-
.../cloudstack/api/response/ExceptionResponse.java | 9 +-
.../agent/manager/ClusteredAgentManagerImpl.java | 125 ++--
server/src/com/cloud/api/ApiDispatcher.java | 86 +--
server/src/com/cloud/api/ApiServer.java | 25 +-
.../src/com/cloud/network/NetworkManagerImpl.java | 582 ++++++++-------
.../com/cloud/network/as/AutoScaleManagerImpl.java | 5 +-
.../utils/exception/RuntimeCloudException.java | 32 +-
9 files changed, 435 insertions(+), 451 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a88ce6bb/api/src/com/cloud/exception/CloudException.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/exception/CloudException.java b/api/src/com/cloud/exception/CloudException.java
index 8cfae21..fd83956 100644
--- a/api/src/com/cloud/exception/CloudException.java
+++ b/api/src/com/cloud/exception/CloudException.java
@@ -30,7 +30,7 @@ import com.cloud.utils.AnnotationHelper;
public class CloudException extends Exception {
// This holds a list of uuids and their names. Add uuid:fieldname pairs
- protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
+ protected ArrayList<String> idList = new ArrayList<String>();
protected Integer csErrorCode;
@@ -44,26 +44,19 @@ public class CloudException extends Exception {
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
}
- public void addProxyObject(Object voObj, Long id, String idFieldName) {
- // Get the VO object's table name.
- String tablename = AnnotationHelper.getTableName(voObj);
- if (tablename != null) {
- addProxyObject(tablename, id, idFieldName);
- }
- return;
- }
+
public CloudException() {
super();
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
}
- public void addProxyObject(String tableName, Long id, String idFieldName) {
- idList.add(new IdentityProxy(tableName, id, idFieldName));
+ public void addProxyObject(String uuid) {
+ idList.add(uuid);
return;
}
- public ArrayList<IdentityProxy> getIdProxyList() {
+ public ArrayList<String> getIdProxyList() {
return idList;
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a88ce6bb/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
index 77846ee..d9564de 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java
@@ -36,7 +36,6 @@ import com.cloud.exception.DiscoveryException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.org.Cluster;
import com.cloud.user.Account;
-import com.cloud.utils.IdentityProxy;
@Implementation(description="Adds a new cluster", responseObject=ClusterResponse.class)
public class AddClusterCmd extends BaseCmd {
@@ -173,8 +172,8 @@ public class AddClusterCmd extends BaseCmd {
} catch (ResourceInUseException ex) {
s_logger.warn("Exception: ", ex);
ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
- for (IdentityProxy proxyObj : ex.getIdProxyList()) {
- e.addProxyObject(proxyObj.getTableName(), proxyObj.getValue(), proxyObj.getidFieldName());
+ for (String proxyObj : ex.getIdProxyList()) {
+ e.addProxyObject(proxyObj);
}
throw e;
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a88ce6bb/api/src/org/apache/cloudstack/api/response/ExceptionResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/ExceptionResponse.java b/api/src/org/apache/cloudstack/api/response/ExceptionResponse.java
index a4050a2..5f8e642 100644
--- a/api/src/org/apache/cloudstack/api/response/ExceptionResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/ExceptionResponse.java
@@ -19,14 +19,13 @@ package org.apache.cloudstack.api.response;
import java.util.ArrayList;
import com.cloud.serializer.Param;
-import com.cloud.utils.IdentityProxy;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;
public class ExceptionResponse extends BaseResponse {
@SerializedName("uuidList") @Param(description="List of uuids associated with this error")
- private ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
+ private ArrayList<String> idList;
@SerializedName("errorcode") @Param(description="numeric code associated with this error")
private Integer errorCode;
@@ -53,12 +52,12 @@ public class ExceptionResponse extends BaseResponse {
this.errorText = errorText;
}
- public void addProxyObject(String tableName, Long id, String idFieldName) {
- idList.add(new IdentityProxy(tableName, id, idFieldName));
+ public void addProxyObject(String id) {
+ idList.add(id);
return;
}
- public ArrayList<IdentityProxy> getIdProxyList() {
+ public ArrayList<String> getIdProxyList() {
return idList;
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a88ce6bb/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
index 1b6dc44..ca0bf5c 100755
--- a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
+++ b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
@@ -53,6 +53,7 @@ import com.cloud.agent.api.TransferAgentCommand;
import com.cloud.agent.transport.Request;
import com.cloud.agent.transport.Request.Version;
import com.cloud.agent.transport.Response;
+import com.cloud.api.ApiDBUtils;
import com.cloud.cluster.ClusterManager;
import com.cloud.cluster.ClusterManagerListener;
import com.cloud.cluster.ClusteredAgentRebalanceService;
@@ -92,13 +93,13 @@ import com.cloud.utils.nio.Task;
public class ClusteredAgentManagerImpl extends AgentManagerImpl implements ClusterManagerListener, ClusteredAgentRebalanceService {
final static Logger s_logger = Logger.getLogger(ClusteredAgentManagerImpl.class);
private static final ScheduledExecutorService s_transferExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Cluster-AgentTransferExecutor"));
- private final long rebalanceTimeOut = 300000; // 5 mins - after this time remove the agent from the transfer list
+ private final long rebalanceTimeOut = 300000; // 5 mins - after this time remove the agent from the transfer list
public final static long STARTUP_DELAY = 5000;
public final static long SCAN_INTERVAL = 90000; // 90 seconds, it takes 60 sec for xenserver to fail login
public final static int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds
public long _loadSize = 100;
- protected Set<Long> _agentToTransferIds = new HashSet<Long>();
+ protected Set<Long> _agentToTransferIds = new HashSet<Long>();
@Inject
protected ClusterManager _clusterMgr = null;
@@ -111,10 +112,10 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
protected ManagementServerHostDao _mshostDao;
@Inject
protected HostTransferMapDao _hostTransferDao;
-
+
@Inject(adapter = AgentLoadBalancerPlanner.class)
protected Adapters<AgentLoadBalancerPlanner> _lbPlanners;
-
+
@Inject
protected AgentManager _agentMgr;
@@ -127,7 +128,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
_peers = new HashMap<String, SocketChannel>(7);
_sslEngines = new HashMap<String, SSLEngine>(7);
_nodeId = _clusterMgr.getManagementNodeId();
-
+
s_logger.info("Configuring ClusterAgentManagerImpl. management server node id(msid): " + _nodeId);
ConfigurationDao configDao = ComponentLocator.getCurrentLocator().getDao(ConfigurationDao.class);
@@ -138,7 +139,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
ClusteredAgentAttache.initialize(this);
_clusterMgr.registerListener(this);
-
+
return super.configure(name, xmlParams);
}
@@ -172,7 +173,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
List<HostVO> hosts = _hostDao.findAndUpdateDirectAgentToLoad(cutSeconds, _loadSize, _nodeId);
List<HostVO> appliances = _hostDao.findAndUpdateApplianceToLoad(cutSeconds, _nodeId);
hosts.addAll(appliances);
-
+
if (hosts != null && hosts.size() > 0) {
s_logger.debug("Found " + hosts.size() + " unmanaged direct hosts, processing connect for them...");
for (HostVO host : hosts) {
@@ -273,12 +274,12 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event, boolean transitState) {
return handleDisconnect(attache, event, false, true);
}
-
+
@Override
protected boolean handleDisconnectWithInvestigation(AgentAttache attache, Status.Event event) {
return handleDisconnect(attache, event, true, true);
}
-
+
protected boolean handleDisconnect(AgentAttache agent, Status.Event event, boolean investigate, boolean broadcast) {
boolean res;
if (!investigate) {
@@ -316,7 +317,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
}
}
-
+
//don't process disconnect if the disconnect came for the host via delayed cluster notification,
//but the host has already reconnected to the current management server
if (!attache.forForward()) {
@@ -324,7 +325,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
+ hostId +" as the host is directly connected to the current management server " + _nodeId);
return true;
}
-
+
return super.handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, false);
}
@@ -346,7 +347,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.debug("cannot propagate agent reconnect because agent is not available", e);
return false;
}
-
+
return super.reconnect(hostId);
}
@@ -408,7 +409,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
public String findPeer(long hostId) {
return _clusterMgr.getPeerName(hostId);
}
-
+
public SSLEngine getSSLEngine(String peerName) {
return _sslEngines.get(peerName);
}
@@ -516,7 +517,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
if (agent == null) {
AgentUnavailableException ex = new AgentUnavailableException("Host with specified id is not in the right state: " + host.getStatus(), hostId);
- ex.addProxyObject(host, hostId, "hostId");
+ ex.addProxyObject(ApiDBUtils.findHostById(hostId).getUuid());
throw ex;
}
@@ -535,11 +536,11 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
}
_timer.cancel();
-
+
//cancel all transfer tasks
s_transferExecutor.shutdownNow();
cleanupTransferMap(_nodeId);
-
+
return super.stop();
}
@@ -705,7 +706,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
return result;
}
-
+
@Override
public void scheduleRebalanceAgents() {
_timer.schedule(new AgentLoadBalancerTask(), 30000);
@@ -743,7 +744,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
}
}
-
+
public void startRebalanceAgents() {
s_logger.debug("Management server " + _nodeId + " is asking other peers to rebalance their agents");
List<ManagementServerHostVO> allMS = _mshostDao.listBy(ManagementServerHost.State.Up);
@@ -762,7 +763,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
return;
}
-
+
if (avLoad == 0L) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("As calculated average load is less than 1, rounding it to 1");
@@ -772,7 +773,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
for (ManagementServerHostVO node : allMS) {
if (node.getMsid() != _nodeId) {
-
+
List<HostVO> hostsToRebalance = new ArrayList<HostVO>();
for (AgentLoadBalancerPlanner lbPlanner : _lbPlanners) {
hostsToRebalance = lbPlanner.getHostsToRebalance(node.getMsid(), avLoad);
@@ -783,20 +784,20 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
}
-
+
if (hostsToRebalance != null && !hostsToRebalance.isEmpty()) {
s_logger.debug("Found " + hostsToRebalance.size() + " hosts to rebalance from management server " + node.getMsid());
for (HostVO host : hostsToRebalance) {
long hostId = host.getId();
s_logger.debug("Asking management server " + node.getMsid() + " to give away host id=" + hostId);
boolean result = true;
-
+
if (_hostTransferDao.findById(hostId) != null) {
s_logger.warn("Somebody else is already rebalancing host id: " + hostId);
continue;
}
- HostTransferMapVO transfer = null;
+ HostTransferMapVO transfer = null;
try {
transfer = _hostTransferDao.startAgentTransfering(hostId, node.getMsid(), _nodeId);
Answer[] answer = sendRebalanceCommand(node.getMsid(), hostId, node.getMsid(), _nodeId, Event.RequestAgentRebalance);
@@ -862,7 +863,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
for (Iterator<Long> iterator = _agentToTransferIds.iterator(); iterator.hasNext();) {
Long hostId = iterator.next();
AgentAttache attache = findAttache(hostId);
-
+
// if the thread:
// 1) timed out waiting for the host to reconnect
// 2) recipient management server is not active any more
@@ -878,22 +879,22 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
_hostTransferDao.completeAgentTransfer(hostId);
continue;
}
-
+
if (transferMap.getInitialOwner() != _nodeId || attache == null || attache.forForward()) {
s_logger.debug("Management server " + _nodeId + " doesn't own host id=" + hostId + " any more, skipping rebalance for the host");
iterator.remove();
_hostTransferDao.completeAgentTransfer(hostId);
continue;
}
-
+
ManagementServerHostVO ms = _mshostDao.findByMsid(transferMap.getFutureOwner());
if (ms != null && ms.getState() != ManagementServerHost.State.Up) {
s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms + ", skipping rebalance for the host");
iterator.remove();
_hostTransferDao.completeAgentTransfer(hostId);
continue;
- }
-
+ }
+
if (attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) {
iterator.remove();
try {
@@ -902,9 +903,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.warn("Failed to submit rebalance task for host id=" + hostId + "; postponing the execution");
continue;
}
-
+
} else {
- s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is " + attache.getNonRecurringListenersSize());
+ s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is " + attache.getNonRecurringListenersSize());
}
}
} else {
@@ -920,16 +921,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
};
}
-
-
+
+
private boolean setToWaitForRebalance(final long hostId, long currentOwnerId, long futureOwnerId) {
s_logger.debug("Adding agent " + hostId + " to the list of agents to transfer");
synchronized (_agentToTransferIds) {
return _agentToTransferIds.add(hostId);
}
}
-
-
+
+
protected boolean rebalanceHost(final long hostId, long currentOwnerId, long futureOwnerId) throws AgentUnavailableException{
boolean result = true;
@@ -949,7 +950,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.warn("Host " + hostId + " failed to connect to the management server " + futureOwnerId + " as a part of rebalance process", ex);
result = false;
}
-
+
if (result) {
s_logger.debug("Successfully transfered host id=" + hostId + " to management server " + futureOwnerId);
finishRebalance(hostId, futureOwnerId, Event.RebalanceCompleted);
@@ -957,7 +958,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.warn("Failed to transfer host id=" + hostId + " to management server " + futureOwnerId);
finishRebalance(hostId, futureOwnerId, Event.RebalanceFailed);
}
-
+
} else if (futureOwnerId == _nodeId) {
HostVO host = _hostDao.findById(hostId);
try {
@@ -976,15 +977,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
result = loadDirectlyConnectedHost(host, true);
} else {
- s_logger.warn("Failed to disconnect " + host.getId() + "(" + host.getName() +
+ s_logger.warn("Failed to disconnect " + host.getId() + "(" + host.getName() +
" as a part of rebalance process without notification");
}
-
+
} catch (Exception ex) {
s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process due to:", ex);
result = false;
}
-
+
if (result) {
s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
} else {
@@ -994,7 +995,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
return result;
}
-
+
protected void finishRebalance(final long hostId, long futureOwnerId, Event event){
@@ -1002,21 +1003,21 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
if (s_logger.isDebugEnabled()) {
s_logger.debug("Finishing rebalancing for the agent " + hostId + " with event " + event);
}
-
+
AgentAttache attache = findAttache(hostId);
if (attache == null || !(attache instanceof ClusteredAgentAttache)) {
s_logger.debug("Unable to find forward attache for the host id=" + hostId + ", assuming that the agent disconnected already");
_hostTransferDao.completeAgentTransfer(hostId);
return;
- }
-
+ }
+
ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache)attache;
-
+
if (success) {
//1) Set transfer mode to false - so the agent can start processing requests normally
forwardAttache.setTransferMode(false);
-
+
//2) Get all transfer requests and route them to peer
Request requestToTransfer = forwardAttache.getRequestToTransfer();
while (requestToTransfer != null) {
@@ -1025,20 +1026,20 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
if (!routeResult) {
logD(requestToTransfer.getBytes(), "Failed to route request to peer");
}
-
+
requestToTransfer = forwardAttache.getRequestToTransfer();
}
-
+
s_logger.debug("Management server " + _nodeId + " completed agent " + hostId + " rebalance to " + futureOwnerId);
-
+
} else {
failRebalance(hostId);
}
-
+
s_logger.debug("Management server " + _nodeId + " completed agent " + hostId + " rebalance");
_hostTransferDao.completeAgentTransfer(hostId);
}
-
+
protected void failRebalance(final long hostId){
try {
s_logger.debug("Management server " + _nodeId + " failed to rebalance agent " + hostId);
@@ -1048,15 +1049,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
s_logger.warn("Failed to reconnect host id=" + hostId + " as a part of failed rebalance task cleanup");
}
}
-
+
protected boolean startRebalance(final long hostId) {
HostVO host = _hostDao.findById(hostId);
-
+
if (host == null || host.getRemoved() != null) {
s_logger.warn("Unable to find host record, fail start rebalancing process");
return false;
- }
-
+ }
+
synchronized (_agents) {
ClusteredDirectAgentAttache attache = (ClusteredDirectAgentAttache)_agents.get(hostId);
if (attache != null && attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) {
@@ -1081,27 +1082,27 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
_hostTransferDao.startAgentTransfer(hostId);
return true;
}
-
+
protected void cleanupTransferMap(long msId) {
List<HostTransferMapVO> hostsJoingingCluster = _hostTransferDao.listHostsJoiningCluster(msId);
-
+
for (HostTransferMapVO hostJoingingCluster : hostsJoingingCluster) {
_hostTransferDao.remove(hostJoingingCluster.getId());
}
-
+
List<HostTransferMapVO> hostsLeavingCluster = _hostTransferDao.listHostsLeavingCluster(msId);
for (HostTransferMapVO hostLeavingCluster : hostsLeavingCluster) {
_hostTransferDao.remove(hostLeavingCluster.getId());
}
}
-
-
+
+
protected class RebalanceTask implements Runnable {
Long hostId = null;
Long currentOwnerId = null;
Long futureOwnerId = null;
-
-
+
+
public RebalanceTask(long hostId, long currentOwnerId, long futureOwnerId) {
this.hostId = hostId;
this.currentOwnerId = currentOwnerId;
@@ -1122,5 +1123,5 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a88ce6bb/server/src/com/cloud/api/ApiDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java
index 3dfcbce..99ba05d 100755
--- a/server/src/com/cloud/api/ApiDispatcher.java
+++ b/server/src/com/cloud/api/ApiDispatcher.java
@@ -111,7 +111,7 @@ public class ApiDispatcher {
setupParameters(cmd, params, entitiesToAccess);
doAccessChecks(cmd, entitiesToAccess);
-
+
try {
UserContext ctx = UserContext.current();
ctx.setAccountId(cmd.getEntityOwnerId());
@@ -158,18 +158,18 @@ public class ApiDispatcher {
List<Role> callerRoles = determineRole(caller);
List<Role> ownerRoles = determineRole(owner);
-
+
//check permission to call this command for the caller
//this needs checking of static roles of the caller
checkACLOnCommand(cmd);
-
+
//check that caller can access the owner account.
_accountMgr.checkAccess(caller, null, true, owner);
-
+
checkACLOnEntities(caller, entitiesToAccess);
}
-
-
+
+
private void checkACLOnCommand(BaseAsyncCreateCmd cmd) {
// TODO Auto-generated method stub
//need to write an commandACLChecker adapter framework to check ACL on commands - default one will use the static roles by referring to commands.properties.
@@ -180,7 +180,7 @@ public class ApiDispatcher {
// TODO Auto-generated method stub
List<Role> effectiveRoles = new ArrayList<Role>();
return effectiveRoles;
-
+
}
private void checkACLOnEntities(Account caller, List<ControlledEntity> entitiesToAccess){
@@ -203,7 +203,7 @@ public class ApiDispatcher {
for(ControlledEntity entity : entitiesToAccess)
s_instance._accountMgr.checkAccess(caller, null, true, entity);
}
-
+
try {
UserContext ctx = UserContext.current();
ctx.setAccountId(cmd.getEntityOwnerId());
@@ -221,9 +221,9 @@ public class ApiDispatcher {
} else {
queueSizeLimit = 1L;
}
-
+
if (queueSizeLimit != null) {
- _asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(),
+ _asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(),
asyncCmd.getSyncObjId().longValue(), queueSizeLimit);
} else {
s_logger.trace("The queue size is unlimited, skipping the synchronizing");
@@ -241,13 +241,12 @@ public class ApiDispatcher {
InvalidParameterValueException ref = (InvalidParameterValueException) t;
ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
- s_logger.info(t.getMessage() + " db_id: " + id.getValue());
+ ex.addProxyObject(idList.get(i));
+ s_logger.info(t.getMessage() + " uuid: " + idList.get(i));
}
} else {
s_logger.info(t.getMessage());
@@ -255,19 +254,18 @@ public class ApiDispatcher {
// Also copy over the cserror code.
ex.setCSErrorCode(ref.getCSErrorCode());
throw ex;
- } else if(t instanceof IllegalArgumentException) {
+ } else if(t instanceof IllegalArgumentException) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
- } else if (t instanceof PermissionDeniedException) {
+ } else if (t instanceof PermissionDeniedException) {
PermissionDeniedException ref = (PermissionDeniedException)t;
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
- s_logger.info("PermissionDenied: " + t.getMessage() + "db_id: " + id.getValue());
+ ex.addProxyObject(idList.get(i));
+ s_logger.info("PermissionDenied: " + t.getMessage() + "uuid: " + idList.get(i));
}
} else {
s_logger.info("PermissionDenied: " + t.getMessage());
@@ -275,17 +273,16 @@ public class ApiDispatcher {
// Also copy over the cserror code.
ex.setCSErrorCode(ref.getCSErrorCode());
throw ex;
- } else if (t instanceof AccountLimitException) {
+ } else if (t instanceof AccountLimitException) {
AccountLimitException ref = (AccountLimitException)t;
ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
- s_logger.info(t.getMessage() + "db_id: " + id.getValue());
+ ex.addProxyObject(idList.get(i));
+ s_logger.info(t.getMessage() + "uuid: " + idList.get(i));
}
} else {
s_logger.info(t.getMessage());
@@ -293,17 +290,16 @@ public class ApiDispatcher {
// Also copy over the cserror code.
ex.setCSErrorCode(ref.getCSErrorCode());
throw ex;
- } else if (t instanceof InsufficientCapacityException) {
+ } else if (t instanceof InsufficientCapacityException) {
InsufficientCapacityException ref = (InsufficientCapacityException)t;
ServerApiException ex = new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
- s_logger.info(t.getMessage() + "db_id: " + id.getValue());
+ ex.addProxyObject(idList.get(i));
+ s_logger.info(t.getMessage() + "uuid: " + idList.get(i));
}
} else {
s_logger.info(t.getMessage());
@@ -315,13 +311,13 @@ public class ApiDispatcher {
ResourceAllocationException ref = (ResourceAllocationException)t;
ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
- s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
+ String id = idList.get(i);
+ ex.addProxyObject(id);
+ s_logger.warn("Exception: " + t.getMessage() + "uuid: " + id);
}
} else {
s_logger.warn("Exception: ", t);
@@ -333,13 +329,13 @@ public class ApiDispatcher {
ResourceUnavailableException ref = (ResourceUnavailableException)t;
ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- ex.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
- s_logger.warn("Exception: " + t.getMessage() + "db_id: " + id.getValue());
+ String id = idList.get(i);
+ ex.addProxyObject(id);
+ s_logger.warn("Exception: " + t.getMessage() + "uuid: " + id);
}
} else {
s_logger.warn("Exception: ", t);
@@ -347,7 +343,7 @@ public class ApiDispatcher {
// Also copy over the cserror code.
ex.setCSErrorCode(ref.getCSErrorCode());
throw ex;
- } else if (t instanceof AsyncCommandQueued) {
+ } else if (t instanceof AsyncCommandQueued) {
throw (AsyncCommandQueued) t;
} else if (t instanceof ServerApiException) {
s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription());
@@ -359,7 +355,7 @@ public class ApiDispatcher {
ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
} else {
ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
- }
+ }
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
throw ex;
}
@@ -378,7 +374,7 @@ public class ApiDispatcher {
}
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
- ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
+ ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
throw ex;
} else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) {
@@ -524,9 +520,9 @@ public class ApiDispatcher {
}
}
-
+
}
-
+
} catch (IllegalArgumentException e) {
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]");
@@ -534,9 +530,9 @@ public class ApiDispatcher {
s_logger.error("Error initializing command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible.");
throw new CloudRuntimeException("Internal error initializing parameters for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]");
}
-
+
}
-
+
//check access on the entities.
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a88ce6bb/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index b440f17..e685aef 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -336,12 +336,11 @@ public class ApiServer implements HttpRequestHandler {
InvalidParameterValueException ref = (InvalidParameterValueException)ex;
ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy obj = idList.get(i);
- e.addProxyObject(obj.getTableName(), obj.getValue(), obj.getidFieldName());
+ e.addProxyObject(idList.get(i));
}
}
// Also copy over the cserror code and the function/layer in which it was thrown.
@@ -351,12 +350,11 @@ public class ApiServer implements HttpRequestHandler {
PermissionDeniedException ref = (PermissionDeniedException)ex;
ServerApiException e = new ServerApiException(BaseCmd.ACCOUNT_ERROR, ex.getMessage());
// copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
// Iterate through entire arraylist and copy over each proxy id.
for (int i = 0 ; i < idList.size(); i++) {
- IdentityProxy obj = idList.get(i);
- e.addProxyObject(obj.getTableName(), obj.getValue(), obj.getidFieldName());
+ e.addProxyObject(idList.get(i));
}
}
e.setCSErrorCode(ref.getCSErrorCode());
@@ -963,33 +961,30 @@ public class ApiServer implements HttpRequestHandler {
// Cast the exception appropriately and retrieve the IdentityProxy
if (ex instanceof ServerApiException) {
ServerApiException ref = (ServerApiException) ex;
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
for (int i=0; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
+ apiResponse.addProxyObject(idList.get(i));
}
}
// Also copy over the cserror code and the function/layer in which it was thrown.
apiResponse.setCSErrorCode(ref.getCSErrorCode());
} else if (ex instanceof PermissionDeniedException) {
PermissionDeniedException ref = (PermissionDeniedException) ex;
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
for (int i=0; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
+ apiResponse.addProxyObject(idList.get(i));
}
}
// Also copy over the cserror code and the function/layer in which it was thrown.
apiResponse.setCSErrorCode(ref.getCSErrorCode());
} else if (ex instanceof InvalidParameterValueException) {
InvalidParameterValueException ref = (InvalidParameterValueException) ex;
- ArrayList<IdentityProxy> idList = ref.getIdProxyList();
+ ArrayList<String> idList = ref.getIdProxyList();
if (idList != null) {
for (int i=0; i < idList.size(); i++) {
- IdentityProxy id = idList.get(i);
- apiResponse.addProxyObject(id.getTableName(), id.getValue(), id.getidFieldName());
+ apiResponse.addProxyObject(idList.get(i));
}
}
// Also copy over the cserror code and the function/layer in which it was thrown.