1 /*******************************************************************************
\r
2 * ============LICENSE_START==================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
25 package com.att.research.datarouter.provisioning;
\r
27 import java.io.ByteArrayOutputStream;
\r
28 import java.io.File;
\r
29 import java.io.FileInputStream;
\r
30 import java.io.InputStream;
\r
31 import java.net.InetAddress;
\r
32 import java.net.UnknownHostException;
\r
33 import java.nio.file.Files;
\r
34 import java.nio.file.Path;
\r
35 import java.nio.file.Paths;
\r
36 import java.nio.file.StandardCopyOption;
\r
37 import java.security.KeyStore;
\r
38 import java.sql.Connection;
\r
39 import java.sql.SQLException;
\r
40 import java.util.ArrayList;
\r
41 import java.util.Arrays;
\r
42 import java.util.Collection;
\r
43 import java.util.HashMap;
\r
44 import java.util.Map;
\r
45 import java.util.Properties;
\r
46 import java.util.Set;
\r
47 import java.util.Timer;
\r
48 import java.util.TimerTask;
\r
49 import java.util.TreeSet;
\r
51 import javax.servlet.http.HttpServletResponse;
\r
53 import org.apache.http.HttpEntity;
\r
54 import org.apache.http.HttpResponse;
\r
55 import org.apache.http.client.methods.HttpGet;
\r
56 import org.apache.http.client.methods.HttpPost;
\r
57 import org.apache.http.conn.scheme.Scheme;
\r
58 import org.apache.http.conn.ssl.SSLSocketFactory;
\r
59 import org.apache.http.entity.ByteArrayEntity;
\r
60 import org.apache.http.entity.ContentType;
\r
61 import org.apache.http.impl.client.AbstractHttpClient;
\r
62 import org.apache.http.impl.client.DefaultHttpClient;
\r
63 import org.apache.log4j.Logger;
\r
64 import org.json.JSONArray;
\r
65 import org.json.JSONException;
\r
66 import org.json.JSONObject;
\r
67 import org.json.JSONTokener;
\r
69 import com.att.research.datarouter.provisioning.beans.EgressRoute;
\r
70 import com.att.research.datarouter.provisioning.beans.Feed;
\r
71 import com.att.research.datarouter.provisioning.beans.IngressRoute;
\r
72 import com.att.research.datarouter.provisioning.beans.NetworkRoute;
\r
73 import com.att.research.datarouter.provisioning.beans.Parameters;
\r
74 import com.att.research.datarouter.provisioning.beans.Subscription;
\r
75 import com.att.research.datarouter.provisioning.beans.Syncable;
\r
76 import com.att.research.datarouter.provisioning.utils.DB;
\r
77 import com.att.research.datarouter.provisioning.utils.RLEBitSet;
\r
78 import com.att.research.datarouter.provisioning.utils.LogfileLoader;
\r
79 import com.att.research.datarouter.provisioning.utils.URLUtilities;
\r
80 import com.att.research.datarouter.provisioning.beans.Group; //Groups feature Rally:US708115 - 1610
\r
83 * This class handles synchronization between provisioning servers (PODs). It has three primary functions:
\r
85 * <li>Checking DNS once per minute to see which POD the DNS CNAME points to. The CNAME will point to
\r
86 * the active (master) POD.</li>
\r
87 * <li>On non-master (standby) PODs, fetches provisioning data and logs in order to keep MySQL in sync.</li>
\r
88 * <li>Providing information to other parts of the system as to the current role (ACTIVE, STANDBY, UNKNOWN)
\r
91 * <p>For this to work correctly, the following code needs to be placed at the beginning of main().</p>
\r
93 * Security.setProperty("networkaddress.cache.ttl", "10");
\r
96 * @author Robert Eby
\r
97 * @version $Id: SynchronizerTask.java,v 1.10 2014/03/21 13:50:10 eby Exp $
\r
99 public class SynchronizerTask extends TimerTask {
\r
100 /** This is a singleton -- there is only one SynchronizerTask object in the server */
\r
101 private static SynchronizerTask synctask;
\r
103 /** This POD is unknown -- not on the list of PODs */
\r
104 public static final int UNKNOWN = 0;
\r
105 /** This POD is active -- on the list of PODs, and the DNS CNAME points to us */
\r
106 public static final int ACTIVE = 1;
\r
107 /** This POD is standby -- on the list of PODs, and the DNS CNAME does not point to us */
\r
108 public static final int STANDBY = 2;
\r
109 private static final String[] stnames = { "UNKNOWN", "ACTIVE", "STANDBY" };
\r
110 private static final long ONE_HOUR = 60 * 60 * 1000L;
\r
112 private final Logger logger;
\r
113 private final Timer rolex;
\r
114 private final String spooldir;
\r
116 private boolean doFetch;
\r
117 private long nextsynctime;
\r
118 private AbstractHttpClient httpclient = null;
\r
121 * Get the singleton SynchronizerTask object.
\r
122 * @return the SynchronizerTask
\r
124 public static synchronized SynchronizerTask getSynchronizer() {
\r
125 if (synctask == null)
\r
126 synctask = new SynchronizerTask();
\r
130 @SuppressWarnings("deprecation")
\r
131 private SynchronizerTask() {
\r
132 logger = Logger.getLogger("com.att.research.datarouter.provisioning.internal");
\r
133 rolex = new Timer();
\r
134 spooldir = (new DB()).getProperties().getProperty("com.att.research.datarouter.provserver.spooldir");
\r
136 doFetch = true; // start off with a fetch
\r
139 logger.info("PROV5000: Sync task starting, server state is UNKNOWN");
\r
141 Properties props = (new DB()).getProperties();
\r
142 String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
\r
143 String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
\r
144 String pass = props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY);
\r
145 KeyStore keyStore = KeyStore.getInstance(type);
\r
146 FileInputStream instream = new FileInputStream(new File(store));
\r
147 keyStore.load(instream, pass.toCharArray());
\r
150 store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
\r
151 pass = props.getProperty(Main.TRUSTSTORE_PASSWORD_PROPERTY);
\r
152 KeyStore trustStore = null;
\r
153 if (store != null && store.length() > 0) {
\r
154 trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
\r
155 instream = new FileInputStream(new File(store));
\r
156 trustStore.load(instream, pass.toCharArray());
\r
160 // We are connecting with the node name, but the certificate will have the CNAME
\r
161 // So we need to accept a non-matching certificate name
\r
162 String keystorepass = props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY); //itrack.web.att.com/browse/DATARTR-6 for changing hard coded passphase ref
\r
163 AbstractHttpClient hc = new DefaultHttpClient();
\r
164 SSLSocketFactory socketFactory =
\r
165 (trustStore == null)
\r
166 ? new SSLSocketFactory(keyStore, keystorepass)
\r
167 : new SSLSocketFactory(keyStore, keystorepass, trustStore);
\r
168 socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
\r
169 Scheme sch = new Scheme("https", 443, socketFactory);
\r
170 hc.getConnectionManager().getSchemeRegistry().register(sch);
\r
173 // Run once every 5 seconds to check DNS, etc.
\r
176 String s = props.getProperty("com.att.research.datarouter.provserver.sync_interval", "5000");
\r
177 interval = Long.parseLong(s);
\r
178 } catch (NumberFormatException e) {
\r
181 rolex.scheduleAtFixedRate(this, 0L, interval);
\r
182 } catch (Exception e) {
\r
183 logger.warn("PROV5005: Problem starting the synchronizer: "+e);
\r
188 * What is the state of this POD?
\r
189 * @return one of ACTIVE, STANDBY, UNKNOWN
\r
191 public int getState() {
\r
196 * Is this the active POD?
\r
197 * @return true if we are active (the master), false otherwise
\r
199 public boolean isActive() {
\r
200 return state == ACTIVE;
\r
204 * This method is used to signal that another POD (the active POD) has sent us a /fetchProv request,
\r
205 * and that we should re-synchronize with the master.
\r
207 public void doFetch() {
\r
212 * Runs once a minute in order to <ol>
\r
213 * <li>lookup DNS names,</li>
\r
214 * <li>determine the state of this POD,</li>
\r
215 * <li>if this is a standby POD, and the fetch flag is set, perform a fetch of state from the active POD.</li>
\r
216 * <li>if this is a standby POD, check if there are any new log records to be replicated.</li>
\r
220 public void run() {
\r
222 state = lookupState();
\r
223 if (state == STANDBY) {
\r
224 // Only copy provisioning data FROM the active server TO the standby
\r
225 if (doFetch || (System.currentTimeMillis() >= nextsynctime)) {
\r
226 logger.debug("Initiating a sync...");
\r
227 JSONObject jo = readProvisioningJSON();
\r
230 syncFeeds( jo.getJSONArray("feeds"));
\r
231 syncSubs( jo.getJSONArray("subscriptions"));
\r
232 syncGroups( jo.getJSONArray("groups")); //Rally:US708115 - 1610
\r
233 syncParams(jo.getJSONObject("parameters"));
\r
234 // The following will not be present in a version=1.0 provfeed
\r
235 JSONArray ja = jo.optJSONArray("ingress");
\r
237 syncIngressRoutes(ja);
\r
238 JSONObject j2 = jo.optJSONObject("egress");
\r
240 syncEgressRoutes( j2);
\r
241 ja = jo.optJSONArray("routing");
\r
243 syncNetworkRoutes(ja);
\r
245 logger.info("PROV5013: Sync completed.");
\r
246 nextsynctime = System.currentTimeMillis() + ONE_HOUR;
\r
249 // Don't do fetches on non-standby PODs
\r
253 // Fetch DR logs as needed - server to server
\r
254 LogfileLoader lfl = LogfileLoader.getLoader();
\r
255 if (lfl.isIdle()) {
\r
256 // Only fetch new logs if the loader is waiting for them.
\r
257 logger.trace("Checking for logs to replicate...");
\r
258 RLEBitSet local = lfl.getBitSet();
\r
259 RLEBitSet remote = readRemoteLoglist();
\r
260 remote.andNot(local);
\r
261 if (!remote.isEmpty()) {
\r
262 logger.debug(" Replicating logs: "+remote);
\r
263 replicateDRLogs(remote);
\r
266 } catch (Exception e) {
\r
267 logger.warn("PROV0020: Caught exception in SynchronizerTask: "+e);
\r
268 e.printStackTrace();
\r
273 * This method is used to lookup the CNAME that points to the active server.
\r
274 * It returns 0 (UNKNOWN), 1(ACTIVE), or 2 (STANDBY) to indicate the state of this server.
\r
275 * @return the current state
\r
277 private int lookupState() {
\r
278 int newstate = UNKNOWN;
\r
280 InetAddress myaddr = InetAddress.getLocalHost();
\r
281 if (logger.isTraceEnabled())
\r
282 logger.trace("My address: "+myaddr);
\r
283 String this_pod = myaddr.getHostName();
\r
284 Set<String> pods = new TreeSet<String>(Arrays.asList(BaseServlet.getPods()));
\r
285 if (pods.contains(this_pod)) {
\r
286 InetAddress pserver = InetAddress.getByName(BaseServlet.active_prov_name);
\r
287 newstate = myaddr.equals(pserver) ? ACTIVE : STANDBY;
\r
288 if (logger.isDebugEnabled() && System.currentTimeMillis() >= next_msg) {
\r
289 logger.debug("Active POD = "+pserver+", Current state is "+stnames[newstate]);
\r
290 next_msg = System.currentTimeMillis() + (5 * 60 * 1000L);
\r
293 logger.warn("PROV5003: My name ("+this_pod+") is missing from the list of provisioning servers.");
\r
295 } catch (UnknownHostException e) {
\r
296 logger.warn("PROV5002: Cannot determine the name of this provisioning server.");
\r
299 if (newstate != state)
\r
300 logger.info(String.format("PROV5001: Server state changed from %s to %s", stnames[state], stnames[newstate]));
\r
303 private static long next_msg = 0; // only display the "Current state" msg every 5 mins.
\r
304 /** Synchronize the Feeds in the JSONArray, with the Feeds in the DB. */
\r
305 private void syncFeeds(JSONArray ja) {
\r
306 Collection<Syncable> coll = new ArrayList<Syncable>();
\r
307 for (int n = 0; n < ja.length(); n++) {
\r
309 Feed f = new Feed(ja.getJSONObject(n));
\r
311 } catch (Exception e) {
\r
312 logger.warn("PROV5004: Invalid object in feed: "+ja.optJSONObject(n));
\r
315 if (sync(coll, Feed.getAllFeeds()))
\r
316 BaseServlet.provisioningDataChanged();
\r
318 /** Synchronize the Subscriptions in the JSONArray, with the Subscriptions in the DB. */
\r
319 private void syncSubs(JSONArray ja) {
\r
320 Collection<Syncable> coll = new ArrayList<Syncable>();
\r
321 for (int n = 0; n < ja.length(); n++) {
\r
323 //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
\r
324 JSONObject j = ja.getJSONObject(n);
\r
325 j.put("sync", "true");
\r
326 Subscription s = new Subscription(j);
\r
328 } catch (Exception e) {
\r
329 logger.warn("PROV5004: Invalid object in subscription: "+ja.optJSONObject(n));
\r
332 if (sync(coll, Subscription.getAllSubscriptions()))
\r
333 BaseServlet.provisioningDataChanged();
\r
336 /** Rally:US708115 - Synchronize the Groups in the JSONArray, with the Groups in the DB. */
\r
337 private void syncGroups(JSONArray ja) {
\r
338 Collection<Syncable> coll = new ArrayList<Syncable>();
\r
339 for (int n = 0; n < ja.length(); n++) {
\r
341 Group g = new Group(ja.getJSONObject(n));
\r
343 } catch (Exception e) {
\r
344 logger.warn("PROV5004: Invalid object in subscription: "+ja.optJSONObject(n));
\r
347 if (sync(coll, Group.getAllgroups()))
\r
348 BaseServlet.provisioningDataChanged();
\r
352 /** Synchronize the Parameters in the JSONObject, with the Parameters in the DB. */
\r
353 private void syncParams(JSONObject jo) {
\r
354 Collection<Syncable> coll = new ArrayList<Syncable>();
\r
355 for (String k : jo.keySet()) {
\r
358 v = jo.getString(k);
\r
359 } catch (JSONException e) {
\r
361 v = ""+jo.getInt(k);
\r
362 } catch (JSONException e1) {
\r
363 JSONArray ja = jo.getJSONArray(k);
\r
364 for (int i = 0; i < ja.length(); i++) {
\r
367 v += ja.getString(i);
\r
371 coll.add(new Parameters(k, v));
\r
373 if (sync(coll, Parameters.getParameterCollection())) {
\r
374 BaseServlet.provisioningDataChanged();
\r
375 BaseServlet.provisioningParametersChanged();
\r
378 private void syncIngressRoutes(JSONArray ja) {
\r
379 Collection<Syncable> coll = new ArrayList<Syncable>();
\r
380 for (int n = 0; n < ja.length(); n++) {
\r
382 IngressRoute in = new IngressRoute(ja.getJSONObject(n));
\r
384 } catch (NumberFormatException e) {
\r
385 logger.warn("PROV5004: Invalid object in ingress routes: "+ja.optJSONObject(n));
\r
388 if (sync(coll, IngressRoute.getAllIngressRoutes()))
\r
389 BaseServlet.provisioningDataChanged();
\r
391 private void syncEgressRoutes(JSONObject jo) {
\r
392 Collection<Syncable> coll = new ArrayList<Syncable>();
\r
393 for (String key : jo.keySet()) {
\r
395 int sub = Integer.parseInt(key);
\r
396 String node = jo.getString(key);
\r
397 EgressRoute er = new EgressRoute(sub, node);
\r
399 } catch (NumberFormatException e) {
\r
400 logger.warn("PROV5004: Invalid subid in egress routes: "+key);
\r
401 } catch (IllegalArgumentException e) {
\r
402 logger.warn("PROV5004: Invalid node name in egress routes: "+key);
\r
405 if (sync(coll, EgressRoute.getAllEgressRoutes()))
\r
406 BaseServlet.provisioningDataChanged();
\r
408 private void syncNetworkRoutes(JSONArray ja) {
\r
409 Collection<Syncable> coll = new ArrayList<Syncable>();
\r
410 for (int n = 0; n < ja.length(); n++) {
\r
412 NetworkRoute nr = new NetworkRoute(ja.getJSONObject(n));
\r
414 } catch (JSONException e) {
\r
415 logger.warn("PROV5004: Invalid object in network routes: "+ja.optJSONObject(n));
\r
418 if (sync(coll, NetworkRoute.getAllNetworkRoutes()))
\r
419 BaseServlet.provisioningDataChanged();
\r
421 private boolean sync(Collection<? extends Syncable> newc, Collection<? extends Syncable> oldc) {
\r
422 boolean changes = false;
\r
424 Map<String, Syncable> newmap = getMap(newc);
\r
425 Map<String, Syncable> oldmap = getMap(oldc);
\r
426 Set<String> union = new TreeSet<String>(newmap.keySet());
\r
427 union.addAll(oldmap.keySet());
\r
429 @SuppressWarnings("resource")
\r
430 Connection conn = db.getConnection();
\r
431 for (String n : union) {
\r
432 Syncable newobj = newmap.get(n);
\r
433 Syncable oldobj = oldmap.get(n);
\r
434 if (oldobj == null) {
\r
435 if (logger.isDebugEnabled())
\r
436 logger.debug(" Inserting record: "+newobj);
\r
437 newobj.doInsert(conn);
\r
439 } else if (newobj == null) {
\r
440 if (logger.isDebugEnabled())
\r
441 logger.debug(" Deleting record: "+oldobj);
\r
442 oldobj.doDelete(conn);
\r
444 } else if (!newobj.equals(oldobj)) {
\r
445 if (logger.isDebugEnabled())
\r
446 logger.debug(" Updating record: "+newobj);
\r
447 newobj.doUpdate(conn);
\r
450 * Change Ownership of FEED - 1610, Syncronised with secondary DB.
\r
452 checkChnageOwner(newobj, oldobj);
\r
458 } catch (SQLException e) {
\r
459 logger.warn("PROV5009: problem during sync, exception: "+e);
\r
460 e.printStackTrace();
\r
464 private Map<String, Syncable> getMap(Collection<? extends Syncable> c) {
\r
465 Map<String, Syncable> map = new HashMap<String, Syncable>();
\r
466 for (Syncable v : c) {
\r
467 map.put(v.getKey(), v);
\r
473 /**Change owner of FEED/SUBSCRIPTION*/
\r
475 * Change Ownership of FEED - 1610
\r
478 private void checkChnageOwner(Syncable newobj, Syncable oldobj) {
\r
479 if(newobj instanceof Feed) {
\r
480 Feed oldfeed = (Feed) oldobj;
\r
481 Feed newfeed = (Feed) newobj;
\r
483 if(!oldfeed.getPublisher().equals(newfeed.getPublisher())){
\r
484 logger.info("PROV5013 - Previous publisher: "+oldfeed.getPublisher() +": New publisher-"+newfeed.getPublisher());
\r
485 oldfeed.setPublisher(newfeed.getPublisher());
\r
486 oldfeed.changeOwnerShip();
\r
489 else if(newobj instanceof Subscription) {
\r
490 Subscription oldsub = (Subscription) oldobj;
\r
491 Subscription newsub = (Subscription) newobj;
\r
493 if(!oldsub.getSubscriber().equals(newsub.getSubscriber())){
\r
494 logger.info("PROV5013 - Previous subscriber: "+oldsub.getSubscriber() +": New subscriber-"+newsub.getSubscriber());
\r
495 oldsub.setSubscriber(newsub.getSubscriber());
\r
496 oldsub.changeOwnerShip();
\r
503 * Issue a GET on the peer POD's /internal/prov/ URL to get a copy of its provisioning data.
\r
504 * @return the provisioning data (as a JONObject)
\r
506 private synchronized JSONObject readProvisioningJSON() {
\r
507 String url = URLUtilities.generatePeerProvURL();
\r
508 HttpGet get = new HttpGet(url);
\r
510 HttpResponse response = httpclient.execute(get);
\r
511 int code = response.getStatusLine().getStatusCode();
\r
512 if (code != HttpServletResponse.SC_OK) {
\r
513 logger.warn("PROV5010: readProvisioningJSON failed, bad error code: "+code);
\r
516 HttpEntity entity = response.getEntity();
\r
517 String ctype = entity.getContentType().getValue().trim();
\r
518 if (!ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE1) && !ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE2)) {
\r
519 logger.warn("PROV5011: readProvisioningJSON failed, bad content type: "+ctype);
\r
522 return new JSONObject(new JSONTokener(entity.getContent()));
\r
523 } catch (Exception e) {
\r
524 logger.warn("PROV5012: readProvisioningJSON failed, exception: "+e);
\r
527 get.releaseConnection();
\r
531 * Issue a GET on the peer POD's /internal/drlogs/ URL to get an RELBitSet representing the
\r
532 * log records available in the remote database.
\r
533 * @return the bitset
\r
535 private RLEBitSet readRemoteLoglist() {
\r
536 RLEBitSet bs = new RLEBitSet();
\r
537 String url = URLUtilities.generatePeerLogsURL();
\r
539 //Fixing if only one Prov is configured, not to give exception to fill logs, return empty bitset.
\r
540 if(url.equals("")) {
\r
545 HttpGet get = new HttpGet(url);
\r
547 HttpResponse response = httpclient.execute(get);
\r
548 int code = response.getStatusLine().getStatusCode();
\r
549 if (code != HttpServletResponse.SC_OK) {
\r
550 logger.warn("PROV5010: readRemoteLoglist failed, bad error code: "+code);
\r
553 HttpEntity entity = response.getEntity();
\r
554 String ctype = entity.getContentType().getValue().trim();
\r
555 if (!ctype.equals("text/plain")) {
\r
556 logger.warn("PROV5011: readRemoteLoglist failed, bad content type: "+ctype);
\r
559 InputStream is = entity.getContent();
\r
560 ByteArrayOutputStream bos = new ByteArrayOutputStream();
\r
562 while ((ch = is.read()) >= 0)
\r
564 bs.set(bos.toString());
\r
566 } catch (Exception e) {
\r
567 logger.warn("PROV5012: readRemoteLoglist failed, exception: "+e);
\r
570 get.releaseConnection();
\r
575 * Issue a POST on the peer POD's /internal/drlogs/ URL to fetch log records available
\r
576 * in the remote database that we wish to copy to the local database.
\r
577 * @param bs the bitset (an RELBitSet) of log records to fetch
\r
579 private void replicateDRLogs(RLEBitSet bs) {
\r
580 String url = URLUtilities.generatePeerLogsURL();
\r
581 HttpPost post = new HttpPost(url);
\r
583 String t = bs.toString();
\r
584 HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create("text/plain"));
\r
585 post.setEntity(body);
\r
586 if (logger.isDebugEnabled())
\r
587 logger.debug("Requesting records: "+t);
\r
589 HttpResponse response = httpclient.execute(post);
\r
590 int code = response.getStatusLine().getStatusCode();
\r
591 if (code != HttpServletResponse.SC_OK) {
\r
592 logger.warn("PROV5010: replicateDRLogs failed, bad error code: "+code);
\r
595 HttpEntity entity = response.getEntity();
\r
596 String ctype = entity.getContentType().getValue().trim();
\r
597 if (!ctype.equals("text/plain")) {
\r
598 logger.warn("PROV5011: replicateDRLogs failed, bad content type: "+ctype);
\r
602 String spoolname = "" + System.currentTimeMillis();
\r
603 Path tmppath = Paths.get(spooldir, spoolname);
\r
604 Path donepath = Paths.get(spooldir, "IN."+spoolname);
\r
605 Files.copy(entity.getContent(), Paths.get(spooldir, spoolname), StandardCopyOption.REPLACE_EXISTING);
\r
606 Files.move(tmppath, donepath, StandardCopyOption.REPLACE_EXISTING);
\r
607 logger.info("Approximately "+bs.cardinality()+" records replicated.");
\r
608 } catch (Exception e) {
\r
609 logger.warn("PROV5012: replicateDRLogs failed, exception: "+e);
\r
611 post.releaseConnection();
\r