Skip to content
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

Add description to JobConfig #21489

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions checkstyle/suppressions.xml
Expand Up @@ -416,6 +416,7 @@
<suppress checks="" files="[\\/]module-info"/>

<suppress checks="FileLength" files="src[\\/]main[\\/]java[\\/]com[\\/]hazelcast[\\/]jet[\\/]aggregate[\\/]AggregateOperations"/>
<suppress checks="FileLength" files="src[\\/]main[\\/]java[\\/]com[\\/]hazelcast[\\/]jet[\\/]config[\\/]JobConfig"/>
<suppress checks="CyclomaticComplexity" files="src[\\/]main[\\/]java[\\/]com[\\/]hazelcast[\\/]jet[\\/]config[\\/]JobConfig"/>

<suppress checks="InnerAssignment|JavadocType|TrailingComment|MethodCount|OperatorWrap|ClassDataAbstractionCoupling|ClassFanOutComplexity|CyclomaticComplexity|NPathComplexity" files="[\\/]src[\\/]main[\\/]java[\\/]com[\\/]hazelcast[\\/]jet[\\/]"/>
Expand Down
3 changes: 3 additions & 0 deletions checkstyle/suppressions_jet.xml
Expand Up @@ -62,6 +62,9 @@
<!-- Suppress maximum line count of a large factory file with lot of javadoc -->
<suppress checks="FileLength" files="com[\\/]hazelcast[\\/]jet[\\/]aggregate[\\/]AggregateOperations.java"/>

<!-- Suppress maximum line count of a large JobConfig file with a lot of javadoc -->
<suppress checks="FileLength" files="com[\\/]hazelcast[\\/]jet[\\/]config[\\/]JobConfig.java"/>

<!-- Suppress checks for auto-generated client protocol codecs -->
<suppress checks="UnusedImports|LineLength|VisibilityModifier|AvoidStarImport|RegexpSingleline|ParameterNumber"
files="src[\\/]main[\\/]java[\\/]com[\\/]hazelcast[\\/]jet[\\/]impl[\\/]client[\\/]protocol[\\/]codec[\\/]"/>
Expand Down
Expand Up @@ -143,6 +143,9 @@ public void validate(SqlValidator validator, SqlValidatorScope scope) {
}

