Search in sources :

Example 11 with NamedThreadFactory

use of com.cloud.utils.concurrency.NamedThreadFactory in project cloudstack by apache.

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInMultiplePool.

@Test
public void testTemplateScheduledForDownloadInMultiplePool() {
    VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
    StoragePoolVO mockPool1 = mock(StoragePoolVO.class);
    when(mockPool1.getId()).thenReturn(2l);
    when(mockPool1.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool1.getDataCenterId()).thenReturn(1l);
    StoragePoolVO mockPool2 = mock(StoragePoolVO.class);
    when(mockPool2.getId()).thenReturn(3l);
    when(mockPool2.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool2.getDataCenterId()).thenReturn(1l);
    StoragePoolVO mockPool3 = mock(StoragePoolVO.class);
    when(mockPool3.getId()).thenReturn(4l);
    when(mockPool3.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool3.getDataCenterId()).thenReturn(2l);
    pools.add(mockPool1);
    pools.add(mockPool2);
    pools.add(mockPool3);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockTemplate.getId()).thenReturn(202l);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
    when(primaryDataStoreDao.findById(2l)).thenReturn(mockPool1);
    when(primaryDataStoreDao.findById(3l)).thenReturn(mockPool2);
    when(primaryDataStoreDao.findById(4l)).thenReturn(mockPool3);
    when(primaryDataStoreDao.listByStatus(StoragePoolStatus.Up)).thenReturn(pools);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
    templateManager._preloadExecutor = preloadExecutor;
    templateManager.prepareTemplate(202, 1, null);
    assertTrue("Test template is scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 2);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 12 with NamedThreadFactory

use of com.cloud.utils.concurrency.NamedThreadFactory in project cloudstack by apache.

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInOnePool.

@Test
public void testTemplateScheduledForDownloadInOnePool() {
    VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    StoragePoolVO mockPool = mock(StoragePoolVO.class);
    PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    when(mockPrimaryDataStore.getId()).thenReturn(2l);
    when(mockPool.getId()).thenReturn(2l);
    when(mockPool.getStatus()).thenReturn(StoragePoolStatus.Up);
    when(mockPool.getDataCenterId()).thenReturn(1l);
    when(mockTemplate.getId()).thenReturn(202l);
    when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
    when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
    when(primaryDataStoreDao.findById(anyLong())).thenReturn(mockPool);
    doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
    templateManager._preloadExecutor = preloadExecutor;
    templateManager.prepareTemplate(202, 1, 2l);
    assertTrue("Test template is scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 1);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) Test(org.junit.Test)

Example 13 with NamedThreadFactory

use of com.cloud.utils.concurrency.NamedThreadFactory in project cloudstack by apache.

the class VmwareContextPoolTest method testMultithreadedPoolClients.

@Test
public void testMultithreadedPoolClients() throws Exception {
    vmwareContextPool = Mockito.spy(vmwareContextPool);
    final ExecutorService executor = Executors.newFixedThreadPool(10, new NamedThreadFactory("VmwareContextPoolClients"));
    final List<PoolClient> clients = new ArrayList<>();
    for (int i = 0; i < 50; i++) {
        final PoolClient client = new PoolClient(vmwareContextPool);
        clients.add(client);
        executor.submit(client);
    }
    Thread.sleep(1000);
    executor.shutdown();
    int totalRegistrations = 0;
    for (final PoolClient client : clients) {
        client.stop();
        totalRegistrations += client.count();
    }
    Mockito.verify(vmwareContextPool, Mockito.atLeast(totalRegistrations)).registerContext(Mockito.any(VmwareContext.class));
}
Also used : NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with NamedThreadFactory

use of com.cloud.utils.concurrency.NamedThreadFactory in project cloudstack by apache.

the class StorageManagerImpl method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    Map<String, String> configs = _configDao.getConfiguration("management-server", params);
    _storagePoolAcquisitionWaitSeconds = NumbersUtil.parseInt(configs.get("pool.acquisition.wait.seconds"), 1800);
    s_logger.info("pool.acquisition.wait.seconds is configured as " + _storagePoolAcquisitionWaitSeconds + " seconds");
    _agentMgr.registerForHostEvents(new StoragePoolMonitor(this, _storagePoolDao, _dataStoreProviderMgr), true, false, true);
    String value = _configDao.getValue(Config.StorageTemplateCleanupEnabled.key());
    _templateCleanupEnabled = (value == null ? true : Boolean.parseBoolean(value));
    s_logger.info("Storage cleanup enabled: " + StorageCleanupEnabled.value() + ", interval: " + StorageCleanupInterval.value() + ", delay: " + StorageCleanupDelay.value() + ", template cleanup enabled: " + _templateCleanupEnabled);
    String cleanupInterval = configs.get("extract.url.cleanup.interval");
    _downloadUrlCleanupInterval = NumbersUtil.parseInt(cleanupInterval, 7200);
    String urlExpirationInterval = configs.get("extract.url.expiration.interval");
    _downloadUrlExpirationInterval = NumbersUtil.parseInt(urlExpirationInterval, 14400);
    String workers = configs.get("expunge.workers");
    int wrks = NumbersUtil.parseInt(workers, 10);
    _executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("StorageManager-Scavenger"));
    _agentMgr.registerForHostEvents(ComponentContext.inject(LocalStoragePoolListener.class), true, false, false);
    _serverId = _msServer.getId();
    UpHostsInPoolSearch = _storagePoolHostDao.createSearchBuilder(Long.class);
    UpHostsInPoolSearch.selectFields(UpHostsInPoolSearch.entity().getHostId());
    SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder();
    hostSearch.and("status", hostSearch.entity().getStatus(), Op.EQ);
    hostSearch.and("resourceState", hostSearch.entity().getResourceState(), Op.EQ);
    UpHostsInPoolSearch.join("hosts", hostSearch, hostSearch.entity().getId(), UpHostsInPoolSearch.entity().getHostId(), JoinType.INNER);
    UpHostsInPoolSearch.and("pool", UpHostsInPoolSearch.entity().getPoolId(), Op.EQ);
    UpHostsInPoolSearch.done();
    StoragePoolSearch = _vmInstanceDao.createSearchBuilder();
    SearchBuilder<VolumeVO> volumeSearch = _volumeDao.createSearchBuilder();
    volumeSearch.and("volumeType", volumeSearch.entity().getVolumeType(), SearchCriteria.Op.EQ);
    volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
    volumeSearch.and("state", volumeSearch.entity().getState(), SearchCriteria.Op.EQ);
    StoragePoolSearch.join("vmVolume", volumeSearch, volumeSearch.entity().getInstanceId(), StoragePoolSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    StoragePoolSearch.done();
    LocalStorageSearch = _storagePoolDao.createSearchBuilder();
    SearchBuilder<StoragePoolHostVO> storageHostSearch = _storagePoolHostDao.createSearchBuilder();
    storageHostSearch.and("hostId", storageHostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
    LocalStorageSearch.join("poolHost", storageHostSearch, storageHostSearch.entity().getPoolId(), LocalStorageSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    LocalStorageSearch.and("type", LocalStorageSearch.entity().getPoolType(), SearchCriteria.Op.IN);
    LocalStorageSearch.done();
    Volume.State.getStateMachine().registerListener(new VolumeStateListener(_configDao, _vmInstanceDao));
    return true;
}
Also used : NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) VolumeStateListener(com.cloud.storage.listener.VolumeStateListener) StoragePoolMonitor(com.cloud.storage.listener.StoragePoolMonitor)

Example 15 with NamedThreadFactory

use of com.cloud.utils.concurrency.NamedThreadFactory in project cloudstack by apache.

the class AsyncJobManagerImpl method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    try {
        final Properties dbProps = DbProperties.getDbProperties();
        final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive"));
        int apiPoolSize = cloudMaxActive / 2;
        int workPoolSize = (cloudMaxActive * 2) / 3;
        s_logger.info("Start AsyncJobManager API executor thread pool in size " + apiPoolSize);
        _apiJobExecutor = Executors.newFixedThreadPool(apiPoolSize, new NamedThreadFactory(AsyncJobManager.API_JOB_POOL_THREAD_PREFIX));
        s_logger.info("Start AsyncJobManager Work executor thread pool in size " + workPoolSize);
        _workerJobExecutor = Executors.newFixedThreadPool(workPoolSize, new NamedThreadFactory(AsyncJobManager.WORK_JOB_POOL_THREAD_PREFIX));
    } catch (final Exception e) {
        throw new ConfigurationException("Unable to load db.properties to configure AsyncJobManagerImpl");
    }
    JoinJobSearch = _joinMapDao.createSearchBuilder(Long.class);
    JoinJobSearch.and(JoinJobSearch.entity().getJoinJobId(), Op.EQ, "joinJobId");
    JoinJobSearch.selectFields(JoinJobSearch.entity().getJobId());
    JoinJobSearch.done();
    JoinJobTimeSearch = _joinMapDao.createSearchBuilder(Long.class);
    JoinJobTimeSearch.and(JoinJobTimeSearch.entity().getNextWakeupTime(), Op.LT, "beginTime");
    JoinJobTimeSearch.and(JoinJobTimeSearch.entity().getExpiration(), Op.GT, "endTime");
    JoinJobTimeSearch.selectFields(JoinJobTimeSearch.entity().getJobId()).done();
    JobIdsSearch = _jobDao.createSearchBuilder();
    JobIdsSearch.and(JobIdsSearch.entity().getId(), Op.IN, "ids").done();
    QueueJobIdsSearch = _queueItemDao.createSearchBuilder();
    QueueJobIdsSearch.and(QueueJobIdsSearch.entity().getContentId(), Op.IN, "contentIds").done();
    JoinJobIdsSearch = _joinMapDao.createSearchBuilder(Long.class);
    JoinJobIdsSearch.selectFields(JoinJobIdsSearch.entity().getJobId());
    JoinJobIdsSearch.and(JoinJobIdsSearch.entity().getJoinJobId(), Op.EQ, "joinJobId");
    JoinJobIdsSearch.and(JoinJobIdsSearch.entity().getJobId(), Op.NIN, "jobIds");
    JoinJobIdsSearch.done();
    ContentIdsSearch = _queueItemDao.createSearchBuilder(Long.class);
    ContentIdsSearch.selectFields(ContentIdsSearch.entity().getContentId()).done();
    AsyncJobExecutionContext.init(this, _joinMapDao);
    OutcomeImpl.init(this);
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) Properties(java.util.Properties) DbProperties(com.cloud.utils.db.DbProperties) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

NamedThreadFactory (com.cloud.utils.concurrency.NamedThreadFactory)16 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)6 VMTemplateVO (com.cloud.storage.VMTemplateVO)4 ExecutorService (java.util.concurrent.ExecutorService)4 Test (org.junit.Test)4 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 ConfigurationException (javax.naming.ConfigurationException)3 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)3 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)3 ArrayList (java.util.ArrayList)2 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)2 PodVlanMapVO (com.cloud.dc.PodVlanMapVO)1 VlanVO (com.cloud.dc.VlanVO)1 HostVO (com.cloud.host.HostVO)1 Network (com.cloud.network.Network)1 Capability (com.cloud.network.Network.Capability)1 Provider (com.cloud.network.Network.Provider)1 Service (com.cloud.network.Network.Service)1 NetworkStateListener (com.cloud.network.NetworkStateListener)1