1   /*
2    * Copyright 2024 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package com.linecorp.centraldogma.server.internal.api;
18  
19  import static com.google.common.base.MoreObjects.firstNonNull;
20  import static java.util.Objects.requireNonNull;
21  
22  import java.util.Objects;
23  
24  import javax.annotation.Nullable;
25  
26  import com.fasterxml.jackson.annotation.JsonCreator;
27  import com.fasterxml.jackson.annotation.JsonProperty;
28  import com.google.common.base.MoreObjects;
29  
30  import com.linecorp.centraldogma.server.management.ServerStatus;
31  
32  public final class UpdateServerStatusRequest {
33      private final ServerStatus serverStatus;
34      private final Scope scope;
35  
36      @JsonCreator
37      public UpdateServerStatusRequest(@JsonProperty("serverStatus") ServerStatus serverStatus,
38                                       @JsonProperty("scope") @Nullable Scope scope) {
39          this.serverStatus = requireNonNull(serverStatus, "serverStatus");
40          this.scope = firstNonNull(scope, Scope.ALL);
41      }
42  
43      @JsonProperty("serverStatus")
44      public ServerStatus serverStatus() {
45          return serverStatus;
46      }
47  
48      @JsonProperty("scope")
49      public Scope scope() {
50          return scope;
51      }
52  
53      @Override
54      public boolean equals(Object o) {
55          if (this == o) {
56              return true;
57          }
58          if (!(o instanceof UpdateServerStatusRequest)) {
59              return false;
60          }
61          final UpdateServerStatusRequest that = (UpdateServerStatusRequest) o;
62          return serverStatus == that.serverStatus && scope == that.scope;
63      }
64  
65      @Override
66      public int hashCode() {
67          return Objects.hash(serverStatus, scope);
68      }
69  
70      @Override
71      public String toString() {
72          return MoreObjects.toStringHelper(this)
73                            .add("serverStatus", serverStatus)
74                            .add("scope", scope)
75                            .toString();
76      }
77  
78      public enum Scope {
79          LOCAL, ALL
80      }
81  }