Explain core concept and working of Calculate() and recalculate() methods of calculationService in Hybris ?

During customizing order and cart there is used calculation service which is very important for customizing as well as in interview. SO today I decided to write my outcomes related to calculate() and recalculate() methods of calculation service.
As you know both Cart and Order is subtype of AbstractOrder so more or less every attributed is same for both item
FYI – During checkout finally Cart is into converted to Order means Copy all data from Cart to Order and cart number converted to order number.
Both Carts and Orders have an attribute called calculated of type Boolean that states whether they are calculated, or not. Now next what will calculate?
Boolean calculated;
In every cart or an order have price, tax, discount etc so this need to be calculate.
So on basis of Boolean attribute calculated there is call of CalulationService's method calculate() and recalculate() methods.
So whenever below action is performed on a Cart or an Order, the Cart or Order’s Boolean property (calculated) which is set to be FALSE
1. Product is be added to the cart
2. Product is be removed from the cart
3. User is changed
4. Currency is changed

So two important method call on basis of calculated=FALSE which is CalculationService.calculate() or CalculationService.recalculate() method
Before going in deep let’s see below
CART
<itemtype code="Cart" extends="AbstractOrder" jaloclass="de.hybris.platform.jalo.order.Cart" autocreate="true" generate="true">
<deployment table="Carts" typecode="43"/>
<attributes>
<attribute autocreate="true" redeclare="true" qualifier="entries" type="CartEntryCollection"/>
<attribute type="java.lang.String" qualifier="sessionId">
 <persistence type="property"/>
 <modifiers read="true" write="true"/>
 </attribute>
 </attributes>
</itemtype>

ORDER

<itemtype code="Order" extends="AbstractOrder" jaloclass="de.hybris.platform.jalo.order.Order" autocreate="true" generate="true">
<deployment table="Orders" typecode="45" propertytable="OrderProps"/>
<attributes>
<attribute autocreate="true" redeclare="true" qualifier="entries" type="OrderEntryCollection"/>
</attributes>
 </itemtype>
                               
Form above item definition every cart has cartEntry and every order has OrderEntry 
FYI- Every cartEntry and orderEntry their is also has Boolean attribute calculated
So depending on  every cartEntry's Boolean attribute value it call CalculationService.calculate() method to calculate their price, tax, discount etc of that cartEntry.
Concept: If there is something change in cartEntry then after also Cart’s calculated Boolean attribute become FALSE 
 Final Conclusion
1. If you adding any product into cart then
 CartEntry's calculated attribute = FALSE
Cart's calculated attribute = FALSE
So first there will call CalculationService.calculate to calculate cartEntry total after finish this call CartEntry's calculated attribute will set to TRUE then after will call CalculationService.recalculate()  to calculate cart TOTAL and after finish this call cart' calculated attribute will set to TRUE
   
2. If again any product is add to same cart then
 CartEntry's calculated attribute = FALSE. If it is FALSE then again Cart's calculated attribute = FALSE So there will again call CalculationService.calculate() method to calculate for these cartEntry and finally again it set to= TRUE after calculate for these newly entered cartEntry and after again call CalculationService.recalculate() to calculate Cart Total.


Core difference between platformwebservice and Ycommercewebservice in hybris? hybris interview question collection

Before release of Hybris 4.6 there was only platformwebservice and after release with hybris 4.6 introduce Ycommercewebservice extension

So here to understand the core difference between these two extension just need to get answer why Ycommercewebservice is require if there is already platformwebservice

And reason is that platformwebservice is only use of CRUD operation on data model and nothing else but Ycommercewebservice provide web service nature to provide eCommerce features like  registration, cart handling, checkout, orders etc

So you can better understanding with below

 

platformwebservice
Ycommercewebservice
Only use for CRUD operation on data model
Provide ecommerce features like card handling , checkout, orders
There is skip of business logic
Use business logic

Introduce in relases of Hybris 4.6

Core concept of running Cron Job in Clustering environment in Hybris | Cron job tutorial

