nonepassby

导航

MSPL服务器应用程序部署补充(应用程序重要性)

上一篇《MSPL服务器应用程序部署的图解说明》讲了如何部署MSPL服务器应用程序。这次讲一下应用程序执行的顺序,应用程序的执行顺序通过应用程序重要性参数(Priority)来体现,MSPL应用的重要性是从0开始的数字,值小的先执行。

 

设置应用程序重要性可以在安装时设定,也可以安装后修改。当设置一个应用程序的重要性时,原来该重要性的应用程序及后续应用的重要性自动+1,如果不设置重要性参数,则重要性默认为当前最大值+1.

 

例如我们在上一讲中如果在安装应用程序FilteringApp要设置其重要性为5,PowerShell命令如下:

 

New-CsServerApplication -Identity "registrar:lyncserver.corp.itime.biz/FilteringApp" -Uri http://www.microsoft.com/LCS/Samples/Filtering -Critical $False -Enabled $True -ScriptName "C:\lync\FilteringApp\Filter.am" -Priority 5

则命令执行的结果为:原来的重要性>=5的应用程序的重要性会递增1,FilteringApp重要性为5.

如果我们要修改已经安装的应用程序FilteringApp重要性为6,则执行以下PowerShell命令:

 

Set-CsServerApplication -Identity "registrar:lyncserver.corp.itime.biz/FilteringApp" -Priority 6

 

在弄清楚重要性之后,MSPL程序实际上就是SIP Message的Filter, 重要性数值小的应用程序先接收并处理SIP消息,并决定是否继续传递消息。这样,后续应用程序接到的SIP Message可能已经是改变后的SIP Message,或者某些SIP消息被“过滤”而接收不到,因此,我们在确定应用程序时要慎重。

另外Lync自带有一个叫做UserService应用程序,凡是重要性大于它的应用程序,必须在am文件中指定元素allowRegistrationBeforeUserServices。

假设UserService应用程序的重要性为4,假设我们想设置FilteringApp应用程序的重要性为4,则应在Filter.am文件中增加allowRegistrationBeforeUserServices节点,文件内容如下:

 

View Code
<?xml version="1.0"?>
<r:applicationManifest
 
r:appUri="http://www.microsoft.com/LC/SDK/Samples/Filter"
 xmlns:r
="http://schemas.microsoft.com/lcs/2006/05">
<r:allowRegistrationBeforeUserServices/>
<!-- 
  - Handle all IMs
  
-->
<r:requestFilter methodNames="ALL"
                 strictRoute
="true"
                 registrarGenerated
="false"
                 domainSupported
="false"/>

<!-- 
  - Ignore all responses.
  
-->
<r:responseFilter reasonCodes="NONE"/>

<!--
  - Don't proxy by default.
  
-->
<r:proxyByDefault action="false" />

<!-- 
  - Script-only application.
  
-->
<r:scriptOnly/>

<!--
  -
  - policy.txt:
  - 
  - The IM policy database file.  Contains three whitespace-delimited
  - columns, formatted as follows:
  -
  -       user@domain     policy   value
  - 
  -  where user@domain is the user's full request-uri, and policy is one
  -  of the following:
  - 
  -       allow: deliver all IMs sent to this user.
  -       filter: deliver all IMs to this user, provided the word in
  -           the value column is not in the message body.
  -       drop: reject all IMs sent to this user.
  -
  
-->
<r:file name="policyTable" path="policy.txt" delimitedBy="whitespace" keyColumnName="uri">
   <!-- Policy applies to this URI. -->
   <r:column name="uri" />

   <!-- The policy verb describing action to be taken (see above description) -->
   <r:column name="policy" />

   <!-- The filter string applied to messages (for "filter" policy) -->
   <r:column name="value" />
</r:file>

<r:splScript><![CDATA[

/*++

Copyright (C) 2004 Microsoft Corporation.

Script:

    Filter.am.

Abstract:

    This sample demonstrates a simple user-based IM filtering policy.  The
    policy data is read from a structured flat file;  see above for a 
    description of this file's contents.  Note that the file is reread if
    modified; alternatively, a static="true" attribute in the <file> tag
    changes this behavior.

    Features demonstrated:

    - Flat file access

--*/

thisScript = "Filter.am :: ";

/*
 * Banner
 */
Log("Debug", false, "");
Log("Debug", false, "Entering Filter.am");

Log("Debug", false, "New ", sipRequest.Method, " request for ", GetUserAtHost(sipRequest.To));

/*
 * Get user@domain string for the user in the To: header.
 */
userUri = GetUri(sipRequest.To);
userAtHost = GetUserAtHost(userUri);

/*
 * Look up the policy for this user.
 */
policy = policyTable[userAtHost].policy;

/*
 * Act on the policy verb.
 */
switch (policy)
{
    case "allow":
        /*
         * Proxy this request.
         */
        ProxyRequest("");
        Log("Debug", false, thisScript, "[allow] Proxying ", sipRequest.Method);
        break;

    case "filter":
        /*
         * Proxy this request, if the content body doesn't contain the specified
         * forbidden text.
         */
        if (IndexOfString(sipRequest.Content, policyTable[userAtHost].value) == -1)
        {
            /*
             * Content body doesn't match filter string.  Proxy.
             */
            Log("Debug", false, thisScript, "[filter] Proxying " , sipRequest.Method);
            ProxyRequest("");
        }
        else
        {
            /*
             * Content matched filter string -- reject this request.
             */
            Log("Debug", false, thisScript, "[filter] Rejecting ", sipRequest.Method);
            Respond(403, "Forbidden (Message filtered)");
        }
        break;

    case "drop":
        /*
         * Drop all requests sent to this user.
         */
        Log("Debug", false, thisScript, "[drop] Rejecting ", sipRequest.Method);
        Respond(403, "Forbidden (Message filtered)");
        break;

    default:
        /*
         * Unknown policy verb -- by default, reject
         */
        Log("Debug", false, thisScript, "No policy verb for user ", userAtHost, " -- dropping ", sipRequest.Method);
        Respond(403, "Forbidden (Invalid policy verb)");
        break;
}

]]></r:splScript>
</r:applicationManifest>

 

然后执行如下PowerShell命令:

 

Set-CsServerApplication -Identity "registrar:lyncserver.corp.itime.biz/FilteringApp" -Priority 4

 

到此,我们了解了服务器应用程序的作业和如何设置服务器应用程序重要性。

 

posted on 2012-05-31 23:16  jack  阅读(332)  评论(1)    收藏  举报