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();
}