aboutsummaryrefslogtreecommitdiffstats
path: root/music-rest/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
blob: 756856d09b772a379194b0dccb7664a3ec8058fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
/*
 * ============LICENSE_START==========================================
 * org.onap.music
 * ===================================================================
 *  Copyright (c) 2017 AT&T Intellectual Property
 * ===================================================================
 *  Modifications Copyright (c) 2019 Samsung
 * ===================================================================
 *  Modifications Copyright (C) 2019 IBM 
 * ===================================================================
 *  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
 *
 *  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=============================================
 * ====================================================================
 */

package org.onap.music.rest;

import java.util.List;
import java.util.Map;
import java.util.UUID;

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;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.datastore.jsonobjects.JsonIndex;
import org.onap.music.datastore.jsonobjects.JsonInsert;
import org.onap.music.datastore.jsonobjects.JsonKeySpace;
import org.onap.music.datastore.jsonobjects.JsonSelect;
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.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
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.JsonResponse;

import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.TableMetadata;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Example;
import io.swagger.annotations.ExampleProperty;

/* Version 2 Class */
//@Path("/v{version: [0-9]+}/keyspaces")
@Path("/v2/keyspaces")
@Api(value = "Data Api")
public class RestMusicDataAPI {
    /*
     * Header values for Versioning X-minorVersion *** - Used to request or communicate a MINOR
     * version back from the client to the server, and from the server back to the client - This
     * will be the MINOR version requested by the client, or the MINOR version of the last MAJOR
     * version (if not specified by the client on the request) - Contains a single position value
     * (e.g. if the full version is 1.24.5, X-minorVersion = "24") - Is optional for the client on
     * request; however, this header should be provided if the client needs to take advantage of
     * MINOR incremented version functionality - Is mandatory for the server on response
     *
     *** X-patchVersion *** - Used only to communicate a PATCH version in a response for
     * troubleshooting purposes only, and will not be provided by the client on request - This will
     * be the latest PATCH version of the MINOR requested by the client, or the latest PATCH version
     * of the MAJOR (if not specified by the client on the request) - Contains a single position
     * value (e.g. if the full version is 1.24.5, X-patchVersion = "5") - Is mandatory for the
     * server on response  (CURRENTLY NOT USED)
     *
     *** X-latestVersion *** - Used only to communicate an API's latest version - Is mandatory for the
     * server on response, and shall include the entire version of the API (e.g. if the full version
     * is 1.24.5, X-latestVersion = "1.24.5") - Used in the response to inform clients that they are
     * not using the latest version of the API (CURRENTLY NOT USED)
     *
     */

    private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
    private static final String XMINORVERSION = "X-minorVersion";
    private static final String XPATCHVERSION = "X-patchVersion";
    private static final String NS = "ns";
    private static final String VERSION = "v2";
    private static final String PARAMETER_ERROR = "Missing Row Identifier. Please provide the parameter of key=value for the row being selected.";


    private class RowIdentifier {
        public String primarKeyValue;
        public StringBuilder rowIdString;
        @SuppressWarnings("unused")
        public PreparedQueryObject queryObject; // the string with all the row
                                                // identifiers separated by AND

        public RowIdentifier(String primaryKeyValue, StringBuilder rowIdString,
                        PreparedQueryObject queryObject) {
            this.primarKeyValue = primaryKeyValue;
            this.rowIdString = rowIdString;
            this.queryObject = queryObject;
        }
    }


