Custome load Optional Configuration file into hybris - sap-commerce-cloud

I have read the online tutorial about Optional Configuration
https://help.sap.com/viewer/b490bb4e85bc42a7aa09d513d0bcb18e/2011/en-US/8beb75da86691014a0229cf991cb67e4.html
I know that after I set the HYBRIS_OPT_CONFIG_DIR and put [2digit number]-local.properties file into this directory, Hybris will load these files automatically.
What I want to do is that, I set up several hybris work nodes as a cluster, and every node need a different configuration because every node's role is different, one is frontend, one is backend and one is data processor.
However, due to some reason, I have to set the same HYBRIS_OPT_CONFIG_DIR value for every node, so I want to know, if there is any way to let hybris load some of properties file in this directory.
For example, I put 10-local.properties and 20-local.properties, and one node only load 10-local.properties and one node will load both of them.
I know that I can implement configuration switch by set different value of HYBRIS_OPT_CONFIG_DIR, but I hope I can find another way.
thanks

I know the question is a bit old but maybe it will help someone in the future.
I see 3 potential solutions here:
Keep common config/local.properties with node type agnostic properties and store additional node type specific properties files in separate directories. Then set HYBRIS_OPT_CONFIG_DIR to a different directory to let hybris load additional props. E.g.
/config/local.properties <- common props
/config/frontend/10-local.properties <- additional frontend props
/config/backend/10-local.properties <- additional backend props
Now setting HYBRIS_OPT_CONFIG_DIR=/config/frontend environment variable will make hybris load /config/local.properties AND /config/frontend/10-local.properties.
Use HYBRIS_RUNTIME_PROPERTIES env variable to point to an additional properties file. E.g. you could have
/config/local.properties <- common props
/config/frontend.properties <- additional frontend props
/config/backend.properties <- additional backend props
Now setting HYBRIS_RUNTIME_PROPERTIES=/config/frontend.properties environment variable will make hybris load /config/local.properties AND /config/frontend.properties.
Use useconfig system property to make hybris load a different properties file. In this case you need to setup props like this:
/config/localfrontend.properties <- frontend props
/config/localbackend.properties <- backend props
Setting useconfig system property (e.g. by using -Duseconfig=frontend) will make Hybris load ONLY /config/localfrontend.properties properties file.

Related

How can I copy an existing overthere.SshHost file in XL Deploy UI using Puppet?

The Infra team in my company has provided us with sample overthere.SshHost under 'Infrastructure' in XL-Deploy UI that has a predefined private key file and passphrase which is not shared with us.
We are asked to duplicate this file manually in the UI, rename it and create infra entries for our application.
How can I achieve this with puppet?
Lets say the sample file is placed under: Infrastructure/Project1/COMMONS/Template_SshHost
and I need to create an overthere.SshHost under Infrastructure/Project1/UAT/Uat_SshHost and Infrastructure/Project1/PREPROD/Preprod_SshHost by copying the sample file.
Thanks in advance!
You can sync a target file with another file accessible via the local file system by using a File resource whose source attribute specifies the path to the original. You can produce a modified copy in a variety of ways, such as by applying one or more File_line resources (from stdlib) or by applying an appropriate script via an Exec resource.
But if you go that route then you have to either
accept that the target file will be re-synced on every Puppet run, OR
set the File resource's replace attribute to false, in which case changes to the original file will not be propagated into the customized copy.
The latter is probably the more acceptable choice for most people. Its file-copying part might look something like this:
$project_dir = '/path/to/Infrastructure/Project1'
file { "${project_dir}/UAT/Uat_SshHost/overthere.SshHost":
ensure => 'file',
source => "${project_dir}/COMMONS/Template_SshHost/overthere.SshHost",
replace => false,
}
But you might want to consider instead writing a custom type and provider for the target file. That would allow you to incorporate changes from the original template without re-syncing the file on every run, and it would give you a lot more flexibility with respect to the customizations you need to apply. It would also present a simpler interface for you to use in your manifests, which could make managing these easier. But, of course, that's offset by the cost is that writing and maintaining a custom type and provider. Only you can determine whether that would be a worthwhile trade-off.

uninitialized constant OrigenTesters

I am working on transferring one application from rgen to Origen.
I added environment/j750.rb in my application.
added the below code into j750.rb
# environment/j750.rb
$tester = OrigenTesters::J750.new
in Target folder, I also added $test as below:
$tester = OrigenTesters::J750.new
however, when I tried to generate pattern, it still failed and showed'uninitialized constant OrigenTesters'.
When and how to initialize it?
Thanks a lot in advance!
Normally this is something that Origen users don't particularly need to worry about, if you add:
gem 'origen_testers'
to your application's Gemfile, then it will be required automatically and a reference like OrigenTesters in your environment file or anywhere else will just work.
However, I note that you mention upgrading from an rgen app, which means that your application must be very old and in fact may not even have a Gemfile.
If you contact me internally I can send you the link to our intranet page which has a guide on how to update these really old apps.

