001/*
002 * Copyright 2010-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2010-2020 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) 2015-2020 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.tasks;
037
038
039
040import java.util.Arrays;
041import java.util.Collections;
042import java.util.Date;
043import java.util.LinkedHashMap;
044import java.util.LinkedList;
045import java.util.List;
046import java.util.Map;
047
048import com.unboundid.ldap.sdk.Attribute;
049import com.unboundid.ldap.sdk.Entry;
050import com.unboundid.util.NotMutable;
051import com.unboundid.util.StaticUtils;
052import com.unboundid.util.ThreadSafety;
053import com.unboundid.util.ThreadSafetyLevel;
054import com.unboundid.util.Validator;
055
056import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
057
058
059
060/**
061 * This class defines a Directory Server task that can be used to cause the
062 * server to generate administrative alerts, or to manage the set of degraded or
063 * unavailable alert types.
064 * <BR>
065 * <BLOCKQUOTE>
066 *   <B>NOTE:</B>  This class, and other classes within the
067 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
068 *   supported for use against Ping Identity, UnboundID, and
069 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
070 *   for proprietary functionality or for external specifications that are not
071 *   considered stable or mature enough to be guaranteed to work in an
072 *   interoperable way with other types of LDAP servers.
073 * </BLOCKQUOTE>
074 * <BR>
075 * The properties that are available for use with this type of task include:
076 * <UL>
077 *   <LI>The alert type of the alert notification to generate.  If this is
078 *       provided, then an alert message must also be provided.</LI>
079 *   <LI>The alert message for the alert notification to generate.  If this is
080 *       provided, then an alert type must also be provided.</LI>
081 *   <LI>The names of the alert types to add to the set of degraded alert types
082 *       in the general monitor entry.</LI>
083 *   <LI>The names of the alert types to remove from the set of degraded alert
084 *       types in the general monitor entry.</LI>
085 *   <LI>The names of the alert types to add to the set of unavailable alert
086 *       types in the general monitor entry.</LI>
087 *   <LI>The names of the alert types to remove from the set of unavailable
088 *       alert types in the general monitor entry.</LI>
089 * </UL>
090 */
091@NotMutable()
092@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
093public final class AlertTask
094       extends Task
095{
096  /**
097   * The fully-qualified name of the Java class that is used for the alert task.
098   */
099  static final String ALERT_TASK_CLASS =
100       "com.unboundid.directory.server.tasks.AlertTask";
101
102
103
104  /**
105   * The name of the attribute used to specify the alert type for the alert to
106   * generate.
107   */
108  private static final String ATTR_ALERT_TYPE = "ds-task-alert-type";
109
110
111
112  /**
113   * The name of the attribute used to specify the message for the alert to
114   * generate.
115   */
116  private static final String ATTR_ALERT_MESSAGE = "ds-task-alert-message";
117
118
119
120  /**
121   * The name of the attribute used to specify the alert type(s) to add to the
122   * set of degraded alert types.
123   */
124  private static final String ATTR_ADD_DEGRADED_TYPE =
125       "ds-task-alert-add-degraded-type";
126
127
128
129  /**
130   * The name of the attribute used to specify the alert type(s) to remove from
131   * the set of degraded alert types.
132   */
133  private static final String ATTR_REMOVE_DEGRADED_TYPE =
134       "ds-task-alert-remove-degraded-type";
135
136
137
138  /**
139   * The name of the attribute used to specify the alert type(s) to add to the
140   * set of unavailable alert types.
141   */
142  private static final String ATTR_ADD_UNAVAILABLE_TYPE =
143       "ds-task-alert-add-unavailable-type";
144
145
146
147  /**
148   * The name of the attribute used to specify the alert type(s) to remove from
149   * the set of unavailable alert types.
150   */
151  private static final String ATTR_REMOVE_UNAVAILABLE_TYPE =
152       "ds-task-alert-remove-unavailable-type";
153
154
155
156  /**
157   * The name of the object class used in alert task entries.
158   */
159  private static final String OC_ALERT_TASK = "ds-task-alert";
160
161
162
163  /**
164   * The task property that will be used for the alert type.
165   */
166  private static final TaskProperty PROPERTY_ALERT_TYPE =
167     new TaskProperty(ATTR_ALERT_TYPE, INFO_ALERT_DISPLAY_NAME_TYPE.get(),
168          INFO_ALERT_DESCRIPTION_TYPE.get(), String.class, false, false,
169          false);
170
171
172
173  /**
174   * The task property that will be used for the alert message.
175   */
176  private static final TaskProperty PROPERTY_ALERT_MESSAGE =
177     new TaskProperty(ATTR_ALERT_MESSAGE, INFO_ALERT_DISPLAY_NAME_MESSAGE.get(),
178          INFO_ALERT_DESCRIPTION_MESSAGE.get(), String.class, false, false,
179          false);
180
181
182
183  /**
184   * The task property that will be used for the add degraded alert types.
185   */
186  private static final TaskProperty PROPERTY_ADD_DEGRADED_TYPE =
187     new TaskProperty(ATTR_ADD_DEGRADED_TYPE,
188          INFO_ALERT_DISPLAY_NAME_ADD_DEGRADED.get(),
189          INFO_ALERT_DESCRIPTION_ADD_DEGRADED.get(), String.class, false, true,
190          false);
191
192
193
194  /**
195   * The task property that will be used for the remove degraded alert types.
196   */
197  private static final TaskProperty PROPERTY_REMOVE_DEGRADED_TYPE =
198     new TaskProperty(ATTR_REMOVE_DEGRADED_TYPE,
199          INFO_ALERT_DISPLAY_NAME_REMOVE_DEGRADED.get(),
200          INFO_ALERT_DESCRIPTION_REMOVE_DEGRADED.get(), String.class, false,
201          true, false);
202
203
204
205  /**
206   * The task property that will be used for the add unavailable alert types.
207   */
208  private static final TaskProperty PROPERTY_ADD_UNAVAILABLE_TYPE =
209     new TaskProperty(ATTR_ADD_UNAVAILABLE_TYPE,
210          INFO_ALERT_DISPLAY_NAME_ADD_UNAVAILABLE.get(),
211          INFO_ALERT_DESCRIPTION_ADD_UNAVAILABLE.get(), String.class, false,
212          true, false);
213
214
215
216  /**
217   * The task property that will be used for the remove unavailable alert types.
218   */
219  private static final TaskProperty PROPERTY_REMOVE_UNAVAILABLE_TYPE =
220     new TaskProperty(ATTR_REMOVE_UNAVAILABLE_TYPE,
221          INFO_ALERT_DISPLAY_NAME_REMOVE_UNAVAILABLE.get(),
222          INFO_ALERT_DESCRIPTION_REMOVE_UNAVAILABLE.get(), String.class, false,
223          true, false);
224
225
226
227  /**
228   * The serial version UID for this serializable class.
229   */
230  private static final long serialVersionUID = 8253375533166941221L;
231
232
233
234  // The alert types to add to the set of degraded alert types.
235  private final List<String> addDegradedTypes;
236
237  // The alert types to add to the set of unavailable alert types.
238  private final List<String> addUnavailableTypes;
239
240  // The alert types to remove from the set of degraded alert types.
241  private final List<String> removeDegradedTypes;
242
243  // The alert types to remove from the set of unavailable alert types.
244  private final List<String> removeUnavailableTypes;
245
246  // The message for the alert to be generated.
247  private final String alertMessage;
248
249  // The name of the alert type for the alert to be generated.
250  private final String alertType;
251
252
253
254  /**
255   * Creates a new uninitialized alert task instance which should only be used
256   * for obtaining general information about this task, including the task name,
257   * description, and supported properties.  Attempts to use a task created with
258   * this constructor for any other reason will likely fail.
259   */
260  public AlertTask()
261  {
262    alertType              = null;
263    alertMessage           = null;
264    addDegradedTypes       = null;
265    addUnavailableTypes    = null;
266    removeDegradedTypes    = null;
267    removeUnavailableTypes = null;
268  }
269
270
271
272  /**
273   * Creates a new alert task that can be used to generate an administrative
274   * alert with the provided information.
275   *
276   * @param  alertType     The alert type to use for the generated alert.  It
277   *                       must not be {@code null}.
278   * @param  alertMessage  The message to use for the generated alert.  It must
279   *                       not be {@code null}.
280   */
281  public AlertTask(final String alertType, final String alertMessage)
282  {
283    this(null, alertType, alertMessage, null, null, null, null, null, null,
284         null, null, null);
285  }
286
287
288
289  /**
290   * Creates a new alert task that can be used to generate an administrative
291   * alert and/or update the set of degraded or unavailable alert types for the
292   * Directory Server.  At least one element must be provided.
293   *
294   * @param  alertType               The alert type to use for the generated
295   *                                 alert.  It may be {@code null} if no alert
296   *                                 should be generated, but if it is
297   *                                 non-{@code null} then the alert message
298   *                                 must also be non-{@code null}.
299   * @param  alertMessage            The message to use for the generated alert.
300   *                                 It may be {@code null} if no alert should
301   *                                 be generated, but if it is non-{@code null}
302   *                                 then the alert type must also be
303   *                                 non-{@code null}.
304   * @param  addDegradedTypes        The names of the alert types to add to the
305   *                                 Directory Server's set of degraded alert
306   *                                 types.  It may be {@code null} or empty if
307   *                                 no degraded alert types should be added.
308   * @param  removeDegradedTypes     The names of the alert types to remove from
309   *                                 the Directory Server's set of degraded
310   *                                 alert types.  It may be {@code null} or
311   *                                 empty if no degraded alert types should be
312   *                                 removed.
313   * @param  addUnavailableTypes     The names of the alert types to add to the
314   *                                 Directory Server's set of unavailable alert
315   *                                 types.  It may be {@code null} or empty if
316   *                                 no unavailable alert types should be added.
317   * @param  removeUnavailableTypes  The names of the alert types to remove from
318   *                                 the Directory Server's set of unavailable
319   *                                 alert types.  It may be {@code null} or
320   *                                 empty if no unavailable alert types should
321   *                                 be removed.
322   */
323  public AlertTask(final String alertType, final String alertMessage,
324                   final List<String> addDegradedTypes,
325                   final List<String> removeDegradedTypes,
326                   final List<String> addUnavailableTypes,
327                   final List<String> removeUnavailableTypes)
328  {
329    this(null, alertType, alertMessage, addDegradedTypes, removeDegradedTypes,
330         addUnavailableTypes, removeUnavailableTypes, null, null, null,
331         null, null);
332  }
333
334
335
336  /**
337   * Creates a new alert task that can be used to generate an administrative
338   * alert and/or update the set of degraded or unavailable alert types for the
339   * Directory Server.  At least one alert-related element must be provided.
340   *
341   * @param  taskID                  The task ID to use for this task.  If it is
342   *                                 {@code null} then a UUID will be generated
343   *                                 for use as the task ID.
344   * @param  alertType               The alert type to use for the generated
345   *                                 alert.  It may be {@code null} if no alert
346   *                                 should be generated, but if it is
347   *                                 non-{@code null} then the alert message
348   *                                 must also be non-{@code null}.
349   * @param  alertMessage            The message to use for the generated alert.
350   *                                 It may be {@code null} if no alert should
351   *                                 be generated, but if it is non-{@code null}
352   *                                 then the alert type must also be
353   *                                 non-{@code null}.
354   * @param  addDegradedTypes        The names of the alert types to add to the
355   *                                 Directory Server's set of degraded alert
356   *                                 types.  It may be {@code null} or empty if
357   *                                 no degraded alert types should be added.
358   * @param  removeDegradedTypes     The names of the alert types to remove from
359   *                                 the Directory Server's set of degraded
360   *                                 alert types.  It may be {@code null} or
361   *                                 empty if no degraded alert types should be
362   *                                 removed.
363   * @param  addUnavailableTypes     The names of the alert types to add to the
364   *                                 Directory Server's set of unavailable alert
365   *                                 types.  It may be {@code null} or empty if
366   *                                 no unavailable alert types should be added.
367   * @param  removeUnavailableTypes  The names of the alert types to remove from
368   *                                 the Directory Server's set of unavailable
369   *                                 alert types.  It may be {@code null} or
370   *                                 empty if no unavailable alert types should
371   *                                 be removed.
372   * @param  scheduledStartTime      The time that this task should start
373   *                                 running.
374   * @param  dependencyIDs           The list of task IDs that will be required
375   *                                 to complete before this task will be
376   *                                 eligible to start.
377   * @param  failedDependencyAction  Indicates what action should be taken if
378   *                                 any of the dependencies for this task do
379   *                                 not complete successfully.
380   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
381   *                                 that should be notified when this task
382   *                                 completes.
383   * @param  notifyOnError           The list of e-mail addresses of individuals
384   *                                 that should be notified if this task does
385   *                                 not complete successfully.
386   */
387  public AlertTask(final String taskID, final String alertType,
388                   final String alertMessage,
389                   final List<String> addDegradedTypes,
390                   final List<String> removeDegradedTypes,
391                   final List<String> addUnavailableTypes,
392                   final List<String> removeUnavailableTypes,
393                   final Date scheduledStartTime,
394                   final List<String> dependencyIDs,
395                   final FailedDependencyAction failedDependencyAction,
396                   final List<String> notifyOnCompletion,
397                   final List<String> notifyOnError)
398  {
399    this(taskID, alertType, alertMessage, addDegradedTypes, removeDegradedTypes,
400         addUnavailableTypes, removeUnavailableTypes, scheduledStartTime,
401         dependencyIDs, failedDependencyAction, null, notifyOnCompletion, null,
402         notifyOnError, null, null, null);
403  }
404
405
406
407  /**
408   * Creates a new alert task that can be used to generate an administrative
409   * alert and/or update the set of degraded or unavailable alert types for the
410   * Directory Server.  At least one alert-related element must be provided.
411   *
412   * @param  taskID                  The task ID to use for this task.  If it is
413   *                                 {@code null} then a UUID will be generated
414   *                                 for use as the task ID.
415   * @param  alertType               The alert type to use for the generated
416   *                                 alert.  It may be {@code null} if no alert
417   *                                 should be generated, but if it is
418   *                                 non-{@code null} then the alert message
419   *                                 must also be non-{@code null}.
420   * @param  alertMessage            The message to use for the generated alert.
421   *                                 It may be {@code null} if no alert should
422   *                                 be generated, but if it is non-{@code null}
423   *                                 then the alert type must also be
424   *                                 non-{@code null}.
425   * @param  addDegradedTypes        The names of the alert types to add to the
426   *                                 Directory Server's set of degraded alert
427   *                                 types.  It may be {@code null} or empty if
428   *                                 no degraded alert types should be added.
429   * @param  removeDegradedTypes     The names of the alert types to remove from
430   *                                 the Directory Server's set of degraded
431   *                                 alert types.  It may be {@code null} or
432   *                                 empty if no degraded alert types should be
433   *                                 removed.
434   * @param  addUnavailableTypes     The names of the alert types to add to the
435   *                                 Directory Server's set of unavailable alert
436   *                                 types.  It may be {@code null} or empty if
437   *                                 no unavailable alert types should be added.
438   * @param  removeUnavailableTypes  The names of the alert types to remove from
439   *                                 the Directory Server's set of unavailable
440   *                                 alert types.  It may be {@code null} or
441   *                                 empty if no unavailable alert types should
442   *                                 be removed.
443   * @param  scheduledStartTime      The time that this task should start
444   *                                 running.
445   * @param  dependencyIDs           The list of task IDs that will be required
446   *                                 to complete before this task will be
447   *                                 eligible to start.
448   * @param  failedDependencyAction  Indicates what action should be taken if
449   *                                 any of the dependencies for this task do
450   *                                 not complete successfully.
451   * @param  notifyOnStart           The list of e-mail addresses of individuals
452   *                                 that should be notified when this task
453   *                                 starts running.
454   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
455   *                                 that should be notified when this task
456   *                                 completes.
457   * @param  notifyOnSuccess         The list of e-mail addresses of individuals
458   *                                 that should be notified if this task
459   *                                 completes successfully.
460   * @param  notifyOnError           The list of e-mail addresses of individuals
461   *                                 that should be notified if this task does
462   *                                 not complete successfully.
463   * @param  alertOnStart            Indicates whether the server should send an
464   *                                 alert notification when this task starts.
465   * @param  alertOnSuccess          Indicates whether the server should send an
466   *                                 alert notification if this task completes
467   *                                 successfully.
468   * @param  alertOnError            Indicates whether the server should send an
469   *                                 alert notification if this task fails to
470   *                                 complete successfully.
471   */
472  public AlertTask(final String taskID, final String alertType,
473                   final String alertMessage,
474                   final List<String> addDegradedTypes,
475                   final List<String> removeDegradedTypes,
476                   final List<String> addUnavailableTypes,
477                   final List<String> removeUnavailableTypes,
478                   final Date scheduledStartTime,
479                   final List<String> dependencyIDs,
480                   final FailedDependencyAction failedDependencyAction,
481                   final List<String> notifyOnStart,
482                   final List<String> notifyOnCompletion,
483                   final List<String> notifyOnSuccess,
484                   final List<String> notifyOnError, final Boolean alertOnStart,
485                   final Boolean alertOnSuccess, final Boolean alertOnError)
486  {
487    super(taskID, ALERT_TASK_CLASS, scheduledStartTime, dependencyIDs,
488         failedDependencyAction, notifyOnStart, notifyOnCompletion,
489         notifyOnSuccess, notifyOnError, alertOnStart, alertOnSuccess,
490         alertOnError);
491
492    this.alertType    = alertType;
493    this.alertMessage = alertMessage;
494
495    Validator.ensureTrue((alertType == null) == (alertMessage == null));
496
497
498    this.addDegradedTypes       = getStringList(addDegradedTypes);
499    this.removeDegradedTypes    = getStringList(removeDegradedTypes);
500    this.addUnavailableTypes    = getStringList(addUnavailableTypes);
501    this.removeUnavailableTypes = getStringList(removeUnavailableTypes);
502
503    if (alertType == null)
504    {
505      Validator.ensureFalse(this.addDegradedTypes.isEmpty() &&
506           this.removeDegradedTypes.isEmpty() &&
507           this.addUnavailableTypes.isEmpty() &&
508           this.removeUnavailableTypes.isEmpty());
509    }
510  }
511
512
513
514  /**
515   * Creates a new alert task from the provided entry.
516   *
517   * @param  entry  The entry to use to create this alert task.
518   *
519   * @throws  TaskException  If the provided entry cannot be parsed as an alert
520   *                         task entry.
521   */
522  public AlertTask(final Entry entry)
523         throws TaskException
524  {
525    super(entry);
526
527
528    // Get the alert type and message.  If either is present, then both must be.
529    alertType    = entry.getAttributeValue(ATTR_ALERT_TYPE);
530    alertMessage = entry.getAttributeValue(ATTR_ALERT_MESSAGE);
531
532    if ((alertType == null) != (alertMessage == null))
533    {
534      throw new TaskException(ERR_ALERT_TYPE_AND_MESSAGE_INTERDEPENDENT.get());
535    }
536
537
538    // Get the values to add/remove from the degraded/unavailable alert types.
539    addDegradedTypes       = parseStringList(entry, ATTR_ADD_DEGRADED_TYPE);
540    removeDegradedTypes    = parseStringList(entry, ATTR_REMOVE_DEGRADED_TYPE);
541    addUnavailableTypes    = parseStringList(entry, ATTR_ADD_UNAVAILABLE_TYPE);
542    removeUnavailableTypes = parseStringList(entry,
543         ATTR_REMOVE_UNAVAILABLE_TYPE);
544
545    if ((alertType == null) && addDegradedTypes.isEmpty() &&
546        removeDegradedTypes.isEmpty() && addUnavailableTypes.isEmpty() &&
547        removeUnavailableTypes.isEmpty())
548    {
549      throw new TaskException(ERR_ALERT_ENTRY_NO_ELEMENTS.get());
550    }
551  }
552
553
554
555  /**
556   * Creates a new alert task from the provided set of task properties.
557   *
558   * @param  properties  The set of task properties and their corresponding
559   *                     values to use for the task.  It must not be
560   *                     {@code null}.
561   *
562   * @throws  TaskException  If the provided set of properties cannot be used to
563   *                         create a valid alert task.
564   */
565  public AlertTask(final Map<TaskProperty,List<Object>> properties)
566         throws TaskException
567  {
568    super(ALERT_TASK_CLASS, properties);
569
570    String type = null;
571    String message = null;
572    final LinkedList<String> addDegraded = new LinkedList<>();
573    final LinkedList<String> removeDegraded = new LinkedList<>();
574    final LinkedList<String> addUnavailable = new LinkedList<>();
575    final LinkedList<String> removeUnavailable = new LinkedList<>();
576    for (final Map.Entry<TaskProperty,List<Object>> entry :
577         properties.entrySet())
578    {
579      final TaskProperty p = entry.getKey();
580      final String attrName = StaticUtils.toLowerCase(p.getAttributeName());
581      final List<Object> values = entry.getValue();
582
583      if (attrName.equals(ATTR_ALERT_TYPE))
584      {
585        type = parseString(p, values, type);
586      }
587      else if (attrName.equals(ATTR_ALERT_MESSAGE))
588      {
589        message = parseString(p, values, message);
590      }
591      else if (attrName.equals(ATTR_ADD_DEGRADED_TYPE))
592      {
593        final String[] s = parseStrings(p, values, null);
594        if (s != null)
595        {
596          addDegraded.addAll(Arrays.asList(s));
597        }
598      }
599      else if (attrName.equals(ATTR_REMOVE_DEGRADED_TYPE))
600      {
601        final String[] s = parseStrings(p, values, null);
602        if (s != null)
603        {
604          removeDegraded.addAll(Arrays.asList(s));
605        }
606      }
607      else if (attrName.equals(ATTR_ADD_UNAVAILABLE_TYPE))
608      {
609        final String[] s = parseStrings(p, values, null);
610        if (s != null)
611        {
612          addUnavailable.addAll(Arrays.asList(s));
613        }
614      }
615      else if (attrName.equals(ATTR_REMOVE_UNAVAILABLE_TYPE))
616      {
617        final String[] s = parseStrings(p, values, null);
618        if (s != null)
619        {
620          removeUnavailable.addAll(Arrays.asList(s));
621        }
622      }
623    }
624
625    alertType              = type;
626    alertMessage           = message;
627    addDegradedTypes       = Collections.unmodifiableList(addDegraded);
628    removeDegradedTypes    = Collections.unmodifiableList(removeDegraded);
629    addUnavailableTypes    = Collections.unmodifiableList(addUnavailable);
630    removeUnavailableTypes = Collections.unmodifiableList(removeUnavailable);
631
632    if ((alertType == null) != (alertMessage == null))
633    {
634      throw new TaskException(ERR_ALERT_TYPE_AND_MESSAGE_INTERDEPENDENT.get());
635    }
636
637    if ((alertType == null) && addDegradedTypes.isEmpty() &&
638        removeDegradedTypes.isEmpty() && addUnavailableTypes.isEmpty() &&
639        removeUnavailableTypes.isEmpty())
640    {
641      throw new TaskException(ERR_ALERT_PROPERTIES_NO_ELEMENTS.get());
642    }
643  }
644
645
646
647  /**
648   * {@inheritDoc}
649   */
650  @Override()
651  public String getTaskName()
652  {
653    return INFO_TASK_NAME_ALERT.get();
654  }
655
656
657
658  /**
659   * {@inheritDoc}
660   */
661  @Override()
662  public String getTaskDescription()
663  {
664    return INFO_TASK_DESCRIPTION_ALERT.get();
665  }
666
667
668
669  /**
670   * Retrieves the name of the alert type to use for the alert notification to
671   * be generated, if appropriate.
672   *
673   * @return  The name of the alert type to use for the alert notification to be
674   *          generated, or {@code null} if no alert should be generated.
675   */
676  public String getAlertType()
677  {
678    return alertType;
679  }
680
681
682
683  /**
684   * Retrieves the message to use for the alert notification to be generated, if
685   * appropriate.
686   *
687   * @return  The message to use for the alert notification to be generated, or
688   *          {@code null} if no alert should be generated.
689   */
690  public String getAlertMessage()
691  {
692    return alertMessage;
693  }
694
695
696
697  /**
698   * Retrieves the names of the alert types that should be added to the set of
699   * degraded alert types.
700   *
701   * @return  The names of the alert types that should be added to the set of
702   *          degraded alert types, or an empty list if no degraded alert types
703   *          should be added.
704   */
705  public List<String> getAddDegradedAlertTypes()
706  {
707    return addDegradedTypes;
708  }
709
710
711
712  /**
713   * Retrieves the names of the alert types that should be removed from the set
714   * of degraded alert types.
715   *
716   * @return  The names of the alert types that should be removed from the set
717   *          of degraded alert types, or an empty list if no degraded alert
718   *          types should be removed.
719   */
720  public List<String> getRemoveDegradedAlertTypes()
721  {
722    return removeDegradedTypes;
723  }
724
725
726
727  /**
728   * Retrieves the names of the alert types that should be added to the set of
729   * unavailable alert types.
730   *
731   * @return  The names of the alert types that should be added to the set of
732   *          unavailable alert types, or an empty list if no unavailable alert
733   *          types should be added.
734   */
735  public List<String> getAddUnavailableAlertTypes()
736  {
737    return addUnavailableTypes;
738  }
739
740
741
742  /**
743   * Retrieves the names of the alert types that should be removed from the set
744   * of unavailable alert types.
745   *
746   * @return  The names of the alert types that should be removed from the set
747   *          of unavailable alert types, or an empty list if no unavailable
748   *          alert types should be removed.
749   */
750  public List<String> getRemoveUnavailableAlertTypes()
751  {
752    return removeUnavailableTypes;
753  }
754
755
756
757  /**
758   * {@inheritDoc}
759   */
760  @Override()
761  protected List<String> getAdditionalObjectClasses()
762  {
763    return Collections.singletonList(OC_ALERT_TASK);
764  }
765
766
767
768  /**
769   * {@inheritDoc}
770   */
771  @Override()
772  protected List<Attribute> getAdditionalAttributes()
773  {
774    final LinkedList<Attribute> attrList = new LinkedList<>();
775
776    if (alertType != null)
777    {
778      attrList.add(new Attribute(ATTR_ALERT_TYPE, alertType));
779      attrList.add(new Attribute(ATTR_ALERT_MESSAGE, alertMessage));
780    }
781
782    if (! addDegradedTypes.isEmpty())
783    {
784      attrList.add(new Attribute(ATTR_ADD_DEGRADED_TYPE, addDegradedTypes));
785    }
786
787    if (! removeDegradedTypes.isEmpty())
788    {
789      attrList.add(new Attribute(ATTR_REMOVE_DEGRADED_TYPE,
790           removeDegradedTypes));
791    }
792
793    if (! addUnavailableTypes.isEmpty())
794    {
795      attrList.add(new Attribute(ATTR_ADD_UNAVAILABLE_TYPE,
796           addUnavailableTypes));
797    }
798
799    if (! removeUnavailableTypes.isEmpty())
800    {
801      attrList.add(new Attribute(ATTR_REMOVE_UNAVAILABLE_TYPE,
802           removeUnavailableTypes));
803    }
804
805    return attrList;
806  }
807
808
809
810  /**
811   * {@inheritDoc}
812   */
813  @Override()
814  public List<TaskProperty> getTaskSpecificProperties()
815  {
816    return Collections.unmodifiableList(Arrays.asList(
817         PROPERTY_ALERT_TYPE, PROPERTY_ALERT_MESSAGE,
818         PROPERTY_ADD_DEGRADED_TYPE, PROPERTY_REMOVE_DEGRADED_TYPE,
819         PROPERTY_ADD_UNAVAILABLE_TYPE, PROPERTY_REMOVE_UNAVAILABLE_TYPE));
820  }
821
822
823
824  /**
825   * {@inheritDoc}
826   */
827  @Override()
828  public Map<TaskProperty,List<Object>> getTaskPropertyValues()
829  {
830    final LinkedHashMap<TaskProperty,List<Object>> props =
831         new LinkedHashMap<>(StaticUtils.computeMapCapacity(6));
832
833    if (alertType != null)
834    {
835      props.put(PROPERTY_ALERT_TYPE,
836           Collections.<Object>singletonList(alertType));
837      props.put(PROPERTY_ALERT_MESSAGE,
838           Collections.<Object>singletonList(alertMessage));
839    }
840
841    if (! addDegradedTypes.isEmpty())
842    {
843      props.put(PROPERTY_ADD_DEGRADED_TYPE,
844           Collections.<Object>unmodifiableList(addDegradedTypes));
845    }
846
847    if (! removeDegradedTypes.isEmpty())
848    {
849      props.put(PROPERTY_REMOVE_DEGRADED_TYPE,
850           Collections.<Object>unmodifiableList(removeDegradedTypes));
851    }
852
853    if (! addUnavailableTypes.isEmpty())
854    {
855      props.put(PROPERTY_ADD_UNAVAILABLE_TYPE,
856           Collections.<Object>unmodifiableList(addUnavailableTypes));
857    }
858
859    if (! removeUnavailableTypes.isEmpty())
860    {
861      props.put(PROPERTY_REMOVE_UNAVAILABLE_TYPE,
862           Collections.<Object>unmodifiableList(removeUnavailableTypes));
863    }
864
865    return Collections.unmodifiableMap(props);
866  }
867
868
869
870  /**
871   * Retrieves an unmodifiable list using information from the provided list.
872   * If the given list is {@code null}, then an empty list will be returned.
873   * Otherwise, an unmodifiable version of the provided list will be returned.
874   *
875   * @param  l  The list to be processed.
876   *
877   * @return  The resulting string list.
878   */
879  private static List<String> getStringList(final List<String> l)
880  {
881    if (l == null)
882    {
883      return Collections.emptyList();
884    }
885    else
886    {
887      return Collections.unmodifiableList(l);
888    }
889  }
890}