Merge "Update distribution files to support helm charts"
[music.git] / src / main / java / org / onap / music / rest / RestMusicAdminAPI.java
index e930e48..0e36565 100755 (executable)
 package org.onap.music.rest;
 
 
-import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
 
@@ -48,6 +52,7 @@ import org.onap.music.datastore.jsonobjects.JSONCallbackResponse;
 import org.onap.music.datastore.jsonobjects.JSONObject;
 import org.onap.music.datastore.jsonobjects.JsonCallback;
 import org.onap.music.datastore.jsonobjects.JsonNotification;
+import org.onap.music.datastore.jsonobjects.JsonNotifyClientResponse;
 import org.onap.music.datastore.jsonobjects.JsonOnboard;
 import org.onap.music.eelf.logging.EELFLoggerDelegate;
 import org.onap.music.eelf.logging.format.AppMessages;
@@ -79,8 +84,8 @@ import javax.ws.rs.core.MediaType;
 import com.datastax.driver.core.ColumnDefinitions;
 import com.datastax.driver.core.ColumnDefinitions.Definition;
 import com.datastax.driver.core.TableMetadata;
-import java.util.Base64.Encoder; 
-import java.util.Base64.Decoder;
+//import java.util.Base64.Encoder; 
+//import java.util.Base64.Decoder;
 
 @Path("/v2/admin")
 // @Path("/v{version: [0-9]+}/admin")
@@ -135,7 +140,7 @@ public class RestMusicAdminAPI {
                         MusicUtil.DEFAULTKEYSPACENAME));
         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
-        pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
+        pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
 
@@ -396,7 +401,8 @@ public class RestMusicAdminAPI {
     }
 
     Client client = Client.create();
-    
+       ObjectMapper mapper = new ObjectMapper();
+       
     @POST
     @Path("/callbackOps")
     @Produces(MediaType.APPLICATION_JSON)
