lasdf1234 commented on code in PR #13801: URL: https://github.com/apache/gravitino/pull/13801#discussion_r4280951395
########## api/src/main/java/org/apache/gravitino/policy/AbstractExecutablePolicyContent.java: ########## @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.gravitino.policy; + +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import java.util.Objects; +import javax.annotation.Nullable; + +/** + * Base for built-in Iceberg maintenance policy contents that carry optional execution peers. + * + * <p>Peers are supplied at construction as an immutable {@link PolicyExecutionSpec}. Subclasses + * keep strategy fields separate and pass the spec through {@link + * #AbstractExecutablePolicyContent(PolicyExecutionSpec)}. Persisted JSON keeps peer keys flat via + * {@link JsonUnwrapped}. + */ +public abstract class AbstractExecutablePolicyContent implements ExecutablePolicyContent { + + @JsonUnwrapped private final PolicyExecutionSpec executionSpec; Review Comment: Thanks — addressed. - Removed `@JsonUnwrapped` and Jackson usage from `api` (`PolicyExecutionSpec` is Jackson-independent again). - Flat peer fields live on `AbstractExecutablePolicyContent` for the existing POConverters content JSON layout (same flat keys as the DTOs); `executionSpec()` reconstructs the in-memory spec. - Dropped the `jackson.annotations` dependency from the `api` module. ########## common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java: ########## @@ -85,10 +134,10 @@ public Map<String, String> properties() { /** Represents a typed iceberg compaction policy content DTO. */ @EqualsAndHashCode - @ToString + @ToString(exclude = {"jobOptions", "updateOptions"}) Review Comment: Good catch — fixed. - `IcebergDataCompactionContent.toString()` now prints `rewriteOptionsKeys=...` only (no values), consistent with `jobOptions` / `updateOptions`. - DTO `@ToString` excludes `rewriteOptions` as well (same as the other option bags). Sensitive-key rejection on create/alter remains the planned follow-up. ########## api/src/main/java/org/apache/gravitino/policy/PolicyExecutionSpec.java: ########## @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.gravitino.policy; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; + +/** + * Immutable execution peer fields for executable policy contents: triggers, cooldown, and option + * bags. + * + * <p>JSON property names remain the flat peer keys on policy content ({@code timeTrigger}, {@code + * commitTrigger}, {@code minIntervalMs}, {@code jobOptions}, {@code updateOptions}). This type is + * the in-memory composition for {@link ExecutablePolicyContent}; persistence uses + * {@code @JsonUnwrapped} so those keys stay flat in stored policy content JSON. + */ +public final class PolicyExecutionSpec { + + /** Spec with every peer unset. */ + public static final PolicyExecutionSpec EMPTY = + new PolicyExecutionSpec(null, null, null, null, null); + + @Nullable private final String timeTrigger; + @Nullable private final Boolean commitTrigger; + @Nullable private final Long minIntervalMs; + private final Map<String, String> jobOptions; + private final Map<String, String> updateOptions; + + private PolicyExecutionSpec( + @Nullable String timeTrigger, + @Nullable Boolean commitTrigger, + @Nullable Long minIntervalMs, + @Nullable Map<String, String> jobOptions, + @Nullable Map<String, String> updateOptions) { + this.timeTrigger = StringUtils.isBlank(timeTrigger) ? null : timeTrigger; + this.commitTrigger = commitTrigger; + this.minIntervalMs = minIntervalMs; + this.jobOptions = PolicyExecutionFields.copyOptions(jobOptions); + this.updateOptions = PolicyExecutionFields.copyOptions(updateOptions); + } + + /** + * Creates an immutable execution spec. + * + * <p>Annotated for Jackson so {@code POConverters} can rebuild executable policy content from + * stored JSON (including {@code @JsonUnwrapped} peers on {@link + * AbstractExecutablePolicyContent}). + * + * @param timeTrigger optional cron expression + * @param commitTrigger optional commit-trigger flag + * @param minIntervalMs optional cooldown ms + * @param jobOptions optional job options + * @param updateOptions optional update options + * @return immutable spec + */ + @JsonCreator + public static PolicyExecutionSpec of( + @JsonProperty("timeTrigger") @Nullable String timeTrigger, + @JsonProperty("commitTrigger") @Nullable Boolean commitTrigger, + @JsonProperty("minIntervalMs") @Nullable Long minIntervalMs, + @JsonProperty("jobOptions") @Nullable Map<String, String> jobOptions, + @JsonProperty("updateOptions") @Nullable Map<String, String> updateOptions) { + if (!PolicyExecutionFields.hasAny( Review Comment: Agreed — fixed by treating every non-null `Boolean` as an explicit value (including `false`). - `PolicyExecutionFields.hasAny` / `PolicyExecutionSpec.of` now retain lone `false` instead of collapsing to `EMPTY`/`null`. - Clarified DTO Javadoc: `null` = unset, `false` = explicitly disabled, `true` = enabled. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
