Readme

HPC AsianOptions Service

Lab version:1.0.0

Last updated:10/27/2018

Contents

Overview

Getting Started

Task 1 – Inspecting the WCF Service Project

Task 2 – Inspecting the WCF Service Configuration

Task 3 – Inspecting the Client Configuration

Task 4 – Inspecting the Client Code for an Interactive Session

Task 5 – Inspecting the Client Code for a Durable Session

Deployment

Task 1 – Copying the WCF Service Configuration to the Head Node

Task 2 – Deploying the WCF Service to On-Premises Nodes

Task 3 – Deploying the WCF Service to Windows Azure Nodes

Running the Client

Task 1 – Verifying Cluster State

Task 2 – Running the Client Application

Summary

Overview

The Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application, a Microsoft Excel workbook that consumes the service, and a utility client application for creating and closing sessions. This sample demonstrates how to build, deploy, and execute an HPC SOA application that can run in Windows Azure and how to consume this type of application from a Microsoft Excel workbook.

The Microsoft Excel workbook demonstrates the interactive and durable session types of the HPC SOA application, which are used to call a WCF service that is deployed to the HPC cluster, whether it resides in an on-premises node or in a Windows Azure node.

Key Features

This sample demonstrates the following:

  • Creation of an HPC-enabled WCF service.
  • Deploying and configuring the WCF service in the cluster (both on-premises and in Windows Azure).
  • Creation of a client HPC SOA application that calls the WCF service using the following session types:

◦Interactive session

◦Durable session

Getting Started

To run this sample, you must first install the HPC Pack 2008 R2 Client Utilities Redistributable Package with Service Pack 1 and the HPC Pack 2008 R2 SDK with Service Pack 1. In addition, you need to have Microsoft Office version 2007 SP1 or higher, and administrative access to your HPC cluster’s head node and broker node.

To run the WCF service in Windows Azure nodes, you must have a valid Windows Azure account, a Windows Azure worker node template defined in your head node, and several Windows Azure worker nodes in the HPC cluster that are started and online. See the Deploying Azure Worker Nodes in Windows HPC Server 2008 R2 SP1 Step-by-Step Guide on TechNet for further information.

Note: Although this solution is for Visual Studio 2010, the AsianOptionsService project uses .NET Framework 3.5; this is because currently the HPC cluster cannot host WCF services compiled for .NET Framework 4.

Task 1 – Inspecting the WCF Service Project

In this task, you will inspect the WCF service project to see the contract and implementation of the service.

  1. Open Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  2. Open the AsianOptions.sln solution file located in the AsianOptions\Source folder.
  3. In the Solution Explorer window, expand the AsianOptionsService project node, as shown in Figure 1

Figure 1

The AsianOptionsService project

  1. Open the IPricingService.cs file and inspect the service contract. The service contract contains only one method: the PriceAsianOptions method.
  2. Open the PricingService.cs file (double-click the PricingService.svc file) and inspect the contents of the service. The service implementation is a loop performing Monte Carlo pricing simulations.
  3. Note the ServiceContext.Logger.TraceEventandServiceContext.Logger.TraceData method calls. These method calls will output debugging information to a trace file, which you will be able to see in the head node after the job finishes running.

Task 2 – Inspecting the WCF Service Configuration

In this task, you will inspect the contents of the service’s configuration file. The configuration file allows you to set how the HPC service host locates your service and hosts it. The configuration file also includes information on how to expose the service through the WCF broker node.

  1. In the AsianOptionsService project, open the AsianOptionsService.config file. Look for the microsoft.Hpc.Session.ServiceRegistrationXML element:

AsianOptionsService.config

microsoft.Hpc.Session.ServiceRegistration

<service

assembly="\\MyHeadNode\Apps\AsianOptions\AsianOptionsService.dll"

contract="AsianOptionsService.IPricingService"

type="AsianOptionsService.PricingService"

includeExceptionDetailInFaults="true"

maxConcurrentCalls="0"

serviceInitializationTimeout="60000"

stdError=""

maxMessageSize="65536"

</service

