Search in sources :

Example 36 with BiConsumer

use of java.util.function.BiConsumer in project photon-model by vmware.

the class AWSEndpointAdapterService method computeDesc.

private BiConsumer<ComputeDescription, Retriever> computeDesc() {
    return (cd, r) -> {
        cd.regionId = r.get(REGION_KEY).orElse(null);
        cd.zoneId = r.get(ZONE_KEY).orElse(null);
        cd.environmentName = ComputeDescription.ENVIRONMENT_NAME_AWS;
        List<String> children = new ArrayList<>();
        children.add(ComputeType.ZONE.toString());
        cd.supportedChildren = children;
        cd.instanceAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_INSTANCE_ADAPTER);
        cd.enumerationAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_ENUMERATION_ADAPTER);
        cd.powerAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_POWER_ADAPTER);
        cd.diskAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_DISK_ADAPTER);
        {
            URI statsAdapterUri = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_STATS_ADAPTER);
            URI costStatsAdapterUri = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_COST_STATS_ADAPTER);
            cd.statsAdapterReferences = new LinkedHashSet<>();
            cd.statsAdapterReferences.add(costStatsAdapterUri);
            cd.statsAdapterReferences.add(statsAdapterUri);
            cd.statsAdapterReference = statsAdapterUri;
        }
    };
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) Utils(com.vmware.xenon.common.Utils) AmazonIdentityManagementClientBuilder(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE) EXTERNAL_ID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY) URI(java.net.URI) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AmazonServiceException(com.amazonaws.AmazonServiceException) StatelessService(com.vmware.xenon.common.StatelessService) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) STATUS_CODE_UNAUTHORIZED(com.vmware.xenon.common.Operation.STATUS_CODE_UNAUTHORIZED) AWSUtils.getEc2AsyncClient(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getEc2AsyncClient) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) HashMap(java.util.HashMap) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) ArrayList(java.util.ArrayList) Regions(com.amazonaws.regions.Regions) ZONE_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ZONE_KEY) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) BiConsumer(java.util.function.BiConsumer) Retriever(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils.Retriever) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) LinkedHashSet(java.util.LinkedHashSet) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) EndpointAdapterUtils(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) AmazonIdentityManagementClient(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient) ARN_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) REGION_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.REGION_KEY) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) List(java.util.List) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 37 with BiConsumer

use of java.util.function.BiConsumer in project photon-model by vmware.

the class EndpointAdapterUtils method configureEndpoint.

private static void configureEndpoint(StatelessService service, EndpointConfigRequest body, BiConsumer<AuthCredentialsServiceState, Retriever> credEnhancer, BiConsumer<ComputeDescription, Retriever> descEnhancer, BiConsumer<ComputeState, Retriever> compEnhancer, BiConsumer<EndpointState, Retriever> endpointEnhancer) {
    TaskManager tm = new TaskManager(service, body.taskReference, body.resourceLink());
    Consumer<Throwable> onFailure = tm::patchTaskToFailure;
    Consumer<Operation> onSuccess = (op) -> {
        EndpointState endpoint = op.getBody(EndpointState.class);
        op.complete();
        AuthCredentialsServiceState authState = new AuthCredentialsServiceState();
        Map<String, String> props = new HashMap<>(body.endpointProperties);
        props.put(MOCK_REQUEST, String.valueOf(body.isMockRequest));
        props.put(ENDPOINT_REFERENCE_URI, body.resourceReference.toString());
        Retriever r = Retriever.of(props);
        try {
            credEnhancer.accept(authState, r);
            ComputeDescription cd = new ComputeDescription();
            descEnhancer.accept(cd, r);
            ComputeState cs = new ComputeState();
            cs.powerState = PowerState.ON;
            compEnhancer.accept(cs, r);
            EndpointState es = new EndpointState();
            es.endpointProperties = new HashMap<>();
            es.regionId = r.get(EndpointConfigRequest.REGION_KEY).orElse(null);
            endpointEnhancer.accept(es, r);
            Stream<Operation> operations = Stream.of(Pair.of(authState, endpoint.authCredentialsLink), Pair.of(cd, endpoint.computeDescriptionLink), Pair.of(cs, endpoint.computeLink), Pair.of(es, endpoint.documentSelfLink)).map((p) -> Operation.createPatch(createInventoryUri(service.getHost(), p.right)).setBody(p.left).setReferer(service.getUri()));
            applyChanges(tm, service, endpoint, operations);
        } catch (Exception e) {
            tm.patchTaskToFailure(e);
        }
    };
    AdapterUtils.getServiceState(service, body.resourceReference, onSuccess, onFailure);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) HashMap(java.util.HashMap) ServiceEndpointLocator(com.vmware.photon.controller.model.util.ServiceEndpointLocator) Level(java.util.logging.Level) Utils(com.vmware.xenon.common.Utils) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) INVENTORY_SERVICE(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) Consumer(java.util.function.Consumer) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) Stream(java.util.stream.Stream) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils.buildUri(com.vmware.xenon.common.UriUtils.buildUri) Optional(java.util.Optional) PhotonModelAdaptersRegistryService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Operation(com.vmware.xenon.common.Operation) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Stream(java.util.stream.Stream) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 38 with BiConsumer