Hello Guys,
Have you ever think that How Cron Job is run in cluster environment. is it run on every nodes or only in a single node ?. SO lets discuss it.
Core Concept : Cron job Always run in Single Node only 
During to creation of Cron Job you can define on which node it can execute mean you can set Node on which it always execute. 
everyReplyCronJob.setNodeID(1);
modelService.save(everyReplyCronJob);
After above code everyReplyCronJob will always run on node 1 in that cluster environment and if you not set node then it can be run any one of node in that cluster environment but only one node for that time

Now  After  release of Hybris 5.5.1 and later version , you can assign your cron job to group of nodes means if there is no available a node then it will execute on any other node of that groups
For that you need to do below
You need to define group of node in Local.properties file as below
cluster.node.groups= group name, another group name
After that you need to do code as below


 everyReplyCronJob.setNodeGroup(“your node group”);

How to create usergroup in hybris | step by step to create usergroups in Hybris | beginners hybris developer

Users are different types of people that access your store whether it be an administrator, customer, or shopper. Users can be assigned to Groups
Groups within Hybris commerce are a simple way to organize your users, or customers. Yet, the feature is powerful and versatile, and it can be used to further extend your offerings to select groups of users. Members of an administrative group may have the rights to manage all, or part of your store. Additionally, non-admin group members can be given special pricing, payment methods, shipping options, taxation, subscriptions, and more.
Below steps you follow to create usergroup in hybris
1.       Hmc  > User > User Groups



In above there is various type of user group  that available like B2B usergroup  in hybris and you can create
2.         
Now you fill all details in above and click on create button

3.       You can also apply personalization for your usergroup in Personalization tab as below




How to configure Jenkins with with Git Hub for linux /windows enviornment - Hybris build process

Hello Friends,

As you already know Jenkins is a software use for continuous integration. Jenkins will be installed on a server where the central build will take place.

Also you know about GIT hub which is use for repository

From project point of view it is very important to know how Jenkins used with Git hub so lets discuss about.
Today will explain how to integrate Jenkins in Linux with private GIT Hub.

After install Jenkins you need to configure so please follow below steps

Note: below configuration given for Linux/Unix environment. If your environment is window then just open what graphical image given and then configure


1.     Configuring the GIT plugin in Jenkins:

Jenkins à Manage Jenkins à Manage Plugins
Make sure Jenkins GIT Client Plugin and Jenkins GIT plugins are installed.




2.     Configure GIT in server (if it is install on Linux enviornment):

Login to Jenkins server via puty
Execute the following command - sudo yum install git-all


3.     Configure GIT executable path:

Jenkins àMange JenkinsàConfigure System
Enter the git executable path(git installed to the server in previous step)
My case the path is /usr/bin/git, change accordingly



4.     SSH Configuration:

Login to Jenkins server via putty
Execute the following commad - sudo -u jenkins ssh-keygen -t rsa
Enter the details accordingly, Passphrase is optional if required then enter some string.
This will create private and public keys under /var/lib/jenkins/.ssh (default files are id_rsa and id_rsa.pub)

5.     Configuring Credential:
Login to Jenkins console --> Jenkins Credentials
Click on add a domain – Enter some name(better git hub host name)
Click on Add credential
Enter the user name as Jenkins(the user that runs the jenkins)
Select From the Jenkins master ~/.ssh



6.     Configure deployment key in GIT:

Login to GIT and click on Profile Settings
Click on SSH Keys – Enter the content of id_rsa.pub(cat id_rsa.pub) to Key filed
Click on add key.







7.     Configure the Job:

Configure the GIT URL and select the credential name created in the previous step
Specify the branch to be build.






Explain Performance Tuning of Hybris Platform must know for hybris Architect / Solution Architect

Hello Friends,
Lets today discuss about hybris performance related things which can very usefull when you are going for Hybris interview for senior position like Architect / hybris solution architect
So below point you must be know

1. Enable JMX Remote monitoring:
Remote JMX monitoring will help us to monitor the server resources (e.g. memory usage and CPU usage) through JMX client such as VisualVM.
Open <<HYBRIS_HOME>>/conf/local.properties and make sure the following properties are added as part of tomcat.generaloptions .
-Dcom.sun.management.jmxremote.port=50055 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -



Memory usage also can be monitored from admin console
Monitoring à Memory



2. JVM Tuning:
The default JVM parameters are not optimal for running large applications. So the parameters (e.g. memory and GC) should be tuned for optimal performance of the application.
Create a folder crash under <<HYBRIS_HOME>>
Open <<HYBRIS_HOME>>/conf/local.properties and replace the variable java.mem with the java.mem=6G
Open <<HYBRIS_HOME>>/conf/local.properties replace tomcat.generaloptions with the following data
tomcat.generaloptions=-Xmx6G -Xms6G -XX:MaxPermSize=1G -XX:NewRatio=1 -XX:SurvivorRatio=12 -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:ParallelGCThreads=8 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/app/hybris/crash/hybris_java.hprof -Xloggc:/app/hybris/crash/hybris_gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -ea -Dcom.sun.management.jmxremote.port=50055 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dorg.tanukisoftware.wrapper.WrapperManager.mbean=true -Djava.endorsed.dirs="%CATALINA_HOME%/lib/endorsed" -Dcatalina.base=%CATALINA_BASE% -Dcatalina.home=%CATALINA_HOME% -Dfile.encoding=UTF-8 -Dlog4j.configuration=log4j_init_tomcat.properties -Djava.util.logging.config.file=jdk_logging.properties -Djava.io.tmpdir="${HYBRIS_TEMP_DIR}" ${jvm.crashHack}
Change the XX:HeapDumpPath and –Xloggc path accordingly

a. Apply the required load to the system – Apache JMeter can be used to load the request to the system.
b.  Monitor the system resources like CPU, Memory and threads using VisualVM while load is applied to the system
c.Change the memory parameters and GC parameters based on the above test result.

If you provide too little memory to an application it will run out of memory. The JVM will not be able to free up memory space at the rate that your application needs it. In this scenario JVM will throw an OutOfMemoryError and shut down completely
The above three steps should be repeated to achieve the optimum system performance by applying different values for the parameters.
3. Thread Tuning:
Modify the thread parameters based on the system performance.
Open <<HYBRIS_HOME>>/bin/platform/ project.properties and replace the following property values.
tomcat.acceptcount=150
tomcat.maxthreads=300
Change the counts accordingly.
Open <<HYBRIS_HOME>>/ config/tomcat/conf/server.xml
And replace the below content
Old
<Connector port="${tomcat.http.port}"
maxHttpHeaderSize="8192"
maxThreads="${tomcat.maxthreads}"
protocol="org.apache.coyote.http11.Http11Protocol"
executor="hybrisExecutor"
enableLookups="false"
acceptCount="100"
connectionTimeout="20000"
URIEncoding="UTF-8"
disableUploadTimeout="true" />
New
<Connector port="${tomcat.http.port}"
maxHttpHeaderSize="8192"
maxThreads="${tomcat.maxthreads}"
protocol="org.apache.coyote.http11.Http11Protocol"
executor="hybrisExecutor"
enableLookups="false"
acceptCount="150"
connectionTimeout="20000"
URIEncoding="UTF-8"
disableUploadTimeout="true" />
Change the acceptCount="150" accordingly

4. Improve Caching:
Open <<HYBRIS_HOME>>/ bin/platform/project.properties
Replace cache.main property value with cache.main=50000

5. Thread Dumps:
Thread Dump is a snapshot taken at a given time which provides with a complete listing of all created Java Threads. The thread dump can be analyzed to determine the bottleneck or blocking threads.
Different tools can be used to analyze the thread dumps e.g. Samurai and IBM Thread and Monitor Dump Analyzer for Java.
Thread Dump can be generated from admin console
Monitoring à Thread Dump


Click on Download button to download the current thread dump.

6. JDBC Logging:
Sometimes the application will be very slow due to slow running queries. Analyzing the slower running queries using JDBC logging and create the indexes wherever required can drastically improve performance.
Monitoring à Database à JDBC logging



Click on Start logging and click on Stop logging after particular time.
Click on Download log

Click on JDBC log analysis à Analyze to find out the details on the queries executed

Core concept of deployment table in itemtype in hybris | use of build.development.mode=true in hybris

 Hello Friends,

