22
Readme HPC AsianOptions Service Lab version: 1.0.0 Last updated: 4/30/2022

Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

ReadmeHPC AsianOptions ServiceLab version: 1.0.0

Last updated: 5/23/2023

Page 2: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Contents

OVERVIEW................................................................................................................................................. 3

GETTING STARTED................................................................................................................................... 4Task 1 – Inspecting the WCF Service Project.......................................................................................4

Task 2 – Inspecting the WCF Service Configuration.............................................................................5

Task 3 – Inspecting the Client Configuration.......................................................................................5

Task 4 – Inspecting the Client Code for an Interactive Session............................................................6

Task 5 – Inspecting the Client Code for a Durable Session...................................................................8

DEPLOYMENT.......................................................................................................................................... 11Task 1 – Copying the WCF Service Configuration to the Head Node.................................................11

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

Task 3 – Deploying the WCF Service to Windows Azure Nodes.........................................................13

RUNNING THE CLIENT............................................................................................................................ 14Task 1 – Verifying Cluster State.........................................................................................................14

Task 2 – Running the Client Application............................................................................................15

SUMMARY................................................................................................................................................ 19

Page 3: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

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

Page 4: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

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 1The AsianOptionsService project

4. Open the IPricingService.cs file and inspect the service contract. The service contract contains only one method: the PriceAsianOptions method.

5. 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.

Page 5: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

a. Note the ServiceContext.Logger.TraceEvent and ServiceContext.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.ServiceRegistration> XML 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>

2. The following attributes are required to configure how the service is hosted:

a. assembly. Defines the location of the service’s assembly file, which should contain both the service contract and the service implementation.

b. contract. Defines the fully qualified name of the service contract.

c. type. Defines the fully qualified name of the service’s implementation class.

3. 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.

4. 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.

Page 6: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Figure 2The AsianOptions project

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

C#

<appSettings> <add key="HeadNodeName" value="HeadNodeMachine"/> <add key="SoaServiceName" value="AsianOptionsService"/> <add key="NodeGroup" value="AzureWorkerNodes"/></appSettings>

3. 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.cs file, select View Code, and locate the GetSession method.

2. The GetSession method creates a new Microsoft.Hpc.Scheduler.Session.SessionStartInfo object and then sets its properties, as shown in the following code snippet:

C#

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

Page 7: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

string schedulerName = ConfigurationManager.AppSettings["HeadNodeName"];

// The name of the called service.string serviceName = ConfigurationManager.AppSettings["SoaServiceName"];

SessionStartInfo info = new SessionStartInfo(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.

3. 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:

a. Binding. A NetTcpBinding object that will be used to create the client channel.

b. EndpointAddress. The address of the WCF broker node’s endpoint. This address is stored in the session.EndpointReference property of the session object.

C#

Session session = 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.

Page 8: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

4. Open the Sheet1.cs file (right-click it in the Solution Explorer and select View Code), locate the Run_Click method, 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( new PriceAsianOptionsRequest(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 time to 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.

Page 9: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

2. This method also uses the Microsoft.Hpc.Scheduler.Session.SessionStartInfo type to define how to start the session, but this time the session is a durable session, created by the Microsoft.Hpc.Scheduler.Session.DurableSession.CreateSession method, 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);

}

3. 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#

SessionAttachInfo attachInfo = 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();}

Page 10: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

4. Locate the SubmitServiceRequests method and examine its contents. This method uses the BrokerClient<T> and the PriceAsianOptionsRequest classes to send service requests to the broker node.

5. 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>.GetResponses<TMessage> 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 (BrokerClient<IPricingService> client = new BrokerClient<IPricingService>(session)){

foreach (BrokerResponse<PriceAsianOptionsResponse> response in client.GetResponses<PriceAsianOptionsResponse>()) { cellContext idx = response.GetUserData<cellContext>(); double price = response.Result.PriceAsianOptionsResult; // More calculations and Excel work // … }}

6. Build the AsianOptions solution.

Page 11: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

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

xcopy AsianOptionsService.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.

Page 12: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

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.

2. Copy the updated service configuration file to the head node, as specified in the previous task.

3. 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:ComputeNodes xcopy \\MyHeadNode\apps\AsianOptions\*.* E:\apps\AsianOptions\ /EY

Page 13: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

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.

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

CMD

hpcpack upload AsianOptionsService.zip /nodetemplate:"Azure node template"

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

5. 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:WindowsAzureNodes hpcsync

Page 14: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Running the Client

Task 1 – Verifying Cluster State

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

1. Open the HPC 2008 R2 Cluster Manager application from Start | All Programs | Microsoft HPC Pack 2008 R2 | HPC Cluster Manager.

2. In the Cluster Manager application, enter the Node Management section and verify that the Windows Azure nodes in the cluster are online, as shown in Figure 3

Figure 3Verifying the state of the Windows Azure Nodes

3. Enter the Configuration section, select the Services option from the configuration list, and run the SOA Service Loading Diagnostics test on the AsianOptionsService service, as shown in Figure 4

Page 15: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Figure 4Running Service Load Diagnostics

4. In the Run Diagnostic Tests window, select the AzureWorkerNodes node group from the Nodes in this group drop-down list, check the Go to Test Results to see test progress and results checkbox, and then click Run.

5. In the Diagnostics window, wait for the test to complete and verify its success.

Note: If the service diagnostic fails, view the diagnostic information and perform the required fix. If this involves changing the service configuration or recompiling the service assemblies, you will need to redeploy your service before running the diagnostics again.

Task 2 – Running the Client Application

In this task, you will test the WCF service in the HPC cluster by running the client application.

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. Build the solution and run the AsianOptions project. You should see the following Excel worksheet:

Page 16: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Figure 5Asian Options Excel Worksheet “Sheet1,” used for an interactive session

4. Click the Run button. This will start an interactive session with the cluster and start calling the service tasks, as shown in Figure 6

Figure 6Sheet1 running an interactive session

5. Select “Sheet 2” from the bottom tabs. You should see the following Excel worksheet:

Page 17: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Figure 7Asian Options Excel Worksheet “Sheet2,” used for a durable session

6. Click the Submit button. This will start a durable session with the cluster. The Status cell should now show “Request sent” and a value should appear in the Session ID cell, as shown in Figure 8

Figure 8The Status and Session ID cells.

7. Once the session has started, you can click the Retrieve button to start retrieving the results from the broker node and update the Microsoft Excel worksheet, as shown in Figure 9

Figure 9

Page 18: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Results retrieved from the broker node and updated in the worksheet

Page 19: Asian Options Serviceaz12722.vo.msecnd.net/.../AsianOptions.docx · Web viewThe Asian Options sample is a solution containing a WCF service designed to run as a Windows HPC SOA application,

Summary

After running the AsianOptions service sample you should have learned the following:

How to create a WCF service that can run inside Windows Azure nodes, as well as in on-premises nodes.

How to create a configuration file for the WCF service and deploy it to the head node.

How to deploy a WCF service assembly to on-premises nodes and to Windows Azure nodes.

How to use an interactive session and a durable session to call the WCF service.