Friday, 7 November 2014

Liferay + Solr Configuration

Steps to configure Solr on Windows with Liferay

I have configured Solr for below environment
>    apache-solr-1.4.1
>    apache-tomcat-7.0.47
>    liferay-portal-6.1.20-ee-ga2

1)    Download Apache Solr 1.4.1
2)    Unzip downloaded .zip file on the location D:/runtime/apache-solr-1.4.1
3)    Copy war file D:/runtime/apache-solr-1.4.1/dist/apache-solr-1.4.1.war to D:/runtime/apache-solr-1.4.1/example/solr
4)    Go to the location D:/runtime/apache-solr-1.4.1/example/solr/conf/
5)    Open file "solrconfig.xml" from above location
6)    Search for the tag "<dataDir>${solr.data.dir: ./solr/data}</dataDir>"
7)    Replace the above tag like below
    "<dataDir>${solr.data.dir:D:/runtime/apache-solr-1.4.1/example/solr/data}</dataDir>"
    (This is the data folder where all the solr indexes will be created)
   
Lets run the solr instance on the plain apache tomcat instance
(In our case it is "apache-tomcat-7.0.47")

1)    Extract the "apache-tomcat-7.0.47" on the location "D:\bundle\solr"
2)    Create a below folder structure if not already available
    D:\bundle\solr\apache-tomcat-7.0.47\conf\Catalina\localhost
3)    Create a file on above path with the name "solr.xml"
4)    Add below content inside "solr.xml" file
    <?xml version="1.0" encoding="utf-8"?>
    <Context docBase="D:/runtime/apache-solr-1.4.1/example/solr/apache-solr-1.4.1.war" debug="0" crossContext="true">
    <Environment name="solr/home" type="java.lang.String" value="D:/runtime/apache-solr-1.4.1/example/solr" override="true"/>
    </Context>

5)    Start tomcat to monitor logs. Make sure that there are no logs available.
    You should see below message under logs to make sure that server is started properly.
   
    INFO: Deploying web application directory D:\bundle\solr\apache-tomcat-7.0.47\webapps\examples
    Nov 07, 2014 4:21:58 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFO: Deploying web application directory D:\bundle\solr\apache-tomcat-7.0.47\webapps\host-manager
    Nov 07, 2014 4:21:58 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFO: Deploying web application directory D:\bundle\solr\apache-tomcat-7.0.47\webapps\manager
    Nov 07, 2014 4:21:58 PM org.apache.catalina.startup.HostConfig deployDirectory
    INFO: Deploying web application directory D:\bundle\solr\apache-tomcat-7.0.47\webapps\ROOT
    Nov 07, 2014 4:21:58 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-apr-8080"]
    Nov 07, 2014 4:21:58 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-apr-8009"]
    Nov 07, 2014 4:21:58 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 4928 ms

   
6)    Confirm from browser that server is working properly
7)    Hit "http://localhost:8080/solr/"
8)    You should see below message in browser
    Welcome to Solr!
    Solr Admin
9)    If you are able to see above message, congratulations we are done with solr setup

Now, lets see the steps to integrate solr with Liferay.

1)    Extract "liferay-portal-6.1.20-ee-ga2" to the location "D:\bundle\solr"
2)    Download solr plugin from net in my case it is as below
    15187207_18881208_18881218.lpkg
    (Make sure that it is compatible with your Liferay)
3)    Put the solr plugin in the location "D:\bundle\solr\liferay-portal-6.1.20-ee-ga2\deploy
4)    Go to the location D:\bundle\solr\liferay-portal-6.1.20-ee-ga2\tomcat-7.0.27\conf
5)    Open server.xml file to change the port (Need to change as tomcat is already using default ports)
    Change below ports:
        >    <Server port="9005" shutdown="SHUTDOWN"> from <Server port="8005" shutdown="SHUTDOWN">
        >    <Connector port="9080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8" />

            from
            <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8" />

        >     <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
            from
             <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
6)    Start the liferay tomcat server
7)    Monitor tomcat logs for exceptions if any
8)    You should see below message in tomcat to make sure that tomcat is started successfuly
    Nov 7, 2014 10:52:56 AM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    Nov 7, 2014 10:52:56 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-9080"]
    Nov 7, 2014 10:52:56 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-bio-9009"]
    Nov 7, 2014 10:52:56 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 45386 ms
9)    Shutdown both the servers
    >    apache-tomcat-7.0.47
    >    liferay-portal-6.1.20-ee-ga2
