Ansible role to install maven with yum

September 8, 2017

It should work on CentOS, Amazon Linux, etc.

– name: “Download maven”
dest: /etc/yum.repos.d/epel-apache-maven.repo
validate_certs: no
timeout: 60
mode: 0777
register: apache-maven

– replace:
path: /etc/yum.repos.d/epel-apache-maven.repo
regexp: ‘\$releasever/’
replace: ‘6/’
backup: yes

– name: “Install dependencies”
name: “{{ item }}”
state: present
update_cache: yes
– apache-maven

Amazon Linux useful stuff

August 24, 2017

The easiest way to get ec2 instance remediation via Auto Scaling is to implement health check API and put it behind Load Balancer. But still it can take 5-10 mins till ELB detects ec2 failure and tells ASG to tear it down.

EC2 System and Instance Status Checks monitor CPU, memory, os, file system, network and hardware of the instance (like loss of network sudo ifdown eth0). But they don’t give a sh*t about failure of custom software running on the instance – unless you tell them to.

This is how ec2 instance can explicitly tell Auto Scaling Group to replace it:

AWS_ACCESS_KEY_ID=AMYIDMYIDMYQ AWS_SECRET_ACCESS_KEY=0MYKEYMYKEYMYKEYMYKEYK aws autoscaling set-instance-health --instance-id "$(curl" --health-status Unhealthy --region ap-southeast-2

It should have AWS credentials of a user with proper IAM permissions though.

Ansible playbook snippets

August 18, 2017


Task: Get AMI Ids of AWS ec2 instances:

- name: get EC2 facts
  action: ec2_facts
  register: the_facts

– debug: var=the_facts.ansible_facts.ansible_ec2_ami_id

Task: Get python disto in use:

- name: Find the path to the python interpreter
  command: which python
  register: pythonpath

Playbook: Create an EC2 instance

- name: AWS connect
  hosts: localhost
  connection: local
  gather_facts: false
  - name: Launch new Instance
    become: false
      aws_access_key: AKIAJBSRYRJL4JIWSAGQ
      aws_secret_key: 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
      instance_tags: "Name=AnsibleTest"
      group_id: sg-c8af43ae
      instance_type: t2.micro
      image: ami-10918173
      wait: true
      region: ap-southeast-2
      keypair: ai-apphost
      vpc_subnet_id: subnet-f2011596
    register: ec2

Task: display IDs of running instances:

- ec2_remote_facts:
 region: ap-southeast-2
 register: thefacts

# - debug:
 # with_items: "{{thefacts.instances}}"
 - debug: var=item.0
 - "{{ thefacts.instances|map(attribute='id')|list }}"

Inspired by :

Java and Big Data

March 22, 2016

Recently I came across an interesting question at Quora. Someone was asking which is better to learn as a fresher, Java or Big Data. Most of the answers were about comparing apples to apples and oranges to oranges, which really makes perfect sense but doesn’t help the inquirer.

Over my 10+ years of experience with Java, I used it across many platforms and domains and believe there are many more applications of it I can not even imagine. On the other hand, Big Data is promising and fancy. I’m pretty sure it’s possible to have it all and learn them both.

I think the question is more about how soon you can earn money with your knowledge. I believe, earning money in IT doesn’t differ much from any other R&D industry: first you invest your time and your mind, as much as you can, and then convince an employer to pay you rather than your competitors.

Talking about competition, Java as a buzzword is much older than Big Data. There are crowds of people having Java in their resumes for 10-15 years and, what’s more important, deep and extensive experience with it. Alternatively, I personally know few people with a PhD degree in Big Data whom I wouldn’t dare to compete with. Luckily, they are not looking for a job, because they are booked out for few years ahead with sophisticated projects for banks, insurers and government.

So my opinion is, to be able to do the job in these days – study them both and a platform like Hadoop as well. But put the Big Data first in your resume.

Calling Spring web services from jQuery

November 11, 2011

I love both frameworks because they are awesome. So here is how you can make Spring 3.0 and jQuery 1.5 work smoothly together, letting you forget about integration pain and concentrate on actual functionality.

Annotate your Spring service like:

