Generate the SkewedSessions Project

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

Generate the SkewedSessions Project

The following article describes how to generate the SkewedSessions project.


Be aware

The SkewedSessions portlet requires a working Data Collection Service(DCS) to display meaningful data. If you do not have access to a DCS, it is still recommended that you step through this tutorial, as it introduces several important concepts, but note that the completed portlet will not display any data.

Overview

This section describes the process for creating a portlet that displays data from the Viewpoint cache database. The cache database is a database where the Viewpoint Data Collector puts data it has collected from your Teradata system(s).

This tutorial creates a portlet that displays skewed active sessions for any AMP that is causing a system-wide skew.  This portlet would be useful for identifying the queries that might be causing the entire system to be skewed.

We're going to follow an iterative development process in this tutorial, with frequent checkpoints to make sure that we are on track.

Step 1: Generate a new project.

Follow the steps in the Generating the Hello Project tutorial. Except in this case we will use SkewedSessions as the portlet name.

Step 2: Add a preferences form for monitored system name.

The user needs to be able to choose the system that will be monitored by this portlet. So let's add a preferences form for choosing a system. You may want to review the Adding a Preferences Form section before making the changes described below.

In the SkewedSessionsPreferences model we add a system field.

SkewedSessions/src/java/com/teradata/portlets/skewedsessions/model/SkewedSessionsPreferences.java

/**
* This class is the model for the preferences for the SkewedSessions portlet.
*/
public class SkewedSessionsPreferences extends PreferencesModel
{
/*
* serial UID. Change this to a unique number for your portlet.
*/
private static final long serialVersionUID = 6960306072306995665L;

//***Add the following section below***/
/**
* The system that is monitored by this portlet.
*/
@Preference private String system;

/**
* Gets the system that is monitored.
*
* @return The monitored system name.
*/
public String getSystem()
{
return system;
}

/**
* Sets the system that is montiored.
*
* @param system The system to monitor.
*/
public void setSystem(String system)
{
this.system = system;
}

//***End add section***/
}

We need to provide the user with a list of systems from which to select the system they wish to monitor. To get the list of systems we use the getSystemNames method in the SessionDAO.


First we need to define the SessionDAO in our spring dataSourceiBatis.xml configuration file. 

<!-- DAO's -->
<bean id="preferencesDAO"
class="com.teradata.portal.shared.dao.ibatis.PreferencesDAOiBatis">
<description>DAO for accessing preferences table</description>
<property name="sqlMapClient" ref="tdPortalMapClient" />
</bean>
<!-- Add the following bean below -->
<bean id="sessionDAO"
class="com.teradata.dcs.data.dao.ibatis.SessionDAOiBatis">
<description>DAO for accessing Sessions table</description>
<property name="sqlMapClient" ref="dcsSqlMapClient" />
</bean>
<!-- End add bean -->

And inject the SessionDAO into our service in the spring applicationContext.xml file. 



<!-- The SkewedSessions manager implemenation -->
<bean id="skewedSessionsManager"
class="com.teradata.portlets.skewedsessions.service.impl.SkewedSessionsManagerImpl">
<description>The business delegate for this application</description>
<!-- Add the following property below -->
<property name="sessionDAO" ref="sessionDAO"/>
<!-- End add property -->
</bean>

Then we add a method to the service that uses the DAO to get the system list. 

SkewedSessions/src/java/com/teradata/portlets/skewedsessions/service/impl/SkewedSessionsManagerImpl .java



//***Add the following import statements below***/
import java.util.List;
import java.util.ArrayList;
import com.teradata.dcs.data.dao.SessionDAO;
import com.teradata.dcs.config.model.System;
//***End add import statements***/

public class SkewedSessionsManagerImpl implements SkewedSessionsManager
{
private static Log log = LogFactory.getLog(SkewedSessionsManagerImpl.class);

//***Add the following code section below***/
private SessionDAO sessionDAO;

/**
* Set the session DAO.
*
* @param value The Session DAO.
*/
public void setSessionDAO(SessionDAO value)
{
sessionDAO = value;
}

/**
* Retrieves a list of the names of the systems that are monitored by the
* Data Collector.
*
* @return A list of system names.
*/
public List<String> getMonitoredSystems()
{
List<System> systems = sessionDAO.getAvailableSystems();
List<String> systemNames = new ArrayList<String>();
for (System system : systems)
{
systemNames.add(system.getName());
}
return systemNames;
}
//***End add code section***/
}

