Tuesday, December 19, 2017

Usefull Links for HTML5

Wednesday, September 13, 2017

Sonar In Hybris


  • Download SonarQube from https://www.sonarqube.org/downloads/
  • Install/Unzip the SonarQube in a directory
  • Create a new mysql db "CREATE DATABASE sonar"
  • Set the db properties in sonar.properties file 
    • sonar.jdbc.username=
    • sonar.jdbc.password=
    • sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
  • Put the mysql driver in the directory sonarqube-6.5\extensions\jdbc-driver
  • Set the following properties in sonar.properties file
    • sonar.web.context=/sonar
    • sonar.web.javaOpts=-server -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
    • sonar.search.port=0
  • Start sonar qube via >StartSonar.bat and access localhost:9000/sonar 
  • login using admin/admin
  • Go to http://localhost:9000/sonar/profiles and restore the hybris official profile java-hybris-profile-public.xml
  • Set Hybris Official profile as the default java profile
  • Download the ant task jar sonarqube-ant-task-2.5.jar and put it in  config/customize/platform/resources/ant/sonar/lib
  • Now there are two ways to run sonar profiler using 1)  a new sonar build file and 2)existing hybris sonar build file
    • 1)  a new sonar build file
      • Create an ant file with the following contents
   
   
        value="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8" />
   
   
   
   
   
        value="Hybris Java Project analyzed with the Sonar Ant Task" />
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
       
           
       
       
       
   
      • Go to the directory and run the above ant file. You will see the sonar is updated with a new project with name "Sonar Build for Hybris"
    • 2)existing hybris sonar build file
      • Add the following properties to local.properties file
        • sonar.language=java
        • sonar.projectName=HYB SONAR
        • sonar.projectKey=HYB SONAR
        • sonar.projectVersion=1.0
        • sonar.excludedExtensions=acceleratorcms,acceleratorfacades,acceleratorservices,acceleratorstorefrontcommons,addonsupport,captchaaddon,commercefacades,platformservices
        • sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
      • Copy platform/resources/ant/sonar.xml into /config/customize/platform/resources/ant and change the following references in the file
        • replace the existing sonarqube-ant-task jar file wih the new sonarqube-ant-task-2.5.jar file
        • replace all "sonar.binaries" with "sonar.java.binaries"
        • replace all "sonar.libraries" with "sonar.java.libraries"
      • In hybris/bin/platform execute "ant customize sonar" to apply the above customisations
      • In hybris/bin/platform execute "ant customize sonar" to apply the above customisations
      • Now a project named HYB SONAR is created in sonar
Ref : https://wiki.hybris.com/display/hybrisALF/Measuring+Code+Quality+with+Sonar

Monday, July 31, 2017

Creating a New Custom Cache Region in Hybris


  • Create a new cahce region bean in core-cache.xml spring file. The below code is to cache only the products
   <bean name="productCacheRegion" class="de.hybris.platform.regioncache.region.impl.EHCacheRegion">
        <constructor-arg name="name" value="productCacheRegion" />
        <constructor-arg name="maxEntries" value="50000" />
        <constructor-arg name="evictionPolicy" value="LFU" />
        <property name="handledTypes">
            <array>
                <value>1</value>
            </array>
        </property>
 </bean>
    

  • Access caching by using the DefaultCacheController
Reference

Webserver based media serving in Hybris


  • Create an extension called staticmedia with a new class named ApacheMediaUrlStrategy that implements MediaURLStrategy interface. By default Hybris uses a base-64 encoded context request parameter that will not work properly in Apache. The ApacheMediaUrlStrategy uses a folder stategy so that apache can directly point to that directory. The below code in the class returns back //hostName/static/media/ in witch mediaHostUrl is an instance variable in ApacheMediaUrlStrategy class that contains hostName/static/media
return new StringBuilder(mediaHostUrl.length() + location.length() + 3).append("//").append(mediaHostUrl).append('/').append(location).toString();
  • Add configuration properties to the local.properties to specify the mediaHostUrlwith an appropriate URL that points to you media serving apache layer and change the mediaurlstrategy
