Project

General

Profile

« Previous | Next » 

Revision 3230

Added by Jing Tao over 17 years ago

Somehow the change went to the head rather than branch. So i rollback the change in head.

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
579 579
  {
580 580
    String server = ((String[])params.get("server"))[0]; // the server that
581 581
    String docid = ((String[])params.get("docid"))[0]; // sent the document
582
    String ipAddress = ((String[])params.get("ipAddress"))[0];
583 582
    String dbaction = "UPDATE"; // the default action is UPDATE
584 583
    boolean override = false;
585 584
    int serverCode = 1;
......
654 653
      DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false);
655 654
      wrapper.writeReplication(dbConn, new StringReader(xmldoc), null, null,
656 655
                               dbaction, docid, user, null, homeServer, 
657
                               server, createdDate, updatedDate, ipAddress);
658
      
656
                               server, createdDate, updatedDate);
657

  
659 658
      MetacatReplication.replLog("document " + docid + " added to DB with " +
660 659
                                 "action " + dbaction);
661
      EventLog.getInstance().log(ipAddress, user, docid, dbaction);
662 660
    }//try
663 661
    catch(Exception e)
664 662
    {
......
668 666
                                       e.getMessage());
669 667
      logMetacat.error("ERROR in MetacatReplication.handleForceReplicate" +
670 668
                         "Request(): " + e.getMessage());
671
      
672 669

  
673 670
    }//catch
674 671
    finally
......
687 684
{
688 685
  String server = ((String[])params.get("server"))[0]; // the server that
689 686
  String docid = ((String[])params.get("docid"))[0]; // sent the document
690
  String user = ((String[])params.get("user"))[0];
691
  String ipAddress = ((String[])params.get("ipAddress"))[0];
692 687
  try
693 688
  {
694 689
    MetacatReplication.replLog("force replication delete request from " + server);
695 690
    MetacatReplication.replLog("force replication delete docid " + docid);
696 691
    logMetacat.info("Force replication delete request from: "+ server);
697 692
    logMetacat.info("Force replication delete docid: "+docid);
698
    DocumentImpl.delete(docid, null, null, server, ipAddress);
693
    DocumentImpl.delete(docid, null, null, server);
699 694
    MetacatReplication.replLog("document " + docid + " was successfully deleted ");
700
    EventLog.getInstance().log(ipAddress, user, docid, "delete");
701 695
    logMetacat.info("document " + docid + " was successfully deleted ");
702 696
  }
703 697
  catch(Exception e)
......
730 724
    String server = ((String[])params.get("server"))[0];
731 725
    // the docid should include rev number
732 726
    String docid = ((String[])params.get("docid"))[0];
733
    String ipAddress = ((String[])params.get("ipAddress"))[0];
734 727
    // Make sure there is a docid and server
735 728
    if (docid==null || server==null || server.equals(""))
736 729
    {
......
809 802
        //into file system
810 803
        DocumentImpl.writeDataFileInReplication(url.openStream(), datafilePath,
811 804
                            docName, docType, docid, user,docHomeServer,server, 
812
                            DocumentImpl.DOCUMENTTABLE, false, createdDate, updatedDate, ipAddress);
805
                            DocumentImpl.DOCUMENTTABLE, false, createdDate, updatedDate);
813 806
                            //false means non-timed replication
814 807
     }
815 808

  
......
817 810

  
818 811
    MetacatReplication.replLog("datafile " + docid + " added to DB with " +
819 812
                                 "action " + dbaction);
820
    EventLog.getInstance().log(ipAddress, user, docid, dbaction);
821 813
    }
822 814
    catch(Exception e)
823 815
    {
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
1948 1948
                            accNumber = null;
1949 1949
                        }
1950 1950
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
1951
                                doAction, accNumber, user, groups, request.getRemoteAddr());
1951
                                doAction, accNumber, user, groups);
1952 1952
                        EventLog.getInstance().log(request.getRemoteAddr(),
1953 1953
                                user, accNumber, action[0]);
1954 1954
                    } catch (NullPointerException npe) {
1955 1955
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
1956
                                doAction, null, user, groups, request.getRemoteAddr());
1956
                                doAction, null, user, groups);
1957 1957
                        EventLog.getInstance().log(request.getRemoteAddr(),
1958 1958
                                user, "", action[0]);
1959 1959
                    }
......
2262 2262

  
2263 2263
                try {
2264 2264
                    // null means notify server is null
2265
                    DocumentImpl.delete(docid[0], user, groups, null, request.getRemoteAddr());
2265
                    DocumentImpl.delete(docid[0], user, groups, null);
2266 2266
                    EventLog.getInstance().log(request.getRemoteAddr(),
2267 2267
                                               user, docid[0], "delete");
2268 2268
                    response.setContentType("text/xml");
......
2956 2956
                        // original command,
2957 2957
                        // not get force replication info from another metacat
2958 2958
                        ForceReplicationHandler frh = new ForceReplicationHandler(
2959
                                docid, "insert", false, null, username, request.getRemoteAddr());
2959
                                docid, "insert", false, null);
2960 2960

  
2961 2961
                        // set content type and other response header fields
2962 2962
                        // first
src/edu/ucsb/nceas/metacat/DocumentImpl.java
537 537
    public static void writeDataFileInReplication(InputStream input,
538 538
            String filePath, String docname, String doctype, String accnum,
539 539
            String user, String docHomeServer, String notificationServer, 
540
            String tableName, boolean timedReplication, String createDate, String updateDate, String ipAddress)
540
            String tableName, boolean timedReplication, String createDate, String updateDate)
541 541
            throws SQLException, AccessionNumberException, Exception
542 542
    {
543 543
        int serverCode = -2;
......
595 595
        if (!timedReplication)
596 596
        {
597 597
          ForceReplicationHandler forceReplication = new ForceReplicationHandler(
598
                accnum, false, notificationServer, user, ipAddress);
598
                accnum, false, notificationServer);
599 599
        }
600 600
    }
601 601
    
......
2236 2236

  
2237 2237
    public static String write(DBConnection conn, Reader xml, String pub,
2238 2238
            Reader dtd, String action, String docid, String user,
2239
            String[] groups, String ruleBase, boolean needValidation, String ipAddress)
2239
            String[] groups, String ruleBase, boolean needValidation)
2240 2240
            throws Exception
2241 2241
    {
2242 2242
        //this method will be called in handleUpdateOrInsert method
......
2244 2244
        // get server location for this doc
2245 2245
        int serverLocation = getServerLocationNumber(docid);
2246 2246
        return write(conn, xml, pub, dtd, action, docid, user, groups,
2247
                serverLocation, false, ruleBase, needValidation, ipAddress);
2247
                serverLocation, false, ruleBase, needValidation);
2248 2248
    }
2249 2249

  
2250 2250
    /**
......
2280 2280
    public static String write(DBConnection conn, Reader xml, String pub,
2281 2281
            Reader dtd, String action, String accnum, String user,
2282 2282
            String[] groups, int serverCode, boolean override, String ruleBase,
2283
            boolean needValidation, String ipAddress) throws Exception
2283
            boolean needValidation) throws Exception
2284 2284
    {
2285 2285
        // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
2286 2286
        //MetaCatUtil util = new MetaCatUtil();
......
2365 2365

  
2366 2366
                // Force replication the docid
2367 2367
                ForceReplicationHandler frh = new ForceReplicationHandler(
2368
                        accnum, true, null, user, ipAddress);
2368
                        accnum, true, null);
2369 2369
                return (accnum);
2370 2370

  
2371 2371
            }
......
2464 2464
        // other servers true mean it is xml document null is because no
2465 2465
        // metacat notify the force replication.
2466 2466
        ForceReplicationHandler frh = new ForceReplicationHandler(accnum,
2467
                action, true, null, user, ipAddress);
2467
                action, true, null);
2468 2468

  
2469 2469
        logMetacat.info("Conn Usage count after writting: "
2470 2470
                + conn.getUsageCount());
......
2511 2511
            String pub, Reader dtd, String action, String accnum, String user,
2512 2512
            String[] groups, String homeServer, String notifyServer,
2513 2513
            String ruleBase, boolean needValidation, String tableName, 
2514
            boolean timedReplication, String createDate, String updateDate, String ipAddress) throws Exception
2514
            boolean timedReplication, String createDate, String updateDate) throws Exception
2515 2515
    {
2516 2516
        long rootId;
2517 2517
        String docType = null;
......
2642 2642
        if (!timedReplication)
2643 2643
        {
2644 2644
          ForceReplicationHandler forceReplication = new ForceReplicationHandler(
2645
                accnum, action, true, notifyServer, user, ipAddress);
2645
                accnum, action, true, notifyServer);
2646 2646
        }
2647 2647
        return (accnum);
2648 2648
    }
......
2778 2778
     * @param docid
2779 2779
     *            the ID of the document to be deleted from the database
2780 2780
     */
2781
    public static void delete(String accnum, String user, String[] groups, String notifyServer, String ipAddress)
2781
    public static void delete(String accnum, String user, String[] groups, String notifyServer)
2782 2782
            throws Exception
2783 2783
    {
2784 2784

  
......
2926 2926

  
2927 2927
            conn.commit();
2928 2928
            conn.setAutoCommit(true);
2929
            //add force delete replcation document here.
2930
            ForceReplicationHandler frh = new ForceReplicationHandler(
2931
                             accnum, ForceReplicationHandler.DELETE, isXML, notifyServer, user, ipAddress);
2932 2929

  
2933 2930
        } catch (Exception e) {
2934 2931
            logMetacat.error("error in DocumentImpl.delete: "
......
2947 2944
                DBConnectionPool.returnDBConnection(conn, serialNumber);
2948 2945
            }
2949 2946
        }
2950
       
2947
       // add force delete replcation document here.
2948
       ForceReplicationHandler frh = new ForceReplicationHandler(
2949
                        accnum, ForceReplicationHandler.DELETE, isXML, notifyServer);
2951 2950

  
2952 2951
    }
2953 2952

  
......
3647 3646
                    xmldoc.toXml(new PrintWriter(System.out), null, null, true);
3648 3647
                }
3649 3648
            } else if (action.equals("DELETE")) {
3650
                DocumentImpl.delete(docid, null, null,null, null);
3649
                DocumentImpl.delete(docid, null, null,null);
3651 3650
                //System.out.println("Document deleted: " + docid);
3652 3651
            } else {
3653 3652
                /*
src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java
66 66
  }//Constructor
67 67

  
68 68
  public String write(DBConnection conn,Reader xml,String pub,Reader dtd,
69
                      String action, String docid, String user, String[] groups, String ipAddress)
69
                      String action, String docid, String user, String[] groups)
70 70
                      throws Exception
71 71
  {
72 72
    return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, 
73
                              groups, ruleBase, needValidation, ipAddress);
73
                              groups, ruleBase, needValidation);
74 74
  }
75 75
  
76 76
  public String writeReplication(DBConnection conn, Reader xml, 
......
78 78
                                        String accnum, String user,
79 79
                                        String[] groups,String homeServer, 
80 80
                                        String notifyServer, String createDate,
81
                                        String updateDate, String ipAddress)
81
                                        String updateDate)
82 82
                                        throws Exception
83 83
  {
84 84
    //we don't need to check validation in replciation
......
89 89
                                        accnum, user, groups, homeServer, 
90 90
                                        notifyServer, ruleBase, false, 
91 91
                                        DocumentImpl.DOCUMENTTABLE, false, 
92
                                        createDate, updateDate, ipAddress);
92
                                        createDate, updateDate);
93 93
                                        // last false means is not timed replication
94 94
                         
95 95
  }
......
116 116
          String accnum, String user,
117 117
          String[] groups,String homeServer, 
118 118
          String notifyServer, String tableName, 
119
          boolean timedReplication, String createDate, String updateDate, String ipAddress)
119
          boolean timedReplication, String createDate, String updateDate)
120 120
          throws Exception
121 121
  {
122 122
   //we don't need to check validation in replciation
......
124 124
   return DocumentImpl.writeReplication(conn, xml, pub, dtd, action, 
125 125
          accnum, user, groups, homeServer, 
126 126
          notifyServer, ruleBase, false, tableName, 
127
          timedReplication, createDate, updateDate, ipAddress);
127
          timedReplication, createDate, updateDate);
128 128
  }
129 129
}//DocumentImple
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
67 67
  private static int DOCERRORNUMBER  = 1;
68 68
  private static int REVINSERTNUMBER = 1;
69 69
  private static int REVERRORNUMBER  = 1;
70
  private String ipAddress = "192.186.1.1";
71 70
  public ReplicationHandler()
72 71
  {
73 72
    //this.out = o;
......
359 358
                              docHomeServer,
360 359
                              remoteserver, tableName, true,// true is for time replication 
361 360
                              createdDate,
362
                              updatedDate, ipAddress);
361
                              updatedDate);
363 362
      logMetacat.info("Successfully replicated doc " + accNumber);
364 363
      if (tableName.equals(DocumentImpl.DOCUMENTTABLE))
365 364
      {
......
472 471
                                                tableName,
473 472
                                                true, //true means timed replication
474 473
                                                createdDate,
475
                                                updatedDate,ipAddress);
474
                                                updatedDate);
476 475
                                         
477 476
        logMetacat.info("Successfully to write datafile " + accNumber);
478 477
        /*MetacatReplication.replLog("wrote datafile " + accNumber + " from " +
......
551 550
         //so we just add one for it. This rev number is no sence.
552 551
         String accnum=docId+util.getOption("accNumSeparator")+"1";
553 552
         //System.out.println("accnum: "+accnum);
554
         DocumentImpl.delete(accnum, null, null, notifyServer, ipAddress);
553
         DocumentImpl.delete(accnum, null, null, notifyServer);
555 554
         logMetacat.info("Successfully deleted doc " + docId);
556 555
         MetacatReplication.replLog("Doc " + docId + " deleted");
557 556
      }
src/edu/ucsb/nceas/metacat/ForceReplicationHandler.java
54 54
  private String action;
55 55
  private boolean xmlDocument;
56 56
  private boolean dbactionFlag = true;
57
  private String user = null;
58
  private String ipAddress = null;
59 57
  private ReplicationServerList serverLists = null;//Serverlist
60 58
  private int homeServerCode = 0; // home server code for the docid
61 59
  // When a metacat A got forcereplication
......
82 80
   * don't want A to notify B again. B is nofitification of A.
83 81
   */
84 82
  public ForceReplicationHandler(String docid, String action, boolean xml,
85
                                                   String myNotificationServer, String user, String ipAddress)
83
                                                   String myNotificationServer)
86 84
  {
87 85
    this.docid = docid;
88 86
    this.action = action;
89 87
    this.xmlDocument =xml;
90
    this.user = user;
91
    this.ipAddress = ipAddress;
92 88
    // Build a severLists from xml_replication table
93 89
    this.serverLists = new ReplicationServerList();
94 90
    // Get sever code for this docid
......
118 114
   * Use this constructor when the action is implied.
119 115
   */
120 116
  public ForceReplicationHandler(String docid, boolean xml,
121
                                                String myNotificationServer, String user, String ipAddress)
117
                                                String myNotificationServer )
122 118
  {
123 119
    this.docid = docid;
124 120
    this.xmlDocument = xml;
125
    this.user = user;
126
    this.ipAddress = ipAddress;
127 121
    dbactionFlag = false;
128 122
    // Build a severLists from xml_replication table
129 123
    this.serverLists = new ReplicationServerList();
......
205 199
                                 "?action=forcereplicate&server=" +
206 200
                                  util.getLocalReplicationServerName()+
207 201
                                 "&docid=" + docid + "&dbaction=" +
208
                                  action+"&ipAddress="+ipAddress);
202
                                  action);
209 203
                //over write the url for delete
210 204
                if (action != null && action.equals(DELETE))
211 205
                {
212 206
                  comeAndGetIt = new URL("https://" + server + "?action=" +
213 207
                                   MetacatReplication.FORCEREPLICATEDELETE +
214
                                  "&docid=" + docid +"&server="+ util.getLocalReplicationServerName()+"&user="+user+"&ipAddress="+ipAddress);
208
                                  "&docid=" + docid +"&server="+ util.getLocalReplicationServerName());
215 209

  
216 210
                }
217 211
              }//if servercode==1
......
228 222
                                 "?action=forcereplicate&server=" +
229 223
                                 util.getLocalReplicationServerName() +
230 224
                                 "&docid=" + docid + "&dbaction=" +
231
                                  action+"&ipAddress="+ipAddress);
225
                                  action);
232 226
                //over write the url for delete
233 227
               if (action != null && action.equals(DELETE))
234 228
               {
235 229
                  comeAndGetIt = new URL("https://" + server + "?action=" +
236 230
                            MetacatReplication.FORCEREPLICATEDELETE +
237
                           "&docid=" + docid+"&server="+ util.getLocalReplicationServerName()+"&user="+user+"&ipAddress="+ipAddress);
231
                           "&docid=" + docid+"&server="+ util.getLocalReplicationServerName());
238 232

  
239 233
                }
240 234
              }//else
......
252 246
                                 "?action=forcereplicatedatafile&server=" +
253 247
                                 util.getLocalReplicationServerName() +
254 248
                                 "&docid=" + docid + "&dbaction=" +
255
                                  action+"&ipAddress="+ipAddress);
249
                                  action);
256 250
                //over write the url for delete
257 251
               if (action != null && action.equals(DELETE))
258 252
               {
259 253
                 comeAndGetIt = new URL("https://" + server + "?action=" +
260 254
                                 MetacatReplication.FORCEREPLICATEDELETE +
261
                                 "&docid=" + docid +"&server="+ util.getLocalReplicationServerName()+"&user="+user+"&ipAddress="+ipAddress);
255
                                 "&docid=" + docid +"&server="+ util.getLocalReplicationServerName());
262 256

  
263 257
               }
264 258

  
......
276 270
                                 "?action=forcereplicatedatafile&server=" +
277 271
                                 util.getLocalReplicationServerName() +
278 272
                                 "&docid=" + docid + "&dbaction=" +
279
                                  action+"&ipAddress="+ipAddress);
273
                                  action);
280 274
                //over write the url for delete
281 275
               if (action != null && action.equals(DELETE))
282 276
               {
283 277
                  comeAndGetIt = new URL("https://" + server + "?action=" +
284 278
                         MetacatReplication.FORCEREPLICATEDELETE +
285
                        "&docid=" + docid+"&server="+ util.getLocalReplicationServerName()+"&user="+user+"&ipAddress="+ipAddress);
279
                        "&docid=" + docid+"&server="+ util.getLocalReplicationServerName());
286 280

  
287 281
               }
288 282

  
......
303 297
                comeAndGetIt = new URL("https://" + server +
304 298
                                 "?action=forcereplicate&server=" +
305 299
                                 util.getLocalReplicationServerName()+
306
                                 "&docid=" + docid+"&ipAddress="+ipAddress);
300
                                 "&docid=" + docid);
307 301

  
308 302
              }//if homeserver ==1
309 303
              else if (replicationServer.getHub()||
......
316 310
                comeAndGetIt = new URL("https://" + server +
317 311
                                 "?action=forcereplicate&server=" +
318 312
                                 util.getLocalReplicationServerName() +
319
                                 "&docid=" + docid+"&ipAddress="+ipAddress);
313
                                 "&docid=" + docid);
320 314

  
321 315
              }//else if
322 316

  
......
330 324
                comeAndGetIt = new URL("https://" + server +
331 325
                                 "?action=forcereplicatedatafile&server=" +
332 326
                                 util.getLocalReplicationServerName() +
333
                                 "&docid=" + docid+"&ipAddress="+ipAddress);
327
                                 "&docid=" + docid);
334 328
              }//if
335 329
              else if (replicationServer.getHub()||
336 330
                          server.equals(MetacatReplication.
......
342 336
                comeAndGetIt = new URL("https://" + server +
343 337
                                 "?action=forcereplicatedatafile&server=" +
344 338
                                 util.getLocalReplicationServerName() +
345
                                 "&docid=" + docid+"&ipAddress="+ipAddress);
339
                                 "&docid=" + docid);
346 340

  
347 341
              }//else
348 342
            }//else if

Also available in: Unified diff