forked from cloudbees/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createMesosTemplate.groovy
153 lines (135 loc) · 4.54 KB
/
createMesosTemplate.groovy
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
/*
Author: kuisathaverat
configure Mesos Cloud from a groovy script
*/
import org.jenkinsci.plugins.mesos.MesosCloud;
import org.jenkinsci.plugins.mesos.MesosSlaveInfo;
import org.apache.mesos.Protos;
import hudson.slaves.NodeProperty;
def createMesosCloud(
nativeLibraryPath,
master,
description,
frameworkName,
role,
slavesUser,
credentialsId,
slaveInfos,
checkpoint,
onDemandRegistration,
jenkinsURL,
declineOfferDuration,
cloudID) {
return new MesosCloud(
nativeLibraryPath,
master,
description,
frameworkName,
role,
slavesUser,
credentialsId,
null,
null,
slaveInfos,
checkpoint,
onDemandRegistration,
jenkinsURL,
declineOfferDuration,
cloudID)
}
def createMesosSlaveInfo(
labelString, mode, slaveCpus, slaveMem,
minExecutors, maxExecutors, executorCpus, executorMem,
remoteFSRoot, idleTerminationMinutes, slaveAttributes,
jvmArgs, jnlpArgs, defaultSlave,
containerInfo, additionalURIs, nodeProperties){
return new MesosSlaveInfo(labelString, mode, slaveCpus, slaveMem, minExecutors,
maxExecutors, executorCpus, executorMem, remoteFSRoot, idleTerminationMinutes,
slaveAttributes, jvmArgs, jnlpArgs, defaultSlave, containerInfo, additionalURIs,
nodeProperties)
}
def createContainerInfo(
type, dockerImage, dockerPrivilegedMode, dockerForcePullImage,
dockerImageCustomizable, useCustomDockerCommandShell, customDockerCommandShell,
volumes, parameters, networking, portMappings, networkInfos){
return new MesosSlaveInfo.ContainerInfo(type, dockerImage,dockerPrivilegedMode,
dockerForcePullImage,dockerImageCustomizable, useCustomDockerCommandShell,
customDockerCommandShell,volumes,parameters, networking,portMappings,networkInfos)
}
def createPortMapping(containerPort, hostPort, protocol){
return new MesosSlaveInfo.PortMapping(containerPort,hostPort,protocol)
}
def createNetworkInfo(networkName){
return new MesosSlaveInfo.NetworkInfo(networkName)
}
def createVolume(containerPath, hostPath, readOnly){
return new MesosSlaveInfo.Volume(containerPath,hostPath,readOnly)
}
def createParameter(key, value){
return new MesosSlaveInfo.Parameter(key, value)
}
//configured
MesosCloud cloud = MesosCloud.get();
//new cloud from scratch
/*
def cloud = createMesosCloud('/native/Library/Path',
'127.0.0.1:8080',
'description',
'Jenkins Scheduler',
'*',
'slavesUser',
'credentialsId',
null,
true,
false,
Jenkins.getInstance().getRootUrl(),
'600000',
null)
Jenkins.instance.clouds.add(cloud)
*/
if (cloud != null) {
def volumes = new LinkedList<MesosSlaveInfo.Volume>()
def parameters = new LinkedList<MesosSlaveInfo.Parameter>()
def portMappings = new LinkedList<MesosSlaveInfo.PortMapping>()
def networkInfos = new LinkedList<MesosSlaveInfo.NetworkInfo>()
def nodeProperties = new LinkedList<? extends NodeProperty<?>>()
def additionalURIs = new LinkedList<URI>()
volumes.add(createVolume('/mnt/folder','/mnt',false))
parameters.add(createParameter('key','value'))
portMappings.add(createPortMapping(8080,80,'http'))
networkInfos.add(createNetworkInfo('sampleNet'))
def containerInfo = createContainerInfo("",
"organization/image:version",
false,
false,
false,
false,
"",
volumes,
parameters,
Protos.ContainerInfo.DockerInfo.Network.BRIDGE.name(),
portMappings,
networkInfos)
def mesosSlaveInfo = createMesosSlaveInfo('labelString',
Node.Mode.NORMAL,
'0.1',
'512',
'1',
'2',
'0.1',
'128',
'/jenkins',
'3',
'',
'-Xms16m -XX:+UseConcMarkSweepGC -Djava.net.preferIPv4Stack=true',
'-noReconnect',
'false',
containerInfo,
additionalURIs,
nodeProperties)
cloud.getSlaveInfos().add(mesosSlaveInfo)
cloud.getSlaveInfos().each {
t ->
println t
}
}