3

We are trying to create a Virtual Machine through an HTTPClient in Java using the REST API exposed by Azure. We are using the following Request URL and XMLs, but we are getting "Bad request" response.

https://management.core.windows.net/{subscription-id}/services/hostedservices/{existing hoster service name}/deployments

<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Name>TestVMAnandP</Name>
  <Label>bXl2bQ==</Label>
  <RoleList>
    <Role>
      <RoleName>TestVMAnandP</RoleName>
      <RoleType>PersistentVMRole</RoleType>
      <ConfigurationSets>
        <ConfigurationSet>
          <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
          <HostName>TestVMAnandP</HostName>
          <UserName>root</UserName>
          <UserPassword>test</UserPassword>
        </ConfigurationSet>
      </ConfigurationSets>
      <DataVirtualHardDisks>
        <DataVirtualHardDisk>
          <Lun>10</Lun>
          <LogicalDiskSizeInGB>50</LogicalDiskSizeInGB>
        </DataVirtualHardDisk>
      </DataVirtualHardDisks>
      <OSVirtualHardDisk>
        <SourceImageName>srini2-srini2-2012-08-23.vhd</SourceImageName>
        <MediaLink>http://sriniteststore.blob.core.windows.net/vhds/srini2-srini2-2012-08-23.vhd</MediaLink>
      </OSVirtualHardDisk>
      <RoleSize>ExtraSmall</RoleSize>
    </Role>
  </RoleList>
  <VirtualNetworkName>MyNetwork</VirtualNetworkName>
</Deployment>

If we try to give a service name same as the vm name in the URL, we are getting 404 Error. We have tried most of the samples given in the web with values replaced, but everything gives us a 400 Error. It would be great if we get some help.

Errors :

Two different kind of errors i am getting :


Error 1 : When i use new <service-name> inside the below URL .management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/                          -------------------------------------------------------------------   Response message--->Not Found---404
java.io.FileNotFoundException: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/anand/deployments
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
Caused by: java.io.FileNotFoundException: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/anand/deployments
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

Error 2 : when i use an existing available <service-name> in the below URL  management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/                                                   
Response message--->Bad Request---400
java.io.IOException: Server returned HTTP response code: 400 for URL: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/azurecogservice/deployments
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: management.core.windows.net/84cc18f5-5bdd-4c95-9d69-862c12c53507/services/hostedservices/azurecogservice/deployments
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

---------------------VALID XML-------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsazure">
    <Name>190bed4a</Name>
    <DeploymentSlot>Production</DeploymentSlot>
    <Label>190bed4a</Label>
    <RoleList>
        <Role>
            <RoleName>SuseOpenVm_rolec8fc</RoleName>
            <RoleType>PersistentVMRole</RoleType>
            <ConfigurationSets>
                <ConfigurationSet>
                    <ConfigurationSetType>LinuxProvisioningConfiguration
                    </ConfigurationSetType>
                    <HostName>SuseOpenVm_rolec8fc</HostName>
                    <UserName>anandsrinivasan</UserName>
                    <UserPassword>Cloud360</UserPassword>
                    <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
                </ConfigurationSet>
                <ConfigurationSet>
                    <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
                    <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
                    <InputEndpoints>
                        <InputEndpoint>
                            <LocalPort>22</LocalPort>
                            <Name>SSH</Name>
                            <Port>22</Port>
                            <Protocol>TCP</Protocol>
                        </InputEndpoint>
                    </InputEndpoints>
                </ConfigurationSet>
            </ConfigurationSets>
            <OSVirtualHardDisk>
                <MediaLink>https://portalvhdsvf842yxvkhbg4.blob.core.windows.net/vhds/190bed4a.vhd</MediaLink>
                <SourceImageName>SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd</SourceImageName>
            </OSVirtualHardDisk>
            <RoleSize>Small</RoleSize>
        </Role>
    </RoleList>
    <VirtualNetworkName>anand360NW</VirtualNetworkName>
</Deployment>

5 Answers 5

2

Whenever I'm having issues with the REST API I first try to complete what I'm trying to do through the portal. In your case I tried creating a Linux VM (TestVMAnandP) with username root and password test. I immediately noticed the following errors:

  • User Name 'root' is not allowed
  • Password should be at least 8 characters
  • Password should contain 3 of the following:
    • a lowercase character
    • a uppercase character
    • a number
    • a special character
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your inputs .. i tried with valid user name and password ..Still getting the same error.
1

I have been working on the same thing a while back.

i suggest you check out my implementation of a java REST client that consumes this API at the Cloudify GitHub repo:

https://github.com/CloudifySource/cloudify/blob/master/esc/src/main/java/org/cloudifysource/esc/driver/provisioning/azure/client/MicrosoftAzureRestClient.java

another good reference is the node.js sdk provided my Microsoft. you can browse the code and see where you went wrong :

https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/services/serviceManagement/servicemanagementservice.js

hope it helps

3 Comments

Eli , With the help of above mentioned client program , i was able to identify the issue inside my XML. Thanks a lot for your valuable help.
Glad it helped. Maybe you can also share exactly what was wrong? I'm guessing it might benefit some other people facing these issues.
Eli , I have updated my correct xml above in my question part.
0

Error code 400/4xx would mean that there is something wrong with the request. And error code 404 specifically says that "The server has not found anything matching the URI given". So can you verify if the information provided in OSVertualHardDisck is correct.

<OSVirtualHardDisk>
        <SourceImageName>srini2-srini2-2012-08-23.vhd</SourceImageName>
        <MediaLink>http://sriniteststore.blob.core.windows.net/vhds/srini2-srini2-2012-08-23.vhd</MediaLink>
      </OSVirtualHardDisk>

Update

Is the the service you are trying to use http://msdn.microsoft.com/en-us/library/windowsazure/jj157194.aspx

You can see the error code explanations here http://msdn.microsoft.com/en-us/library/windowsazure/ee460801.aspx

It might just be possible that the target url that you are using is not valid or expected by server.

8 Comments

Hi ,Verified with the media links.Still i am getting the same error. I even tried with other available media links and default OS Virual disks option also.
Can you post complete error message that you are getting from the service?
Hi Jayanthi, I am getting two different errors. Error 1 : When i use new <service-name> inside the below URL .management.core.windows.net/<subscription-id>/services/…
I think your comment just got truncated. Can you post your comment as an update to your question, that way every body can easily see it.
Error 1 : When i use new <service-name> inside the below URL .management.core.windows.net/<subscription-id>/services/… ------------------------------------------------------------------- Response message--->Not Found---404 java.io.FileNotFoundException: management.core.windows.net/… at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
|
0

Service Management API documentation is seriously messed up. I wouldn't be surprised if you're victim of that. One thing you can try is changing the

<LogicalDiskSizeInGB>50</LogicalDiskSizeInGB>

element to

<LogicalSizeInGB>50</LogicalSizeInGB>

under your DataVirtualHardDisk element.

The reason I'm suggesting this is because if you look at the documentation for Get Data Disk (http://msdn.microsoft.com/en-us/library/windowsazure/jj157180.aspx), it mentions that you get LogicalDiskSizeInGB as one of the response element however when you execute this function, the element you get back is LogicalSizeInGB.

Again it's a hunch. Give it a try.

Update

Another thing you might want to do is parse the exception you're getting to get more details. In .Net we get a WebException (Sorry, haven't worked in Java for a long-long time) so what I normally do is read the response of that exception and that returns me an XML with somewhat more details.

Comments

0

Anand, there is a problem with this API. I have implemented this in fluent management and unfortunately the XML is order dependent.

You can cycle between 400 and 500 HTTP exceptions if this is not precise. I would use powershell to write your VM creation in verbose mode and get your application to use the XML in the exact order you see it and it should be fine.

In the next few days I'll be posting up a java service management client example on http://blog.elastacloud.com which consumes a .publishsettings file to make requests which may be helpful for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.