本文介绍了Azure Service Fabric资源管理器中的Java Webapp部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个无状态Java应用程序,我希望将其部署在Azure结构中.我已经按照文档安装了Fabric SDK和Visual Studio工具.

此后,我创建了Service Fabric应用程序"Guest Executable"模板,并且我的项目结构如下:

我已按照与 https://azure.microsoft.com/zh-cn/documentation/articles/service-fabric-deploy-existing-app/

我的ServiceManifest.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Guest1Pkg"
                 Version="1.0.0"
                 xmlns="http://schemas.microsoft.com/2011/01/fabric"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ServiceTypes>
    <StatelessServiceType ServiceTypeName="Guest1Type" UseImplicitHost="true" />
  </ServiceTypes>
  <CodePackage Name="Code" Version="1.0.0">
    <EntryPoint>
      <ExeHost>
        <Program>HelloWorld.war</Program>
        <Arguments></Arguments>
        <WorkingFolder>CodePackage</WorkingFolder>
      </ExeHost>
    </EntryPoint>
  </CodePackage>
  <ConfigPackage Name="Config" Version="1.0.0" />
  <Resources>
    <Endpoints>
      <Endpoint Name="JavaAppTypeEndpoint" Protocol="http" Port="8080" Type="Input" />
    </Endpoints>
  </Resources>
</ServiceManifest>

我的ApplicationManifest.xml代码段如下:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="Application1Type"
                     ApplicationTypeVersion="1.0.0"
                     xmlns="http://schemas.microsoft.com/2011/01/fabric"
                     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Parameters>
    <Parameter Name="Guest1_InstanceCount" DefaultValue="-1" />
  </Parameters>
  <ServiceManifestImport>
    <ServiceManifestRef ServiceManifestName="Guest1Pkg" ServiceManifestVersion="1.0.0" />
    <ConfigOverrides />
  </ServiceManifestImport>
  <DefaultServices>
    <Service Name="Guest1">
      <StatelessService ServiceTypeName="Guest1Type" InstanceCount="[Guest1_InstanceCount]">
        <SingletonPartition />
      </StatelessService>
    </Service>
  </DefaultServices>
</ApplicationManifest>

我在本地部署到Service Fabric Explorer,并且构建和发布步骤很好,没有任何错误:

-------- Package: Project: Application1 succeeded, Time elapsed: 00:00:00.3530634 --------
2>Started executing script 'Deploy-FabricApplication.ps1'.
2>. 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -PublishProfileFile 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\Local.5Node.xml' -DeployOnly:$true -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'Always' -SkipPackageValidation:$true -ErrorAction Stop
2>Copying application to image store...
2>Copy application package succeeded
2>Registering application type...
2>Register application type succeeded
2>Removing application package from image store...
2>Remove application package succeeded
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:01.9327912
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

Started executing script 'Publish-NewServiceFabricApplication'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Publish-NewServiceFabricApplication -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -ApplicationParameterFilePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\..\ApplicationParameters\Local.5Node.xml' -ApplicationParameter @{_WFDebugParams_='[]'} -Action Create -SkipPackageValidation:$true -ErrorAction Stop
Creating application...


ApplicationName        : fabric:/Application1
ApplicationTypeName    : Application1Type
ApplicationTypeVersion : 1.0.0
ApplicationParameters  : { "_WFDebugParams_" = "[]" }

Create application succeeded.


Finished executing script 'Publish-NewServiceFabricApplication'.
Time elapsed: 00:00:01.8691591
Started executing script 'Get-ServiceFabricApplicationStatus'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Get-ServiceFabricApplicationStatus -ApplicationName 'fabric:/Application1' -ErrorAction Stop
The application has started.
Service Status:
fabric:/Application1/Guest1 is ready.

The application is ready.
Finished executing script 'Get-ServiceFabricApplicationStatus'.
Time elapsed: 00:00:01.0230548

但是应用程序运行状况显示错误,并且事件为

"Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation."

我不知道部署中这里可能出现什么问题,除了上面提到的以外,是否还需要在Application Service入口点中包含任何内容.

此外,Java Web应用程序在独立的tomcat上部署时具有以下上下文 http://localhost:8080/HelloWorld/hello .如果将应用程序部署在Service Fabric群集中,则URL上下文将保持不变还是类似于 http://localhost:8080/Application1/Guest1/HelloWorld/hello 是否由于周围是Azure织物包装器?

最后,事实证明,我们需要在主机虚拟机(Azure VM或本地桌面)中单独安装Java,然后必须引用Java路径.

所以我的服务清单是

<EntryPoint>
      <ExeHost>
        <Program>scripts\launchConfig.cmd</Program>
        <Arguments></Arguments>
        <WorkingFolder>CodePackage</WorkingFolder>
        <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
      </ExeHost>
</EntryPoint>

我已经在Code文件夹下创建了一个名为scripts的文件夹,脚本文件"launchConfig.cmd"只有一行,如下所示:

"C:\Program Files (x86)\Java\jre1.8.0_101\bin\java.exe" -jar HelloWorld.war

我们可能需要删除路径硬编码,但这是它最终引用的方式.

We have a stateless Java Application which I want to be deployed in Azure fabric. I have installed the Fabric SDK and Visual studio tools as per the documentation.

After that I have created the Service Fabric application "Guest Executable" template and my project structure is like below:

