Product SiteDocumentation Site

8.4. Utilizzare regole per determinare il posizionamento delle risorse

If the constraint’s outer-most rule evaluates to false, the cluster treats the constraint as if it was not there. When the rule evaluates to true, the node’s preference for running the resource is updated with the score associated with the rule.
Se questo suona familiare è perché sono state già utilizzate sintassi semplificate per le constraint di tipo location. Considerata la seguente location constraint:

Esempio 8.8. Impedisci a myApacheRsc di essere eseguita su c001n03

<rsc_location id="dont-run-apache-on-c001n03" rsc="myApacheRsc"
              score="-INFINITY" node="c001n03"/>

Questa constraint potrebbe essere scritta più verbosamente come:

Esempio 8.9. Impedisci a myApacheRsc di essere eseguita su c001n03 - versione estesa

<rsc_location id="dont-run-apache-on-c001n03" rsc="myApacheRsc">
    <rule id="dont-run-apache-rule" score="-INFINITY">
      <expression id="dont-run-apache-expr" attribute="#uname"
        operation="eq" value="c00n03"/>
    </rule>
</rsc_location>

Il vantaggio di usare la versione estesa risiede nel fatto che è possibile aggiungere clausole extra nella regola, come limitarla affinché venga applicata solo in determinati orari del giorno o giorni sella settimana (il tema viene affrontato nelle sezioni sottostanti).
It also allows us to match on node properties other than its name. If we rated each machine’s CPU power such that the cluster had the following nodes section:

Esempio 8.10. Una sezione nodi di esempio da utilizzare con score-attribute

<nodes>
   <node id="uuid1" uname="c001n01" type="normal">
      <instance_attributes id="uuid1-custom_attrs">
        <nvpair id="uuid1-cpu_mips" name="cpu_mips" value="1234"/>
      </instance_attributes>
   </node>
   <node id="uuid2" uname="c001n02" type="normal">
      <instance_attributes id="uuid2-custom_attrs">
        <nvpair id="uuid2-cpu_mips" name="cpu_mips" value="5678"/>
      </instance_attributes>
   </node>
</nodes>

allora è possibile prevenire le risorse dall'essere eseguite in macchine meno potenti, mediante la regola
<rule id="need-more-power-rule" score="-INFINITY">
   <expression id=" need-more-power-expr" attribute="cpu_mips"
               operation="lt" value="3000"/>
</rule>

8.4.1. Utilizzo di score-attribute invece di score

When using score-attribute instead of score, each node matched by the rule has its score adjusted differently, according to its value for the named node attribute. Thus, in the previous example, if a rule used score-attribute="cpu_mips", c001n01 would have its preference to run the resource increased by 1234 whereas c001n02 would have its preference increased by 5678.