| 1 | // $Id: CostModuleV1.java,v 1.21 2007-08-01 20:19:23 tigran Exp $ |
| 2 | |
| 3 | package diskCacheV111.poolManager ; |
| 4 | import java.io.PrintWriter; |
| 5 | import java.io.StringWriter; |
| 6 | import java.util.Arrays; |
| 7 | import java.util.HashMap; |
| 8 | import java.util.Map; |
| 9 | import java.util.regex.Pattern; |
| 10 | |
| 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; |
| 13 | import org.dcache.cells.AbstractCellComponent; |
| 14 | import org.dcache.cells.CellCommandListener; |
| 15 | import org.dcache.cells.CellMessageDispatcher; |
| 16 | import org.dcache.cells.CellMessageReceiver; |
| 17 | |
| 18 | import diskCacheV111.pools.CostCalculatable; |
| 19 | import diskCacheV111.pools.CostCalculationEngine; |
| 20 | import diskCacheV111.pools.PoolCostInfo; |
| 21 | import diskCacheV111.pools.PoolV2Mode; |
| 22 | import diskCacheV111.pools.PoolCostInfo.NamedPoolQueueInfo; |
| 23 | import diskCacheV111.vehicles.CostModulePoolInfoTable; |
| 24 | import diskCacheV111.vehicles.DoorTransferFinishedMessage; |
| 25 | import diskCacheV111.vehicles.Pool2PoolTransferMsg; |
| 26 | import diskCacheV111.vehicles.PoolCostCheckable; |
| 27 | import diskCacheV111.vehicles.PoolFetchFileMessage; |
| 28 | import diskCacheV111.vehicles.PoolIoFileMessage; |
| 29 | import diskCacheV111.vehicles.PoolAcceptFileMessage; |
| 30 | import diskCacheV111.vehicles.PoolManagerPoolUpMessage; |
| 31 | import diskCacheV111.vehicles.PoolMgrSelectPoolMsg; |
| 32 | import diskCacheV111.vehicles.PoolMgrSelectWritePoolMsg; |
| 33 | import dmg.cells.nucleus.CellMessage; |
| 34 | import dmg.util.Args; |
| 35 | |
| 36 | public class CostModuleV1 |
| 37 | extends AbstractCellComponent |
| 38 | implements CostModule, |
| 39 | CellCommandListener, |
| 40 | CellMessageReceiver |
| 41 | { |
| 42 | /** The file size used when calculating performance cost ranked percentile */ |
| 43 | public static final long PERCENTILE_FILE_SIZE = 104857600; |
| 44 | private final static Logger _log = LoggerFactory.getLogger(CostModuleV1.class); |
| 45 | |
| 46 | private final Map<String, Entry> _hash = new HashMap<String, Entry>() ; |
| 47 | private boolean _isActive = true ; |
| 48 | private boolean _update = true ; |
| 49 | private boolean _magic = true ; |
| 50 | private boolean _debug = false ; |
| 51 | private boolean _cachedPercentileCostIsValid = false; |
| 52 | private double _cachedPercentileCost; |
| 53 | private double _cachedPercentileFraction; |
| 54 | private final CellMessageDispatcher _handlers = |
| 55 | new CellMessageDispatcher("messageToForward"); |
| 56 | |
| 57 | /** |
| 58 | * Information about some specific pool. |
| 59 | */ |
| 60 | private static class Entry { |
| 61 | private long timestamp ; |
| 62 | private PoolCostInfo _info ; |
| 63 | private double _fakeCpu = -1.0 ; |
| 64 | private double _fakeSpace = -1.0 ; |
| 65 | private Map<String, String> _tagMap = null; |
| 66 | private Entry( PoolCostInfo info ){ |
| 67 | setPoolCostInfo(info) ; |
| 68 | } |
| 69 | private void setPoolCostInfo( PoolCostInfo info ){ |
| 70 | timestamp = System.currentTimeMillis(); |
| 71 | _info = info ; |
| 72 | } |
| 73 | private PoolCostInfo getPoolCostInfo(){ |
| 74 | return _info ; |
| 75 | } |
| 76 | private boolean isValid(){ |
| 77 | return ( System.currentTimeMillis() - timestamp ) < 5*60*1000L ; |
| 78 | } |
| 79 | private void setTagMap(Map<String, String> tagMap) { |
| 80 | _tagMap = tagMap; |
| 81 | } |
| 82 | private Map<String, String> getTagMap() { |
| 83 | return _tagMap; |
| 84 | } |
| 85 | } |
| 86 | private CostCalculationEngine _costCalculationEngine = null ; |
| 87 | private class CostCheck extends PoolCheckAdapter implements PoolCostCheckable { |
| 88 | |
| 89 | private PoolCostInfo _info ; |
| 90 | |
| 91 | private static final long serialVersionUID = -77487683158664348L; |
| 92 | |
| 93 | private CostCheck( String poolName , Entry e , long filesize ){ |
| 94 | super(poolName,filesize); |
| 95 | _info = e.getPoolCostInfo() ; |
| 96 | |
| 97 | CostCalculatable cost = _costCalculationEngine.getCostCalculatable( _info ) ; |
| 98 | |
| 99 | cost.recalculate( filesize ) ; |
| 100 | |
| 101 | setSpaceCost( e._fakeSpace > -1.0 ? |
| 102 | e._fakeSpace : |
| 103 | cost.getSpaceCost() ) ; |
| 104 | setPerformanceCost( e._fakeCpu > -1.0 ? |
| 105 | e._fakeCpu : |
| 106 | cost.getPerformanceCost() ) ; |
| 107 | setTagMap( e.getTagMap() ); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | public CostModuleV1() |
| 112 | { |
| 113 | _handlers.addMessageListener(this); |
| 114 | } |
| 115 | |
| 116 | public void setCostCalculationEngine(CostCalculationEngine engine) |
| 117 | { |
| 118 | _costCalculationEngine = engine; |
| 119 | } |
| 120 | |
| 121 | public synchronized void messageArrived(PoolManagerPoolUpMessage msg) |
| 122 | { |
| 123 | if (! _update) |
| 124 | return; |
| 125 | |
| 126 | String poolName = msg.getPoolName(); |
| 127 | PoolV2Mode poolMode = msg.getPoolMode(); |
| 128 | PoolCostInfo newInfo = msg.getPoolCostInfo(); |
| 129 | |
| 130 | /* Whether the pool mentioned in the message should be removed */ |
| 131 | boolean removePool = poolMode.getMode() == PoolV2Mode.DISABLED || |
| 132 | poolMode.isDisabled(PoolV2Mode.DISABLED_STRICT) || |
| 133 | poolMode.isDisabled(PoolV2Mode.DISABLED_DEAD); |
| 134 | |
| 135 | |
| 136 | /* Check whether we should invalidate the cached entry. We should |
| 137 | * only need to do this if: |
| 138 | * * a new pool is discovered, |
| 139 | * * an existing pool is removed, |
| 140 | * * either: |
| 141 | * o a pool with cost less than the cached value assumes a cost greater |
| 142 | * than the cached value, |
| 143 | * o a pool with the cached value takes on a different value, |
| 144 | * o a pool with cost greater than the cached value assumes a cost less |
| 145 | * than the cached value. |
| 146 | */ |
| 147 | if( _cachedPercentileCostIsValid) { |
| 148 | Entry poolEntry = _hash.get( poolName); |
| 149 | if( poolEntry != null) { |
| 150 | if( removePool) { |
| 151 | _cachedPercentileCostIsValid = false; |
| 152 | } else { |
| 153 | PoolCostInfo oldInfo = poolEntry.getPoolCostInfo(); |
| 154 | double oldCost = _costCalculationEngine.getCostCalculatable( oldInfo).getPerformanceCost(); |
| 155 | double newCost = _costCalculationEngine.getCostCalculatable( newInfo).getPerformanceCost(); |
| 156 | |
| 157 | if( Math.signum( oldCost-_cachedPercentileCost) != Math.signum( newCost-_cachedPercentileCost)) |
| 158 | _cachedPercentileCostIsValid = false; |
| 159 | } |
| 160 | } else { |
| 161 | if( !removePool) |
| 162 | _cachedPercentileCostIsValid = false; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if ( !removePool) { |
| 167 | if( newInfo != null) { |
| 168 | Entry e = _hash.get(poolName); |
| 169 | |
| 170 | if (e == null) { |
| 171 | e = new Entry( newInfo); |
| 172 | _hash.put(poolName, e); |
| 173 | } else { |
| 174 | e.setPoolCostInfo( newInfo); |
| 175 | } |
| 176 | e.setTagMap(msg.getTagMap()); |
| 177 | } |
| 178 | } else { |
| 179 | _hash.remove(poolName); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | public synchronized void messageToForward(PoolIoFileMessage msg) |
| 184 | { |
| 185 | String poolName = msg.getPoolName(); |
| 186 | Entry e = _hash.get(poolName); |
| 187 | if (e == null) |
| 188 | return; |
| 189 | |
| 190 | String requestedQueueName = msg.getIoQueueName(); |
| 191 | |
| 192 | PoolCostInfo costInfo = e.getPoolCostInfo(); |
| 193 | Map<String, NamedPoolQueueInfo> map = |
| 194 | costInfo.getExtendedMoverHash(); |
| 195 | |
| 196 | PoolCostInfo.PoolQueueInfo queue; |
| 197 | PoolCostInfo.PoolSpaceInfo spaceInfo = costInfo.getSpaceInfo(); |
| 198 | |
| 199 | if (map == null) { |
| 200 | queue = costInfo.getMoverQueue(); |
| 201 | } else { |
| 202 | requestedQueueName = |
| 203 | (requestedQueueName == null || |
| 204 | map.get(requestedQueueName) == null) |
| 205 | ? costInfo.getDefaultQueueName() |
| 206 | : requestedQueueName; |
| 207 | queue = map.get(requestedQueueName); |
| 208 | } |
| 209 | |
| 210 | int diff = 0; |
| 211 | long pinned = 0; |
| 212 | if (msg.isReply() && msg.getReturnCode() != 0) { |
| 213 | diff = -1; |
| 214 | if (msg instanceof PoolAcceptFileMessage) { |
| 215 | pinned = -msg.getStorageInfo().getFileSize(); |
| 216 | } |
| 217 | } else if (!msg.isReply() && !_magic) { |
| 218 | diff = 1; |
| 219 | if (msg instanceof PoolAcceptFileMessage) { |
| 220 | pinned = msg.getStorageInfo().getFileSize(); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | queue.modifyQueue(diff); |
| 225 | spaceInfo.modifyPinnedSpace(pinned); |
| 226 | |
| 227 | xsay("Mover"+(requestedQueueName==null?"":("("+requestedQueueName+")")) , poolName, diff, pinned, msg); |
| 228 | } |
| 229 | |
| 230 | public synchronized void messageToForward(DoorTransferFinishedMessage msg) |
| 231 | { |
| 232 | String poolName = msg.getPoolName(); |
| 233 | Entry e = _hash.get(poolName); |
| 234 | if (e == null) |
| 235 | return; |
| 236 | |
| 237 | PoolCostInfo costInfo = e.getPoolCostInfo(); |
| 238 | String requestedQueueName = msg.getIoQueueName(); |
| 239 | |
| 240 | Map<String, NamedPoolQueueInfo> map = |
| 241 | costInfo.getExtendedMoverHash(); |
| 242 | PoolCostInfo.PoolQueueInfo queue; |
| 243 | |
| 244 | if (map == null) { |
| 245 | queue = costInfo.getMoverQueue(); |
| 246 | } else { |
| 247 | requestedQueueName = |
| 248 | (requestedQueueName == null) || |
| 249 | (map.get(requestedQueueName) == null) |
| 250 | ? costInfo.getDefaultQueueName() |
| 251 | : requestedQueueName; |
| 252 | |
| 253 | queue = map.get(requestedQueueName); |
| 254 | } |
| 255 | |
| 256 | int diff = -1; |
| 257 | long pinned = 0; |
| 258 | |
| 259 | queue.modifyQueue(diff); |
| 260 | |
| 261 | xsay("Mover"+(requestedQueueName==null?"":("("+requestedQueueName+")")), poolName, diff, pinned, msg); |
| 262 | } |
| 263 | |
| 264 | public synchronized void messageToForward(PoolFetchFileMessage msg) |
| 265 | { |
| 266 | String poolName = msg.getPoolName(); |
| 267 | Entry e = _hash.get(poolName); |
| 268 | if (e == null) |
| 269 | return; |
| 270 | |
| 271 | PoolCostInfo costInfo = e.getPoolCostInfo(); |
| 272 | PoolCostInfo.PoolQueueInfo queue = costInfo.getRestoreQueue(); |
| 273 | PoolCostInfo.PoolSpaceInfo spaceInfo = costInfo.getSpaceInfo(); |
| 274 | |
| 275 | int diff; |
| 276 | long pinned; |
| 277 | if (!msg.isReply()) { |
| 278 | diff = 1; |
| 279 | pinned = msg.getStorageInfo().getFileSize(); |
| 280 | } else { |
| 281 | diff = -1; |
| 282 | pinned = 0; |
| 283 | } |
| 284 | queue.modifyQueue(diff); |
| 285 | spaceInfo.modifyPinnedSpace(pinned); |
| 286 | |
| 287 | xsay("Restore", poolName, diff, pinned, msg); |
| 288 | } |
| 289 | |
| 290 | public synchronized void messageToForward(PoolMgrSelectPoolMsg msg) |
| 291 | { |
| 292 | if (!_magic) |
| 293 | return; |
| 294 | |
| 295 | if (!msg.isReply()) |
| 296 | return; |
| 297 | String poolName = msg.getPoolName(); |
| 298 | Entry e = _hash.get(poolName); |
| 299 | if (e == null) |
| 300 | return; |
| 301 | |
| 302 | String requestedQueueName = msg.getIoQueueName(); |
| 303 | |
| 304 | PoolCostInfo costInfo = e.getPoolCostInfo(); |
| 305 | Map<String, NamedPoolQueueInfo> map = |
| 306 | costInfo.getExtendedMoverHash(); |
| 307 | PoolCostInfo.PoolQueueInfo queue; |
| 308 | PoolCostInfo.PoolSpaceInfo spaceInfo = costInfo.getSpaceInfo(); |
| 309 | |
| 310 | if (map == null) { |
| 311 | queue = costInfo.getMoverQueue(); |
| 312 | } else { |
| 313 | requestedQueueName = |
| 314 | (requestedQueueName == null) || |
| 315 | (map.get(requestedQueueName) == null) |
| 316 | ? costInfo.getDefaultQueueName() |
| 317 | : requestedQueueName; |
| 318 | queue = map.get(requestedQueueName); |
| 319 | } |
| 320 | |
| 321 | int diff = 1; |
| 322 | long pinned = |
| 323 | (msg instanceof PoolMgrSelectWritePoolMsg) ? msg.getFileSize() : 0; |
| 324 | queue.modifyQueue(diff); |
| 325 | spaceInfo.modifyPinnedSpace(pinned); |
| 326 | |
| 327 | xsay("Mover (magic)"+(requestedQueueName==null?"":("("+requestedQueueName+")")), poolName, diff, pinned, msg); |
| 328 | } |
| 329 | |
| 330 | public synchronized void messageToForward(Pool2PoolTransferMsg msg) |
| 331 | { |
| 332 | _log.debug( "Pool2PoolTransferMsg : reply="+msg.isReply()); |
| 333 | |
| 334 | String sourceName = msg.getSourcePoolName(); |
| 335 | Entry source = _hash.get(sourceName); |
| 336 | if (source == null) |
| 337 | return; |
| 338 | |
| 339 | PoolCostInfo.PoolQueueInfo sourceQueue = |
| 340 | source.getPoolCostInfo().getP2pQueue(); |
| 341 | |
| 342 | String destinationName = msg.getDestinationPoolName(); |
| 343 | Entry destination = _hash.get(destinationName); |
| 344 | if (destination == null) |
| 345 | return; |
| 346 | |
| 347 | PoolCostInfo.PoolQueueInfo destinationQueue = |
| 348 | destination.getPoolCostInfo().getP2pClientQueue(); |
| 349 | PoolCostInfo.PoolSpaceInfo destinationSpaceInfo = |
| 350 | destination.getPoolCostInfo().getSpaceInfo(); |
| 351 | |
| 352 | int diff = msg.isReply() ? -1 : 1; |
| 353 | long pinned = msg.getStorageInfo().getFileSize(); |
| 354 | |
| 355 | sourceQueue.modifyQueue(diff); |
| 356 | destinationQueue.modifyQueue(diff); |
| 357 | destinationSpaceInfo.modifyPinnedSpace(pinned); |
| 358 | |
| 359 | xsay("P2P client (magic)", destinationName, diff, pinned, msg); |
| 360 | xsay("P2P server (magic)", sourceName, diff, 0, msg); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Defined by CostModule interface. Used by PoolManager to inject |
| 365 | * the replies PoolManager sends to doors. |
| 366 | */ |
| 367 | public void messageArrived(CellMessage cellMessage) |
| 368 | { |
| 369 | _handlers.call(cellMessage); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public void getInfo(PrintWriter pw) |
| 374 | { |
| 375 | pw.append( "Submodule : CostModule (cm) : ").println(getClass().getName()); |
| 376 | pw.println("Version : $Revision: 13488 $"); |
| 377 | pw.append(" Debug : ").println(_debug?"on":"off"); |
| 378 | pw.append(" Update : ").println(_update?"on":"off"); |
| 379 | pw.append(" Active : ").println(_isActive?"yes":"no"); |
| 380 | pw.append(" Magic : ").println(_magic?"yes":"no"); |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public void printSetup(PrintWriter pw) |
| 385 | { |
| 386 | pw.append( "#\n# Submodule CostModule (cm) : ") |
| 387 | .println(this.getClass().getName()); |
| 388 | pw.println("# $Revision: 13488 $ \n#\n") ; |
| 389 | pw.println("cm set debug "+(_debug?"on":"off")); |
| 390 | pw.println("cm set update "+(_update?"on":"off")); |
| 391 | pw.println("cm set magic "+(_magic?"on":"off")); |
| 392 | } |
| 393 | |
| 394 | private void xsay(String queue, String pool, int diff, long pinned, Object obj) |
| 395 | { |
| 396 | if (_debug) { |
| 397 | _log.debug("CostModuleV1 : "+queue+" queue of "+pool+" modified by "+diff+"/" + pinned + " due to "+obj.getClass().getName()); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | @Override |
| 402 | public synchronized PoolCostCheckable getPoolCost( String poolName , long filesize ){ |
| 403 | Entry cost = _hash.get(poolName); |
| 404 | |
| 405 | if( ( cost == null ) ||( !cost.isValid() && _update ) ) |
| 406 | return null ; |
| 407 | |
| 408 | return new CostCheck( poolName , cost , filesize ) ; |
| 409 | |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public synchronized double getPoolsPercentilePerformanceCost( double fraction) { |
| 414 | |
| 415 | if( fraction <= 0 || fraction >= 1) |
| 416 | throw new IllegalArgumentException( "supplied fraction (" + Double.toString( fraction) +") not between 0 and 1"); |
| 417 | |
| 418 | if( !_cachedPercentileCostIsValid || _cachedPercentileFraction != fraction) { |
| 419 | |
| 420 | _log.debug( "Rebuilding percentileCost cache"); |
| 421 | |
| 422 | if( _hash.size() > 0) { |
| 423 | if( _log.isDebugEnabled()) |
| 424 | _log.debug( " "+Integer.toString( _hash.size())+" pools available"); |
| 425 | |
| 426 | double poolCosts[] = new double[ _hash.size()]; |
| 427 | |
| 428 | int idx=0; |
| 429 | for( Entry poolInfo : _hash.values()) { |
| 430 | CostCalculatable cost = _costCalculationEngine.getCostCalculatable( poolInfo.getPoolCostInfo()); |
| 431 | cost.recalculate( PERCENTILE_FILE_SIZE); |
| 432 | poolCosts[idx++] = cost.getPerformanceCost(); |
| 433 | } |
| 434 | |
| 435 | Arrays.sort( poolCosts); |
| 436 | |
| 437 | _cachedPercentileCost = poolCosts [ (int) Math.floor( fraction * _hash.size())]; |
| 438 | |
| 439 | } else { |
| 440 | _log.debug( " no pools available"); |
| 441 | _cachedPercentileCost = 0; |
| 442 | } |
| 443 | |
| 444 | _cachedPercentileCostIsValid = true; |
| 445 | _cachedPercentileFraction = fraction; |
| 446 | } |
| 447 | |
| 448 | return _cachedPercentileCost; |
| 449 | } |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | public boolean isActive(){ return _isActive ; } |
| 455 | |
| 456 | public String hh_cm_info = ""; |
| 457 | public String ac_cm_info(Args args) |
| 458 | { |
| 459 | StringWriter s = new StringWriter(); |
| 460 | getInfo(new PrintWriter(s)); |
| 461 | return s.toString(); |
| 462 | } |
| 463 | |
| 464 | public String hh_cm_set_debug = "on|off" ; |
| 465 | public String ac_cm_set_debug_$_1( Args args ){ |
| 466 | if( args.argv(0).equals("on") ){ _debug = true ; } |
| 467 | else if( args.argv(0).equals("off") ){ _debug = false ; } |
| 468 | else throw new IllegalArgumentException("on|off") ; |
| 469 | return ""; |
| 470 | } |
| 471 | public String hh_cm_set_active = "on|off" ; |
| 472 | public String ac_cm_set_active_$_1( Args args ){ |
| 473 | if( args.argv(0).equals("on") ){ _isActive = true ; } |
| 474 | else if( args.argv(0).equals("off") ){ _isActive = false ; } |
| 475 | else throw new IllegalArgumentException("on|off") ; |
| 476 | return ""; |
| 477 | } |
| 478 | public String hh_cm_set_update = "on|off" ; |
| 479 | public String ac_cm_set_update_$_1( Args args ){ |
| 480 | if( args.argv(0).equals("on") ){ _update = true ; } |
| 481 | else if( args.argv(0).equals("off") ){ _update = false ; } |
| 482 | else throw new IllegalArgumentException("on|off") ; |
| 483 | return ""; |
| 484 | } |
| 485 | public String hh_cm_set_magic = "on|off" ; |
| 486 | public String ac_cm_set_magic_$_1( Args args ){ |
| 487 | if( args.argv(0).equals("on") ){ _magic = true ; } |
| 488 | else if( args.argv(0).equals("off") ){ _magic = false ; } |
| 489 | else throw new IllegalArgumentException("on|off") ; |
| 490 | return ""; |
| 491 | } |
| 492 | public String hh_cm_fake = "<poolName> [off] | [-space=<spaceCost>|off] [-cpu=<cpuCost>|off]" ; |
| 493 | public String ac_cm_fake_$_1_2( Args args ){ |
| 494 | String poolName = args.argv(0) ; |
| 495 | Entry e = _hash.get(poolName); |
| 496 | if( e == null ) |
| 497 | throw new |
| 498 | IllegalArgumentException("Pool not found : "+poolName); |
| 499 | |
| 500 | if( args.argc() > 1 ){ |
| 501 | if( args.argv(1).equals("off") ){ |
| 502 | e._fakeCpu = -1.0 ; |
| 503 | e._fakeSpace = -1.0 ; |
| 504 | }else{ |
| 505 | throw new |
| 506 | IllegalArgumentException("Unknown argument : "+args.argv(1)); |
| 507 | } |
| 508 | return "Faked Costs switched off for "+poolName ; |
| 509 | } |
| 510 | String val = args.getOpt("cpu") ; |
| 511 | if( val != null )e._fakeCpu = Double.parseDouble(val) ; |
| 512 | val = args.getOpt("space") ; |
| 513 | if( val != null )e._fakeSpace = Double.parseDouble(val); |
| 514 | |
| 515 | return poolName+" -space="+e._fakeSpace+" -cpu="+e._fakeCpu ; |
| 516 | } |
| 517 | public String hh_xcm_ls = "<poolName> [<filesize>] [-l]" ; |
| 518 | public Object ac_xcm_ls_$_0_2( Args args )throws Exception { |
| 519 | |
| 520 | |
| 521 | if( args.argc()==0 ){ // added by nicolo : binary full cm ls list |
| 522 | |
| 523 | CostModulePoolInfoTable reply = new CostModulePoolInfoTable(); |
| 524 | |
| 525 | /* This cycle browse an HashMap of Entry |
| 526 | * and put the PoolCostInfo object in the |
| 527 | * InfoPoolTable to return. |
| 528 | */ |
| 529 | for (Entry e : _hash.values() ){ |
| 530 | reply.addPoolCostInfo(e.getPoolCostInfo().getPoolName(), e.getPoolCostInfo()); |
| 531 | } |
| 532 | return reply; |
| 533 | |
| 534 | } |
| 535 | |
| 536 | String poolName = args.argv(0) ; |
| 537 | long filesize = Long.parseLong( args.argc() < 2 ? "0" : args.argv(2) ) ; |
| 538 | boolean pci = args.getOpt("l") != null ; |
| 539 | Object [] reply; |
| 540 | |
| 541 | if( pci ){ |
| 542 | |
| 543 | Entry e = _hash.get(poolName) ; |
| 544 | reply = new Object[3] ; |
| 545 | reply[0] = poolName ; |
| 546 | reply[1] = e == null ? null : e.getPoolCostInfo() ; |
| 547 | reply[2] = e == null ? null : Long.valueOf( System.currentTimeMillis() - e.timestamp ) ; |
| 548 | |
| 549 | }else{ |
| 550 | |
| 551 | PoolCostCheckable pcc = getPoolCost( poolName , filesize ) ; |
| 552 | |
| 553 | reply = new Object[4] ; |
| 554 | |
| 555 | reply[0] = poolName ; |
| 556 | reply[1] = Long.valueOf( filesize ) ; |
| 557 | reply[2] = pcc == null ? null : new Double( pcc.getSpaceCost() ) ; |
| 558 | reply[3] = pcc == null ? null : new Double( pcc.getPerformanceCost() ) ; |
| 559 | |
| 560 | } |
| 561 | |
| 562 | return reply ; |
| 563 | } |
| 564 | public String hh_cm_ls = " -d | -t | -r [-size=<filesize>] <pattern> # list all pools" ; |
| 565 | public String ac_cm_ls_$_0_1( Args args )throws Exception { |
| 566 | StringBuilder sb = new StringBuilder() ; |
| 567 | boolean useTime = args.getOpt("t") != null ; |
| 568 | boolean useDetail = args.getOpt("d") != null ; |
| 569 | boolean useReal = args.getOpt("r") != null ; |
| 570 | String sizeStr = args.getOpt("size") ; |
| 571 | long filesize = Long.parseLong( sizeStr == null ? "0" : sizeStr ) ; |
| 572 | Pattern pattern = args.argc() == 0 ? null : Pattern.compile(args.argv(0)) ; |
| 573 | |
| 574 | |
| 575 | for( Entry e : _hash.values() ){ |
| 576 | |
| 577 | String poolName = e.getPoolCostInfo().getPoolName() ; |
| 578 | if( ( pattern != null ) && ( ! pattern.matcher(poolName).matches() ) )continue ; |
| 579 | sb.append(e.getPoolCostInfo().toString()).append("\n") ; |
| 580 | if( useReal ){ |
| 581 | PoolCostCheckable pcc = getPoolCost(poolName,filesize) ; |
| 582 | if( pcc == null ) |
| 583 | sb.append("NONE\n") ; |
| 584 | else |
| 585 | sb.append( getPoolCost(poolName,filesize).toString() ). |
| 586 | append("\n"); |
| 587 | } |
| 588 | if( useDetail ) |
| 589 | sb.append(new CostCheck(poolName,e,filesize).toString()). |
| 590 | append("\n"); |
| 591 | if( useTime ) |
| 592 | sb.append(poolName). |
| 593 | append("="). |
| 594 | append(System.currentTimeMillis()-e.timestamp). |
| 595 | append("\n"); |
| 596 | |
| 597 | } |
| 598 | |
| 599 | return sb.toString(); |
| 600 | } |
| 601 | |
| 602 | |
| 603 | @Override |
| 604 | public synchronized PoolCostInfo getPoolCostInfo(String poolName) { |
| 605 | |
| 606 | PoolCostInfo poolCostInfo = null; |
| 607 | |
| 608 | Entry poolEntry = _hash.get(poolName); |
| 609 | |
| 610 | if( poolEntry != null ) { |
| 611 | poolCostInfo = poolEntry.getPoolCostInfo(); |
| 612 | } |
| 613 | |
| 614 | return poolCostInfo; |
| 615 | } |
| 616 | } |