Search in sources :

Example 1 with EventVO

use of com.cloud.event.EventVO in project cosmic by MissionCriticalCloud.

the class AffinityGroupServiceImplTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    acct = new AccountVO(200L);
    acct.setType(Account.ACCOUNT_TYPE_NORMAL);
    acct.setAccountName(ACCOUNT_NAME);
    acct.setDomainId(DOMAIN_ID);
    final UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, acct);
    when(_processor.getType()).thenReturn("mock");
    when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
    final List<AffinityGroupProcessor> affinityProcessors = new ArrayList<>();
    affinityProcessors.add(_processor);
    _affinityService.setAffinityGroupProcessors(affinityProcessors);
    final AffinityGroupVO group = new AffinityGroupVO(AFFINITY_GROUP_NAME, "mock", "mock group", DOMAIN_ID, 200L, ControlledEntity.ACLType.Account);
    Mockito.when(_affinityGroupDao.persist(Matchers.any(AffinityGroupVO.class))).thenReturn(group);
    Mockito.when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(group);
    Mockito.when(_affinityGroupDao.findByAccountAndName(Matchers.anyLong(), Matchers.anyString())).thenReturn(group);
    Mockito.when(_affinityGroupDao.lockRow(Matchers.anyLong(), anyBoolean())).thenReturn(group);
    Mockito.when(_affinityGroupDao.expunge(Matchers.anyLong())).thenReturn(true);
    Mockito.when(_eventDao.persist(Matchers.any(EventVO.class))).thenReturn(new EventVO());
}
Also used : UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) EventVO(com.cloud.event.EventVO) Before(org.junit.Before)

Example 2 with EventVO

use of com.cloud.event.EventVO in project cloudstack by apache.

the class Upgrade218to22 method migrateEvents.

private void migrateEvents(Connection conn) {
    try (PreparedStatement pstmt1 = conn.prepareStatement("SHOW DATABASES LIKE 'cloud_usage'");
        ResultSet rs1 = pstmt1.executeQuery()) {
        if (!rs1.next()) {
            s_logger.debug("cloud_usage db doesn't exist. Skipping events migration");
            return;
        }
        // get last processed event Id
        Long lastProcessedEvent = getMostRecentEvent(conn);
        // Events not yet processed
        String sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.id > ? and vmevt.state = 'Completed' ";
        if (lastProcessedEvent == null) {
            s_logger.trace("no events are processed earlier, copying all events");
            sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.state = 'Completed' ";
        }
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            int i = 1;
            if (lastProcessedEvent != null) {
                pstmt.setLong(i++, lastProcessedEvent);
            }
            try (ResultSet rs = pstmt.executeQuery()) {
                s_logger.debug("Begin Migrating events");
                while (rs.next()) {
                    EventVO event = new EventVO();
                    event.setType(rs.getString(1));
                    event.setDescription(rs.getString(2));
                    event.setUserId(rs.getLong(3));
                    event.setAccountId(rs.getLong(4));
                    event.setCreatedDate(DateUtil.parseDateString(TimeZone.getTimeZone("GMT"), rs.getString(5)));
                    event.setLevel(rs.getString(6));
                    event.setParameters(rs.getString(7));
                    convertEvent(event, conn);
                }
            }
        }
        s_logger.debug("Migrating events completed");
    } catch (Exception e) {
        throw new CloudRuntimeException("Failed to migrate usage events: ", e);
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) IOException(java.io.IOException) EventVO(com.cloud.event.EventVO) UsageEventVO(com.cloud.event.UsageEventVO)

Example 3 with EventVO

use of com.cloud.event.EventVO in project cloudstack by apache.

the class EventDaoImpl method archiveEvents.

@Override
public void archiveEvents(List<EventVO> events) {
    if (events != null && !events.isEmpty()) {
        TransactionLegacy txn = TransactionLegacy.currentTxn();
        txn.start();
        for (EventVO event : events) {
            event = lockRow(event.getId(), true);
            event.setArchived(true);
            update(event.getId(), event);
            txn.commit();
        }
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) EventVO(com.cloud.event.EventVO)

Example 4 with EventVO

use of com.cloud.event.EventVO in project cloudstack by apache.

the class AffinityGroupServiceImplTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    acct = new AccountVO(200L);
    acct.setType(Account.ACCOUNT_TYPE_NORMAL);
    acct.setAccountName(ACCOUNT_NAME);
    acct.setDomainId(DOMAIN_ID);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, acct);
    when(_processor.getType()).thenReturn("mock");
    when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
    List<AffinityGroupProcessor> affinityProcessors = new ArrayList<AffinityGroupProcessor>();
    affinityProcessors.add(_processor);
    _affinityService.setAffinityGroupProcessors(affinityProcessors);
    AffinityGroupVO group = new AffinityGroupVO(AFFINITY_GROUP_NAME, "mock", "mock group", DOMAIN_ID, 200L, ControlledEntity.ACLType.Account);
    Mockito.when(_affinityGroupDao.persist(Matchers.any(AffinityGroupVO.class))).thenReturn(group);
    Mockito.when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(group);
    Mockito.when(_affinityGroupDao.findByAccountAndName(Matchers.anyLong(), Matchers.anyString())).thenReturn(group);
    Mockito.when(_affinityGroupDao.lockRow(Matchers.anyLong(), anyBoolean())).thenReturn(group);
    Mockito.when(_affinityGroupDao.expunge(Matchers.anyLong())).thenReturn(true);
    Mockito.when(_eventDao.persist(Matchers.any(EventVO.class))).thenReturn(new EventVO());
}
Also used : UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) EventVO(com.cloud.event.EventVO) Before(org.junit.Before)

Example 5 with EventVO

use of com.cloud.event.EventVO in project cloudstack by apache.

the class AffinityApiUnitTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    AccountVO acct = new AccountVO(200L);
    acct.setType(Account.ACCOUNT_TYPE_NORMAL);
    acct.setAccountName("user");
    acct.setDomainId(domainId);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, acct);
    when(_acctMgr.finalizeOwner(any(Account.class), anyString(), anyLong(), nullable(Long.class))).thenReturn(acct);
    when(_processor.getType()).thenReturn("mock");
    when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
    List<AffinityGroupProcessor> affinityProcessors = new ArrayList<AffinityGroupProcessor>();
    affinityProcessors.add(_processor);
    _affinityService.setAffinityGroupProcessors(affinityProcessors);
    AffinityGroupVO group = new AffinityGroupVO("group1", "mock", "mock group", domainId, 200L, ControlledEntity.ACLType.Account);
    Mockito.when(_affinityGroupDao.persist(Matchers.any(AffinityGroupVO.class))).thenReturn(group);
    Mockito.when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(group);
    Mockito.when(_affinityGroupDao.findByAccountAndName(Matchers.anyLong(), Matchers.anyString())).thenReturn(group);
    Mockito.when(_affinityGroupDao.lockRow(Matchers.anyLong(), anyBoolean())).thenReturn(group);
    Mockito.when(_affinityGroupDao.expunge(Matchers.anyLong())).thenReturn(true);
    Mockito.when(_eventDao.persist(Matchers.any(EventVO.class))).thenReturn(new EventVO());
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) Matchers.anyLong(org.mockito.Matchers.anyLong) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) EventVO(com.cloud.event.EventVO) Before(org.junit.Before)

Aggregations

EventVO (com.cloud.event.EventVO)11 ArrayList (java.util.ArrayList)6 Account (com.cloud.user.Account)5 AccountVO (com.cloud.user.AccountVO)4 UserVO (com.cloud.user.UserVO)4 Before (org.junit.Before)4 ControlledEntity (com.cloud.acl.ControlledEntity)2 DomainVO (com.cloud.domain.DomainVO)2 NetworkDomainVO (com.cloud.network.dao.NetworkDomainVO)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 ControlledEntity (org.apache.cloudstack.acl.ControlledEntity)2 UsageEventVO (com.cloud.event.UsageEventVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1