Archive

Archive for the ‘java’ Category

How I met my first NAS – Qnap or Synology

March 11th, 2010 Arun Manivannan No comments

I have a bad habit.  I buy impulsively.  But the good part about it is that when the pressure to buy becomes overwhelming, I wait.  I go back home and read every single word on the planet about what I wanted to buy in the first place.  Eventually, I end up buying something else.

A couple of weeks back, I read a blog about Thecus NAS drives and immediately wanted to buy one.  I wanted to own it on that very day.  Then the pressure built so much that I had to sit and let it mellow.  I googled.

The noise level of most Thecus drives was a huge turn off considering the high probability of getting murdered by my wife (I fondly remember the days when my desktop was louder than an average car on the road).  Netgear NVX and NV+ series were good but they are a bit pricey for the features they offer.

Forgot to mention that my drives will be primarily used for storage and as a torrent slave.  I will also be running a few services like Photo manager, Tomcat, iTunes (more services depends on the success in setting up DDNS) .  If it helps, I dont use windows at home (mac and linux) and I am planning for a RAID 5 setup.

So, I decided to get either the Synology of the Qnap drives.  Synology 1010 and Qnap 459 were my choices after long hours of search. These were the points that I considered.

1)   Buy an Intel Atom based drive because of the support for a variety of software packages.

2) 

QNAP models TS-459, 659, 859

+ high overall performance
+ supports scheduled power on and off
- no RAID 10 support
- no hybrid RAID functionality
- storage cannot be expanded with a companion unit (# drivebays is max, you could buy a 2nd unit of course or use one of the many ports) – No biggie (I backup using my USB drives)
+ has 5 USB 2.0 ports
+ has 2 eSATA ports
+ volume based encryption
+ built-in DHCP server
+ handy LCD display
+ USB Copy function on the frontpanel
+ supports the EXT4 filesystem (> 16 TB volumes)
+ supports WebDAV
+ advanced iSCSI support
+ all the drives are lockable with a key
+ in general, no problem with downgrading of firmware
- one year guarantee
+ great build quality
+ already much experience, add-on software and models available on x86 platform

Synology DS 1010+

- only supports scheduled power off
+ RAID 10 support
+ hybrid RAID functionality (SHR)
+ storage can be expanded (with the extra 5 drivebays case, however will eSATA connection become bottleneck?)
- has 4 USB 2.0 ports
- has 1 eSATA port
+ folder based encryption
- no built-in DHCP server
- no LCD display
- no USB Copy function on the front
- no EXT4 filesystem support (volumes > 16 TB volume will not be possible)
- no WebDAV support
- less advanced iSCSI support
- the drives are not lockable with a key
- in general, very problematic to downgrade firmware
- less models, less choice
+ three years guarantee
- build quality is not as good as QNAP
- first model based on x86 platform

Source : http://forums.smallnetbuilder.com/showthread.php?t=2855

3)  At the end of the read, I wanted to go for one of those Qnap drives - 459, 509 or 659. 659 was way above my budget but I wanted to keep it in the background because it had support for 6 drives and I can always buy 4 drives in the beginning and fill up the other drives on need basis.

Later, I read that RAID is not a backup (did i say that I am totally new to RAID and the whole world of NAS drives) and does not guarantee dataloss and that I will need to have another plan for backup. I then decided to use my USB drives for the important backups (mostly my son’s photos and videos).  So, it doesnt make any sense to buy a 659 for an extra 600 SGD. May be later, I can always go for another NAS for an extra 200 SGD and have it as a backup.

So, 509 and 459. 459 had an Atom Dual core processor and 509 had a Celeron processor. The best part about 509, though, is that you can upgrade the processor to something big (say, Core2Duo) but I always have the fear to open up my system after i burnt a couple of RAMs on my first desktop (a 16 MB was a 100 USD then. that burnt a lot of my fingers) and I found very few people upgrading their processor on a 509.  So, 459 it is.

Hard drives :

