You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2013/10/18 02:11:09 UTC
[1/3] Refactor missed classes
Updated Branches:
refs/heads/txn-refactor 711ad386d -> 323bbccd5
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java
index e27a059..37de4de 100644
--- a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java
@@ -29,7 +29,6 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
-
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
@@ -71,6 +70,7 @@ import com.cloud.dc.dao.ClusterVSMMapDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
@@ -123,7 +123,11 @@ import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallback;
+import com.cloud.utils.db.TransactionCallbackWithException;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.exception.ExceptionUtil;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@@ -274,11 +278,11 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
}
@Override
- public boolean implement(Network network, NetworkOffering offering,
- DeployDestination dest, ReservationContext context)
+ public boolean implement(final Network network, final NetworkOffering offering,
+ final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
- DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
+ final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic) {
s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic);
@@ -289,7 +293,7 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
return false;
}
- List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
+ final List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No Cisco Vnmc device on network " + network.getName());
return false;
@@ -312,114 +316,121 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
return false;
}
- Transaction txn = Transaction.currentTxn();
- boolean status = false;
try {
- txn.start();
-
- // ensure that there is an ASA 1000v assigned to this network
- CiscoAsa1000vDevice assignedAsa = assignAsa1000vToNetwork(network);
- if (assignedAsa == null) {
- s_logger.error("Unable to assign ASA 1000v device to network " + network.getName());
- return false;
- }
-
- ClusterVO asaCluster = _clusterDao.findById(assignedAsa.getClusterId());
- ClusterVSMMapVO clusterVsmMap = _clusterVsmMapDao.findByClusterId(assignedAsa.getClusterId());
- if (clusterVsmMap == null) {
- s_logger.error("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it");
- return false;
- }
-
- CiscoNexusVSMDeviceVO vsmDevice = _vsmDeviceDao.findById(clusterVsmMap.getVsmId());
- if (vsmDevice == null) {
- s_logger.error("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName());
- return false;
- }
-
- CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
- HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
- _hostDao.loadDetails(ciscoVnmcHost);
- Account owner = context.getAccount();
- PublicIp sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
- long vlanId = Long.parseLong(BroadcastDomainType.getValue(network.getBroadcastUri()));
-
- List<VlanVO> vlanVOList = _vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId());
- List<String> publicGateways = new ArrayList<String>();
- for (VlanVO vlanVO : vlanVOList) {
- publicGateways.add(vlanVO.getVlanGateway());
- }
-
- // due to VNMC limitation of not allowing source NAT ip as the outside ip of firewall,
- // an additional public ip needs to acquired for assigning as firewall outside ip.
- // In case there are already additional ip addresses available (network restart) use one
- // of them such that it is not the source NAT ip
- IpAddress outsideIp = null;
- List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
- for (IPAddressVO ip : publicIps) {
- if (!ip.isSourceNat()) {
- outsideIp = ip;
- break;
- }
- }
- if (outsideIp == null) { // none available, acquire one
- try {
- Account caller = CallContext.current().getCallingAccount();
- long callerUserId = CallContext.current().getCallingUserId();
- outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone);
- } catch (ResourceAllocationException e) {
- s_logger.error("Unable to allocate additional public Ip address. Exception details " + e);
- return false;
- }
-
- try {
- outsideIp = _ipAddrMgr.associateIPToGuestNetwork(outsideIp.getId(), network.getId(), true);
- } catch (ResourceAllocationException e) {
- s_logger.error("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details "
- + e);
- return false;
+ Transaction.executeWithException(new TransactionCallbackWithException<Object>() {
+ @Override
+ public Object doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException, ResourceUnavailableException {
+
+ // ensure that there is an ASA 1000v assigned to this network
+ CiscoAsa1000vDevice assignedAsa = assignAsa1000vToNetwork(network);
+ if (assignedAsa == null) {
+ s_logger.error("Unable to assign ASA 1000v device to network " + network.getName());
+ throw new CloudRuntimeException("Unable to assign ASA 1000v device to network " + network.getName());
+ }
+
+ ClusterVO asaCluster = _clusterDao.findById(assignedAsa.getClusterId());
+ ClusterVSMMapVO clusterVsmMap = _clusterVsmMapDao.findByClusterId(assignedAsa.getClusterId());
+ if (clusterVsmMap == null) {
+ s_logger.error("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it");
+ throw new CloudRuntimeException("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it");
+ }
+
+ CiscoNexusVSMDeviceVO vsmDevice = _vsmDeviceDao.findById(clusterVsmMap.getVsmId());
+ if (vsmDevice == null) {
+ s_logger.error("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName());
+ throw new CloudRuntimeException("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName());
+ }
+
+ CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
+ HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
+ _hostDao.loadDetails(ciscoVnmcHost);
+ Account owner = context.getAccount();
+ PublicIp sourceNatIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
+ long vlanId = Long.parseLong(BroadcastDomainType.getValue(network.getBroadcastUri()));
+
+ List<VlanVO> vlanVOList = _vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId());
+ List<String> publicGateways = new ArrayList<String>();
+ for (VlanVO vlanVO : vlanVOList) {
+ publicGateways.add(vlanVO.getVlanGateway());
+ }
+
+ // due to VNMC limitation of not allowing source NAT ip as the outside ip of firewall,
+ // an additional public ip needs to acquired for assigning as firewall outside ip.
+ // In case there are already additional ip addresses available (network restart) use one
+ // of them such that it is not the source NAT ip
+ IpAddress outsideIp = null;
+ List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
+ for (IPAddressVO ip : publicIps) {
+ if (!ip.isSourceNat()) {
+ outsideIp = ip;
+ break;
+ }
+ }
+ if (outsideIp == null) { // none available, acquire one
+ try {
+ Account caller = CallContext.current().getCallingAccount();
+ long callerUserId = CallContext.current().getCallingUserId();
+ outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone);
+ } catch (ResourceAllocationException e) {
+ s_logger.error("Unable to allocate additional public Ip address. Exception details " + e);
+ throw new CloudRuntimeException("Unable to allocate additional public Ip address. Exception details " + e);
+ }
+
+ try {
+ outsideIp = _ipAddrMgr.associateIPToGuestNetwork(outsideIp.getId(), network.getId(), true);
+ } catch (ResourceAllocationException e) {
+ s_logger.error("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details "
+ + e);
+ throw new CloudRuntimeException("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details "
+ + e);
+ }
+ }
+
+ // create logical edge firewall in VNMC
+ String gatewayNetmask = NetUtils.getCidrNetmask(network.getCidr());
+ // due to ASA limitation of allowing single subnet to be assigned to firewall interfaces,
+ // all public ip addresses must be from same subnet, this essentially means single public subnet in zone
+ if (!createLogicalEdgeFirewall(vlanId, network.getGateway(), gatewayNetmask,
+ outsideIp.getAddress().addr(), sourceNatIp.getNetmask(), publicGateways, ciscoVnmcHost.getId())) {
+ s_logger.error("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName());
+ throw new CloudRuntimeException("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName());
+ }
+
+ // create stuff in VSM for ASA device
+ if (!configureNexusVsmForAsa(vlanId, network.getGateway(),
+ vsmDevice.getUserName(), vsmDevice.getPassword(), vsmDevice.getipaddr(),
+ assignedAsa.getInPortProfile(), ciscoVnmcHost.getId())) {
+ s_logger.error("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() +
+ " for ASA device for network " + network.getName());
+ throw new CloudRuntimeException("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() +
+ " for ASA device for network " + network.getName());
+ }
+
+ // configure source NAT
+ if (!configureSourceNat(vlanId, network.getCidr(), sourceNatIp, ciscoVnmcHost.getId())) {
+ s_logger.error("Failed to configure source NAT in Cisco VNMC device for network " + network.getName());
+ throw new CloudRuntimeException("Failed to configure source NAT in Cisco VNMC device for network " + network.getName());
+ }
+
+ // associate Asa 1000v instance with logical edge firewall
+ if (!associateAsaWithLogicalEdgeFirewall(vlanId, assignedAsa.getManagementIp(), ciscoVnmcHost.getId())) {
+ s_logger.error("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() +
+ ") with logical edge firewall in VNMC for network " + network.getName());
+ throw new CloudRuntimeException("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() +
+ ") with logical edge firewall in VNMC for network " + network.getName());
+ }
+
+ return null;
}
- }
-
- // create logical edge firewall in VNMC
- String gatewayNetmask = NetUtils.getCidrNetmask(network.getCidr());
- // due to ASA limitation of allowing single subnet to be assigned to firewall interfaces,
- // all public ip addresses must be from same subnet, this essentially means single public subnet in zone
- if (!createLogicalEdgeFirewall(vlanId, network.getGateway(), gatewayNetmask,
- outsideIp.getAddress().addr(), sourceNatIp.getNetmask(), publicGateways, ciscoVnmcHost.getId())) {
- s_logger.error("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName());
- return false;
- }
-
- // create stuff in VSM for ASA device
- if (!configureNexusVsmForAsa(vlanId, network.getGateway(),
- vsmDevice.getUserName(), vsmDevice.getPassword(), vsmDevice.getipaddr(),
- assignedAsa.getInPortProfile(), ciscoVnmcHost.getId())) {
- s_logger.error("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() +
- " for ASA device for network " + network.getName());
- return false;
- }
-
- // configure source NAT
- if (!configureSourceNat(vlanId, network.getCidr(), sourceNatIp, ciscoVnmcHost.getId())) {
- s_logger.error("Failed to configure source NAT in Cisco VNMC device for network " + network.getName());
- return false;
- }
-
- // associate Asa 1000v instance with logical edge firewall
- if (!associateAsaWithLogicalEdgeFirewall(vlanId, assignedAsa.getManagementIp(), ciscoVnmcHost.getId())) {
- s_logger.error("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() +
- ") with logical edge firewall in VNMC for network " + network.getName());
- return false;
- }
-
- status = true;
- txn.commit();
- } finally {
- if (!status) {
- txn.rollback();
- //FIXME: also undo changes in VNMC, VSM if anything failed
- }
+ }, Exception.class);
+ } catch (CloudRuntimeException e) {
+ s_logger.error("CiscoVnmcElement failed", e);
+ return false;
+ } catch (Exception e) {
+ ExceptionUtil.rethrowRuntime(e);
+ ExceptionUtil.rethrow(e, InsufficientAddressCapacityException.class);
+ ExceptionUtil.rethrow(e, ResourceUnavailableException.class);
+ throw new IllegalStateException(e);
}
return true;
@@ -522,9 +533,9 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
@Override
public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
- String deviceName = Provider.CiscoVnmc.getName();
+ final String deviceName = Provider.CiscoVnmc.getName();
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
- Long physicalNetworkId = cmd.getPhysicalNetworkId();
+ final Long physicalNetworkId = cmd.getPhysicalNetworkId();
CiscoVnmcController ciscoVnmcResource = null;
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
@@ -533,7 +544,7 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
}
long zoneId = physicalNetwork.getDataCenterId();
- PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(),
+ final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() +
@@ -560,27 +571,27 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
hostdetails.putAll(params);
ServerResource resource = new CiscoVnmcResource();
- Transaction txn = Transaction.currentTxn();
try {
resource.configure(cmd.getHost(), hostdetails);
- Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalFirewall, params);
+ final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalFirewall, params);
if (host != null) {
- txn.start();
-
- ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
- _ciscoVnmcDao.persist((CiscoVnmcControllerVO)ciscoVnmcResource);
-
- DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
- _hostDetailsDao.persist(detail);
-
- txn.commit();
- return ciscoVnmcResource;
+ return Transaction.execute(new TransactionCallback<CiscoVnmcController>() {
+ @Override
+ public CiscoVnmcController doInTransaction(TransactionStatus status) {
+ CiscoVnmcController ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
+ _ciscoVnmcDao.persist((CiscoVnmcControllerVO)ciscoVnmcResource);
+
+ DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
+ _hostDetailsDao.persist(detail);
+
+ return ciscoVnmcResource;
+ }
+ });
} else {
throw new CloudRuntimeException("Failed to add Cisco Vnmc device due to internal error.");
}
} catch (ConfigurationException e) {
- txn.rollback();
throw new CloudRuntimeException(e.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java
index eccf4aa..c11c871 100644
--- a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java
+++ b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java
@@ -46,6 +46,8 @@ import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
@@ -206,16 +208,15 @@ public class MidoNetPublicNetworkGuru extends PublicNetworkGuru {
s_logger.debug("public network deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address());
}
- IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
+ final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
if (ip != null && nic.getReservationStrategy() != Nic.ReservationStrategy.Managed) {
-
- Transaction txn = Transaction.currentTxn();
- txn.start();
-
- _ipAddrMgr.markIpAsUnavailable(ip.getId());
- _ipAddressDao.unassignIpAddress(ip.getId());
-
- txn.commit();
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ _ipAddrMgr.markIpAsUnavailable(ip.getId());
+ _ipAddressDao.unassignIpAddress(ip.getId());
+ }
+ });
}
nic.deallocate();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
index d63b14f..8101864 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
@@ -31,7 +31,6 @@ import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.cloudstack.region.gslb.GslbServiceProvider;
-
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
@@ -110,13 +109,14 @@ import com.cloud.offering.NetworkOffering;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.UrlUtil;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
-
import com.google.gson.Gson;
@Local(value = {NetworkElement.class, StaticNatServiceProvider.class, LoadBalancingServiceProvider.class, GslbServiceProvider.class})
@@ -409,9 +409,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
}
@DB
- private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDeviceId, Long capacity, Boolean dedicatedUse, List<Long> newPodsConfig) {
- ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
- Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId());
+ private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(final long lbDeviceId, Long capacity, Boolean dedicatedUse, List<Long> newPodsConfig) {
+ final ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
+ final Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId());
if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId);
@@ -425,7 +425,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
}
}
- List<Long> podsToAssociate = new ArrayList<Long>();
+ final List<Long> podsToAssociate = new ArrayList<Long>();
if (newPodsConfig != null && newPodsConfig.size() > 0) {
for (Long podId: newPodsConfig) {
HostPodVO pod = _podDao.findById(podId);
@@ -441,7 +441,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
}
}
- List<Long> podsToDeassociate = new ArrayList<Long>();
+ final List<Long> podsToDeassociate = new ArrayList<Long>();
for (Long podId: currentPodsConfig) {
if (!newPodsConfig.contains(podId)) {
podsToDeassociate.add(podId);
@@ -482,26 +482,28 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
lbDeviceVo.setIsDedicatedDevice(dedicatedUse);
}
- Transaction txn = Transaction.currentTxn();
- txn.start();
-
- _lbDeviceDao.update(lbDeviceId, lbDeviceVo);
-
- for (Long podId: podsToAssociate) {
- NetScalerPodVO nsPodVo = new NetScalerPodVO(lbDeviceId, podId);
- _netscalerPodDao.persist(nsPodVo);
- }
-
- for (Long podId: podsToDeassociate) {
- NetScalerPodVO nsPodVo = _netscalerPodDao.findByPodId(podId);
- _netscalerPodDao.remove(nsPodVo.getId());
- }
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ _lbDeviceDao.update(lbDeviceId, lbDeviceVo);
+
+ for (Long podId: podsToAssociate) {
+ NetScalerPodVO nsPodVo = new NetScalerPodVO(lbDeviceId, podId);
+ _netscalerPodDao.persist(nsPodVo);
+ }
+
+ for (Long podId: podsToDeassociate) {
+ NetScalerPodVO nsPodVo = _netscalerPodDao.findByPodId(podId);
+ _netscalerPodDao.remove(nsPodVo.getId());
+ }
+
+ // FIXME get the row lock to avoid race condition
+ _detailsDao.persist(lbDeviceVo.getHostId(), lbDetails);
- // FIXME get the row lock to avoid race condition
- _detailsDao.persist(lbDeviceVo.getHostId(), lbDetails);
+ }
+ });
HostVO host = _hostDao.findById(lbDeviceVo.getHostId());
- txn.commit();
-
+
_agentMgr.reconnect(host.getId());
return lbDeviceVo;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
index 5400dd4..ef8ec86 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
@@ -30,7 +30,6 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
-
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
@@ -114,6 +113,8 @@ import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallback;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicProfile;
@@ -552,12 +553,10 @@ public class NiciraNvpElement extends AdapterBase implements
@DB
public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
ServerResource resource = new NiciraNvpResource();
- String deviceName = Network.Provider.NiciraNvp.getName();
+ final String deviceName = Network.Provider.NiciraNvp.getName();
NetworkDevice networkDevice = NetworkDevice
.getNetworkDevice(deviceName);
- Long physicalNetworkId = cmd.getPhysicalNetworkId();
- NiciraNvpDeviceVO niciraNvpDevice = null;
-
+ final Long physicalNetworkId = cmd.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
.findById(physicalNetworkId);
if (physicalNetwork == null) {
@@ -567,7 +566,7 @@ public class NiciraNvpElement extends AdapterBase implements
}
long zoneId = physicalNetwork.getDataCenterId();
- PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
+ final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
.findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
@@ -606,33 +605,33 @@ public class NiciraNvpElement extends AdapterBase implements
Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params);
- Transaction txn = Transaction.currentTxn();
try {
resource.configure(cmd.getHost(), hostdetails);
- Host host = _resourceMgr.addHost(zoneId, resource,
+ final Host host = _resourceMgr.addHost(zoneId, resource,
Host.Type.L2Networking, params);
if (host != null) {
- txn.start();
-
- niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(),
- physicalNetworkId, ntwkSvcProvider.getProviderName(),
- deviceName);
- _niciraNvpDao.persist(niciraNvpDevice);
-
- DetailVO detail = new DetailVO(host.getId(),
- "niciranvpdeviceid", String.valueOf(niciraNvpDevice
- .getId()));
- _hostDetailsDao.persist(detail);
-
- txn.commit();
- return niciraNvpDevice;
+ return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() {
+ @Override
+ public NiciraNvpDeviceVO doInTransaction(TransactionStatus status) {
+ NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(),
+ physicalNetworkId, ntwkSvcProvider.getProviderName(),
+ deviceName);
+ _niciraNvpDao.persist(niciraNvpDevice);
+
+ DetailVO detail = new DetailVO(host.getId(),
+ "niciranvpdeviceid", String.valueOf(niciraNvpDevice
+ .getId()));
+ _hostDetailsDao.persist(detail);
+
+ return niciraNvpDevice;
+ }
+ });
} else {
throw new CloudRuntimeException(
"Failed to add Nicira Nvp Device due to internal error.");
}
} catch (ConfigurationException e) {
- txn.rollback();
throw new CloudRuntimeException(e.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
index c9db371..1149085 100644
--- a/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
+++ b/server/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerManagerImpl.java
@@ -191,7 +191,7 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A
if (e instanceof NetworkRuleConflictException) {
throw (NetworkRuleConflictException) e;
}
- throw new CloudRuntimeException("Unable to add lb rule for ip address " + newRule.getSourceIpAddressId(), e);
+ throw new CloudRuntimeException("Unable to add lb rule for ip address " + newRuleFinal.getSourceIpAddressId(), e);
} finally {
if (!success && newRule != null) {
_lbMgr.removeLBRule(newRule);
[3/3] git commit: updated refs/heads/txn-refactor to 323bbcc
Posted by da...@apache.org.
Add unit tests for Transaction
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/323bbccd
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/323bbccd
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/323bbccd
Branch: refs/heads/txn-refactor
Commit: 323bbccd50c3008ced5f4ab1e0ba1be8e0499a62
Parents: 9cbb309
Author: Darren Shepherd <da...@gmail.com>
Authored: Thu Oct 17 16:07:11 2013 -0700
Committer: Darren Shepherd <da...@gmail.com>
Committed: Thu Oct 17 16:07:11 2013 -0700
----------------------------------------------------------------------
.../db/src/com/cloud/utils/db/Transaction.java | 7 +-
.../com/cloud/utils/db/TransactionLegacy.java | 26 +++-
.../com/cloud/utils/db/TestTransaction.java | 136 +++++++++++++++++++
framework/db/test/db.properties | 18 +++
.../utils/exception/ExceptionUtilTest.java | 48 +++++++
5 files changed, 230 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/323bbccd/framework/db/src/com/cloud/utils/db/Transaction.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/Transaction.java b/framework/db/src/com/cloud/utils/db/Transaction.java
index 4f8e5c7..d65b87e 100755
--- a/framework/db/src/com/cloud/utils/db/Transaction.java
+++ b/framework/db/src/com/cloud/utils/db/Transaction.java
@@ -27,7 +27,12 @@ public class Transaction {
public static <T> T execute(TransactionCallback<T> callback) {
String name = "tx-" + counter.incrementAndGet();
- TransactionLegacy txn = TransactionLegacy.open(name);
+ short databaseId = TransactionLegacy.CLOUD_DB;
+ TransactionLegacy currentTxn = TransactionLegacy.currentTxn(false);
+ if ( currentTxn != null ) {
+ databaseId = currentTxn.getDatabaseId();
+ }
+ TransactionLegacy txn = TransactionLegacy.open(name, databaseId, false);
try {
txn.start();
T result = callback.doInTransaction(STATUS);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/323bbccd/framework/db/src/com/cloud/utils/db/TransactionLegacy.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/TransactionLegacy.java b/framework/db/src/com/cloud/utils/db/TransactionLegacy.java
index b191491..ffa0670 100755
--- a/framework/db/src/com/cloud/utils/db/TransactionLegacy.java
+++ b/framework/db/src/com/cloud/utils/db/TransactionLegacy.java
@@ -117,10 +117,16 @@ public class TransactionLegacy {
private TransactionLegacy _prev = null;
public static TransactionLegacy currentTxn() {
+ return currentTxn(true);
+ }
+
+ protected static TransactionLegacy currentTxn(boolean check) {
TransactionLegacy txn = tls.get();
- assert txn != null : "No Transaction on stack. Did you mark the method with @DB?";
-
- assert checkAnnotation(3, txn) : "Did you even read the guide to use Transaction...IOW...other people's code? Try method can't be private. What about @DB? hmmm... could that be it? " + txn;
+ if (check) {
+ assert txn != null : "No Transaction on stack. Did you mark the method with @DB?";
+
+ assert checkAnnotation(4, txn) : "Did you even read the guide to use Transaction...IOW...other people's code? Try method can't be private. What about @DB? hmmm... could that be it? " + txn;
+ }
return txn;
}
@@ -397,6 +403,10 @@ public class TransactionLegacy {
return lockMaster.release(name);
}
+ /**
+ * @deprecated Use {@link Transaction} for new code
+ */
+ @Deprecated
public void start() {
if (s_logger.isTraceEnabled()) {
s_logger.trace("txn: start requested by: " + buildName());
@@ -1170,5 +1180,13 @@ public class TransactionLegacy {
return new PoolingDataSource(
/* connectionPool */poolableConnectionFactory.getPool());
}
-
+
+ /**
+ * Used for unit testing primarily
+ *
+ * @param conn
+ */
+ protected void setConnection(Connection conn) {
+ this._conn = conn;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/323bbccd/framework/db/test/com/cloud/utils/db/TestTransaction.java
----------------------------------------------------------------------
diff --git a/framework/db/test/com/cloud/utils/db/TestTransaction.java b/framework/db/test/com/cloud/utils/db/TestTransaction.java
new file mode 100644
index 0000000..ea277c7
--- /dev/null
+++ b/framework/db/test/com/cloud/utils/db/TestTransaction.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.cloud.utils.db;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import java.io.FileNotFoundException;
+import java.sql.Connection;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestTransaction {
+
+ TransactionLegacy txn;
+ Connection conn;
+
+ @Before
+ public void setup() {
+ setup(TransactionLegacy.CLOUD_DB);
+ }
+
+ public void setup(short db) {
+ txn = TransactionLegacy.open(db);
+ conn = Mockito.mock(Connection.class);
+ txn.setConnection(conn);
+ }
+
+ @After
+ public void after() {
+ TransactionLegacy.currentTxn().close();
+ }
+
+ @Test
+ public void testCommit() throws Exception {
+ assertEquals(42L, Transaction.execute(new TransactionCallback<Object>() {
+ @Override
+ public Object doInTransaction(TransactionStatus status) {
+ return 42L;
+ }
+ }));
+
+ verify(conn).setAutoCommit(false);
+ verify(conn, times(1)).commit();
+ verify(conn, times(0)).rollback();
+ verify(conn, times(1)).close();
+ }
+
+ @Test
+ public void testRollback() throws Exception {
+ try {
+ Transaction.execute(new TransactionCallback<Object>() {
+ @Override
+ public Object doInTransaction(TransactionStatus status) {
+ throw new RuntimeException("Panic!");
+ }
+ });
+ fail();
+ } catch (RuntimeException e) {
+ assertEquals("Panic!", e.getMessage());
+ }
+
+ verify(conn).setAutoCommit(false);
+ verify(conn, times(0)).commit();
+ verify(conn, times(1)).rollback();
+ verify(conn, times(1)).close();
+ }
+
+ @Test
+ public void testRollbackWithException() throws Exception {
+ try {
+ Transaction.executeWithException(new TransactionCallbackWithException<Object>() {
+ @Override
+ public Object doInTransaction(TransactionStatus status) throws FileNotFoundException {
+ assertEquals(TransactionLegacy.CLOUD_DB, TransactionLegacy.currentTxn().getDatabaseId().shortValue());
+
+ throw new FileNotFoundException("Panic!");
+ }
+ }, FileNotFoundException.class);
+ fail();
+ } catch (FileNotFoundException e) {
+ assertEquals("Panic!", e.getMessage());
+ }
+
+ verify(conn).setAutoCommit(false);
+ verify(conn, times(0)).commit();
+ verify(conn, times(1)).rollback();
+ verify(conn, times(1)).close();
+ }
+
+ @Test
+ public void testOtherdatabaseRollback() throws Exception {
+ after();
+ setup(TransactionLegacy.AWSAPI_DB);
+
+ try {
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ assertEquals(TransactionLegacy.AWSAPI_DB, TransactionLegacy.currentTxn().getDatabaseId().shortValue());
+
+ throw new RuntimeException("Panic!");
+ }
+ });
+ fail();
+ } catch (RuntimeException e) {
+ assertEquals("Panic!", e.getMessage());
+ }
+
+
+ verify(conn).setAutoCommit(false);
+ verify(conn, times(0)).commit();
+ verify(conn, times(1)).rollback();
+ verify(conn, times(1)).close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/323bbccd/framework/db/test/db.properties
----------------------------------------------------------------------
diff --git a/framework/db/test/db.properties b/framework/db/test/db.properties
new file mode 100644
index 0000000..cc1215f
--- /dev/null
+++ b/framework/db/test/db.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# 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,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Just here to make the unit test not blow up
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/323bbccd/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java b/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java
new file mode 100644
index 0000000..33fca37
--- /dev/null
+++ b/utils/test/com/cloud/utils/exception/ExceptionUtilTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.cloud.utils.exception;
+
+import static org.junit.Assert.*;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class ExceptionUtilTest {
+
+ @Test
+ public void test() throws Exception {
+ FileNotFoundException fnfe = new FileNotFoundException();
+ try {
+ ExceptionUtil.rethrow(fnfe, IOException.class);
+ fail();
+ } catch (IOException e) {
+ }
+
+ ExceptionUtil.rethrow(fnfe, ClassNotFoundException.class);
+
+ try {
+ ExceptionUtil.rethrow(fnfe, FileNotFoundException.class);
+ fail();
+ } catch ( FileNotFoundException e ) {
+ }
+ }
+
+}
[2/3] git commit: updated refs/heads/txn-refactor to 323bbcc
Posted by da...@apache.org.
Refactor missed classes
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9cbb309d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9cbb309d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9cbb309d
Branch: refs/heads/txn-refactor
Commit: 9cbb309d6b95c8522bfddd9e4244a19a166cdc7a
Parents: 711ad38
Author: Darren Shepherd <da...@gmail.com>
Authored: Thu Oct 17 16:00:11 2013 -0700
Committer: Darren Shepherd <da...@gmail.com>
Committed: Thu Oct 17 16:00:11 2013 -0700
----------------------------------------------------------------------
.../src/com/cloud/netapp/NetappManagerImpl.java | 10 +-
.../agent/manager/MockAgentManagerImpl.java | 27 +-
.../agent/manager/MockStorageManagerImpl.java | 170 ++++++------
.../cloud/agent/manager/MockVmManagerImpl.java | 46 ++--
.../agent/manager/SimulatorManagerImpl.java | 10 +-
.../simulator/dao/MockConfigurationDaoImpl.java | 4 +-
.../vmware/manager/VmwareManagerImpl.java | 53 ++--
.../network/CiscoNexusVSMDeviceManagerImpl.java | 68 ++---
.../network/element/CiscoNexusVSMElement.java | 50 ++--
.../network/element/BigSwitchVnsElement.java | 45 ++--
.../cloud/network/element/CiscoVnmcElement.java | 265 ++++++++++---------
.../network/guru/MidoNetPublicNetworkGuru.java | 19 +-
.../cloud/network/element/NetscalerElement.java | 52 ++--
.../cloud/network/element/NiciraNvpElement.java | 45 ++--
.../lb/ApplicationLoadBalancerManagerImpl.java | 2 +-
15 files changed, 408 insertions(+), 458 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/file-systems/netapp/src/com/cloud/netapp/NetappManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/file-systems/netapp/src/com/cloud/netapp/NetappManagerImpl.java b/plugins/file-systems/netapp/src/com/cloud/netapp/NetappManagerImpl.java
index 8f7b6d8..e0c2f57 100644
--- a/plugins/file-systems/netapp/src/com/cloud/netapp/NetappManagerImpl.java
+++ b/plugins/file-systems/netapp/src/com/cloud/netapp/NetappManagerImpl.java
@@ -50,7 +50,7 @@ import com.cloud.netapp.dao.PoolDao;
import com.cloud.netapp.dao.VolumeDao;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException;
@Component
@@ -225,7 +225,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
throw new ResourceInUseException("There are luns on the volume");
}
- final Transaction txn = Transaction.currentTxn();
+ final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
PoolVO pool = _poolDao.findById(volume.getPoolId());
if (pool == null) {
@@ -388,7 +388,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
}
Long volumeId = null;
- final Transaction txn = Transaction.currentTxn();
+ final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
NetappVolumeVO volume = null;
volume = _volumeDao.findVolume(ipAddress, aggName, volName);
@@ -624,7 +624,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
String[] result = new String[3];
StringBuilder lunName = new StringBuilder("lun-");
LunVO lun = null;
- final Transaction txn = Transaction.currentTxn();
+ final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
PoolVO pool = _poolDao.findPool(poolName);
@@ -802,7 +802,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
@DB
public void destroyLunOnFiler(String lunName) throws InvalidParameterValueException, ServerException{
- final Transaction txn = Transaction.currentTxn();
+ final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
LunVO lun = _lunDao.findByName(lunName);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
index fcc1b4f..dec6b38 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManagerImpl.java
@@ -42,8 +42,10 @@ import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
+
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -51,6 +53,7 @@ import org.springframework.stereotype.Component;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.HashMap;
@@ -159,7 +162,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
mockHost.setResource("com.cloud.agent.AgentRoutingResource");
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
mockHost = _mockHostDao.persist(mockHost);
@@ -170,7 +173,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
throw new CloudRuntimeException("Error configuring agent", ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -256,7 +259,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
private void handleSystemVMStop() {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
if (this.mode.equalsIgnoreCase("Stop")) {
txn.start();
@@ -279,7 +282,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -323,7 +326,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
mockHost.setResource(resource);
mockHost.setVmId(vmId);
- Transaction simtxn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy simtxn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
simtxn.start();
mockHost = _mockHostDao.persist(mockHost);
@@ -334,7 +337,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
+ ex.getMessage(), ex);
} finally {
simtxn.close();
- simtxn = Transaction.open(Transaction.CLOUD_DB);
+ simtxn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
simtxn.close();
}
@@ -366,7 +369,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
@Override
public MockHost getHost(String guid) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockHost _host = _mockHostDao.findByGuid(guid);
@@ -382,7 +385,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -391,7 +394,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
String hostGuid = cmd.getHostGuid();
MockHost host = null;
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
host = _mockHostDao.findByGuid(hostGuid);
@@ -404,11 +407,11 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
throw new CloudRuntimeException("Unable to get host " + hostGuid + " due to " + ex.getMessage(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
- Transaction vmtxn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy vmtxn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
vmtxn.start();
List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
@@ -435,7 +438,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
+ ex.getMessage(), ex);
} finally {
vmtxn.close();
- vmtxn = Transaction.open(Transaction.CLOUD_DB);
+ vmtxn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
vmtxn.close();
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
index d23575b..64463d4 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
@@ -76,7 +76,7 @@ import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.template.TemplateProp;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.VirtualMachine.State;
@@ -120,7 +120,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
VMTemplateDao templateDao;
private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String volumePath = path.replaceAll(ssUrl, "");
@@ -141,7 +141,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Unable to find volume " + path + " on secondary " + ssUrl, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -154,7 +154,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
}
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO primaryStorage = null;
try {
txn.start();
@@ -168,7 +168,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding primary storagee " + cmd.getPoolUuid(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -179,7 +179,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
newVolume.setPoolId(primaryStorage.getId());
newVolume.setSize(template.getSize());
newVolume.setType(MockVolumeType.VOLUME);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
_mockVolumeDao.persist(newVolume);
@@ -189,7 +189,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving volume " + newVolume, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
@@ -200,7 +200,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
StorageFilerTO sf = cmd.getPool();
DiskProfile dskch = cmd.getDiskCharacteristics();
MockStoragePoolVO storagePool = null;
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
@@ -213,7 +213,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding storage " + sf.getUuid(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -224,7 +224,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
volume.setPath(storagePool.getMountPoint() + volumeName);
volume.setSize(dskch.getSize());
volume.setType(MockVolumeType.VOLUME);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.persist(volume);
@@ -234,7 +234,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving volume " + volume, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -246,7 +246,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String poolid = cmd.getPoolUuid();
@@ -270,7 +270,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getVmName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -284,7 +284,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
}
String vmName = cmd.getVmName();
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVMVO vm = null;
try {
txn.start();
@@ -298,7 +298,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when attaching iso to vm " + vm.getName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new Answer(cmd);
@@ -306,7 +306,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockStoragePoolVO storage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
@@ -321,7 +321,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when deleting storage pool " + cmd.getPool().getPath(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -329,7 +329,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
StorageFilerTO sf = cmd.getPool();
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO storagePool = null;
try {
txn.start();
@@ -361,7 +361,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when modifying storage pool " + cmd.getPool().getPath(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>());
@@ -370,7 +370,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public Answer CreateStoragePool(CreateStoragePoolCommand cmd) {
StorageFilerTO sf = cmd.getPool();
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO storagePool = null;
try {
txn.start();
@@ -402,7 +402,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when creating storage pool " + cmd.getPool().getPath(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>());
@@ -410,7 +410,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public Answer SecStorageSetup(SecStorageSetupCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockSecStorageVO storage = null;
try {
txn.start();
@@ -424,7 +424,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when setting up sec storage" + cmd.getSecUrl(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new SecStorageSetupAnswer(storage.getMountPoint());
@@ -432,7 +432,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public Answer ListVolumes(ListVolumeCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockSecStorageVO storage = null;
try {
txn.start();
@@ -446,11 +446,11 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding sec storage " + cmd.getSecUrl(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
List<MockVolumeVO> volumes = _mockVolumeDao.findByStorageIdAndType(storage.getId(),
@@ -468,7 +468,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -483,7 +483,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
MockSecStorageVO storage = null;
String nfsUrl = ((NfsTO) store).getUrl();
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
storage = _mockSecStorageDao.findByUrl(nfsUrl);
try {
txn.start();
@@ -501,14 +501,14 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@Override
public Answer Destroy(DestroyCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolume().getPath());
@@ -530,7 +530,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when destroying volume " + cmd.getVolume().getPath(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new Answer(cmd);
@@ -539,7 +539,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public DownloadAnswer Download(DownloadCommand cmd) {
MockSecStorageVO ssvo = null;
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
@@ -553,7 +553,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error accessing secondary storage " + cmd.getSecUrl(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -564,7 +564,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
volume.setSize(0);
volume.setType(MockVolumeType.TEMPLATE);
volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.persist(volume);
@@ -574,7 +574,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving volume " + volume, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS,
@@ -583,7 +583,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String volumeId = cmd.getJobId();
@@ -616,7 +616,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error during download job " + cmd.getJobId(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -624,7 +624,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
String uuid = cmd.getStorageId();
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
if (uuid == null) {
@@ -653,7 +653,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -663,7 +663,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
String volPath = cmd.getVolumePath();
MockVolumeVO volume = null;
MockStoragePoolVO storagePool = null;
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(volPath);
@@ -680,7 +680,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Unable to perform snapshot", ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -693,7 +693,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
snapshot.setPoolId(storagePool.getId());
snapshot.setType(MockVolumeType.SNAPSHOT);
snapshot.setStatus(Status.DOWNLOADED);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
snapshot = _mockVolumeDao.persist(snapshot);
@@ -703,7 +703,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving snapshot " + snapshot, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -717,7 +717,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
MockVolumeVO volume = null;
MockVolumeVO snapshot = null;
MockSecStorageVO secStorage = null;
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
@@ -742,7 +742,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when backing up snapshot");
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -754,7 +754,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
newsnapshot.setSize(snapshot.getSize());
newsnapshot.setStatus(Status.DOWNLOADED);
newsnapshot.setType(MockVolumeType.SNAPSHOT);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
snapshot = _mockVolumeDao.persist(snapshot);
@@ -764,7 +764,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when backing up snapshot " + newsnapshot, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -773,7 +773,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO backSnapshot = null;
MockStoragePoolVO primary = null;
try {
@@ -795,7 +795,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when creating volume from snapshot", ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -808,7 +808,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
volume.setSize(backSnapshot.getSize());
volume.setStatus(Status.DOWNLOADED);
volume.setType(MockVolumeType.VOLUME);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
_mockVolumeDao.persist(volume);
@@ -818,7 +818,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when creating volume from snapshot " + volume, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -828,7 +828,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public Answer Delete(DeleteCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVolumeVO template = _mockVolumeDao.findByStoragePathAndType(cmd.getData().getPath());
@@ -842,7 +842,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when deleting object");
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new Answer(cmd);
@@ -879,7 +879,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public void preinstallTemplates(String url, long zoneId) {
MockSecStorageVO storage = null;
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storage = _mockSecStorageDao.findByUrl(url);
@@ -933,14 +933,14 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
} catch (Exception ex) {
throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
} finally {
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@Override
public StoragePoolInfo getLocalStorage(String hostGuid) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null;
MockStoragePoolVO storagePool = null;
try {
@@ -953,7 +953,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -965,7 +965,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storagePool = _mockStoragePoolDao.persist(storagePool);
@@ -975,7 +975,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -985,7 +985,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null;
try {
txn.start();
@@ -996,13 +996,13 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
if (storageSize == null) {
storageSize = DEFAULT_HOST_STORAGE_SIZE;
}
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO storagePool = null;
try {
txn.start();
@@ -1013,7 +1013,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding storagePool " + storagePool, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
if (storagePool == null) {
@@ -1024,7 +1024,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
storagePool.setCapacity(storageSize);
storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
storagePool = _mockStoragePoolDao.persist(storagePool);
@@ -1034,7 +1034,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -1044,7 +1044,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO snapshot = null;
MockSecStorageVO sec = null;
try {
@@ -1066,7 +1066,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
txn.commit();
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -1078,7 +1078,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
template.setSize(snapshot.getSize());
template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
template = _mockVolumeDao.persist(template);
@@ -1088,7 +1088,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving template " + template, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -1098,7 +1098,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public Answer ComputeChecksum(ComputeChecksumCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVolumeVO volume = _mockVolumeDao.findByName(cmd.getTemplatePath());
@@ -1116,14 +1116,14 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
return new Answer(cmd, true, md5);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO volume = null;
MockSecStorageVO sec = null;
try {
@@ -1143,7 +1143,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when creating private template from volume");
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -1155,7 +1155,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
template.setSize(volume.getSize());
template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
template = _mockVolumeDao.persist(template);
@@ -1166,7 +1166,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ template.getName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -1176,7 +1176,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
boolean toSecondaryStorage = cmd.toSecondaryStorage();
MockSecStorageVO sec = null;
MockStoragePoolVO primaryStorage = null;
@@ -1193,11 +1193,11 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getSecondaryStorageURL(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
@@ -1211,12 +1211,12 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getPool(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
MockVolumeVO volume = null;
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
@@ -1230,7 +1230,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getVolumePath(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -1243,7 +1243,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vol = _mockVolumeDao.persist(vol);
@@ -1254,7 +1254,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ vol.getName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
@@ -1266,7 +1266,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vol = _mockVolumeDao.persist(vol);
@@ -1277,7 +1277,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ vol.getName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
index 64df113..0ac49ad 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
@@ -72,7 +72,7 @@ import com.cloud.simulator.dao.MockVMDao;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine.State;
import org.apache.log4j.Logger;
@@ -111,7 +111,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
int cpuHz, long ramSize,
String bootArgs, String hostGuid) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null;
MockVm vm = null;
try {
@@ -128,7 +128,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
@@ -153,7 +153,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
} else if (vmName.startsWith("i-")) {
vm.setType("User");
}
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
vm = _mockVmDao.persist((MockVMVO) vm);
@@ -163,13 +163,13 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to save vm to db " + vm.getName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
} else {
if(vm.getState() == State.Stopped) {
vm.setState(State.Running);
- txn = Transaction.open(Transaction.SIMULATOR_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
@@ -179,7 +179,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to update vm " + vm.getName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -230,7 +230,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override
public Map<String, MockVMVO> getVms(String hostGuid) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
@@ -245,7 +245,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -282,7 +282,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override
public Map<String, State> getVmStates(String hostGuid) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
Map<String, State> states = new HashMap<String, State>();
@@ -301,7 +301,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -338,7 +338,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override
public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
@@ -353,7 +353,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -378,7 +378,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override
public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String vmName = cmd.getVmName();
@@ -405,14 +405,14 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@Override
public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
VirtualMachineTO vmTo = cmd.getVirtualMachine();
try {
txn.start();
@@ -425,7 +425,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to find vm " + vmTo.getName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
return new PrepareForMigrationAnswer(cmd);
}
@@ -438,7 +438,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override
public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(info.getHostUuid());
@@ -455,7 +455,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to clean up rules", ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -503,7 +503,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override
public StopAnswer stopVM(StopCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
String vmName = cmd.getVmName();
@@ -523,14 +523,14 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@Override
public RebootAnswer rebootVM(RebootCommand cmd) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockVm vm = _mockVmDao.findByVmName(cmd.getVmName());
@@ -545,7 +545,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
index f6bd2b6..f30bd36 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -99,7 +99,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.component.PluggableService;
import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.storage.command.DeleteCommand;
@@ -182,7 +182,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
@DB
@Override
public Answer simulate(Command cmd, String hostGuid) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
MockHost host = _mockHost.findByGuid(hostGuid);
String cmdName = cmd.toString();
@@ -373,7 +373,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
return new Answer(cmd, false, e.toString());
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
@@ -403,7 +403,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
@Override
public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command,
String values) {
- Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
+ TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command);
@@ -427,7 +427,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
throw new CloudRuntimeException("Unable to configure simulator because of " + ex.getMessage(), ex);
} finally {
txn.close();
- txn = Transaction.open(Transaction.CLOUD_DB);
+ txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return true;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java
index fd825b7..a681c06 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockConfigurationDaoImpl.java
@@ -20,7 +20,7 @@ import com.cloud.simulator.MockConfigurationVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionLegacy;
import org.springframework.stereotype.Component;
import javax.ejb.Local;
@@ -117,7 +117,7 @@ public class MockConfigurationDaoImpl extends GenericDaoBase<MockConfigurationVO
@Override
public MockConfigurationVO findByNameBottomUP(Long dcId, Long podId, Long clusterId, Long hostId, String name) {
- Transaction txn = Transaction.currentTxn();
+ TransactionLegacy txn = TransactionLegacy.currentTxn();
StringBuilder search = new StringBuilder();
Formatter formatter = new Formatter(search);
formatter.format("select * from mockconfiguration where (name='%s') and ((data_center_id = %d and pod_id = %d and cluster_id = %d and host_id = %d)", name, dcId, podId, clusterId, hostId);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 211f668..9af0aa0 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@ -120,6 +120,8 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SshHelper;
@@ -1091,32 +1093,12 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
// Add DC to database into vmware_data_center table
vmwareDc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, userName, password);
- Transaction txn = Transaction.currentTxn();
- try {
- txn.start();
- vmwareDc = _vmwareDcDao.persist(vmwareDc);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- s_logger.error("Failed to persist VMware datacenter details to database. Exception: " + e.getMessage());
- throw new CloudRuntimeException(e.getMessage());
- }
+ vmwareDc = _vmwareDcDao.persist(vmwareDc);
// Map zone with vmware datacenter
vmwareDcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDc.getId());
- txn = Transaction.currentTxn();
- try {
- txn.start();
- vmwareDcZoneMap = _vmwareDcZoneMapDao.persist(vmwareDcZoneMap);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- s_logger.error("Failed to associate VMware datacenter with zone " + zoneId + ". Exception: " + e.getMessage());
- // Removing VMware datacenter from vmware_data_center table because association with zone failed.
- _vmwareDcDao.remove(vmwareDcZoneMap.getId());
- throw new CloudRuntimeException(e.getMessage());
- }
+ vmwareDcZoneMap = _vmwareDcZoneMapDao.persist(vmwareDcZoneMap);
// Set custom field for this DC
if (addDcCustomFieldDef) {
@@ -1152,40 +1134,35 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
validateZoneWithResources(zoneId, "remove VMware datacenter to zone");
// Get DC associated with this zone
- VmwareDatacenterZoneMapVO vmwareDcZoneMap;
VmwareDatacenterVO vmwareDatacenter;
String vmwareDcName;
- long vmwareDcId;
String vCenterHost;
String userName;
String password;
DatacenterMO dcMo = null;
Transaction txn;
- vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
+ final VmwareDatacenterZoneMapVO vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
// Check if zone is associated with VMware DC
if (vmwareDcZoneMap == null) {
throw new CloudRuntimeException("Zone " + zoneId + " is not associated with any VMware datacenter.");
}
- vmwareDcId = vmwareDcZoneMap.getVmwareDcId();
+ final long vmwareDcId = vmwareDcZoneMap.getVmwareDcId();
vmwareDatacenter = _vmwareDcDao.findById(vmwareDcId);
vmwareDcName = vmwareDatacenter.getVmwareDatacenterName();
vCenterHost = vmwareDatacenter.getVcenterHost();
userName = vmwareDatacenter.getUser();
password = vmwareDatacenter.getPassword();
- txn = Transaction.currentTxn();
- try {
- txn.start();
- // Remove the VMware datacenter entry in table vmware_data_center
- _vmwareDcDao.remove(vmwareDcId);
- // Remove the map entry in table vmware_data_center_zone_map
- _vmwareDcZoneMapDao.remove(vmwareDcZoneMap.getId());
- txn.commit();
- } catch (Exception e) {
- s_logger.info("Caught exception when trying to delete VMware datacenter record." + e.getMessage());
- throw new CloudRuntimeException("Failed to delete VMware datacenter.");
- }
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // Remove the VMware datacenter entry in table vmware_data_center
+ _vmwareDcDao.remove(vmwareDcId);
+ // Remove the map entry in table vmware_data_center_zone_map
+ _vmwareDcZoneMapDao.remove(vmwareDcZoneMap.getId());
+ }
+ });
// Construct context
VmwareContext context = null;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java
index 9ec64ff..1b08a5c 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java
@@ -38,6 +38,8 @@ import com.cloud.resource.ResourceManager;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
import com.cloud.network.dao.PortProfileDao;
@@ -131,29 +133,13 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
if (VSMObj == null) {
// Create the VSM record. For now, we aren't using the vsmName field.
VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password);
- Transaction txn = Transaction.currentTxn();
- try {
- txn.start();
- _ciscoNexusVSMDeviceDao.persist(VSMObj);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- throw new CloudRuntimeException(e.getMessage());
- }
+ _ciscoNexusVSMDeviceDao.persist(VSMObj);
}
// At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id.
long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId();
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId);
- Transaction txn = Transaction.currentTxn();
- try {
- txn.start();
- _clusterVSMDao.persist(connectorObj);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- throw new CloudRuntimeException(e.getMessage());
- }
+ _clusterVSMDao.persist(connectorObj);
// Now, get a list of all the ESXi servers in this cluster.
// This is effectively a select * from host where cluster_id=clusterId;
@@ -196,7 +182,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
}
@DB
- public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException {
+ public boolean deleteCiscoNexusVSM(final long vsmId) throws ResourceInUseException {
CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
if (cisconexusvsm == null) {
// This entry is already not present. Return success.
@@ -225,20 +211,16 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
}
// Iterate through the cluster list again, this time, delete the VSM.
- Transaction txn = Transaction.currentTxn();
- try {
- txn.start();
- // Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
- _ciscoNexusVSMDeviceDao.remove(vsmId);
- // Remove the current record as well from ClusterVSMMapVO's table.
- _clusterVSMDao.removeByVsmId(vsmId);
- // There are no hosts at this stage in the cluster, so we don't need
- // to notify any resources or remove host details.
- txn.commit();
- } catch (Exception e) {
- s_logger.info("Caught exception when trying to delete VSM record.." + e.getMessage());
- throw new CloudRuntimeException("Failed to delete VSM");
- }
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
+ _ciscoNexusVSMDeviceDao.remove(vsmId);
+ // Remove the current record as well from ClusterVSMMapVO's table.
+ _clusterVSMDao.removeByVsmId(vsmId);
+ }
+ });
+
return true;
}
@@ -252,15 +234,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled) {
// it's currently disabled. So change it to enabled and write it out to the db.
cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled);
- Transaction txn = Transaction.currentTxn();
- try {
- txn.start();
- _ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- throw new CloudRuntimeException(e.getMessage());
- }
+ _ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
}
return cisconexusvsm;
@@ -276,15 +250,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled) {
// it's currently disabled. So change it to enabled and write it out to the db.
cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled);
- Transaction txn = Transaction.currentTxn();
- try {
- txn.start();
- _ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- throw new CloudRuntimeException(e.getMessage());
- }
+ _ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
}
return cisconexusvsm;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
index 6c6ce55..92564dd 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java
@@ -61,6 +61,8 @@ import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallback;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@@ -260,7 +262,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
}
@DB
- public Pair<Boolean, Long> validateAndAddVsm(String vsmIp, String vsmUser, String vsmPassword, long clusterId, String clusterName) throws ResourceInUseException {
+ public Pair<Boolean, Long> validateAndAddVsm(final String vsmIp, final String vsmUser, final String vsmPassword, final long clusterId, String clusterName) throws ResourceInUseException {
CiscoNexusVSMDeviceVO vsm = null;
boolean vsmAdded = false;
Long vsmId = 0L;
@@ -293,36 +295,24 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
}
}
// persist credentials to database if the VSM entry is not already in the db.
- if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
- vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
- txn = Transaction.currentTxn();
- try {
- txn.start();
- vsm = _vsmDao.persist(vsm);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- s_logger.error("Failed to persist Cisco Nexus 1000v VSM details to database. Exception: " + e.getMessage());
- throw new CloudRuntimeException(e.getMessage());
+ vsm = Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>() {
+ @Override
+ public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) {
+ CiscoNexusVSMDeviceVO vsm = null;
+ if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
+ vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
+ vsm = _vsmDao.persist(vsm);
+ }
+ // Create a mapping between the cluster and the vsm.
+ vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
+ if (vsm != null) {
+ ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
+ _clusterVSMDao.persist(connectorObj);
+ }
+ return vsm;
}
- }
- // Create a mapping between the cluster and the vsm.
- vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
- if (vsm != null) {
- ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
- txn = Transaction.currentTxn();
- try {
- txn.start();
- _clusterVSMDao.persist(connectorObj);
- txn.commit();
- } catch (Exception e) {
- txn.rollback();
- s_logger.error("Failed to associate Cisco Nexus 1000v VSM with cluster: " + clusterName + ". Exception: " + e.getMessage());
- _vsmDao.remove(vsm.getId()); // Removing VSM from virtual_supervisor_module table because association with cluster failed.
- // Cluster would be deleted from cluster table by callee.
- throw new CloudRuntimeException(e.getMessage());
- }
- }
+ });
+
} else {
String msg;
msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() +
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9cbb309d/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java
index cb6e7fc..6b75634 100644
--- a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java
+++ b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java
@@ -29,7 +29,6 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
-
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import com.cloud.agent.AgentManager;
@@ -84,6 +83,9 @@ import com.cloud.resource.UnableDeleteHostException;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallback;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@@ -329,11 +331,10 @@ public class BigSwitchVnsElement extends AdapterBase implements
@DB
public BigSwitchVnsDeviceVO addBigSwitchVnsDevice(AddBigSwitchVnsDeviceCmd cmd) {
ServerResource resource = new BigSwitchVnsResource();
- String deviceName = VnsConstants.BigSwitchVns.getName();
+ final String deviceName = VnsConstants.BigSwitchVns.getName();
NetworkDevice networkDevice = NetworkDevice
.getNetworkDevice(deviceName);
- Long physicalNetworkId = cmd.getPhysicalNetworkId();
- BigSwitchVnsDeviceVO bigswitchVnsDevice = null;
+ final Long physicalNetworkId = cmd.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
.findById(physicalNetworkId);
@@ -344,7 +345,7 @@ public class BigSwitchVnsElement extends AdapterBase implements
}
long zoneId = physicalNetwork.getDataCenterId();
- PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
+ final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
.findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
@@ -377,33 +378,33 @@ public class BigSwitchVnsElement extends AdapterBase implements
Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params);
- Transaction txn = Transaction.currentTxn();
try {
resource.configure(cmd.getHost(), hostdetails);
- Host host = _resourceMgr.addHost(zoneId, resource,
+ final Host host = _resourceMgr.addHost(zoneId, resource,
Host.Type.L2Networking, params);
if (host != null) {
- txn.start();
-
- bigswitchVnsDevice = new BigSwitchVnsDeviceVO(host.getId(),
- physicalNetworkId, ntwkSvcProvider.getProviderName(),
- deviceName);
- _bigswitchVnsDao.persist(bigswitchVnsDevice);
-
- DetailVO detail = new DetailVO(host.getId(),
- "bigswitchvnsdeviceid",
- String.valueOf(bigswitchVnsDevice.getId()));
- _hostDetailsDao.persist(detail);
-
- txn.commit();
- return bigswitchVnsDevice;
+ return Transaction.execute(new TransactionCallback<BigSwitchVnsDeviceVO>() {
+ @Override
+ public BigSwitchVnsDeviceVO doInTransaction(TransactionStatus status) {
+ BigSwitchVnsDeviceVO bigswitchVnsDevice = new BigSwitchVnsDeviceVO(host.getId(),
+ physicalNetworkId, ntwkSvcProvider.getProviderName(),
+ deviceName);
+ _bigswitchVnsDao.persist(bigswitchVnsDevice);
+
+ DetailVO detail = new DetailVO(host.getId(),
+ "bigswitchvnsdeviceid",
+ String.valueOf(bigswitchVnsDevice.getId()));
+ _hostDetailsDao.persist(detail);
+
+ return bigswitchVnsDevice;
+ }
+ });
} else {
throw new CloudRuntimeException(
"Failed to add BigSwitch Vns Device due to internal error.");
}
} catch (ConfigurationException e) {
- txn.rollback();
throw new CloudRuntimeException(e.getMessage());
}
}