Search in sources :

Example 21 with IAE

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;
    }
}
Also used : TimestampSpec(io.druid.data.input.impl.TimestampSpec) DimensionsSpec(io.druid.data.input.impl.DimensionsSpec) InputRowParser(io.druid.data.input.impl.InputRowParser) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) IAE(io.druid.java.util.common.IAE) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 22 with IAE

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;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) IAE(io.druid.java.util.common.IAE)

Example 23 with IAE

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();
    }
}
Also used : AuditInfo(io.druid.audit.AuditInfo) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) IAE(io.druid.java.util.common.IAE) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 24 with IAE

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);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) Request(com.metamx.http.client.Request) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IAE(io.druid.java.util.common.IAE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 25 with IAE

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);
}
Also used : IAE(io.druid.java.util.common.IAE) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Aggregations

IAE (io.druid.java.util.common.IAE)50 IOException (java.io.IOException)12 ISE (io.druid.java.util.common.ISE)10 ByteBuffer (java.nio.ByteBuffer)10 Function (com.google.common.base.Function)5 DataSegment (io.druid.timeline.DataSegment)5 URI (java.net.URI)5 Interval (org.joda.time.Interval)5 File (java.io.File)4 Nullable (javax.annotation.Nullable)4 DateTime (org.joda.time.DateTime)4 ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ByteSource (com.google.common.io.ByteSource)2 Injector (com.google.inject.Injector)2 Request (com.metamx.http.client.Request)2