Share via


Getting Started

The following prerequisites are required for running the sample:

To run this sample, you need to have administrative access to your HPC cluster’s head node and WCF broker node, and 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. Follow the Deploying Windows Azure Worker Nodes in Windows HPC Server 2008 R2 Step-by-Step Guide on TechNet for further information.

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

Task 1 – Creating an SQL Azure Server

  1. In this task, you will create a new SQL Azure server.
  2. Log on to the Windows Azure Platform Management Portal. Select database in the left lower pane, as shown in Figure 2:

    Figure 2

    Selecting the Database section from the bottom-left options pane

  3. In the main pane, which is titled Getting Started, select Create a newSQL Azure Server, as shown in Figure 3:

    Figure 3

    Creating a new SQL Azure Server

  4. In the Create Server dialog box, select the Windows Azure account you wish to use, as shown in Figure 4, and click next.

    Figure 4

    Selecting a Windows Azure subscription

  5. In the next window of the dialog box, select a region for the SQL Azure server, as shown in Figure 5, to match the region used in the Windows Azure node template in the HPC cluster.

    Figure 5

    Selecting a region

  6. In the next window of the dialog box, create an administrator login name and password, as shown in Figure 6:

    Figure 6

    Setting up the Administrator login

  7. In the final window of the dialog box, configure the firewall rules, as shown in Figure 7. Select Allow other Windows Azure services to access this server, and create firewall rules that allow access to all the on-premises machines from which you intend to access this database.

    Figure 7

    Setting firewall rules

Task 2 – Inspecting the Corpus Loader Project

  1. In this task, you will inspect the corpus loader project used to deploy the “Brown Corpus” to an SQL Azure database.
  2. Open Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  3. Open the WordAssociation.sln solution file located in the WordAssociation\Source folder. In the Solution Explorer window, expand the WordAssociation.Tools.CorpusLoader project node, as shown in Figure 8:

    Figure 8

    The WordAssociation.Tools.CorpusLoader project

  4. Open the Program.cs file and review the contents of the LoadCorpus method. This function has two sections:
    1. The first section uses the Corpus.edmx.sql file to create the Corpus database in SQL Azure and the tables that will hold the Brown Corpus data.
    2. The second part synchronizes the Corpus.sdf file (a local SQLCE database containing the Brown Corpus) with the SQL Azure Corpus database.

Task 3 – Inspect and Configure the Corpus Loader Configuration File

  1. In this task, you will inspect the Corpus Loader project’s App.config file and configure it to use the SQL Azure database you created.
  2. In the WordAssociation.Tools.CorpusLoader project, open the App.config file and look for the <connectionStrings> section.

<connectionStrings> <add name="CorpusEntities" connectionString="metadata=res://*/Corpus.csdl|res://*/Corpus.ssdl|res://*/Corpus.msl;provider=System.Data.SqlClient;provider connection string=&quot; data source=[serverName].database.windows.net;initial catalog=Corpus;user id=[LoginForDb]@[serverName];password=[Password];App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> <add name="Master" connectionString="Server=[serverName].database.windows.net;Database=master;User ID=[LoginForDb]@[serverName]; Password=[password]; Trusted_Connection=False; Encrypt=True;"/> </connectionStrings>
  1. The following fields need to be configured in each of the connection strings (CorpusEntities and Master) to enable connections to the database server you created in Task 1.
    1. [serverName]. This field should be replaced with the name of the server you created.
    2. [LoginForDb]. This field should be replaced with the administrator login name you created.
    3. [Password]. This field should be replaced with the administrator password you created.

Task 4 – Inspecting the WCF Service Projects

  1. In this task, you will inspect the WCF service project to see the contract and implementation of the service.
  2. Open Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.
  3. Open the WordAssociation.sln solution file, which is located in the WordAssociation\Source folder. In the Solution Explorer window, expand the WordAssociation.Serviceproject node, as shown in Figure 9:

    Figure 9

    The WordAssociation.Service project

  4. Open the IWordAssociationService.cs file and inspect the service contract. The service contract contains only one method: the GetTextMatches method.
  5. Open the WordAssociationService.cs file and inspect the contents of the service. The service implementation is a linguistic word-association algorithm – that is, it looks for the most common words that appear in close proximity to each other in a given text (examples of word-associations from common speech are ‘bread’ and ‘butter’ or ‘life’ and ‘death’). For this example, the Brown University Standard Corpus of Present-Day American English will be used as input.
    1. Note the Console.WriteLine method call. This call will output a message, which you will be able to see in the task results window in the HPC 2008 R2 Cluster Manager application.
    2. Also note the ServiceContext.Logger.TraceEvent method call (in the MatchInText method). This method call outputs debug information to a local trace file, which can be collected after the job finishes running.

Task 5 – Inspecting the WCF Service Configuration

