Refactor missed classes

This commit is contained in:
Darren Shepherd 2013-10-17 16:00:11 -07:00
parent 711ad386d1
commit 9cbb309d6b
15 changed files with 405 additions and 455 deletions

View File

@ -50,7 +50,7 @@ import com.cloud.netapp.dao.PoolDao;
import com.cloud.netapp.dao.VolumeDao; import com.cloud.netapp.dao.VolumeDao;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB; 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.exception.CloudRuntimeException;
@Component @Component
@ -225,7 +225,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
throw new ResourceInUseException("There are luns on the volume"); throw new ResourceInUseException("There are luns on the volume");
} }
final Transaction txn = Transaction.currentTxn(); final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start(); txn.start();
PoolVO pool = _poolDao.findById(volume.getPoolId()); PoolVO pool = _poolDao.findById(volume.getPoolId());
if (pool == null) { if (pool == null) {
@ -388,7 +388,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
} }
Long volumeId = null; Long volumeId = null;
final Transaction txn = Transaction.currentTxn(); final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start(); txn.start();
NetappVolumeVO volume = null; NetappVolumeVO volume = null;
volume = _volumeDao.findVolume(ipAddress, aggName, volName); volume = _volumeDao.findVolume(ipAddress, aggName, volName);
@ -624,7 +624,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
String[] result = new String[3]; String[] result = new String[3];
StringBuilder lunName = new StringBuilder("lun-"); StringBuilder lunName = new StringBuilder("lun-");
LunVO lun = null; LunVO lun = null;
final Transaction txn = Transaction.currentTxn(); final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start(); txn.start();
PoolVO pool = _poolDao.findPool(poolName); PoolVO pool = _poolDao.findPool(poolName);
@ -802,7 +802,7 @@ public class NetappManagerImpl extends ManagerBase implements NetappManager
@DB @DB
public void destroyLunOnFiler(String lunName) throws InvalidParameterValueException, ServerException{ public void destroyLunOnFiler(String lunName) throws InvalidParameterValueException, ServerException{
final Transaction txn = Transaction.currentTxn(); final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start(); txn.start();
LunVO lun = _lunDao.findByName(lunName); LunVO lun = _lunDao.findByName(lunName);

View File

@ -42,8 +42,10 @@ import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd; import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -51,6 +53,7 @@ import org.springframework.stereotype.Component;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.HashMap; import java.util.HashMap;
@ -159,7 +162,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion()); mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
mockHost.setResource("com.cloud.agent.AgentRoutingResource"); mockHost.setResource("com.cloud.agent.AgentRoutingResource");
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
mockHost = _mockHostDao.persist(mockHost); mockHost = _mockHostDao.persist(mockHost);
@ -170,7 +173,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
throw new CloudRuntimeException("Error configuring agent", ex); throw new CloudRuntimeException("Error configuring agent", ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -256,7 +259,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
private void handleSystemVMStop() { private void handleSystemVMStop() {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
if (this.mode.equalsIgnoreCase("Stop")) { if (this.mode.equalsIgnoreCase("Stop")) {
txn.start(); 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); throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -323,7 +326,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion()); mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
mockHost.setResource(resource); mockHost.setResource(resource);
mockHost.setVmId(vmId); mockHost.setVmId(vmId);
Transaction simtxn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy simtxn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
simtxn.start(); simtxn.start();
mockHost = _mockHostDao.persist(mockHost); mockHost = _mockHostDao.persist(mockHost);
@ -334,7 +337,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
+ ex.getMessage(), ex); + ex.getMessage(), ex);
} finally { } finally {
simtxn.close(); simtxn.close();
simtxn = Transaction.open(Transaction.CLOUD_DB); simtxn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
simtxn.close(); simtxn.close();
} }
@ -366,7 +369,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
@Override @Override
public MockHost getHost(String guid) { public MockHost getHost(String guid) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockHost _host = _mockHostDao.findByGuid(guid); 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); throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -391,7 +394,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) { public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
String hostGuid = cmd.getHostGuid(); String hostGuid = cmd.getHostGuid();
MockHost host = null; MockHost host = null;
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
host = _mockHostDao.findByGuid(hostGuid); 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); throw new CloudRuntimeException("Unable to get host " + hostGuid + " due to " + ex.getMessage(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
Transaction vmtxn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy vmtxn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
vmtxn.start(); vmtxn.start();
List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId()); List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
@ -435,7 +438,7 @@ public class MockAgentManagerImpl extends ManagerBase implements MockAgentManage
+ ex.getMessage(), ex); + ex.getMessage(), ex);
} finally { } finally {
vmtxn.close(); vmtxn.close();
vmtxn = Transaction.open(Transaction.CLOUD_DB); vmtxn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
vmtxn.close(); vmtxn.close();
} }
} }

View File

