Thursday, August 30, 2012

Config SSL for WebLogic

I'm not a JAVA developer at all. I just helped my colleague finished this configuration.

Suppose you have 3 necessary files already:
<privkey.pem>: private key
<COMPANY.com.crt>: certification
<gd_bundle.crt>: rootCA


### Generate Identify.jks ###
openssl pkcs8 -topk8 -nocrypt -in privkey.pem -inform PEM -out key.der -outform DER
openssl x509 -in COMPANY.com.crt  -inform PEM -out cert.der -outform DER

javac ImportKey.java
java ImportKey key.der cert.der
keytool -import -file gd_bundle.crt -alias -trustcacerts -keystore keystore.ImportKey -storepass importkey

you can change the generated file <keystore.ImportKey> as xxx.jks if you like

[Verify]
keytool -v -list -keystore keystore.ImportKey -storepass importkey 


### Generate Trusts.jks ###
keytool -import -v -trustcacerts -alias importkey -file gd_bundle.crt -keystore bundle.jks  -storepass importkey


### Config weblogic ###
Enter WebLogic admin conosole
indicate these 2 JKS files in "Keystore" tab.
finger out password in "SSL" tab.


### Verify ###
Domain name should be *.COMPANY.com, otherwise, your browser will give a warning.

Wednesday, August 22, 2012

ArrayWritable as Reduce input

1, As the input for a Reducer

ArrayWritable is a class, but you have  to create a subclass indicate its proper type if you wanna use it in Map/Reduce tasks.
(http://archive.cloudera.com/cdh4/cdh/4/hadoop-2.0.0-cdh4.0.1/api/index.html)
With the  code slice below, you can use it as a Mapper's output value(Reducer's input value)

public static class TextArrayWritable extends ArrayWritable {
    public TextArrayWritable() {
        super(Text.class);
    }
}

2, As the input Key for a Reducer

Well, to be a Key for Reducer, a class should be comparable, because the output from a Mapper should be sorted before it become the input of following Reducer.
We have 2 solution to make the ArrayWritable  subclass to be comparable.

1, use setOutputKeyComparatorClass in JobConf. (old style API)
2, add interface WritableComparable to existing TextArrayWritable.
 not good at Java code , my apologies :(

 1 public  class TextArrayWritable extends ArrayWritable implements WritableComparable<TextArrayWritable>{
 2     public TextArrayWritable() {
 3         super(Text.class);
 4     }
 5 
 6     public TextArrayWritable(Text[] values) {
 7         super(Text.class, values);
 8     }
 9 
10     @Override
11     public int compareTo(TextArrayWritable o) {
12         try{
13             Writable[] self = this.get();
14             Writable[] other = o.get();
15 
16             if (self == null) self = new Text[]{};           
17             if (other == null) other = new Text[]{};         
18 
19             if (self.length == other.length){
20                 for (int i = 0; i < self.length; i++){                   
21                     int r = ((Text)self[i]).compareTo(((Text)other[i]));
22                     if (r != 0return r;                    
23                 }                    
24             }
25             else{
26                 return (self.length < other.length) ? -1 : 1;
27             }
28         }
29         catch(Exception e){
30             e.printStackTrace();
31         }
32         return 0;
33     }
34 }