Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.walmartlabs.concord.runtime.v2.model;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2024 Walmart Inc.
* -----
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =====
*/

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.immutables.value.Value;

import java.io.Serial;

@Value.Immutable
@Value.Style(jdkOnly = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonSerialize(as = ImmutableDefaultExclusiveMode.class)
@JsonDeserialize(as = ImmutableDefaultExclusiveMode.class)
public interface DefaultExclusiveMode extends ExclusiveMode {

@Serial
long serialVersionUID = 1L;

static ExclusiveMode of(String group, Mode mode) {
return ImmutableDefaultExclusiveMode.of(group, mode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,13 @@
* =====
*/

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.immutables.value.Value;

import java.io.Serializable;

@Value.Immutable
@Value.Style(jdkOnly = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonSerialize(as = ImmutableExclusiveMode.class)
@JsonDeserialize(as = ImmutableExclusiveMode.class)
public interface ExclusiveMode extends Serializable {

long serialVersionUID = 1L;

@Value.Parameter
@JsonProperty(value = "group", required = true)
String group();
Expand Down Expand Up @@ -64,7 +54,4 @@ enum Mode {
wait
}

static ExclusiveMode of(String group, Mode mode) {
return ImmutableExclusiveMode.of(group, mode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
import org.immutables.value.Value;

import javax.annotation.Nullable;
import java.io.Serial;
import java.io.Serializable;

@Value.Immutable
@Value.Style(jdkOnly = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonSerialize(as = ImmutableGithubTriggerExclusiveMode.class)
@JsonDeserialize(as = ImmutableGithubTriggerExclusiveMode.class)
public interface GithubTriggerExclusiveMode extends Serializable {
public interface GithubTriggerExclusiveMode extends ExclusiveMode, Serializable {

@Serial
long serialVersionUID = 1L;

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public final class ConfigurationGrammar {

private static final Parser<Atom, ExclusiveMode> exclusive =
betweenTokens(JsonToken.START_OBJECT, JsonToken.END_OBJECT,
with(ImmutableExclusiveMode::builder,
with(ImmutableDefaultExclusiveMode::builder,
o -> options(
mandatory("group", stringNotEmptyVal.map(o::group)),
optional("mode", enumVal(ExclusiveMode.Mode.class).map(o::mode))))
.map(ImmutableExclusiveMode.Builder::build));
.map(ImmutableDefaultExclusiveMode.Builder::build));

public static final Parser<Atom, ExclusiveMode> exclusiveVal =
orError(exclusive, YamlValueType.EXCLUSIVE_MODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject;
import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaString;
import com.walmartlabs.concord.runtime.v2.model.ExclusiveMode;
import com.walmartlabs.concord.runtime.v2.model.GithubTriggerExclusiveMode;
import com.walmartlabs.concord.runtime.v2.model.Trigger;

import java.util.List;
Expand Down Expand Up @@ -111,7 +112,7 @@ interface GithubTriggerParams extends DefaultTriggerParams {
GithubTriggerConditions conditions();

@JsonProperty("exclusive")
ExclusiveMode exclusive();
GithubTriggerExclusiveMode exclusive();

interface GithubTriggerConditions {
@JsonProperty(value = "type", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public void test008() throws Exception {
assertEquals(Collections.singletonMap("k", "v"), cfg.arguments());
assertEquals(Collections.singletonMap("k", "v1"), cfg.requirements());
assertEquals(Duration.parse("PT1H"), cfg.processTimeout());
assertEquals(ExclusiveMode.of("X", ExclusiveMode.Mode.cancel), cfg.exclusive());
assertEquals(DefaultExclusiveMode.of("X", ExclusiveMode.Mode.cancel), cfg.exclusive());
assertEquals(EventConfiguration.builder()
.recordTaskInVars(true)
.inVarsBlacklist(Collections.singletonList("pass"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.walmartlabs.concord.common.DateTimeUtils;
import com.walmartlabs.concord.repository.Snapshot;
import com.walmartlabs.concord.runtime.v2.model.DefaultExclusiveMode;
import com.walmartlabs.concord.runtime.v2.model.ExclusiveMode;
import com.walmartlabs.concord.sdk.Constants;
import com.walmartlabs.concord.sdk.MapUtils;
Expand All @@ -44,7 +45,7 @@ public static ExclusiveMode getExclusive(Payload p) {
throw new ProcessException(p.getProcessKey(), "Invalid exclusive mode: exclusive group not specified or empty");
}
ExclusiveMode.Mode mode = MapUtils.getEnum(exclusive, "mode", ExclusiveMode.Mode.class, ExclusiveMode.Mode.cancel);
return ExclusiveMode.of(group, mode);
return DefaultExclusiveMode.of(group, mode);
}

@SuppressWarnings("unchecked")
Expand All @@ -65,10 +66,10 @@ public static OffsetDateTime getStartAt(Payload p) {
return null;
}

if (v instanceof String) {
if (v instanceof String iso) {
OffsetDateTime t;
try {
t = DateTimeUtils.fromIsoString((String) v);
t = DateTimeUtils.fromIsoString(iso);
} catch (DateTimeParseException e) {
throw new ProcessException(p.getProcessKey(), "Invalid '" + k + "' format, expected an ISO-8601 value, got: " + v);
}
Expand Down
Loading