diff --git a/api/src/com/cloud/exception/CloudException.java b/api/src/com/cloud/exception/CloudException.java index 8cfae21e8d1..fd839565253 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 idList = new ArrayList(); + protected ArrayList idList = new ArrayList(); 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 getIdProxyList() { + public ArrayList getIdProxyList() { return idList; } 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 77846ee3295..d9564de3775 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; } diff --git a/api/src/org/apache/cloudstack/api/response/ExceptionResponse.java b/api/src/org/apache/cloudstack/api/response/ExceptionResponse.java index a4050a24af4..5f8e642140a 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 idList = new ArrayList(); + private ArrayList 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 getIdProxyList() { + public ArrayList getIdProxyList() { return idList; } diff --git a/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index 1b6dc44a1a3..ca0bf5cb60d 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 _agentToTransferIds = new HashSet(); + protected Set _agentToTransferIds = new HashSet(); @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 _lbPlanners; - + @Inject protected AgentManager _agentMgr; @@ -127,7 +128,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust _peers = new HashMap(7); _sslEngines = new HashMap(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 hosts = _hostDao.findAndUpdateDirectAgentToLoad(cutSeconds, _loadSize, _nodeId); List 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 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 hostsToRebalance = new ArrayList(); 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 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 hostsJoingingCluster = _hostTransferDao.listHostsJoiningCluster(msId); - + for (HostTransferMapVO hostJoingingCluster : hostsJoingingCluster) { _hostTransferDao.remove(hostJoingingCluster.getId()); } - + List 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 } } } - + } diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 3dfcbce7662..99ba05da833 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 callerRoles = determineRole(caller); List 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 effectiveRoles = new ArrayList(); return effectiveRoles; - + } private void checkACLOnEntities(Account caller, List 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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. } diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index b440f17b9cc..e685aef4b3e 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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 idList = ref.getIdProxyList(); + ArrayList 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. diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 651f33b3948..347cb2ffcc5 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -5,7 +5,7 @@ // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, @@ -59,6 +59,8 @@ import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.agent.api.to.NicTO; import com.cloud.alert.AlertManager; +import com.cloud.api.ApiDBUtils; + import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; @@ -377,7 +379,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @DB - public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, + public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner, VlanType vlanUse, Long guestNetworkId, boolean sourceNat, boolean assign, String requestedIp, boolean isSystem, Long vpcId) throws InsufficientAddressCapacityException { StringBuilder errorMessage = new StringBuilder("Unable to get ip adress in "); @@ -423,13 +425,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException ("Insufficient address capacity", Pod.class, podId); // for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object. - ex.addProxyObject("Pod", podId, "podId"); + ex.addProxyObject(ApiDBUtils.findPodById(podId).getUuid()); throw ex; } s_logger.warn(errorMessage.toString()); InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException ("Insufficient address capacity", DataCenter.class, dcId); - ex.addProxyObject("data_center", dcId, "dcId"); + ex.addProxyObject(ApiDBUtils.findZoneById(dcId).getUuid()); throw ex; } @@ -487,9 +489,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag VlanVO vlan = _vlanDao.findById(addr.getVlanId()); String guestType = vlan.getVlanType().toString(); - - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), - addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, + + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), + addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getSystem()); _usageEventDao.persist(usageEvent); // don't increment resource count for direct ip addresses @@ -501,9 +503,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.commit(); } - + @Override - public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) + public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException { assert (guestNetwork.getTrafficType() != null) : "You're asking for a source nat but your network " + "can't participate in source nat. What do you have to say for yourself?"; @@ -513,28 +515,28 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag PublicIp ipToReturn = null; if (sourceNatIp != null) { - ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), + ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress())); } else { ipToReturn = assignDedicateIpAddress(owner, guestNetwork.getId(), null, dcId, true); } - + return ipToReturn; } - + @Override public PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) throws InsufficientAddressCapacityException, ConcurrentOperationException { return assignDedicateIpAddress(owner, null, vpcId, dcId, false); } - + @DB @Override - public PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat) + public PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat) throws ConcurrentOperationException, InsufficientAddressCapacityException { long ownerId = owner.getId(); - + // Check that the maximum number of public IPs for the given accountId will not be exceeded try { _resourceLimitMgr.checkResourceLimit(owner, ResourceType.public_ip); @@ -558,7 +560,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (s_logger.isDebugEnabled()) { s_logger.debug("lock account " + ownerId + " is acquired"); } - + // If account has Account specific ip ranges, try to allocate ip from there Long vlanId = null; List maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ownerId); @@ -567,7 +569,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } - ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, guestNtwkId, + ip = fetchNewPublicIp(dcId, null, vlanId, owner, VlanType.VirtualNetwork, guestNtwkId, isSourceNat, false, null, false, vpcId); IPAddressVO publicIp = ip.ip(); @@ -593,7 +595,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag /** * Returns the target account for an api command - * + * * @param accountName * - non-null if the account name was passed in in the command * @param domainId @@ -637,7 +639,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List publicIps = new ArrayList(); if (userIps != null && !userIps.isEmpty()) { for (IPAddressVO userIp : userIps) { - PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), + PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress())); publicIps.add(publicIp); } @@ -654,7 +656,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // system if (cleanupIpResources(addr.getId(), Account.ACCOUNT_ID_SYSTEM, _accountMgr.getSystemAccount())) { s_logger.debug("Unassiging ip address " + addr); - _ipAddressDao.unassignIpAddress(addr.getId()); + _ipAddressDao.unassignIpAddress(addr.getId()); } else { success = false; s_logger.warn("Failed to release resources for ip address id=" + addr.getId()); @@ -737,7 +739,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (purposes == null || purposes.isEmpty()) { // since no active rules are there check if any rules are applied on the public IP but are in // revoking state - + purposes = getPublicIpPurposeInRules(ip, true, includingFirewall); if (ip.isOneToOneNat()) { if (purposes == null) { @@ -851,11 +853,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (services == null || services.isEmpty()) { return true; } - + if (networkId == null) { networkId = publicIp.getAssociatedWithNetworkId(); } - + // We only support one provider for one service now Map> serviceToProviders = getServiceProvidersMap(networkId); Set oldProviders = serviceToProviders.get(services.toArray()[0]); @@ -924,7 +926,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return providerToIpList; } - protected boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError, + protected boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError, List publicIps) throws ResourceUnavailableException { boolean success = true; @@ -1004,7 +1006,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return _networksDao.listByZoneAndGuestType(owner.getId(), zoneId, Network.GuestType.Isolated, false); } - + @Override public List getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner) { @@ -1014,23 +1016,23 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true) - public IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) + public IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); long callerUserId = UserContext.current().getCallerUserId(); // check permissions _accountMgr.checkAccess(caller, null, false, ipOwner); - + DataCenter zone = _configMgr.getZone(zoneId); - + return allocateIp(ipOwner, isSystem, caller, callerUserId, zone); } @DB - public IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerUserId, DataCenter zone) + public IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerUserId, DataCenter zone) throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException { - + VlanType vlanType = VlanType.VirtualNetwork; boolean assign = false; @@ -1066,14 +1068,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.start(); - ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, + ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, null, isSystem, null); if (ip == null) { InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException ("Unable to find available public IP addresses", DataCenter.class, zone.getId()); - ex.addProxyObject("data_center", zone.getId(), "zoneId"); + ex.addProxyObject(ApiDBUtils.findZoneById(zone.getId()).getUuid()); throw ex; } UserContext.current().setEventDetails("Ip Id: " + ip.getId()); @@ -1094,7 +1096,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return ip; } - + protected IPAddressVO getExistingSourceNatInNetwork(long ownerId, Long networkId) { List addrs = listPublicIpsAssignedToGuestNtwk(ownerId, networkId, true); @@ -1113,15 +1115,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag assert (sourceNatIp != null) : "How do we get a bunch of ip addresses but none of them are source nat? " + "account=" + ownerId + "; networkId=" + networkId; - } - + } + return sourceNatIp; } @DB @Override - public IPAddressVO associateIPToGuestNetwork(long ipId, long networkId, boolean releaseOnFailure) - throws ResourceAllocationException, ResourceUnavailableException, + public IPAddressVO associateIPToGuestNetwork(long ipId, long networkId, boolean releaseOnFailure) + throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = UserContext.current().getCaller(); Account owner = null; @@ -1134,12 +1136,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.debug("Unable to find ip address by id: " + ipId); return null; } - + if (ipToAssoc.getAssociatedWithNetworkId() != null) { s_logger.debug("IP " + ipToAssoc + " is already assocaited with network id" + networkId); return ipToAssoc; } - + Network network = _networksDao.findById(networkId); if (network != null) { _accountMgr.checkAccess(owner, AccessType.UseNetwork, false, network); @@ -1147,12 +1149,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.debug("Unable to find ip address by id: " + ipId); return null; } - + DataCenter zone = _configMgr.getZone(network.getDataCenterId()); // allow associating IP addresses to guest network only if (network.getTrafficType() != TrafficType.Guest) { - throw new InvalidParameterValueException("Ip address can be associated to the network with trafficType " + + throw new InvalidParameterValueException("Ip address can be associated to the network with trafficType " + TrafficType.Guest); } @@ -1161,16 +1163,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != owner.getId()) { throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP"); } - + // In Advance zone only allow to do IP assoc for Isolated networks with source nat service enabled - if (zone.getNetworkType() == NetworkType.Advanced && - !(network.getGuestType() == GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), + if (zone.getNetworkType() == NetworkType.Advanced && + !(network.getGuestType() == GuestType.Isolated && areServicesSupportedInNetwork(network.getId(), Service.SourceNat))) { - throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + + throw new InvalidParameterValueException("In zone of type " + NetworkType.Advanced + " ip address can be associated only to the network of guest type " + GuestType.Isolated + " with the " + Service.SourceNat.getName() + " enabled"); } - + NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); boolean sharedSourceNat = offering.getSharedSourceNat(); boolean isSourceNat = false; @@ -1181,15 +1183,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } } - + s_logger.debug("Associating ip " + ipToAssoc + " to network " + network); - + IPAddressVO ip = _ipAddressDao.findById(ipId); //update ip address with networkId ip.setAssociatedWithNetworkId(networkId); ip.setSourceNat(isSourceNat); _ipAddressDao.update(ipId, ip); - + boolean success = false; try { success = applyIpAssociations(network, false); @@ -1217,7 +1219,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } } - + @Override @DB @@ -1317,7 +1319,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sgProviders.add(Provider.SecurityGroupProvider); defaultSharedSGEnabledNetworkOfferingProviders.put(Service.SecurityGroup, sgProviders); - Map> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = + Map> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap>(); defaultProviders.clear(); defaultProviders.add(Network.Provider.VirtualRouter); @@ -1331,9 +1333,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.StaticNat, defaultProviders); defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.PortForwarding, defaultProviders); defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Vpn, defaultProviders); - - - Map> defaultVPCOffProviders = + + + Map> defaultVPCOffProviders = new HashMap>(); defaultProviders.clear(); defaultProviders.add(Network.Provider.VirtualRouter); @@ -1389,7 +1391,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } - + if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, @@ -1398,7 +1400,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } - + if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB) == null) { //remove LB service defaultVPCOffProviders.remove(Service.Lb); @@ -1411,14 +1413,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) { - offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, + offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } - + Map> netscalerServiceProviders = new HashMap>(); Set vrProvider = new HashSet(); vrProvider.add(Provider.VirtualRouter); @@ -1432,7 +1434,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag netscalerServiceProviders.put(Service.SecurityGroup, sgProvider); netscalerServiceProviders.put(Service.StaticNat, nsProvider); netscalerServiceProviders.put(Service.Lb, nsProvider); - + Map> serviceCapabilityMap = new HashMap>(); Map elb = new HashMap(); elb.put(Capability.ElasticLb, "true"); @@ -1440,7 +1442,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag eip.put(Capability.ElasticIp, "true"); serviceCapabilityMap.put(Service.Lb, elb); serviceCapabilityMap.put(Service.StaticNat, eip); - + if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true); @@ -1559,7 +1561,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public List listPublicIpsAssignedToGuestNtwk(long accountId, long associatedNetworkId, Boolean sourceNat) { SearchCriteria sc = IpAddressSearch.create(); sc.setParameters("accountId", accountId); - sc.setParameters("associatedWithNetworkId", associatedNetworkId); + sc.setParameters("associatedWithNetworkId", associatedNetworkId); if (sourceNat != null) { sc.addAnd("sourceNat", SearchCriteria.Op.EQ, sourceNat); @@ -1568,7 +1570,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return _ipAddressDao.search(sc, null); } - + @Override public List listPublicIpsAssignedToAccount(long accountId, long dcId, Boolean sourceNat) { SearchCriteria sc = IpAddressSearch.create(); @@ -1585,7 +1587,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override - public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, + public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) throws ConcurrentOperationException { return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null, null); @@ -1593,10 +1595,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan + public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException { - + Account locked = _accountDao.acquireInLockTable(owner.getId()); if (locked == null) { throw new ConcurrentOperationException("Unable to acquire lock on " + owner); @@ -1604,7 +1606,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag try { if (predefined == null - || (offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null && predefined.getBroadcastUri() == null && + || (offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null && predefined.getBroadcastUri() == null && !(predefined.getBroadcastDomainType() == BroadcastDomainType.Vlan || predefined.getBroadcastDomainType() == BroadcastDomainType.Lswitch))) { List configs = _networksDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); if (configs.size() > 0) { @@ -1615,7 +1617,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (errorIfAlreadySetup) { InvalidParameterValueException ex = new InvalidParameterValueException("Found existing network configuration (with specified id) for offering (with specified id)"); ex.addProxyObject(offering, offering.getId(), "offeringId"); - ex.addProxyObject(configs.get(0), configs.get(0).getId(), "networkConfigId"); + ex.addProxyObject(configs.get(0), configs.get(0).getId(), "networkConfigId"); throw ex; } else { return configs; @@ -1632,7 +1634,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (errorIfAlreadySetup) { InvalidParameterValueException ex = new InvalidParameterValueException("Found existing network configuration (with specified id) for offering (with specified id)"); ex.addProxyObject(offering, offering.getId(), "offeringId"); - ex.addProxyObject(configs.get(0), configs.get(0).getId(), "networkConfigId"); + ex.addProxyObject(configs.get(0), configs.get(0).getId(), "networkConfigId"); throw ex; } else { return configs; @@ -1668,9 +1670,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.start(); NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), - related, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(), + related, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId); - networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, + networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); if (domainId != null && aclType == ACLType.Domain) { @@ -1709,7 +1711,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public void allocate(VirtualMachineProfile vm, List> networks) + public void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException { Transaction txn = Transaction.currentTxn(); txn.start(); @@ -1725,26 +1727,26 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (Pair network : networks) { NetworkVO config = network.first(); NicProfile requested = network.second(); - + Boolean isDefaultNic = false; if (vm != null && (requested != null && requested.isDefaultNic())) { isDefaultNic = true; } - + while (deviceIds[deviceId] && deviceId < deviceIds.length) { deviceId++; } - - Pair vmNicPair = allocateNic(requested, config, isDefaultNic, + + Pair vmNicPair = allocateNic(requested, config, isDefaultNic, deviceId, vm); - + NicProfile vmNic = vmNicPair.first(); if (vmNic == null) { continue; } - + deviceId = vmNicPair.second(); - + int devId = vmNic.getDeviceId(); if (devId > deviceIds.length) { throw new IllegalArgumentException("Device id for nic is too large: " + vmNic); @@ -1754,18 +1756,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } deviceIds[devId] = true; - + if (vmNic.isDefaultNic()) { if (defaultNic != null) { - throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + + throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vmNic); } defaultNic = vmNic; } - + nics.add(vmNic); vm.addNic(vmNic); - + } if (nics.size() != networks.size()) { @@ -1779,14 +1781,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag txn.commit(); } - - + + @DB @Override - public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, + public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException{ - + NetworkVO ntwkVO = _networksDao.findById(network.getId()); s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested); NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName()); @@ -1814,14 +1816,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag deviceId = applyProfileToNic(vo, profile, deviceId); vo = _nicDao.persist(vo); - + Integer networkRate = getNetworkRate(network.getId(), vm.getId()); - NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, + NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); - + return new Pair(vmNic, Integer.valueOf(deviceId)); - } + } protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer deviceId) { if (profile.getDeviceId() != null) { @@ -1907,7 +1909,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(config.getId(), null); to.setNetworkRateMbps(networkRate); - + to.setUuid(config.getUuid()); return to; @@ -1925,10 +1927,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (network == null) { // see NetworkVO.java ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration"); - ex.addProxyObject("networks", networkId, "networkId"); + ex.addProxyObject(ApiDBUtils.findNetworkById(networkId).getUuid()); throw ex; } - + if (s_logger.isDebugEnabled()) { s_logger.debug("Lock is acquired for network id " + networkId + " as a part of network implement"); } @@ -1977,7 +1979,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag shutdownNetwork(networkId, context, false); } - + _networksDao.releaseFromLockTable(networkId); if (s_logger.isDebugEnabled()) { s_logger.debug("Lock is released for network id " + networkId + " as a part of network implement"); @@ -1985,7 +1987,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, + private void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, NetworkVO network, NetworkOfferingVO offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { // If this is a 1) guest virtual network 2) network has sourceNat service 3) network offering does not support a @@ -1994,10 +1996,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean sharedSourceNat = offering.getSharedSourceNat(); - if (network.getGuestType() == Network.GuestType.Isolated - && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) + if (network.getGuestType() == Network.GuestType.Isolated + && areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && !sharedSourceNat) { - + List ips = null; if (network.getVpcId() != null) { ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true); @@ -2024,7 +2026,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // because the serializer would look up the NetworkVO class's table and retrieve the // network id instead of the physical network id. // So just throw this exception as is. We may need to TBD by changing the serializer. - throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + + throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); } if (s_logger.isDebugEnabled()) { @@ -2033,7 +2035,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!element.implement(network, offering, dest, context)) { CloudRuntimeException ex = new CloudRuntimeException("Failed to implement provider " + element.getProvider().getName() + " for network with specified id"); ex.addProxyObject(network, network.getId(), "networkId"); - throw ex; + throw ex; } } } @@ -2044,12 +2046,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.warn("Failed to re-program the network as a part of network " + network + " implement"); // see DataCenterVO.java ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId()); - ex.addProxyObject("data_center", network.getDataCenterId(), "dataCenterId"); + ex.addProxyObject(ApiDBUtils.findZoneById(network.getDataCenterId()).getUuid()); throw ex; } } - protected void prepareElement(NetworkElement element, NetworkVO network, + protected void prepareElement(NetworkElement element, NetworkVO network, NicProfile profile, VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { @@ -2084,7 +2086,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (nic.getVmType() == VirtualMachine.Type.User || (nic.getVmType() == VirtualMachine.Type.DomainRouter && getNetwork(networkId).getTrafficType() == TrafficType.Guest)) { _networksDao.setCheckForGc(networkId); } - + txn.commit(); } @@ -2109,7 +2111,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag for (NicVO nic : nics) { Pair implemented = implementNetwork(nic.getNetworkId(), dest, context); - + NetworkVO network = implemented.second(); NicProfile profile = prepareNic(vmProfile, dest, context, nic.getId(), network); vmProfile.addNic(profile); @@ -2117,15 +2119,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination + public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) - throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - + Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicVO nic = _nicDao.findById(nicId); - + NicProfile profile = null; if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { nic.setState(Nic.State.Reserving); @@ -2138,7 +2140,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag URI isolationUri = nic.getIsolationUri(); - profile = new NicProfile(nic, network, broadcastUri, isolationUri, + profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); guru.reserve(profile, network, vmProfile, dest, context); @@ -2159,7 +2161,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag updateNic(nic, network.getId(), 1); } else { - profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); guru.updateNicProfile(profile, network); nic.setState(Nic.State.Reserved); @@ -2186,7 +2188,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); vm.addNic(profile); @@ -2206,27 +2208,27 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { NicVO nicVO = _nicDao.findById(nic.getId()); releaseNic(vmProfile, nicVO); } @DB - protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nicVO) + protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nicVO) throws ConcurrentOperationException, ResourceUnavailableException { //lock the nic Transaction txn = Transaction.currentTxn(); txn.start(); - + NicVO nic = _nicDao.lockRow(nicVO.getId(), true); if (nic == null) { throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic); } - + Nic.State originalState = nic.getState(); NetworkVO network = _networksDao.findById(nicVO.getNetworkId()); - + if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) { if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { NetworkGuru guru = _networkGurus.get(network.getGuruName()); @@ -2245,17 +2247,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } //commit the transaction before proceeding releasing nic profile on the network elements txn.commit(); - + // Perform release on network elements for (NetworkElement element : _networkElements) { if (s_logger.isDebugEnabled()) { s_logger.debug("Asking " + element.getName() + " to release " + nic); } - //NOTE: Context appear to never be used in release method + //NOTE: Context appear to never be used in release method //implementations. Consider removing it from interface Element element.release(network, profile, vmProfile, null); } - + } else { nic.setState(Nic.State.Allocated); updateNic(nic, network.getId(), -1); @@ -2280,7 +2282,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profiles.add(profile); @@ -2288,7 +2290,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return profiles; } - + @Override public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri) { NicVO nic = null; @@ -2299,12 +2301,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } NetworkVO network = _networksDao.findById(networkId); Integer networkRate = getNetworkRate(network.getId(), vm.getId()); - + NetworkGuru guru = _networkGurus.get(network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network)); - guru.updateNicProfile(profile, network); - + guru.updateNicProfile(profile, network); + return profile; } @@ -2341,7 +2343,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // Check for account wide pool. It will have an entry for account_vlan_map. - if (_accountVlanMapDao.findAccountVlanMap(ipVO.getAllocatedToAccountId(), ipVO.getVlanId()) != null) { + if (_accountVlanMapDao.findAccountVlanMap(ipVO.getAllocatedToAccountId(), ipVO.getVlanId()) != null) { //see IPaddressVO.java InvalidParameterValueException ex = new InvalidParameterValueException("Sepcified IP address uuid belongs to" + " Account wide IP pool and cannot be disassociated"); @@ -2395,7 +2397,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public String getNextAvailableMacAddressInNetwork(long networkId) throws InsufficientAddressCapacityException { String mac = _networksDao.getNextAvailableMacAddress(networkId); if (mac == null) { - throw new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId); + throw new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId); } return mac; } @@ -2443,7 +2445,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag removeNic(vm, nic); } } - + @Override public void removeNic(VirtualMachineProfile vm, Nic nic) { removeNic(vm, _nicDao.findById(nic.getId())); @@ -2496,7 +2498,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (ntwkOff == null || ntwkOff.isSystemOnly()) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering by specified id"); if (ntwkOff != null) { - ex.addProxyObject(ntwkOff, networkOfferingId, "networkOfferingId"); + ex.addProxyObject(ntwkOff, networkOfferingId, "networkOfferingId"); // Get the VO object's table name. String tablename = AnnotationHelper.getTableName(ntwkOff); if (tablename != null) { @@ -2526,12 +2528,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (zone == null) { throw new InvalidParameterValueException("Specified zone id was not found"); } - + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { // See DataCenterVO.java PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled"); ex.addProxyObject(zone, zoneId, "zoneId"); - throw ex; + throw ex; } // Only domain and account ACL types are supported in Acton. @@ -2551,7 +2553,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } else if (ntwkOff.getGuestType() == GuestType.Shared) { if (!(aclType == ACLType.Domain || aclType == ACLType.Account)) { - throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " + + throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " + ACLType.Account + " for network of type " + Network.GuestType.Shared); } } @@ -2587,7 +2589,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } DomainVO domain = _domainDao.findById(domainId); - if (domain == null) { + if (domain == null) { throw new InvalidParameterValueException("Unable to find domain by specified id"); } _accountMgr.checkAccess(caller, domain); @@ -2671,7 +2673,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // 2) GuestType is Isolated, but SourceNat service is disabled boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced && ((ntwkOff.getGuestType() == Network.GuestType.Shared) - || (ntwkOff.getGuestType() == GuestType.Isolated && + || (ntwkOff.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)))); // Can add vlan range only to the network which allows it @@ -2684,7 +2686,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); } - throw ex; + throw ex; } Transaction txn = Transaction.currentTxn(); @@ -2711,15 +2713,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!_configMgr.isOfferingForVpc(ntwkOff)){ throw new InvalidParameterValueException("Network offering can't be used for VPC networks"); } - network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, + network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, caller); } else { if (_configMgr.isOfferingForVpc(ntwkOff)){ throw new InvalidParameterValueException("Network offering can be used for VPC networks only"); } - network = createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, + network = createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId); - } + } if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) { // Create vlan ip range @@ -2734,9 +2736,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB - public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, + public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId, - PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId) + PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId); @@ -2776,7 +2778,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (aclType == null || aclType != ACLType.Domain) { throw new InvalidParameterValueException("Only AclType=Domain can be specified for network creation in Basic zone"); } - + // Only one guest network is supported in Basic zone List guestNetworks = _networksDao.listByZoneAndTrafficType(zone.getId(), TrafficType.Guest); if (!guestNetworks.isEmpty()) { @@ -2785,7 +2787,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } // if zone is basic, only Shared network offerings w/o source nat service are allowed - if (!(ntwkOff.getGuestType() == GuestType.Shared && + if (!(ntwkOff.getGuestType() == GuestType.Shared && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) { throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of " + "guestType " + GuestType.Shared + " with disabled " + Service.SourceNat.getName() @@ -2816,14 +2818,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (zone.isSecurityGroupEnabled()) { // Only Account specific Isolated network with sourceNat service disabled are allowed in security group // enabled zone - boolean allowCreation = (ntwkOff.getGuestType() == GuestType.Isolated + boolean allowCreation = (ntwkOff.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)); if (!allowCreation) { throw new InvalidParameterValueException("Only Account specific Isolated network with sourceNat " + "service disabled are allowed in security group enabled zone"); } } - + //don't allow eip/elb networks in Advance zone if (ntwkOff.getElasticIp() || ntwkOff.getElasticLb()) { throw new InvalidParameterValueException("Elastic IP and Elastic LB services are supported in zone of type " + NetworkType.Basic); @@ -2855,7 +2857,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } } - + // If networkDomain is not specified, take it from the global configuration if (areServicesSupportedByNetworkOffering(networkOfferingId, Service.Dns)) { Map dnsCapabilities = getNetworkOfferingServiceCapabilities @@ -2897,7 +2899,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // limitation, remove after we introduce support for multiple ip ranges // with different Cidrs for the same Shared network boolean cidrRequired = zone.getNetworkType() == NetworkType.Advanced && ntwkOff.getTrafficType() == TrafficType.Guest - && (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated + && (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))); if (cidr == null && cidrRequired) { throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of" + @@ -2949,7 +2951,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (networks == null || networks.isEmpty()) { throw new CloudRuntimeException("Fail to create a network"); } else { - if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && + if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && networks.get(0).getTrafficType() == TrafficType.Guest) { Network defaultGuestNetwork = networks.get(0); for (Network nw : networks) { @@ -2963,7 +2965,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag network = networks.get(0); } } - + if (updateResourceCount) { _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network); } @@ -3045,13 +3047,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { permittedAccounts.clear(); Project project = _projectMgr.getProject(projectId); - if (project == null) { + if (project == null) { throw new InvalidParameterValueException("Unable to find project by specified id"); } if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) { // getProject() returns type ProjectVO. InvalidParameterValueException ex = new InvalidParameterValueException("Account " + caller + " cannot access specified project id"); - ex.addProxyObject(project, projectId, "projectId"); + ex.addProxyObject(project, projectId, "projectId"); throw ex; } permittedAccounts.add(project.getProjectAccountId()); @@ -3063,15 +3065,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag path = _domainDao.findById(domainId).getPath(); } else { path = _domainDao.findById(caller.getDomainId()).getPath(); - } - + } + if (listAll && domainId == null) { isRecursive = true; } Filter searchFilter = new Filter(NetworkVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchBuilder sb = _networksDao.createSearchBuilder(); - + if (forVpc != null) { if (forVpc) { sb.and("vpc", sb.entity().getVpcId(), Op.NNULL); @@ -3115,8 +3117,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag SearchBuilder accountSearch = _accountDao.createSearchBuilder(); accountSearch.and("typeNEQ", accountSearch.entity().getType(), SearchCriteria.Op.NEQ); accountSearch.and("typeEQ", accountSearch.entity().getType(), SearchCriteria.Op.EQ); - - + + sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER); List networksToReturn = new ArrayList(); @@ -3125,7 +3127,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!permittedAccounts.isEmpty()) { //get account level networks networksToReturn.addAll(listAccountSpecificNetworks( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, permittedAccounts)); //get domain level networks @@ -3139,12 +3141,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { //add account specific networks networksToReturn.addAll(listAccountSpecificNetworksByDomainPath( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path, isRecursive)); //add domain specific networks of domain + parent domains networksToReturn.addAll(listDomainSpecificNetworksByDomainPath( - buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, + buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path, isRecursive)); //add networks of subdomains @@ -3184,7 +3186,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag networksToReturn=supportedNetworks; } - + if (canUseForDeploy != null) { List networksForDeploy = new ArrayList(); for (NetworkVO network : networksToReturn) { @@ -3192,10 +3194,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag networksForDeploy.add(network); } } - + networksToReturn=networksForDeploy; } - + return networksToReturn; } @@ -3210,11 +3212,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { hasFreeIps = (getAvailableIps(network, null)).size() > 0; } - + return hasFreeIps; } - private SearchCriteria buildNetworkSearchCriteria(SearchBuilder sb, String keyword, Long id, + private SearchCriteria buildNetworkSearchCriteria(SearchBuilder sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId, Map tags) { @@ -3267,11 +3269,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (specifyIpRanges != null) { sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges); } - + if (vpcId != null) { sc.addAnd("vpcId", SearchCriteria.Op.EQ, vpcId); } - + if (tags != null && !tags.isEmpty()) { int count = 0; sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Network.toString()); @@ -3354,7 +3356,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } List networkIds = new ArrayList(); - + List maps = _networkDomainDao.listDomainNetworkMapByDomain(allowedDomains.toArray()); for (NetworkDomainVO map : maps) { @@ -3383,16 +3385,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkVO network = _networksDao.findById(networkId); if (network == null) { // see NetworkVO.java - + InvalidParameterValueException ex = new InvalidParameterValueException("unable to find network with specified id"); - ex.addProxyObject(network, networkId, "networkId"); + ex.addProxyObject(network, networkId, "networkId"); throw ex; } // don't allow to delete system network if (isNetworkSystem(network)) { InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id is system and can't be removed"); - ex.addProxyObject(network, network.getId(), "networkId"); + ex.addProxyObject(network, network.getId(), "networkId"); throw ex; } @@ -3411,7 +3413,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @DB public boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements) { boolean result = false; - + NetworkVO network = _networksDao.lockRow(networkId, true); if (network == null) { s_logger.debug("Unable to find network with id: " + networkId); @@ -3529,11 +3531,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return false; } } - + //In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network DataCenter zone = _configMgr.getZone(network.getDataCenterId()); if (zone.getNetworkType() == NetworkType.Basic) { - List systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), + List systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), Type.ConsoleProxy, Type.SecondaryStorageVm); if (systemVms != null && !systemVms.isEmpty()) { s_logger.warn("Can't delete the network, not all consoleProxy/secondaryStorage vms are expunged"); @@ -3608,7 +3610,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag network.setState(Network.State.Destroy); _networksDao.update(network.getId(), network); _networksDao.remove(network.getId()); - + NetworkOffering ntwkOff = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, network.getAclType()); if (updateResourceCount) { @@ -3627,7 +3629,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } protected boolean deleteVlansInNetwork(long networkId, long userId, Account callerAccount) { - + //cleanup Public vlans List publicVlans = _vlanDao.listVlansByNetworkId(networkId); boolean result = true; @@ -3636,8 +3638,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.warn("Failed to delete vlan " + vlan.getId() + ");"); result = false; } - } - + } + //cleanup private vlans int privateIpAllocCount = _privateIpDao.countAllocatedByNetworkId(networkId); if (privateIpAllocCount > 0) { @@ -3828,7 +3830,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // Check if network exists NetworkVO network = _networksDao.findById(networkId); - if (network == null) { + if (network == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist"); ex.addProxyObject("networks", networkId, "networkId"); throw ex; @@ -3838,9 +3840,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!(network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) { throw new InvalidParameterValueException("Network is not in the right state to be restarted. Correct states are: " + Network.State.Implemented + ", " + Network.State.Setup); } - + if (network.getBroadcastDomainType() == BroadcastDomainType.Lswitch ) { - /** + /** * Unable to restart these networks now. * TODO Restarting a SDN based network requires updating the nics and the configuration * in the controller. This requires a non-trivial rewrite of the restart procedure. @@ -3868,7 +3870,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkVO network = _networksDao.findById(networkId); if (network == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist"); - ex.addProxyObject(network, networkId, "networkId"); + ex.addProxyObject(network, networkId, "networkId"); throw ex; } @@ -3978,13 +3980,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } } - + //apply network ACLs if (!_networkACLMgr.applyNetworkACLs(networkId, caller)) { s_logger.warn("Failed to reapply network ACLs as a part of of network id=" + networkId + " restart"); success = false; } - + return success; } @@ -4047,7 +4049,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public Map getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) { if (!areServicesSupportedByNetworkOffering(offering.getId(), service)) { - // TBD: We should be sending networkOfferingId and not the offering object itself. + // TBD: We should be sending networkOfferingId and not the offering object itself. throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the network offering " + offering); } @@ -4099,7 +4101,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag List networks = _networksDao.listBy(Account.ACCOUNT_ID_SYSTEM, networkOfferingId, zoneId); if (networks == null || networks.isEmpty()) { - // TBD: send uuid instead of zoneId. Hardcode tablename in call to addProxyObject(). + // TBD: send uuid instead of zoneId. Hardcode tablename in call to addProxyObject(). throw new InvalidParameterValueException("Unable to find network with traffic type " + trafficType + " in zone " + zoneId); } return networks.get(0); @@ -4184,7 +4186,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag ResourceUnavailableException, ResourceAllocationException { Account owner = _accountMgr.getActiveAccountById(accountId); boolean createNetwork = false; - + if (guestNetwork != null && guestNetwork.getTrafficType() != TrafficType.Guest) { throw new InvalidParameterValueException("Network " + guestNetwork + " is not of a type " + TrafficType.Guest); } @@ -4208,22 +4210,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (createNetwork) { List requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false); if (requiredOfferings.size() < 1) { - throw new CloudRuntimeException("Unable to find network offering with availability=" + + throw new CloudRuntimeException("Unable to find network offering with availability=" + Availability.Required + " to automatically create the network as part of createVlanIpRange"); } if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) { - + long physicalNetworkId = findPhysicalNetworkId(zoneId, requiredOfferings.get(0).getTags(), requiredOfferings.get(0).getTrafficType()); // Validate physical network PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId); if (physicalNetwork == null) { throw new InvalidParameterValueException("Unable to find physical network with id: "+physicalNetworkId + " and tag: " +requiredOfferings.get(0).getTags()); } - - s_logger.debug("Creating network for account " + owner + " from the network offering id=" + + + s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId() + " as a part of createVlanIpRange process"); guestNetwork = createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network" - , owner.getAccountName() + "-network", null, null, null, null, owner, null, physicalNetwork, + , owner.getAccountName() + "-network", null, null, null, null, owner, null, physicalNetwork, zoneId, ACLType.Account, null, null); if (guestNetwork == null) { @@ -4232,8 +4234,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag "service enabled as a part of createVlanIpRange, for the account " + accountId + "in zone " + zoneId); } } else { - throw new CloudRuntimeException("Required network offering id=" + requiredOfferings.get(0).getId() - + " is not in " + NetworkOffering.State.Enabled); + throw new CloudRuntimeException("Required network offering id=" + requiredOfferings.get(0).getId() + + " is not in " + NetworkOffering.State.Enabled); } } @@ -4336,7 +4338,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.debug("Network " + network + " doesn't support service " + Service.UserData.getName()); return null; } - + return (UserDataServiceProvider)getElementImplementingProvider(passwordProvider); } @@ -4484,7 +4486,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return networks; } - + @DB @Override public IPAddressVO markIpAsUnavailable(long addrId) { @@ -4512,7 +4514,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String guestType = vlan.getVlanType().toString(); UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, - ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), + ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), ip.isSourceNat(), guestType, ip.getSystem()); _usageEventDao.persist(usageEvent); } @@ -4568,15 +4570,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } private boolean checkForNonStoppedVmInNetwork(long networkId) { - List vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Starting, + List vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Migrating, VirtualMachine.State.Stopping); return vms.isEmpty(); } - + @Override @DB @ActionEvent(eventType = EventTypes.EVENT_NETWORK_UPDATE, eventDescription = "updating network", async = true) - public Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, + public Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix, Long networkOfferingId, Boolean changeCidr) { boolean restartNetwork = false; @@ -4604,7 +4606,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (network.getTrafficType() != Networks.TrafficType.Guest) { throw new InvalidParameterValueException("Can't allow networks which traffic type is not " + TrafficType.Guest); } - + _accountMgr.checkAccess(callerAccount, null, true, network); if (name != null) { @@ -4628,18 +4630,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId); if (networkOffering == null || networkOffering.isSystemOnly()) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering with specified id"); - ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId"); + ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId"); throw ex; } - + // network offering should be in Enabled state if (networkOffering.getState() != NetworkOffering.State.Enabled) { InvalidParameterValueException ex = new InvalidParameterValueException("Network offering with specified id is not in " + NetworkOffering.State.Enabled + " state, can't upgrade to it"); - ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId"); + ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId"); throw ex; } - - + + //can't update from vpc to non-vpc network offering boolean forVpcNew = _configMgr.isOfferingForVpc(networkOffering); boolean vorVpcOriginal = _configMgr.isOfferingForVpc(_configMgr.getNetworkOffering(oldNetworkOfferingId)); @@ -4656,7 +4658,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (changeCidr) { if (!checkForNonStoppedVmInNetwork(network.getId())) { InvalidParameterValueException ex = new InvalidParameterValueException("All user vm of network of specified id should be stopped before changing CIDR!"); - ex.addProxyObject(network, networkId, "networkId"); + ex.addProxyObject(network, networkId, "networkId"); throw ex; } } @@ -4711,7 +4713,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!shutdownNetworkElementsAndResources(context, true, network)) { s_logger.warn("Failed to shutdown the network elements and resources as a part of network restart: " + network); CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of update to network of specified id"); - ex.addProxyObject(network, networkId, "networkId"); + ex.addProxyObject(network, networkId, "networkId"); throw ex; } } else { @@ -4721,13 +4723,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!shutdownNetwork(network.getId(), context, true)) { s_logger.warn("Failed to shutdown the network as a part of update to network with specified id"); CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network as a part of update of specified network id"); - ex.addProxyObject(network, networkId, "networkId"); + ex.addProxyObject(network, networkId, "networkId"); throw ex; } } } else { CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of update to network with specified id; network is in wrong state: " + network.getState()); - ex.addProxyObject(network, networkId, "networkId"); + ex.addProxyObject(network, networkId, "networkId"); throw ex; } } @@ -4738,7 +4740,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag boolean validStateToImplement = (networkState == Network.State.Implemented || networkState == Network.State.Setup || networkState == Network.State.Allocated); if (restartNetwork && !validStateToImplement) { CloudRuntimeException ex = new CloudRuntimeException("Failed to implement the network elements and resources as a part of update to network with specified id; network is in wrong state: " + networkState); - ex.addProxyObject(network, networkId, "networkId"); + ex.addProxyObject(network, networkId, "networkId"); throw ex; } @@ -4788,7 +4790,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } catch (Exception ex) { s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network update due to ", ex); CloudRuntimeException e = new CloudRuntimeException("Failed to implement network (with specified id) elements and resources as a part of network update"); - e.addProxyObject(network, networkId, "networkId"); + e.addProxyObject(network, networkId, "networkId"); throw e; } } @@ -4867,8 +4869,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String[] cidr = network.getCidr().split("/"); List ips = _nicDao.listIpAddressInNetwork(network.getId()); Set allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1])); - Set usedIps = new TreeSet(); - + Set usedIps = new TreeSet(); + for (String ip : ips) { if (requestedIp != null && requestedIp.equals(ip)) { s_logger.warn("Requested ip address " + requestedIp + " is already in use in network" + network); @@ -4882,7 +4884,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return allPossibleIps; } - + private String getZoneNetworkDomain(long zoneId) { return _dcDao.findById(zoneId).getDomain(); @@ -5004,7 +5006,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } } - + // if all the rules configured on public IP are revoked then, dis-associate IP with network service provider applyIpAssociations(network, true, continueOnError, publicIps); @@ -5181,7 +5183,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB @ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_CREATE, eventDescription = "Creating Physical Network", create = true) - public PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List + public PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List isolationMethods, String broadcastDomainRangeStr, Long domainId, List tags, String name) { // Check if zone exists @@ -5235,7 +5237,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } catch (NumberFormatException e) { throw new InvalidParameterValueException("Please specify valid integers for the vlan range."); } - + //check for vnet conflicts with other physical network(s) in the zone checkGuestVnetsConflicts(zoneId, vnetStart, vnetEnd, null); @@ -5290,7 +5292,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // add security group provider to the physical network addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId()); - + // add VPCVirtualRouter as the defualt network service provider addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId()); @@ -5332,7 +5334,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag PhysicalNetworkVO network = _physicalNetworkDao.findById(id); if (network == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system"); - ex.addProxyObject(network, id, "physicalNetworkId"); + ex.addProxyObject(network, id, "physicalNetworkId"); throw ex; } @@ -5340,7 +5342,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag DataCenter zone = _dcDao.findById(network.getDataCenterId()); if (zone == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Zone with id=" + network.getDataCenterId() + " doesn't exist in the system"); - ex.addProxyObject(zone, network.getDataCenterId(), "dataCenterId"); + ex.addProxyObject(zone, network.getDataCenterId(), "dataCenterId"); throw ex; } if (newVnetRangeString != null) { @@ -5386,14 +5388,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String[] newVnetRange = newVnetRangeString.split("-"); int maxVnet = 4096; // for GRE phynets allow up to 32bits - // TODO: Not happy about this test. + // TODO: Not happy about this test. // What about guru-like objects for physical networs? s_logger.debug("ISOLATION METHODS:" + network.getIsolationMethods()); // Java does not have unsigned types... - if (network.getIsolationMethods().contains("GRE")) { + if (network.getIsolationMethods().contains("GRE")) { maxVnet = (int)(Math.pow(2, 32)-1); } - String rangeMessage = " between 0 and " + maxVnet; + String rangeMessage = " between 0 and " + maxVnet; if (newVnetRange.length < 2) { throw new InvalidParameterValueException("Please provide valid vnet range" + rangeMessage); } @@ -5416,7 +5418,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (newStartVnet > newEndVnet) { throw new InvalidParameterValueException("Vnet range has to be" + rangeMessage + " and start range should be lesser than or equal to stop range"); } - + //check if new vnet conflicts with vnet ranges of other physical networks checkGuestVnetsConflicts(network.getDataCenterId(), newStartVnet, newEndVnet, network.getId()); @@ -5478,7 +5480,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag || (newEndVnet <= endVnet && newEndVnet >= startVnet)) { throw new InvalidParameterValueException("Vnet range for physical network conflicts with another " + "physical network's vnet in the zone"); - } + } } } @@ -5495,7 +5497,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId); if (pNetwork == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system"); - ex.addProxyObject(pNetwork, physicalNetworkId, "physicalNetworkId"); + ex.addProxyObject(pNetwork, physicalNetworkId, "physicalNetworkId"); throw ex; } @@ -5522,7 +5524,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // delete service providers List providers = _pNSPDao.listBy(physicalNetworkId); - + for(PhysicalNetworkServiceProviderVO provider : providers){ try { deleteNetworkServiceProvider(provider.getId()); @@ -5539,7 +5541,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _pNTrafficTypeDao.deleteTrafficTypes(physicalNetworkId); boolean success = _physicalNetworkDao.remove(physicalNetworkId); - + txn.commit(); return success; @@ -5691,7 +5693,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId); if (destNetwork == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system"); - ex.addProxyObject(destNetwork, destinationPhysicalNetworkId, "destinationPhysicalNetworkId"); + ex.addProxyObject(destNetwork, destinationPhysicalNetworkId, "destinationPhysicalNetworkId"); throw ex; } } @@ -5933,7 +5935,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { pNtwks = _physicalNetworkDao.listByZone(zoneId); } - + if (pNtwks.isEmpty()) { throw new InvalidParameterValueException("Unable to find physical network in zone id=" + zoneId); } @@ -6020,7 +6022,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // shouldn't even come here as network is being cleaned up after all network elements are shutdown s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); } - + //revoke all network ACLs for network try { if (_networkACLMgr.revokeAllNetworkACLsForNetwork(networkId, callerUserId, caller)) { @@ -6162,7 +6164,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.warn("Failed to cleanup firewall rules as a part of shutdownNetworkRules due to ", ex); success = false; } - + //revoke all Network ACLs for the network w/o applying them in the DB List networkACLs = _firewallDao.listByNetworkAndPurpose(networkId, Purpose.NetworkACL); if (s_logger.isDebugEnabled()) { @@ -6184,7 +6186,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag s_logger.warn("Failed to cleanup network ACLs as a part of shutdownNetworkRules due to ", ex); success = false; } - + //release all static nats for the network if (!_rulesMgr.applyStaticNatForNetwork(networkId, false, caller, true)) { s_logger.warn("Failed to disable static nats as part of shutdownNetworkRules for network id " + networkId); @@ -6416,7 +6418,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return networkList.get(0); } - + @Override public String getDefaultManagementTrafficLabel(long zoneId, HypervisorType hypervisorType){ try{ @@ -6425,7 +6427,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if(mgmtTraffic != null){ String label = null; switch(hypervisorType){ - case XenServer : label = mgmtTraffic.getXenNetworkLabel(); + case XenServer : label = mgmtTraffic.getXenNetworkLabel(); break; case KVM : label = mgmtTraffic.getKvmNetworkLabel(); break; @@ -6441,7 +6443,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return null; } - + @Override public String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType){ try{ @@ -6450,7 +6452,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if(storageTraffic != null){ String label = null; switch(hypervisorType){ - case XenServer : label = storageTraffic.getXenNetworkLabel(); + case XenServer : label = storageTraffic.getXenNetworkLabel(); break; case KVM : label = storageTraffic.getKvmNetworkLabel(); break; @@ -6652,7 +6654,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag TrafficType effectiveTrafficType = network.getTrafficType(); if(hType == HypervisorType.VMware && effectiveTrafficType == TrafficType.Control) effectiveTrafficType = TrafficType.Management; - + if (effectiveTrafficType == TrafficType.Control) { return null; } @@ -6682,7 +6684,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // have to remove this sanity check as VMware control network is management network // we need to retrieve traffic label information through physical network -/* +/* if (network.getTrafficType() == TrafficType.Control) { return null; } @@ -6735,10 +6737,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return nsp; } - + protected PhysicalNetworkServiceProvider addDefaultVpcVirtualRouterToPhysicalNetwork(long physicalNetworkId) { - PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, + PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.VPCVirtualRouter.getName(), null, null); // add instance of the provider VpcVirtualRouterElement element = (VpcVirtualRouterElement) getElementImplementingProvider(Network.Provider.VPCVirtualRouter.getName()); @@ -6752,7 +6754,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag protected PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) { - PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, + PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.SecurityGroupProvider.getName(), null, null); return nsp; @@ -6869,17 +6871,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (enabledServices != null && !enabledServices.isEmpty()) { if (!element.canEnableIndividualServices()) { - Set requiredServices = new HashSet(); + Set requiredServices = new HashSet(); requiredServices.addAll(element.getCapabilities().keySet()); - + if (requiredServices.contains(Network.Service.Gateway)) { requiredServices.remove(Network.Service.Gateway); } - + if (requiredServices.contains(Network.Service.Firewall)) { requiredServices.remove(Network.Service.Firewall); } - + if (enabledServices.contains(Network.Service.Firewall)) { enabledServices.remove(Network.Service.Firewall); } @@ -6956,7 +6958,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (networkId == null) { networkId = userIp.getAssociatedWithNetworkId(); } - + NetworkVO network = _networksDao.findById(networkId); NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); if (offering.getGuestType() != GuestType.Isolated) { @@ -7027,7 +7029,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) + public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) throws InsufficientAddressCapacityException { Network guestNetwork = getNetwork(networkId); NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); @@ -7160,7 +7162,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } catch (Exception ex) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + + s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage()); } } @@ -7182,17 +7184,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return networkList.get(0); } - + @Override public List listNetworksByVpc(long vpcId) { return _networksDao.listByVpc(vpcId); } - + @Override public String getDefaultNetworkDomain() { return _networkDomain; } - + @Override public List getNtwkOffDistinctProviders(long ntkwOffId) { List providerNames = _ntwkOfferingSrvcDao.getDistinctProviders(ntkwOffId); @@ -7211,7 +7213,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return false; } - + @Override @ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true) public IpAddress associateIPToNetwork(long ipId, long networkId) throws InsufficientAddressCapacityException, @@ -7227,20 +7229,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag " to VPC.Specify vpcId to associate ip address to VPC"); } return associateIPToGuestNetwork(ipId, networkId, true); - + } - + @Override @DB - public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, - String vlan, String startIp, String endIp, String gateway, String netmask, long networkOwnerId, Long vpcId) + public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, + String vlan, String startIp, String endIp, String gateway, String netmask, long networkOwnerId, Long vpcId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { - + Account owner = _accountMgr.getAccount(networkOwnerId); - + // Get system network offeirng NetworkOfferingVO ntwkOff = _systemNetworks.get(NetworkOffering.SystemPrivateGatewayNetworkOffering); - + // Validate physical network PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId); if (pNtwk == null) { @@ -7249,7 +7251,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag ex.addProxyObject("physical_network", physicalNetworkId, "physicalNetworkId"); throw ex; } - + // VALIDATE IP INFO // if end ip is not specified, default it to startIp if (!NetUtils.isValidIp(startIp)) { @@ -7270,64 +7272,64 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); - - + + Transaction txn = Transaction.currentTxn(); txn.start(); - + //lock datacenter as we need to get mac address seq from there DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true); - + //check if we need to create guest network Network privateNetwork = _networksDao.getPrivateNetwork(BroadcastDomainType.Vlan.toUri(vlan).toString(), cidr, networkOwnerId, pNtwk.getDataCenterId()); if (privateNetwork == null) { //create Guest network - privateNetwork = createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan, + privateNetwork = createGuestNetwork(ntwkOff.getId(), networkName, displayText, gateway, cidr, vlan, null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, null); s_logger.debug("Created private network " + privateNetwork); } else { s_logger.debug("Private network already exists: " + privateNetwork); } - + //add entry to private_ip_address table PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkId(privateNetwork.getId(), startIp); if (privateIp != null) { throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" + " in zone " + _configMgr.getZone(pNtwk.getDataCenterId()).getName()); } - + Long mac = dc.getMacAddress(); Long nextMac = mac + 1; dc.setMacAddress(nextMac); privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac, vpcId); _privateIpDao.persist(privateIp); - + _dcDao.update(dc.getId(), dc); - + txn.commit(); s_logger.debug("Private network " + privateNetwork + " is created"); return privateNetwork; } - + @Override public boolean setupDns(Network network, Provider provider) { boolean dnsProvided = isProviderSupportServiceInNetwork(network.getId(), Service.Dns, provider ); - boolean dhcpProvided =isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, + boolean dhcpProvided =isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, provider); - + boolean setupDns = dnsProvided || dhcpProvided; return setupDns; } - + @Override public List getPhysicalNtwksSupportingTrafficType(long zoneId, TrafficType trafficType) { - + List pNtwks = _physicalNetworkDao.listByZone(zoneId); - + Iterator it = pNtwks.iterator(); while (it.hasNext()) { PhysicalNetwork pNtwk = it.next(); @@ -7337,7 +7339,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return pNtwks; } - + @Override public boolean isPrivateGateway(Nic guestNic) { Network network = getNetwork(guestNic.getNetworkId()); @@ -7346,41 +7348,41 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return true; } - + @Override public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfileImpl vmProfile, boolean prepare) - throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - + VirtualMachine vm = vmProfile.getVirtualMachine(); NetworkVO networkVO = _networksDao.findById(network.getId()); DataCenter dc = _configMgr.getZone(network.getDataCenterId()); - Host host = _hostDao.findById(vm.getHostId()); + Host host = _hostDao.findById(vm.getHostId()); DeployDestination dest = new DeployDestination(dc, null, null, host); - + NicProfile nic = getNicProfileForVm(network, requested, vm); - + //1) allocate nic (if needed) if (nic == null) { int deviceId = _nicDao.countNics(vm.getId()); - - nic = allocateNic(requested, network, false, + + nic = allocateNic(requested, network, false, deviceId, vmProfile).first(); - + if (nic == null) { throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network); } - - s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); + + s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); } - + //2) prepare nic if (prepare) { nic = prepareNic(vmProfile, dest, context, nic.getId(), networkVO); s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); } - + return nic; } @@ -7403,7 +7405,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } return nic; } - + @Override public int getNetworkLockTimeout() { diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java index 57509ffea12..d52657ae816 100644 --- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java @@ -77,7 +77,6 @@ import com.cloud.user.User; import com.cloud.user.UserContext; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; -import com.cloud.utils.IdentityProxy; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.component.Inject; @@ -562,8 +561,8 @@ public class AutoScaleManagerImpl implements AutoScaleManager, AutoScaleSe Account caller = UserContext.current().getCaller(); Account owner = _accountDao.findActiveAccount(accountName, domainId); if (owner == null) { - List idList = new ArrayList(); - idList.add(new IdentityProxy("domain", domainId, "domainId")); + List idList = new ArrayList(); + idList.add(ApiDBUtils.findDomainById(domainId).getUuid()); throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain with specifed domainId"); } _accountMgr.checkAccess(caller, null, false, owner); diff --git a/utils/src/com/cloud/utils/exception/RuntimeCloudException.java b/utils/src/com/cloud/utils/exception/RuntimeCloudException.java index f2e9845de8c..233469678df 100644 --- a/utils/src/com/cloud/utils/exception/RuntimeCloudException.java +++ b/utils/src/com/cloud/utils/exception/RuntimeCloudException.java @@ -23,53 +23,53 @@ import java.util.ArrayList; /** * by the API response serializer. Any exceptions that are thrown by * class, which extends Exception instead of RuntimeException like this - * class does. + * class does. */ public class RuntimeCloudException extends RuntimeException { - + // This holds a list of uuids and their names. Add uuid:fieldname pairs - protected ArrayList idList = new ArrayList(); - + protected ArrayList idList = new ArrayList(); + protected int csErrorCode; - - 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 RuntimeCloudException(String message) { super(message); setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); } - + public RuntimeCloudException(String message, Throwable cause) { super(message, cause); 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); + addProxyObject(tablename, id, idFieldName); } return; } - + public RuntimeCloudException() { super(); setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName())); } - - public ArrayList getIdProxyList() { + + public ArrayList getIdProxyList() { return idList; } - + public void setCSErrorCode(int cserrcode) { this.csErrorCode = cserrcode; } - + public int getCSErrorCode() { return this.csErrorCode; }