@@ -417,25 +423,95 @@ public class RestMusicAdminAPI {
        
        Map<String, Object> resultMap = new HashMap<>();
        try {
-                       logger.info("Got notification: " + inputJsonObj.getData());
+               logger.info(EELFLoggerDelegate.applicationLogger, "Got notification: " + inputJsonObj.getData());
                        String dataStr = inputJsonObj.getData();
-                       ObjectMapper mapper = new ObjectMapper();
                        JSONCallbackResponse jsonResponse = mapper.readValue(dataStr, JSONCallbackResponse.class);
                        String operation = jsonResponse.getOperation();
                        Map<String, String> changeValueMap = jsonResponse.getChangeValue();
                        String primaryKey = jsonResponse.getPrimary_key();
-                       //String full_table = jsonResponse.getFull_table(); //conductor.plans
-                       String field_value = changeValueMap.get("field_value");
+                       String ksTableName = jsonResponse.getFull_table(); //conductor.plans
+                       if(ksTableName.equals("admin.notification_master")) {
+                               CachingUtil.updateCallbackNotifyList(new ArrayList<String>());
+                               return Response.status(Status.OK).entity(resultMap).build();
+                       }
+                       List<String> inputUpdateList = jsonResponse.getUpdateList();
+                       /*String field_value = changeValueMap.get("field_value");
                        if(field_value == null)
-                               field_value = jsonResponse.getFull_table();
-                       //Get from Cache
-                       JsonCallback baseRequestObj = CachingUtil.getCallBackCache(field_value);
-                       //baseRequestObj = null;
-                       
-                       if(baseRequestObj == null) {
+                               field_value = jsonResponse.getFull_table();*/
+                       String field_value = null;
+                       List<String> notifiyList = CachingUtil.getCallbackNotifyList();
+                       if(notifiyList == null || notifiyList.isEmpty()) {
                                logger.info("Is cache empty? reconstructing Object from cache..");
-                               baseRequestObj = constructJsonCallbackFromCache(field_value);
+                               constructJsonCallbackFromCache();
+                               /*notifiyList = CachingUtil.getCallbackNotifyList();
+                               if("update".equals(operation)) {
+                                       List<String> updateList = jsonResponse.getUpdateList();
+                                       //logger.info("update list from trigger: "+updateList);
+                                       for(String element : updateList) {
+                                               logger.info("element: "+element);
+                                               logger.info("notifiyList: "+notifiyList);
+                                               if(notifiyList.contains(element)) {
+                                                       logger.info("Found the notifyOn property: "+element);
+                                                       field_value = element;
+                                               }
+                                       }
+                               }
+                               
+                               baseRequestObj = CachingUtil.getCallBackCache(field_value);
+                               logger.info("Reconstructing Object from cache is Successful.."+baseRequestObj);*/
                        }
+                       notifiyList = CachingUtil.getCallbackNotifyList();
+                       JsonCallback baseRequestObj = null;
+                       
+                       if("update".equals(operation)) {
+                               for(String element: inputUpdateList) {
+                                       baseRequestObj = CachingUtil.getCallBackCache(element);
+                                       if(baseRequestObj != null) {
+                                               logger.info("Found the element that was changed... "+element);
+                                               break;
+                                       }
+                               }
+                               
+                               List<String> updateList = jsonResponse.getUpdateList();
+                               //logger.info("update list from trigger: "+updateList);
+                               for(String element : updateList) {
+                                       if(notifiyList.contains(element)) {
+                                               logger.info("Found the notifyOn property: "+element);
+                                               field_value = element;
+                                               break;
+                                       }
+                               }
+                               if(baseRequestObj == null || field_value == null) {
+                                       for(String element: inputUpdateList) {
+                                               String[] elementArr = element.split(":");
+                                               String newElement = null;
+                                               if(elementArr.length >= 2) {
+                                                       newElement = elementArr[0]+":"+elementArr[1];
+                                       } 
+                                               baseRequestObj = CachingUtil.getCallBackCache(newElement);
+                                               if(baseRequestObj != null) {
+                                                       logger.info("Found the element that was changed... "+newElement);
+                                                       break;
+                                               }
+                                       }
+                                       for(String element : updateList) {
+                                               String[] elementArr = element.split(":");
+                                               String newElement = null;
+                                               if(elementArr.length >= 2) {
+                                                       newElement = elementArr[0]+":"+elementArr[1];
+                                       } 
+                                               if(notifiyList.contains(newElement)) {
+                                                       logger.info("Found the notifyOn property: "+newElement);
+                                                       field_value = newElement;
+                                                       break;
+                                               }
+                                       }
+                               }
+                       } else {
+                               field_value = jsonResponse.getFull_table();
+                               baseRequestObj = CachingUtil.getCallBackCache(field_value);
+                       }
+                       
                        if(baseRequestObj == null) {
                                resultMap.put("Exception",
                            "Oops. Something went wrong. Please make sure Callback properties are onboarded.");
@@ -443,37 +519,36 @@ public class RestMusicAdminAPI {
                            ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
                                return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
                        }
+                       logger.info("Going through list: "+operation+ " && List: "+jsonResponse.getUpdateList());
                        
                        String key = "admin" + "." + "notification_master" + "." + baseRequestObj.getUuid();
                String lockId = MusicCore.createLockReference(key);
-               long lockCreationTime = System.currentTimeMillis();
                ReturnType lockAcqResult = MusicCore.acquireLock(key, lockId);
                if(! lockAcqResult.getResult().toString().equals("SUCCESS")) {
-                       logger.info("Some other node is notifying the caller..");
+                       logger.error(EELFLoggerDelegate.errorLogger, "Some other node is notifying the caller..: ");
                }
                        
                        logger.info(operation+ ": Operation :: changeValue: "+changeValueMap);
                        if(operation.equals("update")) {
                                String notifyWhenChangeIn = baseRequestObj.getNotifyWhenChangeIn(); // conductor.plans.status
-                               logger.info("**********notifyWhenChangeIn: "+notifyWhenChangeIn);
-                               if(field_value.equals(notifyWhenChangeIn)) {
-                                       logger.info("********** notifyting the endpoint: "+baseRequestObj.getApplicationNotificationEndpoint());
-                                       notifyCallBackAppl(jsonResponse, baseRequestObj);
+                               if(null!=field_value) {
+                                       if(field_value.equals(notifyWhenChangeIn)) {
+                                               notifyCallBackAppl(jsonResponse, baseRequestObj);
+                                       }
                                }
-                               
                        } else if(operation.equals("delete")) {
                                String notifyWhenDeletesIn = baseRequestObj.getNotifyWhenDeletesIn(); // conductor.plans.status
-                               logger.info("**********notifyWhenDeletesIn: "+notifyWhenDeletesIn);
-                               if(field_value.equals(notifyWhenDeletesIn)) {
-                                       logger.info("********** notifyting the endpoint: "+baseRequestObj.getApplicationNotificationEndpoint());
-                                       notifyCallBackAppl(jsonResponse, baseRequestObj);
+                               if(null!=field_value) {
+                                       if(field_value.equals(notifyWhenDeletesIn)) {
+                                               notifyCallBackAppl(jsonResponse, baseRequestObj);
+                                       }
                                }
                        } else if(operation.equals("insert")) {
                                String notifyWhenInsertsIn = baseRequestObj.getNotifyWhenInsertsIn(); // conductor.plans.status
-                               logger.info("**********notifyWhenInsertsIn: "+notifyWhenInsertsIn);
-                               if(field_value.equals(notifyWhenInsertsIn)) {
-                                       logger.info("********** notifyting the endpoint: "+baseRequestObj.getApplicationNotificationEndpoint());
-                                       notifyCallBackAppl(jsonResponse, baseRequestObj);
+                               if(null!=field_value) {
+                                       if(field_value.equals(notifyWhenInsertsIn)) {
+                                               notifyCallBackAppl(jsonResponse, baseRequestObj);
+                                       }
                                }
                        }
                        MusicCore.releaseLock(lockId, true);    
@@ -481,7 +556,7 @@ public class RestMusicAdminAPI {
             e.printStackTrace();
             logger.info("Exception...");
         }
-       logger.info(">>> callback is completed. Notification was sent from Music...");
+       logger.info(EELFLoggerDelegate.applicationLogger, "callback is completed. Notification was sent from Music...");
        return Response.status(Status.OK).entity(resultMap).build();
     }
     
@@ -493,7 +568,7 @@ public class RestMusicAdminAPI {
         String password = baseRequestObj.getApplicationPassword();
         JsonNotification jsonNotification = constructJsonNotification(jsonResponse, baseRequestObj);
         jsonNotification.setOperation_type(jsonResponse.getOperation());
-        logger.info("Response sent is: "+jsonNotification);
+        logger.info(EELFLoggerDelegate.applicationLogger, "Notification Response sent is: "+jsonNotification);
         WebResource webResource = client.resource(endpoint);
         String authData = username+":"+password;
         byte[] plainCredsBytes = authData.getBytes();
@@ -506,37 +581,39 @@ public class RestMusicAdminAPI {
             .post(ClientResponse.class, jsonNotification);
         } catch (com.sun.jersey.api.client.ClientHandlerException chf) {
                boolean ok = false;
-               logger.info("Is Service down?");
+               logger.info(EELFLoggerDelegate.applicationLogger, "Is Service down?");
                long now= System.currentTimeMillis();
                long end = now+notifytimeout;
                while(! ok) {
-                       logger.info("retrying since error in notifying callback..");
+                       logger.info(EELFLoggerDelegate.applicationLogger, "retrying since error in notifying callback..");
                        try {
                                response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json")
                            .post(ClientResponse.class, jsonNotification);
                                if(response.getStatus() == 200) ok = true;
                        }catch (Exception e) {
-                               System.err.println("Is response null: "+response==null);
-                               System.err.println("Retry until "+(end-System.currentTimeMillis()));
+                               logger.info(EELFLoggerDelegate.applicationLogger, "Retry until "+(end-System.currentTimeMillis()));
                                if(response == null && System.currentTimeMillis() < end) ok = false;
                                else ok = true;
                                try{ Thread.sleep(notifyinterval); } catch(Exception e1) {}
                        }
                }
         }
-        response.bufferEntity();
-        String responseStr = response.getEntity(String.class);
-        logger.info(">>>>> Response from Notified client: "+responseStr);
+        if(response == null) {
+               logger.error(EELFLoggerDelegate.errorLogger, "Can NOT notify the caller as caller failed to respond..");
+               return;
+        }
+        JsonNotifyClientResponse responseStr = response.getEntity(JsonNotifyClientResponse.class);
+        logger.info(EELFLoggerDelegate.applicationLogger, "Response from Notified client: "+responseStr);
         
         if(response.getStatus() != 200){
                long now= System.currentTimeMillis();
                long end = now+30000;
                while(response.getStatus() != 200 && System.currentTimeMillis() < end) {
-                       logger.info("retrying since error in notifying callback..");
+                       logger.info(EELFLoggerDelegate.applicationLogger, "retrying since error in notifying callback..");
                        response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json")
                            .post(ClientResponse.class, jsonNotification);
                }
-            logger.error("Exception while notifying.. "+response.getStatus());
+               logger.info(EELFLoggerDelegate.applicationLogger, "Exception while notifying.. "+response.getStatus());
         }
     }
     
@@ -556,80 +633,99 @@ public class RestMusicAdminAPI {
                TableMetadata tableInfo = MusicCore.returnColumnMetadata(tableArr[0], tableArr[1]);
                        DataType primaryIdType = tableInfo.getPrimaryKey().get(0).getType();
                        String primaryId = tableInfo.getPrimaryKey().get(0).getName();
-                       logger.info(">>>>>>> Primary Id: "+primaryId);
                        
                        Map<String, String> responseBodyMap = baseRequestObj.getResponseBody();
-               Set<String> keySet = responseBodyMap.keySet();
-               /*for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
-                               DataType colType = null;
-                   try {
-                       colType = tableInfo.getColumn(entry.getKey()).getType();
-                   } catch(NullPointerException ex) {
-                       
-                   }
-               }*/
-                       
-               
-               String cql = "select ";
-               for(String keys: keySet) {
-                       cql = cql + keys + ",";
-               }
-               cql = cql.substring(0, cql.length()-1);
-               cql = cql + " FROM "+fullNotifyArr[0]+" WHERE "+primaryId+" = ?";
-               logger.info("CQL in constructJsonNotification: "+cql);
-               PreparedQueryObject pQuery = new PreparedQueryObject();
-               pQuery.appendQueryString(cql);
-               pQuery.addValue(MusicUtil.convertToActualDataType(primaryIdType, pkValue));
-               Row row = MusicCore.get(pQuery).one();
-               Map<String, String> newMap = new HashMap<>();
-               if(row != null) {
-                       for(String keys: keySet) {
-                               String value = null;
-                               logger.info("responseBodyMap: "+responseBodyMap.toString());
-                               logger.info(">>>>>>>> converting <<<<<<<<<<<< "+keys + " : "+responseBodyMap.get(keys)+ ":" +responseBodyMap.get(keys).equals("uuid"));
-                               if(responseBodyMap.get(keys).equals("uuid"))
-                                       value = row.getUUID(keys).toString();
-                               else if (responseBodyMap.get(keys).equals("text"))
-                                       value = row.getString(keys);
-                               /*else if (responseBodyMap.get(keys).contains("int"))
-                                       value = row.getLong(keys).toString();*/
-                               newMap.put(keys, value);
-                       }
-               }
-               if("delete".equals(jsonResponse.getOperation())) {
-                       newMap.put(primaryId, pkValue);
-               }
-               jsonNotification.setResponse_body(newMap);
-       } catch(Exception e) {
-               e.printStackTrace();
-       }
-       return jsonNotification;
+                       Map<String, String> newMap = new HashMap<>();
+                       if(responseBodyMap.size() == 1 && responseBodyMap.containsKey("")) {
+                               jsonNotification.setResponse_body(newMap);
+                       } else {
+                               for (Entry<String, String> entry : new HashSet<>(responseBodyMap.entrySet())) {
+                                   String trimmed = entry.getKey().trim();
+                                   if (!trimmed.equals(entry.getKey())) {
+                                       responseBodyMap.remove(entry.getKey());
+                                       responseBodyMap.put(trimmed, entry.getValue());
+                                   }
+                               }
+                               
+                               Set<String> keySet = responseBodyMap.keySet();
+                               String cql = "select *";
+                               /*for(String keys: keySet) {
+                                       cql = cql + keys + ",";
+                               }*/
+                               //cql = cql.substring(0, cql.length()-1);
+                               cql = cql + " FROM "+fullNotifyArr[0]+" WHERE "+primaryId+" = ?";
+                               logger.info("CQL in constructJsonNotification: "+cql);
+                               PreparedQueryObject pQuery = new PreparedQueryObject();
+                               pQuery.appendQueryString(cql);
+                               pQuery.addValue(MusicUtil.convertToActualDataType(primaryIdType, pkValue));
+                               Row row = MusicCore.get(pQuery).one();
+                               if(row != null) {
+                                       ColumnDefinitions colInfo = row.getColumnDefinitions();
+                               for (Definition definition : colInfo) {
+                                   String colName = definition.getName();
+                                   if(keySet.contains(colName)) {
+                                       DataType colType = definition.getType();
+                                       Object valueObj = MusicCore.getDSHandle().getColValue(row, colName, colType);
+                                       Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
+                                       logger.info(colName+" : "+valueString);
+                                       newMap.put(colName, valueString.toString());
+                                       keySet.remove(colName);
+                                   }
+                               }
+                               }
+                               if(! keySet.isEmpty()) {
+                                       Iterator<String> iterator = keySet.iterator();
+                                       while (iterator.hasNext()) {
+                                           String element = iterator.next();
+                                           if(element != null && element.length() > 0)
+                                               newMap.put(element,"COLUMN_NOT_FOUND");
+                                       }
+                               }
+                           
+                               if("delete".equals(jsonResponse.getOperation()) || newMap.isEmpty()) {
+                                       newMap.put(primaryId, pkValue);
+                               }
+                               jsonNotification.setResponse_body(newMap);
+                       }
+                       } catch(Exception e) {
+                       e.printStackTrace();
+                       }
+                       return jsonNotification;
     }
     
-    private JsonCallback constructJsonCallbackFromCache(String fullTable) throws Exception{
+    private void constructJsonCallbackFromCache() throws Exception{
        PreparedQueryObject pQuery = new PreparedQueryObject();
-               JsonCallback jsonCallback = new JsonCallback();
+               JsonCallback jsonCallback = null;
+               List<String> notifyList = new java.util.ArrayList<>();
                String cql = 
                 "select id, endpoint_userid, endpoint_password, notify_to_endpoint, notify_insert_on,"
-                + " notify_delete_on, notify_update_on, request from admin.notification_master where notifyon = ? allow filtering";
+                + " notify_delete_on, notify_update_on, request, notifyon from admin.notification_master allow filtering";
         pQuery.appendQueryString(cql);
-        pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), fullTable));
-        logger.info("Query: "+pQuery.getQuery() + " : "+fullTable);
+        //pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), fullTable));
+        logger.info("Query: "+pQuery.getQuery());
         
-        Row row = MusicCore.get(pQuery).one();
-        if(row != null) {
+        ResultSet rs = MusicCore.get(pQuery);
+        Iterator<Row> it = rs.iterator();
+        while (it.hasNext()) {
+            Row row = (Row) it.next();
                String endpoint = row.getString("notify_to_endpoint");
             String username = row.getString("endpoint_userid");
-            String password = row.getString("endpoint_password");
+            ByteBuffer passwordBytes = row.getBytes("endpoint_password");
             String insert = row.getString("notify_insert_on");
             String delete = row.getString("notify_delete_on");
             String update = row.getString("notify_update_on");
             String request = row.getString("request");
+            String notifyon = row.getString("notifyon");
             String uuid = row.getUUID("id").toString();
+            notifyList.add(notifyon);
+            jsonCallback = new JsonCallback();
             jsonCallback.setApplicationNotificationEndpoint(endpoint);
-            jsonCallback.setApplicationPassword(password);
+            
+            Charset charset = Charset.forName("ISO-8859-1");
+            String decodedPwd = charset.decode(passwordBytes).toString();
+            jsonCallback.setApplicationPassword(decodedPwd);
             jsonCallback.setApplicationUsername(username);
-            jsonCallback.setNotifyOn(fullTable);
+            jsonCallback.setNotifyOn(notifyon);
             jsonCallback.setNotifyWhenInsertsIn(insert);
             jsonCallback.setNotifyWhenDeletesIn(delete);
             jsonCallback.setNotifyWhenChangeIn(update);
@@ -648,10 +744,12 @@ public class RestMusicAdminAPI {
             }
             logger.info("After parsing. Saved request_body: "+responseBody);
             jsonCallback.setResponseBody(responseBody);
+            logger.info("Updating Cache with updateCallBackCache: "+notifyon+ " :::: "+jsonCallback);
+            CachingUtil.updateCallBackCache(notifyon, jsonCallback);
         }
-        return jsonCallback;
+        CachingUtil.updateCallbackNotifyList(notifyList);
     }
-
+    
     @POST
     @Path("/onboardCallback")
     @Produces(MediaType.APPLICATION_JSON)
@@ -665,25 +763,30 @@ public class RestMusicAdminAPI {
         String endpoint = jsonNotification.getEndpoint();
         String notify_field = jsonNotification.getNotify_field();
         Map<String, String> responseBody = jsonNotification.getResponse_body();
+        String triggerName = jsonNotification.getTriggerName();
+        if(triggerName == null || triggerName.length() == 0)
+               triggerName = "MusicTrigger";
+        
+        /*JsonCallback callBackCache = CachingUtil.getCallBackCache(notify_field);
+        if(callBackCache != null) {
+               resultMap.put("Exception", "The notification property has already been onboarded.");
+            return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
+        }*/
         
         String[] allFields = notify_field.split(":");
         String inserts = null;
         String updates = null;
         String deletes = null;
+        String tableName = null;
         if(allFields.length >= 2) {
                inserts = updates = notify_field;
         } else if(allFields.length == 1) {
                inserts = deletes = notify_field;;
         }
-                       
+        tableName = allFields[0];
+        String cql = "CREATE TRIGGER IF NOT EXISTS musictrigger ON "+tableName+" Using '"+triggerName+"'";
         PreparedQueryObject pQuery = new PreparedQueryObject();
-        /*if (username == null || password == null || endpoint == null) {
-            logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO,
-                            ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
-            resultMap.put("Exception",
-                            "Please check the request parameters. Some of the required values are missing.");
-            return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
-        }*/
+        
         String uuid = CachingUtil.generateUUID();
         try {
                pQuery.appendQueryString(
@@ -691,14 +794,16 @@ public class RestMusicAdminAPI {
                                                + "notifyon, notify_insert_on, notify_delete_on, notify_update_on, request, current_notifier) VALUES (?,?,?,?,?,?,?,?,?,?)");
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), username));
-               pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
+               Charset charset = Charset.forName("ISO-8859-1");
+            ByteBuffer decodedPwd = charset.encode(password); 
+               pQuery.addValue(MusicUtil.convertToActualDataType(DataType.blob(), decodedPwd.array()));
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), endpoint));
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), notify_field));
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), inserts));
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), deletes));
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), updates));
                pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), responseBody));
-               pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), "UNKNOWN"));
+               pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), MusicCore.getMyHostId()));
                MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL);
                JsonCallback jsonCallback = new JsonCallback();
                jsonCallback.setUuid(uuid);
@@ -712,6 +817,10 @@ public class RestMusicAdminAPI {
                jsonCallback.setResponseBody(responseBody);
                CachingUtil.updateCallBackCache(notify_field, jsonCallback);
                logger.info("Cache updated ");
+               pQuery = new PreparedQueryObject();
+               pQuery.appendQueryString(cql);
+               ResultType nonKeyRelatedPut = MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL);
+               logger.info(EELFLoggerDelegate.applicationLogger, "Created trigger");
         //callBackCache.put(jsonCallback.getApplicationName(), jsonMap);
         } catch (InvalidQueryException e) {
             logger.error(EELFLoggerDelegate.errorLogger,"Exception callback_api table not configured."+e.getMessage());