Chef 12 Opsworks attributes get overriden by last recipe in run list

I am running a Chef 12 Opsworks stack and I created a custom cookbook to take some backups of a few folders on my webserver.
Maybe my approach to this is wrong, but I basically have two (or more) recipes for each website I want backed up and then I'm updating some attributes (site name, backup folder, etc) in each recipe.
So I start with the following in my default.rb file in the attributes folder:
default['backup']['site'] = "SITE1"
default['backup']['root'] = "/var/www/SITE1"
Then in each backup recipe I have the following at the top of the recipe followed by my back up code:
site1.rb
node.override['backup']['site'] = "SITE1"
node.override['backup']['root'] = "/var/www/SITE1"
site2.rb
node.override['backup']['site'] = "SITE2"
node.override['backup']['root'] = "/var/www/SITE2"
Now in my Setup step on the Opsworks Layer I add all the backup recipes, but the problem arises when I start an instance (or run the Setup step from the Deployments) because the attributes seem to be set to whatever the last recipe sets them in alphabetical order.
So SITE1 backup script for example will end up being built with the /var/www/SITE2 root folder in its config and thus not backing up the right site.
Is there are way to prevent this from happening? From what I gather (from my example and reading Chef docs) the attributes are all compiled together at the beginning and then the recipes are being run - which is why the last set of attributes gets set as the final version and then all recipes using those attributes will get those values.
The only way I can deploy them at the moment is by running each recipe independently thus using the correct attribute values, but the moment the instance gets rebooted or the Setup step is ran manually all backup scripts will go back to backing up just one site.
Is my approach to this wrong? Should I be creating separate named attributes for each recipe?
I ended up fixing this by slightly modifying my approach to using attributes upon reading more about the 'chef run' process.
I am still using attributes for the actual 'common' attributes between all recipes, but then in each recipe instead of overriding the recipe specific attributes I replaced them with local ruby variables which then get passed to my 'template' via the 'variables' property.
So my site1.rb recipe for example looks the following way:
site = "SITE1"
root = "/var/www/SITE1"
...
config = {
:site => site,
:root => root,
...
}
...
template "/path/to/config" do
source "config.erb"
variables(
:config => config
)
...
end
This way I get to keep the same variable names inside my config template yet have each backup recipe use its own custom variables without interfering with other recipes.

Override default cookbook chef variables

I am looking for specific instructions on how to override default values in a third party cookbook. For example, i am using apache_spark cookbook (https://github.com/clearstorydata-cookbooks/apache_spark)
And i want to override the attribute
default['apache_spark']['standalone']['master_host']
I tried it my making a main recipe, in which i add
node.default['apache_spark']['standalone']['master_host'] = 'foo.com'
And execute it using chef solo like:
run_list(
'recipe[main]',
'recipe[apache_spark::spark-standalone-worker]'
)
But that does not seem to work. Any suggestions on how it needs to be done?
My main recipe is here https://github.com/Vibhuti/chef-main
The correct fix would be to make a wrapper cookbook and set your values in the cookbook's attributes file (main/attributes/default.rb):
override['apache_spark']['standalone']['master_host'] = 'foo.com'
Also make sure you add a dependency in main's metadata.rb to force the load ordering to be correct:
depends 'apache_spark'

log4 net Dynamic file name assigning

I want to know how to dynamically assign file name using Log4net .My application is such that 10 different files should be dynamically created based on user input ,and later based on the name the corresponding file name needs to be picked up and information written to it
For example in my application based on my buisness requirement for every xml file a corresponding log file with the same name as xml file should be created .Later whenever I do any modification to the xml file an entry needs to be in the corresponding log file
Please help . I having trouble to get control of the appropriate log to write it
Have not done this, but there are probably a number of ways of doing this, so this may not be the best way, but it should work
public OpenLogFile(string fileName)
{
log4net.Layout.ILayout layout = new log4net.Layout.PatternLayout("%d [%t]%-5p : - %m%n");;
log4net.Appender.FileAppender appender = new log4net.Appender.FileAppender(layout , filename);
appender.Threshold = log4net.Core.Level.Info;
log4net.Config.BasicConfigurator.Configure(appender);
}
Then just call OpenLogfile when you need to switch files.
You might need to tweak the layout or appender type.
A big disadvantage of this method is you losing the xml configuration and the ability to change settings at runtime. So a better way might be to configure your appender in the xml file to use a property
eg
file type="log4net.Util.PatternString" value="Logfiles\Log_For_%property{MyLogFileName}"
Then in your code you could change the property
log4net.GlobalContext.Properties["MyLogFileName"] = ...;
The tricky bit is to get log4net to reload itself. I haven't read the documentation of this, so I don't know if there is a way of forcing a reload. It might work if you just call log4net.Config.XmlConfigurator.ConfigureAndWatch again. Otherwise it should work if you opened the xml file and saved it again (without needing to change anything)
Hope this helps.

Resources