-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add path checks before scheduling and before deletion (#149)
- Loading branch information
1 parent
beed776
commit 37ce2e3
Showing
20 changed files
with
446 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
beekeeper-cleanup/src/main/java/com/expediagroup/beekeeper/cleanup/aws/S3PathCleaner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
beekeeper-core/src/main/java/com/expediagroup/beekeeper/core/validation/S3PathValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (C) 2019-2022 Expedia, 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. | ||
*/ | ||
package com.expediagroup.beekeeper.core.validation; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class S3PathValidator { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(S3PathValidator.class); | ||
|
||
/** | ||
* The minimum number of "/" chars for partition location: s3://basePath/table/partition = 4 | ||
*/ | ||
public static boolean validPartitionPath(String location) { | ||
boolean valid = getNumSlashes(location) >= 4; | ||
if (!valid) { | ||
log.warn("Partition \"{}\" doesn't have the correct number of levels in the path", location); | ||
} | ||
return valid; | ||
} | ||
|
||
/** | ||
* The minimum number of "/" chars for table location: s3://basePath/table = 3 | ||
*/ | ||
public static boolean validTablePath(String location) { | ||
boolean valid = getNumSlashes(location) >= 3; | ||
if (!valid) { | ||
log.warn("Table \"{}\" doesn't have the correct number of levels in the path", location); | ||
} | ||
return valid; | ||
} | ||
|
||
private static int getNumSlashes(String location) { | ||
return StringUtils.countMatches(location, "/"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...er-core/src/test/java/com/expediagroup/beekeeper/core/validation/S3PathValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (C) 2019-2022 Expedia, 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. | ||
*/ | ||
package com.expediagroup.beekeeper.core.validation; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class S3PathValidatorTest { | ||
|
||
@Test | ||
void validTablePath() { | ||
assertThat(S3PathValidator.validTablePath("s3://bucket/table")).isTrue(); | ||
assertThat(S3PathValidator.validTablePath("s3://bucket/table/1")).isTrue(); | ||
} | ||
|
||
@Test | ||
void invalidTablePath() { | ||
assertThat(S3PathValidator.validTablePath("s3://bucket")).isFalse(); | ||
} | ||
|
||
@Test | ||
void validPartitionPath() { | ||
assertThat(S3PathValidator.validPartitionPath("s3://bucket/table/partition")).isTrue(); | ||
assertThat(S3PathValidator.validPartitionPath("s3://bucket/table/partition/1")).isTrue(); | ||
} | ||
|
||
@Test | ||
void invalidPartitionPath() { | ||
assertThat(S3PathValidator.validPartitionPath("s3://bucket/table")).isFalse(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.