use of com.cloud.user.AccountVO in project cloudstack by apache.
the class ConfigurationManagerImpl method markDefaultZone.
@Override
@ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the " + "default zone", async = true)
public AccountVO markDefaultZone(final String accountName, final long domainId, final long defaultZoneId) {
// Check if the account exists
final Account account = _accountDao.findEnabledAccount(accountName, domainId);
if (account == null) {
s_logger.error("Unable to find account by name: " + accountName + " in domain " + domainId);
throw new InvalidParameterValueException("Account by name: " + accountName + " doesn't exist in domain " + domainId);
}
// Don't allow modification of system account
if (account.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Can not modify system account");
}
final AccountVO acctForUpdate = _accountDao.findById(account.getId());
acctForUpdate.setDefaultZoneId(defaultZoneId);
if (_accountDao.update(account.getId(), acctForUpdate)) {
CallContext.current().setEventDetails("Default zone id= " + defaultZoneId);
return _accountDao.findById(account.getId());
} else {
return null;
}
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class MidoNetElementTest method testImplement.
/*
* Test the standard case of implement with no errors.
*/
public void testImplement() {
//mock
MidonetApi api = mock(MidonetApi.class, RETURNS_DEEP_STUBS);
//mockAccountDao
AccountDao mockAccountDao = mock(AccountDao.class);
AccountVO mockAccountVO = mock(AccountVO.class);
when(mockAccountDao.findById(anyLong())).thenReturn(mockAccountVO);
when(mockAccountVO.getUuid()).thenReturn("1");
MidoNetElement elem = new MidoNetElement();
elem.setMidonetApi(api);
elem.setAccountDao(mockAccountDao);
//mockRPort
RouterPort mockRPort = mock(RouterPort.class);
when(mockRPort.getId()).thenReturn(UUID.fromString("550e8400-e29b-41d4-a716-446655440000"));
//mockBPort
BridgePort mockBPort = mock(BridgePort.class);
when(mockBPort.link(any(UUID.class))).thenReturn(mockBPort);
//mockPort
Port mockPort = mock(Port.class);
ResourceCollection<Port> peerPorts = new ResourceCollection<Port>(new ArrayList<Port>());
peerPorts.add(mockPort);
//mockBridge
Bridge mockBridge = mock(Bridge.class, RETURNS_DEEP_STUBS);
when(api.addBridge().tenantId(anyString()).name(anyString()).create()).thenReturn(mockBridge);
when(mockBridge.addInteriorPort().create()).thenReturn(mockBPort);
when(mockBridge.getPeerPorts()).thenReturn(peerPorts);
//mockRouter
Router mockRouter = mock(Router.class, RETURNS_DEEP_STUBS);
when(api.addRouter().tenantId(anyString()).name(anyString()).create()).thenReturn(mockRouter);
when(mockRouter.addInteriorRouterPort().create()).thenReturn(mockRPort);
//mockNetwork
Network mockNetwork = mock(Network.class);
when(mockNetwork.getAccountId()).thenReturn((long) 1);
when(mockNetwork.getGateway()).thenReturn("1.2.3.4");
when(mockNetwork.getCidr()).thenReturn("1.2.3.0/24");
when(mockNetwork.getId()).thenReturn((long) 2);
when(mockNetwork.getBroadcastDomainType()).thenReturn(Networks.BroadcastDomainType.Mido);
when(mockNetwork.getTrafficType()).thenReturn(Networks.TrafficType.Public);
boolean result = false;
try {
result = elem.implement(mockNetwork, null, null, null);
} catch (ConcurrentOperationException e) {
fail(e.getMessage());
} catch (InsufficientCapacityException e) {
fail(e.getMessage());
} catch (ResourceUnavailableException e) {
fail(e.getMessage());
}
assertEquals(result, true);
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class MidoNetPublicNetworkGuru method generateBroadcastUri.
private URI generateBroadcastUri(Network network) {
AccountVO acc = _accountDao.findById(network.getAccountId());
String accountUUIDStr = acc.getUuid();
String networkUUIDStr = String.valueOf(network.getId());
return Networks.BroadcastDomainType.Mido.toUri(accountUUIDStr + "." + networkUUIDStr + ":" + networkUUIDStr);
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class VmWorkJobWakeupDispatcher method runJob.
@Override
public void runJob(AsyncJob job) {
try {
List<AsyncJobJoinMapVO> joinRecords = _joinMapDao.listJoinRecords(job.getId());
if (joinRecords.size() != 1) {
s_logger.warn("AsyncJob-" + job.getId() + " received wakeup call with un-supported joining job number: " + joinRecords.size());
// if we fail wakeup-execution for any reason, avoid release sync-source if there is any
job.setSyncSource(null);
return;
}
AsyncJobJoinMapVO joinRecord = joinRecords.get(0);
VmWorkJobVO joinedJob = _workjobDao.findById(joinRecord.getJoinJobId());
Class<?> workClz = null;
try {
workClz = Class.forName(job.getCmd());
} catch (ClassNotFoundException e) {
s_logger.error("VM work class " + job.getCmd() + " is not found", e);
return;
}
// get original work context information from joined job
VmWork work = VmWorkSerializer.deserialize(workClz, joinedJob.getCmdInfo());
assert (work != null);
AccountVO account = _accountDao.findById(work.getAccountId());
assert (account != null);
VMInstanceVO vm = _instanceDao.findById(work.getVmId());
assert (vm != null);
CallContext.register(work.getUserId(), work.getAccountId(), job.getRelated());
try {
Method handler = getHandler(joinRecord.getWakeupHandler());
if (handler != null) {
handler.invoke(_vmMgr);
} else {
assert (false);
s_logger.error("Unable to find wakeup handler " + joinRecord.getWakeupHandler() + " when waking up job-" + job.getId());
}
} finally {
CallContext.unregister();
}
} catch (Throwable e) {
s_logger.warn("Unexpected exception in waking up job-" + job.getId());
// if we fail wakeup-execution for any reason, avoid release sync-source if there is any
job.setSyncSource(null);
}
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class UsageDaoImpl method updateAccounts.
@Override
public void updateAccounts(List<AccountVO> accounts) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
txn.start();
String sql = UPDATE_ACCOUNT;
PreparedStatement pstmt = null;
// in reality I just want CLOUD_USAGE dataSource connection
pstmt = txn.prepareAutoCloseStatement(sql);
for (AccountVO acct : accounts) {
pstmt.setString(1, acct.getAccountName());
Date removed = acct.getRemoved();
if (removed == null) {
pstmt.setString(2, null);
} else {
pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), acct.getRemoved()));
}
pstmt.setLong(3, acct.getId());
pstmt.addBatch();
}
pstmt.executeBatch();
txn.commit();
} catch (Exception ex) {
txn.rollback();
s_logger.error("error saving account to cloud_usage db", ex);
throw new CloudRuntimeException(ex.getMessage());
}
}
Aggregations