~ubuntu-branches/ubuntu/wily/389-ds-console/wily-proposed

« back to all changes in this revision

Viewing changes to src/com/netscape/admin/dirserv/panel/replication/ReplicationAgreement.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-03-15 19:58:37 UTC
  • Revision ID: package-import@ubuntu.com-20120315195837-296zyft51thld8q7
Tags: upstream-1.2.6
ImportĀ upstreamĀ versionĀ 1.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** BEGIN COPYRIGHT BLOCK
 
2
 * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
 
3
 * Copyright (C) 2005 Red Hat, Inc.
 
4
 * All rights reserved.
 
5
 * 
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation version 2 of the License.
 
9
 * 
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 * 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 * END COPYRIGHT BLOCK **/
 
19
 
 
20
package com.netscape.admin.dirserv.panel.replication;
 
21
 
 
22
import java.util.*;
 
23
import java.text.*;
 
24
import java.net.*;
 
25
import java.io.*;
 
26
import javax.swing.*;
 
27
import netscape.ldap.*;
 
28
import netscape.ldap.controls.*;
 
29
import netscape.ldap.util.*;
 
30
import com.netscape.management.client.util.*;
 
31
import com.netscape.management.client.console.*;
 
32
import com.netscape.admin.dirserv.*;
 
33
import com.netscape.admin.dirserv.panel.*;
 
34
import com.netscape.admin.dirserv.task.ReadOnly;
 
35
import com.netscape.admin.dirserv.task.LDAPExport;
 
36
 
 
37
/**
 
38
 * Replication Agreement
 
39
 *
 
40
 * @author  ggoods
 
41
 * @author  jpanchen
 
42
 * @version %I%, %G%
 
43
 * @date                11/11/97
 
44
 * @see     com.netscape.admin.dirserv.panel.replication
 
45
 */
 
46
public class ReplicationAgreement implements IReplicationAgreement {
 
47
    
 
48
    /*==========================================================
 
49
     * constructors
 
50
     *==========================================================*/
 
51
    public ReplicationAgreement(int aType) {
 
52
        agreementType = aType;
 
53
        selattrType = SELATTR_ALL;  /* just a guess */
 
54
        agreementIsNew = true;
 
55
        updateSchedule = new Vector();
 
56
        needsReORC = false;
 
57
    }
 
58
    
 
59
        /*==========================================================
 
60
         * public methods
 
61
     *==========================================================*/
 
62
     
 
63
    /**
 
64
     * Set the current server information
 
65
     */
 
66
    public void setServerInfo(ConsoleInfo info) {
 
67
        _serverInfo = info;
 
68
    }
 
69
    
 
70
    /**
 
71
     * Get server info
 
72
     */
 
73
    public ConsoleInfo getServerInfo() {
 
74
        return _serverInfo;
 
75
    }
 
76
 
 
77
    /**
 
78
     * Set the nickname for this agreement.
 
79
     */
 
80
    public void setNickname(String s) {
 
81
        nickname = s;
 
82
    }
 
83
 
 
84
    /**
 
85
     * Get the nickname for this agreement.
 
86
     */
 
87
    public String getNickname() {
 
88
        return nickname;
 
89
    }
 
90
 
 
91
    /**
 
92
     * Set the original DN of the entry corresponding to this agreement.
 
93
     */
 
94
    public void setOrigEntryDN(String dn) {
 
95
                Debug.println( "ReplicationAgreement.setOrigEntryDN: " + dn );
 
96
        origEntryDN = dn;
 
97
    }
 
98
 
 
99
    /**
 
100
     * Get the original DN of the entry corresponding to this agreement.
 
101
     */
 
102
    public String getOrigEntryDN() {
 
103
        return origEntryDN;
 
104
    }
 
105
 
 
106
    /**
 
107
     * Set the DN of the entry corresponding to this agreement.
 
108
     */
 
109
    protected void setEntryDN(String dn) {
 
110
                Debug.println( "ReplicationAgreement.setEntryDN: " + dn );
 
111
        entryDN = dn;
 
112
    }
 
113
 
 
114
    /**
 
115
     * Get the DN of the entry corresponding to this agreement.
 
116
     */
 
117
    public String getEntryDN() {
 
118
        return entryDN;
 
119
    }
 
120
    
 
121
    /**
 
122
     * Set the root of the replicated subtree.  This routine
 
123
     * removes any extra spaces between DN components.
 
124
     */
 
125
    public void setReplicatedSubtree(String r) {
 
126
        if (r == null ||
 
127
                        r.equals(_resource.getString("replication","misc-rootName"))) {
 
128
            replicatedSubtree = "";
 
129
        } else {
 
130
            if (r == null || r.length() == 0) {
 
131
                replicatedSubtree = null;
 
132
            } else {
 
133
                DN tmpDN = new DN(r);
 
134
                replicatedSubtree = tmpDN.toString();
 
135
            }
 
136
        }
 
137
   }
 
138
 
 
139
    /**
 
140
     * Get the root of the replicated subtree.
 
141
     */
 
142
    public String getReplicatedSubtree() {
 
143
        return replicatedSubtree;
 
144
    }
 
145
 
 
146
    /**
 
147
     * Set the host name of the consumer.
 
148
     */
 
149
    public void setConsumerHost(String h) {
 
150
        consumerHost = h;
 
151
    }
 
152
 
 
153
    /**
 
154
     * Get the host name of the consumer.
 
155
     */
 
156
    public String getConsumerHost() {
 
157
        return consumerHost;
 
158
    }
 
159
 
 
160
    /**
 
161
     * Set the port number for the consumer server.
 
162
     */
 
163
    public void setConsumerPort(int p) {
 
164
        consumerPort = p;
 
165
    }
 
166
 
 
167
    /**
 
168
     * Get the port number for the consumer server.
 
169
     */
 
170
    public int getConsumerPort() {
 
171
        return consumerPort;
 
172
    }
 
173
    /**
 
174
     * Set the host name of the supplier.
 
175
     */
 
176
    public void setSupplierHost(String h) {
 
177
        supplierHost = h;
 
178
    }
 
179
 
 
180
    /**
 
181
     * Get the host name of the supplier.
 
182
     */
 
183
    public String getSupplierHost() {
 
184
        return supplierHost;
 
185
    }
 
186
 
 
187
    /**
 
188
     * Set the port number for the supplier server.
 
189
     */
 
190
    public void setSupplierPort(int p) {
 
191
        supplierPort = p;
 
192
    }
 
193
 
 
194
    /**
 
195
     * Get the port number for the supplier server.
 
196
     */
 
197
    public int getSupplierPort() {
 
198
        return supplierPort;
 
199
    }
 
200
 
 
201
    /**
 
202
     * Set the remote host name of the server
 
203
     */
 
204
    public void setRemoteHost(String h) {
 
205
                consumerHost = h;
 
206
    }
 
207
 
 
208
    /**
 
209
     * Get the remote host name
 
210
     */
 
211
        public String getRemoteHost() {
 
212
                return consumerHost;
 
213
    }
 
214
 
 
215
    /**
 
216
     * Set the remote port of the server
 
217
     */
 
218
    public void setRemotePort(int p) {
 
219
                consumerPort = p;
 
220
    }
 
221
 
 
222
    /**
 
223
     * Get the remote port
 
224
     */
 
225
    public int getRemotePort() {
 
226
                return consumerPort;
 
227
    }
 
228
 
 
229
    /**
 
230
     * Set the DN used when binding to the consumer.
 
231
     */
 
232
    public void setBindDN(String dn) {
 
233
        bindDN = dn;
 
234
    }
 
235
 
 
236
    /**
 
237
     * Get the DN used when binding to the consumer.
 
238
     */
 
239
    public String getBindDN() {
 
240
        return bindDN;
 
241
    }
 
242
 
 
243
    /**
 
244
     * Set the credentials used when binding to the consumer.
 
245
     */
 
246
    public void setBindCredentials(String cred) {
 
247
        bindCredentials = cred;
 
248
    }
 
249
 
 
250
    /**
 
251
     * Get the credentials used when binding to the consumer.
 
252
     */
 
253
    public String getBindCredentials() {
 
254
        return bindCredentials;
 
255
    }
 
256
 
 
257
    /**
 
258
     * Set the schedule used to update the consumer.
 
259
     */
 
260
    public void setUpdateSchedule(Vector sched) {
 
261
        updateSchedule = sched;
 
262
    }
 
263
 
 
264
    /**
 
265
     * Set the schedule used to update the consumer.
 
266
     */
 
267
    public void setUpdateSchedule(String s) {
 
268
        updateSchedule.removeAllElements();
 
269
        updateSchedule.addElement(s);
 
270
    }
 
271
 
 
272
    /**
 
273
     * Add to the update schedule
 
274
     */
 
275
    public void addUpdateSchedule(String schedItem) {
 
276
        if (schedItem != null) {
 
277
            updateSchedule.addElement(schedItem);
 
278
        }
 
279
    }
 
280
 
 
281
 
 
282
    /**
 
283
     * Get the schedule used to update the consumer.
 
284
     */
 
285
    public Vector getUpdateSchedule() {
 
286
        return updateSchedule;
 
287
    }
 
288
 
 
289
    /**
 
290
     * Get the replication schedule, as an array of Strings
 
291
     */
 
292
    public String[] getUpdateScheduleStrings() {
 
293
        String[] ret;
 
294
 
 
295
        if (updateSchedule == null || updateSchedule.isEmpty()) {
 
296
            return null;
 
297
        } else {
 
298
            ret = new String[updateSchedule.size()];
 
299
        }
 
300
        Enumeration schedEnum = updateSchedule.elements();
 
301
        int i = 0;
 
302
        while (schedEnum.hasMoreElements()) {
 
303
            ret[i] = ((String)schedEnum.nextElement());
 
304
            i++;
 
305
        }
 
306
        return ret;
 
307
    }
 
308
 
 
309
    /**
 
310
     * Set the useSSL flag
 
311
     */
 
312
    public void setUseSSL(String val) {
 
313
        Debug.println(8,"ReplicationAgreement.useSSL() val = " + val);
 
314
        if (val.equalsIgnoreCase("true")) {
 
315
            useSSL = true;
 
316
        } else if (val.equals("1")) {
 
317
            useSSL = true;
 
318
        } else if (val.equals(ReplicationTool.REPLICA_TRANSPORT_SSL)) {
 
319
            useSSL = true;
 
320
        } else {
 
321
            useSSL = false;
 
322
        }
 
323
        Debug.println(8,"ReplicationAgreement.useSSL() = " + useSSL );
 
324
    }
 
325
 
 
326
    /**
 
327
     * Set the useSSL flag
 
328
     */
 
329
    public void setUseSSL(boolean val) {
 
330
        useSSL = val;
 
331
    }
 
332
 
 
333
    /**
 
334
     * Get the useSSL flag
 
335
     */
 
336
    public boolean getUseSSL() {
 
337
        return useSSL;
 
338
    }
 
339
 
 
340
    /**
 
341
     * Set the useStartTLS flag
 
342
     */
 
343
    public void setUseStartTLS(String val) {
 
344
        Debug.println(8,"ReplicationAgreement.useStartTLS() val = " + val);
 
345
        if ((val != null) && val.equals(ReplicationTool.REPLICA_TRANSPORT_TLS)) {
 
346
            useStartTLS = true;
 
347
            useSSL = false;
 
348
        } else {
 
349
            useStartTLS = false;
 
350
        }
 
351
        Debug.println(8,"ReplicationAgreement.useStartTLS() = " + useStartTLS );
 
352
    }
 
353
 
 
354
    /**
 
355
     * Set the useSSL flag
 
356
     */
 
357
    public void setUseStartTLS(boolean val) {
 
358
        useStartTLS = val;
 
359
    }
 
360
 
 
361
    /**
 
362
     * Get the useSSL flag
 
363
     */
 
364
    public boolean getUseStartTLS() {
 
365
        return useStartTLS;
 
366
    }
 
367
 
 
368
     /**
 
369
     * Set the setUseSSLAuth flag
 
370
     */
 
371
    public void setUseSSLAuth(String val) {
 
372
        if (val.equalsIgnoreCase("true")) {
 
373
            useSSLAuth = true;
 
374
        }  else if (val.equals(ReplicationTool.REPLICA_BINDMETHOD_SSLCLIENTAUTH)) {
 
375
            useSSLAuth = true;
 
376
        } else {
 
377
            useSSLAuth = false;
 
378
        }
 
379
    }
 
380
   
 
381
    /**
 
382
     * Set the setUseSSLAuth flag
 
383
     */
 
384
    public void setUseSSLAuth(boolean val) {
 
385
        useSSLAuth = val;
 
386
    }
 
387
 
 
388
    /**
 
389
     * Get the useSSLAuth flag
 
390
     */
 
391
    public boolean getUseSSLAuth() {
 
392
        return useSSLAuth;
 
393
    }
 
394
 
 
395
    /**
 
396
     * Set the setUseGSSAPIAuth flag
 
397
     */
 
398
    public void setUseGSSAPIAuth(String val) {
 
399
        if (val.equalsIgnoreCase("true")) {
 
400
            useGSSAPIAuth = true;
 
401
        } else if (val.equals(ReplicationTool.REPLICA_BINDMETHOD_SASL_GSSAPI)) {
 
402
                useGSSAPIAuth = true;
 
403
        } else {
 
404
                useGSSAPIAuth = false;
 
405
        }
 
406
    }
 
407
   
 
408
    /**
 
409
     * Set the setUseGSSAPIAuth flag
 
410
     */
 
411
    public void setUseGSSAPIAuth(boolean val) {
 
412
        useGSSAPIAuth = val;
 
413
    }
 
414
 
 
415
    /**
 
416
     * Get the setUseGSSAPIAuth flag
 
417
     */
 
418
    public boolean getUseGSSAPIAuth() {
 
419
        return useGSSAPIAuth;
 
420
    }
 
421
 
 
422
    /**
 
423
     * Set the setUseDigestAuth flag
 
424
     */
 
425
    public void setUseDigestAuth(String val) {
 
426
        if (val.equalsIgnoreCase("true")) {
 
427
            useDigestAuth = true;
 
428
        } else if (val.equals(ReplicationTool.REPLICA_BINDMETHOD_SASL_DIGEST_MD5)) {
 
429
                useDigestAuth = true;
 
430
        } else {
 
431
                useDigestAuth = false;
 
432
        }
 
433
    }
 
434
   
 
435
    /**
 
436
     * Set the setUseDigestAuth flag
 
437
     */
 
438
    public void setUseDigestAuth(boolean val) {
 
439
        useDigestAuth = val;
 
440
    }
 
441
 
 
442
    /**
 
443
     * Get the setUseDigestAuth flag
 
444
     */
 
445
    public boolean getUseDigestAuth() {
 
446
        return useDigestAuth;
 
447
    }
 
448
 
 
449
    /**
 
450
     * Set the type of agreement.
 
451
     */
 
452
    public void setAgreementType(int type) {
 
453
        agreementType = type;
 
454
    }
 
455
 
 
456
    /**
 
457
     * Get the agreement type
 
458
     */
 
459
    public int getAgreementType() {
 
460
        return agreementType;
 
461
    }
 
462
 
 
463
    /**
 
464
     * Get the CN (common name) of this entry
 
465
     */
 
466
    public String getEntryCN() {
 
467
        return entryCN;
 
468
    }
 
469
 
 
470
    /**
 
471
     * Explicitly set the CN (common name) of this entry
 
472
     */
 
473
    public void setEntryCN(String cn) {
 
474
        entryCN = cn;
 
475
    }
 
476
 
 
477
    /**
 
478
     * Set the replica entry filter (for filtered replication)
 
479
     */
 
480
    public void setEntryFilter(String f) {
 
481
        entryFilter = f;
 
482
    }
 
483
 
 
484
    /**
 
485
     * Get the replica entry filter (for filtered replication)
 
486
     */
 
487
    public String getEntryFilter() {
 
488
        return entryFilter;
 
489
    }
 
490
 
 
491
    /**
 
492
     * Get the type of attribute selection
 
493
     */
 
494
    public int getSelattrType() {
 
495
        return selattrType;
 
496
    }
 
497
 
 
498
    /**
 
499
     * Set the type of attribute selection
 
500
     */
 
501
    public void setSelattrType(int t) {
 
502
        selattrType = t;
 
503
    }
 
504
 
 
505
    /**
 
506
     * Get the list of selected attributes
 
507
     */
 
508
    public Vector getSelectedAttributes() {
 
509
        return selectedAttrs;
 
510
    }
 
511
 
 
512
    public String getSelectedAttributesString() {
 
513
        String retStr = "";
 
514
        if (selectedAttrs == null) {
 
515
            return retStr;
 
516
        }
 
517
        Enumeration en = selectedAttrs.elements();
 
518
        while (en.hasMoreElements()) {
 
519
            retStr += (String)en.nextElement() + "\n";
 
520
        }
 
521
        return retStr;
 
522
    }
 
523
 
 
524
    /**
 
525
     * Set the list of selected attributes in Sorted Vector format
 
526
     */
 
527
    public void setSelectedAttributes(Vector s) {
 
528
        selectedAttrs = s;    
 
529
    }
 
530
 
 
531
    /**
 
532
     * Set the list of selected attributes, sorting it on the
 
533
     * way in.
 
534
     */
 
535
    public void setSelectedAttributes(String s) {
 
536
        // Parse the list into a set of attributes.  Tokens are
 
537
        // whitespace, newlines, tabs, colon, or comma.
 
538
        // The sorting algorithm is lame, but who cares?  There
 
539
        // aren't more than a few hundred elements, tops.
 
540
 
 
541
        int i, j;
 
542
        StringTokenizer st = new StringTokenizer(s, " \n\t:,", false);
 
543
        Vector tmp = new Vector();
 
544
        while (st.hasMoreTokens()) {
 
545
            tmp.addElement(st.nextToken());
 
546
        }
 
547
 
 
548
        // Convert to an array of objects
 
549
        String[] arr = new String[tmp.size()];
 
550
        tmp.copyInto(arr);
 
551
 
 
552
        // Sort "arr" with a cheesy bubble sort
 
553
        for (i = arr.length; --i >= 0; ) {
 
554
            boolean swapped = false;
 
555
            for (j = 0; j < i; j++) {
 
556
                if (arr[j].toLowerCase().compareTo(arr[j + 1].toLowerCase()) > 0) {
 
557
                    String o = arr[j];
 
558
                    arr[j] = arr[j + 1];
 
559
                    arr[j + 1] = o;
 
560
                    swapped = true;
 
561
                }
 
562
                //if (!swapped) {
 
563
                   // break;
 
564
                //}
 
565
            }
 
566
        }
 
567
 
 
568
        // Copy back into selectedAttrs
 
569
        selectedAttrs = new Vector(arr.length);
 
570
        for (i = 0; i < arr.length; i++) {
 
571
            if (i < arr.length - 1) {
 
572
                // Remove any duplicates
 
573
                if (arr[i].equalsIgnoreCase(arr[i +1])) {
 
574
                    continue;
 
575
                }
 
576
            }
 
577
            selectedAttrs.addElement(arr[i]);
 
578
        }
 
579
    }
 
580
 
 
581
    /**
 
582
     * Return a long, descriptive string for this agreement
 
583
     */
 
584
//     public String getDescription() {
 
585
//         String r;
 
586
//         String host;
 
587
//         int port;
 
588
 
 
589
//              host = consumerHost;
 
590
//              port = consumerPort;
 
591
 
 
592
//         r = host;
 
593
//         if (r != null && port != 0) {
 
594
//             r = r + " : " + port;
 
595
//         }
 
596
//         if (nickname != null) {
 
597
//             r = r + " (" + nickname + ")";
 
598
//         }
 
599
//         return r;
 
600
//     }
 
601
 
 
602
 
 
603
    /** 
 
604
     * Set agreement description
 
605
     */
 
606
    public void setDescription(String s){
 
607
        _description = s;
 
608
    }
 
609
 
 
610
    public String getDescription(){
 
611
        return _description;    
 
612
    }
 
613
    /**
 
614
     * Set a reference to the other replciation agreements
 
615
     */
 
616
    public void setAgreementTable(AgreementTable r) {
 
617
        repList = r;
 
618
    }
 
619
 
 
620
    /**
 
621
     * Set the ORC value (one of "start", ???, or null)
 
622
     */
 
623
    public void setORCValue(String s) {
 
624
        orcValue = s;
 
625
    }
 
626
 
 
627
 
 
628
    /**
 
629
     * Get the state of ORC at the time the entry was last read
 
630
     */
 
631
    public String getORCValue() {
 
632
        return orcValue;
 
633
    }
 
634
 
 
635
 
 
636
    /**
 
637
     * Return true if the agreement's DN has changed, false otherwise
 
638
     */
 
639
    public boolean agreementDNHasChanged() {
 
640
        computeNewEntryCNandDN();
 
641
        boolean changed = !DSUtil.equalDNs(origEntryDN, entryDN);
 
642
        Debug.println( "ReplicationAgreement.agreementDNHasChanged: " +
 
643
                       origEntryDN + (changed ? " <> " : " = ") +
 
644
                       entryDN );
 
645
        return changed;
 
646
    }
 
647
 
 
648
    /**
 
649
     * Construct a new entry CN and DNbased on the replica root, host,
 
650
         * and port number
 
651
     */
 
652
    protected void computeNewEntryCNandDN() {
 
653
        entryCN = nickname;
 
654
        String xdn[] = LDAPDN.explodeDN(origEntryDN, false);
 
655
        entryDN = "cn" + "=" + entryCN;
 
656
 
 
657
        if (xdn == null || xdn.length == 0) {
 
658
            entryDN = null;
 
659
        } else {
 
660
            for (int i = 1; i < xdn.length; i++) {
 
661
                entryDN = entryDN + ", " + xdn[i];
 
662
            }
 
663
        }
 
664
    }
 
665
 
 
666
    /**
 
667
     * Return true if the agreement is new (that is, it does not yet
 
668
     * exist as an entry in the server's database.
 
669
     */
 
670
    public boolean getAgreementIsNew() {
 
671
        return agreementIsNew;
 
672
    }
 
673
    
 
674
    public int writeAgreementToServer() {
 
675
        int rc = 0;
 
676
 
 
677
        if (checkForReORC()) {
 
678
            Debug.println("ReplicationAgreement.writeAgreementToServer: " +
 
679
                                                  "Consumer needs to be reinitialized");
 
680
        }
 
681
        
 
682
        // First check for some common fixups we need to do:
 
683
        // 1) If the agreement's subtree, host, or port number has changed,
 
684
                //    its DN will change.
 
685
        switch (agreementType) {
 
686
        case AGREEMENT_TYPE_MMR:
 
687
            setConsumerHost(ReplicationTool.fullyQualifyHostName(
 
688
                                getConsumerHost()));
 
689
            try {
 
690
                rc = ((MMRAgreement)this).writeToServer();
 
691
            } catch (IOException e) {
 
692
                Debug.println("ReplicationAgreement.writeAgreementToServer: " +
 
693
                                                          "Cannot save entry <" + entryDN +
 
694
                                                          "> to server: " + e );
 
695
            }
 
696
            break;
 
697
        case AGREEMENT_TYPE_LEGACYR:
 
698
            setConsumerHost(ReplicationTool.fullyQualifyHostName(
 
699
                                getConsumerHost()));
 
700
            try {
 
701
                rc = ((SIRAgreement)this).writeToServer();
 
702
            } catch (IOException e) {
 
703
                Debug.println("ReplicationAgreement.writeAgreementToServer: " +
 
704
                                                          "Cannot save entry <" + entryDN +
 
705
                                                          "> to server: " + e );
 
706
            }
 
707
            break;
 
708
            case AGREEMENT_TYPE_AD:
 
709
           // case AGREEMENT_TYPE_NT:
 
710
                    setConsumerHost(ReplicationTool.fullyQualifyHostName(
 
711
                                getConsumerHost()));
 
712
            try {
 
713
                rc = ((ActiveDirectoryAgreement)this).writeToServer();
 
714
            } catch (IOException e) {
 
715
                Debug.println("ReplicationAgreement.writeAgreementToServer: " +
 
716
                                                          "Cannot save entry <" + entryDN +
 
717
                                                          "> to server: " + e );
 
718
            }
 
719
            break;
 
720
        }
 
721
        return rc;
 
722
    }
 
723
 
 
724
    public void deleteAgreementFromServer() throws LDAPException {
 
725
        LDAPConnection ld = _serverInfo.getLDAPConnection();
 
726
        ld.delete(origEntryDN);
 
727
    }
 
728
    
 
729
    /**
 
730
     * Verify that the agreement is valid, and doesn't conflict with any
 
731
     * other agreements we know about.  "conflict" means has the same
 
732
     * server, port, and subtree.  Returns a vector of integers describing
 
733
     * the errors, which will be empty if there were no errors.
 
734
     */
 
735
    public Vector checkForErrors() {
 
736
        Vector errors = new Vector();
 
737
        Enumeration replicasEnum = repList.elements();
 
738
        String tmpHost;
 
739
        if ((tmpHost =
 
740
                         ReplicationTool.fullyQualifyHostName(getRemoteHost())) != null) {
 
741
            setRemoteHost(tmpHost);
 
742
        }
 
743
        while (replicasEnum.hasMoreElements()) {
 
744
            ReplicationAgreement ra =
 
745
                                (ReplicationAgreement) replicasEnum.nextElement();
 
746
            if (!ra.getRemoteHost().equalsIgnoreCase(getRemoteHost())) {
 
747
                continue;
 
748
            }
 
749
            if (ra.getRemotePort() != getRemotePort()) {
 
750
                continue;
 
751
            }
 
752
            if (!DSUtil.equalDNs(ra.getReplicatedSubtree(),
 
753
                                                                 getReplicatedSubtree())) {
 
754
                continue;
 
755
            } else if (ra == this) {
 
756
                // If it's this agreement, then it's ok.
 
757
                continue;
 
758
            } else {
 
759
            }
 
760
            errors.addElement(new Integer(AGREEMENT_EXISTS));
 
761
        }
 
762
        
 
763
        return errors;
 
764
    }
 
765
 
 
766
 
 
767
    /**
 
768
     * Cause the replica to be updated immediately
 
769
     */
 
770
    public void updateNow() {   
 
771
        String attrname;
 
772
        Debug.println("ReplicationAgreement.updateNow: begin");
 
773
        if (agreementType == AGREEMENT_TYPE_LEGACYR) {
 
774
            attrname = "replicaUpdateSchedule";
 
775
        } else if (agreementType == AGREEMENT_TYPE_MMR || agreementType == AGREEMENT_TYPE_AD) {
 
776
            attrname = ReplicationTool.REPLICA_SCHEDULE_ATTR;
 
777
        } else {
 
778
            return;
 
779
        }
 
780
        
 
781
                LDAPModificationSet mods;
 
782
                LDAPAttribute attr;
 
783
        try {
 
784
            mods = new LDAPModificationSet();
 
785
            attr = new LDAPAttribute(attrname, "*");
 
786
            mods.add(LDAPModification.ADD, attr);
 
787
            updateEntry(mods);
 
788
        } catch (LDAPException me) {
 
789
                        Debug.println("Unable to add value \"*\" to attribute " + attrname + ": " + me.toString());
 
790
                }
 
791
 
 
792
        if (agreementType == AGREEMENT_TYPE_LEGACYR) {            
 
793
            try {
 
794
                mods = new LDAPModificationSet();
 
795
                attr = new LDAPAttribute("replicaUpdateReplayed", (String)null);
 
796
                mods.add(LDAPModification.REPLACE, attr);
 
797
                attr = new LDAPAttribute("replicaUpdateFailedAt", (String)null);
 
798
                mods.add(LDAPModification.REPLACE, attr);
 
799
                updateEntry(mods);
 
800
            } catch (LDAPException me2) {
 
801
                        Debug.println("Unable to remove \"replicaUpdateReplayed\" and \"replicaUpdateFailedAt\" attributes: " + me2.toString());
 
802
            }
 
803
        }
 
804
            
 
805
        try {
 
806
            mods = new LDAPModificationSet();
 
807
            attr = new LDAPAttribute(attrname, "*");
 
808
            mods.add(LDAPModification.DELETE, attr);
 
809
            updateEntry(mods);
 
810
        } catch (LDAPException me3) {
 
811
                        Debug.println("Unable to remove value \"*\" from attribute " + attrname + ": " + me3.toString());
 
812
        }
 
813
    }
 
814
    
 
815
    
 
816
    /**
 
817
     * Cause online replica creation to begin for this agreement
 
818
         * @return Status ot ORCTask
 
819
     */
 
820
    public int initializeConsumer() {
 
821
        String title = "";
 
822
        String msg = "";
 
823
        
 
824
        if (this.agreementType == AGREEMENT_TYPE_AD) {
 
825
            title = _resource.getString("sync-node-orc", "title");
 
826
            msg   = _resource.getString("sync-node-orc",
 
827
                                                                                   "description");
 
828
        } else {
 
829
                title = _resource.getString("replication-node-orc", "title");
 
830
                msg   = _resource.getString("replication-node-orc",
 
831
                                                                                   "description");
 
832
        }
 
833
                SimpleProgressDialog dlgORC;
 
834
                ORCTask taskORC;
 
835
        
 
836
                taskORC = new ORCTask(this);
 
837
 
 
838
                IDSModel model = (IDSModel)_serverInfo.get( "dsresmodel" );
 
839
                dlgORC = new SimpleProgressDialog (model.getFrame(), taskORC,
 
840
                                                                                   title, msg);
 
841
                taskORC.setProgressDialog (dlgORC);
 
842
        dlgORC.setModal(true);
 
843
                dlgORC.setLocationRelativeTo(model.getFrame());
 
844
        dlgORC.setVisible(true);
 
845
                                
 
846
                if (taskORC.getStatus() == 0) {
 
847
                        /* No problem launching initialization => we only display a message if it was not cancelled */
 
848
                        if (!dlgORC.isCancelled()) {
 
849
                                /* If we had no problems launching the initialization, we check what happened
 
850
                                   with the first update */
 
851
                                if (taskORC.getFirstUpdateStatus() == 0) {
 
852
                                        if (getStatusByKeyword(ReplicationTool.REPLICA_REFRESH_ATTR).equals(ReplicationTool.REPLICA_CONSUMER_INIT_IN_PROGRESS)) {
 
853
                                                /* The initialization has been started, we have the first successful
 
854
                                                   result, but it has not finished ...*/
 
855
                                                DSUtil.showInformationDialog(model.getFrame(),
 
856
                                                                                                         "initconsumer-not-finished",
 
857
                                                                                                         (String[]) null,
 
858
                                                                                                         "replication-agreement",
 
859
                                                                                                         _resource);
 
860
                                        } else {
 
861
                                                /* The initialization has been started, we have the first successful
 
862
                                                   result, and it is finished ...*/
 
863
                                                DSUtil.showInformationDialog(model.getFrame(),
 
864
                                                                                                         "initconsumer-finished",
 
865
                                                                                                         (String[]) null,
 
866
                                                                                                         "replication-agreement",
 
867
                                                                                                         _resource);
 
868
                                        }
 
869
                                } else {
 
870
                                        /* We get the error message from the first update */
 
871
                                        String[] args = {taskORC.getFirstUpdateMessage()};
 
872
                                        if (getStatusByKeyword(ReplicationTool.REPLICA_REFRESH_ATTR).equals(ReplicationTool.REPLICA_CONSUMER_INIT_IN_PROGRESS)) {
 
873
                                                /* The initialization has been started, the first result is no good 
 
874
                                                   but the initialization has not finished ...*/
 
875
                                                DSUtil.showErrorDialog(model.getFrame(),
 
876
                                                                                           "initconsumer-error-not-finished",
 
877
                                                                                           args,
 
878
                                                                                           "replication-agreement",
 
879
                                                                                           _resource);
 
880
                                        } else {
 
881
                                                /* The initialization has been started,  the first result is no good 
 
882
                                                   and the initialization is finished ...*/
 
883
                                                DSUtil.showErrorDialog(model.getFrame(),
 
884
                                                                                           "initconsumer-error-finished",
 
885
                                                                                           args,
 
886
                                                                                           "replication-agreement",
 
887
                                                                                           _resource);
 
888
                                        }
 
889
                                }
 
890
                        }
 
891
                } else {
 
892
                        if (!dlgORC.isCancelled()) {
 
893
                                /* An exception was thrown inside the taskORC. We have the ldap error code in the status of the task
 
894
                                   and the error sent by the server in the firstupdatemessage */
 
895
                                String ldapError = LDAPException.errorCodeToString(taskORC.getStatus());
 
896
                                String ldapMessage = taskORC.getFirstUpdateMessage();
 
897
                                
 
898
                                if ((ldapMessage != null) &&
 
899
                                        (ldapMessage.length() > 0)) {
 
900
                                        ldapError = ldapError + ". "+ldapMessage;
 
901
                                } 
 
902
                                String[] args = {ldapError};
 
903
                                DSUtil.showErrorDialog(model.getFrame(),
 
904
                                                                           "initconsumer-local-error",
 
905
                                                                           args,
 
906
                                                                           "replication-agreement",
 
907
                                                                           _resource);
 
908
                        } else {
 
909
                                /* An exception was thrown inside the taskORC and we tried to cancel the task.
 
910
                                   We have the ldap error code in the status of the task and the error sent by the server in the firstupdatemessage */
 
911
                                String ldapError = LDAPException.errorCodeToString(taskORC.getStatus());
 
912
                                String ldapMessage = taskORC.getFirstUpdateMessage();
 
913
                                
 
914
                                if ((ldapMessage != null) &&
 
915
                                        (ldapMessage.length() > 0)) {
 
916
                                        ldapError = ldapError + ". "+ldapMessage;
 
917
                                } 
 
918
                                String[] args = {ldapError};
 
919
                                DSUtil.showErrorDialog(model.getFrame(),
 
920
                                                                           "initconsumer-stop-local-error",
 
921
                                                                           args,
 
922
                                                                           "replication-agreement",
 
923
                                                                           _resource);
 
924
                        }
 
925
                }       
 
926
                return taskORC.getStatus();
 
927
    }
 
928
 
 
929
        /**
 
930
         * Create an LDIF file with data to initialize the consumer
 
931
         *
 
932
         * @param fileName Name of file for consumer data
 
933
         * @return true if the file creation succeeded
 
934
         */
 
935
        public boolean populateLDIFFile (String fileName) {
 
936
                /* Check if the file exists and show a warning message */
 
937
                File file = new File(fileName);
 
938
                if (DSUtil.fileExists(file)) {
 
939
                        JFrame frame = UtilConsoleGlobals.getActivatedFrame();
 
940
                        int response = DSUtil.showConfirmationDialog(frame,
 
941
                                                                                                                 "confirm-delete-export-file",
 
942
                                                                                                                 DSUtil.inverseAbreviateString(fileName, 30),
 
943
                                                                                                                 "export");
 
944
                        if ( response != JOptionPane.YES_OPTION ) {
 
945
                                return false;
 
946
                        }
 
947
                }
 
948
                String str = getDataVersion();
 
949
                LDAPConnection ld = _serverInfo.getLDAPConnection();
 
950
                boolean status = false;
 
951
                boolean wasReadOnly = false;
 
952
                // RM : TBD : We must add the database dn
 
953
                String backendName = MappingUtils.getBackendForSuffix(_serverInfo.getLDAPConnection(), replicatedSubtree);
 
954
                if (backendName == null) {
 
955
                        return false;
 
956
                }
 
957
                String dnDB = "cn="+backendName+"," + DSUtil.LDBM_BASE_DN;      
 
958
                /* Get read-only state of database */
 
959
                
 
960
                try {                   
 
961
                        wasReadOnly = ReadOnly.isReadOnly( _serverInfo, dnDB );
 
962
                        status = true;
 
963
                } catch ( LDAPException e ) {
 
964
                        Debug.println("ReplicationAgreement.populateLDIFFile() (1) "+e);
 
965
                }
 
966
                if ( status && !wasReadOnly ) {                 
 
967
                        /* Make server read-only */
 
968
                        status = ReadOnly.setReadOnly( _serverInfo, true, dnDB );
 
969
                }
 
970
                if ( status ) {                 
 
971
                        Hashtable attributes = new Hashtable();
 
972
                        
 
973
                        attributes.put(LDAPExport.FILENAME, new LDAPAttribute(LDAPExport.FILENAME, fileName));
 
974
                        attributes.put(LDAPExport.USE_ONE_FILE, new LDAPAttribute(LDAPExport.USE_ONE_FILE, "TRUE"));
 
975
                        attributes.put(LDAPExport.INSTANCE, new LDAPAttribute(LDAPExport.INSTANCE, backendName));
 
976
                        attributes.put(LDAPExport.EXPORT_REPLICA, new LDAPAttribute(LDAPExport.EXPORT_REPLICA, "TRUE"));
 
977
 
 
978
                        IDSModel model = (IDSModel)_serverInfo.get( "dsresmodel" );     
 
979
 
 
980
                        LDAPExport task = new LDAPExport(model, attributes);
 
981
                }
 
982
                if ( !wasReadOnly ) {                   
 
983
                        ReadOnly.setReadOnly( _serverInfo, false, dnDB );
 
984
                }
 
985
                return status;
 
986
        }
 
987
 
 
988
 
 
989
        /**
 
990
         * Create an LDIF file with data to initialize the consumer
 
991
         *
 
992
         * @param fileName Name of file for consumer data
 
993
         * @return true if the file creation succeeded
 
994
         */
 
995
        public boolean populateLDIFFile (IDSModel model) {              
 
996
        String str = getDataVersion();
 
997
        LDAPConnection ld = model.getServerInfo().getLDAPConnection();
 
998
                boolean status = false;
 
999
                boolean wasReadOnly = false;
 
1000
                // RM : TBD : We must add the database dn
 
1001
                String backendName = MappingUtils.getBackendForSuffix(ld, replicatedSubtree);
 
1002
                if (backendName == null) {
 
1003
                        return false;
 
1004
                } 
 
1005
                String dnDB = "cn="+backendName+"," + DSUtil.LDBM_BASE_DN;              
 
1006
                /* Get read-only state of database */
 
1007
                try {                   
 
1008
                        wasReadOnly = ReadOnly.isReadOnly( model.getServerInfo(), dnDB );
 
1009
                        status = true;
 
1010
                } catch ( LDAPException e ) {
 
1011
                        Debug.println("ReplicationAgreement.populateLDIFFile() (1) "+e);
 
1012
                }
 
1013
                if ( status && !wasReadOnly ) {                 
 
1014
                        /* Make server read-only */
 
1015
                        status = ReadOnly.setReadOnly( model.getServerInfo(), true, dnDB );
 
1016
                }
 
1017
                if ( status ) {                 
 
1018
                        DatabaseExportPanel child = new DatabaseExportPanel( model, backendName, true);                 
 
1019
                        String[] args = {backendName};
 
1020
                        String title = _resource.getString("replication-export", "title", args);
 
1021
                        SimpleDialog dlg = new SimpleDialog( model.getFrame(),
 
1022
                                                                                                 title,
 
1023
                                                                                                 SimpleDialog.OK |
 
1024
                                                                                                 SimpleDialog.CANCEL |
 
1025
                                                                                                 SimpleDialog.HELP,
 
1026
                                                                                                 child);
 
1027
                        dlg.setComponent( child );
 
1028
                        dlg.setOKButtonEnabled( false );
 
1029
                        dlg.setDefaultButton( SimpleDialog.OK );
 
1030
                        dlg.packAndShow();
 
1031
                }
 
1032
                if ( !wasReadOnly ) {                   
 
1033
                        ReadOnly.setReadOnly( model.getServerInfo(), false, dnDB );
 
1034
                }
 
1035
                return status;
 
1036
        }
 
1037
 
 
1038
        void waitForORCCompletion (String attrname) throws LDAPException {
 
1039
                boolean               done=false;
 
1040
                LDAPSearchResults     results = null;
 
1041
                String                filter="objectclass=*";
 
1042
                LDAPConnection        ldc = _serverInfo.getLDAPConnection ();
 
1043
                LDAPConnection        ldc_clone = (LDAPConnection)ldc.clone ();   
 
1044
                LDAPSearchConstraints cons=ldc_clone.getSearchConstraints();
 
1045
                LDAPEntry             entry;
 
1046
                String                value;
 
1047
                String[]              attrs;
 
1048
                LDAPSearchResults     result;
 
1049
                LDAPPersistSearchControl control;
 
1050
 
 
1051
                attrs = new String [1];
 
1052
                attrs[0] = attrname;
 
1053
 
 
1054
                /* return intermidiate results */
 
1055
        cons.setBatchSize(1);
 
1056
 
 
1057
                /* setup persistent search control to be notified when 
 
1058
           start ORC is deleted                                */
 
1059
        control = new LDAPPersistSearchControl(
 
1060
                       LDAPPersistSearchControl.MODIFY, false, false, false);
 
1061
        cons.setServerControls(control);
 
1062
 
 
1063
        result = ldc_clone.search(entryDN, ldc_clone.SCOPE_BASE,
 
1064
                                                                  filter, attrs, false, cons);
 
1065
 
 
1066
                while (!done && result.hasMoreElements ()) {
 
1067
                        entry = (LDAPEntry)result.nextElement ();
 
1068
 
 
1069
                        value = DSUtil.getAttrValue (entry, attrname);
 
1070
 
 
1071
                        if (!value.equalsIgnoreCase (ReplicationTool.REPLICA_CONSUMER_INIT_IN_PROGRESS))
 
1072
                                done = true;                    
 
1073
                }
 
1074
 
 
1075
                /* stop persistent serach */
 
1076
                ldc_clone.abandon (result);
 
1077
                ldc_clone.disconnect ();
 
1078
        }
 
1079
 
 
1080
    /**
 
1081
         * Get the copiedFrom attribute for a particular subtree
 
1082
         *
 
1083
         * @param subtree Directory subtree
 
1084
         * @return The copiedFrom attribute
 
1085
         */
 
1086
    public static String getCopiedFrom(LDAPConnection ld, String subtree) {
 
1087
        String cfattr[] = { "copiedFrom" };
 
1088
        String cf = null;
 
1089
        try {
 
1090
            LDAPEntry entry = ld.read(subtree, cfattr);
 
1091
            if (entry != null) {
 
1092
                            LDAPAttribute attr = entry.getAttribute( "copiedFrom");
 
1093
                if ( attr != null ) {
 
1094
                    Enumeration vals = attr.getStringValues();
 
1095
                    cf = (String)vals.nextElement();
 
1096
                }
 
1097
            }
 
1098
        } catch (LDAPException le) {
 
1099
        }
 
1100
        return cf;
 
1101
    }    
 
1102
    
 
1103
    /**
 
1104
     * Check to see if the consumer needs to be reinitialized based on
 
1105
     * values changed.
 
1106
         *
 
1107
         * @return true if the consumer needs to be reinitialized
 
1108
     */
 
1109
    public boolean checkForReORC() {
 
1110
                Debug.print("ReplicationAgreement.checkforReOrc: ");
 
1111
        if (agreementIsNew) {
 
1112
            needsReORC = false;
 
1113
            Debug.println("agreement is new");
 
1114
            return needsReORC;
 
1115
        }
 
1116
                // This method could return true after the first needsReOrc,
 
1117
                // but it seems to continue for debugging purposes
 
1118
 
 
1119
        // Check if replicatedSubtree has changed
 
1120
        Debug.println(replicatedSubtree + " " + origReplicatedSubtree);
 
1121
        if (!stringsEqualIgnoreCase(replicatedSubtree,
 
1122
                                                origReplicatedSubtree)) {
 
1123
            Debug.println("replicatedSubtree changed");
 
1124
            needsReORC = true;
 
1125
        }
 
1126
                // Check if consumerPort has changed
 
1127
                if (consumerPort != origConsumerPort) {
 
1128
                        Debug.println("consumerPort changed");
 
1129
                        needsReORC = true;
 
1130
                }
 
1131
                // Check if consumerHost has changed
 
1132
                if (!stringsEqualIgnoreCase(consumerHost, origConsumerHost)) {
 
1133
                        Debug.println("consumerHost changed");
 
1134
                        needsReORC = true;
 
1135
                }
 
1136
                // Check if entryFilter has changed
 
1137
                if (!stringsEqualIgnoreCase(entryFilter, origEntryFilter)) {
 
1138
                        Debug.println("entryFilter changed");
 
1139
                        needsReORC = true;
 
1140
                }
 
1141
                // Check if selattrType has changed
 
1142
                if (selattrType != origSelattrType) {
 
1143
                        Debug.println("selattrType: (" + selattrType +
 
1144
                                                  ") != (" + origSelattrType + ")");
 
1145
                        needsReORC = true;
 
1146
                }
 
1147
                // Check if selectedAttrs has changed
 
1148
                // Note: depends on the Vectors being sorted!
 
1149
                if (selectedAttrs == null) {
 
1150
                        if (origSelectedAttrs != null) {
 
1151
                                Debug.println("selectedAttrs changed");
 
1152
                                needsReORC = true;
 
1153
                        }
 
1154
                } else {
 
1155
                        if (origSelectedAttrs == null) {
 
1156
                                Debug.println("selectedAttrs changed");
 
1157
                                needsReORC = true;
 
1158
                        } else {
 
1159
                                // Both Vectors non-null.  Are they the same length?
 
1160
                                if (selectedAttrs.size() != origSelectedAttrs.size()) {
 
1161
                                        Debug.println("selectedAttrs changed");
 
1162
                                        needsReORC = true;
 
1163
                                } else {
 
1164
                                        // Same length.  Compare all elements
 
1165
                                        int max = selectedAttrs.size();
 
1166
                                        int i = 0;
 
1167
                                        while (i < max && !needsReORC) {
 
1168
                                                String s1 = (String)selectedAttrs.elementAt(i);
 
1169
                                                String s2 = (String)origSelectedAttrs.elementAt(i);
 
1170
                                                if (!s1.equalsIgnoreCase(s2)) {
 
1171
                                                        Debug.println("selectedAttrs changed");
 
1172
                                                        needsReORC = true;
 
1173
                                                }
 
1174
                                                i++;
 
1175
                                        }
 
1176
                                }
 
1177
                        }
 
1178
                }
 
1179
                if ( !needsReORC ) {
 
1180
                        Debug.println("no changes");
 
1181
                }
 
1182
        return needsReORC;
 
1183
    }
 
1184
 
 
1185
   /**
 
1186
     * Get replication status from Directory
 
1187
     */
 
1188
        public void updateAgreementFromServer() {
 
1189
                LDAPConnection ldc = _serverInfo.getLDAPConnection();
 
1190
        if (ldc == null) {
 
1191
            return;
 
1192
        }
 
1193
                LDAPEntry entry = null;
 
1194
                try {
 
1195
                        entry = ldc.read(getEntryDN());
 
1196
                } catch (LDAPException e) {
 
1197
                        Debug.println("ReplicationAgreement.updateAgreementFromServer() "+e);
 
1198
                }
 
1199
                if (entry == null) {
 
1200
                        return;
 
1201
                }
 
1202
 
 
1203
                /* Update Status */
 
1204
                _status.clear();
 
1205
                      String val = 
 
1206
            DSUtil.getAttrValue(entry,
 
1207
                                ReplicationTool.REPLICA_LAST_UPDATE_STATUS_ATTR);
 
1208
        if (val != null && val.length() > 0) {
 
1209
            _status.put(ReplicationTool.REPLICA_LAST_UPDATE_STATUS_ATTR,
 
1210
                        val);
 
1211
        } else {
 
1212
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1213
                                                  "unable to read the replica status from " +
 
1214
                                                  DSUtil.format(ldc));
 
1215
                }
 
1216
 
 
1217
        val = DSUtil.getAttrValue(entry,
 
1218
                                  ReplicationTool.REPLICA_N_CHANGES_SENT_ATTR);
 
1219
        if (val != null && val.length() > 0) {
 
1220
            _status.put(ReplicationTool.REPLICA_N_CHANGES_SENT_ATTR,
 
1221
                        val);
 
1222
        } else {
 
1223
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1224
                                                  "unable to read the replica number of changes from " +
 
1225
                                                  DSUtil.format(ldc));
 
1226
                }
 
1227
 
 
1228
        val = DSUtil.getAttrValue(entry,
 
1229
                                  ReplicationTool.REPLICA_LAST_UPDATE_START_ATTR);
 
1230
        if (val != null && val.length() > 0) {
 
1231
            _status.put(ReplicationTool.REPLICA_LAST_UPDATE_START_ATTR,
 
1232
                        val);
 
1233
        } else {
 
1234
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1235
                                                  "unable to read the replica last update start from " +
 
1236
                                                  DSUtil.format(ldc));
 
1237
                }
 
1238
 
 
1239
        val = DSUtil.getAttrValue(entry,
 
1240
                                  ReplicationTool.REPLICA_LAST_UPDATE_END_ATTR);
 
1241
        if (val != null && val.length() > 0) {
 
1242
            _status.put(ReplicationTool.REPLICA_LAST_UPDATE_END_ATTR,
 
1243
                        val);
 
1244
        } else {
 
1245
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1246
                                                  "unable to read the replica last update end from " +
 
1247
                                                  DSUtil.format(ldc));
 
1248
                }
 
1249
 
 
1250
        val = DSUtil.getAttrValue(entry,
 
1251
                                  ReplicationTool.REPLICA_UPDATE_IN_PROGRESS_ATTR);             
 
1252
        if (val != null && val.length() > 0) {
 
1253
            _status.put(ReplicationTool.REPLICA_UPDATE_IN_PROGRESS_ATTR,
 
1254
                        val);                   
 
1255
        } else {
 
1256
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1257
                                                  "unable to read the replica in progress from " +
 
1258
                                                  DSUtil.format(ldc));
 
