Skip to content

Commit f2400a0

Browse files
committed
Split schema-loader errors and data-loader errors from CoreError
1 parent f3969d9 commit f2400a0

File tree

45 files changed

+653
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+653
-540
lines changed

core/src/main/java/com/scalar/db/common/error/CoreError.java

Lines changed: 18 additions & 329 deletions
Large diffs are not rendered by default.

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommand.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import com.scalar.db.api.DistributedStorage;
88
import com.scalar.db.api.TableMetadata;
9-
import com.scalar.db.common.error.CoreError;
109
import com.scalar.db.dataloader.cli.exception.DirectoryValidationException;
1110
import com.scalar.db.dataloader.cli.util.DirectoryUtils;
1211
import com.scalar.db.dataloader.cli.util.FileUtils;
1312
import com.scalar.db.dataloader.cli.util.InvalidFilePathException;
1413
import com.scalar.db.dataloader.core.ColumnKeyValue;
14+
import com.scalar.db.dataloader.core.DataLoaderError;
1515
import com.scalar.db.dataloader.core.FileFormat;
1616
import com.scalar.db.dataloader.core.ScanRange;
1717
import com.scalar.db.dataloader.core.dataexport.CsvExportManager;
@@ -57,9 +57,8 @@ public Integer call() throws Exception {
5757
validateOutputDirectory();
5858
FileUtils.validateFilePath(scalarDbPropertiesFilePath);
5959
validatePositiveValue(
60-
spec.commandLine(), dataChunkSize, CoreError.DATA_LOADER_INVALID_DATA_CHUNK_SIZE);
61-
validatePositiveValue(
62-
spec.commandLine(), maxThreads, CoreError.DATA_LOADER_INVALID_MAX_THREADS);
60+
spec.commandLine(), dataChunkSize, DataLoaderError.INVALID_DATA_CHUNK_SIZE);
61+
validatePositiveValue(spec.commandLine(), maxThreads, DataLoaderError.INVALID_MAX_THREADS);
6362

6463
StorageFactory storageFactory = StorageFactory.create(scalarDbPropertiesFilePath);
6564
TableMetadataService metaDataService =
@@ -110,8 +109,7 @@ public Integer call() throws Exception {
110109

111110
private String getScalarDbPropertiesFilePath() {
112111
if (StringUtils.isBlank(configFilePath)) {
113-
throw new IllegalArgumentException(
114-
CoreError.DATA_LOADER_CONFIG_FILE_PATH_BLANK.buildMessage());
112+
throw new IllegalArgumentException(DataLoaderError.CONFIG_FILE_PATH_BLANK.buildMessage());
115113
}
116114
return Objects.equals(configFilePath, DEFAULT_CONFIG_FILE_NAME)
117115
? Paths.get("").toAbsolutePath().resolve(DEFAULT_CONFIG_FILE_NAME).toString()

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/MultiColumnKeyValueConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.scalar.db.dataloader.cli.command.dataexport;
22

3-
import com.scalar.db.common.error.CoreError;
43
import com.scalar.db.dataloader.cli.util.CommandLineInputUtils;
54
import com.scalar.db.dataloader.core.ColumnKeyValue;
5+
import com.scalar.db.dataloader.core.DataLoaderError;
66
import java.util.Arrays;
77
import java.util.List;
88
import java.util.stream.Collectors;
@@ -37,7 +37,7 @@ public class MultiColumnKeyValueConverter
3737
public List<ColumnKeyValue> convert(String keyValue) {
3838
if (keyValue == null || keyValue.trim().isEmpty()) {
3939
throw new IllegalArgumentException(
40-
CoreError.DATA_LOADER_NULL_OR_EMPTY_KEY_VALUE_INPUT.buildMessage());
40+
DataLoaderError.NULL_OR_EMPTY_KEY_VALUE_INPUT.buildMessage());
4141
}
4242
return Arrays.stream(CommandLineInputUtils.splitByDelimiter(keyValue, ",", 0))
4343
.map(CommandLineInputUtils::parseKeyValue)

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommand.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.scalar.db.api.DistributedStorageAdmin;
77
import com.scalar.db.api.TableMetadata;
8-
import com.scalar.db.common.error.CoreError;
8+
import com.scalar.db.dataloader.core.DataLoaderError;
99
import com.scalar.db.dataloader.core.FileFormat;
1010
import com.scalar.db.dataloader.core.ScalarDbMode;
1111
import com.scalar.db.dataloader.core.dataimport.ImportManager;
@@ -55,15 +55,12 @@ public Integer call() throws Exception {
5555
validateImportTarget(controlFilePath, namespace, tableName);
5656
validateLogDirectory(logDirectory);
5757
validatePositiveValue(
58-
spec.commandLine(), dataChunkSize, CoreError.DATA_LOADER_INVALID_DATA_CHUNK_SIZE);
58+
spec.commandLine(), dataChunkSize, DataLoaderError.INVALID_DATA_CHUNK_SIZE);
5959
validatePositiveValue(
60-
spec.commandLine(), transactionSize, CoreError.DATA_LOADER_INVALID_TRANSACTION_SIZE);
60+
spec.commandLine(), transactionSize, DataLoaderError.INVALID_TRANSACTION_SIZE);
61+
validatePositiveValue(spec.commandLine(), maxThreads, DataLoaderError.INVALID_MAX_THREADS);
6162
validatePositiveValue(
62-
spec.commandLine(), maxThreads, CoreError.DATA_LOADER_INVALID_MAX_THREADS);
63-
validatePositiveValue(
64-
spec.commandLine(),
65-
dataChunkQueueSize,
66-
CoreError.DATA_LOADER_INVALID_DATA_CHUNK_QUEUE_SIZE);
63+
spec.commandLine(), dataChunkQueueSize, DataLoaderError.INVALID_DATA_CHUNK_QUEUE_SIZE);
6764
ControlFile controlFile = parseControlFileFromPath(controlFilePath).orElse(null);
6865
ImportOptions importOptions = createImportOptions(controlFile);
6966
ImportLoggerConfig config =
@@ -192,7 +189,7 @@ private void validateImportTarget(String controlFilePath, String namespace, Stri
192189
if (StringUtils.isBlank(controlFilePath)
193190
&& (StringUtils.isBlank(namespace) || StringUtils.isBlank(tableName))) {
194191
throw new ParameterException(
195-
spec.commandLine(), CoreError.DATA_LOADER_IMPORT_TARGET_MISSING.buildMessage());
192+
spec.commandLine(), DataLoaderError.IMPORT_TARGET_MISSING.buildMessage());
196193
}
197194

