Skip to content

Commit

Permalink
Fix #349: Added VM Retry Counter & the functionalities to set it to d…
Browse files Browse the repository at this point in the history
…efault (PR #398)

- Introduces the VmCreation class and moves some attributes and methods from broker there
- Renames some methods and change signature to simplify calls

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Co-authored-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
sohamchari and manoelcampos committed Nov 24, 2022
1 parent 745222b commit 111b8d9
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 84 deletions.
50 changes: 8 additions & 42 deletions src/main/java/org/cloudbus/cloudsim/brokers/DatacenterBroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,51 +449,10 @@ public interface DatacenterBroker extends SimEntity {
*
* @param <T> the class of VMs inside the list
* @return the list of failed VMs
* @see #setFailedVmsRetryDelay(double)
* @see VmCreation#setRetryDelay(double)
*/
<T extends Vm> List<T> getVmFailedList();

/**
* Checks if the broker has to retry allocating VMs
* that couldn't be placed due to lack of suitable Hosts.
* @return
*/
boolean isRetryFailedVms();

/**
* Gets a delay (in seconds) for the broker to retry allocating VMs
* that couldn't be placed due to lack of suitable active Hosts.
*
* @return
* <ul>
* <li>a value larger than zero to indicate the broker will retry
* to place failed VM as soon as new VMs or Cloudlets
* are submitted or after the given delay.</li>
* <li>otherwise, to indicate failed VMs will be just added to the
* {@link #getVmFailedList()} and the user simulation have to deal with it.
* If the VM has an {@link Vm#addOnCreationFailureListener(EventListener) OnCreationFailureListener},
* it will be notified about the failure.</li>
* </ul>
*/
double getFailedVmsRetryDelay();

/**
* Sets a delay (in seconds) for the broker to retry allocating VMs
* that couldn't be placed due to lack of suitable active Hosts.
*
* Setting the attribute as:
* <ul>
* <li>larger than zero, the broker will retry to place failed VM as soon as new VMs or Cloudlets
* are submitted or after the given delay.</li>
* <li>otherwise, failed VMs will be just added to the {@link #getVmFailedList()}
* and the user simulation have to deal with it.
* If the VM has an {@link Vm#addOnCreationFailureListener(EventListener) OnCreationFailureListener},
* it will be notified about the failure.</li>
* </ul>
* @param failedVmsRetryDelay
*/
void setFailedVmsRetryDelay(double failedVmsRetryDelay);

/**
* Checks if the broker must be shut down after becoming idle.
* @return
Expand All @@ -505,4 +464,11 @@ public interface DatacenterBroker extends SimEntity {
* @return
*/
DatacenterBroker setShutdownWhenIdle(boolean shutdownWhenIdle);

/**
* Gets the object that keeps track of number of VM creation retries sent by the broker
* and enables configuring creation retries.
* @return
*/
VmCreation getVmCreation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public abstract class DatacenterBrokerAbstract extends CloudSimEntity implements
*/
private Datacenter lastSelectedDc;

/** @see #setFailedVmsRetryDelay(double) */
private double failedVmsRetryDelay;
private VmCreation vmCreation;

/** @see #getVmFailedList() */
private final List<Vm> vmFailedList;
Expand Down Expand Up @@ -118,9 +117,6 @@ public abstract class DatacenterBrokerAbstract extends CloudSimEntity implements
/** @see #setCloudletComparator(Comparator) */
private Comparator<Cloudlet> cloudletComparator;

/** @see #getVmCreationRequests() */
private int vmCreationRequests;

/** @see #getDatacenterList() */
private List<Datacenter> datacenterList;

Expand Down Expand Up @@ -158,8 +154,7 @@ public DatacenterBrokerAbstract(final CloudSim simulation, final String name) {
this.lastSelectedDc = Datacenter.NULL;
this.shutdownWhenIdle = true;

this.vmCreationRequests = 0;
this.failedVmsRetryDelay = 5;
this.vmCreation = new VmCreation();
this.vmFailedList = new ArrayList<>();
this.vmWaitingList = new ArrayList<>();
this.vmExecList = new ArrayList<>();
Expand Down Expand Up @@ -622,7 +617,7 @@ private boolean processVmCreateResponseFromDatacenter(final SimEvent evt) {
vm.notifyOnHostAllocationListeners();
} else {
vm.setFailed(true);
if(!isRetryFailedVms()){
if(!vmCreation.isRetryFailedVms()){
vmWaitingList.remove(vm);
vmFailedList.add(vm);
LOGGER.warn(
Expand All @@ -634,9 +629,9 @@ private boolean processVmCreateResponseFromDatacenter(final SimEvent evt) {
}

//Decreases to indicate an ack for the request was received (either if the VM was created or not)
vmCreationRequests--;
vmCreation.incCreationRequests(-1);

if(vmCreationRequests == 0 && !vmWaitingList.isEmpty()) {
if(vmCreation.getCreationRequests() == 0 && !vmWaitingList.isEmpty()) {
requestCreationOfWaitingVmsToFallbackDatacenter();
}

Expand Down Expand Up @@ -669,6 +664,10 @@ private void notifyOnVmsCreatedListeners() {
final var listener = onVmsCreatedListeners.get(i);
listener.update(DatacenterBrokerEventInfo.of(listener, this));
}

if (vmWaitingList.isEmpty()) {
vmCreation.resetCurrentRetries();
}
}

/**
Expand All @@ -686,7 +685,7 @@ private void requestCreationOfWaitingVmsToFallbackDatacenter() {

final var msg =
"{}: {}: {} of the requested {} VMs couldn't be created because suitable Hosts weren't found in any available Datacenter."
+ (vmExecList.isEmpty() && !isRetryFailedVms() ? " Shutting broker down..." : "");
+ (vmExecList.isEmpty() && !vmCreation.isRetryFailedVms() ? " Shutting broker down..." : "");
LOGGER.error(msg, getSimulation().clockStr(), getName(), vmWaitingList.size(), getVmsNumber());

/* If it gets here, it means that all datacenters were already queried and not all VMs could be created. */
Expand All @@ -699,10 +698,11 @@ private void requestCreationOfWaitingVmsToFallbackDatacenter() {
}

private void processVmCreationFailure() {
if (isRetryFailedVms()) {
if (vmCreation.isRetryFailedVms()) {
lastSelectedDc = datacenterList.get(0);
this.vmCreationRetrySent = true;
schedule(failedVmsRetryDelay, CloudSimTag.VM_CREATE_RETRY);
schedule(vmCreation.getRetryDelay(), CloudSimTag.VM_CREATE_RETRY);
vmCreation.incCurrentRetries();
} else shutdown();
}

Expand All @@ -729,7 +729,7 @@ private boolean requestDatacenterToCreateWaitingVms(final boolean isFallbackData
if(creationRetry) {
vm.setLastTriedDatacenter(Datacenter.NULL);
}
this.vmCreationRequests += requestVmCreation(lastSelectedDc, isFallbackDatacenter, vm);
vmCreation.incCreationRequests(requestVmCreation(lastSelectedDc, isFallbackDatacenter, vm));
}

return lastSelectedDc != Datacenter.NULL;
Expand Down Expand Up @@ -1122,15 +1122,6 @@ protected Vm getVmFromCreatedList(final int vmIndex) {
return vmIndex >= 0 && vmIndex < vmExecList.size() ? vmExecList.get(vmIndex) : Vm.NULL;
}

/**
* Gets the number of VM creation requests.
*
* @return the number of VM creation requests
*/
protected int getVmCreationRequests() {
return vmCreationRequests;
}

/**
* Gets the list of available datacenters.
*
Expand Down Expand Up @@ -1300,21 +1291,6 @@ public <T extends Vm> List<T> getVmFailedList() {
return (List<T>) vmFailedList;
}

@Override
public boolean isRetryFailedVms() {
return failedVmsRetryDelay > 0;
}

@Override
public double getFailedVmsRetryDelay() {
return failedVmsRetryDelay;
}

@Override
public void setFailedVmsRetryDelay(final double failedVmsRetryDelay) {
this.failedVmsRetryDelay = failedVmsRetryDelay;
}

@Override
public boolean isShutdownWhenIdle() {
return shutdownWhenIdle;
Expand All @@ -1325,4 +1301,9 @@ public DatacenterBroker setShutdownWhenIdle(final boolean shutdownWhenIdle) {
this.shutdownWhenIdle = shutdownWhenIdle;
return this;
}

@Override
public VmCreation getVmCreation() {
return vmCreation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ final class DatacenterBrokerNull implements DatacenterBroker, SimEntityNullBase
@Override public DatacenterBroker setVmDestructionDelay(double delay) { return this; }
@Override public List<Cloudlet> getCloudletSubmittedList() { return Collections.emptyList(); }
@Override public <T extends Vm> List<T> getVmFailedList() { return Collections.emptyList(); }
@Override public boolean isRetryFailedVms() { return false; }
@Override public double getFailedVmsRetryDelay() { return 0; }
@Override public void setFailedVmsRetryDelay(double failedVmsRetryDelay) {/**/}
@Override public VmCreation getVmCreation() { return VmCreation.ofZero(); }
@Override public boolean isShutdownWhenIdle() { return false; }
@Override public DatacenterBroker setShutdownWhenIdle(boolean shutdownWhenIdle) { return this; }
@Override public DatacenterBroker setVmComparator(Comparator<Vm> comparator) { return this; }
Expand Down

0 comments on commit 111b8d9

Please sign in to comment.