Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap 2603 : Display list of Global Temporary Views/Tables with relevant details on Snappy UI. #1246

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -18,8 +18,12 @@
*/
package org.apache.spark.status.api.v1

import scala.collection.mutable

import io.snappydata.SnappyTableStatsProviderService

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

object TableDetails {

def getAllTablesInfo: Seq[TableSummary] = {
Expand Down Expand Up @@ -60,4 +64,27 @@ 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
val schemaFields = view.getSchema.asInstanceOf[StructType].fields
val schemaStringBuilder = new StringBuilder
schemaFields.foreach(field => {
schemaStringBuilder.append("(" + field.name + ":" + field.dataType + ", " +
"nullable=" + { if (field.nullable) "Yes" else "No" } + ")\n")
})

val columnsInfo = mutable.HashMap.empty[String, Any]
columnsInfo += ("numColumns" -> colCount);
columnsInfo += ("fieldsString" -> schemaStringBuilder.toString());

new GlobalTemporaryViewSummary(view.getFullyQualifiedName, view.getTableName,
view.getTableType, columnsInfo)
}).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 columnsInfo: mutable.HashMap[String, Any]
)
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 View's Name")
gblTempViewStatsColumn += ("type" -> "Type")
gblTempViewStatsColumn += ("typeTooltip" -> "Type")
gblTempViewStatsColumn += ("columnsCount" -> "Fields")
gblTempViewStatsColumn += ("columnsCountTooltip" -> "Number of Fields/Columns in the 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporarily creating a session just for listing the tables is quite inefficient. Can't this be included as part of regular tableTypesMap created in getStatsFromAllServers (where tableType can be GLOBAL_TEMPORARY)?

To get the list without session use: SnappyContext.sharedState(sc = null).globalTempViewManager.listViewNames("*"). This avoids unnecessary creation of a SnappyContext object which is expensive and not required. Secondly this list can just be appended to the list of "hiveTables" in getStatsFromAllServers with tableType=GLOBAL_TEMPORARY. Display can use the tableType to distinguish. This avoids separate calls for this as well as the new message.

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