I have followed steps similar to the documentation as in https://azure.microsoft.com/en-us/documentation/articles/service-fabric-deploy-existing-app/

My ServiceManifest.xml is below:

<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="Guest1Pkg"
                 Version="1.0.0"
                 xmlns="http://schemas.microsoft.com/2011/01/fabric"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ServiceTypes>
    <StatelessServiceType ServiceTypeName="Guest1Type" UseImplicitHost="true" />
  </ServiceTypes>
  <CodePackage Name="Code" Version="1.0.0">
    <EntryPoint>
      <ExeHost>
        <Program>HelloWorld.war</Program>
        <Arguments></Arguments>
        <WorkingFolder>CodePackage</WorkingFolder>
      </ExeHost>
    </EntryPoint>
  </CodePackage>
  <ConfigPackage Name="Config" Version="1.0.0" />
  <Resources>
    <Endpoints>
      <Endpoint Name="JavaAppTypeEndpoint" Protocol="http" Port="8080" Type="Input" />
    </Endpoints>
  </Resources>
</ServiceManifest>

My ApplicationManifest.xml snippet is below:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="Application1Type"
                     ApplicationTypeVersion="1.0.0"
                     xmlns="http://schemas.microsoft.com/2011/01/fabric"
                     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Parameters>
    <Parameter Name="Guest1_InstanceCount" DefaultValue="-1" />
  </Parameters>
  <ServiceManifestImport>
    <ServiceManifestRef ServiceManifestName="Guest1Pkg" ServiceManifestVersion="1.0.0" />
    <ConfigOverrides />
  </ServiceManifestImport>
  <DefaultServices>
    <Service Name="Guest1">
      <StatelessService ServiceTypeName="Guest1Type" InstanceCount="[Guest1_InstanceCount]">
        <SingletonPartition />
      </StatelessService>
    </Service>
  </DefaultServices>
</ApplicationManifest>

I deployed to Service Fabric Explorer in my local, and the build and publish steps are good without any errors:

-------- Package: Project: Application1 succeeded, Time elapsed: 00:00:00.3530634 --------
2>Started executing script 'Deploy-FabricApplication.ps1'.
2>. 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\Scripts\Deploy-FabricApplication.ps1' -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -PublishProfileFile 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\Local.5Node.xml' -DeployOnly:$true -UnregisterUnusedApplicationVersionsAfterUpgrade $false -OverrideUpgradeBehavior 'None' -OverwriteBehavior 'Always' -SkipPackageValidation:$true -ErrorAction Stop
2>Copying application to image store...
2>Copy application package succeeded
2>Registering application type...
2>Register application type succeeded
2>Removing application package from image store...
2>Remove application package succeeded
2>Finished executing script 'Deploy-FabricApplication.ps1'.
2>Time elapsed: 00:00:01.9327912
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

Started executing script 'Publish-NewServiceFabricApplication'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Publish-NewServiceFabricApplication -ApplicationPackagePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\pkg\Debug' -ApplicationParameterFilePath 'C:\Users\samanoha\Documents\Visual Studio 2015\Projects\Application1\Application1\PublishProfiles\..\ApplicationParameters\Local.5Node.xml' -ApplicationParameter @{_WFDebugParams_='[]'} -Action Create -SkipPackageValidation:$true -ErrorAction Stop
Creating application...


ApplicationName        : fabric:/Application1
ApplicationTypeName    : Application1Type
ApplicationTypeVersion : 1.0.0
ApplicationParameters  : { "_WFDebugParams_" = "[]" }

Create application succeeded.


Finished executing script 'Publish-NewServiceFabricApplication'.
Time elapsed: 00:00:01.8691591
Started executing script 'Get-ServiceFabricApplicationStatus'.
[void](Connect-ServiceFabricCluster); Import-Module 'C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\ServiceFabricSDK.psm1'; Get-ServiceFabricApplicationStatus -ApplicationName 'fabric:/Application1' -ErrorAction Stop
The application has started.
Service Status:
fabric:/Application1/Guest1 is ready.

The application is ready.
Finished executing script 'Get-ServiceFabricApplicationStatus'.
Time elapsed: 00:00:01.0230548

But the application health state shows error and the event is

"Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation."

I don't have any idea what might be the issue here in deployment, whether anything needs to be included in Application service Entry point in addition to mentioned above.

Also, The Java webapplication when deployed on Standalone tomcat has the following context http://localhost:8080/HelloWorld/hello . If the Application is deployed in Service fabric cluster, will the URL context for this remains same or should it be something like http://localhost:8080/Application1/Guest1/HelloWorld/hello due to the Azure fabric wrapper around it?

解决方案

Finally it turned out that we need to separately install Java in the Host virtual machine (Azure VM or local Desktop) and then we have to reference the java path.

So my service manifest is

<EntryPoint>
      <ExeHost>
        <Program>scripts\launchConfig.cmd</Program>
        <Arguments></Arguments>
        <WorkingFolder>CodePackage</WorkingFolder>
        <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
      </ExeHost>
</EntryPoint>

I have created a folder called scripts under Code folder and the script file "launchConfig.cmd" has just single line as below:

"C:\Program Files (x86)\Java\jre1.8.0_101\bin\java.exe" -jar HelloWorld.war

We might need to remove the path hardcodings, but this is how it referred finally.

这篇关于Azure Service Fabric资源管理器中的Java Webapp部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:51