]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/federation/Federation.java
Restoring the original state (migration)
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / federation / Federation.java
1 package at.ac.tuwien.lsdc.federation;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5
6 import at.ac.tuwien.lsdc.JobGenerator;
7 import at.ac.tuwien.lsdc.SchedSimulator;
8 import at.ac.tuwien.lsdc.sched.AbstractScheduler;
9 import at.ac.tuwien.lsdc.sched.SchedulerB;
10 import at.ac.tuwien.lsdc.types.Application;
11
12 /**
13  * Cloudpartners management. Class to be used to ask cloudpartners to take one
14  * of our APPs over to their infrastructure.
15  * 
16  * @author jan
17  * 
18  */
19 public class Federation {
20         /**
21          * Logger.
22          */
23         private static final Logger LOG = LoggerFactory.getLogger(SchedulerB.class);
24
25         private int numPartners;
26
27         public Federation(int numPartners) {
28                 this.numPartners = numPartners;
29         }
30
31         /**
32          * Try to outsource app.
33          * 
34          * @param app
35          *            Application to outsource.
36          * @return true, if application can be outsourced.
37          */
38         public boolean askToOutsource(Application app) {
39                 if ((Math.random() * 100) < (10 * numPartners)) {
40                         LOG.info("Outsource:" + app);
41                         return true;
42                 }
43                 return false;
44         }
45
46         /**
47          * Try to insource app.
48          * 
49          * @return application to be insourced.
50          */
51         public Application askToInsource() {
52                 int size;
53                 int ram;
54                 int cpu;
55                 int duration;
56                 
57                 long timestamp = AbstractScheduler.getCurrentTime() + JobGenerator.randomInt(1, 3);
58
59                 if ((Math.random() * 100) < (10 * numPartners)) {
60                         LOG.info("Insource app ");
61                         switch (SchedSimulator.getScenario()) {
62                                 case A :
63                                         size = JobGenerator.randomInt(20, 100);
64                                         ram = JobGenerator.randomInt(30, 50);
65                                         cpu = JobGenerator.randomInt(50, 100);
66                                         duration = JobGenerator.randomInt(1, 50);
67                                         return new Application(timestamp, size, ram, cpu, duration);
68                                 case B :
69                                         size = JobGenerator.randomInt(150, 500);
70                                         ram = JobGenerator.randomInt(100, 700);
71                                         cpu = JobGenerator.randomInt(100, 400);
72                                         duration = JobGenerator.randomInt(1, 50);
73                                         return new Application(timestamp, size, ram, cpu, duration);
74                                 default :
75                                         size = JobGenerator.randomInt(20, 500);
76                                         ram = JobGenerator.randomInt(30, 700);
77                                         cpu = JobGenerator.randomInt(50, 400);
78                                         duration = JobGenerator.randomInt(1, 50);
79                                         return new Application(timestamp, size, ram, cpu, duration);
80                         }
81                 }
82                 return null;
83         }
84 }