Skip to content

Commit

Permalink
make BASIC_CATALOG_PROPERTIES_METADATA singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
mchades committed Oct 17, 2024
1 parent 33d7171 commit 7fefe99
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.gravitino.exceptions.ForbiddenException;
import org.apache.gravitino.exceptions.GroupAlreadyExistsException;
import org.apache.gravitino.exceptions.IllegalPrivilegeException;
import org.apache.gravitino.exceptions.InUseException;
import org.apache.gravitino.exceptions.MetalakeAlreadyExistsException;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchFilesetException;
Expand Down Expand Up @@ -323,7 +324,12 @@ public void accept(ErrorResponse errorResponse) {
throw new ForbiddenException(errorMessage);

case ErrorConstants.NOT_IN_USE_CODE:
throw new CatalogNotInUseException(errorMessage);
if (errorResponse.getType().equals(CatalogNotInUseException.class.getSimpleName())) {
throw new CatalogNotInUseException(errorMessage);

} else {
throw new NotInUseException(errorMessage);
}

default:
super.accept(errorResponse);
Expand Down Expand Up @@ -366,7 +372,12 @@ public void accept(ErrorResponse errorResponse) {
throw new ForbiddenException(errorMessage);

case ErrorConstants.NOT_IN_USE_CODE:
throw new CatalogNotInUseException(errorMessage);
if (errorResponse.getType().equals(CatalogNotInUseException.class.getSimpleName())) {
throw new CatalogNotInUseException(errorMessage);

} else {
throw new NotInUseException(errorMessage);
}

case ErrorConstants.INTERNAL_ERROR_CODE:
throw new RuntimeException(errorMessage);
Expand Down Expand Up @@ -412,10 +423,20 @@ public void accept(ErrorResponse errorResponse) {
throw new RuntimeException(errorMessage);

case ErrorConstants.IN_USE_CODE:
throw new CatalogInUseException(errorMessage);
if (errorResponse.getType().equals(CatalogInUseException.class.getSimpleName())) {
throw new CatalogInUseException(errorMessage);

} else {
throw new InUseException(errorMessage);
}

case ErrorConstants.NOT_IN_USE_CODE:
throw new CatalogNotInUseException(errorMessage);
if (errorResponse.getType().equals(CatalogNotInUseException.class.getSimpleName())) {
throw new CatalogNotInUseException(errorMessage);

} else {
throw new NotInUseException(errorMessage);
}

default:
super.accept(errorResponse);
Expand Down Expand Up @@ -536,7 +557,12 @@ public void accept(ErrorResponse errorResponse) {
throw new RuntimeException(errorMessage);

case ErrorConstants.NOT_IN_USE_CODE:
throw new CatalogNotInUseException(errorMessage);
if (errorResponse.getType().equals(CatalogNotInUseException.class.getSimpleName())) {
throw new CatalogNotInUseException(errorMessage);

} else {
throw new NotInUseException(errorMessage);
}

default:
super.accept(errorResponse);
Expand Down Expand Up @@ -577,7 +603,12 @@ public void accept(ErrorResponse errorResponse) {
throw new RuntimeException(errorMessage);

case ErrorConstants.NOT_IN_USE_CODE:
throw new CatalogNotInUseException(errorMessage);
if (errorResponse.getType().equals(CatalogNotInUseException.class.getSimpleName())) {
throw new CatalogNotInUseException(errorMessage);

} else {
throw new NotInUseException(errorMessage);
}

default:
super.accept(errorResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.apache.gravitino.StringIdentifier.DUMMY_ID;
import static org.apache.gravitino.catalog.PropertiesMetadataHelpers.validatePropertyForAlter;
import static org.apache.gravitino.catalog.PropertiesMetadataHelpers.validatePropertyForCreate;
import static org.apache.gravitino.connector.BaseCatalogPropertiesMetadata.BASIC_CATALOG_PROPERTIES_METADATA;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
Expand Down Expand Up @@ -71,10 +72,8 @@
import org.apache.gravitino.Namespace;
import org.apache.gravitino.StringIdentifier;
import org.apache.gravitino.connector.BaseCatalog;
import org.apache.gravitino.connector.BaseCatalogPropertiesMetadata;
import org.apache.gravitino.connector.CatalogOperations;
import org.apache.gravitino.connector.HasPropertyMetadata;
import org.apache.gravitino.connector.PropertiesMetadata;
import org.apache.gravitino.connector.PropertyEntry;
import org.apache.gravitino.connector.SupportsSchemas;
import org.apache.gravitino.connector.capability.Capability;
Expand Down Expand Up @@ -106,13 +105,6 @@ public class CatalogManager implements CatalogDispatcher, Closeable {

private static final String CATALOG_DOES_NOT_EXIST_MSG = "Catalog %s does not exist";
private static final String METALAKE_DOES_NOT_EXIST_MSG = "Metalake %s does not exist";
private static final PropertiesMetadata BASIC_CATALOG_PROPERTIES_METADATA =
new BaseCatalogPropertiesMetadata() {
@Override
protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
return Collections.emptyMap();
}
};

private static final Logger LOG = LoggerFactory.getLogger(CatalogManager.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.Map;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.annotation.Evolving;

@Evolving
public abstract class BaseCatalogPropertiesMetadata extends BasePropertiesMetadata {

public static final PropertiesMetadata BASIC_CATALOG_PROPERTIES_METADATA =
new BaseCatalogPropertiesMetadata() {
@Override
protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
return Collections.emptyMap();
}
};

// The basic property entries for catalog entities
private static final Map<String, PropertyEntry<?>> BASIC_CATALOG_PROPERTY_ENTRIES =
Maps.uniqueIndex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,18 @@
*/
package org.apache.gravitino.server.web.rest;

import static org.apache.gravitino.connector.BaseCatalogPropertiesMetadata.BASIC_CATALOG_PROPERTIES_METADATA;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.connector.BaseCatalog;
import org.apache.gravitino.connector.BaseCatalogPropertiesMetadata;
import org.apache.gravitino.connector.CatalogInfo;
import org.apache.gravitino.connector.CatalogOperations;
import org.apache.gravitino.connector.HasPropertyMetadata;
import org.apache.gravitino.connector.PropertiesMetadata;
import org.apache.gravitino.connector.PropertyEntry;

public class TestCatalog extends BaseCatalog<TestCatalog> {
private static final PropertiesMetadata PROPERTIES_METADATA =
new BaseCatalogPropertiesMetadata() {
@Override
protected Map<String, PropertyEntry<?>> specificPropertyEntries() {
return Collections.emptyMap();
}
};

@Override
public String shortName() {
Expand Down Expand Up @@ -69,6 +61,6 @@ public void close() throws IOException {}

@Override
public PropertiesMetadata catalogPropertiesMetadata() throws UnsupportedOperationException {
return PROPERTIES_METADATA;
return BASIC_CATALOG_PROPERTIES_METADATA;
}
}

0 comments on commit 7fefe99

Please sign in to comment.