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