Skip to content

Commit

Permalink
Changes for SNAP-2603: Display list of Global Temporary Views/Tables …
Browse files Browse the repository at this point in the history
…with relevant details on Snappy UI.

 - Adding resource named AllGlobalTemporaryViewsResource.scala for getting global temporary details.
 - Adding resource path "allglobaltempviews"
 - Updating Snappy Dashboard HTML page for displaying list of all global temporary views/tables.
 - Updated getStatsFromAllServers to fetch and return the global temporary views details.
 - Relevant code changes in TableStatsProviderService, SnappyTableStatsProviderService
   and SnappyThinConnectorTableStatsProvider.
  • Loading branch information
snappy-sachin committed Jan 18, 2019
1 parent 5d53b94 commit ff14fe9
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Changes for SnappyData data platform.
*
* Portions Copyright (c) 2018 SnappyData, Inc. All rights reserved.
*
* Licensed 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. See accompanying
* LICENSE file.
*/
package org.apache.spark.status.api.v1

import javax.ws.rs.{GET, Produces}
import javax.ws.rs.core.MediaType

@Produces(Array(MediaType.APPLICATION_JSON))
private[v1] class AllGlobalTemporaryViewsResource {
@GET
def viewsList(): Seq[GlobalTemporaryViewSummary] = {
// get all view stats details
TableDetails.getAllGlobalTempViewsInfo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ object ClusterDetails {
val membersInfo = MemberDetails.getAllMembersInfo
val tablesInfo = TableDetails.getAllTablesInfo
val extTablesInfo = TableDetails.getAllExternalTablesInfo
val gblTempViewsInfo = TableDetails.getAllGlobalTempViewsInfo

clusterBuff += new ClusterSummary(clusterInfo, membersInfo, tablesInfo, extTablesInfo)
clusterBuff += new ClusterSummary(clusterInfo, membersInfo, tablesInfo,
extTablesInfo, gblTempViewsInfo)
clusterBuff.toList
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ private[v1] class SnappyApiRootResource extends ApiRequestContext {
new AllExternalTablesResource
}

@Path("allglobaltempviews")
def getAllGlobalTempViews(): AllGlobalTemporaryViewsResource = {
new AllGlobalTemporaryViewsResource
}

}

private[spark] object SnappyApiRootResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package org.apache.spark.status.api.v1

import io.snappydata.SnappyTableStatsProviderService

import org.apache.spark.sql.types.StructType

object TableDetails {

def getAllTablesInfo: Seq[TableSummary] = {
Expand Down Expand Up @@ -60,4 +62,16 @@ object TableDetails {
table.getDataSourcePath)
}).values.toList
}

def getAllGlobalTempViewsInfo: Seq[GlobalTemporaryViewSummary] = {

val gblTempViewBuff =
SnappyTableStatsProviderService.getService.getAllGlobalTempViewStatsFromService

gblTempViewBuff.mapValues(view => {
val colCount = view.getSchema.asInstanceOf[StructType].size
new GlobalTemporaryViewSummary(view.getFullyQualifiedName, view.getTableName,
view.getTableType, colCount)
}).values.toList
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ClusterSummary private[spark](
val clusterInfo: mutable.HashMap[String, Any],
val membersInfo: Seq[MemberSummary],
val tablesInfo: Seq[TableSummary],
val externalTablesInfo: Seq[ExternalTableSummary]
val externalTablesInfo: Seq[ExternalTableSummary],
val globalTempViewsInfo: Seq[GlobalTemporaryViewSummary]
)

class MemberSummary private[spark](
Expand Down Expand Up @@ -98,3 +99,10 @@ class ExternalTableSummary private[spark](
val provider: String,
val source: String
)

class GlobalTemporaryViewSummary private[spark](
val tableFQName: String,
val tableName: String,
val tableType: String,
val numColumns: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,22 @@ private[ui] class SnappyDashboardPage (parent: SnappyDashboardTab)
extTablesStatsTitle ++ extTablesStatsTable
}

val gblTempViewsStatsDetails = {
val gblTempViewsStatsTitle = createTitleNode(SnappyDashboardPage.gblTempViewsStatsTitle,
SnappyDashboardPage.gblTempViewsStatsTitleTooltip,
"gblViewsStatsTitle",
false)
val gblTempViewsStatsTable = gblTempViewStats

gblTempViewsStatsTitle ++ gblTempViewsStatsTable
}

val jsScripts = <script src={
UIUtils.prependBaseUri("/static/snappydata/snappy-dashboard.js")
}></script>

val pageContent = jsScripts ++ pageTitleNode ++ clusterStatsDetails ++ membersStatsDetails ++
tablesStatsDetails ++ extTablesStatsDetails
tablesStatsDetails ++ extTablesStatsDetails ++ gblTempViewsStatsDetails

UIUtils.headerSparkPage(pageHeaderText, pageContent, parent, Some(500),
useDataTables = true, isSnappyPage = true)
Expand Down Expand Up @@ -339,6 +349,42 @@ private[ui] class SnappyDashboardPage (parent: SnappyDashboardTab)
</div>
}

private def gblTempViewStats(): Seq[Node] = {

<div class="container-fluid" id="gblTempViewStatsGridContainer" style="display: none;">
<table id="gblTempViewStatsGrid" class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th class="table-th-col-heading">
<span data-toggle="tooltip" title=""
data-original-title={
SnappyDashboardPage.gblTempViewStatsColumn("nameTooltip")
}>
{SnappyDashboardPage.gblTempViewStatsColumn("name")}
</span>
</th>
<th class="table-th-col-heading">
<span data-toggle="tooltip" title=""
data-original-title={
SnappyDashboardPage.gblTempViewStatsColumn("typeTooltip")
}>
{SnappyDashboardPage.gblTempViewStatsColumn("type")}
</span>
</th>
<th class="table-th-col-heading">
<span data-toggle="tooltip" title=""
data-original-title={
SnappyDashboardPage.gblTempViewStatsColumn("columnsCountTooltip")
}>
{SnappyDashboardPage.gblTempViewStatsColumn("columnsCount")}
</span>
</th>
</tr>
</thead>
</table>
</div>
}

}

object SnappyDashboardPage {
Expand Down Expand Up @@ -460,4 +506,14 @@ object SnappyDashboardPage {
extTableStatsColumn += ("externalSource" -> "Source")
extTableStatsColumn += ("externalSourceTooltip" -> "External Source of Tables ")

val gblTempViewsStatsTitle = "Global Temporary Views"
val gblTempViewsStatsTitleTooltip = "SnappyData Global Temporary Views Summary"
val gblTempViewStatsColumn = scala.collection.mutable.HashMap.empty[String, String]
gblTempViewStatsColumn += ("name" -> "Name")
gblTempViewStatsColumn += ("nameTooltip" -> "Global Temporary Views Name")
gblTempViewStatsColumn += ("type" -> "Type")
gblTempViewStatsColumn += ("typeTooltip" -> "Type")
gblTempViewStatsColumn += ("columnsCount" -> "Columns Count")
gblTempViewStatsColumn += ("columnsCountTooltip" -> "Number of Columns in View")

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ object SnappyEmbeddedTableStatsProviderService extends TableStatsProviderService
override def run2(): Unit = {
try {
if (doRun) {
aggregateStats()
aggregateStats(Some(sc))
}
} catch {
case _: CancelException => // ignore
Expand Down Expand Up @@ -182,7 +182,7 @@ object SnappyEmbeddedTableStatsProviderService extends TableStatsProviderService
}

override def getStatsFromAllServers(sc: Option[SparkContext] = None): (Seq[SnappyRegionStats],
Seq[SnappyIndexStats], Seq[SnappyExternalTableStats]) = {
Seq[SnappyIndexStats], Seq[SnappyExternalTableStats], Seq[SnappyGlobalTemporaryViewStats]) = {
var result = new java.util.ArrayList[SnappyRegionStatsCollectorResult]().asScala
val dataServers = GfxdMessage.getAllDataStores
var resultObtained: Boolean = false
Expand Down Expand Up @@ -221,6 +221,32 @@ object SnappyEmbeddedTableStatsProviderService extends TableStatsProviderService
}
}

val globalTempViews: mutable.Buffer[SnappyGlobalTemporaryViewStats] = {

val snc = SnappyContext.apply(this.sparkContext)
val snappySessionCatalog = snc.snappySession.sessionCatalog
val globalTempSchema: String = "global_temp"
val gblTempViewList = snappySessionCatalog.listTables(globalTempSchema)

if (gblTempViewList.isEmpty) {
mutable.Buffer.empty[SnappyGlobalTemporaryViewStats]
} else {
val gtv_buf = mutable.Buffer.empty[SnappyGlobalTemporaryViewStats]

gblTempViewList.foreach(tmpView => {
try {
val gt = snappySessionCatalog.getTempViewOrPermanentTableMetadata(tmpView)
gtv_buf += new SnappyGlobalTemporaryViewStats(tmpView.table, gt.qualifiedName,
gt.tableType.name, gt.comment.getOrElse(""), gt.schema, gt.properties.asJava)
} catch {
case e: Exception => log.debug("Exception while getting details of global " +
"temporary view [" + tmpView + "] : " + e.getMessage, e)
}
})
gtv_buf
}
}

if (resultObtained) {
// Return updated tableSizeInfo
// Map to hold hive table type against table names as keys
Expand All @@ -245,12 +271,14 @@ object SnappyEmbeddedTableStatsProviderService extends TableStatsProviderService
// Return updated details
(regionStats,
result.flatMap(_.getIndexStats.asScala),
externalTables)
externalTables,
globalTempViews)
} else {
// Return last successfully updated tableSizeInfo
(tableSizeInfo.values.toSeq,
result.flatMap(_.getIndexStats.asScala),
externalTables)
externalTables,
globalTempViews)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import scala.util.control.NonFatal

import com.gemstone.gemfire.CancelException
import com.pivotal.gemfirexd.Attribute
import com.pivotal.gemfirexd.internal.engine.ui.{SnappyExternalTableStats, SnappyIndexStats, SnappyRegionStats}
import com.pivotal.gemfirexd.internal.engine.ui.{SnappyExternalTableStats, SnappyGlobalTemporaryViewStats, SnappyIndexStats, SnappyRegionStats}
import io.snappydata.Constant._

import org.apache.spark.SparkContext
Expand Down Expand Up @@ -71,7 +71,7 @@ object SnappyThinConnectorTableStatsProvider extends TableStatsProviderService {
override def run(): Unit = {
try {
if (doRun) {
aggregateStats()
aggregateStats(Some(sc))
}
} catch {
case _: CancelException => // ignore
Expand Down Expand Up @@ -111,7 +111,8 @@ object SnappyThinConnectorTableStatsProvider extends TableStatsProviderService {
}

override def getStatsFromAllServers(sc: Option[SparkContext] = None): (Seq[SnappyRegionStats],
Seq[SnappyIndexStats], Seq[SnappyExternalTableStats]) = synchronized {
Seq[SnappyIndexStats], Seq[SnappyExternalTableStats],
Seq[SnappyGlobalTemporaryViewStats]) = synchronized {
try {
val resultSet = executeStatsStmt(sc)
val regionStats = new ArrayBuffer[SnappyRegionStats]
Expand All @@ -126,14 +127,14 @@ object SnappyThinConnectorTableStatsProvider extends TableStatsProviderService {
regionStats += new SnappyRegionStats(tableName, totalSize, sizeInMemory, rowCount,
isColumnTable, isReplicatedTable, bucketCount)
}
(regionStats, Nil, Nil)
(regionStats, Nil, Nil, Nil)
} catch {
case NonFatal(e) =>
logWarning("Warning: unable to retrieve table stats " +
"from SnappyData cluster due to " + e.toString)
logDebug("Exception stack trace: ", e)
closeConnection()
(Nil, Nil, Nil)
(Nil, Nil, Nil, Nil)
}
}

Expand Down
Loading

0 comments on commit ff14fe9

Please sign in to comment.