    /**
     * Create Keyspace REST
     *
     * @param kspObject
     * @param keyspaceName
     * @return
     * @throws Exception
     */
    @POST
    @Path("/{name}")
    @ApiOperation(value = "Create Keyspace", response = String.class,
        notes = "This API will not work if MUSIC properties has keyspace.active=false ")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"message\" : \"Keysapce <keyspace> Created\","
                + "\"status\" : \"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })  
    public Response createKeySpace(
        @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns,
        JsonKeySpace kspObject,
        @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
            logger.info(EELFLoggerDelegate.applicationLogger,"In Create Keyspace " + keyspaceName);
            if (MusicUtil.isKeyspaceActive() ) {
                logger.info(EELFLoggerDelegate.applicationLogger,"Creating Keyspace " + keyspaceName);
                
                if(kspObject == null || kspObject.getReplicationInfo() == null) {
                    response.status(Status.BAD_REQUEST);
                    return response.entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult()).toMap()).build();
                }
                ResultType result = ResultType.FAILURE;
                try {
                    kspObject.setKeyspaceName(keyspaceName);
                    result = MusicCore.createKeyspace(kspObject, MusicUtil.EVENTUAL);
                    logger.info(EELFLoggerDelegate.applicationLogger, "result = " + result);
                } catch ( MusicQueryException ex) {
                    logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.QUERYERROR 
                    ,ErrorSeverity.WARN, ErrorTypes.QUERYERROR);
                    return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
                } catch ( MusicServiceException ex) {
                    logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                    return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
                }
        
                return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Keyspace " + keyspaceName + " Created").toMap()).build();
            } else {
                String vError = "Keyspace Creation has been turned off. Contact DBA to create the keyspace or set keyspace.active to true.";
                logger.info(EELFLoggerDelegate.applicationLogger,vError);
                logger.error(EELFLoggerDelegate.errorLogger,vError, AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
                return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(vError).toMap()).build();
            }
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
        
    }

    /**
     *
     * @param kspObject
     * @param keyspaceName
     * @return
     * @throws Exception
     */
    @DELETE
    @Path("/{name}")
    @ApiOperation(value = "Delete Keyspace", response = String.class,
        notes = "This API will not work if MUSIC properties has keyspace.active=false ")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"message\" : \"Keysapce <keyspace> Deleted\","
                + "\"status\" : \"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })  
    public Response dropKeySpace(
        @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) throws Exception {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            EELFLoggerDelegate.mdcPut("keyspace", "( " + keyspaceName + " ) ");
            logger.info(EELFLoggerDelegate.applicationLogger,"In Drop Keyspace " + keyspaceName);
            if (MusicUtil.isKeyspaceActive()) {
                String consistency = MusicUtil.EVENTUAL;// for now this needs only
                String droperror = "Error Deleteing Keyspace " + keyspaceName;
                JsonKeySpace kspObject = new JsonKeySpace();
                kspObject.setKeyspaceName(keyspaceName);
                try{
                    ResultType result = MusicCore.dropKeyspace(kspObject, consistency);
                    if ( result.equals(ResultType.FAILURE) ) {
                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError(droperror).toMap()).build();
                    }
                } catch ( MusicQueryException ex) {
                    logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.QUERYERROR 
                    ,ErrorSeverity.WARN, ErrorTypes.QUERYERROR);
                    return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(droperror + " " + ex.getMessage()).toMap()).build();
                } catch ( MusicServiceException ex) {
                    logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR
                        ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                    return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(droperror + " " + ex.getMessage()).toMap()).build();
                }
                return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Keyspace " + keyspaceName + " Deleted").toMap()).build();
            } else {
                String vError = "Keyspace deletion has been turned off. Contact DBA to delete the keyspace or set keyspace.active to true.";
                logger.info(EELFLoggerDelegate.applicationLogger,vError);
                logger.error(EELFLoggerDelegate.errorLogger,vError, AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
                return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(vError).toMap()).build();
            }
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param tableObj
     * @param version
     * @param keyspace
     * @param tablename
     * @param headers
     * @return
     * @throws Exception -
     */
    @POST
    @Path("/{keyspace: .*}/tables/{tablename: .*}")
    @ApiOperation(value = "Create Table", response = String.class,
        notes = "Create a table with the required json in the body.")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"message\" : \"Tablename <tablename> Created under keyspace <keyspace>\","
                + "\"status\" : \"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })  
    public Response createTable(
        @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        JsonTable tableObj,
        @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if ( null == tableObj ) {
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                        .setError(ResultType.BODYMISSING.getResult()).toMap()).build();
            }
            if(keyspace == null || keyspace.isEmpty() || tablename == null || tablename.isEmpty()){
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                        .setError("One or more path parameters are not set, please check and try again."
                            + "Parameter values: keyspace='" + keyspace + "' tablename='" + tablename + "'")
                            .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
            String consistency = MusicUtil.EVENTUAL;
            // for now this needs only eventual consistency
            ResultType result = ResultType.FAILURE;
            try {
                tableObj.setKeyspaceName(keyspace);
                tableObj.setTableName(tablename);
                result = MusicCore.createTable(tableObj, consistency);
            } catch (MusicQueryException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), ex.getMessage()  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            } catch (MusicServiceException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
                response.status(Status.BAD_REQUEST);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }
            if ( result.equals(ResultType.FAILURE) ) {
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError("Error Creating Table " + tablename).toMap()).build();
            }
            return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("TableName " + tablename.trim() + " Created under keyspace " + keyspace.trim()).toMap()).build();
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param keyspace
     * @param tablename
     * @param fieldName
     * @param info
     * @throws Exception
     */
    @POST
    @Path("/{keyspace: .*}/tables/{tablename: .*}/index/{field: .*}")
    @ApiOperation(value = "Create Index", response = String.class,
        notes = "An index provides a means to access data using attributes "
        + "other than the partition key. The benefit is fast, efficient lookup "
        + "of data matching a given condition.")
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"message\" : \"Index Created on <keyspace>.<table>.<field>\","
                + "\"status\" : \"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"Unknown Error in create index.\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })  
    public Response createIndex(
        @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename,
        @ApiParam(value = "Field Name",required = true) @PathParam("field") String fieldName,
        @Context UriInfo info) throws Exception {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if ((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty()) || (fieldName == null || fieldName.isEmpty())){
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                    .setError("one or more path parameters are not set, please check and try again")
                    .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
            MultivaluedMap<String, String> rowParams = info.getQueryParameters();
            String indexName = "";
            if (rowParams.getFirst("index_name") != null)
                indexName = rowParams.getFirst("index_name");
            
            JsonIndex jsonIndexObject = new JsonIndex(indexName, keyspace, tablename, fieldName);
            
            ResultType result = ResultType.FAILURE;
            try {
                result = MusicCore.createIndex(jsonIndexObject, MusicUtil.EVENTUAL);
            } catch (MusicServiceException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
                .CRITICAL, ErrorTypes.GENERALSERVICEERROR, ex);
                response.status(Status.BAD_REQUEST);
                return response.entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }
            if ( result.equals(ResultType.SUCCESS) ) {
                return response.status(Status.OK).entity(new JsonResponse(result).setMessage("Index Created on " + keyspace+"."+tablename+"."+fieldName).toMap()).build();
            } else {
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError("Unknown Error in create index.").toMap()).build();
            }
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param insObj
     * @param keyspace
     * @param tablename
     * @return
     * @throws Exception
     */
    @POST
    @Path("/{keyspace: .*}/tables/{tablename: .*}/rows")
    @ApiOperation(value = "Insert Into Table", response = String.class,
        notes = "Insert into table with data in json body.")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"message\" : \"Insert Successful\","
                + "\"status\" : \"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure - Generic",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })  
    public Response insertIntoTable(
        @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        JsonInsert insObj,
        @ApiParam(value = "Keyspace Name",
            required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name",
            required = true) @PathParam("tablename") String tablename) {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if ( null == insObj ) {
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                        .setError(ResultType.BODYMISSING.getResult()).toMap()).build();
            }
            if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){
            return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                .setError("one or more path parameters are not set, please check and try again")
                .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace","(" + keyspace + ")");
            ReturnType result = null;
            String consistency = insObj.getConsistencyInfo().get("type");
            try {
                insObj.setKeyspaceName(keyspace);
                insObj.setTableName(tablename);
                if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
                    String lockId = insObj.getConsistencyInfo().get("lockId");
                    if(lockId == null) {
                        logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
                                + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
                                + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
                    }
                }
                result = MusicCore.insertIntoTable(insObj);
            }catch (MusicQueryException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), ex.getMessage()  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }catch (Exception ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
                    .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }
            if (result==null) {
                logger.error(EELFLoggerDelegate.errorLogger,"Null result - Please Contact admin", AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
            }else if(result.getResult() == ResultType.FAILURE) {
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result.getResult()).setError(result.getMessage()).toMap()).build();
            }
            return response.status(Status.OK).entity(new JsonResponse(result.getResult()).setMessage("Insert Successful").toMap()).build();
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param insObj
     * @param keyspace
     * @param tablename
     * @param info
     * @return
     * @throws MusicServiceException 
     * @throws MusicQueryException 
     * @throws Exception
     */
    @PUT
    @Path("/{keyspace: .*}/tables/{tablename: .*}/rows")
    @ApiOperation(value = "Update Table", response = String.class,
        notes = "Update the table with the data in the JSON body.")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response updateTable(
        @ApiParam(value = "Major Version",
            required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",
            required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",
            required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",
            required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        JsonUpdate updateObj,
        @ApiParam(value = "Keyspace Name",
            required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name",
            required = true) @PathParam("tablename") String tablename,
        @Context UriInfo info) throws MusicQueryException, MusicServiceException {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if ( null == updateObj ) {
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                        .setError(ResultType.BODYMISSING.getResult()).toMap()).build();
            }
            if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                    .setError("one or more path parameters are not set, please check and try again")
                    .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
            long startTime = System.currentTimeMillis();
            String operationId = UUID.randomUUID().toString();  // just for infoging
                                                                // purposes.
            String consistency = updateObj.getConsistencyInfo().get("type");
            ReturnType operationResult = null;
            logger.info(EELFLoggerDelegate.applicationLogger, "--------------Music " + consistency
                + " update-" + operationId + "-------------------------");
            
            updateObj.setKeyspaceName(keyspace);
            updateObj.setTableName(tablename);
            
            try {
                if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
                    String lockId = updateObj.getConsistencyInfo().get("lockId");
                    if(lockId == null) {
                        logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
                                + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
                                + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
                    }
                }
                operationResult = MusicCore.updateTable(updateObj,info.getQueryParameters());
            }catch (MusicLockingException e) {
                 logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN,
                            ErrorTypes.GENERALSERVICEERROR, e);
                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
            }catch (MusicQueryException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), ex.getMessage()  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }catch (Exception ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }
            long actualUpdateCompletionTime = System.currentTimeMillis();

            long endTime = System.currentTimeMillis();
            long jsonParseCompletionTime = System.currentTimeMillis();
            String timingString = "Time taken in ms for Music " + consistency + " update-" + operationId
                + ":" + "|total operation time:" + (endTime - startTime)
                + "|json parsing time:" + (jsonParseCompletionTime - startTime)
                + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
                + "|";

            if (operationResult != null && operationResult.getTimingInfo() != null) {
                String lockManagementTime = operationResult.getTimingInfo();
                timingString = timingString + lockManagementTime;
            }
            logger.info(EELFLoggerDelegate.applicationLogger, timingString);

            if (operationResult==null) {
                logger.error(EELFLoggerDelegate.errorLogger,"Null result - Please Contact admin", AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
            }
            if ( operationResult.getResult() == ResultType.SUCCESS ) {
                return response.status(Status.OK).entity(new JsonResponse(operationResult.getResult()).setMessage(operationResult.getMessage()).toMap()).build();
            } else {
                logger.error(EELFLoggerDelegate.errorLogger,operationResult.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(operationResult.getResult()).setError(operationResult.getMessage()).toMap()).build();
            }
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param delObj
     * @param keyspace
     * @param tablename
     * @param info
     * @return
     * @throws MusicServiceException 
     * @throws MusicQueryException 
     * @throws Exception
     */
    @DELETE
    @Path("/{keyspace: .*}/tables/{tablename: .*}/rows")
    @ApiOperation(value = "Delete From table", response = String.class,
        notes = "Delete from a table, the row or parts of a row. Based on JSON body.")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response deleteFromTable(
        @ApiParam(value = "Major Version",
            required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",
            required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",
            required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",
            required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        JsonDelete delObj,
        @ApiParam(value = "Keyspace Name",
            required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name",
            required = true) @PathParam("tablename") String tablename,
        @Context UriInfo info) throws MusicQueryException, MusicServiceException {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                    .setError("one or more path parameters are not set, please check and try again")
                    .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
            if(delObj == null) {
                logger.error(EELFLoggerDelegate.errorLogger,ResultType.BODYMISSING.getResult(), AppMessages.MISSINGDATA  ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult()).toMap()).build();
            }
            ReturnType operationResult = null;
            String consistency = delObj.getConsistencyInfo().get("type");
            delObj.setKeyspaceName(keyspace);
            delObj.setTableName(tablename);
            try {
                if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
                    String lockId = delObj.getConsistencyInfo().get("lockId");
                    if(lockId == null) {
                        logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
                            + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
                            + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
                    }
                }
                
                operationResult = MusicCore.deleteFromTable(delObj,info.getQueryParameters());
            } catch (MusicQueryException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), ex.getMessage()  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
                
            } catch (MusicLockingException e) {
                logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR, e);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                        .setError("Unable to perform Delete operation. Exception from music").toMap()).build();
            }
            if (operationResult==null) {
                logger.error(EELFLoggerDelegate.errorLogger,"Null result - Please Contact admin", AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
            }
            if (operationResult.getResult().equals(ResultType.SUCCESS)) {
                return response.status(Status.OK).entity(new JsonResponse(operationResult.getResult()).setMessage(operationResult.getMessage()).toMap()).build();
            } else {
                logger.error(EELFLoggerDelegate.errorLogger,operationResult.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(operationResult.getMessage()).toMap()).build();
            }
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param tabObj
     * @param keyspace
     * @param tablename
     * @throws Exception
     */
    @DELETE
    @Path("/{keyspace: .*}/tables/{tablename: .*}")
    @ApiOperation(value = "Drop Table", response = String.class)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"status\" : \"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })
    public Response dropTable(
        @ApiParam(value = "Major Version",
            required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",
            required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",
            required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",
            required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        @ApiParam(value = "Keyspace Name",
            required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name",
            required = true) @PathParam("tablename") String tablename) throws Exception {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                    .setError("one or more path parameters are not set, please check and try again")
                    .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
            JsonTable jsonTable = new JsonTable();
            jsonTable.setKeyspaceName(keyspace);
            jsonTable.setTableName(tablename);
            try {
                return response.status(Status.OK).entity(new JsonResponse(MusicCore.dropTable(jsonTable, MusicUtil.EVENTUAL)).toMap()).build();
            } catch (MusicQueryException ex) {
                logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.WARN
                    , ErrorTypes.QUERYERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            } catch (MusicServiceException ex) {
                logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(), AppMessages.MISSINGINFO  ,ErrorSeverity.WARN
                , ErrorTypes.GENERALSERVICEERROR,ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param selObj
     * @param keyspace
     * @param tablename
     * @param info
     * @return
     */
    @PUT
    @Path("/{keyspace: .*}/tables/{tablename: .*}/rows/criticalget")
    @ApiOperation(value = "** Depreciated ** - Select Critical", response = Map.class,
        notes = "This API is depreciated in favor of the regular select api.\n"
        + "Avaliable to use with the select api by providing a minorVersion of 1 "
        + "and patchVersion of 0.\n"
        + "Critical Get requires parameter rowId=value and consistency in order to work.\n"
        + "It will fail if either are missing.")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"result\":{\"row 0\":{\"address\":"
                + "{\"city\":\"Someplace\",\"street\":\"1 Some way\"},"
                + "\"emp_salary\":50,\"emp_name\":\"tom\",\"emp_id\":"
                + "\"cfd66ccc-d857-4e90-b1e5-df98a3d40cd6\"}},\"status\":\"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })
    public Response selectCritical(
        @ApiParam(value = "Major Version",
    required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",example = "0",
            required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",example = "0",
            required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",
            required = false, hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        JsonInsert selObj,
        @ApiParam(value = "Keyspace Name",
            required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name",
            required = true) @PathParam("tablename") String tablename,
        @Context UriInfo info) throws Exception {
        try {
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())) { 
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                    .setError("one or more path parameters are not set, please check and try again")
                    .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace", "( " + keyspace + " )");
            if (info.getQueryParameters().isEmpty()) {
                logger.error(EELFLoggerDelegate.errorLogger,RestMusicDataAPI.PARAMETER_ERROR, AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes
                .GENERALSERVICEERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(RestMusicDataAPI.PARAMETER_ERROR).toMap()).build();
            }
            if (selObj == null || selObj.getConsistencyInfo().isEmpty()) {
                String error = " Missing Body or Consistency type.";
                logger.error(EELFLoggerDelegate.errorLogger,ResultType.BODYMISSING.getResult() + error, AppMessages.MISSINGDATA  ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ResultType.BODYMISSING.getResult() + error).toMap()).build();
            }
            ResultSet results = null;
            String consistency = selObj.getConsistencyInfo().get("type");
            String lockId = selObj.getConsistencyInfo().get("lockId");
            selObj.setKeyspaceName(keyspace);
            selObj.setTableName(tablename);
            try {
                if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
                    if(lockId == null) {
                        logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
                            + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
                        return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
                            + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
                    }
                }
                results = MusicCore.selectCritical(selObj, info.getQueryParameters());
            }catch (MusicQueryException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), ex.getMessage()  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
                
            }catch(Exception ex) {
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }

            if(results!=null && results.getAvailableWithoutFetching() >0) {
                return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicDataStoreHandle.marshallResults(results)).toMap()).build();
            }
            return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setError("No data found").toMap()).build();
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     * This API will replace the original select and provide a single API fro select and critical. 
     * The idea is to depreciate the older api of criticalGet and use a single API. 
     * 
     * @param selObj
     * @param keyspace
     * @param tablename
     * @param info
     * @return
     */
    @GET
    @Path("/{keyspace: .*}/tables/{tablename: .*}/rows")
    @ApiOperation(value = "Select", response = Map.class,
        notes = "This has 2 versions: if minorVersion and patchVersion is null or 0, this will be a Eventual Select only.\n"
        + "If minorVersion is 1 and patchVersion is 0, this will act like the Critical Select \n"
        + "Critical Get requires parameter rowId=value and consistency in order to work.\n"
        + "If parameters are missing or consistency information is missing. An eventual select will be preformed.")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiResponses(value={
        @ApiResponse(code=200, message = "Success",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"result\":{\"row 0\":{\"address\":"
                + "{\"city\":\"Someplace\",\"street\":\"1 Some way\"},"
                + "\"emp_salary\":50,\"emp_name\":\"tom\",\"emp_id\":"
                + "\"cfd66ccc-d857-4e90-b1e5-df98a3d40cd6\"}},\"status\":\"SUCCESS\"}")
        })),
        @ApiResponse(code=400, message = "Failure",examples = @Example( value =  {
            @ExampleProperty(mediaType="application/json",value = 
                "{\"error\" : \"<errorMessage>\","
                + "\"status\" : \"FAILURE\"}") 
        }))
    })
    public Response selectWithCritical(
        @ApiParam(value = "Major Version",example = "v2", 
            required = true) @PathParam("version") String version,
        @ApiParam(value = "Minor Version",example = "1",
            required = false) @HeaderParam(XMINORVERSION) String minorVersion,
        @ApiParam(value = "Patch Version",example = "0",
            required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
        @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
        @ApiParam(value = "Application namespace",
            required = false,hidden = true) @HeaderParam(NS) String ns,
        @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
        JsonInsert selObj,
        @ApiParam(value = "Keyspace Name", required = true) @PathParam("keyspace") String keyspace,
        @ApiParam(value = "Table Name", required = true) @PathParam("tablename") String tablename,
        @Context UriInfo info) throws Exception {
        if ((minorVersion != null && patchVersion != null) &&
            (Integer.parseInt(minorVersion) == 1 && Integer.parseInt(patchVersion) == 0) &&
            (!(null == selObj) && !selObj.getConsistencyInfo().isEmpty())) {
            return selectCritical(version, minorVersion, patchVersion, aid, ns, authorization, selObj, keyspace, tablename, info);
        } else {
            return select(version, minorVersion, patchVersion, aid, ns, authorization, keyspace, tablename, info);
        }
    }

    /**
     *
     * @param keyspace
     * @param tablename
     * @param info
     * @return
     * @throws Exception
     */
    private Response select(
        String version,String minorVersion,String patchVersion,
        String aid,String ns,String authorization,String keyspace,        
        String tablename,UriInfo info) throws Exception {
        try { 
            ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
            if((keyspace == null || keyspace.isEmpty()) || (tablename == null || tablename.isEmpty())){
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
                    .setError("one or more path parameters are not set, please check and try again")
                    .toMap()).build();
            }
            EELFLoggerDelegate.mdcPut("keyspace", "( " + keyspace + " ) ");
            try {
                JsonSelect jsonSelect = new JsonSelect();
                jsonSelect.setKeyspaceName(keyspace);
                jsonSelect.setTableName(tablename);
                ResultSet results = MusicCore.select(jsonSelect, info.getQueryParameters());
                if(results.getAvailableWithoutFetching() >0) {
                    return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicDataStoreHandle.marshallResults(results)).toMap()).build();
                }
                return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicDataStoreHandle.marshallResults(results)).setError("No data found").toMap()).build();
            } catch (MusicQueryException ex) {
                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), ex.getMessage()  ,ErrorSeverity
                        .WARN, ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
                
            } catch (MusicServiceException ex) {
                logger.error(EELFLoggerDelegate.errorLogger, ex, AppMessages.UNKNOWNERROR  ,ErrorSeverity.ERROR,
                    ErrorTypes.MUSICSERVICEERROR, ex);
                return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
            }
        } finally {
            EELFLoggerDelegate.mdcRemove("keyspace");
        }
    }

    /**
     *
     * @param keyspace
     * @param tablename
     * @param info
     * @param limit
     * @return
     * @throws MusicServiceException
     */
    public PreparedQueryObject selectSpecificQuery(String keyspace,
        String tablename, UriInfo info, int limit)
        throws MusicServiceException {
        PreparedQueryObject queryObject = new PreparedQueryObject();
        StringBuilder rowIdString = getRowIdentifier(keyspace, 
            tablename,info.getQueryParameters(),queryObject).rowIdString;
        queryObject.appendQueryString(
            "SELECT *  FROM " + keyspace + "." + tablename + " WHERE " + rowIdString);
        if (limit != -1) {
            queryObject.appendQueryString(" LIMIT " + limit);
        }
        queryObject.appendQueryString(";");
        return queryObject;
    }

    /**
     *
     * @param keyspace
     * @param tablename
     * @param rowParams
     * @param queryObject
     * @return
     * @throws MusicServiceException
     */
    private RowIdentifier getRowIdentifier(String keyspace, String tablename,
        MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject)
        throws MusicServiceException {
        StringBuilder rowSpec = new StringBuilder();
        int counter = 0;
        TableMetadata tableInfo = MusicDataStoreHandle.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();
            List<String> valueList = entry.getValue();
            String indValue = valueList.get(0);
            DataType colType = null;
            Object formattedValue = null;
            try {
                colType = tableInfo.getColumn(entry.getKey()).getType();
                formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
            } catch (Exception e) {
                logger.error(EELFLoggerDelegate.errorLogger,e);
            }
            if(tableInfo.getPrimaryKey().get(0).getName().equals(entry.getKey())) {
                primaryKey.append(indValue);
            }
            rowSpec.append(keyName + "= ?");
            queryObject.addValue(formattedValue);
            if (counter != rowParams.size() - 1) {
                rowSpec.append(" AND ");
            }
            counter = counter + 1;
        }
        return new RowIdentifier(primaryKey.toString(), rowSpec, queryObject);
    }
}