diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml index 10c8c2743..b8e4e686d 100644 --- a/.github/workflows/lint-check.yml +++ b/.github/workflows/lint-check.yml @@ -24,3 +24,22 @@ jobs: - name: Run lint check run: | (cd ui && yarn install && yarn test:format) + + java-fmt: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Run Java format check + run: | + build/sbt javafmtCheck \ No newline at end of file diff --git a/server/src/main/java/io/unitycatalog/server/URLTranscoderVerticle.java b/server/src/main/java/io/unitycatalog/server/URLTranscoderVerticle.java index bcb727d70..aac2c6d4e 100644 --- a/server/src/main/java/io/unitycatalog/server/URLTranscoderVerticle.java +++ b/server/src/main/java/io/unitycatalog/server/URLTranscoderVerticle.java @@ -62,9 +62,9 @@ public void start() { transcodePort, ar -> { if (ar.succeeded()) { - LOGGER.info("URL transcoder started on port " + transcodePort); + LOGGER.info("URL transcoder started on port {}", transcodePort); } else { - LOGGER.info("Failed to start URL transcoder: " + ar.cause()); + LOGGER.info("Failed to start URL transcoder: {}", String.valueOf(ar.cause())); } }); } diff --git a/server/src/main/java/io/unitycatalog/server/UnityCatalogServer.java b/server/src/main/java/io/unitycatalog/server/UnityCatalogServer.java index eb40e8622..75378cbdd 100644 --- a/server/src/main/java/io/unitycatalog/server/UnityCatalogServer.java +++ b/server/src/main/java/io/unitycatalog/server/UnityCatalogServer.java @@ -22,7 +22,6 @@ import io.unitycatalog.server.exception.ErrorCode; import io.unitycatalog.server.exception.ExceptionHandlingDecorator; import io.unitycatalog.server.exception.GlobalExceptionHandler; -import io.unitycatalog.server.utils.ServerProperties; import io.unitycatalog.server.persist.MetastoreRepository; import io.unitycatalog.server.security.SecurityConfiguration; import io.unitycatalog.server.security.SecurityContext; @@ -33,6 +32,7 @@ import io.unitycatalog.server.service.iceberg.TableConfigService; import io.unitycatalog.server.utils.OptionParser; import io.unitycatalog.server.utils.RESTObjectMapper; +import io.unitycatalog.server.utils.ServerProperties; import io.unitycatalog.server.utils.VersionUtils; import io.vertx.core.Verticle; import io.vertx.core.Vertx; diff --git a/server/src/main/java/io/unitycatalog/server/persist/ModelRepository.java b/server/src/main/java/io/unitycatalog/server/persist/ModelRepository.java index 5e195e42b..13ab08a79 100644 --- a/server/src/main/java/io/unitycatalog/server/persist/ModelRepository.java +++ b/server/src/main/java/io/unitycatalog/server/persist/ModelRepository.java @@ -41,7 +41,7 @@ public RegisteredModelInfoDAO getRegisteredModelDao(Session session, UUID schema query.setParameter("schemaId", schemaId); query.setParameter("name", name); query.setMaxResults(1); - LOGGER.info("Finding registered model by schemaId: " + schemaId + " and name: " + name); + LOGGER.info("Finding registered model by schemaId: {} and name: {}", schemaId, name); return query.uniqueResult(); // Returns null if no result is found } @@ -75,8 +75,7 @@ public ModelVersionInfoDAO getModelVersionDao(Session session, UUID modelId, Lon query.setParameter("registeredModelId", modelId); query.setParameter("version", version.toString()); query.setMaxResults(1); - LOGGER.info( - "Finding model version by registeredModelId: " + modelId + " and version: " + version); + LOGGER.info("Finding model version by registeredModelId: {} and version: {}", modelId, version); return query.uniqueResult(); // Returns null if no result is found } @@ -107,7 +106,7 @@ public List getModelVersionsDao( query.setParameter("registeredModelId", registeredModelId); query.setParameter("token", Long.parseLong(token)); query.setMaxResults(maxResults); - LOGGER.info("Finding model versions by registeredModelId: " + registeredModelId); + LOGGER.info("Finding model versions by registeredModelId: {}", registeredModelId); return query.getResultList(); // Returns null if no result is found } @@ -136,7 +135,7 @@ public String getNextPageToken(List entities, Optional maxResults, Optional pageToken) { - LOGGER.info("Listing model versions in " + registeredModelFullName); + LOGGER.info("Listing model versions in {}", registeredModelFullName); if (maxResults.isPresent() && maxResults.get() < 0) { throw new BaseException( ErrorCode.INVALID_ARGUMENT, "maxResults must be greater than or equal to 0"); @@ -691,7 +688,7 @@ public ModelVersionInfo updateModelVersion( throw new BaseException(ErrorCode.INVALID_ARGUMENT, "No updated fields defined."); } - LOGGER.info("Updating Model Version: " + fullName + "/" + version); + LOGGER.info("Updating Model Version: {}/{}", fullName, version); ModelVersionInfo modelVersionInfo; String callerId = IdentityUtils.findPrincipalEmailAddress(); @@ -735,7 +732,7 @@ public ModelVersionInfo updateModelVersion( } public void deleteModelVersion(String fullName, Long version) { - LOGGER.info("Deleting model version: " + fullName + "/" + version); + LOGGER.info("Deleting model version: {}/{}", fullName, version); String[] parts = fullName.split("\\."); if (parts.length != 3) { throw new BaseException( @@ -782,7 +779,7 @@ public ModelVersionInfo finalizeModelVersion(FinalizeModelVersion finalizeModelV String fullName = finalizeModelVersion.getFullName(); Long version = finalizeModelVersion.getVersion(); - LOGGER.info("Finalize Model Version: " + fullName + "/" + version); + LOGGER.info("Finalize Model Version: {}/{}", fullName, version); ModelVersionInfo modelVersionInfo; String callerId = IdentityUtils.findPrincipalEmailAddress(); diff --git a/server/src/main/java/io/unitycatalog/server/persist/TableRepository.java b/server/src/main/java/io/unitycatalog/server/persist/TableRepository.java index 96346799e..c01cfaccf 100644 --- a/server/src/main/java/io/unitycatalog/server/persist/TableRepository.java +++ b/server/src/main/java/io/unitycatalog/server/persist/TableRepository.java @@ -38,7 +38,7 @@ public static TableRepository getInstance() { } public TableInfo getTableById(String tableId) { - LOGGER.debug("Getting table by id: " + tableId); + LOGGER.debug("Getting table by id: {}", tableId); try (Session session = SESSION_FACTORY.openSession()) { session.setDefaultReadOnly(true); Transaction tx = session.beginTransaction(); @@ -73,7 +73,7 @@ public TableInfo getTableById(String tableId) { } public TableInfo getTable(String fullName) { - LOGGER.debug("Getting table: " + fullName); + LOGGER.debug("Getting table: {}", fullName); TableInfo tableInfo = null; try (Session session = SESSION_FACTORY.openSession()) { session.setDefaultReadOnly(true); @@ -144,7 +144,7 @@ public TableInfo createTable(CreateTable createTable) { .updatedAt(createTime) .updatedBy(callerId); String fullName = getTableFullName(tableInfo); - LOGGER.debug("Creating table: " + fullName); + LOGGER.debug("Creating table: {}", fullName); Transaction tx; try (Session session = SESSION_FACTORY.openSession()) { @@ -204,7 +204,7 @@ public TableInfoDAO findBySchemaIdAndName(Session session, UUID schemaId, String Query query = session.createQuery(hql, TableInfoDAO.class); query.setParameter("schemaId", schemaId); query.setParameter("name", name); - LOGGER.debug("Finding table by schemaId: " + schemaId + " and name: " + name); + LOGGER.debug("Finding table by schemaId: {} and name: {}", schemaId, name); return query.uniqueResult(); // Returns null if no result is found } diff --git a/server/src/main/java/io/unitycatalog/server/persist/utils/FileUtils.java b/server/src/main/java/io/unitycatalog/server/persist/utils/FileUtils.java index 5b6695670..eb255d0f1 100644 --- a/server/src/main/java/io/unitycatalog/server/persist/utils/FileUtils.java +++ b/server/src/main/java/io/unitycatalog/server/persist/utils/FileUtils.java @@ -11,6 +11,7 @@ import io.unitycatalog.server.exception.BaseException; import io.unitycatalog.server.exception.ErrorCode; import io.unitycatalog.server.utils.Constants; +import io.unitycatalog.server.utils.ServerProperties; import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URI; @@ -20,8 +21,6 @@ import java.nio.file.Paths; import java.util.Comparator; import java.util.stream.Stream; - -import io.unitycatalog.server.utils.ServerProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,7 +75,7 @@ private static URI createLocalDirectory(Path dirPath) { // Create the directory try { Files.createDirectories(dirPath); - LOGGER.debug("Directory created successfully: " + dirPath); + LOGGER.debug("Directory created successfully: {}", dirPath); } catch (Exception e) { throw new BaseException(ErrorCode.INTERNAL, "Failed to create directory: " + dirPath, e); } @@ -151,7 +150,7 @@ private static URI modifyS3Directory(URI parsedUri, boolean createOrDelete) { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(0); s3Client.putObject(new PutObjectRequest(bucketName, path, emptyContentStream, metadata)); - LOGGER.debug("Directory created successfully: " + path); + LOGGER.debug("Directory created successfully: {}", path); return URI.create(String.format("s3://%s/%s", bucketName, path)); } catch (Exception e) { throw new BaseException(ErrorCode.INTERNAL, "Failed to create directory: " + path, e); diff --git a/server/src/main/java/io/unitycatalog/server/persist/utils/HibernateUtils.java b/server/src/main/java/io/unitycatalog/server/persist/utils/HibernateUtils.java index 80f574b2a..d0385cd58 100644 --- a/server/src/main/java/io/unitycatalog/server/persist/utils/HibernateUtils.java +++ b/server/src/main/java/io/unitycatalog/server/persist/utils/HibernateUtils.java @@ -1,13 +1,12 @@ package io.unitycatalog.server.persist.utils; import io.unitycatalog.server.persist.dao.*; +import io.unitycatalog.server.utils.ServerProperties; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; - -import io.unitycatalog.server.utils.ServerProperties; import lombok.Getter; import org.hibernate.SessionFactory; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; diff --git a/server/src/main/java/io/unitycatalog/server/persist/utils/UriUtils.java b/server/src/main/java/io/unitycatalog/server/persist/utils/UriUtils.java index f99e2881f..53f4a6a1f 100644 --- a/server/src/main/java/io/unitycatalog/server/persist/utils/UriUtils.java +++ b/server/src/main/java/io/unitycatalog/server/persist/utils/UriUtils.java @@ -11,6 +11,7 @@ import io.unitycatalog.server.model.AzureUserDelegationSAS; import io.unitycatalog.server.model.GcpOauthToken; import io.unitycatalog.server.model.TemporaryCredentials; +import io.unitycatalog.server.utils.ServerProperties; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -21,8 +22,6 @@ import java.util.Comparator; import java.util.Optional; import java.util.stream.Stream; - -import io.unitycatalog.server.utils.ServerProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -165,7 +164,7 @@ private static URI updateLocalDirectory(URI parsedUri, Operation op) throws IOEx // Create the directory try { Files.createDirectories(dirPath); - LOGGER.debug("Directory created successfully: " + dirPath); + LOGGER.debug("Directory created successfully: {}", dirPath); } catch (Exception e) { throw new BaseException(ErrorCode.INTERNAL, "Failed to create directory: " + dirPath, e); } diff --git a/server/src/main/java/io/unitycatalog/server/service/AuthService.java b/server/src/main/java/io/unitycatalog/server/service/AuthService.java index 0eaadbb41..76966d09f 100644 --- a/server/src/main/java/io/unitycatalog/server/service/AuthService.java +++ b/server/src/main/java/io/unitycatalog/server/service/AuthService.java @@ -16,10 +16,10 @@ import io.unitycatalog.server.exception.GlobalExceptionHandler; import io.unitycatalog.server.exception.OAuthInvalidRequestException; import io.unitycatalog.server.persist.UserRepository; -import io.unitycatalog.server.utils.ServerProperties; import io.unitycatalog.server.security.JwtClaim; import io.unitycatalog.server.security.SecurityContext; import io.unitycatalog.server.utils.JwksOperations; +import io.unitycatalog.server.utils.ServerProperties; import lombok.Builder; import lombok.Getter; import lombok.NonNull; diff --git a/server/src/main/java/io/unitycatalog/server/service/credential/aws/AwsCredentialVendor.java b/server/src/main/java/io/unitycatalog/server/service/credential/aws/AwsCredentialVendor.java index d948e5c4b..c5ff33742 100644 --- a/server/src/main/java/io/unitycatalog/server/service/credential/aws/AwsCredentialVendor.java +++ b/server/src/main/java/io/unitycatalog/server/service/credential/aws/AwsCredentialVendor.java @@ -2,8 +2,8 @@ import io.unitycatalog.server.exception.BaseException; import io.unitycatalog.server.exception.ErrorCode; -import io.unitycatalog.server.utils.ServerProperties; import io.unitycatalog.server.service.credential.CredentialContext; +import io.unitycatalog.server.utils.ServerProperties; import java.time.Duration; import java.util.Map; import java.util.UUID; diff --git a/server/src/main/java/io/unitycatalog/server/service/credential/azure/AzureCredentialVendor.java b/server/src/main/java/io/unitycatalog/server/service/credential/azure/AzureCredentialVendor.java index 3741c8d0d..bdc899c1a 100644 --- a/server/src/main/java/io/unitycatalog/server/service/credential/azure/AzureCredentialVendor.java +++ b/server/src/main/java/io/unitycatalog/server/service/credential/azure/AzureCredentialVendor.java @@ -13,8 +13,8 @@ import com.azure.storage.file.datalake.models.UserDelegationKey; import com.azure.storage.file.datalake.sas.DataLakeServiceSasSignatureValues; import com.azure.storage.file.datalake.sas.PathSasPermission; -import io.unitycatalog.server.utils.ServerProperties; import io.unitycatalog.server.service.credential.CredentialContext; +import io.unitycatalog.server.utils.ServerProperties; import java.net.URI; import java.time.OffsetDateTime; import java.util.Map; diff --git a/server/src/main/java/io/unitycatalog/server/service/credential/gcp/GcpCredentialVendor.java b/server/src/main/java/io/unitycatalog/server/service/credential/gcp/GcpCredentialVendor.java index fd9bbb4cc..fcf06e2f3 100644 --- a/server/src/main/java/io/unitycatalog/server/service/credential/gcp/GcpCredentialVendor.java +++ b/server/src/main/java/io/unitycatalog/server/service/credential/gcp/GcpCredentialVendor.java @@ -11,8 +11,8 @@ import com.google.common.base.CharMatcher; import io.unitycatalog.server.exception.BaseException; import io.unitycatalog.server.exception.ErrorCode; -import io.unitycatalog.server.utils.ServerProperties; import io.unitycatalog.server.service.credential.CredentialContext; +import io.unitycatalog.server.utils.ServerProperties; import java.io.IOException; import java.net.URI; import java.sql.Date; diff --git a/server/src/main/java/io/unitycatalog/server/utils/ServerProperties.java b/server/src/main/java/io/unitycatalog/server/utils/ServerProperties.java index 5de58554a..1c53d665f 100644 --- a/server/src/main/java/io/unitycatalog/server/utils/ServerProperties.java +++ b/server/src/main/java/io/unitycatalog/server/utils/ServerProperties.java @@ -121,14 +121,14 @@ public Map getAdlsConfigurations() { /** * Get a property value by key. - *

- * The key can be one of the following (in that order) - * before looking it up in the server properties: + * + *

The key can be one of the following (in that order) before looking it up in the server + * properties: + * *

    - *
  1. System property
  2. - *
  3. Environment variable
  4. + *
  5. System property + *
  6. Environment variable *
- *

*/ public String getProperty(String key) { if (System.getProperty(key) != null) return System.getProperty(key); @@ -138,6 +138,7 @@ public String getProperty(String key) { /** * Get a property value by key with a default value + * * @see Properties#getProperty(String key, String defaultValue) */ public String getProperty(String key, String defaultValue) { diff --git a/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java b/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java index 618b833b3..4744ba473 100644 --- a/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java @@ -80,7 +80,6 @@ public void testCatalogCRUD() throws ApiException { CatalogInfo catalogInfo4 = catalogOperations.getCatalog(CATALOG_NAME); assertThat(catalogInfo4).isEqualTo(catalogInfo); - // Update catalog name without updating comment and properties System.out.println("Testing update catalog: changing name.."); UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME); diff --git a/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java b/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java index 9f10d2ad4..828a8a711 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java @@ -25,9 +25,7 @@ public TableInfo createTable(CreateTable createTableRequest) throws ApiException public List listTables( String catalogName, String schemaName, Optional pageToken) throws ApiException { return Objects.requireNonNull( - tablesApi - .listTables(catalogName, schemaName, 100, pageToken.orElse(null)) - .getTables()); + tablesApi.listTables(catalogName, schemaName, 100, pageToken.orElse(null)).getTables()); } @Override diff --git a/server/src/test/java/io/unitycatalog/server/service/credential/CredentialOperationsTest.java b/server/src/test/java/io/unitycatalog/server/service/credential/CredentialOperationsTest.java index d6352c99f..47386427e 100644 --- a/server/src/test/java/io/unitycatalog/server/service/credential/CredentialOperationsTest.java +++ b/server/src/test/java/io/unitycatalog/server/service/credential/CredentialOperationsTest.java @@ -8,9 +8,9 @@ import io.unitycatalog.server.exception.BaseException; import io.unitycatalog.server.model.AwsCredentials; import io.unitycatalog.server.model.TemporaryCredentials; -import io.unitycatalog.server.utils.ServerProperties; import io.unitycatalog.server.service.credential.aws.S3StorageConfig; import io.unitycatalog.server.service.credential.azure.ADLSStorageConfig; +import io.unitycatalog.server.utils.ServerProperties; import java.util.Map; import java.util.Set; import java.util.concurrent.CompletionException; @@ -23,8 +23,7 @@ @ExtendWith(MockitoExtension.class) public class CredentialOperationsTest { - @Mock - ServerProperties serverProperties; + @Mock ServerProperties serverProperties; CredentialOperations credentialsOperations; @Test @@ -34,8 +33,7 @@ public void testGenerateS3TemporaryCredentials() { final String SESSION_TOKEN = "sessionToken"; final String S3_REGION = "us-west-2"; final String ROLE_ARN = "roleArn"; - try (MockedStatic mockedStatic = - mockStatic(ServerProperties.class)) { + try (MockedStatic mockedStatic = mockStatic(ServerProperties.class)) { mockedStatic.when(ServerProperties::getInstance).thenReturn(serverProperties); // Test session key is available when(serverProperties.getS3Configurations()) @@ -83,8 +81,7 @@ public void testGenerateAzureTemporaryCredentials() { final String CLIENT_ID = "clientId"; final String CLIENT_SECRET = "clientSecret"; final String TENANT_ID = "tenantId"; - try (MockedStatic mockedStatic = - mockStatic(ServerProperties.class)) { + try (MockedStatic mockedStatic = mockStatic(ServerProperties.class)) { mockedStatic.when(ServerProperties::getInstance).thenReturn(serverProperties); // Test mode used when(serverProperties.getAdlsConfigurations()) @@ -120,8 +117,7 @@ public void testGenerateAzureTemporaryCredentials() { public void testGenerateGcpTemporaryCredentials() { final String PROJECT_ID = "projectId"; final String PRIVATE_KEY_ID = "privateKeyId"; - try (MockedStatic mockedStatic = - mockStatic(ServerProperties.class)) { + try (MockedStatic mockedStatic = mockStatic(ServerProperties.class)) { mockedStatic.when(ServerProperties::getInstance).thenReturn(serverProperties); // Test mode used when(serverProperties.getGcsConfigurations())