001/* 002 * Copyright 2013-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2013-2024 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) 2013-2024 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.extensions; 037 038 039 040import com.unboundid.asn1.ASN1Element; 041import com.unboundid.asn1.ASN1OctetString; 042import com.unboundid.asn1.ASN1Sequence; 043import com.unboundid.ldap.sdk.Control; 044import com.unboundid.ldap.sdk.ExtendedRequest; 045import com.unboundid.ldap.sdk.ExtendedResult; 046import com.unboundid.ldap.sdk.LDAPConnection; 047import com.unboundid.ldap.sdk.LDAPException; 048import com.unboundid.ldap.sdk.ResultCode; 049import com.unboundid.util.Debug; 050import com.unboundid.util.NotNull; 051import com.unboundid.util.Nullable; 052import com.unboundid.util.StaticUtils; 053import com.unboundid.util.ThreadSafety; 054import com.unboundid.util.ThreadSafetyLevel; 055import com.unboundid.util.Validator; 056 057import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 058 059 060 061/** 062 * This class provides an implementation of an extended request that can be used 063 * to identify potential incompatibility problems between two backup 064 * compatibility descriptor values. This can be used to determine whether a 065 * backup from one server (or an older version of the same server) could be 066 * restored into another server (or a newer version of the same server). It 067 * may also be useful in determining whether replication initialization via 068 * binary copy may be performed between two servers. 069 * <BR> 070 * <BLOCKQUOTE> 071 * <B>NOTE:</B> This class, and other classes within the 072 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 073 * supported for use against Ping Identity, UnboundID, and 074 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 075 * for proprietary functionality or for external specifications that are not 076 * considered stable or mature enough to be guaranteed to work in an 077 * interoperable way with other types of LDAP servers. 078 * </BLOCKQUOTE> 079 * <BR> 080 * The OID for this extended request is 1.3.6.1.4.1.30221.2.6.32. It must have 081 * a value with the following encoding: 082 * <PRE> 083 * IdentifyBackupCompatibilityProblemsRequest ::= SEQUENCE { 084 * sourceDescriptor [0] OCTET STRING, 085 * targetDescriptor [1] OCTET STRING, 086 * ... } 087 * </PRE> 088 * 089 * @see IdentifyBackupCompatibilityProblemsExtendedResult 090 * @see GetBackupCompatibilityDescriptorExtendedRequest 091 */ 092@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 093public final class IdentifyBackupCompatibilityProblemsExtendedRequest 094 extends ExtendedRequest 095{ 096 /** 097 * The OID (1.3.6.1.4.1.30221.2.6.32) for the identify backup compatibility 098 * problems extended request. 099 */ 100 @NotNull public static final String 101 IDENTIFY_BACKUP_COMPATIBILITY_PROBLEMS_REQUEST_OID = 102 "1.3.6.1.4.1.30221.2.6.32"; 103 104 105 106 /** 107 * The BER type for the source descriptor element in the value sequence. 108 */ 109 private static final byte TYPE_SOURCE_DESCRIPTOR = (byte) 0x80; 110 111 112 113 /** 114 * The BER type for the target descriptor element in the value sequence. 115 */ 116 private static final byte TYPE_TARGET_DESCRIPTOR = (byte) 0x81; 117 118 119 120 /** 121 * The serial version UID for this serializable class. 122 */ 123 private static final long serialVersionUID = 6723590129573376599L; 124 125 126 127 // The backup compatibility descriptor obtained from the source server, or 128 // from a backup to be restored. 129 @NotNull private final ASN1OctetString sourceDescriptor; 130 131 // The backup compatibility descriptor obtained from the target server. 132 @NotNull private final ASN1OctetString targetDescriptor; 133 134 135 136 /** 137 * Creates a new identify backup compatibility problems extended request with 138 * the provided information. 139 * 140 * @param sourceDescriptor The backup compatibility descriptor obtained from 141 * the source server, or from a backup to be 142 * restored. It must not be {@code null}. 143 * @param targetDescriptor The backup compatibility descriptor obtained from 144 * the target server. It must not be {@code null}. 145 * @param controls The set of controls to include in the request. 146 * It may be {@code null} or empty if no controls 147 * should be included. 148 */ 149 public IdentifyBackupCompatibilityProblemsExtendedRequest( 150 @NotNull final ASN1OctetString sourceDescriptor, 151 @NotNull final ASN1OctetString targetDescriptor, 152 @Nullable final Control... controls) 153 { 154 super(IDENTIFY_BACKUP_COMPATIBILITY_PROBLEMS_REQUEST_OID, 155 encodeValue(sourceDescriptor, targetDescriptor), controls); 156 157 this.sourceDescriptor = new ASN1OctetString(TYPE_SOURCE_DESCRIPTOR, 158 sourceDescriptor.getValue()); 159 this.targetDescriptor = new ASN1OctetString(TYPE_TARGET_DESCRIPTOR, 160 targetDescriptor.getValue()); 161 } 162 163 164 165 /** 166 * Creates a new identify backup compatibility problems extended request from 167 * the provided generic extended request. 168 * 169 * @param r The generic extended request to decode as an identify backup 170 * compatibility problems extended request. 171 * 172 * @throws LDAPException If the provided request cannot be decoded as an 173 * identify backup compatibility problems extended 174 * request. 175 */ 176 public IdentifyBackupCompatibilityProblemsExtendedRequest( 177 @NotNull final ExtendedRequest r) 178 throws LDAPException 179 { 180 super(r); 181 182 final ASN1OctetString value = r.getValue(); 183 if (value == null) 184 { 185 throw new LDAPException(ResultCode.DECODING_ERROR, 186 ERR_IDENTIFY_BACKUP_COMPAT_PROBLEMS_REQUEST_NO_VALUE.get()); 187 } 188 189 try 190 { 191 final ASN1Element[] elements = 192 ASN1Sequence.decodeAsSequence(value.getValue()).elements(); 193 sourceDescriptor = 194 new ASN1OctetString(TYPE_SOURCE_DESCRIPTOR, elements[0].getValue()); 195 targetDescriptor = 196 new ASN1OctetString(TYPE_SOURCE_DESCRIPTOR, elements[1].getValue()); 197 } 198 catch (final Exception e) 199 { 200 Debug.debugException(e); 201 throw new LDAPException(ResultCode.DECODING_ERROR, 202 ERR_IDENTIFY_BACKUP_COMPAT_PROBLEMS_REQUEST_ERROR_PARSING_VALUE.get( 203 StaticUtils.getExceptionMessage(e)), 204 e); 205 } 206 } 207 208 209 210 /** 211 * Encodes the provided information into a format suitable for use as the 212 * value of this extended request. 213 * 214 * @param sourceDescriptor The backup compatibility descriptor obtained from 215 * the source server, or from a backup to be 216 * restored. It must not be {@code null}. 217 * @param targetDescriptor The backup compatibility descriptor obtained from 218 * the target server. It must not be {@code null}. 219 * 220 * @return The ASN.1 octet string containing the encoded representation of 221 * the provided information. 222 */ 223 @NotNull() 224 private static ASN1OctetString encodeValue( 225 @NotNull final ASN1OctetString sourceDescriptor, 226 @NotNull final ASN1OctetString targetDescriptor) 227 { 228 Validator.ensureNotNull(sourceDescriptor); 229 Validator.ensureNotNull(targetDescriptor); 230 231 final ASN1Sequence valueSequence = new ASN1Sequence( 232 new ASN1OctetString(TYPE_SOURCE_DESCRIPTOR, 233 sourceDescriptor.getValue()), 234 new ASN1OctetString(TYPE_TARGET_DESCRIPTOR, 235 targetDescriptor.getValue())); 236 237 return new ASN1OctetString(valueSequence.encode()); 238 } 239 240 241 242 /** 243 * Retrieves the backup compatibility descriptor obtained from the source 244 * server, or from a backup to be restored. 245 * 246 * @return The backup compatibility descriptor obtained from the source 247 * server, or from a backup to be restored. 248 */ 249 @NotNull() 250 public ASN1OctetString getSourceDescriptor() 251 { 252 return sourceDescriptor; 253 } 254 255 256 257 /** 258 * Retrieves the backup compatibility descriptor obtained from the target 259 * server. 260 * 261 * @return The backup compatibility descriptor obtained from the target 262 * server. 263 */ 264 @NotNull() 265 public ASN1OctetString getTargetDescriptor() 266 { 267 return targetDescriptor; 268 } 269 270 271 272 /** 273 * {@inheritDoc} 274 */ 275 @Override() 276 @NotNull() 277 public IdentifyBackupCompatibilityProblemsExtendedResult process( 278 @NotNull final LDAPConnection connection, final int depth) 279 throws LDAPException 280 { 281 final ExtendedResult extendedResponse = super.process(connection, depth); 282 return new IdentifyBackupCompatibilityProblemsExtendedResult( 283 extendedResponse); 284 } 285 286 287 288 /** 289 * {@inheritDoc} 290 */ 291 @Override() 292 @NotNull() 293 public IdentifyBackupCompatibilityProblemsExtendedRequest duplicate() 294 { 295 return duplicate(getControls()); 296 } 297 298 299 300 /** 301 * {@inheritDoc} 302 */ 303 @Override() 304 @NotNull() 305 public IdentifyBackupCompatibilityProblemsExtendedRequest duplicate( 306 @Nullable final Control[] controls) 307 { 308 final IdentifyBackupCompatibilityProblemsExtendedRequest r = 309 new IdentifyBackupCompatibilityProblemsExtendedRequest( 310 sourceDescriptor, targetDescriptor, controls); 311 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); 312 r.setIntermediateResponseListener(getIntermediateResponseListener()); 313 r.setReferralDepth(getReferralDepth()); 314 r.setReferralConnector(getReferralConnectorInternal()); 315 return r; 316 } 317 318 319 320 /** 321 * {@inheritDoc} 322 */ 323 @Override() 324 @NotNull() 325 public String getExtendedRequestName() 326 { 327 return INFO_EXTENDED_REQUEST_NAME_IDENTIFY_BACKUP_COMPAT_PROBLEMS.get(); 328 } 329 330 331 332 /** 333 * {@inheritDoc} 334 */ 335 @Override() 336 public void toString(@NotNull final StringBuilder buffer) 337 { 338 buffer.append("IdentifyBackupCompatibilityProblemsExtendedRequest(" + 339 "sourceDescriptorLength="); 340 buffer.append(sourceDescriptor.getValueLength()); 341 buffer.append(", targetDescriptorLength="); 342 buffer.append(targetDescriptor.getValueLength()); 343 344 final Control[] controls = getControls(); 345 if (controls.length > 0) 346 { 347 buffer.append(", controls={"); 348 for (int i=0; i < controls.length; i++) 349 { 350 if (i > 0) 351 { 352 buffer.append(", "); 353 } 354 355 buffer.append(controls[i]); 356 } 357 buffer.append('}'); 358 } 359 360 buffer.append(')'); 361 } 362}