From 6b1da925eceb6bdfea87ef27bcbc8a4cd93e7339 Mon Sep 17 00:00:00 2001 From: Ajoy Majumdar Date: Fri, 1 Apr 2016 16:27:51 -0700 Subject: [PATCH] Minor bug fixes. #Set the error message in MetacatException #Throw the right message when partition not found for deletion --- .../exception/PartitionNotFoundException.java | 16 +++++++++++++++- .../common/exception/MetacatException.java | 4 ++-- .../metacat/main/api/MetadataV1Resource.java | 7 +++---- .../netflix/metacat/main/api/RequestWrapper.java | 2 +- .../main/services/impl/PartitionServiceImpl.java | 7 ++++++- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/metacat-common-server/src/main/java/com/facebook/presto/exception/PartitionNotFoundException.java b/metacat-common-server/src/main/java/com/facebook/presto/exception/PartitionNotFoundException.java index 7c6bf722e..ec0055b49 100644 --- a/metacat-common-server/src/main/java/com/facebook/presto/exception/PartitionNotFoundException.java +++ b/metacat-common-server/src/main/java/com/facebook/presto/exception/PartitionNotFoundException.java @@ -27,8 +27,22 @@ public PartitionNotFoundException(SchemaTableName tableName, String partitionId) } public PartitionNotFoundException(SchemaTableName tableName, String partitionId, Throwable cause) { - super(String.format("Partition %s not found for table %s", tableName, partitionId==null?"": partitionId), cause); + this(tableName, partitionId, + String.format("Partition %s not found for table %s", partitionId == null ? "" : partitionId, tableName), + cause); + } + + public PartitionNotFoundException(SchemaTableName tableName, String partitionId, String message, Throwable cause) { + super(message, cause); this.tableName = tableName; this.partitionId = partitionId; } + + public SchemaTableName getTableName() { + return tableName; + } + + public String getPartitionId() { + return partitionId; + } } diff --git a/metacat-common/src/main/java/com/netflix/metacat/common/exception/MetacatException.java b/metacat-common/src/main/java/com/netflix/metacat/common/exception/MetacatException.java index 4cddb38ca..bd87599ba 100644 --- a/metacat-common/src/main/java/com/netflix/metacat/common/exception/MetacatException.java +++ b/metacat-common/src/main/java/com/netflix/metacat/common/exception/MetacatException.java @@ -69,7 +69,7 @@ public MetacatException(String message, Response.Status status, Throwable cause) .type(MediaType.APPLICATION_JSON_TYPE) .entity(metacatJson.emptyObjectNode().put("error", message)) .build(), - cause + cause == null? new Exception(message): cause ); } @@ -89,7 +89,7 @@ public MetacatException(String message, int status, Throwable cause) { .type(MediaType.APPLICATION_JSON_TYPE) .entity(metacatJson.emptyObjectNode().put("error", message)) .build(), - cause); + cause == null? new Exception(message): cause); } /** diff --git a/metacat-main/src/main/java/com/netflix/metacat/main/api/MetadataV1Resource.java b/metacat-main/src/main/java/com/netflix/metacat/main/api/MetadataV1Resource.java index 69580bb84..9cc2c0be6 100644 --- a/metacat-main/src/main/java/com/netflix/metacat/main/api/MetadataV1Resource.java +++ b/metacat-main/src/main/java/com/netflix/metacat/main/api/MetadataV1Resource.java @@ -13,6 +13,7 @@ package com.netflix.metacat.main.api; +import com.facebook.presto.spi.NotFoundException; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Lists; import com.netflix.metacat.common.MetacatContext; @@ -24,7 +25,6 @@ import com.netflix.metacat.common.dto.DefinitionMetadataDto; import com.netflix.metacat.common.dto.HasDefinitionMetadata; import com.netflix.metacat.common.dto.SortOrder; -import com.netflix.metacat.common.server.events.MetacatEventBus; import com.netflix.metacat.common.usermetadata.UserMetadataService; import com.netflix.metacat.common.util.MetacatContextManager; import com.netflix.metacat.main.services.MetacatService; @@ -45,8 +45,7 @@ public class MetadataV1Resource implements MetadataV1 { private final MetacatServiceHelper helper; @Inject public MetadataV1Resource(UserMetadataService userMetadataService, - MetacatServiceHelper helper, - MetacatEventBus eventBus) { + MetacatServiceHelper helper) { this.userMetadataService = userMetadataService; this.helper = helper; } @@ -99,7 +98,7 @@ public void deleteDefinitionMetadata(QualifiedName name, Boolean force) { BaseDto dto = null; try { dto = service.get(name); - } catch(Exception ignored){} + } catch(NotFoundException ignored){} if( (force || dto == null) && !"rds".equalsIgnoreCase(name.getCatalogName())) { helper.postPreUpdateEvent(name, dto, metacatContext); userMetadataService.deleteDefinitionMetadatas(Lists.newArrayList(name)); diff --git a/metacat-main/src/main/java/com/netflix/metacat/main/api/RequestWrapper.java b/metacat-main/src/main/java/com/netflix/metacat/main/api/RequestWrapper.java index da969bcd0..8849d27c4 100644 --- a/metacat-main/src/main/java/com/netflix/metacat/main/api/RequestWrapper.java +++ b/metacat-main/src/main/java/com/netflix/metacat/main/api/RequestWrapper.java @@ -65,7 +65,7 @@ public static R requestWrapper( throw new MetacatAlreadyExistsException(e.getMessage()); } catch (NotFoundException|MetacatNotFoundException e) { log.error(e.getMessage(), e); - throw new MetacatNotFoundException("Unable to locate: " + name); + throw new MetacatNotFoundException(String.format("Unable to locate for %s. Details: %s", name, e.getMessage())); } catch (InvalidMetaException | IllegalArgumentException e) { log.error(e.getMessage(), e); throw new MetacatBadRequestException(String.format("%s.%s",e.getMessage(), e.getCause()==null?"":e.getCause().getMessage())); diff --git a/metacat-main/src/main/java/com/netflix/metacat/main/services/impl/PartitionServiceImpl.java b/metacat-main/src/main/java/com/netflix/metacat/main/services/impl/PartitionServiceImpl.java index 31ca0ea74..57c300433 100644 --- a/metacat-main/src/main/java/com/netflix/metacat/main/services/impl/PartitionServiceImpl.java +++ b/metacat-main/src/main/java/com/netflix/metacat/main/services/impl/PartitionServiceImpl.java @@ -19,8 +19,10 @@ import com.facebook.presto.spi.ConnectorPartitionResult; import com.facebook.presto.spi.Pageable; import com.facebook.presto.spi.SavePartitionResult; +import com.facebook.presto.spi.SchemaTableName; import com.facebook.presto.spi.SchemaTablePartitionName; import com.facebook.presto.spi.Sort; +import com.facebook.presto.spi.TableNotFoundException; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Splitter; import com.google.common.collect.Lists; @@ -184,7 +186,10 @@ public void delete(QualifiedName name, List partitionIds) { TagList tags = BasicTagList.of("catalog", name.getCatalogName(), "database", name.getDatabaseName(), "table", name.getTableName()); DynamicGauge.set(LogConstants.GaugeDeletePartitions.toString(), tags, partitionIds.size()); Optional tableHandle = tableService.getTableHandle(name); - if (tableHandle.isPresent() && !partitionIds.isEmpty()) { + if( !tableHandle.isPresent()){ + throw new TableNotFoundException(new SchemaTableName(name.getDatabaseName(), name.getTableName())); + } + if (!partitionIds.isEmpty()) { ConnectorPartitionResult partitionResult = splitManager.getPartitions(tableHandle.get(), null, partitionIds, null, null, false); log.info("Deleting partitions with names {} for {}", partitionIds, name); splitManager.deletePartitions( tableHandle.get(), partitionIds);