Search in sources :

Example 1 with EngineLocalConfig

use of org.ovirt.engine.core.utils.EngineLocalConfig in project ovirt-engine by oVirt.

the class DashboardDataServlet method initCache.

@PostConstruct
private void initCache() {
    dashboardCache = cacheContainer.getCache(DASHBOARD);
    inventoryCache = cacheContainer.getCache(INVENTORY);
    dwhAvailable = checkDwhConfigInEngine() && checkDwhDataSource();
    EngineLocalConfig config = EngineLocalConfig.getInstance();
    try {
        enableBackgroundCacheUpdate = config.getBoolean(ENABLE_CACHE_UPDATE_KEY, Boolean.FALSE);
    } catch (IllegalArgumentException e) {
        // $NON-NLS-1$
        log.error("Missing/Invalid key \"{}\", using default value of 'false'", ENABLE_CACHE_UPDATE_KEY, e);
        enableBackgroundCacheUpdate = false;
    }
    if (!enableBackgroundCacheUpdate || !dwhAvailable) {
        // $NON-NLS-1$
        log.info("Dashboard DB query cache has been disabled.");
        return;
    }
    /*
         * Update the utilization cache now and every 5 minutes (by default) thereafter, but never run 2 updates simultaneously.
         */
    try {
        UTILIZATION_CACHE_UPDATE_INTERVAL = config.getLong(UTILIZATION_CACHE_UPDATE_INTERVAL_KEY);
    } catch (IllegalArgumentException e) {
        // $NON-NLS-1$
        log.error("Missing/Invalid key \"{}\", using default value of 300", UTILIZATION_CACHE_UPDATE_INTERVAL_KEY, e);
        UTILIZATION_CACHE_UPDATE_INTERVAL = 300;
    }
    utilizationCacheUpdate = scheduledExecutor.scheduleWithFixedDelay(new Runnable() {

        // $NON-NLS-1$
        Logger log = LoggerFactory.getLogger(DashboardDataServlet.class.getName() + ".CacheUpdate.Utilization");

        @Override
        public void run() {
            // $NON-NLS-1$
            log.trace("Attempting to update the Utilization cache");
            try {
                populateUtilizationCache();
            } catch (DashboardDataException e) {
                // $NON-NLS-1$
                log.error("Could not update the Utilization Cache: {}", e.getMessage(), e);
            }
        }
    }, 0, UTILIZATION_CACHE_UPDATE_INTERVAL, TimeUnit.SECONDS);
    // $NON-NLS-1$
    log.info("Dashboard utilization cache updater initialized (update interval {}s)", UTILIZATION_CACHE_UPDATE_INTERVAL);
    /*
         * Update the inventory cache now and every 60 seconds (by default) thereafter, but never run 2 updates simultaneously.
         */
    try {
        INVENTORY_CACHE_UPDATE_INTERVAL = config.getLong(INVENTORY_CACHE_UPDATE_INTERVAL_KEY);
    } catch (IllegalArgumentException e) {
        // $NON-NLS-1$
        log.error("Missing/Invalid key \"{}\", using default value of 60", INVENTORY_CACHE_UPDATE_INTERVAL_KEY, e);
        INVENTORY_CACHE_UPDATE_INTERVAL = 60;
    }
    inventoryCacheUpdate = scheduledExecutor.scheduleWithFixedDelay(new Runnable() {

        // $NON-NLS-1$
        Logger log = LoggerFactory.getLogger(DashboardDataServlet.class.getName() + ".CacheUpdate.Inventory");

        @Override
        public void run() {
            // $NON-NLS-1$
            log.trace("Attempting to update the Inventory cache");
            try {
                populateInventoryCache();
            } catch (DashboardDataException e) {
                // $NON-NLS-1$
                log.error("Could not update the Inventory Cache: {}", e.getMessage(), e);
            }
        }
    }, 0, INVENTORY_CACHE_UPDATE_INTERVAL, TimeUnit.SECONDS);
    // $NON-NLS-1$
    log.info("Dashboard inventory cache updater initialized (update interval {}s)", INVENTORY_CACHE_UPDATE_INTERVAL);
}
Also used : Logger(org.slf4j.Logger) EngineLocalConfig(org.ovirt.engine.core.utils.EngineLocalConfig) PostConstruct(javax.annotation.PostConstruct)