198195
// Make sure the control file exists when a path is provided
@@ -201,7 +198,7 @@ private void validateImportTarget(String controlFilePath, String namespace, Stri
201198
if (!Files.exists(path)) {
202199
throw new ParameterException(
203200
spec.commandLine(),
204-
CoreError.DATA_LOADER_MISSING_IMPORT_FILE.buildMessage(
201+
DataLoaderError.MISSING_IMPORT_FILE.buildMessage(
205202
controlFilePath, FILE_OPTION_NAME_LONG_FORMAT));
206203
}
207204
}
@@ -224,7 +221,7 @@ private void validateLogDirectory(String logDirectory) throws ParameterException
224221
if (!Files.isWritable(logDirectoryPath)) {
225222
throw new ParameterException(
226223
spec.commandLine(),
227-
CoreError.DATA_LOADER_LOG_DIRECTORY_CREATION_FAILED.buildMessage(
224+
DataLoaderError.LOG_DIRECTORY_CREATION_FAILED.buildMessage(
228225
logDirectoryPath.toAbsolutePath()));
229226
}
230227
} else {
@@ -234,7 +231,7 @@ private void validateLogDirectory(String logDirectory) throws ParameterException
234231
} catch (IOException e) {
235232
throw new ParameterException(
236233
spec.commandLine(),
237-
CoreError.DATA_LOADER_LOG_DIRECTORY_CREATION_FAILED.buildMessage(
234+
DataLoaderError.LOG_DIRECTORY_CREATION_FAILED.buildMessage(
238235
logDirectoryPath.toAbsolutePath()));
239236
}
240237
}
@@ -248,7 +245,7 @@ private void validateLogDirectory(String logDirectory) throws ParameterException
248245
if (!Files.isWritable(logDirectoryPath)) {
249246
throw new ParameterException(
250247
spec.commandLine(),
251-
CoreError.DATA_LOADER_LOG_DIRECTORY_WRITE_ACCESS_DENIED.buildMessage(
248+
DataLoaderError.LOG_DIRECTORY_WRITE_ACCESS_DENIED.buildMessage(
252249
logDirectoryPath.toAbsolutePath()));
253250
}
254251
}
@@ -271,8 +268,7 @@ private Optional<ControlFile> parseControlFileFromPath(String controlFilePath) {
271268
return Optional.of(controlFile);
272269
} catch (IOException e) {
273270
throw new ParameterException(
274-
spec.commandLine(),
275-
CoreError.DATA_LOADER_INVALID_CONTROL_FILE.buildMessage(controlFilePath));
271+
spec.commandLine(), DataLoaderError.INVALID_CONTROL_FILE.buildMessage(controlFilePath));
276272
}
277273
}
278274

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/util/CommandLineInputUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.scalar.db.dataloader.cli.util;
22

3-
import com.scalar.db.common.error.CoreError;
3+
import com.scalar.db.dataloader.core.DataLoaderError;
44
import java.util.AbstractMap;
55
import java.util.Map;
66
import java.util.Objects;
@@ -19,14 +19,14 @@ public class CommandLineInputUtils {
1919
public static Map.Entry<String, String> parseKeyValue(String keyValue) {
2020
if (StringUtils.isBlank(keyValue)) {
2121
throw new IllegalArgumentException(
22-
CoreError.DATA_LOADER_NULL_OR_EMPTY_KEY_VALUE_INPUT.buildMessage());
22+
DataLoaderError.NULL_OR_EMPTY_KEY_VALUE_INPUT.buildMessage());
2323
}
2424

2525
String[] parts = splitByDelimiter(keyValue, "=", 2);
2626

2727
if (parts.length != 2 || parts[0].trim().isEmpty() || parts[1].trim().isEmpty()) {
2828
throw new IllegalArgumentException(
29-
CoreError.DATA_LOADER_INVALID_KEY_VALUE_INPUT.buildMessage(keyValue));
29+
DataLoaderError.INVALID_KEY_VALUE_INPUT.buildMessage(keyValue));
3030
}
3131
return new AbstractMap.SimpleEntry<>(parts[0].trim(), parts[1].trim());
3232
}
@@ -42,9 +42,8 @@ public static Map.Entry<String, String> parseKeyValue(String keyValue) {
4242
* @throws NullPointerException if value or delimiter is null
4343
*/
4444
public static String[] splitByDelimiter(String value, String delimiter, int limit) {
45-
Objects.requireNonNull(value, CoreError.DATA_LOADER_SPLIT_INPUT_VALUE_NULL.buildMessage());
46-
Objects.requireNonNull(
47-
delimiter, CoreError.DATA_LOADER_SPLIT_INPUT_DELIMITER_NULL.buildMessage());
45+
Objects.requireNonNull(value, DataLoaderError.SPLIT_INPUT_VALUE_NULL.buildMessage());
46+
Objects.requireNonNull(delimiter, DataLoaderError.SPLIT_INPUT_DELIMITER_NULL.buildMessage());
4847
return value.split(delimiter, limit);
4948
}
5049

@@ -56,7 +55,8 @@ public static String[] splitByDelimiter(String value, String delimiter, int limi
5655
* @param value the integer value to validate
5756
* @param error the error that is thrown when the value is invalid
5857
*/
59-
public static void validatePositiveValue(CommandLine commandLine, int value, CoreError error) {
58+
public static void validatePositiveValue(
59+
CommandLine commandLine, int value, DataLoaderError error) {
6060
if (value < 1) {
6161
throw new CommandLine.ParameterException(commandLine, error.buildMessage());
6262
}

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/util/DirectoryUtils.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.scalar.db.dataloader.cli.util;
22

3-
import com.scalar.db.common.error.CoreError;
43
import com.scalar.db.dataloader.cli.exception.DirectoryValidationException;
4+
import com.scalar.db.dataloader.core.DataLoaderError;
55
import java.io.IOException;
66
import java.nio.file.Files;
77
import java.nio.file.Path;
@@ -26,7 +26,7 @@ public static void validateWorkingDirectory() throws DirectoryValidationExceptio
2626
// Check if the current working directory is writable
2727
if (!Files.isWritable(workingDirectoryPath)) {
2828
throw new DirectoryValidationException(
29-
CoreError.DATA_LOADER_DIRECTORY_WRITE_ACCESS.buildMessage(
29+
DataLoaderError.DIRECTORY_WRITE_ACCESS.buildMessage(
3030
workingDirectoryPath.toAbsolutePath()));
3131
}
3232
}
@@ -42,20 +42,19 @@ public static void validateOrCreateTargetDirectory(String directoryPath)
4242
throws DirectoryValidationException {
4343
if (StringUtils.isBlank(directoryPath)) {
4444
throw new IllegalArgumentException(
45-
CoreError.DATA_LOADER_MISSING_DIRECTORY_NOT_ALLOWED.buildMessage());
45+
DataLoaderError.MISSING_DIRECTORY_NOT_ALLOWED.buildMessage());
4646
}
4747

4848
Path path = Paths.get(directoryPath);
4949

5050
if (Files.exists(path)) {
5151
if (!Files.isDirectory(path)) {
5252
throw new DirectoryValidationException(
53-
CoreError.DATA_LOADER_PATH_IS_NOT_A_DIRECTORY.buildMessage(path));
53+
DataLoaderError.PATH_IS_NOT_A_DIRECTORY.buildMessage(path));
5454
}
5555
if (!Files.isWritable(path)) {
5656
throw new DirectoryValidationException(
57-
CoreError.DATA_LOADER_DIRECTORY_WRITE_ACCESS_NOT_ALLOWED.buildMessage(
58-
path.toAbsolutePath()));
57+
DataLoaderError.DIRECTORY_WRITE_ACCESS_NOT_ALLOWED.buildMessage(path.toAbsolutePath()));
5958
}
6059

6160
} else {
@@ -64,7 +63,7 @@ public static void validateOrCreateTargetDirectory(String directoryPath)
6463
Files.createDirectories(path);
6564
} catch (IOException e) {
6665
throw new DirectoryValidationException(
67-
CoreError.DATA_LOADER_DIRECTORY_CREATE_FAILED.buildMessage(
66+
DataLoaderError.DIRECTORY_CREATE_FAILED.buildMessage(
6867
path.toAbsolutePath(), e.getMessage()));
6968
}
7069
}

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/util/FileUtils.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.scalar.db.dataloader.cli.util;
22

3-
import com.scalar.db.common.error.CoreError;
3+
import com.scalar.db.dataloader.core.DataLoaderError;
44
import java.nio.file.Path;
55
import java.nio.file.Paths;
66
import org.apache.commons.lang3.StringUtils;
@@ -15,13 +15,12 @@ public class FileUtils {
1515
*/
1616
public static void validateFilePath(String filePath) throws InvalidFilePathException {
1717
if (StringUtils.isBlank(filePath)) {
18-
throw new IllegalArgumentException(CoreError.DATA_LOADER_FILE_PATH_IS_BLANK.buildMessage());
18+
throw new IllegalArgumentException(DataLoaderError.FILE_PATH_IS_BLANK.buildMessage());
1919
}
2020
Path pathToCheck = Paths.get(filePath);
2121

2222
if (!pathToCheck.toFile().exists()) {
23-
throw new InvalidFilePathException(
24-
CoreError.DATA_LOADER_FILE_NOT_FOUND.buildMessage(pathToCheck));
23+
throw new InvalidFilePathException(DataLoaderError.FILE_NOT_FOUND.buildMessage(pathToCheck));
2524
}
2625
}
2726
}

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static org.junit.jupiter.api.Assertions.assertThrows;
44

5-
import com.scalar.db.common.error.CoreError;
5+
import com.scalar.db.dataloader.core.DataLoaderError;
66
import com.scalar.db.dataloader.core.FileFormat;
77
import java.io.File;
88
import java.nio.file.Paths;
@@ -39,7 +39,7 @@ void call_withBlankScalarDBConfigurationFile_shouldThrowException() {
3939
exportCommand::call,
4040
"Expected to throw FileNotFound exception as configuration path is invalid");
4141
Assertions.assertEquals(
42-
CoreError.DATA_LOADER_CONFIG_FILE_PATH_BLANK.buildMessage(), thrown.getMessage());
42+
DataLoaderError.CONFIG_FILE_PATH_BLANK.buildMessage(), thrown.getMessage());
4343
}
4444