@ -76,7 +76,7 @@ import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.template.TemplateProp; import com.cloud.storage.template.TemplateProp;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ManagerBase; 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.utils.exception.CloudRuntimeException;
import com.cloud.vm.DiskProfile; import com.cloud.vm.DiskProfile;
import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachine.State;
@ -120,7 +120,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
VMTemplateDao templateDao; VMTemplateDao templateDao;
private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) { private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
String volumePath = path.replaceAll(ssUrl, ""); 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); throw new CloudRuntimeException("Unable to find volume " + path + " on secondary " + ssUrl, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -154,7 +154,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
return new PrimaryStorageDownloadAnswer("Can't find primary storage"); 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; MockStoragePoolVO primaryStorage = null;
try { try {
txn.start(); txn.start();
@ -168,7 +168,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding primary storagee " + cmd.getPoolUuid(), ex); throw new CloudRuntimeException("Error when finding primary storagee " + cmd.getPoolUuid(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -179,7 +179,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
newVolume.setPoolId(primaryStorage.getId()); newVolume.setPoolId(primaryStorage.getId());
newVolume.setSize(template.getSize()); newVolume.setSize(template.getSize());
newVolume.setType(MockVolumeType.VOLUME); newVolume.setType(MockVolumeType.VOLUME);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
_mockVolumeDao.persist(newVolume); _mockVolumeDao.persist(newVolume);
@ -189,7 +189,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving volume " + newVolume, ex); throw new CloudRuntimeException("Error when saving volume " + newVolume, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize()); return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
@ -200,7 +200,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
StorageFilerTO sf = cmd.getPool(); StorageFilerTO sf = cmd.getPool();
DiskProfile dskch = cmd.getDiskCharacteristics(); DiskProfile dskch = cmd.getDiskCharacteristics();
MockStoragePoolVO storagePool = null; MockStoragePoolVO storagePool = null;
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid()); 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); throw new CloudRuntimeException("Error when finding storage " + sf.getUuid(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -224,7 +224,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
volume.setPath(storagePool.getMountPoint() + volumeName); volume.setPath(storagePool.getMountPoint() + volumeName);
volume.setSize(dskch.getSize()); volume.setSize(dskch.getSize());
volume.setType(MockVolumeType.VOLUME); volume.setType(MockVolumeType.VOLUME);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
volume = _mockVolumeDao.persist(volume); volume = _mockVolumeDao.persist(volume);
@ -234,7 +234,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving volume " + volume, ex); throw new CloudRuntimeException("Error when saving volume " + volume, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -246,7 +246,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd) { public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
String poolid = cmd.getPoolUuid(); String poolid = cmd.getPoolUuid();
@ -270,7 +270,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getVmName(), ex); + cmd.getVmName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -284,7 +284,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
} }
String vmName = cmd.getVmName(); String vmName = cmd.getVmName();
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVMVO vm = null; MockVMVO vm = null;
try { try {
txn.start(); 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); throw new CloudRuntimeException("Error when attaching iso to vm " + vm.getName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new Answer(cmd); return new Answer(cmd);
@ -306,7 +306,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd) { public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockStoragePoolVO storage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid()); 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); throw new CloudRuntimeException("Error when deleting storage pool " + cmd.getPool().getPath(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -329,7 +329,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) { public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
StorageFilerTO sf = cmd.getPool(); StorageFilerTO sf = cmd.getPool();
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO storagePool = null; MockStoragePoolVO storagePool = null;
try { try {
txn.start(); 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); throw new CloudRuntimeException("Error when modifying storage pool " + cmd.getPool().getPath(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>()); return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>());
@ -370,7 +370,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public Answer CreateStoragePool(CreateStoragePoolCommand cmd) { public Answer CreateStoragePool(CreateStoragePoolCommand cmd) {
StorageFilerTO sf = cmd.getPool(); StorageFilerTO sf = cmd.getPool();
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO storagePool = null; MockStoragePoolVO storagePool = null;
try { try {
txn.start(); 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); throw new CloudRuntimeException("Error when creating storage pool " + cmd.getPool().getPath(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>()); return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>());
@ -410,7 +410,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public Answer SecStorageSetup(SecStorageSetupCommand cmd) { public Answer SecStorageSetup(SecStorageSetupCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockSecStorageVO storage = null; MockSecStorageVO storage = null;
try { try {
txn.start(); 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); throw new CloudRuntimeException("Error when setting up sec storage" + cmd.getSecUrl(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new SecStorageSetupAnswer(storage.getMountPoint()); return new SecStorageSetupAnswer(storage.getMountPoint());
@ -432,7 +432,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public Answer ListVolumes(ListVolumeCommand cmd) { public Answer ListVolumes(ListVolumeCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockSecStorageVO storage = null; MockSecStorageVO storage = null;
try { try {
txn.start(); txn.start();
@ -446,11 +446,11 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding sec storage " + cmd.getSecUrl(), ex); throw new CloudRuntimeException("Error when finding sec storage " + cmd.getSecUrl(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
List<MockVolumeVO> volumes = _mockVolumeDao.findByStorageIdAndType(storage.getId(), 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); throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -483,7 +483,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
MockSecStorageVO storage = null; MockSecStorageVO storage = null;
String nfsUrl = ((NfsTO) store).getUrl(); String nfsUrl = ((NfsTO) store).getUrl();
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
storage = _mockSecStorageDao.findByUrl(nfsUrl); storage = _mockSecStorageDao.findByUrl(nfsUrl);
try { try {
txn.start(); 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); throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@Override @Override
public Answer Destroy(DestroyCommand cmd) { public Answer Destroy(DestroyCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolume().getPath()); 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); throw new CloudRuntimeException("Error when destroying volume " + cmd.getVolume().getPath(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new Answer(cmd); return new Answer(cmd);
@ -539,7 +539,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public DownloadAnswer Download(DownloadCommand cmd) { public DownloadAnswer Download(DownloadCommand cmd) {
MockSecStorageVO ssvo = null; MockSecStorageVO ssvo = null;
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl()); 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); throw new CloudRuntimeException("Error accessing secondary storage " + cmd.getSecUrl(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -564,7 +564,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
volume.setSize(0); volume.setSize(0);
volume.setType(MockVolumeType.TEMPLATE); volume.setType(MockVolumeType.TEMPLATE);
volume.setStatus(Status.DOWNLOAD_IN_PROGRESS); volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
volume = _mockVolumeDao.persist(volume); volume = _mockVolumeDao.persist(volume);
@ -574,7 +574,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving volume " + volume, ex); throw new CloudRuntimeException("Error when saving volume " + volume, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS, 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 @Override
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) { public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
String volumeId = cmd.getJobId(); 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); throw new CloudRuntimeException("Error during download job " + cmd.getJobId(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -624,7 +624,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) { public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
String uuid = cmd.getStorageId(); String uuid = cmd.getStorageId();
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
if (uuid == null) { 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); throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -663,7 +663,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
String volPath = cmd.getVolumePath(); String volPath = cmd.getVolumePath();
MockVolumeVO volume = null; MockVolumeVO volume = null;
MockStoragePoolVO storagePool = null; MockStoragePoolVO storagePool = null;
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(volPath); volume = _mockVolumeDao.findByStoragePathAndType(volPath);
@ -680,7 +680,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Unable to perform snapshot", ex); throw new CloudRuntimeException("Unable to perform snapshot", ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -693,7 +693,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
snapshot.setPoolId(storagePool.getId()); snapshot.setPoolId(storagePool.getId());
snapshot.setType(MockVolumeType.SNAPSHOT); snapshot.setType(MockVolumeType.SNAPSHOT);
snapshot.setStatus(Status.DOWNLOADED); snapshot.setStatus(Status.DOWNLOADED);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
snapshot = _mockVolumeDao.persist(snapshot); snapshot = _mockVolumeDao.persist(snapshot);
@ -703,7 +703,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving snapshot " + snapshot, ex); throw new CloudRuntimeException("Error when saving snapshot " + snapshot, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -717,7 +717,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
MockVolumeVO volume = null; MockVolumeVO volume = null;
MockVolumeVO snapshot = null; MockVolumeVO snapshot = null;
MockSecStorageVO secStorage = null; MockSecStorageVO secStorage = null;
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath()); volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
@ -742,7 +742,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when backing up snapshot"); throw new CloudRuntimeException("Error when backing up snapshot");
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -754,7 +754,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
newsnapshot.setSize(snapshot.getSize()); newsnapshot.setSize(snapshot.getSize());
newsnapshot.setStatus(Status.DOWNLOADED); newsnapshot.setStatus(Status.DOWNLOADED);
newsnapshot.setType(MockVolumeType.SNAPSHOT); newsnapshot.setType(MockVolumeType.SNAPSHOT);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
snapshot = _mockVolumeDao.persist(snapshot); 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); throw new CloudRuntimeException("Error when backing up snapshot " + newsnapshot, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -773,7 +773,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) { public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO backSnapshot = null; MockVolumeVO backSnapshot = null;
MockStoragePoolVO primary = null; MockStoragePoolVO primary = null;
try { try {
@ -795,7 +795,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when creating volume from snapshot", ex); throw new CloudRuntimeException("Error when creating volume from snapshot", ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -808,7 +808,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
volume.setSize(backSnapshot.getSize()); volume.setSize(backSnapshot.getSize());
volume.setStatus(Status.DOWNLOADED); volume.setStatus(Status.DOWNLOADED);
volume.setType(MockVolumeType.VOLUME); volume.setType(MockVolumeType.VOLUME);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
_mockVolumeDao.persist(volume); _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); throw new CloudRuntimeException("Error when creating volume from snapshot " + volume, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -828,7 +828,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public Answer Delete(DeleteCommand cmd) { public Answer Delete(DeleteCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockVolumeVO template = _mockVolumeDao.findByStoragePathAndType(cmd.getData().getPath()); 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"); throw new CloudRuntimeException("Error when deleting object");
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new Answer(cmd); return new Answer(cmd);
@ -879,7 +879,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public void preinstallTemplates(String url, long zoneId) { public void preinstallTemplates(String url, long zoneId) {
MockSecStorageVO storage = null; MockSecStorageVO storage = null;
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
storage = _mockSecStorageDao.findByUrl(url); storage = _mockSecStorageDao.findByUrl(url);
@ -933,14 +933,14 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
} catch (Exception ex) { } catch (Exception ex) {
throw new CloudRuntimeException("Unable to find sec storage at " + url, ex); throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
} finally { } finally {
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@Override @Override
public StoragePoolInfo getLocalStorage(String hostGuid) { public StoragePoolInfo getLocalStorage(String hostGuid) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null; MockHost host = null;
MockStoragePoolVO storagePool = null; MockStoragePoolVO storagePool = null;
try { try {
@ -953,7 +953,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Unable to find host " + hostGuid, ex); throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -965,7 +965,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE); storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
storagePool.setHostGuid(hostGuid); storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem); storagePool.setStorageType(StoragePoolType.Filesystem);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
storagePool = _mockStoragePoolDao.persist(storagePool); storagePool = _mockStoragePoolDao.persist(storagePool);
@ -975,7 +975,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex); throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -985,7 +985,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) { public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null; MockHost host = null;
try { try {
txn.start(); txn.start();
@ -996,13 +996,13 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Unable to find host " + hostGuid, ex); throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
if (storageSize == null) { if (storageSize == null) {
storageSize = DEFAULT_HOST_STORAGE_SIZE; storageSize = DEFAULT_HOST_STORAGE_SIZE;
} }
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockStoragePoolVO storagePool = null; MockStoragePoolVO storagePool = null;
try { try {
txn.start(); txn.start();
@ -1013,7 +1013,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when finding storagePool " + storagePool, ex); throw new CloudRuntimeException("Error when finding storagePool " + storagePool, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
if (storagePool == null) { if (storagePool == null) {
@ -1024,7 +1024,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
storagePool.setCapacity(storageSize); storagePool.setCapacity(storageSize);
storagePool.setHostGuid(hostGuid); storagePool.setHostGuid(hostGuid);
storagePool.setStorageType(StoragePoolType.Filesystem); storagePool.setStorageType(StoragePoolType.Filesystem);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
storagePool = _mockStoragePoolDao.persist(storagePool); storagePool = _mockStoragePoolDao.persist(storagePool);
@ -1034,7 +1034,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex); throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -1044,7 +1044,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) { public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO snapshot = null; MockVolumeVO snapshot = null;
MockSecStorageVO sec = null; MockSecStorageVO sec = null;
try { try {
@ -1066,7 +1066,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
txn.commit(); txn.commit();
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -1078,7 +1078,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
template.setSize(snapshot.getSize()); template.setSize(snapshot.getSize());
template.setStatus(Status.DOWNLOADED); template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE); template.setType(MockVolumeType.TEMPLATE);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
template = _mockVolumeDao.persist(template); template = _mockVolumeDao.persist(template);
@ -1088,7 +1088,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when saving template " + template, ex); throw new CloudRuntimeException("Error when saving template " + template, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -1098,7 +1098,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public Answer ComputeChecksum(ComputeChecksumCommand cmd) { public Answer ComputeChecksum(ComputeChecksumCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockVolumeVO volume = _mockVolumeDao.findByName(cmd.getTemplatePath()); MockVolumeVO volume = _mockVolumeDao.findByName(cmd.getTemplatePath());
@ -1116,14 +1116,14 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
return new Answer(cmd, true, md5); return new Answer(cmd, true, md5);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@Override @Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) { public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO volume = null; MockVolumeVO volume = null;
MockSecStorageVO sec = null; MockSecStorageVO sec = null;
try { try {
@ -1143,7 +1143,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
throw new CloudRuntimeException("Error when creating private template from volume"); throw new CloudRuntimeException("Error when creating private template from volume");
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -1155,7 +1155,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
template.setSize(volume.getSize()); template.setSize(volume.getSize());
template.setStatus(Status.DOWNLOADED); template.setStatus(Status.DOWNLOADED);
template.setType(MockVolumeType.TEMPLATE); template.setType(MockVolumeType.TEMPLATE);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
template = _mockVolumeDao.persist(template); template = _mockVolumeDao.persist(template);
@ -1166,7 +1166,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ template.getName(), ex); + template.getName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -1176,7 +1176,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
@Override @Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) { public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
boolean toSecondaryStorage = cmd.toSecondaryStorage(); boolean toSecondaryStorage = cmd.toSecondaryStorage();
MockSecStorageVO sec = null; MockSecStorageVO sec = null;
MockStoragePoolVO primaryStorage = null; MockStoragePoolVO primaryStorage = null;
@ -1193,11 +1193,11 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getSecondaryStorageURL(), ex); + cmd.getSecondaryStorageURL(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid()); primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
@ -1211,12 +1211,12 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getPool(), ex); + cmd.getPool(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
MockVolumeVO volume = null; MockVolumeVO volume = null;
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath()); volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
@ -1230,7 +1230,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ cmd.getVolumePath(), ex); + cmd.getVolumePath(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -1243,7 +1243,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
vol.setSize(volume.getSize()); vol.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED); vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME); vol.setType(MockVolumeType.VOLUME);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
vol = _mockVolumeDao.persist(vol); vol = _mockVolumeDao.persist(vol);
@ -1254,7 +1254,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ vol.getName(), ex); + vol.getName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath()); 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.setSize(volume.getSize());
vol.setStatus(Status.DOWNLOADED); vol.setStatus(Status.DOWNLOADED);
vol.setType(MockVolumeType.VOLUME); vol.setType(MockVolumeType.VOLUME);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
vol = _mockVolumeDao.persist(vol); vol = _mockVolumeDao.persist(vol);
@ -1277,7 +1277,7 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
+ vol.getName(), ex); + vol.getName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath()); return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());

View File

@ -72,7 +72,7 @@ import com.cloud.simulator.dao.MockVMDao;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.Ternary; import com.cloud.utils.Ternary;
import com.cloud.utils.component.ManagerBase; 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.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachine.State;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -111,7 +111,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
int cpuHz, long ramSize, int cpuHz, long ramSize,
String bootArgs, String hostGuid) { String bootArgs, String hostGuid) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockHost host = null; MockHost host = null;
MockVm vm = null; MockVm vm = null;
try { try {
@ -128,7 +128,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("Unable to start VM " + vmName, ex); throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
@ -153,7 +153,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
} else if (vmName.startsWith("i-")) { } else if (vmName.startsWith("i-")) {
vm.setType("User"); vm.setType("User");
} }
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
vm = _mockVmDao.persist((MockVMVO) vm); 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); throw new CloudRuntimeException("unable to save vm to db " + vm.getName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} else { } else {
if(vm.getState() == State.Stopped) { if(vm.getState() == State.Stopped) {
vm.setState(State.Running); vm.setState(State.Running);
txn = Transaction.open(Transaction.SIMULATOR_DB); txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
_mockVmDao.update(vm.getId(), (MockVMVO)vm); _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); throw new CloudRuntimeException("unable to update vm " + vm.getName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -230,7 +230,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override @Override
public Map<String, MockVMVO> getVms(String hostGuid) { public Map<String, MockVMVO> getVms(String hostGuid) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid); 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); throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -282,7 +282,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override @Override
public Map<String, State> getVmStates(String hostGuid) { public Map<String, State> getVmStates(String hostGuid) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
Map<String, State> states = new HashMap<String, State>(); 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); throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -338,7 +338,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override @Override
public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) { public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName()); 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); throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -378,7 +378,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override @Override
public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) { public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
String vmName = cmd.getVmName(); 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); throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@Override @Override
public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd) { public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
VirtualMachineTO vmTo = cmd.getVirtualMachine(); VirtualMachineTO vmTo = cmd.getVirtualMachine();
try { try {
txn.start(); txn.start();
@ -425,7 +425,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
throw new CloudRuntimeException("unable to find vm " + vmTo.getName(), ex); throw new CloudRuntimeException("unable to find vm " + vmTo.getName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
return new PrepareForMigrationAnswer(cmd); return new PrepareForMigrationAnswer(cmd);
} }
@ -438,7 +438,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override @Override
public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info) { public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(info.getHostUuid()); 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); throw new CloudRuntimeException("unable to clean up rules", ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -503,7 +503,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager {
@Override @Override
public StopAnswer stopVM(StopCommand cmd) { public StopAnswer stopVM(StopCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
String vmName = cmd.getVmName(); 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); throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@Override @Override
public RebootAnswer rebootVM(RebootCommand cmd) { public RebootAnswer rebootVM(RebootCommand cmd) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockVm vm = _mockVmDao.findByVmName(cmd.getVmName()); 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); throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }

View File

@ -99,7 +99,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.component.PluggableService; import com.cloud.utils.component.PluggableService;
import com.cloud.utils.db.DB; 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.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.storage.command.DeleteCommand; import org.apache.cloudstack.storage.command.DeleteCommand;
@ -182,7 +182,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
@DB @DB
@Override @Override
public Answer simulate(Command cmd, String hostGuid) { public Answer simulate(Command cmd, String hostGuid) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
MockHost host = _mockHost.findByGuid(hostGuid); MockHost host = _mockHost.findByGuid(hostGuid);
String cmdName = cmd.toString(); String cmdName = cmd.toString();
@ -373,7 +373,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
return new Answer(cmd, false, e.toString()); return new Answer(cmd, false, e.toString());
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
} }
@ -403,7 +403,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
@Override @Override
public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command, public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command,
String values) { String values) {
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB); TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try { try {
txn.start(); txn.start();
MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command); 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); throw new CloudRuntimeException("Unable to configure simulator because of " + ex.getMessage(), ex);
} finally { } finally {
txn.close(); txn.close();
txn = Transaction.open(Transaction.CLOUD_DB); txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close(); txn.close();
} }
return true; return true;

View File

@ -20,7 +20,7 @@ import com.cloud.simulator.MockConfigurationVO;
import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.TransactionLegacy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.ejb.Local; import javax.ejb.Local;
@ -117,7 +117,7 @@ public class MockConfigurationDaoImpl extends GenericDaoBase<MockConfigurationVO
@Override @Override
public MockConfigurationVO findByNameBottomUP(Long dcId, Long podId, Long clusterId, Long hostId, String name) { 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(); StringBuilder search = new StringBuilder();
Formatter formatter = new Formatter(search); 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); 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);

View File

@ -120,6 +120,8 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.GlobalLock;
import com.cloud.utils.db.Transaction; 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.exception.CloudRuntimeException;
import com.cloud.utils.script.Script; import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SshHelper; 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 // Add DC to database into vmware_data_center table
vmwareDc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, userName, password); vmwareDc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, userName, password);
Transaction txn = Transaction.currentTxn(); vmwareDc = _vmwareDcDao.persist(vmwareDc);
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());
}
// Map zone with vmware datacenter // Map zone with vmware datacenter
vmwareDcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDc.getId()); vmwareDcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDc.getId());
txn = Transaction.currentTxn(); vmwareDcZoneMap = _vmwareDcZoneMapDao.persist(vmwareDcZoneMap);
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());
}
// Set custom field for this DC // Set custom field for this DC
if (addDcCustomFieldDef) { if (addDcCustomFieldDef) {
@ -1152,40 +1134,35 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
validateZoneWithResources(zoneId, "remove VMware datacenter to zone"); validateZoneWithResources(zoneId, "remove VMware datacenter to zone");
// Get DC associated with this zone // Get DC associated with this zone
VmwareDatacenterZoneMapVO vmwareDcZoneMap;
VmwareDatacenterVO vmwareDatacenter; VmwareDatacenterVO vmwareDatacenter;
String vmwareDcName; String vmwareDcName;
long vmwareDcId;
String vCenterHost; String vCenterHost;
String userName; String userName;
String password; String password;
DatacenterMO dcMo = null; DatacenterMO dcMo = null;
Transaction txn; Transaction txn;
vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId); final VmwareDatacenterZoneMapVO vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
// Check if zone is associated with VMware DC // Check if zone is associated with VMware DC
if (vmwareDcZoneMap == null) { if (vmwareDcZoneMap == null) {
throw new CloudRuntimeException("Zone " + zoneId + " is not associated with any VMware datacenter."); throw new CloudRuntimeException("Zone " + zoneId + " is not associated with any VMware datacenter.");
} }
vmwareDcId = vmwareDcZoneMap.getVmwareDcId(); final long vmwareDcId = vmwareDcZoneMap.getVmwareDcId();
vmwareDatacenter = _vmwareDcDao.findById(vmwareDcId); vmwareDatacenter = _vmwareDcDao.findById(vmwareDcId);
vmwareDcName = vmwareDatacenter.getVmwareDatacenterName(); vmwareDcName = vmwareDatacenter.getVmwareDatacenterName();
vCenterHost = vmwareDatacenter.getVcenterHost(); vCenterHost = vmwareDatacenter.getVcenterHost();
userName = vmwareDatacenter.getUser(); userName = vmwareDatacenter.getUser();
password = vmwareDatacenter.getPassword(); password = vmwareDatacenter.getPassword();
txn = Transaction.currentTxn(); Transaction.execute(new TransactionCallbackNoReturn() {
try { @Override
txn.start(); public void doInTransactionWithoutResult(TransactionStatus status) {
// Remove the VMware datacenter entry in table vmware_data_center // Remove the VMware datacenter entry in table vmware_data_center
_vmwareDcDao.remove(vmwareDcId); _vmwareDcDao.remove(vmwareDcId);
// Remove the map entry in table vmware_data_center_zone_map // Remove the map entry in table vmware_data_center_zone_map
_vmwareDcZoneMapDao.remove(vmwareDcZoneMap.getId()); _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.");
}
// Construct context // Construct context
VmwareContext context = null; VmwareContext context = null;

View File

@ -38,6 +38,8 @@ import com.cloud.resource.ResourceManager;
import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; 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.exception.CloudRuntimeException;
import com.cloud.network.dao.CiscoNexusVSMDeviceDao; import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
import com.cloud.network.dao.PortProfileDao; import com.cloud.network.dao.PortProfileDao;
@ -131,29 +133,13 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
if (VSMObj == null) { if (VSMObj == null) {
// Create the VSM record. For now, we aren't using the vsmName field. // Create the VSM record. For now, we aren't using the vsmName field.
VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password); VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password);
Transaction txn = Transaction.currentTxn(); _ciscoNexusVSMDeviceDao.persist(VSMObj);
try {
txn.start();
_ciscoNexusVSMDeviceDao.persist(VSMObj);
txn.commit();
} catch (Exception e) {
txn.rollback();
throw new CloudRuntimeException(e.getMessage());
}
} }
// At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id. // At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id.
long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId(); long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId();
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId); ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId);
Transaction txn = Transaction.currentTxn(); _clusterVSMDao.persist(connectorObj);
try {
txn.start();
_clusterVSMDao.persist(connectorObj);
txn.commit();
} catch (Exception e) {
txn.rollback();
throw new CloudRuntimeException(e.getMessage());
}
// Now, get a list of all the ESXi servers in this cluster. // Now, get a list of all the ESXi servers in this cluster.
// This is effectively a select * from host where cluster_id=clusterId; // This is effectively a select * from host where cluster_id=clusterId;
@ -196,7 +182,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
} }
@DB @DB
public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException { public boolean deleteCiscoNexusVSM(final long vsmId) throws ResourceInUseException {
CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId); CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
if (cisconexusvsm == null) { if (cisconexusvsm == null) {
// This entry is already not present. Return success. // 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. // Iterate through the cluster list again, this time, delete the VSM.
Transaction txn = Transaction.currentTxn(); Transaction.execute(new TransactionCallbackNoReturn() {
try { @Override
txn.start(); public void doInTransactionWithoutResult(TransactionStatus status) {
// Remove the VSM entry in CiscoNexusVSMDeviceVO's table. // Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
_ciscoNexusVSMDeviceDao.remove(vsmId); _ciscoNexusVSMDeviceDao.remove(vsmId);
// Remove the current record as well from ClusterVSMMapVO's table. // Remove the current record as well from ClusterVSMMapVO's table.
_clusterVSMDao.removeByVsmId(vsmId); _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");
}
return true; return true;
} }
@ -252,15 +234,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled) { if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled) {
// it's currently disabled. So change it to enabled and write it out to the db. // it's currently disabled. So change it to enabled and write it out to the db.
cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled); cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled);
Transaction txn = Transaction.currentTxn(); _ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
try {
txn.start();
_ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
txn.commit();
} catch (Exception e) {
txn.rollback();
throw new CloudRuntimeException(e.getMessage());
}
} }
return cisconexusvsm; return cisconexusvsm;
@ -276,15 +250,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled) { if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled) {
// it's currently disabled. So change it to enabled and write it out to the db. // it's currently disabled. So change it to enabled and write it out to the db.
cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled); cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled);
Transaction txn = Transaction.currentTxn(); _ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
try {
txn.start();
_ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
txn.commit();
} catch (Exception e) {
txn.rollback();
throw new CloudRuntimeException(e.getMessage());
}
} }
return cisconexusvsm; return cisconexusvsm;

View File

@ -61,6 +61,8 @@ import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper;
import com.cloud.utils.component.Manager; import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; 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.exception.CloudRuntimeException;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
@ -260,7 +262,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
} }
@DB @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; CiscoNexusVSMDeviceVO vsm = null;
boolean vsmAdded = false; boolean vsmAdded = false;
Long vsmId = 0L; 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. // persist credentials to database if the VSM entry is not already in the db.
if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) { vsm = Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>() {
vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword); @Override
txn = Transaction.currentTxn(); public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) {
try { CiscoNexusVSMDeviceVO vsm = null;
txn.start(); if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
vsm = _vsmDao.persist(vsm); vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
txn.commit(); vsm = _vsmDao.persist(vsm);
} catch (Exception e) { }
txn.rollback(); // Create a mapping between the cluster and the vsm.
s_logger.error("Failed to persist Cisco Nexus 1000v VSM details to database. Exception: " + e.getMessage()); vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
throw new CloudRuntimeException(e.getMessage()); 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 { } else {
String msg; String msg;
msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() + msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() +

View File

@ -29,7 +29,6 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager;
@ -84,6 +83,9 @@ import com.cloud.resource.UnableDeleteHostException;
import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; 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.utils.exception.CloudRuntimeException;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
@ -329,11 +331,10 @@ public class BigSwitchVnsElement extends AdapterBase implements
@DB @DB
public BigSwitchVnsDeviceVO addBigSwitchVnsDevice(AddBigSwitchVnsDeviceCmd cmd) { public BigSwitchVnsDeviceVO addBigSwitchVnsDevice(AddBigSwitchVnsDeviceCmd cmd) {
ServerResource resource = new BigSwitchVnsResource(); ServerResource resource = new BigSwitchVnsResource();
String deviceName = VnsConstants.BigSwitchVns.getName(); final String deviceName = VnsConstants.BigSwitchVns.getName();
NetworkDevice networkDevice = NetworkDevice NetworkDevice networkDevice = NetworkDevice
.getNetworkDevice(deviceName); .getNetworkDevice(deviceName);
Long physicalNetworkId = cmd.getPhysicalNetworkId(); final Long physicalNetworkId = cmd.getPhysicalNetworkId();
BigSwitchVnsDeviceVO bigswitchVnsDevice = null;
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
.findById(physicalNetworkId); .findById(physicalNetworkId);
@ -344,7 +345,7 @@ public class BigSwitchVnsElement extends AdapterBase implements
} }
long zoneId = physicalNetwork.getDataCenterId(); long zoneId = physicalNetwork.getDataCenterId();
PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
.findByServiceProvider(physicalNetwork.getId(), .findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder()); networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) { if (ntwkSvcProvider == null) {
@ -377,33 +378,33 @@ public class BigSwitchVnsElement extends AdapterBase implements
Map<String, Object> hostdetails = new HashMap<String, Object>(); Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params); hostdetails.putAll(params);
Transaction txn = Transaction.currentTxn();
try { try {
resource.configure(cmd.getHost(), hostdetails); resource.configure(cmd.getHost(), hostdetails);
Host host = _resourceMgr.addHost(zoneId, resource, final Host host = _resourceMgr.addHost(zoneId, resource,
Host.Type.L2Networking, params); Host.Type.L2Networking, params);
if (host != null) { if (host != null) {
txn.start(); return Transaction.execute(new TransactionCallback<BigSwitchVnsDeviceVO>() {
@Override
bigswitchVnsDevice = new BigSwitchVnsDeviceVO(host.getId(), public BigSwitchVnsDeviceVO doInTransaction(TransactionStatus status) {
physicalNetworkId, ntwkSvcProvider.getProviderName(), BigSwitchVnsDeviceVO bigswitchVnsDevice = new BigSwitchVnsDeviceVO(host.getId(),
deviceName); physicalNetworkId, ntwkSvcProvider.getProviderName(),
_bigswitchVnsDao.persist(bigswitchVnsDevice); deviceName);
_bigswitchVnsDao.persist(bigswitchVnsDevice);
DetailVO detail = new DetailVO(host.getId(),
"bigswitchvnsdeviceid", DetailVO detail = new DetailVO(host.getId(),
String.valueOf(bigswitchVnsDevice.getId())); "bigswitchvnsdeviceid",
_hostDetailsDao.persist(detail); String.valueOf(bigswitchVnsDevice.getId()));
_hostDetailsDao.persist(detail);
txn.commit();
return bigswitchVnsDevice; return bigswitchVnsDevice;
}
});
} else { } else {
throw new CloudRuntimeException( throw new CloudRuntimeException(
"Failed to add BigSwitch Vns Device due to internal error."); "Failed to add BigSwitch Vns Device due to internal error.");
} }
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
txn.rollback();
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
} }

View File

@ -29,7 +29,6 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; 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.dc.dao.VlanDao;
import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceAllocationException;
@ -123,7 +123,11 @@ import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.EntityManager; import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.Transaction; 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.CloudRuntimeException;
import com.cloud.utils.exception.ExceptionUtil;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
@ -274,11 +278,11 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
} }
@Override @Override
public boolean implement(Network network, NetworkOffering offering, public boolean implement(final Network network, final NetworkOffering offering,
DeployDestination dest, ReservationContext context) final DeployDestination dest, final ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException, throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException { InsufficientCapacityException {
DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic) { if (zone.getNetworkType() == NetworkType.Basic) {
s_logger.debug("Not handling network implement in zone of type " + 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; return false;
} }
List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); final List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No Cisco Vnmc device on network " + network.getName()); s_logger.error("No Cisco Vnmc device on network " + network.getName());
return false; return false;
@ -312,114 +316,121 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
return false; return false;
} }
Transaction txn = Transaction.currentTxn();
boolean status = false;
try { try {
txn.start(); 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 // ensure that there is an ASA 1000v assigned to this network
CiscoAsa1000vDevice assignedAsa = assignAsa1000vToNetwork(network); CiscoAsa1000vDevice assignedAsa = assignAsa1000vToNetwork(network);
if (assignedAsa == null) { if (assignedAsa == null) {
s_logger.error("Unable to assign ASA 1000v device to network " + network.getName()); s_logger.error("Unable to assign ASA 1000v device to network " + network.getName());
return false; 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());
}
ClusterVO asaCluster = _clusterDao.findById(assignedAsa.getClusterId()); return null;
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;
} }
} }, Exception.class);
if (outsideIp == null) { // none available, acquire one } catch (CloudRuntimeException e) {
try { s_logger.error("CiscoVnmcElement failed", e);
Account caller = CallContext.current().getCallingAccount(); return false;
long callerUserId = CallContext.current().getCallingUserId(); } catch (Exception e) {
outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone); ExceptionUtil.rethrowRuntime(e);
} catch (ResourceAllocationException e) { ExceptionUtil.rethrow(e, InsufficientAddressCapacityException.class);
s_logger.error("Unable to allocate additional public Ip address. Exception details " + e); ExceptionUtil.rethrow(e, ResourceUnavailableException.class);
return false; throw new IllegalStateException(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);
return false;
}
}
// 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
}
} }
return true; return true;
@ -522,9 +533,9 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
@Override @Override
public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) { public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
String deviceName = Provider.CiscoVnmc.getName(); final String deviceName = Provider.CiscoVnmc.getName();
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName); NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
Long physicalNetworkId = cmd.getPhysicalNetworkId(); final Long physicalNetworkId = cmd.getPhysicalNetworkId();
CiscoVnmcController ciscoVnmcResource = null; CiscoVnmcController ciscoVnmcResource = null;
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId); PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
@ -533,7 +544,7 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
} }
long zoneId = physicalNetwork.getDataCenterId(); long zoneId = physicalNetwork.getDataCenterId();
PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder()); networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) { if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() +
@ -560,27 +571,27 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
hostdetails.putAll(params); hostdetails.putAll(params);
ServerResource resource = new CiscoVnmcResource(); ServerResource resource = new CiscoVnmcResource();
Transaction txn = Transaction.currentTxn();
try { try {
resource.configure(cmd.getHost(), hostdetails); 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) { if (host != null) {
txn.start(); return Transaction.execute(new TransactionCallback<CiscoVnmcController>() {
@Override
ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName); public CiscoVnmcController doInTransaction(TransactionStatus status) {
_ciscoVnmcDao.persist((CiscoVnmcControllerVO)ciscoVnmcResource); 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); DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
_hostDetailsDao.persist(detail);
txn.commit();
return ciscoVnmcResource; return ciscoVnmcResource;
}
});
} else { } else {
throw new CloudRuntimeException("Failed to add Cisco Vnmc device due to internal error."); throw new CloudRuntimeException("Failed to add Cisco Vnmc device due to internal error.");
} }
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
txn.rollback();
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
} }