public class BankController extends BaseJSONController implements BankControllerIntf {
	ConfigurationDaoIntf dao;
	public @ResponseBody Map<String, String> getList(Session session,
			@RequestParam("type") String type,
			@RequestParam(value="report", required = false) String report,
			HttpServletResponse response) {
               // backend functionality here

BTW don’t forget to instruct Spring to resolve the @Controller-annotatated services in the applicationContext.xml:

<context:component-scan ....>
    <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>

and include Jsonp filter to the server configuration, just next to the Hibernate Open Session In View Filter.

Then make jQuery call it:

					{ "type": $("input[name=type]").val(),
					  "report": $("input[name=report]").val()
				    function(data) {
						// UI manipulation here
						var options = $("#portfolioId");
						$.each(data, function(i, object) {
							options.append($("<option />").val(i).text(object));

and it will deliver the data straight to your web page. That’s it!

Spring 3 dependency management issue

September 28, 2010

In 2010, Spring 3 was released and it was a significant event for all Java devs.

An open issue in Spring 3 is dependency (jar) management. Doc says to use external framework like Maven, ivy or OSGi. Having no experience with ivy, I started digging towards the other twos. Maven is what I love and successfully use for the last 2 years.

Mentioning here OSGi was quite a surprise for me. But the more I learned about the framework, the more I liked the approach it offers. Actually publish-find-bind services model is not new (there was UDDI 10 years ago) but keeping it in line with Java 5 and EJB 3 and being supported by Eclipse, SpringSource, Glassfish, JBoss, Weblogic and Websphere makes it a powerful competitor to Maven.

Also, there’s something interesting gonna happen around web UI in the next versions of Spring. They ditched support for Struts 1 so they have to offer something instead to take care for C in MVC. Webflow seems pretty perspective but  heaps of XML config must go to make the development less painful. It longs to be replaced with annotations – and they started to move towards it with @MVC. Web UI components should be managed and reused somehow and it’s absolutely unclear how to do it with screens, namespaces, templates, .js, .css, etc.

Configuring project properties in Spring

July 6, 2009

It is useful to have all project properties in a text file and make Spring care of objects initialisation, especially if you have multiple environments (dev, stage, prod, etc). For this, I use placeholders like ${mybean.itsproperty} in spring-config.xml – just add a couple of configurers there:

< bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

< property name='location'>< value>config/< /value>< /property>

< /bean>

< bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">

< property name='location'>< value>config/< /value>< /property>

< /bean>

Then I can use placeholders like:

< bean id="coolDS" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

< property name="driverClassName">< value>${coolDS.driverClassName}< /value>< /property>


< /bean>

< bean id="config" class="com.mycompany.Config" scope="singleton">

< property name="incoming_directory">< value>${config.incoming_directory}< /value>< /property>


< /bean>

Note that placeholders should be in format beanName.propertyName if you want to override some environment-specific properties.

Top code comments

May 9, 2009

The best code comments I’ve ever seen:

// I dedicate all this code, all my work, to my wife, Darlene, who will
// have to support me and our three children and the dog once it gets
// released into the public.

* You may think you know what the following code does.
* But you dont. Trust me.
* Fiddle with it, and youll spend many a sleepless
* night cursing the moment you thought youd be clever
* enough to “optimize” the code below.
* Now close this file and go play with something else.

//When I wrote this, only God and I understood what I was doing
//Now, God only knows

Long John; //Silver

//Don’t edit — This configuration file is automatically generated by magic…

.xlsx format (MS Excel 2007)

February 6, 2009

Today I’ve sorted out parsing of the new MS Excel 2007 .xlsx format. It turned out to be just a .zip archive with a bunch of .xml files inside:


As it’s expected, the data I need are in \xl\worksheets\sheet1.xml file, which is ordinary XML file:

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes” ?>
– <worksheet xmlns=”; xmlns:r=””&gt;
– <cols>
<col width=”20.7109375″ />
– <sheetData>
– &lt row r=”2″ spans=”2:12″ s=”9″ customFormat=”1″ ht=”23.25″>
– <c r=”B2″ s=”22″ t=”s”>
<v>16< /v>

So I think parsing this in Java will be easier than parsing old .xls format using Apache POI

SVN client for Eclipse update

January 12, 2009

After updating the project from repository using Ant script (and upper version of svn client – 1.5), I came through the problem:

org.tigris.subversion.javahl.ClientException: svn: This client is too old to work with working copy XXXXX; please get a newer Subversion client

The cause is that svn client 1.5 changes the svn setup files so svn client 1.4 can not read them anymore. The remedy is installing new version of Subclipse plugin, here the process is described:
subclipse: Installation