001/*
002 * Copyright 2010-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.tasks;
022
023
024
025import java.util.Collections;
026import java.util.Date;
027import java.util.LinkedHashMap;
028import java.util.List;
029import java.util.Map;
030
031import com.unboundid.ldap.sdk.Attribute;
032import com.unboundid.ldap.sdk.Entry;
033import com.unboundid.util.NotMutable;
034import com.unboundid.util.ThreadSafety;
035import com.unboundid.util.ThreadSafetyLevel;
036import com.unboundid.util.Validator;
037
038import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
039
040
041
042/**
043 * This class defines a Directory Server task that can be used to dump
044 * information about the contents of a backend which stores its data in a
045 * Berkeley DB Java Edition database.  It reports information about the total
046 * number of keys, total and average key size, and total an average value size
047 * for all of the databases in the environment, and the percentage of the total
048 * live data size contained in each database.
049 * <BR>
050 * <BLOCKQUOTE>
051 *   <B>NOTE:</B>  This class, and other classes within the
052 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
053 *   supported for use against Ping Identity, UnboundID, and
054 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
055 *   for proprietary functionality or for external specifications that are not
056 *   considered stable or mature enough to be guaranteed to work in an
057 *   interoperable way with other types of LDAP servers.
058 * </BLOCKQUOTE>
059 * <BR>
060 * The properties that are available for use with this type of task include:
061 * <UL>
062 *   <LI>The backend ID of the backend for to be examined.  The specified
063 *       backend must be enabled and must store its contents in the Berkeley DB
064 *       Java Edition.</LI>
065 * </UL>
066 */
067@NotMutable()
068@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
069public final class DumpDBDetailsTask
070       extends Task
071{
072  /**
073   * The fully-qualified name of the Java class that is used for the dump DB
074   * details task.
075   */
076  static final String DUMP_DB_DETAILS_TASK_CLASS =
077       "com.unboundid.directory.server.tasks.DumpDBDetailsTask";
078
079
080
081  /**
082   * The name of the attribute used to specify the backend ID of the target
083   * backend.
084   */
085  private static final String ATTR_BACKEND_ID =
086       "ds-task-dump-db-backend-id";
087
088
089
090  /**
091   * The name of the object class used in dump DB details task entries.
092   */
093  private static final String OC_DUMP_DB_DETAILS_TASK = "ds-task-dump-db";
094
095
096
097  /**
098   * The task property that will be used for the backend ID.
099   */
100  private static final TaskProperty PROPERTY_BACKEND_ID =
101     new TaskProperty(ATTR_BACKEND_ID,
102          INFO_DUMP_DB_DISPLAY_NAME_BACKEND_ID.get(),
103          INFO_DUMP_DB_DESCRIPTION_BACKEND_ID.get(), String.class, true,
104          false, false);
105
106
107
108  /**
109   * The serial version UID for this serializable class.
110   */
111  private static final long serialVersionUID = 7267871080385864231L;
112
113
114
115  // The name of the backend to be examined.
116  private final String backendID;
117
118
119
120  /**
121   * Creates a new uninitialized dump DB details task instance which should only
122   * be used for obtaining general information about this task, including the
123   * task name, description, and supported properties.  Attempts to use a task
124   * created with this constructor for any other reason will likely fail.
125   */
126  public DumpDBDetailsTask()
127  {
128    backendID = null;
129  }
130
131
132
133  /**
134   * Creates a new dump DB details task to examine the specified backend.
135   *
136   * @param  taskID     The task ID to use for this task.  If it is {@code null}
137   *                    then a UUID will be generated for use as the task ID.
138   * @param  backendID  The backend ID for the backend to examine.  It must not
139   *                    be {@code null}.
140   */
141  public DumpDBDetailsTask(final String taskID, final String backendID)
142  {
143    this(taskID, backendID, null, null, null, null, null);
144  }
145
146
147
148  /**
149   * Creates a new dump DB details task to examine the specified backend.
150   *
151   * @param  taskID                  The task ID to use for this task.  If it is
152   *                                 {@code null} then a UUID will be generated
153   *                                 for use as the task ID.
154   * @param  backendID               The backend ID for the backend to examine.
155   *                                 It must not be {@code null}.
156   * @param  scheduledStartTime      The time that this task should start
157   *                                 running.
158   * @param  dependencyIDs           The list of task IDs that will be required
159   *                                 to complete before this task will be
160   *                                 eligible to start.
161   * @param  failedDependencyAction  Indicates what action should be taken if
162   *                                 any of the dependencies for this task do
163   *                                 not complete successfully.
164   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
165   *                                 that should be notified when this task
166   *                                 completes.
167   * @param  notifyOnError           The list of e-mail addresses of individuals
168   *                                 that should be notified if this task does
169   *                                 not complete successfully.
170   */
171  public DumpDBDetailsTask(final String taskID, final String backendID,
172                           final Date scheduledStartTime,
173                           final List<String> dependencyIDs,
174                           final FailedDependencyAction failedDependencyAction,
175                           final List<String> notifyOnCompletion,
176                           final List<String> notifyOnError)
177  {
178    this(taskID, backendID, scheduledStartTime, dependencyIDs,
179         failedDependencyAction, null, notifyOnCompletion, null,
180         notifyOnError, null, null, null);
181  }
182
183
184
185  /**
186   * Creates a new dump DB details task to examine the specified backend.
187   *
188   * @param  taskID                  The task ID to use for this task.  If it is
189   *                                 {@code null} then a UUID will be generated
190   *                                 for use as the task ID.
191   * @param  backendID               The backend ID for the backend to examine.
192   *                                 It must not be {@code null}.
193   * @param  scheduledStartTime      The time that this task should start
194   *                                 running.
195   * @param  dependencyIDs           The list of task IDs that will be required
196   *                                 to complete before this task will be
197   *                                 eligible to start.
198   * @param  failedDependencyAction  Indicates what action should be taken if
199   *                                 any of the dependencies for this task do
200   *                                 not complete successfully.
201   * @param  notifyOnStart           The list of e-mail addresses of individuals
202   *                                 that should be notified when this task
203   *                                 starts running.
204   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
205   *                                 that should be notified when this task
206   *                                 completes.
207   * @param  notifyOnSuccess         The list of e-mail addresses of individuals
208   *                                 that should be notified if this task
209   *                                 completes successfully.
210   * @param  notifyOnError           The list of e-mail addresses of individuals
211   *                                 that should be notified if this task does
212   *                                 not complete successfully.
213   * @param  alertOnStart            Indicates whether the server should send an
214   *                                 alert notification when this task starts.
215   * @param  alertOnSuccess          Indicates whether the server should send an
216   *                                 alert notification if this task completes
217   *                                 successfully.
218   * @param  alertOnError            Indicates whether the server should send an
219   *                                 alert notification if this task fails to
220   *                                 complete successfully.
221   */
222  public DumpDBDetailsTask(final String taskID, final String backendID,
223                           final Date scheduledStartTime,
224                           final List<String> dependencyIDs,
225                           final FailedDependencyAction failedDependencyAction,
226                           final List<String> notifyOnStart,
227                           final List<String> notifyOnCompletion,
228                           final List<String> notifyOnSuccess,
229                           final List<String> notifyOnError,
230                           final Boolean alertOnStart,
231                           final Boolean alertOnSuccess,
232                           final Boolean alertOnError)
233  {
234    super(taskID, DUMP_DB_DETAILS_TASK_CLASS, scheduledStartTime, dependencyIDs,
235         failedDependencyAction, notifyOnStart, notifyOnCompletion,
236         notifyOnSuccess, notifyOnError, alertOnStart, alertOnSuccess,
237         alertOnError);
238
239    Validator.ensureNotNull(backendID);
240
241    this.backendID = backendID;
242  }
243
244
245
246  /**
247   * Creates a new dump DB details task from the provided entry.
248   *
249   * @param  entry  The entry to use to create this dump DB details task.
250   *
251   * @throws  TaskException  If the provided entry cannot be parsed as a dump DB
252   *                         details task entry.
253   */
254  public DumpDBDetailsTask(final Entry entry)
255         throws TaskException
256  {
257    super(entry);
258
259    // Get the backend ID.  It must be present.
260    backendID = entry.getAttributeValue(ATTR_BACKEND_ID);
261    if (backendID == null)
262    {
263      throw new TaskException(ERR_DUMP_DB_ENTRY_MISSING_BACKEND_ID.get(
264           getTaskEntryDN(), ATTR_BACKEND_ID));
265    }
266  }
267
268
269
270  /**
271   * Creates a new dump DB details task from the provided set of task
272   * properties.
273   *
274   * @param  properties  The set of task properties and their corresponding
275   *                     values to use for the task.  It must not be
276   *                     {@code null}.
277   *
278   * @throws  TaskException  If the provided set of properties cannot be used to
279   *                         create a valid dump DB details task.
280   */
281  public DumpDBDetailsTask(final Map<TaskProperty,List<Object>> properties)
282         throws TaskException
283  {
284    super(DUMP_DB_DETAILS_TASK_CLASS, properties);
285
286    String id = null;
287    for (final Map.Entry<TaskProperty,List<Object>> entry :
288         properties.entrySet())
289    {
290      final TaskProperty p = entry.getKey();
291      final String attrName = p.getAttributeName();
292      final List<Object> values = entry.getValue();
293
294      if (attrName.equalsIgnoreCase(ATTR_BACKEND_ID))
295      {
296        id = parseString(p, values, id);
297      }
298    }
299
300    if (id == null)
301    {
302      throw new TaskException(ERR_DUMP_DB_ENTRY_MISSING_BACKEND_ID.get(
303           getTaskEntryDN(), ATTR_BACKEND_ID));
304    }
305
306    backendID = id;
307  }
308
309
310
311  /**
312   * {@inheritDoc}
313   */
314  @Override()
315  public String getTaskName()
316  {
317    return INFO_TASK_NAME_DUMP_DB.get();
318  }
319
320
321
322  /**
323   * {@inheritDoc}
324   */
325  @Override()
326  public String getTaskDescription()
327  {
328    return INFO_TASK_DESCRIPTION_DUMP_DB.get();
329  }
330
331
332
333  /**
334   * Retrieves the backend ID of the backend to examine.
335   *
336   * @return  The backend ID of the backend to examine.
337   */
338  public String getBackendID()
339  {
340    return backendID;
341  }
342
343
344
345  /**
346   * {@inheritDoc}
347   */
348  @Override()
349  protected List<String> getAdditionalObjectClasses()
350  {
351    return Collections.singletonList(OC_DUMP_DB_DETAILS_TASK);
352  }
353
354
355
356  /**
357   * {@inheritDoc}
358   */
359  @Override()
360  protected List<Attribute> getAdditionalAttributes()
361  {
362    return Collections.singletonList(new Attribute(ATTR_BACKEND_ID, backendID));
363  }
364
365
366
367  /**
368   * {@inheritDoc}
369   */
370  @Override()
371  public List<TaskProperty> getTaskSpecificProperties()
372  {
373    return Collections.singletonList(PROPERTY_BACKEND_ID);
374  }
375
376
377
378  /**
379   * {@inheritDoc}
380   */
381  @Override()
382  public Map<TaskProperty,List<Object>> getTaskPropertyValues()
383  {
384    final LinkedHashMap<TaskProperty,List<Object>> props =
385         new LinkedHashMap<>(1);
386
387    props.put(PROPERTY_BACKEND_ID,
388         Collections.<Object>singletonList(backendID));
389
390    props.putAll(super.getTaskPropertyValues());
391    return Collections.unmodifiableMap(props);
392  }
393}