4545
@Test

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/MultiColumnKeyValueConverterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import static org.junit.jupiter.api.Assertions.assertThrows;
44

5-
import com.scalar.db.common.error.CoreError;
65
import com.scalar.db.dataloader.core.ColumnKeyValue;
6+
import com.scalar.db.dataloader.core.DataLoaderError;
77
import java.util.Collections;
88
import org.junit.jupiter.api.Assertions;
99
import org.junit.jupiter.api.Test;
@@ -21,7 +21,7 @@ void convert_withInvalidValue_ShouldThrowError() {
2121
() -> multiColumnKeyValueConverter.convert(value),
2222
"Expected to throw exception");
2323
Assertions.assertEquals(
24-
CoreError.DATA_LOADER_INVALID_KEY_VALUE_INPUT.buildMessage("id 15"), thrown.getMessage());
24+
DataLoaderError.INVALID_KEY_VALUE_INPUT.buildMessage("id 15"), thrown.getMessage());
2525
}
2626

2727
@Test

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/ScanOrderingConverterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertThrows;
44

55
import com.scalar.db.api.Scan;
6-
import com.scalar.db.common.error.CoreError;
6+
import com.scalar.db.dataloader.core.DataLoaderError;
77
import java.util.ArrayList;
88
import java.util.Collections;
99
import java.util.List;
@@ -22,7 +22,7 @@ void callConvert_withInvalidValue_shouldThrowException() {
2222
() -> scanOrderingConverter.convert(value),
2323
"Expected to throw exception");
2424
Assertions.assertEquals(
25-
CoreError.DATA_LOADER_INVALID_KEY_VALUE_INPUT.buildMessage(value), thrown.getMessage());
25+
DataLoaderError.INVALID_KEY_VALUE_INPUT.buildMessage(value), thrown.getMessage());
2626
}
2727

2828
@Test

0 commit comments

Comments
 (0)