|  | 
|  | 1 | +/* | 
|  | 2 | + * SPDX-License-Identifier: Apache-2.0 | 
|  | 3 | + * | 
|  | 4 | + * The OpenSearch Contributors require contributions made to | 
|  | 5 | + * this file be licensed under the Apache-2.0 license or a | 
|  | 6 | + * compatible open source license. | 
|  | 7 | + */ | 
|  | 8 | + | 
|  | 9 | +/* | 
|  | 10 | + * Licensed to Elasticsearch under one or more contributor | 
|  | 11 | + * license agreements. See the NOTICE file distributed with | 
|  | 12 | + * this work for additional information regarding copyright | 
|  | 13 | + * ownership. Elasticsearch licenses this file to you under | 
|  | 14 | + * the Apache License, Version 2.0 (the "License"); you may | 
|  | 15 | + * not use this file except in compliance with the License. | 
|  | 16 | + * You may obtain a copy of the License at | 
|  | 17 | + * | 
|  | 18 | + *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 19 | + * | 
|  | 20 | + * Unless required by applicable law or agreed to in writing, | 
|  | 21 | + * software distributed under the License is distributed on an | 
|  | 22 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
|  | 23 | + * KIND, either express or implied.  See the License for the | 
|  | 24 | + * specific language governing permissions and limitations | 
|  | 25 | + * under the License. | 
|  | 26 | + */ | 
|  | 27 | + | 
|  | 28 | +/* | 
|  | 29 | + * Modifications Copyright OpenSearch Contributors. See | 
|  | 30 | + * GitHub history for details. | 
|  | 31 | + */ | 
|  | 32 | + | 
|  | 33 | +package org.opensearch.action.support.clustermanager; | 
|  | 34 | + | 
|  | 35 | +import org.opensearch.action.ActionRequest; | 
|  | 36 | +import org.opensearch.action.ActionRequestValidationException; | 
|  | 37 | +import org.opensearch.cluster.ack.AckedRequest; | 
|  | 38 | +import org.opensearch.common.unit.TimeValue; | 
|  | 39 | +import org.opensearch.core.common.io.stream.StreamInput; | 
|  | 40 | +import org.opensearch.core.common.io.stream.StreamOutput; | 
|  | 41 | +import static org.opensearch.common.unit.TimeValue.timeValueSeconds; | 
|  | 42 | + | 
|  | 43 | + | 
|  | 44 | +import java.io.IOException; | 
|  | 45 | + | 
|  | 46 | +/** | 
|  | 47 | + * A base request for cluster-manager based operations. | 
|  | 48 | + * It is similar to ClusterManagerNodeRequest, but extends ActionRequest and AckedRequest. | 
|  | 49 | + * @opensearch.api | 
|  | 50 | + */ | 
|  | 51 | +public abstract class ClusterManagerNodeAckRequest extends ActionRequest implements AckedRequest { | 
|  | 52 | + | 
|  | 53 | +    public static final TimeValue DEFAULT_CLUSTER_MANAGER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30); | 
|  | 54 | +    protected TimeValue clusterManagerNodeTimeout = DEFAULT_CLUSTER_MANAGER_NODE_TIMEOUT; | 
|  | 55 | +    protected TimeValue masterNodeTimeout = clusterManagerNodeTimeout; | 
|  | 56 | +    public static final TimeValue DEFAULT_ACK_TIMEOUT = timeValueSeconds(30); | 
|  | 57 | +    protected TimeValue timeout = DEFAULT_ACK_TIMEOUT; | 
|  | 58 | + | 
|  | 59 | +    protected ClusterManagerNodeAckRequest() {} | 
|  | 60 | + | 
|  | 61 | +    protected ClusterManagerNodeAckRequest(StreamInput in) throws IOException { | 
|  | 62 | +        super(in); | 
|  | 63 | +        clusterManagerNodeTimeout = in.readTimeValue(); | 
|  | 64 | +    } | 
|  | 65 | + | 
|  | 66 | +    @Override | 
|  | 67 | +    public void writeTo(StreamOutput out) throws IOException { | 
|  | 68 | +        super.writeTo(out); | 
|  | 69 | +        out.writeTimeValue(clusterManagerNodeTimeout); | 
|  | 70 | +    } | 
|  | 71 | + | 
|  | 72 | +    /** | 
|  | 73 | +     * A timeout value in case the cluster-manager has not been discovered yet or disconnected. | 
|  | 74 | +     */ | 
|  | 75 | +    @SuppressWarnings("unchecked") | 
|  | 76 | +    public final ClusterManagerNodeAckRequest clusterManagerNodeTimeout(TimeValue timeout) { | 
|  | 77 | +        this.clusterManagerNodeTimeout = timeout; | 
|  | 78 | +        return this; | 
|  | 79 | +    } | 
|  | 80 | + | 
|  | 81 | +    /** | 
|  | 82 | +     * A timeout value in case the cluster-manager has not been discovered yet or disconnected. | 
|  | 83 | +     */ | 
|  | 84 | +    public final ClusterManagerNodeAckRequest clusterManagerNodeTimeout(String timeout) { | 
|  | 85 | +        return clusterManagerNodeTimeout( | 
|  | 86 | +            TimeValue.parseTimeValue(timeout, null, getClass().getSimpleName() + ".clusterManagerNodeTimeout") | 
|  | 87 | +        ); | 
|  | 88 | +    } | 
|  | 89 | + | 
|  | 90 | +    public final TimeValue clusterManagerNodeTimeout() { | 
|  | 91 | +        return this.clusterManagerNodeTimeout; | 
|  | 92 | +    } | 
|  | 93 | + | 
|  | 94 | +    /** @deprecated As of 2.1, because supporting inclusive language, replaced by {@link #clusterManagerNodeTimeout()} */ | 
|  | 95 | +    @Deprecated | 
|  | 96 | +    public final TimeValue masterNodeTimeout() { | 
|  | 97 | +        return clusterManagerNodeTimeout(); | 
|  | 98 | +    } | 
|  | 99 | + | 
|  | 100 | +    @Override | 
|  | 101 | +    public ActionRequestValidationException validate() { | 
|  | 102 | +        return null; | 
|  | 103 | +    } | 
|  | 104 | +    @Override | 
|  | 105 | +    public TimeValue ackTimeout() { | 
|  | 106 | +        return this.timeout; | 
|  | 107 | +    } | 
|  | 108 | +} | 
0 commit comments