forked from jenkinsci/azure-container-agents-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAciContainerTemplateBuilder.java
More file actions
99 lines (91 loc) · 4.5 KB
/
Copy pathAciContainerTemplateBuilder.java
File metadata and controls
99 lines (91 loc) · 4.5 KB
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
package com.microsoft.jenkins.containeragents.builders;
import com.microsoft.jenkins.containeragents.aci.AciContainerTemplate;
import com.microsoft.jenkins.containeragents.remote.LaunchMethodTypeContent;
import com.microsoft.jenkins.containeragents.strategy.ContainerIdleRetentionStrategy;
import com.microsoft.jenkins.containeragents.util.Constants;
public class AciContainerTemplateBuilder extends AciContainerTemplateFluent<AciContainerTemplateBuilder> {
private AciContainerTemplateFluent<?> fluent;
public AciContainerTemplateBuilder() {
this.fluent = this;
}
public AciContainerTemplateBuilder(AciContainerTemplate template) {
this.fluent = this;
this.fluent.withName(template.getName());
this.fluent.withLabel(template.getLabel());
this.fluent.withImage(template.getImage());
this.fluent.withOsType(template.getOsType());
this.fluent.withIpType(template.getIpType());
this.fluent.withCommand(template.getCommand());
this.fluent.withRootFs(template.getRootFs());
this.fluent.withTimeout(template.getTimeout());
this.fluent.withPorts(template.getPorts());
this.fluent.withCpu(template.getCpu());
this.fluent.withMemory(template.getMemory());
if (template.getRetentionStrategy() instanceof ContainerIdleRetentionStrategy) {
this.fluent.withIdleRetentionStrategy(((ContainerIdleRetentionStrategy) template.getRetentionStrategy())
.getIdleMinutes());
} else {
this.fluent.withOnceRetentionStrategy();
}
this.fluent.withEnvVars(template.getEnvVars());
this.fluent.withPrivateRegistryCredentials(template.getPrivateRegistryCredentials());
this.fluent.withVolume(template.getVolumes());
if (template.getLaunchMethodType().equals(Constants.LAUNCH_METHOD_JNLP)) {
this.fluent.withJNLPLaunchMethod();
} else {
this.fluent.withSSHLaunchMethod(template.getSshCredentialsId(), template.getSshPort());
}
}
public AciContainerTemplateBuilder(AciContainerTemplateFluent<?> fluent) {
this.fluent = fluent;
}
public AciContainerTemplateBuilder(AciContainerTemplateFluent<?> fluent, AciContainerTemplate template) {
this.fluent = fluent;
this.fluent.withName(template.getName());
this.fluent.withLabel(template.getLabel());
this.fluent.withImage(template.getImage());
this.fluent.withOsType(template.getOsType());
this.fluent.withIpType(template.getIpType());
this.fluent.withCommand(template.getCommand());
this.fluent.withRootFs(template.getRootFs());
this.fluent.withTimeout(template.getTimeout());
this.fluent.withPorts(template.getPorts());
this.fluent.withCpu(template.getCpu());
this.fluent.withMemory(template.getMemory());
if (template.getRetentionStrategy() instanceof ContainerIdleRetentionStrategy) {
this.fluent.withIdleRetentionStrategy(((ContainerIdleRetentionStrategy) template.getRetentionStrategy())
.getIdleMinutes());
} else {
this.fluent.withOnceRetentionStrategy();
}
this.fluent.withEnvVars(template.getEnvVars());
this.fluent.withPrivateRegistryCredentials(template.getPrivateRegistryCredentials());
this.fluent.withVolume(template.getVolumes());
if (template.getLaunchMethodType().equals(Constants.LAUNCH_METHOD_JNLP)) {
this.fluent.withJNLPLaunchMethod();
} else {
this.fluent.withSSHLaunchMethod(template.getSshCredentialsId(), template.getSshPort());
}
}
public AciContainerTemplate build() {
AciContainerTemplate template = new AciContainerTemplate(fluent.getName(),
fluent.getLabel(),
fluent.getTimeout(),
fluent.getOsType(),
fluent.getImage(),
fluent.getCommand(),
fluent.getRootFs(),
fluent.getIpType(),
fluent.getPorts(),
fluent.getPrivateRegistryCredentials(),
fluent.getEnvVars(),
fluent.getVolumes(),
fluent.getRetentionStrategy(),
fluent.getCpu(),
fluent.getMemory());
template.setLaunchMethodType(fluent.getLaunchMethodType());
template.setLaunchMethodTypeContent(new LaunchMethodTypeContent(fluent.getSshCredentialsId(),
fluent.getSshPort()));
return template;
}
}