-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cloudlet.java
1502 lines (1318 loc) · 38.9 KB
/
Cloudlet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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-2012, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* Cloudlet is an extension to the cloudlet. It stores, despite all the information encapsulated in
* the Cloudlet, the ID of the VM running it.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public class Cloudlet {
/**
* The User or Broker ID. It is advisable that broker set this ID with its own ID, so that
* CloudResource returns to it after the execution.
**/
private int userId;
/**
* The size of this Cloudlet to be executed in a CloudResource (unit: in MI).
*/
private long cloudletLength;
/**
* The input file size of this Cloudlet before execution (unit: in byte). in byte = program +
* input data size
*/
private final long cloudletFileSize;
/** The output file size of this Cloudlet after execution (unit: in byte). */
private final long cloudletOutputSize;
/** The num of Pe required to execute this job. */
private int numberOfPes;
/** The cloudlet ID. */
private final int cloudletId;
/** The status of this Cloudlet. */
private int status;
/** The format of decimal numbers. */
private DecimalFormat num;
/** The time where this Cloudlet completes. */
private double finishTime;
/**
* Start time of executing this Cloudlet. With new functionalities, such as CANCEL, PAUSED and
* RESUMED, this attribute only stores the latest execution time. Previous execution time are
* ignored.
*/
private double execStartTime;
/** The ID of a reservation made for this cloudlet. */
private int reservationId = -1;
/** The records the transaction history for this Cloudlet. */
private final boolean record;
/** The newline. */
private String newline;
/** The history. */
private StringBuffer history;
/** The res list. */
private final List<Resource> resList;
/** The index. */
private int index;
/** The class type of Cloudlet for resource scheduling. */
private int classType;
/** The ToS for sending Cloudlet over the network. */
private int netToS;
// //////////////////////////////////////////
// Below are CONSTANTS attributes
/** The Cloudlet has been created and added to the CloudletList object. */
public static final int CREATED = 0;
/** The Cloudlet has been assigned to a CloudResource object as planned. */
public static final int READY = 1;
/** The Cloudlet has moved to a Cloud node. */
public static final int QUEUED = 2;
/** The Cloudlet is in execution in a Cloud node. */
public static final int INEXEC = 3;
/** The Cloudlet has been executed successfully. */
public static final int SUCCESS = 4;
/** The Cloudlet is failed. */
public static final int FAILED = 5;
/** The Cloudlet has been canceled. */
public static final int CANCELED = 6;
/**
* The Cloudlet has been paused. It can be resumed by changing the status into <tt>RESUMED</tt>.
*/
public static final int PAUSED = 7;
/** The Cloudlet has been resumed from <tt>PAUSED</tt> state. */
public static final int RESUMED = 8;
/** The cloudlet has failed due to a resource failure. */
public static final int FAILED_RESOURCE_UNAVAILABLE = 9;
/** The vm id. */
protected int vmId;
/** The cost per bw. */
protected double costPerBw;
/** The accumulated bw cost. */
protected double accumulatedBwCost;
// Utilization
/** The utilization of cpu model. */
private UtilizationModel utilizationModelCpu;
/** The utilization of memory model. */
private UtilizationModel utilizationModelRam;
/** The utilization of bw model. */
private UtilizationModel utilizationModelBw;
// Data cloudlet
/** The required files. */
private List<String> requiredFiles = null; // list of required filenames
private int delayCloudletAt;
public int getCloudletDelay() {
return delayCloudletAt;
}
public Cloudlet(
final int cloudletId,
final long cloudletLength,
final int pesNumber,
final long cloudletFileSize,
final long cloudletOutputSize,
final UtilizationModel utilizationModelCpu,
final UtilizationModel utilizationModelRam,
final UtilizationModel utilizationModelBw,
final int delayCloudletAt
) {
this(
cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw,
false);
vmId = -1;
accumulatedBwCost = 0.0;
costPerBw = 0.0;
delayCloudletAt = delayCloudlet;
requiredFiles = new LinkedList<String>();
}
/**
* Allocates a new Cloudlet object. The Cloudlet length, input and output file sizes should be
* greater than or equal to 1. By default this constructor sets the history of this object.
*
* @param cloudletId the unique ID of this Cloudlet
* @param cloudletLength the length or size (in MI) of this cloudlet to be executed in a
* PowerDatacenter
* @param cloudletFileSize the file size (in byte) of this cloudlet <tt>BEFORE</tt> submitting
* to a PowerDatacenter
* @param cloudletOutputSize the file size (in byte) of this cloudlet <tt>AFTER</tt> finish
* executing by a PowerDatacenter
* @param pesNumber the pes number
* @param utilizationModelCpu the utilization model cpu
* @param utilizationModelRam the utilization model ram
* @param utilizationModelBw the utilization model bw
* @pre cloudletID >= 0
* @pre cloudletLength >= 0.0
* @pre cloudletFileSize >= 1
* @pre cloudletOutputSize >= 1
* @post $none
*/
public Cloudlet(
final int cloudletId,
final long cloudletLength,
final int pesNumber,
final long cloudletFileSize,
final long cloudletOutputSize,
final UtilizationModel utilizationModelCpu,
final UtilizationModel utilizationModelRam,
final UtilizationModel utilizationModelBw) {
this(
cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw,
false);
vmId = -1;
accumulatedBwCost = 0.0;
costPerBw = 0.0;
requiredFiles = new LinkedList<String>();
}
/**
* Allocates a new Cloudlet object. The Cloudlet length, input and output file sizes should be
* greater than or equal to 1.
*
* @param cloudletId the unique ID of this cloudlet
* @param cloudletLength the length or size (in MI) of this cloudlet to be executed in a
* PowerDatacenter
* @param cloudletFileSize the file size (in byte) of this cloudlet <tt>BEFORE</tt> submitting
* to a PowerDatacenter
* @param cloudletOutputSize the file size (in byte) of this cloudlet <tt>AFTER</tt> finish
* executing by a PowerDatacenter
* @param record record the history of this object or not
* @param fileList list of files required by this cloudlet
* @param pesNumber the pes number
* @param utilizationModelCpu the utilization model cpu
* @param utilizationModelRam the utilization model ram
* @param utilizationModelBw the utilization model bw
* @pre cloudletID >= 0
* @pre cloudletLength >= 0.0
* @pre cloudletFileSize >= 1
* @pre cloudletOutputSize >= 1
* @post $none
*/
public Cloudlet(
final int cloudletId,
final long cloudletLength,
final int pesNumber,
final long cloudletFileSize,
final long cloudletOutputSize,
final UtilizationModel utilizationModelCpu,
final UtilizationModel utilizationModelRam,
final UtilizationModel utilizationModelBw,
final boolean record,
final List<String> fileList) {
this(
cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw,
record);
vmId = -1;
accumulatedBwCost = 0.0;
costPerBw = 0.0;
requiredFiles = fileList;
}
/**
* Allocates a new Cloudlet object. The Cloudlet length, input and output file sizes should be
* greater than or equal to 1. By default this constructor sets the history of this object.
*
* @param cloudletId the unique ID of this Cloudlet
* @param cloudletLength the length or size (in MI) of this cloudlet to be executed in a
* PowerDatacenter
* @param cloudletFileSize the file size (in byte) of this cloudlet <tt>BEFORE</tt> submitting
* to a PowerDatacenter
* @param cloudletOutputSize the file size (in byte) of this cloudlet <tt>AFTER</tt> finish
* executing by a PowerDatacenter
* @param fileList list of files required by this cloudlet
* @param pesNumber the pes number
* @param utilizationModelCpu the utilization model cpu
* @param utilizationModelRam the utilization model ram
* @param utilizationModelBw the utilization model bw
* @pre cloudletID >= 0
* @pre cloudletLength >= 0.0
* @pre cloudletFileSize >= 1
* @pre cloudletOutputSize >= 1
* @post $none
*/
public Cloudlet(
final int cloudletId,
final long cloudletLength,
final int pesNumber,
final long cloudletFileSize,
final long cloudletOutputSize,
final UtilizationModel utilizationModelCpu,
final UtilizationModel utilizationModelRam,
final UtilizationModel utilizationModelBw,
final List<String> fileList) {
this(
cloudletId,
cloudletLength,
pesNumber,
cloudletFileSize,
cloudletOutputSize,
utilizationModelCpu,
utilizationModelRam,
utilizationModelBw,
false);
vmId = -1;
accumulatedBwCost = 0.0;
costPerBw = 0.0;
requiredFiles = fileList;
}
/**
* Allocates a new Cloudlet object. The Cloudlet length, input and output file sizes should be
* greater than or equal to 1.
*
* @param cloudletId the unique ID of this cloudlet
* @param cloudletLength the length or size (in MI) of this cloudlet to be executed in a
* PowerDatacenter
* @param cloudletFileSize the file size (in byte) of this cloudlet <tt>BEFORE</tt> submitting
* to a PowerDatacenter
* @param cloudletOutputSize the file size (in byte) of this cloudlet <tt>AFTER</tt> finish
* executing by a PowerDatacenter
* @param record record the history of this object or not
* @param pesNumber the pes number
* @param utilizationModelCpu the utilization model cpu
* @param utilizationModelRam the utilization model ram
* @param utilizationModelBw the utilization model bw
* @pre cloudletID >= 0
* @pre cloudletLength >= 0.0
* @pre cloudletFileSize >= 1
* @pre cloudletOutputSize >= 1
* @post $none
*/
public Cloudlet(
final int cloudletId,
final long cloudletLength,
final int pesNumber,
final long cloudletFileSize,
final long cloudletOutputSize,
final UtilizationModel utilizationModelCpu,
final UtilizationModel utilizationModelRam,
final UtilizationModel utilizationModelBw,
final boolean record) {
userId = -1; // to be set by a Broker or user
status = CREATED;
this.cloudletId = cloudletId;
numberOfPes = pesNumber;
execStartTime = 0.0;
finishTime = -1.0; // meaning this Cloudlet hasn't finished yet
classType = 0;
netToS = 0;
delayCloudletAt=0;
// Cloudlet length, Input and Output size should be at least 1 byte.
this.cloudletLength = Math.max(1, cloudletLength);
this.cloudletFileSize = Math.max(1, cloudletFileSize);
this.cloudletOutputSize = Math.max(1, cloudletOutputSize);
// Normally, a Cloudlet is only executed on a resource without being
// migrated to others. Hence, to reduce memory consumption, set the
// size of this ArrayList to be less than the default one.
resList = new ArrayList<Resource>(2);
index = -1;
this.record = record;
vmId = -1;
accumulatedBwCost = 0.0;
costPerBw = 0.0;
requiredFiles = new LinkedList<String>();
setUtilizationModelCpu(utilizationModelCpu);
setUtilizationModelRam(utilizationModelRam);
setUtilizationModelBw(utilizationModelBw);
}
// ////////////////////// INTERNAL CLASS ///////////////////////////////////
/**
* Internal class that keeps track Cloudlet's movement in different CloudResources.
*/
private static class Resource {
/** Cloudlet's submission time to a CloudResource. */
public double submissionTime = 0.0;
/**
* The time of this Cloudlet resides in a CloudResource (from arrival time until departure
* time).
*/
public double wallClockTime = 0.0;
/** The total execution time of this Cloudlet in a CloudResource. */
public double actualCPUTime = 0.0;
/** Cost per second a CloudResource charge to execute this Cloudlet. */
public double costPerSec = 0.0;
/** Cloudlet's length finished so far. */
public long finishedSoFar = 0;
/** a CloudResource id. */
public int resourceId = -1;
/** a CloudResource name. */
public String resourceName = null;
} // end of internal class
// ////////////////////// End of Internal Class //////////////////////////
/**
* Sets the id of the reservation made for this cloudlet.
*
* @param resId the reservation ID
* @return <tt>true</tt> if the ID has successfully been set or <tt>false</tt> otherwise.
*/
public boolean setReservationId(final int resId) {
if (resId <= 0) {
return false;
}
reservationId = resId;
return true;
}
/**
* Gets the reservation ID that owns this Cloudlet.
*
* @return a reservation ID
* @pre $none
* @post $none
*/
public int getReservationId() {
return reservationId;
}
/**
* Checks whether this Cloudlet is submitted by reserving or not.
*
* @return <tt>true</tt> if this Cloudlet has reserved before, <tt>false</tt> otherwise
*/
public boolean hasReserved() {
if (reservationId == -1) {
return false;
}
return true;
}
/**
* Sets the length or size (in MI) of this Cloudlet to be executed in a CloudResource. This
* Cloudlet length is calculated for 1 Pe only <tt>not</tt> the total length.
*
* @param cloudletLength the length or size (in MI) of this Cloudlet to be executed in a
* CloudResource
* @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
* @pre cloudletLength > 0
* @post $none
*/
public boolean setCloudletLength(final long cloudletLength) {
if (cloudletLength <= 0) {
return false;
}
this.cloudletLength = cloudletLength;
return true;
}
/**
* Sets the network service level for sending this cloudlet over a network.
*
* @param netServiceLevel determines the kind of service this cloudlet receives in the network
* (applicable to selected PacketScheduler class only)
* @return <code>true</code> if successful.
* @pre netServiceLevel >= 0
* @post $none
*/
public boolean setNetServiceLevel(final int netServiceLevel) {
boolean success = false;
if (netServiceLevel > 0) {
netToS = netServiceLevel;
success = true;
}
return success;
}
/**
* Gets the network service level for sending this cloudlet over a network.
*
* @return the network service level
* @pre $none
* @post $none
*/
public int getNetServiceLevel() {
return netToS;
}
/**
* Gets the waiting time of this cloudlet executed on a resource.
*
* @return the waiting time
* @pre $none
* @post $none
*/
public double getWaitingTime() {
if (index == -1) {
return 0;
}
// use the latest resource submission time
final double subTime = resList.get(index).submissionTime;
return execStartTime - subTime;
}
/**
* Sets the classType or priority of this Cloudlet for scheduling on a resource.
*
* @param classType classType of this Cloudlet
* @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
* @pre classType > 0
* @post $none
*/
public boolean setClassType(final int classType) {
boolean success = false;
if (classType > 0) {
this.classType = classType;
success = true;
}
return success;
}
/**
* Gets the classtype or priority of this Cloudlet for scheduling on a resource.
*
* @return classtype of this cloudlet
* @pre $none
* @post $none
*/
public int getClassType() {
return classType;
}
/**
* Sets the number of PEs required to run this Cloudlet. <br>
* NOTE: The Cloudlet length is computed only for 1 Pe for simplicity. <br>
* For example, this Cloudlet has a length of 500 MI and requires 2 PEs. This means each Pe will
* execute 500 MI of this Cloudlet.
*
* @param numberOfPes number of Pe
* @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
* @pre numPE > 0
* @post $none
*/
public boolean setNumberOfPes(final int numberOfPes) {
if (numberOfPes > 0) {
this.numberOfPes = numberOfPes;
return true;
}
return false;
}
/**
* Gets the number of PEs required to run this Cloudlet.
*
* @return number of PEs
* @pre $none
* @post $none
*/
public int getNumberOfPes() {
return numberOfPes;
}
/**
* Gets the history of this Cloudlet. The layout of this history is in a readable table column
* with <tt>time</tt> and <tt>description</tt> as headers.
*
* @return a String containing the history of this Cloudlet object.
* @pre $none
* @post $result != null
*/
public String getCloudletHistory() {
String msg = null;
if (history == null) {
msg = "No history is recorded for Cloudlet #" + cloudletId;
} else {
msg = history.toString();
}
return msg;
}
/**
* Gets the length of this Cloudlet that has been executed so far from the latest CloudResource.
* This method is useful when trying to move this Cloudlet into different CloudResources or to
* cancel it.
*
* @return the length of a partially executed Cloudlet or the full Cloudlet length if it is
* completed
* @pre $none
* @post $result >= 0.0
*/
public long getCloudletFinishedSoFar() {
if (index == -1) {
return cloudletLength;
}
final long finish = resList.get(index).finishedSoFar;
if (finish > cloudletLength) {
return cloudletLength;
}
return finish;
}
/**
* Checks whether this Cloudlet has finished execution or not.
*
* @return <tt>true</tt> if this Cloudlet has finished execution, <tt>false</tt> otherwise
* @pre $none
* @post $none
*/
public boolean isFinished() {
if (index == -1) {
return false;
}
boolean completed = false;
// if result is 0 or -ve then this Cloudlet has finished
final long finish = resList.get(index).finishedSoFar;
final long result = cloudletLength - finish;
if (result <= 0.0) {
completed = true;
}
return completed;
}
/**
* Sets the length of this Cloudlet that has been executed so far. This method is used by
* ResCloudlet class when an application is decided to cancel or to move this Cloudlet into
* different CloudResources.
*
* @param length length of this Cloudlet
* @see gridsim.AllocPolicy
* @see gridsim.ResCloudlet
* @pre length >= 0.0
* @post $none
*/
public void setCloudletFinishedSoFar(final long length) {
// if length is -ve then ignore
if (length < 0.0 || index < 0) {
return;
}
final Resource res = resList.get(index);
res.finishedSoFar = length;
if (record) {
write("Sets the length's finished so far to " + length);
}
}
/**
* Sets the user or owner ID of this Cloudlet. It is <tt>VERY</tt> important to set the user ID,
* otherwise this Cloudlet will not be executed in a CloudResource.
*
* @param id the user ID
* @pre id >= 0
* @post $none
*/
public void setUserId(final int id) {
userId = id;
if (record) {
write("Assigns the Cloudlet to " + CloudSim.getEntityName(id) + " (ID #" + id + ")");
}
}
/**
* Gets the user or owner ID of this Cloudlet.
*
* @return the user ID or <tt>-1</tt> if the user ID has not been set before
* @pre $none
* @post $result >= -1
*/
public int getUserId() {
return userId;
}
/**
* Gets the latest resource ID that processes this Cloudlet.
*
* @return the resource ID or <tt>-1</tt> if none
* @pre $none
* @post $result >= -1
*/
public int getResourceId() {
if (index == -1) {
return -1;
}
return resList.get(index).resourceId;
}
/**
* Gets the input file size of this Cloudlet <tt>BEFORE</tt> submitting to a CloudResource.
*
* @return the input file size of this Cloudlet
* @pre $none
* @post $result >= 1
*/
public long getCloudletFileSize() {
return cloudletFileSize;
}
/**
* Gets the output size of this Cloudlet <tt>AFTER</tt> submitting and executing to a
* CloudResource.
*
* @return the Cloudlet output file size
* @pre $none
* @post $result >= 1
*/
public long getCloudletOutputSize() {
return cloudletOutputSize;
}
/**
* Sets the resource parameters for which this Cloudlet is going to be executed. <br>
* NOTE: This method <tt>should</tt> be called only by a resource entity, not the user or owner
* of this Cloudlet.
*
* @param resourceID the CloudResource ID
* @param cost the cost running this CloudResource per second
* @pre resourceID >= 0
* @pre cost > 0.0
* @post $none
*/
public void setResourceParameter(final int resourceID, final double cost) {
final Resource res = new Resource();
res.resourceId = resourceID;
res.costPerSec = cost;
res.resourceName = CloudSim.getEntityName(resourceID);
// add into a list if moving to a new grid resource
resList.add(res);
if (index == -1 && record) {
write("Allocates this Cloudlet to " + res.resourceName + " (ID #" + resourceID
+ ") with cost = $" + cost + "/sec");
} else if (record) {
final int id = resList.get(index).resourceId;
final String name = resList.get(index).resourceName;
write("Moves Cloudlet from " + name + " (ID #" + id + ") to " + res.resourceName + " (ID #"
+ resourceID + ") with cost = $" + cost + "/sec");
}
index++; // initially, index = -1
}
/**
* Sets the submission or arrival time of this Cloudlet into a CloudResource.
*
* @param clockTime the submission time
* @pre clockTime >= 0.0
* @post $none
*/
public void setSubmissionTime(final double clockTime) {
if (clockTime < 0.0 || index < 0) {
return;
}
final Resource res = resList.get(index);
res.submissionTime = clockTime;
if (record) {
write("Sets the submission time to " + num.format(clockTime));
}
}
/**
* Gets the submission or arrival time of this Cloudlet from the latest CloudResource.
*
* @return the submission time or <tt>0.0</tt> if none
* @pre $none
* @post $result >= 0.0
*/
public double getSubmissionTime() {
if (index == -1) {
return 0.0;
}
return resList.get(index).submissionTime;
}
/**
* Sets the execution start time of this Cloudlet inside a CloudResource. <b>NOTE:</b> With new
* functionalities, such as being able to cancel / to pause / to resume this Cloudlet, the
* execution start time only holds the latest one. Meaning, all previous execution start time
* are ignored.
*
* @param clockTime the latest execution start time
* @pre clockTime >= 0.0
* @post $none
*/
public void setExecStartTime(final double clockTime) {
execStartTime = clockTime;
if (record) {
write("Sets the execution start time to " + num.format(clockTime));
}
}
/**
* Gets the latest execution start time.
*
* @return the latest execution start time
* @pre $none
* @post $result >= 0.0
*/
public double getExecStartTime() {
return execStartTime;
}
/**
* Sets this Cloudlet's execution parameters. These parameters are set by the CloudResource
* before departure or sending back to the original Cloudlet's owner.
*
* @param wallTime the time of this Cloudlet resides in a CloudResource (from arrival time until
* departure time).
* @param actualTime the total execution time of this Cloudlet in a CloudResource.
* @pre wallTime >= 0.0
* @pre actualTime >= 0.0
* @post $none
*/
public void setExecParam(final double wallTime, final double actualTime) {
if (wallTime < 0.0 || actualTime < 0.0 || index < 0) {
return;
}
final Resource res = resList.get(index);
res.wallClockTime = wallTime;
res.actualCPUTime = actualTime;
if (record) {
write("Sets the wall clock time to " + num.format(wallTime) + " and the actual CPU time to "
+ num.format(actualTime));
}
}
/**
* Sets the status code of this Cloudlet.
*
* @param newStatus the status code of this Cloudlet
* @throws Exception Invalid range of Cloudlet status
* @pre newStatus >= 0 && newStatus <= 8
* @post $none
*/
public void setCloudletStatus(final int newStatus) throws Exception {
// if the new status is same as current one, then ignore the rest
if (status == newStatus) {
return;
}
// throws an exception if the new status is outside the range
if (newStatus < Cloudlet.CREATED || newStatus > Cloudlet.FAILED_RESOURCE_UNAVAILABLE) {
throw new Exception(
"Cloudlet.setCloudletStatus() : Error - Invalid integer range for Cloudlet status.");
}
if (newStatus == Cloudlet.SUCCESS) {
finishTime = CloudSim.clock();
}
if (record) {
write("Sets Cloudlet status from " + getCloudletStatusString() + " to "
+ Cloudlet.getStatusString(newStatus));
}
status = newStatus;
}
/**
* Gets the status code of this Cloudlet.
*
* @return the status code of this Cloudlet
* @pre $none
* @post $result >= 0
*/
public int getCloudletStatus() {
return status;
}
/**
* Gets the string representation of the current Cloudlet status code.
*
* @return the Cloudlet status code as a string or <tt>null</tt> if the status code is unknown
* @pre $none
* @post $none
*/
public String getCloudletStatusString() {
return Cloudlet.getStatusString(status);
}
/**
* Gets the string representation of the given Cloudlet status code.
*
* @param status the Cloudlet status code
* @return the Cloudlet status code as a string or <tt>null</tt> if the status code is unknown
* @pre $none
* @post $none
*/
public static String getStatusString(final int status) {
String statusString = null;
switch (status) {
case Cloudlet.CREATED:
statusString = "Created";
break;
case Cloudlet.READY:
statusString = "Ready";
break;
case Cloudlet.INEXEC:
statusString = "InExec";
break;
case Cloudlet.SUCCESS:
statusString = "Success";
break;
case Cloudlet.QUEUED:
statusString = "Queued";
break;
case Cloudlet.FAILED:
statusString = "Failed";
break;
case Cloudlet.CANCELED:
statusString = "Canceled";
break;
case Cloudlet.PAUSED:
statusString = "Paused";
break;
case Cloudlet.RESUMED:
statusString = "Resumed";
break;
case Cloudlet.FAILED_RESOURCE_UNAVAILABLE:
statusString = "Failed_resource_unavailable";
break;
default:
break;
}
return statusString;
}
/**
* Gets the length of this Cloudlet.
*
* @return the length of this Cloudlet
* @pre $none
* @post $result >= 0.0
*/
public long getCloudletLength() {
return cloudletLength;
}
/**
* Gets the total length (across all PEs) of this Cloudlet.
*
* @return the total length of this Cloudlet
* @pre $none
* @post $result >= 0.0
*/
public long getCloudletTotalLength() {