Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2010-2017 UnboundID Corp.
* All Rights Reserved.
*/
/*
* Copyright (C) 2015-2017 UnboundID Corp.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPLv2 only)
* or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see .
*/
package com.unboundid.ldap.sdk.unboundidds.tasks;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.unboundid.ldap.sdk.Attribute;
import com.unboundid.ldap.sdk.Entry;
import com.unboundid.util.NotMutable;
import com.unboundid.util.StaticUtils;
import com.unboundid.util.ThreadSafety;
import com.unboundid.util.ThreadSafetyLevel;
import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
import static com.unboundid.util.Validator.*;
/**
* This class defines a Directory Server task that can be used to cause the
* server to generate administrative alerts, or to manage the set of degraded or
* unavailable alert types.
*
*
* NOTE: This class is part of the Commercial Edition of the UnboundID
* LDAP SDK for Java. It is not available for use in applications that
* include only the Standard Edition of the LDAP SDK, and is not supported for
* use in conjunction with non-UnboundID products.
*
*
* The properties that are available for use with this type of task include:
*
*
The alert type of the alert notification to generate. If this is
* provided, then an alert message must also be provided.
*
The alert message for the alert notification to generate. If this is
* provided, then an alert type must also be provided.
*
The names of the alert types to add to the set of degraded alert types
* in the general monitor entry.
*
The names of the alert types to remove from the set of degraded alert
* types in the general monitor entry.
*
The names of the alert types to add to the set of unavailable alert
* types in the general monitor entry.
*
The names of the alert types to remove from the set of unavailable
* alert types in the general monitor entry.
*
*/
@NotMutable()
@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
public final class AlertTask
extends Task
{
/**
* The fully-qualified name of the Java class that is used for the alert task.
*/
static final String ALERT_TASK_CLASS =
"com.unboundid.directory.server.tasks.AlertTask";
/**
* The name of the attribute used to specify the alert type for the alert to
* generate.
*/
private static final String ATTR_ALERT_TYPE = "ds-task-alert-type";
/**
* The name of the attribute used to specify the message for the alert to
* generate.
*/
private static final String ATTR_ALERT_MESSAGE = "ds-task-alert-message";
/**
* The name of the attribute used to specify the alert type(s) to add to the
* set of degraded alert types.
*/
private static final String ATTR_ADD_DEGRADED_TYPE =
"ds-task-alert-add-degraded-type";
/**
* The name of the attribute used to specify the alert type(s) to remove from
* the set of degraded alert types.
*/
private static final String ATTR_REMOVE_DEGRADED_TYPE =
"ds-task-alert-remove-degraded-type";
/**
* The name of the attribute used to specify the alert type(s) to add to the
* set of unavailable alert types.
*/
private static final String ATTR_ADD_UNAVAILABLE_TYPE =
"ds-task-alert-add-unavailable-type";
/**
* The name of the attribute used to specify the alert type(s) to remove from
* the set of unavailable alert types.
*/
private static final String ATTR_REMOVE_UNAVAILABLE_TYPE =
"ds-task-alert-remove-unavailable-type";
/**
* The name of the object class used in alert task entries.
*/
private static final String OC_ALERT_TASK = "ds-task-alert";
/**
* The task property that will be used for the alert type.
*/
private static final TaskProperty PROPERTY_ALERT_TYPE =
new TaskProperty(ATTR_ALERT_TYPE, INFO_ALERT_DISPLAY_NAME_TYPE.get(),
INFO_ALERT_DESCRIPTION_TYPE.get(), String.class, false, false,
false);
/**
* The task property that will be used for the alert message.
*/
private static final TaskProperty PROPERTY_ALERT_MESSAGE =
new TaskProperty(ATTR_ALERT_MESSAGE, INFO_ALERT_DISPLAY_NAME_MESSAGE.get(),
INFO_ALERT_DESCRIPTION_MESSAGE.get(), String.class, false, false,
false);
/**
* The task property that will be used for the add degraded alert types.
*/
private static final TaskProperty PROPERTY_ADD_DEGRADED_TYPE =
new TaskProperty(ATTR_ADD_DEGRADED_TYPE,
INFO_ALERT_DISPLAY_NAME_ADD_DEGRADED.get(),
INFO_ALERT_DESCRIPTION_ADD_DEGRADED.get(), String.class, false, true,
false);
/**
* The task property that will be used for the remove degraded alert types.
*/
private static final TaskProperty PROPERTY_REMOVE_DEGRADED_TYPE =
new TaskProperty(ATTR_REMOVE_DEGRADED_TYPE,
INFO_ALERT_DISPLAY_NAME_REMOVE_DEGRADED.get(),
INFO_ALERT_DESCRIPTION_REMOVE_DEGRADED.get(), String.class, false,
true, false);
/**
* The task property that will be used for the add unavailable alert types.
*/
private static final TaskProperty PROPERTY_ADD_UNAVAILABLE_TYPE =
new TaskProperty(ATTR_ADD_UNAVAILABLE_TYPE,
INFO_ALERT_DISPLAY_NAME_ADD_UNAVAILABLE.get(),
INFO_ALERT_DESCRIPTION_ADD_UNAVAILABLE.get(), String.class, false,
true, false);
/**
* The task property that will be used for the remove unavailable alert types.
*/
private static final TaskProperty PROPERTY_REMOVE_UNAVAILABLE_TYPE =
new TaskProperty(ATTR_REMOVE_UNAVAILABLE_TYPE,
INFO_ALERT_DISPLAY_NAME_REMOVE_UNAVAILABLE.get(),
INFO_ALERT_DESCRIPTION_REMOVE_UNAVAILABLE.get(), String.class, false,
true, false);
/**
* The serial version UID for this serializable class.
*/
private static final long serialVersionUID = 8253375533166941221L;
// The alert types to add to the set of degraded alert types.
private final List addDegradedTypes;
// The alert types to add to the set of unavailable alert types.
private final List addUnavailableTypes;
// The alert types to remove from the set of degraded alert types.
private final List removeDegradedTypes;
// The alert types to remove from the set of unavailable alert types.
private final List removeUnavailableTypes;
// The message for the alert to be generated.
private final String alertMessage;
// The name of the alert type for the alert to be generated.
private final String alertType;
/**
* Creates a new uninitialized alert task instance which should only be used
* for obtaining general information about this task, including the task name,
* description, and supported properties. Attempts to use a task created with
* this constructor for any other reason will likely fail.
*/
public AlertTask()
{
alertType = null;
alertMessage = null;
addDegradedTypes = null;
addUnavailableTypes = null;
removeDegradedTypes = null;
removeUnavailableTypes = null;
}
/**
* Creates a new alert task that can be used to generate an administrative
* alert with the provided information.
*
* @param alertType The alert type to use for the generated alert. It
* must not be {@code null}.
* @param alertMessage The message to use for the generated alert. It must
* not be {@code null}.
*/
public AlertTask(final String alertType, final String alertMessage)
{
this(null, alertType, alertMessage, null, null, null, null, null, null,
null, null, null);
}
/**
* Creates a new alert task that can be used to generate an administrative
* alert and/or update the set of degraded or unavailable alert types for the
* Directory Server. At least one element must be provided.
*
* @param alertType The alert type to use for the generated
* alert. It may be {@code null} if no alert
* should be generated, but if it is
* non-{@code null} then the alert message
* must also be non-{@code null}.
* @param alertMessage The message to use for the generated alert.
* It may be {@code null} if no alert should
* be generated, but if it is non-{@code null}
* then the alert type must also be
* non-{@code null}.
* @param addDegradedTypes The names of the alert types to add to the
* Directory Server's set of degraded alert
* types. It may be {@code null} or empty if
* no degraded alert types should be added.
* @param removeDegradedTypes The names of the alert types to remove from
* the Directory Server's set of degraded
* alert types. It may be {@code null} or
* empty if no degraded alert types should be
* removed.
* @param addUnavailableTypes The names of the alert types to add to the
* Directory Server's set of unavailable alert
* types. It may be {@code null} or empty if
* no unavailable alert types should be added.
* @param removeUnavailableTypes The names of the alert types to remove from
* the Directory Server's set of unavailable
* alert types. It may be {@code null} or
* empty if no unavailable alert types should
* be removed.
*/
public AlertTask(final String alertType, final String alertMessage,
final List addDegradedTypes,
final List removeDegradedTypes,
final List addUnavailableTypes,
final List removeUnavailableTypes)
{
this(null, alertType, alertMessage, addDegradedTypes, removeDegradedTypes,
addUnavailableTypes, removeUnavailableTypes, null, null, null,
null, null);
}
/**
* Creates a new alert task that can be used to generate an administrative
* alert and/or update the set of degraded or unavailable alert types for the
* Directory Server. At least one alert-related element must be provided.
*
* @param taskID The task ID to use for this task. If it is
* {@code null} then a UUID will be generated
* for use as the task ID.
* @param alertType The alert type to use for the generated
* alert. It may be {@code null} if no alert
* should be generated, but if it is
* non-{@code null} then the alert message
* must also be non-{@code null}.
* @param alertMessage The message to use for the generated alert.
* It may be {@code null} if no alert should
* be generated, but if it is non-{@code null}
* then the alert type must also be
* non-{@code null}.
* @param addDegradedTypes The names of the alert types to add to the
* Directory Server's set of degraded alert
* types. It may be {@code null} or empty if
* no degraded alert types should be added.
* @param removeDegradedTypes The names of the alert types to remove from
* the Directory Server's set of degraded
* alert types. It may be {@code null} or
* empty if no degraded alert types should be
* removed.
* @param addUnavailableTypes The names of the alert types to add to the
* Directory Server's set of unavailable alert
* types. It may be {@code null} or empty if
* no unavailable alert types should be added.
* @param removeUnavailableTypes The names of the alert types to remove from
* the Directory Server's set of unavailable
* alert types. It may be {@code null} or
* empty if no unavailable alert types should
* be removed.
* @param scheduledStartTime The time that this task should start
* running.
* @param dependencyIDs The list of task IDs that will be required
* to complete before this task will be
* eligible to start.
* @param failedDependencyAction Indicates what action should be taken if
* any of the dependencies for this task do
* not complete successfully.
* @param notifyOnCompletion The list of e-mail addresses of individuals
* that should be notified when this task
* completes.
* @param notifyOnError The list of e-mail addresses of individuals
* that should be notified if this task does
* not complete successfully.
*/
public AlertTask(final String taskID, final String alertType,
final String alertMessage,
final List addDegradedTypes,
final List removeDegradedTypes,
final List addUnavailableTypes,
final List removeUnavailableTypes,
final Date scheduledStartTime,
final List dependencyIDs,
final FailedDependencyAction failedDependencyAction,
final List notifyOnCompletion,
final List notifyOnError)
{
super(taskID, ALERT_TASK_CLASS, scheduledStartTime, dependencyIDs,
failedDependencyAction, notifyOnCompletion, notifyOnError);
this.alertType = alertType;
this.alertMessage = alertMessage;
ensureTrue((alertType == null) == (alertMessage == null));
this.addDegradedTypes = getStringList(addDegradedTypes);
this.removeDegradedTypes = getStringList(removeDegradedTypes);
this.addUnavailableTypes = getStringList(addUnavailableTypes);
this.removeUnavailableTypes = getStringList(removeUnavailableTypes);
if (alertType == null)
{
ensureFalse(this.addDegradedTypes.isEmpty() &&
this.removeDegradedTypes.isEmpty() &&
this.addUnavailableTypes.isEmpty() &&
this.removeUnavailableTypes.isEmpty());
}
}
/**
* Creates a new alert task from the provided entry.
*
* @param entry The entry to use to create this alert task.
*
* @throws TaskException If the provided entry cannot be parsed as an alert
* task entry.
*/
public AlertTask(final Entry entry)
throws TaskException
{
super(entry);
// Get the alert type and message. If either is present, then both must be.
alertType = entry.getAttributeValue(ATTR_ALERT_TYPE);
alertMessage = entry.getAttributeValue(ATTR_ALERT_MESSAGE);
if ((alertType == null) != (alertMessage == null))
{
throw new TaskException(ERR_ALERT_TYPE_AND_MESSAGE_INTERDEPENDENT.get());
}
// Get the values to add/remove from the degraded/unavailable alert types.
addDegradedTypes = parseStringList(entry, ATTR_ADD_DEGRADED_TYPE);
removeDegradedTypes = parseStringList(entry, ATTR_REMOVE_DEGRADED_TYPE);
addUnavailableTypes = parseStringList(entry, ATTR_ADD_UNAVAILABLE_TYPE);
removeUnavailableTypes = parseStringList(entry,
ATTR_REMOVE_UNAVAILABLE_TYPE);
if ((alertType == null) && addDegradedTypes.isEmpty() &&
removeDegradedTypes.isEmpty() && addUnavailableTypes.isEmpty() &&
removeUnavailableTypes.isEmpty())
{
throw new TaskException(ERR_ALERT_ENTRY_NO_ELEMENTS.get());
}
}
/**
* Creates a new alert task from the provided set of task properties.
*
* @param properties The set of task properties and their corresponding
* values to use for the task. It must not be
* {@code null}.
*
* @throws TaskException If the provided set of properties cannot be used to
* create a valid alert task.
*/
public AlertTask(final Map> properties)
throws TaskException
{
super(ALERT_TASK_CLASS, properties);
String type = null;
String message = null;
final LinkedList addDegraded = new LinkedList();
final LinkedList removeDegraded = new LinkedList();
final LinkedList addUnavailable = new LinkedList();
final LinkedList removeUnavailable = new LinkedList();
for (final Map.Entry> entry :
properties.entrySet())
{
final TaskProperty p = entry.getKey();
final String attrName = StaticUtils.toLowerCase(p.getAttributeName());
final List