switch (key) {
case "description":
jobConfig.setDescription(value);
break;
case "processingGuarantee":
switch (value) {
case "exactlyOnce":
Expand Down
Expand Up @@ -182,6 +182,7 @@ public void test_jobOptions() {
sqlService.execute("CREATE JOB testJob " +
"OPTIONS (" +
// we use non-default value for each config option
"'description'='some random description'," +
"'processingGuarantee'='exactlyOnce'," +
"'snapshotIntervalMillis'='6000'," +
"'autoScaling'='false'," +
Expand All @@ -194,6 +195,7 @@ public void test_jobOptions() {

JobConfig config = instance().getJet().getJob("testJob").getConfig();

assertEquals("some random description", config.getDescription());
assertEquals(EXACTLY_ONCE, config.getProcessingGuarantee());
assertEquals(6000, config.getSnapshotIntervalMillis());
assertFalse("isAutoScaling", config.isAutoScaling());
Expand Down
38 changes: 33 additions & 5 deletions hazelcast/src/main/java/com/hazelcast/jet/config/JobConfig.java
Expand Up @@ -70,6 +70,7 @@ public class JobConfig implements IdentifiedDataSerializable {
private transient boolean locked;

private String name;
private String description;
private ProcessingGuarantee processingGuarantee = ProcessingGuarantee.NONE;
private long snapshotIntervalMillis = SNAPSHOT_INTERVAL_MILLIS_DEFAULT;
private boolean autoScaling = true;
Expand Down Expand Up @@ -117,6 +118,30 @@ public JobConfig setName(@Nullable String name) {
return this;
}

/**
* Returns description of the job or {@code null} if no description was given.
*/
@Nullable
public String getDescription() {
return description;
}

/**
* Sets description of the job.
* <p>
* The default value is {@code null}. Must be set to {@code null} for
* {@linkplain JetService#newLightJob(Pipeline) light jobs}.
*
* @return {@code this} instance for fluent API
* @since 5.2
*/
@Nonnull
public JobConfig setDescription(@Nullable String description) {
throwIfLocked();
this.description = description;
return this;
}

/**
* Tells whether {@link #setSplitBrainProtection(boolean) split brain
* protection} is enabled.
Expand Down Expand Up @@ -1398,6 +1423,7 @@ public int getClassId() {
@Override
public void writeData(ObjectDataOutput out) throws IOException {
out.writeString(name);
out.writeString(description);
out.writeObject(processingGuarantee);
out.writeLong(snapshotIntervalMillis);
out.writeBoolean(autoScaling);
Expand All @@ -1418,6 +1444,7 @@ public void writeData(ObjectDataOutput out) throws IOException {
@Override
public void readData(ObjectDataInput in) throws IOException {
name = in.readString();
description = in.readString();
processingGuarantee = in.readObject();
snapshotIntervalMillis = in.readLong();
autoScaling = in.readBoolean();
Expand Down Expand Up @@ -1451,6 +1478,7 @@ public boolean equals(Object o) {
&& enableMetrics == jobConfig.enableMetrics
&& storeMetricsAfterJobCompletion == jobConfig.storeMetricsAfterJobCompletion
&& Objects.equals(name, jobConfig.name)
&& Objects.equals(description, jobConfig.description)
&& processingGuarantee == jobConfig.processingGuarantee
&& Objects.equals(resourceConfigs, jobConfig.resourceConfigs)
&& Objects.equals(customClassPaths, jobConfig.customClassPaths)
Expand All @@ -1464,18 +1492,18 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(name, processingGuarantee, snapshotIntervalMillis, autoScaling, suspendOnFailure,
return Objects.hash(name, description, processingGuarantee, snapshotIntervalMillis, autoScaling, suspendOnFailure,
splitBrainProtectionEnabled, enableMetrics, storeMetricsAfterJobCompletion, resourceConfigs,
customClassPaths, serializerConfigs, arguments, classLoaderFactory, initialSnapshotName,
maxProcessorAccumulatedRecords, timeoutMillis);
}

@Override
public String toString() {
return "JobConfig {name=" + name + ", processingGuarantee=" + processingGuarantee + ", snapshotIntervalMillis="
+ snapshotIntervalMillis + ", autoScaling=" + autoScaling + ", suspendOnFailure=" + suspendOnFailure +
", splitBrainProtectionEnabled=" + splitBrainProtectionEnabled + ", enableMetrics=" + enableMetrics +
", storeMetricsAfterJobCompletion=" + storeMetricsAfterJobCompletion +
return "JobConfig {name=" + name + ", description=" + description + ", processingGuarantee=" + processingGuarantee +
", snapshotIntervalMillis=" + snapshotIntervalMillis + ", autoScaling=" + autoScaling + ", suspendOnFailure=" +
suspendOnFailure + ", splitBrainProtectionEnabled=" + splitBrainProtectionEnabled + ", enableMetrics=" +
enableMetrics + ", storeMetricsAfterJobCompletion=" + storeMetricsAfterJobCompletion +
", resourceConfigs=" + resourceConfigs + ", serializerConfigs=" + serializerConfigs +
", arguments=" + arguments + ", classLoaderFactory=" + classLoaderFactory +
", initialSnapshotName=" + initialSnapshotName + ", maxProcessorAccumulatedRecords=" +
Expand Down
Expand Up @@ -147,6 +147,8 @@ private Job newJobInt(long jobId, @Nonnull Object jobDefinition, @Nonnull JobCon
protected static void validateConfigForLightJobs(JobConfig config) {
Preconditions.checkTrue(config.getName() == null,
"JobConfig.name not supported for light jobs");
Preconditions.checkTrue(config.getDescription() == null,
"JobConfig.description not supported for light jobs");
Preconditions.checkTrue(config.getResourceConfigs().isEmpty(),
"Resources (jars, classes, attached files) not supported for light jobs");
Preconditions.checkTrue(config.getProcessingGuarantee() == ProcessingGuarantee.NONE,
Expand Down
Expand Up @@ -67,6 +67,17 @@ public void when_setName_thenReturnsName() {
assertEquals(name, config.getName());
}

@Test
public void when_setDescription_thenReturnsDescription() {
// When
JobConfig config = new JobConfig();
String description = "some description";
config.setDescription(description);

// Then
assertEquals(description, config.getDescription());
}

@Test
public void when_enableSplitBrainProtection_thenReturnsEnabled() {
// When
Expand Down Expand Up @@ -190,6 +201,12 @@ public void test_jobConfigForLightJob() {
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("not supported for light jobs");

JobConfig configWithDescription = new JobConfig();
configWithDescription.setDescription("some description");
assertThatThrownBy(() -> inst.getJet().newLightJob(dag, configWithDescription))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("JobConfig.description not supported for light jobs");

JobConfig configWithResource = new JobConfig();
configWithResource.addClass(JobConfigTest.class);
assertThatThrownBy(() -> inst.getJet().newLightJob(dag, configWithResource))
Expand Down Expand Up @@ -246,6 +263,7 @@ public void when_mutatingLockedJobConfig_then_fail() {

List<Supplier> mutatingMethods = Arrays.asList(
() -> jobConfig.setName(""),
() -> jobConfig.setDescription(""),
() -> jobConfig.setSplitBrainProtection(false),
() -> jobConfig.setAutoScaling(false),
() -> jobConfig.setSuspendOnFailure(false),
Expand Down