Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B93A5200C15 for ; Tue, 3 Jan 2017 12:43:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B80B9160B43; Tue, 3 Jan 2017 11:43:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C3491160B56 for ; Tue, 3 Jan 2017 12:43:46 +0100 (CET) Received: (qmail 28458 invoked by uid 500); 3 Jan 2017 11:43:45 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 27314 invoked by uid 99); 3 Jan 2017 11:43:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jan 2017 11:43:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7BA9DDFBD7; Tue, 3 Jan 2017 11:43:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: nitiraj@apache.org To: commits@ambari.apache.org Date: Tue, 03 Jan 2017 11:44:00 -0000 Message-Id: <4eab16f4bfb04cb19f76e29cf4c3e54c@git.apache.org> In-Reply-To: <56f12f1808394fdfa15dc16022039618@git.apache.org> References: <56f12f1808394fdfa15dc16022039618@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [17/20] ambari git commit: AMBARI-19321 : Hive View 2.0 - Minimal view for Hive which includes new UI changes. Also made changes in poms as required (nitirajrathore) archived-at: Tue, 03 Jan 2017 11:43:49 -0000 http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/FreeConnector.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/FreeConnector.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/FreeConnector.java new file mode 100644 index 0000000..a32daa3 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/FreeConnector.java @@ -0,0 +1,53 @@ +/* + * 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.hive20.actor.message.lifecycle; + +public class FreeConnector { + + private final String username; + private final String jobId; + private final boolean forAsync; + + public FreeConnector(String username, String jobId, boolean forAsync) { + this.username = username; + this.jobId = jobId; + this.forAsync = forAsync; + } + + public String getUsername() { + return username; + } + + public String getJobId() { + return jobId; + } + + public boolean isForAsync() { + return forAsync; + } + + @Override + public String toString() { + return "FreeConnector{" + + "username='" + username + '\'' + + ", jobId='" + jobId + '\'' + + ", forAsync=" + forAsync + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/InactivityCheck.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/InactivityCheck.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/InactivityCheck.java new file mode 100644 index 0000000..bd08b09 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/InactivityCheck.java @@ -0,0 +1,21 @@ +/* + * 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.hive20.actor.message.lifecycle; + +public class InactivityCheck {} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/KeepAlive.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/KeepAlive.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/KeepAlive.java new file mode 100644 index 0000000..840289a --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/KeepAlive.java @@ -0,0 +1,21 @@ +/* + * 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.hive20.actor.message.lifecycle; + +public class KeepAlive {} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/TerminateInactivityCheck.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/TerminateInactivityCheck.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/TerminateInactivityCheck.java new file mode 100644 index 0000000..7251a6a --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/actor/message/lifecycle/TerminateInactivityCheck.java @@ -0,0 +1,21 @@ +/* + * 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.hive20.actor.message.lifecycle; + +public class TerminateInactivityCheck {} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/backgroundjobs/BackgroundJobController.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/backgroundjobs/BackgroundJobController.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/backgroundjobs/BackgroundJobController.java new file mode 100644 index 0000000..0b21a18 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/backgroundjobs/BackgroundJobController.java @@ -0,0 +1,84 @@ +/** + * 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.hive20.backgroundjobs; + +import org.apache.ambari.view.ViewContext; + +import java.util.HashMap; +import java.util.Map; + +public class BackgroundJobController { + private ViewContext context; + + protected BackgroundJobController(ViewContext context) { + this.context = context; + } + + private static Map viewSingletonObjects = new HashMap(); + public static BackgroundJobController getInstance(ViewContext context) { + if (!viewSingletonObjects.containsKey(context.getInstanceName())) + viewSingletonObjects.put(context.getInstanceName(), new BackgroundJobController(context)); + return viewSingletonObjects.get(context.getInstanceName()); + } + + private Map jobs = new HashMap(); + public void startJob(String key, Runnable runnable) { + if (jobs.containsKey(key)) { + interrupt(key); + try { + jobs.get(key).join(); + } catch (InterruptedException ignored) { + } + } + Thread t = new Thread(runnable); + jobs.put(key, t); + t.start(); + } + + public Thread.State state(String key) { + if (!jobs.containsKey(key)) { + return Thread.State.TERMINATED; + } + + Thread.State state = jobs.get(key).getState(); + + if (state == Thread.State.TERMINATED) { + jobs.remove(key); + } + + return state; + } + + public boolean interrupt(String key) { + if (!jobs.containsKey(key)) { + return false; + } + + jobs.get(key).interrupt(); + return true; + } + + public boolean isInterrupted(String key) { + if (state(key) == Thread.State.TERMINATED) { + return true; + } + + return jobs.get(key).isInterrupted(); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunner.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunner.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunner.java new file mode 100644 index 0000000..da746a6 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunner.java @@ -0,0 +1,38 @@ +/* + * 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.hive20.client; + +import com.google.common.base.Optional; +import org.apache.ambari.view.hive20.actor.message.SQLStatementJob; +import org.apache.ambari.view.hive20.actor.message.job.Failure; +import org.apache.ambari.view.hive20.resources.jobs.viewJobs.Job; + +public interface AsyncJobRunner { + + void submitJob(ConnectionConfig connectionConfig, SQLStatementJob asyncJob, Job job); + + void cancelJob(String jobId, String username); + + Optional getCursor(String jobId, String username); + + Optional resetAndGetCursor(String jobId, String username); + + Optional getError(String jobId, String username); + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunnerImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunnerImpl.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunnerImpl.java new file mode 100644 index 0000000..7013f8a --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/AsyncJobRunnerImpl.java @@ -0,0 +1,143 @@ +/* + * 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.hive20.client; + +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.Inbox; +import com.google.common.base.Optional; +import org.apache.ambari.view.ViewContext; +import org.apache.ambari.view.hive20.actor.message.Connect; +import org.apache.ambari.view.hive20.actor.message.CursorReset; +import org.apache.ambari.view.hive20.actor.message.ExecuteJob; +import org.apache.ambari.view.hive20.actor.message.FetchError; +import org.apache.ambari.view.hive20.actor.message.FetchResult; +import org.apache.ambari.view.hive20.actor.message.ResetCursor; +import org.apache.ambari.view.hive20.actor.message.ResultNotReady; +import org.apache.ambari.view.hive20.actor.message.SQLStatementJob; +import org.apache.ambari.view.hive20.actor.message.job.CancelJob; +import org.apache.ambari.view.hive20.actor.message.job.Failure; +import org.apache.ambari.view.hive20.actor.message.job.FetchFailed; +import org.apache.ambari.view.hive20.internal.ConnectionException; +import org.apache.ambari.view.hive20.resources.jobs.viewJobs.Job; +import org.apache.ambari.view.hive20.utils.ResultFetchFormattedException; +import org.apache.ambari.view.hive20.utils.ResultNotReadyFormattedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import scala.concurrent.duration.Duration; + +import java.sql.SQLException; +import java.util.concurrent.TimeUnit; + +public class AsyncJobRunnerImpl implements AsyncJobRunner { + + private final Logger LOG = LoggerFactory.getLogger(getClass()); + + private final ActorRef controller; + private final ActorSystem system; + private final ViewContext context; + + public AsyncJobRunnerImpl(ViewContext context, ActorRef controller, ActorSystem system) { + this.context = context; + this.controller = controller; + this.system = system; + } + + + @Override + public void submitJob(ConnectionConfig config, SQLStatementJob job, Job jobp) { + Connect connect = config.createConnectMessage(jobp.getId()); + ExecuteJob executeJob = new ExecuteJob(connect, job); + controller.tell(executeJob, ActorRef.noSender()); + } + + @Override + public void cancelJob(String jobId, String username) { + controller.tell(new CancelJob(jobId, username), ActorRef.noSender()); + } + + @Override + public Optional getCursor(String jobId, String username) { + Inbox inbox = Inbox.create(system); + inbox.send(controller, new FetchResult(jobId, username)); + Object receive = inbox.receive(Duration.create(1, TimeUnit.MINUTES)); + if(receive instanceof ResultNotReady) { + String errorString = "Result not ready for job: " + jobId + ", username: " + username + ". Try after sometime."; + LOG.info(errorString); + throw new ResultNotReadyFormattedException(errorString, new Exception(errorString)); + } else if(receive instanceof Failure) { + Failure failure = (Failure) receive; + throw new ResultFetchFormattedException(failure.getMessage(), failure.getError()); + } else { + Optional iterator = (Optional) receive; + if(iterator.isPresent()) { + return Optional.of(new NonPersistentCursor(context, system, iterator.get())); + } else { + return Optional.absent(); + } + } + } + + @Override + public Optional resetAndGetCursor(String jobId, String username) { + Inbox inbox = Inbox.create(system); + inbox.send(controller, new FetchResult(jobId, username)); + Object receive = inbox.receive(Duration.create(1, TimeUnit.MINUTES)); + if(receive instanceof ResultNotReady) { + String errorString = "Result not ready for job: " + jobId + ", username: " + username + ". Try after sometime."; + LOG.info(errorString); + throw new ResultNotReadyFormattedException(errorString, new Exception(errorString)); + } else if(receive instanceof Failure) { + Failure failure = (Failure) receive; + throw new ResultFetchFormattedException(failure.getMessage(), failure.getError()); + } else { + Optional iterator = (Optional) receive; + if(iterator.isPresent()) { + inbox.send(iterator.get(), new ResetCursor()); + Object resetResult = inbox.receive(Duration.create(1, TimeUnit.MINUTES)); + if (resetResult instanceof CursorReset) { + return Optional.of(new NonPersistentCursor(context, system, iterator.get())); + } else { + return Optional.absent(); + } + } else { + return Optional.absent(); + } + } + } + + @Override + public Optional getError(String jobId, String username) { + Inbox inbox = Inbox.create(system); + inbox.send(controller, new FetchError(jobId, username)); + Object receive = inbox.receive(Duration.create(1, TimeUnit.MINUTES)); + if(receive instanceof FetchFailed){ + FetchFailed fetchFailed = (FetchFailed) receive; + return Optional.of(new Failure(fetchFailed.getMessage(), getExceptionForRetry())); + } + Optional result = (Optional) receive; + return result; + } + + private ConnectionException getExceptionForRetry() { + return new ConnectionException(new SQLException("Cannot connect"),"Connection attempt failed, Please retry"); + } + + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescription.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescription.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescription.java new file mode 100644 index 0000000..d0e4b0c --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescription.java @@ -0,0 +1,45 @@ +/** + * 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.hive20.client; + +public interface ColumnDescription { + enum DataTypes { + TINYINT, // + SMALLINT, // + INT, // + BIGINT, // + BOOLEAN, // + FLOAT, // + DOUBLE, // + STRING, // + BINARY, // -- (Note: Available in Hive 0.8.0 and later) + TIMESTAMP, // -- (Note: Available in Hive 0.8.0 and later) + DECIMAL, // -- (Note: Available in Hive 0.11.0 and later) + // DECIMAL,(precision, scale)  -- (Note: Available in Hive 0.13.0 and later) Not included. + DATE, // -- (Note: Available in Hive 0.12.0 and later) + VARCHAR, // -- (Note: Available in Hive 0.12.0 and later) + CHAR, // -- (Note: Available in Hive 0.13.0 and later) + } + + String getName(); + + String getType(); + + int getPosition(); +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionExtended.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionExtended.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionExtended.java new file mode 100644 index 0000000..d33d3e0 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionExtended.java @@ -0,0 +1,74 @@ +/** + * 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.hive20.client; + +public class ColumnDescriptionExtended implements ColumnDescription { + private String name; + private String type; + private int position; + private String comment; + private boolean partitioned; + private boolean sortedBy; + private boolean clusteredBy; + + public ColumnDescriptionExtended(String name, String type, String comment, boolean partitioned, + boolean sortedBy, boolean clusteredBy, int position) { + this.name = name; + this.type = type; + this.comment = comment; + this.partitioned = partitioned; + this.sortedBy = sortedBy; + this.clusteredBy = clusteredBy; + this.position = position; + } + + public ColumnDescription createShortColumnDescription() { + return new ColumnDescriptionShort(getName(), getType(), getPosition()); + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public int getPosition() { + return position; + } + + public String getComment() { + return comment; + } + + public boolean isPartitioned() { + return partitioned; + } + + public boolean isSortedBy() { + return sortedBy; + } + + public boolean isClusteredBy() { + return clusteredBy; + } + + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionShort.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionShort.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionShort.java new file mode 100644 index 0000000..9374fd1 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ColumnDescriptionShort.java @@ -0,0 +1,53 @@ +/** + * 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.hive20.client; + +import java.util.ArrayList; + +public class ColumnDescriptionShort extends ArrayList implements ColumnDescription { + private static final int INITIAL_CAPACITY = 3; + private String name; + private String type; + private int position; + + public ColumnDescriptionShort(String name, String type, int position) { + super(INITIAL_CAPACITY); + add(name); + add(type); + add(position); + this.name = name; + this.type = type; + this.position = position; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getType() { + return type; + } + + @Override + public int getPosition() { + return position; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ConnectionConfig.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ConnectionConfig.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ConnectionConfig.java new file mode 100644 index 0000000..14bea5a --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/ConnectionConfig.java @@ -0,0 +1,59 @@ +/* + * 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.hive20.client; + +import org.apache.ambari.view.hive20.actor.message.Connect; + +public class ConnectionConfig { + private final String username; + private String password; + private final String jdbcUrl; + + public ConnectionConfig(String username, String password, String jdbcUrl) { + this.username = username; + this.password = password; + this.jdbcUrl = jdbcUrl; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getJdbcUrl() { + return jdbcUrl; + } + + public Connect createConnectMessage() { + return new Connect(username, password, jdbcUrl); + } + + public Connect createConnectMessage(String jobId) { + return new Connect(jobId, username, password, jdbcUrl); + } + + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Cursor.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Cursor.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Cursor.java new file mode 100644 index 0000000..fcf89d4 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Cursor.java @@ -0,0 +1,30 @@ +/* + * 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.hive20.client; + +import java.util.Iterator; +import java.util.List; + +public interface Cursor extends Iterator, Iterable{ + boolean isResettable(); + void reset(); + int getOffset(); + List getDescriptions(); + void keepAlive(); +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegator.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegator.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegator.java new file mode 100644 index 0000000..ffa9e132 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegator.java @@ -0,0 +1,40 @@ +/* + * 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.hive20.client; + +import java.util.List; + +public interface DDLDelegator { + + List getDbList(ConnectionConfig config, String like); + + List getTableList(ConnectionConfig config, String database, String like); + + List getTableDescriptionFormatted(ConnectionConfig config, String database, String table); + + List getTableCreateStatement(ConnectionConfig config, String database, String table); + + List getTableDescription(ConnectionConfig config, String database, String table, String like, boolean extended); + + Cursor getDbListCursor(ConnectionConfig config, String like); + + Cursor getTableListCursor(ConnectionConfig config, String database, String like); + + Cursor getTableDescriptionCursor(ConnectionConfig config, String database, String table, String like, boolean extended); +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegatorImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegatorImpl.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegatorImpl.java new file mode 100644 index 0000000..76c7c03 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/DDLDelegatorImpl.java @@ -0,0 +1,267 @@ +/* + * 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.hive20.client; + +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.Inbox; +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.base.Optional; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import org.apache.ambari.view.ViewContext; +import org.apache.ambari.view.hive20.actor.message.Connect; +import org.apache.ambari.view.hive20.actor.message.ExecuteJob; +import org.apache.ambari.view.hive20.actor.message.GetColumnMetadataJob; +import org.apache.ambari.view.hive20.actor.message.HiveJob; +import org.apache.ambari.view.hive20.actor.message.SQLStatementJob; +import org.apache.ambari.view.hive20.actor.message.job.ExecutionFailed; +import org.apache.ambari.view.hive20.actor.message.job.FetchFailed; +import org.apache.ambari.view.hive20.actor.message.job.Next; +import org.apache.ambari.view.hive20.actor.message.job.NoMoreItems; +import org.apache.ambari.view.hive20.actor.message.job.NoResult; +import org.apache.ambari.view.hive20.actor.message.job.Result; +import org.apache.ambari.view.hive20.actor.message.job.ResultSetHolder; +import org.apache.ambari.view.hive20.utils.HiveActorConfiguration; +import org.apache.ambari.view.hive20.utils.ServiceFormattedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import scala.concurrent.duration.Duration; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class DDLDelegatorImpl implements DDLDelegator { + + public static final String NO_VALUE_MARKER = "NO_VALUE"; + private final Logger LOG = LoggerFactory.getLogger(getClass()); + + private final ActorRef controller; + private final ActorSystem system; + + private final ViewContext context; + private final HiveActorConfiguration actorConfiguration; + + public DDLDelegatorImpl(ViewContext context, ActorSystem system, ActorRef controller) { + this.context = context; + this.system = system; + this.controller = controller; + actorConfiguration = new HiveActorConfiguration(context); + } + + @Override + public List getDbList(ConnectionConfig config, String like) { + Optional rowsFromDB = getRowsFromDB(config, getDatabaseListStatements(like)); + return rowsFromDB.isPresent() ? getFirstColumnValues(rowsFromDB.get().getRows()) : Lists.newArrayList(); + } + + @Override + public List getTableList(ConnectionConfig config, String database, String like) { + Optional rowsFromDB = getRowsFromDB(config, getTableListStatements(database, like)); + return rowsFromDB.isPresent() ? getFirstColumnValues(rowsFromDB.get().getRows()) : Lists.newArrayList(); + } + + @Override + public List getTableDescriptionFormatted(ConnectionConfig config, String database, String table) { + Optional rowsFromDB = getRowsFromDB(config, getTableDescriptionStatements(database, table)); + return rowsFromDB.isPresent() ? rowsFromDB.get().getRows() : null; + } + + @Override + public List getTableCreateStatement(ConnectionConfig config, String database, String table) { + Optional rowsFromDB = getRowsFromDB(config, getShowCreateTableStatements(database, table)); + return rowsFromDB.isPresent() ? rowsFromDB.get().getRows() : null; + } + + private String[] getShowCreateTableStatements(String database, String table) { + return new String[]{ + String.format("use %s",database), + String.format("show create table %s", table) + }; + } + + private String[] getTableDescriptionStatements(String database, String table) { + return new String[]{ + String.format("use %s",database), + String.format("describe formatted %s", table) + }; + } + + @Override + public List getTableDescription(ConnectionConfig config, String database, String table, String like, boolean extended) { + Optional resultOptional = getTableDescription(config, database, table, like); + List descriptions = new ArrayList<>(); + if(resultOptional.isPresent()) { + for (Row row : resultOptional.get().getRows()) { + Object[] values = row.getRow(); + String name = (String) values[3]; + String type = (String) values[5]; + int position = (Integer) values[16]; + descriptions.add(new ColumnDescriptionShort(name, type, position)); + } + } + return descriptions; + } + + @Override + public Cursor getDbListCursor(ConnectionConfig config, String like) { + Optional rowsFromDB = getRowsFromDB(config, getDatabaseListStatements(like)); + if (rowsFromDB.isPresent()) { + Result result = rowsFromDB.get(); + return new PersistentCursor<>(result.getRows(), result.getColumns()); + } else { + return new PersistentCursor<>(Lists.newArrayList(), Lists.newArrayList()); + } + } + + @Override + public Cursor getTableListCursor(ConnectionConfig config, String database, String like) { + Optional rowsFromDB = getRowsFromDB(config, getTableListStatements(database, like)); + if (rowsFromDB.isPresent()) { + Result result = rowsFromDB.get(); + return new PersistentCursor<>(result.getRows(), result.getColumns()); + } else { + return new PersistentCursor<>(Lists.newArrayList(), Lists.newArrayList()); + } + } + + @Override + public Cursor getTableDescriptionCursor(ConnectionConfig config, String database, String table, String like, boolean extended) { + Optional tableDescriptionOptional = getTableDescription(config, database, table, like); + if(tableDescriptionOptional.isPresent()) { + Result result = tableDescriptionOptional.get(); + return new PersistentCursor<>(result.getRows(), result.getColumns()); + } else { + return new PersistentCursor<>(Lists.newArrayList(), Lists.newArrayList()); + } + } + + private String[] getDatabaseListStatements(String like) { + return new String[]{ + String.format("show databases like '%s'", like) + }; + } + + private String[] getTableListStatements(String database, String like) { + return new String[]{ + String.format("use %s", database), + String.format("show tables like '%s'", like) + }; + } + + private Optional getRowsFromDB(ConnectionConfig config, String[] statements) { + Connect connect = config.createConnectMessage(); + HiveJob job = new SQLStatementJob(HiveJob.Type.SYNC, statements, config.getUsername()); + ExecuteJob execute = new ExecuteJob(connect, job); + + LOG.info("Executing query: {}, for user: {}", getJoinedStatements(statements), job.getUsername()); + + return getResultFromDB(execute); + } + + private Optional getTableDescription(ConnectionConfig config, String databasePattern, String tablePattern, String columnPattern) { + Connect connect = config.createConnectMessage(); + HiveJob job = new GetColumnMetadataJob(config.getUsername(), databasePattern, tablePattern, columnPattern); + ExecuteJob execute = new ExecuteJob(connect, job); + + LOG.info("Executing query to fetch the column description for dbPattern: {}, tablePattern: {}, columnPattern: {}, for user: {}", + databasePattern, tablePattern, columnPattern, job.getUsername()); + return getResultFromDB(execute); + } + + private Optional getResultFromDB(ExecuteJob job) { + List descriptions = null; + List rows = Lists.newArrayList(); + Inbox inbox = Inbox.create(system); + inbox.send(controller, job); + Object submitResult; + try { + submitResult = inbox.receive(Duration.create(actorConfiguration.getSyncQueryTimeout(60 * 1000), TimeUnit.MILLISECONDS)); + } catch (Throwable ex) { + String errorMessage = "Query timed out to fetch table description for user: " + job.getConnect().getUsername(); + LOG.error(errorMessage, ex); + throw new ServiceFormattedException(errorMessage, ex); + } + + if (submitResult instanceof NoResult) { + LOG.info("Query returned with no result."); + return Optional.absent(); + } + + if (submitResult instanceof ExecutionFailed) { + ExecutionFailed error = (ExecutionFailed) submitResult; + LOG.error("Failed to get the table description"); + throw new ServiceFormattedException(error.getMessage(), error.getError()); + + } else if (submitResult instanceof ResultSetHolder) { + ResultSetHolder holder = (ResultSetHolder) submitResult; + ActorRef iterator = holder.getIterator(); + while (true) { + inbox.send(iterator, new Next()); + Object receive; + try { + receive = inbox.receive(Duration.create(actorConfiguration.getResultFetchTimeout(60 * 1000), TimeUnit.MILLISECONDS)); + } catch (Throwable ex) { + String errorMessage = "Query timed out to fetch results for user: " + job.getConnect().getUsername(); + LOG.error(errorMessage, ex); + throw new ServiceFormattedException(errorMessage, ex); + } + + if (receive instanceof Result) { + Result result = (Result) receive; + if (descriptions == null) { + descriptions = result.getColumns(); + } + rows.addAll(result.getRows()); + } + + if (receive instanceof NoMoreItems) { + break; + } + + if (receive instanceof FetchFailed) { + FetchFailed error = (FetchFailed) receive; + LOG.error("Failed to fetch results "); + throw new ServiceFormattedException(error.getMessage(), error.getError()); + } + } + + } + return Optional.of(new Result(rows, descriptions)); + } + + private String getJoinedStatements(String[] statements) { + return Joiner.on("; ").skipNulls().join(statements); + } + + private ImmutableList getFirstColumnValues(List rows) { + return FluentIterable.from(rows) + .transform(new Function() { + @Override + public String apply(Row input) { + Object[] values = input.getRow(); + return values.length > 0 ? (String) values[0] : NO_VALUE_MARKER; + } + }).toList(); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/EmptyCursor.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/EmptyCursor.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/EmptyCursor.java new file mode 100644 index 0000000..17af66e --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/EmptyCursor.java @@ -0,0 +1,110 @@ +/* + * 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.hive20.client; + +import com.beust.jcommander.internal.Lists; +import org.apache.commons.lang.NotImplementedException; + +import java.util.Iterator; +import java.util.List; + +public class EmptyCursor implements Cursor { + + private List rows = Lists.newArrayList(); + private List desc = Lists.newArrayList(); + + + @Override + public boolean isResettable() { + return false; + } + + @Override + public void reset() { + + } + + @Override + public int getOffset() { + return 0; + } + + @Override + public List getDescriptions() { + return desc; + } + + @Override + public void keepAlive() { + // Do Nothing + } + + /** + * Returns an iterator over a set of elements of type T. + * + * @return an Iterator. + */ + @Override + public Iterator iterator() { + return rows.iterator(); + } + + /** + * Returns {@code true} if the iteration has more elements. + * (In other words, returns {@code true} if {@link #next} would + * return an element rather than throwing an exception.) + * + * @return {@code true} if the iteration has more elements + */ + @Override + public boolean hasNext() { + return false; + } + + /** + * Returns the next element in the iteration. + * + * @return the next element in the iteration + * @throws NotImplementedException if the iteration has no more elements + */ + @Override + public Row next() { + throw new NotImplementedException(); + } + + /** + * Removes from the underlying collection the last element returned + * by this iterator (optional operation). This method can be called + * only once per call to {@link #next}. The behavior of an iterator + * is unspecified if the underlying collection is modified while the + * iteration is in progress in any way other than by calling this + * method. + * + * @throws UnsupportedOperationException if the {@code remove} + * operation is not supported by this iterator + * @throws IllegalStateException if the {@code next} method has not + * yet been called, or the {@code remove} method has already + * been called after the last call to the {@code next} + * method + */ + @Override + public void remove() { + throw new NotImplementedException(); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthCredentials.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthCredentials.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthCredentials.java new file mode 100644 index 0000000..2897f22 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthCredentials.java @@ -0,0 +1,31 @@ +/** + * 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.hive20.client; + +public class HiveAuthCredentials { + private String password; + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthRequiredException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthRequiredException.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthRequiredException.java new file mode 100644 index 0000000..f34479e --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveAuthRequiredException.java @@ -0,0 +1,27 @@ +/** + * 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.hive20.client; + +import org.apache.ambari.view.hive20.utils.ServiceFormattedException; + +public class HiveAuthRequiredException extends ServiceFormattedException { + public HiveAuthRequiredException() { + super("Hive Password Required", null, 401); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientAuthRequiredException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientAuthRequiredException.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientAuthRequiredException.java new file mode 100644 index 0000000..41c0d64 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientAuthRequiredException.java @@ -0,0 +1,25 @@ +/** + * 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.hive20.client; + +public class HiveClientAuthRequiredException extends Exception { + public HiveClientAuthRequiredException(String comment, Exception ex) { + super(comment + ((ex == null)?"":(": " + ex.toString())), ex); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientException.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientException.java new file mode 100644 index 0000000..4caf50e --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientException.java @@ -0,0 +1,25 @@ +/** + * 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.hive20.client; + +public class HiveClientException extends Exception { + public HiveClientException(String comment, Exception ex) { + super(comment + ((ex == null)?"":(": " + ex.toString())), ex); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientRuntimeException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientRuntimeException.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientRuntimeException.java new file mode 100644 index 0000000..c5fcf69 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/HiveClientRuntimeException.java @@ -0,0 +1,25 @@ +/** + * 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.hive20.client; + +public class HiveClientRuntimeException extends RuntimeException { + public HiveClientRuntimeException(String comment, Exception ex) { + super(comment + ((ex == null)?"":(": " + ex.toString())), ex); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/NonPersistentCursor.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/NonPersistentCursor.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/NonPersistentCursor.java new file mode 100644 index 0000000..40468f7 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/NonPersistentCursor.java @@ -0,0 +1,153 @@ +/* + * 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.hive20.client; + +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.Inbox; +import com.google.common.collect.Lists; +import org.apache.ambari.view.ViewContext; +import org.apache.ambari.view.hive20.actor.message.lifecycle.KeepAlive; +import org.apache.ambari.view.hive20.utils.HiveActorConfiguration; +import org.apache.ambari.view.hive20.utils.ServiceFormattedException; +import org.apache.ambari.view.hive20.actor.message.job.FetchFailed; +import org.apache.ambari.view.hive20.actor.message.job.Next; +import org.apache.ambari.view.hive20.actor.message.job.NoMoreItems; +import org.apache.ambari.view.hive20.actor.message.job.Result; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import scala.concurrent.duration.Duration; + +import java.util.Iterator; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.TimeUnit; + +/** + * Wrapper over iterator actor and blocks to fetch Rows and ColumnDescription whenever there is no more Rows to be + * returned. + */ +public class NonPersistentCursor implements Cursor { + private final Logger LOG = LoggerFactory.getLogger(getClass()); + private static long DEFAULT_WAIT_TIMEOUT = 60 * 1000L; + + private final ActorSystem system; + private final ActorRef actorRef; + private final ViewContext context; + private final HiveActorConfiguration actorConfiguration; + private final Queue rows = Lists.newLinkedList(); + private final List descriptions = Lists.newLinkedList(); + private int offSet = 0; + private boolean endReached = false; + + + public NonPersistentCursor(ViewContext context, ActorSystem system, ActorRef actorRef) { + this.context = context; + this.system = system; + this.actorRef = actorRef; + actorConfiguration = new HiveActorConfiguration(context); + } + + @Override + public boolean isResettable() { + return false; + } + + @Override + public void reset() { + // Do nothing + } + + @Override + public int getOffset() { + return offSet; + } + + @Override + public List getDescriptions() { + fetchIfNeeded(); + return descriptions; + } + + @Override + public void keepAlive() { + Inbox inbox = Inbox.create(system); + inbox.send(actorRef, new KeepAlive()); + } + + @Override + public Iterator iterator() { + return this; + } + + @Override + public boolean hasNext() { + fetchIfNeeded(); + return !endReached; + } + + @Override + public Row next() { + fetchIfNeeded(); + offSet++; + return rows.poll(); + } + + @Override + public void remove() { + throw new RuntimeException("Read only cursor. Method not supported"); + } + + private void fetchIfNeeded() { + if (endReached || rows.size() > 0) return; + getNextRows(); + } + + private void getNextRows() { + Inbox inbox = Inbox.create(system); + inbox.send(actorRef, new Next()); + Object receive; + try { + receive = inbox.receive(Duration.create(actorConfiguration.getResultFetchTimeout(DEFAULT_WAIT_TIMEOUT), + TimeUnit.MILLISECONDS)); + } catch (Throwable ex) { + String errorMessage = "Result fetch timed out"; + LOG.error(errorMessage, ex); + throw new ServiceFormattedException(errorMessage, ex); + } + + if (receive instanceof Result) { + Result result = (Result) receive; + if (descriptions.isEmpty()) { + descriptions.addAll(result.getColumns()); + } + rows.addAll(result.getRows()); + } + + if (receive instanceof NoMoreItems) { + endReached = true; + } + + if (receive instanceof FetchFailed) { + FetchFailed error = (FetchFailed) receive; + LOG.error("Failed to fetch results "); + throw new ServiceFormattedException(error.getMessage(), error.getError()); + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/PersistentCursor.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/PersistentCursor.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/PersistentCursor.java new file mode 100644 index 0000000..1fa1ceb --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/PersistentCursor.java @@ -0,0 +1,87 @@ +/* + * 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.hive20.client; + + +import com.google.common.collect.Lists; + +import java.util.Iterator; +import java.util.List; + +/** + * Wrapper over other iterables. Does not block and can be reset to start again from beginning. + */ +public class PersistentCursor implements Cursor { + private List rows = Lists.newArrayList(); + private List columns = Lists.newArrayList(); + private int offset = 0; + + public PersistentCursor(List rows, List columns) { + this.rows = rows; + this.columns = columns; + } + + + @Override + public Iterator iterator() { + return this; + } + + @Override + public boolean hasNext() { + return rows.size() > 0 && offset < rows.size(); + } + + @Override + public T next() { + T row = rows.get(offset); + offset++; + return row; + } + + @Override + public void remove() { + throw new RuntimeException("Read only cursor. Method not supported"); + } + + @Override + public boolean isResettable() { + return true; + } + + @Override + public void reset() { + this.offset = 0; + } + + @Override + public int getOffset() { + return offset; + } + + @Override + public List getDescriptions() { + return columns; + } + + @Override + public void keepAlive() { + // Do Nothing as we are pre-fetching everything. + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Row.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Row.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Row.java new file mode 100644 index 0000000..e1139f2 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/client/Row.java @@ -0,0 +1,74 @@ +/** + * 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.hive20.client; + +import java.util.Arrays; +import java.util.HashSet; + +public class Row { + private Object[] row; + + public Row(Object[] row) { + this(row, null); + } + + public Row(Object[] row, HashSet selectedColumns) { + if (selectedColumns == null || selectedColumns.size() == 0) + this.row = row.clone(); + else { + this.row = new Object[selectedColumns.size()]; + int rowIndex = 0; + for (Integer selectedIndex : selectedColumns) { + this.row[rowIndex] = row[selectedIndex]; + rowIndex ++; + } + } + } + + public Object[] getRow() { + return row; + } + + public void setRow(Object[] row) { + this.row = row; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Row row1 = (Row) o; + + boolean retValue = Arrays.equals(row, row1.row); + return retValue; + } + + @Override + public int hashCode() { + return Arrays.hashCode(row); + } + + @Override + public String toString() { + return "Row{" + + "row=" + Arrays.toString(row) + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/NotConnectedException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/NotConnectedException.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/NotConnectedException.java new file mode 100644 index 0000000..6096727 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/NotConnectedException.java @@ -0,0 +1,28 @@ +/* + * 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.hive20.exceptions; + +/** + * Exception thrown when the connection is not made and we try to execute some job + */ +public class NotConnectedException extends RuntimeException { + public NotConnectedException(String message) { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/ServiceException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/ServiceException.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/ServiceException.java new file mode 100644 index 0000000..e260c16 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/exceptions/ServiceException.java @@ -0,0 +1,40 @@ +/* +* 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.hive20.exceptions; + +public class ServiceException extends Exception { + public ServiceException() { + } + + public ServiceException(String message) { + super(message); + } + + public ServiceException(String message, Throwable cause) { + super(message, cause); + } + + public ServiceException(Throwable cause) { + super(cause); + } + + public ServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionFailure.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionFailure.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionFailure.java new file mode 100644 index 0000000..d8dd3d3 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionFailure.java @@ -0,0 +1,23 @@ +/* + * 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.hive20.internal; + +public class AsyncExecutionFailure { +} + http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionSuccess.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionSuccess.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionSuccess.java new file mode 100644 index 0000000..63e4112 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/AsyncExecutionSuccess.java @@ -0,0 +1,25 @@ +/* + * 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.hive20.internal; + +public class AsyncExecutionSuccess { + + +} + http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/Connectable.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/Connectable.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/Connectable.java new file mode 100644 index 0000000..10c6e7d --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/Connectable.java @@ -0,0 +1,65 @@ +/* + * 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.hive20.internal; + +import com.google.common.base.Optional; +import org.apache.hive.jdbc.HiveConnection; + +/** + * Life cycle management for java.sql.Connection + */ +public interface Connectable { + + /** + * Get the underlying connection + * @return an optional wrapping the connection + */ + Optional getConnection(); + + /** + * Check if the connection is open + * @return + */ + boolean isOpen(); + + /** + * Open a connection + * @throws ConnectionException + */ + void connect() throws ConnectionException; + + /** + * Reconnect if closed + * @throws ConnectionException + */ + void reconnect() throws ConnectionException; + + /** + * Close the connection + * @throws ConnectionException + */ + void disconnect() throws ConnectionException; + + /** + * True when the connection is unauthorized + * @return + */ + boolean isUnauthorized(); + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionException.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionException.java new file mode 100644 index 0000000..14a6397 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionException.java @@ -0,0 +1,25 @@ +/* + * 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.hive20.internal; + +public class ConnectionException extends Exception { + public ConnectionException(Exception e, String message) { + super(message,e); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionProperties.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionProperties.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionProperties.java new file mode 100644 index 0000000..10cd784 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionProperties.java @@ -0,0 +1,94 @@ +/* + * 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.hive20.internal; + +import com.google.common.collect.Maps; + +import java.util.Map; + +/** + * Holds all information needed to connect to HS2 + */ +public class ConnectionProperties { + + private String host; + private int port; + private String userName; + private String password; + private Map authParams = Maps.newHashMap(); + + public Map getAuthParams() { + return authParams; + } + + public void addAuthParam(String key,String value){ + authParams.put(key, value); + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + @Override + public String toString() { + return "HiveConnectionProps{" + + "authParams=" + authParams + + ", host='" + host + '\'' + + ", port=" + port + + ", userName='" + userName + '\'' + + ", password='" + password + '\'' + + '}'; + } + + public String asUrl() { + return null; + } + + public String asUrlWithoutCredentials() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionSupplier.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionSupplier.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionSupplier.java new file mode 100644 index 0000000..b25b4dd --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ConnectionSupplier.java @@ -0,0 +1,37 @@ +/* + * 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.hive20.internal; + +import org.apache.ambari.view.ViewContext; +import org.apache.ambari.view.hive20.ConnectionDelegate; +import org.apache.ambari.view.hive20.HiveJdbcConnectionDelegate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConnectionSupplier implements ContextSupplier { + + protected final Logger LOG = + LoggerFactory.getLogger(getClass()); + + @Override + public ConnectionDelegate get(ViewContext context) { + LOG.debug("Creating Connection delegate instance for Viewname: {}, Instance Name: {}", context.getViewName(), context.getInstanceName()); + return new HiveJdbcConnectionDelegate(); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ContextSupplier.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ContextSupplier.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ContextSupplier.java new file mode 100644 index 0000000..dff5e25 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/ContextSupplier.java @@ -0,0 +1,37 @@ +/* + * 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.hive20.internal; + +import org.apache.ambari.view.ViewContext; + +/** + * A class that can supply objects of same type. + * @param + */ +public interface ContextSupplier { + /** + * Retrieves an instance of appropriate type. The returned object could be a new instance + * or an exiting instance. No guarantee on that. + * @param context View Context to be used to create the instance + * @return instance of appropriateType + */ + T get(ViewContext context); + + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf30fd7/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/DataStorageSupplier.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/DataStorageSupplier.java b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/DataStorageSupplier.java new file mode 100644 index 0000000..93f8fb1 --- /dev/null +++ b/contrib/views/hive20/src/main/java/org/apache/ambari/view/hive20/internal/DataStorageSupplier.java @@ -0,0 +1,42 @@ +/* + * 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.hive20.internal; + +import org.apache.ambari.view.ViewContext; +import org.apache.ambari.view.hive20.persistence.DataStoreStorage; +import org.apache.ambari.view.hive20.persistence.Storage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * A supplier for data storage + * Duplicated to keep the API uniform + */ +public class DataStorageSupplier implements ContextSupplier { + + protected final Logger LOG = + LoggerFactory.getLogger(getClass()); + + @Override + public Storage get(ViewContext context) { + LOG.debug("Creating storage instance for Viewname: {}, Instance Name: {}", context.getViewName(), context.getInstanceName()); + return new DataStoreStorage(context); + } +}