001 /*
002 * Copyright 2008-2015 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015 UnboundID Corp.
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 */
021 package com.unboundid.ldap.sdk.unboundidds.tasks;
022
023
024
025 import java.util.ArrayList;
026 import java.util.Arrays;
027 import java.util.Collections;
028 import java.util.Date;
029 import java.util.LinkedHashMap;
030 import java.util.List;
031 import java.util.Map;
032
033 import com.unboundid.ldap.sdk.Attribute;
034 import com.unboundid.ldap.sdk.Entry;
035 import com.unboundid.util.NotMutable;
036 import com.unboundid.util.ThreadSafety;
037 import com.unboundid.util.ThreadSafetyLevel;
038
039 import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
040
041
042
043 /**
044 * <BLOCKQUOTE>
045 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
046 * LDAP SDK for Java. It is not available for use in applications that
047 * include only the Standard Edition of the LDAP SDK, and is not supported for
048 * use in conjunction with non-UnboundID products.
049 * </BLOCKQUOTE>
050 * This class defines a Directory Server task that can be used to cause the
051 * server to leave lockdown mode and resume normal operation. Note that because
052 * of the nature of lockdown mode, it this task may only be requested by a user
053 * with the lockdown-mode privilege. Alternately, the server may be restarted
054 * and it will not be placed in lockdown mode at startup unless a significant
055 * problem is encountered in which there may be a risk of unauthorized access to
056 * data.
057 * <BR><BR>
058 * The leave lockdown mode task does not have any task-specific properties. See
059 * the {@link EnterLockdownModeTask} class for more information about lockdown
060 * mode and a task that may be used to force the server to enter this state.
061 */
062 @NotMutable()
063 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
064 public final class LeaveLockdownModeTask
065 extends Task
066 {
067 /**
068 * The fully-qualified name of the Java class that is used for the leave
069 * lockdown mode task.
070 */
071 static final String LEAVE_LOCKDOWN_MODE_TASK_CLASS =
072 "com.unboundid.directory.server.tasks.LeaveLockdownModeTask";
073
074
075
076 /**
077 * The name of the attribute used to specify the reason for taking the server
078 * out of lockdown mode.
079 */
080 private static final String ATTR_LEAVE_LOCKDOWN_REASON =
081 "ds-task-leave-lockdown-reason";
082
083
084
085 /**
086 * The task property for the leave-lockdown reason.
087 */
088 private static final TaskProperty PROPERTY_LEAVE_LOCKDOWN_REASON =
089 new TaskProperty(ATTR_LEAVE_LOCKDOWN_REASON,
090 INFO_DISPLAY_NAME_LEAVE_LOCKDOWN_REASON.get(),
091 INFO_DESCRIPTION_LEAVE_LOCKDOWN_REASON.get(),
092 String.class, false, false, false);
093
094
095
096 /**
097 * The name of the object class used in leave-lockdown-mode task entries.
098 */
099 private static final String OC_LEAVE_LOCKDOWN_MODE_TASK =
100 "ds-task-leave-lockdown-mode";
101
102
103
104 /**
105 * The serial version UID for this serializable class.
106 */
107 private static final long serialVersionUID = -1353712468653879793L;
108
109
110
111 // The reason for leaving lockdown mode.
112 private final String reason;
113
114
115
116 /**
117 * Creates a new uninitialized enter lockdown mode task instance which should
118 * only be used for obtaining general information about this task, including
119 * the task name, description, and supported properties. Attempts to use a
120 * task created with this constructor for any other reason will likely fail.
121 */
122 public LeaveLockdownModeTask()
123 {
124 reason = null;
125 }
126
127
128
129 /**
130 * Creates a new leave lockdown mode task with the specified task ID.
131 *
132 * @param taskID The task ID to use for this task. If it is {@code null}
133 * then a UUID will be generated for use as the task ID.
134 */
135 public LeaveLockdownModeTask(final String taskID)
136 {
137 this(taskID, null);
138 }
139
140
141
142 /**
143 * Creates a new leave lockdown mode task with the specified task ID.
144 *
145 * @param taskID The task ID to use for this task. If it is {@code null}
146 * then a UUID will be generated for use as the task ID.
147 * @param reason The user-specified reason for leaving lockdown mode. This
148 * may be {@code null}.
149 */
150 public LeaveLockdownModeTask(final String taskID, final String reason)
151 {
152 this(taskID, reason, null, null, null, null, null);
153 }
154
155
156
157 /**
158 * Creates a new leave lockdown mode task with the provided information.
159 *
160 * @param taskID The task ID to use for this task. If it is
161 * {@code null} then a UUID will be generated
162 * for use as the task ID.
163 * @param scheduledStartTime The time that this task should start
164 * running.
165 * @param dependencyIDs The list of task IDs that will be required
166 * to complete before this task will be
167 * eligible to start.
168 * @param failedDependencyAction Indicates what action should be taken if
169 * any of the dependencies for this task do
170 * not complete successfully.
171 * @param notifyOnCompletion The list of e-mail addresses of individuals
172 * that should be notified when this task
173 * completes.
174 * @param notifyOnError The list of e-mail addresses of individuals
175 * that should be notified if this task does
176 * not complete successfully.
177 */
178 public LeaveLockdownModeTask(final String taskID,
179 final Date scheduledStartTime, final List<String> dependencyIDs,
180 final FailedDependencyAction failedDependencyAction,
181 final List<String> notifyOnCompletion,
182 final List<String> notifyOnError)
183 {
184 this(taskID, null, scheduledStartTime, dependencyIDs,
185 failedDependencyAction, notifyOnCompletion, notifyOnError);
186 }
187
188
189
190 /**
191 * Creates a new leave lockdown mode task with the provided information.
192 *
193 * @param taskID The task ID to use for this task. If it is
194 * {@code null} then a UUID will be generated
195 * for use as the task ID.
196 * @param reason The user-specified reason for leaving
197 * lockdown mode. This may be {@code null}.
198 * @param scheduledStartTime The time that this task should start
199 * running.
200 * @param dependencyIDs The list of task IDs that will be required
201 * to complete before this task will be
202 * eligible to start.
203 * @param failedDependencyAction Indicates what action should be taken if
204 * any of the dependencies for this task do
205 * not complete successfully.
206 * @param notifyOnCompletion The list of e-mail addresses of individuals
207 * that should be notified when this task
208 * completes.
209 * @param notifyOnError The list of e-mail addresses of individuals
210 * that should be notified if this task does
211 * not complete successfully.
212 */
213 public LeaveLockdownModeTask(final String taskID, final String reason,
214 final Date scheduledStartTime, final List<String> dependencyIDs,
215 final FailedDependencyAction failedDependencyAction,
216 final List<String> notifyOnCompletion,
217 final List<String> notifyOnError)
218 {
219 super(taskID, LEAVE_LOCKDOWN_MODE_TASK_CLASS, scheduledStartTime,
220 dependencyIDs, failedDependencyAction, notifyOnCompletion,
221 notifyOnError);
222
223 this.reason = reason;
224 }
225
226
227
228 /**
229 * Creates a new leave lockdown mode task from the provided entry.
230 *
231 * @param entry The entry to use to create this leave lockdown mode task.
232 *
233 * @throws TaskException If the provided entry cannot be parsed as a leave
234 * lockdown mode task entry.
235 */
236 public LeaveLockdownModeTask(final Entry entry)
237 throws TaskException
238 {
239 super(entry);
240
241 // Get the "reason" string if it is present.
242 reason = entry.getAttributeValue(ATTR_LEAVE_LOCKDOWN_REASON);
243 }
244
245
246
247 /**
248 * Creates a new leave lockdown mode task from the provided set of task
249 * properties.
250 *
251 * @param properties The set of task properties and their corresponding
252 * values to use for the task. It must not be
253 * {@code null}.
254 *
255 * @throws TaskException If the provided set of properties cannot be used to
256 * create a valid leave lockdown mode task.
257 */
258 public LeaveLockdownModeTask(final Map<TaskProperty,List<Object>> properties)
259 throws TaskException
260 {
261 super(LEAVE_LOCKDOWN_MODE_TASK_CLASS, properties);
262
263 String r = null;
264 for (final Map.Entry<TaskProperty,List<Object>> entry :
265 properties.entrySet())
266 {
267 final TaskProperty p = entry.getKey();
268 final String attrName = p.getAttributeName();
269 final List<Object> values = entry.getValue();
270
271 if (attrName.equalsIgnoreCase(ATTR_LEAVE_LOCKDOWN_REASON))
272 {
273 r = parseString(p, values, null);
274 break;
275 }
276 }
277
278 reason = r;
279 }
280
281
282
283 /**
284 * Retrieves the user-specified reason why the server is leaving lockdown
285 * mode.
286 *
287 * @return The reason the server is leaving lockdown mode, or {@code null}
288 * if none was specified.
289 */
290 public String getReason()
291 {
292 return reason;
293 }
294
295
296
297 /**
298 * {@inheritDoc}
299 */
300 @Override()
301 public String getTaskName()
302 {
303 return INFO_TASK_NAME_LEAVE_LOCKDOWN_MODE.get();
304 }
305
306
307
308 /**
309 * {@inheritDoc}
310 */
311 @Override()
312 public String getTaskDescription()
313 {
314 return INFO_TASK_DESCRIPTION_LEAVE_LOCKDOWN_MODE.get();
315 }
316
317
318
319 /**
320 * {@inheritDoc}
321 */
322 @Override()
323 protected List<String> getAdditionalObjectClasses()
324 {
325 return Arrays.asList(OC_LEAVE_LOCKDOWN_MODE_TASK);
326 }
327
328
329
330 /**
331 * {@inheritDoc}
332 */
333 @Override()
334 protected List<Attribute> getAdditionalAttributes()
335 {
336 final ArrayList<Attribute> attrs = new ArrayList<Attribute>(1);
337 if(reason != null)
338 {
339 attrs.add(new Attribute(ATTR_LEAVE_LOCKDOWN_REASON, reason));
340 }
341 return attrs;
342 }
343
344
345
346 /**
347 * {@inheritDoc}
348 */
349 @Override()
350 public List<TaskProperty> getTaskSpecificProperties()
351 {
352 final List<TaskProperty> propList =
353 Arrays.asList(PROPERTY_LEAVE_LOCKDOWN_REASON);
354
355 return Collections.unmodifiableList(propList);
356 }
357
358
359
360 /**
361 * {@inheritDoc}
362 */
363 @Override()
364 public Map<TaskProperty,List<Object>> getTaskPropertyValues()
365 {
366 final LinkedHashMap<TaskProperty,List<Object>> props =
367 new LinkedHashMap<TaskProperty,List<Object>>();
368
369 if(reason != null)
370 {
371 props.put(PROPERTY_LEAVE_LOCKDOWN_REASON,
372 Collections.<Object>unmodifiableList(Arrays.asList(reason)));
373 }
374
375 props.putAll(super.getTaskPropertyValues());
376 return Collections.unmodifiableMap(props);
377 }
378 }