Does someone knows a way to export a hazelcast config to a file?
I know for importing it, there are following ways:
hazelcast.config system property
hazelcast.xml file in the working directory
hazelcast.xml on the classpath
hazelcast-default.xml that comes with hazelcast.jar
But what can I do, if I want to save the actual config as xml. Perhaps for backup purposes. How can I do this?
I'm not aware of a configuration exporter but there is getter methods on Hazaelcast configuration class com.hazelcast.config.Config. You can use them to extract the configuration for you maps, lists, multimaps, groups, etc. For instance:
Map<String, ListConfig> listConfigs = config.getListConfigs();
for(ListConfig listConfig = listConfigs.values()) {
// export the configuration to an output file
System.out.println("List: " + listConfig.getName()+" has max size: "+listConfig.getMaxSize());
}
Related
I am trying to put mappings json files in a subdirectories due to different requirements based on diff profiles.
I have it working with default /mappings directory and all mappings work ok in postman.
WiremockConfiguration options = options()
.usingFilesUnderDirectory(System.getPtoperty(“user.dir”) + “/app/src/main/resources”
src/main/resources
-mappings
—folderA
—folderB
—folderC
But once I try to place json files under sub directory of “mappings” folder, no mappings get picked up and /__admin/mappings endpoint show a total of 0.
WiremockConfiguration options = options()
.usingFilesUnderDirectory(System.getPtoperty(“user.dir”) + “/app/src/main/resources**/mappings/aws**”
(Note the path difference)
I am just wondering if mappings folder subdirectories are even supported in wire mock or have I configured something incorrectly? It seems something too simple to be not supported by wiremock!
Many thanks
I have fixed it but for anyone facing similar problem u need to make “mappings” subdirectory of your custom folders.
src/main/resources
-my_wiremock_mappings
—folderA
—— mappings (should contain json files)
—folderB
—— mappings
—folderC
—— mappings
WiremockConfiguration options = options()
.usingFilesUnderDirectory(System.getPtoperty(“user.dir”) + “/app/src/main/resources/my_wiremock_mappings/folderA”
There is no need to add “mappings” to the path.
If you use a classpath ant pattern, you have to add *.json at the end.
#AutoConfigureWireMock(port = 8081, stubs = "classpath:/stubs/**/*.json")
https://github.com/spring-cloud/spring-cloud-contract/blob/main/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockConfiguration.java#L213
my.properties
#db connection
mongoconnection=mongodb://user:password#host:27017/database?maxPoolSize=1
#serial=vehicleID
077C70=47368
077C71=47367
077C72=47366
Properties properties = new Properties();
properties.load(new FileInputStream("my.properties"));
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String serialNumber = (String) entry.getKey();
String vehicleId = (String) entry.getValue();
}
In for loop I'm getting 'mongoconnection' as key and its respected value.
I want to differentiate 'db connection' and 'serial=vehicleID'
Properties class provide only flat view of all provided key-value pairs, there is no way to differentiate between blocks.
You could write your own parser for the file you are trying to read
I think you can make a tag to set java environment like this:-Dflag=my. and then you can read different file to get different properties by environment.
You could split your properties in two files (serial.properties, connection.properties)bBecause the properties seems to not have any relation between them. One file for the connection. And the other for the serials. This way, you read the serial properties and do your logic, and when you need the database url you read from the other file.
I normally create a properties file with properties that have something in common. For example, translations properties files have his own properties, database connection properties too. This way is easier to edit and find the properties in the future as the project grow.
Hope this helps.
I am working on a java project. I have a properties file that includes some file paths and locations. Is there a way to add a condition to the properties file and choose which path to take?
The normal way to do this with a properties file is to have all the versions of the property in the file, and have the logic to choose them in the actual Java code. For example, if you want different property values per operating system, you might have something like
file.limit.windows = 500
file.limit.mac = 1000
file.limit.linux = 2000
And then have Java code that does something like
properties.getProperty("file.limit." + operatingSystemName);
I've created a configuration class that will store configuration values. These configuration values should be read in from a configuration file "config.properties". Below is the config class:
#Configuration
#ComponentScan(basePackages = {"com.boot.Training.*"})
#PropertySource("file:/src/main/java/config.properties")
public class AppConfig {
#Value("${myFirstName}")
private static String myFirstName;
#Value("${myLastName}")
private static String myLastName;
public static void showVariables() {
System.out.println("firstName: " + myFirstName);
System.out.println("lastName: " + myLastName);
}
}
And below are the contents of the config.properties file:
myFirstName=John
myLastName=Doe
Running my program should simply print the values of these variables. But instead, Eclipse tells me it cannot find the config.properties file, even though I specified that it is located in /src/main/java/config.properties .
I'm likely specifying the file location without taking something else into account. What am I missing here?
The location you are using (file:/src/main/java/config.properties) refers to an absolute path rather than one relative to your project home.
A more common way to do this is to ship config.properties as part of your project in a resources directory, and refer to it via the classpath. If you move it to /src/main/resources/config.properties, you can load it this way:
#PropertySource("classpath:config.properties")
I believe in theory you could just leave it in /src/main/java and change your #PropertySource location to what I have above, but moving it to /resources is the more idiomatic way of doing this.
The basic way to specify a file: location to appoint a properties file that is located elsewhere on your host environment is:
#PropertySource("file:/path/to/application.properties")
Note that /path/to/application.properties should be absolute path pointing to your .properties file (in your example you are mixing file: usage and relative path which is not correct )
it is also possible to specify a system property or an environment variable that will be resolved to its actual value when your application starts. For example, ${CONF_DIR} below will be replaced with its associated value when the Spring application starts:
Open /etc/environment in any text editor like nano or gedit and add the following line:
CONF_DIR=/path/to/directory/with/app/config/files
Check it system variable has been set:
echo $CONF_DIR
/path/to/directory/with/app/config/files
use PropertySource like:
#PropertySource("file:${CONF_DIR}/application.properties")
I want to add new property to an existing file. Whenever, I add the new property, the entire file gets overwritten. Is there a way to update the file and not overwrite property.
FileOutputStream fo = new FileOutputStream(PROPERTIES_FILE);
Properties pr = new Properties();
pr.setProperty("Key1", "KeyValue");
try {
pr.store(fo, " Comments");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
(1) Now if I want to add a new property called Key2 and the set a value KeyValue2. Is it possible ?
(2) Also when I deploy in tomcat, only when I give the absolute path, the file is getting updated. Is there a way to find the file location at runtime. Because when I run test case, the file will be present locally and the path will be different.
(3) Is there a way to leverage classpath in anyway for this.
Thanks in advance!
**I am writing it down since I did not find clear answer for the problem mentioned **
(1) Now if I want to add a new property called Key2 and the set a value KeyValue2. Is it possible ?
**Yes it is possible. The key to understanding here is that, the properties object will be store on calling 'store' api. Here appending does not happens. The file will be overwritten by the contents of the properties object. THE API DOES NOT SUPPORT APPENDING IT.
The solution this problem will be to :
1) Load the properties from the same file
2) Update the new property or existing property
3) then store using the output stream
IN THIS WAY THE CONTENT OF THE FILE WILL NOT BE LOST**
(2) Also when I deploy in tomcat, only when I give the absolute path, the file is getting updated. Is there a way to find the file location at runtime. Because when I run test case, the file will be present locally and the path will be different.
** There are two ways to do it
1) Make sure that the file is present in the classpath. If present in the classpath, we need not give absolute path before the filename
2) Provide another class which set the path. In this way, the path can be set when running the testcases. (TESTNG/JUNIT)**
(3) Is there a way to leverage classpath in anyway for this.
** Already covered above **
Hope this helps