View File

@ -46,6 +46,8 @@ import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.AccountDao;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; 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.exception.CloudRuntimeException;
import com.cloud.vm.Nic; import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile; 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()); 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) { if (ip != null && nic.getReservationStrategy() != Nic.ReservationStrategy.Managed) {
Transaction.execute(new TransactionCallbackNoReturn() {
Transaction txn = Transaction.currentTxn(); @Override
txn.start(); public void doInTransactionWithoutResult(TransactionStatus status) {
_ipAddrMgr.markIpAsUnavailable(ip.getId());
_ipAddrMgr.markIpAsUnavailable(ip.getId()); _ipAddressDao.unassignIpAddress(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId()); }
});
txn.commit();
} }
nic.deallocate(); nic.deallocate();

View File

@ -31,7 +31,6 @@ import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.cloudstack.region.gslb.GslbServiceProvider; import org.apache.cloudstack.region.gslb.GslbServiceProvider;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager;
@ -110,13 +109,14 @@ import com.cloud.offering.NetworkOffering;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; 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.exception.CloudRuntimeException;
import com.cloud.utils.net.UrlUtil; import com.cloud.utils.net.UrlUtil;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
import com.google.gson.Gson; import com.google.gson.Gson;
@Local(value = {NetworkElement.class, StaticNatServiceProvider.class, LoadBalancingServiceProvider.class, GslbServiceProvider.class}) @Local(value = {NetworkElement.class, StaticNatServiceProvider.class, LoadBalancingServiceProvider.class, GslbServiceProvider.class})
@ -409,9 +409,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
} }
@DB @DB
private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDeviceId, Long capacity, Boolean dedicatedUse, List<Long> newPodsConfig) { private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(final long lbDeviceId, Long capacity, Boolean dedicatedUse, List<Long> newPodsConfig) {
ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId); final ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId()); final Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId());
if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) { if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId); 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) { if (newPodsConfig != null && newPodsConfig.size() > 0) {
for (Long podId: newPodsConfig) { for (Long podId: newPodsConfig) {
HostPodVO pod = _podDao.findById(podId); 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) { for (Long podId: currentPodsConfig) {
if (!newPodsConfig.contains(podId)) { if (!newPodsConfig.contains(podId)) {
podsToDeassociate.add(podId); podsToDeassociate.add(podId);
@ -482,26 +482,28 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl
lbDeviceVo.setIsDedicatedDevice(dedicatedUse); lbDeviceVo.setIsDedicatedDevice(dedicatedUse);
} }
Transaction txn = Transaction.currentTxn(); Transaction.execute(new TransactionCallbackNoReturn() {
txn.start(); @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);
_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);
HostVO host = _hostDao.findById(lbDeviceVo.getHostId()); HostVO host = _hostDao.findById(lbDeviceVo.getHostId());
txn.commit();
_agentMgr.reconnect(host.getId()); _agentMgr.reconnect(host.getId());
return lbDeviceVo; return lbDeviceVo;
} }

View File

@ -30,7 +30,6 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; 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.component.AdapterBase;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction; 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.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
@ -552,12 +553,10 @@ public class NiciraNvpElement extends AdapterBase implements
@DB @DB
public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) { public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
ServerResource resource = new NiciraNvpResource(); ServerResource resource = new NiciraNvpResource();
String deviceName = Network.Provider.NiciraNvp.getName(); final String deviceName = Network.Provider.NiciraNvp.getName();
NetworkDevice networkDevice = NetworkDevice NetworkDevice networkDevice = NetworkDevice
.getNetworkDevice(deviceName); .getNetworkDevice(deviceName);
Long physicalNetworkId = cmd.getPhysicalNetworkId(); final Long physicalNetworkId = cmd.getPhysicalNetworkId();
NiciraNvpDeviceVO niciraNvpDevice = null;
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
.findById(physicalNetworkId); .findById(physicalNetworkId);
if (physicalNetwork == null) { if (physicalNetwork == null) {
@ -567,7 +566,7 @@ public class NiciraNvpElement extends AdapterBase implements
} }
long zoneId = physicalNetwork.getDataCenterId(); long zoneId = physicalNetwork.getDataCenterId();
PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
.findByServiceProvider(physicalNetwork.getId(), .findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder()); networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) { if (ntwkSvcProvider == null) {
@ -606,33 +605,33 @@ public class NiciraNvpElement extends AdapterBase implements
Map<String, Object> hostdetails = new HashMap<String, Object>(); Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params); hostdetails.putAll(params);
Transaction txn = Transaction.currentTxn();
try { try {
resource.configure(cmd.getHost(), hostdetails); resource.configure(cmd.getHost(), hostdetails);
Host host = _resourceMgr.addHost(zoneId, resource, final Host host = _resourceMgr.addHost(zoneId, resource,
Host.Type.L2Networking, params); Host.Type.L2Networking, params);
if (host != null) { if (host != null) {
txn.start(); 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);
niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), return niciraNvpDevice;
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;
} else { } else {
throw new CloudRuntimeException( throw new CloudRuntimeException(
"Failed to add Nicira Nvp Device due to internal error."); "Failed to add Nicira Nvp Device due to internal error.");
} }
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
txn.rollback();
throw new CloudRuntimeException(e.getMessage()); throw new CloudRuntimeException(e.getMessage());
} }
} }

View File

@ -191,7 +191,7 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A
if (e instanceof NetworkRuleConflictException) { if (e instanceof NetworkRuleConflictException) {
throw (NetworkRuleConflictException) e; 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 { } finally {
if (!success && newRule != null) { if (!success && newRule != null) {
_lbMgr.removeLBRule(newRule); _lbMgr.removeLBRule(newRule);