2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * Modifications Copyright (C) 2019 IBM.
7 * ===================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * ============LICENSE_END=============================================
21 * ====================================================================
24 package org.onap.music.datastore;
26 import java.util.HashMap;
29 import org.onap.music.eelf.logging.EELFLoggerDelegate;
30 import org.onap.music.exceptions.MusicServiceException;
31 import org.onap.music.main.MusicUtil;
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 (!"localhost".equals(MusicUtil.getMyCassaHost())) {
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);