Skip to content

Commit 6b1da92

Browse files
committed
Minor bug fixes.
#Set the error message in MetacatException #Throw the right message when partition not found for deletion
1 parent f21f424 commit 6b1da92

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

metacat-common-server/src/main/java/com/facebook/presto/exception/PartitionNotFoundException.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@ public PartitionNotFoundException(SchemaTableName tableName, String partitionId)
2727
}
2828

2929
public PartitionNotFoundException(SchemaTableName tableName, String partitionId, Throwable cause) {
30-
super(String.format("Partition %s not found for table %s", tableName, partitionId==null?"": partitionId), cause);
30+
this(tableName, partitionId,
31+
String.format("Partition %s not found for table %s", partitionId == null ? "" : partitionId, tableName),
32+
cause);
33+
}
34+
35+
public PartitionNotFoundException(SchemaTableName tableName, String partitionId, String message, Throwable cause) {
36+
super(message, cause);
3137
this.tableName = tableName;
3238
this.partitionId = partitionId;
3339
}
40+
41+
public SchemaTableName getTableName() {
42+
return tableName;
43+
}
44+
45+
public String getPartitionId() {
46+
return partitionId;
47+
}
3448
}

metacat-common/src/main/java/com/netflix/metacat/common/exception/MetacatException.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public MetacatException(String message, Response.Status status, Throwable cause)
6969
.type(MediaType.APPLICATION_JSON_TYPE)
7070
.entity(metacatJson.emptyObjectNode().put("error", message))
7171
.build(),
72-
cause
72+
cause == null? new Exception(message): cause
7373
);
7474
}
7575

@@ -89,7 +89,7 @@ public MetacatException(String message, int status, Throwable cause) {
8989
.type(MediaType.APPLICATION_JSON_TYPE)
9090
.entity(metacatJson.emptyObjectNode().put("error", message))
9191
.build(),
92-
cause);
92+
cause == null? new Exception(message): cause);
9393
}
9494

9595
/**

metacat-main/src/main/java/com/netflix/metacat/main/api/MetadataV1Resource.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package com.netflix.metacat.main.api;
1515

16+
import com.facebook.presto.spi.NotFoundException;
1617
import com.fasterxml.jackson.databind.node.ObjectNode;
1718
import com.google.common.collect.Lists;
1819
import com.netflix.metacat.common.MetacatContext;
@@ -24,7 +25,6 @@
2425
import com.netflix.metacat.common.dto.DefinitionMetadataDto;
2526
import com.netflix.metacat.common.dto.HasDefinitionMetadata;
2627
import com.netflix.metacat.common.dto.SortOrder;
27-
import com.netflix.metacat.common.server.events.MetacatEventBus;
2828
import com.netflix.metacat.common.usermetadata.UserMetadataService;
2929
import com.netflix.metacat.common.util.MetacatContextManager;
3030
import com.netflix.metacat.main.services.MetacatService;
@@ -45,8 +45,7 @@ public class MetadataV1Resource implements MetadataV1 {
4545
private final MetacatServiceHelper helper;
4646
@Inject
4747
public MetadataV1Resource(UserMetadataService userMetadataService,
48-
MetacatServiceHelper helper,
49-
MetacatEventBus eventBus) {
48+
MetacatServiceHelper helper) {
5049
this.userMetadataService = userMetadataService;
5150
this.helper = helper;
5251
}
@@ -99,7 +98,7 @@ public void deleteDefinitionMetadata(QualifiedName name, Boolean force) {
9998
BaseDto dto = null;
10099
try {
101100
dto = service.get(name);
102-
} catch(Exception ignored){}
101+
} catch(NotFoundException ignored){}
103102
if( (force || dto == null) && !"rds".equalsIgnoreCase(name.getCatalogName())) {
104103
helper.postPreUpdateEvent(name, dto, metacatContext);
105104
userMetadataService.deleteDefinitionMetadatas(Lists.newArrayList(name));

metacat-main/src/main/java/com/netflix/metacat/main/api/RequestWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static <R> R requestWrapper(
6565
throw new MetacatAlreadyExistsException(e.getMessage());
6666
} catch (NotFoundException|MetacatNotFoundException e) {
6767
log.error(e.getMessage(), e);
68-
throw new MetacatNotFoundException("Unable to locate: " + name);
68+
throw new MetacatNotFoundException(String.format("Unable to locate for %s. Details: %s", name, e.getMessage()));
6969
} catch (InvalidMetaException | IllegalArgumentException e) {
7070
log.error(e.getMessage(), e);
7171
throw new MetacatBadRequestException(String.format("%s.%s",e.getMessage(), e.getCause()==null?"":e.getCause().getMessage()));

metacat-main/src/main/java/com/netflix/metacat/main/services/impl/PartitionServiceImpl.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import com.facebook.presto.spi.ConnectorPartitionResult;
2020
import com.facebook.presto.spi.Pageable;
2121
import com.facebook.presto.spi.SavePartitionResult;
22+
import com.facebook.presto.spi.SchemaTableName;
2223
import com.facebook.presto.spi.SchemaTablePartitionName;
2324
import com.facebook.presto.spi.Sort;
25+
import com.facebook.presto.spi.TableNotFoundException;
2426
import com.fasterxml.jackson.databind.node.ObjectNode;
2527
import com.google.common.base.Splitter;
2628
import com.google.common.collect.Lists;
@@ -184,7 +186,10 @@ public void delete(QualifiedName name, List<String> partitionIds) {
184186
TagList tags = BasicTagList.of("catalog", name.getCatalogName(), "database", name.getDatabaseName(), "table", name.getTableName());
185187
DynamicGauge.set(LogConstants.GaugeDeletePartitions.toString(), tags, partitionIds.size());
186188
Optional<TableHandle> tableHandle = tableService.getTableHandle(name);
187-
if (tableHandle.isPresent() && !partitionIds.isEmpty()) {
189+
if( !tableHandle.isPresent()){
190+
throw new TableNotFoundException(new SchemaTableName(name.getDatabaseName(), name.getTableName()));
191+
}
192+
if (!partitionIds.isEmpty()) {
188193
ConnectorPartitionResult partitionResult = splitManager.getPartitions(tableHandle.get(), null, partitionIds, null, null, false);
189194
log.info("Deleting partitions with names {} for {}", partitionIds, name);
190195
splitManager.deletePartitions( tableHandle.get(), partitionIds);

0 commit comments

Comments
 (0)