Commit b2023e0d authored by Nikolay's avatar Nikolay

Started put hardcoded constants in a dedicated Const class.

parent 0222c63c
......@@ -74,7 +74,7 @@ public class CloudletSchedulerDynamicWorkload extends CloudletSchedulerTimeShare
for (ResCloudlet rcl : getCloudletExecList()) {
rcl.updateCloudletFinishedSoFar((long) (timeSpan
* getTotalCurrentAllocatedMipsForCloudlet(rcl, getPreviousTime()) * 1000000));
* getTotalCurrentAllocatedMipsForCloudlet(rcl, getPreviousTime()) * Consts.MILLION));
if (rcl.getRemainingCloudletLength() == 0) { // finished: remove from the list
cloudletsToFinish.add(rcl);
......
......@@ -89,7 +89,7 @@ public class CloudletSchedulerSpaceShared extends CloudletScheduler {
// each machine in the exec list has the same amount of cpu
for (ResCloudlet rcl : getCloudletExecList()) {
rcl.updateCloudletFinishedSoFar((long) (capacity * timeSpam * rcl.getNumberOfPes() * 1000000));
rcl.updateCloudletFinishedSoFar((long) (capacity * timeSpam * rcl.getNumberOfPes() * Consts.MILLION));
}
// no more cloudlets in this scheduler
......
......@@ -65,7 +65,7 @@ public class CloudletSchedulerTimeShared extends CloudletScheduler {
double timeSpam = currentTime - getPreviousTime();
for (ResCloudlet rcl : getCloudletExecList()) {
rcl.updateCloudletFinishedSoFar((long) (getCapacity(mipsShare) * timeSpam * rcl.getNumberOfPes() * 1000000));
rcl.updateCloudletFinishedSoFar((long) (getCapacity(mipsShare) * timeSpam * rcl.getNumberOfPes() * Consts.MILLION));
}
if (getCloudletExecList().size() == 0) {
......
......@@ -237,7 +237,7 @@ public class FileAttribute {
* @return the file size (in bytes)
*/
public int getFileSizeInByte() {
return size * 1000000; // 1e6
return size * Consts.MILLION; // 1e6
// return size * 1048576; // 1e6 - more accurate
}
......
......@@ -216,7 +216,7 @@ public class ResCloudlet {
// In case a Cloudlet has been executed partially by some other grid
// hostList.
cloudletFinishedSoFar = cloudlet.getCloudletFinishedSoFar() * 1000000;
cloudletFinishedSoFar = cloudlet.getCloudletFinishedSoFar() * Consts.MILLION;
}
/**
......@@ -430,14 +430,14 @@ public class ResCloudlet {
* @post $result >= 0
*/
public long getRemainingCloudletLength() {
long length = cloudlet.getCloudletTotalLength() * 1000000 - cloudletFinishedSoFar;
long length = cloudlet.getCloudletTotalLength() * Consts.MILLION - cloudletFinishedSoFar;
// Remaining Cloudlet length can't be negative number.
if (length < 0) {
return 0;
}
return (long) Math.floor(length / 1000000);
return (long) Math.floor(length / Consts.MILLION);
}
/**
......@@ -459,11 +459,11 @@ public class ResCloudlet {
cloudlet.setExecParam(wallClockTime, totalCompletionTime);
long finished = 0;
//if (cloudlet.getCloudletTotalLength() * 1000000 < cloudletFinishedSoFar) {
//if (cloudlet.getCloudletTotalLength() * Consts.MILLION < cloudletFinishedSoFar) {
if (cloudlet.getCloudletStatus()==Cloudlet.SUCCESS) {
finished = cloudlet.getCloudletLength();
} else {
finished = cloudletFinishedSoFar / 1000000;
finished = cloudletFinishedSoFar / Consts.MILLION;
}
cloudlet.setCloudletFinishedSoFar(finished);
......
......@@ -38,6 +38,23 @@ public class CloudletList {
return null;
}
/**
* Returns the position of the cloudlet with that id, if it exists. Otherwise -1.
* @param cloudletList - the list of cloudlets.
* @param id - the id we search for.
* @return - the position of the cloudlet with that id, or -1 otherwise.
*/
public static <T extends Cloudlet> int getPositionById(List<T> cloudletList, int id) {
int i = 0 ;
for (T cloudlet : cloudletList) {
if (cloudlet.getCloudletId() == id) {
return i;
}
i++;
}
return -1;
}
/**
* Sorts the Cloudlets in a list based on their lengths.
*
......
......@@ -89,4 +89,20 @@ public class ResCloudletList {
return false;
}
/**
* Returns the position of the cloudlet with that id, if it exists. Otherwise -1.
* @param cloudletList - the list of cloudlets.
* @param id - the id we search for.
* @return - the position of the cloudlet with that id, or -1 otherwise.
*/
public static <T extends ResCloudlet> int getPositionById(List<T> cloudletList, int id) {
int i = 0 ;
for (T cloudlet : cloudletList) {
if (cloudlet.getCloudletId() == id) {
return i;
}
i++;
}
return -1;
}
}
......@@ -27,7 +27,7 @@ import org.junit.Test;
public class HostDynamicWorkloadTest {
private static final int ID = 0;
private static final long STORAGE = 1000000;
private static final long STORAGE = Consts.MILLION;
private static final int RAM = 1024;
private static final int BW = 10000;
private static final double MIPS = 1000;
......
......@@ -31,7 +31,7 @@ import org.junit.Test;
public class HostTest {
private static final int ID = 0;
private static final long STORAGE = 1000000;
private static final long STORAGE = Consts.MILLION;
private static final int RAM = 1024;
private static final int BW = 10000;
private static final double MIPS = 1000;
......
......@@ -172,7 +172,7 @@ public class TimeSharedProblemDetector {
// of machines
int hostId = 0;
int ram = 2048; // host memory (MB)
long storage = 1000000; // host storage
long storage = Consts.MILLION; // host storage
int bw = 10000;
hostList.add(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment