Sunday, January 12, 2020

AEM | Multisite setup approaches


Setting a new language site


For multi-site requirement, creating a new language site should be done using following steps:

1.      Create a new language master

For any language site, the base should be a language master. Remember the standard rule- “One master per language”. If the master language already exist then use that only, skip this step. All master languages should be created under “/content/mysite/language-masters”. E.g. for all English sites (en_us, en_uk etc.) the base should be English master (/content/mysite/language-masters/en).
              To create a new language master use the language copy option.
a.       Go to /sites.html/content/mysite/language-masters

b.       Click on Create -> Language Copy

c.       In the next screen, Click “Add Pages”  then select “/content/mysite/language-masters/en” as source (You can select any other existing language as per need)
d.       In next screen, select target language (for which you are creating master) and fill in other details

e.       Next select “Create Structure” and Click on “Create”, done.

f.        Now you can see that your language master is created:

2.      Create a new language site

To create a new language site- Use the “live copy” option. The new site should be created based on the respective language master. Follow the steps below:
a.       Go to /sites.html/content/mysite
b.       Click on Create -> Live Copy

c.       In the next step, select the respective language master as source and click “Next”

d.       Select Destination as “/content/mysite” and click “Next”

e.       In the next screen, enter necessary details.
                                             I.            Make sure to enter name as {language-code}_{country-code} e.g. “fr_fr”
                                           II.            Select Rollout Configs as “Standard rollout config”

f.        Click on create. That’s it. You have completed the language site creation.

Wednesday, November 20, 2019

AEM | Clearing dispatcher cache via Jenkin jobs and Scripts

During development, it is often needed a quick way to clear dispatcher cache. In this article, I am going to enlist basic methods:

1. curl command/ script

You can run the below curl command-

curl -H "CQ-Action: Delete" -H "Content-Length: 0"  -H "Content-Type: application/octet-stream"  -H "CQ-Handle: /content/mymyproj"  http://localhost/dispatcher/invalidate.cache

curl -H "CQ-Action: Delete" -H "Content-Length: 0"  -H "Content-Type: application/octet-stream"  -H "CQ-Handle: /etc.clientlibs/myproj"  http://localhost/dispatcher/invalidate.cache

In above commands:
  • Replace the "localhost" with correct dispatcher server URL. You can get the URL from the flush agent transport URL. Use the public URL/ IP of the dispatcher or make sure you are connected to relevant VPN. Or make sure your machine IP is white-listed by the dispatcher to allow you direct access. If proxy information is available then you can pass it to curl command.
  • If your dispatcher is on https and the command gives error relate to SSL certificate. Then ignore the ssl certificate warning by using "-k" argument to the curl command.
Also you can run these commands as a batch file in bat script for windows and sh script for Linux/ Mac. An example file-

2. Jenkin Job

The same can be achieved through a Jenkin job. To the build step- Add a "Execute Shell" step. Here paste the same curl command.



Other tools like postman can be used too for this purpose. Just hit the rest end point with required parameters as passed in the curl command above.

Tuesday, September 10, 2019

Github | Could not read from remote repository error while cloning repo with ssh URL

Problem:

When trying to clone a repo from SSH url (e.g. git@github.com:repo-account/my-project.git), sometimes you may encounter an error like below:


Cloning into 'C:\user\projects\my-project\ssh-code\test\dotcom-my-repo'...
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Root Cause:

This happens when the request for clone is not supplied with proper public ssh key (which must be white listed at github.com) or clone command is not able to grab it.

Solution:

In such scenarios ensure following things:

1. Ensure public ssh key is  added to github account
2. Instead of using any git UI tool, open git "bash" window

 

3. If you have ssh public key generated already and want to use same for the repo checkout then skip this step otherwise create a new ssh key - https://help.github.com/en/enterprise/2.18/user/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

4. If you have just one ssh key for all projects then simply run below command in bash window:
      git clone git@github.com:repo-account/my-project.git
    In case you get into issues, try creating a fresh ssh key and add it to github account.

If you have more than one ssh key and want to use specific key for this checkout then run below command:
GIT_SSH_COMMAND="ssh -i C:/Users/vivmishr/.ssh/abc" git clone git@github.com:repo-account/my-project.git

Hope it works!

Wednesday, July 31, 2019

Free port 80 in windows

Problem:

While you are using certain application like nginx, apache etc. which run on port 80, you may face issue sometimes with the starting up of these applications reason being the port 80 already in use by some other application. 

Solution:

In order to free the port, follow these steps:

1.    Click Start > Settings > Ethernet >Network and Internet > Windows Firewall
2.       In the left pane, click Advanced Settings
3.       In Windows Firewall with Advanced Security, click Inbound Rules.
4.    Sort Items by "Network Protocol" column
4.       Find Local Port 80 with Protocol TCP.  It might be "World Wide Web Services (HTTP Traffic-In)" or Citrix or Skype or Apache
5.       Once you find it, stop or disable that rule from Windows Services 

Try starting your application again.

Wednesday, October 17, 2018

Performance | Replicating to multiple replication agents programmatically without looping

Objective:

Normally developers use loops to Replicate pages or assets programmatically through Java code to multiple replication agents, which is a bad practice in terms of performance. It particularly impacts the queue performance when replicating thousands of content nodes and one can observe the lag between queuing of items in replication queue to different agents.

Solution:

Do not use loops instead utilize AgentFilters to set list of replication agents through which replication should be done. Here is sample code:

String replicationAgents = { "publish_agent1", "publish_agent2" }; // From configuration
ReplicationOptions options = new ReplicationOptions();
options.setFilter(agent -> Arrays.asList(replicationAgents).contains(agent.getId()));
replicate.replicate(resolver.adaptTo(Session.class), type, targetPathsArray, options);

Advantage of this approach is that it reduces the queue lag significantly. While processing all replication items, individual item is assigned to various replication agents at one go.

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...