use of java.util.function.BiConsumer in project photon-model by vmware.

the class VSphereAdapterSnapshotService method performSnapshotOperation.

private DeferredResult<SnapshotContext> performSnapshotOperation(SnapshotContext context) {
    DeferredResult<SnapshotContext> result = new DeferredResult<>();
    VSphereIOThreadPool pool = VSphereIOThreadPoolAllocator.getPool(this);
    DeferredResult<AuthCredentialsService.AuthCredentialsServiceState> credentials;
    if (IAAS_API_ENABLED) {
        credentials = SessionUtil.retrieveExternalToken(this, context.operation.getAuthorizationContext());
    } else {
        URI authUri = createInventoryUri(this.getHost(), context.parentComputeDescription.description.authCredentialsLink);
        Operation op = Operation.createGet(authUri);
        credentials = this.sendWithDeferredResult(op, AuthCredentialsService.AuthCredentialsServiceState.class);
    }
    switch(context.requestType) {
        case CREATE:
            BiConsumer<AuthCredentialsService.AuthCredentialsServiceState, Throwable> create = (authCredentialsServiceState, throwable) -> {
                if (throwable != null) {
                    result.fail(throwable);
                    return;
                }
                pool.submit(context.parentComputeDescription.adapterManagementReference, authCredentialsServiceState, (connection, e) -> {
                    if (e != null) {
                        result.fail(e);
                    } else {
                        createSnapshot(connection, context, result);
                    }
                });
            };
            credentials.whenComplete(create);
            break;
        case DELETE:
            BiConsumer<AuthCredentialsService.AuthCredentialsServiceState, Throwable> delete = (authCredentialsServiceState, throwable) -> {
                if (throwable != null) {
                    result.fail(throwable);
                    return;
                }
                pool.submit(context.parentComputeDescription.adapterManagementReference, authCredentialsServiceState, (connection, e) -> {
                    if (e != null) {
                        result.fail(e);
                    } else {
                        deleteSnapshot(context, connection, result);
                    }
                });
            };
            credentials.whenComplete(delete);
            break;
        case REVERT:
            BiConsumer<AuthCredentialsService.AuthCredentialsServiceState, Throwable> revert = (authCredentialsServiceState, throwable) -> {
                if (throwable != null) {
                    result.fail(throwable);
                    return;
                }
                pool.submit(context.parentComputeDescription.adapterManagementReference, authCredentialsServiceState, (connection, e) -> {
                    if (e != null) {
                        result.fail(e);
                    } else {
                        revertSnapshot(context, connection, result);
                    }
                });
            };
            credentials.whenComplete(revert);
            break;
        default:
            result.fail(new IllegalStateException("Unsupported requestType " + context.requestType));
    }
    return result;
}
Also used : Service(com.vmware.xenon.common.Service) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) SessionUtil(com.vmware.photon.controller.model.resources.SessionUtil) ResourceOperationUtils.handleAdapterResourceOperationRegistration(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceOperationSpecService(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) StringUtils(org.apache.commons.lang3.StringUtils) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ArrayList(java.util.ArrayList) TargetCriteria(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.TargetCriteria) Utils(com.vmware.xenon.common.Utils) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) SnapshotRequestType(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotRequestType) BiConsumer(java.util.function.BiConsumer) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) TaskInfo(com.vmware.vim25.TaskInfo) OperationSequence(com.vmware.xenon.common.OperationSequence) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) MapUtils(org.apache.commons.collections.MapUtils) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) List(java.util.List) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) Optional(java.util.Optional) VSphereConstants(com.vmware.photon.controller.model.adapters.vsphere.constants.VSphereConstants) FactoryService(com.vmware.xenon.common.FactoryService) IAAS_API_ENABLED(com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED) TaskInfoState(com.vmware.vim25.TaskInfoState) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) Operation(com.vmware.xenon.common.Operation) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) URI(java.net.URI) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 39 with BiConsumer

use of java.util.function.BiConsumer in project cdap by caskdata.