10)    Go to the location D:\bundle\solr\liferay-portal-6.1.20-ee-ga2\tomcat-7.0.27\webapps\solr-web\WEB-INF\classes\META-INF
11)    Open file "solr-spring.xml"
12)    Search for the tag <bean id="com.liferay.portal.search.solr.server.BasicAuthSolrServer"
    (Replace the constructor-argument as below "<constructor-arg type="java.lang.String" value="http://localhost:8080/solr" />")
13)    Go to the location "D:\bundle\solr\liferay-portal-6.1.20-ee-ga2\tomcat-7.0.27\webapps\solr-web\WEB-INF\conf"
14)    Copy the file "schema.xml"
15)    Go to the location D:\runtime\apache-solr-1.4.1\example\solr\conf
16)    Paste the "schema.xml" file in this location (Need to overwrite file)
17)    Start "apache-tomcat-7.0.47" server, once it is up then start "liferay-portal-6.1.20-ee-ga2"
18)    Go to the Liferay Control panel -> Server Administration -> Resources
19)    Click on the "Reindex all search indexes"
20)    Indexes will be generated on the path "D:\runtime\apache-solr-1.4.1\example\solr\data"

We are done with integration of liferay with solr.

Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics

Thursday, 25 September 2014

Start liferay tomcat in a debug mode

1) Open the "....\liferay-portal-6.1-.....\tomcat\bin\catalina.bat" file (for windows)

2) Search for "DEBUG_OPTS" and replaced whole line with below content
set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044

3) Start tomcat with "....\liferay-portal-6.1-.....\tomcat\bin\startup.bat"

4) Inside Liferay IDE/Eclipse go to "Run" -> "Debug Configurations..."

5) Go to "Remote Java Application" and double click on it

6) Give "Name" : "xyzportlet-debug"

7) Project : "Need to select via {Browse} option"

8) Inside "Connection Properties"
    "Host" : "localhost"
   "Port" : "1044" (which we have specified in "catalina.bat" file)

9) Attach source of the project via "Source" tab of a wizard

10) Click on "Apply" and "Debug"

11) Set the break point in your source code (Point where you want to break the execution and debug)

That is it. We are all set to debug our code. Now, access your code via "Browser" and enjoy debugging.

Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics

Wednesday, 24 September 2014

How to check SQL Server Database size

1) Open "Microsoft SQL Server Management Studio Express"
2) Open "New Query" window
3) Fire below query to select database whose size we want to check
     use {database name};
4) Execute above command via pressing "f5"
5) So far, we have selected database whose size we want to check.
6) Fire below query to get size
            "    SELECT
              database_name = DB_NAME(database_id)
            , log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
            , row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
            , total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
            FROM sys.master_files WITH(NOWAIT)
            WHERE database_id = DB_ID() -- for current db
            GROUP BY database_id
"
6) You will see result in below format
    "database_name" : "log_size_mb" : "row_size_mb" : "total_size_mb"

Cheers!
Henal Saraiya

Steps to verify Liferay service via SOAP UI

1)    Download SOUP UI (http://softlayer-sng.dl.sourceforge.net/project/soapui/soapui/5.0.0/SoapUI-x32-5.0.0.exe)
2)    Get list of services exposed by Liferay
    -    Hit URL : http://<server>:<port>/api/secure/axis
3)    Open SOAP UI ("C:\Program Files (x86)\SmartBear\SoapUI-5.0.0\bin\SoapUI-5.0.0.exe")
    -    Click on File -> New SOAP Project
    -    Project Name : "Portal_PortalService"
    -    Initial WSDL : "http://localhost:8080/api/secure/axis/Portal_PortalService?wsdl"
    -    Click on "OK"
4)    Under "Projects" our project will get list down
5)    Explore project(click "+" sign) to see list of operations/methods
6)    Double click on "getBuildNumber" -> "Request1"
7)    That will open a new window where we can specify input parameters for the method
8)    Click on "Authorization" tab of "Request1" window
9)    In "Authorization:" dropdown select "Add New Authorization"
10)    Select "Type" : "Basic" (Inside "Add Authorization" popup)
11)    Click on "Ok"
12)    A new screen will appear under "Authorization" section
13)    Give "UserName" & "Password" (liferay's screenname & password)
14)    Let other options as it is i.e.(Default options)
    -    Domain : ""
    -    Pre-emptive auth: "Use Global Preference"
    -    Outgoing WSS : ""
    -    Incoming WSS : ""
15)    Click on green arrow under "Request 1" screen (Left top) (Its use to Submit request to specified endpoint URL)
16)    On the right section of "Request 1" section you will be able to see response in XML/Raw format

Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics

Friday, 19 September 2014

Steps to migrate content from DataBase to AdvanceFileSystem

Steps to migrate liferay content from DataBase to AdvanceFileSystem and upload a content using "AdvancedFileSystemStore"

1)    Stop tomcat server
2)    Add below property in portal-ext.properties file
        #
        # FileSystemStore
        #
        dl.store.file.system.root.dir={Path of your drive}
