diff options
Diffstat (limited to 'src/main/java/org/onap/music/rest')
7 files changed, 282 insertions, 188 deletions
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<String, Object> getOnboardedInfo( - @ApiParam(value = "AID", required = true) @HeaderParam("aid") String uuid, - @ApiParam(value = "Application namespace", - required = true) @HeaderParam("ns") String appName, + public Map<String, Object> getOnboardedInfoSearch( + JsonOnboard jsonObj, @Context HttpServletResponse response) throws Exception { Map<String, Object> 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<Row> 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<String, Object> deleteOnboardApp(JsonOnboard jsonObj, - @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, @Context HttpServletResponse response) throws Exception { Map<String, Object> 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)); @@ -226,6 +229,18 @@ public class RestMusicAdminAPI { } 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(), UUID.fromString(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<String, Object> updateOnboardApp(JsonOnboard jsonObj, - @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid, @Context HttpServletResponse response) throws Exception { Map<String, Object> 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; } } diff --git a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java b/src/main/java/org/onap/music/rest/RestMusicBmAPI.java index 90b82229..8f62f9c1 100644 --- a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicBmAPI.java @@ -35,6 +35,7 @@ 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; @@ -58,7 +59,8 @@ import io.swagger.annotations.ApiParam; @Path("/v{version: [0-9]+}/benchmarks/") @Api(value = "Benchmark API", hidden = true) public class RestMusicBmAPI { - private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicBmAPI.class); + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicBmAPI.class); // pure zk calls... @@ -86,11 +88,11 @@ public class RestMusicBmAPI { @Consumes(MediaType.APPLICATION_JSON) public void pureZkUpdate(JsonInsert insObj, @PathParam("name") String nodeName) throws Exception { - logger.info("--------------Zk normal update-------------------------"); + logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zk normal update-------------------------"); long start = System.currentTimeMillis(); MusicCore.pureZkWrite(nodeName, insObj.serialize()); long end = System.currentTimeMillis(); - logger.info("Total time taken for Zk normal update:" + (end - start) + " ms"); + logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk normal update:" + (end - start) + " ms"); } /** @@ -122,7 +124,7 @@ public class RestMusicBmAPI { String operationId = UUID.randomUUID().toString();// just for debugging purposes. String consistency = updateObj.getConsistencyInfo().get("type"); - logger.info("--------------Zookeeper " + consistency + " update-" + operationId + logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zookeeper " + consistency + " update-" + operationId + "-------------------------"); byte[] data = updateObj.serialize(); @@ -138,7 +140,7 @@ public class RestMusicBmAPI { long zkPutTime = 0, lockReleaseTime = 0; if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) { - logger.info("acquired lock with id " + lockId); + logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId); MusicCore.pureZkWrite(lockname, data); zkPutTime = System.currentTimeMillis(); boolean voluntaryRelease = true; @@ -171,7 +173,7 @@ public class RestMusicBmAPI { + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime) + lockingInfo; - logger.info(timingString); + logger.info(EELFLoggerDelegate.applicationLogger,timingString); } /** @@ -201,7 +203,7 @@ public class RestMusicBmAPI { } long end = System.currentTimeMillis(); - logger.info("Total time taken for Zk atomic read:" + (end - start) + " ms"); + logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk atomic read:" + (end - start) + " ms"); } /** @@ -225,7 +227,7 @@ public class RestMusicBmAPI { long startTime = System.currentTimeMillis(); String operationId = UUID.randomUUID().toString();// just for debugging purposes. String consistency = insObj.getConsistencyInfo().get("type"); - logger.info("--------------Cassandra " + consistency + " update-" + operationId + logger.info(EELFLoggerDelegate.applicationLogger,"--------------Cassandra " + consistency + " update-" + operationId + "-------------------------"); PreparedQueryObject queryObject = new PreparedQueryObject(); Map<String, Object> valuesMap = insObj.getValues(); @@ -272,20 +274,20 @@ public class RestMusicBmAPI { if ((ttl != null) && (timestamp != null)) { - logger.info("both there"); + logger.info(EELFLoggerDelegate.applicationLogger,"both there"); queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?"); queryObject.addValue(Integer.parseInt(ttl)); queryObject.addValue(Long.parseLong(timestamp)); } if ((ttl != null) && (timestamp == null)) { - logger.info("ONLY TTL there"); + logger.info(EELFLoggerDelegate.applicationLogger,"ONLY TTL there"); queryObject.appendQueryString(" USING TTL ?"); queryObject.addValue(Integer.parseInt(ttl)); } if ((ttl == null) && (timestamp != null)) { - logger.info("ONLY timestamp there"); + logger.info(EELFLoggerDelegate.applicationLogger,"ONLY timestamp there"); queryObject.appendQueryString(" USING TIMESTAMP ?"); queryObject.addValue(Long.parseLong(timestamp)); } @@ -305,9 +307,8 @@ public class RestMusicBmAPI { + "|json parsing time:" + (jsonParseCompletionTime - startTime) + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime) + "|"; - logger.info(timingString); + logger.info(EELFLoggerDelegate.applicationLogger,timingString); return operationResult; } - } diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java index ba0f1a3b..e16cc373 100755 --- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java @@ -1,20 +1,16 @@ /* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * ============LICENSE_START========================================== org.onap.music + * =================================================================== Copyright (c) 2017 AT&T + * Intellectual Property =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. * * ============LICENSE_END============================================= * ==================================================================== @@ -26,7 +22,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; -// import java.util.logging.Level; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -47,15 +42,17 @@ import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.datastore.jsonobjects.JsonDelete; import org.onap.music.datastore.jsonobjects.JsonInsert; import org.onap.music.datastore.jsonobjects.JsonKeySpace; -import org.onap.music.response.jsonobjects.JsonResponse; import org.onap.music.datastore.jsonobjects.JsonTable; import org.onap.music.datastore.jsonobjects.JsonUpdate; +import org.onap.music.eelf.logging.EELFLoggerDelegate; +import org.onap.music.exceptions.MusicServiceException; import org.onap.music.main.CachingUtil; import org.onap.music.main.MusicCore; +import org.onap.music.main.MusicCore.Condition; import org.onap.music.main.MusicUtil; import org.onap.music.main.ResultType; import org.onap.music.main.ReturnType; -import org.onap.music.main.MusicCore.Condition; +import org.onap.music.response.jsonobjects.JsonResponse; import com.datastax.driver.core.DataType; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; @@ -90,8 +87,7 @@ public class RestMusicDataAPI { * */ - - private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicDataAPI.class); + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class); private static String xLatestVersion = "X-latestVersion"; private class RowIdentifier { @@ -165,8 +161,9 @@ public class RestMusicDataAPI { return resultMap; } - String consistency = MusicUtil.EVENTUAL;// for now this needs only eventual - // consistency + String consistency = MusicUtil.EVENTUAL;// for now this needs only + // eventual + // consistency PreparedQueryObject queryObject = new PreparedQueryObject(); boolean result = false; @@ -182,13 +179,14 @@ public class RestMusicDataAPI { queryObject.appendQueryString(";"); long end = System.currentTimeMillis(); - logger.info("Time taken for setting up query in create keyspace:" + (end - start)); + logger.info(EELFLoggerDelegate.applicationLogger, + "Time taken for setting up query in create keyspace:" + (end - start)); try { result = MusicCore.nonKeyRelatedPut(queryObject, consistency); - logger.debug("resulta = " + result); + logger.error(EELFLoggerDelegate.errorLogger, "resulta = " + result); } catch (Exception e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } logger.debug("result = " + result); @@ -237,7 +235,7 @@ public class RestMusicDataAPI { return resultMap; } } catch (Exception e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } resultMap.remove("uuid"); if (CachingUtil.isAAFApplication(ns)) @@ -286,8 +284,9 @@ public class RestMusicDataAPI { return resultMap; } - String consistency = MusicUtil.EVENTUAL;// for now this needs only eventual - // consistency + String consistency = MusicUtil.EVENTUAL;// for now this needs only + // eventual + // consistency String appName = CachingUtil.getAppName(keyspaceName); String uuid = CachingUtil.getUuidFromMusicCache(keyspaceName); PreparedQueryObject pQuery = new PreparedQueryObject(); @@ -303,10 +302,9 @@ public class RestMusicDataAPI { } else if (count == 1) { pQuery = new PreparedQueryObject(); pQuery.appendQueryString( - "UPDATE admin.keyspace_master SET keyspace_name=?,password=?,is_api=null where uuid = ?;"); + "UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;"); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), - MusicUtil.DEFAULTKEYSPACENAME)); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), null)); + MusicUtil.DEFAULTKEYSPACENAME)); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid)); MusicCore.nonKeyRelatedPut(pQuery, consistency); } else { @@ -407,14 +405,18 @@ public class RestMusicDataAPI { } } - queryObject.appendQueryString("CREATE TABLE IF NOT EXISTS " + keyspace + "." + tablename - + " " + fieldsString); + queryObject.appendQueryString( + "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString); if (propertiesMap != null) queryObject.appendQueryString(" WITH " + propertiesString); queryObject.appendQueryString(";"); - result = MusicCore.nonKeyRelatedPut(queryObject, consistency); + try { + result = MusicCore.nonKeyRelatedPut(queryObject, consistency); + } catch (MusicServiceException ex) { + return new JsonResponse(false, ex.getMessage(), "").toMap(); + } return new JsonResponse(result, "", "").toMap(); } @@ -555,20 +557,20 @@ public class RestMusicDataAPI { String timestamp = insObj.getTimestamp(); if ((ttl != null) && (timestamp != null)) { - logger.info("both there"); + logger.info(EELFLoggerDelegate.applicationLogger, "both there"); queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?"); queryObject.addValue(Integer.parseInt(ttl)); queryObject.addValue(Long.parseLong(timestamp)); } if ((ttl != null) && (timestamp == null)) { - logger.info("ONLY TTL there"); + logger.info(EELFLoggerDelegate.applicationLogger, "ONLY TTL there"); queryObject.appendQueryString(" USING TTL ?"); queryObject.addValue(Integer.parseInt(ttl)); } if ((ttl == null) && (timestamp != null)) { - logger.info("ONLY timestamp there"); + logger.info(EELFLoggerDelegate.applicationLogger, "ONLY timestamp there"); queryObject.appendQueryString(" USING TIMESTAMP ?"); queryObject.addValue(Long.parseLong(timestamp)); } @@ -591,7 +593,7 @@ public class RestMusicDataAPI { : new ReturnType(ResultType.FAILURE, "Null result - Please Contact admin").toMap(); } catch (Exception ex) { - logger.error(ex.getMessage()); + logger.info(EELFLoggerDelegate.applicationLogger, ex.getMessage()); return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap(); } } @@ -642,14 +644,19 @@ public class RestMusicDataAPI { String operationId = UUID.randomUUID().toString();// just for infoging // purposes. String consistency = updateObj.getConsistencyInfo().get("type"); - logger.info("--------------Music " + consistency + " update-" + operationId - + "-------------------------"); + logger.info(EELFLoggerDelegate.applicationLogger, "--------------Music " + consistency + + " update-" + operationId + "-------------------------"); // obtain the field value pairs of the update PreparedQueryObject queryObject = new PreparedQueryObject(); Map<String, Object> valuesMap = updateObj.getValues(); TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename); + if (tableInfo == null) { + return new ReturnType(ResultType.FAILURE, + "Table information not found. Please check input for table name= " + + keyspace + "." + tablename).toMap(); + } String vectorTs = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); StringBuilder fieldValueString = new StringBuilder("vector_ts=?,"); @@ -689,8 +696,12 @@ public class RestMusicDataAPI { queryObject.addValue(Long.parseLong(timestamp)); } // get the row specifier - RowIdentifier rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), - queryObject); + RowIdentifier rowId = null; + try { + rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject); + } catch (MusicServiceException ex) { + return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap(); + } queryObject.appendQueryString( " SET " + fieldValueString + " WHERE " + rowId.rowIdString + ";"); @@ -701,8 +712,10 @@ public class RestMusicDataAPI { conditionInfo = null; else {// to avoid parsing repeatedly, just send the select query to // obtain row - String selectQuery = "SELECT * FROM " + keyspace + "." + tablename + " WHERE " - + rowId.rowIdString + ";"; + PreparedQueryObject selectQuery = new PreparedQueryObject(); + selectQuery.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + " WHERE " + + rowId.rowIdString + ";"); + selectQuery.addValue(rowId.primarKeyValue); conditionInfo = new MusicCore.Condition(updateObj.getConditions(), selectQuery); } @@ -715,8 +728,7 @@ public class RestMusicDataAPI { String lockId = updateObj.getConsistencyInfo().get("lockId"); operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue, queryObject, lockId, conditionInfo); - } - else if (consistency.equalsIgnoreCase("atomic_delete_lock")) { + } else if (consistency.equalsIgnoreCase("atomic_delete_lock")) { // this function is mainly for the benchmarks operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject, conditionInfo); @@ -737,7 +749,7 @@ public class RestMusicDataAPI { String lockManagementTime = operationResult.getTimingInfo(); timingString = timingString + lockManagementTime; } - logger.info(timingString); + logger.info(EELFLoggerDelegate.applicationLogger, timingString); return (operationResult != null) ? operationResult.toMap() : new ReturnType(ResultType.FAILURE, "Null result - Please Contact admin") .toMap(); @@ -800,8 +812,12 @@ public class RestMusicDataAPI { } // get the row specifier - RowIdentifier rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), - queryObject); + RowIdentifier rowId = null; + try { + rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject); + } catch (MusicServiceException ex) { + return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap(); + } String rowSpec = rowId.rowIdString.toString(); if ((columnList != null) && (!rowSpec.isEmpty())) { @@ -825,8 +841,10 @@ public class RestMusicDataAPI { conditionInfo = null; else {// to avoid parsing repeatedly, just send the select query to // obtain row - String selectQuery = "SELECT * FROM " + keyspace + "." + tablename + " WHERE " - + rowId.rowIdString + ";"; + PreparedQueryObject selectQuery = new PreparedQueryObject(); + selectQuery.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + " WHERE " + + rowId.rowIdString + ";"); + selectQuery.addValue(rowId.primarKeyValue); conditionInfo = new MusicCore.Condition(delObj.getConditions(), selectQuery); } @@ -861,7 +879,8 @@ public class RestMusicDataAPI { @DELETE @Path("/{keyspace}/tables/{tablename}") @ApiOperation(value = "Drop Table", response = String.class) - + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) public Map<String, Object> dropTable( @ApiParam(value = "Major Version", required = true) @PathParam("version") String version, @@ -893,8 +912,13 @@ public class RestMusicDataAPI { String consistency = "eventual";// for now this needs only eventual // consistency PreparedQueryObject query = new PreparedQueryObject(); - query.appendQueryString("DROP TABLE IF EXISTS " + keyspace + "." + tablename + ";"); - return new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency), "", "").toMap(); + query.appendQueryString("DROP TABLE " + keyspace + "." + tablename + ";"); + try { + return new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency), "", "").toMap(); + } catch (MusicServiceException ex) { + return new JsonResponse(false, ex.getMessage(), "").toMap(); + } + } /** @@ -948,9 +972,12 @@ public class RestMusicDataAPI { PreparedQueryObject queryObject = new PreparedQueryObject(); StringBuilder rowSpec = new StringBuilder(); - RowIdentifier rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), - queryObject); - + RowIdentifier rowId = null; + try { + rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject); + } catch (MusicServiceException ex) { + return MusicUtil.setErrorResponse(ex); + } queryObject.appendQueryString( "SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowSpec + ";"); @@ -1018,11 +1045,21 @@ public class RestMusicDataAPI { queryObject.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + ";"); else { int limit = -1; // do not limit the number of results - queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns, userId, - password, keyspace, tablename, info, limit); + try { + queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns, + userId, password, keyspace, tablename, info, limit); + } catch (MusicServiceException ex) { + return MusicUtil.setErrorResponse(ex); + } } - ResultSet results = MusicCore.get(queryObject); - return MusicCore.marshallResults(results); + + try { + ResultSet results = MusicCore.get(queryObject); + return MusicCore.marshallResults(results); + } catch (MusicServiceException ex) { + return MusicUtil.setErrorResponse(ex); + } + } /** @@ -1032,11 +1069,13 @@ public class RestMusicDataAPI { * @param info * @param limit * @return + * @throws MusicServiceException * @throws Exception */ public PreparedQueryObject selectSpecificQuery(String version, String minorVersion, String patchVersion, String aid, String ns, String userId, String password, - String keyspace, String tablename, UriInfo info, int limit) { + String keyspace, String tablename, UriInfo info, int limit) + throws MusicServiceException { PreparedQueryObject queryObject = new PreparedQueryObject(); StringBuilder rowIdString = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), @@ -1061,13 +1100,23 @@ public class RestMusicDataAPI { * @param rowParams * @param queryObject * @return + * @throws MusicServiceException * @throws Exception */ private RowIdentifier getRowIdentifier(String keyspace, String tablename, - MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject) { + MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject) + throws MusicServiceException { StringBuilder rowSpec = new StringBuilder(); int counter = 0; TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename); + if (tableInfo == null) { + logger.error(EELFLoggerDelegate.errorLogger, + "Table information not found. Please check input for table name= " + + keyspace + "." + tablename); + throw new MusicServiceException( + "Table information not found. Please check input for table name= " + + keyspace + "." + tablename); + } StringBuilder primaryKey = new StringBuilder(); for (MultivaluedMap.Entry<String, List<String>> entry : rowParams.entrySet()) { String keyName = entry.getKey(); @@ -1084,5 +1133,4 @@ public class RestMusicDataAPI { } return new RowIdentifier(primaryKey.toString(), rowSpec, queryObject); } - } diff --git a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java index 8612b1fa..5f28f447 100644 --- a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java @@ -35,10 +35,15 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; 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; @@ -52,8 +57,9 @@ import io.swagger.annotations.ApiParam; @Api(value="Lock Api") public class RestMusicLocksAPI { - private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicLocksAPI.class); + private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class); private static String xLatestVersion = "X-latestVersion"; + /** * Puts the requesting process in the q for this lock. The corresponding * node will be created in zookeeper if it did not already exist @@ -74,10 +80,10 @@ public class RestMusicLocksAPI { @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName, @Context HttpServletResponse response){ response.addHeader(xLatestVersion,MusicUtil.getVersion()); - Boolean status = true; + ResultType status = ResultType.SUCCESS; String lockId = MusicCore.createLockReference(lockName); - if ( lockId == null ) { status = false; } - return new JsonLockResponse(status.toString(),"",lockId).toMap(); + if (lockId == null) { status = ResultType.FAILURE; } + return new JsonLockResponse(status).setLock(lockId).toMap(); } /** @@ -98,8 +104,9 @@ public class RestMusicLocksAPI { @Context HttpServletResponse response){ response.addHeader(xLatestVersion,MusicUtil.getVersion()); String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$')); - Boolean lockStatus = MusicCore.acquireLock(lockName,lockId); - return new JsonLockResponse(lockStatus.toString(),"",lockId,lockStatus.toString(),"").toMap(); + ReturnType lockStatus = MusicCore.acquireLock(lockName,lockId); + return new JsonLockResponse(lockStatus.getResult()).setLock(lockId) + .setMessage(lockStatus.getMessage()).toMap(); } @@ -115,8 +122,10 @@ public class RestMusicLocksAPI { @Context HttpServletResponse response){ response.addHeader(xLatestVersion,MusicUtil.getVersion()); String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$')); - String lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, lockObj.getLeasePeriod()).toString(); - return new JsonLockResponse(lockLeaseStatus,"",lockName,lockLeaseStatus,"",String.valueOf(lockObj.getLeasePeriod())).toMap(); + ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, lockObj.getLeasePeriod()); + return new JsonLockResponse(lockLeaseStatus.getResult()).setLock(lockName) + .setMessage(lockLeaseStatus.getMessage()) + .setLockLease(String.valueOf(lockObj.getLeasePeriod())).toMap(); } @@ -131,13 +140,14 @@ public class RestMusicLocksAPI { @Context HttpServletResponse response){ response.addHeader(xLatestVersion,MusicUtil.getVersion()); String who = MusicCore.whoseTurnIsIt(lockName); - String status = "true"; + ResultType status = ResultType.SUCCESS; String error = ""; if ( who == null ) { - status = "false"; + status = ResultType.FAILURE; error = "There was a problem getting the lock holder"; } - return new JsonLockResponse(status,error,lockName,"",who).toMap(); + return new JsonLockResponse(status).setError(error) + .setLock(lockName).setLockHolder(who).toMap(); } @GET @@ -152,13 +162,13 @@ public class RestMusicLocksAPI { response.addHeader(xLatestVersion,MusicUtil.getVersion()); MusicLockState mls = MusicCore.getMusicLockState(lockName); Map<String,Object> returnMap = null; - JsonLockResponse jsonResponse = new JsonLockResponse("false","",lockName); + JsonLockResponse jsonResponse = new JsonLockResponse(ResultType.FAILURE).setLock(lockName); if(mls == null) { jsonResponse.setError(""); jsonResponse.setMessage("No lock object created yet.."); } else { - jsonResponse.setStatus("true"); - jsonResponse.setLockStatus(mls.getLockStatus().toString()); + jsonResponse.setStatus(ResultType.SUCCESS); + jsonResponse.setLockStatus(mls.getLockStatus()); jsonResponse.setLockHolder(mls.getLockHolder()); } return returnMap; @@ -182,11 +192,13 @@ public class RestMusicLocksAPI { boolean voluntaryRelease = true; MusicLockState mls = MusicCore.releaseLock(lockId,voluntaryRelease); Map<String,Object> returnMap = null; - if ( mls.getLockStatus() == MusicLockState.LockStatus.UNLOCKED ) { - returnMap = new JsonLockResponse("Unlocked","","").toMap(); + if (mls.getLockStatus() == MusicLockState.LockStatus.UNLOCKED) { + returnMap = new JsonLockResponse(ResultType.SUCCESS).setLock(lockId) + .setLockStatus(mls.getLockStatus()).toMap(); } - if ( mls.getLockStatus() == MusicLockState.LockStatus.LOCKED) { - returnMap = new JsonLockResponse("Locked","","").toMap(); + if (mls.getLockStatus() == MusicLockState.LockStatus.LOCKED) { + returnMap = new JsonLockResponse(ResultType.FAILURE).setLock(lockId) + .setLockStatus(mls.getLockStatus()).toMap(); } return returnMap; } @@ -203,7 +215,7 @@ public class RestMusicLocksAPI { @Context HttpServletResponse response){ response.addHeader(xLatestVersion,MusicUtil.getVersion()); MusicCore.deleteLock(lockName); - return new JsonLockResponse("true","","").toMap(); + return new JsonLockResponse(ResultType.SUCCESS).toMap(); } } diff --git a/src/main/java/org/onap/music/rest/RestMusicQAPI.java b/src/main/java/org/onap/music/rest/RestMusicQAPI.java index 3e92461c..9a4f6c6b 100755 --- a/src/main/java/org/onap/music/rest/RestMusicQAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicQAPI.java @@ -44,6 +44,7 @@ import org.onap.music.datastore.jsonobjects.JsonDelete; import org.onap.music.datastore.jsonobjects.JsonInsert; import org.onap.music.datastore.jsonobjects.JsonTable; import org.onap.music.datastore.jsonobjects.JsonUpdate; +import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.main.MusicCore; import com.att.eelf.configuration.EELFLogger; @@ -60,7 +61,7 @@ import io.swagger.annotations.ApiParam; @Api(value="Q Api") public class RestMusicQAPI { - private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicQAPI.class); + private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class); /** diff --git a/src/main/java/org/onap/music/rest/RestMusicTestAPI.java b/src/main/java/org/onap/music/rest/RestMusicTestAPI.java index 6b6bc101..f606eb8d 100644 --- a/src/main/java/org/onap/music/rest/RestMusicTestAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicTestAPI.java @@ -31,6 +31,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.main.MusicUtil; import com.att.eelf.configuration.EELFLogger; @@ -43,7 +44,8 @@ import io.swagger.annotations.ApiOperation; @Path("/v{version: [0-9]+}/test") @Api(value="Test Api") public class RestMusicTestAPI { - private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicTestAPI.class); + + private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicTestAPI.class); /** * Returns a test JSON. This will confirm that REST is working. diff --git a/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java b/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java index 924b0289..f0a32b5c 100644 --- a/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java @@ -31,6 +31,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import org.onap.music.response.jsonobjects.JsonResponse; +import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.main.MusicUtil; import com.att.eelf.configuration.EELFLogger; @@ -44,7 +45,8 @@ import io.swagger.annotations.ApiOperation; @Api(value="Version Api") public class RestMusicVersionAPI { - private static EELFLogger logger = EELFManager.getInstance().getLogger(RestMusicVersionAPI.class); + private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicVersionAPI.class); + /** * Get the version of MUSIC * @return |