My Darling Little Son, Ryan!

Starting Java Application in init.d without Long Classpath in Command Line

The key is to use interesting ‘/usr/bin/env’ command with launches Java process with given environment variables (e.g. CLASSPATH) and key return Java’s PID :)


. /lib/lsb/init-functions

options="CLASSPATH=$CP /usr/lib/jvm/java-6-sun/bin/java $JAVA_OPTS $MAIN_CLASS $OPTS"

if start-stop-daemon -v -b -m --oknodo -c $USER --start --quiet -d $bin_dir --pidfile "$pid_dir/myapp-$1.pid" --exec /usr/bin/env -- $options; then
log_end_msg 0
else
log_end_msg 1
fi

so you can type 'ps auxw | grep java' and enjoy short process names. long live linux!

Akka Project

I was following Jonas Boner on his twitter and github recently.

Gradually I saw that he and his team in scalablesolutions.se are building blocks of an enterprise stack and I was just wondering where is this heading to.

Then I came across http://akkasource.org/ . The thing Jonas was building step by step!

To be honest it really attracted at the first sight. As a distributed env programmer, Akka has everything I had to build for my own for years. JGroups clustering, K/V database, OTP, Actors, any many others that I was not even imagining to have: STM.

And the whole stack runs on Scala/Java.

Thanks Jonas for building such an interesting stack. I will dedicate the first possible time to evaluate it.

Apache HTTPd Reverse Proxy and Tomcat CAS

Having a correct combination of front-end Apache HTTPd Reverse Proxy server and back-end Tomcat hosted CAS was not as easy as it seems for me.

I could have used mod_auth_cas but decided to relay only on jk based proxy.

Here is my config:

  • Apache HTTPd 2.2
  • Apache Tomcat 6.0
  • CAS 3.3.1
  • Balancer (mod_proxy + proxy_ajp + proxy_balancer)

deployment model:

  • Front-end machine (ip: 192.168.183.3) running httpd on ports 80, 443.
  • CAS back-end app running tomcat on ports 18180 (http) and 18109 (ajp)
  • Another back-end app on the same box which uses CAS and runs on ports 18080 (http) and 18009 (ajp)

Steps:

0. Add proper hostnams to /etc/hosts. In my case all (profiles.myraysaz.com) simply points to 192.168.183.3

  1. CAS Tomcat
    1. Configure your CAS box. I have deployed my CAS application under “/auth” in Tomcat (i.e. rename cas-3.3.1 in webapps to auth) .
    2. set correct paths in your cas.properties. This is mine:
      cas.properties
      cas.securityContext.serviceProperties.service=https://profiles.myraysaz.com/auth/services/j_acegi_cas_security_check
      cas.securityContext.casProcessingFilterEntryPoint.loginUrl=https://profiles.myraysaz.com/auth/login
      cas.securityContext.ticketValidator.casServerUrlPrefix=https://profiles.myraysaz.com/auth
      cas.themeResolver.defaultThemeName=default
      cas.viewResolver.basename=default_views
      host.name=profiles.myraysaz.com
      database.hibernate.dialect=org.hibernate.dialect.HSQLDialect
    3. Here is server.xml of this box. Pay attention to proxyName and proxyPort!
      server.xml
      <?xml version='1.0' encoding='utf-8'?>
      <Server port="18105" shutdown="SHUTD0WN">
      
        <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />
        <Listener className="org.apache.catalina.core.JasperListener" />
        <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
        <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
      
        <Service name="Catalina">
      
          <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
              maxThreads="1000"
              minSpareThreads="50"/>
      
          <Connector executor="tomcatThreadPool"
                     port="18180"
                      protocol="HTTP/1.1"
                     connectionTimeout="20000"
                     redirectPort="443"
                      enableLookups="false"
                      proxyName="profiles.myraysaz.com"
          />
      
          <Connector executor="tomcatThreadPool"
                     port="18109" protocol="AJP/1.3"
                     redirectPort="443"
                      enableLookups="false"
                      proxyName="profiles.myraysaz.com"
          />
      
          <Engine name="Catalina" defaultHost="profiles.myraysaz.com">
            <Host name="profiles.myraysaz.com"  appBase="webapps"
                  unpackWARs="false" autoDeploy="true"
                  xmlValidation="false" xmlNamespaceAware="false">
            </Host>
          </Engine>
        </Service>
      </Server>
    4. Be sure this is working by pointing browser to http://ip:18080/auth
  2. Configure HTTPd.
    1. Enable required modules:
      a2enmod proxy
      a2enmod proxy_ajp
      a2enmod proxy_balancer
    2. Here is my host file definition in sites-enabled
      000-profiles.myraysaz.conf
      <VirtualHost 192.168.183.3:80>
              ServerName profiles.myraysaz.com
              ServerAdmin amin@raysaz.com
      	DocumentRoot /
      
              ErrorLog /var/log/apache2/profiles/error.log
              LogLevel warn
              CustomLog /var/log/apache2/profiles/access.log combined
      
      	ProxyRequests Off
      	ProxyPreserveHost On
      
      	<Proxy *>
      	    Order deny,allow
      	    Allow from all
      	</Proxy>
      
      	ProxyPass /auth balancer://casCluster/auth stickysession=JSESSIONID|jsessionid
              ProxyPassReverse /auth balancer://casCluster/auth
              <Proxy balancer://casCluster>
                      Order deny,allow
                      allow from all
                      #BalancerMember ajp://192.168.183.3:18109
                      BalancerMember ajp://profiles.myraysaz.com:18109
              </Proxy>
      
      	ProxyPass / balancer://profilesCluster/ stickysession=JSESSIONID|jsessionid
              ProxyPassReverse / balancer://profilesCluster/
              <Proxy balancer://profilesCluster>
                      Order deny,allow
                      allow from all
                      BalancerMember ajp://profiles.myraysaz.com:18009
              </Proxy>
      </VirtualHost>
      
      <VirtualHost 192.168.183.3:443>
              ServerName profiles.myraysaz.com
              ServerAdmin amin@raysaz.com
      	DocumentRoot /
      
              ErrorLog /var/log/apache2/profiles/error-ssl.log
              LogLevel warn
              CustomLog /var/log/apache2/profiles/access-ssl.log combined
      
      	ProxyRequests Off
      	ProxyPreserveHost On
      
      	<Proxy *>
      	    Order deny,allow
      	    Allow from all
      	</Proxy>
      
      	ProxyPass /auth balancer://casCluster/auth stickysession=JSESSIONID|jsessionid
              ProxyPassReverse /auth balancer://casCluster/auth
              <Proxy balancer://casCluster>
                      Order deny,allow
                      allow from all
                      BalancerMember ajp://profiles.myraysaz.com:18109
              </Proxy>
      
      	ProxyPass / balancer://profilesCluster/ stickysession=JSESSIONID|jsessionid
              ProxyPassReverse / balancer://profilesCluster/
              <Proxy balancer://profilesCluster>
                      Order deny,allow
                      allow from all
                      BalancerMember ajp://profiles.myraysaz.com:18009
              </Proxy>
      
      	SSLEngine On
      	SSLCertificateFile    /etc/ssl/profiles/profiles.myraysaz.com.crt
      
      </VirtualHost>
    3. you can make a fake SSL using:
      make-ssl-cert /usr/share/ssl-cert/ssleay.cnf auth.myraysaz.com.crt
    4. This config is able to stick on session id and supports multiple back end cas-servers.
  3. SSL+CAS
    CAS (java) needs access your SSL certificate. If you make a fake one using SSL, do as follows to import it to Java.

     

    1. Eliminate private key part from fake certificate.
      cp profiles.myraysaz.com.crt profiles.myraysaz.com.crt-only
      vim profiles.myraysaz.com.crt-only
    2. import it to java
      sudo keytool -import -file profiles.myraysaz.com.crt-only -alias mycas -keystore /opt/java/jdk1.6.0_06/jre/lib/security/cacerts

