Skip to content

Commit

Permalink
Code quality review
Browse files Browse the repository at this point in the history
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
manoelcampos committed Oct 16, 2018
1 parent 3093cb4 commit 4f19587
Show file tree
Hide file tree
Showing 36 changed files with 195 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* period of time to balance the load of arrived Cloudlets
* or even to enable fault tolerance.</p>
*
* <p>See the {@link DatacenterBroker#DEFAULT_VM_DESTRUCTION_DELAY}
* <p>See the {@link DatacenterBroker#DEF_VM_DESTRUCTION_DELAY}
* for details about the default behaviour.</p>
*
* <p>For details about Fault Injection, check the {@link org.cloudsimplus.faultinjection} package.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
* period of time to balance the load of arrived Cloudlets
* or even to enable fault tolerance.</p>
*
* <p>See the {@link DatacenterBroker#DEFAULT_VM_DESTRUCTION_DELAY}
* <p>See the {@link DatacenterBroker#DEF_VM_DESTRUCTION_DELAY}
* for details about the default behaviour.</p>
*
* <p>For details about Fault Injection, check the {@link org.cloudsimplus.faultinjection} package.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ private HostFaultInjectionExperiment(final long seed) {
this(0, null, seed);
}

HostFaultInjectionExperiment(int index, ExperimentRunner runner) {
HostFaultInjectionExperiment(final int index, final ExperimentRunner runner) {
this(index, runner, -1);
}

private HostFaultInjectionExperiment(int index, ExperimentRunner runner, long seed) {
private HostFaultInjectionExperiment(final int index, final ExperimentRunner runner, final long seed) {
super(index, runner, seed);
setNumBrokersToCreate(readContractList().size());
setAfterScenarioBuild(exp -> createFaultInjectionForHosts(getDatacenter0()));
Expand Down Expand Up @@ -197,7 +197,7 @@ private List<String> readContractList() {
* @return the selected {@link AwsEc2Template} which will allow the customer
* to run the maximum number of VMs
*/
private AwsEc2Template getSuitableAwsEc2InstanceTemplate(DatacenterBroker broker, List<AwsEc2Template> all) throws IOException {
private AwsEc2Template getSuitableAwsEc2InstanceTemplate(final DatacenterBroker broker, final List<AwsEc2Template> all) {
if(all.isEmpty()){
throw new RuntimeException("There aren't VM templates to create VMs for customer " + broker.getId());
}
Expand All @@ -208,7 +208,7 @@ private AwsEc2Template getSuitableAwsEc2InstanceTemplate(DatacenterBroker broker
return selected;
}

selected = getCheaperVmTemplate(broker, all);
selected = getCheapestVmTemplate(broker, all);

return selected;
}
Expand All @@ -220,7 +220,7 @@ private AwsEc2Template getSuitableAwsEc2InstanceTemplate(DatacenterBroker broker
* @return the most powerful VM according to customer contract or {@link AwsEc2Template#NULL}
* if a suitable template could not be found
*/
private AwsEc2Template getMostPowerfulVmTemplateForCustomerPrice(SlaContract contract, List<AwsEc2Template> all) {
private AwsEc2Template getMostPowerfulVmTemplateForCustomerPrice(final SlaContract contract, final List<AwsEc2Template> all) {
final Comparator<AwsEc2Template> comparator = Comparator.naturalOrder();
return all.stream()
.filter(t -> getActualPriceForAllVms(contract, t) <= contract.getMaxPrice())
Expand All @@ -230,17 +230,20 @@ private AwsEc2Template getMostPowerfulVmTemplateForCustomerPrice(SlaContract con

/**
* If a VM template matching the customer contract cannot be found,
* gets the cheaper VM from the entire list and
* gets the cheapest VM from the entire list and
* computes the new k-fault-tolerance level which is possible using such a VM.
* That is, computes the k number of VMs which can be created
* from that template, that will not exceed the total price the customer
* is willing to pay.
*
* At the end, updates the customer contract.
*
* @param broker the broker representing a customer to get the cheapest {@link AwsEc2Template}
* which maximizes the number of VMs for the customer's expected price
* @param all the list of all existing {@link AwsEc2Template}s
* @return the cheaper VM template
*/
private AwsEc2Template getCheaperVmTemplate(DatacenterBroker broker, List<AwsEc2Template> all) {
private AwsEc2Template getCheapestVmTemplate(final DatacenterBroker broker, final List<AwsEc2Template> all) {
final SlaContract contract = getContract(broker);
final AwsEc2Template instance =
all.stream()
Expand Down Expand Up @@ -273,12 +276,12 @@ private AwsEc2Template getCheaperVmTemplate(DatacenterBroker broker, List<AwsEc2
* @param instance the instance type to compute the k-fault-tolerance level
* @return the computed k-fault-tolerance level, where the minimum value for k will be 1
*/
private int getFaultToleranceLevelForTemplate(SlaContract contract, AwsEc2Template instance) {
private int getFaultToleranceLevelForTemplate(final SlaContract contract, final AwsEc2Template instance) {
final int faultToleranceLevel = (int)Math.floor(contract.getMaxPrice() / instance.getPricePerHour());
return Math.max(faultToleranceLevel, 1);
}

private SlaContract getContract(DatacenterBroker broker){
private SlaContract getContract(final DatacenterBroker broker){
return contractsMap.get(broker);
}

Expand All @@ -296,7 +299,7 @@ private List<AwsEc2Template> readAllAvailableAwsEc2Instances() throws IOExceptio
}

@Override
protected List<Vm> createVms(DatacenterBroker broker) {
protected List<Vm> createVms(final DatacenterBroker broker) {
numVms = getContract(broker).getMinFaultToleranceLevel();
final List<Vm> list = new ArrayList<>(numVms);
final int id = getVmList().size();
Expand All @@ -308,7 +311,7 @@ protected List<Vm> createVms(DatacenterBroker broker) {

}

public Vm createVm(DatacenterBroker broker, int id, AwsEc2Template template) {
public Vm createVm(final DatacenterBroker broker, final int id, final AwsEc2Template template) {
final Vm vm = new VmSimple(id, VM_MIPS, template.getCpus());
vm
.setRam(template.getMemoryInMB()).setBw(VM_BW).setSize(VM_SIZE)
Expand Down Expand Up @@ -389,7 +392,7 @@ public Host createHost() {
*
* @param datacenter
*/
private void createFaultInjectionForHosts(Datacenter datacenter) {
private void createFaultInjectionForHosts(final Datacenter datacenter) {
PoissonDistr poisson = new PoissonDistr(MEAN_FAILURE_NUMBER_PER_HOUR, getSeed());

faultInjection = new HostFaultInjection(datacenter, poisson);
Expand Down Expand Up @@ -445,7 +448,7 @@ private Vm cloneVm(final Vm vm) {
* @return the List of cloned Cloudlets.
* @see #createFaultInjectionForHosts(org.cloudbus.cloudsim.datacenters.Datacenter)
*/
private List<Cloudlet> cloneCloudlets(Vm sourceVm) {
private List<Cloudlet> cloneCloudlets(final Vm sourceVm) {
final List<Cloudlet> sourceVmCloudlets = sourceVm.getCloudletScheduler().getCloudletList();
final List<Cloudlet> clonedCloudlets = new ArrayList<>(sourceVmCloudlets.size());
for (Cloudlet cl : sourceVmCloudlets) {
Expand Down Expand Up @@ -480,7 +483,7 @@ private Cloudlet cloneCloudlet(final Cloudlet source, final long length) {

@Override
public void printResults() {
for (DatacenterBroker broker : getBrokerList()) {
for (final DatacenterBroker broker : getBrokerList()) {
new CloudletsTableBuilder(broker.getCloudletFinishedList()).build();
}
}
Expand Down Expand Up @@ -523,7 +526,7 @@ public double getPercentageOfAvailabilityMeetingSla() {
* @param broker
* @return minimum customer availability
*/
private double getCustomerMinAvailability(DatacenterBroker broker) {
private double getCustomerMinAvailability(final DatacenterBroker broker) {
return contractsMap.get(broker).getAvailabilityMetric().getMinDimension().getValue();

}
Expand All @@ -532,7 +535,7 @@ private double getCustomerMinAvailability(DatacenterBroker broker) {
* Calculates the total cost of all VMs a given broker executed,
* for the entire simulation time.
*/
public double getTotalCost(DatacenterBroker broker) {
public double getTotalCost(final DatacenterBroker broker) {
final SlaContract contract = getContract(broker);

final AwsEc2Template template = templatesMap.get(broker);
Expand All @@ -548,7 +551,7 @@ public double getTotalCost(DatacenterBroker broker) {
* @param template the template to compute the total price for that contract
* @return
*/
private double getActualPriceForAllVms(SlaContract contract, AwsEc2Template template) {
private double getActualPriceForAllVms(final SlaContract contract, final AwsEc2Template template) {
return template.getPricePerHour()*contract.getMinFaultToleranceLevel();
}

Expand All @@ -558,7 +561,7 @@ private double getActualPriceForAllVms(SlaContract contract, AwsEc2Template temp
* @param broker
* @return
*/
public double getCustomerActualPricePerHour(DatacenterBroker broker) {
public double getCustomerActualPricePerHour(final DatacenterBroker broker) {
return getTotalCost(broker)/getTotalExecutionTimeForVmsInHours(broker);
}

Expand All @@ -567,14 +570,14 @@ public double getCustomerActualPricePerHour(DatacenterBroker broker) {
* @param broker
* @return
*/
private double getTotalExecutionTimeForVmsInHours(DatacenterBroker broker) {
private double getTotalExecutionTimeForVmsInHours(final DatacenterBroker broker) {
return broker.getVmCreatedList().stream().mapToDouble(Vm::getTotalExecutionTime).sum()/3600.0;
}

/**
* Gets the price per hour for the AWS EC2 Template to be used for a given customer.
*/
public Double getTemplatesMap(DatacenterBroker broker) {
public Double getTemplatesMap(final DatacenterBroker broker) {
return templatesMap.get(broker).getPricePerHour();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public interface DatacenterBroker extends SimEntity {
DatacenterBroker NULL = new DatacenterBrokerNull();

/**
* A default delay value to indicate that <b>no</b> VM should be
* immediately destroyed after it becoming idle.
* A default delay value to indicate that <b>NO</b> VM should be
* immediately destroyed after becoming idle.
*
* <p>This is used as the default value returned by the {@link #getVmDestructionDelayFunction()}
* if a {@link Function} is not set.</p>
*
* @see #setVmDestructionDelayFunction(Function)
*/
double DEFAULT_VM_DESTRUCTION_DELAY = -1.0;
double DEF_VM_DESTRUCTION_DELAY = -1.0;

/**
* Specifies that an already submitted cloudlet, which is in the {@link #getCloudletWaitingList() waiting list},
Expand Down Expand Up @@ -346,7 +346,7 @@ public interface DatacenterBroker extends SimEntity {
* after the VM becomes idle, to destroy it.
*
* @return
* @see #DEFAULT_VM_DESTRUCTION_DELAY
* @see #DEF_VM_DESTRUCTION_DELAY
* @see Vm#getIdleInterval()
*/
Function<Vm, Double> getVmDestructionDelayFunction();
Expand All @@ -358,7 +358,7 @@ public interface DatacenterBroker extends SimEntity {
*
* @param function the {@link Function} to set (if null is given, it sets the default Function)
* @return
* @see #DEFAULT_VM_DESTRUCTION_DELAY
* @see #DEF_VM_DESTRUCTION_DELAY
* @see Vm#getIdleInterval()
*/
DatacenterBroker setVmDestructionDelayFunction(Function<Vm, Double> function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public abstract class DatacenterBrokerAbstract extends CloudSimEntity implements DatacenterBroker {

/**
* A default {@link Function} which always returns {@link #DEFAULT_VM_DESTRUCTION_DELAY} to indicate that any VM should not be
* A default {@link Function} which always returns {@link #DEF_VM_DESTRUCTION_DELAY} to indicate that any VM should not be
* immediately destroyed after it becomes idle.
* This way, using this Function the broker will destroy VMs only after:
* <ul>
Expand All @@ -45,7 +45,7 @@ public abstract class DatacenterBrokerAbstract extends CloudSimEntity implements
*
* @see #setVmDestructionDelayFunction(Function)
*/
private static final Function<Vm, Double> DEFAULT_VM_DESTRUCTION_DELAY_FUNCTION = vm -> DEFAULT_VM_DESTRUCTION_DELAY;
private static final Function<Vm, Double> DEF_VM_DESTRUCTION_DELAY_FUNCTION = vm -> DEF_VM_DESTRUCTION_DELAY;

/**
* A map of registered event listeners for the onVmsCreatedListeners event
Expand Down Expand Up @@ -189,7 +189,7 @@ public DatacenterBrokerAbstract(final CloudSim simulation, final String name) {

setDefaultPolicies();

vmDestructionDelayFunction = DEFAULT_VM_DESTRUCTION_DELAY_FUNCTION;
vmDestructionDelayFunction = DEF_VM_DESTRUCTION_DELAY_FUNCTION;
}

/**
Expand Down Expand Up @@ -760,7 +760,7 @@ private void requestVmDestructionAfterAllCloudletsFinished() {
/**
* Request an idle VM to be destroyed at the time defined by a delay {@link Function}.
* The request will be sent if the given delay function returns a value
* greater than {@link #DEFAULT_VM_DESTRUCTION_DELAY}.
* greater than {@link #DEF_VM_DESTRUCTION_DELAY}.
* Otherwise, it doesn't send the request, meaning the VM should not be destroyed according to a specific delay.
*
* @param vm the VM to destroy
Expand All @@ -770,7 +770,7 @@ private void requestIdleVmDestruction(final Vm vm) {
final double delay = vmDestructionDelayFunction.apply(vm);

boolean vmAlive = vmExecList.contains(vm);
if (vmAlive && ((delay > DEFAULT_VM_DESTRUCTION_DELAY && vm.isIdleEnough(delay)) || isFinished())) {
if (vmAlive && ((delay > DEF_VM_DESTRUCTION_DELAY && vm.isIdleEnough(delay)) || isFinished())) {
LOGGER.info("{}: {}: Requesting {} destruction.", getSimulation().clock(), getName(), vm);
sendNow(getDatacenter(vm), CloudSimTags.VM_DESTROY, vm);
vmExecList.remove(vm);
Expand All @@ -782,7 +782,7 @@ private void requestIdleVmDestruction(final Vm vm) {
return;
}

if (vmAlive && delay > DEFAULT_VM_DESTRUCTION_DELAY) {
if (vmAlive && delay > DEF_VM_DESTRUCTION_DELAY) {
send(this, getDelayToCheckVmIdleness(vm), CloudSimTags.VM_DESTROY, vm);
}

Expand Down Expand Up @@ -1121,7 +1121,7 @@ public Function<Vm, Double> getVmDestructionDelayFunction() {

@Override
public DatacenterBroker setVmDestructionDelayFunction(final Function<Vm, Double> function) {
this.vmDestructionDelayFunction = function == null ? DEFAULT_VM_DESTRUCTION_DELAY_FUNCTION : function;
this.vmDestructionDelayFunction = function == null ? DEF_VM_DESTRUCTION_DELAY_FUNCTION : function;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,11 @@ public Simulation getSimulation() {
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CloudletAbstract)) return false;
public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof CloudletAbstract)) return false;

final CloudletAbstract that = (CloudletAbstract) o;
final CloudletAbstract that = (CloudletAbstract) other;

if (id != that.id) return false;
return broker.equals(that.broker);
Expand All @@ -847,5 +847,4 @@ public int hashCode() {
result = 31 * result + broker.hashCode();
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class CloudInformationService extends CloudSimEntity {
* Instantiates a new CloudInformationService object.
*
* @param simulation The CloudSim instance that represents the simulation the Entity is related to
* @pre name != null
*/
CloudInformationService(CloudSim simulation) {
super(simulation);
Expand Down

0 comments on commit 4f19587

Please sign in to comment.