Hot questions for Using Azure in deployment

Top Java Programmings / Azure / deployment

Question:

I'm trying to deploy a VM using the Azure Java SDK. I am able to retrieve listings from my Azure portal through Java.

When trying to deploy the VM it asks for a Deployment Name in the function:

computeManagementClient.getVirtualMachinesOperations().create(String, String, VirtualMachineCreateParameters);

The second string is supposed to be Deployment Name, where can I find what this should be in the Azure portal or how do I create the deployment name container?

I've tried several names I thought might be correct and get the exception:

    Exception in thread "main" java.util.concurrent.ExecutionException: com.microsoft.windowsazure.exception.ServiceException: ResourceNotFound: The deployment name 'thundertest' does not exist.
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at com.microsoft.windowsazure.management.compute.VirtualMachineOperationsImpl.create(VirtualMachineOperationsImpl.java:5359)
    at com.thunderhead.cloudlib.azure.RequestBuilder.createVirtualMachines(RequestBuilder.java:344)
    at com.thunderhead.cloudlib.azure.RequestBuilder.main(RequestBuilder.java:365)
Caused by: com.microsoft.windowsazure.exception.ServiceException: ResourceNotFound: The deployment name '<deploymentName?>' does not exist.
    at com.microsoft.windowsazure.exception.ServiceException.createFromXml(ServiceException.java:216)
    at com.microsoft.windowsazure.management.compute.VirtualMachineOperationsImpl.beginCreating(VirtualMachineOperationsImpl.java:1884)
    at com.microsoft.windowsazure.management.compute.VirtualMachineOperationsImpl$3.call(VirtualMachineOperationsImpl.java:1038)
    at com.microsoft.windowsazure.management.compute.VirtualMachineOperationsImpl$3.call(VirtualMachineOperationsImpl.java:1035)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Answer:

Calling computeManagementClient.getVirtualMachinesOperations().createDeployment() first should give you a deployment object who's name you can pass to computeManagementClient.getVirtualMachinesOperations().create.

Question:

I am trying to use the Azure Java SDK to automate tasks for my azure virtual machines such as starting and stopping them at various stages of the day

I was looking at the azure documentation for start virtual machine here

The method signature in question is as follows

OperationResponse beginStarting(java.lang.String serviceName,
                            java.lang.String deploymentName,
                            java.lang.String virtualMachineName)
                     throws java.io.IOException,
                            ServiceException

I was wondering - where can I get the values for serviceName and deploymentName on the azure console for my virtual machine?

I tried looking on the old portal and the new portal but to date I have been unable to find these values

This question looks like a duplicate to the question at the below url but it is not Azure find deployment name

Indeed when you look at the old portal (https://manage.windowsazure.com) - the above link gives the correct answer for getting a deployment name

However, if you create a VirtualMachine in the old portal and view it in the new portal (https://portal.azure.com) - it shows under the Virtual Machine Classic option. With the help of the above link I was able to perform operations on the classic virtual machines using the Java SDK

If I create a Virtual Machine in the new portal under the Virtual Machine option (not Virtual Machine (classic)) I am unable to find the deploymentName or serviceName

So to update the question - how does one find the deploymentName and serviceName for a Virtual machine in the new portal

Also - one other thing I noticed with the SDK - If you have the wrong serviceName entered - it logs that the deployment name is wrong - that got me for a while on the classic virtual machines

Just to close out this question To be able to perform operations on non classic virtual machines - use this maven dependency

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-mgmt-compute</artifactId>
    <version>0.9.0</version>
</dependency>

For operations on non classic virtual machines - you need to use Active Directory Security - see this link - https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/ To perform operations on classic virtual machines - use this maven dependency

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-svc-mgmt-compute</artifactId>
    <version>0.9.0</version>
</dependency>

For operations on classic virtual machines - you need to use certs


Answer:

I haven't worked with Java SDK (so I may be totally off base here) but I don't think you can use this library to perform operations on a non-classic Virtual Machines. These VMs are deployed through Azure Resource Manager and they have entirely different mechanism to manage resources.

Looking at the source code here: https://github.com/azure/azure-sdk-for-java, I believe this is where you will find the methods to manage Virtual Machines: https://github.com/Azure/azure-sdk-for-java/tree/master/resource-management/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute.

For your specific query, please see the documentation here: http://azure.github.io/azure-sdk-for-java/com/microsoft/azure/management/compute/VirtualMachineOperations.html#beginStarting-java.lang.String-java.lang.String- (This is the place where you will find entire documentation - http://azure.github.io/azure-sdk-for-java/).

Question:

I create a Web App in Azure and upload my war file via FTP into webapps/my.war. It is unpacked and deployed successfully. Next time I upload a new version of my.war, overwriting the existing file, it's like 50/50 that it will be unpacked and deployed. When it fails for the first time, I find no way to get it back other than deleting the webapp and create a new one.

I have tried all ways I can think off with combinations of stopping the webapp before uploading or not, removing the files webapps/my and webapps/my.war or not etc.

Why is this and how can I fix it? I mean, the PAAS should just work out of the box, so I must be doing some basic things wrong.

I forgot to mention I am using latest version of Tomcat 8.0.


Answer:

It's a feature of Tomcat, not a mistake for Tomcat on Azure, so it's not necessary to fix anything. According to the Tomcat offical document for Deploying on a running Tomcat server, there is an explaination for this case as below.

On Windows, the anti-locking features are enabled. Please refer to the document for Context Configuration to know the effectsof antiResourceLocking=true in the conf/context.xml of Tomcat 8.0.

You need to restart your webapp to make Tomcat delete the old version for updating, or manuall delete them on Tomcat shutdown.

Question:

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?


Answer:

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.

Question:

I am new to service fabric and trying to deploy java application to local service fabric cluster with 5 nodes. i am using Ubuntu VM and following below steps to build and deploy it in asf cluster. while deploying i am getting below error. i tried to deploy in asf remote cluster also and got the same issue. Can you please help me on this.

Link :Jav Application deploymen to ASF cluster

Error code:


Answer:

Just tried this out and it worked for me so just going to ask some questions to make sure we didn't miss anything from the documents.

Under DhrumilSpringServiceFabric->DhrumilSpringGettingStartedPkg -> code, do you have two files?

  1. gs-spring-boot-0.1.0.jar
  2. entryPoint.sh

The entryPoint.sh file should have the following contents:

#!/bin/bash BASEDIR=$(dirname $0) cd $BASEDIR java -jar gs-spring-boot-0.1.0.jar

Additionally, in the ServiceManifest.xml (located in DhrumilSpringServiceFabric->DhrumilSpringGettingStartedPkg), there should be the following snippet:

   <CodePackage Name="code" Version="1.0.0">
  <EntryPoint>
     <ExeHost>
        <Program>entryPoint.sh</Program>
        <Arguments></Arguments>
        <WorkingFolder>CodePackage</WorkingFolder>
     </ExeHost>
  </EntryPoint>

The Program property value "entryPoint.sh" has to be identical including casing with what's in your "code" folder.

If the above all check out, then please respond and happy to dive deeper into this.

Question:

I have an azure server that runs my Tomcat web apps. Everything works well but I find that exporting my war, undeploying, then redeploying the war to Tomcat is a hassle. On my dev environment I run Tomcat within eclipse and have my latest code to run. What would be the problem with running eclipse on my azure server, having Tomcat run within eclipse to run my web apps? This way with any change I can simply git pull my latest code into eclipse and restart tomcat. Is this a bad idea in production and why? If so any recommendations on how to make this easier? I would rather not expose the tomcat manager application to the world so please don't recommend that.


Answer:

Per my experience, the easy way to continuous deployment for Tomcat web apps in Eclipse is using local Git repository.

First, Create a Dynamic Web Project with Tomcat in Eclipse. There is a key step for creating project different from normal step. When configuring web module settings, need to set webapps/ROOT for Content directory, see below:

Then, the project structure tree as below:

Second, Configure the continuous deployment for Azure WebApp on Azure Portal.

After done above, copy the git clone url for git cmd.

Until now, open the git bash to push project into Azure. The steps as below.

  1. Open the git bash cmd and cd into project directory <app-name>.
  2. git init
  3. git add webapps
  4. git commit -m "Initial Commit"
  5. git remote add <app-name> <git-clone-url>
  6. git push <app-name> master

Now, you can browse https://<app-name>.azurewebsites.net/ to see it.

For continous developement, you just need to repeat the step 3, 4 and 6.

Question:

I have followed step by step instruction for this document. And it works perfectly fine.

However, I tried changing the return from "Greetings from Spring Boot!" to "Greetings from Spring Boot! v2.0" and made necessary changes (on tests). And then ran mvn clean package to remove any existing jar and create a new one and finally ran ./mvnw azure-webapp:deploy it does update the existing web service. And also states "BUILD Success"

Not sure where am i going wrong.


Answer:

Just as hujtomi said in the comment, every time the maven deploy task will create different web app. Could you please have a check with that?

Question:

I am trying to deploy my java web application to Azure using FTP. Is the .war file enough to be uploaded? Or all the project files have to be uploaded?


Answer:

I believe that .war file is enough, because in that file you have everything that your java web application need, like the java classes, servlets, static web pages, etc, as you can see in this example, opening the war file: war file

In fact, when we use, for example, the Tomcat server, that's the only thing that the server use for running the web application.

I hope I have helped you!