use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class SimulatorManagerImpl method configureSimulator.
@Override
public Long configureSimulator(final Long zoneId, final Long podId, final Long clusterId, final Long hostId, final String command, final String values, final Integer count, final String jsonResponse) {
Long id = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command);
if (config == null) {
config = new MockConfigurationVO();
config.setClusterId(clusterId);
config.setDataCenterId(zoneId);
config.setPodId(podId);
config.setHostId(hostId);
config.setName(command);
config.setValues(values);
config.setCount(count);
config.setJsonResponse(jsonResponse);
config = _mockConfigDao.persist(config);
txn.commit();
} else {
config.setValues(values);
config.setCount(count);
config.setJsonResponse(jsonResponse);
_mockConfigDao.update(config.getId(), config);
txn.commit();
}
id = config.getId();
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to configure simulator mock because of " + ex.getMessage(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return id;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class SimulatorManagerImpl method querySimulatorMock.
@Override
public MockConfigurationVO querySimulatorMock(final Long id) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
return _mockConfigDao.findById(id);
} catch (final Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Unable to query simulator mock because of " + ex.getMessage(), ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidServiceType.
void runCreateGlobalLoadBalancerRuleInvalidServiceType() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
RegionVO region = new RegionVO();
region.setGslbEnabled(true);
when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
gslbServiceImpl._rulesMgr = Mockito.mock(RulesManager.class);
gslbServiceImpl._lbDao = Mockito.mock(LoadBalancerDao.class);
gslbServiceImpl._networkDao = Mockito.mock(NetworkDao.class);
gslbServiceImpl._globalConfigDao = Mockito.mock(ConfigurationDao.class);
gslbServiceImpl._ipAddressDao = Mockito.mock(IPAddressDao.class);
gslbServiceImpl._agentMgr = Mockito.mock(AgentManager.class);
CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = createCmd.getClass().getSuperclass();
Field regionIdField = _class.getDeclaredField("regionId");
regionIdField.setAccessible(true);
regionIdField.set(createCmd, new Integer(1));
Field algoField = _class.getDeclaredField("algorithm");
algoField.setAccessible(true);
algoField.set(createCmd, "roundrobin");
Field stickyField = _class.getDeclaredField("stickyMethod");
stickyField.setAccessible(true);
stickyField.set(createCmd, "sourceip");
Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
nameField.setAccessible(true);
nameField.set(createCmd, "gslb-rule");
Field descriptionField = _class.getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(createCmd, "testing create gslb-rule");
Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
serviceDomainField.setAccessible(true);
serviceDomainField.set(createCmd, "gslb-rule-domain");
Field serviceTypeField = _class.getDeclaredField("serviceType");
serviceTypeField.setAccessible(true);
serviceTypeField.set(createCmd, "invalidtcp");
try {
gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
} catch (InvalidParameterValueException e) {
Assert.assertTrue(e.getMessage().contains("Invalid service type"));
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runRemoveFromGlobalLoadBalancerRuleTest.
void runRemoveFromGlobalLoadBalancerRuleTest() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runRemoveFromGlobalLoadBalancerRuleTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
gslbServiceImpl._rulesMgr = Mockito.mock(RulesManager.class);
gslbServiceImpl._lbDao = Mockito.mock(LoadBalancerDao.class);
gslbServiceImpl._networkDao = Mockito.mock(NetworkDao.class);
gslbServiceImpl._globalConfigDao = Mockito.mock(ConfigurationDao.class);
gslbServiceImpl._ipAddressDao = Mockito.mock(IPAddressDao.class);
gslbServiceImpl._agentMgr = Mockito.mock(AgentManager.class);
List<GslbServiceProvider> mockGslbProviders = new ArrayList<GslbServiceProvider>();
mockGslbProviders.add(Mockito.mock(GslbServiceProvider.class));
gslbServiceImpl._gslbProviders = mockGslbProviders;
RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd = new RemoveFromGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = removeFromGslbCmd.getClass().getSuperclass();
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
Field gslbRuleId = _class.getDeclaredField("id");
gslbRuleId.setAccessible(true);
gslbRuleId.set(removeFromGslbCmd, new Long(1));
GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO("test-gslb-rule", "test-gslb-rule", "test-domain", "roundrobin", "sourceip", "tcp", 1, 1, 1, GlobalLoadBalancerRule.State.Active);
when(gslbServiceImpl._gslbRuleDao.findById(new Long(1))).thenReturn(gslbRule);
LoadBalancerVO lbRule = new LoadBalancerVO();
lbRule.setState(FirewallRule.State.Active);
Field networkIdField = LoadBalancerVO.class.getSuperclass().getDeclaredField("networkId");
networkIdField.setAccessible(true);
networkIdField.set(lbRule, new Long(1));
Field idField = LoadBalancerVO.class.getSuperclass().getDeclaredField("id");
idField.setAccessible(true);
idField.set(lbRule, new Long(1));
Field sourceIpAddressId = LoadBalancerVO.class.getSuperclass().getDeclaredField("sourceIpAddressId");
sourceIpAddressId.setAccessible(true);
sourceIpAddressId.set(lbRule, new Long(1));
when(gslbServiceImpl._lbDao.findById(new Long(1))).thenReturn(lbRule);
Field lbRules = _class.getDeclaredField("loadBalancerRulesIds");
lbRules.setAccessible(true);
List<Long> lbRuleIds = new ArrayList<Long>();
lbRuleIds.add(new Long(1));
lbRules.set(removeFromGslbCmd, lbRuleIds);
NetworkVO networkVo = new NetworkVO();
Field dcID = NetworkVO.class.getDeclaredField("dataCenterId");
dcID.setAccessible(true);
dcID.set(networkVo, new Long(1));
Field phyNetworkId = NetworkVO.class.getDeclaredField("physicalNetworkId");
phyNetworkId.setAccessible(true);
phyNetworkId.set(networkVo, new Long(200));
when(gslbServiceImpl._networkDao.findById(new Long(1))).thenReturn(networkVo);
GlobalLoadBalancerLbRuleMapVO gslbLbMap = new GlobalLoadBalancerLbRuleMapVO(1, 1, 1);
List<GlobalLoadBalancerLbRuleMapVO> listSslbLbMap = new ArrayList<GlobalLoadBalancerLbRuleMapVO>();
listSslbLbMap.add(gslbLbMap);
when(gslbServiceImpl._gslbLbMapDao.listByGslbRuleId(new Long(1))).thenReturn(listSslbLbMap);
when(gslbServiceImpl._gslbLbMapDao.findByGslbRuleIdAndLbRuleId(new Long(1), new Long(1))).thenReturn(gslbLbMap);
IPAddressVO ip = new IPAddressVO(new Ip("10.1.1.1"), 1, 1, 1, true);
when(gslbServiceImpl._ipAddressDao.findById(new Long(1))).thenReturn(ip);
gslbServiceImpl.removeFromGlobalLoadBalancerRule(removeFromGslbCmd);
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRulePostiveTest.
void runCreateGlobalLoadBalancerRulePostiveTest() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
RegionVO region = new RegionVO();
region.setGslbEnabled(true);
when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
gslbServiceImpl._rulesMgr = Mockito.mock(RulesManager.class);
gslbServiceImpl._lbDao = Mockito.mock(LoadBalancerDao.class);
gslbServiceImpl._networkDao = Mockito.mock(NetworkDao.class);
gslbServiceImpl._globalConfigDao = Mockito.mock(ConfigurationDao.class);
gslbServiceImpl._ipAddressDao = Mockito.mock(IPAddressDao.class);
gslbServiceImpl._agentMgr = Mockito.mock(AgentManager.class);
CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = createCmd.getClass().getSuperclass();
Field regionIdField = _class.getDeclaredField("regionId");
regionIdField.setAccessible(true);
regionIdField.set(createCmd, new Integer(1));
Field algoField = _class.getDeclaredField("algorithm");
algoField.setAccessible(true);
algoField.set(createCmd, "roundrobin");
Field stickyField = _class.getDeclaredField("stickyMethod");
stickyField.setAccessible(true);
stickyField.set(createCmd, "sourceip");
Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
nameField.setAccessible(true);
nameField.set(createCmd, "gslb-rule");
Field descriptionField = _class.getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(createCmd, "testing create gslb-rule");
Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
serviceDomainField.setAccessible(true);
serviceDomainField.set(createCmd, "gslb-rule-domain");
Field serviceTypeField = _class.getDeclaredField("serviceType");
serviceTypeField.setAccessible(true);
serviceTypeField.set(createCmd, "tcp");
try {
gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
} catch (Exception e) {
s_logger.info("exception in testing runCreateGlobalLoadBalancerRulePostiveTest message: " + e.toString());
}
}
Aggregations