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