Project

General

Profile

« Previous | Next » 

Revision 3229

Added by Jing Tao about 17 years ago

This commit is for branch. In this commit the correct ip and user name will be stored in access_log table in replication event. However, it only for Forcereplication. And the test isn't completed yet. This commit is only for future use.

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];
582 583
    String dbaction = "UPDATE"; // the default action is UPDATE
583 584
    boolean override = false;
584 585
    int serverCode = 1;
......
653 654
      DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false);
654 655
      wrapper.writeReplication(dbConn, new StringReader(xmldoc), null, null,
655 656
                               dbaction, docid, user, null, homeServer, 
656
                               server, createdDate, updatedDate);
657

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

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

  
......
810 817

  
811 818
    MetacatReplication.replLog("datafile " + docid + " added to DB with " +
812 819
                                 "action " + dbaction);
820
    EventLog.getInstance().log(ipAddress, user, docid, dbaction);
813 821
    }
814 822
    catch(Exception e)
815 823
    {
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);
1951
                                doAction, accNumber, user, groups, request.getRemoteAddr());
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);
1956
                                doAction, null, user, groups, request.getRemoteAddr());
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);
2265
                    DocumentImpl.delete(docid[0], user, groups, null, request.getRemoteAddr());
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);
2959
                                docid, "insert", false, null, username, request.getRemoteAddr());
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)
540
            String tableName, boolean timedReplication, String createDate, String updateDate, String ipAddress)
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);
598
                accnum, false, notificationServer, user, ipAddress);
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)
2239
            String[] groups, String ruleBase, boolean needValidation, String ipAddress)
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);
2247
                serverLocation, false, ruleBase, needValidation, ipAddress);
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) throws Exception
2283
            boolean needValidation, String ipAddress) 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);
2368
                        accnum, true, null, user, ipAddress);
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);
2467
                action, true, null, user, ipAddress);
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) throws Exception
2514
            boolean timedReplication, String createDate, String updateDate, String ipAddress) 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);
2645
                accnum, action, true, notifyServer, user, ipAddress);
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)
2781
    public static void delete(String accnum, String user, String[] groups, String notifyServer, String ipAddress)
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);
2929 2932

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

  
2951 2952
    }
2952 2953

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

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

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

  
257 263
               }
258 264

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

  
281 287
               }
282 288

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

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

  
315 321
              }//else if
316 322

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

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

Also available in: Unified diff