![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.druid.client.ServerViewUtil Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.druid.client;
import org.apache.druid.client.selector.ServerSelector;
import org.apache.druid.query.DataSource;
import org.apache.druid.query.LocatedSegmentDescriptor;
import org.apache.druid.query.SegmentDescriptor;
import org.apache.druid.query.TableDataSource;
import org.apache.druid.query.planning.DataSourceAnalysis;
import org.apache.druid.server.coordination.DruidServerMetadata;
import org.apache.druid.timeline.TimelineLookup;
import org.apache.druid.timeline.TimelineObjectHolder;
import org.apache.druid.timeline.partition.PartitionChunk;
import org.joda.time.Interval;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
/**
*/
public class ServerViewUtil
{
public static List getTargetLocations(
TimelineServerView serverView,
String datasource,
List intervals,
int numCandidates
)
{
return getTargetLocations(serverView, new TableDataSource(datasource), intervals, numCandidates);
}
public static List getTargetLocations(
TimelineServerView serverView,
DataSource datasource,
List intervals,
int numCandidates
)
{
final DataSourceAnalysis analysis = datasource.getAnalysis();
final Optional extends TimelineLookup> maybeTimeline = serverView.getTimeline(analysis);
if (!maybeTimeline.isPresent()) {
return Collections.emptyList();
}
List located = new ArrayList<>();
for (Interval interval : intervals) {
for (TimelineObjectHolder holder : maybeTimeline.get().lookup(interval)) {
for (PartitionChunk chunk : holder.getObject()) {
ServerSelector selector = chunk.getObject();
final SegmentDescriptor descriptor = new SegmentDescriptor(
holder.getInterval(), holder.getVersion(), chunk.getChunkNumber()
);
long size = selector.getSegment().getSize();
List candidates = selector.getCandidates(numCandidates);
located.add(new LocatedSegmentDescriptor(descriptor, size, candidates));
}
}
}
return located;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy