001 /* 002 * Copyright 2010-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.Arrays; 026 import java.util.Collections; 027 import java.util.Date; 028 import java.util.LinkedHashMap; 029 import java.util.List; 030 import java.util.Map; 031 032 import com.unboundid.ldap.sdk.Attribute; 033 import com.unboundid.ldap.sdk.Entry; 034 import com.unboundid.util.NotMutable; 035 import com.unboundid.util.ThreadSafety; 036 import com.unboundid.util.ThreadSafetyLevel; 037 038 import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*; 039 import static com.unboundid.util.Validator.*; 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 dump 051 * information about the contents of a backend which stores its data in a 052 * Berkeley DB Java Edition database. It reports information about the total 053 * number of keys, total and average key size, and total an average value size 054 * for all of the databases in the environment, and the percentage of the total 055 * live data size contained in each database. 056 * <BR><BR> 057 * The properties that are available for use with this type of task include: 058 * <UL> 059 * <LI>The backend ID of the backend for to be examined. The specified 060 * backend must be enabled and must store its contents in the Berkeley DB 061 * Java Edition.</LI> 062 * </UL> 063 */ 064 @NotMutable() 065 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 066 public final class DumpDBDetailsTask 067 extends Task 068 { 069 /** 070 * The fully-qualified name of the Java class that is used for the dump DB 071 * details task. 072 */ 073 static final String DUMP_DB_DETAILS_TASK_CLASS = 074 "com.unboundid.directory.server.tasks.DumpDBDetailsTask"; 075 076 077 078 /** 079 * The name of the attribute used to specify the backend ID of the target 080 * backend. 081 */ 082 private static final String ATTR_BACKEND_ID = 083 "ds-task-dump-db-backend-id"; 084 085 086 087 /** 088 * The name of the object class used in dump DB details task entries. 089 */ 090 private static final String OC_DUMP_DB_DETAILS_TASK = "ds-task-dump-db"; 091 092 093 094 /** 095 * The task property that will be used for the backend ID. 096 */ 097 private static final TaskProperty PROPERTY_BACKEND_ID = 098 new TaskProperty(ATTR_BACKEND_ID, 099 INFO_DUMP_DB_DISPLAY_NAME_BACKEND_ID.get(), 100 INFO_DUMP_DB_DESCRIPTION_BACKEND_ID.get(), String.class, true, 101 false, false); 102 103 104 105 /** 106 * The serial version UID for this serializable class. 107 */ 108 private static final long serialVersionUID = 7267871080385864231L; 109 110 111 112 // The name of the backend to be examined. 113 private final String backendID; 114 115 116 117 /** 118 * Creates a new uninitialized dump DB details task instance which should only 119 * be used for obtaining general information about this task, including the 120 * task name, description, and supported properties. Attempts to use a task 121 * created with this constructor for any other reason will likely fail. 122 */ 123 public DumpDBDetailsTask() 124 { 125 backendID = null; 126 } 127 128 129 130 131 /** 132 * Creates a new dump DB details task to examine the specified backend. 133 * 134 * @param taskID The task ID to use for this task. If it is {@code null} 135 * then a UUID will be generated for use as the task ID. 136 * @param backendID The backend ID for the backend to examine. It must not 137 * be {@code null}. 138 */ 139 public DumpDBDetailsTask(final String taskID, final String backendID) 140 { 141 this(taskID, backendID, null, null, null, null, null); 142 } 143 144 145 146 /** 147 * Creates a new dump DB details task to examine the specified backend. 148 * 149 * @param taskID The task ID to use for this task. If it is 150 * {@code null} then a UUID will be generated 151 * for use as the task ID. 152 * @param backendID The backend ID for the backend to examine. 153 * It must not be {@code null}. 154 * @param scheduledStartTime The time that this task should start 155 * running. 156 * @param dependencyIDs The list of task IDs that will be required 157 * to complete before this task will be 158 * eligible to start. 159 * @param failedDependencyAction Indicates what action should be taken if 160 * any of the dependencies for this task do 161 * not complete successfully. 162 * @param notifyOnCompletion The list of e-mail addresses of individuals 163 * that should be notified when this task 164 * completes. 165 * @param notifyOnError The list of e-mail addresses of individuals 166 * that should be notified if this task does 167 * not complete successfully. 168 */ 169 public DumpDBDetailsTask(final String taskID, final String backendID, 170 final Date scheduledStartTime, 171 final List<String> dependencyIDs, 172 final FailedDependencyAction failedDependencyAction, 173 final List<String> notifyOnCompletion, 174 final List<String> notifyOnError) 175 { 176 super(taskID, DUMP_DB_DETAILS_TASK_CLASS, scheduledStartTime, dependencyIDs, 177 failedDependencyAction, notifyOnCompletion, notifyOnError); 178 179 ensureNotNull(backendID); 180 181 this.backendID = backendID; 182 } 183 184 185 186 /** 187 * Creates a new dump DB details task from the provided entry. 188 * 189 * @param entry The entry to use to create this dump DB details task. 190 * 191 * @throws TaskException If the provided entry cannot be parsed as a dump DB 192 * details task entry. 193 */ 194 public DumpDBDetailsTask(final Entry entry) 195 throws TaskException 196 { 197 super(entry); 198 199 // Get the backend ID. It must be present. 200 backendID = entry.getAttributeValue(ATTR_BACKEND_ID); 201 if (backendID == null) 202 { 203 throw new TaskException(ERR_DUMP_DB_ENTRY_MISSING_BACKEND_ID.get( 204 getTaskEntryDN(), ATTR_BACKEND_ID)); 205 } 206 } 207 208 209 210 /** 211 * Creates a new dump DB details task from the provided set of task 212 * properties. 213 * 214 * @param properties The set of task properties and their corresponding 215 * values to use for the task. It must not be 216 * {@code null}. 217 * 218 * @throws TaskException If the provided set of properties cannot be used to 219 * create a valid dump DB details task. 220 */ 221 public DumpDBDetailsTask(final Map<TaskProperty,List<Object>> properties) 222 throws TaskException 223 { 224 super(DUMP_DB_DETAILS_TASK_CLASS, properties); 225 226 String id = null; 227 for (final Map.Entry<TaskProperty,List<Object>> entry : 228 properties.entrySet()) 229 { 230 final TaskProperty p = entry.getKey(); 231 final String attrName = p.getAttributeName(); 232 final List<Object> values = entry.getValue(); 233 234 if (attrName.equalsIgnoreCase(ATTR_BACKEND_ID)) 235 { 236 id = parseString(p, values, id); 237 } 238 } 239 240 if (id == null) 241 { 242 throw new TaskException(ERR_DUMP_DB_ENTRY_MISSING_BACKEND_ID.get( 243 getTaskEntryDN(), ATTR_BACKEND_ID)); 244 } 245 246 backendID = id; 247 } 248 249 250 251 /** 252 * {@inheritDoc} 253 */ 254 @Override() 255 public String getTaskName() 256 { 257 return INFO_TASK_NAME_DUMP_DB.get(); 258 } 259 260 261 262 /** 263 * {@inheritDoc} 264 */ 265 @Override() 266 public String getTaskDescription() 267 { 268 return INFO_TASK_DESCRIPTION_DUMP_DB.get(); 269 } 270 271 272 273 /** 274 * Retrieves the backend ID of the backend to examine. 275 * 276 * @return The backend ID of the backend to examine. 277 */ 278 public String getBackendID() 279 { 280 return backendID; 281 } 282 283 284 285 /** 286 * {@inheritDoc} 287 */ 288 @Override() 289 protected List<String> getAdditionalObjectClasses() 290 { 291 return Arrays.asList(OC_DUMP_DB_DETAILS_TASK); 292 } 293 294 295 296 /** 297 * {@inheritDoc} 298 */ 299 @Override() 300 protected List<Attribute> getAdditionalAttributes() 301 { 302 return Arrays.asList(new Attribute(ATTR_BACKEND_ID, backendID)); 303 } 304 305 306 307 /** 308 * {@inheritDoc} 309 */ 310 @Override() 311 public List<TaskProperty> getTaskSpecificProperties() 312 { 313 return Collections.unmodifiableList(Arrays.asList(PROPERTY_BACKEND_ID)); 314 } 315 316 317 318 /** 319 * {@inheritDoc} 320 */ 321 @Override() 322 public Map<TaskProperty,List<Object>> getTaskPropertyValues() 323 { 324 final LinkedHashMap<TaskProperty,List<Object>> props = 325 new LinkedHashMap<TaskProperty,List<Object>>(1); 326 327 props.put(PROPERTY_BACKEND_ID, Collections.<Object>unmodifiableList( 328 Arrays.asList(backendID))); 329 330 props.putAll(super.getTaskPropertyValues()); 331 return Collections.unmodifiableMap(props); 332 } 333 }