- MusicCore.nonKeyRelatedPut(queryObject, consistency);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity
- .WARN, ErrorTypes.MUSICSERVICEERROR, e);
- }
-
- try {
- boolean isAAF = Boolean.valueOf(CachingUtil.isAAFApplication(ns));
- String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
- queryObject = new PreparedQueryObject();
- queryObject.appendQueryString(
- "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), aid));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, ns);
- CachingUtil.updateMusicValidateCache(ns, userId, hashedpwd);
- MusicCore.eventualPut(queryObject);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity
- .WARN, ErrorTypes.MUSICSERVICEERROR, e);
- return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
+ long end = System.currentTimeMillis();
+ logger.info(EELFLoggerDelegate.applicationLogger,
+ "Time taken for setting up query in create keyspace:" + (end - start));
+
+ ResultType result = ResultType.FAILURE;
+ try {
+ result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ logger.info(EELFLoggerDelegate.applicationLogger, "result = " + result);
+ } 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("err:" + ex.getMessage()).toMap()).build();
+ }
+
+ try {
+ queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("CREATE ROLE IF NOT EXISTS '" + userId
+ + "' WITH PASSWORD = '" + password + "' AND LOGIN = true;");
+ MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName
+ + " to '" + userId + "'");
+ queryObject.appendQueryString(";");
+ MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity
+ .WARN, ErrorTypes.MUSICSERVICEERROR, e);
+ }
+
+ try {
+ boolean isAAF = Boolean.valueOf(CachingUtil.isAAFApplication(ns));
+ String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
+ queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), aid));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+ CachingUtil.updateMusicCache(keyspaceName, ns);
+ CachingUtil.updateMusicValidateCache(ns, userId, hashedpwd);
+ MusicCore.eventualPut(queryObject);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity
+ .WARN, ErrorTypes.MUSICSERVICEERROR, e);
+ return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.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();