Search in sources :

Example 1 with NamedThreadFactory

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

the class MockAgentManagerImpl method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    try {
        random = SecureRandom.getInstance("SHA1PRNG");
        _executor = new ThreadPoolExecutor(1, 5, 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("Simulator-Agent-Mgr"));
    } catch (NoSuchAlgorithmException e) {
        s_logger.debug("Failed to initialize random:" + e.toString());
        return false;
    }
    return true;
}
Also used : NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 2 with NamedThreadFactory

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

the class ClientTransportProvider method initialize.

public void initialize(String serverAddress, int serverPort) {
    _serverAddress = serverAddress;
    _serverPort = serverPort;
    _executor = Executors.newFixedThreadPool(_poolSize, new NamedThreadFactory("Transport-Worker"));
    _connection = new ClientTransportConnection(this);
    _executor.execute(new ManagedContextRunnable() {

        @Override
        protected void runInContext() {
            try {
                _connection.connect(_serverAddress, _serverPort);
            } catch (Throwable e) {
                s_logger.info("[ignored]" + "error during ipc client initialization: " + e.getLocalizedMessage());
            }
        }
    });
}
Also used : ManagedContextRunnable(org.apache.cloudstack.managed.context.ManagedContextRunnable) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory)

Example 3 with NamedThreadFactory

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

the class TemplateManagerImplTest method testTemplateScheduledForDownloadInDisabledPool.

@Test
public void testTemplateScheduledForDownloadInDisabledPool() {
    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.Disabled);
    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 not scheduled for seeding on disabled pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 0);
}
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 4 with NamedThreadFactory

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

the class NioConnection method start.

public void start() throws NioConnectionException {
    _todos = new ArrayList<ChangeRequest>();
    try {
        init();
    } catch (final ConnectException e) {
        s_logger.warn("Unable to connect to remote: is there a server running on port " + _port);
        return;
    } catch (final IOException e) {
        s_logger.error("Unable to initialize the threads.", e);
        throw new NioConnectionException(e.getMessage(), e);
    } catch (final Exception e) {
        s_logger.error("Unable to initialize the threads due to unknown exception.", e);
        throw new NioConnectionException(e.getMessage(), e);
    }
    _isStartup = true;
    _threadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory(this._name + "-NioConnectionHandler"));
    _isRunning = true;
    _futureTask = _threadExecutor.submit(this);
}
Also used : NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) IOException(java.io.IOException) NioConnectionException(com.cloud.utils.exception.NioConnectionException) CancelledKeyException(java.nio.channels.CancelledKeyException) ConnectException(java.net.ConnectException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) NioConnectionException(com.cloud.utils.exception.NioConnectionException) ClosedSelectorException(java.nio.channels.ClosedSelectorException) ConnectException(java.net.ConnectException)

Example 5 with NamedThreadFactory

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

the class UploadMonitorImpl method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    final Map<String, String> configs = _configDao.getConfiguration("management-server", params);
    _sslCopy = Boolean.parseBoolean(configs.get("secstorage.encrypt.copy"));
    String cert = configs.get("secstorage.secure.copy.cert");
    if ("realhostip.com".equalsIgnoreCase(cert)) {
        s_logger.warn("Only realhostip.com ssl cert is supported, ignoring self-signed and other certs");
    }
    _ssvmUrlDomain = configs.get("secstorage.ssl.cert.domain");
    _agentMgr.registerForHostEvents(new UploadListener(this), true, false, false);
    String cleanupInterval = configs.get("extract.url.cleanup.interval");
    _cleanupInterval = NumbersUtil.parseInt(cleanupInterval, 7200);
    String urlExpirationInterval = configs.get("extract.url.expiration.interval");
    _urlExpirationInterval = NumbersUtil.parseInt(urlExpirationInterval, 14400);
    String workers = (String) params.get("expunge.workers");
    int wrks = NumbersUtil.parseInt(workers, 1);
    _executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("UploadMonitor-Scavenger"));
    return true;
}
Also used : NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)

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