Skip to content

Commit fc65856

Browse files
authored
Move deploymentStrategy out of schedulingInfo (#124)
1 parent e8682c4 commit fc65856

File tree

12 files changed

+185
-182
lines changed

12 files changed

+185
-182
lines changed

mantis-common/src/main/java/io/mantisrx/runtime/MantisJobDefinition.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.mantisrx.common.Label;
2020
import io.mantisrx.runtime.command.InvalidJobException;
21+
import io.mantisrx.runtime.descriptor.DeploymentStrategy;
2122
import io.mantisrx.runtime.descriptor.SchedulingInfo;
2223
import io.mantisrx.runtime.descriptor.StageSchedulingInfo;
2324
import io.mantisrx.runtime.parameter.Parameter;
@@ -42,6 +43,7 @@ public class MantisJobDefinition {
4243
private JobSla jobSla;
4344
private long subscriptionTimeoutSecs = 0L;
4445
private SchedulingInfo schedulingInfo;
46+
private DeploymentStrategy deploymentStrategy;
4547
private int slaMin = 0;
4648
private int slaMax = 0;
4749
private String cronSpec = "";
@@ -65,7 +67,8 @@ public MantisJobDefinition(@JsonProperty("name") String name,
6567
@JsonProperty("cronPolicy") NamedJobDefinition.CronPolicy cronPolicy,
6668
@JsonProperty("isReadyForJobMaster") boolean isReadyForJobMaster,
6769
@JsonProperty("migrationConfig") WorkerMigrationConfig migrationConfig,
68-
@JsonProperty("labels") List<Label> labels
70+
@JsonProperty("labels") List<Label> labels,
71+
@JsonProperty("deploymentStrategy") DeploymentStrategy deploymentStrategy
6972
) {
7073
this.name = name;
7174
this.user = user;
@@ -86,6 +89,7 @@ public MantisJobDefinition(@JsonProperty("name") String name,
8689
if (subscriptionTimeoutSecs > 0)
8790
this.subscriptionTimeoutSecs = subscriptionTimeoutSecs;
8891
this.schedulingInfo = schedulingInfo;
92+
this.deploymentStrategy = deploymentStrategy;
8993
this.slaMin = slaMin;
9094
this.slaMax = slaMax;
9195
this.cronSpec = cronSpec;
@@ -178,6 +182,10 @@ public void setSchedulingInfo(SchedulingInfo schedulingInfo) {
178182
this.schedulingInfo = schedulingInfo;
179183
}
180184

185+
public DeploymentStrategy getDeploymentStrategy() {
186+
return deploymentStrategy;
187+
}
188+
181189
public int getSlaMin() {
182190
return slaMin;
183191
}

mantis-common/src/main/java/io/mantisrx/runtime/descriptor/DeploymentStrategy.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Netflix, Inc.
2+
* Copyright 2021 Netflix, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,9 +21,11 @@
2121
import lombok.Builder;
2222
import lombok.EqualsAndHashCode;
2323
import lombok.Singular;
24+
import lombok.ToString;
2425

2526
@Builder
2627
@EqualsAndHashCode
28+
@ToString
2729
public class DeploymentStrategy {
2830
@Singular(ignoreNullCollections = true) private Map<Integer, StageDeploymentStrategy> stages;
2931

mantis-common/src/main/java/io/mantisrx/runtime/descriptor/SchedulingInfo.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,24 @@
2727
import java.util.*;
2828
import java.util.function.Function;
2929
import lombok.EqualsAndHashCode;
30+
import lombok.ToString;
3031

3132
@EqualsAndHashCode
33+
@ToString
3234
public class SchedulingInfo {
3335

3436
private Map<Integer, StageSchedulingInfo> stages = new HashMap<>();
35-
private final DeploymentStrategy deploymentStrategy;
3637

3738
@JsonCreator
3839
@JsonIgnoreProperties(ignoreUnknown = true)
3940
public SchedulingInfo(
40-
@JsonProperty("stages") Map<Integer, StageSchedulingInfo> stages,
41-
@JsonProperty("deploymentStrategy") DeploymentStrategy deploymentStrategy) {
41+
@JsonProperty("stages") Map<Integer, StageSchedulingInfo> stages) {
4242
this.stages = stages;
43-
this.deploymentStrategy = deploymentStrategy;
44-
}
45-
46-
@JsonIgnore
47-
public SchedulingInfo(Map<Integer, StageSchedulingInfo> stages) {
48-
this.stages = stages;
49-
this.deploymentStrategy = null;
5043
}
5144

5245
@JsonIgnore
5346
SchedulingInfo(Builder builder) {
5447
stages.putAll(builder.builderStages);
55-
this.deploymentStrategy = builder.deploymentStrategy;
5648
}
5749

5850
public static void main(String[] args) {
@@ -84,8 +76,6 @@ public Map<Integer, StageSchedulingInfo> getStages() {
8476
return stages;
8577
}
8678

87-
public DeploymentStrategy getDeploymentStrategy() { return this.deploymentStrategy; }
88-
8979
public void addJobMasterStage(StageSchedulingInfo schedulingInfo) {
9080
stages.put(0, schedulingInfo);
9181
}
@@ -94,34 +84,12 @@ public StageSchedulingInfo forStage(int stageNum) {
9484
return stages.get(stageNum);
9585
}
9686

97-
public boolean requireInheritInstanceCheck() {
98-
return this.deploymentStrategy != null && this.deploymentStrategy.requireInheritInstanceCheck();
99-
}
100-
101-
public boolean requireInheritInstanceCheck(int stageNum) {
102-
return this.deploymentStrategy != null && this.deploymentStrategy.requireInheritInstanceCheck(stageNum);
103-
}
104-
105-
@Override
106-
public String toString() {
107-
return "SchedulingInfo{" +
108-
"stages=" + stages +
109-
'}';
110-
}
111-
11287
public static class Builder {
11388

11489
private final Map<Integer, StageSchedulingInfo> builderStages = new HashMap<>();
11590
private Integer currentStage = 1;
11691
private int numberOfStages;
11792

118-
private DeploymentStrategy deploymentStrategy;
119-
120-
public Builder addDeploymentStrategy(DeploymentStrategy strategy) {
121-
this.deploymentStrategy = strategy;
122-
return this;
123-
}
124-
12593
public Builder addStage(StageSchedulingInfo stageSchedulingInfo) {
12694
builderStages.put(currentStage, stageSchedulingInfo);
12795
currentStage++;

mantis-common/src/main/java/io/mantisrx/runtime/descriptor/StageDeploymentStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Netflix, Inc.
2+
* Copyright 2021 Netflix, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2021 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.mantisrx.runtime.descriptor;
18+
19+
import static org.junit.Assert.*;
20+
21+
import org.junit.Test;
22+
23+
public class DeploymentStrategyTest {
24+
@Test
25+
public void shouldRequireInheritInstanceCheck() {
26+
DeploymentStrategy res = DeploymentStrategy.builder()
27+
.stage(1, StageDeploymentStrategy.builder().inheritInstanceCount(true).build())
28+
.build();
29+
assertTrue(res.requireInheritInstanceCheck());
30+
assertTrue(res.requireInheritInstanceCheck(1));
31+
assertFalse(res.requireInheritInstanceCheck(2));
32+
33+
res = DeploymentStrategy.builder()
34+
.stage(2, StageDeploymentStrategy.builder().inheritInstanceCount(true).build())
35+
.stage(3, StageDeploymentStrategy.builder().inheritInstanceCount(false).build())
36+
.build();
37+
assertTrue(res.requireInheritInstanceCheck());
38+
assertTrue(res.requireInheritInstanceCheck(2));
39+
assertFalse(res.requireInheritInstanceCheck(1));
40+
assertFalse(res.requireInheritInstanceCheck(3));
41+
}
42+
43+
@Test
44+
public void shouldNotRequireInheritInstanceCheck() {
45+
DeploymentStrategy res = DeploymentStrategy.builder()
46+
.stage(1, StageDeploymentStrategy.builder().inheritInstanceCount(false).build())
47+
.build();
48+
assertFalse(res.requireInheritInstanceCheck(1));
49+
assertFalse(res.requireInheritInstanceCheck(2));
50+
assertFalse(res.requireInheritInstanceCheck());
51+
52+
// test default setting
53+
res = DeploymentStrategy.builder().build();
54+
assertFalse(res.requireInheritInstanceCheck(1));
55+
assertFalse(res.requireInheritInstanceCheck(2));
56+
assertFalse(res.requireInheritInstanceCheck());
57+
58+
// test multiple stages
59+
res = DeploymentStrategy.builder()
60+
.stage(1, StageDeploymentStrategy.builder().build())
61+
.stage(3, StageDeploymentStrategy.builder().inheritInstanceCount(false).build())
62+
.build();
63+
assertFalse(res.requireInheritInstanceCheck(1));
64+
assertFalse(res.requireInheritInstanceCheck(2));
65+
assertFalse(res.requireInheritInstanceCheck());
66+
}
67+
}

mantis-common/src/test/java/io/mantisrx/runtime/descriptor/SchedulingInfoTest.java

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -25,82 +25,6 @@
2525
import org.junit.Test;
2626

2727
public class SchedulingInfoTest {
28-
@Test
29-
public void shouldRequireInheritInstanceCheck() {
30-
SchedulingInfo.Builder builder = new SchedulingInfo.Builder().numberOfStages(1);
31-
builder.addStage(
32-
StageSchedulingInfo.builder().numberOfInstances(1).scalable(true).build());
33-
builder.addDeploymentStrategy(
34-
DeploymentStrategy.builder()
35-
.stage(1,
36-
new StageDeploymentStrategy.StageDeploymentStrategyBuilder().inheritInstanceCount(true).build())
37-
.build());
38-
39-
SchedulingInfo res = builder.build();
40-
assertTrue(res.requireInheritInstanceCheck());
41-
assertTrue(res.requireInheritInstanceCheck(1));
42-
assertFalse(res.requireInheritInstanceCheck(2));
43-
assertTrue(res.forStage(1).getScalable());
44-
45-
// test multiple stages
46-
builder = new SchedulingInfo.Builder().numberOfStages(3);
47-
builder.addStage(StageSchedulingInfo.builder().numberOfInstances(1).build())
48-
.addStage(StageSchedulingInfo.builder().numberOfInstances(2).build())
49-
.addStage(StageSchedulingInfo.builder().numberOfInstances(2).build());
50-
51-
builder.addDeploymentStrategy(
52-
DeploymentStrategy.builder()
53-
.stage(2,
54-
new StageDeploymentStrategy.StageDeploymentStrategyBuilder().inheritInstanceCount(true).build())
55-
.stage(3,
56-
new StageDeploymentStrategy.StageDeploymentStrategyBuilder().inheritInstanceCount(false).build())
57-
.build());
58-
res = builder.build();
59-
assertTrue(res.requireInheritInstanceCheck());
60-
assertTrue(res.requireInheritInstanceCheck(2));
61-
assertFalse(res.requireInheritInstanceCheck(1));
62-
assertFalse(res.requireInheritInstanceCheck(3));
63-
}
64-
65-
@Test
66-
public void shouldNotRequireInheritInstanceCheck() {
67-
SchedulingInfo.Builder builder = new SchedulingInfo.Builder().numberOfStages(1);
68-
builder.addStage(
69-
StageSchedulingInfo.builder().numberOfInstances(1).build());
70-
SchedulingInfo res = builder.build();
71-
assertFalse(res.requireInheritInstanceCheck(1));
72-
assertFalse(res.requireInheritInstanceCheck(2));
73-
assertFalse(res.requireInheritInstanceCheck());
74-
75-
// test default setting
76-
builder = new SchedulingInfo.Builder().numberOfStages(1);
77-
builder.addStage(
78-
StageSchedulingInfo.builder().numberOfInstances(1).build());
79-
builder.addDeploymentStrategy(
80-
DeploymentStrategy.builder().build());
81-
res = builder.build();
82-
assertFalse(res.requireInheritInstanceCheck(1));
83-
assertFalse(res.requireInheritInstanceCheck(2));
84-
assertFalse(res.requireInheritInstanceCheck());
85-
86-
// test multiple stages
87-
builder = new SchedulingInfo.Builder().numberOfStages(3);
88-
builder.addStage(StageSchedulingInfo.builder().numberOfInstances(1).build())
89-
.addStage(StageSchedulingInfo.builder().numberOfInstances(2).build())
90-
.addStage(StageSchedulingInfo.builder().numberOfInstances(2).build());
91-
builder.addDeploymentStrategy(
92-
DeploymentStrategy.builder()
93-
.stage(1,
94-
StageDeploymentStrategy.builder().build())
95-
.stage(3,
96-
StageDeploymentStrategy.builder().inheritInstanceCount(false).build())
97-
.build());
98-
res = builder.build();
99-
assertFalse(res.requireInheritInstanceCheck(1));
100-
assertFalse(res.requireInheritInstanceCheck(2));
101-
assertFalse(res.requireInheritInstanceCheck());
102-
}
103-
10428
@Test
10529
public void buildWithInheritInstanceTest() {
10630
Map<Integer, StageSchedulingInfo> givenStages = new HashMap<>();

mantis-control-plane/mantis-control-plane-client/src/main/java/io/mantisrx/server/master/client/MantisMasterClientApi.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.mantisrx.runtime.MantisJobState;
2424
import io.mantisrx.runtime.WorkerMigrationConfig;
2525
import io.mantisrx.runtime.codec.JsonCodec;
26+
import io.mantisrx.runtime.descriptor.DeploymentStrategy;
2627
import io.mantisrx.runtime.descriptor.SchedulingInfo;
2728
import io.mantisrx.runtime.parameter.Parameter;
2829
import io.mantisrx.server.core.JobAssignmentResult;
@@ -286,7 +287,25 @@ public Observable<JobSubmitResponse> submitJob(final String name, final String v
286287
final List<Label> labels) {
287288
try {
288289
String jobDef = getJobDefinitionString(name, null, version, parameters, jobSla,
289-
subscriptionTimeoutSecs, schedulingInfo, readyForJobMaster, migrationConfig, labels);
290+
subscriptionTimeoutSecs, schedulingInfo, readyForJobMaster, migrationConfig, labels, null);
291+
return submitJob(jobDef);
292+
} catch (MalformedURLException | JsonProcessingException e) {
293+
return Observable.error(e);
294+
}
295+
}
296+
297+
public Observable<JobSubmitResponse> submitJob(final String name, final String version,
298+
final List<Parameter> parameters,
299+
final JobSla jobSla,
300+
final long subscriptionTimeoutSecs,
301+
final SchedulingInfo schedulingInfo,
302+
final boolean readyForJobMaster,
303+
final WorkerMigrationConfig migrationConfig,
304+
final List<Label> labels,
305+
final DeploymentStrategy deploymentStrategy) {
306+
try {
307+
String jobDef = getJobDefinitionString(name, null, version, parameters, jobSla,
308+
subscriptionTimeoutSecs, schedulingInfo, readyForJobMaster, migrationConfig, labels, deploymentStrategy);
290309
return submitJob(jobDef);
291310
} catch (MalformedURLException | JsonProcessingException e) {
292311
return Observable.error(e);
@@ -322,12 +341,12 @@ public Observable<JobSubmitResponse> submitJob(final String submitJobRequestJson
322341
private String getJobDefinitionString(String name, String jobUrl, String version, List<Parameter> parameters,
323342
JobSla jobSla, long subscriptionTimeoutSecs, SchedulingInfo schedulingInfo,
324343
boolean readyForJobMaster, final WorkerMigrationConfig migrationConfig,
325-
final List<Label> labels)
344+
final List<Label> labels, final DeploymentStrategy deploymentStrategy)
326345
throws JsonProcessingException, MalformedURLException {
327346
MantisJobDefinition jobDefinition = new MantisJobDefinition(name, System.getProperty("user.name"),
328347
jobUrl == null ? null : new URL(jobUrl),
329348
version, parameters, jobSla, subscriptionTimeoutSecs, schedulingInfo, 0, 0,
330-
null, null, readyForJobMaster, migrationConfig, labels);
349+
null, null, readyForJobMaster, migrationConfig, labels, deploymentStrategy);
331350
return objectMapper.writeValueAsString(jobDefinition);
332351
}
333352

mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/api/akka/route/proto/JobClusterProtoAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ public static final JobClusterManagerProto.SubmitJobRequest toSubmitJobClusterRe
235235
jd.getSubscriptionTimeoutSecs(),
236236
jd.getSchedulingInfo(),
237237
jd.getSchedulingInfo() == null ? -1 : jd.getSchedulingInfo().getStages().size(),
238-
jd.getLabels())
238+
jd.getLabels(),
239+
jd.getDeploymentStrategy())
239240
));
240241

241242
return request;

mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/master/jobcluster/JobClusterActor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ public void onJobSubmit(final SubmitJobRequest request) {
12971297
}
12981298
}
12991299

1300-
logger.info("Submitting job ");
1300+
logger.info("Submitting job {}", request);
13011301
try {
13021302
if (requireJobActorProcess(request)) {
13031303
logger.info("Sending job submit request to job actor for inheritance: {}", request.requestId);

mantis-control-plane/mantis-control-plane-server/src/main/java/io/mantisrx/server/master/domain/DataFormatAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public static IMantisJobMetadata convertMantisJobWriteableToMantisJobMetadata(Ma
459459
// generate job defn
460460
JobDefinition jobDefn = new JobDefinition(archJob.getName(), archJob.getUser(),
461461
artifactName.orElse(""), null,archJob.getParameters(), archJob.getSla(),
462-
archJob.getSubscriptionTimeoutSecs(),schedulingInfo, archJob.getNumStages(),archJob.getLabels());
462+
archJob.getSubscriptionTimeoutSecs(),schedulingInfo, archJob.getNumStages(),archJob.getLabels(), null);
463463
Optional<JobId> jIdOp = JobId.fromId(archJob.getJobId());
464464
if(!jIdOp.isPresent()) {
465465
throw new IllegalArgumentException("Invalid JobId " + archJob.getJobId());

0 commit comments

Comments
 (0)