• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HotelsDotCom / waggle-dance / #318

pending completion
#318

push

web-flow
Feature/upgrade springboot (#268)

* update springboot to 2.1.18

* update springboot to 2.2.13

* Upgrade to srping boot 2.7.11

* Update changelog

* Update changelog

* fix version

3 of 3 new or added lines in 2 files covered. (100.0%)

132 of 3058 relevant lines covered (4.32%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/mapping/model/MetaStoreMappingImpl.java
1
/**
2
 * Copyright (C) 2016-2021 Expedia, Inc.
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.hotels.bdp.waggledance.mapping.model;
17

18
import java.io.IOException;
19
import java.util.Collections;
20
import java.util.List;
21
import java.util.Locale;
22

23
import org.apache.hadoop.hive.metastore.MetaStoreFilterHook;
24
import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
25
import org.apache.hadoop.hive.metastore.api.Database;
26
import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
27
import org.apache.hadoop.hive.metastore.api.MetaException;
28
import org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore;
29
import org.apache.thrift.TException;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

33
import com.hotels.bdp.waggledance.api.model.ConnectionType;
34
import com.hotels.bdp.waggledance.client.CloseableThriftHiveMetastoreIface;
35
import com.hotels.bdp.waggledance.server.security.AccessControlHandler;
36
import com.hotels.bdp.waggledance.server.security.NotAllowedException;
37

38
class MetaStoreMappingImpl implements MetaStoreMapping {
39

40
  private final static Logger log = LoggerFactory.getLogger(MetaStoreMappingImpl.class);
×
41

42
  private final String databasePrefix;
43
  private final CloseableThriftHiveMetastoreIface client;
44
  private final AccessControlHandler accessControlHandler;
45
  private final String name;
46
  private final long latency;
47
  private final MetaStoreFilterHook metastoreFilter;
48

49
  private final ConnectionType connectionType;
50

51
  MetaStoreMappingImpl(
×
52
      String databasePrefix,
53
      String name,
54
      CloseableThriftHiveMetastoreIface client,
55
      AccessControlHandler accessControlHandler,
56
      ConnectionType connectionType,
57
      long latency,
58
      MetaStoreFilterHook metastoreFilter) {
59
    this.databasePrefix = databasePrefix;
×
60
    this.name = name;
×
61
    this.client = client;
×
62
    this.accessControlHandler = accessControlHandler;
×
63
    this.connectionType = connectionType;
×
64
    this.latency = latency;
×
65
    this.metastoreFilter = metastoreFilter;
×
66
  }
×
67

68
  @Override
69
  public String transformOutboundDatabaseName(String databaseName) {
70
    return databaseName.toLowerCase(Locale.ROOT);
×
71
  }
72

73
  @Override
74
  public List<String> transformOutboundDatabaseNameMultiple(String databaseName) {
75
    return Collections.singletonList(transformInboundDatabaseName(databaseName));
×
76
  }
77

78
  @Override
79
  public ThriftHiveMetastore.Iface getClient() {
80
    return client;
×
81
  }
82

83
  @Override
84
  public MetaStoreFilterHook getMetastoreFilter() {
85
    return metastoreFilter;
×
86
  }
87

88
  @Override
89
  public Database transformOutboundDatabase(Database database) {
90
    database.setName(transformOutboundDatabaseName(database.getName()));
×
91
    return database;
×
92
  }
93

94
  @Override
95
  public String transformInboundDatabaseName(String databaseName) {
96
    return databaseName.toLowerCase(Locale.ROOT);
×
97
  }
98

99
  @Override
100
  public String getDatabasePrefix() {
101
    return databasePrefix;
×
102
  }
103

104
  @Override
105
  public void close() throws IOException {
106
    client.close();
×
107
  }
×
108

109
  @Override
110
  public boolean isAvailable() {
111
    try {
112
      boolean isOpen = client.isOpen();
×
113
      if (isOpen && connectionType == ConnectionType.TUNNELED) {
×
114
        client.getStatus();
×
115
      }
116
      return isOpen;
×
117
    } catch (Exception e) {
×
118
      log.error("Metastore Mapping {} unavailable", name, e);
×
119
      return false;
×
120
    }
121
  }
122

123
  @Override
124
  public MetaStoreMapping checkWritePermissions(String databaseName) {
125
    if (!accessControlHandler.hasWritePermission(databaseName)) {
×
126
      throw new NotAllowedException(
×
127
          "You cannot perform this operation on the virtual database '" + databaseName + "'.");
×
128
    }
129
    return this;
×
130
  }
131

132
  @Override
133
  public void createDatabase(Database database)
134
    throws AlreadyExistsException, InvalidObjectException, MetaException, TException {
135
    if (accessControlHandler.hasCreatePermission()) {
×
136
      getClient().create_database(database);
×
137
      accessControlHandler.databaseCreatedNotification(database.getName());
×
138
    } else {
×
139
      throw new NotAllowedException("You cannot create the database '" + database.getName() + "'.");
×
140
    }
141
  }
×
142

143
  @Override
144
  public String getMetastoreMappingName() {
145
    return name;
×
146
  }
147

148
  @Override
149
  public long getLatency() {
150
    return latency;
×
151
  }
152

153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc