Azure-Samples / azure-batch-samples

Azure Batch and HPC Code Samples
Other
261 stars 487 forks source link

Java sample code fails to get batchUrl #275

Closed tej-walker closed 5 years ago

tej-walker commented 5 years ago

I am new to Azure Batch Service, I have followed the README of Java Samples and included the batch and storage details. everything is doubled checked and correct. But when I run, it fails with below error: I baseUrl is returning as null when I did a syso, is it something todo with batchUri vs baseUrl? need help:


    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.IllegalArgumentException: **Parameter baseUrl is required and cannot be null.**
    at com.microsoft.azure.batch.auth.BatchSharedKeyCredentials.<init> (BatchSharedKeyCredentials.java:50)
    at PoolAndResourceFile.main (PoolAndResourceFile.java:318)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
bgklein commented 5 years ago

Are you setting AZURE_BATCH_ENDPOINT? The error states that https://docs.microsoft.com/en-us/java/api/com.microsoft.azure.batch.auth.batchsharedkeycredentials?view=azure-java-stable is failing to be created due to https://github.com/Azure-Samples/azure-batch-samples/blob/4bc4fc74d38b1cece15f5c2e84809cf2842f8db4/Java/PoolAndResourceFile/src/main/java/PoolAndResourceFile.java#L305 being null

tej-walker commented 5 years ago

I did set all the batch and storage account information. below are the "sample" keys how I did:

    String batchAccount = System.getenv("batchaccountname");
    String batchKey = System.getenv("PrimaryAccessKey");
    String batchUri = System.getenv("https://xxxx.yyyy.batch.azure.com");
    String storageAccountName = System.getenv("storageaccountname");
    String storageAccountKey = System.getenv("Key1"); 

Note: All the above info I have taken from the batch account--> Keys section

bgklein commented 5 years ago

This section of code gets environment variables for the keys provided in System.getenv(). Unless you are setting the environment variables in your system to be value=value it appears this is a misunderstanding of what environment variables are?

tej-walker commented 5 years ago

I figured it out (the env variables were already set). I restarted the machine and tried, it worked. Probably I should have opened a new command prompt and try it. Thank you so much for investing your time to debug this issue.