/** * A factory method for {@link SampledCounterConfig} based on the global settings defined on this object * * @see #getSampleIntervalSeconds() * @see #getSampleHistorySize() * * @return a {@code SampledCounterConfig} */ public SampledRateCounterConfig makeSampledGetRateCounterConfig() { return new SampledRateCounterConfig(getSampleIntervalSeconds(), getSampleHistorySize(), true); }
private void assertManagementRESTServiceConfigurationIsCorrect(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService = configuration.getManagementRESTService(); if (managementRESTService == null || !managementRESTService.isEnabled()) { return; } String url = configuration.getTerracottaConfiguration() != null ? configuration.getTerracottaConfiguration().getUrl() : null; boolean connectingToSecureCluster = url != null && url.contains("@"); if (connectingToSecureCluster && !managementRESTService.isSslEnabled()) { throw new InvalidConfigurationException("The REST agent cannot be bound to a port when SSL is disabled and" + " connecting to a secure cluster. Change your configuration to" + " <ManagementRESTServiceConfiguration sslEnabled=\"true\" .../>" + " or remove the ManagementRESTServiceConfiguration element."); } if (connectingToSecureCluster && managementRESTService.getSecurityServiceLocation() == null) { managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); LOG.warn("The REST agent must have a non-null Security Service Location when SSL is enabled." + " Using ManagementRESTServiceConfiguration.AUTO_LOCATION as a connection to a secure cluster" + " is configured."); } if (managementRESTService.isSslEnabled() && managementRESTService.getSecurityServiceLocation() == null) { throw new InvalidConfigurationException("The REST agent must have a non-null Security Service Location when" + " SSL is enabled. Change your configuration to" + " <ManagementRESTServiceConfiguration securityServiceLocation=\"...\" .../>."); } }
if (!MGMT_SVR_BY_BIND.containsKey(managementRESTServiceConfiguration.getBind())) { if (!MGMT_SVR_BY_BIND.isEmpty()) { String alreadyBound = MGMT_SVR_BY_BIND.keySet().iterator().next(); managementRESTServiceConfiguration.setBind(alreadyBound); LOG.warn("You cannot have several Ehcache management rest agents running in the same ClassLoader; CacheManager " + cacheManager.getName() + " will be registered to the already running Ehcache management rest agent " + (ManagementRESTServiceConfiguration.NO_BIND.equals(managementRESTServiceConfiguration.getBind()) ? "reachable through the TSA agent" : "listening on port " + alreadyBound) + ", the configuration will not be changed for " + cacheManager.getName()); (ManagementRESTServiceConfiguration.NO_BIND.equals(managementRESTServiceConfiguration.getBind()) ? ", reachable through the TSA agent" : ", on port " + managementRESTServiceConfiguration.getBind()) + ", the configuration will not be changed for " + cacheManager.getName()); ManagementServerHolder managementServerHolder = MGMT_SVR_BY_BIND.get(managementRESTServiceConfiguration.getBind()); managementServerHolder.register(cacheManager, clientUUID); } catch (Exception e) {
private ManagementRESTServiceConfiguration getDefaultClusteredManagementRESTServiceConfiguration(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService; managementRESTService = new ManagementRESTServiceConfiguration(); String url = configuration.getTerracottaConfiguration().getUrl(); if (url != null && url.contains("@")) { managementRESTService.setSslEnabled(true); } managementRESTService.setEnabled(true); managementRESTService.setBind(ManagementRESTServiceConfiguration.NO_BIND); managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); return managementRESTService; }
/** * A factory method for {@link SampledCounterConfig} based on the global settings defined on this object * * @see #getSampleSearchIntervalSeconds() * @see #getSampleHistorySize() * * @return a {@code SampledCounterConfig} */ public SampledRateCounterConfig makeSampledSearchRateCounterConfig() { return new SampledRateCounterConfig(getSampleSearchIntervalSeconds(), getSampleHistorySize(), true); }
private void init() { if (managementRESTServiceConfiguration == null) { return; } addAttribute(new SimpleNodeAttribute("enabled", managementRESTServiceConfiguration.isEnabled()).defaultValue(false)); addAttribute(new SimpleNodeAttribute("bind", managementRESTServiceConfiguration.getBind()) .defaultValue(ManagementRESTServiceConfiguration.DEFAULT_BIND)); addAttribute(new SimpleNodeAttribute("securityServiceLocation", managementRESTServiceConfiguration .getSecurityServiceLocation()).optional(true)); addAttribute(new SimpleNodeAttribute("securityServiceTimeout", managementRESTServiceConfiguration .getSecurityServiceTimeout()).optional(true) .defaultValue(ManagementRESTServiceConfiguration.DEFAULT_SECURITY_SVC_TIMEOUT)); addAttribute(new SimpleNodeAttribute("sslEnabled", managementRESTServiceConfiguration.isSslEnabled()) .optional(true).defaultValue(false)); addAttribute(new SimpleNodeAttribute("needClientAuth", managementRESTServiceConfiguration.isNeedClientAuth()) .optional(true).defaultValue(false)); addAttribute(new SimpleNodeAttribute("sampleHistorySize", managementRESTServiceConfiguration.getSampleHistorySize()) .optional(true).defaultValue(StatisticsGateway.DEFAULT_HISTORY_SIZE)); addAttribute(new SimpleNodeAttribute("sampleIntervalSeconds", managementRESTServiceConfiguration .getSampleIntervalSeconds()).optional(true).defaultValue(StatisticsGateway.DEFAULT_INTERVAL_SECS)); addAttribute(new SimpleNodeAttribute("sampleSearchIntervalSeconds", managementRESTServiceConfiguration .getSampleSearchIntervalSeconds()).optional(true).defaultValue(StatisticsGateway.DEFAULT_SEARCH_INTERVAL_SECS)); } }
private AgentMetadataEntity buildAgentMetadata() { AgentMetadataEntity ame = new AgentMetadataEntity(); ame.setAgentId(AgentEntity.EMBEDDED_AGENT_ID); ame.setAgencyOf(AGENCY); ame.setVersion(this.getClass().getPackage().getImplementationVersion()); ame.setRestAPIVersion("v1"); ame.setAvailable(true); if (isTsaBridged()) { ame.setSecured(isTsaSecured()); ame.setSslEnabled(isTsaSecured()); ame.setNeedClientAuth(false); } else { ame.setSecured(Utils.trimToNull(configuration.getSecurityServiceLocation()) != null); ame.setSslEnabled(Utils.trimToNull(configuration.getSecurityServiceLocation()) != null); ame.setNeedClientAuth(configuration.isNeedClientAuth()); } ame.setLicensed(ServiceLocator.locate(LicenseService.class).isLicensed()); ame.setSampleHistorySize(configuration.getSampleHistorySize()); ame.setSampleIntervalSeconds(configuration.getSampleIntervalSeconds()); ame.setEnabled(configuration.isEnabled()); return ame; }
/** * {@inheritDoc} */ public void setSampledStatisticsEnabled(final boolean enableStatistics) { if (cacheManager == null) { throw new IllegalStateException("You must add the cache to a CacheManager before enabling/disabling sampled statistics."); } boolean oldValue = isSampledStatisticsEnabled(); if (oldValue != enableStatistics) { if (enableStatistics) { ManagementRESTServiceConfiguration mgmtRESTConfigSvc = cacheManager.getConfiguration().getManagementRESTService(); if (mgmtRESTConfigSvc != null && mgmtRESTConfigSvc.isEnabled()) { sampledCacheStatistics.enableSampledStatistics(cacheManager.getTimer(), mgmtRESTConfigSvc.makeSampledCounterConfig(), mgmtRESTConfigSvc.makeSampledGetRateCounterConfig(), mgmtRESTConfigSvc.makeSampledSearchRateCounterConfig()); } else { sampledCacheStatistics.enableSampledStatistics(cacheManager.getTimer()); } setStatisticsEnabled(true); } else { sampledCacheStatistics.disableSampledStatistics(); } firePropertyChange("SampledStatisticsEnabled", oldValue, enableStatistics); } }
void start(ManagementRESTServiceConfiguration managementRESTServiceConfiguration) throws Exception { Method initializeMethod = MANAGEMENT_SERVER_CLASS.getMethod("initialize", ManagementRESTServiceConfiguration.class); initializeMethod.invoke(managementServer, managementRESTServiceConfiguration); Method startMethod = MANAGEMENT_SERVER_CLASS.getMethod("start"); startMethod.invoke(managementServer); MGMT_SVR_BY_BIND.put(managementRESTServiceConfiguration.getBind(), this); }
private int getProperSampleHistorySize(ManagementRESTServiceConfiguration mRest) { return mRest == null ? StatisticsGateway.DEFAULT_HISTORY_SIZE : mRest.getSampleHistorySize(); }
private int getProperSampleIntervalSeconds(ManagementRESTServiceConfiguration mRest) { return mRest == null ? StatisticsGateway.DEFAULT_INTERVAL_SECS : mRest.getSampleIntervalSeconds(); }
managementRESTService = getDefaultClusteredManagementRESTServiceConfiguration(configuration); if (managementRESTService != null && managementRESTService.isEnabled()) { initializeManagementService(managementRESTService);
private int getProperSampleSearchIntervalSeconds(ManagementRESTServiceConfiguration mRest) { return mRest == null ? StatisticsGateway.DEFAULT_SEARCH_INTERVAL_SECS : mRest.getSampleSearchIntervalSeconds(); }
private void init() { if (managementRESTServiceConfiguration == null) { return; } addAttribute(new SimpleNodeAttribute("enabled", managementRESTServiceConfiguration.isEnabled()).defaultValue(false)); addAttribute(new SimpleNodeAttribute("bind", managementRESTServiceConfiguration.getBind()) .defaultValue(ManagementRESTServiceConfiguration.DEFAULT_BIND)); addAttribute(new SimpleNodeAttribute("securityServiceLocation", managementRESTServiceConfiguration .getSecurityServiceLocation()).optional(true)); addAttribute(new SimpleNodeAttribute("securityServiceTimeout", managementRESTServiceConfiguration .getSecurityServiceTimeout()).optional(true) .defaultValue(ManagementRESTServiceConfiguration.DEFAULT_SECURITY_SVC_TIMEOUT)); addAttribute(new SimpleNodeAttribute("sslEnabled", managementRESTServiceConfiguration.isSslEnabled()) .optional(true).defaultValue(false)); addAttribute(new SimpleNodeAttribute("needClientAuth", managementRESTServiceConfiguration.isNeedClientAuth()) .optional(true).defaultValue(false)); addAttribute(new SimpleNodeAttribute("sampleHistorySize", managementRESTServiceConfiguration.getSampleHistorySize()) .optional(true).defaultValue(CacheStatisticsSampler.DEFAULT_HISTORY_SIZE)); addAttribute(new SimpleNodeAttribute("sampleIntervalSeconds", managementRESTServiceConfiguration .getSampleIntervalSeconds()).optional(true).defaultValue(CacheStatisticsSampler.DEFAULT_INTERVAL_SECS)); addAttribute(new SimpleNodeAttribute("sampleSearchIntervalSeconds", managementRESTServiceConfiguration .getSampleSearchIntervalSeconds()).optional(true).defaultValue(CacheStatisticsSampler.DEFAULT_SEARCH_INTERVAL_SEC)); } }
private ManagementRESTServiceConfiguration getDefaultClusteredManagementRESTServiceConfiguration(Configuration configuration) { ManagementRESTServiceConfiguration managementRESTService; managementRESTService = new ManagementRESTServiceConfiguration(); String url = configuration.getTerracottaConfiguration().getUrl(); if (url != null && url.contains("@")) { managementRESTService.setSslEnabled(true); } managementRESTService.setEnabled(true); managementRESTService.setBind(ManagementRESTServiceConfiguration.NO_BIND); managementRESTService.setSecurityServiceLocation(ManagementRESTServiceConfiguration.AUTO_LOCATION); return managementRESTService; }
/** * A factory method for {@link SampledCounterConfig} based on the global settings defined on this object * * @see #getSampleSearchIntervalSeconds() * @see #getSampleHistorySize() * * @return a {@code SampledCounterConfig} */ public SampledRateCounterConfig makeSampledSearchRateCounterConfig() { return new SampledRateCounterConfig(getSampleSearchIntervalSeconds(), getSampleHistorySize(), true); }
private void initializeManagementService(ManagementRESTServiceConfiguration managementRESTService) { /** * ManagementServer will only be instantiated and started if one isn't already running on the configured port for this class * loader space. */ synchronized (CacheManager.class) { ClusteredInstanceFactory clusteredInstanceFactory = terracottaClient.getClusteredInstanceFactory(); String clientUUID = clusteredInstanceFactory == null ? null : clusteredInstanceFactory.getUUID(); ManagementServerLoader.register(this, clientUUID, managementRESTService); registeredMgmtSvrBind = managementRESTService.getBind(); } }
private int getProperSampleHistorySize(ManagementRESTServiceConfiguration mRest) { return mRest == null ? StatisticsGateway.DEFAULT_HISTORY_SIZE : mRest.getSampleHistorySize(); }
private int getProperSampleIntervalSeconds(ManagementRESTServiceConfiguration mRest) { return mRest == null ? StatisticsGateway.DEFAULT_INTERVAL_SECS : mRest.getSampleIntervalSeconds(); }