Changes between Version 2 and Version 3 of Doc/panc/tips


Ignore:
Timestamp:
Sep 4, 2007, 3:40:29 PM (18 years ago)
Author:
/O=GRID-FR/C=FR/O=CNRS/OU=LAL/CN=Charles Loomis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Doc/panc/tips

    v2 v3  
    11= Record Validation =
    22
     3Often one wants to ensure that several entries in a record are consistent.  For example, here one wants to ensure that the number of children is consistent with the given maximum.  To remember where to put the validation code, keep in mind that you're validating the record and *not* the entries of the record.  Thus, the 'with' clause should be tied to the record definition. 
    34{{{
    4 type structure_enclosure = {
    5   'type' : string with match(self, 'blade|dumb|hypervisor')
    6   'children' : string[1..] with is_profile_list(self)
     5type my_kids = {
     6  'children' : string[1..] with is_profile_list(SELF)
    77  'maxchildren' ? long(1..)
    88} with {
    9   if (exists(self['maxchildren'])) {
    10     self['maxchildren'] >= length(self['children']);
     9  if (exists(SELF['maxchildren'])) {
     10    SELF['maxchildren'] >= length(SELF['children']);
    1111  } else {
    1212    true;
     
    1414};
    1515}}}
    16 
    17 For the older compiler (v6) you must define an intermediate type as a 'with' clause on a record definition is not valid in the older compiler.
    18 
    19 That is,
    20 
     16For the older compiler (v6) does not allow a 'with' clause to be put on a record definition.  For that compiler, you must define an intermediate type.
    2117{{{
    22 type structure_enclosure = {
    23   'type' : string with match(self, 'blade|dumb|hypervisor')
     18type my_kids = {
    2419  'children' : string[1..] with is_profile_list(self)
    2520  'maxchildren' ? long(1..)
    26 } with {
    27   if (exists(self['maxchildren'])) {
    28     self['maxchildren'] >= length(self['children']);
    29   } else {
    30     true;
    31   };
    3221};
    3322
    34 type validated_structure_enclosure =
    35   structure_enclosure with {
     23type my_validated_kids =
     24  my_kids with {
    3625    if (exists(self['maxchildren'])) {
    3726      self['maxchildren'] >= length(self['children']);
     
    4130  };
    4231}}}
    43 
     32This same technique can be used with any resource (list, nlist, record).