View Javadoc

1   /*
2    * Copyright 2010 Fraunhofer Gesellschaft, Munich, Germany,
3    * for its Fraunhofer Institute for Computer Architecture and Software
4    * Technology (FIRST), Berlin, Germany. All rights reserved.
5    * http://www.first.fraunhofer.de/
6    */
7   
8   package net.kwfgrid.gwes.prorater;
9   
10  import net.kwfgrid.gwes.GenericWorkflowHandler;
11  import net.kwfgrid.gwes.Constants;
12  import net.kwfgrid.gwes.exception.OperationMapperException;
13  import net.kwfgrid.gwes.operationmapper.OperationMapper;
14  import net.kwfgrid.gworkflowdl.structure.Transition;
15  import org.apache.log4j.Logger;
16  
17  import java.io.IOException;
18  import java.io.InputStream;
19  import java.util.ArrayList;
20  import java.util.Properties;
21  
22  /**
23   * A Prorater is a simple kind of a load balancer aiming to maximize a homogeneous load
24   * by prorating the activities among computing nodes.
25   * The priority property of the activities is the dominant criterium for prorating.
26   * Nodes with a quality below resource.prorater.min_quality are skiped
27   * until its quality grows. The quality (in [0,1]) is a monotone reciprocal function of the load.
28   *
29   * @author Helge Rose'
30   * @version $Id: AbstractProrater.java 1419 2010-11-01 14:12:17Z hoheisel $
31   */
32  public abstract class AbstractProrater extends OperationMapper {
33  
34      /**
35       * log4j logger.
36       */
37      final static Logger logger = Logger.getLogger(SimpleProrater.class);
38  
39      /**
40       * Nodes with a quality below MIN_QUALITY are skipted.
41       */
42      static float MIN_QUALITY;
43  
44      /**
45       * Wait period in Milliseconds after last usage of hardware.
46       */
47      static int WAIT_AFTER_LAST_ASSIGNMENT;
48  
49      AbstractProrater() {
50          Properties prop = new Properties();
51          InputStream is = SimpleProrater.class.getResourceAsStream("/gwes.properties");
52          if (is != null) try {
53              prop.load(is);
54              //System.out.println("load: "+prop);
55          }
56          catch (IOException e) {
57              logger.error(e, e);
58          }
59  
60          String s = prop.getProperty(Constants.PROP_SYSTEM_RESOURCE_PRORATER_MIN_QUALITY, "0.1");
61          MIN_QUALITY = Float.parseFloat(s);
62          s = prop.getProperty(Constants.PROP_SYSTEM_RESOURCE_PRORATER_WAIT, "12000");
63          WAIT_AFTER_LAST_ASSIGNMENT = Integer.parseInt(s);
64      }
65  
66      public boolean processTransition(GenericWorkflowHandler handler, Transition transition) throws OperationMapperException {
67          try {
68              ArrayList<Transition> transitions = new ArrayList<Transition>();
69              transitions.add(transition);
70              init(transitions);
71          } catch (IOException e) {
72              throw new OperationMapperException("Exception during processTransitions(): "+e, e);
73          }
74  
75          return decide();
76      }
77  
78      public boolean processTransitions(GenericWorkflowHandler handler, ArrayList<Transition> transitions) throws OperationMapperException {
79          try {
80              init(transitions);
81          } catch (IOException e) {
82              throw new OperationMapperException("Exception during processTransitions(): "+e, e);
83          }
84          return decide();
85      }
86  
87      abstract void init(ArrayList<Transition> transitions) throws IOException;
88  
89      abstract boolean decide();
90  }