merge from asterix_stabilization_issue_257

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_installer@1242 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-algebra/pom.xml b/asterix-algebra/pom.xml
index 70f8c53..b81e77f 100644
--- a/asterix-algebra/pom.xml
+++ b/asterix-algebra/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -14,8 +15,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 			<plugin>
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ByNameToByIndexFieldAccessRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ByNameToByIndexFieldAccessRule.java
index 704ccb5..5c54a4a 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ByNameToByIndexFieldAccessRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ByNameToByIndexFieldAccessRule.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -15,6 +15,7 @@
 
 package edu.uci.ics.asterix.optimizer.rules;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -93,40 +94,44 @@
             }
 
             IAType t = (IAType) env.getType(fce.getArguments().get(0).getValue());
-            switch (t.getTypeTag()) {
-                case ANY: {
-                    return false;
-                }
-                case RECORD: {
-                    ARecordType recType = (ARecordType) t;
-                    ILogicalExpression fai = createFieldAccessByIndex(recType, fce);
-                    if (fai == null) {
+            try {
+                switch (t.getTypeTag()) {
+                    case ANY: {
                         return false;
                     }
-                    expressions.get(i).setValue(fai);
-                    changed = true;
-                    break;
-                }
-                case UNION: {
-                    AUnionType unionT = (AUnionType) t;
-                    if (unionT.isNullableType()) {
-                        IAType t2 = unionT.getUnionList().get(1);
-                        if (t2.getTypeTag() == ATypeTag.RECORD) {
-                            ARecordType recType = (ARecordType) t2;
-                            ILogicalExpression fai = createFieldAccessByIndex(recType, fce);
-                            if (fai == null) {
-                                return false;
-                            }
-                            expressions.get(i).setValue(fai);
-                            changed = true;
-                            break;
+                    case RECORD: {
+                        ARecordType recType = (ARecordType) t;
+                        ILogicalExpression fai = createFieldAccessByIndex(recType, fce);
+                        if (fai == null) {
+                            return false;
                         }
+                        expressions.get(i).setValue(fai);
+                        changed = true;
+                        break;
                     }
-                    throw new NotImplementedException("Union " + unionT);
+                    case UNION: {
+                        AUnionType unionT = (AUnionType) t;
+                        if (unionT.isNullableType()) {
+                            IAType t2 = unionT.getUnionList().get(1);
+                            if (t2.getTypeTag() == ATypeTag.RECORD) {
+                                ARecordType recType = (ARecordType) t2;
+                                ILogicalExpression fai = createFieldAccessByIndex(recType, fce);
+                                if (fai == null) {
+                                    return false;
+                                }
+                                expressions.get(i).setValue(fai);
+                                changed = true;
+                                break;
+                            }
+                        }
+                        throw new NotImplementedException("Union " + unionT);
+                    }
+                    default: {
+                        throw new AlgebricksException("Cannot call field-access on data of type " + t);
+                    }
                 }
-                default: {
-                    throw new AlgebricksException("Cannot call field-access on data of type " + t);
-                }
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
             }
         }
         assign.removeAnnotation(AsterixOperatorAnnotations.PUSHED_FIELD_ACCESS);
@@ -134,7 +139,8 @@
     }
 
     @SuppressWarnings("unchecked")
-    private static ILogicalExpression createFieldAccessByIndex(ARecordType recType, AbstractFunctionCallExpression fce) {
+    private static ILogicalExpression createFieldAccessByIndex(ARecordType recType, AbstractFunctionCallExpression fce)
+            throws IOException {
         String s = getStringSecondArgument(fce);
         if (s == null) {
             return null;
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java
index bc61c49..b0ce342 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/ConstantFoldingRule.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -16,6 +16,7 @@
 package edu.uci.ics.asterix.optimizer.rules;
 
 import java.io.DataInputStream;
+import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.List;
 
@@ -188,7 +189,12 @@
                 ARecordType rt = (ARecordType) _emptyTypeEnv.getType(expr.getArguments().get(0).getValue());
                 String str = ((AString) ((AsterixConstantValue) ((ConstantExpression) expr.getArguments().get(1)
                         .getValue()).getValue()).getObject()).getStringValue();
-                int k = rt.findFieldPosition(str);
+                int k;
+                try {
+                    k = rt.findFieldPosition(str);
+                } catch (IOException e) {
+                    throw new AlgebricksException(e);
+                }
                 if (k >= 0) {
                     // wait for the ByNameToByIndex rule to apply
                     return new Pair<Boolean, ILogicalExpression>(changed, expr);
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java
index 6651ea3..ffd447c 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AccessMethodUtils.java
@@ -1,5 +1,21 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.optimizer.rules.am;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -44,7 +60,8 @@
  * Static helper functions for rewriting plans using indexes.
  */
 public class AccessMethodUtils {
-    public static void appendPrimaryIndexTypes(Dataset dataset, IAType itemType, List<Object> target) {
+    public static void appendPrimaryIndexTypes(Dataset dataset, IAType itemType, List<Object> target)
+            throws IOException {
         ARecordType recordType = (ARecordType) itemType;
         List<String> partitioningKeys = DatasetUtils.getPartitioningKeys(dataset);
         for (String partitioningKey : partitioningKeys) {
@@ -109,7 +126,7 @@
         analysisCtx.matchedFuncExprs.add(new OptimizableFuncExpr(funcExpr, fieldVar, constFilterVal));
         return true;
     }
-    
+
     public static boolean analyzeFuncExprArgsForTwoVars(AbstractFunctionCallExpression funcExpr,
             AccessMethodAnalysisContext analysisCtx) {
         LogicalVariable fieldVar1 = null;
@@ -180,7 +197,11 @@
         // Primary keys.
         List<String> partitioningKeys = DatasetUtils.getPartitioningKeys(dataset);
         for (String partitioningKey : partitioningKeys) {
-            dest.add(recordType.getFieldType(partitioningKey));
+            try {
+                dest.add(recordType.getFieldType(partitioningKey));
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
+            }
         }
     }
 
@@ -229,14 +250,14 @@
     }
 
     /**
-     *  Returns the first expr optimizable by this index.
+     * Returns the first expr optimizable by this index.
      */
     public static IOptimizableFuncExpr chooseFirstOptFuncExpr(Index chosenIndex, AccessMethodAnalysisContext analysisCtx) {
         List<Integer> indexExprs = analysisCtx.getIndexExprs(chosenIndex);
         int firstExprIndex = indexExprs.get(0);
         return analysisCtx.matchedFuncExprs.get(firstExprIndex);
     }
-    
+
     public static UnnestMapOperator createSecondaryIndexUnnestMap(Dataset dataset, ARecordType recordType, Index index,
             ILogicalOperator inputOp, AccessMethodJobGenParams jobGenParams, IOptimizationContext context,
             boolean outputPrimaryKeysOnly, boolean retainInput) throws AlgebricksException {
@@ -299,7 +320,11 @@
         List<Object> primaryIndexOutputTypes = new ArrayList<Object>();
         // Append output variables/types generated by the primary-index search (not forwarded from input).
         primaryIndexUnnestVars.addAll(dataSourceScan.getVariables());
-        appendPrimaryIndexTypes(dataset, recordType, primaryIndexOutputTypes);
+        try {
+            appendPrimaryIndexTypes(dataset, recordType, primaryIndexOutputTypes);
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
+        }
         // An index search is expressed as an unnest over an index-search function.
         IFunctionInfo primaryIndexSearch = FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.INDEX_SEARCH);
         AbstractFunctionCallExpression primaryIndexSearchFunc = new ScalarFunctionCallExpression(primaryIndexSearch,
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java
index 5c65299..3b547e7 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/BTreeAccessMethod.java
@@ -1,5 +1,21 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.optimizer.rules.am;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.HashSet;
@@ -205,7 +221,7 @@
                 if (optFuncExpr.getNumLogicalVars() > 1) {
                     // If we are optimizing a join, the matching field may be the second field name.
                     keyPos = indexOf(optFuncExpr.getFieldName(1), chosenIndex.getKeyFieldNames());
-                }                
+                }
             }
             if (keyPos < 0) {
                 throw new AlgebricksException(
@@ -238,7 +254,7 @@
                     // If high and low keys are set, we exit for now.
                     if (setLowKeys.cardinality() == numSecondaryKeys && setHighKeys.cardinality() == numSecondaryKeys) {
                         doneWithExprs = true;
-                    }                    
+                    }
                     break;
                 }
                 case HIGH_EXCLUSIVE: {
@@ -390,7 +406,11 @@
                     secondaryIndexUnnestOp, context, true, retainInput, false);
         } else {
             List<Object> primaryIndexOutputTypes = new ArrayList<Object>();
-            AccessMethodUtils.appendPrimaryIndexTypes(dataset, recordType, primaryIndexOutputTypes);
+            try {
+                AccessMethodUtils.appendPrimaryIndexTypes(dataset, recordType, primaryIndexOutputTypes);
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
+            }
             primaryIndexUnnestOp = new UnnestMapOperator(dataSourceScan.getVariables(),
                     secondaryIndexUnnestOp.getExpressionRef(), primaryIndexOutputTypes, retainInput);
             primaryIndexUnnestOp.getInputs().add(new MutableObject<ILogicalOperator>(inputOp));
@@ -521,7 +541,7 @@
             return (optFuncExpr.getOperatorSubTree(0) == null || optFuncExpr.getOperatorSubTree(0) == probeSubTree);
         }
     }
-    
+
     private ILogicalExpression createSelectCondition(List<Mutable<ILogicalExpression>> predList) {
         if (predList.size() > 1) {
             IFunctionInfo finfo = AsterixBuiltinFunctions.getAsterixFunctionInfo(AlgebricksBuiltinFunctions.AND);
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/TypeTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/TypeTranslator.java
index 4047d9a..5abbd91 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/TypeTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/TypeTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -12,6 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package edu.uci.ics.asterix.translator;
 
 import java.util.ArrayList;
@@ -29,6 +30,7 @@
 import edu.uci.ics.asterix.aql.expression.UnorderedListTypeDefinition;
 import edu.uci.ics.asterix.common.annotations.IRecordFieldDataGen;
 import edu.uci.ics.asterix.common.annotations.RecordDataGenAnnotation;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.MetadataManager;
 import edu.uci.ics.asterix.metadata.MetadataTransactionContext;
@@ -89,41 +91,45 @@
             throw new AlgebricksException("Cannot redefine builtin type " + tdname + " .");
         }
         TypeSignature typeSignature = new TypeSignature(typeDataverse, tdname);
-        switch (texpr.getTypeKind()) {
-            case TYPEREFERENCE: {
-                TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
-                IAType t = solveTypeReference(typeSignature, typeMap);
-                if (t != null) {
-                    typeMap.put(typeSignature, t);
-                } else {
-                    addIncompleteTopLevelTypeReference(tdname, tre, incompleteTopLevelTypeReferences, typeDataverse);
+        try {
+            switch (texpr.getTypeKind()) {
+                case TYPEREFERENCE: {
+                    TypeReferenceExpression tre = (TypeReferenceExpression) texpr;
+                    IAType t = solveTypeReference(typeSignature, typeMap);
+                    if (t != null) {
+                        typeMap.put(typeSignature, t);
+                    } else {
+                        addIncompleteTopLevelTypeReference(tdname, tre, incompleteTopLevelTypeReferences, typeDataverse);
+                    }
+                    break;
                 }
-                break;
+                case RECORD: {
+                    RecordTypeDefinition rtd = (RecordTypeDefinition) texpr;
+                    ARecordType recType = computeRecordType(typeSignature, rtd, typeMap, incompleteFieldTypes,
+                            incompleteItemTypes, typeDataverse);
+                    typeMap.put(typeSignature, recType);
+                    break;
+                }
+                case ORDEREDLIST: {
+                    OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
+                    AOrderedListType olType = computeOrderedListType(typeSignature, oltd, typeMap, incompleteItemTypes,
+                            incompleteFieldTypes, typeDataverse);
+                    typeMap.put(typeSignature, olType);
+                    break;
+                }
+                case UNORDEREDLIST: {
+                    UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
+                    AUnorderedListType ulType = computeUnorderedListType(typeSignature, ultd, typeMap,
+                            incompleteItemTypes, incompleteFieldTypes, typeDataverse);
+                    typeMap.put(typeSignature, ulType);
+                    break;
+                }
+                default: {
+                    throw new IllegalStateException();
+                }
             }
-            case RECORD: {
-                RecordTypeDefinition rtd = (RecordTypeDefinition) texpr;
-                ARecordType recType = computeRecordType(typeSignature, rtd, typeMap, incompleteFieldTypes,
-                        incompleteItemTypes, typeDataverse);
-                typeMap.put(typeSignature, recType);
-                break;
-            }
-            case ORDEREDLIST: {
-                OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) texpr;
-                AOrderedListType olType = computeOrderedListType(typeSignature, oltd, typeMap, incompleteItemTypes,
-                        incompleteFieldTypes, typeDataverse);
-                typeMap.put(typeSignature, olType);
-                break;
-            }
-            case UNORDEREDLIST: {
-                UnorderedListTypeDefinition ultd = (UnorderedListTypeDefinition) texpr;
-                AUnorderedListType ulType = computeUnorderedListType(typeSignature, ultd, typeMap, incompleteItemTypes,
-                        incompleteFieldTypes, typeDataverse);
-                typeMap.put(typeSignature, ulType);
-                break;
-            }
-            default: {
-                throw new IllegalStateException();
-            }
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
         }
     }
 
@@ -181,7 +187,7 @@
                 }
                 t = dt.getDatatype();
             } else {
-                t = typeMap.get(typeSignature);   
+                t = typeMap.get(typeSignature);
             }
             for (AbstractCollectionType act : incompleteItemTypes.get(typeSignature)) {
                 act.setItemType(t);
@@ -191,7 +197,8 @@
 
     private static AOrderedListType computeOrderedListType(TypeSignature typeSignature, OrderedListTypeDefinition oltd,
             Map<TypeSignature, IAType> typeMap, Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, String defaultDataverse) {
+            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, String defaultDataverse)
+            throws AsterixException {
         TypeExpression tExpr = oltd.getItemTypeExpression();
         String typeName = typeSignature != null ? typeSignature.getName() : null;
         AOrderedListType aolt = new AOrderedListType(null, typeName);
@@ -202,7 +209,8 @@
     private static AUnorderedListType computeUnorderedListType(TypeSignature typeSignature,
             UnorderedListTypeDefinition ultd, Map<TypeSignature, IAType> typeMap,
             Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
-            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, String defaulDataverse) {
+            Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, String defaulDataverse)
+            throws AsterixException {
         TypeExpression tExpr = ultd.getItemTypeExpression();
         String typeName = typeSignature != null ? typeSignature.getName() : null;
         AUnorderedListType ault = new AUnorderedListType(null, typeName);
@@ -213,7 +221,7 @@
     private static void setCollectionItemType(TypeExpression tExpr, Map<TypeSignature, IAType> typeMap,
             Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes,
             Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, AbstractCollectionType act,
-            String defaultDataverse) {
+            String defaultDataverse) throws AsterixException {
         switch (tExpr.getTypeKind()) {
             case ORDEREDLIST: {
                 OrderedListTypeDefinition oltd = (OrderedListTypeDefinition) tExpr;
@@ -306,7 +314,8 @@
 
     private static ARecordType computeRecordType(TypeSignature typeSignature, RecordTypeDefinition rtd,
             Map<TypeSignature, IAType> typeMap, Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes,
-            Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes, String defaultDataverse) {
+            Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes, String defaultDataverse)
+            throws AsterixException {
         List<String> names = rtd.getFieldNames();
         int n = names.size();
         String[] fldNames = new String[n];
@@ -318,14 +327,14 @@
         boolean isOpen = rtd.getRecordKind() == RecordKind.OPEN;
         ARecordType recType = new ARecordType(typeSignature == null ? null : typeSignature.getName(), fldNames,
                 fldTypes, isOpen);
-        
+
         List<IRecordFieldDataGen> fieldDataGen = rtd.getFieldDataGen();
         if (fieldDataGen.size() == n) {
             IRecordFieldDataGen[] rfdg = new IRecordFieldDataGen[n];
             rfdg = fieldDataGen.toArray(rfdg);
             recType.getAnnotations().add(new RecordDataGenAnnotation(rfdg, rtd.getUndeclaredFieldsDataGen()));
         }
-        
+
         for (int j = 0; j < n; j++) {
             TypeExpression texpr = rtd.getFieldTypes().get(j);
             switch (texpr.getTypeKind()) {
diff --git a/asterix-app/pom.xml b/asterix-app/pom.xml
index 2f80c30..7d6e64a 100644
--- a/asterix-app/pom.xml
+++ b/asterix-app/pom.xml
@@ -17,8 +17,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 			<plugin>
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
index 8d804a4..5d3ab0a 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/DatasetOperations.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2011 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -12,9 +12,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package edu.uci.ics.asterix.file;
 
 import java.io.File;
+import java.io.IOException;
 import java.rmi.RemoteException;
 import java.util.List;
 import java.util.logging.Logger;
@@ -329,7 +331,12 @@
         ISerializerDeserializer[] recordFields = new ISerializerDeserializer[1 + numKeys];
         recordFields[0] = payloadSerde;
         for (int i = 0; i < numKeys; i++) {
-            IAType keyType = itemType.getFieldType(partitioningKeys.get(i));
+            IAType keyType;
+            try {
+                keyType = itemType.getFieldType(partitioningKeys.get(i));
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
+            }
             ISerializerDeserializer keySerde = dataFormat.getSerdeProvider().getSerializerDeserializer(keyType);
             recordFields[i + 1] = keySerde;
         }
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java
index 34ba208..87d3b08 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/file/SecondaryIndexCreator.java
@@ -1,6 +1,22 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.file;
 
 import java.io.DataOutput;
+import java.io.IOException;
 import java.util.List;
 
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
@@ -137,13 +153,12 @@
         numPrimaryKeys = DatasetUtils.getPartitioningKeys(dataset).size();
         numSecondaryKeys = createIndexStmt.getKeyFields().size();
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> primarySplitsAndConstraint = metadataProvider
-                .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(
-                        dataverseName, datasetName, datasetName);
+                .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(dataverseName, datasetName, datasetName);
         primaryFileSplitProvider = primarySplitsAndConstraint.first;
         primaryPartitionConstraint = primarySplitsAndConstraint.second;
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> secondarySplitsAndConstraint = metadataProvider
-                .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(
-                        dataverseName, datasetName, secondaryIndexName);
+                .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(dataverseName, datasetName,
+                        secondaryIndexName);
         secondaryFileSplitProvider = secondarySplitsAndConstraint.first;
         secondaryPartitionConstraint = secondarySplitsAndConstraint.second;
         // Must be called in this order.
@@ -159,7 +174,12 @@
         primaryComparatorFactories = new IBinaryComparatorFactory[numPrimaryKeys];
         ISerializerDeserializerProvider serdeProvider = metadataProvider.getFormat().getSerdeProvider();
         for (int i = 0; i < numPrimaryKeys; i++) {
-            IAType keyType = itemType.getFieldType(partitioningKeys.get(i));
+            IAType keyType;
+            try {
+                keyType = itemType.getFieldType(partitioningKeys.get(i));
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
+            }
             primaryRecFields[i] = serdeProvider.getSerializerDeserializer(keyType);
             primaryComparatorFactories[i] = AqlBinaryComparatorFactoryProvider.INSTANCE.getBinaryComparatorFactory(
                     keyType, true);
@@ -286,8 +306,8 @@
             fieldPermutation[i] = i;
         }
         Pair<IFileSplitProvider, AlgebricksPartitionConstraint> secondarySplitsAndConstraint = metadataProvider
-                .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(
-                        dataverseName, datasetName, secondaryIndexName);
+                .splitProviderAndPartitionConstraintsForInternalOrFeedDataset(dataverseName, datasetName,
+                        secondaryIndexName);
         TreeIndexBulkLoadOperatorDescriptor treeIndexBulkLoadOp = new TreeIndexBulkLoadOperatorDescriptor(spec,
                 AsterixStorageManagerInterface.INSTANCE, AsterixIndexRegistryProvider.INSTANCE,
                 secondarySplitsAndConstraint.first, secondaryRecDesc.getTypeTraits(), secondaryComparatorFactories,
diff --git a/asterix-app/src/test/resources/runtimets/queries/constructor/int_01.aql b/asterix-app/src/test/resources/runtimets/queries/constructor/int_01.aql
index 683481f..58ae18d 100644
--- a/asterix-app/src/test/resources/runtimets/queries/constructor/int_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/constructor/int_01.aql
@@ -13,5 +13,4 @@
 let $c7 := int32("-320")
 let $c8 := int64("-640i64")
 let $c9 := int64("-9223372036854775808")
-return {"int8": $c1,"int16": $c2,"int32": $c3, "int64": $c4, "int8": $c5,"int16": $c6,"int32": $c7, "int64": $c8, "int64_min" : $c9}
-
+return {"int8": $c1,"int16": $c2,"int32": $c3, "int64": $c4, "int8_2": $c5,"int16_2": $c6,"int32_2": $c7, "int64_2": $c8, "int64_min" : $c9}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/join_across_dataverses.aql b/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/join_across_dataverses.aql
index 8266c79..197baaa 100644
--- a/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/join_across_dataverses.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/join_across_dataverses.aql
@@ -57,4 +57,4 @@
 for $o in dataset('test2.Orders')
 where $c.cid = $o.cid
 order by $c.name, $o.total
-return {"cust_name":$c.name, "cust_age": $c.age, "order_total":$o.total, "orderList":[$o.oid, $o.cid], "orderList":{{$o.oid, $o.cid}}}
+return {"cust_name":$c.name, "cust_age": $c.age, "order_total":$o.total, "orderList":[$o.oid, $o.cid]}
diff --git a/asterix-app/src/test/resources/runtimets/queries/custord/join_q_01.aql b/asterix-app/src/test/resources/runtimets/queries/custord/join_q_01.aql
index ddde56e..f5d2080 100644
--- a/asterix-app/src/test/resources/runtimets/queries/custord/join_q_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/custord/join_q_01.aql
@@ -47,4 +47,4 @@
 for $o in dataset('Orders')
 where $c.cid = $o.cid 
 order by $c.name, $o.total
-return {"cust_name":$c.name, "cust_age": $c.age, "order_total":$o.total, "orderList":[$o.oid, $o.cid], "orderList":{{$o.oid, $o.cid}}} 
+return {"cust_name":$c.name, "cust_age": $c.age, "order_total":$o.total, "orderList":[$o.oid, $o.cid]} 
diff --git a/asterix-app/src/test/resources/runtimets/queries/custord/order_q_03.aql b/asterix-app/src/test/resources/runtimets/queries/custord/order_q_03.aql
index b930a10..52bc6d2 100644
--- a/asterix-app/src/test/resources/runtimets/queries/custord/order_q_03.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/custord/order_q_03.aql
@@ -26,4 +26,4 @@
 let $c2 := {{ $o.orderstatus, $o.clerk}}
 let $c3 := [$o.heList, $o.openlist, $o.loc, $o.line, $o.poly, $o.lastorder]
 let $c4 := [$o.heList, $o.openlist, $o.loc, $o.line, $o.poly, $o.lastorder]
-return { "orderid": $o.oid, "ordertot":$o.total, "list": $c1, "item1": $c1[0], "item1": $c1[?], "item2": $c1[1], "item3": $c1[2]}
+return { "orderid": $o.oid, "ordertot":$o.total, "list": $c1, "item1": $c1[0], "item2": $c1[1], "item3": $c1[2]}
diff --git a/asterix-app/src/test/resources/runtimets/queries/custord/order_q_04.aql b/asterix-app/src/test/resources/runtimets/queries/custord/order_q_04.aql
index b2d55d9..e2fd5b6 100644
--- a/asterix-app/src/test/resources/runtimets/queries/custord/order_q_04.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/custord/order_q_04.aql
@@ -26,4 +26,4 @@
 let $c2 := {{ $o.orderstatus, $o.clerk}}
 let $c3 := [$o.heList, $o.openlist, $o.loc, $o.line, $o.poly, $o.lastorder]
 let $c4 := [$o.heList, $o.openlist, $o.loc, $o.line, $o.poly, $o.lastorder]
-return { "orderid": $o.oid, "ordertot":$o.total, "list": $c3, "item1": $c3[0], "item1": $c3[?], "item2": $c3[1], "item5": $c3[5], "item10": $c3[10]}
+return { "orderid": $o.oid, "ordertot":$o.total, "list": $c3, "item1": $c3[0], "item2": $c3[1], "item5": $c3[5], "item10": $c3[10]}
diff --git a/asterix-app/src/test/resources/runtimets/queries/custord/order_q_05.aql b/asterix-app/src/test/resources/runtimets/queries/custord/order_q_05.aql
index 5693312..481c1fd 100644
--- a/asterix-app/src/test/resources/runtimets/queries/custord/order_q_05.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/custord/order_q_05.aql
@@ -24,4 +24,4 @@
 for $o in dataset('Orders')
 let $c1 := []
 let $c2 := {{}}
-return { "orderid": $o.oid, "ordertot":$o.total, "emptyorderedlist": $c1, "emptyunorderedlist": $c2, "olist_item1": $c1[0], "olist_item1": $c1[?], "olist_item5": $c1[4], "ulist_item1": $c2[?]}
+return { "orderid": $o.oid, "ordertot":$o.total, "emptyorderedlist": $c1, "emptyunorderedlist": $c2, "olist_item1": $c1[0], "olist_item5": $c1[4], "ulist_item1": $c2[?]}
diff --git a/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_01.aql b/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_01.aql
index 10a6335..fe0e9e5 100644
--- a/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_01.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_01.aql
@@ -17,7 +17,7 @@
 
 create feed dataset TweetFeed(TweetType)
 using "edu.uci.ics.asterix.tools.external.data.RateControlledFileSystemBasedAdapterFactory"
-(("fs"="localfs"),("path"="nc1://data/twitter/obamatweets.adm"),("format"="adm"),("output-type-name"="TweetType"),("tuple-interval"="10"))
+(("output-type-name"="TweetType"),("fs"="localfs"),("path"="nc1://data/twitter/obamatweets.adm"),("format"="adm"),("tuple-interval"="10"))
 primary key id;
 
 write output to nc1:"rttest/feeds_feeds_01.adm";
diff --git a/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_03.aql b/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_03.aql
index 41b2115..615ee83 100644
--- a/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_03.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/feeds/feeds_03.aql
@@ -21,7 +21,7 @@
 
 create feed dataset TweetFeed(TweetType)
 using "edu.uci.ics.asterix.tools.external.data.RateControlledFileSystemBasedAdapterFactory"
-(("fs"="localfs"),("path"="nc1://data/twitter/obamatweets.adm"),("format"="adm"),("output-type-name"="TweetType"),("tuple-interval"="10"))
+(("output-type-name"="TweetType"),("fs"="localfs"),("path"="nc1://data/twitter/obamatweets.adm"),("format"="adm"),("tuple-interval"="10"))
 apply function feed_processor@1
 primary key id;
 
diff --git a/asterix-app/src/test/resources/runtimets/queries/records/closed-closed-fieldname-conflict_issue173.aql b/asterix-app/src/test/resources/runtimets/queries/records/closed-closed-fieldname-conflict_issue173.aql
new file mode 100644
index 0000000..b356a56
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/records/closed-closed-fieldname-conflict_issue173.aql
@@ -0,0 +1,11 @@
+/*
+ * Description    : Tests whether a conflict between two closed field names are detected
+ * Expected Result: An error reporting that there is a duplicate field name "name"
+ * Author: zheilbron
+ */
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+let $x := {"name": "john", "name": "smith"}
+return $x
diff --git a/asterix-app/src/test/resources/runtimets/queries/records/open-closed-fieldname-conflict_issue173.aql b/asterix-app/src/test/resources/runtimets/queries/records/open-closed-fieldname-conflict_issue173.aql
new file mode 100644
index 0000000..a5ac400
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/records/open-closed-fieldname-conflict_issue173.aql
@@ -0,0 +1,21 @@
+/*
+ * Description    : Tests whether a conflict between an open and closed field name are detected
+ * Expected Result: An error reporting that there is a duplicate field name "name"
+ * Author: zheilbron
+ */
+ 
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type opentype as open {
+id:int32,
+fname:string
+}
+
+create dataset testds(opentype) primary key id; 
+
+insert into dataset testds({'id': 1, 'fname': "name"});
+
+for $x in dataset('testds')
+return {$x.fname: "smith", lowercase("NAME"): "john"}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/records/open-open-fieldname-conflict_issue173.aql b/asterix-app/src/test/resources/runtimets/queries/records/open-open-fieldname-conflict_issue173.aql
new file mode 100644
index 0000000..225e596
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/records/open-open-fieldname-conflict_issue173.aql
@@ -0,0 +1,21 @@
+/*
+ * Description    : Tests whether a conflict between two open field names are detected
+ * Expected Result: An error reporting that there is a duplicate field name "name"
+ * Author: zheilbron
+ */
+ 
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type opentype as open {
+fname1: string,
+fname2: string
+}
+
+create dataset testds(opentype) primary key fname1; 
+
+insert into dataset testds({'fname1': "name", 'fname2': "name"});
+
+for $x in dataset('testds')
+return {$x.fname1: "john", $x.fname2: "smith"}
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/constructor/int_01.adm b/asterix-app/src/test/resources/runtimets/results/constructor/int_01.adm
index fb52e3b..470d1f8 100644
--- a/asterix-app/src/test/resources/runtimets/results/constructor/int_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/constructor/int_01.adm
@@ -1 +1 @@
-{ "int8": 80i8, "int16": 160i16, "int32": 320, "int64": 640i64, "int8": -80i8, "int16": -160i16, "int32": -320, "int64": -640i64, "int64_min": -9223372036854775808i64 }
\ No newline at end of file
+{ "int8": 80i8, "int16": 160i16, "int32": 320, "int64": 640i64, "int8_2": -80i8, "int16_2": -160i16, "int32_2": -320, "int64_2": -640i64, "int64_min": -9223372036854775808i64 }
diff --git a/asterix-app/src/test/resources/runtimets/results/cross-dataverse/join_across_dataverses.adm b/asterix-app/src/test/resources/runtimets/results/cross-dataverse/join_across_dataverses.adm
index 87619a8..e78ad8f 100644
--- a/asterix-app/src/test/resources/runtimets/results/cross-dataverse/join_across_dataverses.adm
+++ b/asterix-app/src/test/resources/runtimets/results/cross-dataverse/join_across_dataverses.adm
@@ -1,3 +1,3 @@
-{ "cust_name": "Jodi Alex", "cust_age": 19, "order_total": 7.206f, "orderList": [ 10, 5 ], "orderList": {{ 10, 5 }} }
-{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 14.2326f, "orderList": [ 10, 775 ], "orderList": {{ 10, 775 }} }
-{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 97.20656f, "orderList": [ 1000, 775 ], "orderList": {{ 1000, 775 }} }
+{ "cust_name": "Jodi Alex", "cust_age": 19, "order_total": 7.206f, "orderList": [ 10, 5 ] }
+{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 14.2326f, "orderList": [ 10, 775 ] }
+{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 97.20656f, "orderList": [ 1000, 775 ] }
diff --git a/asterix-app/src/test/resources/runtimets/results/custord/join_q_01.adm b/asterix-app/src/test/resources/runtimets/results/custord/join_q_01.adm
index 7648e4a..e78ad8f 100644
--- a/asterix-app/src/test/resources/runtimets/results/custord/join_q_01.adm
+++ b/asterix-app/src/test/resources/runtimets/results/custord/join_q_01.adm
@@ -1,3 +1,3 @@
-{ "cust_name": "Jodi Alex", "cust_age": 19, "order_total": 7.206f, "orderList": [ 10, 5 ], "orderList": {{ 10, 5 }} }
-{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 14.2326f, "orderList": [ 10, 775 ], "orderList": {{ 10, 775 }} }
-{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 97.20656f, "orderList": [ 1000, 775 ], "orderList": {{ 1000, 775 }} }
\ No newline at end of file
+{ "cust_name": "Jodi Alex", "cust_age": 19, "order_total": 7.206f, "orderList": [ 10, 5 ] }
+{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 14.2326f, "orderList": [ 10, 775 ] }
+{ "cust_name": "Jodi Rotruck", "cust_age": null, "order_total": 97.20656f, "orderList": [ 1000, 775 ] }
diff --git a/asterix-app/src/test/resources/runtimets/results/custord/order_q_03.adm b/asterix-app/src/test/resources/runtimets/results/custord/order_q_03.adm
index 903c00d..4e02c4b 100644
--- a/asterix-app/src/test/resources/runtimets/results/custord/order_q_03.adm
+++ b/asterix-app/src/test/resources/runtimets/results/custord/order_q_03.adm
@@ -1,4 +1,4 @@
-{ "orderid": 1000, "ordertot": 97.20656f, "list": [ "ORDER_DELIVERED", "Kathryne" ], "item1": "ORDER_DELIVERED", "item1": "ORDER_DELIVERED", "item2": "Kathryne", "item3": null }
-{ "orderid": 10, "ordertot": 7.206f, "list": [ "ORDER_DELIVERED", "ALEX" ], "item1": "ORDER_DELIVERED", "item1": "ORDER_DELIVERED", "item2": "ALEX", "item3": null }
-{ "orderid": 100, "ordertot": 124.26f, "list": [ "ORDER_DELIVERED", "YASSER" ], "item1": "ORDER_DELIVERED", "item1": "ORDER_DELIVERED", "item2": "YASSER", "item3": null }
-{ "orderid": 10, "ordertot": 14.2326f, "list": [ "ORDER_DELIVERED", "MIKE" ], "item1": "ORDER_DELIVERED", "item1": "ORDER_DELIVERED", "item2": "MIKE", "item3": null }
+{ "orderid": 1000, "ordertot": 97.20656f, "list": [ "ORDER_DELIVERED", "Kathryne" ], "item1": "ORDER_DELIVERED", "item2": "Kathryne", "item3": null }
+{ "orderid": 10, "ordertot": 7.206f, "list": [ "ORDER_DELIVERED", "ALEX" ], "item1": "ORDER_DELIVERED", "item2": "ALEX", "item3": null }
+{ "orderid": 100, "ordertot": 124.26f, "list": [ "ORDER_DELIVERED", "YASSER" ], "item1": "ORDER_DELIVERED", "item2": "YASSER", "item3": null }
+{ "orderid": 10, "ordertot": 14.2326f, "list": [ "ORDER_DELIVERED", "MIKE" ], "item1": "ORDER_DELIVERED", "item2": "MIKE", "item3": null }
diff --git a/asterix-app/src/test/resources/runtimets/results/custord/order_q_04.adm b/asterix-app/src/test/resources/runtimets/results/custord/order_q_04.adm
index f22ea7f..3992f7d 100644
--- a/asterix-app/src/test/resources/runtimets/results/custord/order_q_04.adm
+++ b/asterix-app/src/test/resources/runtimets/results/custord/order_q_04.adm
@@ -1,4 +1,4 @@
-{ "orderid": 1000, "ordertot": 97.20656f, "list": [ [ "1.0f", "yassser" ], [ 11, 14, "yasir", 1.6f ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), null ], "item1": [ "1.0f", "yassser" ], "item1": [ "1.0f", "yassser" ], "item2": [ 11, 14, "yasir", 1.6f ], "item5": null, "item10": null }
-{ "orderid": 10, "ordertot": 7.206f, "list": [ [ 1.0f, "5.2f", "60" ], [ 13231, "foo", null, 13.25d, 13.2f ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), null ], "item1": [ 1.0f, "5.2f", "60" ], "item1": [ 1.0f, "5.2f", "60" ], "item2": [ 13231, "foo", null, 13.25d, 13.2f ], "item5": null, "item10": null }
-{ "orderid": 100, "ordertot": 124.26f, "list": [ [ 1.3f, 5.2f, "60", 12.32f ], [ 10, 2.0f, 3.0d, 40 ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), null ], "item1": [ 1.3f, 5.2f, "60", 12.32f ], "item1": [ 1.3f, 5.2f, "60", 12.32f ], "item2": [ 10, 2.0f, 3.0d, 40 ], "item5": null, "item10": null }
-{ "orderid": 10, "ordertot": 14.2326f, "list": [ [ 2.4f, "15" ], [ 110 ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), { "oid": 75, "total": 87.61863f } ], "item1": [ 2.4f, "15" ], "item1": [ 2.4f, "15" ], "item2": [ 110 ], "item5": { "oid": 75, "total": 87.61863f }, "item10": null }
+{ "orderid": 1000, "ordertot": 97.20656f, "list": [ [ "1.0f", "yassser" ], [ 11, 14, "yasir", 1.6f ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), null ], "item1": [ "1.0f", "yassser" ], "item2": [ 11, 14, "yasir", 1.6f ], "item5": null, "item10": null }
+{ "orderid": 10, "ordertot": 7.206f, "list": [ [ 1.0f, "5.2f", "60" ], [ 13231, "foo", null, 13.25d, 13.2f ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), null ], "item1": [ 1.0f, "5.2f", "60" ], "item2": [ 13231, "foo", null, 13.25d, 13.2f ], "item5": null, "item10": null }
+{ "orderid": 100, "ordertot": 124.26f, "list": [ [ 1.3f, 5.2f, "60", 12.32f ], [ 10, 2.0f, 3.0d, 40 ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), null ], "item1": [ 1.3f, 5.2f, "60", 12.32f ], "item2": [ 10, 2.0f, 3.0d, 40 ], "item5": null, "item10": null }
+{ "orderid": 10, "ordertot": 14.2326f, "list": [ [ 2.4f, "15" ], [ 110 ], point("10.1,11.1"), line("10.1,11.1 10.2,11.2"), polygon("1.2,1.3 2.1,2.5 3.5,3.6 4.6,4.8"), { "oid": 75, "total": 87.61863f } ], "item1": [ 2.4f, "15" ], "item2": [ 110 ], "item5": { "oid": 75, "total": 87.61863f }, "item10": null }
diff --git a/asterix-app/src/test/resources/runtimets/results/custord/order_q_05.adm b/asterix-app/src/test/resources/runtimets/results/custord/order_q_05.adm
index dd3420e..4d8b37c 100644
--- a/asterix-app/src/test/resources/runtimets/results/custord/order_q_05.adm
+++ b/asterix-app/src/test/resources/runtimets/results/custord/order_q_05.adm
@@ -1,4 +1,4 @@
-{ "orderid": 1000, "ordertot": 97.20656f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
-{ "orderid": 10, "ordertot": 7.206f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
-{ "orderid": 100, "ordertot": 124.26f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
-{ "orderid": 10, "ordertot": 14.2326f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
+{ "orderid": 1000, "ordertot": 97.20656f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
+{ "orderid": 10, "ordertot": 7.206f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
+{ "orderid": 100, "ordertot": 124.26f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
+{ "orderid": 10, "ordertot": 14.2326f, "emptyorderedlist": [  ], "emptyunorderedlist": {{  }}, "olist_item1": null, "olist_item5": null, "ulist_item1": null }
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 6956e4b..de694cd 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -2626,6 +2626,24 @@
         <output-file compare="Text">open-record-constructor_02.adm</output-file>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="records">
+      <compilation-unit name="closed-closed-fieldname-conflict_issue173">
+        <output-file compare="Text">closed-closed-fieldname-conflict_issue173.adm</output-file>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
+  <test-case FilePath="records">
+      <compilation-unit name="open-closed-fieldname-conflict_issue173">
+        <output-file compare="Text">open-closed-fieldname-conflict_issue173.adm</output-file>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="records">
+      <compilation-unit name="open-open-fieldname-conflict_issue173">
+        <output-file compare="Text">open-open-fieldname-conflict_issue173.adm</output-file>
+        <expected-error>edu.uci.ics.asterix.common.exceptions.AsterixException</expected-error>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="scan">
     <test-case FilePath="scan">
diff --git a/asterix-aql/pom.xml b/asterix-aql/pom.xml
index 7ac2cbb..7617582 100644
--- a/asterix-aql/pom.xml
+++ b/asterix-aql/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -13,8 +14,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 			<plugin>
@@ -36,14 +37,15 @@
 						<goals>
 							<goal>jjdoc</goal>
 						</goals>
-                        <phase>process-sources</phase>
+						<phase>process-sources</phase>
 					</execution>
 				</executions>
 			</plugin>
 		</plugins>
 		<pluginManagement>
 			<plugins>
-				<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+				<!--This plugin's configuration is used to store Eclipse m2e settings 
+					only. It has no influence on the Maven build itself. -->
 				<plugin>
 					<groupId>org.eclipse.m2e</groupId>
 					<artifactId>lifecycle-mapping</artifactId>
diff --git a/asterix-aql/src/main/javacc/AQL.jj b/asterix-aql/src/main/javacc/AQL.jj
index 78d1129..e296266 100644
--- a/asterix-aql/src/main/javacc/AQL.jj
+++ b/asterix-aql/src/main/javacc/AQL.jj
@@ -17,6 +17,7 @@
 
 import java.util.Map;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import edu.uci.ics.asterix.aql.literal.FloatLiteral;
 import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
 import edu.uci.ics.asterix.aql.literal.FalseLiteral;
@@ -914,7 +915,7 @@
 
 Map<String,String> getConfiguration()  throws ParseException :
 {
-	Map<String,String> configuration = new HashMap<String,String>();
+	Map<String,String> configuration = new LinkedHashMap<String,String>();
 	String key;
 	String value;
 }
diff --git a/asterix-common/pom.xml b/asterix-common/pom.xml
index ee81e75..0994109 100644
--- a/asterix-common/pom.xml
+++ b/asterix-common/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -15,8 +16,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 		</plugins>
diff --git a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
index f84f294..c334bbb 100644
--- a/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
+++ b/asterix-common/src/main/java/edu/uci/ics/asterix/common/context/AsterixAppRuntimeContext.java
@@ -45,7 +45,7 @@
         ICacheMemoryAllocator allocator = new HeapBufferAllocator();
         IPageReplacementStrategy prs = new ClockPageReplacementStrategy();
         IIOManager ioMgr = ncApplicationContext.getRootContext().getIOManager();
-        IPageCleanerPolicy pcp = new DelayPageCleanerPolicy(600000);
+        IPageCleanerPolicy pcp = new DelayPageCleanerPolicy(1000);
         bufferCache = new BufferCache(ioMgr, allocator, prs, pcp, fileMapManager, pageSize, numPages, Integer.MAX_VALUE);
 
         // Initialize the index registry
diff --git a/asterix-events/pom.xml b/asterix-events/pom.xml
new file mode 100644
index 0000000..46bb96a
--- /dev/null
+++ b/asterix-events/pom.xml
@@ -0,0 +1,171 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+          <artifactId>asterix</artifactId>
+          <groupId>edu.uci.ics.asterix</groupId>
+          <version>0.0.4-SNAPSHOT</version>
+  </parent>
+  <groupId>edu.uci.ics.asterix</groupId>
+  <artifactId>asterix-events</artifactId>
+  <version>0.0.4-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+       <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>2.0.2</version>
+          <configuration>
+             <source>1.6</source>
+             <target>1.6</target>
+          </configuration>
+       </plugin>
+       <plugin>
+          <groupId>org.jvnet.jaxb2.maven2</groupId>
+          <artifactId>maven-jaxb2-plugin</artifactId>
+          <executions>
+            <execution>
+              <id>event</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+              <configuration>
+                <args>
+                  <arg>-Xsetters</arg>
+                  <arg>-Xvalue-constructor</arg>
+                </args>
+                <plugins>
+                  <plugin>
+                    <groupId>org.jvnet.jaxb2_commons</groupId>
+                    <artifactId>jaxb2-basics</artifactId>
+                    <version>0.6.2</version>
+                  </plugin>
+                  <plugin>
+                    <groupId>org.jvnet.jaxb2_commons</groupId>
+                    <artifactId>jaxb2-value-constructor</artifactId>
+                    <version>3.0</version>
+                  </plugin>
+                </plugins>
+                <schemaDirectory>src/main/resources/schema</schemaDirectory>
+                <schemaIncludes>
+	          <include>event.xsd</include>
+	        </schemaIncludes>
+                <generatePackage>edu.uci.ics.asterix.event.schema.event</generatePackage>
+                <generateDirectory>${project.build.directory}/generated-sources/event</generateDirectory>
+              </configuration>
+            </execution>
+            <execution>
+              <id>pattern</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+              <configuration>
+                <args>
+                  <arg>-Xsetters</arg>
+                  <arg>-Xvalue-constructor</arg>
+                </args>
+                <plugins>
+                  <plugin>
+                    <groupId>org.jvnet.jaxb2_commons</groupId>
+                    <artifactId>jaxb2-basics</artifactId>
+                    <version>0.6.2</version>
+                  </plugin>
+                  <plugin>
+                    <groupId>org.jvnet.jaxb2_commons</groupId>
+                    <artifactId>jaxb2-value-constructor</artifactId>
+                    <version>3.0</version>
+                  </plugin>
+                </plugins>
+                <schemaDirectory>src/main/resources/schema</schemaDirectory>
+                <schemaIncludes>
+	          <include>pattern.xsd</include>
+	        </schemaIncludes>
+                <generatePackage>edu.uci.ics.asterix.event.schema.pattern</generatePackage>
+                <generateDirectory>${project.build.directory}/generated-sources/pattern</generateDirectory>
+              </configuration>
+            </execution>
+            <execution>
+              <id>cluster</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+              <configuration>
+                <args>
+                  <arg>-Xsetters</arg>
+                  <arg>-Xvalue-constructor</arg>
+                </args>
+                <plugins>
+                  <plugin>
+                    <groupId>org.jvnet.jaxb2_commons</groupId>
+                    <artifactId>jaxb2-basics</artifactId>
+                    <version>0.6.2</version>
+                  </plugin>
+                  <plugin>
+                    <groupId>org.jvnet.jaxb2_commons</groupId>
+                    <artifactId>jaxb2-value-constructor</artifactId>
+                    <version>3.0</version>
+                  </plugin>
+                </plugins>
+                <schemaDirectory>src/main/resources/schema</schemaDirectory>
+                <schemaIncludes>
+	          <include>cluster.xsd</include>
+	        </schemaIncludes>
+                <generatePackage>edu.uci.ics.asterix.event.schema.cluster</generatePackage>
+                <generateDirectory>${project.build.directory}/generated-sources/cluster</generateDirectory>
+                <bindingDirectory>src/main/resources/schema</bindingDirectory>
+                <bindingIncludes>
+                  <bindingInclude>jaxb-bindings.xjb</bindingInclude>
+                </bindingIncludes>
+              </configuration>
+            </execution>
+          </executions>
+       </plugin>
+       <plugin>
+         <artifactId>maven-assembly-plugin</artifactId>
+         <version>2.2-beta-2</version>
+         <executions>
+           <execution>
+             <configuration>
+               <descriptor>src/main/assembly/binary-assembly.xml</descriptor>
+             </configuration>
+             <phase>package</phase>
+             <goals>
+               <goal>attached</goal>
+             </goals>
+           </execution>
+         </executions>
+       </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>args4j</groupId>
+      <artifactId>args4j</artifactId>
+      <version>2.0.12</version>
+      <type>jar</type>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jvnet.jaxb2_commons</groupId>
+      <artifactId>jaxb2-value-constructor</artifactId>
+      <version>3.0</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.4</version>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/asterix-events/src/main/assembly/binary-assembly.xml b/asterix-events/src/main/assembly/binary-assembly.xml
new file mode 100644
index 0000000..29ebbdd
--- /dev/null
+++ b/asterix-events/src/main/assembly/binary-assembly.xml
@@ -0,0 +1,27 @@
+<assembly>
+  <id>bin</id>
+  <formats>
+    <format>tar.gz</format>
+    <format>tar.bz2</format>
+    <format>zip</format>
+  </formats>
+  <fileSets>
+    <fileSet>
+      <directory>src/main/resources/events</directory>
+      <outputDirectory>events</outputDirectory>
+      <includes></includes>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/scripts</directory>
+      <outputDirectory>scripts</outputDirectory>
+      <includes></includes>
+    </fileSet>
+    <fileSet>
+      <directory>target</directory>
+      <outputDirectory>target</outputDirectory>
+      <includes>
+        <include>*.jar</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+</assembly>
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/api/ClusterInfo.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/api/ClusterInfo.java
new file mode 100644
index 0000000..630f9b3
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/api/ClusterInfo.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.api;
+
+import java.util.List;
+
+public class ClusterInfo {
+
+	List<NodeInfo> nodes;
+
+	public ClusterInfo(List<NodeInfo> nodes) {
+		this.nodes = nodes;
+	}
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/api/NodeInfo.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/api/NodeInfo.java
new file mode 100644
index 0000000..835e0dc
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/api/NodeInfo.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.api;
+
+public class NodeInfo {
+
+	private final String id;
+	private final String ip;
+
+	public NodeInfo(String id, String ip) {
+		this.id = id;
+		this.ip = ip;
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public String getIp() {
+		return ip;
+	}
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/driver/EventConfig.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/driver/EventConfig.java
new file mode 100644
index 0000000..9d0138b
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/driver/EventConfig.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.driver;
+
+import org.kohsuke.args4j.Option;
+
+public class EventConfig {
+
+	@Option(name = "-h", required = false, usage = "Help")
+	public boolean help = false;
+
+	@Option(name = "-d", required = false, usage = "Show the execution on a timeline")
+	public boolean dryRun = false;
+
+	@Option(name = "-s", required = false, usage = "Seed for randomization")
+	public int seed = -1;
+
+	@Option(name = "-c", required = true, usage = "Path to cluster configuration (REQUIRED)")
+	public String clusterPath;
+
+	@Option(name = "-p", required = true, usage = "Path to pattern configuration (REQUIRED)")
+	public String patternPath;
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/driver/EventDriver.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/driver/EventDriver.java
new file mode 100644
index 0000000..17d6647
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/driver/EventDriver.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.driver;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.kohsuke.args4j.CmdLineParser;
+
+import edu.uci.ics.asterix.event.management.DefaultOutputHandler;
+import edu.uci.ics.asterix.event.management.EventUtil;
+import edu.uci.ics.asterix.event.management.EventrixClient;
+import edu.uci.ics.asterix.event.management.IOutputHandler;
+import edu.uci.ics.asterix.event.management.Randomizer;
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.event.schema.cluster.Property;
+import edu.uci.ics.asterix.event.schema.event.Events;
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+
+public class EventDriver {
+
+	public static final String CLIENT_NODE_ID = "client_node";
+	public static final Node CLIENT_NODE = new Node(CLIENT_NODE_ID,
+			"127.0.0.1", null, null, null, null);
+
+	private static String eventsDir;
+	private static Events events;
+	private static Map<String, String> env = new HashMap<String, String>();
+	private static String scriptDirSuffix;
+
+	public static String getEventsDir() {
+		return eventsDir;
+	}
+
+	public static Events getEvents() {
+		return events;
+	}
+
+	public static Map<String, String> getEnvironment() {
+		return env;
+	}
+
+	public static String getStringifiedEnv(Cluster cluster) {
+		StringBuffer buffer = new StringBuffer();
+		for (Property p : cluster.getEnv().getProperty()) {
+			buffer.append(p.getKey() + "=" + p.getValue() + " ");
+		}
+		return buffer.toString();
+	}
+
+	public static Cluster initializeCluster(String path) throws JAXBException,
+			IOException {
+		File file = new File(path);
+		JAXBContext ctx = JAXBContext.newInstance(Cluster.class);
+		Unmarshaller unmarshaller = ctx.createUnmarshaller();
+		Cluster cluster = (Cluster) unmarshaller.unmarshal(file);
+		for (Property p : cluster.getEnv().getProperty()) {
+			env.put(p.getKey(), p.getValue());
+		}
+		return cluster;
+	}
+
+	public static Patterns initializePatterns(String path)
+			throws JAXBException, IOException {
+		File file = new File(path);
+		JAXBContext ctx = JAXBContext.newInstance(Patterns.class);
+		Unmarshaller unmarshaller = ctx.createUnmarshaller();
+		return (Patterns) unmarshaller.unmarshal(file);
+	}
+
+	private static void initialize(EventConfig eventConfig) throws IOException,
+			JAXBException {
+
+	}
+
+	public static EventrixClient getClient(String eventsDir, Cluster cluster,
+			boolean dryRun) throws Exception {
+		return new EventrixClient(eventsDir, cluster, dryRun,
+				new DefaultOutputHandler());
+	}
+
+	public static EventrixClient getClient(String eventsDir, Cluster cluster,
+			boolean dryRun, IOutputHandler outputHandler) throws Exception {
+		return new EventrixClient(eventsDir, cluster, dryRun, outputHandler);
+	}
+
+	public static void main(String[] args) throws Exception {
+		String eventsHome = System.getenv("EVENT_HOME");
+		if (eventsHome == null) {
+			throw new IllegalStateException("EVENT_HOME is not set");
+		}
+		eventsDir = eventsHome + File.separator + EventUtil.EVENTS_DIR;
+		EventConfig eventConfig = new EventConfig();
+		CmdLineParser parser = new CmdLineParser(eventConfig);
+		try {
+			parser.parseArgument(args);
+			if (eventConfig.help) {
+				parser.printUsage(System.out);
+			}
+			if (eventConfig.seed > 0) {
+				Randomizer.getInstance(eventConfig.seed);
+			}
+			Cluster cluster = initializeCluster(eventConfig.clusterPath);
+			Patterns patterns = initializePatterns(eventConfig.patternPath);
+			initialize(eventConfig);
+
+			if (!eventConfig.dryRun) {
+				prepare(cluster);
+			}
+			EventrixClient client = new EventrixClient(eventsDir, cluster,
+					eventConfig.dryRun, new DefaultOutputHandler());
+			client.submit(patterns);
+			if (!eventConfig.dryRun) {
+				cleanup(cluster);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			parser.printUsage(System.err);
+		}
+	}
+
+	private static void prepare(Cluster cluster) throws IOException,
+			InterruptedException {
+
+		scriptDirSuffix = "" + System.nanoTime();
+		List<String> args = new ArrayList<String>();
+		args.add(scriptDirSuffix);
+		Node clientNode = new Node();
+		clientNode.setId("client");
+		clientNode.setIp("127.0.0.1");
+		for (Node node : cluster.getNode()) {
+			args.add(node.getIp());
+		}
+		EventUtil.executeLocalScript(clientNode, eventsDir + "/" + "events"
+				+ "/" + "prepare.sh", args);
+	}
+
+	private static void cleanup(Cluster cluster) throws IOException,
+			InterruptedException {
+		List<String> args = new ArrayList<String>();
+		args.add(scriptDirSuffix);
+		Node clientNode = new Node();
+		clientNode.setId("client");
+		clientNode.setIp("127.0.0.1");
+		for (Node node : cluster.getNode()) {
+			args.add(node.getIp());
+		}
+		EventUtil.executeLocalScript(clientNode, eventsDir + "/" + "events"
+				+ "/" + "cleanup.sh", args);
+	}
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/DefaultOutputHandler.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/DefaultOutputHandler.java
new file mode 100644
index 0000000..e8f06a0
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/DefaultOutputHandler.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import edu.uci.ics.asterix.event.schema.pattern.Event;
+
+public class DefaultOutputHandler implements IOutputHandler {
+
+    @Override
+    public OutputAnalysis reportEventOutput(Event event, String output) {
+        return new OutputAnalysis(true, null);
+    }
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/ErrorHandler.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/ErrorHandler.java
new file mode 100644
index 0000000..a6c038b
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/ErrorHandler.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+public class ErrorHandler {
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventExecutor.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventExecutor.java
new file mode 100644
index 0000000..1dd257e
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventExecutor.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+
+import edu.uci.ics.asterix.event.driver.EventDriver;
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.event.schema.cluster.Property;
+import edu.uci.ics.asterix.event.schema.pattern.Pattern;
+
+public class EventExecutor {
+
+	public static final String EVENTS_DIR = "events";
+	private static final String EXECUTE_SCRIPT = "execute.sh";
+	private static final String IP_LOCATION = "IP_LOCATION";
+	private static final String CLUSTER_ENV = "ENV";
+	private static final String SCRIPT = "SCRIPT";
+	private static final String ARGS = "ARGS";
+	private static final String DAEMON = "DAEMON";
+
+	public void executeEvent(Node node, String script, List<String> args,
+			boolean isDaemon, Cluster cluster, Pattern pattern,
+			IOutputHandler outputHandler, EventrixClient client)
+			throws IOException {
+		List<String> pargs = new ArrayList<String>();
+		pargs.add("/bin/bash");
+		pargs.add(client.getEventsDir() + File.separator + "scripts"
+				+ File.separator + EXECUTE_SCRIPT);
+		StringBuffer envBuffer = new StringBuffer(IP_LOCATION + "="
+				+ node.getIp() + " ");
+		if (!node.getId().equals(EventDriver.CLIENT_NODE_ID)) {
+			for (Property p : cluster.getEnv().getProperty()) {
+				if (p.getKey().equals("JAVA_HOME")) {
+					String val = node.getJavaHome() == null ? p.getValue()
+							: node.getJavaHome();
+					envBuffer.append(p.getKey() + "=" + val + " ");
+				} else if (p.getKey().equals("JAVA_OPTS")) {
+					String val = "-Xmx" + (node.getRam() == null ? cluster.getRam()
+							: node.getRam());
+					envBuffer.append(p.getKey() + "=" + val + " ");
+				} else {
+					envBuffer.append(p.getKey() + "=" + p.getValue() + " ");
+				}
+
+			}
+			pargs.add(cluster.getUsername() == null ? System
+					.getProperty("user.name") : cluster.getUsername());
+		}
+		StringBuffer argBuffer = new StringBuffer();
+		if (args != null && args.size() > 0) {
+			for (String arg : args) {
+				argBuffer.append(arg + " ");
+			}
+		}
+
+		ProcessBuilder pb = new ProcessBuilder(pargs);
+		pb.environment().put(IP_LOCATION, node.getIp());
+		pb.environment().put(CLUSTER_ENV, envBuffer.toString());
+		pb.environment().put(SCRIPT, script);
+		pb.environment().put(ARGS, argBuffer.toString());
+		pb.environment().put(DAEMON, isDaemon ? "true" : "false");
+
+		Process p = pb.start();
+		if (!isDaemon) {
+			BufferedInputStream bis = new BufferedInputStream(
+					p.getInputStream());
+			StringWriter writer = new StringWriter();
+			IOUtils.copy(bis, writer, "UTF-8");
+			String result = writer.getBuffer().toString();
+			OutputAnalysis analysis = outputHandler.reportEventOutput(
+					pattern.getEvent(), result);
+			if (!analysis.isExpected()) {
+				throw new IOException(analysis.getErrorMessage() + result);
+			}
+		}
+	}
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventTask.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventTask.java
new file mode 100644
index 0000000..9f52642
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventTask.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import edu.uci.ics.asterix.event.driver.EventDriver;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.event.schema.event.Event;
+import edu.uci.ics.asterix.event.schema.pattern.Pattern;
+import edu.uci.ics.asterix.event.schema.pattern.Period;
+
+public class EventTask extends TimerTask {
+
+	public static enum State {
+		INITIALIZED, IN_PROGRESS, COMPLETED, FAILED
+	}
+
+	private static final Logger logger = Logger.getLogger(EventTask.class
+			.getName());
+
+	private Pattern pattern;
+	private Event event;
+	private long interval = 0;
+	private long initialDelay = 0;
+	private int maxOccurs = Integer.MAX_VALUE;
+	private int occurrenceCount = 0;
+	private Timer timer;
+	private String taskScript;
+	private Node location;
+	private List<String> taskArgs;
+	private EventrixClient client;
+	private List<Node> candidateLocations;
+	private boolean dynamicLocation = false;
+	private boolean reuseLocation = false;
+	private State state;
+
+	static {
+		logger.setLevel(Level.WARNING);
+	}
+
+	public EventTask(Pattern pattern, EventrixClient client) {
+		this.pattern = pattern;
+		this.client = client;
+		Period period = pattern.getPeriod();
+		if (period != null && period.getAbsvalue() != null) {
+			this.interval = EventUtil.parseTimeInterval(period.getAbsvalue(),
+					period.getUnit());
+		}
+		if (pattern.getDelay() != null) {
+			this.initialDelay = EventUtil.parseTimeInterval(new ValueType(
+					pattern.getDelay().getValue()), pattern.getDelay()
+					.getUnit());
+		}
+		if (pattern.getMaxOccurs() != null) {
+			this.maxOccurs = pattern.getMaxOccurs();
+		}
+		this.timer = new Timer();
+		taskArgs = EventUtil.getEventArgs(pattern);
+		candidateLocations = EventUtil.getCandidateLocations(pattern,
+				client.getCluster());
+		if (pattern.getEvent().getNodeid().getValue().getRandom() != null
+				&& period != null && maxOccurs > 1) {
+			dynamicLocation = true;
+			reuseLocation = pattern.getEvent().getNodeid().getValue()
+					.getRandom().getRange().isReuse();
+		} else {
+			location = EventUtil.getEventLocation(pattern, candidateLocations,
+					client.getCluster());
+		}
+		String scriptsDir;
+		if (location.getId().equals(EventDriver.CLIENT_NODE_ID)) {
+			scriptsDir = client.getEventsDir() + File.separator + "events";
+		} else {
+			scriptsDir = client.getCluster().getWorkingDir().getDir() + File.separator + "eventrix" + File.separator + "events";
+		}
+		event = EventUtil.getEvent(pattern, client.getEvents());
+		taskScript = scriptsDir + File.separator + event.getScript();
+		state = State.INITIALIZED;
+	}
+
+	public void start() {
+		if (interval > 0) {
+			timer.schedule(this, initialDelay, interval);
+		} else {
+			timer.schedule(this, initialDelay);
+		}
+	}
+
+	@Override
+	public void run() {
+		if (candidateLocations.size() == 0) {
+			timer.cancel();
+			client.notifyCompletion(new EventTaskReport(this));
+		} else {
+			if (dynamicLocation) {
+				location = EventUtil.getEventLocation(pattern,
+						candidateLocations, client.getCluster());
+				if (!reuseLocation) {
+					candidateLocations.remove(location);
+				}
+			}
+
+			logger.info(EventUtil.dateFormat.format(new Date()) + " "
+					+ "EVENT " + pattern.getEvent().getType().toUpperCase()
+					+ " at " + location.getId().toUpperCase());
+			try {
+				if (!client.isDryRun()) {
+					new EventExecutor().executeEvent(location, taskScript,
+							taskArgs, event.isDaemon(), client.getCluster(),
+							pattern, client.getErrorHandler(), client);
+				}
+				occurrenceCount++;
+				if (occurrenceCount >= maxOccurs) {
+					timer.cancel();
+					client.notifyCompletion(new EventTaskReport(this));
+				}
+			} catch (IOException ioe) {
+				timer.cancel();
+				client
+						.notifyCompletion(new EventTaskReport(this, false, ioe));
+			}
+		}
+
+	}
+
+	public Node getLocation() {
+		return location;
+	}
+
+	public long getInterval() {
+		return interval;
+	}
+
+	public long getInitialDelay() {
+		return initialDelay;
+	}
+
+	public Pattern getPattern() {
+		return pattern;
+	}
+
+	public State getState() {
+		return state;
+	}
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventTaskReport.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventTaskReport.java
new file mode 100644
index 0000000..7ad3682
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventTaskReport.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import java.io.Serializable;
+
+public class EventTaskReport implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    private final EventTask task;
+    private final boolean success;
+    private final Exception e;
+
+    public EventTaskReport(EventTask task, boolean success, Exception e) {
+        this.task = task;
+        this.success = success;
+        this.e = e;
+    }
+
+    public EventTaskReport(EventTask task) {
+        this.task = task;
+        this.success = true;
+        this.e = null;
+    }
+
+    public Exception getException() {
+        return e;
+    }
+
+    public EventTask getTask() {
+        return task;
+    }
+
+    public boolean isSuccess() {
+        return success;
+    }
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventUtil.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventUtil.java
new file mode 100644
index 0000000..7fe0d7c
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventUtil.java
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import edu.uci.ics.asterix.event.driver.EventDriver;
+import edu.uci.ics.asterix.event.management.ValueType.Type;
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.event.schema.event.Event;
+import edu.uci.ics.asterix.event.schema.event.Events;
+import edu.uci.ics.asterix.event.schema.pattern.Pattern;
+
+public class EventUtil {
+
+	public static final String EVENTS_DIR = "events";
+	public static final String CLUSTER_CONF = "config/cluster.xml";
+	public static final String PATTERN_CONF = "config/pattern.xml";
+	public static final DateFormat dateFormat = new SimpleDateFormat(
+			"yyyy/MM/dd HH:mm:ss");
+
+	private static final String IP_LOCATION = "IP_LOCATION";
+	private static final String CLUSTER_ENV = "ENV";
+	private static final String SCRIPT = "SCRIPT";
+	private static final String ARGS = "ARGS";
+	private static final String EXECUTE_SCRIPT = "events/execute.sh";
+
+	public static long parseTimeInterval(ValueType v, String unit)
+			throws IllegalArgumentException {
+		int val = 0;
+		switch (v.getType()) {
+		case ABS:
+			val = Integer.parseInt(v.getAbsoluteValue());
+			break;
+		case RANDOM_MIN_MAX:
+			val = Randomizer.getInstance().getRandomInt(v.getMin(), v.getMax());
+			break;
+		case RANDOM_RANGE:
+			String[] values = v.getRangeSet();
+			val = Integer.parseInt(values[Randomizer.getInstance()
+					.getRandomInt(0, values.length - 1)]);
+			break;
+		}
+		return computeInterval(val, unit);
+	}
+
+	public static long parseTimeInterval(String v, String unit)
+			throws IllegalArgumentException {
+		int value = Integer.parseInt(v);
+		return computeInterval(value, unit);
+	}
+
+	private static long computeInterval(int val, String unit) {
+		int vmult = 1;
+		if ("hr".equalsIgnoreCase(unit)) {
+			vmult = 3600 * 1000;
+		} else if ("min".equalsIgnoreCase(unit)) {
+			vmult = 60 * 1000;
+		} else if ("sec".equalsIgnoreCase(unit)) {
+			vmult = 1000;
+		} else
+			throw new IllegalArgumentException(
+					" invalid unit value specified for frequency (hr,min,sec)");
+		return val * vmult;
+
+	}
+
+	public static Event getEvent(Pattern pattern, Events events) {
+		for (Event event : events.getEvent()) {
+			if (event.getType().equals(pattern.getEvent().getType())) {
+				return event;
+			}
+		}
+		throw new IllegalArgumentException(" Unknown event type"
+				+ pattern.getEvent().getType());
+	}
+
+	public static Node getEventLocation(Pattern pattern,
+			List<Node> candidateLocations, Cluster cluster) {
+		ValueType value = new ValueType(pattern.getEvent().getNodeid()
+				.getValue());
+		Node location = null;
+		Type vtype = value.getType();
+
+		switch (vtype) {
+		case ABS:
+			location = getNodeFromId(value.getAbsoluteValue(), cluster);
+			break;
+		case RANDOM_RANGE:
+			int nodeIndex = Randomizer.getInstance().getRandomInt(0,
+					candidateLocations.size() - 1);
+			location = candidateLocations.get(nodeIndex);
+			break;
+		case RANDOM_MIN_MAX:
+			throw new IllegalStateException(
+					" Canont configure a min max value range for location");
+		}
+		return location;
+
+	}
+
+	public static List<Node> getCandidateLocations(Pattern pattern,
+			Cluster cluster) {
+		ValueType value = new ValueType(pattern.getEvent().getNodeid()
+				.getValue());
+		List<Node> candidateList = new ArrayList<Node>();
+		switch (value.getType()) {
+		case ABS:
+			candidateList.add(getNodeFromId(value.getAbsoluteValue(), cluster));
+			break;
+		case RANDOM_RANGE:
+			boolean anyOption = false;
+			String[] values = value.getRangeSet();
+			for (String v : values) {
+				if (v.equalsIgnoreCase("ANY")) {
+					anyOption = true;
+				}
+			}
+			if (anyOption) {
+				for (Node node : cluster.getNode()) {
+					candidateList.add(node);
+				}
+			} else {
+				boolean found = false;
+				for (String v : values) {
+					for (Node node : cluster.getNode()) {
+						if (node.getId().equals(v)) {
+							candidateList.add(node);
+							found = true;
+							break;
+						}
+					}
+					if (!found) {
+						throw new IllegalStateException("Unknonw nodeId : " + v);
+					}
+					found = false;
+				}
+
+			}
+			String[] excluded = value.getRangeExcluded();
+			if (excluded != null && excluded.length > 0) {
+				List<Node> markedForRemoval = new ArrayList<Node>();
+				for (String exclusion : excluded) {
+					for (Node node : candidateList) {
+						if (node.getId().equals(exclusion)) {
+							markedForRemoval.add(node);
+						}
+					}
+				}
+				candidateList.removeAll(markedForRemoval);
+			}
+			break;
+		case RANDOM_MIN_MAX:
+			throw new IllegalStateException(
+					" Invalid value configured for location");
+		}
+		return candidateList;
+	}
+
+	private static Node getNodeFromId(String nodeid, Cluster cluster) {
+		if (nodeid.equals(EventDriver.CLIENT_NODE.getId())) {
+			return EventDriver.CLIENT_NODE;
+		}
+
+		if (nodeid.equals(cluster.getMasterNode().getId())) {
+			String ram = cluster.getMasterNode().getRam() == null ? cluster
+					.getRam() : cluster.getMasterNode().getRam();
+			String logDir = cluster.getMasterNode().getLogdir() == null ? cluster
+					.getLogdir() : cluster.getMasterNode().getLogdir();
+			String javaHome = cluster.getMasterNode().getJavaHome() == null ? cluster
+					.getJavaHome() : cluster.getMasterNode().getJavaHome();
+			return new Node(cluster.getMasterNode().getId(), cluster
+					.getMasterNode().getIp(), ram, javaHome, logDir, null);
+		}
+
+		List<Node> nodeList = cluster.getNode();
+		for (Node node : nodeList) {
+			if (node.getId().equals(nodeid)) {
+				return node;
+			}
+		}
+		StringBuffer buffer = new StringBuffer();
+		buffer.append(EventDriver.CLIENT_NODE.getId() + ",");
+		buffer.append(cluster.getMasterNode().getId() + ",");
+		for (Node v : cluster.getNode()) {
+			buffer.append(v.getId() + ",");
+		}
+		buffer.deleteCharAt(buffer.length() - 1);
+		throw new IllegalArgumentException("Unknown node id :" + nodeid
+				+ " valid ids:" + buffer);
+	}
+
+	public static void executeEventScript(Node node, String script,
+			List<String> args, Cluster cluster) throws IOException,
+			InterruptedException {
+		List<String> pargs = new ArrayList<String>();
+		pargs.add("/bin/bash");
+		pargs.add(EventDriver.getEventsDir() + "/" + EXECUTE_SCRIPT);
+		StringBuffer argBuffer = new StringBuffer();
+		String env = EventDriver.getStringifiedEnv(cluster) + " " + IP_LOCATION
+				+ "=" + node.getIp();
+		if (args != null) {
+			for (String arg : args) {
+				argBuffer.append(arg + " ");
+			}
+		}
+		ProcessBuilder pb = new ProcessBuilder(pargs);
+		pb.environment().putAll(EventDriver.getEnvironment());
+		pb.environment().put(IP_LOCATION, node.getIp());
+		pb.environment().put(CLUSTER_ENV, env);
+		pb.environment().put(SCRIPT, script);
+		pb.environment().put(ARGS, argBuffer.toString());
+		pb.start();
+	}
+
+	public static void executeLocalScript(Node node, String script,
+			List<String> args) throws IOException, InterruptedException {
+		List<String> pargs = new ArrayList<String>();
+		pargs.add("/bin/bash");
+		pargs.add(script);
+		if (args != null) {
+			pargs.addAll(args);
+		}
+		ProcessBuilder pb = new ProcessBuilder(pargs);
+		pb.environment().putAll(EventDriver.getEnvironment());
+		pb.environment().put(IP_LOCATION, node.getIp());
+		pb.start();
+	}
+
+	public static List<String> getEventArgs(Pattern pattern) {
+		List<String> pargs = new ArrayList<String>();
+		if (pattern.getEvent().getPargs() == null) {
+			return pargs;
+		}
+		String[] args = pattern.getEvent().getPargs().split(" ");
+		for (String arg : args) {
+			pargs.add(arg.trim());
+		}
+		return pargs;
+	}
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventrixClient.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventrixClient.java
new file mode 100644
index 0000000..4cd4b82
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/EventrixClient.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import edu.uci.ics.asterix.event.driver.EventDriver;
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.event.schema.event.Events;
+import edu.uci.ics.asterix.event.schema.pattern.Event;
+import edu.uci.ics.asterix.event.schema.pattern.Nodeid;
+import edu.uci.ics.asterix.event.schema.pattern.Pattern;
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.event.schema.pattern.Value;
+
+public class EventrixClient {
+
+	private static final Logger LOGGER = Logger.getLogger(EventrixClient.class
+			.getName());
+
+	private EventTask[] tasks;
+	private boolean dryRun = false;
+	private LinkedBlockingQueue<EventTaskReport> msgInbox = new LinkedBlockingQueue<EventTaskReport>();
+	private AtomicInteger pendingTasks = new AtomicInteger(0);
+	private final Cluster cluster;
+	private IPatternListener listener;
+	private IOutputHandler outputHandler;
+	private Events events;
+	private String eventsDir;
+
+	public EventrixClient(String eventsDir, Cluster cluster, boolean dryRun,
+			IOutputHandler outputHandler) throws Exception {
+		this.eventsDir = eventsDir;
+		this.events = initializeEvents();
+		this.cluster = cluster;
+		this.dryRun = dryRun;
+		this.outputHandler = outputHandler;
+		if (!dryRun) {
+			initializeCluster(eventsDir);
+		}
+	}
+
+	public void submit(Patterns patterns) throws Exception {
+		initTasks(patterns);
+		try {
+			waitForCompletion();
+		} catch (InterruptedException ie) {
+			LOGGER.info("Interrupted exception :" + ie);
+		} catch (Exception e) {
+			throw e;
+		}
+
+	}
+
+	public void submit(Patterns patterns, IPatternListener listener)
+			throws Exception {
+		this.listener = listener;
+		initTasks(patterns);
+	}
+
+	private void initTasks(Patterns patterns) {
+		tasks = new EventTask[patterns.getPattern().size()];
+		pendingTasks.set(tasks.length);
+		int index = 0;
+		for (Pattern pattern : patterns.getPattern()) {
+			tasks[index] = new EventTask(pattern, this);
+			tasks[index].start();
+			index++;
+		}
+	}
+
+	public Cluster getCluster() {
+		return cluster;
+	}
+
+	public boolean isDryRun() {
+		return dryRun;
+	}
+
+	public Events getEvents() {
+		return events;
+	}
+
+	public String getEventsDir() {
+		return eventsDir;
+	}
+
+	public synchronized void notifyCompletion(EventTaskReport report) {
+
+		if (report.isSuccess()) {
+			if (listener != null) {
+				pendingTasks.decrementAndGet();
+				listener.eventCompleted(report);
+				if (pendingTasks.get() == 0) {
+					listener.jobCompleted();
+				}
+			} else {
+				try {
+					msgInbox.put(report);
+				} catch (InterruptedException e) {
+				}
+			}
+		} else {
+			for (EventTask t : tasks) {
+				if (t.getState() == EventTask.State.INITIALIZED
+						|| t.getState() == EventTask.State.IN_PROGRESS) {
+					t.cancel();
+				}
+			}
+			if (listener != null) {
+				listener.jobFailed(report);
+			} else {
+				try {
+					msgInbox.put(report);
+				} catch (InterruptedException e) {
+				}
+			}
+		}
+	}
+
+	private void waitForCompletion() throws Exception {
+		while (true) {
+			EventTaskReport report = msgInbox.take();
+			if (report.isSuccess()) {
+				if (pendingTasks.decrementAndGet() == 0) {
+					break;
+				}
+			} else {
+				throw new RuntimeException(report.getException().getMessage());
+			}
+		}
+	}
+
+	private void initializeCluster(String eventsDir) throws Exception {
+		Patterns patterns = initPattern(eventsDir);
+		submit(patterns);
+	}
+
+	private Patterns initPattern(String eventsDir) {
+		Nodeid nodeid = new Nodeid(new Value(null,
+				EventDriver.CLIENT_NODE.getId()));
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		String workingDir = cluster.getWorkingDir().getDir();
+		String username = cluster.getUsername() == null ? System
+				.getProperty("user.name") : cluster.getUsername();
+		patternList.add(getDirectoryTransferPattern(username, eventsDir,
+				nodeid, cluster.getMasterNode().getIp(), workingDir));
+
+		if (!cluster.getWorkingDir().isNFS()) {
+			for (Node node : cluster.getNode()) {
+				patternList.add(getDirectoryTransferPattern(username,
+						eventsDir, nodeid, node.getIp(), workingDir));
+			}
+		}
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
+
+	private Pattern getDirectoryTransferPattern(String username, String src,
+			Nodeid srcNode, String destNodeIp, String destDir) {
+		String pargs = username + " " + src + " " + destNodeIp + " " + destDir;
+		Event event = new Event("directory_transfer", srcNode, pargs);
+		return new Pattern(null, 1, null, event);
+	}
+
+	public IOutputHandler getErrorHandler() {
+		return outputHandler;
+	}
+
+	private Events initializeEvents() throws JAXBException,
+			FileNotFoundException {
+		File file = new File(eventsDir + File.separator + "events"
+				+ File.separator + "events.xml");
+		JAXBContext eventCtx = JAXBContext.newInstance(Events.class);
+		Unmarshaller unmarshaller = eventCtx.createUnmarshaller();
+		events = (Events) unmarshaller.unmarshal(file);
+		return events;
+	}
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/IOutputHandler.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/IOutputHandler.java
new file mode 100644
index 0000000..c7929cb
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/IOutputHandler.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import edu.uci.ics.asterix.event.schema.pattern.Event;
+
+public interface IOutputHandler {
+
+    public OutputAnalysis reportEventOutput(Event event, String output);
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/IPatternListener.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/IPatternListener.java
new file mode 100644
index 0000000..06a56cf
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/IPatternListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+public interface IPatternListener {
+
+    public void eventCompleted(EventTaskReport report);
+
+    public void jobCompleted();
+
+    public void jobFailed(EventTaskReport report);
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/OutputAnalysis.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/OutputAnalysis.java
new file mode 100644
index 0000000..2845ede
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/OutputAnalysis.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+public class OutputAnalysis {
+
+    private final boolean expected;
+    private final String errorMessage;
+
+    public OutputAnalysis(boolean expected, String errorMessage) {
+        this.expected = expected;
+        this.errorMessage = errorMessage;
+    }
+
+    public boolean isExpected() {
+        return expected;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/Randomizer.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/Randomizer.java
new file mode 100644
index 0000000..e59e154
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/Randomizer.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import java.util.Random;
+import java.util.logging.Logger;
+
+public class Randomizer {
+
+	private static final Logger LOGGER = Logger.getLogger(Randomizer.class
+			.getName());
+	private static Randomizer INSTANCE;
+	private final Random random;
+	private final int seed;
+
+	public static Randomizer getInstance(int seed) {
+		if (INSTANCE == null) {
+			INSTANCE = new Randomizer(seed);
+		}
+		return INSTANCE;
+	}
+
+	public static Randomizer getInstance() {
+		if (INSTANCE == null) {
+			INSTANCE = new Randomizer();
+		}
+		return INSTANCE;
+	}
+
+	private Randomizer() {
+		Random rm = new Random();
+		seed = rm.nextInt(10000);
+		random = new Random(seed);
+		LOGGER.info("SEED:" + seed);
+	}
+
+	private Randomizer(int seed) {
+		this.seed = seed;
+		random = new Random(seed);
+		LOGGER.info("SEED:" + seed);
+	}
+
+	public Random getRandom() {
+		return random;
+	}
+
+	public int getSeed() {
+		return seed;
+	}
+
+	public int getRandomInt(int min, int max) {
+		return min + random.nextInt(max - min + 1);
+	}
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/ValueType.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/ValueType.java
new file mode 100644
index 0000000..8aa5cc5
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/management/ValueType.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.management;
+
+import edu.uci.ics.asterix.event.schema.pattern.Value;
+
+public class ValueType {
+
+	public static enum Type {
+		ABS, RANDOM_RANGE, RANDOM_MIN_MAX
+	}
+
+	private Value value;
+	private Type type;
+
+	public ValueType(Value value) {
+		this.value = value;
+		if (value.getAbsvalue() != null) {
+			type = Type.ABS;
+		} else if (value.getRandom() != null) {
+			if (value.getRandom().getMinmax() != null) {
+				type = Type.RANDOM_MIN_MAX;
+			} else if (value.getRandom().getRange() != null) {
+				type = Type.RANDOM_RANGE;
+			} else {
+				throw new IllegalStateException("Incorrect value type");
+			}
+		}
+	}
+
+	public int getMin() {
+		switch (type) {
+		case RANDOM_MIN_MAX:
+			return Integer.parseInt(value.getRandom().getMinmax().getMin());
+		default:
+			throw new IllegalStateException("");
+		}
+	}
+
+	public int getMax() {
+		switch (type) {
+		case RANDOM_MIN_MAX:
+			return Integer.parseInt(value.getRandom().getMinmax().getMax());
+		default:
+			throw new IllegalStateException("");
+		}
+	}
+
+	public String[] getRangeSet() {
+		switch (type) {
+		case RANDOM_RANGE:
+			return value.getRandom().getRange().getSet().split(" ");
+		default:
+			throw new IllegalStateException("");
+		}
+	}
+
+	public String[] getRangeExcluded() {
+		switch (type) {
+		case RANDOM_RANGE:
+			String exl = value.getRandom().getRange().getExclude();
+			return exl != null ? exl.split(" ") : null;
+		default:
+			throw new IllegalStateException("");
+		}
+	}
+
+	public String getAbsoluteValue() {
+		switch (type) {
+		case ABS:
+			return value.getAbsvalue();
+		default:
+			throw new IllegalStateException("");
+		}
+	}
+
+	public Type getType() {
+		return type;
+	}
+
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/xml/ConfigParser.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/xml/ConfigParser.java
new file mode 100644
index 0000000..b399226
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/xml/ConfigParser.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.xml;
+
+import java.io.File;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+public class ConfigParser {
+
+	private static final String JAXB_PKG = "edu.uci.ics.asterix.event.trigger";
+	
+	public static void main(String [] args){
+		try {
+			String path = "config/event_pattern1.xml";
+			JAXBContext ctx =  JAXBContext.newInstance(JAXB_PKG);
+		    Unmarshaller unmarshaller = ctx.createUnmarshaller();
+		    Object o = unmarshaller.unmarshal(new File(path));
+	  } catch (JAXBException e) {
+			e.printStackTrace();
+		}
+
+	}
+}
diff --git a/asterix-events/src/main/java/edu/uci/ics/asterix/event/xml/PatternParser.java b/asterix-events/src/main/java/edu/uci/ics/asterix/event/xml/PatternParser.java
new file mode 100644
index 0000000..426279c
--- /dev/null
+++ b/asterix-events/src/main/java/edu/uci/ics/asterix/event/xml/PatternParser.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.event.xml;
+
+public class PatternParser {
+
+	public static void parsePattern(String path){
+		
+	}
+}
+
diff --git a/asterix-events/src/main/resources/events/asterix_deploy/asterix_deploy.sh b/asterix-events/src/main/resources/events/asterix_deploy/asterix_deploy.sh
new file mode 100755
index 0000000..532e559
--- /dev/null
+++ b/asterix-events/src/main/resources/events/asterix_deploy/asterix_deploy.sh
@@ -0,0 +1,11 @@
+MANAGIX_HOME=$1
+HYRACKS_CLI=$MANAGIX_HOME/asterix/hyracks-cli/bin/hyrackscli
+if  ! [ -x $HYRACKS_CLI ]
+then
+     chmod +x $HYRACKS_CLI
+fi
+ASTERIX_ZIP=$2
+HOST=$3
+echo "connect to \"$HOST\";" > temp
+echo "create application asterix \"$ASTERIX_ZIP\";" >> temp 
+($HYRACKS_CLI < temp)  
diff --git a/asterix-events/src/main/resources/events/backup/backup.sh b/asterix-events/src/main/resources/events/backup/backup.sh
new file mode 100755
index 0000000..cff37df
--- /dev/null
+++ b/asterix-events/src/main/resources/events/backup/backup.sh
@@ -0,0 +1,19 @@
+WORKING_DIR=$1
+ASTERIX_INSTANCE_NAME=$2
+ASTERIX_DATA_DIR=$3
+BACKUP_ID=$4
+HDFS_URL=$5
+HADOOP_VERSION=$6
+HDFS_BACKUP_DIR=$7
+NODE_ID=$8
+
+export HADOOP_HOME=$WORKING_DIR/hadoop-$HADOOP_VERSION
+
+nodeStores=$(echo $ASTERIX_DATA_DIR | tr "," "\n")
+for nodeStore in $nodeStores
+do
+  NODE_BACKUP_DIR=$HDFS_BACKUP_DIR/$ASTERIX_INSTANCE_NAME/$BACKUP_ID/$NODE_ID/$nodeStore
+  $HADOOP_HOME/bin/hadoop fs -mkdir $HDFS_URL/$NODE_BACKUP_DIR
+  echo "$HADOOP_HOME/bin/hadoop fs -copyFromLocal $nodeStore/$NODE_ID $HDFS_URL/$NODE_BACKUP_DIR" >> ~/backup.log
+  $HADOOP_HOME/bin/hadoop fs -copyFromLocal $nodeStore/$NODE_ID/$ASTERIX_INSTANCE_NAME/* $HDFS_URL/$NODE_BACKUP_DIR/
+done
diff --git a/asterix-events/src/main/resources/events/cc_failure/cc_failure.sh b/asterix-events/src/main/resources/events/cc_failure/cc_failure.sh
new file mode 100755
index 0000000..0855f5f
--- /dev/null
+++ b/asterix-events/src/main/resources/events/cc_failure/cc_failure.sh
@@ -0,0 +1,6 @@
+#kill -9 `ps -ef  | grep hyracks | grep -v grep | cut -d "/" -f1 | tr -s " " | cut -d " " -f2`
+CC_PARENT_ID_INFO=`ps -ef  | grep hyracks | grep cc_start | grep -v ssh`
+CC_PARENT_ID=`echo $CC_PARENT_ID_INFO | tr -s " " | cut -d " " -f2`
+CC_ID_INFO=`ps -ef | grep hyracks | grep $CC_PARENT_ID | grep -v bash`
+CC_ID=`echo $CC_ID_INFO |  tr -s " " | cut -d " " -f2`
+kill -9 $CC_ID
diff --git a/asterix-events/src/main/resources/events/cc_start/cc_start.sh b/asterix-events/src/main/resources/events/cc_start/cc_start.sh
new file mode 100755
index 0000000..e0b29e0
--- /dev/null
+++ b/asterix-events/src/main/resources/events/cc_start/cc_start.sh
@@ -0,0 +1,9 @@
+if [ ! -d $LOG_DIR ]; 
+then 
+  mkdir -p $LOG_DIR
+fi
+if [ ! -z $1 ];
+then
+  JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=$1,server=y,suspend=n"
+fi  
+$HYRACKS_HOME/bin/hyrackscc -client-net-ip-address $CLIENT_NET_IP -client-net-port 1098 -cluster-net-ip-address $CLUSTER_NET_IP -cluster-net-port 1099 -http-port 8888  &> $LOG_DIR/cc.log
diff --git a/asterix-events/src/main/resources/events/events.xml b/asterix-events/src/main/resources/events/events.xml
new file mode 100644
index 0000000..857ee5a
--- /dev/null
+++ b/asterix-events/src/main/resources/events/events.xml
@@ -0,0 +1,100 @@
+<events xmlns="events">
+  <event>
+    <type>node_join</type>
+    <script>node_join/nc_join.sh</script>
+    <description>Creates a NodeController process at a specified location.</description>
+    <args>location_of_cc location(hostname/ip_address) node_controller_id</args>
+    <daemon>true</daemon>
+  </event>
+  <event>
+    <type>node_failure</type>
+    <script>node_failure/nc_failure.sh</script>
+    <description>Kills a NodeController process at a specified location.</description>
+    <args>node_controller_id</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>cc_start</type>
+    <script>cc_start/cc_start.sh</script>
+    <description>Starts a  ClusterController process at a specified location.</description>
+    <args></args>
+    <daemon>true</daemon>
+  </event>
+  <event>
+    <type>cc_failure</type>
+    <script>cc_failure/cc_failure.sh</script>
+    <description>Kills the Cluster Controller process running at a specified location.</description>
+    <args></args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>node_restart</type>
+    <script>node_restart/nc_restart.sh</script>
+    <description>Shuts and restarts a NodeControllerProcess after a specified time interval, at a specified location</description>
+    <args>address of cc, node controller id and sleep interval(seconds)</args>
+    <daemon>true</daemon>
+  </event>
+  <event>
+    <type>asterix_deploy</type>
+    <script>asterix_deploy/asterix_deploy.sh</script>
+    <description>Deploys Asterix application on a cluster running hyracks</description>
+    <args>IP address of the node running the hyracks cluster controller</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>zookeeper_start</type>
+    <script>zookeeper/start.sh</script>
+    <description>Launches ZooKeeper server process</description>
+    <args>IP address of the ZooKeeper server</args>
+    <daemon>true</daemon>
+  </event>
+  <event>
+    <type>zookeeper_stop</type>
+    <script>zookeeper/stop.sh</script>
+    <description>Terminates ZooKeeper server process</description>
+    <args>IP address of the ZooKeeper server</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>file_transfer</type>
+    <script>file/transfer.sh</script>
+    <description>Copies a file on the local file system to a remote node</description>
+    <args>local_source_path destination_node destination_path</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>directory_transfer</type>
+    <script>file/dir_transfer.sh</script>
+    <description>Copies a directory (and its contents) on the local file system to a remote node</description>
+    <args>local_source_path destination_node destination_path</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>file_delete</type>
+    <script>file/delete.sh</script>
+    <description>Deletes a file on the local file system to a remote node</description>
+    <args>local_source_path destination_node destination_path</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>backup</type>
+    <script>backup/backup.sh</script>
+    <description>Takes a backup of an Asterix instance</description>
+    <args>Asterix_data_dir HDFSurl</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>restore</type>
+    <script>restore/restore.sh</script>
+    <description>Restores an Asterix instance from a back up</description>
+    <args>Asterix_data_dir HDFSurl</args>
+    <daemon>false</daemon>
+  </event>
+  <event>
+    <type>hdfs_delete</type>
+    <script>hdfs/delete.sh</script>
+    <description>Deletes an HDFS path</description>
+    <args>WorkingDir HadoopVersion HDFSUrl Path_to_Delete</args>
+    <daemon>false</daemon>
+  </event>
+</events>
diff --git a/asterix-events/src/main/resources/events/file/delete.sh b/asterix-events/src/main/resources/events/file/delete.sh
new file mode 100755
index 0000000..d5ac3ff
--- /dev/null
+++ b/asterix-events/src/main/resources/events/file/delete.sh
@@ -0,0 +1,3 @@
+PATH_TO_DELETE=$1
+echo "rm -rf $PATH_TO_DELETE" >> ~/backup.log
+rm -rf $PATH_TO_DELETE
diff --git a/asterix-events/src/main/resources/events/file/dir_transfer.sh b/asterix-events/src/main/resources/events/file/dir_transfer.sh
new file mode 100755
index 0000000..af7da70
--- /dev/null
+++ b/asterix-events/src/main/resources/events/file/dir_transfer.sh
@@ -0,0 +1,7 @@
+USERNAME=$1
+DIR_TO_TRANSFER=$2
+DEST_HOST=$3
+DEST_DIR=$4
+ssh -l $USERNAME $DEST_HOST "mkdir -p $DEST_DIR"
+echo "scp -r $DIR_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/" 
+scp -r $DIR_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/
diff --git a/asterix-events/src/main/resources/events/file/transfer.sh b/asterix-events/src/main/resources/events/file/transfer.sh
new file mode 100755
index 0000000..08f0b43
--- /dev/null
+++ b/asterix-events/src/main/resources/events/file/transfer.sh
@@ -0,0 +1,23 @@
+USERNAME=$1
+FILE_TO_TRANSFER=$2
+DEST_HOST=$3
+DEST_DIR=$4
+POST_ACTION=$5
+ssh -l $USERNAME $DEST_HOST "mkdir -p $DEST_DIR"
+echo "scp $FILE_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/" 
+scp $FILE_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/
+if [ $POST_ACTION == "unpack" ]
+ then 
+ filename=`echo ${FILE_TO_TRANSFER##*/}`
+ fileType=`echo ${FILE_TO_TRANSFER##*.}`
+ if [ $fileType == "tar" ]
+ then 
+   echo "ssh -l $USERNAME $DEST_HOST cd $DEST_DIR && tar xf $filename"
+   ssh -l $USERNAME $DEST_HOST "cd $DEST_DIR && tar xf $filename"
+ else if [ $fileType == "zip" ]
+   then
+     echo "ssh -l $USERNAME $DEST_HOST unzip -o -q -d $DEST_DIR $DEST_DIR/$filename"
+     ssh -l $USERNAME $DEST_HOST "unzip -o -q -d $DEST_DIR $DEST_DIR/$filename"
+   fi 
+ fi
+fi
diff --git a/asterix-events/src/main/resources/events/hdfs/delete.sh b/asterix-events/src/main/resources/events/hdfs/delete.sh
new file mode 100755
index 0000000..6ff54ee
--- /dev/null
+++ b/asterix-events/src/main/resources/events/hdfs/delete.sh
@@ -0,0 +1,7 @@
+WORKING_DIR=$1
+HADOOP_VERSION=$2
+HDFS_URL=$3
+HDFS_PATH=$4
+export HADOOP_HOME=$WORKING_DIR/hadoop-$HADOOP_VERSION
+echo "$HADOOP_HOME/bin/hadoop fs -rmr $HDFS_URL/$HDFS_PATH"
+$HADOOP_HOME/bin/hadoop fs -rmr $HDFS_URL/$HDFS_PATH
diff --git a/asterix-events/src/main/resources/events/node_failure/nc_failure.sh b/asterix-events/src/main/resources/events/node_failure/nc_failure.sh
new file mode 100755
index 0000000..b853be1
--- /dev/null
+++ b/asterix-events/src/main/resources/events/node_failure/nc_failure.sh
@@ -0,0 +1,19 @@
+NC_ID=$1
+
+#if [ $NC_ID == 'ANY' ]
+#then
+#  NC_ID="." 
+#fi 
+#
+#USER=`who am i | tr -s " " | cut -d " " -f1`
+#PARENT_ID=`ps -ef  | tr -s " " | grep nc_join | grep -v grep | grep -v ssh | grep $NC_ID | cut -d " " -f2 | head -n 1` 
+#PID=`ps -ef | tr -s " " | grep hyracks | grep -v grep | grep -v nc_join |  grep $PARENT_ID | cut -d " " -f2 | head -n 1`
+#kill -9 $PID
+#
+
+
+INFO=`ps -ef | grep nc_join | grep -v grep | grep -v ssh| grep $NC_ID | head -n 1`
+PARENT_ID=`echo  $INFO | cut -d " "  -f2`
+PID_INFO=`ps -ef |  grep hyracks | grep -v grep | grep -v nc_join |  grep $PARENT_ID`
+PID=`echo $PID_INFO | cut -d " " -f2`
+kill -9 $PID
diff --git a/asterix-events/src/main/resources/events/node_join/nc_join.sh b/asterix-events/src/main/resources/events/node_join/nc_join.sh
new file mode 100755
index 0000000..62d71ce
--- /dev/null
+++ b/asterix-events/src/main/resources/events/node_join/nc_join.sh
@@ -0,0 +1,11 @@
+CC_HOST=$1
+NC_ID=$2
+if [ ! -d $LOG_DIR ]; 
+then 
+  mkdir -p $LOG_DIR
+fi
+if [ ! -z $3 ];
+then
+  JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=$3,server=y,suspend=n"
+fi  
+$HYRACKS_HOME/bin/hyracksnc -node-id $NC_ID -cc-host $CC_HOST -cc-port 1099 -cluster-net-ip-address $IP_LOCATION  -data-ip-address $IP_LOCATION &> $LOG_DIR/${NC_ID}.log
diff --git a/asterix-events/src/main/resources/events/node_restart/nc_restart.sh b/asterix-events/src/main/resources/events/node_restart/nc_restart.sh
new file mode 100755
index 0000000..961ce8d
--- /dev/null
+++ b/asterix-events/src/main/resources/events/node_restart/nc_restart.sh
@@ -0,0 +1,21 @@
+CC_HOST=$1
+NC_ID=$2
+SLEEP_TIME=$3
+
+if [ $NC_ID == 'ANY' ]
+then
+  NC_ID="." 
+  PARENT_ID=`ps -ej | tr -s " " | grep nc_join | grep -v grep | grep -v ssh |  cut -d " " -f2 | head -n 1` 
+  PARENT_PROCESS_ENTRY=`ps -ef | grep $PARENT_ID | grep -v grep   | head -n 1`
+  NC_ID=`echo ${PARENT_PROCESS_ENTRY##* }`
+  echo "NCid is $NC_ID" >> ~/try.txt
+else 
+  PARENT_ID=`ps -ej | tr -s " " | grep nc_join | grep -v grep | grep -v ssh | grep $NC_ID | cut -d " " -f2 | head -n 1` 
+fi 
+
+PID=`ps -ej | tr -s " " | grep hyracks | grep -v grep | grep -v nc_join |  grep $PARENT_ID | cut -d " " -f2 | head -n 1`
+kill -9 $PID
+
+sleep $3
+
+$HYRACKS_HOME/hyracks-server/target/hyracks-server-0.2.2-SNAPSHOT-binary-assembly/bin/hyracksnc -node-id $NC_ID -cc-host $CC_HOST -cc-port 1099 -cluster-net-ip-address $IP_LOCATION  -data-ip-address $IP_LOCATION
diff --git a/asterix-events/src/main/resources/events/restore/restore.sh b/asterix-events/src/main/resources/events/restore/restore.sh
new file mode 100755
index 0000000..96f3db4
--- /dev/null
+++ b/asterix-events/src/main/resources/events/restore/restore.sh
@@ -0,0 +1,25 @@
+WORKING_DIR=$1
+ASTERIX_INSTANCE_NAME=$2
+ASTERIX_DATA_DIR=$3
+BACKUP_ID=$4
+HDFS_URL=$5
+HADOOP_VERSION=$6
+HDFS_BACKUP_DIR=$7
+NODE_ID=$8
+
+export HADOOP_HOME=$WORKING_DIR/hadoop-$HADOOP_VERSION
+
+nodeStores=$(echo $ASTERIX_DATA_DIR | tr "," "\n")
+for nodeStore in $nodeStores
+do
+  NODE_BACKUP_DIR=$HDFS_BACKUP_DIR/$ASTERIX_INSTANCE_NAME/$BACKUP_ID/$NODE_ID/$nodeStore
+  DEST_DIR=$nodeStore/$NODE_ID/$ASTERIX_INSTANCE_NAME
+  if [ ! -d $DEST_DIR ]
+  then 
+    mkdir -p $DEST_DIR
+  else 
+    rm -rf $DEST_DIR/*
+  fi
+  echo "$HADOOP_HOME/bin/hadoop fs -copyToLocal $HDFS_URL/$NODE_BACKUP_DIR/  $DEST_DIR/" >> ~/restore.log 
+  $HADOOP_HOME/bin/hadoop fs -copyToLocal $HDFS_URL/$NODE_BACKUP_DIR/*  $DEST_DIR/ 
+done
diff --git a/asterix-events/src/main/resources/schema/cluster.xsd b/asterix-events/src/main/resources/schema/cluster.xsd
new file mode 100644
index 0000000..edfe220
--- /dev/null
+++ b/asterix-events/src/main/resources/schema/cluster.xsd
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cl="cluster" targetNamespace="cluster" elementFormDefault="qualified">
+
+<!-- definition of simple types --> 
+<xs:element name="name" type="xs:string"/>
+<xs:element name="ram" type="xs:string"/>
+<xs:element name="logdir" type="xs:string"/>
+<xs:element name="id" type="xs:string"/>
+<xs:element name="ip" type="xs:string"/>
+<xs:element name="cluster-ip" type="xs:string"/>
+<xs:element name="key" type="xs:string"/>
+<xs:element name="value" type="xs:string"/>
+<xs:element name="dir" type="xs:string"/>
+<xs:element name="NFS" type="xs:boolean"/>
+<xs:element name="store" type="xs:string"/>
+<xs:element name="java_home" type="xs:string"/>
+<xs:element name="username" type="xs:string"/>
+
+<!-- definition of complex elements -->
+<xs:element name="workingDir">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="cl:dir"/>
+      <xs:element ref="cl:NFS"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="master-node">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="cl:id"/>
+      <xs:element ref="cl:ip"/>
+      <xs:element ref="cl:cluster-ip"/>
+      <xs:element ref="cl:java_home" minOccurs="0"/>
+      <xs:element ref="cl:ram" minOccurs="0"/>
+      <xs:element ref="cl:logdir" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="property">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="cl:key"/>
+      <xs:element ref="cl:value"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="env">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="cl:property" minOccurs="0" maxOccurs="unbounded"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="node">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="cl:id"/>
+      <xs:element ref="cl:ip"/>
+      <xs:element ref="cl:ram" minOccurs="0"/>
+      <xs:element ref="cl:java_home" minOccurs="0"/>
+      <xs:element ref="cl:logdir" minOccurs="0"/>
+      <xs:element ref="cl:store" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="cluster">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="cl:name"/>
+      <xs:element ref="cl:username"/>
+      <xs:element ref="cl:env" minOccurs="0"/>
+      <xs:element ref="cl:ram" minOccurs="0"/>
+      <xs:element ref="cl:java_home" minOccurs="0"/>
+      <xs:element ref="cl:logdir" minOccurs="0"/>
+      <xs:element ref="cl:store" minOccurs="0"/>
+      <xs:element ref="cl:workingDir"/>
+      <xs:element ref="cl:master-node"/>
+      <xs:element ref="cl:node" maxOccurs="unbounded"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+</xs:schema>     
diff --git a/asterix-events/src/main/resources/schema/event.xsd b/asterix-events/src/main/resources/schema/event.xsd
new file mode 100644
index 0000000..a233c18
--- /dev/null
+++ b/asterix-events/src/main/resources/schema/event.xsd
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:es="events" targetNamespace="events" elementFormDefault="qualified">
+
+<!-- definition of simple types --> 
+<xs:element name="script" type="xs:string"/>
+<xs:element name="type" type="xs:string"/>
+<xs:element name="description" type="xs:string"/>
+<xs:element name="args" type="xs:string"/>
+<xs:element name="daemon" type="xs:boolean"/>
+
+<!-- definition of complex elements -->
+
+<xs:element name="event">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="es:type"/>
+      <xs:element ref="es:script"/>
+      <xs:element ref="es:description"/>
+      <xs:element ref="es:args"/>
+      <xs:element ref="es:daemon"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="events">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="es:event" maxOccurs="unbounded"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+ 
+</xs:schema>     
diff --git a/asterix-events/src/main/resources/schema/jaxb-bindings.xjb b/asterix-events/src/main/resources/schema/jaxb-bindings.xjb
new file mode 100644
index 0000000..b5982e0
--- /dev/null
+++ b/asterix-events/src/main/resources/schema/jaxb-bindings.xjb
@@ -0,0 +1,9 @@
+<jxb:bindings version="1.0"
+xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
+xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+<jxb:globalBindings>
+  <jxb:serializable uid="1"/>
+</jxb:globalBindings>
+
+</jxb:bindings>
diff --git a/asterix-events/src/main/resources/schema/pattern.xsd b/asterix-events/src/main/resources/schema/pattern.xsd
new file mode 100644
index 0000000..4eee880
--- /dev/null
+++ b/asterix-events/src/main/resources/schema/pattern.xsd
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:eg="patterns" targetNamespace="patterns">
+
+
+<!-- definition of simple types --> 
+<xs:element name="maxOccurs" type = "xs:int"/> 
+<xs:element name="pargs" type="xs:string"/>
+<xs:element name="absvalue" type="xs:string"/>
+<xs:element name="unit" type="xs:string"/>
+<xs:element name="type" type="xs:string"/>
+<xs:element name="min" type="xs:string"/>
+<xs:element name="max" type="xs:string"/>
+<xs:element name="abs" type="xs:string"/>
+<xs:element name="set" type="xs:string"/>
+<xs:element name="exclude" type="xs:string"/>
+<xs:element name="reuse" type="xs:boolean"/>
+<!-- definition of attributes -->
+
+<!-- definition of complex elements -->
+
+<xs:element name="range">
+  <xs:complexType>
+    <xs:sequence>
+     <xs:element ref="eg:set"/>
+     <xs:element ref="eg:exclude" minOccurs="0"/>
+     <xs:element ref="eg:reuse" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="minmax">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:min"/>
+      <xs:element ref="eg:max"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+
+<xs:element name="random">
+  <xs:complexType>
+    <xs:sequence>
+       <xs:element ref="eg:minmax" minOccurs="0"/>
+       <xs:element ref="eg:range" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="value">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:random" minOccurs="0"/>
+      <xs:element ref="eg:absvalue" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="nodeid">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:value"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="period">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:absvalue"/>
+      <xs:element ref="eg:unit"/>
+    </xs:sequence>   
+  </xs:complexType>
+</xs:element>    
+
+<xs:element name="delay">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:value"/>
+      <xs:element ref="eg:unit"/>
+    </xs:sequence>   
+  </xs:complexType>
+</xs:element>    
+
+<xs:element name="event">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:type"/>
+      <xs:element ref="eg:nodeid"/>
+      <xs:element ref="eg:pargs"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+ 
+<xs:element name="pattern">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:delay"/>
+      <xs:element ref="eg:maxOccurs" maxOccurs="1" minOccurs="0"/>
+      <xs:element ref="eg:period"/>
+      <xs:element ref="eg:event"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="patterns">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="eg:pattern" maxOccurs="unbounded"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+</xs:schema>     
diff --git a/asterix-events/src/main/resources/scripts/execute.sh b/asterix-events/src/main/resources/scripts/execute.sh
new file mode 100755
index 0000000..72234c1
--- /dev/null
+++ b/asterix-events/src/main/resources/scripts/execute.sh
@@ -0,0 +1,22 @@
+USERNAME=$1
+if [ $DAEMON == "false" ]; then 
+  if [ -z $USERNAME ]
+  then
+    cmd_output=$(ssh $IP_LOCATION "$ENV $SCRIPT $ARGS" 2>&1 >/dev/null) 
+    echo "ssh $IP_LOCATION $ENV $SCRIPT $ARGS" >> ./execute.log
+    echo "$cmd_output"
+  else
+    echo "ssh -l $USERNAME $IP_LOCATION $ENV $SCRIPT $ARGS" >> ./execute.log
+    cmd_output=$(ssh -l $USERNAME $IP_LOCATION "$ENV $SCRIPT $ARGS" 2>&1 >/dev/null) 
+    echo "$cmd_output"
+  fi  
+else 
+  if [ -z $USERNAME ];
+  then
+     echo "ssh $IP_LOCATION $ENV $SCRIPT $ARGS &" >> ./execute.log
+     ssh $IP_LOCATION "$ENV $SCRIPT $ARGS" &
+  else
+     echo "ssh -l $USERNAME $IP_LOCATION $ENV $SCRIPT $ARGS &" >> ./execute.log
+     ssh -l $USERNAME $IP_LOCATION "$ENV $SCRIPT $ARGS" &
+  fi   
+fi
diff --git a/asterix-events/src/main/resources/scripts/prepare.sh b/asterix-events/src/main/resources/scripts/prepare.sh
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/asterix-events/src/main/resources/scripts/prepare.sh
diff --git a/asterix-external-data/pom.xml b/asterix-external-data/pom.xml
index 3076323..337da7f 100644
--- a/asterix-external-data/pom.xml
+++ b/asterix-external-data/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -14,8 +15,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 			<plugin>
@@ -50,14 +51,12 @@
 				<artifactId>maven-surefire-plugin</artifactId>
 				<version>2.7.2</version>
 				<configuration>
-					<!--
-						doesn't work from m2eclipse, currently
-						<additionalClasspathElements>
-						<additionalClasspathElement>${basedir}/src/main/resources</additionalClasspathElement>
-						</additionalClasspathElements>
-					-->
+					<!-- doesn't work from m2eclipse, currently <additionalClasspathElements> 
+						<additionalClasspathElement>${basedir}/src/main/resources</additionalClasspathElement> 
+						</additionalClasspathElements> -->
 					<forkMode>pertest</forkMode>
-					<argLine>-enableassertions -Xmx${test.heap.size}m -Dfile.encoding=UTF-8
+					<argLine>-enableassertions -Xmx${test.heap.size}m
+						-Dfile.encoding=UTF-8
 						-Djava.util.logging.config.file=src/test/resources/logging.properties</argLine>
 					<includes>
 						<include>**/*TestSuite.java</include>
@@ -102,39 +101,39 @@
 			<version>1.3.1-201002241208</version>
 			<scope>test</scope>
 		</dependency>
-                <dependency>
-                        <groupId>org.twitter4j</groupId>
-                        <artifactId>twitter4j-core</artifactId>
-                        <version>2.2.3</version>
-                </dependency>
-                <dependency>
-                        <groupId>org.apache.hadoop</groupId>
-                        <artifactId>hadoop-core</artifactId>
-                        <version>0.20.2</version>
-                        <type>jar</type>
-                        <scope>compile</scope>
-                </dependency>
-                <dependency>
-                        <groupId>net.java.dev.rome</groupId>
-                        <artifactId>rome-fetcher</artifactId>
-                        <version>1.0.0</version>
-                        <type>jar</type>
-                        <scope>compile</scope>
-                </dependency>
-                <dependency>
-                         <groupId>rome</groupId>
-                         <artifactId>rome</artifactId>
-                         <version>1.0.1-modified-01</version>
-                </dependency>
-	        <dependency>
-		         <groupId>edu.uci.ics.hyracks</groupId>
-		         <artifactId>hyracks-dataflow-hadoop</artifactId>
-	        </dependency>
-<dependency>
-            <groupId>jdom</groupId>
-            <artifactId>jdom</artifactId>
-            <version>1.0</version>
-        </dependency>
+		<dependency>
+			<groupId>org.twitter4j</groupId>
+			<artifactId>twitter4j-core</artifactId>
+			<version>2.2.3</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.hadoop</groupId>
+			<artifactId>hadoop-core</artifactId>
+			<version>0.20.2</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>net.java.dev.rome</groupId>
+			<artifactId>rome-fetcher</artifactId>
+			<version>1.0.0</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>rome</groupId>
+			<artifactId>rome</artifactId>
+			<version>1.0.1-modified-01</version>
+		</dependency>
+		<dependency>
+			<groupId>edu.uci.ics.hyracks</groupId>
+			<artifactId>hyracks-dataflow-hadoop</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>jdom</groupId>
+			<artifactId>jdom</artifactId>
+			<version>1.0</version>
+		</dependency>
 	</dependencies>
 
 </project>
diff --git a/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/feed/lifecycle/FeedManager.java b/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/feed/lifecycle/FeedManager.java
index 29e4486..6a5dae7 100644
--- a/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/feed/lifecycle/FeedManager.java
+++ b/asterix-external-data/src/main/java/edu/uci/ics/asterix/external/feed/lifecycle/FeedManager.java
@@ -44,7 +44,7 @@
                     queue.put(feedMessage);
                 }
             } else {
-                throw new AsterixException("Unable to deliver message. Unknown feed :" + feedId);
+                //throw new AsterixException("Unable to deliver message. Unknown feed :" + feedId);
             }
         } catch (Exception e) {
             throw new AsterixException(e);
diff --git a/asterix-hyracks-glue/pom.xml b/asterix-hyracks-glue/pom.xml
index 5f991a4..1a18d1c 100644
--- a/asterix-hyracks-glue/pom.xml
+++ b/asterix-hyracks-glue/pom.xml
@@ -1,51 +1,52 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <artifactId>asterix</artifactId>
-    <groupId>edu.uci.ics.asterix</groupId>
-    <version>0.0.4-SNAPSHOT</version>
-  </parent>
-  <groupId>edu.uci.ics.asterix</groupId>
-  <artifactId>asterix-hyracks-glue</artifactId>
-  <version>0.0.4-SNAPSHOT</version>
-  <build>
-       <plugins>
-           <plugin>
-              <groupId>org.apache.maven.plugins</groupId>
-              <artifactId>maven-compiler-plugin</artifactId>
-              <version>2.0.2</version>
-              <configuration>
-                 <source>1.6</source>
-                 <target>1.6</target>
-              </configuration>
-           </plugin>
-       </plugins>
-  </build>     
-  <name>asterix-hyracks-glue</name>
-  <url>http://maven.apache.org</url>
-  <dependencies>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.1</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-       <groupId>edu.uci.ics.asterix</groupId>
-       <artifactId>asterix-transactions</artifactId>
-       <version>0.0.4-SNAPSHOT</version>
-       <scope>compile</scope>
-    </dependency>
-    <dependency>
-    	<groupId>edu.uci.ics.asterix</groupId>
-    	<artifactId>asterix-common</artifactId>
-    	<version>0.0.4-SNAPSHOT</version>
-    	<type>jar</type>
-    	<scope>compile</scope>
-    </dependency>
-  </dependencies>
-  <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-  </properties>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<artifactId>asterix</artifactId>
+		<groupId>edu.uci.ics.asterix</groupId>
+		<version>0.0.4-SNAPSHOT</version>
+	</parent>
+	<groupId>edu.uci.ics.asterix</groupId>
+	<artifactId>asterix-hyracks-glue</artifactId>
+	<version>0.0.4-SNAPSHOT</version>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.0.2</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<name>asterix-hyracks-glue</name>
+	<url>http://maven.apache.org</url>
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>edu.uci.ics.asterix</groupId>
+			<artifactId>asterix-transactions</artifactId>
+			<version>0.0.4-SNAPSHOT</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>edu.uci.ics.asterix</groupId>
+			<artifactId>asterix-common</artifactId>
+			<version>0.0.4-SNAPSHOT</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+	</dependencies>
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
 </project>
diff --git a/asterix-installer/pom.xml b/asterix-installer/pom.xml
new file mode 100644
index 0000000..f4a1f9b
--- /dev/null
+++ b/asterix-installer/pom.xml
@@ -0,0 +1,148 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+          <artifactId>asterix</artifactId>
+          <groupId>edu.uci.ics.asterix</groupId>
+          <version>0.0.4-SNAPSHOT</version>
+  </parent>
+  <groupId>edu.uci.ics.asterix</groupId>
+  <artifactId>asterix-installer</artifactId>
+  <version>0.0.4-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+       <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>2.0.2</version>
+          <configuration>
+             <source>1.6</source>
+             <target>1.6</target>
+          </configuration>
+       </plugin>
+
+       <plugin>
+          <groupId>org.jvnet.jaxb2.maven2</groupId>
+          <artifactId>maven-jaxb2-plugin</artifactId>
+          <executions>
+            <execution>
+              <id>configuration</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+              <configuration>
+                <schemaDirectory>src/main/resources/schema</schemaDirectory>
+                <schemaIncludes>
+                  <include>managix-conf.xsd</include>
+                </schemaIncludes>
+                <generatePackage>edu.uci.ics.asterix.installer.schema.conf</generatePackage>
+                <generateDirectory>${project.build.directory}/generated-sources/configuration</generateDirectory>
+              </configuration>
+            </execution>
+            <execution>
+              <id>cluster</id>
+              <goals>
+                <goal>generate</goal>
+              </goals>
+              <configuration>
+                <schemaDirectory>src/main/resources/schema</schemaDirectory>
+                <schemaIncludes>
+                  <include>cluster.xsd</include>
+                </schemaIncludes>
+                <generatePackage>edu.uci.ics.asterix.installer.schema.cluster</generatePackage>
+                <generateDirectory>${project.build.directory}/generated-sources/cluster</generateDirectory>
+              </configuration>
+            </execution>
+          </executions>
+       </plugin>
+       <plugin>
+         <artifactId>maven-assembly-plugin</artifactId>
+         <version>2.2-beta-2</version>
+         <executions>
+           <execution>
+             <configuration>
+               <descriptor>src/main/assembly/binary-assembly.xml</descriptor>
+             </configuration>
+             <phase>package</phase>
+             <goals>
+               <goal>attached</goal>
+             </goals>
+           </execution>
+         </executions>
+       </plugin>
+    </plugins> 
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>args4j</groupId>
+      <artifactId>args4j</artifactId>
+      <version>2.0.12</version>
+      <type>jar</type>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+      <version>3.4.4</version>
+      <exclusions>
+            <exclusion>
+                <groupId>com.sun.jmx</groupId>
+                <artifactId>jmxri</artifactId>
+            </exclusion>
+            <exclusion>
+                <groupId>com.sun.jdmk</groupId>
+                <artifactId>jmxtools</artifactId>
+            </exclusion>
+            <exclusion>
+                <groupId>javax.jms</groupId>
+                <artifactId>jms</artifactId>
+            </exclusion>
+        </exclusions>
+    </dependency>
+    <dependency>
+        <groupId>commons-io</groupId>
+        <artifactId>commons-io</artifactId>
+        <version>1.4</version>
+    </dependency>
+    <dependency>
+        <groupId>edu.uci.ics.asterix</groupId>
+        <artifactId>asterix-events</artifactId>
+        <version>0.0.4-SNAPSHOT</version>
+        <type>jar</type>
+        <scope>compile</scope>
+    </dependency>
+    <dependency>
+        <groupId>edu.uci.ics.hyracks</groupId>
+        <artifactId>hyracks-server</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <type>zip</type>
+        <classifier>binary-assembly</classifier>
+    </dependency>
+    <dependency>
+        <groupId>edu.uci.ics.hyracks</groupId>
+        <artifactId>hyracks-cli</artifactId>
+        <version>0.2.3-SNAPSHOT</version>
+        <type>zip</type>
+        <classifier>binary-assembly</classifier>
+    </dependency>
+    <dependency>
+        <groupId>edu.uci.ics.asterix</groupId>
+        <artifactId>asterix-app</artifactId>
+        <version>0.0.4-SNAPSHOT</version>
+        <type>zip</type>
+        <classifier>binary-assembly</classifier>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/asterix-installer/src/main/assembly/binary-assembly.xml b/asterix-installer/src/main/assembly/binary-assembly.xml
new file mode 100644
index 0000000..9788d2c
--- /dev/null
+++ b/asterix-installer/src/main/assembly/binary-assembly.xml
@@ -0,0 +1,125 @@
+<assembly>
+  <id>binary-assembly</id>
+  <formats>
+    <format>zip</format>
+  </formats>
+  <includeBaseDirectory>false</includeBaseDirectory>
+  <fileSets>
+    <fileSet>
+      <directory>src/main/resources/conf</directory>
+      <outputDirectory>conf</outputDirectory>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/clusters</directory>
+      <outputDirectory>clusters</outputDirectory>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/zookeeper</directory>
+      <fileMode>0755</fileMode>
+      <outputDirectory>.managix/zookeeper/bin</outputDirectory>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/scripts</directory>
+      <fileMode>0755</fileMode>
+      <includes>
+        <include>managix</include>
+      </includes>
+      <outputDirectory>bin</outputDirectory>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/scripts</directory>
+      <fileMode>0755</fileMode>
+      <excludes>
+        <exclude>managix</exclude>
+      </excludes>
+      <outputDirectory>.managix/scripts</outputDirectory>
+    </fileSet>
+    <fileSet>
+      <directory>src/main/resources/hadoop-0.20.2</directory>
+      <outputDirectory>.managix/hadoop-0.20.2</outputDirectory>
+      <fileMode>0755</fileMode>
+    </fileSet>
+    <fileSet>
+      <directory>target</directory>
+      <outputDirectory>lib</outputDirectory>
+      <includes>
+        <include>*.jar</include>
+      </includes>
+    </fileSet>
+    <fileSet>
+      <directory>../asterix-events/src/main/resources/events</directory>
+      <outputDirectory>.managix/eventrix/events</outputDirectory>
+      <fileMode>0755</fileMode>
+    </fileSet>
+    <fileSet>
+      <directory>../asterix-events/src/main/resources/scripts</directory>
+      <outputDirectory>.managix/eventrix/scripts</outputDirectory>
+    </fileSet>
+  </fileSets>
+  <dependencySets>
+    <dependencySet>
+      <includes>
+         <include>log4j:log4j</include>
+         <include>commons-lang:commons-lang</include>
+         <include>edu.uci.ics.asterix:asterix-events</include>
+         <include>org.apache.zookeeper:zookeeper</include>
+         <include>args4j:args4j</include>
+         <include>log4j:log4j</include>
+         <include>commons-io:commons-io</include>
+         <include>org.slf4j:slf4j-api</include>
+         <include>org.slf4j:slf4j-log4j12</include>
+       </includes>
+       <unpack>false</unpack>
+       <outputDirectory>lib</outputDirectory>
+    </dependencySet>
+    <dependencySet>
+      <includes>
+        <include>org.apache.hadoop:hadoop-core</include>
+        <include>commons-cli:commons-cli</include>
+        <include>commons-logging:commons-logging</include>
+      </includes>
+      <unpack>false</unpack>
+      <outputDirectory>.managix/hadoop-0.20.2/lib</outputDirectory>
+    </dependencySet>
+    <dependencySet>
+      <includes>
+        <include>org.apache.zookeeper:zookeeper</include>
+        <include>log4j:log4j</include>
+        <include>org.slf4j:slf4j-api</include>
+      </includes>
+      <unpack>false</unpack>
+      <outputDirectory>.managix/zookeeper/lib</outputDirectory>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>asterix</outputDirectory>
+      <includes>
+        <include>hyracks-server*</include>
+      </includes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>asterix</outputDirectory>
+      <includes>
+        <include>hyracks-cli*</include>
+      </includes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>asterix</outputDirectory>
+      <includes>
+        <include>asterix-app*</include>
+      </includes>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+    <dependencySet>
+      <outputDirectory>.managix/eventrix</outputDirectory>
+      <includes>
+        <include>asterix-events*</include>
+      </includes>
+      <unpack>false</unpack>
+      <useTransitiveDependencies>false</useTransitiveDependencies>
+    </dependencySet>
+  </dependencySets>
+</assembly>
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AbstractCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AbstractCommand.java
new file mode 100644
index 0000000..2e199fb
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AbstractCommand.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.util.logging.Logger;
+
+import org.kohsuke.args4j.CmdLineParser;
+
+public abstract class AbstractCommand implements ICommand {
+
+    protected static final Logger LOGGER = Logger.getLogger(AbstractCommand.class.getName());
+
+    protected CommandConfig config;
+    
+    protected String usageDescription;
+
+    public void execute(String[] args) throws Exception {
+        String[] cmdArgs = new String[args.length - 1];
+        System.arraycopy(args, 1, cmdArgs, 0, cmdArgs.length);
+        config = getCommandConfig();
+        CmdLineParser parser = new CmdLineParser(config);
+        parser.parseArgument(cmdArgs);
+        execCommand();
+    }
+
+    abstract protected void execCommand() throws Exception;
+
+    abstract protected String getUsageDescription();
+
+    abstract protected CommandConfig getCommandConfig();
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AlterCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AlterCommand.java
new file mode 100644
index 0000000..f5450ff
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/AlterCommand.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.util.Date;
+import java.util.Properties;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.service.ILookupService;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class AlterCommand extends AbstractCommand {
+
+    @Override
+    protected void execCommand() throws Exception {
+        String instanceName = ((AlterConfig) config).name;
+        ManagixUtil.validateAsterixInstanceExists(instanceName, State.INACTIVE);
+        ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
+        AsterixInstance instance = lookupService.getAsterixInstance(instanceName);
+
+        Properties asterixConfProp = ManagixUtil.getAsterixConfiguration(((AlterConfig) config).confPath);
+        instance.setConfiguration(asterixConfProp);
+        instance.setModifiedTimestamp(new Date());
+        lookupService.updateAsterixInstance(instance);
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new AlterConfig();
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
+
+class AlterConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = false, usage = "Name of Asterix Instance")
+    public String name;
+
+    @Option(name = "-conf", required = false, usage = "Path to instance configuration")
+    public String confPath;
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/BackupCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/BackupCommand.java
new file mode 100644
index 0000000..f8dcc80
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/BackupCommand.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.util.Date;
+import java.util.List;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.events.PatternCreator;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.model.BackupInfo;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class BackupCommand extends AbstractCommand {
+
+    @Override
+    protected void execCommand() throws Exception {
+        String asterixInstanceName = ((BackupConfig) config).name;
+        AsterixInstance instance = ManagixUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
+        List<BackupInfo> backupInfo = instance.getBackupInfo();
+        PatternCreator pc = new PatternCreator();
+        Patterns patterns = pc.getBackUpAsterixPattern(instance, ((BackupConfig) config).localPath);
+        ManagixUtil.getEventrixClient(instance.getCluster()).submit(patterns);
+        int backupId = backupInfo.size();
+        BackupInfo binfo = new BackupInfo(backupId, new Date());
+        backupInfo.add(binfo);
+        System.out.println(asterixInstanceName + " backed up " + binfo);
+        ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new BackupConfig();
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
+
+class BackupConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = true, usage = "Name of the Asterix instance")
+    public String name;
+
+    @Option(name = "-local", required = false, usage = "Path on the local file system for backup")
+    public String localPath;
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CommandConfig.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CommandConfig.java
new file mode 100644
index 0000000..c0dd480
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CommandConfig.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+public interface CommandConfig {
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CommandHandler.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CommandHandler.java
new file mode 100644
index 0000000..179412f
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CommandHandler.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import edu.uci.ics.asterix.installer.command.ICommand.CommandType;
+
+public class CommandHandler {
+
+    public void processCommand(String args[]) throws Exception {
+        CommandType cmdType = CommandType.valueOf(args[0].toUpperCase());
+        ICommand cmd = null;
+        switch (cmdType) {
+            case CREATE:
+                cmd = new CreateCommand();
+                break;
+            case ALTER:
+                cmd = new AlterCommand();
+                break;
+            case DELETE:
+                cmd = new DeleteCommand();
+                break;
+            case DESCRIBE:
+                cmd = new DescribeCommand();
+                break;
+            case BACKUP:
+                cmd = new BackupCommand();
+                break;
+            case RESTORE:
+                cmd = new RestoreCommand();
+                break;
+            case START:
+                cmd = new StartCommand();
+                break;
+            case STOP:
+                cmd = new StopCommand();
+                break;
+        }
+        cmd.execute(args);
+    }
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
new file mode 100644
index 0000000..5a3da5b
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Env;
+import edu.uci.ics.asterix.event.schema.cluster.Property;
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.installer.driver.ManagixDriver;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.error.VerificationUtil;
+import edu.uci.ics.asterix.installer.events.PatternCreator;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixRuntimeState;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class CreateCommand extends AbstractCommand {
+
+    private String asterixInstanceName;
+    private Cluster cluster;
+
+    @Override
+    protected void execCommand() throws Exception {
+        asterixInstanceName = ((CreateConfig) config).name;
+        ManagixUtil.validateAsterixInstanceNotExists(asterixInstanceName);
+        CreateConfig createConfig = (CreateConfig) config;
+        JAXBContext ctx = JAXBContext.newInstance(Cluster.class);
+        Unmarshaller unmarshaller = ctx.createUnmarshaller();
+        cluster = (Cluster) unmarshaller.unmarshal(new File(createConfig.clusterPath));
+        AsterixInstance asterixInstance = ManagixUtil.createAsterixInstance(asterixInstanceName, cluster,
+                ((CreateConfig) config).asterixConf);
+        ManagixUtil.createAsterixZip(asterixInstance, true);
+        List<Property> clusterProperties = new ArrayList<Property>();
+        clusterProperties.add(new Property("HYRACKS_HOME", cluster.getWorkingDir().getDir() + File.separator
+                + "hyracks"));
+        clusterProperties.add(new Property("JAVA_OPTS", "-Xmx" + cluster.getRam()));
+        clusterProperties.add(new Property("CLUSTER_NET_IP", cluster.getMasterNode().getClusterIp()));
+        clusterProperties.add(new Property("CLIENT_NET_IP", cluster.getMasterNode().getIp()));
+        clusterProperties.add(new Property("LOG_DIR", cluster.getLogdir()));
+        clusterProperties.add(new Property("JAVA_HOME", cluster.getJavaHome()));
+        cluster.setEnv(new Env(clusterProperties));
+
+        PatternCreator pc = new PatternCreator();
+        Patterns patterns = pc.getStartAsterixPattern(asterixInstanceName, cluster);
+        ManagixUtil.getEventrixClient(cluster).submit(patterns);
+
+        AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(asterixInstance);
+        VerificationUtil.updateInstanceWithRuntimeDescription(asterixInstance, runtimeState, true);
+        ServiceProvider.INSTANCE.getLookupService().writeAsterixInstance(asterixInstance);
+        System.out.println(asterixInstance.getDescription(false));
+        ManagixUtil.deleteDirectory(ManagixDriver.getManagixHome() + File.separator + ManagixDriver.ASTERIX_DIR
+                + File.separator + asterixInstanceName);
+
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new CreateConfig();
+    }
+
+    public Cluster getCluster() {
+        return cluster;
+    }
+
+    public String getAsterixInstanceName() {
+        return asterixInstanceName;
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}
+
+class CreateConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = true, usage = "Name of Asterix Instance")
+    public String name;
+
+    @Option(name = "-c", required = true, usage = "Path to cluster configuration")
+    public String clusterPath;
+
+    @Option(name = "-a", required = true, usage = "Path to cluster configuration")
+    public String asterixConf;
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DeleteCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DeleteCommand.java
new file mode 100644
index 0000000..60ce4c1
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DeleteCommand.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.util.logging.Level;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.events.PatternCreator;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class DeleteCommand extends AbstractCommand {
+
+    @Override
+    protected void execCommand() throws Exception {
+        String asterixInstanceName = ((DeleteConfig) config).name;
+        AsterixInstance instance = ManagixUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
+        PatternCreator pc = new PatternCreator();
+        Patterns patterns = pc.createDeleteInstancePattern(instance);
+        ManagixUtil.getEventrixClient(instance.getCluster()).submit(patterns);
+        ServiceProvider.INSTANCE.getLookupService().removeAsterixInstance(asterixInstanceName);
+        LOGGER.log(Level.INFO, " Asterix instance: " + asterixInstanceName + " deleted");
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new DeleteConfig();
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
+
+class DeleteConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = false, usage = "Name of Asterix Instance")
+    public String name;
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DescribeCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DescribeCommand.java
new file mode 100644
index 0000000..6b6536a
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/DescribeCommand.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.util.List;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.error.ManagixException;
+import edu.uci.ics.asterix.installer.error.VerificationUtil;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.model.AsterixRuntimeState;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class DescribeCommand extends AbstractCommand {
+
+    @Override
+    protected void execCommand() throws Exception {
+        String asterixInstanceName = ((DescribeConfig) config).name;
+        boolean adminView = ((DescribeConfig) config).admin;
+        if (asterixInstanceName != null) {
+            ManagixUtil
+                    .validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE, State.ACTIVE, State.UNUSABLE);
+            AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(
+                    asterixInstanceName);
+            if (instance != null) {
+                AsterixRuntimeState state = VerificationUtil.getAsterixRuntimeState(instance);
+                boolean expectedRunning = instance.getState().equals(State.UNUSABLE) ? instance.getPreviousState()
+                        .equals(State.ACTIVE) : !instance.getState().equals(State.INACTIVE);
+                VerificationUtil.updateInstanceWithRuntimeDescription(instance, state, expectedRunning);
+                ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
+                System.out.println(instance.getDescription(adminView));
+            } else {
+                throw new ManagixException("Asterix instance by the name " + asterixInstanceName + " does not exist.");
+            }
+        } else {
+            List<AsterixInstance> asterixInstances = ServiceProvider.INSTANCE.getLookupService().getAsterixInstances();
+            if (asterixInstances.size() > 0) {
+                for (AsterixInstance instance : asterixInstances) {
+                    AsterixRuntimeState state = VerificationUtil.getAsterixRuntimeState(instance);
+                    boolean expectedRunning = instance.getState().equals(State.UNUSABLE) ? instance.getPreviousState()
+                            .equals(State.ACTIVE) : !instance.getState().equals(State.INACTIVE);
+                    VerificationUtil.updateInstanceWithRuntimeDescription(instance, state, expectedRunning);
+                    ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
+                    System.out.println(instance.getDescription(adminView));
+                }
+            } else {
+                LOGGER.info("No Asterix instances found!");
+            }
+
+        }
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new DescribeConfig();
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
+
+class DescribeConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = false, usage = "Name of Asterix Instance")
+    public String name;
+
+    @Option(name = "-admin", required = false, usage = "Detailed description")
+    public boolean admin;
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ICommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ICommand.java
new file mode 100644
index 0000000..2822337
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ICommand.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+public interface ICommand {
+
+	public enum CommandType {
+		CREATE, DELETE, START, STOP, BACKUP, RESTORE, DESCRIBE, ALTER
+	}
+
+	public void execute(String args[]) throws Exception;
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/RestoreCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/RestoreCommand.java
new file mode 100644
index 0000000..620c88f
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/RestoreCommand.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.events.PatternCreator;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+
+public class RestoreCommand extends AbstractCommand {
+
+    @Override
+    protected void execCommand() throws Exception {
+        String asterixInstanceName = ((RestoreConfig) config).name;
+        AsterixInstance instance = ManagixUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
+        int backupId = ((RestoreConfig) config).backupId;
+        if (instance.getBackupInfo().size() <= backupId || backupId < 0) {
+            throw new IllegalStateException("Invalid backup id");
+        }
+        PatternCreator pc = new PatternCreator();
+        Patterns patterns = pc.getRestoreAsterixPattern(instance, backupId);
+        ManagixUtil.getEventrixClient(instance.getCluster()).submit(patterns);
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new RestoreConfig();
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
+
+class RestoreConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = true, usage = "Name of the Asterix instance")
+    public String name;
+
+    @Option(name = "-b", required = true, usage = "Id corresponding to the backed up version")
+    public int backupId;
+
+}
\ No newline at end of file
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
new file mode 100644
index 0000000..3c5e32f
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.io.File;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.installer.driver.ManagixDriver;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.error.VerificationUtil;
+import edu.uci.ics.asterix.installer.events.PatternCreator;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.model.AsterixRuntimeState;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class StartCommand extends AbstractCommand {
+
+    @Override
+    protected void execCommand() throws Exception {
+        String asterixInstanceName = ((StartConfig) config).name;
+        AsterixInstance instance = ManagixUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
+        ManagixUtil.createAsterixZip(instance, false);
+        PatternCreator pc = new PatternCreator();
+        Patterns patterns = pc.getStartAsterixPattern(asterixInstanceName, instance.getCluster());
+        ManagixUtil.getEventrixClient(instance.getCluster()).submit(patterns);
+        ManagixUtil.deleteDirectory(ManagixDriver.getManagixHome() + File.separator + ManagixDriver.ASTERIX_DIR
+                + File.separator + asterixInstanceName);
+        AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
+        VerificationUtil.updateInstanceWithRuntimeDescription(instance, runtimeState, true);
+        System.out.println(instance.getDescription(false));
+        ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new StartConfig();
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
+
+class StartConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = false, usage = "Name of Asterix Instance")
+    public String name;
+
+    @Option(name = "-conf", required = false, usage = "Path to instance configuration")
+    public String confPath;
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StopCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StopCommand.java
new file mode 100644
index 0000000..d82d751
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StopCommand.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.command;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.asterix.event.management.EventrixClient;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.event.schema.pattern.Pattern;
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.events.PatternCreator;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class StopCommand extends AbstractCommand {
+
+    @Override
+    protected void execCommand() throws Exception {
+        String asterixInstanceName = ((StopConfig) config).name;
+        AsterixInstance asterixInstance = ManagixUtil.validateAsterixInstanceExists(asterixInstanceName, State.ACTIVE,
+                State.UNUSABLE);
+        PatternCreator pc = new PatternCreator();
+        List<Pattern> patternsToExecute = new ArrayList<Pattern>();
+        patternsToExecute.add(pc.createCCStopPattern(asterixInstance.getCluster().getMasterNode().getId()));
+
+        for (Node node : asterixInstance.getCluster().getNode()) {
+            patternsToExecute.add(pc.createNCStopPattern(node.getId(), asterixInstanceName + "_" + node.getId()));
+        }
+        EventrixClient client = ManagixUtil.getEventrixClient(asterixInstance.getCluster());
+        try {
+            client.submit(new Patterns(patternsToExecute));
+        } catch (Exception e) {
+            // processes are already dead
+        }
+        asterixInstance.setState(State.INACTIVE);
+        asterixInstance.setStateChangeTimestamp(new Date());
+        ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(asterixInstance);
+    }
+
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new StopConfig();
+    }
+
+    public String getAsterixInstanceName() {
+        return ((StopConfig) config).name;
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
+
+class StopConfig implements CommandConfig {
+
+    @Option(name = "-h", required = false, usage = "Help")
+    public boolean help = false;
+
+    @Option(name = "-n", required = true, usage = "Name of Asterix Instance")
+    public String name;
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixConfig.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixConfig.java
new file mode 100644
index 0000000..f955caf
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixConfig.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.driver;
+
+import java.util.Set;
+
+class ManagixConfig {
+
+    public String asterixHome;
+    public String hyracksHome;
+    public String hdfsUrl;
+    public Set<String> zookeeperNodes;
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixDriver.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixDriver.java
new file mode 100644
index 0000000..1474ca9
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixDriver.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.driver;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import edu.uci.ics.asterix.event.schema.event.Events;
+import edu.uci.ics.asterix.installer.command.CommandHandler;
+import edu.uci.ics.asterix.installer.schema.conf.Configuration;
+import edu.uci.ics.asterix.installer.service.ILookupService;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+@SuppressWarnings("restriction")
+public class ManagixDriver {
+
+    public static final String MANAGIX_INTERNAL_DIR = ".managix";
+    public static final String MANAGIX_EVENT_DIR = MANAGIX_INTERNAL_DIR + File.separator + "eventrix";
+    public static final String MANAGIX_EVENT_SCRIPTS_DIR = MANAGIX_INTERNAL_DIR + File.separator + "eventrix"
+            + File.separator + "scripts";
+
+    public static final String ASTERIX_DIR = "asterix";
+    public static final String EVENTS_DIR = "events";
+
+    private static final Logger LOGGER = Logger.getLogger(ManagixDriver.class.getName());
+    private static final String ENV_MANAGIX_HOME = "MANAGIX_HOME";
+    private static final String MANAGIX_CONF_XML = "conf" + File.separator + "managix-conf.xml";
+
+    private static Configuration conf;
+    private static String managixHome;
+    private static String hyracksServerZip;
+    private static String hyracksClientZip;
+    private static String asterixZip;
+    private static Events events;
+
+    public static String getHyrackServerZip() {
+        return hyracksServerZip;
+    }
+
+    public static String getHyracksClientZip() {
+        return hyracksClientZip;
+    }
+
+    public static String getAsterixZip() {
+        return asterixZip;
+    }
+
+    public static String getHyracksClientHome() {
+        return ASTERIX_DIR + File.separator + "hyracks-cli";
+    }
+
+    public static Configuration getConfiguration() {
+        return conf;
+    }
+
+    private static void initConfig() throws Exception {
+        managixHome = System.getenv(ENV_MANAGIX_HOME);
+        File configFile = new File(managixHome + File.separator + MANAGIX_CONF_XML);
+        JAXBContext configCtx = JAXBContext.newInstance(Configuration.class);
+        Unmarshaller unmarshaller = configCtx.createUnmarshaller();
+        conf = (Configuration) unmarshaller.unmarshal(configFile);
+
+        hyracksServerZip = initBinary("hyracks-server");
+        hyracksClientZip = initBinary("hyracks-cli");
+        ManagixUtil.unzip(hyracksClientZip, getHyracksClientHome());
+        asterixZip = initBinary("asterix-app");
+
+        ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
+        if (!lookupService.isRunning(conf)) {
+            lookupService.startService(conf);
+        }
+    }
+
+    private static String initBinary(final String fileNamePattern) {
+        String asterixDir = ManagixDriver.getAsterixDir();
+        File file = new File(asterixDir);
+        File[] zipFiles = file.listFiles(new FileFilter() {
+            public boolean accept(File arg0) {
+                return arg0.getAbsolutePath().contains(fileNamePattern) && arg0.isFile();
+            }
+        });
+        if (zipFiles.length == 0) {
+            String msg = " Binary not found at " + asterixDir;
+            LOGGER.log(Level.SEVERE, msg);
+            throw new IllegalStateException(msg);
+        }
+        if (zipFiles.length > 1) {
+            String msg = " Multiple binaries found at " + asterixDir;
+            LOGGER.log(Level.SEVERE, msg);
+            throw new IllegalStateException(msg);
+        }
+
+        return zipFiles[0].getAbsolutePath();
+    }
+
+    public static String getManagixHome() {
+        return managixHome;
+    }
+
+    public static String getAsterixDir() {
+        return managixHome + File.separator + ASTERIX_DIR;
+    }
+
+    public static Events getEvents() {
+        return events;
+    }
+
+    public static void main(String args[]) {
+        try {
+            if (args.length != 0) {
+                initConfig();
+                CommandHandler cmdHandler = new CommandHandler();
+                cmdHandler.processCommand(args);
+            } else {
+                printUsage();
+            }
+        } catch (IllegalArgumentException iae) {
+            LOGGER.log(Level.SEVERE, "Unknown command");
+            printUsage();
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOGGER.log(Level.SEVERE, e.getMessage());
+        }
+    }
+
+    private static void printUsage() {
+        StringBuffer buffer = new StringBuffer("managix <command> <args>" + "\n");
+        buffer.append("Commands" + "\n");
+        buffer.append("create   " + ":" + " Creates a new asterix instance" + "\n");
+        buffer.append("delete   " + ":" + " Deletes an asterix instance" + "\n");
+        buffer.append("start    " + ":" + " Starts an  asterix instance" + "\n");
+        buffer.append("stop     " + ":" + " Stops an asterix instance that is in ACTIVE state" + "\n");
+        buffer.append("backup   " + ":" + " Creates a back up for an existing asterix instance" + "\n");
+        buffer.append("restore  " + ":" + " Restores an asterix instance" + "\n");
+        buffer.append("alter    " + ":" + " Alters the configuration for an existing asterix instance" + "\n");
+        buffer.append("describe " + ":" + " Describes an existing asterix instance" + "\n");
+        LOGGER.log(Level.INFO, buffer.toString());
+    }
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixUtil.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixUtil.java
new file mode 100644
index 0000000..f849151
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/driver/ManagixUtil.java
@@ -0,0 +1,306 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.driver;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+import java.util.Random;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.commons.io.IOUtils;
+
+import edu.uci.ics.asterix.event.driver.EventDriver;
+import edu.uci.ics.asterix.event.management.EventrixClient;
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.installer.error.ManagixException;
+import edu.uci.ics.asterix.installer.error.OutputHandler;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class ManagixUtil {
+
+    public static AsterixInstance createAsterixInstance(String asterixInstanceName, Cluster cluster, String asterixConf)
+            throws FileNotFoundException, IOException {
+        Properties asterixConfProp = getAsterixConfiguration(asterixConf);
+        Node metadataNode = getMetadataNode(cluster);
+        String asterixZipName = ManagixDriver.getAsterixZip().substring(
+                ManagixDriver.getAsterixZip().lastIndexOf(File.separator) + 1);
+        String asterixVersion = asterixZipName.substring("asterix-app-".length(),
+                asterixZipName.indexOf("-binary-assembly"));
+        String hyracksZipName = ManagixDriver.getHyrackServerZip().substring(
+                ManagixDriver.getHyrackServerZip().lastIndexOf(File.separator) + 1);
+        String hyracksVersion = hyracksZipName.substring("hyracks-server-".length(),
+                hyracksZipName.indexOf("-binary-assembly"));
+        AsterixInstance instance = new AsterixInstance(asterixInstanceName, cluster, asterixConfProp,
+                metadataNode.getId(), asterixVersion, hyracksVersion);
+        return instance;
+    }
+
+    public static void createAsterixZip(AsterixInstance asterixInstance, boolean newDeployment) throws IOException {
+        writeAsterixConfigurationFile(asterixInstance, newDeployment);
+        String asterixInstanceDir = ManagixDriver.getAsterixDir() + File.separator + asterixInstance.getName();
+        unzip(ManagixDriver.getAsterixZip(), asterixInstanceDir);
+        File sourceJar = new File(asterixInstanceDir + File.separator + "lib" + File.separator + "asterix-app-"
+                + asterixInstance.getAsterixVersion() + ".jar");
+        String origFile = "test.properties";
+        File replacementFile = new File(asterixInstanceDir + File.separator + "test.properties");
+        replaceInJar(sourceJar, origFile, replacementFile);
+        new File(asterixInstanceDir + File.separator + "test.properties").delete();
+        String asterixZipName = ManagixDriver.getAsterixZip().substring(
+                ManagixDriver.getAsterixZip().lastIndexOf(File.separator) + 1);
+        zipDir(new File(asterixInstanceDir), new File(asterixInstanceDir + File.separator + asterixZipName));
+
+    }
+
+    private static Node getMetadataNode(Cluster cluster) {
+        Random random = new Random();
+        int nNodes = cluster.getNode().size();
+        return cluster.getNode().get(random.nextInt(nNodes));
+    }
+
+    private static void writeAsterixConfigurationFile(AsterixInstance asterixInstance, boolean newData)
+            throws IOException {
+        String asterixInstanceName = asterixInstance.getName();
+        Cluster cluster = asterixInstance.getCluster();
+        String metadataNodeId = asterixInstance.getMetadataNodeId();
+
+        StringBuffer conf = new StringBuffer();
+        conf.append("MetadataNode=" + asterixInstanceName + "_" + metadataNodeId + "\n");
+        conf.append("NewUniverse=" + newData + "\n");
+
+        for (Node node : cluster.getNode()) {
+            StringBuffer nodeDataStore = new StringBuffer();
+            if (node.getStore() != null) {
+                String[] nodeStores = node.getStore().split(",");
+                for (String ns : nodeStores) {
+                    nodeDataStore.append(ns + File.separator + asterixInstanceName + File.separator);
+                    nodeDataStore.append(",");
+                }
+                nodeDataStore.deleteCharAt(nodeDataStore.length() - 1);
+            } else {
+                if (cluster.getStore() != null) {
+                    String[] nodeStores = cluster.getStore().split(",");
+                    for (String ns : nodeStores) {
+                        nodeDataStore.append(ns + File.separator + node.getId() + File.separator + asterixInstanceName
+                                + File.separator);
+                        nodeDataStore.append(",");
+                    }
+                    nodeDataStore.deleteCharAt(nodeDataStore.length() - 1);
+                }
+            }
+            if (nodeDataStore.length() == 0) {
+                throw new IllegalStateException(" Store not defined for node " + node.getId());
+            }
+            conf.append(asterixInstanceName + "_" + node.getId() + ".stores" + "=" + nodeDataStore + "\n");
+
+        }
+        Properties asterixConfProp = asterixInstance.getConfiguration();
+        String outputDir = asterixConfProp.getProperty("output_dir");
+        conf.append("OutputDir=" + outputDir);
+        File asterixConfDir = new File(ManagixDriver.getAsterixDir() + File.separator + asterixInstanceName);
+        asterixConfDir.mkdirs();
+        dumpToFile(ManagixDriver.getAsterixDir() + File.separator + asterixInstanceName + File.separator
+                + "test.properties", conf.toString());
+    }
+
+    public static Properties getAsterixConfiguration(String asterixConf) throws FileNotFoundException, IOException {
+        Properties prop = new Properties();
+        prop.load(new FileInputStream(asterixConf));
+        return prop;
+    }
+
+    public static void unzip(String sourceFile, String destDir) throws IOException {
+        BufferedOutputStream dest = null;
+        FileInputStream fis = new FileInputStream(sourceFile);
+        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
+        ZipEntry entry = null;
+
+        int BUFFER_SIZE = 4096;
+        while ((entry = zis.getNextEntry()) != null) {
+            String dst = destDir + File.separator + entry.getName();
+            if (entry.isDirectory()) {
+                createDir(destDir, entry);
+                continue;
+            }
+            int count;
+            byte data[] = new byte[BUFFER_SIZE];
+
+            //write the file to the disk
+            FileOutputStream fos = new FileOutputStream(dst);
+            dest = new BufferedOutputStream(fos, BUFFER_SIZE);
+            while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) {
+                dest.write(data, 0, count);
+            }
+            //close the output streams
+            dest.flush();
+            dest.close();
+        }
+
+        zis.close();
+    }
+
+    public static void zipDir(File sourceDir, File destFile) throws IOException {
+        FileOutputStream fos = new FileOutputStream(destFile);
+        ZipOutputStream zos = new ZipOutputStream(fos);
+        zipDir(sourceDir, destFile, zos);
+        zos.close();
+    }
+
+    private static void zipDir(File sourceDir, final File destFile, ZipOutputStream zos) throws IOException {
+        File[] dirList = sourceDir.listFiles(new FileFilter() {
+            public boolean accept(File f) {
+                return !f.getName().endsWith(destFile.getName());
+            }
+        });
+        for (int i = 0; i < dirList.length; i++) {
+            File f = dirList[i];
+            if (f.isDirectory()) {
+                zipDir(f, destFile, zos);
+            } else {
+                int bytesIn = 0;
+                byte[] readBuffer = new byte[2156];
+                FileInputStream fis = new FileInputStream(f);
+                ZipEntry entry = new ZipEntry(sourceDir.getName() + File.separator + f.getName());
+                zos.putNextEntry(entry);
+                while ((bytesIn = fis.read(readBuffer)) != -1) {
+                    zos.write(readBuffer, 0, bytesIn);
+                }
+                fis.close();
+            }
+        }
+    }
+
+    private static void replaceInJar(File sourceJar, String origFile, File replacementFile) throws IOException {
+        File destJar = new File(sourceJar.getAbsolutePath() + ".modified");
+        InputStream jarIs = null;
+        FileInputStream fis = new FileInputStream(replacementFile);
+        JarFile sourceJarFile = new JarFile(sourceJar);
+        Enumeration<JarEntry> entries = sourceJarFile.entries();
+        JarOutputStream jos = new JarOutputStream(new FileOutputStream(destJar));
+        byte[] buffer = new byte[2048];
+        int read;
+        while (entries.hasMoreElements()) {
+            JarEntry entry = (JarEntry) entries.nextElement();
+            String name = entry.getName();
+            if (name.equals(origFile)) {
+                continue;
+            }
+            jarIs = sourceJarFile.getInputStream(entry);
+            jos.putNextEntry(entry);
+            while ((read = jarIs.read(buffer)) != -1) {
+                jos.write(buffer, 0, read);
+            }
+        }
+        JarEntry entry = new JarEntry(origFile);
+        jos.putNextEntry(entry);
+        while ((read = fis.read(buffer)) != -1) {
+            jos.write(buffer, 0, read);
+        }
+        fis.close();
+        jos.close();
+        jarIs.close();
+        sourceJar.delete();
+        destJar.renameTo(sourceJar);
+        sourceJar.setExecutable(true);
+    }
+
+    public static void dumpToFile(String dest, String content) throws IOException {
+        FileWriter writer = new FileWriter(dest);
+        writer.write(content);
+        writer.close();
+    }
+
+    private static void createDir(String destDirectory, ZipEntry entry) {
+        String name = entry.getName();
+        int index = name.lastIndexOf(File.separator);
+        String dirSequence = name.substring(0, index);
+        File newDirs = new File(destDirectory + File.separator + dirSequence);
+        newDirs.mkdirs();
+    }
+
+    public static AsterixInstance validateAsterixInstanceExists(String name, State... permissibleStates)
+            throws Exception {
+        AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(name);
+        if (instance == null) {
+            throw new ManagixException(" Asterix instance by name " + name + " does not exist.");
+        }
+        boolean valid = false;
+        for (State state : permissibleStates) {
+            if (state.equals(instance.getState())) {
+                valid = true;
+                break;
+            }
+        }
+        if (!valid) {
+            throw new ManagixException(" Asterix instance by the name " + name + " is in " + instance.getState()
+                    + " state ");
+        }
+        return instance;
+    }
+
+    public static void validateAsterixInstanceNotExists(String name) throws Exception {
+        AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(name);
+        if (instance != null) {
+            throw new ManagixException(" Asterix instance by name " + name + " already exists.");
+        }
+    }
+
+    public static void deleteDirectory(String path) throws IOException {
+        Runtime.getRuntime().exec("rm -rf " + path);
+    }
+
+    public static String executeLocalScript(String path, List<String> args) throws Exception {
+        List<String> pargs = new ArrayList<String>();
+        pargs.add("/bin/bash");
+        pargs.add(path);
+        if (args != null) {
+            pargs.addAll(args);
+        }
+        ProcessBuilder pb = new ProcessBuilder(pargs);
+        pb.environment().putAll(EventDriver.getEnvironment());
+        pb.environment().put("IP_LOCATION", EventDriver.CLIENT_NODE.getIp());
+        Process p = pb.start();
+        BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
+        StringWriter writer = new StringWriter();
+        IOUtils.copy(bis, writer, "UTF-8");
+        return writer.toString();
+    }
+
+    public static EventrixClient getEventrixClient(Cluster cluster) throws Exception {
+        return new EventrixClient(ManagixDriver.getManagixHome() + File.separator + ManagixDriver.MANAGIX_EVENT_DIR,
+                cluster, false, OutputHandler.INSTANCE);
+    }
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/ManagixException.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/ManagixException.java
new file mode 100644
index 0000000..e13a2f4
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/ManagixException.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.error;
+
+public class ManagixException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    public ManagixException(String message) {
+        super(message);
+    }
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/OutputHandler.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/OutputHandler.java
new file mode 100644
index 0000000..c5ad2a4
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/OutputHandler.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.error;
+
+import edu.uci.ics.asterix.event.management.IOutputHandler;
+import edu.uci.ics.asterix.event.management.OutputAnalysis;
+import edu.uci.ics.asterix.event.schema.pattern.Event;
+import edu.uci.ics.asterix.installer.model.EventList.EventType;
+
+public class OutputHandler implements IOutputHandler {
+
+    public static IOutputHandler INSTANCE = new OutputHandler();
+
+    private OutputHandler() {
+
+    }
+
+    public OutputAnalysis reportEventOutput(Event event, String output) {
+
+        EventType eventType = EventType.valueOf(event.getType().toUpperCase());
+        boolean ignore = true;
+        String trimmedOutput = output.trim();
+        StringBuffer errorMessage = new StringBuffer();
+        switch (eventType) {
+            case FILE_TRANSFER:
+                if (trimmedOutput.length() > 0) {
+                    if (!output.contains("Permission denied") || output.contains("does not exist")
+                            || output.contains("File exist")) {
+                        ignore = true;
+                    } else {
+                        ignore = false;
+                    }
+                }
+                break;
+
+            case BACKUP:
+                if (trimmedOutput.length() > 0) {
+                    if (trimmedOutput.contains("AccessControlException")) {
+                        errorMessage.append("Insufficient permissions on HDFS back up directory");
+                        ignore = false;
+                    }
+                    if (output.contains("does not exist") || output.contains("File exist")) {
+                        ignore = true;
+                    } else {
+                        ignore = false;
+                    }
+                }
+                break;
+
+            case RESTORE:
+                if (trimmedOutput.length() > 0) {
+                    if (trimmedOutput.contains("AccessControlException")) {
+                        errorMessage.append("Insufficient permissions on HDFS back up directory");
+                        ignore = false;
+                    }
+                    if (output.contains("does not exist") || output.contains("File exist")) {
+                        ignore = true;
+                    } else {
+                        ignore = false;
+                    }
+                }
+                break;
+
+            case ASTERIX_DEPLOY:
+                if (trimmedOutput.length() > 0) {
+                    if (trimmedOutput.contains("Exception")) {
+                        ignore = false;
+                        errorMessage.append("Error in deploying Asterix: " + output);
+                        errorMessage.append("\nStop the instance to initiate a cleanup");
+                    }
+                }
+        }
+        if (ignore) {
+            return new OutputAnalysis(true, null);
+        } else {
+            return new OutputAnalysis(false, errorMessage.toString());
+        }
+    }
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/VerificationUtil.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/VerificationUtil.java
new file mode 100644
index 0000000..3b157ec
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/error/VerificationUtil.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.error;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.installer.driver.ManagixDriver;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.model.AsterixInstance.State;
+import edu.uci.ics.asterix.installer.model.AsterixRuntimeState;
+import edu.uci.ics.asterix.installer.model.ProcessInfo;
+
+public class VerificationUtil {
+
+    private static final String VERIFY_SCRIPT_PATH = ManagixDriver.getManagixHome() + File.separator
+            + ManagixDriver.MANAGIX_INTERNAL_DIR + File.separator + "scripts" + File.separator + "verify.sh";
+
+    public static AsterixRuntimeState getAsterixRuntimeState(AsterixInstance instance) throws Exception {
+
+        Cluster cluster = instance.getCluster();
+        List<String> args = new ArrayList<String>();
+        args.add(instance.getName());
+        args.add(instance.getCluster().getMasterNode().getIp());
+        for (Node node : cluster.getNode()) {
+            args.add(node.getIp());
+            args.add(instance.getName() + "_" + node.getId());
+        }
+
+        String output = ManagixUtil.executeLocalScript(VERIFY_SCRIPT_PATH, args);
+        boolean ccRunning = true;
+        List<String> failedNCs = new ArrayList<String>();
+        String[] infoFields;
+        ProcessInfo pInfo;
+        List<ProcessInfo> processes = new ArrayList<ProcessInfo>();
+
+        for (String line : output.split("\n")) {
+            infoFields = line.split(":");
+            try {
+                int pid = Integer.parseInt(infoFields[3]);
+                pInfo = new ProcessInfo(infoFields[0], infoFields[1], pid);
+                processes.add(pInfo);
+            } catch (Exception e) {
+                if (infoFields[0].equalsIgnoreCase("CC")) {
+                    ccRunning = false;
+                } else {
+                    failedNCs.add(infoFields[1]);
+                }
+            }
+        }
+        return new AsterixRuntimeState(processes, failedNCs, ccRunning);
+    }
+
+    public static void updateInstanceWithRuntimeDescription(AsterixInstance instance, AsterixRuntimeState state,
+            boolean expectedRunning) {
+        StringBuffer summary = new StringBuffer();
+        if (expectedRunning) {
+            if (!state.isCcRunning()) {
+                summary.append("Cluster Controller not running at " + instance.getCluster().getMasterNode().getIp()
+                        + "\n");
+                instance.setState(State.UNUSABLE);
+            }
+            if (state.getFailedNCs() != null && !state.getFailedNCs().isEmpty()) {
+                summary.append("Node Controller not running at the following nodes" + "\n");
+                for (String failedNC : state.getFailedNCs()) {
+                    summary.append(failedNC + "\n");
+                }
+                instance.setState(State.UNUSABLE);
+            }
+            if (!(instance.getState().equals(State.UNUSABLE))) {
+                instance.setState(State.ACTIVE);
+            }
+        } else {
+            if (state.getProcesses() != null && state.getProcesses().size() > 0) {
+                summary.append("Following process still running " + "\n");
+                for (ProcessInfo pInfo : state.getProcesses()) {
+                    summary.append(pInfo + "\n");
+                }
+                instance.setState(State.UNUSABLE);
+            } else {
+                instance.setState(State.INACTIVE);
+            }
+        }
+        state.setSummary(summary.toString());
+        instance.setAsterixRuntimeStates(state);
+    }
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/events/PatternCreator.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/events/PatternCreator.java
new file mode 100644
index 0000000..74bdbc2
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/events/PatternCreator.java
@@ -0,0 +1,283 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.events;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import edu.uci.ics.asterix.event.driver.EventDriver;
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+import edu.uci.ics.asterix.event.schema.pattern.Delay;
+import edu.uci.ics.asterix.event.schema.pattern.Event;
+import edu.uci.ics.asterix.event.schema.pattern.Nodeid;
+import edu.uci.ics.asterix.event.schema.pattern.Pattern;
+import edu.uci.ics.asterix.event.schema.pattern.Patterns;
+import edu.uci.ics.asterix.event.schema.pattern.Value;
+import edu.uci.ics.asterix.installer.command.StopCommand;
+import edu.uci.ics.asterix.installer.driver.ManagixDriver;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.service.ILookupService;
+import edu.uci.ics.asterix.installer.service.ServiceProvider;
+
+public class PatternCreator {
+
+    private static final Logger LOGGER = Logger.getLogger(PatternCreator.class.getName());
+    private ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
+    private static int CC_DEBUG_PORT = 8800;
+    private static int NC_DEBUG_PORT = 8701;
+
+    private void addInitialDelay(Pattern p, int delay, String unit) {
+        Delay d = new Delay(new Value(null, "" + delay), unit);
+        p.setDelay(d);
+    }
+
+    public Patterns getStartAsterixPattern(String asterixInstanceName, Cluster cluster) throws Exception {
+        String ccLocationId = cluster.getMasterNode().getId();
+        String ccLocationIp = cluster.getMasterNode().getIp();
+
+        String destDir = cluster.getWorkingDir().getDir() + File.separator + "hyracks";
+        List<Pattern> ps = new ArrayList<Pattern>();
+
+        Pattern createCC = createCCStartPattern(ccLocationId);
+        addInitialDelay(createCC, 2, "sec");
+        ps.add(createCC);
+
+        Pattern copyHyracks = createCopyHyracksPattern(cluster, ccLocationIp, destDir);
+        ps.add(copyHyracks);
+
+        boolean copyHyracksToNC = !cluster.getWorkingDir().isNFS();
+        for (Node node : cluster.getNode()) {
+            if (copyHyracksToNC) {
+                Pattern copyHyracksForNC = createCopyHyracksPattern(cluster, node.getIp(), destDir);
+                ps.add(copyHyracksForNC);
+            }
+            Pattern createNC = createNCStartPattern(cluster.getMasterNode().getIp(), node.getId(), asterixInstanceName
+                    + "_" + node.getId());
+            addInitialDelay(createNC, 4, "sec");
+            ps.add(createNC);
+        }
+
+        Pattern asterixDeploy = createAsterixDeployPattern(asterixInstanceName, cluster);
+        addInitialDelay(asterixDeploy, 6, "sec");
+        ps.add(asterixDeploy);
+
+        Patterns patterns = new Patterns(ps);
+        patterns.getPattern().addAll(createHadoopLibraryTransferPattern(cluster).getPattern());
+        return patterns;
+    }
+
+    public Patterns getStopCommandPattern(StopCommand stopCommand) throws Exception {
+        List<Pattern> ps = new ArrayList<Pattern>();
+        AsterixInstance asterixInstance = lookupService.getAsterixInstance(stopCommand.getAsterixInstanceName());
+        Cluster cluster = asterixInstance.getCluster();
+
+        String ccLocation = cluster.getMasterNode().getId();
+        Pattern createCC = createCCStopPattern(ccLocation);
+        addInitialDelay(createCC, 5, "sec");
+        ps.add(createCC);
+
+        String asterixInstanceName = stopCommand.getAsterixInstanceName();
+        int nodeControllerIndex = 1;
+        for (Node node : cluster.getNode()) {
+            Pattern createNC = createNCStopPattern(node.getId(), asterixInstanceName + "_" + nodeControllerIndex);
+            ps.add(createNC);
+            nodeControllerIndex++;
+        }
+
+        Patterns patterns = new Patterns(ps);
+        return patterns;
+    }
+
+    public Patterns getBackUpAsterixPattern(AsterixInstance instance, String backupPath) throws Exception {
+        Cluster cluster = instance.getCluster();
+        String clusterStore = instance.getCluster().getStore();
+        String hdfsUrl = ManagixDriver.getConfiguration().getBackup().getHdfs().getUrl();
+        String hadoopVersion = ManagixDriver.getConfiguration().getBackup().getHdfs().getVersion();
+        String hdfsBackupDir = ManagixDriver.getConfiguration().getBackup().getHdfs().getBackupDir();
+        String workingDir = cluster.getWorkingDir().getDir();
+        String backupId = "" + instance.getBackupInfo().size();
+        String nodeStore;
+        String pargs;
+        List<Pattern> patternList = new ArrayList<Pattern>();
+        for (Node node : cluster.getNode()) {
+            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+            nodeStore = node.getStore() == null ? clusterStore : node.getStore();
+            pargs = workingDir + " " + instance.getName() + " " + nodeStore + " " + backupId + " " + hdfsUrl + " "
+                    + hadoopVersion + " " + hdfsBackupDir + " " + node.getId();
+            Event event = new Event("backup", nodeid, pargs);
+            patternList.add(new Pattern(null, 1, null, event));
+        }
+        return new Patterns(patternList);
+    }
+
+    public Patterns getRestoreAsterixPattern(AsterixInstance instance, int backupId) throws Exception {
+        Cluster cluster = instance.getCluster();
+        String clusterStore = instance.getCluster().getStore();
+        String hdfsUrl = ManagixDriver.getConfiguration().getBackup().getHdfs().getUrl();
+        String hadoopVersion = ManagixDriver.getConfiguration().getBackup().getHdfs().getVersion();
+        String hdfsBackupDir = ManagixDriver.getConfiguration().getBackup().getHdfs().getBackupDir();
+        String workingDir = cluster.getWorkingDir().getDir();
+        String nodeStore;
+        String pargs;
+        List<Pattern> patternList = new ArrayList<Pattern>();
+        for (Node node : cluster.getNode()) {
+            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+            nodeStore = node.getStore() == null ? clusterStore : node.getStore();
+            pargs = workingDir + " " + instance.getName() + " " + nodeStore + " " + backupId + " " + hdfsUrl + " "
+                    + hadoopVersion + " " + hdfsBackupDir + " " + node.getId();
+            Event event = new Event("restore", nodeid, pargs);
+            patternList.add(new Pattern(null, 1, null, event));
+        }
+        return new Patterns(patternList);
+    }
+
+    public Patterns createHadoopLibraryTransferPattern(Cluster cluster) throws Exception {
+        List<Pattern> patternList = new ArrayList<Pattern>();
+        String workingDir = cluster.getWorkingDir().getDir();
+        String hadoopVersion = ManagixDriver.getConfiguration().getBackup().getHdfs().getVersion();
+        File hadoopDir = new File(ManagixDriver.getManagixHome() + File.separator + ManagixDriver.MANAGIX_INTERNAL_DIR
+                + File.separator + "hadoop-" + hadoopVersion);
+        if (!hadoopDir.exists()) {
+            throw new IllegalStateException("Hadoop version :" + hadoopVersion + " not supported");
+        }
+
+        Nodeid nodeid = new Nodeid(new Value(null, EventDriver.CLIENT_NODE.getId()));
+        String username = cluster.getUsername() != null ? cluster.getUsername() : System.getProperty("user.name");
+        String pargs = username + " " + hadoopDir.getAbsolutePath() + " " + cluster.getMasterNode().getIp() + " "
+                + workingDir;
+        Event event = new Event("directory_transfer", nodeid, pargs);
+        Pattern p = new Pattern(null, 1, null, event);
+        addInitialDelay(p, 2, "sec");
+        patternList.add(p);
+
+        boolean copyToNC = !cluster.getWorkingDir().isNFS();
+        if (copyToNC) {
+            for (Node node : cluster.getNode()) {
+                nodeid = new Nodeid(new Value(null, node.getId()));
+                pargs = cluster.getUsername() + " " + hadoopDir.getAbsolutePath() + " " + node.getIp() + " "
+                        + workingDir;
+                event = new Event("directory_transfer", nodeid, pargs);
+                p = new Pattern(null, 1, null, event);
+                addInitialDelay(p, 2, "sec");
+                patternList.add(p);
+            }
+        }
+        Patterns patterns = new Patterns(patternList);
+        return patterns;
+    }
+
+    public Patterns createDeleteInstancePattern(AsterixInstance instance) throws Exception {
+        List<Pattern> patternList = new ArrayList<Pattern>();
+        patternList.addAll(createRemoveAsterixStoragePattern(instance).getPattern());
+        if (instance.getBackupInfo() != null && instance.getBackupInfo().size() > 0) {
+            patternList.addAll(createRemoveHDFSBackupPattern(instance).getPattern());
+        }
+        Patterns patterns = new Patterns(patternList);
+        return patterns;
+    }
+
+    private Patterns createRemoveHDFSBackupPattern(AsterixInstance instance) throws Exception {
+        List<Pattern> patternList = new ArrayList<Pattern>();
+        Cluster cluster = instance.getCluster();
+        String hdfsUrl = ManagixDriver.getConfiguration().getBackup().getHdfs().getUrl();
+        String hadoopVersion = ManagixDriver.getConfiguration().getBackup().getHdfs().getVersion();
+        String hdfsBackupDir = ManagixDriver.getConfiguration().getBackup().getHdfs().getBackupDir();
+        String workingDir = cluster.getWorkingDir().getDir();
+        Node launchingNode = cluster.getNode().get(0);
+        Nodeid nodeid = new Nodeid(new Value(null, launchingNode.getId()));
+        String pathToDelete = hdfsBackupDir + File.separator + instance.getName();
+        String pargs = workingDir + " " + hadoopVersion + " " + hdfsUrl + " " + pathToDelete;
+        Event event = new Event("hdfs_delete", nodeid, pargs);
+        patternList.add(new Pattern(null, 1, null, event));
+        Patterns patterns = new Patterns(patternList);
+        return patterns;
+    }
+
+    private Patterns createRemoveAsterixStoragePattern(AsterixInstance instance) throws Exception {
+        List<Pattern> patternList = new ArrayList<Pattern>();
+        Cluster cluster = instance.getCluster();
+        String pargs = null;
+
+        for (Node node : cluster.getNode()) {
+            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+            String[] nodeStores;
+            if (node.getStore() != null) {
+                nodeStores = node.getStore().trim().split(",");
+                for (String ns : nodeStores) {
+                    pargs = ns + File.separator + instance.getName();
+                }
+            } else {
+                nodeStores = cluster.getStore().trim().split(",");
+                for (String ns : nodeStores) {
+                    pargs = ns + File.separator + node.getId() + File.separator + instance.getName();
+                }
+            }
+            Event event = new Event("file_delete", nodeid, pargs);
+            patternList.add(new Pattern(null, 1, null, event));
+        }
+        Patterns patterns = new Patterns(patternList);
+        return patterns;
+    }
+
+    private Pattern createCopyHyracksPattern(Cluster cluster, String destinationIp, String destDir) {
+        Nodeid nodeid = new Nodeid(new Value(null, EventDriver.CLIENT_NODE.getId()));
+        String username = cluster.getUsername() != null ? cluster.getUsername() : System.getProperty("user.name");
+        String pargs = username + " " + ManagixDriver.getHyrackServerZip() + " " + destinationIp + " " + destDir + " "
+                + "unpack";
+        Event event = new Event("file_transfer", nodeid, pargs);
+        return new Pattern(null, 1, null, event);
+    }
+
+    private Pattern createCCStartPattern(String hostId) {
+        Nodeid nodeid = new Nodeid(new Value(null, hostId));
+        Event event = new Event("cc_start", nodeid, "" + CC_DEBUG_PORT);
+        CC_DEBUG_PORT++;
+        return new Pattern(null, 1, null, event);
+    }
+
+    public Pattern createCCStopPattern(String hostId) {
+        Nodeid nodeid = new Nodeid(new Value(null, hostId));
+        Event event = new Event("cc_failure", nodeid, null);
+        return new Pattern(null, 1, null, event);
+    }
+
+    public Pattern createNCStartPattern(String ccHost, String hostId, String nodeControllerId) {
+        Nodeid nodeid = new Nodeid(new Value(null, hostId));
+        Event event = new Event("node_join", nodeid, ccHost + " " + nodeControllerId + " " + NC_DEBUG_PORT);
+        NC_DEBUG_PORT++;
+        return new Pattern(null, 1, null, event);
+    }
+
+    public Pattern createNCStopPattern(String hostId, String nodeControllerId) {
+        Nodeid nodeid = new Nodeid(new Value(null, hostId));
+        Event event = new Event("node_failure", nodeid, nodeControllerId);
+        return new Pattern(null, 1, null, event);
+    }
+
+    private Pattern createAsterixDeployPattern(String asterixInstanceName, Cluster cluster) {
+        Nodeid nodeid = new Nodeid(new Value(null, EventDriver.CLIENT_NODE.getId()));
+        String asterixZipName = ManagixDriver.getAsterixZip().substring(
+                ManagixDriver.getAsterixZip().lastIndexOf(File.separator) + 1);
+        String asterixInstanceZip = ManagixDriver.getAsterixDir() + File.separator + asterixInstanceName
+                + File.separator + asterixZipName;
+        Event event = new Event("asterix_deploy", nodeid, ManagixDriver.getManagixHome() + " " + asterixInstanceZip
+                + " " + cluster.getMasterNode().getIp());
+        return new Pattern(null, 1, null, event);
+    }
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/AsterixInstance.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/AsterixInstance.java
new file mode 100644
index 0000000..d1a6485
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/AsterixInstance.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.model;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import edu.uci.ics.asterix.event.schema.cluster.Cluster;
+import edu.uci.ics.asterix.event.schema.cluster.Node;
+
+public class AsterixInstance implements Serializable {
+
+    private static final long serialVersionUID = 2874439550187520449L;
+
+    public enum State {
+        ACTIVE,
+        INACTIVE,
+        UNUSABLE
+    }
+
+    private final Cluster cluster;
+    private final String name;
+    private final Date createdTimestamp;
+    private Date stateChangeTimestamp;
+    private Date modifiedTimestamp;
+    private Properties configuration;
+    private State state;
+    private final String metadataNodeId;
+    private final String asterixVersion;
+    private final String hyracksVersion;
+    private final List<BackupInfo> backupInfo;
+    private final String webInterfaceUrl;
+    private AsterixRuntimeState runtimeState;
+    private State previousState;
+
+    public AsterixInstance(String name, Cluster cluster, Properties configuration, String metadataNodeId,
+            String asterixVersion, String hyracksVersion) {
+        this.name = name;
+        this.cluster = cluster;
+        this.configuration = configuration;
+        this.metadataNodeId = metadataNodeId;
+        this.state = State.ACTIVE;
+        this.previousState = State.UNUSABLE;
+        this.asterixVersion = asterixVersion;
+        this.hyracksVersion = hyracksVersion;
+        this.createdTimestamp = new Date();
+        this.backupInfo = new ArrayList<BackupInfo>();
+        this.webInterfaceUrl = "http://" + cluster.getMasterNode().getIp() + ":" + 19001;
+    }
+
+    public Date getModifiedTimestamp() {
+        return stateChangeTimestamp;
+    }
+
+    public Properties getConfiguration() {
+        return configuration;
+    }
+
+    public void setConfiguration(Properties properties) {
+        this.configuration = properties;
+    }
+
+    public State getState() {
+        return state;
+    }
+
+    public void setState(State state) {
+        this.previousState = this.state;
+        this.state = state;
+    }
+
+    public Cluster getCluster() {
+        return cluster;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Date getCreatedTimestamp() {
+        return createdTimestamp;
+    }
+
+    public Date getStateChangeTimestamp() {
+        return stateChangeTimestamp;
+    }
+
+    public void setStateChangeTimestamp(Date stateChangeTimestamp) {
+        this.stateChangeTimestamp = stateChangeTimestamp;
+    }
+
+    public void setModifiedTimestamp(Date modifiedTimestamp) {
+        this.modifiedTimestamp = modifiedTimestamp;
+    }
+
+    public String getMetadataNodeId() {
+        return metadataNodeId;
+    }
+
+    public String getAsterixVersion() {
+        return asterixVersion;
+    }
+
+    public String getHyracksVersion() {
+        return hyracksVersion;
+    }
+
+    public String getDescription(boolean detailed) {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("Name:" + name + "\n");
+        buffer.append("Created:" + createdTimestamp + "\n");
+        buffer.append("Web-Url:" + webInterfaceUrl + "\n");
+        buffer.append("State:" + state);
+        if (!state.equals(State.UNUSABLE) && stateChangeTimestamp != null) {
+            buffer.append(" (" + stateChangeTimestamp + ")" + "\n");
+        } else {
+            buffer.append("\n");
+        }
+        if (modifiedTimestamp != null) {
+            buffer.append("Last modified timestamp:" + modifiedTimestamp + "\n");
+        }
+
+        if (runtimeState.getSummary() != null && runtimeState.getSummary().length() > 0) {
+            buffer.append("\nWARNING!:" + runtimeState.getSummary() + "\n");
+        }
+        if (detailed) {
+            addDetailedInformation(buffer);
+        }
+        buffer.append("\n");
+        return buffer.toString();
+    }
+
+    public List<BackupInfo> getBackupInfo() {
+        return backupInfo;
+    }
+
+    public String getWebInterfaceUrl() {
+        return webInterfaceUrl;
+    }
+
+    public AsterixRuntimeState getAsterixRuntimeState() {
+        return runtimeState;
+    }
+
+    public void setAsterixRuntimeStates(AsterixRuntimeState runtimeState) {
+        this.runtimeState = runtimeState;
+    }
+
+    private void addDetailedInformation(StringBuffer buffer) {
+        buffer.append("Master node:" + cluster.getMasterNode().getId() + ":" + cluster.getMasterNode().getIp() + "\n");
+        for (Node node : cluster.getNode()) {
+            buffer.append(node.getId() + ":" + node.getIp() + "\n");
+        }
+
+        buffer.append("\n");
+        if (backupInfo != null && backupInfo.size() > 0) {
+            for (BackupInfo info : backupInfo) {
+                buffer.append("Backup:" + info.getId() + " created at " + info.getDate() + "\n");
+            }
+        }
+        buffer.append("\n");
+        buffer.append("Asterix version:" + asterixVersion + "\n");
+        buffer.append("Hyracks version:" + hyracksVersion + "\n");
+        buffer.append("Asterix Configuration" + "\n");
+        for (Entry<Object, Object> entry : configuration.entrySet()) {
+            buffer.append(entry.getKey() + " = " + entry.getValue() + "\n");
+        }
+        buffer.append("Metadata Node:" + metadataNodeId + "\n");
+        buffer.append("Processes" + "\n");
+        for (ProcessInfo pInfo : runtimeState.getProcesses()) {
+            buffer.append(pInfo + "\n");
+        }
+
+    }
+
+    public State getPreviousState() {
+        return previousState;
+    }
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/AsterixRuntimeState.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/AsterixRuntimeState.java
new file mode 100644
index 0000000..207c570
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/AsterixRuntimeState.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.model;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class AsterixRuntimeState implements Serializable {
+
+    private final List<ProcessInfo> processes;
+    private final List<String> failedNCs;
+    private final boolean ccRunning;
+    private String summary;
+
+    public AsterixRuntimeState(List<ProcessInfo> processes, List<String> failedNCs, boolean ccRunning) {
+        this.processes = processes;
+        this.failedNCs = failedNCs;
+        this.ccRunning = ccRunning;
+    }
+
+    public List<ProcessInfo> getProcesses() {
+        return processes;
+    }
+
+    public List<String> getFailedNCs() {
+        return failedNCs;
+    }
+
+    public boolean isCcRunning() {
+        return ccRunning;
+    }
+
+    public void setSummary(String summary) {
+        this.summary = summary;
+    }
+
+    public String getSummary() {
+        return summary;
+    }
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/BackupInfo.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/BackupInfo.java
new file mode 100644
index 0000000..a5d2b36
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/BackupInfo.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.model;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class BackupInfo implements Serializable {
+   
+    private final int id;
+    private final Date date;
+
+    public BackupInfo(int id, Date date) {
+        this.id = id;
+        this.date = date;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+    
+    @Override
+    public String toString() {
+        return id + "_" + date;
+    }
+
+}
\ No newline at end of file
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/EventList.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/EventList.java
new file mode 100644
index 0000000..e7f7264
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/EventList.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.model;
+
+public class EventList {
+
+    public enum EventType {
+        NODE_JOIN,
+        NODE_FAILURE,
+        CC_START,
+        CC_FAILURE,
+        ASTERIX_DEPLOY,
+        BACKUP,
+        RESTORE,
+        FILE_DELETE,
+        HDFS_DELETE,
+        FILE_TRANSFER,
+        DIRECTORY_TRANSFER
+    }
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/ProcessInfo.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/ProcessInfo.java
new file mode 100644
index 0000000..2880671
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/model/ProcessInfo.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.model;
+
+import java.io.Serializable;
+
+public class ProcessInfo implements Serializable {
+
+    private static final long serialVersionUID = 304186774065853730L;
+    private final String processName;
+    private final String host;
+    private final int processId;
+
+    public ProcessInfo(String processName, String host, int processId) {
+        this.processName = processName;
+        this.host = host;
+        this.processId = processId;
+    }
+
+    public String getProcessName() {
+        return processName;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public int getProcessId() {
+        return processId;
+    }
+
+    public String toString() {
+        return processName + " at " + host + " [ " + processId + " ] ";
+    }
+
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ILookupService.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ILookupService.java
new file mode 100644
index 0000000..f258e66
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ILookupService.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.service;
+
+import java.util.List;
+
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.schema.conf.Configuration;
+
+public interface ILookupService {
+
+    public void writeAsterixInstance(AsterixInstance asterixInstance) throws Exception;
+
+    public AsterixInstance getAsterixInstance(String name) throws Exception;
+
+    public boolean isRunning(Configuration conf) throws Exception;
+
+    public void startService(Configuration conf) throws Exception;
+
+    public boolean exists(String name) throws Exception;
+
+    public void removeAsterixInstance(String name) throws Exception;
+
+    public List<AsterixInstance> getAsterixInstances() throws Exception;
+
+    public void updateAsterixInstance(AsterixInstance updatedInstance) throws Exception;
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ServiceProvider.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ServiceProvider.java
new file mode 100644
index 0000000..1a9e9e6
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ServiceProvider.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.service;
+
+public class ServiceProvider {
+
+    public static ServiceProvider INSTANCE = new ServiceProvider();
+    private static ILookupService lookupService = new ZooKeeperService();
+    
+    private ServiceProvider() {
+
+    }
+
+    public ILookupService getLookupService() {
+        return lookupService;
+    }
+ 
+}
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ZooKeeperService.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ZooKeeperService.java
new file mode 100644
index 0000000..977147e
--- /dev/null
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/service/ZooKeeperService.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.installer.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.data.Stat;
+
+import edu.uci.ics.asterix.installer.driver.ManagixDriver;
+import edu.uci.ics.asterix.installer.driver.ManagixUtil;
+import edu.uci.ics.asterix.installer.error.ManagixException;
+import edu.uci.ics.asterix.installer.model.AsterixInstance;
+import edu.uci.ics.asterix.installer.schema.conf.Configuration;
+
+public class ZooKeeperService implements ILookupService {
+
+    private static final Logger LOGGER = Logger.getLogger(ZooKeeperService.class.getName());
+
+    private static final int ZOOKEEPER_LEADER_CONN_PORT = 2222;
+    private static final int ZOOKEEPER_LEADER_ELEC_PORT = 2223;
+    private static final int ZOOKEEPER_SESSION_TIME_OUT = 40 * 1000; //milliseconds
+    private static final String ZOOKEEPER_HOME = ManagixDriver.getManagixHome() + File.separator
+            + ManagixDriver.MANAGIX_INTERNAL_DIR + File.separator + "zookeeper";
+    private static final String ZOO_KEEPER_CONFIG = ZOOKEEPER_HOME + File.separator + "zk.cfg";
+
+    private boolean isRunning = false;
+    private ZooKeeper zk;
+    private String zkConnectionString;
+    private static final String ASTERIX_INSTANCE_BASE_PATH = "/Asterix";
+    private static final int DEFAULT_NODE_VERSION = -1;
+    private LinkedBlockingQueue<String> msgQ = new LinkedBlockingQueue<String>();
+    private ZooKeeperWatcher watcher = new ZooKeeperWatcher(msgQ);
+
+    public boolean isRunning(Configuration conf) throws Exception {
+        LOGGER.setLevel(Level.WARNING);
+        List<String> servers = conf.getZookeeper().getServers().getServer();
+        int clientPort = conf.getZookeeper().getClientPort().intValue();
+        StringBuffer connectionString = new StringBuffer();
+        for (String serverAddress : servers) {
+            connectionString.append(serverAddress);
+            connectionString.append(":");
+            connectionString.append(clientPort);
+            connectionString.append(",");
+        }
+        if (connectionString.length() > 0) {
+            connectionString.deleteCharAt(connectionString.length() - 1);
+        }
+        zkConnectionString = connectionString.toString();
+
+        zk = new ZooKeeper(zkConnectionString, ZOOKEEPER_SESSION_TIME_OUT, watcher);
+        try {
+            zk.exists("/dummy", watcher);
+            if (LOGGER.isLoggable(Level.INFO)) {
+                LOGGER.info("ZooKeeper running at " + connectionString);
+            }
+            createRootIfNotExist();
+            isRunning = true;
+        } catch (KeeperException ke) {
+            isRunning = false;
+        }
+        return isRunning;
+    }
+
+    public void startService(Configuration conf) throws Exception {
+        LOGGER.info("Starting ZooKeeper at " + zkConnectionString);
+        ZookeeperUtil.writeConfiguration(ZOO_KEEPER_CONFIG, conf, ZOOKEEPER_LEADER_CONN_PORT,
+                ZOOKEEPER_LEADER_ELEC_PORT);
+        String initScript = ZOOKEEPER_HOME + File.separator + "bin" + File.separator + "zk.init";
+        StringBuffer cmdBuffer = new StringBuffer();
+        cmdBuffer.append(initScript + " ");
+        cmdBuffer.append(conf.getZookeeper().getHomeDir() + " ");
+        List<String> zkServers = conf.getZookeeper().getServers().getServer();
+        for (String zkServer : zkServers) {
+            cmdBuffer.append(zkServer + " ");
+        }
+        Runtime.getRuntime().exec(cmdBuffer.toString());
+        zk = new ZooKeeper(zkConnectionString, ZOOKEEPER_SESSION_TIME_OUT, watcher);
+        msgQ.take();
+        createRootIfNotExist();
+    }
+
+    public void writeAsterixInstance(AsterixInstance asterixInstance) throws Exception {
+        String instanceBasePath = ASTERIX_INSTANCE_BASE_PATH + File.separator + asterixInstance.getName();
+        ByteArrayOutputStream b = new ByteArrayOutputStream();
+        ObjectOutputStream o = new ObjectOutputStream(b);
+        o.writeObject(asterixInstance);
+        zk.create(instanceBasePath, b.toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+    }
+
+    private void createRootIfNotExist() throws Exception {
+        try {
+            Stat stat = zk.exists(ASTERIX_INSTANCE_BASE_PATH, false);
+            if (stat == null) {
+                zk.create(ASTERIX_INSTANCE_BASE_PATH, "root".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+            }
+        } catch (Exception e) {
+            createRootIfNotExist();
+        }
+    }
+
+    public AsterixInstance getAsterixInstance(String name) throws Exception {
+        String path = ASTERIX_INSTANCE_BASE_PATH + File.separator + name;
+        Stat stat = zk.exists(ASTERIX_INSTANCE_BASE_PATH + File.separator + name, false);
+        if (stat == null) {
+            return null;
+        }
+        byte[] asterixInstanceBytes = zk.getData(path, false, new Stat());
+        return readAsterixInstanceObject(asterixInstanceBytes);
+    }
+
+    public boolean exists(String asterixInstanceName) throws Exception {
+        return zk.exists(ASTERIX_INSTANCE_BASE_PATH + File.separator + asterixInstanceName, false) != null;
+    }
+
+    public void removeAsterixInstance(String name) throws Exception {
+        if (!exists(name)) {
+            throw new ManagixException(" Asterix instance by name " + name + " does not exists.");
+        }
+        zk.delete(ASTERIX_INSTANCE_BASE_PATH + File.separator + name, DEFAULT_NODE_VERSION);
+    }
+
+    public List<AsterixInstance> getAsterixInstances() throws Exception {
+        List<String> instanceNames = zk.getChildren(ASTERIX_INSTANCE_BASE_PATH, false);
+        List<AsterixInstance> asterixInstances = new ArrayList<AsterixInstance>();
+        String path;
+        for (String instanceName : instanceNames) {
+            path = ASTERIX_INSTANCE_BASE_PATH + File.separator + instanceName;
+            byte[] asterixInstanceBytes = zk.getData(path, false, new Stat());
+            asterixInstances.add(readAsterixInstanceObject(asterixInstanceBytes));
+        }
+        return asterixInstances;
+    }
+
+    private AsterixInstance readAsterixInstanceObject(byte[] asterixInstanceBytes) throws IOException,
+            ClassNotFoundException {
+        ByteArrayInputStream b = new ByteArrayInputStream(asterixInstanceBytes);
+        ObjectInputStream ois = new ObjectInputStream(b);
+        return (AsterixInstance) ois.readObject();
+    }
+
+    public void updateAsterixInstance(AsterixInstance updatedInstance) throws Exception {
+        removeAsterixInstance(updatedInstance.getName());
+        writeAsterixInstance(updatedInstance);
+    }
+
+}
+
+class ZooKeeperWatcher implements Watcher {
+
+    private boolean isRunning = true;
+    private LinkedBlockingQueue<String> msgQ;
+
+    public ZooKeeperWatcher(LinkedBlockingQueue<String> msgQ) {
+        this.msgQ = msgQ;
+    }
+
+    public void process(WatchedEvent wEvent) {
+        switch (wEvent.getState()) {
+            case SyncConnected:
+                msgQ.add("connected");
+                break;
+        }
+    }
+
+    public boolean isRunning() {
+        return isRunning;
+    }
+
+}
+
+class ZookeeperUtil {
+
+    public static void writeConfiguration(String zooKeeperConfigPath, Configuration conf, int leaderConnPort,
+            int leaderElecPort) throws IOException {
+
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("tickTime=1000" + "\n");
+        buffer.append("dataDir=" + conf.getZookeeper().getHomeDir() + File.separator + "data" + "\n");
+        buffer.append("clientPort=" + conf.getZookeeper().getClientPort().intValue() + "\n");
+        buffer.append("initLimit=" + 2 + "\n");
+        buffer.append("syncLimit=" + 2 + "\n");
+
+        List<String> servers = conf.getZookeeper().getServers().getServer();
+        int serverId = 1;
+        for (String server : servers) {
+            buffer.append("server" + "." + serverId + "=" + server + ":" + leaderConnPort + ":" + leaderElecPort + "\n");
+            serverId++;
+        }
+        ManagixUtil.dumpToFile(zooKeeperConfigPath, buffer.toString());
+    }
+
+}
diff --git a/asterix-installer/src/main/resources/clusters/local.xml b/asterix-installer/src/main/resources/clusters/local.xml
new file mode 100644
index 0000000..920d1ab
--- /dev/null
+++ b/asterix-installer/src/main/resources/clusters/local.xml
@@ -0,0 +1,24 @@
+<cluster xmlns="cluster">
+  <name>local</name>
+  <workingDir>
+     <dir>/tmp/asterix/installer</dir> <!-- a working directory with write permissions>
+     <NFS>true</NFS> <!--true if the directory is on NFS and readable by all nodes in the cluster>
+  </workingDir>
+  <logdir>/tmp/asterix/logs</logdir><!-- directory that will house the logs writtern by Asterix processes (CC/NC)-->
+  <store>/tmp/asterix/storage</store><!-- storage directory (on each node) that will house the Asterix datasets-->
+  <java_home>/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home</java_home>
+  <ram>1024m</ram>
+  <master-node>
+     <id>master</id>
+     <ip>127.0.0.1</ip>
+     <cluster-ip>127.0.0.1</cluster-ip>
+  </master-node>
+  <node>
+     <id>node1</id>
+     <ip>127.0.0.1</ip>
+  </node>
+  <node>
+     <id>node2</id>
+     <ip>127.0.0.1</ip>
+  </node>
+</cluster>
diff --git a/asterix-installer/src/main/resources/conf/asterix.conf b/asterix-installer/src/main/resources/conf/asterix.conf
new file mode 100644
index 0000000..659b48e
--- /dev/null
+++ b/asterix-installer/src/main/resources/conf/asterix.conf
@@ -0,0 +1 @@
+output_dir=/tmp/asterix_output/
diff --git a/asterix-installer/src/main/resources/conf/log4j.properties b/asterix-installer/src/main/resources/conf/log4j.properties
new file mode 100644
index 0000000..0e340f7
--- /dev/null
+++ b/asterix-installer/src/main/resources/conf/log4j.properties
@@ -0,0 +1,60 @@
+# Define some default values that can be overridden by system properties
+zookeeper.root.logger=SEVERE, CONSOLE
+zookeeper.console.threshold=WARN
+zookeeper.log.dir=.
+zookeeper.log.file=zookeeper.log
+zookeeper.log.threshold=WARN
+zookeeper.tracelog.dir=.
+zookeeper.tracelog.file=zookeeper_trace.log
+
+log4j.logger.edu.uci.ics=INFO
+
+#
+# ZooKeeper Logging Configuration
+#
+
+# Format is "<default threshold> (, <appender>)+
+
+# DEFAULT: console appender only
+log4j.rootLogger=WARN
+
+# Example with rolling log file
+#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
+
+# Example with rolling log file and tracing
+#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
+
+#
+# Log INFO level and above messages to the console
+#
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
+
+#
+# Add ROLLINGFILE to rootLogger to get log file output
+#    Log DEBUG level and above messages to a log file
+log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
+log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
+log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}
+
+# Max log file size of 10MB
+log4j.appender.ROLLINGFILE.MaxFileSize=10MB
+# uncomment the next line to limit number of backup files
+#log4j.appender.ROLLINGFILE.MaxBackupIndex=10
+
+log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
+
+
+#
+# Add TRACEFILE to rootLogger to get log file output
+#    Log DEBUG level and above messages to a log file
+log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
+log4j.appender.TRACEFILE.Threshold=TRACE
+log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}
+
+log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
+### Notice we are including log4j's NDC here (%x)
+log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n
diff --git a/asterix-installer/src/main/resources/conf/managix-conf.xml b/asterix-installer/src/main/resources/conf/managix-conf.xml
new file mode 100644
index 0000000..9dac8ac
--- /dev/null
+++ b/asterix-installer/src/main/resources/conf/managix-conf.xml
@@ -0,0 +1,16 @@
+<configuration xmlns="managix">
+  <backup>
+    <hdfs>
+      <version>0.20.2</version>
+      <url>hdfs://mjcarey-desktop.ics.uci.edu:54310</url>
+      <backupDir>/user/raman/asterix_desktop</backupDir>
+    </hdfs>
+  </backup>
+  <zookeeper>
+    <homeDir>/Users/ramangrover29/zookeeper</homeDir>
+    <clientPort>2900</clientPort>
+    <servers>
+      <server>localhost</server>
+    </servers>
+  </zookeeper>
+</configuration>
diff --git a/asterix-installer/src/main/resources/hadoop-0.20.2/bin/hadoop b/asterix-installer/src/main/resources/hadoop-0.20.2/bin/hadoop
new file mode 100755
index 0000000..683e95d
--- /dev/null
+++ b/asterix-installer/src/main/resources/hadoop-0.20.2/bin/hadoop
@@ -0,0 +1,290 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# The Hadoop command script
+#
+# Environment Variables
+#
+#   JAVA_HOME        The java implementation to use.  Overrides JAVA_HOME.
+#
+#   HADOOP_CLASSPATH Extra Java CLASSPATH entries.
+#
+#   HADOOP_HEAPSIZE  The maximum amount of heap to use, in MB. 
+#                    Default is 1000.
+#
+#   HADOOP_OPTS      Extra Java runtime options.
+#   
+#   HADOOP_NAMENODE_OPTS       These options are added to HADOOP_OPTS 
+#   HADOOP_CLIENT_OPTS         when the respective command is run.
+#   HADOOP_{COMMAND}_OPTS etc  HADOOP_JT_OPTS applies to JobTracker 
+#                              for e.g.  HADOOP_CLIENT_OPTS applies to 
+#                              more than one command (fs, dfs, fsck, 
+#                              dfsadmin etc)  
+#
+#   HADOOP_CONF_DIR  Alternate conf dir. Default is ${HADOOP_HOME}/conf.
+#
+#   HADOOP_ROOT_LOGGER The root appender. Default is INFO,console
+#
+
+bin=`dirname "$0"`
+bin=`cd "$bin"; pwd`
+
+. "$bin"/hadoop-config.sh
+
+cygwin=false
+case "`uname`" in
+CYGWIN*) cygwin=true;;
+esac
+
+# if no args specified, show usage
+if [ $# = 0 ]; then
+  echo "Usage: hadoop [--config confdir] COMMAND"
+  echo "where COMMAND is one of:"
+  echo "  namenode -format     format the DFS filesystem"
+  echo "  secondarynamenode    run the DFS secondary namenode"
+  echo "  namenode             run the DFS namenode"
+  echo "  datanode             run a DFS datanode"
+  echo "  dfsadmin             run a DFS admin client"
+  echo "  mradmin              run a Map-Reduce admin client"
+  echo "  fsck                 run a DFS filesystem checking utility"
+  echo "  fs                   run a generic filesystem user client"
+  echo "  balancer             run a cluster balancing utility"
+  echo "  jobtracker           run the MapReduce job Tracker node" 
+  echo "  pipes                run a Pipes job"
+  echo "  tasktracker          run a MapReduce task Tracker node" 
+  echo "  job                  manipulate MapReduce jobs"
+  echo "  queue                get information regarding JobQueues" 
+  echo "  version              print the version"
+  echo "  jar <jar>            run a jar file"
+  echo "  distcp <srcurl> <desturl> copy file or directories recursively"
+  echo "  archive -archiveName NAME <src>* <dest> create a hadoop archive"
+  echo "  daemonlog            get/set the log level for each daemon"
+  echo " or"
+  echo "  CLASSNAME            run the class named CLASSNAME"
+  echo "Most commands print help when invoked w/o parameters."
+  exit 1
+fi
+
+# get arguments
+COMMAND=$1
+shift
+
+if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then
+  . "${HADOOP_CONF_DIR}/hadoop-env.sh"
+fi
+
+# some Java parameters
+if [ "$JAVA_HOME" != "" ]; then
+  #echo "run java in $JAVA_HOME"
+  JAVA_HOME=$JAVA_HOME
+fi
+  
+if [ "$JAVA_HOME" = "" ]; then
+  echo "Error: JAVA_HOME is not set."
+  exit 1
+fi
+
+JAVA=$JAVA_HOME/bin/java
+JAVA_HEAP_MAX=-Xmx1000m 
+
+# check envvars which might override default args
+if [ "$HADOOP_HEAPSIZE" != "" ]; then
+  #echo "run with heapsize $HADOOP_HEAPSIZE"
+  JAVA_HEAP_MAX="-Xmx""$HADOOP_HEAPSIZE""m"
+  #echo $JAVA_HEAP_MAX
+fi
+
+# CLASSPATH initially contains $HADOOP_CONF_DIR
+CLASSPATH=${HADOOP_CONF_DIR}
+CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
+
+# for developers, add Hadoop classes to CLASSPATH
+if [ -d "$HADOOP_HOME/build/classes" ]; then
+  CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/classes
+fi
+if [ -d "$HADOOP_HOME/build/webapps" ]; then
+  CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build
+fi
+if [ -d "$HADOOP_HOME/build/test/classes" ]; then
+  CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/test/classes
+fi
+if [ -d "$HADOOP_HOME/build/tools" ]; then
+  CLASSPATH=${CLASSPATH}:$HADOOP_HOME/build/tools
+fi
+
+# so that filenames w/ spaces are handled correctly in loops below
+IFS=
+
+# for releases, add core hadoop jar & webapps to CLASSPATH
+if [ -d "$HADOOP_HOME/webapps" ]; then
+  CLASSPATH=${CLASSPATH}:$HADOOP_HOME
+fi
+for f in $HADOOP_HOME/hadoop-*-core.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+done
+
+# add libs to CLASSPATH
+for f in $HADOOP_HOME/lib/*.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+done
+
+if [ -d "$HADOOP_HOME/build/ivy/lib/Hadoop/common" ]; then
+for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/*.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+done
+fi
+
+for f in $HADOOP_HOME/lib/jsp-2.1/*.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+done
+
+for f in $HADOOP_HOME/hadoop-*-tools.jar; do
+  TOOL_PATH=${TOOL_PATH}:$f;
+done
+for f in $HADOOP_HOME/build/hadoop-*-tools.jar; do
+  TOOL_PATH=${TOOL_PATH}:$f;
+done
+
+# add user-specified CLASSPATH last
+if [ "$HADOOP_CLASSPATH" != "" ]; then
+  CLASSPATH=${HADOOP_CLASSPATH}:${CLASSPATH}
+fi
+
+# default log directory & file
+if [ "$HADOOP_LOG_DIR" = "" ]; then
+  HADOOP_LOG_DIR="$HADOOP_HOME/logs"
+fi
+if [ "$HADOOP_LOGFILE" = "" ]; then
+  HADOOP_LOGFILE='hadoop.log'
+fi
+
+# default policy file for service-level authorization
+if [ "$HADOOP_POLICYFILE" = "" ]; then
+  HADOOP_POLICYFILE="hadoop-policy.xml"
+fi
+
+# restore ordinary behaviour
+unset IFS
+
+# figure out which class to run
+if [ "$COMMAND" = "namenode" ] ; then
+  CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode'
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS"
+elif [ "$COMMAND" = "secondarynamenode" ] ; then
+  CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode'
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_SECONDARYNAMENODE_OPTS"
+elif [ "$COMMAND" = "datanode" ] ; then
+  CLASS='org.apache.hadoop.hdfs.server.datanode.DataNode'
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_DATANODE_OPTS"
+elif [ "$COMMAND" = "fs" ] ; then
+  CLASS=org.apache.hadoop.fs.FsShell
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "dfs" ] ; then
+  CLASS=org.apache.hadoop.fs.FsShell
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "dfsadmin" ] ; then
+  CLASS=org.apache.hadoop.hdfs.tools.DFSAdmin
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "mradmin" ] ; then
+  CLASS=org.apache.hadoop.mapred.tools.MRAdmin
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "fsck" ] ; then
+  CLASS=org.apache.hadoop.hdfs.tools.DFSck
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "balancer" ] ; then
+  CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS"
+elif [ "$COMMAND" = "jobtracker" ] ; then
+  CLASS=org.apache.hadoop.mapred.JobTracker
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_JOBTRACKER_OPTS"
+elif [ "$COMMAND" = "tasktracker" ] ; then
+  CLASS=org.apache.hadoop.mapred.TaskTracker
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_TASKTRACKER_OPTS"
+elif [ "$COMMAND" = "job" ] ; then
+  CLASS=org.apache.hadoop.mapred.JobClient
+elif [ "$COMMAND" = "queue" ] ; then
+  CLASS=org.apache.hadoop.mapred.JobQueueClient
+elif [ "$COMMAND" = "pipes" ] ; then
+  CLASS=org.apache.hadoop.mapred.pipes.Submitter
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "version" ] ; then
+  CLASS=org.apache.hadoop.util.VersionInfo
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "jar" ] ; then
+  CLASS=org.apache.hadoop.util.RunJar
+elif [ "$COMMAND" = "distcp" ] ; then
+  CLASS=org.apache.hadoop.tools.DistCp
+  CLASSPATH=${CLASSPATH}:${TOOL_PATH}
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "daemonlog" ] ; then
+  CLASS=org.apache.hadoop.log.LogLevel
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "archive" ] ; then
+  CLASS=org.apache.hadoop.tools.HadoopArchives
+  CLASSPATH=${CLASSPATH}:${TOOL_PATH}
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+elif [ "$COMMAND" = "sampler" ] ; then
+  CLASS=org.apache.hadoop.mapred.lib.InputSampler
+  HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
+else
+  CLASS=$COMMAND
+fi
+
+# cygwin path translation
+if $cygwin; then
+  CLASSPATH=`cygpath -p -w "$CLASSPATH"`
+  HADOOP_HOME=`cygpath -w "$HADOOP_HOME"`
+  HADOOP_LOG_DIR=`cygpath -w "$HADOOP_LOG_DIR"`
+  TOOL_PATH=`cygpath -p -w "$TOOL_PATH"`
+fi
+# setup 'java.library.path' for native-hadoop code if necessary
+JAVA_LIBRARY_PATH=''
+if [ -d "${HADOOP_HOME}/build/native" -o -d "${HADOOP_HOME}/lib/native" ]; then
+  JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} -Xmx32m org.apache.hadoop.util.PlatformName | sed -e "s/ /_/g"`
+  
+  if [ -d "$HADOOP_HOME/build/native" ]; then
+    JAVA_LIBRARY_PATH=${HADOOP_HOME}/build/native/${JAVA_PLATFORM}/lib
+  fi
+  
+  if [ -d "${HADOOP_HOME}/lib/native" ]; then
+    if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
+      JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${HADOOP_HOME}/lib/native/${JAVA_PLATFORM}
+    else
+      JAVA_LIBRARY_PATH=${HADOOP_HOME}/lib/native/${JAVA_PLATFORM}
+    fi
+  fi
+fi
+
+# cygwin path translation
+if $cygwin; then
+  JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
+fi
+
+HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR"
+HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.file=$HADOOP_LOGFILE"
+HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.home.dir=$HADOOP_HOME"
+HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING"
+HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.root.logger=${HADOOP_ROOT_LOGGER:-INFO,console}"
+if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
+  HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
+fi  
+HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.policy.file=$HADOOP_POLICYFILE"
+
+# run it
+#echo "exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@""
+exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@"
diff --git a/asterix-installer/src/main/resources/hadoop-0.20.2/bin/hadoop-config.sh b/asterix-installer/src/main/resources/hadoop-0.20.2/bin/hadoop-config.sh
new file mode 100755
index 0000000..1f9d52d
--- /dev/null
+++ b/asterix-installer/src/main/resources/hadoop-0.20.2/bin/hadoop-config.sh
@@ -0,0 +1,68 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# included in all the hadoop scripts with source command
+# should not be executable directly
+# also should not be passed any arguments, since we need original $*
+
+# resolve links - $0 may be a softlink
+
+this="$0"
+while [ -h "$this" ]; do
+  ls=`ls -ld "$this"`
+  link=`expr "$ls" : '.*-> \(.*\)$'`
+  if expr "$link" : '.*/.*' > /dev/null; then
+    this="$link"
+  else
+    this=`dirname "$this"`/"$link"
+  fi
+done
+
+# convert relative path to absolute path
+bin=`dirname "$this"`
+script=`basename "$this"`
+bin=`cd "$bin"; pwd`
+this="$bin/$script"
+
+# the root of the Hadoop installation
+export HADOOP_HOME=`dirname "$this"`/..
+
+#check to see if the conf dir is given as an optional argument
+if [ $# -gt 1 ]
+then
+    if [ "--config" = "$1" ]
+	  then
+	      shift
+	      confdir=$1
+	      shift
+	      HADOOP_CONF_DIR=$confdir
+    fi
+fi
+ 
+# Allow alternate conf dir location.
+HADOOP_CONF_DIR="${HADOOP_CONF_DIR:-$HADOOP_HOME/conf}"
+
+#check to see it is specified whether to use the slaves or the
+# masters file
+if [ $# -gt 1 ]
+then
+    if [ "--hosts" = "$1" ]
+    then
+        shift
+        slavesfile=$1
+        shift
+        export HADOOP_SLAVES="${HADOOP_CONF_DIR}/$slavesfile"
+    fi
+fi
diff --git a/asterix-installer/src/main/resources/hadoop-0.20.2/conf/hadoop-env.sh b/asterix-installer/src/main/resources/hadoop-0.20.2/conf/hadoop-env.sh
new file mode 100644
index 0000000..e9396a4
--- /dev/null
+++ b/asterix-installer/src/main/resources/hadoop-0.20.2/conf/hadoop-env.sh
@@ -0,0 +1,54 @@
+# Set Hadoop-specific environment variables here.
+
+# The only required environment variable is JAVA_HOME.  All others are
+# optional.  When running a distributed configuration it is best to
+# set JAVA_HOME in this file, so that it is correctly defined on
+# remote nodes.
+
+# The java implementation to use.  Required.
+# export JAVA_HOME=$JAVA_HOME
+
+# Extra Java CLASSPATH elements.  Optional.
+# export HADOOP_CLASSPATH=
+
+# The maximum amount of heap to use, in MB. Default is 1000.
+# export HADOOP_HEAPSIZE=2000
+
+# Extra Java runtime options.  Empty by default.
+# export HADOOP_OPTS=-server
+
+# Command specific options appended to HADOOP_OPTS when specified
+export HADOOP_NAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_NAMENODE_OPTS"
+export HADOOP_SECONDARYNAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_SECONDARYNAMENODE_OPTS"
+export HADOOP_DATANODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_DATANODE_OPTS"
+export HADOOP_BALANCER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_BALANCER_OPTS"
+export HADOOP_JOBTRACKER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_JOBTRACKER_OPTS"
+# export HADOOP_TASKTRACKER_OPTS=
+# The following applies to multiple commands (fs, dfs, fsck, distcp etc)
+# export HADOOP_CLIENT_OPTS
+
+# Extra ssh options.  Empty by default.
+# export HADOOP_SSH_OPTS="-o ConnectTimeout=1 -o SendEnv=HADOOP_CONF_DIR"
+
+# Where log files are stored.  $HADOOP_HOME/logs by default.
+# export HADOOP_LOG_DIR=${HADOOP_HOME}/logs
+
+# File naming remote slave hosts.  $HADOOP_HOME/conf/slaves by default.
+# export HADOOP_SLAVES=${HADOOP_HOME}/conf/slaves
+
+# host:path where hadoop code should be rsync'd from.  Unset by default.
+# export HADOOP_MASTER=master:/home/$USER/src/hadoop
+
+# Seconds to sleep between slave commands.  Unset by default.  This
+# can be useful in large clusters, where, e.g., slave rsyncs can
+# otherwise arrive faster than the master can service them.
+# export HADOOP_SLAVE_SLEEP=0.1
+
+# The directory where pid files are stored. /tmp by default.
+# export HADOOP_PID_DIR=/var/hadoop/pids
+
+# A string representing this instance of hadoop. $USER by default.
+# export HADOOP_IDENT_STRING=$USER
+
+# The scheduling priority for daemon processes.  See 'man nice'.
+# export HADOOP_NICENESS=10
diff --git a/asterix-installer/src/main/resources/schema/managix-conf.xsd b/asterix-installer/src/main/resources/schema/managix-conf.xsd
new file mode 100644
index 0000000..b53c089
--- /dev/null
+++ b/asterix-installer/src/main/resources/schema/managix-conf.xsd
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mg="managix" targetNamespace="managix" elementFormDefault="qualified">
+
+<!-- definition of simple types --> 
+<xs:element name="asterix_home" type="xs:string"/>
+<xs:element name="hyracks_home" type="xs:string"/>
+<xs:element name="hdfsurl" type="xs:string"/>
+<xs:element name="server" type="xs:string"/>
+<xs:element name="clientPort" type="xs:integer"/>
+<xs:element name="homeDir" type="xs:string"/>
+<xs:element name="version" type="xs:string"/>
+<xs:element name="url" type="xs:string"/>
+<xs:element name="backupDir" type="xs:string"/>
+
+<!-- definition of complex elements -->
+<xs:element name="hdfs">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="mg:version"/>
+      <xs:element ref="mg:url"/>
+      <xs:element ref="mg:backupDir"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="backup">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="mg:hdfs"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="zookeeper">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="mg:homeDir"/>
+      <xs:element ref="mg:clientPort"/>
+      <xs:element ref="mg:servers"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="servers">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="mg:server" maxOccurs="unbounded"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+<xs:element name="configuration">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element ref="mg:backup" minOccurs="0"/>
+      <xs:element ref="mg:asterix_home" minOccurs="0"/>
+      <xs:element ref="mg:hyracks_home" minOccurs="0"/>
+      <xs:element ref="mg:hdfsurl" minOccurs="0"/>
+      <xs:element ref="mg:zookeeper"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+</xs:schema>     
diff --git a/asterix-installer/src/main/resources/scripts/managix b/asterix-installer/src/main/resources/scripts/managix
new file mode 100755
index 0000000..d788873
--- /dev/null
+++ b/asterix-installer/src/main/resources/scripts/managix
@@ -0,0 +1,20 @@
+if [ -z $MANAGIX_HOME ] 
+ then
+   echo "MANAGIX_HOME is not defined"
+   exit 1
+fi
+
+VERSION=0.0.4-SNAPSHOT
+
+for jar in `ls $MANAGIX_HOME/lib/*.jar`
+  do 
+  if [ -z $MANAGIX_CLASSPATH ] 
+  then 
+    MANAGIX_CLASSPATH=$jar 
+  else
+    MANAGIX_CLASSPATH=$MANAGIX_CLASSPATH:$jar 
+  fi
+done
+
+MANAGIX_CLASSPATH=$MANAGIX_CLASSPATH:$MANAGIX_HOME/conf/log4j.properties
+java $JAVA_OPTS -Dlog4j.configuration=file:$MANAGIX_HOME/conf/log4j.properties -cp $MANAGIX_CLASSPATH edu.uci.ics.asterix.installer.driver.ManagixDriver $@
diff --git a/asterix-installer/src/main/resources/scripts/verify.sh b/asterix-installer/src/main/resources/scripts/verify.sh
new file mode 100755
index 0000000..fe1bb0c
--- /dev/null
+++ b/asterix-installer/src/main/resources/scripts/verify.sh
@@ -0,0 +1,21 @@
+INSTANCE_NAME=$1
+MASTER_NODE=$2
+shift 2
+numargs=$#
+for ((i=1 ; i <= numargs ; i=i+2))
+do
+ host=$1
+ nc_id=$2
+ INFO=$(ssh $host "ps -ef | grep nc_join | grep -v grep | grep -v ssh| grep $nc_id" | head -n 1 )
+ PARENT_ID=`echo  $INFO | cut -d " "  -f2`
+ PID_INFO=$(ssh $host "ps -ef |  grep hyracks | grep -v grep | grep -v nc_join |  grep $PARENT_ID") 
+ PID=`echo $PID_INFO | cut -d " " -f2`
+ echo "NC:$host:$nc_id:$PID"
+ shift 2
+done
+
+CC_PARENT_ID_INFO=$(ssh $MASTER_NODE "ps -ef  | grep hyracks | grep cc_start | grep -v ssh")
+CC_PARENT_ID=`echo $CC_PARENT_ID_INFO | tr -s " " | cut -d " " -f2` 
+CC_ID_INFO=$(ssh $MASTER_NODE "ps -ef | grep hyracks | grep $CC_PARENT_ID | grep -v bash")
+CC_ID=`echo $CC_ID_INFO |  tr -s " " | cut -d " " -f2`
+echo "CC:$MASTER_NODE:N/A:$CC_ID"
diff --git a/asterix-installer/src/main/resources/zookeeper/start_zk.sh b/asterix-installer/src/main/resources/zookeeper/start_zk.sh
new file mode 100755
index 0000000..c8154bf
--- /dev/null
+++ b/asterix-installer/src/main/resources/zookeeper/start_zk.sh
@@ -0,0 +1,8 @@
+ZK_HOME=$1
+ZK_ID=$2
+mkdir $ZK_HOME/data
+echo $2 > $ZK_HOME/data/myid
+CLASSPATH=$ZK_HOME/lib/zookeeper-3.4.4.jar:$ZK_HOME/lib/log4j-1.2.15.jar:$ZK_HOME/lib/slf4j-api-1.6.1.jar:$ZK_HOME/conf:$ZK_HOME/conf/log4j.properties
+ZK_CONF=$ZK_HOME/zk.cfg
+export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8400,server=y,suspend=n"
+java $JAVA_OPTS -Dlog4j.configuration="file:$ZK_HOME/conf/log4j.properties" -cp $CLASSPATH org.apache.zookeeper.server.quorum.QuorumPeerMain $ZK_CONF
diff --git a/asterix-installer/src/main/resources/zookeeper/zk.init b/asterix-installer/src/main/resources/zookeeper/zk.init
new file mode 100755
index 0000000..9b554b1
--- /dev/null
+++ b/asterix-installer/src/main/resources/zookeeper/zk.init
@@ -0,0 +1,13 @@
+ZK_HOME=$1
+shift 1
+cd $MANAGIX_HOME/.managix/zookeeper
+tar cf zk.pkg.tar *
+zk_server_id=1
+for zk_host in  $@
+do
+  ssh $zk_host "mkdir $ZK_HOME"
+  scp ./zk.pkg.tar $zk_host:$ZK_HOME/
+  ssh $zk_host "cd $ZK_HOME && tar xf $ZK_HOME/zk.pkg.tar && chmod +x $ZK_HOME/bin/start_zk.sh"
+  ssh $zk_host "$ZK_HOME/bin/start_zk.sh $ZK_HOME $zk_server_id" &
+  zk_server_id=`expr $zk_server_id + 1`	
+done
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/Asterix_ADM_Parser.md b/asterix-maven-plugins/lexer-generator-maven-plugin/Asterix_ADM_Parser.md
new file mode 100644
index 0000000..eeaffc9
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/Asterix_ADM_Parser.md
@@ -0,0 +1,53 @@
+The Asterix ADM Parser
+======================
+
+The ADM parser inside Asterix is composed by two different components:
+
+* **The Parser** AdmTupleParser, which converts the adm tokens in internal objects
+* **The Lexer**  AdmLexer, which scans the adm file and returns a list of adm tokens
+
+These two classes belong to the package:
+
+    edu.uci.ics.asterix.runtime.operators.file
+
+The Parser is loaded through a factory (*AdmSchemafullRecordParserFactory*) by
+
+    edu.uci.ics.asterix.external.dataset.adapter.FileSystemBasedAdapter extends AbstractDatasourceAdapter
+
+
+How to add a new datatype
+-------------------------
+The ADM format allows two different kinds of datatype:
+
+* primitive
+* with constructor
+
+A primitive datatype allows to write the actual value of the field without extra markup:
+
+    { name : "Diego", age : 23 }
+
+while the datatypes with constructor require to specify first the type of the value and then a string with the serialized value
+
+    { center : point3d("P2.1,3,8.5") }
+
+In order to add a new datatype the steps are:
+
+1.  Add the new token to the **Lexer**
+  * **if the datatype is primite** is necessary to create a TOKEN able to recognize **the format of the value**
+  * **if the datatype is with constructor** is necessary to create **only** a TOKEN able to recognize **the name of the constructor**
+
+2.  Change the **Parser** in order to convert correctly the new token in internal objects
+  * This will require to **add new cases to the switch-case statements** and the introduction of **a serializer/deserializer object** for that datatype.
+
+
+The Lexer
+----------
+To add new datatype or change the tokens definition you have to change ONLY the file adm.grammar located in 
+	asterix-runtime/src/main/resources/adm.grammar
+The lexer will be generated from that definition file during each maven building.
+
+The maven configuration in located in asterix-runtime/pom.xml
+
+
+> Author: Diego Giorgini - diegogiorgini@gmail.com   
+> 6 December 2012
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/README.md b/asterix-maven-plugins/lexer-generator-maven-plugin/README.md
new file mode 100644
index 0000000..b3632e6
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/README.md
@@ -0,0 +1,111 @@
+Lexer Generator
+===============
+
+This tool automate the creation of Hand-Coded-Like Lexers.   
+It was created to address the performance issues of other (more advanced) lexer generators like JavaCC that arise when you need to scan TB of data. In particular it is *~20x faster* than javacc and typically can parse the data from a normal harddisk at *more than 70MBs*.
+
+
+Maven Plugin (to put inside pom.xml)
+-------------------------------------
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.0.2</version>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>edu.uci.ics.asterix</groupId>
+                <artifactId>lexer-generator-maven-plugin</artifactId>
+                <version>0.1-SNAPSHOT</version>
+                <configuration>
+                    <grammarFile>src/main/java/edu/uci/ics/asterix/runtime/operators/file/adm/adm.grammar</grammarFile>
+                    <outputDir>${project.build.directory}/generated-sources</outputDir>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>generate-lexer</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>generate-lexer</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+
+Command line
+-------------
+    LexerGenerator\nusage: java LexerGenerator <configuration file>
+
+
+
+What means Hand-Coded-Like and why it is so fast
+------------------------------------------------
+The most of the Lexers use a Finite State Machine encoded in data structure called [State Transition Table](http://en.wikipedia.org/wiki/State_transition_table).   
+While elegant and practical this approach require some extra controls and operations to deal with the data structure at runtime. A different approach consists in encoding the State Machine as actual code, in this way all the operations done are limited to the minumum amount needed to parse our grammar.   
+A common problem with this kind of hard-hand-coded lexers is that is almost impossible to do manutency and changes, this is the reason of this Lexer Generator able to produce a Hand-Coded-Like lexer starting from a grammar specification.
+
+Another big difference with the most of the LexerGenerator (expecially the ones for Java) is that since it is optimized for performance we **don't return objects** and we **use the minimum possible of objects internally**.    
+This actually is the main reason of the ~20x when compared with javacc.
+
+
+Configuration File
+------------------
+Is a simple *key: value* configuration file plus the *specification of your grammar*.   
+The four configuration keys are listed below:
+
+    # LEXER GENERATOR configuration file
+    # ---------------------------------------
+    # Place *first* the generic configuration
+    # then list your grammar.
+
+    PACKAGE:          edu.uci.ics.asterix.admfast.parser
+    LEXER_NAME:       AdmLexer
+    OUTPUT_DIR:       output/
+
+
+Specify The Grammar
+-------------------
+Your grammar has to be listed in the configuration file after the *TOKENS:* keyword.
+
+    TOKENS:
+
+    BOOLEAN_LIT        = string(boolean)
+    COMMA              = char(\,)
+    COLON              = char(:)
+    STRING_LITERAL     = char("), anythingUntil(")
+    INT_LITERAL        = signOrNothing(), digitSequence()
+    INT8_LITERAL       = token(INT_LITERAL), string(i8)
+    @EXPONENT          = caseInsensitiveChar(e), signOrNothing(), digitSequence()
+    DOUBLE_LITERAL     = signOrNothing(), digitSequence(), char(.), digitSequence(), token(@EXPONENT)
+    DOUBLE_LITERAL     = signOrNothing(), digitSequence(), token(@EXPONENT)
+
+Each token is composed by a **name** and a sequence of **rules**.   
+Each rule is then written with the format: **constructor(parameter)**  
+the list of the rules available is coded inside *NodeChainFactory.java*
+
+You can write more than a sequence of rules just addind more another line and repeating the token name.
+
+You can reuse the rules of a token inside another one with the special rule: **token(** *TOKEN_NAME* **)**
+
+Lastly you can define *auxiliary* token definitions that will not be encoded in the final lexer (but that can be useful inside other token definitions) just **startig the token name with @**.
+
+**Attention:** please pay attention to not write rules that once merged int the state machine would lead to a *conflict between transaction* like a transaction for a generic digit and one for a the digit 0 from the same node. 
+
+The result: MyLexer
+-------------------
+The result of the execution of the LexerGenerator is the creation of the Lexer inside the directory *components**.
+The lexer is extremly easy and minimal and can be used likewise an Iterator:
+
+     MyLexer myLexer = new MyLexer(new FileReader(file)));
+     while((token = MyLexer.next()) != MyLexer.TOKEN_EOF){
+        System.out.println(MyLexer.tokenKindToString(token));
+     }
+
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/pom.xml b/asterix-maven-plugins/lexer-generator-maven-plugin/pom.xml
new file mode 100644
index 0000000..524727f
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/pom.xml
@@ -0,0 +1,36 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>edu.uci.ics.asterix</groupId>
+  <artifactId>lexer-generator-maven-plugin</artifactId>
+  <version>0.1</version>
+  <packaging>maven-plugin</packaging>
+  <name>lexer-generator-maven-plugin</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0.2</version>
+    </dependency>
+  </dependencies>    
+</project>
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerGenerator.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerGenerator.java
new file mode 100644
index 0000000..512f3d0
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerGenerator.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.Reader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.apache.maven.plugin.logging.Log;
+
+public class LexerGenerator {
+    private LinkedHashMap<String, Token> tokens = new LinkedHashMap<String, Token>();
+    private Log logger;
+
+    public LexerGenerator() {
+    }
+
+    public LexerGenerator(Log logger) {
+        this.logger = logger;
+    }
+
+    private void log(String info) {
+        if (logger == null) {
+            System.out.println(info);
+        } else {
+            logger.info(info);
+        }
+    }
+
+    public void addToken(String rule) throws Exception {
+        Token newToken;
+        if (rule.charAt(0) == '@') {
+            newToken = new TokenAux(rule, tokens);
+        } else {
+            newToken = new Token(rule, tokens);
+        }
+        Token existingToken = tokens.get(newToken.getName());
+        if (existingToken == null) {
+            tokens.put(newToken.getName(), newToken);
+        } else {
+            existingToken.merge(newToken);
+        }
+    }
+
+    public void generateLexer(HashMap<String, String> config) throws Exception {
+        LexerNode main = this.compile();
+        config.put("TOKENS_CONSTANTS", this.tokensConstants());
+        config.put("TOKENS_IMAGES", this.tokensImages());
+        config.put("LEXER_LOGIC", main.toJava());
+        config.put("LEXER_AUXFUNCTIONS", replaceParams(this.auxiliaryFunctions(main), config));
+        String[] files = { "/Lexer.java", "/LexerException.java" };
+        String outputDir = config.get("OUTPUT_DIR");
+        (new File(outputDir)).mkdirs();
+        for (String file : files) {
+            String input = readFile(LexerGenerator.class.getResourceAsStream(file));
+            String fileOut = file.replace("Lexer", config.get("LEXER_NAME"));
+            String output = replaceParams(input, config);
+            log("Generating: " + file + "\t>>\t" + fileOut);
+            FileWriter out = new FileWriter((new File(outputDir, fileOut)).toString());
+            out.write(output);
+            out.close();
+            log(" [done]\n");
+        }
+    }
+
+    public String printParsedGrammar() {
+        StringBuilder result = new StringBuilder();
+        for (Token token : tokens.values()) {
+            result.append(token.toString()).append("\n");
+        }
+        return result.toString();
+    }
+
+    private LexerNode compile() throws Exception {
+        LexerNode main = new LexerNode();
+        for (Token token : tokens.values()) {
+            if (token instanceof TokenAux)
+                continue;
+            main.merge(token.getNode());
+        }
+        return main;
+    }
+
+    private String tokensImages() {
+        StringBuilder result = new StringBuilder();
+        Set<String> uniqueTokens = tokens.keySet();
+        for (String token : uniqueTokens) {
+            result.append(", \"<").append(token).append(">\" ");
+        }
+        return result.toString();
+    }
+
+    private String tokensConstants() {
+        StringBuilder result = new StringBuilder();
+        Set<String> uniqueTokens = tokens.keySet();
+        int i = 2;
+        for (String token : uniqueTokens) {
+            result.append(", TOKEN_").append(token).append("=").append(i).append(" ");
+            i++;
+        }
+        return result.toString();
+    }
+
+    private String auxiliaryFunctions(LexerNode main) {
+        StringBuilder result = new StringBuilder();
+        Set<String> functions = main.neededAuxFunctions();
+        for (String token : functions) {
+            result.append("private int parse_" + token
+                    + "(char currentChar) throws IOException, [LEXER_NAME]Exception{\n");
+            result.append(tokens.get(token).getNode().toJavaAuxFunction());
+            result.append("\n}\n\n");
+        }
+        return result.toString();
+    }
+
+    private static String readFile(Reader input) throws FileNotFoundException, IOException {
+        StringBuffer fileData = new StringBuffer(1000);
+        BufferedReader reader = new BufferedReader(input);
+        char[] buf = new char[1024];
+        int numRead = 0;
+        while ((numRead = reader.read(buf)) != -1) {
+            String readData = String.valueOf(buf, 0, numRead);
+            fileData.append(readData);
+            buf = new char[1024];
+        }
+        reader.close();
+        return fileData.toString();
+    }
+
+    private static String readFile(InputStream input) throws FileNotFoundException, IOException {
+        if (input == null) {
+            throw new FileNotFoundException();
+        }
+        return readFile(new InputStreamReader(input));
+    }
+
+    private static String readFile(String fileName) throws FileNotFoundException, IOException {
+        return readFile(new FileReader(fileName));
+    }
+
+    private static String replaceParams(String input, HashMap<String, String> config) {
+        for (Entry<String, String> param : config.entrySet()) {
+            String key = "\\[" + param.getKey() + "\\]";
+            String value = param.getValue();
+            input = input.replaceAll(key, value);
+        }
+        return input;
+    }
+
+    public static void main(String args[]) throws Exception {
+        if (args.length == 0 || args[0] == "--help" || args[0] == "-h") {
+            System.out.println("LexerGenerator\nusage: java LexerGenerator <configuration file>");
+            return;
+        }
+
+        LexerGenerator lexer = new LexerGenerator();
+        HashMap<String, String> config = new HashMap<String, String>();
+
+        System.out.println("Config file:\t" + args[0]);
+        String input = readFile(args[0]);
+        boolean tokens = false;
+        for (String line : input.split("\r?\n")) {
+            line = line.trim();
+            if (line.length() == 0 || line.charAt(0) == '#')
+                continue;
+            if (tokens == false && !line.equals("TOKENS:")) {
+                config.put(line.split("\\s*:\\s*")[0], line.split("\\s*:\\s*")[1]);
+            } else if (line.equals("TOKENS:")) {
+                tokens = true;
+            } else {
+                lexer.addToken(line);
+            }
+        }
+
+        String parsedGrammar = lexer.printParsedGrammar();
+        lexer.generateLexer(config);
+        System.out.println("\nGenerated grammar:");
+        System.out.println(parsedGrammar);
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerGeneratorMojo.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerGeneratorMojo.java
new file mode 100644
index 0000000..11ee1d5
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerGeneratorMojo.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator;
+
+import edu.uci.ics.asterix.lexergenerator.LexerGenerator;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.io.File;
+
+/**
+ * @goal generate-lexer
+ * @phase generate-sources
+ * @requiresDependencyResolution compile
+ */
+public class LexerGeneratorMojo extends AbstractMojo {
+    /**
+     * parameter injected from pom.xml
+     * 
+     * @parameter
+     * @required
+     */
+    private File grammarFile;
+
+    /**
+     * parameter injected from pom.xml
+     * 
+     * @parameter
+     * @required
+     */
+    private File outputDir;
+
+    public void execute() throws MojoExecutionException {
+        LexerGenerator lexer = new LexerGenerator(getLog());
+        HashMap<String, String> config = new HashMap<String, String>();
+        getLog().info("--- Lexer Generator Maven Plugin - started with grammarFile: " + grammarFile.toString());
+        try {
+            String input = readFile(grammarFile);
+            config.put("OUTPUT_DIR", outputDir.toString());
+            boolean tokens = false;
+            for (String line : input.split("\r?\n")) {
+                line = line.trim();
+                if (line.length() == 0 || line.charAt(0) == '#')
+                    continue;
+                if (tokens == false && !line.equals("TOKENS:")) {
+                    config.put(line.split("\\s*:\\s*")[0], line.split("\\s*:\\s*")[1]);
+                } else if (line.equals("TOKENS:")) {
+                    tokens = true;
+                } else {
+                    lexer.addToken(line);
+                }
+            }
+            lexer.generateLexer(config);
+        } catch (Throwable e) {
+            throw new MojoExecutionException("Error while generating lexer", e);
+        }
+        String parsedGrammar = lexer.printParsedGrammar();
+        getLog().info("--- Generated grammar:\n" + parsedGrammar);
+    }
+
+    private String readFile(File file) throws FileNotFoundException, IOException {
+        StringBuffer fileData = new StringBuffer(1000);
+        BufferedReader reader = new BufferedReader(new FileReader(file));
+        char[] buf = new char[1024];
+        int numRead = 0;
+        while ((numRead = reader.read(buf)) != -1) {
+            String readData = String.valueOf(buf, 0, numRead);
+            fileData.append(readData);
+            buf = new char[1024];
+        }
+        reader.close();
+        return fileData.toString();
+    }
+
+}
\ No newline at end of file
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerNode.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerNode.java
new file mode 100644
index 0000000..7b8d059
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/LexerNode.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import edu.uci.ics.asterix.lexergenerator.rules.*;
+
+public class LexerNode {
+    private static String TOKEN_PREFIX = "TOKEN_";
+    private LinkedHashMap<Rule, LexerNode> actions = new LinkedHashMap<Rule, LexerNode>();
+    private String finalTokenName;
+    private Set<String> ongoingParsing = new HashSet<String>();
+
+    public LexerNode clone() {
+        LexerNode node = new LexerNode();
+        node.finalTokenName = this.finalTokenName;
+        for (Map.Entry<Rule, LexerNode> entry : this.actions.entrySet()) {
+            node.actions.put(entry.getKey().clone(), entry.getValue().clone());
+        }
+        for (String ongoing : this.ongoingParsing) {
+            node.ongoingParsing.add(ongoing);
+        }
+        return node;
+    }
+
+    public void add(Rule newRule) {
+        if (actions.get(newRule) == null) {
+            actions.put(newRule, new LexerNode());
+        }
+    }
+
+    public void append(Rule newRule) {
+        if (actions.size() == 0) {
+            add(newRule);
+        } else {
+            for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+                action.getValue().append(newRule);
+            }
+            if (actions.containsKey(new RuleEpsilon())) {
+                actions.remove(new RuleEpsilon());
+                add(newRule);
+            }
+        }
+    }
+
+    public void merge(LexerNode newNode) throws Exception {
+        for (Map.Entry<Rule, LexerNode> action : newNode.actions.entrySet()) {
+            if (this.actions.get(action.getKey()) == null) {
+                this.actions.put(action.getKey(), action.getValue());
+            } else {
+                this.actions.get(action.getKey()).merge(action.getValue());
+            }
+        }
+        if (newNode.finalTokenName != null) {
+            if (this.finalTokenName == null) {
+                this.finalTokenName = newNode.finalTokenName;
+            } else {
+                throw new Exception("Rule conflict between: " + this.finalTokenName + " and " + newNode.finalTokenName);
+            }
+        }
+        for (String ongoing : newNode.ongoingParsing) {
+            this.ongoingParsing.add(ongoing);
+        }
+    }
+
+    public void append(LexerNode node) throws Exception {
+        for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+            if (action.getKey() instanceof RuleEpsilon)
+                continue;
+            action.getValue().append(node);
+        }
+        if (actions.containsKey(new RuleEpsilon())) {
+            actions.remove(new RuleEpsilon());
+            merge(node.clone());
+        }
+        if (actions.size() == 0 || finalTokenName != null) {
+            finalTokenName = null;
+            merge(node.clone());
+        }
+    }
+
+    public void appendTokenName(String name) {
+        if (actions.size() == 0) {
+            this.finalTokenName = name;
+        } else {
+            ongoingParsing.add(TOKEN_PREFIX + name);
+            for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+                action.getValue().appendTokenName(name);
+            }
+        }
+    }
+
+    public LexerNode removeTokensName() {
+        this.finalTokenName = null;
+        this.ongoingParsing.clear();
+        for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+            action.getValue().removeTokensName();
+        }
+        return this;
+    }
+
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        if (finalTokenName != null)
+            result.append("! ");
+        if (actions.size() == 1)
+            result.append(actions.keySet().toArray()[0].toString() + actions.values().toArray()[0].toString());
+        if (actions.size() > 1) {
+            result.append(" ( ");
+            for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+                if (result.length() != 3) {
+                    result.append(" || ");
+                }
+                result.append(action.getKey().toString());
+                result.append(action.getValue().toString());
+            }
+            result.append(" ) ");
+        }
+        return result.toString();
+    }
+
+    public String toJava() {
+        StringBuffer result = new StringBuffer();
+        if (numberOfRuleChar() > 2) {
+            result.append(toJavaSingleCharRules());
+            result.append(toJavaComplexRules(false));
+        } else {
+            result.append(toJavaComplexRules(true));
+        }
+        if (this.finalTokenName != null) {
+            result.append("return " + TOKEN_PREFIX + finalTokenName + ";\n");
+        } else if (ongoingParsing != null) {
+            String ongoingParsingArgs = collectionJoin(ongoingParsing, ',');
+            result.append("return parseError(" + ongoingParsingArgs + ");\n");
+        }
+        return result.toString();
+    }
+
+    private int numberOfRuleChar() {
+        int singleCharRules = 0;
+        for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+            if (action.getKey() instanceof RuleChar)
+                singleCharRules++;
+        }
+        return singleCharRules;
+    }
+
+    private String toJavaSingleCharRules() {
+        StringBuffer result = new StringBuffer();
+        result.append("switch(currentChar){\n");
+        for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+            if (action.getKey() instanceof RuleChar) {
+                RuleChar rule = (RuleChar) action.getKey();
+                result.append("case '" + rule.expectedChar() + "':\n");
+                result.append(rule.javaAction()).append("\n");
+                result.append(action.getValue().toJava());
+            }
+        }
+        result.append("}\n");
+        return result.toString();
+    }
+
+    private String toJavaComplexRules(boolean all) {
+        StringBuffer result = new StringBuffer();
+        for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+            if (!all && action.getKey() instanceof RuleChar)
+                continue;
+            if (action.getKey() instanceof RuleEpsilon)
+                continue;
+            String act = action.getKey().javaAction();
+            if (act.length() > 0) {
+                act = "\n" + act;
+            }
+            result.append(action.getKey().javaMatch(act + "\n" + action.getValue().toJava()));
+        }
+        return result.toString();
+    }
+
+    public void expandFirstAction(LinkedHashMap<String, Token> tokens) throws Exception {
+        for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+            Rule first = action.getKey();
+            if (first instanceof RulePartial) {
+                if (tokens.get(((RulePartial) first).getPartial()) == null) {
+                    throw new Exception("Cannot find a token used as part of another definition, missing token: "
+                            + ((RulePartial) first).getPartial());
+                }
+                actions.remove(first);
+                LexerNode node = tokens.get(((RulePartial) first).getPartial()).getNode().clone();
+                merge(node);
+            }
+        }
+    }
+
+    public Set<String> neededAuxFunctions() {
+        HashSet<String> partials = new HashSet<String>();
+        for (Map.Entry<Rule, LexerNode> action : actions.entrySet()) {
+            Rule rule = action.getKey();
+            if (rule instanceof RulePartial) {
+                partials.add(((RulePartial) rule).getPartial());
+            }
+            partials.addAll(action.getValue().neededAuxFunctions());
+        }
+        return partials;
+    }
+
+    public String toJavaAuxFunction() {
+        String oldFinalTokenName = finalTokenName;
+        if (oldFinalTokenName == null)
+            finalTokenName = "AUX_NOT_FOUND";
+        String result = toJava();
+        finalTokenName = oldFinalTokenName;
+        return result;
+    }
+
+    private String collectionJoin(Collection<String> collection, char c) {
+        StringBuilder ongoingParsingArgs = new StringBuilder();
+        for (String token : collection) {
+            ongoingParsingArgs.append(token);
+            ongoingParsingArgs.append(c);
+        }
+        if (ongoingParsing.size() > 0) {
+            ongoingParsingArgs.deleteCharAt(ongoingParsingArgs.length() - 1);
+        }
+        return ongoingParsingArgs.toString();
+    }
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/NodeChainFactory.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/NodeChainFactory.java
new file mode 100644
index 0000000..941f822
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/NodeChainFactory.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator;
+
+import java.util.HashMap;
+
+import edu.uci.ics.asterix.lexergenerator.rulegenerators.*;
+
+public class NodeChainFactory {
+    static private HashMap<String, RuleGenerator> ruleGenerators = new HashMap<String, RuleGenerator>();
+
+    static {
+        ruleGenerators.put("char", new RuleGeneratorChar());
+        ruleGenerators.put("string", new RuleGeneratorString());
+        ruleGenerators.put("anythingUntil", new RuleGeneratorAnythingUntil());
+        ruleGenerators.put("signOrNothing", new RuleGeneratorSignOrNothing());
+        ruleGenerators.put("sign", new RuleGeneratorSign());
+        ruleGenerators.put("digitSequence", new RuleGeneratorDigitSequence());
+        ruleGenerators.put("caseInsensitiveChar", new RuleGeneratorCaseInsensitiveChar());
+        ruleGenerators.put("charOrNothing", new RuleGeneratorCharOrNothing());
+        ruleGenerators.put("token", new RuleGeneratorToken());
+        ruleGenerators.put("nothing", new RuleGeneratorNothing());
+    }
+
+    public static LexerNode create(String generator, String constructor) throws Exception {
+        constructor = constructor.replace("@", "aux_");
+        if (ruleGenerators.get(generator) == null)
+            throw new Exception("Rule Generator not found for '" + generator + "'");
+        return ruleGenerators.get(generator).generate(constructor);
+    }
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/Token.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/Token.java
new file mode 100644
index 0000000..bb122c2
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/Token.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator;
+
+import java.util.LinkedHashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Token {
+    private String userDescription;
+    private String name;
+    private LexerNode node;
+
+    public Token(String str, LinkedHashMap<String, Token> tokens) throws Exception {
+        userDescription = str;
+        node = new LexerNode();
+        parse(userDescription, tokens);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public LexerNode getNode() {
+        return node;
+    }
+
+    public String toString() {
+        return this.name + " => " + getNode().toString();
+    }
+
+    public void merge(Token newToken) throws Exception {
+        node.merge(newToken.getNode());
+    }
+
+    private void parse(String str, LinkedHashMap<String, Token> tokens) throws Exception {
+        Pattern p = Pattern.compile("^(@?\\w+)\\s*=\\s*(.+)");
+        Matcher m = p.matcher(str);
+        if (!m.find())
+            throw new Exception("Token definition not correct: " + str);
+        this.name = m.group(1).replaceAll("@", "aux_");
+        String[] textRules = m.group(2).split("(?<!\\\\),\\s*");
+        for (String textRule : textRules) {
+            Pattern pRule = Pattern.compile("^(\\w+)(\\((.*)\\))?");
+            Matcher mRule = pRule.matcher(textRule);
+            mRule.find();
+            String generator = mRule.group(1);
+            String constructor = mRule.group(3);
+            if (constructor == null)
+                throw new Exception("Error in rule format: " + "\n " + str + " = " + generator + " : " + constructor);
+            constructor = constructor.replace("\\", "");
+            node.append(NodeChainFactory.create(generator, constructor));
+            node.expandFirstAction(tokens);
+        }
+        node.appendTokenName(name);
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/TokenAux.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/TokenAux.java
new file mode 100644
index 0000000..a9c7ffc
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/TokenAux.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator;
+
+import java.util.LinkedHashMap;
+
+public class TokenAux extends Token {
+
+    public TokenAux(String str, LinkedHashMap<String, Token> tokens) throws Exception {
+        super(str, tokens);
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGenerator.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGenerator.java
new file mode 100644
index 0000000..3733746
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGenerator.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+
+public interface RuleGenerator {
+    public LexerNode generate(String input) throws Exception;
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorAnythingUntil.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorAnythingUntil.java
new file mode 100644
index 0000000..b14eb3e
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorAnythingUntil.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleAnythingUntil;
+
+public class RuleGeneratorAnythingUntil implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode result = new LexerNode();
+        if (input == null || input.length() != 1)
+            throw new Exception("Wrong rule format for generator anythingExcept: " + input);
+        result.append(new RuleAnythingUntil(input.charAt(0)));
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorCaseInsensitiveChar.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorCaseInsensitiveChar.java
new file mode 100644
index 0000000..b789f59
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorCaseInsensitiveChar.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleChar;
+
+public class RuleGeneratorCaseInsensitiveChar implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode result = new LexerNode();
+        if (input == null || input.length() != 1)
+            throw new Exception("Wrong rule format for generator char: " + input);
+        char cl = Character.toLowerCase(input.charAt(0));
+        char cu = Character.toUpperCase(cl);
+        result.add(new RuleChar(cl));
+        result.add(new RuleChar(cu));
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorChar.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorChar.java
new file mode 100644
index 0000000..0b830e6
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorChar.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleChar;
+
+public class RuleGeneratorChar implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode result = new LexerNode();
+        if (input == null || input.length() != 1)
+            throw new Exception("Wrong rule format for generator char: " + input);
+        result.append(new RuleChar(input.charAt(0)));
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorCharOrNothing.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorCharOrNothing.java
new file mode 100644
index 0000000..d01ff7d
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorCharOrNothing.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleChar;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleEpsilon;
+
+public class RuleGeneratorCharOrNothing implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode result = new LexerNode();
+        if (input == null || input.length() != 1)
+            throw new Exception("Wrong rule format for generator charOrNothing: " + input);
+        result.add(new RuleChar(input.charAt(0)));
+        result.add(new RuleEpsilon());
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorDigitSequence.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorDigitSequence.java
new file mode 100644
index 0000000..d067ee7
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorDigitSequence.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleDigitSequence;
+
+public class RuleGeneratorDigitSequence implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode result = new LexerNode();
+        result.append(new RuleDigitSequence());
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorNothing.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorNothing.java
new file mode 100644
index 0000000..fec06a1
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorNothing.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleEpsilon;
+
+public class RuleGeneratorNothing implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode node = new LexerNode();
+        node.add(new RuleEpsilon());
+        return node;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorSign.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorSign.java
new file mode 100644
index 0000000..0160f09
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorSign.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleChar;
+
+public class RuleGeneratorSign implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode result = new LexerNode();
+        result.add(new RuleChar('+'));
+        result.add(new RuleChar('-'));
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorSignOrNothing.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorSignOrNothing.java
new file mode 100644
index 0000000..7c4297d
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorSignOrNothing.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleChar;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleEpsilon;
+
+public class RuleGeneratorSignOrNothing implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        LexerNode result = new LexerNode();
+        result.add(new RuleChar('+'));
+        result.add(new RuleChar('-'));
+        result.add(new RuleEpsilon());
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorString.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorString.java
new file mode 100644
index 0000000..eb0471b
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorString.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleChar;
+
+public class RuleGeneratorString implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) {
+        LexerNode result = new LexerNode();
+        if (input == null)
+            return result;
+        for (int i = 0; i < input.length(); i++) {
+            result.append(new RuleChar(input.charAt(i)));
+        }
+        return result;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorToken.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorToken.java
new file mode 100644
index 0000000..b4c23d8
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rulegenerators/RuleGeneratorToken.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rulegenerators;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RulePartial;
+
+public class RuleGeneratorToken implements RuleGenerator {
+
+    @Override
+    public LexerNode generate(String input) throws Exception {
+        if (input == null || input.length() == 0)
+            throw new Exception("Wrong rule format for generator token : " + input);
+        LexerNode node = new LexerNode();
+        node.add(new RulePartial(input));
+        return node;
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/Rule.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/Rule.java
new file mode 100644
index 0000000..01cd1d5
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/Rule.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rules;
+
+public interface Rule {
+    public int hashCode();
+
+    public boolean equals(Object o);
+
+    public String toString();
+
+    public String javaAction();
+
+    public String javaMatch(String action);
+
+    public Rule clone();
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleAnythingUntil.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleAnythingUntil.java
new file mode 100644
index 0000000..8d45835
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleAnythingUntil.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rules;
+
+public class RuleAnythingUntil implements Rule {
+
+    private char expected;
+
+    public RuleAnythingUntil clone() {
+        return new RuleAnythingUntil(expected);
+    }
+
+    public RuleAnythingUntil(char expected) {
+        this.expected = expected;
+    }
+
+    @Override
+    public String toString() {
+        return " .* " + String.valueOf(expected);
+    }
+
+    @Override
+    public int hashCode() {
+        return 10 * (int) expected;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null)
+            return false;
+        if (o instanceof RuleAnythingUntil) {
+            if (((RuleAnythingUntil) o).expected == this.expected) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String javaAction() {
+        return "currentChar = readNextChar();";
+    }
+
+    @Override
+    public String javaMatch(String action) {
+        StringBuilder result = new StringBuilder();
+        result.append("boolean escaped = false;");
+        result.append("while (currentChar!='").append(expected).append("' || escaped)");
+        result.append("{\nif(!escaped && currentChar=='\\\\\\\\'){escaped=true;}\nelse {escaped=false;}\ncurrentChar = readNextChar();\n}");
+        result.append("\nif (currentChar=='").append(expected).append("'){");
+        result.append(action);
+        result.append("}\n");
+        return result.toString();
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleChar.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleChar.java
new file mode 100644
index 0000000..0e53374
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleChar.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rules;
+
+public class RuleChar implements Rule {
+
+    private char expected;
+
+    public RuleChar clone() {
+        return new RuleChar(expected);
+    }
+
+    public RuleChar(char expected) {
+        this.expected = expected;
+    }
+
+    @Override
+    public String toString() {
+        return String.valueOf(expected);
+    }
+
+    public char expectedChar() {
+        return expected;
+    }
+
+    @Override
+    public int hashCode() {
+        return (int) expected;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null)
+            return false;
+        if (o instanceof RuleChar) {
+            if (((RuleChar) o).expected == this.expected) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String javaAction() {
+        return "currentChar = readNextChar();";
+    }
+
+    @Override
+    public String javaMatch(String action) {
+        StringBuilder result = new StringBuilder();
+        result.append("if (currentChar=='");
+        result.append(expected);
+        result.append("'){");
+        result.append(action);
+        result.append("}");
+        return result.toString();
+    }
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleDigitSequence.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleDigitSequence.java
new file mode 100644
index 0000000..13381e0
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleDigitSequence.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rules;
+
+public class RuleDigitSequence implements Rule {
+
+    public RuleDigitSequence clone() {
+        return new RuleDigitSequence();
+    }
+
+    @Override
+    public String toString() {
+        return " [0-9]+ ";
+    }
+
+    @Override
+    public int hashCode() {
+        return 1;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null)
+            return false;
+        if (o instanceof RuleDigitSequence) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public String javaAction() {
+        return "";
+    }
+
+    @Override
+    public String javaMatch(String action) {
+        StringBuilder result = new StringBuilder();
+        result.append("if(currentChar >= '0' && currentChar<='9'){" + "\ncurrentChar = readNextChar();"
+                + "\nwhile(currentChar >= '0' && currentChar<='9'){" + "\ncurrentChar = readNextChar();" + "\n}\n");
+        result.append(action);
+        result.append("\n}");
+        return result.toString();
+    }
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleEpsilon.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleEpsilon.java
new file mode 100644
index 0000000..41b7535
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RuleEpsilon.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rules;
+
+public class RuleEpsilon implements Rule {
+
+    public RuleEpsilon clone() {
+        return new RuleEpsilon();
+    }
+
+    @Override
+    public String toString() {
+        return "?";
+    }
+
+    @Override
+    public int hashCode() {
+        return 0;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null)
+            return false;
+        if (o instanceof RuleEpsilon) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public String javaAction() {
+        return "";
+    }
+
+    @Override
+    public String javaMatch(String action) {
+        StringBuilder result = new StringBuilder();
+        result.append("{").append(action).append("}");
+        return result.toString();
+    }
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RulePartial.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RulePartial.java
new file mode 100644
index 0000000..89caf4f
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/java/edu/uci/ics/asterix/lexergenerator/rules/RulePartial.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package edu.uci.ics.asterix.lexergenerator.rules;
+
+public class RulePartial implements Rule {
+
+    private String partialName;
+
+    public RulePartial clone() {
+        return new RulePartial(partialName);
+    }
+
+    public RulePartial(String expected) {
+        this.partialName = expected;
+    }
+
+    public String getPartial() {
+        return this.partialName;
+    }
+
+    @Override
+    public String toString() {
+        return partialName;
+    }
+
+    @Override
+    public int hashCode() {
+        return (int) partialName.charAt(1);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null)
+            return false;
+        if (o instanceof RulePartial) {
+            if (((RulePartial) o).partialName.equals(this.partialName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String javaAction() {
+        return "";
+    }
+
+    @Override
+    public String javaMatch(String action) {
+        StringBuilder result = new StringBuilder();
+        result.append("if (parse_" + partialName + "(currentChar)==TOKEN_" + partialName + "){");
+        result.append(action);
+        result.append("}");
+        return result.toString();
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
new file mode 100644
index 0000000..8cee79d
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
@@ -0,0 +1,219 @@
+package [PACKAGE]; 
+
+import java.io.IOException;
+import [PACKAGE].[LEXER_NAME]Exception;
+
+public class [LEXER_NAME] {
+
+    public static final int
+        TOKEN_EOF = 0, TOKEN_AUX_NOT_FOUND = 1 [TOKENS_CONSTANTS];
+
+    // Human representation of tokens. Useful for debug.
+    // Is possible to convert a TOKEN_CONSTANT in its image through
+    // [LEXER_NAME].tokenKindToString(TOKEN_CONSTANT); 
+    private static final String[] tokenImage = {
+            "<EOF>", "<AUX_NOT_FOUND>" [TOKENS_IMAGES]
+          };
+    
+    private static final char EOF_CHAR = 4;
+    protected java.io.Reader inputStream;
+    protected int column;
+    protected int line;
+    protected boolean prevCharIsCR;
+    protected boolean prevCharIsLF;
+    protected char[] buffer;
+    protected int bufsize;
+    protected int bufpos;
+    protected int tokenBegin;
+    protected int endOf_USED_Buffer;
+    protected int endOf_UNUSED_Buffer;
+    protected int maxUnusedBufferSize;
+
+// ================================================================================
+//  Auxiliary functions. Can parse the tokens used in the grammar as partial/auxiliary
+// ================================================================================
+
+    [LEXER_AUXFUNCTIONS]
+
+// ================================================================================
+//  Main method. Return a TOKEN_CONSTANT
+// ================================================================================            
+            
+    public int next() throws [LEXER_NAME]Exception, IOException{
+        char currentChar = buffer[bufpos];
+        while (currentChar == ' ' || currentChar=='\t' || currentChar == '\n' || currentChar=='\r')
+            currentChar = readNextChar(); 
+        tokenBegin = bufpos;
+        if (currentChar==EOF_CHAR) return TOKEN_EOF;
+
+        [LEXER_LOGIC]
+    }
+
+// ================================================================================
+//  Public interface
+// ================================================================================
+    
+    public [LEXER_NAME](java.io.Reader stream) throws IOException{
+        reInit(stream);
+    }
+
+    public void reInit(java.io.Reader stream) throws IOException{
+        done();
+        inputStream    = stream;
+        bufsize        = 4096;
+        line           = 1;
+        column         = 0;
+        bufpos         = -1;
+        endOf_UNUSED_Buffer = bufsize;
+        endOf_USED_Buffer = 0;
+        prevCharIsCR   = false;
+        prevCharIsLF   = false;
+        buffer         = new char[bufsize];
+        tokenBegin     = -1;
+        maxUnusedBufferSize = 4096/2;
+        readNextChar();
+    }
+
+    public String getLastTokenImage() {
+        if (bufpos >= tokenBegin)
+            return new String(buffer, tokenBegin, bufpos - tokenBegin);
+          else
+            return new String(buffer, tokenBegin, bufsize - tokenBegin) +
+                                  new String(buffer, 0, bufpos);
+    }
+    
+    public static String tokenKindToString(int token) {
+        return tokenImage[token]; 
+    }
+
+    public void done(){
+        buffer = null;
+    }
+
+// ================================================================================
+//  Parse error management
+// ================================================================================    
+    
+    protected int parseError(String reason) throws [LEXER_NAME]Exception {
+        StringBuilder message = new StringBuilder();
+        message.append(reason).append("\n");
+        message.append("Line: ").append(line).append("\n");
+        message.append("Row: ").append(column).append("\n");
+        throw new [LEXER_NAME]Exception(message.toString());
+    }
+
+    protected int parseError(int ... tokens) throws [LEXER_NAME]Exception {
+        StringBuilder message = new StringBuilder();
+        message.append("Error while parsing. ");
+        message.append(" Line: ").append(line);
+        message.append(" Row: ").append(column);
+        message.append(" Expecting:");
+        for (int tokenId : tokens){
+            message.append(" ").append([LEXER_NAME].tokenKindToString(tokenId));
+        }
+        throw new [LEXER_NAME]Exception(message.toString());
+    }
+    
+    protected void updateLineColumn(char c){
+        column++;
+    
+        if (prevCharIsLF)
+        {
+            prevCharIsLF = false;
+            line += (column = 1);
+        }
+        else if (prevCharIsCR)
+        {
+            prevCharIsCR = false;
+            if (c == '\n')
+            {
+                prevCharIsLF = true;
+            }
+            else
+            {
+                line += (column = 1);
+            }
+        }
+        
+        if (c=='\r') {
+            prevCharIsCR = true;
+        } else if(c == '\n') {
+            prevCharIsLF = true;
+        }
+    }
+    
+// ================================================================================
+//  Read data, buffer management. It uses a circular (and expandable) buffer
+// ================================================================================    
+
+    protected char readNextChar() throws IOException {
+        if (++bufpos >= endOf_USED_Buffer)
+            fillBuff();
+        char c = buffer[bufpos];
+        updateLineColumn(c);
+        return c;
+    }
+
+    protected boolean fillBuff() throws IOException {
+        if (endOf_UNUSED_Buffer == endOf_USED_Buffer) // If no more unused buffer space 
+        {
+          if (endOf_UNUSED_Buffer == bufsize)         // -- If the previous unused space was
+          {                                           // -- at the end of the buffer
+            if (tokenBegin > maxUnusedBufferSize)     // -- -- If the first N bytes before
+            {                                         //       the current token are enough
+              bufpos = endOf_USED_Buffer = 0;         // -- -- -- setup buffer to use that fragment 
+              endOf_UNUSED_Buffer = tokenBegin;
+            }
+            else if (tokenBegin < 0)                  // -- -- If no token yet
+              bufpos = endOf_USED_Buffer = 0;         // -- -- -- reuse the whole buffer
+            else
+              ExpandBuff(false);                      // -- -- Otherwise expand buffer after its end
+          }
+          else if (endOf_UNUSED_Buffer > tokenBegin)  // If the endOf_UNUSED_Buffer is after the token
+            endOf_UNUSED_Buffer = bufsize;            // -- set endOf_UNUSED_Buffer to the end of the buffer
+          else if ((tokenBegin - endOf_UNUSED_Buffer) < maxUnusedBufferSize)
+          {                                           // If between endOf_UNUSED_Buffer and the token
+            ExpandBuff(true);                         // there is NOT enough space expand the buffer                          
+          }                                           // reorganizing it
+          else 
+            endOf_UNUSED_Buffer = tokenBegin;         // Otherwise there is enough space at the start
+        }                                             // so we set the buffer to use that fragment
+        int i;
+        if ((i = inputStream.read(buffer, endOf_USED_Buffer, endOf_UNUSED_Buffer - endOf_USED_Buffer)) == -1)
+        {
+            inputStream.close();
+            buffer[endOf_USED_Buffer]=(char)EOF_CHAR;
+            endOf_USED_Buffer++;
+            return false;
+        }
+            else
+                endOf_USED_Buffer += i;
+        return true;
+    }
+
+
+    protected void ExpandBuff(boolean wrapAround)
+    {
+      char[] newbuffer = new char[bufsize + maxUnusedBufferSize];
+
+      try {
+        if (wrapAround) {
+          System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+          System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
+          buffer = newbuffer;
+          endOf_USED_Buffer = (bufpos += (bufsize - tokenBegin));
+        }
+        else {
+          System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+          buffer = newbuffer;
+          endOf_USED_Buffer = (bufpos -= tokenBegin);
+        }
+      } catch (Throwable t) {
+          throw new Error(t.getMessage());
+      }
+
+      bufsize += maxUnusedBufferSize;
+      endOf_UNUSED_Buffer = bufsize;
+      tokenBegin = 0;
+    }    
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/LexerException.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/LexerException.java
new file mode 100644
index 0000000..76aa8a4
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/LexerException.java
@@ -0,0 +1,13 @@
+package [PACKAGE];
+
+public class [LEXER_NAME]Exception extends Exception {
+    
+    public [LEXER_NAME]Exception(String message) {
+        super(message);
+    }
+    
+    private static final long serialVersionUID = 1L;
+
+}
+
+
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/default.config b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/default.config
new file mode 100644
index 0000000..7efbeb8
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/default.config
@@ -0,0 +1,16 @@
+# LEXER GENERATOR configuration file
+# ---------------------------------------
+# Place *first* the generic configuration
+# then list your grammar.
+
+PACKAGE:          com.my.lexer
+LEXER_NAME:       MyLexer
+OUTPUT_DIR:       output
+
+TOKENS:
+
+BOOLEAN_LIT = string(boolean)
+FALSE_LIT   = string(false)
+BOMB_LIT    = string(bomb)
+BONSAI_LIT  = string(bonsai)
+HELLO_LIT   = string(hello)
\ No newline at end of file
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/Fixtures.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/Fixtures.java
new file mode 100644
index 0000000..2ed2eaa
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/Fixtures.java
@@ -0,0 +1,100 @@
+package edu.uci.ics.asterix.lexergenerator;
+
+import edu.uci.ics.asterix.lexergenerator.rules.Rule;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleChar;
+
+public class Fixtures {
+    static  String token_name       = "MYTOKEN";
+    static  String token2_name       = "MYTOKEN2";
+    static  String token_return     = "return TOKEN_MYTOKEN;\n";
+    static  String token2_return     = "return TOKEN_MYTOKEN2;\n";
+    static  String token_parseerror = "return parseError(TOKEN_MYTOKEN);\n";
+    static  String token_tostring   = "! ";
+    static  String rule_action      = "myaction";
+    static  String rule_name        = "myrule";
+    static  String rule_match       = "matchCheck("+rule_name+")";
+    static  String rule2_action     = "myaction2";
+    static  String rule2_name       = "myrule2";
+    static  String rule2_match      = "matchCheck2("+rule_name+")";
+    
+    static public Rule createRule(final String name){
+        return new Rule(){
+            String rule_name        = name;
+            String rule_action      = "myaction";
+            String rule_match       = "matchCheck("+rule_name+")";
+            
+            @Override
+            public Rule clone(){
+                return Fixtures.createRule(name+"_clone");
+            }
+            
+            @Override
+            public String javaAction() {
+                return rule_action;
+            }
+
+            @Override
+            public String javaMatch(String action) {
+                return rule_match+"{"+action+"}";
+            }
+            
+            @Override
+            public String toString(){
+                return rule_name;
+            }
+            
+        }; 
+    }
+    
+    static Rule rule = new Rule(){
+        
+        public Rule clone(){
+            return null;
+        }
+        
+        @Override
+        public String javaAction() {
+            return rule_action;
+        }
+
+        @Override
+        public String javaMatch(String action) {
+            return rule_match+"{"+action+"}";
+        }
+        
+        @Override
+        public String toString(){
+            return rule_name;
+        }
+        
+    }; 
+
+    static Rule rule2 = new Rule(){
+
+        public Rule clone(){
+            return null;
+        }
+        
+        @Override
+        public String javaAction() {
+            return rule2_action;
+        }
+
+        @Override
+        public String javaMatch(String act) {
+            return rule2_match+"{"+act+"}";
+        }
+        
+        @Override
+        public String toString(){
+            return rule2_name;
+        }
+        
+    };
+    
+    static RuleChar ruleA = new RuleChar('a');
+    static RuleChar ruleB = new RuleChar('b');
+    static RuleChar ruleC = new RuleChar('c');
+    static String ruleABC_action = "currentChar = readNextChar();";
+    
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAddRuleTest.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAddRuleTest.java
new file mode 100644
index 0000000..7541124
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAddRuleTest.java
@@ -0,0 +1,51 @@
+package edu.uci.ics.asterix.lexergenerator;
+
+import static edu.uci.ics.asterix.lexergenerator.Fixtures.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+
+public class LexerNodeAddRuleTest {
+
+    @Test
+    public void NodeRuleRuleNodeNode() {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        node.add(rule2);
+        node.appendTokenName(token_name);
+        assertEquals(" ( " + rule_name +token_tostring + " || " + rule2_name + token_tostring + " ) ", node.toString());
+        assertEquals(rule_match+"{"
+                        +"\n" + rule_action
+                        +"\n" +token_return
+                     +"}"
+                     +rule2_match+"{"
+                        +"\n"+rule2_action
+                        +"\n"+token_return
+                     +"}"
+                     +token_parseerror , node.toJava());
+    }
+    
+    @Test
+    public void NodeSwitchCase() {
+        LexerNode node = new LexerNode();
+        node.append(ruleA);
+        node.add(ruleB);
+        node.add(ruleC);
+        node.appendTokenName(token_name);
+        assertEquals(" ( a" + token_tostring + " || b" + token_tostring + " || c" + token_tostring + " ) ", node.toString());
+        assertEquals("switch(currentChar){\n" +
+                "case 'a':" +
+                "\n" + ruleABC_action +
+                "\n" + token_return   +
+                "case 'b':" +
+                "\n" + ruleABC_action +
+                "\n" + token_return   +
+                "case 'c':" +
+                "\n" + ruleABC_action +
+                "\n" + token_return   +
+                "}\n"+ token_parseerror , node.toJava());
+    }
+
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAppendNodeTest.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAppendNodeTest.java
new file mode 100644
index 0000000..5151e77
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAppendNodeTest.java
@@ -0,0 +1,81 @@
+package edu.uci.ics.asterix.lexergenerator;
+
+import static edu.uci.ics.asterix.lexergenerator.Fixtures.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleEpsilon;
+
+public class LexerNodeAppendNodeTest {
+
+    @Test
+    public void AppendIsMergeIfNoActions() throws Exception {
+        LexerNode node = new LexerNode();
+        LexerNode node2 = new LexerNode();
+        node2.append(createRule("rule"));
+        node2.appendTokenName(token_name);
+        node.append(node2);
+        assertEquals("rule_clone! ", node.toString());
+    }
+
+    @Test
+    public void AppendIsAppend() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(createRule("A"));
+        LexerNode node2 = new LexerNode();
+        node2.append(createRule("rule"));
+        node2.appendTokenName(token_name);
+        node.append(node2);
+        assertEquals("Arule_clone! ", node.toString());
+    }
+    
+    @Test
+    public void AppendedNodesAreCloned() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(createRule("A"));
+        node.appendTokenName(token_name);
+        LexerNode node2 = new LexerNode();
+        node2.append(createRule("B"));
+        node2.appendTokenName(token2_name);
+        node.append(node2);
+        // TODO
+        // assertEquals("A! B_clone! ", node.toString());
+        
+        LexerNode node3 = new LexerNode();
+        node3.append(createRule("C"));
+        node3.append(createRule("D"));
+        node3.appendTokenName(token2_name);
+        node.append(node3);
+        // TODO
+        // assertEquals("A! B_clone! C_cloneD_clone! ", node.toString());
+    }
+
+    @Test
+    public void EpsilonRuleDoesNotPropagateAppended() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(new RuleEpsilon());
+        LexerNode node2 = new LexerNode();
+        node2.append(createRule("A"));
+        node2.appendTokenName(token2_name);
+        node.append(node2);
+        assertEquals("A_clone! ", node.toString());
+    }
+
+    @Test
+    public void EpsilonRuleIsRemovedAndIssueMerge() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(new RuleEpsilon());
+        LexerNode node2 = new LexerNode();
+        node2.append(createRule("A"));
+        node2.appendTokenName(token2_name);
+        node.append(node2);
+        node.add(new RuleEpsilon());
+        node.append(node2);
+        // TODO
+        // assertEquals(" ( A_clone! A_clone!  || A_clone!  ) ", node.toString());
+  }
+    
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAppendRuleTest.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAppendRuleTest.java
new file mode 100644
index 0000000..84fd292
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAppendRuleTest.java
@@ -0,0 +1,47 @@
+package edu.uci.ics.asterix.lexergenerator;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import static edu.uci.ics.asterix.lexergenerator.Fixtures.*;
+
+public class LexerNodeAppendRuleTest {    
+    @Test
+    public void SingleNode() {
+        LexerNode node = new LexerNode();
+        node.appendTokenName(token_name);
+        assertEquals(token_tostring, node.toString());
+        assertEquals(token_return,   node.toJava());
+    }
+
+    @Test
+    public void NodeRuleNode() {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        node.appendTokenName(token_name);
+        assertEquals(rule_name+token_tostring, node.toString());
+        assertEquals(rule_match+"{"
+                        +"\n"+rule_action
+                        +"\n"+token_return
+                     +"}"+token_parseerror, node.toJava());
+    }
+
+    @Test
+    public void NodeRuleNodeRuleNode() {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        node.append(rule2);
+        node.appendTokenName(token_name);
+        assertEquals(rule_name+rule2_name+token_tostring, node.toString());
+        assertEquals(rule_match+"{"
+                        +"\n"+rule_action
+                        +"\n"+rule2_match+"{"
+                            +"\n"+rule2_action
+                            +"\n"+token_return
+                        +"}"
+                        +token_parseerror
+                     +"}"+token_parseerror, node.toJava());
+    }
+}
\ No newline at end of file
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAuxFunctionsTest.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAuxFunctionsTest.java
new file mode 100644
index 0000000..9f12c00
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeAuxFunctionsTest.java
@@ -0,0 +1,111 @@
+package edu.uci.ics.asterix.lexergenerator;
+
+import static edu.uci.ics.asterix.lexergenerator.Fixtures.*;
+import static org.junit.Assert.*;
+
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Set;
+
+import org.junit.Test;
+
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+import edu.uci.ics.asterix.lexergenerator.Token;
+import edu.uci.ics.asterix.lexergenerator.rules.RuleEpsilon;
+import edu.uci.ics.asterix.lexergenerator.rules.RulePartial;
+
+public class LexerNodeAuxFunctionsTest {
+    String expectedDifferentReturn = "return TOKEN_AUX_NOT_FOUND;\n"; 
+    
+    @Test
+    public void NodeRuleRuleNodeNode() {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        node.add(rule2);
+        node.appendTokenName(token_name);
+        assertEquals(" ( " + rule_name +token_tostring + " || " + rule2_name + token_tostring + " ) ", node.toString());
+        assertEquals(rule_match+"{"
+                        +"\n" + rule_action
+                        +"\n" +token_return
+                     +"}"
+                     +rule2_match+"{"
+                        +"\n"+rule2_action
+                        +"\n"+token_return
+                     +"}"
+                     +expectedDifferentReturn , node.toJavaAuxFunction());
+    }
+    
+    @Test
+    public void NodeSwitchCase() {
+        LexerNode node = new LexerNode();
+        node.append(ruleA);
+        node.add(ruleB);
+        node.add(ruleC);
+        node.appendTokenName(token_name);
+        assertEquals(" ( a" + token_tostring + " || b" + token_tostring + " || c" + token_tostring + " ) ", node.toString());
+        assertEquals("switch(currentChar){\n" +
+                "case 'a':" +
+                "\n" + ruleABC_action +
+                "\n" + token_return   +
+                "case 'b':" +
+                "\n" + ruleABC_action +
+                "\n" + token_return   +
+                "case 'c':" +
+                "\n" + ruleABC_action +
+                "\n" + token_return   +
+                "}\n"+ expectedDifferentReturn , node.toJavaAuxFunction());
+    }
+
+    @Test
+    public void NodeNeededAuxFunctions() {
+        LexerNode node = new LexerNode();
+        node.append(ruleA);
+        node.add(new RulePartial("token1"));
+        node.append(ruleC);
+        node.append(new RulePartial("token2"));
+        node.appendTokenName(token_name);
+        assertEquals(" ( actoken2!  || token1ctoken2!  ) ", node.toString());
+        Set<String> expectedNeededAuxFunctions = new HashSet<String>();
+        expectedNeededAuxFunctions.add("token1");
+        expectedNeededAuxFunctions.add("token2");
+        assertEquals(expectedNeededAuxFunctions, node.neededAuxFunctions());
+    }    
+
+    @Test(expected=Exception.class)
+    public void NodeExpandFirstActionError() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(ruleA);
+        node.add(new RulePartial("token1"));
+        node.append(ruleC);
+        node.add(new RuleEpsilon());
+        node.append(new RulePartial("token2"));
+        node.appendTokenName(token_name);
+        assertEquals(" ( actoken2!  || token1ctoken2!  || token2!  ) ", node.toString());
+        LinkedHashMap<String, Token> tokens = new LinkedHashMap<String, Token>();
+        try {
+            node.expandFirstAction(tokens);
+        } catch (Exception e) {
+            assertEquals("Cannot find a token used as part of another definition, missing token: token1", e.getMessage());
+            throw e;
+        }
+    } 
+
+    public void NodeExpandFirstAction() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(ruleA);
+        node.add(new RulePartial("token1"));
+        node.append(ruleC);
+        node.add(new RuleEpsilon());
+        node.append(new RulePartial("token2"));
+        node.appendTokenName(token_name);
+        assertEquals(" ( actoken2!  || token1ctoken2!  || token2!  ) ", node.toString());
+        LinkedHashMap<String, Token> tokens = new LinkedHashMap<String, Token>();
+        Token a = new Token("token1 = string(T1-blabla)", tokens);
+        Token b = new Token("token1 = string(T1-blabla)", tokens);
+        tokens.put("token1", a);
+        tokens.put("token2", b);
+        node.expandFirstAction(tokens);
+        assertEquals(" ( actoken2!  || T1-blablactoken2!  || T2-blabla!  ) ", node.toString());
+    }
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeCloneTest.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeCloneTest.java
new file mode 100644
index 0000000..87e3ff4
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeCloneTest.java
@@ -0,0 +1,56 @@
+package edu.uci.ics.asterix.lexergenerator;
+
+import static edu.uci.ics.asterix.lexergenerator.Fixtures.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+
+public class LexerNodeCloneTest {
+    
+    @Test
+    public void Depth1() throws Exception {
+        LexerNode node = new LexerNode();
+        LexerNode newNode = node.clone();
+        assertFalse(node == newNode);
+    }
+    
+    
+    @Test
+    public void Depth2() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(createRule("my1"));
+        node.add(createRule("my2"));
+        node.add(ruleA);
+        node.appendTokenName(token_name);
+        LexerNode newNode = node.clone();
+
+        assertEquals(" ( my1!  || my2!  || a!  ) ", node.toString());
+        assertEquals(" ( my1_clone!  || my2_clone!  || a!  ) ", newNode.toString());
+    }
+
+    @Test
+    public void Depth3() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(createRule("my1"));
+        node.add(createRule("my2"));
+        node.add(ruleA);
+        node.appendTokenName(token_name);
+        LexerNode node2 = new LexerNode();
+        node2.append(createRule("my3"));
+        node2.add(createRule("my4"));
+        node2.add(ruleB);
+        node2.appendTokenName(token2_name);
+        node.append(node2);
+        LexerNode newNode = node.clone();
+        // TODO
+        // assertEquals(" ( my1!  (  || my3_clone!  || my4_clone!  || b!  ) " +
+        //		     " || my2!  (  || my3_clone!  || my4_clone!  || b!  ) " +
+        //		     " || a!  (  || my3_clone!  || my4_clone!  || b!  )  ) ", node.toString());
+        // assertEquals(" ( my1_clone!  (  || my3_clone_clone!  || my4_clone_clone!  || b!  ) " +
+        //		     " || my2_clone!  (  || my3_clone_clone!  || my4_clone_clone!  || b!  ) " +
+        //		     " || a!  (  || my3_clone_clone!  || my4_clone_clone!  || b!  )  ) ", newNode.toString());
+    }
+    
+}
diff --git a/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeMergeNodeTest.java b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeMergeNodeTest.java
new file mode 100644
index 0000000..4b22d99
--- /dev/null
+++ b/asterix-maven-plugins/lexer-generator-maven-plugin/src/test/java/edu/uci/ics/asterix/lexergenerator/LexerNodeMergeNodeTest.java
@@ -0,0 +1,83 @@
+package edu.uci.ics.asterix.lexergenerator;
+
+import static edu.uci.ics.asterix.lexergenerator.Fixtures.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import edu.uci.ics.asterix.lexergenerator.LexerNode;
+
+public class LexerNodeMergeNodeTest {
+
+    @Test
+    public void MergeIsAdd() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        LexerNode node2 = new LexerNode();
+        node2.append(rule2);
+        node2.append(rule);
+        node2.merge(node);
+        node2.appendTokenName(token_name);
+        
+        LexerNode expected = new LexerNode();
+        expected.append(rule2);
+        expected.append(rule);
+        expected.add(rule);
+        expected.appendTokenName(token_name);
+        
+        assertEquals(expected.toString(), node2.toString());
+        assertEquals(expected.toJava(), node2.toJava());
+    }
+
+    @Test
+    public void MergeTwoToken() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        node.appendTokenName(token_name);
+        LexerNode node2 = new LexerNode();
+        node2.append(rule2);
+        node2.appendTokenName(token2_name);
+        node.merge(node2);
+
+        assertEquals(" ( "+rule_name+token_tostring+" || "+rule2_name+token_tostring+" ) ", node.toString());
+        assertEquals(rule_match + "{"
+        		+ "\n" + rule_action
+        		+ "\n" + token_return
+        +"}"+rule2_match+"{" 
+        + "\n" + rule2_action
+        + "\n" + token2_return
+        +"}return parseError(TOKEN_MYTOKEN,TOKEN_MYTOKEN2);\n"
+, node.toJava());
+    }
+
+    @Test(expected=Exception.class)
+    public void MergeConflict() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        node.appendTokenName(token_name);
+        LexerNode node2 = new LexerNode();
+        node2.append(rule);
+        node2.appendTokenName(token2_name);
+        try {
+            node.merge(node2);
+        } catch (Exception e) {
+            assertEquals("Rule conflict between: "+token_name +" and "+token2_name, e.getMessage());
+            throw e;
+        }
+    }
+
+    @Test
+    public void MergeWithoutConflictWithRemoveTokensName() throws Exception {
+        LexerNode node = new LexerNode();
+        node.append(rule);
+        node.append(rule);
+        node.appendTokenName(token_name);
+        LexerNode node2 = new LexerNode();
+        node2.append(rule);
+        node2.append(rule);
+        node2.appendTokenName(token2_name);
+        node2.removeTokensName();
+        node.merge(node2);
+        assertEquals(rule_name+rule_name+token_tostring, node.toString());
+    }
+}
diff --git a/asterix-maven-plugins/pom.xml b/asterix-maven-plugins/pom.xml
new file mode 100644
index 0000000..0677ffb
--- /dev/null
+++ b/asterix-maven-plugins/pom.xml
@@ -0,0 +1,21 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>edu.uci.ics.asterix</groupId>
+  <artifactId>asterix-maven-plugins</artifactId>
+  <version>0.1</version>
+  <packaging>pom</packaging>
+
+  <dependencies>
+  	<dependency>
+  		<groupId>org.apache.maven</groupId>
+  		<artifactId>maven-plugin-api</artifactId>
+  		<version>2.2.1</version>
+  		<type>jar</type>
+  		<scope>compile</scope>
+  	</dependency>
+  </dependencies>
+
+  <modules>
+    <module>lexer-generator-maven-plugin</module>
+  </modules>
+</project>
diff --git a/asterix-metadata/pom.xml b/asterix-metadata/pom.xml
index 58566f8..3e8e0f9 100644
--- a/asterix-metadata/pom.xml
+++ b/asterix-metadata/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -14,8 +15,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 		</plugins>
@@ -54,12 +55,12 @@
 			<version>0.0.4-SNAPSHOT</version>
 			<scope>compile</scope>
 		</dependency>
-                <dependency>
-                        <groupId>org.apache.hadoop</groupId>
-                        <artifactId>hadoop-core</artifactId>
-                        <version>0.20.2</version>
-                        <type>jar</type>
-                        <scope>compile</scope>
-                </dependency>
+		<dependency>
+			<groupId>org.apache.hadoop</groupId>
+			<artifactId>hadoop-core</artifactId>
+			<version>0.20.2</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
 	</dependencies>
 </project>
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataEntityTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataEntityTupleTranslator.java
index df61cd9..9c9d02b 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataEntityTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/api/IMetadataEntityTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -50,5 +50,5 @@
      *            Metadata entity to be written into a tuple.
      * @throws IOException
      */
-    public ITupleReference getTupleFromMetadataEntity(T metadataEntity) throws IOException;
+    public ITupleReference getTupleFromMetadataEntity(T metadataEntity) throws MetadataException, IOException;
 }
\ No newline at end of file
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataRecordTypes.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataRecordTypes.java
index 01c849b..679c2db 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataRecordTypes.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/bootstrap/MetadataRecordTypes.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -18,6 +18,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.om.types.AOrderedListType;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.AUnionType;
@@ -49,31 +51,34 @@
     /**
      * Create all metadata record types.
      */
-    public static void init() {
+    public static void init() throws MetadataException {
         // Attention: The order of these calls is important because some types
         // depend on other types being created first.
         // These calls are one "dependency chain".
-        DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE = createPropertiesRecordType();
-        INTERNAL_DETAILS_RECORDTYPE = createInternalDetailsRecordType();
-        EXTERNAL_DETAILS_RECORDTYPE = createExternalDetailsRecordType();
-        FEED_DETAILS_RECORDTYPE = createFeedDetailsRecordType();
-        DATASET_HINTS_RECORDTYPE = createPropertiesRecordType();
-        DATASET_RECORDTYPE = createDatasetRecordType();
+        try {
+            DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE = createPropertiesRecordType();
+            INTERNAL_DETAILS_RECORDTYPE = createInternalDetailsRecordType();
+            EXTERNAL_DETAILS_RECORDTYPE = createExternalDetailsRecordType();
+            FEED_DETAILS_RECORDTYPE = createFeedDetailsRecordType();
+            DATASET_HINTS_RECORDTYPE = createPropertiesRecordType();
+            DATASET_RECORDTYPE = createDatasetRecordType();
 
-        // Starting another dependency chain.
-        FIELD_RECORDTYPE = createFieldRecordType();
-        RECORD_RECORDTYPE = createRecordTypeRecordType();
-        DERIVEDTYPE_RECORDTYPE = createDerivedTypeRecordType();
-        DATATYPE_RECORDTYPE = createDatatypeRecordType();
+            // Starting another dependency chain.
+            FIELD_RECORDTYPE = createFieldRecordType();
+            RECORD_RECORDTYPE = createRecordTypeRecordType();
+            DERIVEDTYPE_RECORDTYPE = createDerivedTypeRecordType();
+            DATATYPE_RECORDTYPE = createDatatypeRecordType();
 
-        // Independent of any other types.
-        DATAVERSE_RECORDTYPE = createDataverseRecordType();
-        INDEX_RECORDTYPE = createIndexRecordType();
-        NODE_RECORDTYPE = createNodeRecordType();
-        NODEGROUP_RECORDTYPE = createNodeGroupRecordType();
-        FUNCTION_RECORDTYPE = createFunctionRecordType();
-        DATASOURCE_ADAPTER_RECORDTYPE = createDatasourceAdapterRecordType();
-
+            // Independent of any other types.
+            DATAVERSE_RECORDTYPE = createDataverseRecordType();
+            INDEX_RECORDTYPE = createIndexRecordType();
+            NODE_RECORDTYPE = createNodeRecordType();
+            NODEGROUP_RECORDTYPE = createNodeGroupRecordType();
+            FUNCTION_RECORDTYPE = createFunctionRecordType();
+            DATASOURCE_ADAPTER_RECORDTYPE = createDatasourceAdapterRecordType();
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
     }
 
     // Helper constants for accessing fields in an ARecord of type
@@ -82,7 +87,7 @@
     public static final int DATAVERSE_ARECORD_FORMAT_FIELD_INDEX = 1;
     public static final int DATAVERSE_ARECORD_TIMESTAMP_FIELD_INDEX = 2;
 
-    private static final ARecordType createDataverseRecordType() {
+    private static final ARecordType createDataverseRecordType() throws AsterixException {
         return new ARecordType("DataverseRecordType", new String[] { "DataverseName", "DataFormat", "Timestamp" },
                 new IAType[] { BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING }, true);
     }
@@ -93,7 +98,7 @@
     public static final int DATASOURCE_PROPERTIES_NAME_FIELD_INDEX = 0;
     public static final int DATASOURCE_PROPERTIES_VALUE_FIELD_INDEX = 1;
 
-    private static final ARecordType createPropertiesRecordType() {
+    private static final ARecordType createPropertiesRecordType() throws AsterixException {
         String[] fieldNames = { "Name", "Value" };
         IAType[] fieldTypes = { BuiltinType.ASTRING, BuiltinType.ASTRING };
         return new ARecordType(null, fieldNames, fieldTypes, true);
@@ -107,7 +112,7 @@
     public static final int INTERNAL_DETAILS_ARECORD_PRIMARYKEY_FIELD_INDEX = 3;
     public static final int INTERNAL_DETAILS_ARECORD_GROUPNAME_FIELD_INDEX = 4;
 
-    private static final ARecordType createInternalDetailsRecordType() {
+    private static final ARecordType createInternalDetailsRecordType() throws AsterixException {
         AOrderedListType olType = new AOrderedListType(BuiltinType.ASTRING, null);
         String[] fieldNames = { "FileStructure", "PartitioningStrategy", "PartitioningKey", "PrimaryKey", "GroupName" };
         IAType[] fieldTypes = { BuiltinType.ASTRING, BuiltinType.ASTRING, olType, olType, BuiltinType.ASTRING };
@@ -119,7 +124,7 @@
     public static final int EXTERNAL_DETAILS_ARECORD_DATASOURCE_ADAPTER_FIELD_INDEX = 0;
     public static final int EXTERNAL_DETAILS_ARECORD_PROPERTIES_FIELD_INDEX = 1;
 
-    private static final ARecordType createExternalDetailsRecordType() {
+    private static final ARecordType createExternalDetailsRecordType() throws AsterixException {
 
         AOrderedListType orderedPropertyListType = new AOrderedListType(DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE, null);
         String[] fieldNames = { "DatasourceAdapter", "Properties" };
@@ -137,7 +142,7 @@
     public static final int FEED_DETAILS_ARECORD_FUNCTION_FIELD_INDEX = 7;
     public static final int FEED_DETAILS_ARECORD_STATE_FIELD_INDEX = 8;
 
-    private static final ARecordType createFeedDetailsRecordType() {
+    private static final ARecordType createFeedDetailsRecordType() throws AsterixException {
         AOrderedListType orderedListType = new AOrderedListType(BuiltinType.ASTRING, null);
         AOrderedListType orderedListOfPropertiesType = new AOrderedListType(DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE,
                 null);
@@ -168,7 +173,7 @@
     public static final int DATASET_ARECORD_HINTS_FIELD_INDEX = 7;
     public static final int DATASET_ARECORD_TIMESTAMP_FIELD_INDEX = 8;
 
-    private static final ARecordType createDatasetRecordType() {
+    private static final ARecordType createDatasetRecordType() throws AsterixException {
         String[] fieldNames = { "DataverseName", "DatasetName", "DataTypeName", "DatasetType", "InternalDetails",
                 "ExternalDetails", "FeedDetails", "Hints", "Timestamp" };
 
@@ -200,7 +205,7 @@
     public static final int FIELD_ARECORD_FIELDNAME_FIELD_INDEX = 0;
     public static final int FIELD_ARECORD_FIELDTYPE_FIELD_INDEX = 1;
 
-    private static final ARecordType createFieldRecordType() {
+    private static final ARecordType createFieldRecordType() throws AsterixException {
         String[] fieldNames = { "FieldName", "FieldType" };
         IAType[] fieldTypes = { BuiltinType.ASTRING, BuiltinType.ASTRING };
         return new ARecordType(null, fieldNames, fieldTypes, true);
@@ -211,7 +216,7 @@
     public static final int RECORDTYPE_ARECORD_ISOPEN_FIELD_INDEX = 0;
     public static final int RECORDTYPE_ARECORD_FIELDS_FIELD_INDEX = 1;
 
-    private static final ARecordType createRecordTypeRecordType() {
+    private static final ARecordType createRecordTypeRecordType() throws AsterixException {
         AOrderedListType olType = new AOrderedListType(FIELD_RECORDTYPE, null);
         String[] fieldNames = { "IsOpen", "Fields" };
         IAType[] fieldTypes = { BuiltinType.ABOOLEAN, olType };
@@ -228,7 +233,7 @@
     public static final int DERIVEDTYPE_ARECORD_UNORDEREDLIST_FIELD_INDEX = 5;
     public static final int DERIVEDTYPE_ARECORD_ORDEREDLIST_FIELD_INDEX = 6;
 
-    private static final ARecordType createDerivedTypeRecordType() {
+    private static final ARecordType createDerivedTypeRecordType() throws AsterixException {
         String[] fieldNames = { "Tag", "IsAnonymous", "EnumValues", "Record", "Union", "UnorderedList", "OrderedList" };
         List<IAType> recordUnionList = new ArrayList<IAType>();
         recordUnionList.add(BuiltinType.ANULL);
@@ -257,7 +262,7 @@
     public static final int DATATYPE_ARECORD_DERIVED_FIELD_INDEX = 2;
     public static final int DATATYPE_ARECORD_TIMESTAMP_FIELD_INDEX = 3;
 
-    private static final ARecordType createDatatypeRecordType() {
+    private static final ARecordType createDatatypeRecordType() throws AsterixException {
         String[] fieldNames = { "DataverseName", "DatatypeName", "Derived", "Timestamp" };
         List<IAType> recordUnionList = new ArrayList<IAType>();
         recordUnionList.add(BuiltinType.ANULL);
@@ -277,7 +282,7 @@
     public static final int INDEX_ARECORD_ISPRIMARY_FIELD_INDEX = 5;
     public static final int INDEX_ARECORD_TIMESTAMP_FIELD_INDEX = 6;
 
-    private static final ARecordType createIndexRecordType() {
+    private static final ARecordType createIndexRecordType() throws AsterixException {
         AOrderedListType olType = new AOrderedListType(BuiltinType.ASTRING, null);
         String[] fieldNames = { "DataverseName", "DatasetName", "IndexName", "IndexStructure", "SearchKey",
                 "IsPrimary", "Timestamp" };
@@ -292,7 +297,7 @@
     public static final int NODE_ARECORD_NUMBEROFCORES_FIELD_INDEX = 1;
     public static final int NODE_ARECORD_WORKINGMEMORYSIZE_FIELD_INDEX = 2;
 
-    private static final ARecordType createNodeRecordType() {
+    private static final ARecordType createNodeRecordType() throws AsterixException {
         String[] fieldNames = { "NodeName", "NumberOfCores", "WorkingMemorySize" };
         IAType[] fieldTypes = { BuiltinType.ASTRING, BuiltinType.AINT32, BuiltinType.AINT32 };
         return new ARecordType("NodeRecordType", fieldNames, fieldTypes, true);
@@ -304,7 +309,7 @@
     public static final int NODEGROUP_ARECORD_NODENAMES_FIELD_INDEX = 1;
     public static final int NODEGROUP_ARECORD_TIMESTAMP_FIELD_INDEX = 2;
 
-    private static final ARecordType createNodeGroupRecordType() {
+    private static final ARecordType createNodeGroupRecordType() throws AsterixException {
         AUnorderedListType ulType = new AUnorderedListType(BuiltinType.ASTRING, null);
         String[] fieldNames = { "GroupName", "NodeNames", "Timestamp" };
         IAType[] fieldTypes = { BuiltinType.ASTRING, ulType, BuiltinType.ASTRING };
@@ -326,7 +331,7 @@
     public static final int FUNCTION_ARECORD_FUNCTION_LANGUAGE_FIELD_INDEX = 6;
     public static final int FUNCTION_ARECORD_FUNCTION_KIND_FIELD_INDEX = 7;
 
-    private static final ARecordType createFunctionRecordType() {
+    private static final ARecordType createFunctionRecordType() throws AsterixException {
 
         String[] fieldNames = { "DataverseName", "Name", "Arity", "Params", "ReturnType", "Definition", "Language",
                 "Kind" };
@@ -342,7 +347,7 @@
     public static final int DATASOURCE_ADAPTER_ARECORD_TYPE_FIELD_INDEX = 3;
     public static final int DATASOURCE_ADAPTER_ARECORD_TIMESTAMP_FIELD_INDEX = 4;
 
-    private static ARecordType createDatasourceAdapterRecordType() {
+    private static ARecordType createDatasourceAdapterRecordType() throws AsterixException {
         String[] fieldNames = { "DataverseName", "Name", "Classname", "Type", "Timestamp" };
         IAType[] fieldTypes = { BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING, BuiltinType.ASTRING,
                 BuiltinType.ASTRING };
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlDataSource.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlDataSource.java
index b7ba1a1..e4c7ba2 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlDataSource.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlDataSource.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -15,6 +15,7 @@
 
 package edu.uci.ics.asterix.metadata.declared;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -63,46 +64,54 @@
         this.id = id;
         this.dataset = dataset;
         this.datasourceType = datasourceType;
-        switch (datasourceType) {
-            case FEED:
-                initFeedDataset(itemType, dataset);
-            case INTERNAL: {
-                initInternalDataset(itemType);
-                break;
+        try {
+            switch (datasourceType) {
+                case FEED:
+                    initFeedDataset(itemType, dataset);
+                case INTERNAL: {
+                    initInternalDataset(itemType);
+                    break;
+                }
+                case EXTERNAL_FEED:
+                case EXTERNAL: {
+                    initExternalDataset(itemType);
+                    break;
+                }
+                default: {
+                    throw new IllegalArgumentException();
+                }
             }
-            case EXTERNAL_FEED:
-            case EXTERNAL: {
-                initExternalDataset(itemType);
-                break;
-            }
-            default: {
-                throw new IllegalArgumentException();
-            }
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
         }
     }
 
     public AqlDataSource(AqlSourceId id, Dataset dataset, IAType itemType) throws AlgebricksException {
         this.id = id;
         this.dataset = dataset;
-        switch (dataset.getDatasetType()) {
-            case FEED:
-                initFeedDataset(itemType, dataset);
-                break;
-            case INTERNAL:
-                initInternalDataset(itemType);
-                break;
-            case EXTERNAL: {
-                initExternalDataset(itemType);
-                break;
+        try {
+            switch (dataset.getDatasetType()) {
+                case FEED:
+                    initFeedDataset(itemType, dataset);
+                    break;
+                case INTERNAL:
+                    initInternalDataset(itemType);
+                    break;
+                case EXTERNAL: {
+                    initExternalDataset(itemType);
+                    break;
+                }
+                default: {
+                    throw new IllegalArgumentException();
+                }
             }
-            default: {
-                throw new IllegalArgumentException();
-            }
+        } catch (IOException e) {
+            throw new AlgebricksException(e);
         }
     }
 
     // TODO: Seems like initFeedDataset() could simply call this method.
-    private void initInternalDataset(IAType itemType) {
+    private void initInternalDataset(IAType itemType) throws IOException {
         List<String> partitioningKeys = DatasetUtils.getPartitioningKeys(dataset);
         ARecordType recordType = (ARecordType) itemType;
         int n = partitioningKeys.size();
@@ -114,7 +123,7 @@
         domain = new AsterixNodeGroupDomain(DatasetUtils.getNodegroupName(dataset));
     }
 
-    private void initFeedDataset(IAType itemType, Dataset dataset) {
+    private void initFeedDataset(IAType itemType, Dataset dataset) throws IOException {
         if (dataset.getDatasetDetails() instanceof ExternalDatasetDetails) {
             initExternalDataset(itemType);
         } else {
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
index d92c76d..321a73c 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/declared/AqlMetadataProvider.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -16,6 +16,7 @@
 package edu.uci.ics.asterix.metadata.declared;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -851,7 +852,7 @@
                     splitsAndConstraint.first, typeTraits, comparatorFactories, fieldPermutation, indexOp,
                     new BTreeDataflowHelperFactory(), filterFactory, NoOpOperationCallbackProvider.INSTANCE, jobTxnId);
             return new Pair<IOperatorDescriptor, AlgebricksPartitionConstraint>(btreeInsert, splitsAndConstraint.second);
-        } catch (MetadataException e) {
+        } catch (MetadataException | IOException e) {
             throw new AlgebricksException(e);
         }
     }
@@ -918,8 +919,8 @@
                     new RTreeDataflowHelperFactory(valueProviderFactories), filterFactory,
                     NoOpOperationCallbackProvider.INSTANCE, jobTxnId);
             return new Pair<IOperatorDescriptor, AlgebricksPartitionConstraint>(rtreeUpdate, splitsAndConstraint.second);
-        } catch (MetadataException me) {
-            throw new AlgebricksException(me);
+        } catch (MetadataException | IOException e) {
+            throw new AlgebricksException(e);
         }
     }
 
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/ExternalDatasetDetails.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/ExternalDatasetDetails.java
index 07da617..18cef34 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/ExternalDatasetDetails.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/ExternalDatasetDetails.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2011 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -12,6 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package edu.uci.ics.asterix.metadata.entities;
 
 import java.io.DataOutput;
@@ -22,6 +23,7 @@
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
 import edu.uci.ics.asterix.builders.RecordBuilder;
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.metadata.IDatasetDetails;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
@@ -76,7 +78,8 @@
         fieldValue.reset();
         aString.setValue(this.getAdapter());
         stringSerde.serialize(aString, fieldValue.getDataOutput());
-        externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_DATASOURCE_ADAPTER_FIELD_INDEX, fieldValue);
+        externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_DATASOURCE_ADAPTER_FIELD_INDEX,
+                fieldValue);
 
         // write field 1
         listBuilder.reset((AOrderedListType) externalRecordType.getFieldTypes()[1]);
@@ -93,8 +96,8 @@
 
         try {
             externalRecordBuilder.write(out, true);
-        } catch (IOException ioe) {
-            throw new HyracksDataException(ioe);
+        } catch (IOException | AsterixException e) {
+            throw new HyracksDataException(e);
         }
 
     }
@@ -121,8 +124,8 @@
 
         try {
             propertyRecordBuilder.write(out, true);
-        } catch (IOException ioe) {
-            throw new HyracksDataException(ioe);
+        } catch (IOException | AsterixException e) {
+            throw new HyracksDataException(e);
         }
     }
 }
\ No newline at end of file
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/FeedDatasetDetails.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/FeedDatasetDetails.java
index 367066b..22de3d3 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/FeedDatasetDetails.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/FeedDatasetDetails.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2011 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -12,6 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package edu.uci.ics.asterix.metadata.entities;
 
 import java.io.DataOutput;
@@ -23,6 +24,7 @@
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
 import edu.uci.ics.asterix.builders.RecordBuilder;
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.common.functions.FunctionSignature;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
@@ -160,8 +162,8 @@
 
         try {
             feedRecordBuilder.write(out, true);
-        } catch (IOException ioe) {
-            throw new HyracksDataException(ioe);
+        } catch (IOException | AsterixException e) {
+            throw new HyracksDataException(e);
         }
 
     }
@@ -188,8 +190,8 @@
 
         try {
             propertyRecordBuilder.write(out, true);
-        } catch (IOException ioe) {
-            throw new HyracksDataException(ioe);
+        } catch (IOException | AsterixException e) {
+            throw new HyracksDataException(e);
         }
     }
 
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/InternalDatasetDetails.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/InternalDatasetDetails.java
index 51d154a..4267af2 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/InternalDatasetDetails.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/InternalDatasetDetails.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2011 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -12,6 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package edu.uci.ics.asterix.metadata.entities;
 
 import java.io.DataOutput;
@@ -22,6 +23,7 @@
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
 import edu.uci.ics.asterix.builders.RecordBuilder;
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.metadata.IDatasetDetails;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
@@ -146,8 +148,8 @@
 
         try {
             internalRecordBuilder.write(out, true);
-        } catch (IOException ioe) {
-            throw new HyracksDataException(ioe);
+        } catch (IOException | AsterixException e) {
+            throw new HyracksDataException(e);
         }
     }
 
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasetTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasetTupleTranslator.java
index 483bb70..a0aa36e 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasetTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasetTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2012 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -30,9 +30,11 @@
 import edu.uci.ics.asterix.builders.RecordBuilder;
 import edu.uci.ics.asterix.builders.UnorderedListBuilder;
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.common.functions.FunctionSignature;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.metadata.IDatasetDetails;
+import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
 import edu.uci.ics.asterix.metadata.entities.Dataset;
@@ -212,7 +214,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(Dataset dataset) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(Dataset dataset) throws IOException, MetadataException {
         // write the key in the first 2 fields of the tuple
         tupleBuilder.reset();
         aString.setValue(dataset.getDataverseName());
@@ -277,7 +279,11 @@
         recordBuilder.addField(MetadataRecordTypes.DATASET_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue);
 
         // write record
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
 
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
@@ -342,7 +348,7 @@
 
         try {
             propertyRecordBuilder.write(out, true);
-        } catch (IOException ioe) {
+        } catch (IOException | AsterixException ioe) {
             throw new HyracksDataException(ioe);
         }
     }
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasourceAdapterTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasourceAdapterTupleTranslator.java
index 6353e99..4a5e4dc 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasourceAdapterTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatasourceAdapterTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2012 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -12,6 +12,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package edu.uci.ics.asterix.metadata.entitytupletranslators;
 
 import java.io.ByteArrayInputStream;
@@ -20,6 +21,7 @@
 import java.io.IOException;
 import java.util.Calendar;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.external.dataset.adapter.AdapterIdentifier;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.metadata.MetadataException;
@@ -64,7 +66,8 @@
 
     private DatasourceAdapter createAdapterFromARecord(ARecord adapterRecord) {
         String dataverseName = ((AString) adapterRecord
-                .getValueByPos(MetadataRecordTypes.DATASOURCE_ADAPTER_ARECORD_DATAVERSENAME_FIELD_INDEX)).getStringValue();
+                .getValueByPos(MetadataRecordTypes.DATASOURCE_ADAPTER_ARECORD_DATAVERSENAME_FIELD_INDEX))
+                .getStringValue();
         String adapterName = ((AString) adapterRecord
                 .getValueByPos(MetadataRecordTypes.DATASOURCE_ADAPTER_ARECORD_NAME_FIELD_INDEX)).getStringValue();
         String classname = ((AString) adapterRecord
@@ -76,7 +79,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(DatasourceAdapter adapter) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(DatasourceAdapter adapter) throws IOException, MetadataException {
         // write the key in the first 2 fields of the tuple
         tupleBuilder.reset();
         aString.setValue(adapter.getAdapterIdentifier().getNamespace());
@@ -121,7 +124,11 @@
         recordBuilder.addField(MetadataRecordTypes.DATASOURCE_ADAPTER_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue);
 
         // write record
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
 
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatatypeTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatatypeTupleTranslator.java
index d37fbc6..185f35b 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatatypeTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DatatypeTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -28,6 +28,7 @@
 import edu.uci.ics.asterix.builders.IARecordBuilder;
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
 import edu.uci.ics.asterix.builders.RecordBuilder;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.MetadataNode;
@@ -140,8 +141,12 @@
                         fieldTypes[fieldId] = getTypeFromTypeName(dataverseName, fieldTypeName);
                         fieldId++;
                     }
-                    return new Datatype(dataverseName, datatypeName, new ARecordType(datatypeName, fieldNames,
-                            fieldTypes, isOpen), isAnonymous);
+                    try {
+                        return new Datatype(dataverseName, datatypeName, new ARecordType(datatypeName, fieldNames,
+                                fieldTypes, isOpen), isAnonymous);
+                    } catch (AsterixException e) {
+                        throw new MetadataException(e);
+                    }
                 }
                 case UNION: {
                     IACursor cursor = ((AOrderedList) derivedTypeRecord
@@ -189,7 +194,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(Datatype dataType) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(Datatype dataType) throws IOException, MetadataException {
         // write the key in the first two fields of the tuple
         tupleBuilder.reset();
         aString.setValue(dataType.getDataverseName());
@@ -218,7 +223,11 @@
         ATypeTag tag = dataType.getDatatype().getTypeTag();
         if (isDerivedType(tag)) {
             fieldValue.reset();
-            writeDerivedTypeRecord(dataType, fieldValue.getDataOutput());
+            try {
+                writeDerivedTypeRecord(dataType, fieldValue.getDataOutput());
+            } catch (AsterixException e) {
+                throw new MetadataException(e);
+            }
             recordBuilder.addField(MetadataRecordTypes.DATATYPE_ARECORD_DERIVED_FIELD_INDEX, fieldValue);
         }
 
@@ -229,14 +238,18 @@
         recordBuilder.addField(MetadataRecordTypes.DATATYPE_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue);
 
         // write record
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
 
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
         return tuple;
     }
 
-    public void writeDerivedTypeRecord(Datatype type, DataOutput out) throws IOException {
+    private void writeDerivedTypeRecord(Datatype type, DataOutput out) throws IOException, AsterixException {
         DerivedTypeTag tag;
         IARecordBuilder derivedRecordBuilder = new RecordBuilder();
         ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
@@ -348,7 +361,7 @@
         listBuilder.write(dataOutput, true);
     }
 
-    public void writeRecordType(Datatype instance, DataOutput out) throws IOException {
+    private void writeRecordType(Datatype instance, DataOutput out) throws IOException, AsterixException {
 
         ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
         ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DataverseTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DataverseTupleTranslator.java
index 271bf90..1e32004 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DataverseTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/DataverseTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -21,7 +21,9 @@
 import java.io.IOException;
 import java.util.Calendar;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
 import edu.uci.ics.asterix.metadata.entities.Dataverse;
@@ -61,7 +63,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(Dataverse instance) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(Dataverse instance) throws IOException, MetadataException {
         // write the key in the first field of the tuple
         tupleBuilder.reset();
         aString.setValue(instance.getDataverseName());
@@ -88,7 +90,11 @@
         stringSerde.serialize(aString, fieldValue.getDataOutput());
         recordBuilder.addField(MetadataRecordTypes.DATAVERSE_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue);
 
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
 
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
index 8296a22..c34bc72 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/FunctionTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -23,7 +23,9 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
 import edu.uci.ics.asterix.metadata.entities.Function;
@@ -48,7 +50,6 @@
     // Third key field.
     public static final int FUNCTION_FUNCTIONARITY_TUPLE_FIELD_INDEX = 2;
 
-    
     // Payload field containing serialized Function.
     public static final int FUNCTION_PAYLOAD_TUPLE_FIELD_INDEX = 3;
 
@@ -103,7 +104,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(Function function) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(Function function) throws IOException, MetadataException {
         // write the key in the first 2 fields of the tuple
         tupleBuilder.reset();
         aString.setValue(function.getDataverseName());
@@ -178,7 +179,11 @@
         recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_KIND_FIELD_INDEX, fieldValue);
 
         // write record
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
 
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/IndexTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/IndexTupleTranslator.java
index d71480f..07d7cc9 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/IndexTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/IndexTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -25,7 +25,9 @@
 
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
 import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
 import edu.uci.ics.asterix.metadata.entities.Index;
@@ -106,7 +108,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(Index instance) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(Index instance) throws IOException, MetadataException {
         // write the key in the first 3 fields of the tuple
         tupleBuilder.reset();
         aString.setValue(instance.getDataverseName());
@@ -181,11 +183,19 @@
             aString.setValue(GRAM_LENGTH_FIELD_NAME);
             stringSerde.serialize(aString, nameValue.getDataOutput());
             intSerde.serialize(new AInt32(instance.getGramLength()), fieldValue.getDataOutput());
-            recordBuilder.addField(nameValue, fieldValue);
+            try {
+                recordBuilder.addField(nameValue, fieldValue);
+            } catch (AsterixException e) {
+                throw new MetadataException(e);
+            }
         }
 
         // write record
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
 
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeGroupTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeGroupTupleTranslator.java
index da66d4b..ce72322 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeGroupTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeGroupTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -24,7 +24,9 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.builders.UnorderedListBuilder;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
 import edu.uci.ics.asterix.metadata.entities.NodeGroup;
@@ -79,7 +81,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(NodeGroup instance) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(NodeGroup instance) throws IOException, MetadataException {
         // write the key in the first field of the tuple
         tupleBuilder.reset();
         aString.setValue(instance.getNodeGroupName());
@@ -114,7 +116,11 @@
         stringSerde.serialize(aString, fieldValue.getDataOutput());
         recordBuilder.addField(MetadataRecordTypes.NODEGROUP_ARECORD_TIMESTAMP_FIELD_INDEX, fieldValue);
 
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
 
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeTupleTranslator.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeTupleTranslator.java
index 8d324b4..9e276cc 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeTupleTranslator.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entitytupletranslators/NodeTupleTranslator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -17,7 +17,9 @@
 
 import java.io.IOException;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.metadata.MetadataException;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataPrimaryIndexes;
 import edu.uci.ics.asterix.metadata.bootstrap.MetadataRecordTypes;
 import edu.uci.ics.asterix.metadata.entities.Node;
@@ -80,7 +82,7 @@
     }
 
     @Override
-    public ITupleReference getTupleFromMetadataEntity(Node instance) throws IOException {
+    public ITupleReference getTupleFromMetadataEntity(Node instance) throws IOException, MetadataException {
         // write the key in the first field of the tuple
         tupleBuilder.reset();
         aString.setValue(instance.getNodeName());
@@ -121,7 +123,11 @@
         // listBuilder.write(fieldValue.getDataOutput());
         // recordBuilder.addField(3, fieldValue);
 
-        recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        try {
+            recordBuilder.write(tupleBuilder.getDataOutput(), true);
+        } catch (AsterixException e) {
+            throw new MetadataException(e);
+        }
         tupleBuilder.addFieldEndOffset();
         tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
         return tuple;
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java
index cead5f2..df41c6e 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/utils/DatasetUtils.java
@@ -1,5 +1,21 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.metadata.utils;
 
+import java.io.IOException;
 import java.util.List;
 
 import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
@@ -25,7 +41,12 @@
         List<String> partitioningKeys = getPartitioningKeys(dataset);
         IBinaryComparatorFactory[] bcfs = new IBinaryComparatorFactory[partitioningKeys.size()];
         for (int i = 0; i < partitioningKeys.size(); i++) {
-            IAType keyType = itemType.getFieldType(partitioningKeys.get(i));
+            IAType keyType;
+            try {
+                keyType = itemType.getFieldType(partitioningKeys.get(i));
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
+            }
             bcfs[i] = comparatorFactoryProvider.getBinaryComparatorFactory(keyType, true);
         }
         return bcfs;
@@ -39,7 +60,12 @@
         List<String> partitioningKeys = getPartitioningKeys(dataset);
         IBinaryHashFunctionFactory[] bhffs = new IBinaryHashFunctionFactory[partitioningKeys.size()];
         for (int i = 0; i < partitioningKeys.size(); i++) {
-            IAType keyType = itemType.getFieldType(partitioningKeys.get(i));
+            IAType keyType;
+            try {
+                keyType = itemType.getFieldType(partitioningKeys.get(i));
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
+            }
             bhffs[i] = hashFunProvider.getBinaryHashFunctionFactory(keyType);
         }
         return bhffs;
@@ -54,7 +80,12 @@
         int numKeys = partitioningKeys.size();
         ITypeTraits[] typeTraits = new ITypeTraits[numKeys + 1];
         for (int i = 0; i < numKeys; i++) {
-            IAType keyType = itemType.getFieldType(partitioningKeys.get(i));
+            IAType keyType;
+            try {
+                keyType = itemType.getFieldType(partitioningKeys.get(i));
+            } catch (IOException e) {
+                throw new AlgebricksException(e);
+            }
             typeTraits[i] = AqlTypeTraitProvider.INSTANCE.getTypeTrait(keyType);
         }
         typeTraits[numKeys] = AqlTypeTraitProvider.INSTANCE.getTypeTrait(itemType);
diff --git a/asterix-om/pom.xml b/asterix-om/pom.xml
index 8cceaa0..8ff3f84 100644
--- a/asterix-om/pom.xml
+++ b/asterix-om/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -14,8 +15,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 		</plugins>
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/builders/IARecordBuilder.java b/asterix-om/src/main/java/edu/uci/ics/asterix/builders/IARecordBuilder.java
index 544b532..7cdb9a9 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/builders/IARecordBuilder.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/builders/IARecordBuilder.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -18,6 +18,7 @@
 import java.io.DataOutput;
 import java.io.IOException;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.hyracks.data.std.api.IValueReference;
 
@@ -49,8 +50,10 @@
      *            The field name.
      * @param out
      *            The field value.
+     * @throws AsterixException
+     *             if the field name conflicts with a closed field name
      */
-    public void addField(IValueReference name, IValueReference value);
+    public void addField(IValueReference name, IValueReference value) throws AsterixException;
 
     /**
      * @param out
@@ -59,8 +62,10 @@
      *            Whether to write a typetag as part of the record's serialized
      *            representation.
      * @throws IOException
+     * @throws AsterixException
+     *             if any open field names conflict with each other
      */
-    public void write(DataOutput out, boolean writeTypeTag) throws IOException;
+    public void write(DataOutput out, boolean writeTypeTag) throws IOException, AsterixException;
 
     public int getFieldId(String fieldName);
 
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java b/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java
index 03f0e20..f5d07ae 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/builders/RecordBuilder.java
@@ -1,40 +1,46 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.builders;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Arrays;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.SerializerDeserializerUtil;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.asterix.om.util.NonTaggedFormatUtil;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
 import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunction;
+import edu.uci.ics.hyracks.data.std.accessors.PointableBinaryComparatorFactory;
 import edu.uci.ics.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory;
 import edu.uci.ics.hyracks.data.std.api.IValueReference;
 import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
 
 public class RecordBuilder implements IARecordBuilder {
-    private int openPartOffset;
+    private final static int DEFAULT_NUM_OPEN_FIELDS = 10;
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
 
-    private ARecordType recType;
-
-    private ByteArrayOutputStream closedPartOutputStream;
-    private int[] closedPartOffsets;
-    private int numberOfClosedFields;
-    private byte[] nullBitMap;
-    private int nullBitMapSize;
-
-    private ByteArrayOutputStream openPartOutputStream;
-    private long[] openPartOffsets;
-    private long[] tempOpenPartOffsets;
-
-    private int numberOfOpenFields;
-
-    private int fieldNameHashCode;
-    private final IBinaryHashFunction utf8HashFunction;
-
-    // for write()
     private int openPartOffsetArraySize;
     private byte[] openPartOffsetArray;
     private int offsetPosition;
@@ -42,25 +48,40 @@
     private boolean isOpen;
     private boolean isNullable;
     private int numberOfSchemaFields;
-    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
-    private final static byte RECORD_TYPE_TAG = ATypeTag.RECORD.serialize();
+
+    private int openPartOffset;
+    private ARecordType recType;
+
+    private final IBinaryHashFunction utf8HashFunction;
+    private final IBinaryComparator utf8Comparator;
+
+    private final ByteArrayOutputStream closedPartOutputStream;
+    private int[] closedPartOffsets;
+    private int numberOfClosedFields;
+    private byte[] nullBitMap;
+    private int nullBitMapSize;
+
+    private final ByteArrayAccessibleOutputStream openPartOutputStream;
+    private long[] openPartOffsets;
+    private int[] openFieldNameLengths;
+
+    private int numberOfOpenFields;
 
     public RecordBuilder() {
 
         this.closedPartOutputStream = new ByteArrayOutputStream();
         this.numberOfClosedFields = 0;
 
-        this.openPartOutputStream = new ByteArrayOutputStream();
-        this.openPartOffsets = new long[20];
-        this.tempOpenPartOffsets = new long[20];
-
+        this.openPartOutputStream = new ByteArrayAccessibleOutputStream();
+        this.openPartOffsets = new long[DEFAULT_NUM_OPEN_FIELDS];
+        this.openFieldNameLengths = new int[DEFAULT_NUM_OPEN_FIELDS];
         this.numberOfOpenFields = 0;
 
-        this.fieldNameHashCode = 0;
         this.utf8HashFunction = new PointableBinaryHashFunctionFactory(UTF8StringPointable.FACTORY)
                 .createBinaryHashFunction();
+        this.utf8Comparator = new PointableBinaryComparatorFactory(UTF8StringPointable.FACTORY)
+                .createBinaryComparator();
 
-        // for write()
         this.openPartOffsetArray = null;
         this.openPartOffsetArraySize = 0;
         this.offsetPosition = 0;
@@ -135,23 +156,31 @@
     }
 
     @Override
-    public void addField(IValueReference name, IValueReference value) {
+    public void addField(IValueReference name, IValueReference value) throws AsterixException {
         if (numberOfOpenFields == openPartOffsets.length) {
-            tempOpenPartOffsets = openPartOffsets;
-            openPartOffsets = new long[numberOfOpenFields + 20];
-            for (int i = 0; i < tempOpenPartOffsets.length; i++)
-                openPartOffsets[i] = tempOpenPartOffsets[i];
+            openPartOffsets = Arrays.copyOf(openPartOffsets, openPartOffsets.length + DEFAULT_NUM_OPEN_FIELDS);
+            openFieldNameLengths = Arrays.copyOf(openFieldNameLengths, openFieldNameLengths.length
+                    + DEFAULT_NUM_OPEN_FIELDS);
         }
-        fieldNameHashCode = utf8HashFunction.hash(name.getByteArray(), name.getStartOffset() + 1, name.getLength());
+        int fieldNameHashCode = utf8HashFunction.hash(name.getByteArray(), name.getStartOffset() + 1, name.getLength());
+        if (recType != null) {
+            int cFieldPos = recType.findFieldPosition(name.getByteArray(), name.getStartOffset() + 1,
+                    name.getLength() - 1);
+            if (cFieldPos >= 0) {
+                throw new AsterixException("Open field \"" + recType.getFieldNames()[cFieldPos]
+                        + "\" has the same field name as closed field at index " + cFieldPos);
+            }
+        }
         openPartOffsets[this.numberOfOpenFields] = fieldNameHashCode;
         openPartOffsets[this.numberOfOpenFields] = (openPartOffsets[numberOfOpenFields] << 32);
-        openPartOffsets[numberOfOpenFields++] += openPartOutputStream.size();
+        openPartOffsets[numberOfOpenFields] += openPartOutputStream.size();
+        openFieldNameLengths[numberOfOpenFields++] = name.getLength() - 1;
         openPartOutputStream.write(name.getByteArray(), name.getStartOffset() + 1, name.getLength() - 1);
         openPartOutputStream.write(value.getByteArray(), value.getStartOffset(), value.getLength());
     }
 
     @Override
-    public void write(DataOutput out, boolean writeTypeTag) throws IOException {
+    public void write(DataOutput out, boolean writeTypeTag) throws IOException, AsterixException {
         int h = headerSize;
         int recordLength;
         // prepare the open part
@@ -163,13 +192,27 @@
                 openPartOffsetArray = new byte[openPartOffsetArraySize];
 
             Arrays.sort(this.openPartOffsets, 0, numberOfOpenFields);
+            if (numberOfOpenFields > 1) {
+                byte[] openBytes = openPartOutputStream.getByteArray();
+                for (int i = 1; i < numberOfOpenFields; i++) {
+                    if (utf8Comparator.compare(openBytes, (int) openPartOffsets[i - 1], openFieldNameLengths[i - 1],
+                            openBytes, (int) openPartOffsets[i], openFieldNameLengths[i]) == 0) {
+                        String field = UTF8StringSerializerDeserializer.INSTANCE
+                                .deserialize(new DataInputStream(new ByteArrayInputStream(openBytes,
+                                        (int) openPartOffsets[i], openFieldNameLengths[i])));
+                        throw new AsterixException("Open fields " + (i - 1) + " and " + i
+                                + " have the same field name \"" + field + "\"");
+                    }
+                }
+            }
 
             openPartOffset = h + numberOfSchemaFields * 4 + closedPartOutputStream.size();
+            int fieldNameHashCode;
             for (int i = 0; i < numberOfOpenFields; i++) {
                 fieldNameHashCode = (int) (openPartOffsets[i] >> 32);
                 SerializerDeserializerUtil.writeIntToByteArray(openPartOffsetArray, (int) fieldNameHashCode,
                         offsetPosition);
-                int fieldOffset = (int) ((openPartOffsets[i] << 64) >> 64);
+                int fieldOffset = (int) openPartOffsets[i];
                 SerializerDeserializerUtil.writeIntToByteArray(openPartOffsetArray, fieldOffset + openPartOffset + 4
                         + openPartOffsetArraySize, offsetPosition + 4);
                 offsetPosition += 8;
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
index 393f634..a450f27 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARecordSerializerDeserializer.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -21,6 +21,7 @@
 
 import edu.uci.ics.asterix.builders.IARecordBuilder;
 import edu.uci.ics.asterix.builders.RecordBuilder;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryComparatorFactoryProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlBinaryHashFunctionFactoryProvider;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -149,7 +150,7 @@
             } else {
                 return new ARecord(this.recordType, closedFields);
             }
-        } catch (IOException e) {
+        } catch (IOException | AsterixException e) {
             throw new HyracksDataException(e);
         }
     }
@@ -166,7 +167,7 @@
         return fields;
     }
 
-    private ARecordType mergeRecordTypes(ARecordType recType1, ARecordType recType2) {
+    private ARecordType mergeRecordTypes(ARecordType recType1, ARecordType recType2) throws AsterixException {
 
         String[] fieldNames = new String[recType1.getFieldNames().length + recType2.getFieldNames().length];
         IAType[] fieldTypes = new IAType[recType1.getFieldTypes().length + recType2.getFieldTypes().length];
@@ -199,7 +200,7 @@
             }
             try {
                 recordBuilder.write(out, false);
-            } catch (IOException e) {
+            } catch (IOException | AsterixException e) {
                 throw new HyracksDataException(e);
             }
         } else {
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/base/DefaultOpenFieldType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/base/DefaultOpenFieldType.java
index 9184616..45ae5c5 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/base/DefaultOpenFieldType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/pointables/base/DefaultOpenFieldType.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -15,6 +15,8 @@
 
 package edu.uci.ics.asterix.om.pointables.base;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
+import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
 import edu.uci.ics.asterix.om.types.AOrderedListType;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.ATypeTag;
@@ -27,13 +29,19 @@
  * fields in the open part, e.g., a "record" (nested) field in the open part is
  * always a fully open one, and a "list" field in the open part is always a list
  * of "ANY".
- * 
  */
 public class DefaultOpenFieldType {
 
     // nested open field rec type
-    public static ARecordType NESTED_OPEN_RECORD_TYPE = new ARecordType("nested-open", new String[] {},
-            new IAType[] {}, true);
+    public static ARecordType NESTED_OPEN_RECORD_TYPE;
+
+    static {
+        try {
+            NESTED_OPEN_RECORD_TYPE = new ARecordType("nested-open", new String[] {}, new IAType[] {}, true);
+        } catch (AsterixException e) {
+            throw new AsterixRuntimeException();
+        }
+    }
 
     // nested open list type
     public static AOrderedListType NESTED_OPEN_AORDERED_LIST_TYPE = new AOrderedListType(BuiltinType.ANY,
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java
index daf7164..8ed2084 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ClosedRecordConstructorResultType.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -19,6 +19,7 @@
 
 import org.apache.commons.lang3.mutable.Mutable;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.AString;
 import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
@@ -49,7 +50,7 @@
         ARecordType type = (ARecordType) TypeComputerUtilities.getRequiredType(f);
         if (type != null)
             return type;
-        
+
         int n = f.getArguments().size() / 2;
         String[] fieldNames = new String[n];
         IAType[] fieldTypes = new IAType[n];
@@ -68,6 +69,10 @@
             fieldTypes[i] = (IAType) env.getType(e2);
             i++;
         }
-        return new ARecordType(null, fieldNames, fieldTypes, false);
+        try {
+            return new ARecordType(null, fieldNames, fieldTypes, false);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
     }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedLocalAvgTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedLocalAvgTypeComputer.java
index 8b54197..ee52425 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedLocalAvgTypeComputer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/NonTaggedLocalAvgTypeComputer.java
@@ -1,8 +1,24 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.om.typecomputer.impl;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.AUnionType;
@@ -23,7 +39,11 @@
         List<IAType> unionList = new ArrayList<IAType>();
         unionList.add(BuiltinType.ANULL);
         unionList.add(BuiltinType.ADOUBLE);
-        return new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
-                new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, false);
+        try {
+            return new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
+                    new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, false);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
     }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java
index c46c59b..0c6fc55 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OpenRecordConstructorResultType.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2010 by The Regents of the University of California
+ * Copyright 2009-2013 by The Regents of the University of California
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may obtain a copy of the License from
@@ -21,6 +21,7 @@
 
 import org.apache.commons.lang3.mutable.Mutable;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.AString;
 import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
@@ -72,6 +73,10 @@
         IAType[] fieldTypes = new IAType[n];
         fieldNames = namesList.toArray(fieldNames);
         fieldTypes = typesList.toArray(fieldTypes);
-        return new ARecordType(null, fieldNames, fieldTypes, true);
+        try {
+            return new ARecordType(null, fieldNames, fieldTypes, true);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
     }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/RecordConstructorResultType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/RecordConstructorResultType.java
index d20f43b..1f072f0 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/RecordConstructorResultType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/RecordConstructorResultType.java
@@ -1,9 +1,25 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.om.typecomputer.impl;
 
 import java.util.Iterator;
 
 import org.apache.commons.lang3.mutable.Mutable;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.AString;
 import edu.uci.ics.asterix.om.constants.AsterixConstantValue;
 import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
@@ -58,6 +74,10 @@
             }
             i++;
         }
-        return new ARecordType(null, fieldNames, fieldTypes, isOpen);
+        try {
+            return new ARecordType(null, fieldNames, fieldTypes, isOpen);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
     }
 }
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
index 1cf6ba7..ac1facc 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
@@ -1,15 +1,38 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.om.types;
 
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import edu.uci.ics.asterix.common.annotations.IRecordTypeAnnotation;
 import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.base.IAObject;
 import edu.uci.ics.asterix.om.visitors.IOMVisitor;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryComparator;
+import edu.uci.ics.hyracks.api.dataflow.value.IBinaryHashFunction;
+import edu.uci.ics.hyracks.data.std.accessors.PointableBinaryComparatorFactory;
+import edu.uci.ics.hyracks.data.std.accessors.PointableBinaryHashFunctionFactory;
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+import edu.uci.ics.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
+import edu.uci.ics.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer;
 
 public class ARecordType extends AbstractComplexType {
 
@@ -18,16 +41,110 @@
     private IAType[] fieldTypes;
     private boolean isOpen;
     private final List<IRecordTypeAnnotation> annotations = new ArrayList<IRecordTypeAnnotation>();
-    private final Map<String, Integer> typeMap = new HashMap<String, Integer>();
 
-    public ARecordType(String typeName, String[] fieldNames, IAType[] fieldTypes, boolean isOpen) {
+    private transient IBinaryHashFunction fieldNameHashFunction;
+    private transient IBinaryComparator fieldNameComparator;
+    private final byte serializedFieldNames[];
+    private final int serializedFieldNameOffsets[];
+    private final long hashCodeIndexPairs[];
+
+    /**
+     * @param typeName
+     *            the name of the type
+     * @param fieldNames
+     *            the names of the closed fields
+     * @param fieldTypes
+     *            the types of the closed fields
+     * @param isOpen
+     *            whether the record is open
+     * @throws AsterixException
+     *             if there are duplicate field names or if there is an error serializing the field names
+     */
+    public ARecordType(String typeName, String[] fieldNames, IAType[] fieldTypes, boolean isOpen)
+            throws AsterixException {
         super(typeName);
         this.fieldNames = fieldNames;
         this.fieldTypes = fieldTypes;
         this.isOpen = isOpen;
+
+        fieldNameComparator = new PointableBinaryComparatorFactory(UTF8StringPointable.FACTORY)
+                .createBinaryComparator();
+        fieldNameHashFunction = new PointableBinaryHashFunctionFactory(UTF8StringPointable.FACTORY)
+                .createBinaryHashFunction();
+        ByteArrayAccessibleOutputStream baaos = new ByteArrayAccessibleOutputStream();
+        DataOutputStream dos = new DataOutputStream(baaos);
+        serializedFieldNameOffsets = new int[fieldNames.length];
+        hashCodeIndexPairs = new long[fieldNames.length];
+
+        int length = 0;
         for (int i = 0; i < fieldNames.length; i++) {
-            typeMap.put(fieldNames[i], i);
+            serializedFieldNameOffsets[i] = baaos.size();
+            try {
+                dos.writeUTF(fieldNames[i]);
+            } catch (IOException e) {
+                throw new AsterixException(e);
+            }
+            length = baaos.size() - serializedFieldNameOffsets[i];
+            hashCodeIndexPairs[i] = fieldNameHashFunction.hash(baaos.getByteArray(), serializedFieldNameOffsets[i],
+                    length);
+            hashCodeIndexPairs[i] = hashCodeIndexPairs[i] << 32;
+            hashCodeIndexPairs[i] = hashCodeIndexPairs[i] | i;
         }
+        serializedFieldNames = baaos.getByteArray();
+
+        Arrays.sort(hashCodeIndexPairs);
+        int j;
+        for (int i = 0; i < fieldNames.length; i++) {
+            j = findFieldPosition(serializedFieldNames, serializedFieldNameOffsets[i],
+                    UTF8StringPointable.getStringLength(serializedFieldNames, serializedFieldNameOffsets[i]));
+            if (j != i) {
+                throw new AsterixException("Closed fields " + j + " and " + i + " have the same field name \""
+                        + fieldNames[i] + "\"");
+            }
+        }
+    }
+
+    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+        ois.defaultReadObject();
+        fieldNameComparator = new PointableBinaryComparatorFactory(UTF8StringPointable.FACTORY)
+                .createBinaryComparator();
+        fieldNameHashFunction = new PointableBinaryHashFunctionFactory(UTF8StringPointable.FACTORY)
+                .createBinaryHashFunction();
+    }
+
+    /**
+     * Returns the position of the field in the closed schema or -1 if the field does not exist.
+     * 
+     * @param bytes
+     *            the serialized bytes of the field name
+     * @param start
+     *            the starting offset of the field name in bytes
+     * @param length
+     *            the length of the field name in bytes
+     * @return the position of the field in the closed schema or -1 if the field does not exist.
+     */
+    public int findFieldPosition(byte[] bytes, int start, int length) {
+        if (hashCodeIndexPairs.length == 0) {
+            return -1;
+        }
+
+        int fIndex;
+        int probeFieldHash = fieldNameHashFunction.hash(bytes, start, length);
+        int i = Arrays.binarySearch(hashCodeIndexPairs, ((long) probeFieldHash) << 32);
+        i = (i < 0) ? (i = -1 * (i + 1)) : i;
+
+        while (i < hashCodeIndexPairs.length && (int) (hashCodeIndexPairs[i] >>> 32) == probeFieldHash) {
+            fIndex = (int) hashCodeIndexPairs[i];
+            int cFieldLength = UTF8StringPointable.getStringLength(serializedFieldNames,
+                    serializedFieldNameOffsets[fIndex]);
+            if (fieldNameComparator.compare(serializedFieldNames, serializedFieldNameOffsets[fIndex], cFieldLength,
+                    bytes, start, length) == 0) {
+                return fIndex;
+            }
+            i++;
+        }
+
+        return -1;
     }
 
     public final String[] getFieldNames() {
@@ -73,17 +190,22 @@
         return isOpen;
     }
 
-    public int findFieldPosition(String fldName) {
-        for (int i = 0; i < fieldNames.length; i++) {
-            if (fieldNames[i].equals(fldName)) {
-                return i;
-            }
-        }
-        return -1;
+    /**
+     * Returns the position of the field in the closed schema or -1 if the field does not exist.
+     * 
+     * @param fieldName
+     *            the name of the field whose position is sought
+     * @return the position of the field in the closed schema or -1 if the field does not exist.
+     */
+    public int findFieldPosition(String fieldName) throws IOException {
+        ByteArrayAccessibleOutputStream baaos = new ByteArrayAccessibleOutputStream();
+        DataOutputStream dos = new DataOutputStream(baaos);
+        UTF8StringSerializerDeserializer.INSTANCE.serialize(fieldName, dos);
+        return findFieldPosition(baaos.getByteArray(), 0, baaos.getByteArray().length);
     }
 
-    public IAType getFieldType(String fieldName) {
-        return fieldTypes[typeMap.get(fieldName)];
+    public IAType getFieldType(String fieldName) throws IOException {
+        return fieldTypes[findFieldPosition(fieldName)];
     }
 
     @Override
@@ -115,12 +237,11 @@
     public int hash() {
         int h = 0;
         for (int i = 0; i < fieldNames.length; i++) {
-            h += 31 * h + fieldNames[i].hashCode();
+            h += 31 * h + (int) (hashCodeIndexPairs[i] >> 32);
         }
         for (int i = 0; i < fieldTypes.length; i++) {
             h += 31 * h + fieldTypes[i].hashCode();
         }
         return h;
     }
-
 }
diff --git a/asterix-runtime/pom.xml b/asterix-runtime/pom.xml
index 93b38df..be64661 100644
--- a/asterix-runtime/pom.xml
+++ b/asterix-runtime/pom.xml
@@ -16,27 +16,84 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
-			<plugin>
-				<groupId>org.codehaus.mojo</groupId>
-				<artifactId>javacc-maven-plugin</artifactId>
-				<version>2.6</version>
-				<executions>
-					<execution>
-						<id>javacc</id>
-						<goals>
-							<goal>javacc</goal>
-						</goals>
-						<configuration>
-							<isStatic>false</isStatic>
-						</configuration>
-					</execution>
-				</executions>
-			</plugin>
-		</plugins>
+	      	<plugin>
+	        	<groupId>edu.uci.ics.asterix</groupId>
+	        	<artifactId>lexer-generator-maven-plugin</artifactId>
+	        	<version>0.1</version>
+	        	<configuration>
+	        	  	<grammarFile>src/main/resources/adm.grammar</grammarFile>
+	        	  	<outputDir>${project.build.directory}/generated-sources/edu/uci/ics/asterix/runtime/operators/file/adm</outputDir>
+	        	</configuration>
+	        	<executions>
+		          	<execution>
+		          		<id>generate-lexer</id>
+            			<phase>generate-sources</phase>
+			            <goals>
+	              			<goal>generate-lexer</goal>
+	            		</goals>
+	          		</execution>
+	        	</executions>
+	      	</plugin>
+	      	 <plugin>
+			    <groupId>org.codehaus.mojo</groupId>
+			    <artifactId>build-helper-maven-plugin</artifactId>
+			    <executions>
+			        <execution>
+			            <id>add-source</id>
+			            <phase>generate-sources</phase>
+			            <goals>
+			                <goal>add-source</goal>
+			            </goals>
+			            <configuration>
+			                <sources>
+			                    <source>${project.build.directory}/generated-sources/</source>
+			                </sources>
+			            </configuration>
+			        </execution>
+			    </executions>
+ 			</plugin>
+	    </plugins>
+		<pluginManagement>
+			<plugins>
+				<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+				<plugin>
+					<groupId>org.eclipse.m2e</groupId>
+					<artifactId>lifecycle-mapping</artifactId>
+					<version>1.0.0</version>
+					<configuration>
+						<lifecycleMappingMetadata>
+							<pluginExecutions>
+								<pluginExecution>
+									<pluginExecutionFilter>
+										<groupId>
+											edu.uci.ics.asterix
+										</groupId>
+										<artifactId>
+											lexer-generator-maven-plugin
+										</artifactId>
+										<versionRange>
+											[0.1,)
+										</versionRange>
+										<goals>
+											<goal>generate-lexer</goal>
+										</goals>
+									</pluginExecutionFilter>
+									<action>
+										<execute>
+											<runOnIncremental>false</runOnIncremental>
+										</execute>
+									</action>
+								</pluginExecution>
+							</pluginExecutions>
+						</lifecycleMappingMetadata>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
 	</build>
 
 	<dependencies>
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java
index 89081ab..f720434 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableGlobalAvgAggregateDescriptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.runtime.aggregates.serializable.std;
 
 import java.io.DataOutput;
@@ -6,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
@@ -59,8 +75,15 @@
         List<IAType> unionList = new ArrayList<IAType>();
         unionList.add(BuiltinType.ANULL);
         unionList.add(BuiltinType.ADOUBLE);
-        final ARecordType recType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
-                new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT64 }, true);
+        ARecordType _recType;
+        try {
+            _recType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
+                    new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT64 }, true);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
+
+        final ARecordType recType = _recType;
 
         return new ICopySerializableAggregateFunctionFactory() {
             private static final long serialVersionUID = 1L;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java
index 41047f7..219204b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/serializable/std/SerializableLocalAvgAggregateDescriptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.runtime.aggregates.serializable.std;
 
 import java.io.DataOutput;
@@ -6,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
@@ -63,8 +79,15 @@
         List<IAType> unionList = new ArrayList<IAType>();
         unionList.add(BuiltinType.ANULL);
         unionList.add(BuiltinType.ADOUBLE);
-        final ARecordType recType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
-                new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT64 }, true);
+        ARecordType tmpRecType;
+        try {
+            tmpRecType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
+                    new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT64 }, true);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
+
+        final ARecordType recType = tmpRecType;
 
         return new ICopySerializableAggregateFunctionFactory() {
             private static final long serialVersionUID = 1L;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java
index 4fe5e35..93c7026 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/AvgAggregateDescriptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.runtime.aggregates.std;
 
 import java.io.DataOutput;
@@ -7,6 +22,7 @@
 import java.util.List;
 
 import edu.uci.ics.asterix.common.config.GlobalConfig;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
@@ -64,8 +80,15 @@
         List<IAType> unionList = new ArrayList<IAType>();
         unionList.add(BuiltinType.ANULL);
         unionList.add(BuiltinType.ADOUBLE);
-        final ARecordType recType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
-                new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, true);
+        ARecordType tmpRecType;
+        try {
+            tmpRecType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
+                    new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, true);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
+
+        final ARecordType recType = tmpRecType;
 
         return new ICopyAggregateFunctionFactory() {
             private static final long serialVersionUID = 1L;
@@ -78,7 +101,7 @@
 
                     private DataOutput out = provider.getDataOutput();
                     private ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval = args[0].createEvaluator(inputVal);                    
+                    private ICopyEvaluator eval = args[0].createEvaluator(inputVal);
                     private double sum;
                     private int count;
                     private ATypeTag aggType;
@@ -115,13 +138,13 @@
                     @Override
                     public void step(IFrameTupleReference tuple) throws AlgebricksException {
                         inputVal.reset();
-                        eval.evaluate(tuple);                        
+                        eval.evaluate(tuple);
                         ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER
                                 .deserialize(inputVal.getByteArray()[0]);
                         if (typeTag == ATypeTag.NULL || aggType == ATypeTag.NULL) {
                             aggType = ATypeTag.NULL;
                             return;
-                        } else if (aggType == ATypeTag.SYSTEM_NULL) {                           
+                        } else if (aggType == ATypeTag.SYSTEM_NULL) {
                             aggType = typeTag;
                         } else if (typeTag != ATypeTag.SYSTEM_NULL && typeTag != aggType) {
                             throw new AlgebricksException("Unexpected type " + typeTag
@@ -129,7 +152,7 @@
                         }
                         if (typeTag != ATypeTag.SYSTEM_NULL) {
                             ++count;
-                        }                        
+                        }
                         switch (typeTag) {
                             case INT8: {
                                 byte val = AInt8SerializerDeserializer.getByte(inputVal.getByteArray(), 1);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java
index 347f5e7..d262ef4 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/GlobalAvgAggregateDescriptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.runtime.aggregates.std;
 
 import java.io.DataOutput;
@@ -6,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
@@ -61,8 +76,15 @@
         List<IAType> unionList = new ArrayList<IAType>();
         unionList.add(BuiltinType.ANULL);
         unionList.add(BuiltinType.ADOUBLE);
-        final ARecordType recType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
-                new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, false);
+        ARecordType tmpRecType;
+        try {
+            tmpRecType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
+                    new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, false);
+        } catch (AsterixException e) {
+            throw new AlgebricksException(e);
+        }
+
+        final ARecordType recType = tmpRecType;
 
         return new ICopyAggregateFunctionFactory() {
             private static final long serialVersionUID = 1L;
@@ -114,7 +136,7 @@
                         inputVal.reset();
                         eval.evaluate(tuple);
                         byte[] serBytes = inputVal.getByteArray();
-                        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[0]);                        
+                        ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serBytes[0]);
                         switch (typeTag) {
                             case NULL: {
                                 metNull = true;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java
index de02246..5400d78 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/aggregates/std/LocalAvgAggregateDescriptor.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.runtime.aggregates.std;
 
 import java.io.DataOutput;
@@ -6,7 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
@@ -72,8 +87,15 @@
                 List<IAType> unionList = new ArrayList<IAType>();
                 unionList.add(BuiltinType.ANULL);
                 unionList.add(BuiltinType.ADOUBLE);
-                final ARecordType recType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
-                        new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, false);
+                ARecordType tmpRecType;
+                try {
+                    tmpRecType = new ARecordType(null, new String[] { "sum", "count" }, new IAType[] {
+                            new AUnionType(unionList, "OptionalDouble"), BuiltinType.AINT32 }, false);
+                } catch (AsterixException e) {
+                    throw new AlgebricksException(e);
+                }
+
+                final ARecordType recType = tmpRecType;
 
                 return new ICopyAggregateFunction() {
 
@@ -204,5 +226,4 @@
             }
         };
     }
-
 }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/ClosedRecordConstructorEvalFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/ClosedRecordConstructorEvalFactory.java
index 38983e2..db3bc40 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/ClosedRecordConstructorEvalFactory.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/common/ClosedRecordConstructorEvalFactory.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.runtime.evaluators.common;
 
 import java.io.DataOutput;
@@ -5,6 +20,7 @@
 
 import edu.uci.ics.asterix.builders.IARecordBuilder;
 import edu.uci.ics.asterix.builders.RecordBuilder;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.types.ARecordType;
 import edu.uci.ics.asterix.om.types.ATypeTag;
 import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -72,8 +88,8 @@
                     }
                 }
                 recBuilder.write(out, true);
-            } catch (IOException ioe) {
-                throw new AlgebricksException(ioe);
+            } catch (IOException | AsterixException e) {
+                throw new AlgebricksException(e);
             }
         }
     }
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
index 77869ba..81ae62b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/OpenRecordConstructorDescriptor.java
@@ -1,9 +1,25 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * you may obtain a copy of the License from
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package edu.uci.ics.asterix.runtime.evaluators.functions;
 
 import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.builders.RecordBuilder;
+import edu.uci.ics.asterix.common.exceptions.AsterixException;
 import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
 import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
@@ -86,8 +102,8 @@
                                 }
                             }
                             recBuilder.write(out, true);
-                        } catch (IOException ioe) {
-                            throw new AlgebricksException(ioe);
+                        } catch (IOException | AsterixException e) {
+                            throw new AlgebricksException(e);
                         }
                     }
                 };
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
index 8606088..2e64ad4 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
@@ -22,10 +22,8 @@
 import java.util.List;
 import java.util.Queue;
 
-import edu.uci.ics.asterix.adm.parser.nontagged.AdmLexer;
-import edu.uci.ics.asterix.adm.parser.nontagged.AdmLexerConstants;
-import edu.uci.ics.asterix.adm.parser.nontagged.ParseException;
-import edu.uci.ics.asterix.adm.parser.nontagged.Token;
+import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexer;
+import edu.uci.ics.asterix.runtime.operators.file.adm.AdmLexerException;
 import edu.uci.ics.asterix.builders.IARecordBuilder;
 import edu.uci.ics.asterix.builders.IAsterixListBuilder;
 import edu.uci.ics.asterix.builders.OrderedListBuilder;
@@ -36,6 +34,7 @@
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ALineSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APoint3DSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
@@ -55,7 +54,7 @@
 import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
 /**
- * Parser for ADM formatted data. 
+ * Parser for ADM formatted data.
  */
 public class ADMDataParser extends AbstractDataParser implements IDataParser {
 
@@ -82,21 +81,25 @@
     }
 
     @Override
-    public void initialize(InputStream in, ARecordType recordType, boolean datasetRec) {
-        admLexer = new AdmLexer(in);
+    public void initialize(InputStream in, ARecordType recordType, boolean datasetRec) throws AsterixException {
         this.recordType = recordType;
         this.datasetRec = datasetRec;
+        try {
+            admLexer = new AdmLexer(new java.io.InputStreamReader(in));
+        } catch (IOException e) {
+            throw new AsterixException(e);
+        }
     }
 
     protected boolean parseAdmInstance(IAType objectType, boolean datasetRec, DataOutput out) throws AsterixException,
             IOException {
-        Token token;
+        int token;
         try {
             token = admLexer.next();
-        } catch (ParseException pe) {
-            throw new AsterixException(pe);
+        } catch (AdmLexerException e) {
+            throw new AsterixException(e);
         }
-        if (token.kind == AdmLexerConstants.EOF) {
+        if (token == AdmLexer.TOKEN_EOF) {
             return false;
         } else {
             admFromLexerStream(token, objectType, out, datasetRec);
@@ -104,157 +107,212 @@
         }
     }
 
-    private void admFromLexerStream(Token token, IAType objectType, DataOutput out, Boolean datasetRec)
+    private void admFromLexerStream(int token, IAType objectType, DataOutput out, Boolean datasetRec)
             throws AsterixException, IOException {
 
-        switch (token.kind) {
-            case AdmLexerConstants.NULL_LITERAL: {
+        switch (token) {
+            case AdmLexer.TOKEN_NULL_LITERAL: {
                 if (checkType(ATypeTag.NULL, objectType, out)) {
                     nullSerde.serialize(ANull.NULL, out);
                 } else
                     throw new AsterixException(" This field can not be null ");
                 break;
             }
-            case AdmLexerConstants.TRUE_LITERAL: {
+            case AdmLexer.TOKEN_TRUE_LITERAL: {
                 if (checkType(ATypeTag.BOOLEAN, objectType, out)) {
                     booleanSerde.serialize(ABoolean.TRUE, out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.BOOLEAN_CONS: {
+            case AdmLexer.TOKEN_BOOLEAN_CONS: {
                 parseConstructor(ATypeTag.BOOLEAN, objectType, out);
                 break;
             }
-            case AdmLexerConstants.FALSE_LITERAL: {
+            case AdmLexer.TOKEN_FALSE_LITERAL: {
                 if (checkType(ATypeTag.BOOLEAN, objectType, out)) {
                     booleanSerde.serialize(ABoolean.FALSE, out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.DOUBLE_LITERAL: {
+            case AdmLexer.TOKEN_DOUBLE_LITERAL: {
                 if (checkType(ATypeTag.DOUBLE, objectType, out)) {
-                    aDouble.setValue(Double.parseDouble(token.image));
+                    aDouble.setValue(Double.parseDouble(admLexer.getLastTokenImage()));
                     doubleSerde.serialize(aDouble, out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.DOUBLE_CONS: {
+            case AdmLexer.TOKEN_DOUBLE_CONS: {
                 parseConstructor(ATypeTag.DOUBLE, objectType, out);
                 break;
             }
-            case AdmLexerConstants.FLOAT_LITERAL: {
+            case AdmLexer.TOKEN_FLOAT_LITERAL: {
                 if (checkType(ATypeTag.FLOAT, objectType, out)) {
-                    aFloat.setValue(Float.parseFloat(token.image));
+                    aFloat.setValue(Float.parseFloat(admLexer.getLastTokenImage()));
                     floatSerde.serialize(aFloat, out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.FLOAT_CONS: {
+            case AdmLexer.TOKEN_FLOAT_CONS: {
                 parseConstructor(ATypeTag.FLOAT, objectType, out);
                 break;
             }
-            case AdmLexerConstants.INT8_LITERAL: {
+            case AdmLexer.TOKEN_INT8_LITERAL: {
                 if (checkType(ATypeTag.INT8, objectType, out)) {
-                    parseInt8(token.image, out);
+                    parseInt8(admLexer.getLastTokenImage(), out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.INT8_CONS: {
+            case AdmLexer.TOKEN_INT8_CONS: {
                 parseConstructor(ATypeTag.INT8, objectType, out);
                 break;
             }
-            case AdmLexerConstants.INT16_LITERAL: {
+            case AdmLexer.TOKEN_INT16_LITERAL: {
                 if (checkType(ATypeTag.INT16, objectType, out)) {
-                    parseInt16(token.image, out);
+                    parseInt16(admLexer.getLastTokenImage(), out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.INT16_CONS: {
+            case AdmLexer.TOKEN_INT16_CONS: {
                 parseConstructor(ATypeTag.INT16, objectType, out);
                 break;
             }
-            case AdmLexerConstants.INT_LITERAL:
-            case AdmLexerConstants.INT32_LITERAL: {
+            case AdmLexer.TOKEN_INT_LITERAL:
+            case AdmLexer.TOKEN_INT32_LITERAL: {
                 if (checkType(ATypeTag.INT32, objectType, out)) {
-                    parseInt32(token.image, out);
+                    parseInt32(admLexer.getLastTokenImage(), out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.INT32_CONS: {
+            case AdmLexer.TOKEN_INT32_CONS: {
                 parseConstructor(ATypeTag.INT32, objectType, out);
                 break;
             }
-            case AdmLexerConstants.INT64_LITERAL: {
+            case AdmLexer.TOKEN_INT64_LITERAL: {
                 if (checkType(ATypeTag.INT64, objectType, out)) {
-                    parseInt64(token.image, out);
+                    parseInt64(admLexer.getLastTokenImage(), out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.INT64_CONS: {
+            case AdmLexer.TOKEN_INT64_CONS: {
                 parseConstructor(ATypeTag.INT64, objectType, out);
                 break;
             }
-            case AdmLexerConstants.STRING_LITERAL: {
+            case AdmLexer.TOKEN_STRING_LITERAL: {
                 if (checkType(ATypeTag.STRING, objectType, out)) {
-                    aString.setValue(token.image.substring(1, token.image.length() - 1));
+                    aString.setValue(admLexer.getLastTokenImage().substring(1,
+                            admLexer.getLastTokenImage().length() - 1));
                     stringSerde.serialize(aString, out);
                 } else
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeName());
                 break;
             }
-            case AdmLexerConstants.STRING_CONS: {
+            case AdmLexer.TOKEN_STRING_CONS: {
                 parseConstructor(ATypeTag.STRING, objectType, out);
                 break;
             }
-            case AdmLexerConstants.DATE_CONS: {
+            case AdmLexer.TOKEN_DATE_CONS: {
                 parseConstructor(ATypeTag.DATE, objectType, out);
                 break;
             }
-            case AdmLexerConstants.TIME_CONS: {
+            case AdmLexer.TOKEN_TIME_CONS: {
                 parseConstructor(ATypeTag.TIME, objectType, out);
                 break;
             }
-            case AdmLexerConstants.DATETIME_CONS: {
+            case AdmLexer.TOKEN_DATETIME_CONS: {
                 parseConstructor(ATypeTag.DATETIME, objectType, out);
                 break;
             }
-            case AdmLexerConstants.DURATION_CONS: {
+            case AdmLexer.TOKEN_INTERVAL_DATE_CONS: {
+                try {
+                    if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+                        if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+                            if (admLexer.next() == AdmLexer.TOKEN_STRING_CONS) {
+                                AIntervalSerializerDeserializer.parseDate(admLexer.getLastTokenImage(), out);
+
+                                if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                } catch (AdmLexerException ex) {
+                    throw new AsterixException(ex);
+                }
+                throw new AsterixException("Wrong interval data parsing for date interval.");
+            }
+            case AdmLexer.TOKEN_INTERVAL_TIME_CONS: {
+                try {
+                    if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+                        if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+                            if (admLexer.next() == AdmLexer.TOKEN_STRING_CONS) {
+                                AIntervalSerializerDeserializer.parseTime(admLexer.getLastTokenImage(), out);
+
+                                if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                } catch (AdmLexerException ex) {
+                    throw new AsterixException(ex);
+                }
+                throw new AsterixException("Wrong interval data parsing for time interval.");
+            }
+            case AdmLexer.TOKEN_INTERVAL_DATETIME_CONS: {
+                try {
+                    if (checkType(ATypeTag.INTERVAL, objectType, out)) {
+                        if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
+                            if (admLexer.next() == AdmLexer.TOKEN_STRING_CONS) {
+                                AIntervalSerializerDeserializer.parseDatetime(admLexer.getLastTokenImage(), out);
+
+                                if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                } catch (AdmLexerException ex) {
+                    throw new AsterixException(ex);
+                }
+                throw new AsterixException("Wrong interval data parsing for datetime interval.");
+            }
+            case AdmLexer.TOKEN_DURATION_CONS: {
                 parseConstructor(ATypeTag.DURATION, objectType, out);
                 break;
             }
-            case AdmLexerConstants.POINT_CONS: {
+            case AdmLexer.TOKEN_POINT_CONS: {
                 parseConstructor(ATypeTag.POINT, objectType, out);
                 break;
             }
-            case AdmLexerConstants.POINT3D_CONS: {
+            case AdmLexer.TOKEN_POINT3D_CONS: {
                 parseConstructor(ATypeTag.POINT3D, objectType, out);
                 break;
             }
-            case AdmLexerConstants.CIRCLE_CONS: {
+            case AdmLexer.TOKEN_CIRCLE_CONS: {
                 parseConstructor(ATypeTag.CIRCLE, objectType, out);
                 break;
             }
-            case AdmLexerConstants.RECTANGLE_CONS: {
+            case AdmLexer.TOKEN_RECTANGLE_CONS: {
                 parseConstructor(ATypeTag.RECTANGLE, objectType, out);
                 break;
             }
-            case AdmLexerConstants.LINE_CONS: {
+            case AdmLexer.TOKEN_LINE_CONS: {
                 parseConstructor(ATypeTag.LINE, objectType, out);
                 break;
             }
-            case AdmLexerConstants.POLYGON_CONS: {
+            case AdmLexer.TOKEN_POLYGON_CONS: {
                 parseConstructor(ATypeTag.POLYGON, objectType, out);
                 break;
             }
-            case AdmLexerConstants.START_UNORDERED_LIST: {
+            case AdmLexer.TOKEN_START_UNORDERED_LIST: {
                 if (checkType(ATypeTag.UNORDEREDLIST, objectType, out)) {
                     objectType = getComplexType(objectType, ATypeTag.UNORDEREDLIST);
                     parseUnorderedList((AUnorderedListType) objectType, out);
@@ -263,7 +321,7 @@
                 break;
             }
 
-            case AdmLexerConstants.START_ORDERED_LIST: {
+            case AdmLexer.TOKEN_START_ORDERED_LIST: {
                 if (checkType(ATypeTag.ORDEREDLIST, objectType, out)) {
                     objectType = getComplexType(objectType, ATypeTag.ORDEREDLIST);
                     parseOrderedList((AOrderedListType) objectType, out);
@@ -271,7 +329,7 @@
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeTag());
                 break;
             }
-            case AdmLexerConstants.START_RECORD: {
+            case AdmLexer.TOKEN_START_RECORD: {
                 if (checkType(ATypeTag.RECORD, objectType, out)) {
                     objectType = getComplexType(objectType, ATypeTag.RECORD);
                     parseRecord((ARecordType) objectType, out, datasetRec);
@@ -279,11 +337,11 @@
                     throw new AsterixException(mismatchErrorMessage + objectType.getTypeTag());
                 break;
             }
-            case AdmLexerConstants.EOF: {
+            case AdmLexer.TOKEN_EOF: {
                 break;
             }
             default: {
-                throw new AsterixException("Unexpected ADM token kind: " + admLexer.tokenKindToString(token.kind) + ".");
+                throw new AsterixException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token) + ".");
             }
         }
     }
@@ -365,7 +423,7 @@
             recBuilder.reset(null);
 
         recBuilder.init();
-        Token token = null;
+        int token;
         boolean inRecord = true;
         boolean expectingRecordField = false;
         boolean first = true;
@@ -375,15 +433,15 @@
         IAType fieldType = null;
         do {
             token = nextToken();
-            switch (token.kind) {
-                case AdmLexerConstants.END_RECORD: {
+            switch (token) {
+                case AdmLexer.TOKEN_END_RECORD: {
                     if (expectingRecordField) {
                         throw new AsterixException("Found END_RECORD while expecting a record field.");
                     }
                     inRecord = false;
                     break;
                 }
-                case AdmLexerConstants.STRING_LITERAL: {
+                case AdmLexer.TOKEN_STRING_LITERAL: {
                     // we've read the name of the field
                     // now read the content
                     fieldNameBuffer.reset();
@@ -391,12 +449,14 @@
                     expectingRecordField = false;
 
                     if (recType != null) {
-                        String fldName = token.image.substring(1, token.image.length() - 1);
+                        String fldName = admLexer.getLastTokenImage().substring(1,
+                                admLexer.getLastTokenImage().length() - 1);
                         fieldId = recBuilder.getFieldId(fldName);
                         if (fieldId < 0 && !recType.isOpen()) {
                             throw new AsterixException("This record is closed, you can not add extra fields !!");
                         } else if (fieldId < 0 && recType.isOpen()) {
-                            aStringFieldName.setValue(token.image.substring(1, token.image.length() - 1));
+                            aStringFieldName.setValue(admLexer.getLastTokenImage().substring(1,
+                                    admLexer.getLastTokenImage().length() - 1));
                             stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput());
                             openRecordField = true;
                             fieldType = null;
@@ -407,16 +467,17 @@
                             openRecordField = false;
                         }
                     } else {
-                        aStringFieldName.setValue(token.image.substring(1, token.image.length() - 1));
+                        aStringFieldName.setValue(admLexer.getLastTokenImage().substring(1,
+                                admLexer.getLastTokenImage().length() - 1));
                         stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput());
                         openRecordField = true;
                         fieldType = null;
                     }
 
                     token = nextToken();
-                    if (token.kind != AdmLexerConstants.COLON) {
-                        throw new AsterixException("Unexpected ADM token kind: "
-                                + admLexer.tokenKindToString(token.kind) + " while expecting \":\".");
+                    if (token != AdmLexer.TOKEN_COLON) {
+                        throw new AsterixException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
+                                + " while expecting \":\".");
                     }
 
                     token = nextToken();
@@ -436,7 +497,7 @@
 
                     break;
                 }
-                case AdmLexerConstants.COMMA: {
+                case AdmLexer.TOKEN_COMMA: {
                     if (first) {
                         throw new AsterixException("Found COMMA before any record field.");
                     }
@@ -447,7 +508,7 @@
                     break;
                 }
                 default: {
-                    throw new AsterixException("Unexpected ADM token kind: " + admLexer.tokenKindToString(token.kind)
+                    throw new AsterixException("Unexpected ADM token kind: " + AdmLexer.tokenKindToString(token)
                             + " while parsing record fields.");
                 }
             }
@@ -498,18 +559,18 @@
             itemType = oltype.getItemType();
         orderedListBuilder.reset(oltype);
 
-        Token token = null;
+        int token;
         boolean inList = true;
         boolean expectingListItem = false;
         boolean first = true;
         do {
             token = nextToken();
-            if (token.kind == AdmLexerConstants.END_ORDERED_LIST) {
+            if (token == AdmLexer.TOKEN_END_ORDERED_LIST) {
                 if (expectingListItem) {
                     throw new AsterixException("Found END_COLLECTION while expecting a list item.");
                 }
                 inList = false;
-            } else if (token.kind == AdmLexerConstants.COMMA) {
+            } else if (token == AdmLexer.TOKEN_COMMA) {
                 if (first) {
                     throw new AsterixException("Found COMMA before any list item.");
                 }
@@ -542,18 +603,18 @@
             itemType = uoltype.getItemType();
         unorderedListBuilder.reset(uoltype);
 
-        Token token = null;
+        int token;
         boolean inList = true;
         boolean expectingListItem = false;
         boolean first = true;
         do {
             token = nextToken();
-            if (token.kind == AdmLexerConstants.END_UNORDERED_LIST) {
+            if (token == AdmLexer.TOKEN_END_UNORDERED_LIST) {
                 if (expectingListItem) {
                     throw new AsterixException("Found END_COLLECTION while expecting a list item.");
                 }
                 inList = false;
-            } else if (token.kind == AdmLexerConstants.COMMA) {
+            } else if (token == AdmLexer.TOKEN_COMMA) {
                 if (first) {
                     throw new AsterixException("Found COMMA before any list item.");
                 }
@@ -574,11 +635,13 @@
         returnTempBuffer(itemBuffer);
     }
 
-    private Token nextToken() throws AsterixException {
+    private int nextToken() throws AsterixException {
         try {
             return admLexer.next();
-        } catch (ParseException pe) {
-            throw new AsterixException(pe);
+        } catch (AdmLexerException e) {
+            throw new AsterixException(e);
+        } catch (IOException e) {
+            throw new AsterixException(e);
         }
     }
 
@@ -633,73 +696,109 @@
 
     private void parseConstructor(ATypeTag typeTag, IAType objectType, DataOutput out) throws AsterixException {
         try {
-            Token token = admLexer.next();
-            if (token.kind == AdmLexerConstants.CONSTRUCTOR_OPEN) {
+            int token = admLexer.next();
+            if (token == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
                 if (checkType(typeTag, objectType, out)) {
                     token = admLexer.next();
-                    if (token.kind == AdmLexerConstants.STRING_LITERAL) {
+                    if (token == AdmLexer.TOKEN_STRING_LITERAL) {
                         switch (typeTag) {
                             case BOOLEAN:
-                                parseBoolean(token.image.substring(1, token.image.length() - 1), out);
+                                parseBoolean(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case INT8:
-                                parseInt8(token.image.substring(1, token.image.length() - 1), out);
+                                parseInt8(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case INT16:
-                                parseInt16(token.image.substring(1, token.image.length() - 1), out);
+                                parseInt16(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case INT32:
-                                parseInt32(token.image.substring(1, token.image.length() - 1), out);
+                                parseInt32(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case INT64:
-                                parseInt64(token.image.substring(1, token.image.length() - 1), out);
+                                parseInt64(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case FLOAT:
-                                aFloat.setValue(Float.parseFloat(token.image.substring(1, token.image.length() - 1)));
+                                aFloat.setValue(Float.parseFloat(admLexer.getLastTokenImage().substring(1,
+                                        admLexer.getLastTokenImage().length() - 1)));
                                 floatSerde.serialize(aFloat, out);
                                 break;
                             case DOUBLE:
-                                aDouble.setValue(Double.parseDouble(token.image.substring(1, token.image.length() - 1)));
+                                aDouble.setValue(Double.parseDouble(admLexer.getLastTokenImage().substring(1,
+                                        admLexer.getLastTokenImage().length() - 1)));
                                 doubleSerde.serialize(aDouble, out);
                                 break;
                             case STRING:
-                                aString.setValue(token.image.substring(1, token.image.length() - 1));
+                                aString.setValue(admLexer.getLastTokenImage().substring(1,
+                                        admLexer.getLastTokenImage().length() - 1));
                                 stringSerde.serialize(aString, out);
                                 break;
                             case TIME:
-                                parseTime(token.image.substring(1, token.image.length() - 1), out);
+                                parseTime(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case DATE:
-                                parseDate(token.image.substring(1, token.image.length() - 1), out);
+                                parseDate(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case DATETIME:
-                                parseDatetime(token.image.substring(1, token.image.length() - 1), out);
+                                parseDatetime(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case DURATION:
-                                parseDuration(token.image.substring(1, token.image.length() - 1), out);
+                                parseDuration(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case POINT:
-                                parsePoint(token.image.substring(1, token.image.length() - 1), out);
+                                parsePoint(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case POINT3D:
-                                parsePoint3d(token.image.substring(1, token.image.length() - 1), out);
+                                parsePoint3d(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case CIRCLE:
-                                parseCircle(token.image.substring(1, token.image.length() - 1), out);
+                                parseCircle(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case RECTANGLE:
-                                parseRectangle(token.image.substring(1, token.image.length() - 1), out);
+                                parseRectangle(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case LINE:
-                                parseLine(token.image.substring(1, token.image.length() - 1), out);
+                                parseLine(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
                             case POLYGON:
-                                parsePolygon(token.image.substring(1, token.image.length() - 1), out);
+                                parsePolygon(
+                                        admLexer.getLastTokenImage().substring(1,
+                                                admLexer.getLastTokenImage().length() - 1), out);
                                 break;
+                            default:
+                                throw new AsterixException("Missing deserializer method for constructor: "
+                                        + AdmLexer.tokenKindToString(token) + ".");
 
                         }
                         token = admLexer.next();
-                        if (token.kind == AdmLexerConstants.CONSTRUCTOR_CLOSE)
+                        if (token == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE)
                             return;
                     }
                 }
diff --git a/asterix-runtime/src/main/javacc/AdmLexer.jj b/asterix-runtime/src/main/javacc/AdmLexer.jj
deleted file mode 100644
index fbab62f..0000000
--- a/asterix-runtime/src/main/javacc/AdmLexer.jj
+++ /dev/null
@@ -1,150 +0,0 @@
-options {
-
-	  
-       STATIC = false;
-	
-}
-
-PARSER_BEGIN(AdmLexer)
-
-package edu.uci.ics.asterix.adm.parser;
-
-import java.io.*;
-
-public class AdmLexer {
-
-	public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException {
-	   	File file = new File(args[0]);
-		Reader freader =  new BufferedReader(new InputStreamReader 
-		         (new FileInputStream(file), "UTF-8"));		
-		AdmLexer flexer = new AdmLexer(freader);
-		Token t = null;
-		do {
-		   t = flexer.next();		   
-		   System.out.println(AdmLexerConstants.tokenImage[t.kind]);
-		} while (t.kind != EOF);
-	    freader.close();
-	}
-	
-	public Token next() throws ParseException {
-	   return getNextToken();
-	}
-	
-	public String tokenKindToString(int tokenKind) {
-	   return AdmLexerConstants.tokenImage[tokenKind];
-	}
-}
-
-PARSER_END(AdmLexer)
-
-<DEFAULT>
-TOKEN :
-{
-	<NULL_LITERAL : "null">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<TRUE_LITERAL : "true">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<FALSE_LITERAL : "false">
-}
-
-
-<DEFAULT>
-TOKEN :
-{
-	<INTEGER_LITERAL : ("-")? (<DIGIT>)+ >
-}
-
-
-<DEFAULT>
-TOKEN :
-{
-	<#DIGIT : ["0" - "9"]>
-}
-
-
-TOKEN:
-{
-  < DOUBLE_LITERAL: 
-	      ("-")? <INTEGER> ( "." <INTEGER> )? (<EXPONENT>)? 
-	    | ("-")? "." <INTEGER>
-  >
-  | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
-	| <INTEGER : (<DIGIT>)+ >
-	| <FLOAT_LITERAL: <DOUBLE_LITERAL>("f"|"F")>
- }
-
-<DEFAULT>
-TOKEN :
-{
-	<STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") >
-	|
-	< #EscapeQuot: "\\\"" >
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<START_RECORD : "{">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<END_RECORD : "}">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<COMMA : ",">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<COLON : ":">
-}
-
-
-<DEFAULT>
-TOKEN :
-{
-	<START_ORDERED_LIST : "[">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<END_ORDERED_LIST : "]">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<START_UNORDERED_LIST : "{{">
-}
-
-<DEFAULT>
-TOKEN :
-{
-	<END_UNORDERED_LIST : "}}">
-}
-
-
-
-
-SKIP:
-{
-    " "
-|   "\t"
-|   "\r"
-|   "\n"
-}
diff --git a/asterix-runtime/src/main/javacc/nontagged/AdmLexer.jj b/asterix-runtime/src/main/javacc/nontagged/AdmLexer.jj
deleted file mode 100644
index d94033d..0000000
--- a/asterix-runtime/src/main/javacc/nontagged/AdmLexer.jj
+++ /dev/null
Binary files differ
diff --git a/asterix-runtime/src/main/resources/adm.grammar b/asterix-runtime/src/main/resources/adm.grammar
new file mode 100644
index 0000000..56c7212
--- /dev/null
+++ b/asterix-runtime/src/main/resources/adm.grammar
@@ -0,0 +1,63 @@
+# LEXER GENERATOR configuration file
+# ---------------------------------------
+# Place *first* the generic configuration
+# then list your grammar.
+
+PACKAGE:          edu.uci.ics.asterix.runtime.operators.file.adm
+LEXER_NAME:       AdmLexer
+
+TOKENS:
+
+BOOLEAN_CONS   = string(boolean)
+INT8_CONS      = string(int8)
+INT16_CONS     = string(int16)
+INT32_CONS     = string(int32)
+INT64_CONS     = string(int64)
+FLOAT_CONS     = string(float)
+DOUBLE_CONS    = string(double)
+DATE_CONS      = string(date)
+DATETIME_CONS  = string(datetime)
+DURATION_CONS  = string(duration)
+STRING_CONS    = string(string)
+POINT_CONS     = string(point)
+POINT3D_CONS   = string(point3d)
+LINE_CONS      = string(line)
+POLYGON_CONS   = string(polygon)
+RECTANGLE_CONS = string(rectangle)
+CIRCLE_CONS    = string(circle)
+TIME_CONS      = string(time)
+INTERVAL_TIME_CONS      = string(interval_time)
+INTERVAL_DATE_CONS      = string(interval_date)
+INTERVAL_DATETIME_CONS  = string(interval_datetime)
+
+NULL_LITERAL   = string(null)
+TRUE_LITERAL   = string(true)
+FALSE_LITERAL  = string(false)
+
+CONSTRUCTOR_OPEN     = char(()
+CONSTRUCTOR_CLOSE    = char())
+START_RECORD         = char({)
+END_RECORD           = char(})
+COMMA                = char(\,)
+COLON                = char(:)
+START_ORDERED_LIST   = char([)
+END_ORDERED_LIST     = char(])
+START_UNORDERED_LIST = string({{)
+END_UNORDERED_LIST   = string(}})
+
+STRING_LITERAL       = char("), anythingUntil(")
+
+INT_LITERAL          = signOrNothing(), digitSequence()
+INT8_LITERAL         = token(INT_LITERAL), string(i8)
+INT16_LITERAL        = token(INT_LITERAL), string(i16)
+INT32_LITERAL        = token(INT_LITERAL), string(i32)
+INT64_LITERAL        = token(INT_LITERAL), string(i64)
+
+@EXPONENT            = caseInsensitiveChar(e), signOrNothing(), digitSequence()
+
+DOUBLE_LITERAL		 = signOrNothing(), char(.), digitSequence()
+DOUBLE_LITERAL		 = signOrNothing(), digitSequence(), char(.), digitSequence()
+DOUBLE_LITERAL		 = signOrNothing(), digitSequence(), char(.), digitSequence(), token(@EXPONENT)
+DOUBLE_LITERAL		 = signOrNothing(), digitSequence(), token(@EXPONENT)
+
+FLOAT_LITERAL		 = token(DOUBLE_LITERAL), caseInsensitiveChar(f)
diff --git a/asterix-test-framework/pom.xml b/asterix-test-framework/pom.xml
index 2f0142e..9462b5d 100755
--- a/asterix-test-framework/pom.xml
+++ b/asterix-test-framework/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -13,21 +14,21 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
-            <plugin>
-                <groupId>org.jvnet.jaxb2.maven2</groupId>
-                <artifactId>maven-jaxb2-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
+			<plugin>
+				<groupId>org.jvnet.jaxb2.maven2</groupId>
+				<artifactId>maven-jaxb2-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>generate</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
 		</plugins>
 	</build>
 
diff --git a/asterix-tools/pom.xml b/asterix-tools/pom.xml
index 62176d9..0440618 100644
--- a/asterix-tools/pom.xml
+++ b/asterix-tools/pom.xml
@@ -15,8 +15,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 			<plugin>
diff --git a/asterix-transactions/pom.xml b/asterix-transactions/pom.xml
index 7db5cd9..a402077 100644
--- a/asterix-transactions/pom.xml
+++ b/asterix-transactions/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
 		<artifactId>asterix</artifactId>
@@ -16,8 +17,8 @@
 				<artifactId>maven-compiler-plugin</artifactId>
 				<version>2.0.2</version>
 				<configuration>
-					<source>1.6</source>
-					<target>1.6</target>
+					<source>1.7</source>
+					<target>1.7</target>
 				</configuration>
 			</plugin>
 		</plugins>
@@ -25,9 +26,9 @@
 	</build>
 
 	<dependencies>
-	    <dependency>
-  		<groupId>edu.uci.ics.hyracks</groupId>
-  		<artifactId>hyracks-storage-am-common</artifactId>
-  	</dependency>
+		<dependency>
+			<groupId>edu.uci.ics.hyracks</groupId>
+			<artifactId>hyracks-storage-am-common</artifactId>
+		</dependency>
 	</dependencies>
 </project>
diff --git a/pom.xml b/pom.xml
index fadaa0b..e13d3c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,8 +82,11 @@
                 <module>asterix-hyracks-glue</module>
                 <module>asterix-external-data</module>
                 <module>asterix-metadata</module>
+                <module>asterix-installer</module>
+                <module>asterix-events</module>
                 <module>asterix-dist</module>
                 <module>asterix-test-framework</module>
+        <module>asterix-maven-plugins</module>
         </modules>
 
 	<repositories>