OmniSciDB  0b528656ed
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.omnisci.thrift.server.OmniSci;
19 import com.omnisci.thrift.server.TClusterHardwareInfo;
20 import com.omnisci.thrift.server.TColumnType;
21 import com.omnisci.thrift.server.TCopyParams;
22 import com.omnisci.thrift.server.TCreateParams;
23 import com.omnisci.thrift.server.TDBObject;
24 import com.omnisci.thrift.server.TDBObjectType;
25 import com.omnisci.thrift.server.TDashboard;
26 import com.omnisci.thrift.server.TNodeMemoryInfo;
27 import com.omnisci.thrift.server.TOmniSciException;
28 import com.omnisci.thrift.server.TQueryResult;
29 import com.omnisci.thrift.server.TServerStatus;
30 import com.omnisci.thrift.server.TTableDetails;
31 import com.omnisci.thrift.server.TTableMeta;
32 
33 import org.apache.thrift.TException;
34 import org.apache.thrift.protocol.TBinaryProtocol;
35 import org.apache.thrift.protocol.TProtocol;
36 import org.apache.thrift.transport.TSocket;
37 
38 import java.util.Collection;
39 import java.util.HashSet;
40 import java.util.List;
41 
42 public class MapdTestClient {
43  OmniSci.Client client;
44  String sessionId;
45 
46  public TServerStatus get_server_status() throws TOmniSciException, TException {
47  return client.get_server_status(sessionId);
48  }
49 
50  public List<TServerStatus> get_status() throws TOmniSciException, TException {
51  return client.get_status(sessionId);
52  }
53 
54  public TClusterHardwareInfo get_hardware_info() throws TOmniSciException, TException {
55  return client.get_hardware_info(sessionId);
56  }
57 
58  public List<TNodeMemoryInfo> get_memory(String memory_level)
59  throws TOmniSciException, TException {
60  return client.get_memory(sessionId, memory_level);
61  }
62 
63  public TTableDetails get_table_details(String table_name) throws Exception {
64  return client.get_table_details(sessionId, table_name);
65  }
66 
67  public List<TTableMeta> get_tables_meta() throws TOmniSciException, Exception {
68  return client.get_tables_meta(sessionId);
69  }
70 
71  public TQueryResult runSql(String sql) throws Exception {
72  return client.sql_execute(sessionId, sql, true, null, -1, -1);
73  }
74 
75  public List<TColumnType> sqlValidate(String sql) throws Exception {
76  return client.sql_validate(sessionId, sql);
77  }
78 
79  public int create_dashboard(String name) throws Exception {
80  return client.create_dashboard(
81  sessionId, name, "STATE", name + "_hash", name + "_meta");
82  }
83 
84  public void replace_dashboard(
85  int dashboard_id, java.lang.String name, java.lang.String new_owner)
86  throws Exception {
87  client.replace_dashboard(sessionId,
88  dashboard_id,
89  name,
90  new_owner,
91  "STATE",
92  name + "_hash",
93  name + "_meta");
94  }
95 
96  public TDashboard get_dashboard(int id) throws Exception {
97  TDashboard dashboard = client.get_dashboard(sessionId, id);
98  return dashboard;
99  }
100 
101  public void delete_dashboard(int id) throws Exception {
102  client.delete_dashboard(sessionId, id);
103  }
104 
105  public List<TDashboard> get_dashboards() throws Exception {
106  return client.get_dashboards(sessionId);
107  }
108 
109  public void import_table(String table_name, String file_name, TCopyParams copy_params)
110  throws Exception {
111  client.import_table(sessionId, table_name, file_name, copy_params);
112  }
113 
114  public void import_geo_table(String table_name,
115  String file_name,
116  TCopyParams copy_params,
117  java.util.List<TColumnType> row_desc,
118  TCreateParams create_params) throws Exception {
119  client.import_geo_table(
120  sessionId, table_name, file_name, copy_params, row_desc, create_params);
121  }
122 
123  public List<String> get_users() throws Exception {
124  return client.get_users(sessionId);
125  }
126 
127  public List<String> get_roles() throws Exception {
128  return client.get_roles(sessionId);
129  }
130 
131  public List<TDBObject> get_db_object_privs(String objectName, TDBObjectType type)
132  throws Exception {
133  return client.get_db_object_privs(sessionId, objectName, type);
134  }
135 
136  public void disconnect() throws Exception {
137  client.disconnect(sessionId);
138  }
139 
140  public Collection<String> get_all_roles_for_user(String username) throws Exception {
141  List<String> roles = client.get_all_roles_for_user(sessionId, username);
142  return new HashSet<String>(roles);
143  }
144 
145  public static MapdTestClient getClient(
146  String host, int port, String db, String user, String password)
147  throws Exception {
148  TSocket transport = new TSocket(host, port);
149  transport.open();
150  TProtocol protocol = new TBinaryProtocol(transport);
151  OmniSci.Client client = new OmniSci.Client(protocol);
152  MapdTestClient session = new MapdTestClient();
153  session.client = client;
154  session.sessionId = client.connect(user, password, db);
155  return session;
156  }
157 }
List< TNodeMemoryInfo > get_memory(String memory_level)
TTableDetails get_table_details(String table_name)
List< TTableMeta > get_tables_meta()
void import_table(String table_name, String file_name, TCopyParams copy_params)
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)
List< TColumnType > sqlValidate(String sql)
void import_geo_table(String table_name, String file_name, TCopyParams copy_params, java.util.List< TColumnType > row_desc, TCreateParams create_params)
TQueryResult runSql(String sql)
List< TDBObject > get_db_object_privs(String objectName, TDBObjectType type)
TClusterHardwareInfo get_hardware_info()
List< TDashboard > get_dashboards()