Adding System Skew to the Portlet Header

Extensibility
Extensibility covers the mechanisms by which you, as the user or developer, can extend the functionality of the Teradata Database, for example with the use of User Defined Functions, or UDFs.
Teradata Employee

Adding System Skew to the Portlet Header

In this section we will add the system name and system skew value to the portlet header.

We need to be able to get the skew value from the service. We don't want to query the cache database again because we might get a value from the database that doesn't match the value we got in our original query (because the Data Collector updated the database between queries). So we should cache the value in a field in the service. We need to make the following changes to the service.

First, we add a field to the service to hold the latest skew value. We need to save the value for each system that we might be monitoring so we will save it in a map.

SkewedSession\src\java\com\teradata\portlets\skewedsessions\service\impl\SkewedSessionsManagerImpl.java


//** Add following section below **/
import java.util.Map;
import java.util.HashMap;
//** End add section **/

public class SkewedSessionsManagerImpl implements SkewedSessionsManager
{
private static Log log = LogFactory.getLog(SkewedSessionsManagerImpl.class);
private SessionDAO sessionDAO;
private SystemStatisticsDAO statisticsDAO;
//** Add following section below **/
private Map<String, Float> lastAmpCpuSkew = new HashMap<String, Float>();
//End add section

Second, we save the skew value when we collect skewed sessions:


SkewedSession\src\java\com\teradata\portlets\skewedsessions\service\impl\SkewedSessionsManagerImpl.java

    public List<Session> getCurrentSkewedSessions(SkewedSessionsPreferences preferences)
{
List<Session> result = new ArrayList<Session>();
Integer id = getSystemId(preferences.getSystem());
if (id != null)
{
SystemStatistics statistics = statisticsDAO.getCurrentSystemStatistics(id);
if (statistics != null && statistics.getAmpCpuSkew() > preferences.getAmpCpuSkewThreshold())
{
//** Add the following section below **/
// save the system skew value
lastAmpCpuSkew.put(preferences.getSystem(), statistics.getAmpCpuSkew());
//** End add section **/

List<Integer> systemIds = new ArrayList<Integer>();
systemIds.add(id);

// fetch the data
List<Session> sessions = sessionDAO.getCurrentActiveSessions(systemIds);

for (Session session : sessions)
{
if ((session.getComputedState().equals("ACTIVE"))
&& (session.getCpuSkew() > preferences.getSessionCpuSkewThreshold()))
{
result.add(session);
}
}
}
}
return result;
}

Third, we add a new method to fetch the skew value.

SkewedSession\src\java\com\teradata\portlets\skewedsessions\service\impl\SkewedSessionsManagerImpl.java


    /**
* Get the most recently collected AMP CPU skew for the specified system.
*
* @param systemName the system to monitor.
* @return the AMP CPU skew or null if no value has been fetched.
*/
public Float getCurrentAmpCpuSkew(String systemName)
{
return lastAmpCpuSkew.get(systemName);
}


Fourth, we add the new method to the service interface so that it is accessible from our controller.

SkewedSession\src\java\com\teradata\portlets\skewedsessions\service\SkewedSessionsManager.java


    /**
* Get the most recently collected AMP CPU skew for the specified system.
*
* @param systemName the system to monitor.
* @return the AMP CPU skew or null if no value has been fetched.
*/
public Float getCurrentAmpCpuSkew(String systemName);


Next, we need to modify the controller to get the value from the service and add it as a view object so that it is accessible from the view.

SkewedSession\src\java\com\teradata\portlets\skewedsessions\controllers\SkewedSessionsViewController.java

    public void summary(ControllerContext ctx)
{
ctx.setViewName("summary");

// get the user's preferences for this portlet instance
SkewedSessionsPreferences preferences = new SkewedSessionsPreferences();
preferences = ctx.loadPreferences(SKEWED_SESSIONS, preferences);

// get the active sessions for the user's preferred system
List<Session> sessions =
skewedSessionsManager.getCurrentSkewedSessions(preferences);

// build a table widget model
SkewedSessionsTableWidget tableWidget = new SkewedSessionsTableWidget();
tableWidget.setSessions(sessions);

// pass table widget model to the view
ctx.addViewObject("skewedSessions", tableWidget);

//** Add the following section below **/

// get the system skew value
Float ampCpuSkew = skewedSessionsManager.getCurrentAmpCpuSkew(preferences.getSystem());

if (ampCpuSkew != null)
{
ctx.addViewObject("ampCpuSkew", ampCpuSkew);
}

//** End add section **/

// pass the preferences to the view
ctx.addViewObject("preferences", preferences);
}

Finally, we add the system name and skew value to the portlet header. Viewpoint provides a portlet-header-overlay tag that allows us to add content to the header.

SkewedSessions\web\WEB-INF\portlet-jsp\summary.jsp

<%@ page contentType="text/html" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!-- Add the following section below -->

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!-- End add section -->

<%@ taglib prefix="vs" uri="http://teradata.com/viewpoint/security" %>
<%@ taglib prefix="vp" uri="http://teradata.com/viewpoint/core"%>

<jsp:include page="include.jsp"/>

<c:choose>
<c:when test="${preferences.system == null}">
Please use preferences to choose a system.
</c:when>
<c:otherwise>
<vp:tableWidget context="${context}" model="${skewedSessions}" />
</c:otherwise>
</c:choose>
<!-- Add the following section below -->

<vp:portletHeaderOverlay state="all" mode="append" namespace="${context}">
<div class="headerItem">
${preferences.system}
(Skew: <fmt:formatNumber value="${ampCpuSkew}" maxFractionDigits="0" />%)
</div>
</vp:portletHeaderOverlay>

<!-- End add section -->

The end result should look like this:

Tags (2)