Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
minor modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloricardomg committed Jun 26, 2010
1 parent 4c17266 commit 2d46c19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
@@ -1,6 +1,8 @@
package org.globus.workspace.spotinstances;

import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;

Expand All @@ -10,6 +12,7 @@
import org.nimbustools.api.repr.vm.NIC;



public class SIRequest implements Comparable<SIRequest>{

private String id;
Expand Down Expand Up @@ -75,6 +78,10 @@ public Integer getNeededInstances(){
public Integer getAllocatedInstances() {
return allocatedVMs.size();
}

public Collection<Integer> getVMIds(){
return Collections.unmodifiableCollection(this.allocatedVMs);
}

public void addCreatedVMs(int[] createdIds) {
if(createdIds != null && createdIds.length > 0){
Expand Down Expand Up @@ -117,7 +124,14 @@ private void setStatus(SIRequestStatus status) {

@Override
public int compareTo(SIRequest o) {
return getMaxBid().compareTo(o.getMaxBid());
int compareBid = getMaxBid().compareTo(o.getMaxBid());

if(compareBid == 0){
//Older created requests have preference over newly created ones
return this.creationTime.compareTo(o.creationTime);
}

return compareBid;
}

public Caller getCaller() {
Expand Down Expand Up @@ -181,7 +195,7 @@ public void fulfillVM(int vmid, Double spotPrice) {
}

private void changeStatus(Double spotPrice) {
if(this.allocatedVMs.isEmpty()){
if(spotPrice != null && this.allocatedVMs.isEmpty()){
if(!this.persistent && (!needsMoreInstances() || spotPrice > this.maxBid)){
this.setStatus(SIRequestStatus.CLOSED);
} else {
Expand All @@ -198,7 +212,7 @@ public VirtualMachine[] getUnallocatedVMs(int quantity) throws SIRequestExceptio
VirtualMachine[] result = new VirtualMachine[quantity];
int j = 0;

for (int i = 0; i < quantity; i++) {
for (int i = 0; i < bindings.length && j < quantity; i++) {
VirtualMachine current = bindings[i];
if(current.getID().equals(-1)){
result[j++] = current;
Expand Down Expand Up @@ -232,6 +246,9 @@ public Calendar getCreationTime() {
}

public void cancelRequest() {
for (Integer id : allocatedVMs) {
fulfillVM(id, null);
}
this.setStatus(SIRequestStatus.CANCELLED);
}
}
Expand Up @@ -6,7 +6,7 @@

public class SIRequestUtils {

public static Collection<SIRequest> getRequestsEqualPrice(
public static List<SIRequest> getRequestsEqualPrice(
Double price, Collection<SIRequest> allRequests) {

List<SIRequest> offersEqualPrice = new ArrayList<SIRequest>();
Expand All @@ -20,7 +20,7 @@ public static Collection<SIRequest> getRequestsEqualPrice(
return offersEqualPrice;
}

public static Collection<SIRequest> getRequestsAbovePrice(Double price,
public static List<SIRequest> getRequestsAbovePrice(Double price,
Collection<SIRequest> allRequests) {

List<SIRequest> offersAbovePrice = new ArrayList<SIRequest>();
Expand All @@ -34,7 +34,7 @@ public static Collection<SIRequest> getRequestsAbovePrice(Double price,
return offersAbovePrice;
}

public static Collection<SIRequest> filterActiveRequestsBelowPrice(Double price,
public static List<SIRequest> filterActiveRequestsBelowPrice(Double price,
Collection<SIRequest> allRequests) {

List<SIRequest> activeRequestsBelowPrice = new ArrayList<SIRequest>();
Expand All @@ -48,7 +48,7 @@ public static Collection<SIRequest> filterActiveRequestsBelowPrice(Double price,
return activeRequestsBelowPrice;
}

public static Collection<SIRequest> filterActiveRequestsEqualPrice(
public static List<SIRequest> filterActiveRequestsEqualPrice(
Double price, Collection<SIRequest> allRequests) {

List<SIRequest> activeRequestsEqualPrice = new ArrayList<SIRequest>();
Expand All @@ -62,7 +62,7 @@ public static Collection<SIRequest> filterActiveRequestsEqualPrice(
return activeRequestsEqualPrice;
}

public static Collection<SIRequest> filterOpenRequestsEqualPrice(
public static List<SIRequest> filterOpenRequestsEqualPrice(
Double price, Collection<SIRequest> allRequests) {

List<SIRequest> inactiveRequestsEqualPrice = new ArrayList<SIRequest>();
Expand All @@ -76,7 +76,7 @@ public static Collection<SIRequest> filterOpenRequestsEqualPrice(
return inactiveRequestsEqualPrice;
}

public static Collection<SIRequest> filterAliveRequestsAbovePrice(
public static List<SIRequest> filterAliveRequestsAbovePrice(
Double currentPrice, Collection<SIRequest> allRequests) {
List<SIRequest> aliveRequestsAbovePrice = new ArrayList<SIRequest>();

Expand All @@ -89,7 +89,7 @@ public static Collection<SIRequest> filterAliveRequestsAbovePrice(
return aliveRequestsAbovePrice;
}

public static Collection<SIRequest> filterAliveRequests(
public static List<SIRequest> filterAliveRequests(
Collection<SIRequest> allRequests) {

List<SIRequest> aliveRequests = new ArrayList<SIRequest>();
Expand All @@ -101,6 +101,20 @@ public static Collection<SIRequest> filterAliveRequests(
}

return aliveRequests;
}

public static List<SIRequest> filterHungryAliveRequestsEqualPrice(
Double price, Collection<SIRequest> allRequests) {

List<SIRequest> hungryRequests = new ArrayList<SIRequest>();

for (SIRequest siRequest : allRequests) {
if(siRequest.getMaxBid().equals(price) && siRequest.needsMoreInstances() && siRequest.getStatus().isAlive()){
hungryRequests.add(siRequest);
}
}

return hungryRequests;
}


Expand Down

0 comments on commit 2d46c19

Please sign in to comment.