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 @@ -252,7 +252,7 @@ private void dropEntity(
// if it is a principal, we also need to drop the secrets
if (entity.getType() == PolarisEntityType.PRINCIPAL) {
// get internal properties
Map<String, String> properties = this.deserializeProperties(entity.getInternalProperties());
Map<String, String> properties = entity.getInternalPropertiesAsMap();

// get client_id
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
Expand Down Expand Up @@ -432,7 +432,7 @@ private void revokeGrantRecord(
// validate input
callCtx.getDiagServices().checkNotNull(catalog, "unexpected_null_catalog");

Map<String, String> internalProp = getInternalPropertyMap(catalog);
Map<String, String> internalProp = catalog.getInternalPropertiesAsMap();
String integrationIdentifierOrId =
internalProp.get(PolarisEntityConstants.getStorageIntegrationIdentifierPropertyName());
String storageConfigInfoStr =
Expand Down Expand Up @@ -751,8 +751,7 @@ private void revokeGrantRecord(
principal);

// get internal properties
Map<String, String> properties =
this.deserializeProperties(refreshPrincipal.getInternalProperties());
Map<String, String> properties = refreshPrincipal.getInternalPropertiesAsMap();

// get client_id
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
Expand Down Expand Up @@ -798,14 +797,14 @@ private void revokeGrantRecord(
.generateNewPrincipalSecrets(callCtx, principal.getName(), principal.getId());

// generate properties
Map<String, String> internalProperties = getInternalPropertyMap(principal);
Map<String, String> internalProperties = principal.getInternalPropertiesAsMap();
internalProperties.put(
PolarisEntityConstants.getClientIdPropertyName(), principalSecrets.getPrincipalClientId());

// remember client id
PolarisBaseEntity updatedPrincipal =
new PolarisBaseEntity.Builder(principal)
.internalProperties(this.serializeProperties(internalProperties))
.internalPropertiesAsMap(internalProperties)
.build();
// now create and persist new catalog entity
EntityResult lowLevelResult = this.persistNewEntity(callCtx, ms, updatedPrincipal);
Expand Down Expand Up @@ -1616,21 +1615,6 @@ private void revokeGrantRecord(
}
}

/**
* Get the internal property map for an entity
*
* @param entity the target entity
* @return a map of string representing the internal properties
*/
public Map<String, String> getInternalPropertyMap(@Nonnull PolarisBaseEntity entity) {
String internalPropStr = entity.getInternalProperties();
Map<String, String> res = new HashMap<>();
if (internalPropStr == null) {
return res;
}
return deserializeProperties(internalPropStr);
}

/** {@inheritDoc} */
@Override
public @Nonnull ResolvedEntityResult loadResolvedEntityById(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package org.apache.polaris.core.persistence;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Nonnull;
import java.util.Map;
import org.apache.polaris.core.PolarisCallContext;
Expand All @@ -34,8 +31,6 @@

/** Shared basic PolarisMetaStoreManager logic for transactional and non-transactional impls. */
public abstract class BaseMetaStoreManager implements PolarisMetaStoreManager {
/** mapper, allows to serialize/deserialize properties to/from JSON */
private static final ObjectMapper MAPPER = new ObjectMapper();

public static PolarisStorageConfigurationInfo extractStorageConfiguration(
@Nonnull PolarisDiagnostics diagnostics, PolarisBaseEntity reloadedEntity) {
Expand All @@ -52,36 +47,6 @@ public static PolarisStorageConfigurationInfo extractStorageConfiguration(
return PolarisStorageConfigurationInfo.deserialize(storageConfigInfoStr);
}

/**
* Given the internal property as a map of key/value pairs, serialize it to a String
*
* @param properties a map of key/value pairs
* @return a String, the JSON representation of the map
*/
public String serializeProperties(Map<String, String> properties) {
try {
// Deserialize the JSON string to a Map<String, String>
return MAPPER.writeValueAsString(properties);
} catch (JsonProcessingException ex) {
throw new RuntimeException("serializeProperties failed: " + ex.getMessage(), ex);
}
}

/**
* Given the serialized properties, deserialize those to a {@code Map<String, String>}
*
* @param properties a JSON string representing the set of properties
* @return a Map of string
*/
public Map<String, String> deserializeProperties(String properties) {
try {
// Deserialize the JSON string to a Map<String, String>
return MAPPER.readValue(properties, new TypeReference<>() {});
} catch (JsonProcessingException ex) {
throw new RuntimeException("deserializeProperties failed: " + ex.getMessage(), ex);
}
}

/**
* Performs basic validation of expected invariants on a new entity, then returns the entity with
* fields filled out for which the persistence layer is responsible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void dropEntity(
// if it is a principal, we also need to drop the secrets
if (entity.getType() == PolarisEntityType.PRINCIPAL) {
// get internal properties
Map<String, String> properties = this.deserializeProperties(entity.getInternalProperties());
Map<String, String> properties = entity.getInternalPropertiesAsMap();

// get client_id
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
Expand Down Expand Up @@ -763,8 +763,7 @@ private void bootstrapPolarisService(
principal);

// get internal properties
Map<String, String> properties =
this.deserializeProperties(refreshPrincipal.getInternalProperties());
Map<String, String> properties = refreshPrincipal.getInternalPropertiesAsMap();

// get client_id
String clientId = properties.get(PolarisEntityConstants.getClientIdPropertyName());
Expand Down Expand Up @@ -821,14 +820,14 @@ private void bootstrapPolarisService(
ms.generateNewPrincipalSecretsInCurrentTxn(callCtx, principal.getName(), principal.getId());

// generate properties
Map<String, String> internalProperties = getInternalPropertyMap(principal);
Map<String, String> internalProperties = principal.getInternalPropertiesAsMap();
internalProperties.put(
PolarisEntityConstants.getClientIdPropertyName(), principalSecrets.getPrincipalClientId());

// remember client id
PolarisBaseEntity updatedPrincipal =
new PolarisBaseEntity.Builder(principal)
.internalProperties(this.serializeProperties(internalProperties))
.internalPropertiesAsMap(internalProperties)
.build();

// now create and persist new catalog entity
Expand Down Expand Up @@ -955,7 +954,7 @@ private void bootstrapPolarisService(
// get metastore we should be using
TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore());

Map<String, String> internalProp = getInternalPropertyMap(catalog);
Map<String, String> internalProp = catalog.getInternalPropertiesAsMap();
String integrationIdentifierOrId =
internalProp.get(PolarisEntityConstants.getStorageIntegrationIdentifierPropertyName());
String storageConfigInfoStr =
Expand Down Expand Up @@ -2062,21 +2061,6 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
}
}

/**
* Get the internal property map for an entity
*
* @param entity the target entity
* @return a map of string representing the internal properties
*/
public Map<String, String> getInternalPropertyMap(@Nonnull PolarisBaseEntity entity) {
String internalPropStr = entity.getInternalProperties();
Map<String, String> res = new HashMap<>();
if (internalPropStr == null) {
return res;
}
return deserializeProperties(internalPropStr);
}

/** {@link #loadResolvedEntityById(PolarisCallContext, long, long, PolarisEntityType)} */
private @Nonnull ResolvedEntityResult loadResolvedEntityById(
@Nonnull PolarisCallContext callCtx,
Expand Down