<groupId>org.onap.music</groupId>
<artifactId>MUSIC</artifactId>
<packaging>war</packaging>
- <version>2.4.5</version>
+ <version>2.4.11</version>
<description>
This is the MUSIC REST interface, packaged as a war file.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <jersey1.version>1.9</jersey1.version>
+ <jersey1.version>1.17</jersey1.version>
<jersey2.version>2.26</jersey2.version>
<jaxrs.version>2.0.1</jaxrs.version>
<cassandra.version>3.0.0</cassandra.version>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
- <version>1.1.3</version>
+ <version>1.2.3</version>
<exclusions>
<exclusion>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <version>1.1.3</version>
+ <version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
- <version>3.3.0.1</version>
+ <version>3.3.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey-jaxrs</artifactId>
- <version>1.5.0</version>
+ <version>1.5.8</version>
</dependency>
<dependency>
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.TableMetadata;
+import com.datastax.driver.core.exceptions.AlreadyExistsException;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
/**
ResultSet rs = session.execute(preparedInsert.bind(queryObject.getValues().toArray()));
result = rs.wasApplied();
- } catch (Exception e) {
+ }
+ catch (AlreadyExistsException ae) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Executing Session Failure for Request = "
+ + "[" + queryObject.getQuery() + "]" + " Reason = " + ae.getMessage());
+ }
+ catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "Executing Session Failure for Request = "
+ "[" + queryObject.getQuery() + "]" + " Reason = " + e.getMessage());
throw new MusicServiceException("Executing Session Failure for Request = " + "["
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CachingUtil.class);
private static CacheAccess<String, String> musicCache = JCS.getInstance("musicCache");
+ private static CacheAccess<String, String> musicLockCache = JCS.getInstance("musicLockCache");
private static CacheAccess<String, Map<String, String>> aafCache = JCS.getInstance("aafCache");
private static CacheAccess<String, String> appNameCache = JCS.getInstance("appNameCache");
private static Map<String, Number> userAttempts = new HashMap<>();
public void initializeAafCache() throws MusicServiceException {
logger.info(EELFLoggerDelegate.applicationLogger,"Resetting and initializing AAF Cache...");
- String query = "SELECT application_name, keyspace_name, username, password FROM admin.keyspace_master WHERE is_api = ? allow filtering";
+ String query = "SELECT uuid, application_name, keyspace_name, username, password FROM admin.keyspace_master WHERE is_api = ? allow filtering";
PreparedQueryObject pQuery = new PreparedQueryObject();
pQuery.appendQueryString(query);
try {
String userId = row.getString("username");
String password = row.getString("password");
String keySpace = row.getString("application_name");
+ String uuid = row.getUUID("uuid").toString();
try {
userAttempts.put(nameSpace, 0);
AAFResponse responseObj = triggerAAF(nameSpace, userId, password);
map.put(userId, password);
aafCache.put(nameSpace, map);
musicCache.put(nameSpace, keySpace);
+ musicLockCache.put(nameSpace, uuid);
logger.debug("Cronjob: Cache Updated with AAF response for namespace "
+ nameSpace);
}
String keySpace) throws Exception {
if (aafCache.get(nameSpace) != null) {
- if (!musicCache.get(nameSpace).equals(keySpace)) {
+ if (keySpace != null && !musicCache.get(nameSpace).equals(keySpace)) {
logger.debug("Create new application for the same namespace.");
} else if (aafCache.get(nameSpace).get(userId).equals(password)) {
logger.debug("Authenticated with cache value..");
AAFResponse responseObj = triggerAAF(nameSpace, userId, password);
if (responseObj.getNs().size() > 0) {
- if (responseObj.getNs().get(0).getAdmin().contains(userId))
- return true;
-
+ if (responseObj.getNs().get(0).getAdmin().contains(userId)) {
+ //Map<String, String> map = new HashMap<>();
+ //map.put(userId, password);
+ //aafCache.put(nameSpace, map);
+ return true;
+ }
}
logger.info(EELFLoggerDelegate.applicationLogger,"Invalid user. Cache not updated");
return false;
resultMap.put("aid", uuid);
return resultMap;
}
+
+
+ public static Map<String, Object> authenticateAIDUserLock(String aid, String nameSpace)
+ throws Exception {
+ Map<String, Object> resultMap = new HashMap<>();
+ String uuid = null;
+
+ if (musicLockCache.get(nameSpace) == null) {
+ PreparedQueryObject pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString(
+ "SELECT uuid from admin.keyspace_master where application_name = '"
+ + nameSpace + "' allow filtering");
+ Row rs = MusicCore.get(pQuery).one();
+ try {
+ uuid = rs.getUUID("uuid").toString();
+ musicLockCache.put(nameSpace, uuid);
+ } catch (Exception e) {
+ logger.error("Exception occured during uuid retrieval from DB." + e.getMessage());
+ resultMap.put("Exception", "Unauthorized operation. Check AID and Namespace. ");
+ return resultMap;
+ }
+ if (!musicLockCache.get(nameSpace).toString().equals(aid)) {
+ resultMap.put("Exception Message",
+ "Unauthorized operation. Invalid AID for the Namespace");
+ return resultMap;
+ }
+ } else if (musicLockCache.get(nameSpace) != null
+ && !musicLockCache.get(nameSpace).toString().equals(aid)) {
+ resultMap.put("Exception Message",
+ "Unauthorized operation. Invalid AID for the Namespace");
+ return resultMap;
+ }
+ return resultMap;
+ }
+
+
+
public static void updateMusicCache(String aid, String keyspace) {
logger.info("Updating musicCache for keyspace " + keyspace + " with aid " + aid);
}
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString(
- "select * from admin.keyspace_master where application_name=? and username=? allow filtering");
+ "select * from admin.keyspace_master where application_name = ? and username = ? and password = ? allow filtering");
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
Row rs = MusicCore.get(queryObject).one();
if (rs == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"Namespace and UserId doesn't match. namespace: "+ns+" and userId: "+userId);
+ logger.error(EELFLoggerDelegate.errorLogger,"Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
- resultMap.put("Exception", "Namespace and UserId doesn't match. namespace: "+ns+" and userId: "+userId);
+ resultMap.put("Exception", "Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
} else {
boolean is_aaf = rs.getBool("is_aaf");
String keyspace = rs.getString("keyspace_name");
}
- /**
- * this function is mainly for the benchmarks to see the effect of lock deletion.
- *
- * @param keyspaceName
- * @param tableName
- * @param primaryKey
- * @param queryObject
- * @param conditionInfo
- * @return
- */
- public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName,
- String primaryKey, PreparedQueryObject queryObject, Condition conditionInfo) {
- long start = System.currentTimeMillis();
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
- long lockCreationTime = System.currentTimeMillis();
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = acquireLockWithLease(key, lockId, leasePeriod);
- long lockAcqTime = System.currentTimeMillis();
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
- queryObject, lockId, conditionInfo);
- long criticalPutTime = System.currentTimeMillis();
- deleteLock(key);
- long lockDeleteTime = System.currentTimeMillis();
- String timingInfo = "|lock creation time:" + (lockCreationTime - start)
- + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
- + "|critical put time:" + (criticalPutTime - lockAcqTime)
- + "|lock delete time:" + (lockDeleteTime - criticalPutTime) + "|";
- criticalPutResult.setTimingInfo(timingInfo);
- return criticalPutResult;
- } else {
- logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- deleteLock(key);
- return lockAcqResult;
- }
- }
+
/**
*
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to release lock:" + (end - start) + " ms");
return mls;
}
+
+ public static void voluntaryReleaseLock(String lockId) throws MusicLockingException{
+ getLockingServiceHandle().unlockAndDeleteId(lockId);
+ }
/**
*
* @param primaryKey primary key value
* @param queryObject query object containing prepared query and values
* @return ReturnType
+ * @throws MusicLockingException
*/
public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, Condition conditionInfo) {
+ PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
+
+ long start = System.currentTimeMillis();
+ String key = keyspaceName + "." + tableName + "." + primaryKey;
+ String lockId = createLockReference(key);
+ long lockCreationTime = System.currentTimeMillis();
+ ReturnType lockAcqResult = acquireLock(key, lockId);
+ long lockAcqTime = System.currentTimeMillis();
+ if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
+ ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
+ queryObject, lockId, conditionInfo);
+ long criticalPutTime = System.currentTimeMillis();
+ voluntaryReleaseLock(lockId);
+ long lockDeleteTime = System.currentTimeMillis();
+ String timingInfo = "|lock creation time:" + (lockCreationTime - start)
+ + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
+ + "|critical put time:" + (criticalPutTime - lockAcqTime)
+ + "|lock delete time:" + (lockDeleteTime - criticalPutTime) + "|";
+ criticalPutResult.setTimingInfo(timingInfo);
+ return criticalPutResult;
+ } else {
+ logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
+ destroyLockRef(lockId);
+ return lockAcqResult;
+ }
+ }
+
+ /**
+ * this function is mainly for the benchmarks to see the effect of lock deletion.
+ *
+ * @param keyspaceName
+ * @param tableName
+ * @param primaryKey
+ * @param queryObject
+ * @param conditionInfo
+ * @return
+ * @throws MusicLockingException
+ */
+ public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName,
+ String primaryKey, PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
+
long start = System.currentTimeMillis();
String key = keyspaceName + "." + tableName + "." + primaryKey;
String lockId = createLockReference(key);
long lockCreationTime = System.currentTimeMillis();
long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = acquireLockWithLease(key, lockId, leasePeriod);
+ ReturnType lockAcqResult = acquireLock(key, lockId);
long lockAcqTime = System.currentTimeMillis();
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
queryObject, lockId, conditionInfo);
long criticalPutTime = System.currentTimeMillis();
- boolean voluntaryRelease = true;
deleteLock(key);
long lockDeleteTime = System.currentTimeMillis();
String timingInfo = "|lock creation time:" + (lockCreationTime - start)
return criticalPutResult;
} else {
logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- destroyLockRef(lockId);
+ deleteLock(key);
return lockAcqResult;
}
}
+
+
/**
* @param queryObject query object containing prepared query and values
* @return ResultSet
* @throws MusicServiceException
+ * @throws MusicLockingException
*/
public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException {
+ PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
String key = keyspaceName + "." + tableName + "." + primaryKey;
String lockId = createLockReference(key);
long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = acquireLockWithLease(key, lockId, leasePeriod);
+ ReturnType lockAcqResult = acquireLock(key, lockId);
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
ResultSet result =
criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
- boolean voluntaryRelease = true;
- releaseLock(lockId, voluntaryRelease);
+ voluntaryReleaseLock(lockId);
return result;
} else {
+ destroyLockRef(lockId);
logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
return null;
}
}
+
+ public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
+ PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
+ String key = keyspaceName + "." + tableName + "." + primaryKey;
+ String lockId = createLockReference(key);
+ long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
+
+ ReturnType lockAcqResult = acquireLock(key, lockId);
+
+ if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
+ logger.info(EELFLoggerDelegate.applicationLogger, "acquired lock with id " + lockId);
+ ResultSet result = criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
+ deleteLock(key);
+ return result;
+ } else {
+ deleteLock(key);
+ logger.info(EELFLoggerDelegate.applicationLogger, "unable to acquire lock, id " + lockId);
+ return null;
+ }
+ }
+
+
/**
* authenticate user logic
resultMap.put("Exception", "Aid is mandatory for nonAAF applications ");
return resultMap;
}
- resultMap = CachingUtil.authenticateAIDUser(aid, keyspace);
+ if(operation.contains("Lock")) {
+ resultMap = CachingUtil.authenticateAIDUserLock(aid, nameSpace);
+ }
+ else {
+ resultMap = CachingUtil.authenticateAIDUser(aid, keyspace);
+ }
+
if (!resultMap.isEmpty())
return resultMap;
}
if (isAAF && nameSpace != null && userId != null && password != null) {
boolean isValid = true;
try {
- isValid = CachingUtil.authenticateAAFUser(nameSpace, userId, password, keyspace);
+ isValid = CachingUtil.authenticateAAFUser(nameSpace, userId, password, keyspace);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,"Got exception while AAF authentication for namespace " + nameSpace);
resultMap.put("Exception", e.getMessage());
public static final String ATOMIC = "atomic";
public static final String EVENTUAL = "eventual";
public static final String CRITICAL = "critical";
+ public static final String ATOMICDELETELOCK = "atomic_delete_lock";
+
public static final String DEFAULTKEYSPACENAME = "TBD";
private static String cassName = "cassandra";
private static String cassPwd = "cassandra";
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;
-import org.apache.log4j.Logger;
import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
import org.onap.music.main.ReturnType;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.TableMetadata;
import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
+//import io.swagger.annotations.ApiOperation;
+//import io.swagger.annotations.ApiParam;
/*
* These are functions created purely for benchmarking purposes. Commented out Swagger - This should
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.datastore.jsonobjects.JsonInsert;
private class RowIdentifier {
public String primarKeyValue;
public StringBuilder rowIdString;
+ @SuppressWarnings("unused")
public PreparedQueryObject queryObject;// the string with all the row
// identifiers separated by AND
}
}
+ @SuppressWarnings("unused")
private String buildVersion(String major, String minor, String patch) {
if (minor != null) {
major += "." + minor;
logger.error(EELFLoggerDelegate.errorLogger, "resulta = " + result);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ resultMap.put("Exception", "Couldn't create keyspace. Please make sure all the information is correct.");
}
logger.debug("result = " + result);
if (!result) {
resultMap.put("Status", String.valueOf(result));
- resultMap.put("Exception", "Keyspace already exists. Please contact admin.");
+ if(!resultMap.containsKey("Exception"))
+ resultMap.put("Exception", "Keyspace already exists. Please contact admin.");
if (resultMap.get("uuid").equals("new")) {
queryObject = new PreparedQueryObject();
queryObject.appendQueryString(
} else {
queryObject = new PreparedQueryObject();
queryObject.appendQueryString(
- "UPDATE admin.keyspace_master SET keyspace_name=?,password=?,is_api=null where uuid = ?;");
+ "UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;");
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
MusicUtil.DEFAULTKEYSPACENAME));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), null));
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
resultMap.remove("aid");
queryObject.appendQueryString("CREATE ROLE IF NOT EXISTS '" + userId
+ "' WITH PASSWORD = '" + password + "' AND LOGIN = true;");
result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
- if (result) {
- queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName
- + " to " + userId);
- queryObject.appendQueryString(";");
- result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
- } else {
- resultMap.remove("uuid");
- resultMap.put("Exception", "Exception while creating user.");
- return resultMap;
- }
+ queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName
+ + " to '" + userId + "'");
+ queryObject.appendQueryString(";");
+ result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
}
if (ot instanceof String) {
value = "'" + value + "'";
} else if (ot instanceof Map) {
+ @SuppressWarnings("unchecked")
Map<String, Object> otMap = (Map<String, Object>) ot;
value = "{" + MusicUtil.jsonMaptoSqlString(otMap, ",") + "}";
}
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
result = MusicCore.atomicPut(keyspace, tablename, primaryKey, queryObject, null);
+ }
+ else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
+ result = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, primaryKey, queryObject, null);
+
}
return (result != null) ? result.toMap()
: new ReturnType(ResultType.FAILURE,
operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, conditionInfo);
}
+ else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
+ operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, conditionInfo);
+ }
try {
return operationResult.toMap();
} catch (NullPointerException e) {
String lockId = selObj.getConsistencyInfo().get("lockId");
PreparedQueryObject queryObject = new PreparedQueryObject();
- StringBuilder rowSpec = new StringBuilder();
RowIdentifier rowId = null;
try {
return MusicUtil.setErrorResponse(ex);
}
queryObject.appendQueryString(
- "SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowSpec + ";");
+ "SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowId.rowIdString + ";");
ResultSet results = null;
String consistency = selObj.getConsistencyInfo().get("type");
- if (consistency.equalsIgnoreCase("critical")) {
+ if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
results = MusicCore.criticalGet(keyspace, tablename, rowId.primarKeyValue, queryObject,
lockId);
- } else if (consistency.equalsIgnoreCase("atomic")) {
+ } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
results = MusicCore.atomicGet(keyspace, tablename, rowId.primarKeyValue, queryObject);
}
+
+ else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
+ results = MusicCore.atomicGetWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject);
+ }
return MusicCore.marshallResults(results);
}
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
import org.onap.music.main.ReturnType;
import org.onap.music.response.jsonobjects.JsonLockResponse;
-import org.powermock.core.spi.testresult.Result;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(value="Lock Api")
public class RestMusicLocksAPI {
- private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class);
+ @SuppressWarnings("unused")
+ private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class);
private static String xLatestVersion = "X-latestVersion";
/**
*
* @param lockName
* @return
+ * @throws Exception
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
public Map<String,Object> createLockReference(
@ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
- @Context HttpServletResponse response){
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",
+ required = true) @HeaderParam("ns") String ns,
+ @ApiParam(value = "userId",
+ required = true) @HeaderParam("userId") String userId,
+ @ApiParam(value = "Password",
+ required = true) @HeaderParam("password") String password,
+ @Context HttpServletResponse response) throws Exception{
+ response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid,
+ "createLockReference");
+ if (!resultMap.isEmpty()) {
+ return resultMap;
+ }
ResultType status = ResultType.SUCCESS;
String lockId = MusicCore.createLockReference(lockName);
if (lockId == null) { status = ResultType.FAILURE; }
*
* @param lockId
* @return
+ * @throws Exception
*/
@GET
@Path("/acquire/{lockreference}")
@Produces(MediaType.APPLICATION_JSON)
public Map<String,Object> accquireLock(
@ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
- @Context HttpServletResponse response){
+ @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",
+ required = true) @HeaderParam("ns") String ns,
+ @ApiParam(value = "userId",
+ required = true) @HeaderParam("userId") String userId,
+ @ApiParam(value = "Password",
+ required = true) @HeaderParam("password") String password,
+ @Context HttpServletResponse response) throws Exception{
response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid,
+ "accquireLock");
+ if (!resultMap.isEmpty()) {
+ return resultMap;
+ }
String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
ReturnType lockStatus = MusicCore.acquireLock(lockName,lockId);
return new JsonLockResponse(lockStatus.getResult()).setLock(lockId)
@Produces(MediaType.APPLICATION_JSON)
public Map<String,Object> accquireLockWithLease(JsonLeasedLock lockObj,
@ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
- @Context HttpServletResponse response){
+ @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",
+ required = true) @HeaderParam("ns") String ns,
+ @ApiParam(value = "userId",
+ required = true) @HeaderParam("userId") String userId,
+ @ApiParam(value = "Password",
+ required = true) @HeaderParam("password") String password,
+ @Context HttpServletResponse response) throws Exception{
response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid,
+ "accquireLockWithLease");
+ if (!resultMap.isEmpty()) {
+ return resultMap;
+ }
String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, lockObj.getLeasePeriod());
return new JsonLockResponse(lockLeaseStatus.getResult()).setLock(lockName)
@Produces(MediaType.APPLICATION_JSON)
public Map<String,Object> currentLockHolder(
@ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
- @Context HttpServletResponse response){
+ @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",
+ required = true) @HeaderParam("ns") String ns,
+ @ApiParam(value = "userId",
+ required = true) @HeaderParam("userId") String userId,
+ @ApiParam(value = "Password",
+ required = true) @HeaderParam("password") String password,
+ @Context HttpServletResponse response) throws Exception{
response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid,
+ "currentLockHolder");
+ if (!resultMap.isEmpty()) {
+ return resultMap;
+ }
String who = MusicCore.whoseTurnIsIt(lockName);
ResultType status = ResultType.SUCCESS;
String error = "";
@Produces(MediaType.APPLICATION_JSON)
public Map<String,Object> currentLockState(
@ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
- @Context HttpServletResponse response){
+ @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",
+ required = true) @HeaderParam("ns") String ns,
+ @ApiParam(value = "userId",
+ required = true) @HeaderParam("userId") String userId,
+ @ApiParam(value = "Password",
+ required = true) @HeaderParam("password") String password,
+ @Context HttpServletResponse response) throws Exception{
response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid,
+ "currentLockState");
+ if (!resultMap.isEmpty()) {
+ return resultMap;
+ }
MusicLockState mls = MusicCore.getMusicLockState(lockName);
Map<String,Object> returnMap = null;
JsonLockResponse jsonResponse = new JsonLockResponse(ResultType.FAILURE).setLock(lockName);
* deletes the process from the zk queue
*
* @param lockId
+ * @throws Exception
*/
@DELETE
@Path("/release/{lockreference}")
response = Map.class)
@Produces(MediaType.APPLICATION_JSON)
public Map<String,Object> unLock(@PathParam("lockreference") String lockId,
- @Context HttpServletResponse response){
+ @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",
+ required = true) @HeaderParam("ns") String ns,
+ @ApiParam(value = "userId",
+ required = true) @HeaderParam("userId") String userId,
+ @ApiParam(value = "Password",
+ required = true) @HeaderParam("password") String password,
+ @Context HttpServletResponse response) throws Exception{
response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid,
+ "unLock");
+ if (!resultMap.isEmpty()) {
+ return resultMap;
+ }
boolean voluntaryRelease = true;
MusicLockState mls = MusicCore.releaseLock(lockId,voluntaryRelease);
Map<String,Object> returnMap = null;
/**
*
* @param lockName
+ * @throws Exception
*/
@DELETE
@Path("/delete/{lockname}")
@ApiOperation(value = "Delete Lock", response = Map.class)
@Produces(MediaType.APPLICATION_JSON)
public Map<String,Object> deleteLock(@PathParam("lockname") String lockName,
- @Context HttpServletResponse response){
+ @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",
+ required = true) @HeaderParam("ns") String ns,
+ @ApiParam(value = "userId",
+ required = true) @HeaderParam("userId") String userId,
+ @ApiParam(value = "Password",
+ required = true) @HeaderParam("password") String password,
+ @Context HttpServletResponse response) throws Exception{
response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, null, aid,
+ "deleteLock");
+ if (!resultMap.isEmpty()) {
+ return resultMap;
+ }
MusicCore.deleteLock(lockName);
return new JsonLockResponse(ResultType.SUCCESS).toMap();
}
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.main.MusicUtil;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(value="Test Api")
public class RestMusicTestAPI {
- private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicTestAPI.class);
+ @SuppressWarnings("unused")
+ private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicTestAPI.class);
/**
* Returns a test JSON. This will confirm that REST is working.
EELF0006E|\
An unsupported logging framework is bound to SLF4J. |\
Verify your logging frameworks.|\
- An unsupported logging framework is bound to SLF4J.
\ No newline at end of file
+ An unsupported logging framework is bound to SLF4J.
+
* ============LICENSE_END=============================================
* ====================================================================
*/
+
package org.onap.music.unittests;
+
/**
* @author srupane
*
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.exceptions.NoHostAvailableException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
public class CassandraCQL {
public static final String createKeySpace =
- "CREATE KEYSPACE IF NOT EXISTS testCassa WITH replication = {'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;";
+ "CREATE KEYSPACE IF NOT EXISTS testCassa WITH replication = "
+ +"{'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;";
public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testCassa";
public static final String createTableEmployees =
"CREATE TABLE IF NOT EXISTS testCassa.employees "
- + "(vector_ts text,emp_id uuid,emp_name text,emp_salary varint,address Map<text,text>,PRIMARY KEY (emp_name)) "
- + "WITH comment='Financial Info of employees' "
- + "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} "
- + "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};";
+ + "(vector_ts text,empId uuid,empName text,empSalary varint,address Map<text,text>,PRIMARY KEY (empName)) "
+ + "WITH comment='Financial Info of employees' "
+ + "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} "
+ + "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};";
public static final String insertIntoTablePrepared1 =
- "INSERT INTO testCassa.employees (vector_ts,emp_id,emp_name,emp_salary) VALUES (?,?,?,?); ";
+ "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary) VALUES (?,?,?,?); ";
public static final String insertIntoTablePrepared2 =
- "INSERT INTO testCassa.employees (vector_ts,emp_id,emp_name,emp_salary,address) VALUES (?,?,?,?,?);";
+ "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary,address) VALUES (?,?,?,?,?);";
public static final String selectALL = "SELECT * FROM testCassa.employees;";
public static final String selectSpecific =
- "SELECT * FROM testCassa.employees WHERE emp_name= ?;";
+ "SELECT * FROM testCassa.employees WHERE empName= ?;";
public static final String updatePreparedQuery =
- "UPDATE testCassa.employees SET vector_ts=?,address= ? WHERE emp_name= ?;";
+ "UPDATE testCassa.employees SET vector_ts=?,address= ? WHERE empName= ?;";
public static final String deleteFromTable = " ";
List<Object> preppreparedInsertValues1 = new ArrayList<>();
String vectorTs =
String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID emp_id = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40cd6");
- BigInteger emp_salary = BigInteger.valueOf(23443);
- String emp_name = "Mr Test one";
+ UUID empId = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ BigInteger empSalary = BigInteger.valueOf(23443);
+ String empName = "Mr Test one";
preppreparedInsertValues1.add(vectorTs);
- preppreparedInsertValues1.add(emp_id);
- preppreparedInsertValues1.add(emp_name);
- preppreparedInsertValues1.add(emp_salary);
+ preppreparedInsertValues1.add(empId);
+ preppreparedInsertValues1.add(empName);
+ preppreparedInsertValues1.add(empSalary);
return preppreparedInsertValues1;
}
List<Object> preparedInsertValues2 = new ArrayList<>();
String vectorTs =
String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID emp_id = UUID.fromString("abc434cc-d657-4e90-b4e5-df4223d40cd6");
- BigInteger emp_salary = BigInteger.valueOf(45655);
- String emp_name = "Mr Test two";
+ UUID empId = UUID.fromString("abc434cc-d657-4e90-b4e5-df4223d40cd6");
+ BigInteger empSalary = BigInteger.valueOf(45655);
+ String empName = "Mr Test two";
Map<String, String> address = new HashMap<>();
preparedInsertValues2.add(vectorTs);
- preparedInsertValues2.add(emp_id);
- preparedInsertValues2.add(emp_name);
- preparedInsertValues2.add(emp_salary);
+ preparedInsertValues2.add(empId);
+ preparedInsertValues2.add(empName);
+ preparedInsertValues2.add(empSalary);
address.put("Street", "1 some way");
address.put("City", "Some town");
preparedInsertValues2.add(address);
String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
Map<String, String> address = new HashMap<>();
preparedUpdateValues.add(vectorTs);
- String emp_name = "Mr Test one";
+ String empName = "Mr Test one";
address.put("Street", "101 Some Way");
address.put("City", "New York");
preparedUpdateValues.add(address);
- preparedUpdateValues.add(emp_name);
+ preparedUpdateValues.add(empName);
return preparedUpdateValues;
}
// Generate Different Prepared Query Objects
/**
- * Query Object for Get
+ * Query Object for Get.
*
* @return
*/
public static PreparedQueryObject setPreparedGetQuery() {
PreparedQueryObject queryObject = new PreparedQueryObject();
- String emp_name1 = "Mr Test one";
+ String empName1 = "Mr Test one";
queryObject.appendQueryString(selectSpecific);
- queryObject.addValue(emp_name1);
+ queryObject.addValue(empName1);
return queryObject;
}
/**
- * Query Object 1 for Insert
+ * Query Object 1 for Insert.
*
- * @return
+ * @return {@link PreparedQueryObject}
*/
public static PreparedQueryObject setPreparedInsertQueryObject1() {
}
/**
- * Query Object 2 for Insert
+ * Query Object 2 for Insert.
*
- * @return
+ * @return {@link PreparedQueryObject}
*/
public static PreparedQueryObject setPreparedInsertQueryObject2() {
}
/**
- * Query Object for Update
+ * Query Object for Update.
*
- * @return
+ * @return {@link PreparedQueryObject}
*/
public static PreparedQueryObject setPreparedUpdateQueryObject() {
@Test
public void testAcquireLockifLockRefDoesntExist() {
- Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
+ Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1");
assertEquals(lock.getResult(), ResultType.FAILURE);
assertEquals(lock.getMessage(), "Lockid doesn't exist");
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
ReturnType returnType =
MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
}
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
rs = Mockito.mock(ResultSet.class);
Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
assertNull(rs1);
Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
-
}
@Test
major=2
minor=4
-patch=5
+patch=11
base_version=${major}.${minor}.${patch}