Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes. #390

Merged
merged 1 commit into from
May 18, 2020
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 @@ -34,8 +34,6 @@
import lombok.AllArgsConstructor;

import java.io.IOException;
import java.time.Instant;
import java.util.Date;

/**
* Module that provides a error decoder, used to parse errors.
Expand Down Expand Up @@ -76,10 +74,10 @@ public Exception decode(final String methodKey, final Response response) {
case 412: // PRECONDITION_FAILED
return new MetacatPreconditionFailedException(message);
case 429:
return new MetacatTooManyRequestsException(message);
return new RetryableException(message, new MetacatTooManyRequestsException(message), null);
case 500: //INTERNAL_SERVER_ERROR
case 503: //SERVICE_UNAVAILABLE
return new RetryableException(message, null, new Date(Instant.now().toEpochMilli()));
return new RetryableException(message, new MetacatException(message), null);
default:
return new MetacatException(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
import com.netflix.metacat.common.QualifiedName;
import com.netflix.metacat.common.dto.Pageable;
import com.netflix.metacat.common.dto.Sort;
import com.netflix.metacat.common.exception.MetacatException;
import com.netflix.metacat.common.server.connectors.ConnectorRequestContext;
import com.netflix.metacat.common.server.connectors.ConnectorTableService;
import com.netflix.metacat.common.server.connectors.ConnectorUtils;
import com.netflix.metacat.common.server.connectors.exception.ConnectorException;
import com.netflix.metacat.common.server.connectors.exception.InvalidMetadataException;
import com.netflix.metacat.common.server.connectors.exception.TableNotFoundException;
import com.netflix.metacat.common.server.connectors.model.TableInfo;
import com.netflix.metacat.connector.druid.converter.DataSource;
import com.netflix.metacat.connector.druid.converter.DruidConnectorInfoConverter;
import com.netflix.metacat.connector.druid.converter.DruidConverterUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -66,9 +71,21 @@ public DruidConnectorTableService(
@Override
public TableInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
log.debug("Get table metadata for qualified name {} for request {}", name, context);
final ObjectNode node = this.druidClient.getLatestDataByName(name.getTableName());
final DataSource dataSource = DruidConverterUtil.getDatasourceFromLatestSegmentJsonObject(node);
return this.druidConnectorInfoConverter.getTableInfoFromDatasource(dataSource);
try {
final ObjectNode node = this.druidClient.getLatestDataByName(name.getTableName());
final DataSource dataSource = DruidConverterUtil.getDatasourceFromLatestSegmentJsonObject(node);
return this.druidConnectorInfoConverter.getTableInfoFromDatasource(dataSource);
} catch (MetacatException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any metacat exception is rethrown as a TableNotFound?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method getLatestDataByName throws this specific error when segments are not found.

log.error(String.format("Table %s not found.", name), e);
throw new TableNotFoundException(name);
} catch (HttpClientErrorException e) {
log.error(String.format("Failed getting table %s.", name), e);
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
throw new TableNotFoundException(name);
} else {
throw new InvalidMetadataException(String.format("Invalid table %s. %s", name, e.getMessage()));
}
}
}

/**
Expand Down