3)    Start server
4)    Go to "Control Panel"
5)    Go to "Server" -> "Server Administration" -> "Data Migration"
6)    select dl.store.impl to "AdvanceFileSystemStore"
7)    Click on "Execute"
8)    Once migration task is completed, stop server
    [Note: You should see below message in tomcat log]
   
        12:11:31,141 INFO  [com.liferay.portal.plugin.PluginPackageUtil][PluginPackageUtil:1421] Checking for available updates
        12:11:31,143 INFO  [com.liferay.portal.plugin.PluginPackageUtil][PluginPackageUtil:1465] Finished checking for available updates in 1 ms
        12:12:25,676 DEBUG [http-bio-8080-exec-8][MaintenanceUtil:64] Executing com.liferay.portal.convert.ConvertDocumentLibrary
        12:12:25,692 INFO  [liferay/convert_process-1][ConvertProcess:41] Starting conversion for com.liferay.portal.convert.ConvertDocumentLibrary
        12:12:25,703 DEBUG [liferay/convert_process-1][MaintenanceUtil:64] Migrating 18 document library files
        12:12:26,743 DEBUG [liferay/convert_process-1][MaintenanceUtil:64] Migrating message boards attachments in 32 messages
        12:12:26,804 DEBUG [liferay/convert_process-1][MaintenanceUtil:64] Migrating wiki page attachments in 0 pages
        12:12:26,813 DEBUG [liferay/convert_process-1][MaintenanceUtil:64] Please set dl.store.impl in your portal-ext.properties to use com.liferay.portlet.documentlibrary.store.AdvancedF
        ileSystemStore
        12:12:26,814 INFO  [liferay/convert_process-1][ConvertProcess:47] Finished conversion for com.liferay.portal.convert.ConvertDocumentLibrary in 1122 ms

8)    Make sure that content is migrated and available in the folder specified in point#2 i.e. {Path of your drive}       
9)    Make below changes in portal-ext.properties
   
    ##### For Advance File System Store
    dl.store.impl=com.liferay.portlet.documentlibrary.store.AdvancedFileSystemStore
   
    #comment out below line which was added earlier
    #
    # Set the name of a class that implements
    # com.liferay.portlet.documentlibrary.store.Store. The
    # document library server will use this to persist documents.
    #
    #dl.store.impl=com.liferay.portlet.documentlibrary.store.JCRStore
    jcr.initialize.on.startup=false

10)    Start Server
11)    Upload a document / images using "Document and Media"
12)    Go to the location specified in point#2
13)    Make sure content is available in it

So far, we have migrated content from Database to "AdvanceFileSystemStore" and uploading content via "AdvanceFileSystemStore" is done.

Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics

Thursday, 18 September 2014

Liferay + SQL Server / Steps for Installation of SQL Server 2005

Steps for Installation of SQL Server 2005

1)     Install SQL Server 2005 with below options
    >    Use sql authentication instead of windows authentication
    >    Give User Name & Password as "sa" and "sa"
2)    Configuration
    >    Open C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft SQL Server 2005\Configuration Tools\SQL Server Configuration Manager
    >    Navigate "SQL Server 2005 Network Configuration" > "Protocols for SQLEXPRESS"
    >     double click "TCP/IP"
    >    Go to "IP Address" tab
    >    Under "IP All" section give TCP Port "1433"
    >    "Apply" and "Ok"
    >    Navigate to "SQL Server 2005 Services"
    >    Restart Service of "SQL Server (SQLEXPRESS)" (available on right tab)
3)    Verify SQL Server's service is up and listening on port 1433   
    >    Go to command prompt
    >    type "telnet localhost 1433" and hit enter
4)    Create Database with "Microsoft SQL Server Management Studio Express"
    >    Right click on "Databases" -> "New Database"
    >    Give database name "test"
    >    Click on "Ok"
5)    Create a User and give permission to newly created DB
    >    Go to "Object Explorer"
    >    Click on "Security"
    >    Go to "Logins"
    >    Right click on it and select "New Login"
    >    Give "Login Name"
    >    select "SQL Server authentication"
    >    give "Password" & "Confirm password"
    >    Uncheck "Enforce password policy"
    >    From the "Default database" select DB (on which permission you want to grant)
    >    Click on the "Server Roles" (under "Select a page" on left column inside "Login-new" wizard)
    >    Check "sysadmin"
    >    Move to "User Mapping"
    >    Select the databases whose mapping you want to do with new user (in our case its "test")
    >    Click on "Status" section on left column
    >     Let the default settings as it is i.e.
        1)    Permission to connect to database engine : "Grant"
        2)    Login : "Enabled"
    > Click on "Ok"

So far we have done SQL Server setup, DB created and User is mapped to database with required permissions.

Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics