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

HotelsDotCom / waggle-dance / #391

19 Apr 2024 02:19PM UTC coverage: 73.279% (-0.3%) from 73.587%
#391

push

web-flow
Added extensions and Rate limiting options (#314)

* Added extensions and Rate limiting options

120 of 169 new or added lines in 18 files covered. (71.01%)

5 existing lines in 1 file now uncovered.

2523 of 3443 relevant lines covered (73.28%)

0.73 hits per line

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

87.5
/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/server/ExceptionWrappingHMSHandler.java
1
/**
2
 * Copyright (C) 2016-2024 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.server;
17

18
import java.lang.reflect.InvocationHandler;
19
import java.lang.reflect.InvocationTargetException;
20
import java.lang.reflect.Method;
21
import java.lang.reflect.Proxy;
22
import java.lang.reflect.UndeclaredThrowableException;
23
import java.util.Arrays;
24

25
import org.apache.commons.lang3.StringUtils;
26
import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
27
import org.apache.hadoop.hive.metastore.IHMSHandler;
28
import org.apache.hadoop.hive.metastore.api.MetaException;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

32
import com.hotels.bdp.waggledance.server.security.NotAllowedException;
33

34
public class ExceptionWrappingHMSHandler implements InvocationHandler {
35

36
  private final static Logger LOG = LoggerFactory.getLogger(ExceptionWrappingHMSHandler.class);
1✔
37

38
  private final IHMSHandler baseHandler;
39
  private String user = "";
1✔
40

41
  public static IHMSHandler newProxyInstance(IHMSHandler baseHandler) {
42
    return (IHMSHandler) Proxy
1✔
43
        .newProxyInstance(ExceptionWrappingHMSHandler.class.getClassLoader(), new Class[] { IHMSHandler.class },
1✔
44
            new ExceptionWrappingHMSHandler(baseHandler));
1✔
45
  }
46

47
  public ExceptionWrappingHMSHandler(IHMSHandler baseHandler) {
1✔
48
    this.baseHandler = baseHandler;
1✔
49
  }
1✔
50

51
  @Override
52
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
53
    if (method.getName().equals("set_ugi")) {
1✔
NEW
54
      user = (String) args[0];
×
55
    }
56
    try {
57
      LOG
1✔
58
          .info("WD Audit:[User:{}, method:{}, source_ip:{}, args:{}]", user, method.getName(),
1✔
59
              HMSHandler.getThreadLocalIpAddress(), StringUtils.left(Arrays.toString(args), 256));
1✔
60
      return method.invoke(baseHandler, args);
1✔
61
    } catch (InvocationTargetException e) {
1✔
62
      Throwable cause = e.getCause();
1✔
63
      if (cause instanceof NotAllowedException) {
1✔
64
        // not logging this as this is an "expected" exception, just rewriting it so any client can do something with
65
        // the thrift exception.
66
        throw new MetaException("Waggle Dance: " + cause.getMessage());
1✔
67
      } else if (cause instanceof WaggleDanceServerException) {
1✔
68
        LOG.debug("Got error processing '{}' with args '{}'", method, Arrays.toString(args), cause);
1✔
69
        throw new MetaException("Waggle Dance: " + cause.getMessage());
1✔
70
      } else {
71
        // Need to unwrap this, so callers get the correct exception thrown by the handler.
72
        throw e.getCause();
1✔
73
      }
74
    } catch (UndeclaredThrowableException e) {
×
75
      // Need to unwrap this, so callers get the correct exception thrown by the handler.
76
      throw e.getCause();
×
77
    }
78
  }
79

80
}
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

© 2025 Coveralls, Inc