You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ni...@apache.org on 2016/12/28 09:33:21 UTC
[21/23] ambari git commit: AMBARI-19302 : removed contrib/views/hive
folder and made necessary changes in pom.xml files (nitirajrathore)
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
deleted file mode 100644
index 13f93c3..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Utils.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.client;
-
-import org.apache.hive.service.cli.thrift.TStatus;
-import org.apache.hive.service.cli.thrift.TStatusCode;
-import org.apache.http.client.CookieStore;
-import org.apache.http.cookie.Cookie;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class Utils {
- // This value is set to true by the setServiceUnavailableRetryStrategy() when the server returns 401
- static final String HIVE_SERVER2_RETRY_KEY = "hive.server2.retryserver";
- static final String HIVE_SERVER2_RETRY_TRUE = "true";
- static final String HIVE_SERVER2_RETRY_FALSE = "false";
-
- static final String HIVE_COMPILE_ERROR_MSG = "Error while compiling statement:";
-
- static void verifySuccess(TStatus status, String comment) throws HiveClientException {
- if (status.getStatusCode() != TStatusCode.SUCCESS_STATUS &&
- status.getStatusCode() != TStatusCode.SUCCESS_WITH_INFO_STATUS) {
- String message = (status.getErrorMessage() != null) ? status.getErrorMessage() : "";
-
- // For schemantic exception Error code is between 10000-19999
- // https://issues.apache.org/jira/browse/HIVE-3001
- // https://issues.apache.org/jira/browse/HIVE-12867
- if((status.getErrorCode() >= 10000 && status.getErrorCode() <= 19999)|| message.contains(HIVE_COMPILE_ERROR_MSG)){
- throw new HiveInvalidQueryException(status.getStatusCode(),message);
- }
- throw new HiveErrorStatusException(status.getStatusCode(), comment + ". " + message);
- }
- }
-
- static boolean needToSendCredentials(CookieStore cookieStore, String cookieName, boolean isSSL) {
- if (cookieName == null || cookieStore == null) {
- return true;
- }
-
- List<Cookie> cookies = cookieStore.getCookies();
-
- for (Cookie c : cookies) {
- // If this is a secured cookie and the current connection is non-secured,
- // then, skip this cookie. We need to skip this cookie because, the cookie
- // replay will not be transmitted to the server.
- if (c.isSecure() && !isSSL) {
- continue;
- }
- if (c.getName().equals(cookieName)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Removes the empty strings and returns back only the strings with content
- */
- static String[] removeEmptyStrings(String[] strs) {
- List<String> nonEmptyStrings = new ArrayList<>();
- for(String str : strs) {
- if (!(str == null || str.trim().isEmpty())) {
- nonEmptyStrings.add(str.trim());
- }
- }
- return nonEmptyStrings.toArray(new String[] {});
- }
-
- public static class HiveAuthenticationParams {
- public static final String AUTH_TYPE = "auth";
- // We're deprecating this variable's name.
- public static final String AUTH_QOP_DEPRECATED = "sasl.qop";
- public static final String AUTH_QOP = "saslQop";
- public static final String AUTH_SIMPLE = "noSasl";
- public static final String AUTH_TOKEN = "delegationToken";
- public static final String AUTH_USER = "user";
- public static final String HS2_PROXY_USER = "hive.server2.proxy.user";
- public static final String AUTH_PRINCIPAL = "principal";
- public static final String AUTH_PASSWD = "password";
- public static final String AUTH_KERBEROS_AUTH_TYPE = "kerberosAuthType";
- public static final String AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT = "fromSubject";
- public static final String ANONYMOUS_USER = "anonymous";
- public static final String ANONYMOUS_PASSWD = "anonymous";
- public static final String USE_SSL = "ssl";
- public static final String SSL_TRUST_STORE = "sslTrustStore";
- public static final String SSL_TRUST_STORE_PASSWORD = "trustStorePassword";
- // We're deprecating the name and placement of this in the parsed map (from hive conf vars to
- // hive session vars).
- public static final String TRANSPORT_MODE_DEPRECATED = "hive.server2.transport.mode";
- public static final String TRANSPORT_MODE = "transportMode";
- // We're deprecating the name and placement of this in the parsed map (from hive conf vars to
- // hive session vars).
- public static final String HTTP_PATH_DEPRECATED = "hive.server2.thrift.http.path";
- public static final String HTTP_PATH = "httpPath";
- public static final String SERVICE_DISCOVERY_MODE = "serviceDiscoveryMode";
- // Don't use dynamic service discovery
- public static final String SERVICE_DISCOVERY_MODE_NONE = "none";
- // Use ZooKeeper for indirection while using dynamic service discovery
- public static final String SERVICE_DISCOVERY_MODE_ZOOKEEPER = "zooKeeper";
- public static final String ZOOKEEPER_NAMESPACE = "zooKeeperNamespace";
- // Default namespace value on ZooKeeper.
- // This value is used if the param "zooKeeperNamespace" is not specified in the JDBC Uri.
- public static final String ZOOKEEPER_DEFAULT_NAMESPACE = "hiveserver2";
- // Non-configurable params:
- // Currently supports JKS keystore format
- public static final String SSL_TRUST_STORE_TYPE = "JKS";
- static final String COOKIE_AUTH = "cookieAuth";
- static final String COOKIE_AUTH_FALSE = "false";
- static final String COOKIE_NAME = "cookieName";
- // The default value of the cookie name when CookieAuth=true
- static final String DEFAULT_COOKIE_NAMES_HS2 = "hive.server2.auth";
- static final String HTTP_HEADER_PREFIX = "http.header.";
- // --------------- Begin 2 way ssl options -------------------------
- // Use two way ssl. This param will take effect only when ssl=true
- static final String USE_TWO_WAY_SSL = "twoWay";
- static final String TRUE = "true";
- static final String SSL_KEY_STORE = "sslKeyStore";
- static final String SSL_KEY_STORE_PASSWORD = "keyStorePassword";
- static final String SSL_KEY_STORE_TYPE = "JKS";
- static final String SUNX509_ALGORITHM_STRING = "SunX509";
- // --------------- End 2 way ssl options ----------------------------
- static final String SUNJSSE_ALGORITHM_STRING = "SunJSSE";
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/ViewSessionState.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/ViewSessionState.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/ViewSessionState.java
deleted file mode 100644
index aa6cd47..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/ViewSessionState.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.client;
-
-import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hadoop.hive.ql.session.SessionState;
-
-public class ViewSessionState extends SessionState {
- public ViewSessionState(HiveConf conf) {
- super(conf);
- }
-
- public ViewSessionState(HiveConf conf, String userName) {
- super(conf, userName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/DataStoreStorage.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/DataStoreStorage.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/DataStoreStorage.java
deleted file mode 100644
index 5457a5c..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/DataStoreStorage.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence;
-
-import org.apache.ambari.view.PersistenceException;
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
-import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy;
-import org.apache.ambari.view.hive.utils.ServiceFormattedException;
-import org.apache.commons.beanutils.BeanUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.WebApplicationException;
-import java.beans.Transient;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Engine for storing objects to context DataStore storage
- */
-public class DataStoreStorage implements Storage {
- private final static Logger LOG =
- LoggerFactory.getLogger(DataStoreStorage.class);
-
- protected ViewContext context;
-
- /**
- * Constructor
- * @param context View Context instance
- */
- public DataStoreStorage(ViewContext context) {
- this.context = context;
- }
-
- @Override
- public synchronized void store(Class model, Indexed obj) {
-
- try {
- Indexed newBean = (Indexed) BeanUtils.cloneBean(obj);
- preprocessEntity(newBean);
- context.getDataStore().store(newBean);
- obj.setId(newBean.getId());
- } catch (Exception e) {
- throw new ServiceFormattedException("S020 Data storage error", e);
- }
- }
-
- private void preprocessEntity(Indexed obj) {
- cleanTransientFields(obj);
- }
-
- private void cleanTransientFields(Indexed obj) {
- for (Method m : obj.getClass().getMethods()) {
- Transient aTransient = m.getAnnotation(Transient.class);
- if (aTransient != null && m.getName().startsWith("set")) {
- try {
- m.invoke(obj, new Object[]{ null });
- } catch (IllegalAccessException e) {
- throw new ServiceFormattedException("S030 Data storage error", e);
- } catch (InvocationTargetException e) {
- throw new ServiceFormattedException("S030 Data storage error", e);
- }
- }
- }
- }
-
- @Override
- public synchronized <T extends Indexed> T load(Class<T> model, Object id) throws ItemNotFound {
- LOG.debug(String.format("Loading %s #%s", model.getName(), id));
- try {
- T obj = context.getDataStore().find(model, id);
- if (obj != null) {
- return obj;
- } else {
- throw new ItemNotFound();
- }
- } catch (PersistenceException e) {
- throw new ServiceFormattedException("S040 Data storage error", e);
- }
- }
-
- @Override
- public synchronized <T extends Indexed> List<T> loadAll(Class<? extends T> model, FilteringStrategy filter) {
- LinkedList<T> list = new LinkedList<T>();
- LOG.debug(String.format("Loading all %s-s", model.getName()));
- try {
- for(T item: context.getDataStore().findAll(model, filter.whereStatement())) {
- list.add(item);
- }
- } catch (PersistenceException e) {
- throw new ServiceFormattedException("S050 Data storage error", e);
- }
- return list;
- }
-
- @Override
- public synchronized <T extends Indexed> List<T> loadAll(Class<T> model) {
- return loadAll(model, new OnlyOwnersFilteringStrategy(this.context.getUsername()));
- }
-
- @Override
- public synchronized void delete(Class model, Object id) throws ItemNotFound {
- LOG.debug(String.format("Deleting %s:%s", model.getName(), id));
- Object obj = load(model, id);
- try {
- context.getDataStore().remove(obj);
- } catch (PersistenceException e) {
- throw new ServiceFormattedException("S060 Data storage error", e);
- }
- }
-
- @Override
- public boolean exists(Class model, Object id) {
- try {
- return context.getDataStore().find(model, id) != null;
- } catch (PersistenceException e) {
- throw new ServiceFormattedException("S070 Data storage error", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/IStorageFactory.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/IStorageFactory.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/IStorageFactory.java
deleted file mode 100644
index 298d4c8..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/IStorageFactory.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence;
-
-public interface IStorageFactory {
- Storage getStorage();
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/InstanceKeyValueStorage.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/InstanceKeyValueStorage.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/InstanceKeyValueStorage.java
deleted file mode 100644
index 98703fa..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/InstanceKeyValueStorage.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.hive.persistence.utils.ContextConfigurationAdapter;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-import org.apache.ambari.view.hive.utils.ServiceFormattedException;
-import org.apache.commons.configuration.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
-
-import javax.ws.rs.WebApplicationException;
-import java.util.List;
-
-
-/**
- * Persistent storage engine for storing java beans to
- * instance data
- */
-@Deprecated
-public class InstanceKeyValueStorage extends KeyValueStorage {
- private final static Logger LOG =
- LoggerFactory.getLogger(InstanceKeyValueStorage.class);
-
- private ContextConfigurationAdapter config = null;
- private int VALUE_LENGTH_LIMIT = 254;
-
- /**
- * Constructor.
- * @param context View Context instance
- */
- public InstanceKeyValueStorage(ViewContext context) {
- super(context);
- }
-
- /**
- * Returns config instance, adapter to Persistence API
- * @return config instance
- */
- @Override
- protected synchronized Configuration getConfig() {
- if (config == null) {
- config = new ContextConfigurationAdapter(context);
- }
- return config;
- }
-
- /**
- * Value is limited to 256 symbols, this code splits value into chunks and saves them as <key>#<chunk_id>
- * @param modelPropName key
- * @param json value
- */
- protected void write(String modelPropName, String json) {
- int saved = 0;
- int page = 1;
- while (saved < json.length()) {
- int end = Math.min(saved + VALUE_LENGTH_LIMIT, json.length());
- String substring = json.substring(saved, end);
- getConfig().setProperty(modelPropName + "#" + page, substring);
- saved += VALUE_LENGTH_LIMIT;
- page += 1;
- LOG.debug("Chunk saved: " + modelPropName + "#" + page + "=" + substring);
- }
- getConfig().setProperty(modelPropName, page - 1);
- LOG.debug("Write finished: " + modelPropName + " pages:" + (page - 1));
- }
-
- /**
- * Read chunked value (keys format <key>#<chunk_id>)
- * @param modelPropName key
- * @return value
- */
- protected String read(String modelPropName) {
- StringBuilder result = new StringBuilder();
- int pages = getConfig().getInt(modelPropName);
- LOG.debug("Read started: " + modelPropName + " pages:" + pages);
-
- for(int page = 1; page <= pages; page++) {
- String substring = getConfig().getString(modelPropName + "#" + page);
- LOG.debug("Chunk read: " + modelPropName + "#" + page + "=" + substring);
- if (substring != null) {
- result.append(substring);
- }
- }
-
- return result.toString();
- }
-
- /**
- * Remove chunked value (keys format <key>#<chunk_id>)
- * @param modelPropName key
- */
- protected void clear(String modelPropName) {
- int pages = getConfig().getInt(modelPropName);
- LOG.debug("Clean started: " + modelPropName + " pages:" + pages);
-
- for(int page = 1; page <= pages; page++) {
- getConfig().clearProperty(modelPropName + "#" + page);
- LOG.debug("Chunk clean: " + modelPropName + "#" + page);
- }
- getConfig().clearProperty(modelPropName);
- }
-
- public static void storageSmokeTest(ViewContext context) {
- try {
- final String property = "test.smoke.property";
- context.putInstanceData(property, "42");
- boolean status = context.getInstanceData(property).equals("42");
- context.removeInstanceData(property);
- if (!status) throw new ServiceFormattedException("Ambari Views instance data DB doesn't work properly", null);
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new ServiceFormattedException(ex.getMessage(), ex);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/KeyValueStorage.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/KeyValueStorage.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/KeyValueStorage.java
deleted file mode 100644
index 6e88063..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/KeyValueStorage.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence;
-
-import com.google.gson.Gson;
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
-import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy;
-import org.apache.commons.configuration.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Engine for storing objects to key-value storage
- */
-public abstract class KeyValueStorage implements Storage {
- private final static Logger LOG =
- LoggerFactory.getLogger(KeyValueStorage.class);
- protected final Gson gson = new Gson();
- protected ViewContext context;
-
- /**
- * Constructor
- * @param context View Context instance
- */
- public KeyValueStorage(ViewContext context) {
- this.context = context;
- }
-
- /**
- * Returns config instance, adapter to Persistence API
- * @return config instance
- */
- protected abstract Configuration getConfig();
-
- @Override
- public <T extends Indexed> void store(Class<T> model, Indexed obj) {
- String modelIndexingPropName = getIndexPropertyName(model);
-
- if (obj.getId() == null) {
- int lastIndex = getConfig().getInt(modelIndexingPropName, 0);
- lastIndex ++;
- getConfig().setProperty(modelIndexingPropName, lastIndex);
- obj.setId(String.valueOf(lastIndex));
- }
-
- String modelPropName = getItemPropertyName(model, obj.getId());
- String json = serialize(obj);
- write(modelPropName, json);
- }
-
- @Override
- public <T extends Indexed> T load(Class<T> model, Object id) throws ItemNotFound {
- String modelPropName = getItemPropertyName(model, id);
- LOG.debug(String.format("Loading %s", modelPropName));
- if (getConfig().containsKey(modelPropName)) {
- String json = read(modelPropName);
- LOG.debug(String.format("json: %s", json));
-
- return deserialize(model, json);
- } else {
- throw new ItemNotFound();
- }
- }
-
- /**
- * Write json to storage
- * @param modelPropName key
- * @param json value
- */
- protected void write(String modelPropName, String json) {
- getConfig().setProperty(modelPropName, json);
- }
-
- /**
- * Read json from storage
- * @param modelPropName key
- * @return value
- */
- protected String read(String modelPropName) {
- return getConfig().getString(modelPropName);
- }
-
- /**
- * Remove line from storage
- * @param modelPropName key
- */
- protected void clear(String modelPropName) {
- getConfig().clearProperty(modelPropName);
- }
-
- protected String serialize(Indexed obj) {
- return gson.toJson(obj);
- }
-
- protected <T extends Indexed> T deserialize(Class<T> model, String json) {
- return gson.fromJson(json, model);
- }
-
- @Override
- public synchronized <T extends Indexed> List<T> loadAll(Class<? extends T> model, FilteringStrategy filter) {
- ArrayList<T> list = new ArrayList<T>();
- String modelIndexingPropName = getIndexPropertyName(model);
- LOG.debug(String.format("Loading all %s-s", model.getName()));
- int lastIndex = getConfig().getInt(modelIndexingPropName, 0);
- for(int i=1; i<=lastIndex; i++) {
- try {
- T item = load(model, i);
- if ((filter == null) || filter.isConform(item)) {
- list.add(item);
- }
- } catch (ItemNotFound ignored) {
- }
- }
- return list;
- }
-
- @Override
- public synchronized <T extends Indexed> List<T> loadAll(Class<T> model) {
- return loadAll(model, new OnlyOwnersFilteringStrategy(this.context.getUsername()));
- }
-
- @Override
- public synchronized void delete(Class model, Object id) {
- LOG.debug(String.format("Deleting %s:%s", model.getName(), id));
- String modelPropName = getItemPropertyName(model, id);
- clear(modelPropName);
- }
-
- @Override
- public boolean exists(Class model, Object id) {
- return getConfig().containsKey(getItemPropertyName(model, id));
- }
-
- private String getIndexPropertyName(Class model) {
- return String.format("%s:index", model.getName());
- }
-
- private String getItemPropertyName(Class model, Object id) {
- return String.format("%s.%s", model.getName(), id);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/LocalKeyValueStorage.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/LocalKeyValueStorage.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/LocalKeyValueStorage.java
deleted file mode 100644
index 24ed335..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/LocalKeyValueStorage.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-import org.apache.ambari.view.hive.utils.MisconfigurationFormattedException;
-import org.apache.commons.configuration.ConfigurationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
-
-import java.util.List;
-
-
-/**
- * Persistent storage engine for storing java beans to
- * properties file
- * Path to file should be in 'dataworker.storagePath' parameter
- */
-@Deprecated
-public class LocalKeyValueStorage extends KeyValueStorage {
- private final static Logger LOG =
- LoggerFactory.getLogger(LocalKeyValueStorage.class);
-
- private PersistentConfiguration config = null;
-
- /**
- * Constructor
- * @param context View Context instance
- */
- public LocalKeyValueStorage(ViewContext context) {
- super(context);
- }
-
- /**
- * Returns config instance
- * @return config instance
- */
- @Override
- protected synchronized PersistentConfiguration getConfig() {
- if (config == null) {
- String fileName = context.getProperties().get("dataworker.storagePath");
- if (fileName == null) {
- String msg = "dataworker.storagePath is not configured!";
- LOG.error(msg);
- throw new MisconfigurationFormattedException("dataworker.storagePath");
- }
- try {
- config = new PersistentConfiguration(fileName);
- } catch (ConfigurationException e) {
- e.printStackTrace();
- }
- }
- return config;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/PersistentConfiguration.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/PersistentConfiguration.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/PersistentConfiguration.java
deleted file mode 100644
index b8405ff..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/PersistentConfiguration.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
-
-import java.io.File;
-
-/**
- * Configuration enables all necessary options for PropertiesConfiguration:
- * auto-save, auto-reloading, no delimiter parsing and other
- */
-@Deprecated
-public class PersistentConfiguration extends PropertiesConfiguration {
- /**
- * Constructor
- * @param fileName path to data file
- * @throws ConfigurationException
- */
- public PersistentConfiguration(String fileName) throws ConfigurationException {
- super();
-
- File config = new File(fileName);
- setFile(config);
- this.setAutoSave(true);
- this.setReloadingStrategy(new FileChangedReloadingStrategy());
- this.setDelimiterParsingDisabled(true);
- this.setListDelimiter((char) 0);
-
- if (config.exists()) {
- this.load();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/Storage.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/Storage.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/Storage.java
deleted file mode 100644
index a34f566..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/Storage.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence;
-
-import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
-
-import java.util.List;
-
-/**
- * Object storage interface
- */
-public interface Storage {
- /**
- * Persist object to DB. It should be Indexed
- * @param obj object to save
- */
- <T extends Indexed> void store(Class<T> model, Indexed obj);
-
- /**
- * Load object
- * @param model bean class
- * @param id identifier
- * @return bean instance
- * @throws ItemNotFound thrown if item with id was not found in DB
- */
- <T extends Indexed> T load(Class<T> model, Object id) throws ItemNotFound;
-
- /**
- * Load all objects of given bean class
- * @param model bean class
- * @param filter filtering strategy (return only those objects that conform condition)
- * @param <T> bean class
- * @return list of filtered objects
- */
- <T extends Indexed> List<T> loadAll(Class<? extends T> model, FilteringStrategy filter);
-
- /**
- * Load all objects of given bean class
- * @param model bean class
- * @param <T> bean class
- * @return list of all objects
- */
- <T extends Indexed> List<T> loadAll(Class<T> model);
-
- /**
- * Delete object
- * @param model bean class
- * @param id identifier
- */
- void delete(Class model, Object id) throws ItemNotFound;
-
- /**
- * Check is object exists
- * @param model bean class
- * @param id identifier
- * @return true if exists
- */
- boolean exists(Class model, Object id);
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ContextConfigurationAdapter.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ContextConfigurationAdapter.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ContextConfigurationAdapter.java
deleted file mode 100644
index afc4c78..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ContextConfigurationAdapter.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.commons.configuration.Configuration;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Persistence API to Apache Configuration adapter
- */
-@Deprecated
-public class ContextConfigurationAdapter implements Configuration {
- private ViewContext context;
-
- /**
- * Constructor of adapter
- * @param context View Context
- */
- public ContextConfigurationAdapter(ViewContext context) {
- this.context = context;
- }
-
- @Override
- public Configuration subset(String prefix) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isEmpty() {
- return context.getInstanceData().isEmpty();
- }
-
- @Override
- public boolean containsKey(String s) {
- Map<String, String> data = context.getInstanceData();
- return data.containsKey(s);
- }
-
- @Override
- public void addProperty(String s, Object o) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void setProperty(String s, Object o) {
- context.putInstanceData(s, o.toString());
- }
-
- @Override
- public void clearProperty(String key) {
- context.removeInstanceData(key);
- }
-
- @Override
- public void clear() {
- for (String key : context.getInstanceData().keySet())
- context.removeInstanceData(key);
- }
-
- @Override
- public Object getProperty(String key) {
- return context.getInstanceData(key);
- }
-
- @Override
- public Iterator getKeys(String s) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Iterator getKeys() {
- return context.getInstanceData().keySet().iterator();
- }
-
- @Override
- public Properties getProperties(String s) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean getBoolean(String s) {
- return getBoolean(s, null);
- }
-
- @Override
- public boolean getBoolean(String s, boolean b) {
- return getBoolean(s, (Boolean)b);
- }
-
- @Override
- public Boolean getBoolean(String s, Boolean aBoolean) {
- String data = context.getInstanceData(s);
- return (data != null)?Boolean.parseBoolean(data):aBoolean;
- }
-
- @Override
- public byte getByte(String s) {
- return getByte(s, null);
- }
-
- @Override
- public byte getByte(String s, byte b) {
- return getByte(s, (Byte)b);
- }
-
- @Override
- public Byte getByte(String s, Byte aByte) {
- String data = context.getInstanceData(s);
- return (data != null)?Byte.parseByte(data):aByte;
- }
-
- @Override
- public double getDouble(String s) {
- return getDouble(s, null);
- }
-
- @Override
- public double getDouble(String s, double v) {
- return getDouble(s, (Double)v);
- }
-
- @Override
- public Double getDouble(String s, Double aDouble) {
- String data = context.getInstanceData(s);
- return (data != null)?Double.parseDouble(data):aDouble;
- }
-
- @Override
- public float getFloat(String s) {
- return getFloat(s, null);
- }
-
- @Override
- public float getFloat(String s, float v) {
- return getFloat(s, (Float)v);
- }
-
- @Override
- public Float getFloat(String s, Float aFloat) {
- String data = context.getInstanceData(s);
- return (data != null)?Float.parseFloat(data):aFloat;
- }
-
- @Override
- public int getInt(String s) {
- return getInteger(s, null);
- }
-
- @Override
- public int getInt(String s, int i) {
- return getInteger(s, i);
- }
-
- @Override
- public Integer getInteger(String s, Integer integer) {
- String data = context.getInstanceData(s);
- return (data != null)?Integer.parseInt(data):integer;
- }
-
- @Override
- public long getLong(String s) {
- return getLong(s, null);
- }
-
- @Override
- public long getLong(String s, long l) {
- return getLong(s, (Long)l);
- }
-
- @Override
- public Long getLong(String s, Long aLong) {
- String data = context.getInstanceData(s);
- return (data != null)?Long.parseLong(data):aLong;
- }
-
- @Override
- public short getShort(String s) {
- return getShort(s, null);
- }
-
- @Override
- public short getShort(String s, short i) {
- return getShort(s, (Short)i);
- }
-
- @Override
- public Short getShort(String s, Short aShort) {
- String data = context.getInstanceData(s);
- return (data != null)?Short.parseShort(data):aShort;
- }
-
- @Override
- public BigDecimal getBigDecimal(String s) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public BigDecimal getBigDecimal(String s, BigDecimal bigDecimal) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public BigInteger getBigInteger(String s) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public BigInteger getBigInteger(String s, BigInteger bigInteger) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public String getString(String s) {
- return context.getInstanceData(s);
- }
-
- @Override
- public String getString(String s, String s2) {
- String data = getString(s);
- return (data != null)?data:s2;
- }
-
- @Override
- public String[] getStringArray(String s) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public List getList(String s) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public List getList(String s, List list) {
- throw new UnsupportedOperationException();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/FilteringStrategy.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/FilteringStrategy.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/FilteringStrategy.java
deleted file mode 100644
index eba572e..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/FilteringStrategy.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-/**
- * Filtering strategy for stored objects
- */
-public interface FilteringStrategy {
- /**
- * Check whether item conforms chosen filter or not
- * @param item item to check
- * @return true if item conforms this filter
- */
- boolean isConform(Indexed item);
- String whereStatement();
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Indexed.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Indexed.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Indexed.java
deleted file mode 100644
index 82b7d57..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Indexed.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-/**
- * Interface to represent item with identifier
- */
-public interface Indexed {
- /**
- * Get the ID
- * @return ID
- */
- String getId();
-
- /**
- * Set ID
- * @param id ID
- */
- void setId(String id);
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ItemNotFound.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ItemNotFound.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ItemNotFound.java
deleted file mode 100644
index 06976b9..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/ItemNotFound.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-/**
- * Thrown when item was not found in DB
- */
-public class ItemNotFound extends Exception {
- public ItemNotFound() {
- }
-
- public ItemNotFound(String message) {
- super(message);
- }
-
- public ItemNotFound(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ItemNotFound(Throwable cause) {
- super(cause);
- }
-
- public ItemNotFound(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/OnlyOwnersFilteringStrategy.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/OnlyOwnersFilteringStrategy.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/OnlyOwnersFilteringStrategy.java
deleted file mode 100644
index 620f440..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/OnlyOwnersFilteringStrategy.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-public class OnlyOwnersFilteringStrategy implements FilteringStrategy {
- private final String username;
-
- public OnlyOwnersFilteringStrategy(String username) {
- this.username = username;
- }
-
- @Override
- public boolean isConform(Indexed item) {
- Owned object = (Owned) item;
- return object.getOwner().compareTo(username) == 0;
- }
-
- @Override
- public String whereStatement() {
- return "owner = '" + username + "'";
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Owned.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Owned.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Owned.java
deleted file mode 100644
index 460bf37..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/Owned.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-/**
- * Interface to represent item with owner
- */
-public interface Owned {
- /**
- * Get the owner
- * @return owner
- */
- String getOwner();
-
- /**
- * Set owner
- * @param owner owner
- */
- void setOwner(String owner);
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/PersonalResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/PersonalResource.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/PersonalResource.java
deleted file mode 100644
index 1b41edb..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/PersonalResource.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-public interface PersonalResource extends Indexed, Owned {
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/StorageFactory.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/StorageFactory.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/StorageFactory.java
deleted file mode 100644
index 88a6d66..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/persistence/utils/StorageFactory.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.persistence.utils;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.hive.persistence.DataStoreStorage;
-import org.apache.ambari.view.hive.persistence.IStorageFactory;
-import org.apache.ambari.view.hive.persistence.LocalKeyValueStorage;
-import org.apache.ambari.view.hive.persistence.Storage;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Storage factory, creates storage of Local or Persistence API type.
- * Type depends on context configuration: if "dataworker.storagePath" is set,
- * storage of Local type will be created. Otherwise, Persistence API will be used.
- *
- * Storage is singleton.
- */
-public class StorageFactory implements IStorageFactory {
- protected final static Logger LOG =
- LoggerFactory.getLogger(StorageFactory.class);
-
- private ViewContext context;
-
- /**
- * Constructor of storage factory
- * @param context View Context instance
- */
- public StorageFactory(ViewContext context) {
- this.context = context;
- }
-
- /**
- * Creates storage instance
- * @return storage instance
- */
- public Storage getStorage() {
- String fileName = context.getProperties().get("dataworker.storagePath");
-
- Storage storageInstance;
- if (fileName != null) {
- LOG.debug("Using local storage in " + fileName + " to store data");
- // If specifed, use LocalKeyValueStorage - key-value file based storage
- storageInstance = new LocalKeyValueStorage(context);
- } else {
- LOG.debug("Using Persistence API to store data");
- // If not specifed, use ambari-views Persistence API
- storageInstance = new DataStoreStorage(context);
- }
- return storageInstance;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/CRUDResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/CRUDResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/CRUDResourceManager.java
deleted file mode 100644
index c7167a8..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/CRUDResourceManager.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.resources;
-
-import org.apache.ambari.view.hive.persistence.IStorageFactory;
-import org.apache.ambari.view.hive.persistence.Storage;
-import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
-import org.apache.ambari.view.hive.utils.ServiceFormattedException;
-
-import java.util.List;
-
-/**
- * CRUD resource manager
- * @param <T> Data type with ID
- */
-abstract public class CRUDResourceManager<T extends Indexed> implements IResourceManager<T> {
- //TODO: refactor: generic parameter gets Fabric for Indexed objects, not objects itself
- private Storage storage = null;
-
- protected final Class<? extends T> resourceClass;
- protected IStorageFactory storageFactory;
-
- /**
- * Constructor
- * @param resourceClass model class
- */
- public CRUDResourceManager(Class<? extends T> resourceClass, IStorageFactory storageFactory) {
- this.resourceClass = resourceClass;
- this.storageFactory = storageFactory;
- }
- // CRUD operations
-
- /**
- * Create operation
- * @param object object
- * @return model object
- */
- @Override
- public T create(T object) {
- object.setId(null);
- return this.save(object);
- }
-
- /**
- * Read operation
- * @param id identifier
- * @return model object
- * @throws org.apache.ambari.view.hive.persistence.utils.ItemNotFound
- */
- @Override
- public T read(Object id) throws ItemNotFound {
- T object = null;
- object = storageFactory.getStorage().load(this.resourceClass, id);
- if (!checkPermissions(object))
- throw new ItemNotFound();
- return object;
- }
-
- /**
- * Read all objects
- * @param filteringStrategy filtering strategy
- * @return list of filtered objects
- */
- @Override
- public List<T> readAll(FilteringStrategy filteringStrategy) {
- return storageFactory.getStorage().loadAll(this.resourceClass, filteringStrategy);
- }
-
- /**
- * Update operation
- * @param newObject new object
- * @param id identifier of previous object
- * @return model object
- * @throws org.apache.ambari.view.hive.persistence.utils.ItemNotFound
- */
- @Override
- public T update(T newObject, String id) throws ItemNotFound {
- newObject.setId(id);
- this.save(newObject);
- return newObject;
- }
-
- /**
- * Delete operation
- * @param resourceId object identifier
- * @throws org.apache.ambari.view.hive.persistence.utils.ItemNotFound
- */
- @Override
- public void delete(Object resourceId) throws ItemNotFound {
- if (!storageFactory.getStorage().exists(this.resourceClass, resourceId)) {
- throw new ItemNotFound();
- }
- storageFactory.getStorage().delete(this.resourceClass, resourceId);
- }
-
- // UTILS
-
- protected T save(T object) {
- storageFactory.getStorage().store(resourceClass, object);
- return object;
- }
-
- protected abstract boolean checkPermissions(T object);
-
- protected void cleanupAfterErrorAndThrowAgain(Indexed object, ServiceFormattedException e) {
- try {
- delete(object.getId());
- } catch (ItemNotFound itemNotFound) {
- throw new ServiceFormattedException("E040 Item not found", itemNotFound);
- }
- throw e;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/IResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/IResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/IResourceManager.java
deleted file mode 100644
index 222d695..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/IResourceManager.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.resources;
-
-import org.apache.ambari.view.hive.persistence.utils.FilteringStrategy;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
-
-import java.util.List;
-
-public interface IResourceManager<T extends Indexed> {
- T create(T object);
-
- T read(Object id) throws ItemNotFound;
-
- List<T> readAll(FilteringStrategy filteringStrategy);
-
- T update(T newObject, String id) throws ItemNotFound;
-
- void delete(Object resourceId) throws ItemNotFound;
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/PersonalCRUDResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/PersonalCRUDResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/PersonalCRUDResourceManager.java
deleted file mode 100644
index e8ce02e..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/PersonalCRUDResourceManager.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.resources;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.hive.persistence.IStorageFactory;
-import org.apache.ambari.view.hive.persistence.utils.ItemNotFound;
-import org.apache.ambari.view.hive.persistence.utils.PersonalResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.concurrent.Callable;
-
-/**
- * Resource manager that returns only user owned elements from DB
- * @param <T> Data type with ID and Owner
- */
-public class PersonalCRUDResourceManager<T extends PersonalResource> extends CRUDResourceManager<T> {
- protected boolean ignorePermissions = false;
-
- private final static Logger LOG =
- LoggerFactory.getLogger(PersonalCRUDResourceManager.class);
- protected ViewContext context;
-
- /**
- * Constructor
- * @param resourceClass model class
- */
- public PersonalCRUDResourceManager(Class<? extends T> resourceClass, IStorageFactory storageFabric, ViewContext context) {
- super(resourceClass, storageFabric);
- this.context = context;
- }
-
- @Override
- public T update(T newObject, String id) throws ItemNotFound {
- T object = storageFactory.getStorage().load(this.resourceClass, id);
- if (object.getOwner().compareTo(this.context.getUsername()) != 0) {
- throw new ItemNotFound();
- }
-
- newObject.setOwner(this.context.getUsername());
- return super.update(newObject, id);
- }
-
- @Override
- public T save(T object) {
- if (!ignorePermissions) {
- // in threads permissions should be ignored,
- // because context.getUsername doesn't work. See BUG-27093.
- object.setOwner(this.context.getUsername());
- }
- return super.save(object);
- }
-
- @Override
- protected boolean checkPermissions(T object) {
- if (ignorePermissions) {
- return true;
- }
- return object.getOwner().compareTo(this.context.getUsername()) == 0;
- }
-
- /**
- * Execute action ignoring objects owner
- * @param actions callable to execute
- * @return value returned from actions
- * @throws Exception
- */
- public T ignorePermissions(Callable<T> actions) throws Exception {
- ignorePermissions = true;
- T result;
- try {
- result = actions.call();
- } finally {
- ignorePermissions = false;
- }
- return result;
- }
-
- protected String getUsername() {
- return context.getUsername();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/SharedCRUDResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/SharedCRUDResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/SharedCRUDResourceManager.java
deleted file mode 100644
index 9c4ca36..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/SharedCRUDResourceManager.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.resources;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.hive.persistence.IStorageFactory;
-import org.apache.ambari.view.hive.persistence.utils.Indexed;
-
-/**
- * Resource manager that doesn't restrict access (Allow all)
- * @param <T> Data type with ID
- */
-public class SharedCRUDResourceManager<T extends Indexed> extends CRUDResourceManager<T> {
- protected ViewContext context;
-
- /**
- * Constructor
- * @param responseClass model class
- */
- public SharedCRUDResourceManager(Class<T> responseClass, IStorageFactory storageFabric) {
- super(responseClass, storageFabric);
- }
-
- @Override
- protected boolean checkPermissions(T object) {
- return true; //everyone has permission
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/browser/HiveBrowserService.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/browser/HiveBrowserService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/browser/HiveBrowserService.java
deleted file mode 100644
index f758fe3..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/browser/HiveBrowserService.java
+++ /dev/null
@@ -1,276 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.resources.browser;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.ViewResourceHandler;
-import org.apache.ambari.view.hive.client.ColumnDescription;
-import org.apache.ambari.view.hive.client.Cursor;
-import org.apache.ambari.view.hive.client.UserLocalConnection;
-import org.apache.ambari.view.hive.resources.jobs.ResultsPaginationController;
-import org.apache.ambari.view.hive.utils.BadRequestFormattedException;
-import org.apache.ambari.view.hive.utils.ServiceFormattedException;
-import org.apache.ambari.view.hive.utils.SharedObjectsFactory;
-import org.apache.commons.collections4.map.PassiveExpiringMap;
-import org.apache.hive.service.cli.thrift.TSessionHandle;
-import org.json.simple.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.inject.Inject;
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-
-/**
- * Database access resource
- */
-public class HiveBrowserService {
- @Inject
- ViewResourceHandler handler;
- @Inject
- protected ViewContext context;
-
- protected final static Logger LOG =
- LoggerFactory.getLogger(HiveBrowserService.class);
-
- private static final long EXPIRING_TIME = 10*60*1000; // 10 minutes
- private static Map<String, Cursor> resultsCache;
- private UserLocalConnection connectionLocal = new UserLocalConnection();
-
- public static Map<String, Cursor> getResultsCache() {
- if (resultsCache == null) {
- PassiveExpiringMap<String, Cursor> resultsCacheExpiringMap =
- new PassiveExpiringMap<String, Cursor>(EXPIRING_TIME);
- resultsCache = Collections.synchronizedMap(resultsCacheExpiringMap);
- }
- return resultsCache;
- }
-
- /**
- * Returns list of databases
- */
- @GET
- @Path("database")
- @Produces(MediaType.APPLICATION_JSON)
- public Response databases(@QueryParam("like")String like,
- @QueryParam("first") String fromBeginning,
- @QueryParam("count") Integer count,
- @QueryParam("columns") final String requestedColumns) {
- if (like == null)
- like = "*";
- else
- like = "*" + like + "*";
- String curl = null;
- try {
- JSONObject response = new JSONObject();
- TSessionHandle session = connectionLocal.get(context).getOrCreateSessionByTag("DDL");
- List<String> tables = connectionLocal.get(context).ddl().getDBList(session, like);
- response.put("databases", tables);
- return Response.ok(response).build();
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (IllegalArgumentException ex) {
- throw new BadRequestFormattedException(ex.getMessage(), ex);
- } catch (Exception ex) {
- throw new ServiceFormattedException(ex.getMessage(), ex, curl);
- }
- }
-
- /**
- * Returns list of databases
- */
- @GET
- @Path("database.page")
- @Produces(MediaType.APPLICATION_JSON)
- public Response databasesPaginated(@QueryParam("like")String like,
- @QueryParam("first") String fromBeginning,
- @QueryParam("count") Integer count,
- @QueryParam("searchId") String searchId,
- @QueryParam("format") String format,
- @QueryParam("columns") final String requestedColumns) {
- if (like == null)
- like = "*";
- else
- like = "*" + like + "*";
- String curl = null;
- try {
- final String finalLike = like;
- return ResultsPaginationController.getInstance(context)
- .request("databases", searchId, false, fromBeginning, count, format,
- new Callable<Cursor>() {
- @Override
- public Cursor call() throws Exception {
- TSessionHandle session = connectionLocal.get(context).getOrCreateSessionByTag("DDL");
- return connectionLocal.get(context).ddl().getDBListCursor(session, finalLike);
- }
- }).build();
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (IllegalArgumentException ex) {
- throw new BadRequestFormattedException(ex.getMessage(), ex);
- } catch (Exception ex) {
- throw new ServiceFormattedException(ex.getMessage(), ex, curl);
- }
- }
-
- /**
- * Returns list of databases
- */
- @GET
- @Path("database/{db}/table")
- @Produces(MediaType.APPLICATION_JSON)
- public Response tablesInDatabase(@PathParam("db") String db,
- @QueryParam("like")String like,
- @QueryParam("first") String fromBeginning,
- @QueryParam("count") Integer count,
- @QueryParam("columns") final String requestedColumns) {
- if (like == null)
- like = "*";
- else
- like = "*" + like + "*";
- String curl = null;
- try {
- JSONObject response = new JSONObject();
- TSessionHandle session = connectionLocal.get(context).getOrCreateSessionByTag("DDL");
- List<String> tables = connectionLocal.get(context).ddl().getTableList(session, db, like);
- response.put("tables", tables);
- response.put("database", db);
- return Response.ok(response).build();
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (IllegalArgumentException ex) {
- throw new BadRequestFormattedException(ex.getMessage(), ex);
- } catch (Exception ex) {
- throw new ServiceFormattedException(ex.getMessage(), ex, curl);
- }
- }
-
- /**
- * Returns list of databases
- */
- @GET
- @Path("database/{db}/table.page")
- @Produces(MediaType.APPLICATION_JSON)
- public Response tablesInDatabasePaginated(@PathParam("db") final String db,
- @QueryParam("like")String like,
- @QueryParam("first") String fromBeginning,
- @QueryParam("count") Integer count,
- @QueryParam("searchId") String searchId,
- @QueryParam("format") String format,
- @QueryParam("columns") final String requestedColumns) {
- if (like == null)
- like = "*";
- else
- like = "*" + like + "*";
- String curl = null;
- try {
- final String finalLike = like;
- return ResultsPaginationController.getInstance(context)
- .request(db + ":tables", searchId, false, fromBeginning, count, format,
- new Callable<Cursor>() {
- @Override
- public Cursor call() throws Exception {
- TSessionHandle session = connectionLocal.get(context).getOrCreateSessionByTag("DDL");
- Cursor cursor = connectionLocal.get(context).ddl().getTableListCursor(session, db, finalLike);
- cursor.selectColumns(requestedColumns);
- return cursor;
- }
- }).build();
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (IllegalArgumentException ex) {
- throw new BadRequestFormattedException(ex.getMessage(), ex);
- } catch (Exception ex) {
- throw new ServiceFormattedException(ex.getMessage(), ex, curl);
- }
- }
-
- /**
- * Returns list of databases
- */
- @GET
- @Path("database/{db}/table/{table}")
- @Produces(MediaType.APPLICATION_JSON)
- public Response describeTable(@PathParam("db") String db,
- @PathParam("table") String table,
- @QueryParam("like") String like,
- @QueryParam("columns") String requestedColumns,
- @QueryParam("extended") String extended) {
- boolean extendedTableDescription = (extended != null && extended.equals("true"));
- String curl = null;
- try {
- JSONObject response = new JSONObject();
- TSessionHandle session = connectionLocal.get(context).getOrCreateSessionByTag("DDL");
- List<ColumnDescription> columnDescriptions = connectionLocal.get(context).ddl()
- .getTableDescription(session, db, table, like, extendedTableDescription);
- response.put("columns", columnDescriptions);
- response.put("database", db);
- response.put("table", table);
- return Response.ok(response).build();
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (IllegalArgumentException ex) {
- throw new BadRequestFormattedException(ex.getMessage(), ex);
- } catch (Exception ex) {
- throw new ServiceFormattedException(ex.getMessage(), ex, curl);
- }
- }
-
- /**
- * Returns list of databases
- */
- @GET
- @Path("database/{db}/table/{table}.page")
- @Produces(MediaType.APPLICATION_JSON)
- public Response describeTablePaginated(@PathParam("db") final String db,
- @PathParam("table") final String table,
- @QueryParam("like") final String like,
- @QueryParam("first") String fromBeginning,
- @QueryParam("searchId") String searchId,
- @QueryParam("count") Integer count,
- @QueryParam("format") String format,
- @QueryParam("columns") final String requestedColumns) {
- String curl = null;
- try {
- return ResultsPaginationController.getInstance(context)
- .request(db + ":tables:" + table + ":columns", searchId, false, fromBeginning, count, format,
- new Callable<Cursor>() {
- @Override
- public Cursor call() throws Exception {
- TSessionHandle session = connectionLocal.get(context).getOrCreateSessionByTag("DDL");
- Cursor cursor = connectionLocal.get(context).ddl().
- getTableDescriptionCursor(session, db, table, like);
- cursor.selectColumns(requestedColumns);
- return cursor;
- }
- }).build();
- } catch (WebApplicationException ex) {
- throw ex;
- } catch (IllegalArgumentException ex) {
- throw new BadRequestFormattedException(ex.getMessage(), ex);
- } catch (Exception ex) {
- throw new ServiceFormattedException(ex.getMessage(), ex, curl);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c0f9621f/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileResource.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileResource.java
deleted file mode 100644
index 633e859..0000000
--- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileResource.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.hive.resources.files;
-
-/**
- * File bean
- */
-public class FileResource {
- private String filePath;
- private String fileContent;
- private boolean hasNext;
- private long page;
- private long pageCount;
-
- public String getFilePath() {
- return filePath;
- }
-
- public void setFilePath(String filePath) {
- this.filePath = filePath;
- }
-
- public String getFileContent() {
- return fileContent;
- }
-
- public void setFileContent(String fileContent) {
- this.fileContent = fileContent;
- }
-
- public boolean isHasNext() {
- return hasNext;
- }
-
- public void setHasNext(boolean hasNext) {
- this.hasNext = hasNext;
- }
-
- public long getPage() {
- return page;
- }
-
- public void setPage(long page) {
- this.page = page;
- }
-
- public long getPageCount() {
- return pageCount;
- }
-
- public void setPageCount(long pageCount) {
- this.pageCount = pageCount;
- }
-}
\ No newline at end of file