Then comes the problem about hard-drives. I wanted to buy the Seagate 1.5 TB 7200.11 or any other 2 TB drives so that i can make a good 6 TB out of my 4 slot 459 (2 TB gone for parity).  Later, I found that the 1.5 TBs are notoriously fault prone. The WD Caviar Greens play horribly with Qnaps (Google “site:forum.qnap.com Caviar Green”) and so are most of the other WD drives. The Caviar blacks 1 TB are excellent drives despite their noise level but some say that the noise and the clicks are that not that troublesome. schumaku from the forum is known for his expertise in harddrives. He was suggesting not to buy the highest capacity of any drive – they are known to create the highest number of problems. 

Most were complaining that Seagates gave a lot of problem and they had various problems with different drives and that they were unlucky.  (my luck factor is near to zero). I never wanted to take any risk.

The Hitachi Ultrastar A7K2000 is the best for Qnap drives. Everybody agrees to it but at 513 SGD for a 2 TB, I’ll give it a pass. Finally, I decided to go for Samsung drives F1 or F3.  They say that F3s should work very well but I dont see them on the Qnap compatibility list (http://www.qnap.com/pro_compatibility.asp).  So, here is my final configuration.

NAS :

Qnap 459 Pro (Intel Atom D510 1.66 GHz (Dual-Core) – RAM – 1GB DDRII (I might end up upgrading the RAM alone))

HDD:

4 * 1 TB (RAID 5) - Samsung Spinpoint F1 HE103UJ (buying RAID Class depends on availability)

Lunarcodes – Coding when the moon goes up

December 9th, 2009 Arun Manivannan No comments
After a lot of thought over the weekend, I decided to rewrite Fetch2Me in Java. Not that Python is bad. Python is brilliant. However, i felt that my code quality in Java (from where i come) is not yet production standard. Over the past year, i had the opportunity to open up a lot of open source projects and realised that my code quality is horrible. HORRIBLE !!!
So, this is the plan i came up with.  Bring together our old NIIT gang and –

1)    Rewrite Fetch2Me in Java using HttpUnit and Java Mail API
2)    Expose the core functionality of Fetch2Me as a REST service
3)    Write a front end for web access to the REST service. Typically we should be writing a Inbox like web page for checking gmail (or any mail for that case), sending mails (with and without attachments). This front end will be written using GWT and Guice.
4)    Write a Firefox plugin similar to the requirement in (3)
5)    SMS service should also be exposed as REST service.

Use Maven for build purposes and Git for source control.  Optionally use Hudson for continuous integration and come up with an Eclipse plugin. Write lots and lots of of JUnit test cases.  My gut feeling is that this should take at least a few months development time.
I am sure there are a million products out there which does the same thing but there are two important highlights in this effort.
1)  We get to learn a lot of new things, open up the source code of lot of other open source projects, started reading PHP, ASP.net, C#, Ruby, Python (and convert them to Java) — all those which we wouldnt have done in our day job. I thought we could learn by mistakes – both development and design, we could refactor the code as much as we want at any point of time in the project (we understand that optimizing early is a crime).
and
2)  Soon after we are done with increments in the project, we’ll open source it. People can just pick our code and host it in their domain and call it a day. I am sure many will find interest in our work and hopefully start using it.

Oracle buys Sun — The funny side

April 21st, 2009 Arun Manivannan No comments

I was reading this article on slashdot and found this response particularly interesting. :-)

What the fuck is “netbeans”?

They are the seeds of the internet. You plant some and sprinkle them with bits. Eventually they grow into a huge series of tubes. How do you think the internet was created? With lots and lots of netbeans.

RedHat Linux and Solaris, MySQL and Oracle, Bea backed Eclipse and NetBeans,  Peoplesoft, Siebel … good for Oracle but doesnt it sound more “Microsofty?”

Categories: Uncategorized, java Tags:

Exit code for Java programs — ERRORLEVEL, $?, $status

June 11th, 2008 Arun Manivannan No comments

Running a java program from your shell script is commonplace for Batch operations.  And the wrapper shell script doesnt know about the success/failure of the wrapped Java program unless we return an exit code. 

In most cases, we have the Java source on hand. For others who use a different mechanism to achieve the functionality of the batch operation, I am not sure how far this will be useful to you.

