Default and Specific config options in hazelcast with wildcards - hazelcast

I would like to be able to something like the following with a hazelcast config (in Scala):
.setMapConfigs(
Map(
"*Foo" → specificConfig
"*" → defaultConfig
)
)
So anything matching *Foo would get the specificConfig otherwise the default.
However, this doesn't seem to work and everything gets the default config including "*Foo" maps.
Is there a way to do this?

Hazelcast support wildcard for his configuration, in the name property.
See the documentation
In xml (but it's the same with a configuration in java/scala) :
<map name="default">
...
</map>
<map name="*Foo">
...
</map>

Related

How to limit logging for an external package when converting from log4j to log4j2... What is the correct properties file setting?

In log4j I have: "log4j.logger.org.apache.struts2=ERROR"
What is the equivalent properties file setting in log4j2?
The configuration of LoggerConfig elements in log4j2.properties uses the syntax:
logger.<id>.<property_name>=<property_value>
where <id> is any string identifier (used only to group the configuration of the same Logger, otherwise ignored), <property_name> is the Java bean property you want to set (cf. LoggerConfig javadoc and its setter methods).
Hence the equivalent Log4j 2.x configuration for the one in your question is:
logger.1.name=org.apache.struts2
logger.1.level=ERROR

HazelCast configuration generates a lot members

I'm trying to add hazelcast to my project. the configuration below generates a lot of members.
What I need is only tow.
Configuration
<hz:hazelcast id="instance">
<hz:config>
<hz:group name="mass-storage-${env}" password="tomcat-${env}"></hz:group>
<hz:properties>
<hz:property name="hazelcast.merge.first.run.delay.seconds">5</hz:property>
<hz:property name="hazelcast.merge.next.run.delay.seconds">5</hz:property>
</hz:properties>
<hz:network port="${hazelcast.config-cluster.discovery-port}" port-auto-increment="false">
<hz:join>
<hz:multicast enabled="false"/>
<hz:tcp-ip>
<hz:member>${hazelcast.config-cluster.address-1}</hz:member>
<hz:member>${hazelcast.config-cluster.address-2}</hz:member>
</hz:tcp-ip>
</hz:join>
</hz:network>
<hz:map name="driveAccessTokensCache">
<hz:near-cache time-to-live-seconds="${drive.access.token.ttl.seconds}" max-idle-seconds="10" eviction-policy="LRU" invalidate-on-change="true" max-size="5000"/>
</hz:map>
<hz:map name="accessTokensCache">
<hz:near-cache time-to-live-seconds="${user.access.token.ttl.seconds}" max-idle-seconds="10" eviction-policy="LRU" invalidate-on-change="true" max-size="5000"/>
</hz:map>
</hz:config>
</hz:hazelcast>
this is what i got :
Members [2] {
Member [ecarbsul1680h11]:18934 this
Member [ecarbsul1550h11]:18934
}
03-Jun-2020 17:16:17.657 INFO [hz._hzInstance_2_dev.ServiceThread] com.hazelcast.cluster.ClusterManager.null [10.30.197.120]:5701 [dev]
Members [6] {
Member [10.30.197.223]:18934
Member [10.30.197.223]:5701
Member [10.30.197.226]:18934
Member [10.30.197.226]:5701
Member [10.30.197.120]:5701 this
Member [10.30.197.253]:5701
}
this is what i want to get :
Members [2] {
Member [ecarbsul1680h11]:18934 this
Member [ecarbsul1550h11]:18934
}
Could you please help me to know what is wrong with my configuration ?
Thanks
This line in your XML
<hz:hazelcast id="instance">
would direct Spring to create 1 #Bean of type "HazelcastInstance" with bean name "instance".
IF this file was used, you would see log messages mentioning the cluster name mass-storage-${env}.
You have a log message
03-Jun-2020 17:16:17.657 INFO [hz._hzInstance_2_dev.ServiceThread] com.hazelcast.cluster.ClusterManager.null [10.30.197.120]:5701 [dev]
that mentions a different cluster name (the default cluster name of dev).
So whatever is creating your Hazelcast instances isn't using this XML file, which is why it's not behaving as you had requested.
Try using #ImportResource("classpath:hazelcast-spring.xml") to get Spring to load the XML.
I also see mention of Tomcat. If you're using Tomcat with Hazelcast for session caching, Tomcat will create it's own Hazelcast instance unless you tell it to use an existing one. That might explain where the extra instances are coming from.

Is there a way to set the minlevel of a NLog logger via a variable?

Using NLog v4.4.12, I have this in my App.config
<nlog>
<include file="..\Common\Logs\Variables.xml" />
<rules>
<logger name="*" minlevel="${logLevel}" writeTo="LogFile, Wcf"/>
</rules>
</nlog>
And here is my Variables.xml file content
<?xml version="1.0" encoding="utf-8"?>
<nlog autoReload="true">
<variable name="logLevel" value="Fatal" />
</nlog>
But I get an Exception when launching my app
Unknown log level: ${logLevel}
Am I doing something wrong or is it just impossible?
The goal of this is to eventually have an xml file per project that need to log things so each project can have his own minlevel and be able to change it at runtime via the edition of this xml.
Edit: Adding this code just before the Exception is thrown shows that my variable is there with the desired value.
var nl = NLog.LogManager.Configuration;
if (nl != null)
{
if (nl.Variables.ContainsKey("logLevel"))
{
Console.WriteLine(nl.Variables["logLevel"]);
}
}
** Updated Answer **
NLog ver. 4.6 added support for using NLog-Config-Variables in minLevel. See https://github.com/NLog/NLog/pull/2709
NLog ver. 4.6.7 added support for adjusting minLevel at runtime, by modifying NLog-Config-Variables and calling ReconfigExistingLoggers(). See https://github.com/NLog/NLog/pull/3184
** Original Answer **
Unfortunately you can't use layout renderers (the ${...}) in the <logger> attributes like minLevel, level, etc
There are two options:
Use filters
<logger name="*" writeTo="LogFile, Wcf">
<filters>
<when condition="(level < ${logLevel})" action="Ignore"/>
</filters>
</logger>
Downsides:
less readable
hurt performance more compared to the minLevel attribute
Change the rules in code
var rule = config.LoggingRules[0];
// disable old levels, enable new
rule.DisableLoggingForLevel(LogLevel.Debug);
rule.DisableLoggingForLevel(LogLevel.Trace);
rule.EnableLoggingForLevels(LogLevel.Info, LogLevel.Fatal);
//apply config
LogManager.Configuration = config;
I had my variables in a config file as part of a Service Fabric application, which would vary by environment, and wanted these to override the values in my Nlog.config file.
As per the user above, I came up against the same problem with loglevel when I wished to set a minimum level for it. Rather than hardcoding the levels in the code, I created a variable to retrieve the value from my config file, along the lines of what the original user had done:
var config = context.CodePackageActivationContext.GetConfigurationPackageObject("Config");
ILoggerFactory logger = new LoggerFactory().AddNLog();
var nlogConfigSection = config.Settings.Sections["MyService_NlogSettings"];
I set the variables that could be set, such as connection string etc. using the GlobalDiagnosticsContext, but obviously couldn't set the loglevel this way, due to its dislike of variables!
So instead, I did the following:
LogManager.Configuration.LoggingRules[0].SetLoggingLevels((NLog.LogLevel.FromString(nlogConfigSection.Parameters["AzureNLogLevel"].Value)),
NLog.LogLevel.FromString("Fatal"));
The 'SetloggingLevels' method expects values for Minlevel and MaxLevel of logging, hence my Config value was the min, and I hardcoded "Fatal" as the max since I was after a replication of 'minLevel' type logging, although obviously this too could have been set in my config file.

Combining configuration files

I'm developing a jee application which has to look at two files in order to load configuration parameters. Both files are properties-like files.
The first one contains a default configuration properties and the other one overrides them. So the first one is read-only and the other one can be modified. I need to react and update changes made on second configuration file.
I've take a look on several resources:
Composite Configuration
Combined Configuration
Combining Configuration Sources
I've not been able to figure out what and how to make configuration strategy with commons-configuration2.
Up to now, I've been able to read from one configuration file:
FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
.configure(new Parameters().properties()
.setFileName(ConfigurationResources.PROPERTIES_FILEPATH)
.setThrowExceptionOnMissing(true)
.setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
.setIncludesAllowed(false));
Any ideas?
You need CombinedConfiguration. Here is the sample code
Parameters params = new Parameters();
CombinedConfigurationBuilder builder = new CombinedConfigurationBuilder()
.configure(params.fileBased().setFile(new File("configuration.xml")));
CombinedConfiguration cc = builder.getConfiguration();
Here configuration.xml file would contain the list of property files
<configuration systemProperties="systemProperties.xml">
<!-- Load the system properties -->
<system/>
<!-- Now load the config file, using a system property as file name -->
<properties fileName="myprops1.properties"/>
<properties fileName="myprops2.propert"/>
</configuration>
This documentation on Combined Configuration will be really helpful
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> config1 = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
PropertiesConfiguration.class)
.configure(params.properties().setFileNamesetFileName("file1.properties")));
FileBasedConfigurationBuilder<FileBasedConfiguration> config2 = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
PropertiesConfiguration.class).configure(params.properties().setFileName("default_file2.properties"));
CombinedConfiguration config = new CombinedConfiguration(new OverrideCombiner());
config.addConfiguration(config1.getConfiguration());//this overrides config2
config.addConfiguration(config2.getConfiguration());
return config;
This is something I have used in my project to create a combined configuration. A combined configuration naturally creates a hierarchy of configurations taken from different or same source. For example you could also write something like : FileBasedConfigurationBuilder<FileBasedConfiguration> config2 = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class).configure(params.properties()‌​.setFileName(System.‌​getProperty("default‌​_file2.properties"))‌​);
The FileBasedConfigurationBuilder can be substituted with any kind of configuration you may like. Refer to the link https://commons.apache.org/proper/commons-configuration/apidocs/org/apache/commons/configuration2/builder/BasicConfigurationBuilder.html

IgniteConfiguration properties - do these properties still exist?

When porting from gridgain to ignite, I can't find matching properties for the following in IgniteConfiguration. Have they been totally purged or is there something else we should be using ?
<bean id="abstractGridConfiguration" abstract="true"
class="org.apache.ignite.configuration.IgniteConfiguration">
.......
<!--<property name="restEnabled" value="false"/>-->
<!--<property name="executorServiceShutdown" value="true"/>-->
<!--<property name="systemExecutorServiceShutdown" value="true"/>-->
To disable REST add this:
<property name="connectorConfiguration"><null/></property>
As for the thread pools, in Ignite you can only specify sizes (see IgniteConfiguration.setXxxThreadPoolSize() properties). Thus having shutdown flags doesn't make sense anymore.

Resources