HP Matrix Operating Environment Software User Manual

Page 61

Advertising
background image

package package-name

imports

globals

functions

queries

rules

The order in which the elements are declared is not important, except for the package name. If
you declare a package name, it must be the first element in the rule file.

Example: Rule to verify server memory criteria

package com.hp.hpio.controller.policy;

import java.util.List;
import java.lang.Integer;

import com.hp._2007.ess.sw.model.infrastructureutilityschema.LogicalServer;
import com.hp._2007.ess.sw.model.infrastructureutilityschema.ComputeServer;

import com.hp.hpio.controller.wrapper.LogicalServerWrapper;

import com.hp.hpio.common.messages.HPIOBundleKey;
import com.hp.hpio.common.messages.HPIOMessage;

dialect "java" // Since we are using Java syntax with drools

/*
* INIT should be the first rule in a drl file which inserts service
* entity, resource list and result map into working memory by reading
* from PolicyExecutionVO passed to rule engine.
*
*/

/* DO NOT MODIFY */
rule "INIT"
salience 1000
when
pVO : PolicyExecutionVO();
then
insert(pVO.getAllocationEntry().getServiceEntity());
insert(pVO.getResultMap());
insert(pVO.getResourceList());
end

/*
* Rule to check memory criteria for a given service entity
* (LogicalServer) compared to list of physical resources available
* (ComputeServer)
*
*/

rule "MemorySizeCriteria"

when

$pVO : PolicyExecutionVO( );
$resLst : List();

$logicalServer : LogicalServer();
$computeServer : ComputeServer() from $resLst;

eval(memorySizeCriteria($logicalServer, $computeServer, $pVO));

then

$pVO.match($computeServer, HPIOMessage.get(HPIOBundleKey.ALLOCATION_CRITERIA_MEMORY));

end

function boolean memorySizeCriteria(
LogicalServer logicalServer,
ComputeServer computeServer,
PolicyExecutionVO pVO) {

pVO.doesNotMatch(computeServer,HPIOMessage.get(HPIOBundleKey.ALLOCATION_CRITERIA_MEMORY));

/* -------------- CUSTOM LOGIC ----------------------*/
Integer logicalMemorySizeMB = LogicalServerWrapper.getMemorySizeMi(logicalServer);

if (computeServer.getMemoryConsumedMB() == null) {
computeServer.setMemoryConsumedMB(0);
}
Integer resourceMemorySizeMB = computeServer.getMemorySizeMB() - computeServer.getMemoryConsumedMB();

if(logicalMemorySizeMB.doubleValue() <= resourceMemorySizeMB.doubleValue()){
return true;

Customizable allocation process

61

Advertising