The only possible mechanism (at least that’s what i know) is to give out your exit code using the System.exit (int) method call.  I would suggest you to keep off status codes 0-255 because that is already reserved in Unix platforms (Solaris inclusive).

For the DOS, you use the ERRORLEVEL to catch your exit status.

echo %ERRORLEVEL% should give you a number indicating the exit code of your last executed program.

For bash and ksh, it is $?  as in “echo $?”

For cshell, it is $status as in “echo $status” which returns.  I dont see $? working on cshell (at least on my Solaris box).

When you are calling a Java program from inside a Java program (using Runtime.exec()), the code will look something like this (more elegant, of course) :

Assume the following program is the one which is called

public class WaitAndTerminate {
public static void main(String[] args) {
System.out.println("Program begin");
System.exit(1000);
System.out.println("Program exit");
}
}

and this is your caller program

 
public class Caller {
public static void main(String[] args) {
BufferedReader inStream=null;
try {
System.out.println("Caller start");
Process process=Runtime.getRuntime().exec("java WaitAndTerminate");
inStream = new BufferedReader(new InputStreamReader( process.getInputStream() ));
//the waitFor waits for the called program to exit
process.waitFor();
System.out.println(process.exitValue());
} catch (IOException e) {
e.printStackTrace();
}
catch (InterruptedException ie){
ie.printStackTrace();
}
}
}

The getInputStream() method of the Process, as you can see, grabs the output of the called program so that it could be logged.

One other main utility of this mechanism is that we can get to know whether the Java program succeeds completely or not.  In which case, make the last line of your main program return a System.exit(1000) (which indicates that the program is terminated successfully). Any termination in the middle (assuming a system restart or assuming that the called program is a webservice client making a call to a service hosted on a application server which is restarting – My God) will not return a status code of 1000. Ideally, it would return 2 or something like that.

Lets code that into Java now with a bit of modification into our previously written code.


public class WaitAndTerminate {
public static void main(String[] args) {
System.out.println("Program begin");
Object object=new Object();
synchronized (object){
try {
object.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.exit(1000);
System.out.println("Program exit");
}
}

The Caller Program is this :
 The destroy() method forcefully terminates the application, giving out a status code of 1.

public class Caller {
public static void main(String[] args) {
BufferedReader inStream=null;
try {
System.out.println("Caller start");
Process process=Runtime.getRuntime().exec("java WaitAndTerminate");
inStream = new BufferedReader(new InputStreamReader( process.getInputStream() ));
System.out.println(inStream.readLine());
//forceful termination of the called program
process.destroy();
process.waitFor();
System.out.println(process.exitValue());
} catch (IOException e) {
e.printStackTrace();
}
catch (InterruptedException ie){
ie.printStackTrace();
}
}
}

Output :
Caller start
Program begin
1

Categories: Unix, java Tags: , ,

NameNotFoundException with FSContext

February 5th, 2008 Arun Manivannan No comments

This was my trace. Never thought i was so dumb. I was breaking my head on this for about two hours.

javax.naming.NameNotFoundException; remaining name 'c:\temp'
at com.sun.jndi.fscontext.FSContext.checkExists

(FSContext.java:860)
at com.sun.jndi.fscontext.FSContext.

checkIsDirectory(FSContext.java:893)
at com.sun.jndi.fscontext.FSContext.(FSContext.java:148)
at com.sun.jndi.fscontext.FSContext.(FSContext.java:123)
at com.sun.jndi.fscontext.RefFSContext.(RefFSContext.java:136)
at com.sun.jndi.fscontext.RefFSContextFactory.

createContext(RefFSContextFactory.java:32)
at com.sun.jndi.fscontext.RefFSContextFactory.

createContextAux(RefFSContextFactory.java:37)
at com.sun.jndi.fscontext.FSContextFactory.

getInitialContext(FSContextFactory.java:65)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.(Unknown Source)
at com.ml.cortex.eds.dao.ConnectionManager.

createDataSources(ConnectionManager.java:34)

The solution is simple. Before using a url in the FSContext create the directory. In my case, c:\temp. Create the directory “temp” inside c:\ drive.