adcb65847ed3bf27d9423e0452e72587123e5a2c
[music.git] / src / main / java / org / onap / music / rest / RestMusicAdminAPI.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  * Modifications Copyright (C) 2018 IBM.
8  * ================================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  *
21  * ============LICENSE_END=============================================
22  * ====================================================================
23  */
24
25 package org.onap.music.rest;
26
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.UUID;
34
35 import javax.ws.rs.Consumes;
36 import javax.ws.rs.DELETE;
37 import javax.ws.rs.GET;
38 import javax.ws.rs.HeaderParam;
39 import javax.ws.rs.POST;
40 import javax.ws.rs.PUT;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.Produces;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45 import javax.ws.rs.core.Response.ResponseBuilder;
46 import javax.ws.rs.core.Response.Status;
47
48 import org.mindrot.jbcrypt.BCrypt;
49 import org.onap.music.authentication.CachingUtil;
50 import org.onap.music.authentication.MusicAAFAuthentication;
51 import org.onap.music.authentication.MusicAuthenticator;
52 import org.onap.music.datastore.PreparedQueryObject;
53 import org.onap.music.datastore.jsonobjects.JsonOnboard;
54 import org.onap.music.eelf.logging.EELFLoggerDelegate;
55 import org.onap.music.eelf.logging.format.AppMessages;
56 import org.onap.music.eelf.logging.format.ErrorSeverity;
57 import org.onap.music.eelf.logging.format.ErrorTypes;
58 import org.onap.music.exceptions.MusicServiceException;
59 import org.onap.music.main.MusicCore;
60 import org.onap.music.main.MusicUtil;
61 import org.onap.music.main.ResultType;
62 import org.onap.music.response.jsonobjects.JsonResponse;
63
64 import com.datastax.driver.core.DataType;
65 import com.datastax.driver.core.ResultSet;
66 import com.datastax.driver.core.Row;
67
68 import io.swagger.annotations.Api;
69 import io.swagger.annotations.ApiOperation;
70 import io.swagger.annotations.ApiParam;
71 //import java.util.Base64.Encoder;
72 //import java.util.Base64.Decoder;
73
74 @Path("/v2/admin")
75 // @Path("/v{version: [0-9]+}/admin")
76 // @Path("/admin")
77 @Api(value = "Admin Api", hidden = true)
78 public class RestMusicAdminAPI {
79     private static EELFLoggerDelegate logger =
80                     EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
81     // Set to true in env like ONAP. Where access to creating and dropping keyspaces exist.    
82     private static final boolean KEYSPACE_ACTIVE = false;
83     
84     private MusicAuthenticator authenticator = new MusicAAFAuthentication();
85
86     /*
87      * API to onboard an application with MUSIC. This is the mandatory first step.
88      *
89      */
90     @POST
91     @Path("/onboardAppWithMusic")
92     @ApiOperation(value = "Onboard application", response = String.class)
93     @Consumes(MediaType.APPLICATION_JSON)
94     @Produces(MediaType.APPLICATION_JSON)
95     public Response onboardAppWithMusic(JsonOnboard jsonObj,
96             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
97         logger.info(EELFLoggerDelegate.errorLogger, "oboarding app");
98         ResponseBuilder response =
99                         Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
100         if (!authenticator.authenticateAdmin(authorization)) {
101             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
102                     ErrorTypes.AUTHENTICATIONERROR);
103             return response.status(Status.UNAUTHORIZED)
104                     .entity(new JsonResponse(ResultType.FAILURE)
105                             .setError("Unauthorized: Please check admin username,password and try again").toMap())
106                     .build();
107         }
108
109         Map<String, Object> resultMap = new HashMap<>();
110         String appName = jsonObj.getAppname();
111         String userId = jsonObj.getUserId();
112         String isAAF = jsonObj.getIsAAF();
113         String password = jsonObj.getPassword();
114         String keyspace_name = jsonObj.getKeyspace();
115         
116         if (appName == null || userId == null || isAAF == null || password == null) {
117             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", AppMessages.MISSINGINFO,
118                             ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
119             resultMap.put("Exception",
120                             "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.");
121             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
122         }
123
124         PreparedQueryObject pQuery = new PreparedQueryObject();
125         /*
126          * pQuery.appendQueryString(
127          * "select uuid from admin.keyspace_master where application_name = ? allow filtering"
128          * ); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
129          * appName)); ResultSet rs = MusicCore.get(pQuery); if (!rs.all().isEmpty()) {
130          * logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA
131          * ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
132          * response.status(Status.BAD_REQUEST); return response.entity(new
133          * JsonResponse(ResultType.FAILURE).setError("Application " + appName +
134          * " has already been onboarded. Please contact admin.").toMap()).build(); }
135          */
136         //pQuery = new PreparedQueryObject();
137         String uuid = MusicUtil.generateUUID();
138         pQuery.appendQueryString(
139                         "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
140                                         + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
141         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
142         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),keyspace_name));
143         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
144         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
145         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
146         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
147         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
148
149         String returnStr = MusicCore.eventualPut(pQuery).toString();
150         if (returnStr.contains("Failure")) {
151             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
152             response.status(Status.BAD_REQUEST);
153             return response.entity(new JsonResponse(ResultType.FAILURE).setError("Oops. Something wrong with onboarding process. "
154                     + "Please retry later or contact admin.").toMap()).build();
155         }
156         CachingUtil.updateisAAFCache(appName, isAAF);
157         resultMap.put("Success", "Your application " + appName + " has been onboarded with MUSIC.");
158         resultMap.put("Generated AID", uuid);
159         return response.status(Status.OK).entity(resultMap).build();
160     }
161
162
163     @POST
164     @Path("/search")
165     @ApiOperation(value = "Search Onboard application", response = String.class)
166     @Consumes(MediaType.APPLICATION_JSON)
167     @Produces(MediaType.APPLICATION_JSON)
168     public Response getOnboardedInfoSearch(JsonOnboard jsonObj,
169             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
170         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
171         
172         if (!authenticator.authenticateAdmin(authorization)) {
173             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
174                     ErrorTypes.AUTHENTICATIONERROR);
175             return response.status(Status.UNAUTHORIZED)
176                     .entity(new JsonResponse(ResultType.FAILURE)
177                             .setError("Unauthorized: Please check admin username,password and try again").toMap())
178                     .build();
179         }
180         
181         Map<String, Object> resultMap = new HashMap<>();
182         String appName = jsonObj.getAppname();
183         String uuid = jsonObj.getAid();
184         String isAAF = jsonObj.getIsAAF();
185         if (appName == null && uuid == null && isAAF == null) {
186             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.", AppMessages.MISSINGINFO,
187                             ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
188             resultMap.put("Exception",
189                             "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.");
190             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
191         }
192
193         PreparedQueryObject pQuery = new PreparedQueryObject();
194         String cql = "select uuid, keyspace_name from admin.keyspace_master where ";
195         if (appName != null)
196             cql = cql + "application_name = ? AND ";
197         if (uuid != null)
198             cql = cql + "uuid = ? AND ";
199         if (isAAF != null)
200             cql = cql + "is_aaf = ?";
201
202         if (cql.endsWith("AND "))
203             cql = cql.trim().substring(0, cql.length() - 4);
204         logger.info("Query in callback is: " + cql);
205         cql = cql + " allow filtering";
206         pQuery.appendQueryString(cql);
207         if (appName != null)
208             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
209         if (uuid != null)
210             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
211         if (isAAF != null)
212             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(),
213                             Boolean.parseBoolean(isAAF)));
214         ResultSet rs = MusicCore.get(pQuery);
215         Iterator<Row> it = rs.iterator();
216         while (it.hasNext()) {
217             Row row = it.next();
218             resultMap.put(row.getUUID("uuid").toString(), row.getString("keyspace_name"));
219         }
220         if (resultMap.isEmpty()) {
221             if (uuid != null) {
222                 logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
223                 response.status(Status.BAD_REQUEST);
224                 return response.entity(new JsonResponse(ResultType.FAILURE).setError("Please make sure Aid is correct and application is onboarded.").toMap()).build();
225
226             } else {
227                 logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
228                 response.status(Status.BAD_REQUEST);
229                 return response.entity(new JsonResponse(ResultType.FAILURE).setError("Application is not onboarded. Please make sure all the information is correct.").toMap()).build();
230             }
231         }
232         return response.status(Status.OK).entity(resultMap).build();
233     }
234
235
236     @DELETE
237     @Path("/onboardAppWithMusic")
238     @ApiOperation(value = "Delete Onboard application", response = String.class)
239     @Consumes(MediaType.APPLICATION_JSON)
240     @Produces(MediaType.APPLICATION_JSON)
241     public Response deleteOnboardApp(JsonOnboard jsonObj,
242             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
243         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
244         
245         if (!authenticator.authenticateAdmin(authorization)) {
246             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
247                     ErrorTypes.AUTHENTICATIONERROR);
248             return response.status(Status.UNAUTHORIZED)
249                     .entity(new JsonResponse(ResultType.FAILURE)
250                             .setError("Unauthorized: Please check admin username,password and try again").toMap())
251                     .build();
252         }
253         
254         Map<String, Object> resultMap = new HashMap<>();
255         String appName = jsonObj.getAppname();
256         String aid = jsonObj.getAid();
257         PreparedQueryObject pQuery = new PreparedQueryObject();
258         String consistency = MusicUtil.EVENTUAL;
259         if (appName == null && aid == null) {
260             logger.error(EELFLoggerDelegate.errorLogger, "Please make sure either appName(ns) or Aid is present", AppMessages.MISSINGINFO,
261                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
262             resultMap.put("Exception", "Please make sure either appName(ns) or Aid is present");
263             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
264         }
265         if (aid != null) {
266             if ( KEYSPACE_ACTIVE ) {
267               pQuery.appendQueryString(
268                               "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
269               pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
270                               UUID.fromString(aid)));
271               Row row = MusicCore.get(pQuery).one();
272               if (row != null) {
273                   String ks = row.getString("keyspace_name");
274                   if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
275                       PreparedQueryObject queryObject = new PreparedQueryObject();
276                       queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
277                       MusicCore.nonKeyRelatedPut(queryObject, consistency);
278                   }
279               }
280             }
281             pQuery = new PreparedQueryObject();
282             pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS");
283             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
284                             UUID.fromString(aid)));
285             ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
286             if (result == ResultType.SUCCESS) {
287                 resultMap.put("Success", "Your application has been deleted successfully");
288             } else {
289                 resultMap.put("Exception",
290                                 "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
291                 logger.error(EELFLoggerDelegate.errorLogger, "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded", AppMessages.INCORRECTDATA,
292                                 ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
293                 return response.status(Status.BAD_REQUEST).entity(resultMap).build();
294
295             }
296             return response.status(Status.OK).entity(resultMap).build();
297         }
298
299         pQuery.appendQueryString(
300                         "select uuid from admin.keyspace_master where application_name = ? allow filtering");
301         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
302         ResultSet rs = MusicCore.get(pQuery);
303         List<Row> rows = rs.all();
304         String uuid = null;
305         if (rows.isEmpty()) {
306             resultMap.put("Exception",
307                             "Application not found. Please make sure Application exists.");
308             logger.error(EELFLoggerDelegate.errorLogger, "Application not found. Please make sure Application exists.", AppMessages.INCORRECTDATA,
309                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
310             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
311         } else if (rows.size() == 1) {
312             uuid = rows.get(0).getUUID("uuid").toString();
313             pQuery = new PreparedQueryObject();
314             pQuery.appendQueryString(
315                             "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
316             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
317                             UUID.fromString(uuid)));
318             Row row = MusicCore.get(pQuery).one();
319             String ks = row.getString("keyspace_name");
320             if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
321                 PreparedQueryObject queryObject = new PreparedQueryObject();
322                 queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
323                 MusicCore.nonKeyRelatedPut(queryObject, consistency);
324             }
325
326             pQuery = new PreparedQueryObject();
327             pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?");
328             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
329                             UUID.fromString(uuid)));
330             MusicCore.eventualPut(pQuery);
331             resultMap.put("Success", "Your application " + appName + " has been deleted.");
332             return response.status(Status.OK).entity(resultMap).build();
333         } else {
334             resultMap.put("Failure",
335                             "More than one Aid exists for this application, so please provide Aid.");
336             logger.error(EELFLoggerDelegate.errorLogger, "More than one Aid exists for this application, so please provide Aid.", AppMessages.MULTIPLERECORDS,
337                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
338             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
339         }
340     }
341
342
343     @PUT
344     @Path("/onboardAppWithMusic")
345     @ApiOperation(value = "Update Onboard application", response = String.class)
346     @Consumes(MediaType.APPLICATION_JSON)
347     @Produces(MediaType.APPLICATION_JSON)
348     public Response updateOnboardApp(JsonOnboard jsonObj,
349             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
350         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
351         if (!authenticator.authenticateAdmin(authorization)) {
352             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
353                     ErrorTypes.AUTHENTICATIONERROR);
354             return response.status(Status.UNAUTHORIZED)
355                     .entity(new JsonResponse(ResultType.FAILURE)
356                             .setError("Unauthorized: Please check admin username,password and try again").toMap())
357                     .build();
358         }
359         
360         Map<String, Object> resultMap = new HashMap<>();
361         String aid = jsonObj.getAid();
362         String appName = jsonObj.getAppname();
363         String userId = jsonObj.getUserId();
364         String isAAF = jsonObj.getIsAAF();
365         String password = jsonObj.getPassword();
366         String consistency = "eventual";
367         PreparedQueryObject pQuery;
368         
369         if (aid == null) {
370             resultMap.put("Exception", "Please make sure Aid is present");
371             logger.error(EELFLoggerDelegate.errorLogger, "Please make sure Aid is present", AppMessages.MISSINGDATA,
372                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
373             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
374         }
375
376         if (appName == null && userId == null && password == null && isAAF == null) {
377             resultMap.put("Exception",
378                             "No parameters found to update. Please update atleast one parameter.");
379             logger.error(EELFLoggerDelegate.errorLogger, "No parameters found to update. Please update atleast one parameter.", AppMessages.MISSINGDATA,
380                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
381             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
382         }
383
384         if (appName != null) {
385             pQuery = new PreparedQueryObject();
386             pQuery.appendQueryString(
387                             "select uuid from admin.keyspace_master where application_name = ? allow filtering");
388             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
389             ResultSet rs = MusicCore.get(pQuery);
390             if (!rs.all().isEmpty()) {
391                 resultMap.put("Exception", "Application " + appName
392                                 + " has already been onboarded. Please contact admin.");
393                 logger.error(EELFLoggerDelegate.errorLogger, "Application " + appName+"has already been onboarded. Please contact admin.", AppMessages.ALREADYEXIST,
394                                 ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
395                 return response.status(Status.BAD_REQUEST).entity(resultMap).build();
396             }
397         }
398
399         pQuery = new PreparedQueryObject();
400         StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET ");
401         if (appName != null)
402             preCql.append(" application_name = ?,");
403         if (userId != null)
404             preCql.append(" username = ?,");
405         if (password != null)
406             preCql.append(" password = ?,");
407         if (isAAF != null)
408             preCql.append(" is_aaf = ?,");
409         preCql.deleteCharAt(preCql.length() - 1);
410         preCql.append(" WHERE uuid = ? IF EXISTS");
411         pQuery.appendQueryString(preCql.toString());
412         if (appName != null)
413             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
414         if (userId != null)
415             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
416         if (password != null)
417             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
418         if (isAAF != null)
419             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
420
421         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid)));
422         ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
423
424         if (result == ResultType.SUCCESS) {
425             resultMap.put("Success", "Your application has been updated successfully");
426         } else {
427             resultMap.put("Exception",
428                             "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
429             logger.error(EELFLoggerDelegate.errorLogger, "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded", AppMessages.INCORRECTDATA,
430                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
431             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
432         }
433
434         return response.status(Status.OK).entity(resultMap).build();
435     }
436
437     
438     
439   //Dashboard related calls
440     @GET
441     @Path("/getall")
442     @Produces(MediaType.APPLICATION_JSON)
443     @Consumes(MediaType.APPLICATION_JSON)
444     public List<Application> getall(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws MusicServiceException{
445         List<Application> appList = new ArrayList<>();
446         ResponseBuilder response =
447                 Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
448         if (!authenticator.authenticateAdmin(authorization)) {
449             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
450                     ErrorTypes.AUTHENTICATIONERROR);
451             return appList;
452         }
453         
454         PreparedQueryObject queryObject = new PreparedQueryObject();
455         queryObject.appendQueryString("SELECT *  FROM " + "admin" + "." + "keyspace_master" + ";");
456         ResultSet results = MusicCore.get(queryObject);
457         for(Row row : results) {
458             Application app = new Application();
459             app.setApplication_name(row.getString("application_name"));
460             app.setIs_aaf(row.getBool("is_aaf"));
461             app.setIs_api(row.getBool("is_api"));
462             app.setUsername(row.getString("username"));
463             app.setKeyspace_name(row.getString("keyspace_name"));
464             app.setUuid(row.getUUID("uuid").toString());
465             appList.add(app);
466         }
467         return appList;
468         
469         //return app;
470         
471     }
472     @DELETE
473     @Path("/delete")
474     @Produces(MediaType.APPLICATION_JSON)
475     @Consumes(MediaType.APPLICATION_JSON)
476     public boolean delete(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
477             @ApiParam(value = "uuid", required = true) @HeaderParam("uuid") String uuid) throws Exception {
478         ResponseBuilder response =
479                 Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
480         if (!authenticator.authenticateAdmin(authorization)) {
481             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
482                     ErrorTypes.AUTHENTICATIONERROR);
483             return false;
484         }
485         PreparedQueryObject queryObject = new PreparedQueryObject();
486         queryObject.appendQueryString("delete from admin.keyspace_master where uuid=?");
487         queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),uuid));
488         ResultType result;
489         try {
490          result = MusicCore.nonKeyRelatedPut(queryObject, "eventual");
491         }catch(Exception ex) {
492             return false;
493         }
494         return true;
495     }
496 }