AMBARI-10997. Improve Error Handling - hive view (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/642fd46c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/642fd46c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/642fd46c Branch: refs/heads/trunk Commit: 642fd46cbf5d8e232007b487ceef0618aa2dd9e7 Parents: c0da0a1 Author: Alex Antonenko <hiv...@gmail.com> Authored: Fri May 8 13:23:32 2015 +0300 Committer: Alex Antonenko <hiv...@gmail.com> Committed: Fri May 8 21:02:37 2015 +0300 ---------------------------------------------------------------------- contrib/views/hive/pom.xml | 2 +- .../apache/ambari/view/hive/BaseService.java | 4 +- .../apache/ambari/view/hive/HelpService.java | 2 +- .../ambari/view/hive/client/Connection.java | 5 +- .../resources/PersonalCRUDResourceManager.java | 9 +- .../resources/browser/HiveBrowserService.java | 2 +- .../view/hive/resources/files/FileService.java | 2 +- .../view/hive/resources/jobs/Aggregator.java | 4 +- .../resources/jobs/ConnectionController.java | 3 +- .../jobs/IOperationHandleResourceManager.java | 6 +- .../resources/jobs/JobResourceProvider.java | 4 +- .../view/hive/resources/jobs/JobService.java | 32 +++- .../jobs/OperationHandleController.java | 31 ++-- .../jobs/OperationHandleControllerFactory.java | 4 +- .../jobs/OperationHandleResourceManager.java | 40 ++++- .../hive/resources/jobs/ProgressRetriever.java | 67 ++++++++ .../hive/resources/jobs/atsJobs/ATSParser.java | 27 +++ .../jobs/atsJobs/ATSRequestsDelegate.java | 4 + .../jobs/atsJobs/ATSRequestsDelegateImpl.java | 15 +- .../hive/resources/jobs/atsJobs/IATSParser.java | 2 + .../resources/jobs/atsJobs/TezVertexId.java | 24 +++ .../view/hive/resources/jobs/rm/RMParser.java | 88 ++++++++++ .../hive/resources/jobs/rm/RMParserFactory.java | 39 +++++ .../resources/jobs/rm/RMRequestsDelegate.java | 31 ++++ .../jobs/rm/RMRequestsDelegateImpl.java | 99 +++++++++++ .../resources/FileResourceResourceProvider.java | 4 +- .../resources/FileResourceService.java | 2 +- .../SavedQueryResourceProvider.java | 4 +- .../savedQueries/SavedQueryService.java | 2 +- .../resources/udfs/UDFResourceProvider.java | 4 +- .../view/hive/resources/udfs/UDFService.java | 2 +- .../hive/utils/ServiceFormattedException.java | 20 ++- .../view/hive/utils/SharedObjectsFactory.java | 20 ++- .../src/main/resources/ui/hive-web/.gitignore | 4 +- .../ui/hive-web/app/adapters/application.js | 2 +- .../app/components/alert-message-widget.js | 2 +- .../app/components/collapsible-widget.js | 2 +- .../app/components/column-filter-widget.js | 2 +- .../app/components/date-range-widget.js | 45 +++-- .../hive-web/app/components/expander-widget.js | 6 + .../ui/hive-web/app/components/modal-widget.js | 12 +- .../ui/hive-web/app/components/notify-widget.js | 8 +- .../app/components/number-range-widget.js | 42 +++-- .../ui/hive-web/app/components/panel-widget.js | 2 +- .../hive-web/app/components/popover-widget.js | 5 +- .../hive-web/app/components/progress-widget.js | 29 +--- .../ui/hive-web/app/components/query-editor.js | 6 +- .../ui/hive-web/app/components/query-tabs.js | 121 -------------- .../hive-web/app/components/typeahead-widget.js | 19 ++- .../ui/hive-web/app/controllers/databases.js | 10 +- .../ui/hive-web/app/controllers/history.js | 25 +++ .../ui/hive-web/app/controllers/index.js | 95 ++++------- .../controllers/index/history-query/explain.js | 5 +- .../app/controllers/index/history-query/logs.js | 13 +- .../controllers/index/history-query/results.js | 6 +- .../ui/hive-web/app/controllers/job-progress.js | 92 +++++++++++ .../ui/hive-web/app/controllers/job.js | 2 +- .../ui/hive-web/app/controllers/messages.js | 10 +- .../ui/hive-web/app/controllers/open-queries.js | 6 +- .../ui/hive-web/app/controllers/queries.js | 20 ++- .../ui/hive-web/app/controllers/query-tabs.js | 164 +++++++++++++++++++ .../ui/hive-web/app/controllers/settings.js | 144 ++++++++-------- .../ui/hive-web/app/controllers/tez-ui.js | 19 +-- .../ui/hive-web/app/controllers/udfs.js | 17 ++ .../hive-web/app/controllers/visual-explain.js | 27 ++- .../ui/hive-web/app/helpers/all-uppercase.js | 4 +- .../ui/hive-web/app/helpers/code-helper.js | 2 +- .../ui/hive-web/app/helpers/date-binding.js | 2 +- .../ui/hive-web/app/helpers/log-helper.js | 2 +- .../ui/hive-web/app/helpers/path-binding.js | 2 +- .../hive-web/app/helpers/preformatted-string.js | 2 +- .../ui/hive-web/app/helpers/tb-helper.js | 2 +- .../ui/hive-web/app/initializers/i18n.js | 22 ++- .../ui/hive-web/app/initializers/notify.js | 2 +- .../ui/hive-web/app/mixins/filterable.js | 8 +- .../main/resources/ui/hive-web/app/router.js | 2 +- .../ui/hive-web/app/routes/application.js | 15 +- .../ui/hive-web/app/routes/index/saved-query.js | 12 +- .../ui/hive-web/app/serializers/database.js | 4 +- .../ui/hive-web/app/services/notify.js | 31 ++-- .../resources/ui/hive-web/app/styles/app.scss | 44 ++++- .../hive-web/app/styles/dropdown-submenu.scss | 1 - .../ui/hive-web/app/styles/mixins.scss | 32 ++-- .../ui/hive-web/app/styles/notifications.scss | 1 + .../ui/hive-web/app/styles/query-tabs.scss | 3 +- .../resources/ui/hive-web/app/styles/vars.scss | 1 + .../ui/hive-web/app/templates/application.hbs | 2 +- .../templates/components/progress-widget.hbs | 10 +- .../app/templates/components/query-tabs.hbs | 29 ---- .../ui/hive-web/app/templates/index.hbs | 8 +- .../ui/hive-web/app/templates/messages.hbs | 20 ++- .../ui/hive-web/app/templates/query-tabs.hbs | 29 ++++ .../ui/hive-web/app/templates/tez-ui.hbs | 2 +- .../hive-web/app/templates/visual-explain.hbs | 105 ++++++------ .../ui/hive-web/app/utils/constants.js | 61 +++---- .../ui/hive-web/app/utils/dag-rules.js | 2 +- .../ui/hive-web/app/utils/functions.js | 21 ++- .../resources/ui/hive-web/app/views/message.js | 4 +- .../resources/ui/hive-web/app/views/messages.js | 35 ++++ .../ui/hive-web/app/views/notification.js | 14 +- .../ui/hive-web/app/views/visual-explain.js | 108 +++++++----- .../src/main/resources/ui/hive-web/package.json | 2 +- .../ui/hive-web/tests/blanket-options.js | 23 ++- .../ui/hive-web/tests/helpers/api-mock.js | 17 +- .../main/resources/ui/hive-web/tests/index.html | 1 + .../hive-web/tests/integration/database-test.js | 2 - .../hive-web/tests/unit/adapters/application.js | 2 +- .../unit/components/collapsible-widget-test.js | 2 +- .../components/column-filter-widget-test.js | 2 +- .../unit/components/date-range-widget-test.js | 10 +- .../unit/components/expander-widget-test.js | 4 +- .../unit/components/extended-input-test.js | 8 +- .../tests/unit/components/no-bubbling-test.js | 2 +- .../unit/components/number-range-widget-test.js | 10 +- .../unit/components/popover-widget-test.js | 2 +- .../unit/components/progress-widget-test.js | 4 +- .../tests/unit/components/query-editor-test.js | 4 +- .../tests/unit/components/select-widget-test.js | 6 +- .../tests/unit/components/tabs-wiget-test.js | 2 +- .../unit/components/typeahead-widget-test.js | 2 +- .../tests/unit/controllers/index-test.js | 103 +++++++++++- .../tests/unit/controllers/settings-test.js | 1 - .../unit/controllers/visual-explain-test.js | 2 +- .../hive-web/tests/unit/services/notify-test.js | 153 +++++++++++++++++ contrib/views/hive/src/main/resources/view.xml | 17 +- .../view/hive/resources/jobs/ATSParserTest.java | 26 ++- .../hive/resources/jobs/AggregatorTest.java | 32 +++- 127 files changed, 1915 insertions(+), 734 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/pom.xml ---------------------------------------------------------------------- diff --git a/contrib/views/hive/pom.xml b/contrib/views/hive/pom.xml index 81bf144..f3f8f36 100644 --- a/contrib/views/hive/pom.xml +++ b/contrib/views/hive/pom.xml @@ -19,7 +19,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.ambari.contrib.views</groupId> <artifactId>hive</artifactId> - <version>0.2.0-SNAPSHOT</version> + <version>0.3.0-SNAPSHOT</version> <name>Hive</name> <parent> http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/BaseService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/BaseService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/BaseService.java index a963975..d29d758 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/BaseService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/BaseService.java @@ -18,13 +18,13 @@ package org.apache.ambari.view.hive; -import com.google.inject.Inject; import org.apache.ambari.view.ViewContext; -import org.apache.ambari.view.hive.utils.HdfsApi; import org.apache.ambari.view.hive.utils.SharedObjectsFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; + /** * Parent service http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java index 870e31a..d581d9a 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/HelpService.java @@ -18,10 +18,10 @@ package org.apache.ambari.view.hive; -import com.google.inject.Inject; import org.apache.ambari.view.ViewContext; import org.apache.ambari.view.ViewResourceHandler; +import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java index cf1a998..15ebd09 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/client/Connection.java @@ -18,6 +18,7 @@ package org.apache.ambari.view.hive.client; +import org.apache.ambari.view.hive.utils.HiveClientFormattedException; import org.apache.commons.codec.binary.Hex; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.shims.ShimLoader; @@ -347,10 +348,10 @@ public class Connection { public String getLogs(TOperationHandle handle) { LogsCursor results = new LogsCursor(this, handle); results.reset(); // we have to read from FIRST line, to get - // logs from beginning on every call this function + // logs from beginning on every call this function List<String> logLineList = results.getValuesInColumn(0); StringBuilder log = new StringBuilder(); - for(String line : logLineList) { + for (String line : logLineList) { log.append(line); log.append('\n'); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/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 index 4593b76..72a4e8f 100644 --- 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 @@ -92,14 +92,7 @@ public class PersonalCRUDResourceManager<T extends PersonalResource> extends CRU return result; } - protected static String getUsername(ViewContext context) { - String userName = context.getProperties().get("dataworker.username"); - if (userName == null || userName.compareTo("null") == 0 || userName.compareTo("") == 0) - userName = context.getUsername(); - return userName; - } - protected String getUsername() { - return getUsername(context); + return context.getUsername(); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/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 index 844d20e..a0d44f5 100644 --- 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 @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.browser; -import com.google.inject.Inject; import org.apache.ambari.view.ViewContext; import org.apache.ambari.view.ViewResourceHandler; import org.apache.ambari.view.hive.client.ColumnDescription; @@ -34,6 +33,7 @@ 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; http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileService.java index 8bde44c..ef48b5d 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/files/FileService.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.files; -import com.google.inject.Inject; import com.jayway.jsonpath.JsonPath; import org.apache.ambari.view.ViewContext; import org.apache.ambari.view.ViewResourceHandler; @@ -32,6 +31,7 @@ import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.Context; http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/Aggregator.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/Aggregator.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/Aggregator.java index 687298e..31eb678 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/Aggregator.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/Aggregator.java @@ -130,7 +130,7 @@ public class Aggregator { } public Job readATSJob(Job viewJob) throws ItemNotFound { - TOperationHandle operationHandle = operationHandleResourceManager.getHandleForJob(viewJob); + TOperationHandle operationHandle = operationHandleResourceManager.getHandleForJob(viewJob).toTOperationHandle(); String hexGuid = Hex.encodeHexString(operationHandle.getOperationId().getGuid()); HiveQueryId atsHiveQuery = ats.getHiveQueryIdByOperationId(hexStringToUrlSafeBase64(hexGuid)); @@ -174,12 +174,12 @@ public class Aggregator { if (viewJob.getDagName() == null || viewJob.getDagName().isEmpty()) { if (hiveQueryId.dagNames != null && hiveQueryId.dagNames.size() > 0) { viewJob.setDagName(hiveQueryId.dagNames.get(0)); - viewJob.setDagId(tezDagId.entity); viewJobResourceManager.update(viewJob, viewJob.getId()); } } if ((tezDagId.status.compareToIgnoreCase(Job.JOB_STATE_UNKNOWN) != 0) && !viewJob.getStatus().equals(tezDagId.status)) { + viewJob.setDagId(tezDagId.entity); viewJob.setStatus(tezDagId.status); viewJobResourceManager.update(viewJob, viewJob.getId()); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ConnectionController.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ConnectionController.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ConnectionController.java index f481993..92cf67d 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ConnectionController.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ConnectionController.java @@ -68,6 +68,7 @@ public class ConnectionController { } catch (HiveClientException e) { throw new HiveClientFormattedException(e); } - return operationHandleControllerFactory.createControllerForHandle(operationHandle); + StoredOperationHandle storedOperationHandle = StoredOperationHandle.buildFromTOperationHandle(operationHandle); + return operationHandleControllerFactory.createControllerForHandle(storedOperationHandle); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/IOperationHandleResourceManager.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/IOperationHandleResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/IOperationHandleResourceManager.java index 185402e..961d6c2 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/IOperationHandleResourceManager.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/IOperationHandleResourceManager.java @@ -28,9 +28,13 @@ import java.util.List; public interface IOperationHandleResourceManager extends IResourceManager<StoredOperationHandle> { List<StoredOperationHandle> readJobRelatedHandles(Job job); + List<Job> getHandleRelatedJobs(StoredOperationHandle operationHandle); + + Job getJobByHandle(StoredOperationHandle handle) throws ItemNotFound; + void putHandleForJob(TOperationHandle h, Job job); boolean containsHandleForJob(Job job); - TOperationHandle getHandleForJob(Job job) throws ItemNotFound; + StoredOperationHandle getHandleForJob(Job job) throws ItemNotFound; } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobResourceProvider.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobResourceProvider.java index 460278e..48a544d 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobResourceProvider.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobResourceProvider.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.jobs; -import com.google.inject.Inject; import org.apache.ambari.view.*; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; @@ -27,6 +26,7 @@ import org.apache.ambari.view.hive.utils.SharedObjectsFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.Map; @@ -61,6 +61,8 @@ public class JobResourceProvider implements ResourceProvider<Job> { @Override public Set<Job> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { + if (context == null) + return new HashSet(); return new HashSet<Job>(getResourceManager().readAll( new OnlyOwnersFilteringStrategy(this.context.getUsername()))); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobService.java index 3c1895b..ae0e828 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/JobService.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.jobs; -import com.google.inject.Inject; import org.apache.ambari.view.ViewResourceHandler; import org.apache.ambari.view.hive.BaseService; import org.apache.ambari.view.hive.backgroundjobs.BackgroundJobController; @@ -26,13 +25,9 @@ import org.apache.ambari.view.hive.client.Connection; import org.apache.ambari.view.hive.client.Cursor; import org.apache.ambari.view.hive.client.HiveClientException; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; -import org.apache.ambari.view.hive.resources.jobs.atsJobs.ATSRequestsDelegate; -import org.apache.ambari.view.hive.resources.jobs.atsJobs.ATSRequestsDelegateImpl; -import org.apache.ambari.view.hive.resources.jobs.atsJobs.ATSParser; import org.apache.ambari.view.hive.resources.jobs.atsJobs.IATSParser; import org.apache.ambari.view.hive.resources.jobs.viewJobs.*; import org.apache.ambari.view.hive.utils.*; -import org.apache.ambari.view.hive.utils.HdfsApi; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; @@ -41,6 +36,7 @@ import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.*; @@ -87,8 +83,7 @@ public class JobService extends BaseService { protected Aggregator getAggregator() { if (aggregator == null) { - ATSRequestsDelegate transport = new ATSRequestsDelegateImpl(context, "http://127.0.0.1:8188"); - IATSParser atsParser = new ATSParser(transport); + IATSParser atsParser = getSharedObjectsFactory().getATSParser(); aggregator = new Aggregator(getResourceManager(), getOperationHandleResourceManager(), atsParser); } return aggregator; @@ -320,6 +315,29 @@ public class JobService extends BaseService { } /** + * Get progress info + */ + @GET + @Path("{jobId}/progress") + @Produces(MediaType.APPLICATION_JSON) + public Response getProgress(@PathParam("jobId") String jobId) { + try { + final JobController jobController = getResourceManager().readController(jobId); + + ProgressRetriever.Progress progress = new ProgressRetriever(jobController.getJob(), getSharedObjectsFactory()). + getProgress(); + + return Response.ok(progress).build(); + } catch (WebApplicationException ex) { + throw ex; + } catch (ItemNotFound itemNotFound) { + throw new NotFoundFormattedException(itemNotFound.getMessage(), itemNotFound); + } catch (Exception ex) { + throw new ServiceFormattedException(ex.getMessage(), ex); + } + } + + /** * Delete single item */ @DELETE http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleController.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleController.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleController.java index 34fc2d9..8156c29 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleController.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleController.java @@ -22,6 +22,7 @@ package org.apache.ambari.view.hive.resources.jobs; import org.apache.ambari.view.hive.client.Cursor; import org.apache.ambari.view.hive.client.HiveClientException; import org.apache.ambari.view.hive.client.IConnectionFactory; +import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; import org.apache.ambari.view.hive.resources.jobs.viewJobs.Job; import org.apache.ambari.view.hive.utils.HiveClientFormattedException; import org.apache.hive.service.cli.thrift.TGetOperationStatusResp; @@ -32,23 +33,21 @@ import org.slf4j.LoggerFactory; public class OperationHandleController { private final static Logger LOG = LoggerFactory.getLogger(OperationHandleController.class); + private final IConnectionFactory connectionsFabric; - private IConnectionFactory connectionsFabric; - private TOperationHandle operationHandle; - private IOperationHandleResourceManager operationHandlesStorage; + private final TOperationHandle operationHandle; + private final StoredOperationHandle storedOperationHandle; + private final IOperationHandleResourceManager operationHandlesStorage; - public OperationHandleController(IConnectionFactory connectionsFabric, TOperationHandle storedOperationHandle, IOperationHandleResourceManager operationHandlesStorage) { + public OperationHandleController(IConnectionFactory connectionsFabric, StoredOperationHandle storedOperationHandle, IOperationHandleResourceManager operationHandlesStorage) { this.connectionsFabric = connectionsFabric; - this.operationHandle = storedOperationHandle; + this.storedOperationHandle = storedOperationHandle; + this.operationHandle = storedOperationHandle.toTOperationHandle(); this.operationHandlesStorage = operationHandlesStorage; } - public TOperationHandle getStoredOperationHandle() { - return operationHandle; - } - - public void setStoredOperationHandle(TOperationHandle storedOperationHandle) { - this.operationHandle = storedOperationHandle; + public StoredOperationHandle getStoredOperationHandle() { + return storedOperationHandle; } public OperationStatus getOperationStatus() throws NoOperationStatusSetException, HiveClientException { @@ -107,7 +106,15 @@ public class OperationHandleController { } public String getLogs() { - return connectionsFabric.getHiveConnection().getLogs(operationHandle); + String logs; + try { + logs = connectionsFabric.getHiveConnection().getLogs(operationHandle); + } catch (HiveClientFormattedException ex) { + logs = ""; + LOG.info(String.format("Logs are not available yet for job #%s [%s]\n%s", + storedOperationHandle.getJobId(), storedOperationHandle.getGuid(), ex.toString())); + } + return logs; } public Cursor getResults() { http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleControllerFactory.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleControllerFactory.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleControllerFactory.java index 0310855..4297078 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleControllerFactory.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleControllerFactory.java @@ -32,12 +32,12 @@ public class OperationHandleControllerFactory { operationHandlesStorage = new OperationHandleResourceManager(connectionsFabric); } - public OperationHandleController createControllerForHandle(TOperationHandle storedOperationHandle) { + public OperationHandleController createControllerForHandle(StoredOperationHandle storedOperationHandle) { return new OperationHandleController(connectionsFabric, storedOperationHandle, operationHandlesStorage); } public OperationHandleController getHandleForJob(Job job) throws ItemNotFound { - TOperationHandle handle = operationHandlesStorage.getHandleForJob(job); + StoredOperationHandle handle = operationHandlesStorage.getHandleForJob(job); return createControllerForHandle(handle); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleResourceManager.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleResourceManager.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleResourceManager.java index 9e49dd1..f0eecea 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleResourceManager.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/OperationHandleResourceManager.java @@ -55,6 +55,38 @@ public class OperationHandleResourceManager extends SharedCRUDResourceManager<St } @Override + public StoredOperationHandle getHandleForJob(Job job) throws ItemNotFound { + List<StoredOperationHandle> jobRelatedHandles = readJobRelatedHandles(job); + if (jobRelatedHandles.size() == 0) + throw new ItemNotFound(); + return jobRelatedHandles.get(0); + } + + @Override + public List<Job> getHandleRelatedJobs(final StoredOperationHandle operationHandle) { + return storageFactory.getStorage().loadAll(Job.class, new FilteringStrategy() { + @Override + public boolean isConform(Indexed item) { + Job job = (Job) item; + return (job.getId() != null && job.getId().equals(operationHandle.getJobId())); + } + + @Override + public String whereStatement() { + return "id = '" + operationHandle.getJobId() + "'"; + } + }); + } + + @Override + public Job getJobByHandle(StoredOperationHandle handle) throws ItemNotFound { + List<Job> handleRelatedJobs = getHandleRelatedJobs(handle); + if (handleRelatedJobs.size() == 0) + throw new ItemNotFound(); + return handleRelatedJobs.get(0); + } + + @Override public void putHandleForJob(TOperationHandle h, Job job) { StoredOperationHandle handle = StoredOperationHandle.buildFromTOperationHandle(h); handle.setJobId(job.getId()); @@ -77,12 +109,4 @@ public class OperationHandleResourceManager extends SharedCRUDResourceManager<St List<StoredOperationHandle> jobRelatedHandles = readJobRelatedHandles(job); return jobRelatedHandles.size() > 0; } - - @Override - public TOperationHandle getHandleForJob(Job job) throws ItemNotFound { - List<StoredOperationHandle> jobRelatedHandles = readJobRelatedHandles(job); - if (jobRelatedHandles.size() == 0) - throw new ItemNotFound(); - return jobRelatedHandles.get(0).toTOperationHandle(); - } } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ProgressRetriever.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ProgressRetriever.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ProgressRetriever.java new file mode 100644 index 0000000..6be8147 --- /dev/null +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/ProgressRetriever.java @@ -0,0 +1,67 @@ +/** + * 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.jobs; + +import org.apache.ambari.view.hive.resources.jobs.atsJobs.TezVertexId; +import org.apache.ambari.view.hive.resources.jobs.rm.RMParser; +import org.apache.ambari.view.hive.resources.jobs.viewJobs.Job; +import org.apache.ambari.view.hive.utils.ServiceFormattedException; +import org.apache.ambari.view.hive.utils.SharedObjectsFactory; + +import java.util.List; +import java.util.Map; + +public class ProgressRetriever { + private final Progress progress; + private final Job job; + private final SharedObjectsFactory sharedObjects; + + public ProgressRetriever(Job job, SharedObjectsFactory sharedObjects) { + this.job = job; + this.sharedObjects = sharedObjects; + + this.progress = new Progress(); + } + + public Progress getProgress() { + jobCheck(); + + progress.dagProgress = sharedObjects.getRMParser().getDAGProgress( + job.getApplicationId(), job.getDagId()); + + List<TezVertexId> vertices = sharedObjects.getATSParser().getVerticesForDAGId(job.getDagId()); + progress.vertexProgresses = sharedObjects.getRMParser().getDAGVerticesProgress(job.getApplicationId(), job.getDagId(), vertices); + + return progress; + } + + public void jobCheck() { + if (job.getApplicationId() == null || job.getApplicationId().isEmpty()) { + throw new ServiceFormattedException("E070 ApplicationId is not defined yet"); + } + if (job.getDagId() == null || job.getDagId().isEmpty()) { + throw new ServiceFormattedException("E080 DagID is not defined yet"); + } + } + + public static class Progress { + public Double dagProgress; + public List<RMParser.VertexProgress> vertexProgresses; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSParser.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSParser.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSParser.java index a6446ff..6e46fee 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSParser.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSParser.java @@ -58,6 +58,24 @@ public class ATSParser implements IATSParser { } @Override + public List<TezVertexId> getVerticesForDAGId(String dagId) { + JSONObject entities = delegate.tezVerticesListForDAG(dagId); + JSONArray vertices = (JSONArray) entities.get("entities"); + + List<TezVertexId> parsedVertices = new LinkedList<TezVertexId>(); + for(Object vertex : vertices) { + try { + TezVertexId parsedVertex = parseVertex((JSONObject) vertex); + parsedVertices.add(parsedVertex); + } catch (Exception ex) { + LOG.error("Error while parsing the vertex", ex); + } + } + + return parsedVertices; + } + + @Override public HiveQueryId getHiveQueryIdByOperationId(String guidString) { JSONObject entities = delegate.hiveQueryIdByOperationId(guidString); JSONArray jobs = (JSONArray) entities.get("entities"); @@ -131,6 +149,15 @@ public class ATSParser implements IATSParser { return parsedJob; } + private TezVertexId parseVertex(JSONObject vertex) { + TezVertexId tezVertexId = new TezVertexId(); + tezVertexId.entity = (String)vertex.get("entity"); + JSONObject otherinfo = (JSONObject)vertex.get("otherinfo"); + if (otherinfo != null) + tezVertexId.vertexName = (String)otherinfo.get("vertexName"); + return tezVertexId; + } + private JSONObject getLastEvent(JSONObject atsEntity) { JSONArray events = (JSONArray) atsEntity.get("events"); return (JSONObject) events.get(0); http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegate.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegate.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegate.java index f9b19bf..2e59ea0 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegate.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegate.java @@ -29,9 +29,13 @@ public interface ATSRequestsDelegate { String tezDagNameUrl(String name); + String tezVerticesListForDAGUrl(String dagId); + JSONObject hiveQueryIdList(String username); JSONObject hiveQueryIdByOperationId(String operationId); JSONObject tezDagByName(String name); + + JSONObject tezVerticesListForDAG(String dagId); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegateImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegateImpl.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegateImpl.java index 6ac5ef8..1876b2a 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegateImpl.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/ATSRequestsDelegateImpl.java @@ -63,6 +63,11 @@ public class ATSRequestsDelegateImpl implements ATSRequestsDelegate { } @Override + public String tezVerticesListForDAGUrl(String dagId) { + return atsUrl + "/ws/v1/timeline/TEZ_VERTEX_ID?primaryFilter=TEZ_DAG_ID:" + dagId; + } + + @Override public JSONObject hiveQueryIdList(String username) { String hiveQueriesListUrl = atsUrl + "/ws/v1/timeline/HIVE_QUERY_ID?primaryFilter=requestuser:" + username; String response = readFromWithDefault(hiveQueriesListUrl, "{ \"entities\" : [ ] }"); @@ -83,10 +88,16 @@ public class ATSRequestsDelegateImpl implements ATSRequestsDelegate { return (JSONObject) JSONValue.parse(response); } - protected String readFromWithDefault(String hiveQueriesListUrl, String defaultResponse) { + @Override + public JSONObject tezVerticesListForDAG(String dagId) { + String response = readFromWithDefault(tezVerticesListForDAGUrl(dagId), "{ \"entities\" : [ ] }"); + return (JSONObject) JSONValue.parse(response); + } + + protected String readFromWithDefault(String atsUrl, String defaultResponse) { String response; try { - InputStream responseInputStream = context.getURLStreamProvider().readFrom(hiveQueriesListUrl, "GET", + InputStream responseInputStream = context.getURLStreamProvider().readFrom(atsUrl, "GET", null, new HashMap<String, String>()); response = IOUtils.toString(responseInputStream); } catch (IOException e) { http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/IATSParser.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/IATSParser.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/IATSParser.java index 6109001..292ead8 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/IATSParser.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/IATSParser.java @@ -23,6 +23,8 @@ import java.util.List; public interface IATSParser { List<HiveQueryId> getHiveQueryIdsList(String username); + List<TezVertexId> getVerticesForDAGId(String dagId); + HiveQueryId getHiveQueryIdByOperationId(String guidString); TezDagId getTezDAGByName(String name); http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/TezVertexId.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/TezVertexId.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/TezVertexId.java new file mode 100644 index 0000000..34dd996 --- /dev/null +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/atsJobs/TezVertexId.java @@ -0,0 +1,24 @@ +/** + * 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.jobs.atsJobs; + +public class TezVertexId { + public String entity; + public String vertexName; +} http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParser.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParser.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParser.java new file mode 100644 index 0000000..e1d4c73 --- /dev/null +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParser.java @@ -0,0 +1,88 @@ +/** + * 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.jobs.rm; + +import org.apache.ambari.view.hive.resources.jobs.atsJobs.TezVertexId; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class RMParser { + private RMRequestsDelegate delegate; + + public RMParser(RMRequestsDelegate delegate) { + this.delegate = delegate; + } + + public Double getDAGProgress(String appId, String dagId) { + String dagIdx = parseDagIdIndex(dagId); + JSONObject dagProgress = (JSONObject) delegate.dagProgress(appId, dagIdx).get("dagProgress"); + return (Double) (dagProgress.get("progress")); + } + + public List<VertexProgress> getDAGVerticesProgress(String appId, String dagId, List<TezVertexId> vertices) { + String dagIdx = parseDagIdIndex(dagId); + + Map<String, String> vertexIdToEntityMapping = new HashMap<String, String>(); + StringBuilder builder = new StringBuilder(); + if (vertices.size() > 0) { + for (TezVertexId vertexId : vertices) { + String[] parts = vertexId.entity.split("_"); + String vertexIdx = parts[parts.length - 1]; + builder.append(vertexIdx).append(","); + + vertexIdToEntityMapping.put(vertexId.entity, vertexId.vertexName); + } + builder.setLength(builder.length() - 1); // remove last comma + } + + String commaSeparatedVertices = builder.toString(); + + JSONArray vertexProgresses = (JSONArray) delegate.verticesProgress( + appId, dagIdx, commaSeparatedVertices).get("vertexProgresses"); + + List<VertexProgress> parsedVertexProgresses = new LinkedList<VertexProgress>(); + for (Object vertex : vertexProgresses) { + JSONObject jsonObject = (JSONObject) vertex; + + VertexProgress vertexProgressInfo = new VertexProgress(); + vertexProgressInfo.id = (String) jsonObject.get("id"); + vertexProgressInfo.name = vertexIdToEntityMapping.get(vertexProgressInfo.id); + vertexProgressInfo.progress = (Double) jsonObject.get("progress"); + + parsedVertexProgresses.add(vertexProgressInfo); + } + return parsedVertexProgresses; + } + + public String parseDagIdIndex(String dagId) { + String[] dagIdParts = dagId.split("_"); + return dagIdParts[dagIdParts.length - 1]; + } + + public static class VertexProgress { + public String id; + public String name; + public Double progress; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParserFactory.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParserFactory.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParserFactory.java new file mode 100644 index 0000000..9733147 --- /dev/null +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMParserFactory.java @@ -0,0 +1,39 @@ +/** + * 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.jobs.rm; + +import org.apache.ambari.view.ViewContext; + +public class RMParserFactory { + + private ViewContext context; + + public RMParserFactory(ViewContext context) { + this.context = context; + } + + public RMParser getRMParser() { + RMRequestsDelegate delegate = new RMRequestsDelegateImpl(context, getRMUrl(context)); + return new RMParser(delegate); + } + + public static String getRMUrl(ViewContext context) { + return context.getProperties().get("yarn.resourcemanager.url"); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegate.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegate.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegate.java new file mode 100644 index 0000000..6114b34 --- /dev/null +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegate.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.hive.resources.jobs.rm; + +import org.json.simple.JSONObject; + +public interface RMRequestsDelegate { + String dagProgressUrl(String appId, String dagIdx); + + String verticesProgressUrl(String appId, String dagIdx, String vertices); + + JSONObject dagProgress(String appId, String dagIdx); + + JSONObject verticesProgress(String appId, String dagIdx, String commaSeparatedVertices); +} http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegateImpl.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegateImpl.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegateImpl.java new file mode 100644 index 0000000..a1987cd --- /dev/null +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/jobs/rm/RMRequestsDelegateImpl.java @@ -0,0 +1,99 @@ +/** + * 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.jobs.rm; + +import org.apache.ambari.view.ViewContext; +import org.apache.ambari.view.hive.utils.ServiceFormattedException; +import org.apache.commons.io.IOUtils; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; + +public class RMRequestsDelegateImpl implements RMRequestsDelegate { + protected final static Logger LOG = + LoggerFactory.getLogger(RMRequestsDelegateImpl.class); + public static final String EMPTY_ENTITIES_JSON = "{ \"entities\" : [ ] }"; + + private ViewContext context; + private String rmUrl; + + public RMRequestsDelegateImpl(ViewContext context, String rmUrl) { + this.context = context; + this.rmUrl = rmUrl; + } + + @Override + public String dagProgressUrl(String appId, String dagIdx) { + return rmUrl + String.format("/proxy/%s/ws/v1/tez/dagProgress?dagID=%s", appId, dagIdx); + } + + @Override + public String verticesProgressUrl(String appId, String dagIdx, String vertices) { + return rmUrl + String.format("/proxy/%s/ws/v1/tez/vertexProgresses?dagID=%s&vertexID=%s", appId, dagIdx, vertices); + } + + @Override + public JSONObject dagProgress(String appId, String dagIdx) { + String url = dagProgressUrl(appId, dagIdx); + String response; + try { + InputStream responseInputStream = context.getURLStreamProvider().readFrom(url, "GET", + null, new HashMap<String, String>()); + response = IOUtils.toString(responseInputStream); + } catch (IOException e) { + throw new ServiceFormattedException( + String.format("R010 DAG %s in app %s not found or ResourceManager is unreachable", dagIdx, appId)); + } + return (JSONObject) JSONValue.parse(response); + } + + @Override + public JSONObject verticesProgress(String appId, String dagIdx, String commaSeparatedVertices) { + String url = verticesProgressUrl(appId, dagIdx, commaSeparatedVertices); + String response; + try { + InputStream responseInputStream = context.getURLStreamProvider().readFrom(url, "GET", + null, new HashMap<String, String>()); + response = IOUtils.toString(responseInputStream); + } catch (IOException e) { + throw new ServiceFormattedException( + String.format("R020 DAG %s in app %s not found or ResourceManager is unreachable", dagIdx, appId)); + } + return (JSONObject) JSONValue.parse(response); + } + + protected String readFromWithDefault(String url, String defaultResponse) { + String response; + try { + InputStream responseInputStream = context.getURLStreamProvider().readFrom(url, "GET", + null, new HashMap<String, String>()); + response = IOUtils.toString(responseInputStream); + } catch (IOException e) { + LOG.error("Error while reading from RM", e); + response = defaultResponse; + } + return response; + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java index 76b77dd..f497f76 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceResourceProvider.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.resources; -import com.google.inject.Inject; import org.apache.ambari.view.*; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; @@ -26,6 +25,7 @@ import org.apache.ambari.view.hive.utils.SharedObjectsFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.Map; @@ -60,6 +60,8 @@ public class FileResourceResourceProvider implements ResourceProvider<FileResour @Override public Set<FileResourceItem> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { + if (context == null) + return new HashSet(); return new HashSet<FileResourceItem>(getResourceManager().readAll( new OnlyOwnersFilteringStrategy(this.context.getUsername()))); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java index 222cf03..412b026 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/resources/FileResourceService.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.resources; -import com.google.inject.Inject; import org.apache.ambari.view.ViewResourceHandler; import org.apache.ambari.view.hive.BaseService; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; @@ -29,6 +28,7 @@ import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.Context; http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java index a5561aa..ac4f798 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryResourceProvider.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.savedQueries; -import com.google.inject.Inject; import org.apache.ambari.view.*; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; @@ -26,6 +25,7 @@ import org.apache.ambari.view.hive.utils.SharedObjectsFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.Map; @@ -63,6 +63,8 @@ public class SavedQueryResourceProvider implements ResourceProvider<SavedQuery> @Override public Set<SavedQuery> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { + if (context == null) + return new HashSet(); return new HashSet<SavedQuery>(getResourceManager().readAll( new OnlyOwnersFilteringStrategy(this.context.getUsername()))); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java index 338457a..82e0896 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/savedQueries/SavedQueryService.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.savedQueries; -import com.google.inject.Inject; import org.apache.ambari.view.ViewResourceHandler; import org.apache.ambari.view.hive.BaseService; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; @@ -29,6 +28,7 @@ import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.Context; http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java index 4117678..3670ca1 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFResourceProvider.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.udfs; -import com.google.inject.Inject; import org.apache.ambari.view.*; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; import org.apache.ambari.view.hive.persistence.utils.OnlyOwnersFilteringStrategy; @@ -26,6 +25,7 @@ import org.apache.ambari.view.hive.utils.SharedObjectsFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.Map; @@ -61,6 +61,8 @@ public class UDFResourceProvider implements ResourceProvider<UDF> { @Override public Set<UDF> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException { + if (context == null) + return new HashSet(); return new HashSet<UDF>(getResourceManager().readAll( new OnlyOwnersFilteringStrategy(this.context.getUsername()))); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java index aa170c9..8082e00 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/resources/udfs/UDFService.java @@ -18,7 +18,6 @@ package org.apache.ambari.view.hive.resources.udfs; -import com.google.inject.Inject; import org.apache.ambari.view.ViewResourceHandler; import org.apache.ambari.view.hive.BaseService; import org.apache.ambari.view.hive.persistence.utils.ItemNotFound; @@ -30,6 +29,7 @@ import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.Context; http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java index 19b324c..e9698c3 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/ServiceFormattedException.java @@ -26,6 +26,8 @@ import org.slf4j.LoggerFactory; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.io.PrintWriter; +import java.io.StringWriter; import java.security.AccessControlException; import java.util.HashMap; @@ -60,15 +62,25 @@ public class ServiceFormattedException extends WebApplicationException { protected static Response errorEntity(String message, Throwable e, int status, String header) { HashMap<String, Object> response = new HashMap<String, Object>(); - response.put("message", message); + String trace = null; - if (e != null) - trace = ExceptionUtils.getStackTrace(e); + + response.put("message", message); + if (e != null) { + trace = e.toString() + "\n\n"; + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + trace += sw.toString(); + + if (message == null) { + response.put("message", "E090 " + e.getClass().getSimpleName()); + } + } response.put("trace", trace); response.put("status", status); if(message != null) LOG.error(message); - if(trace != null) LOG.debug(trace); + if(trace != null) LOG.error(trace); Response.ResponseBuilder responseBuilder = Response.status(status).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON); if (header != null) http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java index 2c7e242..05ff7b6 100644 --- a/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java +++ b/contrib/views/hive/src/main/java/org/apache/ambari/view/hive/utils/SharedObjectsFactory.java @@ -29,6 +29,8 @@ import org.apache.ambari.view.hive.resources.jobs.ConnectionController; import org.apache.ambari.view.hive.resources.jobs.OperationHandleControllerFactory; import org.apache.ambari.view.hive.resources.jobs.atsJobs.ATSParser; import org.apache.ambari.view.hive.resources.jobs.atsJobs.ATSParserFactory; +import org.apache.ambari.view.hive.resources.jobs.rm.RMParser; +import org.apache.ambari.view.hive.resources.jobs.rm.RMParserFactory; import org.apache.ambari.view.hive.resources.jobs.viewJobs.IJobControllerFactory; import org.apache.ambari.view.hive.resources.jobs.viewJobs.JobControllerFactory; import org.apache.ambari.view.hive.resources.savedQueries.SavedQueryResourceManager; @@ -43,9 +45,10 @@ import java.util.Map; */ public class SharedObjectsFactory implements IStorageFactory, IConnectionFactory { private ViewContext context; - private IConnectionFactory hiveConnectionFactory; - private IStorageFactory storageFactory; - private ATSParserFactory atsParserFactory; + private final IConnectionFactory hiveConnectionFactory; + private final IStorageFactory storageFactory; + private final ATSParserFactory atsParserFactory; + private final RMParserFactory rmParserFactory; private static final Map<Class, Map<String, Object>> localObjects = new HashMap<Class, Map<String, Object>>(); @@ -54,6 +57,7 @@ public class SharedObjectsFactory implements IStorageFactory, IConnectionFactory this.hiveConnectionFactory = new ConnectionFactory(context); this.storageFactory = new StorageFactory(context); this.atsParserFactory = new ATSParserFactory(context); + this.rmParserFactory = new RMParserFactory(context); synchronized (localObjects) { if (localObjects.size() == 0) { @@ -64,6 +68,7 @@ public class SharedObjectsFactory implements IStorageFactory, IConnectionFactory localObjects.put(ATSParser.class, new HashMap<String, Object>()); localObjects.put(SavedQueryResourceManager.class, new HashMap<String, Object>()); localObjects.put(HdfsApi.class, new HashMap<String, Object>()); + localObjects.put(RMParser.class, new HashMap<String, Object>()); } } } @@ -124,6 +129,13 @@ public class SharedObjectsFactory implements IStorageFactory, IConnectionFactory } // ============================= + public RMParser getRMParser() { + if (!localObjects.get(RMParser.class).containsKey(getTagName())) + localObjects.get(RMParser.class).put(getTagName(), rmParserFactory.getRMParser()); + return (RMParser) localObjects.get(RMParser.class).get(getTagName()); + } + + // ============================= public HdfsApi getHdfsApi() { if (!localObjects.get(HdfsApi.class).containsKey(getTagName())) localObjects.get(HdfsApi.class).put(getTagName(), HdfsApi.connectToHDFSApi(context)); @@ -135,6 +147,8 @@ public class SharedObjectsFactory implements IStorageFactory, IConnectionFactory * @return tag name */ public String getTagName() { + if (context == null) + return "<null>"; return String.format("%s:%s", context.getInstanceName(), context.getUsername()); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/.gitignore ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/.gitignore b/contrib/views/hive/src/main/resources/ui/hive-web/.gitignore index 043148a..e1b6b28 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/.gitignore +++ b/contrib/views/hive/src/main/resources/ui/hive-web/.gitignore @@ -32,4 +32,6 @@ tmp/ public/ -_generators/ \ No newline at end of file +_generators/ + +coverage.json http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/adapters/application.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/adapters/application.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/adapters/application.js index e838a3d..cf2511d 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/adapters/application.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/adapters/application.js @@ -21,7 +21,7 @@ import constants from 'hive/utils/constants'; export default DS.RESTAdapter.extend({ headers: { - "X-Requested-By": "ambari" + 'X-Requested-By': 'ambari' }, buildURL: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/alert-message-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/alert-message-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/alert-message-widget.js index df44c37..565d93d 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/alert-message-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/alert-message-widget.js @@ -24,7 +24,7 @@ export default Ember.Component.extend({ this.sendAction('removeMessage', this.get('message')); }, - toggleMessage: function() { + toggleMessage: function () { this.toggleProperty('message.isExpanded'); if (!this.get('message.isExpanded')) { http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/collapsible-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/collapsible-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/collapsible-widget.js index f2081f2..eb174ab 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/collapsible-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/collapsible-widget.js @@ -30,7 +30,7 @@ export default Ember.Component.extend({ } }, - sendControlAction: function(action) { + sendControlAction: function (action) { this.set('controlAction', action); this.sendAction('controlAction', this.get('heading'), this.get('toggledParam')); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/column-filter-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/column-filter-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/column-filter-widget.js index 2622d4b..cbf0ddd 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/column-filter-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/column-filter-widget.js @@ -27,7 +27,7 @@ export default Ember.Component.extend({ } }, - isSorted: (function() { + isSorted: (function () { var sortProperties = this.get('sortProperties'); if (sortProperties) { http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/date-range-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/date-range-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/date-range-widget.js index 790cb35..9e38786 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/date-range-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/date-range-widget.js @@ -29,34 +29,57 @@ export default Ember.Component.extend({ return moment(this.get('dateRange.to')).format('MM/DD/YYYY'); }.property('dateRange.to'), + updateMinDate: function () { + if (this.get('rendered')) { + this.$('.toDate').datepicker("option", "minDate", new Date(this.get('dateRange.from'))); + } + }.observes('dateRange.from'), + + updateMaxDate: function () { + if (this.get('rendered')) { + this.$('.fromDate').datepicker("option", "maxDate", new Date(this.get('dateRange.to'))); + } + }.observes('dateRange.to'), + didInsertElement: function () { var self = this; + var dateRange = this.get('dateRange'); - if (!this.get('dateRange.min') && !this.get('dateRange.max')) { - this.set('dateRange.max', new Date()); + if (!dateRange.get('min') && !dateRange.get('max')) { + dateRange.set('max', new Date()); } - if (!this.get('dateRange.from') && !this.get('dateRange.to')) { - this.set('dateRange.from', this.get('dateRange.min')); - this.set('dateRange.to', this.get('dateRange.max')); + if (!dateRange.get('from') && !dateRange.get('to')) { + dateRange.set('from', dateRange.get('min')); + dateRange.set('to', dateRange.get('max')); } this.$(".fromDate").datepicker({ - defaultDate: this.get("dateRange.from"), + defaultDate: new Date(dateRange.get("from")), + maxDate: new Date(dateRange.get('to')), + onSelect: function (selectedDate) { self.$(".toDate").datepicker("option", "minDate", selectedDate); - self.set('dateRange.from', new Date(selectedDate)); - self.sendAction('rangeChanged', self.get('dateRange')); + + dateRange.set('from', new Date(selectedDate).getTime()); + self.sendAction('rangeChanged', dateRange); } }); this.$(".toDate").datepicker({ - defaultDate: this.get('dateRange.to'), + defaultDate: new Date(dateRange.get('to')), + minDate: new Date(dateRange.get('from')), + onSelect: function (selectedDate) { + selectedDate += ' 23:59'; + self.$(".fromDate").datepicker("option", "maxDate", selectedDate); - self.set('dateRange.to', new Date(selectedDate + " 23:59")); - self.sendAction('rangeChanged', self.get('dateRange')); + + dateRange.set('to', new Date(selectedDate).getTime()); + self.sendAction('rangeChanged', dateRange); } }); + + this.set('rendered', true); } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/expander-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/expander-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/expander-widget.js index d46a490..12da9ea 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/expander-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/expander-widget.js @@ -21,6 +21,12 @@ import Ember from 'ember'; export default Ember.Component.extend({ tagName: 'expander', + didInsertElement: function () { + if (this.get('isExpanded')) { + this.$('.accordion-body').toggle(); + } + }, + actions: { toggle: function () { this.toggleProperty('isExpanded'); http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/modal-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/modal-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/modal-widget.js index 790e84b..5172664 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/modal-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/modal-widget.js @@ -19,27 +19,27 @@ import Ember from 'ember'; export default Ember.Component.extend(Ember.I18n.TranslateableProperties, { - show: function() { + show: function () { this.$('.modal').modal().on('hidden.bs.modal', function () { this.sendAction('close'); }.bind(this)); }.on('didInsertElement'), - keyPress: function(e) { - Ember.run.debounce(this, function() { + keyPress: function (e) { + Ember.run.debounce(this, function () { if (e.which === 13) { this.send('ok'); } else if (e.which === 27) { this.send('close'); } - }, 200) + }, 200); }, - setupEvents: function() { + setupEvents: function () { this.$(document).on('keyup', Ember.$.proxy(this.keyPress, this)); }.on('didInsertElement'), - destroyEvents: function() { + destroyEvents: function () { this.$(document).off('keyup', Ember.$.proxy(this.keyPress, this)); }.on('willDestroyElement'), http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/notify-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/notify-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/notify-widget.js index 5a37f13..25ae1b3 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/notify-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/notify-widget.js @@ -21,12 +21,12 @@ import Ember from 'ember'; export default Ember.Component.extend({ tagName: 'notifications', - classNames: ['notifications-container'], - notifications : Ember.computed.alias('notify.notifications'), + classNames: [ 'notifications-container' ], + removeNotificationAction: 'removeNotification', actions: { - removeNotification: function(notification) { - this.notify.removeNotification(notification); + removeNotification: function (notification) { + this.sendAction('removeNotificationAction', notification); } } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/number-range-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/number-range-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/number-range-widget.js index 4ab1dba..80489dc 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/number-range-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/number-range-widget.js @@ -21,30 +21,42 @@ import Ember from 'ember'; export default Ember.Component.extend({ didInsertElement: function () { var self = this; + var numberRange = this.get('numberRange'); - var slider; - - if (!self.get('numberRange.from') && !self.get('numberRange.to')) { - self.get('numberRange').set('from', self.get('numberRange.min')); - self.get('numberRange').set('to', self.get('numberRange.max')); + if (!numberRange.get('from') && !numberRange.get('to')) { + numberRange.set('from', numberRange.get('min')); + numberRange.set('to', numberRange.get('max')); } - slider = self.$( ".slider" ).slider({ + this.$('.slider').slider({ range: true, - min: self.get('numberRange.min'), - max: self.get('numberRange.max'), - units: self.get('numberRange.units'), - values: [ self.get('numberRange.from'), self.get('numberRange.to') ], + min: numberRange.get('min'), + max: numberRange.get('max'), + units: numberRange.get('units'), + values: [numberRange.get('from'), numberRange.get('to')], + slide: function (event, ui) { - self.set('numberRange.from', ui.values[0]); - self.set('numberRange.to', ui.values[1]); + numberRange.set('from', ui.values[0]); + numberRange.set('to', ui.values[1]); }, change: function () { - self.sendAction('rangeChanged', self.get('numberRange')); + self.sendAction('rangeChanged', numberRange); } }); - this.set('slider', slider); - } + this.set('rendered', true); + }, + + updateMin: function () { + if (this.get('rendered')) { + this.$('.slider').slider('values', 0, this.get('numberRange.from')); + } + }.observes('numberRange.from'), + + updateMax: function () { + if (this.get('rendered')) { + this.$('.slider').slider('values', 1, this.get('numberRange.to')); + } + }.observes('numberRange.to') }); http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/panel-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/panel-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/panel-widget.js index 1f41a43..e2b4ae8 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/panel-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/panel-widget.js @@ -22,7 +22,7 @@ export default Ember.Component.extend(Ember.I18n.TranslateableProperties, { tagName: 'panel', actions: { - sendMenuItemAction: function(action) { + sendMenuItemAction: function (action) { this.set('menuItemAction', action); this.sendAction('menuItemAction'); } http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/popover-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/popover-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/popover-widget.js index e1bd4c5..cfb0c31 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/popover-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/popover-widget.js @@ -20,8 +20,9 @@ import Ember from 'ember'; export default Ember.Component.extend(Ember.I18n.TranslateableProperties, { tagName: 'popover', - attributeBindings: ['title', 'content:data-content'], - didInsertElement: function() { + attributeBindings: [ 'title', 'content:data-content' ], + + didInsertElement: function () { this.$().popover({ html: true, placement: 'left', http://git-wip-us.apache.org/repos/asf/ambari/blob/642fd46c/contrib/views/hive/src/main/resources/ui/hive-web/app/components/progress-widget.js ---------------------------------------------------------------------- diff --git a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/progress-widget.js b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/progress-widget.js index 2a86ee7..d7c3fda 100644 --- a/contrib/views/hive/src/main/resources/ui/hive-web/app/components/progress-widget.js +++ b/contrib/views/hive/src/main/resources/ui/hive-web/app/components/progress-widget.js @@ -12,34 +12,19 @@ * 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 + * See the License for the specific `language governing permissions and * limitations under the License. */ -// this component is a work in progress - import Ember from 'ember'; export default Ember.Component.extend({ - formattedStages: Ember.ArrayProxy.create({ content: [] }), - - formatStages: function() { - var formattedStages = this.get('formattedStages'); - var stages = this.get('stages'); - var currentStage; + tagName: 'progress-bar', - stages.forEach(function(stage) { - currentStage = formattedStages.findBy('name', stage.get('name')); + updateValue: function () { + var progress = this.get('value') || 0; - if(currentStage) { - currentStage.set('progress', 'width: %@%'.fmt(stage.get('value'))) - } else { - formattedStages.pushObject(Ember.Object.create({ - name: stage.get('name'), - className: stage.get('className'), - progress: 'width: %@%'.fmt(stage.get('value')) - })); - } - }); - }.observes('stages.@each.value').on('init') + this.set('style', 'width: %@%'.fmt(progress)); + this.set('percentage', '%@%'.fmt(progress)); + }.observes('value').on('didInsertElement') });