My Architectural Headings

When I build a system, I try to:

1. Avoid ORM
they cause more trouble than what they solve. for simple cases I recommend pure JDBC and for complex cases i enjoy iBATIS (and recently IBM pureQuery)

2. Use Messaging
messaging is not just using a message broker, it is a mental model for designing messages first and then services (Contract First Design).

3. Insist on functional paradigm
insist in immutability, finalizing, constructor dependency injection and recursion.

4. Use In Memory Database and In Memory Data Grids
Rare systems require IMDG/IMDB solutions. We call such a systems XTP (extreme-transaction processing) systems. In such cases we ought to put data in memory rather on disk. I have used GigaSpaces, and Coherence in the past and now work closely with Infinispan. TimesTen is a another solution that an XTP architecture should have an eye on.

5. Reduce contention
EDA As much as possible.

6. Insist on Testing and Coverage

7. Live in -10/-5 years from Now
I don’t use tools unless they are proved or unless I have no other choice!

8. Java is not the Only one!
I am a Java architect but I recommend and learn other systems built with Python, C, Erlang and Scala as well.

My CPU is full but I have not crashed yet!

No doubt I am on the busiest days of my life, working on wide range of projects and companies. This much has gathered not necessarily on my own will but from the shrinking society of experienced software engineering in my country, Iran. Everyone (with even two or three years of experience) decides to leave to other countries (esp Canada and Australia) and what is left is tens of dandling projects looking for a lead in any price. This processes has speed up after fake election here in Iran and I do hope that I myself join these fellows soon too.

Sometimes I myself wonder how do can I handle so much work? It became so strange to I myself when I decided to sit down and make this list:

1 – DPI (Data Processing Company of Iran)

I started to tighten my career in DPI after my friend Ara left to US a month ago.

2 – MAGFA (IT Development Center)

My career in MAGFA dates back to six years ago. We build and maintain SMS oriented products. Now we have build a modern engine with strong clustering capabilities. Team members have codenamed this an Palang (meaning leopard in Farsi). Palang handles about 20% of our daily load by now and we have plan to put in under full load in about three months. A lot of work to do, in a great domain including cool staff such as Java, Erlang, OpenMQ and Perlbal.

3 – Raysaz

I help raysaz to run their epayment and eticketing systems. We have huge load for some concerts and although we have strong machines but still there is much space for optimization and tuning. Most of my work is to help development team take correct decisions and tune our stack on top of Linux/Tomcat/Apache.

4 – Teenab

GlusterFS + Amazon S3!

5 – ?

I do X for Y (now find X and Y)!

6 – Navaco

Working as a banking systems consultant (based on my previous experience in Caspian and DPI) for Navaco which is hoping to do core system development for Bank Maskan one day. I also try to help DPI and Navaco move toward a mutual agreement these days. (mission impossible IV)

7 – ONT Soft

Literally I am the lead of support team in ONT soft for the contract we have with NSN (Nokia Siemens Networks) in Iran to support IACC Proxy, MM1 Proxy and L5 balancers. Hopefully they all work well and there is not much work in this field right now.

8 – Community

I keep reading and contributing to projects. I am interesting of reading about modern highly available and high-traffic architectures and paradigm. I sometimes contribute to Iran Java Users Groups mailing list and meeting. I am also very interested in JBoss new IMDG solution (infinispan) and keep following and testing every new release.

I also instruct myself how to be a better agile coach and coordinator in a team. How to remain polite and friendly and yet take the most possible from junior developers and also teach them a whole new things including correct programming paradigms, linux and documentation.

Functional programming has always been my interest and I dedicate sometime to improve my erlang and scala.

9 – Remain responsive for other project

