0
# Service Management
1
2
Core service layer components providing CLI service implementation and composite service functionality for the Thrift server.
3
4
## Capabilities
5
6
### SparkSQLCLIService
7
8
Main CLI service implementation that provides the interface between Hive CLI service and Spark SQL.
9
10
```scala { .api }
11
/**
12
* Spark SQL implementation of Hive CLI service
13
* @param hiveServer The parent HiveServer2 instance
14
* @param sqlContext The SQL context for this service
15
*/
16
private[hive] class SparkSQLCLIService(hiveServer: HiveServer2, sqlContext: SQLContext)
17
extends CLIService(hiveServer) with ReflectedCompositeService {
18
19
/**
20
* Initialize the CLI service with Hive configuration
21
* @param hiveConf Hive configuration object
22
*/
23
override def init(hiveConf: HiveConf): Unit
24
25
/**
26
* Get server information for client requests
27
* @param sessionHandle Session handle for the request
28
* @param getInfoType Type of information requested
29
* @return GetInfoValue containing the requested information
30
*/
31
override def getInfo(sessionHandle: SessionHandle, getInfoType: GetInfoType): GetInfoValue
32
}
33
```
34
35
**Service Information Provided:**
36
- `CLI_SERVER_NAME`: Returns "Spark SQL"
37
- `CLI_DBMS_NAME`: Returns "Spark SQL"
38
- `CLI_DBMS_VER`: Returns the Spark version from SparkContext
39
- Other info types: Delegated to parent CLIService
40
41
### ReflectedCompositeService
42
43
Trait providing composite service functionality using reflection to work with Hive service hierarchy.
44
45
```scala { .api }
46
/**
47
* Trait for services that need composite service functionality via reflection
48
*/
49
private[thriftserver] trait ReflectedCompositeService {
50
this: AbstractService =>
51
52
/**
53
* Initialize composite service and all child services
54
* @param hiveConf Hive configuration to apply
55
*/
56
def initCompositeService(hiveConf: HiveConf): Unit
57
}
58
```
59
60
## Service Hierarchy
61
62
The service management follows this hierarchy:
63
64
```
65
HiveThriftServer2 (extends HiveServer2)
66
├── SparkSQLCLIService (extends CLIService)
67
│ └── SparkSQLSessionManager (extends SessionManager)
68
│ └── SparkSQLOperationManager (extends OperationManager)
69
└── ThriftCLIService (ThriftBinaryCLIService or ThriftHttpCLIService)
70
```
71
72
## Authentication Support
73
74
The SparkSQLCLIService provides comprehensive authentication support:
75
76
**Kerberos Authentication:**
77
- Configuration via `hive.server2.authentication.kerberos.principal`
78
- Keytab configuration via `hive.server2.authentication.kerberos.keytab`
79
- Automatic UGI (UserGroupInformation) management
80
- Service principal validation and login
81
82
**SPNEGO Authentication:**
83
- Configuration via `hive.server2.authentication.spnego.principal`
84
- Keytab configuration via `hive.server2.authentication.spnego.keytab`
85
- HTTP authentication support for web-based clients
86
87
## Security Features
88
89
**Service UGI Management:**
90
- Automatic login from keytab when security is enabled
91
- Service UGI creation and management
92
- HTTP UGI for SPNEGO authentication
93
- Integration with Hadoop security framework
94
95
**Configuration Validation:**
96
- Principal and keytab file validation
97
- Security configuration error handling
98
- LoginException and IOException handling
99
100
## Usage Example
101
102
```scala
103
import org.apache.spark.sql.hive.thriftserver.SparkSQLCLIService
104
import org.apache.hadoop.hive.conf.HiveConf
105
import org.apache.hive.service.server.HiveServer2
106
107
// Create CLI service (typically done by HiveThriftServer2)
108
val hiveServer = new HiveServer2()
109
val sparkSqlCliService = new SparkSQLCLIService(hiveServer, sqlContext)
110
111
// Configure Hive settings
112
val hiveConf = new HiveConf()
113
hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT, "10000")
114
115
// Initialize the service
116
sparkSqlCliService.init(hiveConf)
117
118
// Service is now ready to handle client connections
119
```
120
121
## Types
122
123
### Required Imports
124
125
```scala { .api }
126
import java.io.IOException
127
import java.util.{List => JList}
128
import javax.security.auth.login.LoginException
129
import org.apache.hadoop.hive.conf.HiveConf
130
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
131
import org.apache.hadoop.security.UserGroupInformation
132
import org.apache.hive.service.{AbstractService, Service, ServiceException}
133
import org.apache.hive.service.Service.STATE
134
import org.apache.hive.service.auth.HiveAuthFactory
135
import org.apache.hive.service.cli._
136
import org.apache.hive.service.server.HiveServer2
137
import org.apache.spark.sql.SQLContext
138
```