Home > Sample chapters

Hello, Service Fabric!

Managing your local cluster

There are multiple ways to manage your local cluster. You can use Visual Studio Server Explorer, Cloud Explorer, Service Fabric Local Cluster Manager, or PowerShell. You’ll walk through all the options in this section.

Visual Studio Server Explorer

You can bring up Server Explorer from the Visual Studio View\Server Explorer menu. Under the Azure node, you’ll see a Service Fabric Cluster (Local) node, along with other Azure resource types if you have Azure SDK installed. Figure 1-12 shows that on my cluster I have five nodes, and I have a single Hello World application deployed. You should note that applications and cluster nodes are presented separately, showing the clear separation between workloads and cluster resources that was introduced earlier in this chapter.

FIGURE 1-12

FIGURE 1-12 Server Explorer

The Nodes view in Figure 1-12 seems straightforward—it shows a cluster that consists of five nodes. The application view, however, needs some explanation. What do those levels of nodes mean? Don’t worry, you’ll go through each of them next.

Application Type node

At the top level, there is an Application Type node that represents an application type, which in this case is HelloWorldApplicationType. When you write your application code in Visual Studio, you define an application type. When the application is deployed, you get an application instance on the cluster. This relationship is similar to the relationship between a class and an object in Object Oriented Programming (OOP).

Application Instance node

Below the Application Type node is the Application Instance node, which is identified by the application’s name (fabric:/HelloWorldApplication in this case). By default, an application is named after the corresponding application type name. But you can change to any other name in the format of fabric:/<string>; for example, fabric:/MyApplication.

Service Type node

Under the Application Instance node, you have Service Type nodes. Each node represents a registered service type, such as the HelloServiceType in this example. Each service in a Service Fabric application is named as fabric:<application name>/<service name>. This name also is the address of the service. Service Fabric built-in naming service resolves this name to the actual service instance address at run time.

Partition node

A partition is identified by a GUID, suggesting it’s not something that a client would use to address a partition directly. Instead, the Service Fabric naming service will figure out the correct partition to which a service request should be sent.

Replica node

Figure 1-12 shows that by default, Service Fabric maintains multiple replicas for a partition for high availability. In this case, the Hello World service has a single partition with five replicas.

Visual Studio Cloud Explorer

Microsoft Azure SDK comes with a Visual Studio extension named Cloud Explorer, which you can access by the View\Cloud Explorer menu. Cloud Explorer is similar to Server Explorer in terms of Service Fabric cluster management functionalities, as shown in Figure 1-13.

FIGURE 1-13

FIGURE 1-13 Cloud Explorer

Service Fabric Explorer

Neither Server Explorer nor Cloud Explorer is designed as a full-fledged management tool. They are designed for you to navigate and view your cloud resources and server resources easily and with limited management functionality.

Service Fabric SDK provides a powerful tool named Service Fabric Explorer. To bring up the management UI, you can use any browser and navigate to http://localhost:19080/Explorer.

The left panel of the Service Fabric Explorer looks much like Server Explorer or Cloud Explorer. However, the tool also has a details panel to the right providing very detailed information on the currently selected item, as shown in Figure 1-14.

FIGURE 1-14

FIGURE 1-14 Local Cluster Manager

The management tool is loaded with features. You’ll use this tool frequently throughout this book for different scenarios. For now, perform a little exercise to familiarize yourself with the tool. In this exercise, you’ll delete the Hello World application from the cluster.

  1. In the Service Fabric Explorer, select the fabric:/HelloWorldApplicationnode in the left pane. Then, in the right pane, click the Actions button and then click the Delete Application menu, as shown in Figure 1-15.

    FIGURE 1-15

    FIGURE 1-15 Deleting a new application instance

  2. In the Confirm Application Deletion dialog box, shown in Figure 1-16, click the Delete Application button to continue.

    FIGURE 1-16

    FIGURE 1-16 Confirm Application Deletion dialog box

  3. The UI refreshes itself every few seconds. Once the UI is refreshed, you can see the application instance has been removed, as shown in Figure 1-17.

FIGURE 1-17

FIGURE 1-17 Two application instances

Windows PowerShell

Windows PowerShell is a powerful automation and configuration management framework. Service Fabric SDK installs a number of PowerShell cmdlets for you to manage your applications and clusters using command lines or automation scripts.

If you look under the Scripts folder of the HelloWorldApplication, you can find a Deploy-FabricApplication.ps1, which in turn calls a number of prebuilt scripts under your Service Fabric SDK folder (C:\Program Files\Microsoft SDKs\Service Fabric\Tools\Scripts by default) to deploy, upgrade, and remove your applications.

To get started, open a new Windows PowerShell window and use the Connect-ServiceFabricCluster cmdlet to connect to the local cluster, as shown in Figure 1-18.

FIGURE 1-18

FIGURE 1-18 Connect-ServiceFabricCluster cmdlet

Next, try a few commands. You’ll be introduced to more cmdlets as you go through the chapters.

  • List application instances.

    To list application instances on the cluster, type the following cmdlet:

    Get-ServiceFabricApplication

    The above cmdlet generates the following output on my environment (before the application instance is removed. To restore the instance, press F5 in Visual Studio to redeploy application):

    ApplicationName        : fabric:/HelloWorldApplication
    ApplicationTypeName    : HelloWorldApplicationType
    ApplicationTypeVersion : 1.0.0.0

             ApplicationStatus      : Ready
             HealthState             : Ok
             ApplicationParameters  : { "HelloWorldService_InstanceCount" = "-1" }
  • List cluster node names and statuses.

    To list all the nodes and their current statuses, use the following cmdlet:

    Get-ServiceFabricNode | Format-Table NodeName, NodeStatus

    A healthy cluster would look like this:

    NodeName NodeStatus
    -------- ----------
    Node.1           Up
    Node.2           Up
    Node.3           Up
    Node.4           Up
    Node.5           Up