1259
                }
 
1260
 
 
1261
       val = DSUtil.getAttrValue(entry,
 
1262
                                  ReplicationTool.REPLICA_REFRESH_ATTR);                
 
1263
        if (val != null && val.length() > 0) {
 
1264
            _status.put(ReplicationTool.REPLICA_REFRESH_ATTR,
 
1265
                        val);                   
 
1266
        } else {
 
1267
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1268
                                                  "unable to read the replica refresh attribute " +
 
1269
                                                  DSUtil.format(ldc));
 
1270
                }
 
1271
 
 
1272
                val = DSUtil.getAttrValue(entry,
 
1273
                                  ReplicationTool.REPLICA_CONSUMER_INIT_BEGIN_ATTR);            
 
1274
        if (val != null && val.length() > 0) {
 
1275
            _status.put(ReplicationTool.REPLICA_CONSUMER_INIT_BEGIN_ATTR,
 
1276
                        val);                   
 
1277
        } else {
 
1278
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1279
                                                  "unable to read the consumer initialization begin attribute (" + 
 
1280
                                                  ReplicationTool.REPLICA_CONSUMER_INIT_BEGIN_ATTR + ") "+
 
1281
                                                  DSUtil.format(ldc));
 
1282
                }               
 
1283
 
 
1284
                val = DSUtil.getAttrValue(entry,
 
1285
                                  ReplicationTool.REPLICA_CONSUMER_INIT_END_ATTR);              
 