</microsoft.Hpc.Session.ServiceRegistration

  1. The following attributes are required to configure how the service is hosted:
  2. assembly. Defines the location of the service’s assembly file, which should contain both the service contract and the service implementation.
  3. contract. Defines the fully qualified name of the service contract.
  4. type. Defines the fully qualified name of the service’s implementation class.
  5. Inside the AsianOptionsService.config file, locate the brokerServiceAddresses XML element under the microsoft.Hpc.Broker>\<services> element. Each of the <add> XML elements defines a base address that the WCF broker node uses to listen for client service requests.
  6. Inside the AsianOptionsService.config file, locate the system.serviceModel XML element and inspect the contents of that element. This XML element contains the configuration for the service’s message logging as well as the binding configuration for the endpoints exposed by the service.

Task 3 – Inspecting the Client Configuration

In this task, you will explore the client configuration used to create the new service job.

  1. In the Solution Explorer window, expand the AsianOptions project node.

Figure 2

The AsianOptions project

  1. In the AsianOptions project, open the app.config file and locate the appSettings XML element:

C#

appSettings

addkey="HeadNodeName"

value="HeadNodeMachine"/>

addkey="SoaServiceName"

value="AsianOptionsService"/>

addkey="NodeGroup"

value="AzureWorkerNodes"/>

</appSettings

  1. Set the HeadNodeName attribute to match your head node’s machine name.

Note: There is no need to change the SoaServiceName attribute, as this attribute is currently set to the name of the tested service(AsianOptionsService).

Task 4 – Inspecting the Client Code for an Interactive Session

In this task, you will examine the client code that creates an interactive session and then calls the hosted WCF service in the HPC cluster. Interactive sessions are service jobs that host WCF services in the HPC cluster, and allow interaction with the services through the WCF broker node, which routes requests and responses from the client to the cluster and back.

  1. In the AsianOptions project, right-click the ThisWorkbook.csfile, select View Code, and locate the GetSession method.
  2. The GetSession method creates a new Microsoft.Hpc.Scheduler.Session.SessionStartInfoobject and then sets its properties, as shown in the following code snippet:

C#

// The name of the head node in the cluster.

stringschedulerName =

ConfigurationManager.AppSettings["HeadNodeName"];

// The name of the called service.

stringserviceName =

ConfigurationManager.AppSettings["SoaServiceName"];

SessionStartInfo info =

newSessionStartInfo(schedulerName, serviceName);

info.Secure = false;

info.NodeGroupList.Add(

ConfigurationManager.AppSettings["NodeGroup"]);

Note: You can also set other properties of the SessionStartInfo object to configure how the job executes. For instance, you can set the SessionResourceUnitType property to SessionUnitType.Cores and then set the MinimumUnits and MaximumUnits to define how many cores will be available for each hosted service.

  1. After setting the session start information, the GetSession method creates a new session object using the Microsoft.HPC.Scheduler.Session.Session class, and then creates a new PricingServiceClient object, which is a generated WCF proxy that will be used to send requests to the service. The PricingServiceClient’s constructor accepts:
  2. Binding. A NetTcpBinding object that will be used to create the client channel.
  3. EndpointAddress.The address of the WCF broker node’s endpoint. This address is stored in the session.EndpointReferenceproperty of the session object.

C#

Sessionsession =Session.CreateSession(info);

Client = new PricingServiceClient(

new NetTcpBinding(SecurityMode.None, false),

session.EndpointReference);

Note: The client’s proxy uses NetTcpBinding with no security (the false parameter in the NetTcpBinding object constructor). If you change the proxy to use transport security, you will also need to change the SessionStartInfo.Secure property to true. You cannot use bindings other than the NetTcp binding.

The Session class is responsible for creating a new job with a service task in the job scheduler. Once the session starts, the client application can send service requests to the WCF broker node that will route them to the available WCF service in the HPC cluster using the Client property.

  1. Open the Sheet1.cs file (right-click it in the Solution Explorer and select View Code), locate the Run_Clickmethod, and examine its contents. This method uses the generated proxy to call the service asynchronously and update the worksheet based on the responses returned from the WCF service, as shown in the following code snippet:

C#

client = Globals.Client;

foreach (string col in cols)

{

for (int i = 2; i <= 11; i++)

{

client.BeginPriceAsianOptions(

newPriceAsianOptionsRequest(initial,

exercise,

up,

down,

interest,

periods,

runs),

(IAsyncResult result) =>

{

double price = client.EndPriceAsianOptions(result)

.PriceAsianOptionsResult;

// Populate the cell: Cell Id is stored in result.AsyncState

this.Range[(string)result.AsyncState, missing].Value2 = price;

// Some more Excel work

// …

} ,null);

}

}

Task 5 – Inspecting the Client Code for a Durable Session

In this task, you will examine the client code that creates a durable session, sends requests to the WCF service hosted in the HPC cluster, and reconnects to the session at a later timeto retrieve the responses returned by the hosted services. Durable sessions are different from interactive sessions in that the WCF broker queues the responses that the WCF service returns, allowing clients to disconnect from the session after sending requests to the broker node, and retrieve the responses by reconnecting to the durable session later on.

  1. In the AsianOptions project, open the Sheet2.cs file (right-click it in the Solution Explorer and select View Code).Locate the SubmitRequests method and examine its contents.
  2. This method also uses the Microsoft.Hpc.Scheduler.Session.SessionStartInfotype to define how to start the session, but this time the session is a durable session, created by the Microsoft.Hpc.Scheduler.Session.DurableSession.CreateSessionmethod, as shown in the following code snippet:

C#

using (DurableSession session = DurableSession.CreateSession(info))

{

this.Range["D21", missing].Value2= "Session Created.";

this.Range["D20", missing].Value2 = session.Id;

SubmitServiceRequests(initial,

exercise,

up,

down,

periods,

runs,

interestStart,

interestEnd,

interestStep,

session);

}

  1. After creating the session and sending requests to the service, the session object is disposed, but the durable session keeps running in the job scheduler, collecting responses from the running services. To connect to the running session, the DurableSession.AttachSession method is called from the RetrieveResponses method (still in the Sheet2.cs file), with an object of type Microsoft.Hpc.Scheduler.Session.SessionAttachInfo that contains the ID of the running durable session, as shown in the following code snippet:

C#

SessionAttachInfoattachInfo =

new SessionAttachInfo(schedulerName, sessionId);

Console.WriteLine("Attaching to session {0}...", sessionId);

// Attach to an already running session

using (DurableSession session = DurableSession.AttachSession(attachInfo))

{

GetServiceResponse(results, session);

// Close the session to reclaim the system storage

// used to store the results. After the session is closed

// you cannot attach to the same session again

session.Close();

}

  1. Locate the SubmitServiceRequestsmethod and examine its contents. This method uses the BrokerClient<T> and the PriceAsianOptionsRequest classes to send service requests to the broker node.
  2. Locate the GetServiceResponse method. This method creates a BrokerClient<T> object and then iterates the service responses received from the broker node by calling the BrokerClient<T>.GetResponsesTMessage generic method. In this method, TMessage is of type PriceAsianOptionsResponse, a message contract class representing the response type of the called service operation, as shown in the following code snippet:

C#

using(BrokerClientIPricingServiceclient =

newBrokerClientIPricingService>(session))

{

foreach(BrokerResponsePriceAsianOptionsResponseresponsein

client.GetResponsesPriceAsianOptionsResponse>())

{

cellContextidx = response.GetUserDatacellContext>();

doubleprice = response.Result.PriceAsianOptionsResult;

// More calculations and Excel work

// …

}

}

  1. Build the AsianOptions solution.

Deployment

In order to run this sample, you will need to deploy the WCF service assemblies and configuration to your head node, your on-premises nodes, and your Windows Azure nodes.

Task 1 – Copying the WCF Service Configuration to the Head Node

In this task, you will copy the WCF service configuration file to the head node’s service registration folder. This allows you to use the HPC 2008 R2 Cluster Manager application to diagnose the service deployment and create new service tasks for the service. It also allows clients to create new sessions (interactive and durable) against the head node.

  1. Open the command prompt window from Start | All Programs | Microsoft Visual Studio 2010 | Visual Studio Tools | Visual Studio Command Prompt (2010).
  2. Navigate to the AsianOptions sample folder, and from there navigate to the Source\AsianOptionsService\bin folder.
  3. Run the following command to copy the service configuration file to the head node:

CMD

xcopyAsianOptionsService.config \\MyHeadNode\HpcServiceRegistration\ /Y

Note: Replace the MyHeadNode machine name with the name of your head node machine. The HpcServiceRegistration share is created when installing the head node.

Task 2 – Deploying the WCF Service to On-Premises Nodes

In this task, you will deploy the WCF service to your HPC cluster’s on-premises nodes.

Note: If this sample is only being tested on Windows Azure nodes, you can skip this task.

There are two ways in which you can copy the WCF service such that it is accessible to your on-premises nodes:

  • Copy the service assembly to a shared folder in the HPC cluster.
  • Copy the service assembly to each of the on-premises nodes in the HPC cluster.

If you examine the service configuration file (task 2 in the Getting Started section above), you will notice that the location of the service assembly is set to a shared folder in the head node machine,Therefore, follow the following steps:

  1. In your head node machine, create a share named apps. Verify that all the on-premises nodes can access this share.
  2. Open the command prompt window from Start | All Programs | Microsoft Visual Studio 2010 | Visual Studio Tools | Visual Studio Command Prompt (2010).
  3. Navigate to the AsianOptions sample folder, and from there navigate to the Source\AsianOptionsService\bin folder.
  4. Run the following command to copy the service assembly to the head node:

CMD

xcopy *.* \\MyHeadNode\apps\AsianOptions\ /EY

Note: Replace the MyHeadNode machine name with the name of your head node machine.

If you want to deploy the service assembly to each on-premises node, follow these instructions:

  1. Change the AsianOptions service configuration file to point to the folder in which the service assembly is located. For example:

AsianOptionsService.config

microsoft.Hpc.Session.ServiceRegistration

<service

assembly="e:\apps\AsianOptions\AsianOptionsService.dll"

contract="AsianOptionsService.IPricingService"

type="AsianOptionsService.PricingService"

includeExceptionDetailInFaults="true"

maxConcurrentCalls="0"

serviceInitializationTimeout="60000"

stdError=""

maxMessageSize="65536"

</service

</microsoft.Hpc.Session.ServiceRegistration

Note: The assembly must be located in the same folder in each on-premises node.

  1. Copy the updated service configuration file to the head node, as specified in the previous task.
  2. Copy the service assembly to the target location in each of the on-premises nodes. If you already have the service assembly located in the head node, you can run the following command to automatically copy the files to all the on-premises nodes:

CMD

clusrun /nodegroup:ComputeNodesxcopy \\MyHeadNode\apps\AsianOptions\*.* E:\apps\AsianOptions\ /EY

Note: If you only want to deploy the service to some of the compute nodes, change the node group specified in the nodegroup parameter. Also, remember to rename the MyHeadNode machine name to that of your head node machine.

Task 3 – Deploying the WCF Service to Windows Azure Nodes

In this task, you will deploy the WCF service to your Windows Azure nodes.

  1. Open the command prompt window from Start | All Programs | Microsoft Visual Studio 2010 | Visual Studio Tools | Visual Studio Command Prompt (2010).
  2. Navigate to the AsianOptions sample folder, and from there navigate to the Source\AsianOptionsService folder.
  3. Run the following command to create a deployment package for the service:

CMD

hpcpack create AsianOptionsService.zip bin\

Note: Do not change the name of the package; the name must match that of the service configuration file and the service name used by the client application.

  1. Run the following command to upload the deployment package to the Windows Azure package storage:

CMD

hpcpackupload AsianOptionsService.zip /nodetemplate:"Azure node template"

Note: Change the value of the nodetemplate parameter to the name of your Windows Azure node template.

  1. If you already have Windows Azure nodes started in the HPC cluster, you need to copy the new package to them. To sync the Windows Azure nodes with the new packages stored in the application packages blob, run the following command:

CMD

clusrun /nodegroup:WindowsAzureNodeshpcsync

Running the Client

Task 1 – Verifying Cluster State

In this task, you will verify that the nodes in your cluster are online.