Let’s discuss about deployment table definition in items means what is deployment and why should give, when it is mandatory , In which case you should not give deployment table.

So

1. What is deployment

 > Process of defining the table for the item type in items.xml is called deployment means specify the table name while defining the item type so that the values
 of the item type will be persisted in that table like below

  <itemtype code="EveryreplyCustomer" generate="true" autocreate="true" jaloclass="de.hybris.platform.acceleratorcms.jalo.components.EveryreplyCustomer">
      <description>It represents everyreply Customer.</description>
    <deployment table="EveryreplyCustomer" typecode="31003" />
  </itemtype>
 
 2. Now when it is mandatory to give deployment table it items definition

 > Before going to dicsuss i think below point you already know
   a. If the item type is not extending any item type then by default GenericItem will be considered as the parent of the item type.so the deployment ofGenericItem will be used by the item type.
   b. If we don’t specify the deployment for any of our item type then deployment specified in the closest type in the hierarchy will be considered.
  
  
Now before going to next lets discuss about   build.development.mode=true
so above is one of legacy mode which tell  "Build process checks the missing deployments"
               
 A.  So if build.development.mode=true in local.properties file then Build process checks the missing deployments
   a. If you define a itemtype B which extends a itemtype A and itemtype A has no deployment table then BUILD will FAIL
  
    <itemtype code="itemTypeA" generate="true" autocreate="true" jaloclass="de.hybris.platform.acceleratorcms.jalo.components.itemTypeA">
    </itemtype>
 
      <itemtype code="itemTypeB" generate="true" autocreate="true" extends="itemTypeA" jaloclass="de.hybris.platform.acceleratorcms.jalo.components.itemTypeA">
    </itemtype>
  
  
    But after given deployment table in itemtypeA then build will success
               
    Now again
               
                Test your knowledge with below
               
                <itemtype code="ItemTypeA" generate="true" autocreate="true"  jaloclass="de.hybris.platform.acceleratorcms.jalo.components.ItemTypeA">
                <description>It represents ItemTypeA.</description>
                <attributes>
                <attribute qualifier="myCustCustomerId1" type="java.lang.String" generate="true" autocreate="true">
                                <persistence type="property" />
                                <description>It is localized customerId of the everyreply user.</description>
                </attribute>
                </attributes>
                </itemtype>
                 will above throw build error?
                 
                 No, above will not throw build error
                 
    Again
                 
                 <itemtype code="ItemTypeA" generate="true" autocreate="true" extends="GenericItem" jaloclass="de.hybris.platform.acceleratorcms.jalo.components.ItemTypeA">
                <description>It represents ItemTypeA.</description>
                <attributes>
                <attribute qualifier="myCustCustomerId1" type="java.lang.String" generate="true" autocreate="true">
                <persistence type="property" />
                <description>It is localized customerId of the everyreply user.</description>
                </attribute>
                </attributes>
                </itemtype>

              will above throw build error?
               
                Yes , above will throw build error and you must be define deployment table. so after giving extends="GenericItem" rules will also apply here.
               
               
Again
               
                <itemtype code="ItemTypeA" generate="true" autocreate="true" extends="GenericItem" jaloclass="de.hybris.platform.acceleratorcms.jalo.components.ItemTypeA" abstract="true">
                <description>It represents ItemTypeA.</description>
                <attributes>
             <attribute qualifier="myCustCustomerId1" type="java.lang.String" generate="true" autocreate="true">
                <persistence type="property" />
                <description>It is localized customerId of the everyreply user.</description>
                </attribute>
                </attributes>
                </itemtype>
               
                will above throw build error ?
                 
                 No, In case abstract="true" there is no require to give deployment table while build.development.mode=true

               
B. if build.development.mode=false in local.properties file then Build process will not checks the missing deployments               


Hybris recommend

1. It is not recommend to build.development.mode=false because in this case there will storing many item types in GenericItem table will decrease the performance and possibility of data truncation due to columns limit in the table.
2. Deployment table should not be defined for any Item type if there is already a deployment defined for its super type otherwise it will decrease the performance as it has to perform multiple joins while retrieving.