1 | package diskCacheV111.poolManager ; |
2 | |
3 | import java.util.HashMap; |
4 | import java.util.Map; |
5 | |
6 | public class PoolManagerParameter implements java.io.Serializable { |
7 | |
8 | static final long serialVersionUID = -3402641110205054015L; |
9 | |
10 | static final int P2P_SAME_HOST_BEST_EFFORT = 0 ; |
11 | static final int P2P_SAME_HOST_NEVER = 1 ; |
12 | static final int P2P_SAME_HOST_NOT_CHECKED = 2 ; |
13 | |
14 | // |
15 | // The parameters |
16 | // |
17 | int _allowSameHostCopy = P2P_SAME_HOST_BEST_EFFORT ; |
18 | int _maxPnfsFileCopies = 500 ; |
19 | |
20 | boolean _p2pAllowed = true ; |
21 | boolean _p2pOnCost = false ; |
22 | boolean _p2pForTransfer = false ; |
23 | |
24 | boolean _hasHsmBackend = false ; |
25 | boolean _stageOnCost = false ; |
26 | |
27 | double _slope = 0.0 ; |
28 | double _minCostCut = 0.0 ; |
29 | private double _costCut = 0.0 ; |
30 | private boolean _costCutIsPercentile = false ; |
31 | double _alertCostCut = 0.0 ; |
32 | double _panicCostCut = 0.0 ; |
33 | double _fallbackCostCut = 0.0 ; |
34 | |
35 | double _spaceCostFactor = 1.0 ; |
36 | double _performanceCostFactor = 1.0 ; |
37 | |
38 | // |
39 | // is parameter set ? |
40 | // |
41 | boolean _allowSameHostCopySet = false ; |
42 | boolean _maxPnfsFileCopiesSet = false ; |
43 | |
44 | boolean _p2pAllowedSet = false ; |
45 | boolean _p2pForTransferSet = false ; |
46 | boolean _p2pOnCostSet = false ; |
47 | |
48 | boolean _stageOnCostSet = false ; |
49 | boolean _hasHsmBackendSet = false ; |
50 | |
51 | boolean _slopeSet = false ; |
52 | boolean _minCostCutSet = false ; |
53 | boolean _costCutSet = false ; |
54 | boolean _alertCostCutSet = false ; |
55 | boolean _panicCostCutSet = false ; |
56 | boolean _fallbackCostCutSet = false ; |
57 | |
58 | boolean _performanceCostFactorSet = false ; |
59 | boolean _spaceCostFactorSet = false ; |
60 | |
61 | PoolManagerParameter(){} |
62 | PoolManagerParameter( PoolManagerParameter copy ){ |
63 | |
64 | _allowSameHostCopy = copy._allowSameHostCopy ; _allowSameHostCopySet = copy._allowSameHostCopySet ; |
65 | _maxPnfsFileCopies = copy._maxPnfsFileCopies ; _maxPnfsFileCopiesSet = copy._maxPnfsFileCopiesSet ; |
66 | |
67 | _p2pAllowed = copy._p2pAllowed ; _p2pAllowedSet = copy._p2pAllowedSet ; |
68 | _p2pOnCost = copy._p2pOnCost ; _p2pOnCostSet = copy._p2pOnCostSet ; |
69 | _p2pForTransfer = copy._p2pForTransfer ; _p2pForTransferSet = copy._p2pForTransferSet ; |
70 | |
71 | _hasHsmBackend = copy._hasHsmBackend ; _hasHsmBackendSet = copy._hasHsmBackendSet ; |
72 | _stageOnCost = copy._stageOnCost ; _stageOnCostSet = copy._stageOnCostSet ; |
73 | |
74 | _slope = copy._slope ; _slopeSet = copy._slopeSet ; |
75 | _minCostCut = copy._minCostCut ; _minCostCutSet = copy._minCostCutSet ; |
76 | _costCut = copy._costCut; _costCutSet = copy._costCutSet; |
77 | _costCutIsPercentile = copy._costCutIsPercentile; |
78 | _alertCostCut = copy._alertCostCut; _alertCostCutSet = copy._alertCostCutSet; |
79 | _panicCostCut = copy._panicCostCut ; _panicCostCutSet = copy._panicCostCutSet ; |
80 | _fallbackCostCut = copy._fallbackCostCut ; _fallbackCostCutSet = copy._fallbackCostCutSet ; |
81 | |
82 | _spaceCostFactor = copy._spaceCostFactor ; _spaceCostFactorSet = copy._spaceCostFactorSet ; |
83 | _performanceCostFactor = copy._performanceCostFactor ; _performanceCostFactorSet = copy._performanceCostFactorSet ; |
84 | |
85 | } |
86 | PoolManagerParameter setValid( boolean valid ){ |
87 | _allowSameHostCopySet = valid ; |
88 | _maxPnfsFileCopiesSet = valid ; |
89 | |
90 | _p2pAllowedSet = valid ; |
91 | _p2pOnCostSet = valid ; |
92 | _p2pForTransferSet = valid ; |
93 | |
94 | _hasHsmBackendSet = valid ; |
95 | _stageOnCostSet = valid ; |
96 | |
97 | _slopeSet = valid ; |
98 | _minCostCutSet = valid ; |
99 | _costCutSet = valid ; |
100 | _alertCostCutSet = valid ; |
101 | _panicCostCutSet = valid ; |
102 | _fallbackCostCutSet = valid ; |
103 | |
104 | _spaceCostFactorSet = valid ; |
105 | _performanceCostFactorSet = valid ; |
106 | return this ; |
107 | } |
108 | Map<String, Object[]> toMap(){ |
109 | |
110 | Map<String, Object[]> map = new HashMap<String, Object[]>() ; |
111 | map.put( "p2p-allowed" , new Object[]{ Boolean.valueOf(_p2pAllowedSet) , Boolean.valueOf(_p2pAllowed) } ) ; |
112 | map.put( "p2p-oncost" , new Object[]{ Boolean.valueOf(_p2pOnCostSet) , Boolean.valueOf(_p2pOnCost) } ) ; |
113 | map.put( "p2p-fortransfer" , new Object[]{ Boolean.valueOf(_p2pForTransferSet) , Boolean.valueOf(_p2pForTransfer) } ) ; |
114 | map.put( "stage-allowed" , new Object[]{ Boolean.valueOf(_hasHsmBackendSet) , Boolean.valueOf(_hasHsmBackend) } ) ; |
115 | map.put( "stage-oncost" , new Object[]{ Boolean.valueOf(_stageOnCostSet) , Boolean.valueOf(_stageOnCost) } ) ; |
116 | |
117 | map.put( "slope" , new Object[]{ Boolean.valueOf(_slopeSet) , new Double(_slope) } ) ; |
118 | map.put( "idle" , new Object[]{ Boolean.valueOf(_minCostCutSet) , new Double(_minCostCut) } ) ; |
119 | map.put( "p2p" , new Object[]{ Boolean.valueOf(_costCutSet) , new Double(_costCut) } ) ; |
120 | map.put( "alert" , new Object[]{ Boolean.valueOf(_alertCostCutSet) , new Double(_alertCostCut) } ) ; |
121 | map.put( "panic" , new Object[]{ Boolean.valueOf(_panicCostCutSet) , new Double(_panicCostCut) } ) ; |
122 | map.put( "fallback" , new Object[]{ Boolean.valueOf(_fallbackCostCutSet) , new Double(_fallbackCostCut) } ) ; |
123 | |
124 | map.put( "spacecostfactor" , new Object[]{ Boolean.valueOf(_spaceCostFactorSet) , new Double(_spaceCostFactor) } ) ; |
125 | map.put( "cpucostfactor" , new Object[]{ Boolean.valueOf(_performanceCostFactorSet) , new Double(_performanceCostFactor) } ) ; |
126 | |
127 | map.put( "max-pnfs-copies" , new Object[]{ Boolean.valueOf(_maxPnfsFileCopiesSet) , Integer.valueOf(_maxPnfsFileCopies) } ) ; |
128 | map.put( "same-host-copies" , new Object[]{ Boolean.valueOf(_allowSameHostCopySet) , Integer.valueOf(_allowSameHostCopy) } ) ; |
129 | |
130 | return map ; |
131 | } |
132 | PoolManagerParameter merge( PoolManagerParameter copy ){ |
133 | |
134 | if( _p2pOnCostSet = copy._p2pOnCostSet )_p2pOnCost = copy._p2pOnCost ; |
135 | if( _p2pForTransferSet = copy._p2pForTransferSet )_p2pForTransfer = copy._p2pForTransfer ; |
136 | if( _stageOnCostSet = copy._stageOnCostSet )_stageOnCost = copy._stageOnCost ; |
137 | if( _p2pAllowedSet = copy._p2pAllowedSet )_p2pAllowed = copy._p2pAllowed ; |
138 | if( _slopeSet = copy._slopeSet )_slope = copy._slope ; |
139 | if( _costCutSet = copy._costCutSet ) { |
140 | _costCut = copy._costCut; |
141 | _costCutIsPercentile = copy._costCutIsPercentile; |
142 | } |
143 | if( _alertCostCutSet = copy._alertCostCutSet )_alertCostCut = copy._alertCostCut; |
144 | if( _panicCostCutSet = copy._panicCostCutSet )_panicCostCut = copy._panicCostCut ; |
145 | if( _minCostCutSet = copy._minCostCutSet )_minCostCut = copy._minCostCut ; |
146 | if( _maxPnfsFileCopiesSet = copy._maxPnfsFileCopiesSet )_maxPnfsFileCopies = copy._maxPnfsFileCopies ; |
147 | if( _allowSameHostCopySet = copy._allowSameHostCopySet )_allowSameHostCopy = copy._allowSameHostCopy ; |
148 | if( _fallbackCostCutSet = copy._fallbackCostCutSet )_fallbackCostCut = copy._fallbackCostCut ; |
149 | if( _hasHsmBackendSet = copy._hasHsmBackendSet )_hasHsmBackend = copy._hasHsmBackend ; |
150 | if( _spaceCostFactorSet = copy._spaceCostFactorSet )_spaceCostFactor = copy._spaceCostFactor ; |
151 | if( _performanceCostFactorSet = copy._performanceCostFactorSet )_performanceCostFactor = copy._performanceCostFactor ; |
152 | |
153 | return this ; |
154 | } |
155 | void setAllowSameHostCopy( int value ){ _allowSameHostCopy = value ; _allowSameHostCopySet = true ; } |
156 | void unsetAllowSameHostCopy(){ _allowSameHostCopySet = false ; } |
157 | void setP2pOnCost( boolean value ){ _p2pOnCost = value ; _p2pOnCostSet = true ; } |
158 | void unsetP2pOnCost(){ _p2pOnCostSet = false ; } |
159 | void setP2pForTransfer( boolean value ){ _p2pForTransfer = value ; _p2pForTransferSet = true ; } |
160 | void unsetP2pForTransfer(){ _p2pForTransferSet = false ; } |
161 | void setHasHsmBackend( boolean value ){ _hasHsmBackend = value ; _hasHsmBackendSet = true ; } |
162 | void unsetHasHsmBackend(){ _hasHsmBackend = false ; } |
163 | void setStageOnCost( boolean value ){ _stageOnCost = value ; _stageOnCostSet = true ; } |
164 | void unsetStageOnCost(){ _stageOnCostSet = false ; } |
165 | void setP2pAllowed( boolean value ){ _p2pAllowed = value ; _p2pAllowedSet = true ; } |
166 | void unsetP2pAllowed(){ _p2pAllowedSet = false ; } |
167 | void setSlope( double value ){ _slope = value ; _slopeSet = true ; } |
168 | void unsetSlope(){ _slopeSet = false ; } |
169 | |
170 | /** |
171 | * Obtain the threshold cost for triggering p2p transfers on cost: |
172 | * transfers involving reading from a pool with cost greater than the |
173 | * costCut may trigger a pool-to-pool transfer. The value returned is |
174 | * either an absolute measure of cost or a percentile value. Whether the |
175 | * number is an absolute cost or a percentile cost is discoverable by |
176 | * calling the {@link #isCostCutPercentile()} method. |
177 | * <p> |
178 | * If the value is absolute then the returned value may be used directly |
179 | * when evaluating whether the cost for a transfer exceeds the threshold |
180 | * for triggering a pool-to-pool transfer. |
181 | * <p> |
182 | * If the number is a percentile value then the corresponding threshold is |
183 | * determined dynamically. If f is the value returned by |
184 | * <code>getCostCut()</code> and a list of N pools is sorted in ascending |
185 | * performance cost then the value used is the cost of pool with index |
186 | * floor(fN). |
187 | * <p> |
188 | * @return the threshold cost for pool-to-pool transfers |
189 | */ |
190 | double getCostCut() { |
191 | return _costCut; |
192 | } |
193 | |
194 | /** |
195 | * Assign a new value for the threshold at which read requests will trigger |
196 | * pool-to-pool transfers. The value may be optionally suffixed with a |
197 | * percent symbol; doing so will result in the value/100 being stored and |
198 | * subsequent calls to {@link #isCostCutPercentile()} |
199 | * returning true. |
200 | * @param value the String representation of the new costCut value. |
201 | * @see #getCostCut() |
202 | */ |
203 | void setCostCut( String value ) { |
204 | if( value.endsWith( "%")) { |
205 | String numberPart = value.substring( 0, value.length()-1); |
206 | _costCut = Double.parseDouble( numberPart)/100; |
207 | setCostCutIsPercentile( true); |
208 | } else { |
209 | _costCut = Double.parseDouble(value) ; |
210 | setCostCutIsPercentile( false); |
211 | } |
212 | _costCutSet = true ; |
213 | } |
214 | |
215 | /** |
216 | * Mark that the current costCut value should be interpreted as having a |
217 | * relative value compared to the maximum CPU cost of all pools. |
218 | * @param isPercentile true if the costCut should be interpreted as relative, |
219 | * false otherwise. |
220 | * @throws IllegalArgumentException if the transition would result in an illegal state. |
221 | */ |
222 | void setCostCutIsPercentile( boolean isPercentile) { |
223 | if( isPercentile) { |
224 | if( _costCut <= 0) |
225 | throw new IllegalArgumentException( "Number " + isPercentile + "is too small; must be > 0%"); |
226 | if( _costCut >= 1) |
227 | throw new IllegalArgumentException( "Number " + isPercentile + " is too large; must be < 100%"); |
228 | } |
229 | _costCutIsPercentile = isPercentile; |
230 | } |
231 | |
232 | /** |
233 | * Discover whether the current costCut value should be interpreted as |
234 | * the percentile value. |
235 | */ |
236 | boolean isCostCutPercentile() { |
237 | return _costCutIsPercentile; |
238 | } |
239 | |
240 | /** |
241 | * Mark that the costCut value is no longer valid. |
242 | */ |
243 | void unsetCostCut(){ |
244 | _costCutSet = false; |
245 | } |
246 | |
247 | /** |
248 | * Obtain a String representation of the current costCut value. |
249 | * <p> |
250 | * This method returns a String that, for any costCut value, can be |
251 | * supplied to {@link #setCostCut(String)} without changing its value. |
252 | * <p> |
253 | * If the current costCut uses a percentile value then the String |
254 | * representation will be the value, as a percentage, appended with the |
255 | * percent symbol otherwise the current value is returned. |
256 | * @return a String representation of the current cost cut |
257 | * @see #setCostCut(String) |
258 | */ |
259 | String getCostCutString() { |
260 | if( _costCutIsPercentile) { |
261 | return Double.toString( _costCut * 100) + "%"; |
262 | } else { |
263 | return Double.toString( _costCut); |
264 | } |
265 | } |
266 | void setAlertCostCut( double value ){ _alertCostCut = value ; _alertCostCutSet = true ; } |
267 | void unsetAlertCostCut(){ _alertCostCutSet = false ; } |
268 | void setPanicCostCut( double value ){ _panicCostCut = value ; _panicCostCutSet = true ; } |
269 | void unsetPanicCostCut(){ _panicCostCutSet = false ; } |
270 | void setMinCostCut( double value ){ _minCostCut = value ; _minCostCutSet = true ; } |
271 | void unsetMinCostCut(){ _minCostCutSet = false ; } |
272 | void setFallbackCostCut( double value ){ _fallbackCostCut = value ; _fallbackCostCutSet = true ; } |
273 | void unsetFallbackCostCut(){ _fallbackCostCutSet = false ; } |
274 | void setMaxPnfsFileCopies( int value ){ _maxPnfsFileCopies = value ; _maxPnfsFileCopiesSet = true ; } |
275 | void unsetMaxPnfsFileCopies(){ _maxPnfsFileCopiesSet = false ; } |
276 | void setPerformanceCostFactor( double value ){ _performanceCostFactor = value ; _performanceCostFactorSet = true ; } |
277 | void unsetPerformanceCostFactor(){ _performanceCostFactorSet = false ; } |
278 | void setSpaceCostFactor( double value ){ _spaceCostFactor = value ; _spaceCostFactorSet = true ; } |
279 | void unsetSpaceCostFactor(){ _spaceCostFactorSet = false ; } |
280 | } |