-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performing tasks on a remote worker with Docker. #24
base: scheduler
Are you sure you want to change the base?
Changes from 15 commits
d1d3516
aa5d3db
2e9e19e
3263936
4ffca6b
8ff2ba0
9995d6e
04980f5
d674dd7
4a227ab
4108561
9dbcad8
c9df93e
257d7a2
2778e1b
a1160ce
7ddbd80
ba307c5
cc7b190
4acc5aa
299ee0d
c0be175
d145f83
7f66f3a
4ac36ea
423cae0
41b33d3
5a339a1
31902ac
1e7fc3e
31e2500
7a1ff81
590cec3
f7eee51
6bc32f7
eb11112
6155c9e
b0130ce
0c16a4f
b960213
6a54d18
e5bb4e1
03c6524
4cb4eb9
029998e
331e7c3
5b3c49d
d07aaee
30ee95e
0e7e072
a5e2b1e
9777525
e843eeb
5b14f76
72f0d5b
7cf7612
a4d2410
6613e61
edc5fb8
6beadbb
8927983
fa457db
94cff19
fa29733
d384761
678898d
605a80d
18916a5
3254339
57fb84c
fa6a286
2ae275c
669715d
29bfd18
1e3b5a4
47d6ba7
d735683
307b2b2
0de5f5d
d84689f
8ab7b00
3b55797
c3b1d11
1841dee
cf004dc
98a3c53
6f6a25f
69e8d76
17adb4e
8933f15
5fdd5b7
59bdd83
f614d69
f2b8bd6
0f88363
1dfc5b9
60bedda
b0aec4f
1894f66
bf5824c
9bf18eb
29ae51d
c66c791
f2a6877
255fede
c66ac7f
0183f29
c2bd0c7
c8c0d5b
fce90ec
e6bc370
72ca41e
2f21187
976cb1d
fb4fc3f
7c004d3
4cda575
aa1520e
a462d98
cd8cae8
d45509c
cdbb1a4
33eeba6
39d1527
13f2b85
a1823dc
ad5c91a
c58615b
1fe1575
e1b1ee6
b0635d6
f151bfb
bae5c91
d2ee2cb
b4f5f65
7dc0bb0
81d2a13
3e18487
0449dc7
39c7bfe
1980a41
ff43c53
68a69c3
0a8c908
8c25681
365877d
7b960ff
133f6b7
46db737
b49aaf2
c73bdfd
225c5cb
eb47684
474d17d
83eac19
8c73e71
93a3f8f
cfff7c6
fd34ee9
77d5e37
5588a3d
6abb416
9119f89
db7475d
0ab583c
8449b86
176a291
5cf1755
439c9dd
11faca6
05bc87f
f2860e5
3db7660
f2b93c1
017b5ff
4217f60
fecc577
bc5da7b
bf44af5
949b9d2
e46085c
43cb281
eb93f7d
5f612fb
adce0e4
ace9b70
18e4855
c54bd8e
1719aa2
a3ac715
5881060
57b1ca8
98511bb
e06f6c0
a99a21d
e23f5d8
5bdff1b
4f976f7
acd3da8
4bf2f97
a4778af
9d0d7d9
5c4f22d
0efed76
2c4e452
e04b234
225d195
0c86843
2037525
ffc32ad
8474423
1448947
2dc12b1
40c287f
eebeebd
d1d1af6
71171c4
2bf2a28
2dfe64e
107b6c8
48e3dfc
e1fc276
871e522
72347da
c88aa22
5bfe1b9
8cccfbd
845cd7a
22df4ce
a6e7803
45ab8e0
4711aa0
a714d43
d61014d
772ccc2
5344864
082c510
9b6af8b
263d226
58636d1
ebec0d7
359ec42
4a64329
08a175d
78650ff
35ebd5e
a4503f6
8dcff9a
10004fe
a81e0c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
package org.fogbowcloud.arrebol; | ||
|
||
import com.google.gson.Gson; | ||
import org.apache.log4j.Logger; | ||
import org.fogbowcloud.arrebol.execution.DockerTaskExecutor; | ||
import org.fogbowcloud.arrebol.execution.RawTaskExecutor; | ||
import org.fogbowcloud.arrebol.execution.TaskExecutor; | ||
import org.fogbowcloud.arrebol.execution.Worker; | ||
import org.fogbowcloud.arrebol.execution.*; | ||
import org.fogbowcloud.arrebol.models.job.Job; | ||
import org.fogbowcloud.arrebol.models.job.JobState; | ||
import org.fogbowcloud.arrebol.models.specification.Specification; | ||
|
@@ -20,18 +18,15 @@ | |
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
@Component | ||
public class ArrebolController { | ||
|
||
private final Logger LOGGER = Logger.getLogger(ArrebolController.class); | ||
|
||
private final Properties properties; | ||
private Configuration configuration; | ||
private final DefaultScheduler scheduler; | ||
private final Map<String, Job> jobPool; | ||
private final TaskQueue queue; | ||
|
@@ -43,16 +38,17 @@ public class ArrebolController { | |
@Autowired | ||
private JobRepository jobRepository; | ||
|
||
public ArrebolController(Properties properties) { | ||
this.properties = properties; | ||
public ArrebolController() { | ||
|
||
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath(); | ||
Properties arrebolProperties = new Properties(); | ||
|
||
try (InputStream input = new FileInputStream(path + File.separator + "arrebol.conf")) { | ||
arrebolProperties.load(input); | ||
} catch (IOException ex) { | ||
LOGGER.error("Error on loading properties file path=" + path, ex); | ||
//Configuration arrebolConfiguration | ||
try { | ||
Gson gson = new Gson(); | ||
BufferedReader bufferedReader = new BufferedReader(new FileReader(path + File.separator + "arrebol.json")); | ||
this.configuration = gson.fromJson(bufferedReader, Configuration.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I liked the util certifyConfigurationProperties method you guys added. maybe, refactor lines 62-64 to a loadConfigurationFile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
DockerVariable.DEFAULT_IMAGE = this.configuration.getImageId(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ins't this DockerStuff related to an specific worker type? shouldn't be moved to worker specific loading code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to inside new method called loadGlobalVariables. |
||
} catch (FileNotFoundException e) { | ||
LOGGER.error("Error on loading properties file path=" + path, e); | ||
System.exit(1); | ||
} | ||
|
||
|
@@ -62,7 +58,7 @@ public ArrebolController(Properties properties) { | |
this.queue = new TaskQueue(queueId, queueName); | ||
|
||
int poolId = 1; | ||
WorkerPool pool = createPool(arrebolProperties, poolId); | ||
WorkerPool pool = createPool(configuration, poolId); | ||
|
||
//create the scheduler bind the pieces together | ||
FifoSchedulerPolicy policy = new FifoSchedulerPolicy(); | ||
|
@@ -75,39 +71,65 @@ public ArrebolController(Properties properties) { | |
private static final String RAW_TYPE = "raw"; | ||
private static final String DOCKER_TYPE = "docker"; | ||
|
||
private WorkerPool createPool(Properties properties, int poolId) { | ||
private WorkerPool createPool(Configuration configuration, int poolId) { | ||
|
||
//we need to deal with missing/wrong properties | ||
thiagomanel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Collection<Worker> workers = new LinkedList<>(); | ||
String poolType = properties.getProperty("pool.type"); | ||
|
||
int poolSize = new Integer(properties.getProperty("pool.size")); | ||
for (int i = 0; i < poolSize; i++) { | ||
TaskExecutor executor = createTaskExecutor(poolType, properties); | ||
Specification resourceSpec = null; | ||
Worker worker = new MatchAnyWorker(resourceSpec, "resourceId-"+i, poolId, executor); | ||
workers.add(worker); | ||
} | ||
populatePool(workers, poolId, configuration); | ||
|
||
WorkerPool pool = new StaticPool(poolId, workers); | ||
LOGGER.info("pool={" + pool + "} created with workers={" + workers + "}"); | ||
|
||
return pool; | ||
} | ||
|
||
private TaskExecutor createTaskExecutor(String type, Properties properties) { | ||
private void populatePool(Collection<Worker> workers, int poolId, Configuration configuration){ | ||
String poolType = configuration.getPoolType(); | ||
if(poolType.equals(DOCKER_TYPE)){ | ||
joivo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
workers.addAll(createDockerWorkers(poolId, configuration)); | ||
} else if(poolType.equals(RAW_TYPE)){ | ||
workers.addAll(createRawWorkers(poolId, configuration)); | ||
} | ||
} | ||
|
||
private Collection<Worker> createDockerWorkers(Integer poolId, Configuration configuration){ | ||
Collection<Worker> workers = new LinkedList<>(); | ||
int poolSize = new Integer(configuration.getPoolSize()); | ||
String imageId = configuration.getImageId(); | ||
for(String address : configuration.getWorkers()){ | ||
for (int i = 0; i < poolSize; i++) { | ||
joivo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LOGGER.info("Creating docker worker with address=" + address); | ||
joivo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Worker worker = createDockerWorker(poolId, i, imageId, address); | ||
workers.add(worker); | ||
} | ||
} | ||
return workers; | ||
} | ||
|
||
TaskExecutor executor = null; | ||
private Worker createDockerWorker(Integer poolId, int resourceId, String imageId, String address){ | ||
TaskExecutor executor = new DockerTaskExecutor(imageId, "docker-executor-" + UUID.randomUUID().toString(), address); | ||
Specification resourceSpec = null; | ||
Worker worker = new MatchAnyWorker(resourceSpec, "resourceId-"+resourceId, poolId, executor); | ||
return worker; | ||
} | ||
|
||
if (type.equals(RAW_TYPE)) { | ||
executor = new RawTaskExecutor(); | ||
} else if (type.equals(DOCKER_TYPE)) { | ||
String imageId = properties.getProperty("pool.image_id"); | ||
executor = new DockerTaskExecutor(imageId, "docker-executor-" + UUID.randomUUID().toString()); | ||
private Collection<Worker> createRawWorkers(Integer poolId, Configuration configuration){ | ||
Collection<Worker> workers = new LinkedList<>(); | ||
int poolSize = new Integer(configuration.getPoolSize()); | ||
for (int i = 0; i < poolSize; i++) { | ||
LOGGER.info("Creating raw worker[" + i + "]"); | ||
joivo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Worker worker = createRawWorker(poolId, i); | ||
workers.add(worker); | ||
} | ||
return workers; | ||
} | ||
|
||
return executor; | ||
private Worker createRawWorker(Integer poolId, int resourceId){ | ||
TaskExecutor executor = new RawTaskExecutor(); | ||
Specification resourceSpec = null; | ||
Worker worker = new MatchAnyWorker(resourceSpec, "resourceId-"+resourceId, poolId, executor); | ||
return worker; | ||
} | ||
|
||
public void start() { | ||
|
@@ -158,4 +180,6 @@ public TaskState getTaskState(String taskId) { | |
//FIXME: | ||
return null; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.fogbowcloud.arrebol; | ||
|
||
import java.util.List; | ||
|
||
public class Configuration { | ||
|
||
private String poolType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make them final There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
private Integer poolSize; | ||
private String imageId; | ||
private List<String> workers; | ||
|
||
public Configuration(String poolType, Integer poolSize, String imageId, List<String> workers) { | ||
joivo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.poolType = poolType; | ||
this.poolSize = poolSize; | ||
this.imageId = imageId; | ||
this.workers = workers; | ||
} | ||
|
||
public String getPoolType() { | ||
return poolType; | ||
} | ||
|
||
public Integer getPoolSize() { | ||
return poolSize; | ||
} | ||
|
||
public String getImageId() { | ||
return imageId; | ||
} | ||
|
||
public List<String> getWorkers() { | ||
return workers; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gson gson = new Gson(); could be moved to before the try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to inside loadConfigurationFile method.