I remain responsive and in touch for the most of the projects and companies I had worked for since most of the have live applications. A list of companies such as: Caspian (for Caspian Bank), Basamad AC&C (OPXi Manager), TeleXis (telecom billing system), and Pars Azarakhsh (Digital Library).

10 – Learn French

We plan to move to Quebec. Hence i should know some french.

Wow.. the list contains at least 5 major works and 5 minor. An this becomes more strange considering that I am not a only-talks consultant but a coder man which manages and coordinates most of the above teams and write down hundreds lines of code each day.

And yet I try to try to remain a (relatively) responsible husband and member of the family. I dedicate time to remain in family ring and visit parents regularly. We also wait for our first son – Ryan – to come within a month :)

Thanks the Load for all the power and capabilities he’d given to me.

Basic rabbitmqctl Bash Completion

_rabbitmqctl()
{
        local cur prev opts
        COMPREPLY=()
        cur=”${COMP_WORDS[COMP_CWORD]}”
        prev=”${COMP_WORDS[COMP_CWORD-1]}”

        #
        #  The basic options we’ll complete.
        #
        opts=”stop stop_app start_app reset force_reset cluster status rotate_logs add_user delete_user change_password list_users add_vhost delete_vhost list_vhosts map_user_vhost unmap_user_vhost list_user_vhosts list_vhost_users list_queues list_exchanges list_bindings list_connections”

        #
        #  Complete the arguments to some of the basic commands.
        #
        # TBD

        COMPREPLY=($(compgen -W “${opts}” — ${cur}))
        return 0
}

complete -F _rabbitmqctl rabbitmqctl

PMP or SBA?

I feel myself at the junction of “Pure Message Passing” and “Space Based Architecture”! which one is more suitable for developing high-throughput systems?

The first solution pure-message-passingĀ  (where i feel myself quite a habitat) comes from the world of functional actor based systems well developed in Erlang and followed by its successors in Scala, Kilim or even JUC. Its side effect free nature makes it a perfect choice for highly concurrent, multi core domains but enforces its own programming model using messaging boxes and actors.

The second one, SBA (where i have applied for residency) comes from tuple spaces. a simple but strong paradigm first developed in Linda and followed by its worthy successor javaspaces and successfully used in domains such as orbitz and gigaspaces xap. Its share-take nature makes it a perfect choice for caching and in memory solution but again enforces its model to some extend which is well documented in xap’s PU.

These two model, although seem quite obverse in first sight, but share a lot in nature. they both introduce the separation of data and processor in an even driven paradigm. Even driven nature of these two models make both very strong for suitable todays complex and high demanding nature. and yes, both have their own mathematically proven theory behind.

Now the question comes in mind, which will be superior or will the both remain as competitor? maybe SBA since dummies don’t enjoy immutables? or maybe they collide into one single computational model? mixing quantum physics and relativity? cloud-computing? anyone?

Life is Beautiful

I feel deep happiness and joy these days…

Our cat – pishoo -  is back to garage, I found my beautiful hand-watch (which I had left in my desk drawer at Caspian), I have found a cool new swimming pool close to our house at Sohrevardi (which I get used to visit regularly 2-3 times a week), I am about to finalize my contract with company.com, we are going to go for holidays to Thailand in two weeks and then probably to Turkey for another business trip, and more over i receive endless love from my darling wife Ghazaleh just like always.

So what else does a man need to feel in heaven?

Places I Ever Wished To Work For

There are 3 companies which I always looked to work for:

  • Google, since knowledge is there; I sent my resume, they implicitly said  “Are you kidding?”
  • LShift, since we both love Erlang; again I sent my resume, the said “Come what may!”
  • Gigaspaces; I never dared to send a resume; sure they wont hire Iranians anyway.

And then comes this new position (which is not finalized yet but we are in good shape of progress) which seems to out-weight all these three. Now its my turn to say… come what may… :)

« Older entries