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 20, 2018
1 parent 975e565 commit dd7de81
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
*/
package org.cloudsimplus.examples.listeners;

/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/

import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
*/
package org.cloudsimplus.examples.listeners;

/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/

import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
*/
package org.cloudsimplus.examples.listeners;

/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/

import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
*/
package org.cloudsimplus.examples.listeners;

/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/

import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
*/
package org.cloudsimplus.examples.listeners;

/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/

import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public HostsCpuUsageExample(){
}

private Cloudlet createCloudlet(final int pesNumber) {
long length = 10000;
long fileSize = 300;
long outputSize = 300;
final long length = 10000;
final long fileSize = 300;
final long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();

return new CloudletSimple(length, pesNumber)
Expand All @@ -147,9 +147,9 @@ private Cloudlet createCloudlet(final int pesNumber) {
* @return
*/
private Vm createVm(final int pesNumber, final long mips) {
long size = 10000; //image size (Megabyte)
int ram = 2048; //vm memory (Megabyte)
long bw = 1000;
final long size = 10000; //image size (Megabyte)
final int ram = 2048; //vm memory (Megabyte)
final long bw = 1000;
Vm vm = new VmSimple(mips, pesNumber)
.setRam(ram).setBw(bw).setSize(size)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
Expand Down Expand Up @@ -201,15 +201,15 @@ private Datacenter createDatacenter() {
return dc;
}

private Host createHost(int pesNumber, long mips) {
private Host createHost(final int pesNumber, final long mips) {
List<Pe> peList = new ArrayList<>();
for (int i = 0; i < pesNumber; i++) {
peList.add(new PeSimple(mips, new PeProvisionerSimple()));
}

long ram = 2048; //host memory (Megabyte)
long storage = 1000000; //host storage (Megabyte)
long bw = 10000; //Megabits/s
final long ram = 2048; //host memory (Megabyte)
final long storage = 1000000; //host storage (Megabyte)
final long bw = 10000; //Megabits/s

Host host = new HostSimple(ram, bw, storage, peList);
host
Expand All @@ -218,5 +218,4 @@ private Host createHost(int pesNumber, long mips) {
.setVmScheduler(new VmSchedulerTimeShared());
return host;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public VmsCpuUsageExample() {
}

private Cloudlet createCloudlet(final int pesNumber) {
long length = 10000;
long fileSize = 300;
long outputSize = 300;
final long length = 10000;
final long fileSize = 300;
final long outputSize = 300;
UtilizationModel utilizationModelDynamic = new UtilizationModelDynamic(0.25);
UtilizationModel utilizationModelCpu = new UtilizationModelDynamic(0.5);

Expand All @@ -144,9 +144,9 @@ private Cloudlet createCloudlet(final int pesNumber) {
* @return
*/
private Vm createVm(final int pesNumber, final int mips, final int id) {
long size = 10000; //image size (Megabyte)
int ram = 2048; //vm memory (Megabyte)
long bw = 1000;
final long size = 10000; //image size (Megabyte)
final int ram = 2048; //vm memory (Megabyte)
final long bw = 1000;

//create two VMs
Vm vm = new VmSimple(id, mips, pesNumber);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cloudbus.cloudsim.provisioners;

import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.ResourceManageable;
import org.cloudbus.cloudsim.vms.Vm;

/**
Expand All @@ -11,35 +10,12 @@
* @author Manoel Campos da Silva Filho
* @see PeProvisioner#NULL
*/
final class PeProvisionerNull implements PeProvisioner {
final class PeProvisionerNull extends ResourceProvisionerNull implements PeProvisioner {
@Override public void setPe(Pe pe) {/**/}
@Override public boolean allocateResourceForVm(Vm vm, long newTotalVmResourceCapacity) {
return false;
}
@Override public boolean allocateResourceForVm(Vm vm, double newTotalVmResource) {
return false;
}
@Override public long getAllocatedResourceForVm(Vm vm) {
return 0;
}
@Override public long getTotalAllocatedResource() {
return 0;
}
@Override public double getUtilization() {
return 0;
}
@Override public boolean deallocateResourceForVm(Vm vm) {
return false;
}
@Override public void deallocateResourceForAllVms() {/**/}
@Override public boolean isSuitableForVm(Vm vm, long newVmTotalAllocatedResource) {
@Override public boolean allocateResourceForVm(Vm vm, double newTotalVmResource) {
return false;
}
@Override public ResourceManageable getResource() {
return ResourceManageable.NULL;
}
@Override public void setResource(ResourceManageable resource) {/**/}
@Override public long getCapacity() { return 0; }
@Override public long getAvailableResource() { return 0; }
@Override public boolean isResourceAllocatedToVm(Vm vm) { return false; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Manoel Campos da Silva Filho
* @see ResourceProvisioner#NULL
*/
final class ResourceProvisionerNull implements ResourceProvisioner {
class ResourceProvisionerNull implements ResourceProvisioner {
@Override public boolean allocateResourceForVm(Vm vm, long newTotalVmResourceCapacity) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ public abstract class PowerVmSelectionPolicy {
* @param host the host to get a Vm to migrate from
* @return the vm to migrate or {@link Vm#NULL} if there is not Vm to migrate
*/
public abstract Vm getVmToMigrate(final Host host);
public abstract Vm getVmToMigrate(Host host);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public class BrokerBuilder extends Builder implements BrokerBuilderInterface {
public class BrokerBuilder implements BrokerBuilderInterface {
private final List<DatacenterBroker> brokers;
private final SimulationScenarioBuilder scenario;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
*/
package org.cloudsimplus.builders;

import java.util.List;

import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;

import java.util.List;

/**
* An interface to classes that build {@link DatacenterBrokerSimple} objects.
*
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public interface BrokerBuilderInterface {
public interface BrokerBuilderInterface extends Builder{
BrokerBuilderDecorator createBroker();
DatacenterBroker findBroker(int id);
List<DatacenterBroker> getBrokers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.cloudbus.cloudsim.vms.Vm;

/**
* An abstract Builder for creation of CloudSim objects,
* A Builder interface for creation of simulation objects,
* such as {@link Datacenter},
* {@link Host},
* {@link Vm}
Expand All @@ -44,8 +44,8 @@
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public abstract class Builder {
public void validateAmount(final double amount){
public interface Builder {
default void validateAmount(final double amount){
if(amount <= 0)
throw new IllegalArgumentException("The amount has to be greater than 0.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public class CloudletBuilder extends Builder {
public class CloudletBuilder implements Builder {
private long length = 10000;
private long outputSize = 300;
private long fileSize = 300;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public class DatacenterBuilder extends Builder {
public class DatacenterBuilder implements Builder {
private static final String DC_NAME_FORMAT = "Datacenter%d";
private final SimulationScenarioBuilder scenario;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public class HostBuilder extends Builder {
public class HostBuilder implements Builder {
private double mips = 2000;
private int pes = 1;
private long bandwidth = 10000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
*/
package org.cloudsimplus.builders;

import org.cloudbus.cloudsim.provisioners.PeProvisioner;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.PeSimple;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.cloudbus.cloudsim.provisioners.PeProvisioner;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.PeSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;

/**
* A Builder class to create {@link PeSimple} objects.
*
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public class PeBuilder extends Builder {
public class PeBuilder implements Builder {
private Class<? extends PeProvisioner> provisionerClass = PeProvisionerSimple.class;

public List<Pe> create(final double amount, final double mipsOfEachPe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public class VmBuilder {
public class VmBuilder implements Builder {
private Supplier<CloudletScheduler> cloudletSchedulerSupplier;
private long size = 10000;
private long ram = 512;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Before;
import org.junit.Test;

import static org.cloudbus.cloudsim.power.models.PowerModelTest.assignHostForPowerModel;
import static org.junit.Assert.assertEquals;

/**
Expand All @@ -25,8 +26,7 @@ public class PowerModelCubicTest {

@Before
public void setUp() {
powerModel = new PowerModelCubic(MAX_POWER, STATIC_POWER_PERCENT);
powerModel.setHost(PowerModelTest.createHostWithOneVm());
powerModel = assignHostForPowerModel(new PowerModelCubic(MAX_POWER, STATIC_POWER_PERCENT));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Before;
import org.junit.Test;

import static org.cloudbus.cloudsim.power.models.PowerModelTest.assignHostForPowerModel;
import static org.junit.Assert.assertEquals;

/**
Expand All @@ -25,8 +26,7 @@ public class PowerModelSqrtTest {

@Before
public void setUp() {
powerModel = new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT);
powerModel.setHost(PowerModelTest.createHostWithOneVm());
powerModel = assignHostForPowerModel(new PowerModelSqrt(MAX_POWER, STATIC_POWER_PERCENT));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Before;
import org.junit.Test;

import static org.cloudbus.cloudsim.power.models.PowerModelTest.assignHostForPowerModel;
import static org.junit.Assert.assertEquals;

/**
Expand All @@ -24,9 +25,8 @@ public class PowerModelSquareTest {
private PowerModelSquare powerModel;

@Before
public void setUp() throws Exception {
powerModel = new PowerModelSquare(MAX_POWER, STATIC_POWER_PERCENT);
powerModel.setHost(PowerModelTest.createHostWithOneVm());
public void setUp() {
powerModel = assignHostForPowerModel(new PowerModelSquare(MAX_POWER, STATIC_POWER_PERCENT));
}

@Test
Expand Down

0 comments on commit dd7de81

Please sign in to comment.