In this task, you will inspect the contents of the service’s configuration file. The service 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 WordAssociation.Service project, open the WordAssociationService.cs file and locate the following constant:

public const string ConnectionString = @"metadata=res://*/Corpus.csdl|res://*/Corpus.ssdl|res://*/Corpus.msl; provider=System.Data.SqlClient; provider connection string=""data source=[serverName].database.windows.net; initial catalog=Corpus;user id=[LoginForDb]@[serverName]; password=[Password];App=EntityFramework""";
  1. The following fields need to be configured to enable connections to the database server you created in Task 1.
    1. [serverName]. This field should be replaced with the name of the server you created.
    2. [LoginForDb]. This field should be replaced with the administrator login name you created.
    3. [Password]. This field should be replaced with the administrator password you created.
  2. In the WordAssociation.Service project, open the WordAssociation.config file. Look for the <microsoft.Hpc.Session.ServiceRegistration> XML element:

    SquareService.config

    <microsoft.Hpc.Session.ServiceRegistration> <service assembly="WordAssociation.Service.dll" contract="WordAssociation.Service.IWordAssociationService" type="WordAssociation.Service.WordAssociationService" includeExceptionDetailInFaults="true" maxConcurrentCalls="0" serviceInitializationTimeout="60000" stdError="" maxMessageSize="65536"> </service> </microsoft.Hpc.Session.ServiceRegistration>

  3. The following attributes are required to configure the hosting of the service:
    1. assembly. Defines the location of the service’s assembly file, which should contain both the service contract and the service implementation. When running WCF services in Windows Azure nodes, only the name of the assembly needs to be set.
    2. contract. Defines the fully qualified name of the service contract.
    3. type. Defines the fully qualified name of the service’s implementation class.
  4. Inside the WordAssociation.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.
  5. Inside the WordAssociation.config file, locate the <system.serviceModel> XML element and inspect its contents. This XML element contains the configuration for the broker service’s message logging as well as the binding configuration for the endpoints exposed by the broker service.

Task 6 – Inspecting the Client Configuration

  1. In this task, you will explore the client configuration used to create the new service job (also referred to as session).
  2. In the Solution Explorer window, expand the WordAssociation.ConsoleClient project node, as shown in Figure 10:

    Figure 10

    The WordAssociation.ConsoleClient project

  3. In the WordAssociation.ConsoleClient project, open the app.config file and locate the <appSettings> XML element:

    C#

    <appSettings> <add key="HeadNodeName" value="MyHeadNode"/> <add key="SoaServiceName" value="WordAssociation"/> <add key="NodeGroup" value="AzureNodes"/> </appSettings>

  4. Set the HeadNodeName key to match the name of the head node machine. If you intend to test this sample with on-premises nodes in addition to Windows Azure nodes, change the name of the NodeGroup key to that of the desired node group.
    Note:
     There is no need to change the SoaServiceName key, as this attribute is currently set to the name of the tested service, which is WordAssociation.
  5. Still in the App.config file, locate the <connectionStrings> section:

<connectionStrings> <add name="CorpusEntities" connectionString="metadata=res://*/Corpus.csdl|res://*/Corpus.ssdl|res://*/Corpus.msl;provider=System.Data.SqlClient;provider connection string=&quot; data source=[serverName].database.windows.net;initial catalog=Corpus;user id=[LoginForDb]@[serverName];password=[Password];App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> </connectionStrings>
  1. The following fields need to be configured to enable connections to the database server you created in Task 1.
    1. [serverName]. This field should be replaced with the name of the server you created.
    2. [LoginForDb]. This field should be replaced with the administrator login name you created.
    3. [Password]. This field should be replaced with the administrator password you created.

Task 7 – Inspecting the Client Code for Calling the WordAssociation Service

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 polls the WCF broker node for completed service calls.

  1. In the WordAssociation.ConsoleClient project’s Program.cs file, locate the AnalyzeFile method and examine its contents.
  2. The AnalyzeFile 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. 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 AnalyzeFile method uses the Microsoft.Hpc.Scheduler.Session.SessionStartInfo type to define how to start the durable session created by the Microsoft.Hpc.Scheduler.Session.DurableSession.CreateSession method. Once the session is created, the AnalyzeFile method creates a BrokerClient<IWordAssociationService> object that is used both to send service requests to the WCF Broker node and to poll the broker node for responses with the PollBroker method:

    C#

    using (var session = DurableSession.CreateSession(info)) { using (var client = new BrokerClient<IWordAssociationService>(session)) { // creating a long running task for polling the WCF broker node PollBroker(result, countdown, client); foreach (var text in texts) { client.SendRequest<GetTextMatchesRequest>( new GetTextMatchesRequest(text.Id, words)); } client.EndRequests(); countdown.Wait(); } session.Close(); }
  4. Build the WordAssociation solution.