aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--distribution/cassandra_job/runcql.sh80
-rw-r--r--musictrigger/assembly.xml2
-rwxr-xr-xmusictrigger/src/MusicTrigger.java93
-rwxr-xr-xpom.xml19
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java353
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java25
-rw-r--r--src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java28
-rwxr-xr-xversion.properties2
8 files changed, 239 insertions, 363 deletions
diff --git a/distribution/cassandra_job/runcql.sh b/distribution/cassandra_job/runcql.sh
index 687e93b3..2ffd5f2f 100644
--- a/distribution/cassandra_job/runcql.sh
+++ b/distribution/cassandra_job/runcql.sh
@@ -1,25 +1,41 @@
#! /bin/bash
+if [ -z "$TIMEOUT" ]; then
+ TIMEOUT=10;
+fi
+if [ -z "$DELAY" ]; then
+ DELAY=60;
+fi
+TO="--request-timeout=$TIMEOUT"
+
if [ $CASS_HOSTNAME ]; then
- echo "#############################################"
- echo "############## Let run cql's ################"
- echo "#############################################"
- echo "Current Variales in play"
- echo "Default User"
- echo "DEF_USER="$DEF_USER
- echo "DEF_PASS=***********"
- echo "New User"
- echo "USERNAME="$USERNAME
- echo "PASSWORD=***********"
- if cqlsh -u cassandra -p cassandra -e "describe keyspaces;";
+ echo "Sleeping for $DELAY seconds before running cql";
+ sleep $DELAY;
+ >&2 echo "#############################################"
+ >&2 echo "############## Let run cql's ################"
+ >&2 echo "#############################################"
+ >&2 echo "Current Variables in play"
+ >&2 echo "Default User"
+ >&2 echo "DEF_USER="$DEF_USER
+ >&2 echo "DEF_PASS=***********"
+ >&2 echo "New User"
+ >&2 echo "USERNAME="$USERNAME
+ >&2 echo "PASSWORD=***********"
+ >&2 echo "TIMEOUT="$TIMEOUT
+ >&2 echo "Running cqlsh $TO -u cassandra -p cassandra -e \"describe keyspaces;\" ${CASS_HOSTNAME} ${PORT};"
+ if cqlsh $TO -u cassandra -p cassandra -e "describe keyspaces;" ${CASS_HOSTNAME} ${PORT};
then
>&2 echo "Cassandra user still avalable, will continue as usual";
else
- if cqlsh -u $USERNAME -p $PASSWORD -e "describe keyspaces;";
+ CASSFAIL=true
+ >&2 echo "$DEF_USER failed, trying with $USERNAME"
+ if cqlsh $TO -u $USERNAME -p $PASSWORD -e "describe keyspaces;" ${CASS_HOSTNAME} ${PORT};
then
>&2 echo "Password $USERNAME in play, update Variables"
DEF_USER=$USERNAME
DEF_PASS=$PASSWORD
- if cqlsh -u $USERNAME -p $PASSWORD -e "describe keyspaces;" | grep admin1;
+ >&2 echo "DEF_USER="$DEF_USER
+ >&2 echo "DEF_PASS=***********"
+ if cqlsh $TO -u $USERNAME -p $PASSWORD -e "describe keyspaces;" ${CASS_HOSTNAME} ${PORT} | grep admin;
then
>&2 echo "Admin table exists, everything looks good"
exit 0;
@@ -28,25 +44,28 @@ if [ $CASS_HOSTNAME ]; then
>&2 echo "DEF_USER=" $DEF_USER
fi
else
- >&2 echo "Continue and as usual"
+ if [ $CASSFAIL ]; then
+ >&2 echo "$DEF_USER and $USERNAME fail. DB might need to be initialized again. This shouldn't have happend."
+ exit 1;
+ else
+ >&2 echo "Continue and as usual"
+ fi
fi
fi
- echo "admin.cql file:"
- cat /cql/admin.cql
+ >&2 echo "Running admin.cql file:"
>&2 echo "Running cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin.cql ${CASS_HOSTNAME} ${PORT}"
sleep 1;
- if cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin.cql ${CASS_HOSTNAME} ${PORT};
+ if cqlsh $TO -u $DEF_USER -p $DEF_PASS -f /cql/admin.cql ${CASS_HOSTNAME} ${PORT};
then
>&2 echo "Success - admin.cql - Admin keyspace created";
else
>&2 echo "Failure - admin.cql";
exit 0;
fi
- echo "admin_pw.cql file:"
- cat /cql/admin_pw.cql
+ >&2 echo "Running admin_pw.cql file:"
>&2 echo "Running cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin_pw.cql ${CASS_HOSTNAME} ${PORT}"
sleep 1;
- if cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin_pw.cql ${CASS_HOSTNAME} ${PORT};
+ if cqlsh $TO -u $DEF_USER -p $DEF_PASS -f /cql/admin_pw.cql ${CASS_HOSTNAME} ${PORT};
then
>&2 echo "Success - admin_pw.cql - Password Changed";
else
@@ -54,16 +73,17 @@ if [ $CASS_HOSTNAME ]; then
exit 0;
fi
- for f in /cql/extra/*; do
- case "$f" in
- *.cql)
- echo "$0: running $f" && cqlsh -u ${USERNAME} -p ${PASSWORD} -f "$f" ${CASS_HOSTNAME} ${PORT};
- ;;
- *)
- echo "$0: ignoring $f"
- ;;
- esac
- done
+ >&2 echo "Running Test - look for admin keyspace:"
+ >&2 echo "Running cqlsh -u $USERNAME -p $PASSWORD -e "select * from system_auth.roles;" ${CASS_HOSTNAME} ${PORT}"
+ sleep 1;
+ if cqlsh $TO -u $USERNAME -p $PASSWORD -e "select * from system_auth.roles;" ${CASS_HOSTNAME} ${PORT}
+ then
+ >&2 echo "Success - running test";
+ else
+ >&2 echo "Failure - running test";
+ exit 0;
+ fi
+
else
>&2 echo "Missing CASS_HOSTNAME";
exit 0;
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 @@
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
-</assembly>
+</assembly> \ 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<Mutation> 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<Mutation> 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<Cell> cls = partition.getRow(clt).cells().iterator();
- Iterator<ColumnDefinition> 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
diff --git a/pom.xml b/pom.xml
index 22a17245..eba89df1 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<groupId>org.onap.music</groupId>
<artifactId>MUSIC</artifactId>
<packaging>war</packaging>
- <version>3.0.22</version>
+ <version>3.0.24</version>
<description>
This is the MUSIC REST interface, packaged as a war file.
</description>
@@ -171,6 +171,12 @@
</build>
<dependencies>
+ <!-- Added to fix MUSIC-157 License Issue -->
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.2.3</version>
+ </dependency>
<!-- Development -->
<dependency>
<groupId>javax.servlet</groupId>
@@ -184,12 +190,6 @@
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
- <!-- /Development -->
- <!-- <dependency>
- <groupId>com.hazelcast</groupId>
- <artifactId>hazelcast-client</artifactId>
- <version>3.7.1</version>
- </dependency> -->
<!-- Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
@@ -338,11 +338,6 @@
<artifactId>jbcrypt</artifactId>
<version>0.4</version>
</dependency>
- <dependency>
- <groupId>com.owlike</groupId>
- <artifactId>genson</artifactId>
- <version>1.3</version>
- </dependency>
</dependencies>
diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
index 33128f3c..0e365650 100755
--- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
@@ -22,28 +22,18 @@
package org.onap.music.rest;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.cert.X509Certificate;
-import java.util.ArrayList;
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;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
@@ -76,24 +66,26 @@ import org.onap.music.main.ResultType;
import org.onap.music.main.ReturnType;
import org.onap.music.response.jsonobjects.JsonResponse;
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
-import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
import com.sun.jersey.core.util.Base64;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+import com.datastax.driver.core.TableMetadata;
+
+import javax.ws.rs.core.HttpHeaders;
+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;
@Path("/v2/admin")
// @Path("/v{version: [0-9]+}/admin")
@@ -432,7 +424,6 @@ public class RestMusicAdminAPI {
Map<String, Object> resultMap = new HashMap<>();
try {
logger.info(EELFLoggerDelegate.applicationLogger, "Got notification: " + inputJsonObj.getData());
- logger.info("Got notification: " + inputJsonObj.getData());
String dataStr = inputJsonObj.getData();
JSONCallbackResponse jsonResponse = mapper.readValue(dataStr, JSONCallbackResponse.class);
String operation = jsonResponse.getOperation();
@@ -452,6 +443,22 @@ public class RestMusicAdminAPI {
if(notifiyList == null || notifiyList.isEmpty()) {
logger.info("Is cache empty? reconstructing Object from cache..");
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;
@@ -474,45 +481,45 @@ public class RestMusicAdminAPI {
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;
- }
- }
+ 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 || field_value == null) {
+ if(baseRequestObj == null) {
resultMap.put("Exception",
"Oops. Something went wrong. Please make sure Callback properties are onboarded.");
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
- logger.info(EELFLoggerDelegate.applicationLogger, "Going through list: "+operation+ " && List: "+jsonResponse.getUpdateList());
+ logger.info("Going through list: "+operation+ " && List: "+jsonResponse.getUpdateList());
String key = "admin" + "." + "notification_master" + "." + baseRequestObj.getUuid();
String lockId = MusicCore.createLockReference(key);
@@ -521,7 +528,7 @@ public class RestMusicAdminAPI {
logger.error(EELFLoggerDelegate.errorLogger, "Some other node is notifying the caller..: ");
}
- logger.info(EELFLoggerDelegate.applicationLogger, operation+ ": Operation :: changeValue: "+changeValueMap);
+ logger.info(operation+ ": Operation :: changeValue: "+changeValueMap);
if(operation.equals("update")) {
String notifyWhenChangeIn = baseRequestObj.getNotifyWhenChangeIn(); // conductor.plans.status
if(null!=field_value) {
@@ -547,125 +554,28 @@ public class RestMusicAdminAPI {
MusicCore.releaseLock(lockId, true);
} catch(Exception e) {
e.printStackTrace();
- logger.error(EELFLoggerDelegate.errorLogger, "Exception while notifying...."+e.getMessage());
+ logger.info("Exception...");
}
logger.info(EELFLoggerDelegate.applicationLogger, "callback is completed. Notification was sent from Music...");
return Response.status(Status.OK).entity(resultMap).build();
}
- private void notifyCallBackAppl(JSONCallbackResponse jsonResponse, JsonCallback baseRequestObj) throws Exception {
+ private void notifyCallBackAppl(JSONCallbackResponse jsonResponse, JsonCallback baseRequestObj) {
int notifytimeout = MusicUtil.getNotifyTimeout();
int notifyinterval = MusicUtil.getNotifyInterval();
String endpoint = baseRequestObj.getApplicationNotificationEndpoint();
String username = baseRequestObj.getApplicationUsername();
String password = baseRequestObj.getApplicationPassword();
JsonNotification jsonNotification = constructJsonNotification(jsonResponse, baseRequestObj);
- jsonNotification.setPassword("************");
jsonNotification.setOperation_type(jsonResponse.getOperation());
- logger.info(EELFLoggerDelegate.applicationLogger, "Notification Response sending is: "+jsonNotification);
- logger.info("Notification Response sending is: "+jsonNotification);
- jsonNotification.setPassword(baseRequestObj.getApplicationPassword());
+ logger.info(EELFLoggerDelegate.applicationLogger, "Notification Response sent is: "+jsonNotification);
WebResource webResource = client.resource(endpoint);
String authData = username+":"+password;
byte[] plainCredsBytes = authData.getBytes();
byte[] base64CredsBytes = Base64.encode(plainCredsBytes);
String base64Creds = new String(base64CredsBytes);
- ClientConfig config = new DefaultClientConfig();
- config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
+ Map<String, String> response_body = baseRequestObj.getResponseBody();
ClientResponse response = null;
- WebResource service = null;
- boolean ok = false;
- try {
- Client client = Client.create(config);
- TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){
- public X509Certificate[] getAcceptedIssuers(){return null;}
- public void checkClientTrusted(X509Certificate[] certs, String authType){}
- public void checkServerTrusted(X509Certificate[] certs, String authType){}
- }};
-
- // Install the all-trusting trust manager
- try {
- SSLContext sc = SSLContext.getInstance("TLS");
- sc.init(null, trustAllCerts, new SecureRandom());
- HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
- } catch (Exception e) {
- ;
- }
-
- try {
- SSLContext sslcontext = SSLContext.getInstance( "TLS" );
- sslcontext.init( null, null, null );
- Map<String, Object> properties = config.getProperties();
- HTTPSProperties httpsProperties = new HTTPSProperties(
- new HostnameVerifier() {
- @Override
- public boolean verify( String s, SSLSession sslSession ) {
- return true;
- }
- }, sslcontext
- );
- properties.put( HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, httpsProperties );
- HttpsURLConnection.setDefaultHostnameVerifier (new HostnameVerifier() {
- @Override
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
- });
- Client.create( config );
- }
- catch ( KeyManagementException | NoSuchAlgorithmException e ) {
- throw new RuntimeException( e );
- }
-
- service = client.resource(endpoint);
-
- response = service.header("Authorization", "Basic " + base64Creds).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
- .post(ClientResponse.class, jsonNotification);
-
- } catch (Exception chf) {
- logger.info(EELFLoggerDelegate.applicationLogger, "Is Service down?");
- logger.info("An Exception occured while notifying. "+chf+ " : "+chf.getMessage() +" ...Retrying for: "+notifytimeout);
- }
- if(response != null && response.getStatus() == 200) ok = true;
- if(!ok) {
- long now= System.currentTimeMillis();
- long end = now+notifytimeout;
- while(! ok) {
- logger.info(EELFLoggerDelegate.applicationLogger, "retrying since error in notifying callback for "+notifytimeout+"ms");
- logger.info("retrying since error in notifying callback.. response status: "+ (response == null ? "404" : response.getStatus()));
- try {
- ok = true;
- response = service.header("Authorization", "Basic " + base64Creds).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
- .post(ClientResponse.class, jsonNotification);
- if(response != null && response.getStatus() == 200) ok = true;
- else if(System.currentTimeMillis() < end) {
- try{ Thread.sleep(notifyinterval); } catch(Exception e1) {}
- ok = false;
- }
- }catch (Exception e) {
- 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) {}
- }
- }
- }
-
- if(response == null) {
- logger.error(EELFLoggerDelegate.errorLogger, "Can NOT notify the caller as caller failed to respond..");
- return;
- }
- try {
- JsonNotifyClientResponse responseStr = response.getEntity(JsonNotifyClientResponse.class);
- logger.info(EELFLoggerDelegate.applicationLogger, "Response from Notified client: "+responseStr);
- logger.info("Response from Notified client: "+responseStr);
- } catch(Exception e) {
- logger.info("Exception while reading response from Caller");
- logger.error("Exception while reading response from Caller");
- logger.error(EELFLoggerDelegate.errorLogger, "Can NOT notify the caller as caller failed to respond..");
- }
-
- /*ClientResponse response = null;
try {
response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json")
.post(ClientResponse.class, jsonNotification);
@@ -704,7 +614,7 @@ public class RestMusicAdminAPI {
.post(ClientResponse.class, jsonNotification);
}
logger.info(EELFLoggerDelegate.applicationLogger, "Exception while notifying.. "+response.getStatus());
- }*/
+ }
}
private JsonNotification constructJsonNotification(JSONCallbackResponse jsonResponse, JsonCallback baseRequestObj) {
@@ -725,66 +635,64 @@ public class RestMusicAdminAPI {
String primaryId = tableInfo.getPrimaryKey().get(0).getName();
Map<String, String> responseBodyMap = baseRequestObj.getResponseBody();
- 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());
- }
+ 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);
}
-
- Set<String> keySet = responseBodyMap.keySet();
- Map<String, String> newMap = new HashMap<>();
- if(responseBodyMap.size() == 1 && responseBodyMap.containsKey("")) {
- jsonNotification.setResponse_body(newMap);
- return jsonNotification;
- }
- logger.info(EELFLoggerDelegate.applicationLogger, "responseBodyMap is not blank: "+responseBodyMap);
- 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(EELFLoggerDelegate.applicationLogger, "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();
- 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;
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ return jsonNotification;
}
-
-
private void constructJsonCallbackFromCache() throws Exception{
PreparedQueryObject pQuery = new PreparedQueryObject();
JsonCallback jsonCallback = null;
@@ -794,6 +702,7 @@ public class RestMusicAdminAPI {
+ " 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());
ResultSet rs = MusicCore.get(pQuery);
Iterator<Row> it = rs.iterator();
@@ -821,7 +730,7 @@ public class RestMusicAdminAPI {
jsonCallback.setNotifyWhenDeletesIn(delete);
jsonCallback.setNotifyWhenChangeIn(update);
jsonCallback.setUuid(uuid);
- logger.info(EELFLoggerDelegate.applicationLogger, "From DB. Saved request_body: "+request);
+ logger.info("From DB. Saved request_body: "+request);
request = request.substring(1, request.length()-1);
String[] keyValuePairs = request.split(",");
Map<String,String> responseBody = new HashMap<>();
@@ -833,9 +742,9 @@ public class RestMusicAdminAPI {
val = entry[1];
responseBody.put(entry[0], val);
}
- logger.info(EELFLoggerDelegate.applicationLogger, "After parsing. Saved request_body: "+responseBody);
+ logger.info("After parsing. Saved request_body: "+responseBody);
jsonCallback.setResponseBody(responseBody);
- logger.info(EELFLoggerDelegate.applicationLogger, "Updating Cache with updateCallBackCache: "+notifyon+ " :::: "+jsonCallback);
+ logger.info("Updating Cache with updateCallBackCache: "+notifyon+ " :::: "+jsonCallback);
CachingUtil.updateCallBackCache(notifyon, jsonCallback);
}
CachingUtil.updateCallbackNotifyList(notifyList);
@@ -907,6 +816,7 @@ public class RestMusicAdminAPI {
jsonCallback.setNotifyWhenInsertsIn(inserts);
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);
@@ -923,27 +833,6 @@ public class RestMusicAdminAPI {
}
return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Callback api successfully registered").toMap()).build();
}
-
- @DELETE
- @Path("/onboardCallback")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public Response deleteCallbackProp(JsonNotification jsonNotification) {
- Map<String, Object> resultMap = new HashMap<>();
- ResponseBuilder response =
- Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
- String notifyOn = jsonNotification.getNotify_field();
- PreparedQueryObject pQuery = new PreparedQueryObject();
- try {
- pQuery.appendQueryString("DELETE FROM admin.notification_master WHERE notifyon = ?");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), notifyOn));
- MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL);
- } catch(Exception e) {
- e.printStackTrace();
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setMessage("Callback api registration failed").toMap()).build();
- }
- return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Callback api successfully deleted").toMap()).build();
- }
/*public String encodePwd(String password) {
return Base64.getEncoder().encodeToString(password.getBytes());
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index 592b744b..2d1a8836 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -157,13 +157,14 @@ public class RestMusicDataAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
Map<String, Object> authMap = CachingUtil.verifyOnboarding(ns, userId, password);
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"authMap has an error. verifyOnboarding may have failed silently", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
response.status(Status.UNAUTHORIZED);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
if(kspObject == null || kspObject.getReplicationInfo() == null) {
+ authMap.put(ResultType.EXCEPTION.getResult(), ResultType.BODYMISSING.getResult());
response.status(Status.BAD_REQUEST);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult()).toMap()).build();
+ return response.entity(authMap).build();
}
@@ -182,7 +183,7 @@ public class RestMusicDataAPI {
} else {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
response.status(Status.UNAUTHORIZED);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
}
@@ -367,7 +368,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
String consistency = MusicUtil.EVENTUAL;
// for now this needs only eventual consistency
@@ -593,7 +594,7 @@ public class RestMusicDataAPI {
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
response.status(Status.UNAUTHORIZED);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
MultivaluedMap<String, String> rowParams = info.getQueryParameters();
String indexName = "";
@@ -661,7 +662,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
Map<String, Object> valuesMap = insObj.getValues();
@@ -871,7 +872,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
long startTime = System.currentTimeMillis();
String operationId = UUID.randomUUID().toString();// just for infoging
@@ -1084,7 +1085,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
if(delObj == null) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
@@ -1219,7 +1220,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
String consistency = "eventual";// for now this needs only eventual
// consistency
@@ -1274,7 +1275,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"Error while authentication... ", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
String lockId = selObj.getConsistencyInfo().get("lockId");
@@ -1357,7 +1358,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
}
PreparedQueryObject queryObject = new PreparedQueryObject();
diff --git a/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java b/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
index 44b4a514..895f0abf 100644
--- a/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
@@ -111,28 +111,10 @@ public class RestMusicHealthCheckAPI {
}
}
- @GET
- @Path("/musicHealthCheck")
- @ApiOperation(value = "Get Health Status", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Response musicHealthCheck() {
- logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for Health Check status for MUSIC");
- Map<String, Object> resultMap = new HashMap<>();
- MusicHealthCheck healthCheck = new MusicHealthCheck();
- String status = healthCheck.getZookeeperStatus();
- if(status.equals("ACTIVE")) {
- resultMap.put("ZooKeeper", "Active");
- }else {
- resultMap.put("ZooKeeper", "Inactive");
- }
- status = healthCheck.getCassandraStatus(ConsistencyLevel.ANY.toString());
- if(status.equals("ACTIVE")) {
- resultMap.put("Cassandra", "Active");
- } else {
- resultMap.put("Cassandra", "Inactive");
- }
- resultMap.put("MUSIC", "Active");
- return Response.status(Status.OK).entity(resultMap).build();
- }
+
+
+
+
+
}
diff --git a/version.properties b/version.properties
index ecd85846..36a7f087 100755
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
major=3
minor=0
-patch=22
+patch=24
base_version=${major}.${minor}.${patch}