001/*
002 * Copyright 2022-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2022-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2022-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.logs.v2.json;
037
038
039
040import com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType;
041import com.unboundid.ldap.sdk.unboundidds.logs.LogException;
042import com.unboundid.ldap.sdk.unboundidds.logs.v2.
043            EntryRebalancingRequestAccessLogMessage;
044import com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField;
045import com.unboundid.util.NotExtensible;
046import com.unboundid.util.NotMutable;
047import com.unboundid.util.NotNull;
048import com.unboundid.util.Nullable;
049import com.unboundid.util.ThreadSafety;
050import com.unboundid.util.ThreadSafetyLevel;
051import com.unboundid.util.json.JSONObject;
052
053
054
055/**
056 * This class provides a data structure that holds information about a
057 * JSON-formatted entry rebalancing request access log message.
058 * <BR>
059 * <BLOCKQUOTE>
060 *   <B>NOTE:</B>  This class, and other classes within the
061 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
062 *   supported for use against Ping Identity, UnboundID, and
063 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
064 *   for proprietary functionality or for external specifications that are not
065 *   considered stable or mature enough to be guaranteed to work in an
066 *   interoperable way with other types of LDAP servers.
067 * </BLOCKQUOTE>
068 */
069@NotExtensible()
070@NotMutable()
071@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
072public class JSONEntryRebalancingRequestAccessLogMessage
073       extends JSONAccessLogMessage
074       implements EntryRebalancingRequestAccessLogMessage
075{
076  /**
077   * The serial version UID for this serializable class.
078   */
079  private static final long serialVersionUID = 144849488576686304L;
080
081
082
083  // The size limit for this log message.
084  @Nullable private final Integer sizeLimit;
085
086  // The rebalancing operation ID for this log message.
087  @Nullable private final Long rebalancingOperationID;
088
089  // The triggered by connection ID for this log message.
090  @Nullable private final Long triggeredByConnectionID;
091
092  // The triggered by operation ID for this log message.
093  @Nullable private final Long triggeredByOperationID;
094
095  // The source backend server for this log message.
096  @Nullable private final String sourceBackendServer;
097
098  // The source backend set name for this log message.
099  @Nullable private final String sourceBackendSetName;
100
101  // The subtree base DN for this log message.
102  @Nullable private final String subtreeBaseDN;
103
104  // The target backend server for this log message.
105  @Nullable private final String targetBackendServer;
106
107  // The target backend set name for this log message.
108  @Nullable private final String targetBackendSetName;
109
110
111
112  /**
113   * Creates a new JSON entry rebalancing request access log message from the
114   * provided JSON object.
115   *
116   * @param  jsonObject  The JSON object that contains an encoded representation
117   *                     of this log message.  It must not be {@code null}.
118   *
119   * @throws  LogException  If the provided JSON object cannot be parsed as a
120   *                        valid log message.
121   */
122  public JSONEntryRebalancingRequestAccessLogMessage(
123              @NotNull final JSONObject jsonObject)
124         throws LogException
125  {
126    super(jsonObject);
127
128    rebalancingOperationID = getLongNoThrow(
129         JSONFormattedAccessLogFields.ENTRY_REBALANCING_OPERATION_ID);
130    triggeredByConnectionID = getLongNoThrow(
131         JSONFormattedAccessLogFields.TRIGGERED_BY_CONNECTION_ID);
132    triggeredByOperationID = getLongNoThrow(
133         JSONFormattedAccessLogFields.TRIGGERED_BY_OPERATION_ID);
134    subtreeBaseDN = getString(
135         JSONFormattedAccessLogFields.ENTRY_REBALANCING_BASE_DN);
136    sizeLimit = getIntegerNoThrow(
137         JSONFormattedAccessLogFields.ENTRY_REBALANCING_SIZE_LIMIT);
138    sourceBackendSetName = getString(
139         JSONFormattedAccessLogFields.ENTRY_REBALANCING_SOURCE_BACKEND_SET);
140    sourceBackendServer = getBackendServer(jsonObject,
141         JSONFormattedAccessLogFields.ENTRY_REBALANCING_SOURCE_SERVER);
142    targetBackendSetName = getString(
143         JSONFormattedAccessLogFields.ENTRY_REBALANCING_TARGET_BACKEND_SET);
144    targetBackendServer = getBackendServer(jsonObject,
145         JSONFormattedAccessLogFields.ENTRY_REBALANCING_TARGET_SERVER);
146  }
147
148
149
150  /**
151   * Retrieves a string representation of the backend server indicated by the
152   * specified field in the given JSON object.
153   *
154   * @param  jsonObject  The JSON object that contains an encoded representation
155   *                     of this log message.  It must not be {@code null}.
156   * @param  logField    The log field from which to obtain the information
157   *                     about the backend server.
158   *
159   * @return  A string representation of the backend server indicated by the
160   *          specified field in the given JSON object, or {@code null} if it is
161   *          not included in the log message.
162   */
163  @Nullable()
164  private static String getBackendServer(@NotNull final JSONObject jsonObject,
165                                         @NotNull final LogField logField)
166  {
167    final JSONObject serverObject =
168         jsonObject.getFieldAsObject(logField.getFieldName());
169    if (serverObject == null)
170    {
171      return null;
172    }
173
174    final String address = serverObject.getFieldAsString(
175         JSONFormattedAccessLogFields.ENTRY_REBALANCING_SOURCE_SERVER_ADDRESS.
176              getFieldName());
177    if (address == null)
178    {
179      return null;
180    }
181
182    final Integer port = serverObject.getFieldAsInteger(
183         JSONFormattedAccessLogFields.ENTRY_REBALANCING_SOURCE_SERVER_PORT.
184              getFieldName());
185    if (port == null)
186    {
187      return address;
188    }
189    else
190    {
191      return address + ':' + port;
192    }
193  }
194
195
196
197  /**
198   * {@inheritDoc}
199   */
200  @Override()
201  @NotNull()
202  public AccessLogMessageType getMessageType()
203  {
204    return AccessLogMessageType.ENTRY_REBALANCING_REQUEST;
205  }
206
207
208
209  /**
210   * {@inheritDoc}
211   */
212  @Override()
213  @Nullable()
214  public final Long getRebalancingOperationID()
215  {
216    return rebalancingOperationID;
217  }
218
219
220
221  /**
222   * {@inheritDoc}
223   */
224  @Override()
225  @Nullable()
226  public final Long getTriggeredByConnectionID()
227  {
228    return triggeredByConnectionID;
229  }
230
231
232
233
234  /**
235   * {@inheritDoc}
236   */
237  @Override()
238  @Nullable()
239  public final Long getTriggeredByOperationID()
240  {
241    return triggeredByOperationID;
242  }
243
244
245
246  /**
247   * {@inheritDoc}
248   */
249  @Override()
250  @Nullable()
251  public final String getSubtreeBaseDN()
252  {
253    return subtreeBaseDN;
254  }
255
256
257
258  /**
259   * {@inheritDoc}
260   */
261  @Override()
262  @Nullable()
263  public final Integer getSizeLimit()
264  {
265    return sizeLimit;
266  }
267
268
269
270  /**
271   * {@inheritDoc}
272   */
273  @Override()
274  @Nullable()
275  public final String getSourceBackendSetName()
276  {
277    return sourceBackendSetName;
278  }
279
280
281
282  /**
283   * {@inheritDoc}
284   */
285  @Override()
286  @Nullable()
287  public final String getSourceBackendServer()
288  {
289    return sourceBackendServer;
290  }
291
292
293
294  /**
295   * {@inheritDoc}
296   */
297  @Override()
298  @Nullable()
299  public final String getTargetBackendSetName()
300  {
301    return targetBackendSetName;
302  }
303
304
305
306  /**
307   * {@inheritDoc}
308   */
309  @Override()
310  @Nullable()
311  public final String getTargetBackendServer()
312  {
313    return targetBackendServer;
314  }
315}