From 3acbae6bf3be04f352bfaac340b8303064a2f7c4 Mon Sep 17 00:00:00 2001 From: "Thomas Nelson Jr (arthurdent3)" Date: Tue, 20 Feb 2018 16:50:44 -0500 Subject: Applying bug fixes To many overlapping changes so including all of them. When pushing individually build was breaking. Issue-ID: MUSIC-33,MUSIC-34,MUSIC-35,MUSIC-36,MUSIC-37 Change-Id: I15b6f7c683d0d2eeadd99c2376dedd6c43a67a8c Signed-off-by: Thomas Nelson Jr (arthurdent3) --- .../org/onap/music/rest/RestMusicAdminAPI.java | 208 ++++++++++++--------- 1 file changed, 118 insertions(+), 90 deletions(-) (limited to 'src/main/java/org/onap/music/rest/RestMusicAdminAPI.java') diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java index 87a3a1ba..0265d039 100755 --- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java @@ -21,6 +21,7 @@ */ package org.onap.music.rest; + import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -29,8 +30,6 @@ import java.util.UUID; import javax.servlet.http.HttpServletResponse; 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.PUT; import javax.ws.rs.Path; @@ -39,23 +38,21 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.datastore.jsonobjects.JsonOnboard; +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 com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import com.datastax.driver.core.DataType; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; @Path("/v{version: [0-9]+}/admin") // @Path("/admin") @Api(value = "Admin Api", hidden = true) public class RestMusicAdminAPI { - private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicAdminAPI.class); + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class); /* * API to onboard an application with MUSIC. This is the mandatory first step. @@ -86,7 +83,7 @@ public class RestMusicAdminAPI { pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); ResultSet rs = MusicCore.get(pQuery); if (!rs.all().isEmpty()) { - resultMap.put("Exception", "Your application " + appName + resultMap.put("Exception", "Application " + appName + " has already been onboarded. Please contact admin."); return resultMap; } @@ -116,50 +113,55 @@ public class RestMusicAdminAPI { resultMap.put("Generated AID", uuid); return resultMap; } - - - /* - * API to onboard an application with MUSIC. This is the mandatory first step. - * - */ - @GET - @Path("/onboardAppWithMusic") - @ApiOperation(value = "Onboard application", response = String.class) + + + @POST + @Path("/search") + @ApiOperation(value = "Search Onboard application", response = String.class) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - public Map getOnboardedInfo( - @ApiParam(value = "AID", required = true) @HeaderParam("aid") String uuid, - @ApiParam(value = "Application namespace", - required = true) @HeaderParam("ns") String appName, + public Map getOnboardedInfoSearch( + JsonOnboard jsonObj, @Context HttpServletResponse response) throws Exception { Map resultMap = new HashMap<>(); response.addHeader("X-latestVersion", MusicUtil.getVersion()); - if (appName == null && uuid == null) { + String appName = jsonObj.getAppname(); + String uuid = jsonObj.getAid(); + String isAAF = jsonObj.getIsAAF(); + + if (appName == null && uuid == null && isAAF == null) { resultMap.put("Exception", - "Please check the request parameters. Some of the required values appName(ns), aid are missing."); + "Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF."); return resultMap; } PreparedQueryObject pQuery = new PreparedQueryObject(); - String cql = "select uuid, keyspace_name from admin.keyspace_master where "; if (appName != null) - cql = cql + "application_name = ?"; - else if (uuid != null) - cql = cql + "uuid = ?"; + cql = cql + "application_name = ? AND "; + if (uuid != null) + cql = cql + "uuid = ? AND "; + if(isAAF != null) + cql = cql + "is_aaf = ?"; + + if(cql.endsWith("AND ")) + cql = cql.trim().substring(0, cql.length()-4); + System.out.println("Query is: "+cql); cql = cql + " allow filtering"; System.out.println("Get OnboardingInfo CQL: " + cql); pQuery.appendQueryString(cql); if (appName != null) pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); - else if (uuid != null) + if (uuid != null) pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid)); + if (isAAF != null) + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), Boolean.parseBoolean(isAAF))); ResultSet rs = MusicCore.get(pQuery); Iterator it = rs.iterator(); while (it.hasNext()) { Row row = (Row) it.next(); - resultMap.put(row.getString("keyspace_name"), row.getUUID("uuid")); + resultMap.put( row.getUUID("uuid").toString(),row.getString("keyspace_name")); } if (resultMap.isEmpty()) resultMap.put("ERROR", "Application is not onboarded. Please contact admin."); @@ -173,46 +175,47 @@ public class RestMusicAdminAPI { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map deleteOnboardApp(JsonOnboard jsonObj, - @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, @Context HttpServletResponse response) throws Exception { Map resultMap = new HashMap<>(); response.addHeader("X-latestVersion", MusicUtil.getVersion()); String appName = jsonObj.getAppname(); + String aid = jsonObj.getAid(); PreparedQueryObject pQuery = new PreparedQueryObject(); - long count = 0; + String consistency = MusicUtil.EVENTUAL;; if (appName == null && aid == null) { resultMap.put("Exception", "Please make sure either appName(ns) or Aid is present"); return resultMap; } if (aid != null) { - pQuery.appendQueryString( - "select count(*) as count from admin.keyspace_master where uuid = ?"); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), - UUID.fromString(aid))); - Row row = MusicCore.get(pQuery).one(); - if (row != null) { - count = row.getLong(0); - } - - if (count == 0) { - resultMap.put("Failure", "Please verify your AID."); - return resultMap; - } else { - pQuery = new PreparedQueryObject(); - pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?"); + pQuery.appendQueryString("SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?"); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), + UUID.fromString(aid))); + Row row = MusicCore.get(pQuery).one(); + if(row!=null) { + String ks = row.getString("keyspace_name"); + if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) { + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("DROP KEYSPACE " + ks + ";"); + MusicCore.nonKeyRelatedPut(queryObject, consistency); + } + } + pQuery = new PreparedQueryObject(); + pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS"); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid))); - String result = MusicCore.eventualPut(pQuery).toString(); - if (result.toLowerCase().contains("success")) { - resultMap.put("Success", "Your application has been deleted."); - return resultMap; - } else { - resultMap.put("Failure", "Please verify your AID."); - return resultMap; - } - } - + boolean result = MusicCore.nonKeyRelatedPut(pQuery, consistency); + if (result) { + resultMap.put("Success", "Your application has been deleted successfully"); + } else { + resultMap.put("Exception", + "Oops. Spomething went wrong. Please make sure Aid is correct or Application is onboarded"); + } + return resultMap; } + + + + pQuery.appendQueryString( "select uuid from admin.keyspace_master where application_name = ? allow filtering"); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); @@ -225,6 +228,18 @@ public class RestMusicAdminAPI { return resultMap; } else if (rows.size() == 1) { uuid = rows.get(0).getUUID("uuid").toString(); + pQuery = new PreparedQueryObject(); + pQuery.appendQueryString("SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?"); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), + UUID.fromString(uuid))); + Row row = MusicCore.get(pQuery).one(); + String ks = row.getString("keyspace_name"); + if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) { + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("DROP KEYSPACE " + ks + ";"); + MusicCore.nonKeyRelatedPut(queryObject, consistency); + } + pQuery = new PreparedQueryObject(); pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?"); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), @@ -233,7 +248,7 @@ public class RestMusicAdminAPI { resultMap.put("Success", "Your application " + appName + " has been deleted."); return resultMap; } else { - resultMap.put("Failure", "Please provide UUID for the application."); + resultMap.put("Failure", "More than one Aid exists for this application, so please provide Aid."); } return resultMap; @@ -246,16 +261,16 @@ public class RestMusicAdminAPI { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Map updateOnboardApp(JsonOnboard jsonObj, - @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, @Context HttpServletResponse response) throws Exception { Map resultMap = new HashMap<>(); response.addHeader("X-latestVersion", MusicUtil.getVersion()); + String aid = jsonObj.getAid(); String appName = jsonObj.getAppname(); String userId = jsonObj.getUserId(); String isAAF = jsonObj.getIsAAF(); String password = jsonObj.getPassword(); String consistency = "eventual"; - PreparedQueryObject pQuery = new PreparedQueryObject(); + PreparedQueryObject pQuery; if (aid == null) { resultMap.put("Exception", "Please make sure Aid is present"); @@ -267,39 +282,52 @@ public class RestMusicAdminAPI { "No parameters found to update. Please update atleast one parameter."); return resultMap; } - - StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET "); - if (appName != null) - preCql.append(" application_name = ?,"); - if (userId != null) - preCql.append(" username = ?,"); - if (password != null) - preCql.append(" password = ?,"); - if (isAAF != null) - preCql.append(" is_aaf = ?,"); - preCql.deleteCharAt(preCql.length() - 1); - preCql.append(" WHERE uuid = ?"); - pQuery.appendQueryString(preCql.toString()); - if (appName != null) - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); - if (userId != null) - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId)); - if (password != null) - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password)); - if (isAAF != null) - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF)); - - - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid))); - Boolean result = MusicCore.nonKeyRelatedPut(pQuery, consistency); - - if (result) { - resultMap.put("Success", "Your application has been updated successfully"); - } else { - resultMap.put("Exception", - "Oops. Spomething went wrong. Please make sure Aid is correct and application is onboarded"); + + if(appName!=null) { + pQuery = new PreparedQueryObject(); + pQuery.appendQueryString( + "select uuid from admin.keyspace_master where application_name = ? allow filtering"); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); + ResultSet rs = MusicCore.get(pQuery); + if (!rs.all().isEmpty()) { + resultMap.put("Exception", "Application " + appName + + " has already been onboarded. Please contact admin."); + return resultMap; + } } - + + pQuery = new PreparedQueryObject(); + StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET "); + if (appName != null) + preCql.append(" application_name = ?,"); + if (userId != null) + preCql.append(" username = ?,"); + if (password != null) + preCql.append(" password = ?,"); + if (isAAF != null) + preCql.append(" is_aaf = ?,"); + preCql.deleteCharAt(preCql.length() - 1); + preCql.append(" WHERE uuid = ? IF EXISTS"); + pQuery.appendQueryString(preCql.toString()); + if (appName != null) + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); + if (userId != null) + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId)); + if (password != null) + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password)); + if (isAAF != null) + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF)); + + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid))); + boolean result = MusicCore.nonKeyRelatedPut(pQuery, consistency); + + if (result) { + resultMap.put("Success", "Your application has been updated successfully"); + } else { + resultMap.put("Exception", + "Oops. Spomething went wrong. Please make sure Aid is correct and application is onboarded"); + } + return resultMap; } } -- cgit 1.2.3-korg