-
Notifications
You must be signed in to change notification settings - Fork 330
Add policy content and validator for more maintenance policies #1261
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * 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.polaris.core.policy.content.maintenance; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Strings; | ||
| import java.util.Set; | ||
| import org.apache.polaris.core.policy.content.PolicyContentUtil; | ||
| import org.apache.polaris.core.policy.validator.InvalidPolicyException; | ||
|
|
||
| public class DataCompactionPolicyContent extends BaseMaintenancePolicyContent { | ||
| private static final String DEFAULT_POLICY_SCHEMA_VERSION = "2025-02-03"; | ||
| private static final Set<String> POLICY_SCHEMA_VERSIONS = Set.of(DEFAULT_POLICY_SCHEMA_VERSION); | ||
|
|
||
| @JsonCreator | ||
| public DataCompactionPolicyContent( | ||
| @JsonProperty(value = "enable", required = true) boolean enable) { | ||
| super(enable); | ||
| } | ||
|
|
||
| public static DataCompactionPolicyContent fromString(String content) { | ||
| if (Strings.isNullOrEmpty(content)) { | ||
| throw new InvalidPolicyException("Policy is empty"); | ||
| } | ||
|
|
||
| DataCompactionPolicyContent policy; | ||
| try { | ||
| policy = PolicyContentUtil.MAPPER.readValue(content, DataCompactionPolicyContent.class); | ||
| } catch (Exception e) { | ||
| throw new InvalidPolicyException(e); | ||
| } | ||
|
|
||
| validateVersion(content, policy, DEFAULT_POLICY_SCHEMA_VERSION, POLICY_SCHEMA_VERSIONS); | ||
|
|
||
| return policy; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * 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.polaris.core.policy.content.maintenance; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Strings; | ||
| import java.util.Set; | ||
| import org.apache.polaris.core.policy.content.PolicyContentUtil; | ||
| import org.apache.polaris.core.policy.validator.InvalidPolicyException; | ||
|
|
||
| public class MetadataCompactionPolicyContent extends BaseMaintenancePolicyContent { | ||
| private static final String DEFAULT_POLICY_SCHEMA_VERSION = "2025-02-03"; | ||
| private static final Set<String> POLICY_SCHEMA_VERSIONS = Set.of(DEFAULT_POLICY_SCHEMA_VERSION); | ||
|
|
||
| @JsonCreator | ||
| public MetadataCompactionPolicyContent( | ||
| @JsonProperty(value = "enable", required = true) boolean enable) { | ||
| super(enable); | ||
| } | ||
|
|
||
| public static MetadataCompactionPolicyContent fromString(String content) { | ||
| if (Strings.isNullOrEmpty(content)) { | ||
| throw new InvalidPolicyException("Policy is empty"); | ||
| } | ||
|
|
||
| MetadataCompactionPolicyContent policy; | ||
| try { | ||
| policy = PolicyContentUtil.MAPPER.readValue(content, MetadataCompactionPolicyContent.class); | ||
| } catch (Exception e) { | ||
| throw new InvalidPolicyException(e); | ||
| } | ||
|
|
||
| validateVersion(content, policy, DEFAULT_POLICY_SCHEMA_VERSION, POLICY_SCHEMA_VERSIONS); | ||
|
|
||
| return policy; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.polaris.core.policy.content.maintenance; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Strings; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import org.apache.polaris.core.policy.content.PolicyContentUtil; | ||
| import org.apache.polaris.core.policy.validator.InvalidPolicyException; | ||
|
|
||
| public class OrphanFileRemovalPolicyContent extends BaseMaintenancePolicyContent { | ||
| private static final String DEFAULT_POLICY_SCHEMA_VERSION = "2025-02-03"; | ||
| private static final Set<String> POLICY_SCHEMA_VERSIONS = Set.of(DEFAULT_POLICY_SCHEMA_VERSION); | ||
|
|
||
| @JsonProperty(value = "max_orphan_file_age_in_days") | ||
| private int maxOrphanFileAgeInDays; | ||
|
|
||
| private List<String> locations; | ||
|
|
||
| @JsonCreator | ||
| public OrphanFileRemovalPolicyContent( | ||
| @JsonProperty(value = "enable", required = true) boolean enable) { | ||
| super(enable); | ||
| } | ||
|
|
||
| public int getMaxOrphanFileAgeInDays() { | ||
| return maxOrphanFileAgeInDays; | ||
| } | ||
|
|
||
| public void setMaxOrphanFileAgeInDays(int maxOrphanFileAgeInDays) { | ||
| this.maxOrphanFileAgeInDays = maxOrphanFileAgeInDays; | ||
| } | ||
|
|
||
| public List<String> getLocations() { | ||
| return locations; | ||
| } | ||
|
|
||
| public void setLocations(List<String> locations) { | ||
| this.locations = locations; | ||
| } | ||
|
|
||
| public static OrphanFileRemovalPolicyContent fromString(String content) { | ||
| if (Strings.isNullOrEmpty(content)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of repeating this everywhere, perhaps we can push this check up into the caller --
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd nice to keep this parsing method in each individual class, so that they can be invoked separately, not only for validation use cases, but also for a general parsing or constructor use cases. WDYT?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making sure that they can be invoked separately makes sense. Maybe a supertype could contain some of this logic then?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was trying to do that per your comment here, #1238 (comment). |
||
| throw new InvalidPolicyException("Policy is empty"); | ||
| } | ||
|
|
||
| OrphanFileRemovalPolicyContent policy; | ||
| try { | ||
| policy = PolicyContentUtil.MAPPER.readValue(content, OrphanFileRemovalPolicyContent.class); | ||
| } catch (Exception e) { | ||
| throw new InvalidPolicyException(e); | ||
| } | ||
|
|
||
| validateVersion(content, policy, DEFAULT_POLICY_SCHEMA_VERSION, POLICY_SCHEMA_VERSIONS); | ||
|
|
||
| int maxAge = policy.getMaxOrphanFileAgeInDays(); | ||
| if (maxAge < 0) { | ||
| throw new InvalidPolicyException( | ||
| "Invalid max_orphan_file_age_in_days: " | ||
| + maxAge | ||
| + ". It must be greater than or equal to 0"); | ||
| } | ||
|
|
||
| return policy; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * 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.polaris.core.policy.content.maintenance; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Strings; | ||
| import java.util.Set; | ||
| import org.apache.polaris.core.policy.content.PolicyContentUtil; | ||
| import org.apache.polaris.core.policy.validator.InvalidPolicyException; | ||
|
|
||
| public class SnapshotRetentionPolicyContent extends BaseMaintenancePolicyContent { | ||
| private static final String DEFAULT_POLICY_SCHEMA_VERSION = "2025-02-03"; | ||
| private static final Set<String> POLICY_SCHEMA_VERSIONS = Set.of(DEFAULT_POLICY_SCHEMA_VERSION); | ||
|
|
||
| @JsonCreator | ||
| public SnapshotRetentionPolicyContent( | ||
| @JsonProperty(value = "enable", required = true) boolean enable) { | ||
| super(enable); | ||
| } | ||
|
|
||
| public static SnapshotRetentionPolicyContent fromString(String content) { | ||
| if (Strings.isNullOrEmpty(content)) { | ||
| throw new InvalidPolicyException("Policy is empty"); | ||
| } | ||
|
|
||
| SnapshotRetentionPolicyContent policy; | ||
| try { | ||
| policy = PolicyContentUtil.MAPPER.readValue(content, SnapshotRetentionPolicyContent.class); | ||
| } catch (Exception e) { | ||
| throw new InvalidPolicyException(e); | ||
| } | ||
|
|
||
| validateVersion(content, policy, DEFAULT_POLICY_SCHEMA_VERSION, POLICY_SCHEMA_VERSIONS); | ||
|
|
||
| return policy; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.