/** * @Title: getMaximumAvaliableCapacity @Description: get the number of maximum capacity * * @return the number of maximum capacity * @throws */ public synchronized long getMaximumAvaliableCapacity() { long capacity = 0; Collection<InstanceStatus> attachedInstances = InstanceFilter.getAttachedInstances(allInstances); for (InstanceStatus instanceStatus : attachedInstances) { InstanceTemplate instanceTemplate = instanceStatus.getType(); capacity += instanceTemplate.getMaximunCapacity(); } return capacity; }
/** * @Title: handOver @Description: replace on chosen spot type with another unchosen spot type * * @param oldChosenType the old spot type * @param newChosenType the new unchosen spot type * @throws */ public synchronized void handOver( InstanceTemplate oldChosenType, InstanceTemplate newChosenType) { if (!spotGroups.containsKey(oldChosenType)) { throw new IllegalArgumentException(oldChosenType.toString() + " not chosen"); } if (spotGroups.containsKey(newChosenType)) { throw new IllegalArgumentException(newChosenType.toString() + " already chosen"); } Set<InstanceStatus> instances = spotGroups.remove(oldChosenType); spotGroups.put(newChosenType, instances); }
/** * @Title: getNominalCapacity @Description: get the number of capacity if all nominal instances * are online * * @return * @throws */ public synchronized long getNominalCapacity() { FaultTolerantLevel ftLevel = FaultTolerantLevel.ZERO; if (isSpotEnabled()) { ftLevel = this.faultTolerantLevel; } long capacity = 0; Collection<InstanceStatus> nominalInstances = InstanceFilter.getNominalInstances(allInstances); for (InstanceStatus instanceStatus : nominalInstances) { InstanceTemplate instanceTemplate = instanceStatus.getType(); capacity += instanceTemplate.getCapacity(ftLevel); } return capacity; }
/** * @Title: addChosenSpotType @Description: add one spot type if not chosen * * @param type the spot type wants to choose * @throws */ public synchronized void addChosenSpotType(InstanceTemplate type) { if (spotGroups.containsKey(type)) { return; } Set<InstanceStatus> group = new HashSet<InstanceStatus>(); if (hasOrphan()) { List<InstanceStatus> orphansToMove = null; for (InstanceStatus instanceStatus : orphans) { if (instanceStatus.getType().equals(type)) { if (orphansToMove == null) { orphansToMove = new ArrayList<InstanceStatus>(); } orphansToMove.add(instanceStatus); } } if (orphansToMove != null) { orphans.removeAll(orphansToMove); group.addAll(orphansToMove); } } for (Entry<InstanceTemplate, Set<InstanceStatus>> entry : spotGroups.entrySet()) { Set<InstanceStatus> set = entry.getValue(); if (set.size() > 0) { List<InstanceStatus> instancesToMove = null; for (InstanceStatus instanceStatus : set) { InstanceTemplate instanceTemplate = instanceStatus.getType(); if (instanceTemplate.equals(type)) { if (instancesToMove == null) { instancesToMove = new ArrayList<InstanceStatus>(); } instancesToMove.add(instanceStatus); } } if (instancesToMove != null) { set.removeAll(instancesToMove); group.addAll(instancesToMove); } } } spotGroups.put(type, group); }
/** * @Title: getAvailableCapacity @Description: get the number of current capacity * * @return the number of current capacity * @throws */ public synchronized long getAvailableCapacity() { FaultTolerantLevel ftLevel = FaultTolerantLevel.ZERO; if (isSpotEnabled()) { ftLevel = this.faultTolerantLevel; } long capacity = 0; Collection<InstanceStatus> attachedInstances = InstanceFilter.getAttachedInstances(allInstances); for (InstanceStatus instanceStatus : attachedInstances) { InstanceTemplate instanceTemplate = instanceStatus.getType(); if (instanceStatus instanceof OnDemandInstanceStatus) { capacity += instanceTemplate.getCapacity(FaultTolerantLevel.ZERO); } else { capacity += instanceTemplate.getCapacity(ftLevel); } } return capacity; }
/** * @Title: moveOrphanToType @Description: assign orphan in the spot type * * @param type the spot type to move to * @return whether the operation is successful * @throws */ public synchronized boolean moveOrphanToType(InstanceTemplate type) { Set<InstanceStatus> group = spotGroups.get(type); if (group == null) { throw new IllegalArgumentException("non chosen spot type " + type.toString()); } if (hasOrphan()) { InstanceStatus instanceStatus = orphans.poll(); group.add(instanceStatus); return true; } return false; }