Project

General

Profile

« Previous | Next » 

Revision 1011

Added by Jing Tao about 22 years ago

Fixed the getall didn't work. Now local host can insert or update documents from remote host.
But still there some problem on force replcation.

View differences:

src/edu/ucsb/nceas/metacat/ReplicationHandler.java
114 114
    }
115 115
    catch (Exception e)
116 116
    {
117
      System.out.println("Error in replicationHandler.run(): " + e.getMessage());
117
      //System.out.println("Error in replicationHandler.run():"+e.getMessage());
118 118
    }
119 119
  }
120 120
  
......
159 159
          }
160 160
          catch(SQLException sqleee)
161 161
          {
162
            System.out.println("error getting db connection in " + 
162
            /*System.out.println("error getting db connection in " + 
163 163
                               "ReplicationHandler.update: " +
164
                               sqleee.getMessage());
164
                               sqleee.getMessage());*/
165 165
          }
166 166
        }
167 167
      }
168 168
    }
169 169
    catch(Exception e)
170 170
    {
171
      System.out.println("error in ReplicationHandler.update: " + 
172
                          e.getMessage());
171
      /*System.out.println("error in ReplicationHandler.update: " + 
172
                          e.getMessage());*/
173 173
    }
174 174
    
175 175
    Enumeration keys;
......
194 194
      {
195 195
        server = (String)(keys.nextElement());
196 196
        MetacatReplication.replLog("full update started to: " + server);
197
        u = new URL("https://" + server + "?action=update");
198
        System.out.println("Sending Message: " + u.toString());
197
        u = new URL("https://" + server + "?server="
198
        +getLocalReplicationServerName()+"&action=update");
199
        //System.out.println("Sending Message: " + u.toString());
199 200
        String result = MetacatReplication.getURLContent(u);
200 201
        responses.add(result);
201 202
      }
......
253 254
          
254 255
          if(flag)
255 256
          { //if the document needs to be updated or inserted, this is executed
256
            u = new URL("https://" + docServer + "?action=read&docid=" +
257
                          docid);
258
            System.out.println("Sending message: " + u.toString());
257
            u = new URL("https://" + docServer + "?server="+
258
                  getLocalReplicationServerName()+"&action=read&docid="+docid);
259
            //System.out.println("Sending message: " + u.toString());
259 260
            String newxmldoc = MetacatReplication.getURLContent(u);
260 261
            DocInfoHandler dih = new DocInfoHandler();
261 262
            XMLReader docinfoParser = initParser(dih);
262 263
            URL docinfoUrl = new URL("https://" + docServer + 
263
                                   "?action=getdocumentinfo&docid=" +
264
                                   docid);
265
            System.out.println("Sending message: " + docinfoUrl.toString());
264
                  "?server="+getLocalReplicationServerName()+
265
                  "&action=getdocumentinfo&docid="+docid);
266
            //System.out.println("Sending message: " + docinfoUrl.toString());
266 267
            String docInfoStr = MetacatReplication.getURLContent(docinfoUrl);
267 268
            docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
268 269
            Hashtable docinfoHash = dih.getDocInfo();
269 270
            int serverCode = MetacatReplication.getServerCode(docServer);
270
            System.out.println("updating doc: " + docid + " action: "+ action);
271
            //System.out.println("updating doc: " + docid +" action: "+ action);
272
            //docid should include rev number too
273
            String accnum=docid+util.getOption("accNumSeparator")+
274
                                              (String)docinfoHash.get("rev");
275
            //System.out.println("accnum: "+accnum);
271 276
            try
272 277
            {
273 278
              String newDocid = DocumentImpl.write(conn, 
......
275 280
                              (String)docinfoHash.get("public_access"),
276 281
                              null,  /* the dtd text */
277 282
                              action, 
278
                              docid, 
283
                              accnum, 
279 284
                              (String)docinfoHash.get("user_owner"),
280 285
                              null, /* null for groups[] */
281 286
                              serverCode, 
......
283 288
                              false /* validate */);
284 289
              MetacatReplication.replLog("wrote doc " + docid + " from " + 
285 290
                                         docServer);
286
              System.out.println("wrote doc " + docid + " from " + 
287
                                 docServer);
291
              /*System.out.println("wrote doc " + docid + " from " + 
292
                                 docServer);*/
288 293
            }
289 294
            catch(Exception e)
290 295
            {
......
311 316
        while(keys.hasMoreElements())
312 317
        {
313 318
          server = (String)(keys.nextElement()); 
314
          URL dateurl = new URL("https://" + server + "?action=gettime");
319
          URL dateurl = new URL("https://" + server + "?server="+
320
          getLocalReplicationServerName()+"&action=gettime");
315 321
          String datexml = MetacatReplication.getURLContent(dateurl);
316 322
          String datestr = datexml.substring(11, datexml.indexOf('<', 11));
317 323
          StringBuffer sql = new StringBuffer();
......
330 336
    }
331 337
    catch(Exception e)
332 338
    {
333
      System.out.println("error in ReplicationHandler.update: " + 
334
                          e.getMessage());
339
      /*System.out.println("error in ReplicationHandler.update: " + 
340
                          e.getMessage());*/
335 341
      e.printStackTrace(System.out);
336 342
    }
337 343
    finally
......
382 388
      while(keys.hasMoreElements())
383 389
      { //go through each server
384 390
        server = (String)(keys.nextElement());
385
        URL u = new URL("https://" + server + "?action=getcatalog");
391
        URL u = new URL("https://" + server + "?server="+
392
        getLocalReplicationServerName()+"&action=getcatalog");
386 393
        System.out.println("sending message " + u.toString());
387 394
        String catxml = MetacatReplication.getURLContent(u);
388 395
        //System.out.println("catxml: " + catxml);
......
628 635

  
629 636
    return parser;
630 637
  }
638
  
639
  /**
640
   * Method to get the name of local replication server
641
   */
642
   private String getLocalReplicationServerName()
643
   {
644
     String replicationServerName=null;
645
     String serverHost=null;
646
     serverHost=util.getOption("server");
647
     // append "context/servelet/replication" to the host name
648
     replicationServerName=serverHost+"/"+util.getOption("context")+
649
                                            "/servlet/replication";
650
     return replicationServerName;
651
       
652
   }
631 653
}
654
   

Also available in: Unified diff