OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MapdTestClient.java
Go to the documentation of this file.
1 /*
2  * Copyright 2015 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.mapd.tests;
17 
18 import com.mapd.thrift.server.MapD;
19 import com.mapd.thrift.server.TClusterHardwareInfo;
20 import com.mapd.thrift.server.TDBObject;
21 import com.mapd.thrift.server.TDBObjectType;
22 import com.mapd.thrift.server.TDashboard;
23 import com.mapd.thrift.server.TMapDException;
24 import com.mapd.thrift.server.TQueryResult;
25 import com.mapd.thrift.server.TServerStatus;
26 import com.mapd.thrift.server.TTableDetails;
27 
28 import org.apache.thrift.TException;
29 import org.apache.thrift.protocol.TBinaryProtocol;
30 import org.apache.thrift.protocol.TProtocol;
31 import org.apache.thrift.transport.TSocket;
32 
33 import java.util.Collection;
34 import java.util.HashSet;
35 import java.util.List;
36 
37 public class MapdTestClient {
38  MapD.Client client;
40 
41  public TServerStatus get_server_status() throws TMapDException, TException {
42  return client.get_server_status(sessionId);
43  }
44 
45  public List<TServerStatus> get_status() throws TMapDException, TException {
46  return client.get_status(sessionId);
47  }
48 
49  public TClusterHardwareInfo get_hardware_info() throws TMapDException, TException {
50  return client.get_hardware_info(sessionId);
51  }
52 
53  public TTableDetails get_table_details(String table_name) throws Exception {
54  return client.get_table_details(sessionId, table_name);
55  }
56 
57  public TQueryResult runSql(String sql) throws Exception {
58  return client.sql_execute(sessionId, sql, true, null, -1, -1);
59  }
60 
61  public int create_dashboard(String name) throws Exception {
62  return client.create_dashboard(
63  sessionId, name, "STATE", name + "_hash", name + "_meta");
64  }
65 
66  public void replace_dashboard(
67  int dashboard_id, java.lang.String name, java.lang.String new_owner)
68  throws Exception {
69  client.replace_dashboard(sessionId,
70  dashboard_id,
71  name,
72  new_owner,
73  "STATE",
74  name + "_hash",
75  name + "_meta");
76  }
77 
78  public TDashboard get_dashboard(int id) throws Exception {
79  TDashboard dashboard = client.get_dashboard(sessionId, id);
80  return dashboard;
81  }
82 
83  public void delete_dashboard(int id) throws Exception {
84  client.delete_dashboard(sessionId, id);
85  }
86 
87  public List<TDashboard> get_dashboards() throws Exception {
88  return client.get_dashboards(sessionId);
89  }
90 
91  public List<String> get_users() throws Exception {
92  return client.get_users(sessionId);
93  }
94 
95  public List<String> get_roles() throws Exception {
96  return client.get_roles(sessionId);
97  }
98 
99  public List<TDBObject> get_db_object_privs(String objectName, TDBObjectType type)
100  throws Exception {
101  return client.get_db_object_privs(sessionId, objectName, type);
102  }
103 
104  public void disconnect() throws Exception {
105  client.disconnect(sessionId);
106  }
107 
108  public Collection<String> get_all_roles_for_user(String username) throws Exception {
109  List<String> roles = client.get_all_roles_for_user(sessionId, username);
110  return new HashSet<String>(roles);
111  }
112 
113  public static MapdTestClient getClient(
114  String host, int port, String db, String user, String password)
115  throws Exception {
116  TSocket transport = new TSocket(host, port);
117  transport.open();
118  TProtocol protocol = new TBinaryProtocol(transport);
119  MapD.Client client = new MapD.Client(protocol);
120  MapdTestClient session = new MapdTestClient();
121  session.client = client;
122  session.sessionId = client.connect(user, password, db);
123  return session;
124  }
125 }
TTableDetails get_table_details(String table_name)
TDashboard get_dashboard(int id)
List< TServerStatus > get_status()
void replace_dashboard(int dashboard_id, java.lang.String name, java.lang.String new_owner)
Collection< String > get_all_roles_for_user(String username)
static MapdTestClient getClient(String host, int port, String db, String user, String password)
TQueryResult runSql(String sql)
List< TDBObject > get_db_object_privs(String objectName, TDBObjectType type)
TClusterHardwareInfo get_hardware_info()
List< TDashboard > get_dashboards()