Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.indexing.seekablestream;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import org.apache.druid.common.guava.FutureUtils;
import org.apache.druid.indexer.TaskLocation;
import org.apache.druid.indexer.TaskStatus;
import org.apache.druid.indexing.common.RetryPolicy;
import org.apache.druid.indexing.common.RetryPolicyConfig;
import org.apache.druid.indexing.common.RetryPolicyFactory;
import org.apache.druid.indexing.common.TaskInfoProvider;
import org.apache.druid.java.util.common.Either;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.concurrent.Execs;
import org.apache.druid.java.util.common.jackson.JacksonUtils;
import org.apache.druid.java.util.emitter.EmittingLogger;
import org.apache.druid.java.util.http.client.response.BytesFullResponseHandler;
import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
import org.apache.druid.metadata.PendingSegmentRecord;
import org.apache.druid.rpc.HttpResponseException;
import org.apache.druid.rpc.IgnoreHttpResponseHandler;
import org.apache.druid.rpc.RequestBuilder;
import org.apache.druid.rpc.ServiceClient;
import org.apache.druid.rpc.ServiceClientFactory;
import org.apache.druid.rpc.ServiceClosedException;
import org.apache.druid.rpc.ServiceLocation;
import org.apache.druid.rpc.ServiceLocations;
import org.apache.druid.rpc.ServiceLocator;
import org.apache.druid.rpc.ServiceNotAvailableException;
import org.apache.druid.rpc.ServiceRetryPolicy;
import org.apache.druid.rpc.StandardRetryPolicy;
import org.apache.druid.rpc.indexing.SpecificTaskRetryPolicy;
import org.apache.druid.segment.incremental.ParseExceptionReport;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.Period;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
/**
* Implementation of {@link SeekableStreamIndexTaskClient} based on {@link ServiceClient}.
*/
public abstract class SeekableStreamIndexTaskClientAsyncImpl
implements SeekableStreamIndexTaskClient
{
private static final EmittingLogger log = new EmittingLogger(SeekableStreamIndexTaskClientAsyncImpl.class);
public static final int MIN_RETRY_WAIT_SECONDS = 2;
public static final int MAX_RETRY_WAIT_SECONDS = 10;
private final ServiceClientFactory serviceClientFactory;
private final TaskInfoProvider taskInfoProvider;
private final ObjectMapper jsonMapper;
private final Duration httpTimeout;
private final long httpRetries;
// Used by getOffsetsWhenPaused, due to special retry logic.
private final ScheduledExecutorService retryExec;
public SeekableStreamIndexTaskClientAsyncImpl(
final String dataSource,
final ServiceClientFactory serviceClientFactory,
final TaskInfoProvider taskInfoProvider,
final ObjectMapper jsonMapper,
final Duration httpTimeout,
final long httpRetries
)
{
this.serviceClientFactory = serviceClientFactory;
this.taskInfoProvider = taskInfoProvider;
this.jsonMapper = jsonMapper;
this.httpTimeout = httpTimeout;
this.httpRetries = httpRetries;
this.retryExec = Execs.scheduledSingleThreaded(
StringUtils.format(
"%s-%s-%%d",
getClass().getSimpleName(),
StringUtils.encodeForFormat(dataSource)
)
);
}
@Override
@SuppressWarnings("unchecked")
public ListenableFuture>> getCheckpointsAsync(
final String id,
final boolean retry
)
{
return makeRequest(id, new RequestBuilder(HttpMethod.GET, "/checkpoints"))
.handler(new BytesFullResponseHandler())
.onSuccess(r -> {
final TypeFactory factory = jsonMapper.getTypeFactory();
return (TreeMap>)
JacksonUtils.readValue(
jsonMapper,
r.getContent(),
factory.constructMapType(
TreeMap.class,
factory.constructType(Integer.class),
factory.constructMapType(Map.class, getPartitionType(), getSequenceType())
)
);
})
.onNotAvailable(e -> Either.value(new TreeMap<>()))
.retry(retry)
.go();
}
@Override
public ListenableFuture stopAsync(final String id, final boolean publish)
{
return makeRequest(id, new RequestBuilder(HttpMethod.POST, "/stop" + (publish ? "?publish=true" : "")))
.onSuccess(r -> true)
.onHttpError(e -> {
log.warn("Task [%s] coundln't be stopped because of http request failure [%s].", id, e.getMessage());
return Either.value(false);
})
.onNotAvailable(e -> {
log.warn("Task [%s] coundln't be stopped because it is not available.", id);
return Either.value(false);
})
.onClosed(e -> {
log.warn("Task [%s] couldn't be stopped because it is no longer running.", id);
return Either.value(true);
})
.go();
}
@Override
public ListenableFuture resumeAsync(final String id)
{
return makeRequest(id, new RequestBuilder(HttpMethod.POST, "/resume"))
.onSuccess(r -> true)
.onException(e -> Either.value(false))
.go();
}
@Override
public ListenableFuture