Project

General

Profile

« Previous | Next » 

Revision 2298

Added by Jing Tao about 20 years ago

Add new feature that delete can be broadcasted by force replication.

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
47 47
  private Vector fileLocks = new Vector();
48 48
  private Thread lockThread = null;
49 49
  private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter;
50
  public static final String FORCEREPLICATEDELETE = "forcereplicatedelete";
50 51

  
51 52
  /**
52 53
   * Initialize the servlet by creating appropriate database connections
......
228 229
      //read a specific docid from remote host, and store it into local host
229 230
      handleForceReplicateRequest(out, params, response);
230 231

  
232
    } else if ( action.equals(FORCEREPLICATEDELETE) ) {
233
      //read a specific docid from remote host, and store it into local host
234
      handleForceReplicateDeleteRequest(out, params, response);
235

  
231 236
    } else if ( action.equals("update") ) {
232 237
      //request an update list from the server
233 238
      handleUpdateRequest(out, params, response);
......
595 600
    }//finally
596 601
  }
597 602

  
603
/*
604
 * when a forcereplication delete request comes in, local host will delete this
605
 * document
606
 */
607
private void handleForceReplicateDeleteRequest(PrintWriter out, Hashtable params,
608
                                         HttpServletResponse response)
609
{
610
  String server = ((String[])params.get("server"))[0]; // the server that
611
  String docid = ((String[])params.get("docid"))[0]; // sent the document
612
  try
613
  {
614
    MetacatReplication.replLog("force replication delete request from " + server);
615
    MetacatReplication.replLog("force replication delete docid " + docid);
616
    MetaCatUtil.debugMessage("Force replication delete request from: "+ server, 34);
617
    MetaCatUtil.debugMessage("Force replication delete docid: "+docid, 34);
618
    DocumentImpl.delete(docid, null, null, server);
619
    MetacatReplication.replLog("document " + docid + " was successfully deleted ");
620
    MetaCatUtil.debugMessage("document " + docid + " was successfully deleted ", 34);
621
  }
622
  catch(Exception e)
623
  {
624
    MetacatReplication.replErrorLog("document " + docid +
625
                                    " failed to delete because "+
626
                                     e.getMessage());
627
    MetaCatUtil.debugMessage("ERROR in MetacatReplication.handleForceDeleteReplicate" +
628
                       "Request(): " + e.getMessage(), 30);
629

  
630
  }//catch
631

  
632
}
633

  
634

  
598 635
  /**
599 636
   * when a forcereplication data file request comes in, local host sends a
600 637
   * readdata request to the requesting server (remote server) for the specified
......
668 705

  
669 706
      //if action is delete, we don't delete the data file. Just archieve
670 707
      //the xml_documents
671
      if (dbaction.equals("delete"))
708
      /*if (dbaction.equals("delete"))
672 709
      {
673 710
        //conn = util.getConnection();
674 711
        DocumentImpl.delete(docid,user,null);
675 712
        //util.returnConnection(conn);
676
      }
713
      }*/
677 714
      //To data file insert or update is same
678
      else if (dbaction.equals("insert")||dbaction.equals("update"))
715
      if (dbaction.equals("insert")||dbaction.equals("update"))
679 716
      {
680 717
        //Get data file and store it into local file system.
681 718
        // sending back readdata request to server
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
1822 1822
            try {
1823 1823

  
1824 1824
                try {
1825
                    DocumentImpl.delete(docid[0], user, groups);
1825
                    // null means notify server is null
1826
                    DocumentImpl.delete(docid[0], user, groups, null);
1826 1827
                    EventLog.getInstance().log(request.getRemoteAddr(),
1827 1828
                                               user, docid[0], "delete");
1828 1829
                    response.setContentType("text/xml");
src/edu/ucsb/nceas/metacat/DocumentImpl.java
1156 1156
    /**
1157 1157
     * Build the index records for this document.  For each node, all absolute
1158 1158
     * and relative paths to the root of the document are created and inserted
1159
     * into the xml_index table.  This requires that the DocumentImpl instance 
1160
     * exists, so first call the constructor that reads the document from the 
1159
     * into the xml_index table.  This requires that the DocumentImpl instance
1160
     * exists, so first call the constructor that reads the document from the
1161 1161
     * database.
1162 1162
     *
1163 1163
     * @throws McdbException on error getting the node records for the document
......
1179 1179
            Long nodeId = new Long(currentNode.getNodeId());
1180 1180
            nodeRecordMap.put(nodeId, currentNode);
1181 1181
        }
1182
        
1183
        // Opening separate db connection for deleting and writing 
1182

  
1183
        // Opening separate db connection for deleting and writing
1184 1184
        // XML Index -- be sure that it is all in one db transaction
1185 1185
        int serialNumber = -1;
1186 1186
        DBConnection dbConn = null;
......
1191 1191
            dbConn.setAutoCommit(false);
1192 1192
            //make sure record is done
1193 1193
            //checkDocumentTable();
1194
            
1194

  
1195 1195
            // Delete the previous index entries for this document
1196 1196
            deleteNodeIndex(dbConn);
1197
            
1197

  
1198 1198
            // Step through all of the node records we were given
1199 1199
            // and build the new index and update the database
1200 1200
            it = nodeRecordLists.iterator();
......
1204 1204
                if (currentNode.nodetype.equals("ELEMENT") ||
1205 1205
                    currentNode.nodetype.equals("ATTRIBUTE") ) {
1206 1206

  
1207
                    System.err.println("\nStarting Node: " + 
1208
                        currentNode.getNodeId() + " (" + 
1209
                        currentNode.getParentNodeId() + "): " + 
1207
                    System.err.println("\nStarting Node: " +
1208
                        currentNode.getNodeId() + " (" +
1209
                        currentNode.getParentNodeId() + "): " +
1210 1210
                        currentNode.getNodeName() + " (" +
1211 1211
                        currentNode.getNodeType() + ")");
1212 1212
                    if (atRootElement) {
1213 1213
                        rootNodeId = currentNode.getNodeId();
1214 1214
                        atRootElement = false;
1215 1215
                    }
1216
                    traverseParents(nodeRecordMap, rootNodeId, 
1216
                    traverseParents(nodeRecordMap, rootNodeId,
1217 1217
                            currentNode.getNodeId(),
1218 1218
                            currentNode.getNodeId(), "", pathList);
1219 1219
                    updateNodeIndex(dbConn, pathList);
1220

  
1220 1221
                }
1222

  
1221 1223
            }
1222 1224
            dbConn.commit();
1223 1225
        } catch (SQLException e) {
1224 1226
            MetaCatUtil.debugMessage(
1225 1227
                "SQL Exception while inserting path index in " +
1226 1228
                "DocumentImpl.buildIndex for document " + docid, 10);
1227
      		MetaCatUtil.debugMessage(e.getMessage(), 10);
1229
                      MetaCatUtil.debugMessage(e.getMessage(), 10);
1228 1230
            e.printStackTrace();
1229 1231
            try {
1230 1232
                dbConn.rollback();
1231 1233
            } catch (SQLException sqle) {
1232
            	MetaCatUtil.debugMessage(
1233
					"Error while rolling back commit in DocumentImpl.buildIndex"
1234
                    MetaCatUtil.debugMessage(
1235
                                        "Error while rolling back commit in DocumentImpl.buildIndex"
1234 1236
                    + "\n" + sqle.getMessage(), 10);
1235 1237
            }
1236 1238
        } finally {
1237
			DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1239
                        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1238 1240
        }
1239 1241
    }
1240 1242

  
......
1249 1251
     * @param children the string representation of all child nodes of this id
1250 1252
     * @param pathList the hash to which paths are added
1251 1253
     */
1252
    private void traverseParents(HashMap records, long rootNodeId, 
1253
            long leafNodeId, long id, 
1254

  
1255
    private void traverseParents(HashMap records, long rootNodeId,
1256
            long leafNodeId, long id,
1254 1257
            String children, HashMap pathList) {
1255 1258
        Long nodeId = new Long(id);
1256 1259
        NodeRecord current = (NodeRecord)records.get(nodeId);
......
1273 1276
            String path = current.getNodeName() + children;
1274 1277
            if (!children.equals("")) {
1275 1278
                System.err.print("B: " + path +"\n");
1276
                pathList.put(path, new PathIndexEntry(leafNodeId, path, docid, 
1279
                pathList.put(path, new PathIndexEntry(leafNodeId, path, docid,
1277 1280
                    doctype, parentId));
1278 1281
            }
1279 1282
            if (id == rootNodeId) {
......
1281 1284
                System.err.print("C: " + fullPath +"\n");
1282 1285
                pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath,
1283 1286
                    docid, doctype, parentId));
1287

  
1284 1288
            }
1285 1289
        }
1286 1290
    }
1287 1291

  
1288 1292
    /**
1289
     * Delete the paths from the xml_index table on the database in preparation 
1293
     * Delete the paths from the xml_index table on the database in preparation
1290 1294
     * of a subsequent update.
1291 1295
     *
1292 1296
     * @param conn the database connection to use, keeping a single transaction
......
1298 1302
        String sql = "DELETE FROM xml_index WHERE docid LIKE ?";
1299 1303
        MetaCatUtil.debugMessage(sql, 55);
1300 1304
        System.err.println("SQL is: " + sql);
1301
        
1305

  
1302 1306
        PreparedStatement pstmt = conn.prepareStatement(sql);
1303 1307

  
1304 1308
        // Increase usage count for the connection
1305 1309
        conn.increaseUsageCount(1);
1306
        
1310

  
1307 1311
        // Execute the delete and close the statement
1308 1312
        pstmt.setString(1, familyId);
1309 1313
        int rows = pstmt.executeUpdate();
......
1311 1315
        MetaCatUtil.debugMessage("Deleted " + rows + " rows from xml_index " +
1312 1316
            "for document " + docid, 55);
1313 1317
    }
1314
    
1318

  
1315 1319
    /**
1316
	 * Insert the paths from the pathList into the xml_index table on the
1320
         * Insert the paths from the pathList into the xml_index table on the
1317 1321
     * database.
1318 1322
     *
1319 1323
     * @param conn the database connection to use, keeping a single transaction
1320 1324
     * @param pathList the hash of paths to insert
1321 1325
     * @throws SQLException if there is an error inserting into the db
1322 1326
     */
1323
    private void updateNodeIndex(DBConnection conn, HashMap pathList) 
1324
    	throws SQLException
1327
    private void updateNodeIndex(DBConnection conn, HashMap pathList)
1328
            throws SQLException
1325 1329
    {
1326 1330
        // Create an insert statement to reuse for all of the path
1327 1331
        // insertions
......
1333 1337
        String familyId = MetaCatUtil.getDocIdFromString(docid);
1334 1338
        pstmt.setString(3, familyId);
1335 1339
        pstmt.setString(4, doctype);
1336
        
1340

  
1337 1341
        // Step through the hashtable and insert each of the path values
1338 1342
        Iterator it = pathList.values().iterator();
1339 1343
        while (it.hasNext()) {
......
1348 1352
        // Close the database statement
1349 1353
        pstmt.close();
1350 1354
    }
1351
    
1355

  
1352 1356
    private boolean isRevisionOnly(DocumentIdentifier docid) throws Exception
1353 1357
    {
1354 1358
        //System.out.println("inRevisionOnly");
......
2316 2320
     * @param docid
2317 2321
     *            the ID of the document to be deleted from the database
2318 2322
     */
2319
    public static void delete(String accnum, String user, String[] groups)
2323
    public static void delete(String accnum, String user, String[] groups, String notifyServer)
2320 2324
            throws Exception
2321 2325
    {
2322
        // OLD
2323
        //DocumentIdentifier id = new DocumentIdentifier(accnum);
2324
        //String docid = id.getIdentifier();
2325
        //String rev = id.getRev();
2326 2326

  
2327
        // OLD
2328
        // Determine if the docid,rev are OK for DELETE
2329
        //AccessionNumber ac = new AccessionNumber(conn);
2330
        //docid = ac.generate(docid, rev, "DELETE");
2331 2327
        DBConnection conn = null;
2332 2328
        int serialNumber = -1;
2333 2329
        PreparedStatement pstmt = null;
2330
        boolean isXML   = true;
2334 2331
        try {
2335 2332
            //check out DBConnection
2336 2333
            conn = DBConnectionPool.getDBConnection("DocumentImpl.delete");
......
2338 2335

  
2339 2336
            // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV
2340 2337
            // IN IT
2341
            AccessionNumber ac = new AccessionNumber(accnum, "DELETE");
2342
            String docid = ac.getDocid();
2343
            String rev = ac.getRev();
2338
            //AccessionNumber ac = new AccessionNumber(accnum, "DELETE");
2339
            String docid = MetaCatUtil.getDocIdFromAccessionNumber(accnum);
2340
            //String rev = ac.getRev();
2344 2341

  
2342
            // get the type of deleting docid, this will be used in forcereplication
2343
            String type = getDocTypeFromDB(conn, docid);
2344
            if (type != null && type.trim().equals("BIN"))
2345
            {
2346
              isXML = false;
2347
            }
2348

  
2345 2349
            MetaCatUtil.debugMessage("Start deleting doc " + docid + "...", 20);
2346 2350
            // check for 'write' permission for 'user' to delete this document
2347 2351
            if (!hasAllPermission(user, groups, accnum)) { throw new Exception(
......
2428 2432
                DBConnectionPool.returnDBConnection(conn, serialNumber);
2429 2433
            }
2430 2434
        }
2431
        //IF this is a package document:
2432
        //delete all of the relations that this document created.
2433
        //if the deleted document is a package document its relations should
2434
        //no longer be active if it has been deleted from the system.
2435
       // add force delete replcation document here.
2436
       ForceReplicationHandler frh = new ForceReplicationHandler(
2437
                        accnum, ForceReplicationHandler.DELETE, isXML, notifyServer);
2435 2438
    }
2436 2439

  
2440
    private static String getDocTypeFromDB(DBConnection conn, String docidWithoutRev)
2441
                                 throws SQLException
2442
    {
2443
      String type = null;
2444
      String sql = "SELECT DOCTYPE FROM xml_documents WHERE docid LIKE " + "'" +
2445
                    docidWithoutRev +"'";
2446
      Statement stmt = null;
2447
      stmt = conn.createStatement();
2448
      ResultSet result = stmt.executeQuery(sql);
2449
      boolean hasResult = result.next();
2450
      if (hasResult)
2451
      {
2452
        type = result.getString(1);
2453
      }
2454
      MetaCatUtil.debugMessage("The type of deleting docid " + docidWithoutRev +
2455
                               " is " + type, 2);
2456
      return type;
2457
    }
2458

  
2437 2459
    /**
2438 2460
     * Check for "WRITE" permission on @docid for @user and/or @groups
2439 2461
     * from DB connection
......
3096 3118
                    xmldoc.toXml(new PrintWriter(System.out), null, null, true);
3097 3119
                }
3098 3120
            } else if (action.equals("DELETE")) {
3099
                DocumentImpl.delete(docid, null, null);
3121
                DocumentImpl.delete(docid, null, null,null);
3100 3122
                System.out.println("Document deleted: " + docid);
3101 3123
            } else {
3102 3124
                /*
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
124 124
    ReplicationServer replServer = null; // Variable to store the
125 125
                                        // ReplicationServer got from
126 126
                                        // Server list
127
    String server; // Variable to store server name
127
    String server = null; // Variable to store server name
128 128
    String update;
129 129
    ReplMessageHandler message = new ReplMessageHandler();
130 130
    Vector responses = new Vector();
......
332 332
          String docId = (String)w.elementAt(0);
333 333
          try
334 334
          {
335
            handleDeleteSingleDocument(docId);
335
            handleDeleteSingleDocument(docId, server);
336 336
          }
337 337
          catch (Exception ee)
338 338
          {
......
547 547

  
548 548

  
549 549
  /* Handle delete single document*/
550
  private void handleDeleteSingleDocument(String docId)
550
  private void handleDeleteSingleDocument(String docId, String notifyServer)
551 551
               throws Exception
552 552
  {
553 553
    MetaCatUtil.debugMessage("Try delete doc: "+docId, 40);
......
566 566
         //so we just add one for it. This rev number is no sence.
567 567
         String accnum=docId+util.getOption("accNumSeparator")+"1";
568 568
         //System.out.println("accnum: "+accnum);
569
         DocumentImpl.delete(accnum, null, null);
569
         DocumentImpl.delete(accnum, null, null, notifyServer);
570 570
         MetaCatUtil.debugMessage("Successfully deleted doc " + docId, 30);
571 571
         MetacatReplication.replLog("Doc " + docId + " deleted");
572 572
      }
src/edu/ucsb/nceas/metacat/ForceReplicationHandler.java
1 1
/**
2 2
 *  '$RCSfile$'
3
 *    Purpose: A class to asyncronously force the replication of each server 
4
 *             that has an entry in the xml_replication table.  When run, 
5
 *             this thread communicates with each server in the list and 
6
 *             solicites a read of an updated or newly inserted document 
3
 *    Purpose: A class to asyncronously force the replication of each server
4
 *             that has an entry in the xml_replication table.  When run,
5
 *             this thread communicates with each server in the list and
6
 *             solicites a read of an updated or newly inserted document
7 7
 *             with a certain docid.
8 8
 *  Copyright: 2000 Regents of the University of California and the
9 9
 *             National Center for Ecological Analysis and Synthesis
......
28 28
 * along with this program; if not, write to the Free Software
29 29
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30 30
 */
31
 
31

  
32 32
package edu.ucsb.nceas.metacat;
33 33

  
34 34
import java.util.*;
......
39 39
import java.text.*;
40 40

  
41 41
/**
42
 * A class to asyncronously force the replication of each server 
43
 * that has an entry in the xml_replication table.  When run, 
44
 * this thread communicates with each server in the list and 
45
 * solicites a read of an updated or newly inserted document 
42
 * A class to asyncronously force the replication of each server
43
 * that has an entry in the xml_replication table.  When run,
44
 * this thread communicates with each server in the list and
45
 * solicites a read of an updated or newly inserted document
46 46
 * with a certain docid.
47 47
 */
48 48
public class ForceReplicationHandler implements Runnable
......
53 53
  private String action;
54 54
  private boolean xmlDocument;
55 55
  private boolean dbactionFlag = true;
56
  private ReplicationServerList serverLists = null;//Serverlist 
56
  private ReplicationServerList serverLists = null;//Serverlist
57 57
  private int homeServerCode = 0; // home server code for the docid
58
  // When a metacat A got forcereplication 
58
  // When a metacat A got forcereplication
59 59
  // notification from B, then A will update its record. And A will notification
60 60
  // other metacat in its serverlist to update this docid if A is a hub. But we
61 61
  // don't want A to notify B again. B is nofitification of A
62 62
  private String notificationServer = null;
63
  
64
  
65
  
63

  
64
  //constant
65
  public static final String DELETE = "delete";
66

  
67

  
68

  
66 69
  /**
67 70
   * Constructor of ForceReplicationHandler
68 71
   * @param docid the docid to force replicate
69
   * @param the action that is being performed on the document (either 
72
   * @param the action that is being performed on the document (either
70 73
   *        INSERT or UPDATE)
71 74
   * @param xml the docid is a xml document or not (data file)
72
   * @param notificationServer, when a metacat A got forcereplication 
75
   * @param notificationServer, when a metacat A got forcereplication
73 76
   * notification from B, then A will update its record. And A will notification
74 77
   * other metacat in its serverlist to update this docid if A is a hub. But we
75 78
   * don't want A to notify B again. B is nofitification of A.
76 79
   */
77
  public ForceReplicationHandler(String docid, String action, boolean xml, 
80
  public ForceReplicationHandler(String docid, String action, boolean xml,
78 81
                                                   String myNotificationServer)
79 82
  {
80 83
    this.docid = docid;
......
94 97
    }//catch
95 98
    // Get the notification server
96 99
    this.notificationServer = myNotificationServer;
97
    
100

  
98 101
    if(this.action.equals(""))
99 102
    {
100 103
      dbactionFlag = false;
101 104
    }
102
    
105

  
103 106
    btThread = new Thread(this);
104 107
    btThread.setPriority(Thread.MIN_PRIORITY);
105 108
    btThread.start();
106 109
  }
107
  
110

  
108 111
  /**
109 112
   * Use this constructor when the action is implied.
110 113
   */
111
  public ForceReplicationHandler(String docid, boolean xml, 
114
  public ForceReplicationHandler(String docid, boolean xml,
112 115
                                                String myNotificationServer )
113 116
  {
114 117
    this.docid = docid;
......
132 135
    btThread.setPriority(Thread.MIN_PRIORITY);
133 136
    btThread.start();
134 137
  }
135
  
138

  
136 139
  /**
137
   * Method to send force replication command to other server to get 
140
   * Method to send force replication command to other server to get
138 141
   * a new or updated docid
139 142
   */
140 143
  public void run()
141 144
  {
142
    
145

  
143 146
    try
144 147
    {
145 148
      // URL for notifcation
......
149 152
      {
150 153
        return;
151 154
      }
152
      
153
      // Thread seelping for some seconds to make sure the document was insert 
155

  
156
      // Thread seelping for some seconds to make sure the document was insert
154 157
      // into the database before we send force replication request
155 158
      int sleepTime = Integer.parseInt
156 159
                         (MetaCatUtil.getOption("forcereplicationwaitingtime"));
......
165 168
        ReplicationServer replicationServer = serverLists.serverAt(i);
166 169
       // Get this ReplicationServer 's name
167 170
        String server = replicationServer.getServerName();
168
        
169
        // If the server is the notification server, we don't notify it back 
171

  
172
        // If the server is the notification server, we don't notify it back
170 173
        // again, if server is null we don't replication it
171 174
        if (server!=null && !server.equals(notificationServer))
172 175
        {
173
          
176

  
174 177
          if(dbactionFlag)
175 178
          {
176 179
            // xml documents and server can replicate xml doucment
......
179 182
              // If this docid's homeserver is localhost, replicate it
180 183
              if (homeServerCode==1)
181 184
              {
182
                MetacatReplication.replLog("force xml replicating to " 
185
                MetacatReplication.replLog("force xml replicating to "
183 186
                                                                    + server);
184
                comeAndGetIt = new URL("https://" + server + 
185
                                 "?action=forcereplicate&server=" + 
186
                                 util.getOption("server") + 
187
                comeAndGetIt = new URL("https://" + server +
188
                                 "?action=forcereplicate&server=" +
189
                                 util.getOption("server") +
187 190
                                 util.getOption("replicationpath") +
188 191
                                 "&docid=" + docid + "&dbaction=" +
189 192
                                  action);
193
                //over write the url for delete
194
                if (action != null && action.equals(DELETE))
195
                {
196
                  comeAndGetIt = new URL("https://" + server + "?action=" +
197
                                   MetacatReplication.FORCEREPLICATEDELETE +
198
                                  "&docid=" + docid +"&server="+ util.getOption("server")+
199
                                   util.getOption("replicationpath"));
200

  
201
                }
190 202
              }//if servercode==1
191 203
              else if (replicationServer.getHub()||
192 204
                   server.equals(MetacatReplication.
......
195 207
                // If the docid's home server is not local host, but local host
196 208
                // is a hub of this server, replicate the docid too.
197 209
                // If the server is homeserver of the docid, replication it too
198
                MetacatReplication.replLog("force xml replicating to " 
210
                MetacatReplication.replLog("force xml replicating to "
199 211
                                                                    + server);
200
                comeAndGetIt = new URL("https://" + server + 
201
                                 "?action=forcereplicate&server=" + 
202
                                 util.getOption("server") + 
212
                comeAndGetIt = new URL("https://" + server +
213
                                 "?action=forcereplicate&server=" +
214
                                 util.getOption("server") +
203 215
                                 util.getOption("replicationpath") +
204 216
                                 "&docid=" + docid + "&dbaction=" +
205 217
                                  action);
206
               
218
                //over write the url for delete
219
               if (action != null && action.equals(DELETE))
220
               {
221
                  comeAndGetIt = new URL("https://" + server + "?action=" +
222
                            MetacatReplication.FORCEREPLICATEDELETE +
223
                           "&docid=" + docid+"&server="+ util.getOption("server")+
224
                           util.getOption("replicationpath"));
225

  
226
                }
207 227
              }//else
208
             
228

  
209 229
            }//if xmlDocument
210 230
            //It is data file and configured to handle data replication
211 231
            else if (replicationServer.getDataReplication())
......
213 233
              // If the docid's home server is local host, replicate the docid
214 234
              if (homeServerCode==1)
215 235
              {
216
                MetacatReplication.replLog("force data replicating to " 
236
                MetacatReplication.replLog("force data replicating to "
217 237
                                                                      + server);
218
                comeAndGetIt = new URL("https://" + server + 
219
                                 "?action=forcereplicatedatafile&server=" + 
220
                                 util.getOption("server") + 
238
                comeAndGetIt = new URL("https://" + server +
239
                                 "?action=forcereplicatedatafile&server=" +
240
                                 util.getOption("server") +
221 241
                                 util.getOption("replicationpath") +
222 242
                                 "&docid=" + docid + "&dbaction=" +
223 243
                                  action);
244
                //over write the url for delete
245
               if (action != null && action.equals(DELETE))
246
               {
247
                 comeAndGetIt = new URL("https://" + server + "?action=" +
248
                                 MetacatReplication.FORCEREPLICATEDELETE +
249
                                 "&docid=" + docid +"&server="+ util.getOption("server")+
250
                                util.getOption("replicationpath") );
251

  
252
               }
253

  
224 254
              }//if serverCode==1
225 255
              else if (replicationServer.getHub()||
226 256
                server.equals(MetacatReplication.
227 257
                                    getServerNameForServerCode(homeServerCode)))
228 258
              {
229
                // If the docid's home server is not local host, but local host 
259
                // If the docid's home server is not local host, but local host
230 260
                // is a hub of this server, replicate the docid too.
231 261
                // If the server is homeserver of the docid replication it too
232
                 MetacatReplication.replLog("force data replicating to " 
262
                 MetacatReplication.replLog("force data replicating to "
233 263
                                                                      + server);
234
                comeAndGetIt = new URL("https://" + server + 
235
                                 "?action=forcereplicatedatafile&server=" + 
236
                                 util.getOption("server") + 
264
                comeAndGetIt = new URL("https://" + server +
265
                                 "?action=forcereplicatedatafile&server=" +
266
                                 util.getOption("server") +
237 267
                                 util.getOption("replicationpath") +
238 268
                                 "&docid=" + docid + "&dbaction=" +
239 269
                                  action);
240
                
270
                //over write the url for delete
271
               if (action != null && action.equals(DELETE))
272
               {
273
                  comeAndGetIt = new URL("https://" + server + "?action=" +
274
                         MetacatReplication.FORCEREPLICATEDELETE +
275
                        "&docid=" + docid+"&server="+ util.getOption("server")+
276
                       util.getOption("replicationpath") );
277

  
278
               }
279

  
241 280
              }//else if servercode==1
242 281
            }//else if data file
243
    
282

  
244 283
          }//if has explicite action
245 284
          else
246 285
          { // has implicite action
......
251 290
            {
252 291
              // If homeserver of this doicd is local, replicate it
253 292
              if (homeServerCode ==1)
254
              { 
255
                comeAndGetIt = new URL("https://" + server + 
256
                                 "?action=forcereplicate&server=" + 
257
                                 util.getOption("server") + 
293
              {
294
                comeAndGetIt = new URL("https://" + server +
295
                                 "?action=forcereplicate&server=" +
296
                                 util.getOption("server") +
258 297
                                 util.getOption("replicationpath") +
259 298
                                 "&docid=" + docid);
260
                
299

  
261 300
              }//if homeserver ==1
262 301
              else if (replicationServer.getHub()||
263 302
                   server.equals(MetacatReplication.
264 303
                   getServerNameForServerCode(homeServerCode)))
265 304
              {
266
                // If home server of this docid is not local host, but local 
305
                // If home server of this docid is not local host, but local
267 306
                // host is a hub for this server, replicate this doicd
268 307
                // If the server is homeserver of the docid, replication it too
269
                comeAndGetIt = new URL("https://" + server + 
270
                                 "?action=forcereplicate&server=" + 
271
                                 util.getOption("server") + 
308
                comeAndGetIt = new URL("https://" + server +
309
                                 "?action=forcereplicate&server=" +
310
                                 util.getOption("server") +
272 311
                                 util.getOption("replicationpath") +
273 312
                                 "&docid=" + docid);
274
                
313

  
275 314
              }//else if
276
              
315

  
277 316
            }//if xmlDoucment
278
            else if (replicationServer.getDataReplication())          
317
            else if (replicationServer.getDataReplication())
279 318
            { //It is datafile and server is configured to replicate data file
280
              
319

  
281 320
              //if home server is local host, replicate the data file
282 321
              if (homeServerCode ==1)
283 322
              {
284
                comeAndGetIt = new URL("https://" + server + 
285
                                 "?action=forcereplicatedatafile&server=" + 
286
                                 util.getOption("server") + 
323
                comeAndGetIt = new URL("https://" + server +
324
                                 "?action=forcereplicatedatafile&server=" +
325
                                 util.getOption("server") +
287 326
                                 util.getOption("replicationpath") +
288 327
                                 "&docid=" + docid);
289 328
              }//if
......
294 333
                // If home server is not local host, but the local host is a hub
295 334
                // For this server, replicate the data file
296 335
                // If the server is homeserver of the docid, replication it too
297
                comeAndGetIt = new URL("https://" + server + 
298
                                 "?action=forcereplicatedatafile&server=" + 
299
                                 util.getOption("server") + 
336
                comeAndGetIt = new URL("https://" + server +
337
                                 "?action=forcereplicatedatafile&server=" +
338
                                 util.getOption("server") +
300 339
                                 util.getOption("replicationpath") +
301 340
                                 "&docid=" + docid);
302
                
341

  
303 342
              }//else
304 343
            }//else if
305 344
          }//else has implicit action
306
          
345

  
307 346
          //Make sure comeAndGetIt is not empty
308 347
          if ( comeAndGetIt != null && !comeAndGetIt.equals(""))
309 348
          {
310
            MetaCatUtil.debugMessage("sending message: " 
349
            MetaCatUtil.debugMessage("sending message: "
311 350
                                                + comeAndGetIt.toString(), 25);
312 351
            String message = MetacatReplication.getURLContent(comeAndGetIt);
313 352
          }
......
316 355
          //invoces a read request from the server to this local machine.
317 356
        }//if notification server
318 357
      }//for
319
     
358

  
320 359
    }//try
321 360
    catch(Exception e)
322 361
    {
323
      System.out.println("error in ForceReplicationHandler.run: " + 
362
      System.out.println("error in ForceReplicationHandler.run: " +
324 363
                          e.getMessage());
325 364
      e.printStackTrace(System.out);
326 365
    }

Also available in: Unified diff