use of io.druid.java.util.common.IAE in project druid by druid-io.
the class DataSchema method getParser.
@JsonIgnore
public InputRowParser getParser() {
if (parser == null) {
log.warn("No parser has been specified");
return null;
}
final InputRowParser inputRowParser = jsonMapper.convertValue(this.parser, InputRowParser.class);
final Set<String> dimensionExclusions = Sets.newHashSet();
for (AggregatorFactory aggregator : aggregators) {
dimensionExclusions.addAll(aggregator.requiredFields());
dimensionExclusions.add(aggregator.getName());
}
if (inputRowParser.getParseSpec() != null) {
final DimensionsSpec dimensionsSpec = inputRowParser.getParseSpec().getDimensionsSpec();
final TimestampSpec timestampSpec = inputRowParser.getParseSpec().getTimestampSpec();
// exclude timestamp from dimensions by default, unless explicitly included in the list of dimensions
if (timestampSpec != null) {
final String timestampColumn = timestampSpec.getTimestampColumn();
if (!(dimensionsSpec.hasCustomDimensions() && dimensionsSpec.getDimensionNames().contains(timestampColumn))) {
dimensionExclusions.add(timestampColumn);
}
}
if (dimensionsSpec != null) {
final Set<String> metSet = Sets.newHashSet();
for (AggregatorFactory aggregator : aggregators) {
metSet.add(aggregator.getName());
}
final Set<String> dimSet = Sets.newHashSet(dimensionsSpec.getDimensionNames());
final Set<String> overlap = Sets.intersection(metSet, dimSet);
if (!overlap.isEmpty()) {
throw new IAE("Cannot have overlapping dimensions and metrics of the same name. Please change the name of the metric. Overlap: %s", overlap);
}
return inputRowParser.withParseSpec(inputRowParser.getParseSpec().withDimensionsSpec(dimensionsSpec.withDimensionExclusions(Sets.difference(dimensionExclusions, dimSet))));
} else {
return inputRowParser;
}
} else {
log.warn("No parseSpec in parser has been specified.");
return inputRowParser;
}
}
use of io.druid.java.util.common.IAE in project druid by druid-io.
the class DruidNode method init.
private void init(String serviceName, String host, Integer port) {
Preconditions.checkNotNull(serviceName);
this.serviceName = serviceName;
if (host == null && port == null) {
host = getDefaultHost();
port = -1;
} else {
final HostAndPort hostAndPort;
if (host != null) {
hostAndPort = HostAndPort.fromString(host);
if (port != null && hostAndPort.hasPort() && port != hostAndPort.getPort()) {
throw new IAE("Conflicting host:port [%s] and port [%d] settings", host, port);
}
} else {
hostAndPort = HostAndPort.fromParts(getDefaultHost(), port);
}
host = hostAndPort.getHostText();
if (hostAndPort.hasPort()) {
port = hostAndPort.getPort();
}
if (port == null) {
port = SocketUtil.findOpenPort(8080);
}
}
this.port = port;
this.host = host;
}
use of io.druid.java.util.common.IAE in project druid by druid-io.
the class LookupCoordinatorResource method createOrUpdateLookup.
@POST
@Produces({ MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE })
@Path("/{tier}/{lookup}")
public Response createOrUpdateLookup(@PathParam("tier") String tier, @PathParam("lookup") String lookup, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, InputStream in, @Context HttpServletRequest req) {
try {
if (Strings.isNullOrEmpty(tier)) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(new NullPointerException("`tier` required"))).build();
}
if (Strings.isNullOrEmpty(lookup)) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(new IAE("`lookup` required"))).build();
}
final boolean isSmile = SmileMediaTypes.APPLICATION_JACKSON_SMILE.equals(req.getContentType());
final ObjectMapper mapper = isSmile ? smileMapper : jsonMapper;
final Map<String, Object> lookupSpec;
try {
lookupSpec = mapper.readValue(in, new TypeReference<Map<String, Object>>() {
});
} catch (IOException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(e)).build();
}
if (lookupCoordinatorManager.updateLookup(tier, lookup, lookupSpec, new AuditInfo(author, comment, req.getRemoteAddr()))) {
return Response.status(Response.Status.ACCEPTED).build();
} else {
throw new RuntimeException("Unknown error updating configuration");
}
} catch (Exception e) {
LOG.error(e, "Error updating tier [%s] lookup [%s]", tier, lookup);
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
use of io.druid.java.util.common.IAE in project druid by druid-io.
the class LookupCoordinatorManager method updateAllOnHost.
void updateAllOnHost(final URL url, Map<String, Map<String, Object>> knownLookups) throws IOException, InterruptedException, ExecutionException {
final AtomicInteger returnCode = new AtomicInteger(0);
final AtomicReference<String> reasonString = new AtomicReference<>(null);
final byte[] bytes;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Loading up %d lookups to %s", knownLookups.size(), url);
}
bytes = smileMapper.writeValueAsBytes(knownLookups);
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
try (final InputStream result = httpClient.go(new Request(HttpMethod.POST, url).addHeader(HttpHeaders.Names.ACCEPT, SmileMediaTypes.APPLICATION_JACKSON_SMILE).addHeader(HttpHeaders.Names.CONTENT_TYPE, SmileMediaTypes.APPLICATION_JACKSON_SMILE).setContent(bytes), makeResponseHandler(returnCode, reasonString), lookupCoordinatorManagerConfig.getHostUpdateTimeout()).get()) {
if (!httpStatusIsSuccess(returnCode.get())) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
StreamUtils.copyAndClose(result, baos);
} catch (IOException e2) {
LOG.warn(e2, "Error reading response");
}
throw new IOException(String.format("Bad update request to [%s] : [%d] : [%s] Response: [%s]", url, returnCode.get(), reasonString.get(), StringUtils.fromUtf8(baos.toByteArray())));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Update on [%s], Status: %s reason: [%s]", url, returnCode.get(), reasonString.get());
}
final Map<String, Object> resultMap = smileMapper.readValue(result, MAP_STRING_OBJ_TYPE);
final Object missingValuesObject = resultMap.get(LookupModule.FAILED_UPDATES_KEY);
if (null == missingValuesObject) {
throw new IAE("Update result did not have field for [%s]", LookupModule.FAILED_UPDATES_KEY);
}
final Map<String, Object> missingValues = smileMapper.convertValue(missingValuesObject, MAP_STRING_OBJ_TYPE);
if (!missingValues.isEmpty()) {
throw new IAE("Lookups failed to update: %s", smileMapper.writeValueAsString(missingValues.keySet()));
} else {
LOG.debug("Updated all lookups on [%s]", url);
}
}
}
}
use of io.druid.java.util.common.IAE in project druid by druid-io.
the class ApproximateHistogramFoldingAggregatorFactory method factorizeBuffered.
@Override
public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) {
ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(fieldName);
if (selector == null) {
// gracefully handle undefined metrics
selector = new ObjectColumnSelector<ApproximateHistogram>() {
@Override
public Class<ApproximateHistogram> classOfObject() {
return ApproximateHistogram.class;
}
@Override
public ApproximateHistogram get() {
return new ApproximateHistogram(0);
}
};
}
final Class cls = selector.classOfObject();
if (cls.equals(Object.class) || ApproximateHistogram.class.isAssignableFrom(cls)) {
return new ApproximateHistogramFoldingBufferAggregator(selector, resolution, lowerLimit, upperLimit);
}
throw new IAE("Incompatible type for metric[%s], expected a ApproximateHistogram, got a %s", fieldName, cls);
}
Aggregations