Further additions to Avro messages
authorChristos KK Loverdos <loverdos@gmail.com>
Wed, 29 Aug 2012 13:02:26 +0000 (16:02 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Wed, 29 Aug 2012 13:02:59 +0000 (16:02 +0300)
PolicyTest is failing.

src/main/avro/aquarium-conf.avdl
src/main/java/gr/grnet/aquarium/message/avro/AquariumConf.java
src/main/java/gr/grnet/aquarium/message/avro/_CronSpecTuple.java [new file with mode: 0644]
src/main/java/gr/grnet/aquarium/message/avro/_EffectivePriceTable.java
src/main/java/gr/grnet/aquarium/message/avro/_EffectiveUnitPrice.java [new file with mode: 0644]
src/main/java/gr/grnet/aquarium/message/avro/_FullPriceTable.java
src/main/java/gr/grnet/aquarium/message/avro/_Policy.java
src/main/java/gr/grnet/aquarium/message/avro/_SelectorValue.java
src/test/scala/gr/grnet/aquarium/message/avro/PolicyTest.scala [new file with mode: 0644]

index cdbafa3..e11bb93 100644 (file)
@@ -57,7 +57,18 @@ protocol AquariumConf {
     string chargingBehaviorClass;
   }
 
+  record _CronSpecTuple {
+    string a;
+    string b;
+  }
+
+  record _EffectiveUnitPrice {
+    double unitPrice;
+    union {_CronSpecTuple, null} when;
+  }
+
   record _EffectivePriceTable {
+    array<_EffectiveUnitPrice> priceOverrides;
   }
 
   record _SelectorValue {
index 6127890..685bb37 100644 (file)
@@ -7,7 +7,7 @@ package gr.grnet.aquarium.message.avro;
 
 @SuppressWarnings("all")
 public interface AquariumConf {
-  public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse("{\"protocol\":\"AquariumConf\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"types\":[{\"type\":\"enum\",\"name\":\"_EventVersion\",\"symbols\":[\"VERSION_1_0\"]},{\"type\":\"record\",\"name\":\"_AnyValue\",\"fields\":[{\"name\":\"anyValue\",\"type\":[\"null\",\"int\",\"long\",\"boolean\",\"double\",\"bytes\",\"string\"]}]},{\"type\":\"record\",\"name\":\"_ResourceType\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"unit\",\"type\":\"string\"},{\"name\":\"chargingBehaviorClass\",\"type\":\"string\"}]},{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[]},{\"type\":\"record\",\"name\":\"_SelectorValue\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[\"_EffectivePriceTable\",{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]},{\"type\":\"record\",\"name\":\"_FullPriceTable\",\"fields\":[{\"name\":\"perResource\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"map\",\"values\":\"_SelectorValue\"}}}]},{\"type\":\"record\",\"name\":\"_Policy\",\"fields\":[{\"name\":\"ID\",\"type\":\"string\",\"aliases\":[\"id, _id, idInStore, inStoreID\"]},{\"name\":\"parentID\",\"type\":\"string\"},{\"name\":\"validFromMillis\",\"type\":\"long\"},{\"name\":\"validToMillis\",\"type\":\"long\"},{\"name\":\"resourceTypes\",\"type\":{\"type\":\"array\",\"items\":\"_ResourceType\"}},{\"name\":\"chargingBehaviors\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"roleMapping\",\"type\":{\"type\":\"map\",\"values\":\"_FullPriceTable\"}}]}],\"messages\":{}}");
+  public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse("{\"protocol\":\"AquariumConf\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"types\":[{\"type\":\"enum\",\"name\":\"_EventVersion\",\"symbols\":[\"VERSION_1_0\"]},{\"type\":\"record\",\"name\":\"_AnyValue\",\"fields\":[{\"name\":\"anyValue\",\"type\":[\"null\",\"int\",\"long\",\"boolean\",\"double\",\"bytes\",\"string\"]}]},{\"type\":\"record\",\"name\":\"_ResourceType\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"unit\",\"type\":\"string\"},{\"name\":\"chargingBehaviorClass\",\"type\":\"string\"}]},{\"type\":\"record\",\"name\":\"_CronSpecTuple\",\"fields\":[{\"name\":\"a\",\"type\":\"string\"},{\"name\":\"b\",\"type\":\"string\"}]},{\"type\":\"record\",\"name\":\"_EffectiveUnitPrice\",\"fields\":[{\"name\":\"unitPrice\",\"type\":\"double\"},{\"name\":\"when\",\"type\":[\"_CronSpecTuple\",\"null\"]}]},{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[{\"name\":\"priceOverrides\",\"type\":{\"type\":\"array\",\"items\":\"_EffectiveUnitPrice\"}}]},{\"type\":\"record\",\"name\":\"_SelectorValue\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[\"_EffectivePriceTable\",{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]},{\"type\":\"record\",\"name\":\"_FullPriceTable\",\"fields\":[{\"name\":\"perResource\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"map\",\"values\":\"_SelectorValue\"}}}]},{\"type\":\"record\",\"name\":\"_Policy\",\"fields\":[{\"name\":\"ID\",\"type\":\"string\",\"aliases\":[\"id, _id, idInStore, inStoreID\"]},{\"name\":\"parentID\",\"type\":\"string\"},{\"name\":\"validFromMillis\",\"type\":\"long\"},{\"name\":\"validToMillis\",\"type\":\"long\"},{\"name\":\"resourceTypes\",\"type\":{\"type\":\"array\",\"items\":\"_ResourceType\"}},{\"name\":\"chargingBehaviors\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"roleMapping\",\"type\":{\"type\":\"map\",\"values\":\"_FullPriceTable\"}}]}],\"messages\":{}}");
 
   @SuppressWarnings("all")
   public interface Callback extends AquariumConf {
diff --git a/src/main/java/gr/grnet/aquarium/message/avro/_CronSpecTuple.java b/src/main/java/gr/grnet/aquarium/message/avro/_CronSpecTuple.java
new file mode 100644 (file)
index 0000000..c5898f3
--- /dev/null
@@ -0,0 +1,170 @@
+/**
+ * Autogenerated by Avro
+ * 
+ * DO NOT EDIT DIRECTLY
+ */
+package gr.grnet.aquarium.message.avro;  
+@SuppressWarnings("all")
+public class _CronSpecTuple extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
+  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_CronSpecTuple\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"a\",\"type\":\"string\"},{\"name\":\"b\",\"type\":\"string\"}]}");
+  @Deprecated public java.lang.CharSequence a;
+  @Deprecated public java.lang.CharSequence b;
+  public org.apache.avro.Schema getSchema() { return SCHEMA$; }
+  // Used by DatumWriter.  Applications should not call. 
+  public java.lang.Object get(int field$) {
+    switch (field$) {
+    case 0: return a;
+    case 1: return b;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+  // Used by DatumReader.  Applications should not call. 
+  @SuppressWarnings(value="unchecked")
+  public void put(int field$, java.lang.Object value$) {
+    switch (field$) {
+    case 0: a = (java.lang.CharSequence)value$; break;
+    case 1: b = (java.lang.CharSequence)value$; break;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+
+  /**
+   * Gets the value of the 'a' field.
+   */
+  public java.lang.CharSequence getA() {
+    return a;
+  }
+
+  /**
+   * Sets the value of the 'a' field.
+   * @param value the value to set.
+   */
+  public void setA(java.lang.CharSequence value) {
+    this.a = value;
+  }
+
+  /**
+   * Gets the value of the 'b' field.
+   */
+  public java.lang.CharSequence getB() {
+    return b;
+  }
+
+  /**
+   * Sets the value of the 'b' field.
+   * @param value the value to set.
+   */
+  public void setB(java.lang.CharSequence value) {
+    this.b = value;
+  }
+
+  /** Creates a new _CronSpecTuple RecordBuilder */
+  public static gr.grnet.aquarium.message.avro._CronSpecTuple.Builder newBuilder() {
+    return new gr.grnet.aquarium.message.avro._CronSpecTuple.Builder();
+  }
+  
+  /** Creates a new _CronSpecTuple RecordBuilder by copying an existing Builder */
+  public static gr.grnet.aquarium.message.avro._CronSpecTuple.Builder newBuilder(gr.grnet.aquarium.message.avro._CronSpecTuple.Builder other) {
+    return new gr.grnet.aquarium.message.avro._CronSpecTuple.Builder(other);
+  }
+  
+  /** Creates a new _CronSpecTuple RecordBuilder by copying an existing _CronSpecTuple instance */
+  public static gr.grnet.aquarium.message.avro._CronSpecTuple.Builder newBuilder(gr.grnet.aquarium.message.avro._CronSpecTuple other) {
+    return new gr.grnet.aquarium.message.avro._CronSpecTuple.Builder(other);
+  }
+  
+  /**
+   * RecordBuilder for _CronSpecTuple instances.
+   */
+  public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<_CronSpecTuple>
+    implements org.apache.avro.data.RecordBuilder<_CronSpecTuple> {
+
+    private java.lang.CharSequence a;
+    private java.lang.CharSequence b;
+
+    /** Creates a new Builder */
+    private Builder() {
+      super(gr.grnet.aquarium.message.avro._CronSpecTuple.SCHEMA$);
+    }
+    
+    /** Creates a Builder by copying an existing Builder */
+    private Builder(gr.grnet.aquarium.message.avro._CronSpecTuple.Builder other) {
+      super(other);
+    }
+    
+    /** Creates a Builder by copying an existing _CronSpecTuple instance */
+    private Builder(gr.grnet.aquarium.message.avro._CronSpecTuple other) {
+            super(gr.grnet.aquarium.message.avro._CronSpecTuple.SCHEMA$);
+      if (isValidValue(fields()[0], other.a)) {
+        this.a = (java.lang.CharSequence) data().deepCopy(fields()[0].schema(), other.a);
+        fieldSetFlags()[0] = true;
+      }
+      if (isValidValue(fields()[1], other.b)) {
+        this.b = (java.lang.CharSequence) data().deepCopy(fields()[1].schema(), other.b);
+        fieldSetFlags()[1] = true;
+      }
+    }
+
+    /** Gets the value of the 'a' field */
+    public java.lang.CharSequence getA() {
+      return a;
+    }
+    
+    /** Sets the value of the 'a' field */
+    public gr.grnet.aquarium.message.avro._CronSpecTuple.Builder setA(java.lang.CharSequence value) {
+      validate(fields()[0], value);
+      this.a = value;
+      fieldSetFlags()[0] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'a' field has been set */
+    public boolean hasA() {
+      return fieldSetFlags()[0];
+    }
+    
+    /** Clears the value of the 'a' field */
+    public gr.grnet.aquarium.message.avro._CronSpecTuple.Builder clearA() {
+      a = null;
+      fieldSetFlags()[0] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'b' field */
+    public java.lang.CharSequence getB() {
+      return b;
+    }
+    
+    /** Sets the value of the 'b' field */
+    public gr.grnet.aquarium.message.avro._CronSpecTuple.Builder setB(java.lang.CharSequence value) {
+      validate(fields()[1], value);
+      this.b = value;
+      fieldSetFlags()[1] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'b' field has been set */
+    public boolean hasB() {
+      return fieldSetFlags()[1];
+    }
+    
+    /** Clears the value of the 'b' field */
+    public gr.grnet.aquarium.message.avro._CronSpecTuple.Builder clearB() {
+      b = null;
+      fieldSetFlags()[1] = false;
+      return this;
+    }
+
+    @Override
+    public _CronSpecTuple build() {
+      try {
+        _CronSpecTuple record = new _CronSpecTuple();
+        record.a = fieldSetFlags()[0] ? this.a : (java.lang.CharSequence) defaultValue(fields()[0]);
+        record.b = fieldSetFlags()[1] ? this.b : (java.lang.CharSequence) defaultValue(fields()[1]);
+        return record;
+      } catch (Exception e) {
+        throw new org.apache.avro.AvroRuntimeException(e);
+      }
+    }
+  }
+}
index 6920c6a..34f1727 100644 (file)
@@ -6,11 +6,13 @@
 package gr.grnet.aquarium.message.avro;  
 @SuppressWarnings("all")
 public class _EffectivePriceTable extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
-  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[]}");
+  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"priceOverrides\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"_EffectiveUnitPrice\",\"fields\":[{\"name\":\"unitPrice\",\"type\":\"double\"},{\"name\":\"when\",\"type\":[{\"type\":\"record\",\"name\":\"_CronSpecTuple\",\"fields\":[{\"name\":\"a\",\"type\":\"string\"},{\"name\":\"b\",\"type\":\"string\"}]},\"null\"]}]}}}]}");
+  @Deprecated public java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice> priceOverrides;
   public org.apache.avro.Schema getSchema() { return SCHEMA$; }
   // Used by DatumWriter.  Applications should not call. 
   public java.lang.Object get(int field$) {
     switch (field$) {
+    case 0: return priceOverrides;
     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
     }
   }
@@ -18,10 +20,26 @@ public class _EffectivePriceTable extends org.apache.avro.specific.SpecificRecor
   @SuppressWarnings(value="unchecked")
   public void put(int field$, java.lang.Object value$) {
     switch (field$) {
+    case 0: priceOverrides = (java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice>)value$; break;
     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
     }
   }
 
+  /**
+   * Gets the value of the 'priceOverrides' field.
+   */
+  public java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice> getPriceOverrides() {
+    return priceOverrides;
+  }
+
+  /**
+   * Sets the value of the 'priceOverrides' field.
+   * @param value the value to set.
+   */
+  public void setPriceOverrides(java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice> value) {
+    this.priceOverrides = value;
+  }
+
   /** Creates a new _EffectivePriceTable RecordBuilder */
   public static gr.grnet.aquarium.message.avro._EffectivePriceTable.Builder newBuilder() {
     return new gr.grnet.aquarium.message.avro._EffectivePriceTable.Builder();
@@ -43,6 +61,7 @@ public class _EffectivePriceTable extends org.apache.avro.specific.SpecificRecor
   public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<_EffectivePriceTable>
     implements org.apache.avro.data.RecordBuilder<_EffectivePriceTable> {
 
+    private java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice> priceOverrides;
 
     /** Creates a new Builder */
     private Builder() {
@@ -57,12 +76,42 @@ public class _EffectivePriceTable extends org.apache.avro.specific.SpecificRecor
     /** Creates a Builder by copying an existing _EffectivePriceTable instance */
     private Builder(gr.grnet.aquarium.message.avro._EffectivePriceTable other) {
             super(gr.grnet.aquarium.message.avro._EffectivePriceTable.SCHEMA$);
+      if (isValidValue(fields()[0], other.priceOverrides)) {
+        this.priceOverrides = (java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice>) data().deepCopy(fields()[0].schema(), other.priceOverrides);
+        fieldSetFlags()[0] = true;
+      }
+    }
+
+    /** Gets the value of the 'priceOverrides' field */
+    public java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice> getPriceOverrides() {
+      return priceOverrides;
+    }
+    
+    /** Sets the value of the 'priceOverrides' field */
+    public gr.grnet.aquarium.message.avro._EffectivePriceTable.Builder setPriceOverrides(java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice> value) {
+      validate(fields()[0], value);
+      this.priceOverrides = value;
+      fieldSetFlags()[0] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'priceOverrides' field has been set */
+    public boolean hasPriceOverrides() {
+      return fieldSetFlags()[0];
+    }
+    
+    /** Clears the value of the 'priceOverrides' field */
+    public gr.grnet.aquarium.message.avro._EffectivePriceTable.Builder clearPriceOverrides() {
+      priceOverrides = null;
+      fieldSetFlags()[0] = false;
+      return this;
     }
 
     @Override
     public _EffectivePriceTable build() {
       try {
         _EffectivePriceTable record = new _EffectivePriceTable();
+        record.priceOverrides = fieldSetFlags()[0] ? this.priceOverrides : (java.util.List<gr.grnet.aquarium.message.avro._EffectiveUnitPrice>) defaultValue(fields()[0]);
         return record;
       } catch (Exception e) {
         throw new org.apache.avro.AvroRuntimeException(e);
diff --git a/src/main/java/gr/grnet/aquarium/message/avro/_EffectiveUnitPrice.java b/src/main/java/gr/grnet/aquarium/message/avro/_EffectiveUnitPrice.java
new file mode 100644 (file)
index 0000000..6d30acb
--- /dev/null
@@ -0,0 +1,169 @@
+/**
+ * Autogenerated by Avro
+ * 
+ * DO NOT EDIT DIRECTLY
+ */
+package gr.grnet.aquarium.message.avro;  
+@SuppressWarnings("all")
+public class _EffectiveUnitPrice extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
+  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_EffectiveUnitPrice\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"unitPrice\",\"type\":\"double\"},{\"name\":\"when\",\"type\":[{\"type\":\"record\",\"name\":\"_CronSpecTuple\",\"fields\":[{\"name\":\"a\",\"type\":\"string\"},{\"name\":\"b\",\"type\":\"string\"}]},\"null\"]}]}");
+  @Deprecated public double unitPrice;
+  @Deprecated public gr.grnet.aquarium.message.avro._CronSpecTuple when;
+  public org.apache.avro.Schema getSchema() { return SCHEMA$; }
+  // Used by DatumWriter.  Applications should not call. 
+  public java.lang.Object get(int field$) {
+    switch (field$) {
+    case 0: return unitPrice;
+    case 1: return when;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+  // Used by DatumReader.  Applications should not call. 
+  @SuppressWarnings(value="unchecked")
+  public void put(int field$, java.lang.Object value$) {
+    switch (field$) {
+    case 0: unitPrice = (java.lang.Double)value$; break;
+    case 1: when = (gr.grnet.aquarium.message.avro._CronSpecTuple)value$; break;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+
+  /**
+   * Gets the value of the 'unitPrice' field.
+   */
+  public java.lang.Double getUnitPrice() {
+    return unitPrice;
+  }
+
+  /**
+   * Sets the value of the 'unitPrice' field.
+   * @param value the value to set.
+   */
+  public void setUnitPrice(java.lang.Double value) {
+    this.unitPrice = value;
+  }
+
+  /**
+   * Gets the value of the 'when' field.
+   */
+  public gr.grnet.aquarium.message.avro._CronSpecTuple getWhen() {
+    return when;
+  }
+
+  /**
+   * Sets the value of the 'when' field.
+   * @param value the value to set.
+   */
+  public void setWhen(gr.grnet.aquarium.message.avro._CronSpecTuple value) {
+    this.when = value;
+  }
+
+  /** Creates a new _EffectiveUnitPrice RecordBuilder */
+  public static gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder newBuilder() {
+    return new gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder();
+  }
+  
+  /** Creates a new _EffectiveUnitPrice RecordBuilder by copying an existing Builder */
+  public static gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder newBuilder(gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder other) {
+    return new gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder(other);
+  }
+  
+  /** Creates a new _EffectiveUnitPrice RecordBuilder by copying an existing _EffectiveUnitPrice instance */
+  public static gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder newBuilder(gr.grnet.aquarium.message.avro._EffectiveUnitPrice other) {
+    return new gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder(other);
+  }
+  
+  /**
+   * RecordBuilder for _EffectiveUnitPrice instances.
+   */
+  public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<_EffectiveUnitPrice>
+    implements org.apache.avro.data.RecordBuilder<_EffectiveUnitPrice> {
+
+    private double unitPrice;
+    private gr.grnet.aquarium.message.avro._CronSpecTuple when;
+
+    /** Creates a new Builder */
+    private Builder() {
+      super(gr.grnet.aquarium.message.avro._EffectiveUnitPrice.SCHEMA$);
+    }
+    
+    /** Creates a Builder by copying an existing Builder */
+    private Builder(gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder other) {
+      super(other);
+    }
+    
+    /** Creates a Builder by copying an existing _EffectiveUnitPrice instance */
+    private Builder(gr.grnet.aquarium.message.avro._EffectiveUnitPrice other) {
+            super(gr.grnet.aquarium.message.avro._EffectiveUnitPrice.SCHEMA$);
+      if (isValidValue(fields()[0], other.unitPrice)) {
+        this.unitPrice = (java.lang.Double) data().deepCopy(fields()[0].schema(), other.unitPrice);
+        fieldSetFlags()[0] = true;
+      }
+      if (isValidValue(fields()[1], other.when)) {
+        this.when = (gr.grnet.aquarium.message.avro._CronSpecTuple) data().deepCopy(fields()[1].schema(), other.when);
+        fieldSetFlags()[1] = true;
+      }
+    }
+
+    /** Gets the value of the 'unitPrice' field */
+    public java.lang.Double getUnitPrice() {
+      return unitPrice;
+    }
+    
+    /** Sets the value of the 'unitPrice' field */
+    public gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder setUnitPrice(double value) {
+      validate(fields()[0], value);
+      this.unitPrice = value;
+      fieldSetFlags()[0] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'unitPrice' field has been set */
+    public boolean hasUnitPrice() {
+      return fieldSetFlags()[0];
+    }
+    
+    /** Clears the value of the 'unitPrice' field */
+    public gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder clearUnitPrice() {
+      fieldSetFlags()[0] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'when' field */
+    public gr.grnet.aquarium.message.avro._CronSpecTuple getWhen() {
+      return when;
+    }
+    
+    /** Sets the value of the 'when' field */
+    public gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder setWhen(gr.grnet.aquarium.message.avro._CronSpecTuple value) {
+      validate(fields()[1], value);
+      this.when = value;
+      fieldSetFlags()[1] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'when' field has been set */
+    public boolean hasWhen() {
+      return fieldSetFlags()[1];
+    }
+    
+    /** Clears the value of the 'when' field */
+    public gr.grnet.aquarium.message.avro._EffectiveUnitPrice.Builder clearWhen() {
+      when = null;
+      fieldSetFlags()[1] = false;
+      return this;
+    }
+
+    @Override
+    public _EffectiveUnitPrice build() {
+      try {
+        _EffectiveUnitPrice record = new _EffectiveUnitPrice();
+        record.unitPrice = fieldSetFlags()[0] ? this.unitPrice : (java.lang.Double) defaultValue(fields()[0]);
+        record.when = fieldSetFlags()[1] ? this.when : (gr.grnet.aquarium.message.avro._CronSpecTuple) defaultValue(fields()[1]);
+        return record;
+      } catch (Exception e) {
+        throw new org.apache.avro.AvroRuntimeException(e);
+      }
+    }
+  }
+}
index e042b6b..1962408 100644 (file)
@@ -6,7 +6,7 @@
 package gr.grnet.aquarium.message.avro;  
 @SuppressWarnings("all")
 public class _FullPriceTable extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
-  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_FullPriceTable\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"perResource\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"map\",\"values\":{\"type\":\"record\",\"name\":\"_SelectorValue\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[]},{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]}}}}]}");
+  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_FullPriceTable\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"perResource\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"map\",\"values\":{\"type\":\"record\",\"name\":\"_SelectorValue\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[{\"name\":\"priceOverrides\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"_EffectiveUnitPrice\",\"fields\":[{\"name\":\"unitPrice\",\"type\":\"double\"},{\"name\":\"when\",\"type\":[{\"type\":\"record\",\"name\":\"_CronSpecTuple\",\"fields\":[{\"name\":\"a\",\"type\":\"string\"},{\"name\":\"b\",\"type\":\"string\"}]},\"null\"]}]}}}]},{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]}}}}]}");
   @Deprecated public java.util.Map<java.lang.CharSequence,java.util.Map<java.lang.CharSequence,gr.grnet.aquarium.message.avro._SelectorValue>> perResource;
   public org.apache.avro.Schema getSchema() { return SCHEMA$; }
   // Used by DatumWriter.  Applications should not call. 
index b5daa37..a99519d 100644 (file)
@@ -6,7 +6,7 @@
 package gr.grnet.aquarium.message.avro;  
 @SuppressWarnings("all")
 public class _Policy extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
-  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_Policy\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"ID\",\"type\":\"string\",\"aliases\":[\"id, _id, idInStore, inStoreID\"]},{\"name\":\"parentID\",\"type\":\"string\"},{\"name\":\"validFromMillis\",\"type\":\"long\"},{\"name\":\"validToMillis\",\"type\":\"long\"},{\"name\":\"resourceTypes\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"_ResourceType\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"unit\",\"type\":\"string\"},{\"name\":\"chargingBehaviorClass\",\"type\":\"string\"}]}}},{\"name\":\"chargingBehaviors\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"roleMapping\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"record\",\"name\":\"_FullPriceTable\",\"fields\":[{\"name\":\"perResource\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"map\",\"values\":{\"type\":\"record\",\"name\":\"_SelectorValue\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[]},{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]}}}}]}}}]}");
+  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_Policy\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"ID\",\"type\":\"string\",\"aliases\":[\"id, _id, idInStore, inStoreID\"]},{\"name\":\"parentID\",\"type\":\"string\"},{\"name\":\"validFromMillis\",\"type\":\"long\"},{\"name\":\"validToMillis\",\"type\":\"long\"},{\"name\":\"resourceTypes\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"_ResourceType\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"unit\",\"type\":\"string\"},{\"name\":\"chargingBehaviorClass\",\"type\":\"string\"}]}}},{\"name\":\"chargingBehaviors\",\"type\":{\"type\":\"array\",\"items\":\"string\"}},{\"name\":\"roleMapping\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"record\",\"name\":\"_FullPriceTable\",\"fields\":[{\"name\":\"perResource\",\"type\":{\"type\":\"map\",\"values\":{\"type\":\"map\",\"values\":{\"type\":\"record\",\"name\":\"_SelectorValue\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[{\"name\":\"priceOverrides\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"_EffectiveUnitPrice\",\"fields\":[{\"name\":\"unitPrice\",\"type\":\"double\"},{\"name\":\"when\",\"type\":[{\"type\":\"record\",\"name\":\"_CronSpecTuple\",\"fields\":[{\"name\":\"a\",\"type\":\"string\"},{\"name\":\"b\",\"type\":\"string\"}]},\"null\"]}]}}}]},{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]}}}}]}}}]}");
   @Deprecated public java.lang.CharSequence ID;
   @Deprecated public java.lang.CharSequence parentID;
   @Deprecated public long validFromMillis;
index dd662c4..95cbe93 100644 (file)
@@ -6,7 +6,7 @@
 package gr.grnet.aquarium.message.avro;  
 @SuppressWarnings("all")
 public class _SelectorValue extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
-  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_SelectorValue\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[]},{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]}");
+  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"_SelectorValue\",\"namespace\":\"gr.grnet.aquarium.message.avro\",\"fields\":[{\"name\":\"selectorValue\",\"type\":[{\"type\":\"record\",\"name\":\"_EffectivePriceTable\",\"fields\":[{\"name\":\"priceOverrides\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"_EffectiveUnitPrice\",\"fields\":[{\"name\":\"unitPrice\",\"type\":\"double\"},{\"name\":\"when\",\"type\":[{\"type\":\"record\",\"name\":\"_CronSpecTuple\",\"fields\":[{\"name\":\"a\",\"type\":\"string\"},{\"name\":\"b\",\"type\":\"string\"}]},\"null\"]}]}}}]},{\"type\":\"map\",\"values\":\"_SelectorValue\"}]}]}");
   @Deprecated public java.lang.Object selectorValue;
   public org.apache.avro.Schema getSchema() { return SCHEMA$; }
   // Used by DatumWriter.  Applications should not call. 
diff --git a/src/test/scala/gr/grnet/aquarium/message/avro/PolicyTest.scala b/src/test/scala/gr/grnet/aquarium/message/avro/PolicyTest.scala
new file mode 100644 (file)
index 0000000..7e68765
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.message.avro
+
+import org.junit.Test
+import scala.collection.JavaConverters.seqAsJavaListConverter
+import scala.collection.JavaConverters.mapAsJavaMapConverter
+import gr.grnet.aquarium.charging.VMChargingBehavior
+import java.io.ByteArrayOutputStream
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+class PolicyTest {
+  @Test
+  def testOne() {
+    val policyConf = _Policy.newBuilder().
+      setChargingBehaviors(
+        List[CharSequence](
+          "gr.grnet.aquarium.charging.VMChargingBehavior",
+          "gr.grnet.aquarium.charging.ContinuousChargingBehavior",
+          "gr.grnet.aquarium.charging.OnceChargingBehavior"
+        ).asJava).
+      setID("default-policy").
+      setParentID("").
+      setValidFromMillis(0L).
+      setValidToMillis(Long.MaxValue).
+      setResourceTypes(
+        List(
+          _ResourceType.newBuilder().
+            setName("diskspace").
+            setUnit("MB/Hr").
+            setChargingBehaviorClass("gr.grnet.aquarium.charging.ContinuousChargingBehavior").
+          build(),
+          _ResourceType.newBuilder().
+            setName("vmtime").
+            setUnit("Hr").
+            setChargingBehaviorClass("gr.grnet.aquarium.charging.VMChargingBehavior").
+          build(),
+          _ResourceType.newBuilder().
+            setName("addcredits").
+            setUnit("Credits").
+            setChargingBehaviorClass("gr.grnet.aquarium.charging.OnceChargingBehavior").
+          build()
+        ).asJava).
+      setRoleMapping(
+        Map[CharSequence, _FullPriceTable](
+            "default" -> _FullPriceTable.newBuilder().
+              setPerResource(
+                Map(
+                  ("diskspace": CharSequence) -> Map[CharSequence, _SelectorValue](
+                    "default" -> _SelectorValue.newBuilder().
+                      setSelectorValue(_EffectiveUnitPrice.newBuilder().
+                        setUnitPrice(0.01).
+                        setWhen(null)
+                      build()).
+                    build()
+                  ).asJava,
+                  ("vmtime": CharSequence) -> Map[CharSequence, _SelectorValue](
+                    VMChargingBehavior.Selectors.Power.powerOn -> _SelectorValue.newBuilder().
+                      setSelectorValue(_EffectiveUnitPrice.newBuilder().
+                        setUnitPrice(0.01).
+                        setWhen(null)
+                      build()).
+                    build(),
+                    VMChargingBehavior.Selectors.Power.powerOff -> _SelectorValue.newBuilder().
+                      setSelectorValue(_EffectiveUnitPrice.newBuilder().
+                        setUnitPrice(0.01).
+                        setWhen(null)
+                      build()).
+                    build()
+                  ).asJava,
+                  ("addcredits": CharSequence) -> Map[CharSequence, _SelectorValue](
+                    "default" -> _SelectorValue.newBuilder().
+                      setSelectorValue(_EffectiveUnitPrice.newBuilder().
+                        setUnitPrice(-1.0).
+                        setWhen(null)
+                      build()).
+                    build()
+                  ).asJava
+                ).asJava
+            ).build()
+        ).asJava).
+    build()
+
+    val generatedJSON = AvroHelpers.jsonStringOfSpecificRecord(policyConf)
+    println(generatedJSON)
+  }
+}