Implement workaround of Azure management api throw NPE when get unexisted namespace

This commit is contained in:
Warren Zhu 2018-06-04 14:44:17 +08:00
Родитель 67ea8baa55
Коммит 964be98524
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -46,14 +46,14 @@ public class AzureAdmin {
} }
public EventHubNamespace getOrCreateEventHubNamespace(String namespace) { public EventHubNamespace getOrCreateEventHubNamespace(String namespace) {
EventHubNamespace eventHubNamespace = azure.eventHubNamespaces().getByResourceGroup(resourceGroup, namespace); try {
return azure.eventHubNamespaces().getByResourceGroup(resourceGroup, namespace);
if (eventHubNamespace == null) { } catch (NullPointerException e) {
// azure management api has no way to determine whether an eventhub namespace exists
// Workaround for this is by catching NPE
return azure.eventHubNamespaces().define(namespace).withRegion(region) return azure.eventHubNamespaces().define(namespace).withRegion(region)
.withExistingResourceGroup(resourceGroup).create(); .withExistingResourceGroup(resourceGroup).create();
} }
return eventHubNamespace;
} }
public StorageAccount getOrCreateStorageAccount(String name) { public StorageAccount getOrCreateStorageAccount(String name) {