Our service has an interface, so we need to declare this new method here as well.

SkewedSessions/src/java/com/teradata/portlets/skewedsessions/service/SkewedSessionsManager .java



/**
* SkewedSessionsManagerImpl.java
*/
package com.teradata.portlets.skewedsessions.service;

//***Add import statement below***/
import java.util.List;
//***End add import statement***/

/**
* This is the interface for the SkewedSessionsManagerImpl class. This class
* implements the Business Delegate pattern. (see
* http://java.sun.com/blueprints/corej2eepatterns/Patterns/BusinessDelegate.html).
* This class is used to interface between the DAO's (see
* http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html)
* and the controllers. Business logic should be implemented here.
*/
public interface SkewedSessionsManager
{
//***Add the following method below***/

/**
* Retrieves a list of the names of the systems that are monitored by the DCS.
*
* @return A list of system names.
*/
public List<String> getMonitoredSystems();

//***End add method***/

Now we need to modify the Preferences controller so we can retrieve a list of available systems for monitoring. We will be retrieving the system list from the getMonitoredSystems() function we implemented above, so we add the Manager to our Preferences controller and add the system list we retrieve to the view object.

SkewedSessions/src/java/com/teradata/portlets/skewedsessions/controllers/SkewedSessionsPreferencesController.java



//***Add import statement below***/
import com.teradata.portlets.skewedsessions.service.SkewedSessionsManager;
//***End add import statement***/
...

public class SkewedSessionsPreferencesController extends FormControllerBase
{
//***Add the following code section***/
protected SkewedSessionsManager skewedSessionsManager = null;

/**
* Setter for the skewedSessionsManager field. This is required so that Spring
* can wire up the implementation at runtime.
*
* @param value The SkewedSessionsManager to be used.
*/
public void setSkewedSessionsManager(SkewedSessionsManager value)
{

// Check our pre conditions
if (value == null)
{
throw new NullPointerException("'manager' argument is null");
}

skewedSessionsManager = value;
}
//***End add code section***/
...
public void renderForm(ControllerContext ctx)
{
//***Add following code section below***/
ctx.addViewObject("systemNames", skewedSessionsManager.getMonitoredSystems());
//***End add code section***/
ctx.addViewObject("preferences", initCommandObject(ctx));
}
}


Next, we need to tell Spring to inject our skewedSessionsManager object into our Preferences controller.

SkewedSessions/web/WEB-INF/applicationContext.xml

    <bean id="skewedSessionsPreferencesController"
class="com.teradata.portlets.skewedsessions.controllers.SkewedSessionsPreferencesController">
<description>Controller for edit view</description>
<!-- Add the following property below -->
<property name="skewedSessionsManager" ref="skewedSessionsManager"/>
<!-- End add property -->
</bean>

 

In the preferences view, we need to prompt the user for their preferred system. The user can select the system from a list of systems. Note that ${systemNames} below references the systemNames object that we added to the view in the controller. In the preferences.jsp file, replace the "[preferences]" flag with the text noted below in the Add Section comment block:



<form:form id="${context}_form" commandName="preferences" method="post" action="${formAction}">
<input type="hidden" name="modal" value="${context}"/>
<input type="hidden" name="role" value="${role}" />
<input type="hidden" name="user" value="${user}" />

<!-- form content goes here -->
<!-- Add the following section below -->
<br/>
Please choose a system to monitor.
<br/>
<br/>
System:
<form:select path="system" size="1">
<c:forEach items="${systemNames}" var="system">
<form:option label="${system}" value="${system}"/>
</c:forEach>
</form:select>
<!-- End add section -->
<br/>
<form:errors path="*" cssStyle="color:red"/>
<br/>
...

You have now completed the preferences form. Go ahead and deploy your portlet and verify that it is working correctly. The preferences page should look like this:


Tags (2)