1286
        if (val != null && val.length() > 0) {
 
1287
            _status.put(ReplicationTool.REPLICA_CONSUMER_INIT_END_ATTR,
 
1288
                        val);                   
 
1289
        } else {
 
1290
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1291
                                                  "unable to read the consumer initialization end attribute (" + 
 
1292
                                                  ReplicationTool.REPLICA_CONSUMER_INIT_END_ATTR + ") "+
 
1293
                                                  DSUtil.format(ldc));
 
1294
                }
 
1295
 
 
1296
                val = DSUtil.getAttrValue(entry,
 
1297
                                  ReplicationTool.REPLICA_CONSUMER_INIT_STATUS_ATTR);           
 
1298
        if (val != null && val.length() > 0) {
 
1299
            _status.put(ReplicationTool.REPLICA_CONSUMER_INIT_STATUS_ATTR,
 
1300
                        val);                   
 
1301
        } else {
 
1302
                        Debug.println("ReplicationAgreement.updateAgreementFromServer: " +
 
1303
                                                  "unable to read the consumer initialization status attribute (" + 
 
1304
                                                  ReplicationTool.REPLICA_CONSUMER_INIT_STATUS_ATTR + ") "+
 
1305
                                                  DSUtil.format(ldc));
 
1306
                }
 
1307
 
 
1308
 
 
1309
 
 
1310
                nickname = DSUtil.getAttrValue(entry,
 
1311
                                  ReplicationTool.MMR_NICKNAME_ATTR);
 
1312
 
 
1313
                _description = nickname;
 
1314
                
 
1315
                entryCN = DSUtil.getAttrValue(entry,
 
1316
                                  ReplicationTool.MMR_NAME_ATTR);
 
1317
 
 
1318
                replicatedSubtree = DSUtil.getAttrValue(entry,
 
1319
                                  ReplicationTool.REPLICA_ROOT_ATTR);
 
1320
                origReplicatedSubtree = replicatedSubtree;
 
1321
 
 
1322
                String sConsumerPort = DSUtil.getAttrValue(entry,
 
1323
                                  ReplicationTool.REPLICA_PORT_ATTR);
 
1324
                try {
 
1325
                        int value = Integer.parseInt(sConsumerPort);
 
1326
                        consumerPort = value;
 
1327
                        origConsumerPort = consumerPort;
 
1328
                } catch (Exception e) {
 
1329
                }
 
1330
 
 
1331
                consumerHost = DSUtil.getAttrValue(entry,
 
1332
                                  ReplicationTool.REPLICA_HOST_ATTR);
 
1333
                
 
1334
 
 
1335
 
 
1336
                supplierHost = ldc.getHost();
 
1337
                origSupplierHost = origSupplierHost;
 
1338
                
 
1339
                supplierPort = ldc.getPort();
 
1340
                origSupplierPort = supplierPort;
 
1341
 
 
1342
                bindDN = DSUtil.getAttrValue(entry,
 
1343
                                  ReplicationTool.REPLICA_BINDDN_ATTR);
 
1344
 
 
1345
                bindCredentials = DSUtil.getAttrValue(entry,
 
1346
                                  ReplicationTool.REPLICA_CRED_ATTR);
 
1347
 
 
1348
                setUseSSL(DSUtil.getAttrValue(entry,
 
1349
                                                  ReplicationTool.REPLICA_TRANSPORT_ATTR));
 
1350
                setUseStartTLS(DSUtil.getAttrValue(entry,
 
1351
                                                  ReplicationTool.REPLICA_TRANSPORT_ATTR));
 
1352
 
 
1353
                setUseSSLAuth(DSUtil.getAttrValue(entry,
 
1354
                                  ReplicationTool.REPLICA_BINDMETHOD_ATTR));
 
1355
                setUseGSSAPIAuth(DSUtil.getAttrValue(entry,
 
1356
                                                                  ReplicationTool.REPLICA_BINDMETHOD_ATTR));
 
1357
                setUseDigestAuth(DSUtil.getAttrValue(entry,
 
1358
                                                                  ReplicationTool.REPLICA_BINDMETHOD_ATTR));
 
1359
 
 
1360
                String[] schedule = DSUtil.getAttrValues(entry,
 
1361
                                  ReplicationTool.REPLICA_SCHEDULE_ATTR);
 
1362
                
 
1363
                Vector v = new Vector();
 
1364
                if ((schedule != null) &&
 
1365
                        (schedule.length > 0)) {                        
 
1366
                        for (int i=0; i<schedule.length; i++) {                         
 
1367
                                v.addElement(schedule[i]);
 
1368
                        }                       
 
1369
                } else {
 
1370
                        v.addElement(new String(""));
 
1371
                }
 
1372
                setUpdateSchedule(v);
 
1373
        }
 
1374
 
 
1375
    
 
1376
    /**
 
1377
     * Get replication status from Directory
 
1378
     */
 
1379
    public void updateReplicaStatus() {
 
1380
 
 
1381
        int lderr;
 
1382
        String errmsg;
 
1383
 
 
1384
        LDAPConnection ld = _serverInfo.getLDAPConnection();
 
1385
        if (ld == null) {
 
1386
            return;
 
1387
        }
 
1388
        
 
1389
        LDAPEntry entry = null;
 
1390
        _status.clear();
 
1391
        // Get the root DSE status attributes
 
1392
        try {
 
1393
            entry = ld.read(getEntryDN(), ReplicationTool.REPLICA_STATUS_ATTRS);                        
 
1394
        } catch (LDAPException le2) {
 
1395
            Debug.println("ReplicationAgreement.updateReplicaStatus: "+
 
1396
                        le2.toString());
 
1397
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1398
                                                  "unable to read the replication status from DN " +
 
1399
                                                  getEntryDN() + ": " + DSUtil.format(ld));
 
1400
                        return;
 
1401
        }
 
1402
 
 
1403
        Debug.println(9, "ReplicationAgreement.updateReplicaStatus: status " +
 
1404
                      "entry is " + entry.toString());
 
1405
        String val = 
 
1406
            DSUtil.getAttrValue(entry,
 
1407
                                ReplicationTool.REPLICA_LAST_UPDATE_STATUS_ATTR);
 
1408
        if (val != null && val.length() > 0) {
 
1409
            _status.put(ReplicationTool.REPLICA_LAST_UPDATE_STATUS_ATTR,
 
1410
                        val);
 
1411
        } else {
 
1412
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1413
                                                  "unable to read the replica status from " +
 
1414
                                                  DSUtil.format(ld));
 
1415
                }
 
1416
 
 
1417
        val = DSUtil.getAttrValue(entry,
 
1418
                                  ReplicationTool.REPLICA_N_CHANGES_SENT_ATTR);
 
1419
        if (val != null && val.length() > 0) {
 
1420
            _status.put(ReplicationTool.REPLICA_N_CHANGES_SENT_ATTR,
 
1421
                        val);
 
1422
        } else {
 
1423
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1424
                                                  "unable to read the replica number of changes from " +
 
1425
                                                  DSUtil.format(ld));
 
1426
                }
 
1427
 
 
1428
        val = DSUtil.getAttrValue(entry,
 
1429
                                  ReplicationTool.REPLICA_LAST_UPDATE_START_ATTR);
 
1430
        if (val != null && val.length() > 0) {
 
1431
            _status.put(ReplicationTool.REPLICA_LAST_UPDATE_START_ATTR,
 
1432
                        val);
 
1433
        } else {
 
1434
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1435
                                                  "unable to read the replica last update start from " +
 
1436
                                                  DSUtil.format(ld));
 
1437
                }
 
1438
 
 
1439
        val = DSUtil.getAttrValue(entry,
 
1440
                                  ReplicationTool.REPLICA_LAST_UPDATE_END_ATTR);
 
1441
        if (val != null && val.length() > 0) {
 
1442
            _status.put(ReplicationTool.REPLICA_LAST_UPDATE_END_ATTR,
 
1443
                        val);
 
1444
        } else {
 
1445
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1446
                                                  "unable to read the replica last update end from " +
 
1447
                                                  DSUtil.format(ld));
 
1448
                }
 
1449
 
 
1450
        val = DSUtil.getAttrValue(entry,
 
1451
                                  ReplicationTool.REPLICA_UPDATE_IN_PROGRESS_ATTR);             
 
1452
        if (val != null && val.length() > 0) {
 
1453
            _status.put(ReplicationTool.REPLICA_UPDATE_IN_PROGRESS_ATTR,
 
1454
                        val);                   
 
1455
        } else {
 
1456
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1457
                                                  "unable to read the replica in progress from " +
 
1458
                                                  DSUtil.format(ld));
 
1459
                }
 
1460
 
 
1461
       val = DSUtil.getAttrValue(entry,
 
1462
                                  ReplicationTool.REPLICA_REFRESH_ATTR);                
 
1463
        if (val != null && val.length() > 0) {
 
1464
            _status.put(ReplicationTool.REPLICA_REFRESH_ATTR,
 
1465
                        val);                   
 
1466
        } else {
 
1467
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1468
                                                  "unable to read the replica refresh attribute " +
 
1469
                                                  DSUtil.format(ld));
 
1470
                }
 
1471
 
 
1472
                val = DSUtil.getAttrValue(entry,
 
1473
                                  ReplicationTool.REPLICA_CONSUMER_INIT_BEGIN_ATTR);            
 
1474
        if (val != null && val.length() > 0) {
 
1475
            _status.put(ReplicationTool.REPLICA_CONSUMER_INIT_BEGIN_ATTR,
 
1476
                        val);                   
 
1477
        } else {
 
1478
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1479
                                                  "unable to read the consumer initialization begin attribute (" + 
 
1480
                                                  ReplicationTool.REPLICA_CONSUMER_INIT_BEGIN_ATTR + ") "+
 
1481
                                                  DSUtil.format(ld));
 
1482
                }               
 
1483
 
 
1484
                val = DSUtil.getAttrValue(entry,
 
1485
                                  ReplicationTool.REPLICA_CONSUMER_INIT_END_ATTR);              
 
1486
        if (val != null && val.length() > 0) {
 
1487
            _status.put(ReplicationTool.REPLICA_CONSUMER_INIT_END_ATTR,
 
1488
                        val);                   
 
1489
        } else {
 
1490
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1491
                                                  "unable to read the consumer initialization end attribute (" + 
 
1492
                                                  ReplicationTool.REPLICA_CONSUMER_INIT_END_ATTR + ") "+
 
1493
                                                  DSUtil.format(ld));
 
1494
                }
 
1495
 
 
1496
                val = DSUtil.getAttrValue(entry,
 
1497
                                  ReplicationTool.REPLICA_CONSUMER_INIT_STATUS_ATTR);           
 
1498
        if (val != null && val.length() > 0) {
 
1499
            _status.put(ReplicationTool.REPLICA_CONSUMER_INIT_STATUS_ATTR,
 
1500
                        val);                   
 
1501
        } else {
 
1502
                        Debug.println("ReplicationAgreement.updateReplicaStatus: " +
 
1503
                                                  "unable to read the consumer initialization status attribute (" + 
 
1504
                                                  ReplicationTool.REPLICA_CONSUMER_INIT_STATUS_ATTR + ") "+
 
1505
                                                  DSUtil.format(ld));
 
1506
                }
 
1507
                
 
1508
    }
 
1509
    
 
1510
    private String getStatusByKeyword(String keyword) {
 
1511
        if (_status != null && _status.containsKey(keyword)) {
 
1512
            return _status.get(keyword).toString();
 
1513
        }
 
1514
        return _resource.getString("replication-info-status-code",
 
1515
                                   "unknown");
 
1516
    }
 
1517
 
 
1518
    public String getLastUpdateStatus() {
 
1519
        return getStatusByKeyword(ReplicationTool.REPLICA_LAST_UPDATE_STATUS_ATTR);
 
1520
    }
 
1521
    
 
1522
    public String getInProgress() {
 
1523
        return getStatusByKeyword(ReplicationTool.REPLICA_UPDATE_IN_PROGRESS_ATTR);
 
1524
    }
 
1525
    
 
1526
    public String getNChangesLast() {
 
1527
        return getStatusByKeyword(ReplicationTool.REPLICA_N_CHANGES_SENT_ATTR);
 
1528
    }
 
1529
    
 
1530
    public String getLastUpdateBegin() {
 
1531
        String sdt = getStatusByKeyword(ReplicationTool.REPLICA_LAST_UPDATE_START_ATTR);
 
1532
                
 
1533
                /* In this particular case, the date is not available */
 
1534
                if (sdt.equals("0")) {
 
1535
                        return _resource.getString("replication-agreement", "lastupdatebegin-unknown-value");
 
1536
                }
 
1537
                
 
1538
        Date dt = DSUtil.getDateTime(sdt);
 
1539
        if (dt==null)
 
1540
            return "null"; //XXX
 
1541
        return dt.toString();
 
1542
    }
 
1543
    
 
1544
    public String getLastUpdateEnd() {
 
1545
        String sdt = getStatusByKeyword(ReplicationTool.REPLICA_LAST_UPDATE_END_ATTR);
 
1546
 
 
1547
                /* In this particular case, the date is not available */
 
1548
                if (sdt.equals("0")) {
 
1549
                        return _resource.getString("replication-agreement", "lastupdateend-unknown-value");
 
1550
                }
 
1551
 
 
1552
        Date dt = DSUtil.getDateTime(sdt);
 
1553
            if (dt==null)
 
1554
            return "null"; //XXX
 
1555
        return dt.toString();
 
1556
    }
 
1557
    
 
1558
        public String getConsumerInitializationBegin() {
 
1559
                String sdt = getStatusByKeyword(ReplicationTool.REPLICA_CONSUMER_INIT_BEGIN_ATTR);
 
1560
                
 
1561
                /* In this particular case, the date is not available */
 
1562
                if ((sdt.equals(_resource.getString("replication-info-status-code",
 
1563
                                                                                        "unknown"))) ||
 
1564
                        (sdt.equals("0"))) {                    
 
1565
                        return _resource.getString("replication-agreement", "initconsumer-begin-unknown-value");                
 
1566
                }
 
1567
                
 
1568
        Date dt = DSUtil.getDateTime(sdt);
 
1569
            if (dt==null)
 
1570
            return "null"; //XXX
 
1571
        return dt.toString();
 
1572
        }
 
1573
 
 
1574
        public String getConsumerInitializationEnd() {
 
1575
                String sdt = getStatusByKeyword(ReplicationTool.REPLICA_CONSUMER_INIT_END_ATTR);
 
1576
                
 
1577
                /* In this particular case, the date is not available */
 
1578
                if ((sdt.equals(_resource.getString("replication-info-status-code",
 
1579
                                                                                        "unknown"))) ||
 
1580
                        (sdt.equals("0"))) {
 
1581
                        return _resource.getString("replication-agreement", "initconsumer-end-unknown-value");
 
1582
                }
 
1583
                
 
1584
                Date dt = DSUtil.getDateTime(sdt);
 
1585
        if (dt==null)
 
1586
            return "null"; //XXX
 
1587
        return dt.toString();
 
1588
        }
 
1589
 
 
1590
        public String getConsumerInitializationStatus() {
 
1591
                String sdt = getStatusByKeyword(ReplicationTool.REPLICA_CONSUMER_INIT_STATUS_ATTR);             
 
1592
                return sdt;
 
1593
        }
 
1594
 
 
1595
        public String getConsumerInitializationInProgress() {
 
1596
                String sdt = getStatusByKeyword(ReplicationTool.REPLICA_REFRESH_ATTR);
 
1597
                if ((sdt == null) ||
 
1598
                        !sdt.equals(ReplicationTool.REPLICA_CONSUMER_INIT_IN_PROGRESS)) {
 
1599
                        return _resource.getString("replication-agreement", "initconsumer-inprogress-false-value");
 
1600
                } else {
 
1601
                        return _resource.getString("replication-agreement", "initconsumer-inprogress-true-value");
 
1602
                }
 
1603
        }
 
1604
 
 
1605
 
 
1606
        /*==========================================================
 
1607
         * protected methods
 
1608
     *==========================================================*/  
 
1609
   
 
1610
    protected void parseReplAttrList(LDAPAttribute attr) {
 
1611
        // Note: we only support a single replicatedAttributeList attribute,
 
1612
            // and that attribute must give a filter of "(objectclass=*)".
 
1613
            //If we encounter
 
1614
        // multiple attributes, or a different filter, then warn the user.
 
1615
        boolean attrParsed = false;
 
1616
 
 
1617
        if (attr.size() == 0) {
 
1618
            selattrType = SELATTR_ALL;
 
1619
            return;
 
1620
        }
 
1621
 
 
1622
        if (attr.size() > 2) {
 
1623
            selattrNotRepresentable = true;
 
1624
            selattrType = SELATTR_ALL;
 
1625
            return;
 
1626
        }
 
1627
 
 
1628
        String selAttrFilter = (String)attr.getStringValues().nextElement();
 
1629
        if (selAttrFilter == null || selAttrFilter.length() == 0) {
 
1630
            // no value in entry
 
1631
            selectedAttrs = null;
 
1632
            selattrType = SELATTR_ALL;
 
1633
        } else {
 
1634
            StringTokenizer st =
 
1635
                        new StringTokenizer(selAttrFilter, "$", false);
 
1636
            if (st.hasMoreTokens()) {
 
1637
                String s = st.nextToken().trim();
 
1638
                if (!"(objectclass=*)".equalsIgnoreCase(s)) {
 
1639
                    selattrNotRepresentable = true;
 
1640
                    return;
 
1641
                }
 
1642
            } else {
 
1643
                selattrNotRepresentable = true;
 
1644
                return;
 
1645
            }
 
1646
            if (st.hasMoreTokens()) {
 
1647
                String s = st.nextToken();
 
1648
                s.trim();
 
1649
                st = new StringTokenizer(s, " ", false);
 
1650
                if (st.hasMoreTokens()) {
 
1651
                    String incOrExc = st.nextToken();
 
1652
                    if ("include".equalsIgnoreCase(incOrExc)) {
 
1653
                        selattrType = SELATTR_INCLUDE;
 
1654
                    } else if ("exclude".equalsIgnoreCase(incOrExc)) {
 
1655
                        selattrType = SELATTR_EXCLUDE;
 
1656
                    } else {
 
1657
                        selattrType = 0;
 
1658
                    }
 
1659
                    String attrString = "";
 
1660
                    while (st.hasMoreTokens()) {
 
1661
                        attrString += st.nextToken() + " ";
 
1662
                    }
 
1663
                    setSelectedAttributes(attrString);
 
1664
                    attrParsed = true;
 
1665
                }
 
1666
            }
 
1667
            if (!attrParsed) {
 
1668
                selattrNotRepresentable = true;
 
1669
            }
 
1670
        }
 
1671
    }
 
1672
 
 
1673
    protected String createReplicatedAttributesList() {
 
1674
        if (selectedAttrs == null || selectedAttrs.size() == 0) {
 
1675
            return null;
 
1676
        }
 
1677
 
 
1678
        String attrList = "(objectclass=*) $ ";
 
1679
 
 
1680
        if (selattrType == SELATTR_INCLUDE) {
 
1681
            attrList += "INCLUDE";
 
1682
        } else if (selattrType == SELATTR_EXCLUDE) {
 
1683
            attrList += "EXCLUDE";
 
1684
        } else {
 
1685
            return null;
 
1686
        }
 
1687
 
 
1688
        Enumeration selAttrsEnum = selectedAttrs.elements();
 
1689
        while (selAttrsEnum.hasMoreElements()) {
 
1690
            attrList += " " + (String)selAttrsEnum.nextElement();
 
1691
        }
 
1692
        return attrList;
 
1693
    }
 
1694
 
 
1695
    void updateEntry(LDAPModificationSet mods) throws LDAPException {
 
1696
        if (mods == null) {
 
1697
            return;
 
1698
        }
 
1699
        modsDump( mods );
 
1700
        LDAPConnection ld = _serverInfo.getLDAPConnection();
 
1701
                Debug.println( "Replication.updateEntry: " + entryDN );
 
1702
        ld.modify(entryDN, mods);
 
1703
    }
 
1704
 
 
1705
 
 
1706
 
 
1707
    protected void createNewEntry(LDAPEntry e) throws LDAPException {
 
1708
        if (e == null) {
 
1709
            return;
 
1710
        }
 
1711
        LDAPConnection ld = _serverInfo.getLDAPConnection();
 
1712
                Debug.println( "Replication.createNewEntry: " + e.getDN() );
 
1713
        ld.add(e);
 
1714
    }
 
1715
 
 
1716
 
 
1717
 
 
1718
    protected void deleteOldEntry() throws LDAPException {
 
1719
        LDAPConnection ld = _serverInfo.getLDAPConnection();
 
1720
                Debug.println( "Replication.deleteOldEntry: " + getOrigEntryDN() );
 
1721
        ld.delete(getOrigEntryDN());
 
1722
    }
 
1723
 
 
1724
 
 
1725
        protected void disconnect(LDAPConnection ld) {
 
1726
                if (ld != null) {
 
1727
                        try {
 
1728
                                ld.disconnect();
 
1729
                        } catch ( LDAPException e ) {
 
1730
                        }
 
1731
                }
 
1732
        }
 
1733
 
 
1734
    /*==========================================================
 
1735
         * private methods
 
1736
         *==========================================================*/
 
1737
         
 
1738
    private boolean isSpecialNamingContext(String nc) {
 
1739
        return false;
 
1740
    }
 
1741
 
 
1742
    // Compare 2 strings.  One or both can be null
 
1743
    private boolean stringsEqualIgnoreCase(String s1, String s2) {
 
1744
        boolean ret = false;
 
1745
        
 
1746
        if (s1 == null) {
 
1747
            if (s2 == null) {
 
1748
                ret = true;
 
1749
            } else {
 
1750
                ret = false;
 
1751
            }
 
1752
        } else {
 
1753
            if (s2 == null) {
 
1754
                ret = false;
 
1755
            } else {
 
1756
                if (s1.length() != s2.length()) {
 
1757
                    ret = false;
 
1758
                } else {
 
1759
                    ret = s1.equalsIgnoreCase(s2);
 
1760
                }
 
1761
            }
 
1762
        }
 
1763
        return ret;
 
1764
    }
 
1765
    
 
1766
    //convert General Time String to Date String
 
1767
    static private String timeToString(String gt) {
 
1768
        Calendar cal = Calendar.getInstance();
 
1769
        try {
 
1770
            cal.set(Integer.parseInt(gt.substring(0,4)),
 
1771
                Integer.parseInt(gt.substring(4,6)) - 1,
 
1772
                Integer.parseInt(gt.substring(6,8)),
 
1773
                Integer.parseInt(gt.substring(8,10)),
 
1774
                Integer.parseInt(gt.substring(10,12)),
 
1775
                Integer.parseInt(gt.substring(12,14)));
 
1776
        } catch (NumberFormatException e) {
 
1777
            return " ";    
 
1778
        }
 
1779
        Date date = cal.getTime();
 
1780
        DateFormat formatter =
 
1781
                    DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
 
1782
        return formatter.format(date);
 
1783
    }
 
1784
 
 
1785
 
 
1786
    /*==========================================================
 
1787
         * Debug methods
 
1788
         *==========================================================*/
 
1789
         
 
1790
    public String toString() {
 
1791
        String ret = "";
 
1792
        ret += "Type: ";
 
1793
        if (agreementType == AGREEMENT_TYPE_MMR) {
 
1794
            ret += "Multi Master";
 
1795
        } else if (agreementType == AGREEMENT_TYPE_LEGACYR) {
 
1796
            ret += "Legacy";
 
1797
        } else if (agreementType == AGREEMENT_TYPE_AD) {
 
1798
            ret += "Windows";
 
1799
        } else {
 
1800
            ret += "(unknown)";
 
1801
        }
 
1802
        ret += "\n";
 
1803
        ret += "Host: " + getRemoteHost() + "\n";
 
1804
        ret += "Port: " + getRemotePort() + "\n";
 
1805
        ret += "Subtree: " + replicatedSubtree + "\n";
 
1806
        ret += "SSL: " + useSSL + "\n";
 
1807
        ret += "TLS: " + useStartTLS + "\n";
 
1808
        ret += "SSL Client Auth: " + useSSLAuth + "\n";
 
1809
        ret += "SASL/GSSAPI Auth: " + useGSSAPIAuth + "\n";
 
1810
        ret += "SASL/Digest-MD5 Auth: " + useDigestAuth + "\n";
 
1811
 
 
1812
        return ret;
 
1813
    }
 
1814
 
 
1815
 
 
1816
 
 
1817
    /**
 
1818
     * Dump out a mods set for debugging
 
1819
     */
 
1820
    private void modsDump(LDAPModificationSet mods) {
 
1821
        Debug.println("ReplicationAgreement.modsDump:");
 
1822
        if (mods == null) {
 
1823
            Debug.println("  null");
 
1824
        } else {
 
1825
            LDAPModification lm;
 
1826
            int op;
 
1827
            LDAPAttribute attr;
 
1828
            Enumeration valuesEnum;
 
1829
            for (int i = 0; i < mods.size(); i++) {
 
1830
                lm = mods.elementAt(i);
 
1831
                op = lm.getOp();
 
1832
                switch (op) {
 
1833
                case LDAPModification.ADD:
 
1834
                    Debug.print("add");
 
1835
                    break;
 
1836
                case LDAPModification.DELETE:
 
1837
                    Debug.print("delete");
 
1838
                    break;
 
1839
                case LDAPModification.REPLACE:
 
1840
                    Debug.print("replace");
 
1841
                    break;
 
1842
                default:
 
1843
                    Debug.print("unknown op (" + op + "): ");
 
1844
                }
 
1845
                Debug.print(": ");
 
1846
                attr = lm.getAttribute();
 
1847
                Debug.println(attr.getName());
 
1848
                valuesEnum = attr.getStringValues();
 
1849
                while ( (valuesEnum != null) &&
 
1850
                                                valuesEnum.hasMoreElements()) {
 
1851
                    Debug.println(attr.getName() + ": " +
 
1852
                                        (String)valuesEnum.nextElement());
 
1853
                }
 
1854
                Debug.println("-");
 
1855
            }
 
1856
        }
 
1857
    }
 
1858
 
 
1859
        private String getDataVersion() {
 
1860
                String baseDN = "cn=monitor";
 
1861
                String filter = "objectclass=*";
 
1862
                String[] attrs = {"dataversion"};
 
1863
                String result;
 
1864
        LDAPConnection ld = _serverInfo.getLDAPConnection();
 
1865
        try {
 
1866
            LDAPSearchResults res = ld.search(baseDN, ld.SCOPE_BASE, 
 
1867
                filter, attrs, false);
 
1868
            LDAPEntry entry = res.next();
 
1869
                        if (entry != null) {
 
1870
                                LDAPAttribute attr = entry.getAttribute(attrs[0]);
 
1871
                                if (attr != null) {
 
1872
                                        Enumeration enums = attr.getStringValues();
 
1873
                                        result = (String)enums.nextElement();
 
1874
                                        Debug.println ("ReplicationAgreement.getDataversion: " + result);
 
1875
                                        return result;
 
1876
                                }
 
1877
                        }
 
1878
        } catch (LDAPException e) {
 
1879
                        Debug.println("ReplicationAgreement.getDataversion: " + e );   
 
1880
        }
 
1881
        return "";
 
1882
    }
 
1883
 
 
1884
  /**
 
1885
   * Getter for property domain.
 
1886
   * @return Value of windows domain (if applicable)
 
1887
   */
 
1888
  public String getDomain() {
 
1889
      return domain;
 
1890
  }  
 
1891
 
 
1892
  /**
 
1893
   * Setter for property domain.
 
1894
   * @param domain New value of property domain.
 
1895
   */
 
1896
  public void setDomain(String domain) {
 
1897
      this.domain = domain;
 
1898
  }
 
1899
  
 
1900
    //==========================================================
 
1901
    // UPDATED FUNCTIONALITY MOVED TO ReplicationTool.java
 
1902
    //
 
1903
    //      private String canonicalHost(String host)
 
1904
    //      protected String fullyQualifyHostName(String host)
 
1905
    //==========================================================
 
1906
       
 
1907
    /*==========================================================
 
1908
     * variables
 
1909
     *==========================================================*/    
 
1910
    public static final int AGREEMENT_TYPE_LEGACYR = 1;
 
1911
    public static final int AGREEMENT_TYPE_MMR = 2;
 
1912
    public static final int AGREEMENT_TYPE_CIR = 3;
 
1913
    public static final int AGREEMENT_TYPE_SIR = 4;
 
1914
    
 
1915
    public static final int AGREEMENT_TYPE_AD = 5; //Active Directory
 
1916
    public static final int AGREEMENT_TYPE_NT = 6; //legacy nt replication (not used)
 
1917
    
 
1918
    protected static final int CLOSE_AGREEMENT = 1;
 
1919
    protected static final int KEEP_AGREEMENT  = 2;
 
1920
 
 
1921
    protected String nickname;                      // A short, human-readable nickname for this agreement.
 
1922
    protected String entryDN;                       // The DN of the entry containing this agreement.
 
1923
    protected String origEntryDN;                   // DN of entry at time it was read from directory
 
1924
    protected String entryCN;                       // CN of the entry containing this agreement.
 
1925
    protected String replicatedSubtree;             // The DN of the top of the replicated subtree.
 
1926
    protected String supplierHost;                  // The host name for the supplier server.
 
1927
    protected int supplierPort;                     // The port number of the supplier server process.
 
1928
    protected String consumerHost;                  // The host name of the consumer server
 
1929
    protected int consumerPort;                     // The post number of the consumer server process.
 
1930
    protected String bindDN;                        // The DN to bind as when connecting to the consumer. XXX LDAPDN?
 
1931
    protected String bindCredentials;               // The credentials (password) used when connectin to the consumer.
 
1932
    protected Vector updateSchedule;                // Schedule(s) for updates
 
1933
    //protected ReplicationAgreementEditor editor;           // Reference to repl agrmt editor window.  If null, no window is open
 
1934
    protected boolean useSSL;                       // true if SSL should be used when connecting to remote server
 
1935
    protected boolean useStartTLS;                  // true if startTLS should be used when connecting to remote server
 
1936
    protected boolean useSSLAuth;                           // true if useSSL and strong auth by SSL required
 
1937
    protected boolean useGSSAPIAuth;                    // true if using SASL/GSSAPI for auth
 
1938
    protected boolean useDigestAuth;                    // true if using SASL/Digest-MD5 for auth
 
1939
    protected int agreementType;                    // mmr or legacyr
 
1940
    //protected Vector namingContexts;                // Naming contexts supported by the server
 
1941
    protected String orcValue;                      // non-null if replica is being reinitialized
 
1942
    protected Vector selectedAttrs;                 // Attribute names for selective attribute replication
 
1943
    protected int selattrType;                      // Either SELATTR_INCLUDE or SELATTR_EXCLUDE
 
1944
    protected boolean selattrNotRepresentable;      // true if the selective attribute repl info found in
 
1945
                                                    // config entry cannot be represented by this UI.
 
1946
    protected String entryFilter;                   // LDAPFilter describing entries to replicate
 
1947
    protected boolean filterNotRepresentable;       // true if fitlered repl info found in config entry
 
1948
                                                    // cannot be represented by this UI.
 
1949
    protected boolean agreementIsNew;               // true if this is a new agreement, e.g. not read from srvr
 
1950
    protected AgreementTable repList;               // The other replication agreements (for validation)
 
1951
        
 
1952
    protected String origSupplierHost;              // Original host name
 
1953
    protected int origSupplierPort;                 // Original supplier port number
 
1954
    protected int origConsumerPort;                 // Original consumer port number.
 
1955
    protected String origConsumerHost;              // Original consumer host name
 
1956
    protected int origSelattrType;                  // Original type of selattr selection
 
1957
    protected Vector origSelectedAttrs;             // Originally-selected attributes
 
1958
    protected String origEntryFilter;               // Original entry filter
 
1959
    protected String origReplicatedSubtree;         // Original replicated subtree.
 
1960
    protected String machineDataDN;                 // Machine Data DN of the Directory Server
 
1961
    protected String _description;
 
1962
    private boolean needsReORC;                     // If true, a change has been made which requires re-initting the consumer
 
1963
    private ConsoleInfo _serverInfo;
 
1964
    
 
1965
    // status
 
1966
    private Hashtable _status = new Hashtable();
 
1967
    
 
1968
        //get resource bundle
 
1969
    private static ResourceSet _resource =
 
1970
            new ResourceSet("com.netscape.admin.dirserv.panel.replication.replication");     
 
1971
    
 
1972
    /**
 
1973
     * Holds value of property domain.
 
1974
     */
 
1975
    private String domain;
 
1976
    
 
1977
}
 
1978