Hot questions for Using Azure in azure cloud services

Top Java Programmings / Azure / azure cloud services

Question:

When Azure shuts down a Cloud Service instance (e.g. when the host OS reboots, or when autoscaling down), it triggers a Stop method, so applications have a chance to gracefully shutdown.

I can find documentation how to do this in .NET: http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleentrypoint.onstop.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1 but I cannot find any documentation on how to do this from Java.

How can I do this in Java?


Answer:

Implement com.microsoft.windowsazure.serviceruntime.RoleEnvironmentStoppingListener

This is available from Maven Central: http://search.maven.org/#artifactdetails|com.microsoft.azure|azure-serviceruntime|0.6.0|jar

Question:

How to get Cloud Service (Hosted Service) diagnostic data using Java or Rest API?

We can get DiagnosticsConnectionString from Azure Portal for Roles and using which we can query to WADPerformanceCounter Table (Storage API).

Getting following exception while executing:

query:java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details. at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNe‌​xt(LazySegmentedIter‌​ator.java:113) at TestStorage.main(TestStorage.java:225) Caused by: com.microsoft.azure.storage.table.TableServiceException: Bad Request


Answer:

@Prit, There is not any code in your question so that I couldn't figure out the issue which was caused by what.

So I post my steps and code here as reference for helping.

  1. Copy the DIAGNOSTICS CONNECTION STRINGS of one role of the Cloud Service at the tab CONFIGURE of Cloud Service on Azure Management portal, the format of conection string is like DefaultEndpointsProtocol=https;AccountName=<storage-account-name>;AccountKey=<storage-key>.

  2. Use the GUI tool Micorsoft Azure Storage Explorer to find & view the table WADPerformanceCounter.

  1. Code in Java to retrieve all diagnostic data as below.

    import com.microsoft.azure.storage.CloudStorageAccount;
    import com.microsoft.azure.storage.table.CloudTable;
    import com.microsoft.azure.storage.table.CloudTableClient;
    import com.microsoft.azure.storage.table.TableQuery;
    import com.microsoft.azure.storage.table.TableServiceEntity;
    
    public class WADPerformanceCounterReader {
    
        public static final String storageConnectionString = 
            "DefaultEndpointsProtocol=https;"+
            "AccountName=<storage-account-name>;"+
            "AccountKey=<storage-key>";
    
        public static void main(String[] args) {
            try {
                // Retrieve storage account from connection-string.
                CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
    
                // Create the table client.
                CloudTableClient tableClient = storageAccount.createCloudTableClient();
    
                CloudTable cloudTable = tableClient.getTableReference("WADPerformanceCountersTable");
                TableQuery<TableServiceEntity> query = TableQuery.from(TableServiceEntity.class);
                for (TableServiceEntity entity : cloudTable.execute(query)) {
                    System.out.println(entity.getPartitionKey()+"\t"+entity.getRowKey());
               }
            } catch (Exception e) {
                // Output the stack trace.
                e.printStackTrace();
            }
        }
    
    }
    

Hope it helps.

Question:

My Azure Web Role has R,Java etc configured on it automatically before my actual application starts running. Everything configures perfectly fine and the application is running smoothly. I have had no problem with my web app for 2 weeks and it was working fine in an Azure Web Role. Then one day while I was opening my web app I faced an error related to R-core. On remotely accessing my Azure VM, I found out that my R,Java and R packages were deleted. Going through the event viewer I found out that my Azure VM was restarted 3times.

It is an ASP.NET web app hosted in IIS on an Azure Web Role.

After the whole scenario, could you please direct me about Web Role Recycling. When its working fine for 2 weeks how come it recycles itself and deletes my installations ?


Answer:

Microsoft periodically upgrades the host OS, guest OS, and guest agent hosting the cloud service. Your VM will be rebooted during this time (or guest agent restarted). Cloud services are "stateless", meaning in this case that any prerequisites you have for running your application must be installed via a start-up script.

For more details see: