Skip to content

Commit

Permalink
Minor bug fixes.
Browse files Browse the repository at this point in the history
#Set the error message in MetacatException
#Throw the right message when partition not found for deletion
  • Loading branch information
ajoymajumdar committed Apr 1, 2016
1 parent f21f424 commit 6b1da92
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static <R> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -184,7 +186,10 @@ public void delete(QualifiedName name, List<String> partitionIds) {
TagList tags = BasicTagList.of("catalog", name.getCatalogName(), "database", name.getDatabaseName(), "table", name.getTableName());
DynamicGauge.set(LogConstants.GaugeDeletePartitions.toString(), tags, partitionIds.size());
Optional<TableHandle> 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);
Expand Down

0 comments on commit 6b1da92

Please sign in to comment.