Example 2 with EngineLocalConfig

use of org.ovirt.engine.core.utils.EngineLocalConfig in project ovirt-engine by oVirt.

the class ForwardServlet method init.

@Override
public void init(final ServletConfig config) throws ServletException {
    // Let the parent do its work:
    super.init(config);
    targetContext = config.getInitParameter(CONTEXT_PARAM);
    if (targetContext == null) {
        // $NON-NLS-1$
        throw new ServletException("Target context not defined in web.xml");
    }
    uri = config.getInitParameter(URI_PARAM);
    if (uri == null) {
        // $NON-NLS-1$
        throw new ServletException("Target URI not defined in web.xml");
    }
    // we use %{x} convention to avoid conflict with jboss properties
    EngineLocalConfig engineLocalConfig = EngineLocalConfig.getInstance();
    targetContext = ServletUtils.getAsAbsoluteContext(getServletContext().getContextPath(), engineLocalConfig.expandString(targetContext.replaceAll("%\\{", "\\${")));
    uri = engineLocalConfig.expandString(uri.replaceAll("%\\{", "\\${"));
}
Also used : ServletException(javax.servlet.ServletException) EngineLocalConfig(org.ovirt.engine.core.utils.EngineLocalConfig)

Example 3 with EngineLocalConfig

use of org.ovirt.engine.core.utils.EngineLocalConfig in project ovirt-engine by oVirt.

the class SsoOAuthServiceUtils method createPost.

private static HttpPost createPost(String path) throws Exception {
    EngineLocalConfig config = EngineLocalConfig.getInstance();
    String base = config.getProperty("ENGINE_SSO_SERVICE_URL");
    HttpPost request = new HttpPost();
    request.setURI(new URI(base + path));
    request.setHeader("Accept", "application/json");
    request.setHeader("Content-Language", "en-US");
    return request;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) URI(java.net.URI) EngineLocalConfig(org.ovirt.engine.core.utils.EngineLocalConfig)

Example 4 with EngineLocalConfig

use of org.ovirt.engine.core.utils.EngineLocalConfig in project ovirt-engine by oVirt.

the class SsoOAuthServiceUtils method createGet.

private static HttpGet createGet(String path) throws Exception {
    EngineLocalConfig config = EngineLocalConfig.getInstance();
    String base = config.getProperty("ENGINE_SSO_SERVICE_URL");
    HttpGet request = new HttpGet();
    request.setURI(new URI(base + path));
    request.setHeader("Accept", "application/json");
    return request;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) URI(java.net.URI) EngineLocalConfig(org.ovirt.engine.core.utils.EngineLocalConfig)

Example 5 with EngineLocalConfig

use of org.ovirt.engine.core.utils.EngineLocalConfig in project ovirt-engine by oVirt.

the class DbFacadeLocator method loadDbFacadeConfig.

private void loadDbFacadeConfig() {
    final EngineLocalConfig config = EngineLocalConfig.getInstance();
    try {
        connectionTimeout = config.getInteger("ENGINE_DB_CONNECTION_TIMEOUT");
        checkInterval = config.getInteger("ENGINE_DB_CHECK_INTERVAL");
    } catch (Exception exception) {
        log.warn("Can't load connection checking parameters of DB facade, " + "will continue using the default values. Error: {}", exception.getMessage());
        log.debug("Exception", exception);
    }
}
Also used : IOException(java.io.IOException) EngineLocalConfig(org.ovirt.engine.core.utils.EngineLocalConfig)

Aggregations

EngineLocalConfig (org.ovirt.engine.core.utils.EngineLocalConfig)9 URI (java.net.URI)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 PostConstruct (javax.annotation.PostConstruct)1 ServletException (javax.servlet.ServletException)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPost (org.apache.http.client.methods.HttpPost)1 Logger (org.slf4j.Logger)1