the class AbstractSparkSubmitter method createSubmitArguments.

/**
 * Creates the list of arguments that will be used for calling {@link SparkSubmit#main(String[])}.
 *
 * @param runtimeContext the {@link SparkRuntimeContext} for the spark program
 * @param configs set of Spark configurations
 * @param resources list of resources that needs to be localized to Spark containers
 * @param jobFile the job file for Spark
 * @return a list of arguments
 */
private List<String> createSubmitArguments(SparkRuntimeContext runtimeContext, Map<String, String> configs, List<LocalizeResource> resources, URI jobFile) {
    SparkSpecification spec = runtimeContext.getSparkSpecification();
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    addMaster(configs, builder);
    builder.add("--conf").add("spark.app.name=" + spec.getName());
    BiConsumer<String, String> confAdder = (k, v) -> builder.add("--conf").add(k + "=" + v);
    configs.forEach(confAdder);
    getSubmitConf().forEach(confAdder);
    String archives = Joiner.on(',').join(Iterables.transform(Iterables.filter(resources, ARCHIVE_FILTER), RESOURCE_TO_PATH));
    String files = Joiner.on(',').join(Iterables.transform(Iterables.filter(resources, Predicates.not(ARCHIVE_FILTER)), RESOURCE_TO_PATH));
    if (!archives.isEmpty()) {
        builder.add("--archives").add(archives);
    }
    if (!files.isEmpty()) {
        builder.add("--files").add(files);
    }
    boolean isPySpark = jobFile.getPath().endsWith(".py");
    if (isPySpark) {
        // For python, add extra py library files
        String pyFiles = configs.get("spark.submit.pyFiles");
        if (pyFiles != null) {
            builder.add("--py-files").add(pyFiles);
        }
    } else {
        builder.add("--class").add(SparkMainWrapper.class.getName());
    }
    if ("file".equals(jobFile.getScheme())) {
        builder.add(jobFile.getPath());
    } else {
        builder.add(jobFile.toString());
    }
    if (!isPySpark) {
        // Add extra arguments for easily identifying the program from command line.
        // Arguments to user program is always coming from the runtime arguments.
        builder.add("--cdap.spark.program=" + runtimeContext.getProgramRunId().toString());
        builder.add("--cdap.user.main.class=" + spec.getMainClassName());
    }
    return builder.build();
}
Also used : Iterables(com.google.common.collect.Iterables) Arrays(java.util.Arrays) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SparkSpecification(co.cask.cdap.api.spark.SparkSpecification) SparkMainWrapper(co.cask.cdap.app.runtime.spark.SparkMainWrapper) Future(java.util.concurrent.Future) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Predicates(com.google.common.base.Predicates) URI(java.net.URI) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) ClassLoaders(co.cask.cdap.common.lang.ClassLoaders) Function(com.google.common.base.Function) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) SparkSubmit(org.apache.spark.deploy.SparkSubmit) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) SparkRuntimeContext(co.cask.cdap.app.runtime.spark.SparkRuntimeContext) Predicate(com.google.common.base.Predicate) LocalizeResource(co.cask.cdap.internal.app.runtime.distributed.LocalizeResource) Collections(java.util.Collections) AbstractFuture(com.google.common.util.concurrent.AbstractFuture) Joiner(com.google.common.base.Joiner) SparkSpecification(co.cask.cdap.api.spark.SparkSpecification) SparkMainWrapper(co.cask.cdap.app.runtime.spark.SparkMainWrapper) ImmutableList(com.google.common.collect.ImmutableList)

Example 40 with BiConsumer

use of java.util.function.BiConsumer in project elasticsearch-indexing-proxy by codelibs.

the class IndexingProxyService method updateWriterNode.

