From 9545cc70a4e86943ada2013027e91382eba3dfb6 Mon Sep 17 00:00:00 2001 From: Thomas Nelson Date: Wed, 17 Oct 2018 01:54:37 -0400 Subject: Update pom and other files to fix bug in MUSIC Change-Id: Ic6086b40a2dd41b15b028cd0ddb7c62df7175682 Issue-ID: MUSIC-147 Signed-off-by: Thomas Nelson --- musictrigger/assembly.xml | 2 +- musictrigger/src/MusicTrigger.java | 93 +++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 53 deletions(-) (limited to 'musictrigger') diff --git a/musictrigger/assembly.xml b/musictrigger/assembly.xml index 90178d8f..34451eef 100644 --- a/musictrigger/assembly.xml +++ b/musictrigger/assembly.xml @@ -19,4 +19,4 @@ . - + \ No newline at end of file diff --git a/musictrigger/src/MusicTrigger.java b/musictrigger/src/MusicTrigger.java index b5894da1..eb79cb8c 100755 --- a/musictrigger/src/MusicTrigger.java +++ b/musictrigger/src/MusicTrigger.java @@ -51,15 +51,23 @@ import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; + public class MusicTrigger implements ITrigger { private static final Logger logger = LoggerFactory.getLogger(MusicTrigger.class); - public Collection augment(Partition partition) { + new Thread(new Runnable() { + public void run() { + makeAsyncCall(partition); + } + }).start(); + return Collections.emptyList(); + } + + private void makeAsyncCall(Partition partition) { boolean isDelete = false; - logger.info("Step 1: "+partition.partitionLevelDeletion().isLive()); if(partition.partitionLevelDeletion().isLive()) { } else { @@ -69,6 +77,7 @@ public class MusicTrigger implements ITrigger { logger.info("MusicTrigger isDelete: " + isDelete); String ksName = partition.metadata().ksName; String tableName = partition.metadata().cfName; + String pkValue = partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()); logger.info("MusicTrigger Table: " + tableName); boolean isInsert = checkQueryType(partition); org.json.simple.JSONObject obj = new org.json.simple.JSONObject(); @@ -121,7 +130,7 @@ public class MusicTrigger implements ITrigger { } } } catch (Exception e) { - + logger.info("Exception while constructing.. "+e.getMessage()); } obj.put("updateList", updateList); } else { @@ -132,11 +141,12 @@ public class MusicTrigger implements ITrigger { logger.info("Sending response: "+obj.toString()); try { notifyMusic(obj.toString()); + logger.info("MUSIC was notified.. "+obj.toString()); } catch(Exception e) { - e.printStackTrace(); logger.error("Notification failed..."+e.getMessage()); + logger.info("Notification failed..."+e.getMessage()); } - return Collections.emptyList(); + } private int fromByteArray(byte[] bytes) { @@ -160,62 +170,41 @@ public class MusicTrigger implements ITrigger { } private void notifyMusic(String request) { - System.out.println("notifyMusic..."); + logger.info("notifyMusic..."); Client client = Client.create(); WebResource webResource = client.resource("http://localhost:8080/MUSIC/rest/v2/admin/callbackOps"); JSONObject data = new JSONObject(); data.setData(request); - - ClientResponse response = webResource.accept("application/json").type("application/json") + ClientResponse response = null; + try { + response = webResource.accept("application/json").type("application/json") .post(ClientResponse.class, data); + } catch (Exception e) { + logger.info("Exception while notifying MUSIC. Retrying.."); + try { + response = webResource.accept("application/json").type("application/json") + .post(ClientResponse.class, data); + } catch (Exception e1) { + logger.info("Exception while notifying MUSIC. Stopping retry attempts.."); + } + } if(response.getStatus() != 200){ - System.out.println("Exception while notifying MUSIC..."); + logger.info("Exception while notifying MUSIC..."); + try { + response = webResource.accept("application/json").type("application/json") + .post(ClientResponse.class, data); + } catch (Exception e) { + logger.info("Exception while notifying MUSIC. Retrying.."); + try { + response = webResource.accept("application/json").type("application/json") + .post(ClientResponse.class, data); + } catch (Exception e1) { + logger.info("Exception while notifying MUSIC. Stopping retry attempts.."); + } + } } - /*response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON)); - response.bufferEntity(); - String x = response.getEntity(String.class); - System.out.println("Response: "+x);*/ - } - /*public Collection augment(Partition partition) { - - String tableName = partition.metadata().cfName; - System.out.println("Table: " + tableName); - - JSONObject obj = new JSONObject(); - obj.put("message_id", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey())); - - - try { - UnfilteredRowIterator it = partition.unfilteredIterator(); - while (it.hasNext()) { - Unfiltered un = it.next(); - Clustering clt = (Clustering) un.clustering(); - Iterator cls = partition.getRow(clt).cells().iterator(); - Iterator columns = partition.getRow(clt).columns().iterator(); - - while(cls.hasNext()){ - Cell cell = cls.next(); - String data = new String(cell.value().array()); // If cell type is text - System.out.println(cell + " : " +data); - - } - while(columns.hasNext()){ - ColumnDefinition columnDef = columns.next(); - Cell cell = cls.next(); - String data = new String(cell.value().array()); // If cell type is text - obj.put(columnDef.toString(), data); - } - } - } catch (Exception e) { - } - - System.out.println(obj.toString()); - - return Collections.emptyList(); - }*/ - } \ No newline at end of file -- cgit 1.2.3-korg