Search in sources :

Example 31 with AccountVO

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;
    }
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AccountVO(com.cloud.user.AccountVO) ActionEvent(com.cloud.event.ActionEvent)

Example 32 with AccountVO

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);
}
Also used : BridgePort(org.midonet.client.resource.BridgePort) RouterPort(org.midonet.client.resource.RouterPort) BridgePort(org.midonet.client.resource.BridgePort) Port(org.midonet.client.resource.Port) Router(org.midonet.client.resource.Router) AccountDao(com.cloud.user.dao.AccountDao) AccountVO(com.cloud.user.AccountVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) MidonetApi(org.midonet.client.MidonetApi) Network(com.cloud.network.Network) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UUID(java.util.UUID) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) RouterPort(org.midonet.client.resource.RouterPort) Bridge(org.midonet.client.resource.Bridge) ResourceCollection(org.midonet.client.resource.ResourceCollection)

Example 33 with AccountVO

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);
}
Also used : AccountVO(com.cloud.user.AccountVO)

Example 34 with AccountVO

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);
    }
}
Also used : AsyncJobJoinMapVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO) Method(java.lang.reflect.Method) AccountVO(com.cloud.user.AccountVO) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 35 with AccountVO

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());
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement) AccountVO(com.cloud.user.AccountVO) Date(java.util.Date) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

AccountVO (com.cloud.user.AccountVO)139 Account (com.cloud.user.Account)65 Test (org.junit.Test)52 UserVO (com.cloud.user.UserVO)44 Field (java.lang.reflect.Field)41 ArrayList (java.util.ArrayList)40 DomainVO (com.cloud.domain.DomainVO)32 AccountManager (com.cloud.user.AccountManager)27 Before (org.junit.Before)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)21 Date (java.util.Date)16 QuotaAccountVO (org.apache.cloudstack.quota.vo.QuotaAccountVO)16 DomainDao (com.cloud.domain.dao.DomainDao)14 SslCertDao (com.cloud.network.dao.SslCertDao)14 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)13 NetworkDao (com.cloud.network.dao.NetworkDao)13 NetworkVO (com.cloud.network.dao.NetworkVO)13