private void updateWriterNode(final long version, final List<DiscoveryNode> nodeList, final BiConsumer<UpdateResponse, Exception> consumer) {
    if (logger.isDebugEnabled()) {
        logger.debug("No available write node.");
    }
    Collections.shuffle(nodeList);
    final DiscoveryNode nextNode = nodeList.get(0);
    final Map<String, Object> source = new HashMap<>();
    source.put(IndexingProxyPlugin.NODE_NAME, nextNode.getName());
    source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
    client.prepareUpdate(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, FILE_ID).setVersion(version).setDoc(source).setRefreshPolicy(RefreshPolicy.WAIT_UNTIL).execute(wrap(res -> {
        randomWait();
        consumer.accept(res, null);
    }, ex -> {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to update file_id.", ex);
        }
        randomWait();
        consumer.accept(null, ex);
    }));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexingProxyPlugin(org.codelibs.elasticsearch.idxproxy.IndexingProxyPlugin) Arrays(java.util.Arrays) Date(java.util.Date) WriteRequestHandler(org.codelibs.elasticsearch.idxproxy.action.WriteRequestHandler) Environment(org.elasticsearch.env.Environment) FileTime(java.nio.file.attribute.FileTime) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) JsonXContent(org.elasticsearch.common.xcontent.json.JsonXContent) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) LifecycleListener(org.elasticsearch.common.component.LifecycleListener) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) Streams(org.elasticsearch.common.io.Streams) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Path(java.nio.file.Path) RefreshPolicy(org.elasticsearch.action.support.WriteRequest.RefreshPolicy) CreateRequest(org.codelibs.elasticsearch.idxproxy.action.CreateRequest) WriteResponse(org.codelibs.elasticsearch.idxproxy.action.WriteResponse) SearchHit(org.elasticsearch.search.SearchHit) ActionRequest(org.elasticsearch.action.ActionRequest) ActionFilter(org.elasticsearch.action.support.ActionFilter) ActionFilters(org.elasticsearch.action.support.ActionFilters) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Reader(java.io.Reader) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) IndexingProxyStreamInput(org.codelibs.elasticsearch.idxproxy.stream.IndexingProxyStreamInput) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) Strings(org.apache.logging.log4j.util.Strings) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) AccessController(java.security.AccessController) TransportException(org.elasticsearch.transport.TransportException) ProxyActionFilter(org.codelibs.elasticsearch.idxproxy.action.ProxyActionFilter) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) CreateRequestHandler(org.codelibs.elasticsearch.idxproxy.action.CreateRequestHandler) ClusterService(org.elasticsearch.cluster.service.ClusterService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UpdateRequestBuilder(org.elasticsearch.action.update.UpdateRequestBuilder) ActionListener.wrap(org.elasticsearch.action.ActionListener.wrap) HashMap(java.util.HashMap) IndexingProxyStreamOutput(org.codelibs.elasticsearch.idxproxy.stream.IndexingProxyStreamOutput) Names(org.elasticsearch.threadpool.ThreadPool.Names) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Inject(org.elasticsearch.common.inject.Inject) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) RequestUtils(org.codelibs.elasticsearch.idxproxy.util.RequestUtils) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) TimeValue(org.elasticsearch.common.unit.TimeValue) BiConsumer(java.util.function.BiConsumer) Result(org.elasticsearch.action.DocWriteResponse.Result) TransportService(org.elasticsearch.transport.TransportService) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) CreateResponse(org.codelibs.elasticsearch.idxproxy.action.CreateResponse) RequestSender(org.codelibs.elasticsearch.idxproxy.sender.RequestSender) FileAccessUtils(org.codelibs.elasticsearch.idxproxy.util.FileAccessUtils) PluginComponent(org.codelibs.elasticsearch.idxproxy.IndexingProxyPlugin.PluginComponent) Iterator(java.util.Iterator) Files(java.nio.file.Files) ActionResponse(org.elasticsearch.action.ActionResponse) Client(org.elasticsearch.client.Client) IOException(java.io.IOException) PingResponse(org.codelibs.elasticsearch.idxproxy.action.PingResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) InputStreamReader(java.io.InputStreamReader) AbstractLifecycleComponent(org.elasticsearch.common.component.AbstractLifecycleComponent) PingRequest(org.codelibs.elasticsearch.idxproxy.action.PingRequest) Consumer(java.util.function.Consumer) LocalNodeMasterListener(org.elasticsearch.cluster.LocalNodeMasterListener) Paths(java.nio.file.Paths) WriteRequest(org.codelibs.elasticsearch.idxproxy.action.WriteRequest) PingRequestHandler(org.codelibs.elasticsearch.idxproxy.action.PingRequestHandler) Collections(java.util.Collections) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ActionListener(org.elasticsearch.action.ActionListener) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Date(java.util.Date)

Aggregations

BiConsumer (java.util.function.BiConsumer)264 Test (org.junit.Test)111 List (java.util.List)109 Map (java.util.Map)79 IOException (java.io.IOException)78 ArrayList (java.util.ArrayList)74 Consumer (java.util.function.Consumer)71 HashMap (java.util.HashMap)66 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)54 Collectors (java.util.stream.Collectors)53 CountDownLatch (java.util.concurrent.CountDownLatch)52 Collections (java.util.Collections)46 Set (java.util.Set)46 Collection (java.util.Collection)45 Arrays (java.util.Arrays)44 TimeUnit (java.util.concurrent.TimeUnit)43 Function (java.util.function.Function)43 Assert (org.junit.Assert)43 Optional (java.util.Optional)41 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)35