The System Center Platform in Service Manager Part 4: The Management Service – Try It!

This post is a continuation in the series which describes the System Center common platform components implemented in Service Manager.  Previous posts:

The System Center Platform in Service Manager Part 1: Introduction

The System Center Platform in Service Manager Part 2: The Model-Based Database

The System Center Platform in Service Manager Part 2: The Model-Based Database - Try It!

The System Center Platform in Service Manager Part 3: The Data Access Service

The System Center Platform in Service Manager Part 3: The Data Access Service - Try It!

The System Center Platform in Service Manager Part 4: The Management Service

In the previous post, we learned about how the Management Service is the worker in Service Manager.  In this post, I’ll show you how to create a simple workflow in a management pack.  After importing the management pack the Management Service will pick up the workflow and run it automatically.

NOTE:  This Management Pack has only been tested on Beta 2 builds of Service Manager and I’m pretty sure it won’t work on Beta 1; maybe on CTP2.  Beta 2 is not publicly released yet.  If this doesn’t work for you on Beta 1 or CTP2 (TAP release only), please try again when Beta 2 comes out.

The goal of this very simple management pack is to create a workflow that will attempt to create a folder on the file system every 10 seconds using the System.SimpleScheduler and System.CommandExecuter modules.

First of all, as with any management pack we need to complete the Manifest section.  In this case, we’ll take a dependency on the System.Library and Microsoft.SystemCenter.Library MPs which contain the two module definitions we want to use for our workflow.

<ManagementPack ContentReadable="true" SchemaVersion="1.1"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <Manifest>

    <Identity>

      <ID>Woodgrove.Workflow.HelloManagementService</ID>

      <Version>1.0.0.0</Version>

    </Identity>

    <Name>Woodgrove Workflow Hello Management Service</Name>

    <References>

      <Reference Alias="System">

        <ID>System.Library</ID>

        <Version>1.0.3113.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="SCLibrary">

        <ID>Microsoft.SystemCenter.Library</ID>

        <Version>1.0.3113.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

    </References>

  </Manifest>

 

Next, we need to define a new class as our workflow target.  More information on workflow targeting

 

  <TypeDefinitions>

    <EntityTypes>

      <ClassTypes>

        <ClassType ID="Woodgrove.WorkflowTarget" Base="SCLibrary!Microsoft.SystemCenter.WorkflowTarget" Singleton="true" Hosted="false" Abstract="false" Accessibility="Internal"/>

      </ClassTypes>

    </EntityTypes>

  </TypeDefinitions>

Next, we’ll create the a Rule workflow in the Monitoring section of the management pack.  All Rules in Service Manager should target the Microsoft.SystemCenter.WorkflowTarget class or a class derived from that class.  This class is located in the Microsoft.SystemCenter.Library management pack.  If you don’t target this class you’ll workflow will be prevented from running.  All workflows targeted at this class will run on whichever Management Server in the Service Manager Management group is the currently designated workflow server.

 

 

  <Monitoring>

    <Rules>

      <Rule ID="Woodgrove.Workflow.HellowManagementService.Rule" Enabled="true" Target="Woodgrove.WorkflowTarget">

        <Category>System</Category>

 

Inside the Rule, we’ll first declare the SimpleScheduler DataSource module and configure it to run every 10 seconds.

 

        <DataSources>

          <DataSource ID="Schedule" TypeID="System!System.SimpleScheduler">

            <IntervalSeconds>10</IntervalSeconds>

            <SyncTime/>

          </DataSource>

        </DataSources>

 

Next, we’ll configure the CommandExecuter module to run a mkdir (make directory) command on the file system to create a folder in the root of the C: drive.

 

        <WriteActions>

          <WriteAction ID="RunCommand" TypeID="System!System.CommandExecuter">

            <ApplicationName />

            <WorkingDirectory />

            <CommandLine>mkdir C:\A_Service_Manager_Workflow_Made_This_Folder</CommandLine>

            <TimeoutSeconds>120</TimeoutSeconds>

            <RequireOutput>true</RequireOutput>

            <Files />

          </WriteAction>

        </WriteActions>

      </Rule>

    </Rules>

  </Monitoring>

</ManagementPack>

 

Here is the complete management pack:

<ManagementPack ContentReadable="true" SchemaVersion="1.1"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <Manifest>

    <Identity>

      <ID>Woodgrove.Workflow.HelloManagementService</ID>

      <Version>1.0.0.0</Version>

    </Identity>

    <Name>Woodgrove Workflow Hello Management Service</Name>

    <References>

      <Reference Alias="System">

        <ID>System.Library</ID>

        <Version>1.0.3113.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="SCLibrary">

        <ID>Microsoft.SystemCenter.Library</ID>

        <Version>1.0.3113.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

    </References>

  </Manifest>

  <TypeDefinitions>

    <EntityTypes>

      <ClassTypes>

        <ClassType ID="Woodgrove.WorkflowTarget" Base="SCLibrary!Microsoft.SystemCenter.WorkflowTarget" Singleton="true" Hosted="false" Abstract="false" Accessibility="Internal"/>

      </ClassTypes>

    </EntityTypes>

  </TypeDefinitions>

  <Monitoring>

    <Rules>

      <Rule ID="Woodgrove.Workflow.HellowManagementService.Rule" Enabled="true" Target="Woodgrove.WorkflowTarget">

        <Category>System</Category>

        <DataSources>

          <DataSource ID="Schedule" TypeID="System!System.SimpleScheduler">

            <IntervalSeconds>10</IntervalSeconds>

            <SyncTime/>

          </DataSource>

        </DataSources>

        <WriteActions>

          <WriteAction ID="RunCommand" TypeID="System!System.CommandExecuter">

            <ApplicationName />

            <WorkingDirectory />

            <CommandLine>mkdir C:\A_Service_Manager_Workflow_Made_This_Folder</CommandLine>

            <TimeoutSeconds>120</TimeoutSeconds>

            <RequireOutput>true</RequireOutput>

            <Files />

          </WriteAction>

        </WriteActions>

      </Rule>

    </Rules>

  </Monitoring>

</ManagementPack>

 

If you import this management pack into Service Manager and wait a few seconds you will see a new directory created in the C:\ root directory on your management server!  Using this very basic pattern you can create all kinds of different scheduled jobs that run on the Service Manager platform.  We'll get into more details of authoring workflows and we'll introduce you to the workflow authoring tool we are providing at Beta 2 a little later.

Next up, we’ll take a look at the Management Service’s boss – the Management Configuration Service.