1   /*
2    * Copyright 2023 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.command;
18  
19  import java.util.Objects;
20  
21  import javax.annotation.Nullable;
22  
23  import com.fasterxml.jackson.annotation.JsonCreator;
24  import com.fasterxml.jackson.annotation.JsonInclude;
25  import com.fasterxml.jackson.annotation.JsonInclude.Include;
26  import com.fasterxml.jackson.annotation.JsonProperty;
27  import com.google.common.base.MoreObjects.ToStringHelper;
28  
29  import com.linecorp.centraldogma.common.Author;
30  import com.linecorp.centraldogma.server.management.ServerStatus;
31  
32  /**
33   * A {@link Command} which is used to update the status of all servers in the cluster.
34   */
35  @JsonInclude(Include.NON_NULL)
36  public final class UpdateServerStatusCommand extends AdministrativeCommand<Void> {
37  
38      private final ServerStatus serverStatus;
39  
40      /**
41       * Creates a new instance with the specified properties.
42       */
43      @JsonCreator
44      public UpdateServerStatusCommand(@JsonProperty("timestamp") @Nullable Long timestamp,
45                                       @JsonProperty("author") @Nullable Author author,
46                                       @JsonProperty("serverStatus") ServerStatus serverStatus) {
47          super(CommandType.UPDATE_SERVER_STATUS, timestamp, author);
48          this.serverStatus = serverStatus;
49      }
50  
51      /**
52       * Returns the status of the server.
53       */
54      @JsonProperty("serverStatus")
55      public ServerStatus serverStatus() {
56          return serverStatus;
57      }
58  
59      @Override
60      public boolean equals(Object o) {
61          if (this == o) {
62              return true;
63          }
64          if (!(o instanceof UpdateServerStatusCommand)) {
65              return false;
66          }
67          final UpdateServerStatusCommand that = (UpdateServerStatusCommand) o;
68  
69          return super.equals(that) && serverStatus == that.serverStatus;
70      }
71  
72      @Override
73      public int hashCode() {
74          return Objects.hash(super.hashCode(), serverStatus);
75      }
76  
77      @Override
78      ToStringHelper toStringHelper() {
79          return super.toStringHelper()
80                      .add("serverStatus", serverStatus);
81      }
82  }