Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
*/
package org.apache.polaris.core.persistence;

import com.google.errorprone.annotations.FormatMethod;
import org.apache.polaris.core.exceptions.PolarisException;
import org.apache.polaris.core.policy.PolarisPolicyMappingRecord;

/**
* Exception raised when an existing policy mapping preveents the attempted creation of a new policy
* mapping record.
*/
public class PolicyMappingAlreadyExistsException extends RuntimeException {
public class PolicyMappingAlreadyExistsException extends PolarisException {
private PolarisPolicyMappingRecord existingRecord;

/**
Expand All @@ -35,6 +37,11 @@ public PolicyMappingAlreadyExistsException(PolarisPolicyMappingRecord existingRe
this.existingRecord = existingRecord;
}

@FormatMethod
public PolicyMappingAlreadyExistsException(String message, Object... arg) {
super(String.format(message, arg));
}

public PolarisPolicyMappingRecord getExistingRecord() {
return this.existingRecord;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.exceptions;

import com.google.errorprone.annotations.FormatMethod;
import org.apache.polaris.core.exceptions.PolarisException;

public class PolicyAttachException extends PolarisException {
@FormatMethod
public PolicyAttachException(String message, Object... args) {
super(String.format(message, args));
}

@FormatMethod
public PolicyAttachException(Throwable cause, String message, Object... args) {
super(String.format(message, args), cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.polaris.core.policy.content.maintenance.MetadataCompactionPolicyContent;
import org.apache.polaris.core.policy.content.maintenance.OrphanFileRemovalPolicyContent;
import org.apache.polaris.core.policy.content.maintenance.SnapshotRetentionPolicyContent;
import org.apache.polaris.core.policy.exceptions.PolicyAttachException;
import org.apache.polaris.core.policy.validator.maintenance.BaseMaintenancePolicyValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -102,4 +103,12 @@ public static boolean canAttach(PolicyEntity policy, PolarisEntity targetEntity)
return false;
}
}

public static void validateAttach(PolicyEntity policy, PolarisEntity targetEntity) {
if (!canAttach(policy, targetEntity)) {
throw new PolicyAttachException(
"Cannot attach policy '%s' to target entity '%s'",
policy.getName(), targetEntity.getName());
}
}
}
Loading