media.apachemedia.url=
media.folder.images.url.strategy=apacheMediaURLStrategy
  • Add the new strategy to the staticmedia-spring.xml file
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    <bean id="apacheMediaURLStrategy" class="com.package.staticmedia.media.url.impl.ApacheMediaUrlStrategy">
        <property name="mediaHostUrl" value="#{configurationService.configuration.getProperty('media.apachemedia.url')}" />
    </bean>
</beans>
  • Create ysynch to copy the image contents to the media.apachemedia.url
  • Modify httpd.conf file to hanlde the media url inside the VirtualDirectory with 7 days of  cache expiry for images and 10 minutes for the _ui directory
SetEnvIf Request_URI "^/images/*" no-jk
Alias /images /opt/hybris/media/sys_master/images "/opt/hybris/media/sys_master/images">
Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
        Header append Cache-Control public,max-age=604800

    SetEnvIf Request_URI "^/_ui/*" no-jk
    Alias /_ui /opt/hybris/storefront/web/webroot/_ui    "/opt/hybris/storefront/web/webroot/_ui">
        Options FollowSymLinks MultiViews Indexes 
   AllowOverride None
        Order allow,deny
        Allow from all
        Header append Cache-Control public,max-age=600
Reference
Hybris Wiki Static Contents from Apache
Wiki Versioned Static content

Thursday, March 16, 2017

Hybris Vertical Cluster Configuration with Apache mod_jk configuration

Hybris is having its own cluster setup and hence instead of using the application server cluster configuration the hybris cluster configuration has to be used. For the demonstration purpose I have used two instances of hybris instances in the same machine and an Apache HTTP Server as a load balancer with the help of mod_jk

Hybris Cluster Setup

  • Make sure that both the instances of the hybris is having same code and using the same db. 
  • Configure both instances to point to the same stand alone solr server. For reference see the link Solr Clustering and Replication in Hybris
  • Since both instances are running on the same machine, to avoid the port conflict change the ports in the second instance via following link Changing default ports in hybris
  • In case of vertical clustering and unicast we need to specify separate ports and if we are using other methods then same configuration has to be used in all the nodes even in case of vertical clustering
  • Enter the following values in the local.properties file in both the hybris isntances 
        #clustering
         clustermode=true
         cluster.nodes.autodiscovery=true
         cluster.nodes.ping.interval=10000
         cluster.nodes.stale.timeout=30000

    • Unicast

                 #unicast
                 cluster.broadcast.methods=unicast
                 cluster.broadcast.method.unicast.serveraddress=localhost
                 cluster.broadcast.method.unicast.clusternodes=localhost:9997 ; localhost:19997
    • JGroups
           cluster.broadcast.methods=jgroups 
           cluster.broadcast.method.jgroups=de.hybris.platform.cluster.jgroups.JGroupsBroadcastMethod
           cluster.broadcast.method.jgroups.tcp.bind_addr=localhost
           cluster.broadcast.method.jgroups.tcp.bind_port=7800
           cluster.broadcast.method.jgroups.channel.name=hybris-broadcast
           cluster.broadcast.method.jgroups.configuration=jgroups-udp.xml

<Connector protocol="AJP/1.3" port="${tomcat.ajp.port}" proxyPort="${proxy.http.port}" redirectPort="${proxy.ssl.port}" useIPVHosts="${tomcat.ajp.useipv}" connectionTimeout="10000" keepAliveTimeout="10000" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">

<Connector protocol="AJP/1.3" port="${tomcat.ajp.port}" proxyPort="${proxy.http.port}" redirectPort="${proxy.ssl.port}" useIPVHosts="${tomcat.ajp.useipv}" connectionTimeout="10000" keepAliveTimeout="10000" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node2">
Apache HTTP Server Load Blancer Setup
Follow the linnk HTTP Server mod_jk configuration to load balance Tomcat instances in Hybris