2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * ===================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.datastore;
25 import java.util.HashMap;
28 import org.onap.music.eelf.logging.EELFLoggerDelegate;
29 import org.onap.music.exceptions.MusicServiceException;
30 import org.onap.music.main.MusicUtil;
31 import org.onap.music.service.impl.MusicZKCore;
33 import com.datastax.driver.core.ResultSet;
34 import com.datastax.driver.core.TableMetadata;
36 public class MusicDataStoreHandle {
40 public static MusicDataStore mDstoreHandle = null;
41 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStoreHandle.class);
48 public static MusicDataStore getDSHandle(String remoteIp) {
49 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
50 long start = System.currentTimeMillis();
51 if (mDstoreHandle == null) {
52 mDstoreHandle = new MusicDataStore(remoteIp);
54 long end = System.currentTimeMillis();
55 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
62 * @throws MusicServiceException
64 public static MusicDataStore getDSHandle() throws MusicServiceException {
65 logger.info(EELFLoggerDelegate.metricsLogger,"Acquiring data store handle");
66 long start = System.currentTimeMillis();
67 if (mDstoreHandle == null) {
68 // Quick Fix - Best to put this into every call to getDSHandle?
69 if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
70 mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
72 mDstoreHandle = new MusicDataStore();
75 if(mDstoreHandle.getSession() == null) {
76 String message = "Connection to Cassandra has not been enstablished."
77 + " Please check connection properites and reboot.";
78 logger.info(EELFLoggerDelegate.applicationLogger, message);
79 throw new MusicServiceException(message);
81 long end = System.currentTimeMillis();
82 logger.info(EELFLoggerDelegate.metricsLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
92 * @throws MusicServiceException
94 public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
95 return getDSHandle().returnColumnMetadata(keyspace, tablename);
102 * @throws MusicServiceException
104 public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
105 return getDSHandle().marshalData(results);