Tuesday, October 23, 2012

How to manage Hot backup Or Manage Disaster Recovery in CQ

There are various approach, I am listing them with pros and cons

Approach 1: Use clustering, but direct the requests only to one node. In case of problems with this node just switch over to the other node. Essentially this is an active-passive scenario.
+ proven technology, documented and fully supported feature
+ automatic fail over easily possible
- additional license cost
- Latency issue might effect performance
- Managing cluster is sometime difficult

Approach 2: Use replication (on modification, no version, no status update).
+ proven technology, documented and fully supported
+ easy handling, reconfiguration during runtime
- manual reconfiguration of replication in case of switch
- "on modification" only works for cq:pages and not for other type like DAM
workflows, Events, Replication queues. (But if you activate DAM asset it will be there is stand by system)

So, this approach 2 doesn't achieve a "full-standby" system, but it more looks like a way not to loose content. Everything else is probably gone, so it's only for a really worst-case scenario.

Approach 3: Build periodically content packages and replicate them to the standby-system
+ you can also do a provisioning of other staging systems with this content
+ load on the active system predictable, normal editing actions are not
loaded with this
- self-written, not supported
- you can package workflows and events when grabbing them from repository
- Need testing to see if it will work.

Some Questions:

Q: What is best way to create active passive clustering node and what should be I careful about.
A: Create multi node cluster and make sure that DR nodes are not taking any request. You have to careful about that there is not a lot of latency between DR node active nodes.
Also it is very difficult to keep one node from active node as master in case master goes down. There is no harm of having DR as master node but not recommended (As write always goes through master). You can use either felix console or preferredMaster property to set up master in advance. Please read http://crxcluster.wemblog.com very carefully to understand CRX better.

To make a node master:

Since this is exposed as a JMX you can monitor it and invoke it during run time.

Q: Do I have to take cold backup of all the nodes
A: No, if you are using clustering then taking backup of any node (usually master) is enough.

Q: How about publish instance 
A: It is not recommended to use clustering in publish instance, Unless there is no other way to support some use case. In that case each publish instane is Hotback of each other. Note that you can not recover publish instance from nightly backup (As things might have been updated from the time back up was created). Usually it is recommended to have a backup publish instance which does not take load but configured as replication agent in author.

Q: I am just left with nightly backup, How should I create new publish instance ?
A: In this case you have to find out things replicated from the time last nightly backup was created and now. You can use nightly backup in conjunction with http://www.wemblog.com/2011/10/how-to-find-all-pages-modified-or.html  to support this use case.

How to work with Configurations in CQ

Use Case: You want to create configuration which can be edited at run time using OSGI console.



CQ already comes with predefined configuration that you can find using following Xpath queries

Or using query builder predicate (http://HOST:PORT/libs/cq/search/content/querydebug.html)


From front end you can find all configurations under config tab in felix console

You can also download all configurations using felix console

You can also go to configuration through Component tab

On file systems you can find configuration under /crx-quickstart/launchpad/config folder.

Configuration can be at any of above location but order of precedence of selecting a configuration is,

1) /apps
2) /libs
3) File system

For more information please see http://dev.day.com/content/kb/home/cq5/CQ5SystemAdministration/LoadingOrderFelixConfig.html

How to Create a felix Configuration:

1) By creating a sling:OsgiConfig node using CRXDE

Step 1:

Step 2:

2) Using xml

3) By Code

How to Read Property:

1) Using generic class (You can create interface)

2) Within bundle

Cool part about configuration that I like most is, You can create environment specific configurations and based on your environment particular configuration will get selected. You can set configurations as given in http://www.wemblog.com/2012/01/how-to-set-up-run-mode-in-cq-wem.html

Some Questions:

Q: Where does my configuration get stored when I change it through felix console directly

Ans: In CQ5.5 it get stored in repository under /apps/system/config thus get replicated across all cluster. But in CQ5.4 and before it get stored in file system under /crx-quickstart/launchpad/config/<Name of config>.config thus requires changes in all cluster instance.

Q: What if I just want configuration for particular environment

Ans: In that case you have to set up your config for that environment and then create configuration under that node. See example above.

Q: What is recommended way to create configuration

Ans: It is recommended to change configuration through repository and not through felix console if possible. That way you can track configuration in SVN as well.

Q: I see that there is already a configuration under felix console, How can I create one under repository to override that.
Ans: To do that first go to felix console -> configuration -> open configuration and look for pid

Then create exactly same node under /apps/config<Any enviornment> of type osgiconfig

Q. How to create configuration that has drop down of selected value
A. You can do something like,

How to create Configuration factory to locate services

Some time we want to create configuration factories to create factory of configuration (For example Logger configuration)

In order to create such configuration you could use annotation

To read such configuration though supporting class you can use,

  @Reference (cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE,        policy=ReferencePolicy.DYNAMIC, referenceInterface = MyCustomService.class, name="MyCustomService")

How to locate configurations in configuration factory (Note that you might not need to do this if you are using independent configuration factories, for example configuration factories of scheduler) 

Please ask any other question that you want me to add here.

Tuesday, October 2, 2012

How to implement CQ scheduler to run on a event

Use Case:

1) You want to implement a scheduler to run on a specific event. That event could be any thing ranging from any Node action (Add,Modify,Delete) or any replication action (Activate, Deactivate, Reverse)

Pre requisite:

1) http://sling.apache.org/site/eventing-and-jobs.html
2) http://felix.apache.org/site/apache-felix-event-admin.html
3) http://www.osgi.org/javadoc/r4v41/org/osgi/service/event/package-summary.html
4) http://sling.apache.org/apidocs/sling5/org/apache/sling/event/package-summary.html


Step 1

Step 2: Handler to perform action

Note: you can find some more code example at http://wemcode.wemblog.com