|
6 | 6 | package com.microsoft.azuretools.utils; |
7 | 7 |
|
8 | 8 | import com.microsoft.azure.management.Azure; |
9 | | -import rx.Observable; |
10 | | -import rx.schedulers.Schedulers; |
| 9 | +import org.apache.commons.lang3.StringUtils; |
11 | 10 |
|
12 | | -import java.util.concurrent.Callable; |
| 11 | +import java.util.Arrays; |
13 | 12 |
|
14 | 13 | public class AzureRegisterProviderNamespaces { |
15 | | - public static void registerAzureNamespaces(Azure azureInstance) { |
16 | | - String[] namespaces = new String[] {"Microsoft.Resources", "Microsoft.Network", "Microsoft.Compute", |
17 | | - "Microsoft.KeyVault", "Microsoft.Storage", "Microsoft.Web", "Microsoft.Authorization", "Microsoft.HDInsight"}; |
18 | | - try { |
19 | | - Observable.from(namespaces).flatMap(namespace -> { |
20 | | - return Observable.fromCallable(new Callable<Object>() { |
21 | | - @Override |
22 | | - public Object call() throws Exception { |
23 | | - azureInstance.providers().register(namespace); |
24 | | - return null; |
25 | | - } |
26 | | - }).subscribeOn(Schedulers.io()); |
27 | | - }).toBlocking().subscribe(); |
28 | | -// azureInstance.providers().register("Microsoft.Resources"); |
29 | | -// azureInstance.providers().register("Microsoft.Network"); |
30 | | -// azureInstance.providers().register("Microsoft.Compute"); |
31 | | -// azureInstance.providers().register("Microsoft.KeyVault"); |
32 | | -// azureInstance.providers().register("Microsoft.Storage"); |
33 | | -// azureInstance.providers().register("Microsoft.Web"); |
34 | | -// azureInstance.providers().register("Microsoft.Authorization"); |
35 | | -// azureInstance.providers().register("Microsoft.HDInsight"); |
36 | | - } catch (Exception ignored) { |
37 | | - // No need to handle this for now since this functionality will be eventually removed once the Azure SDK |
38 | | - // something similar |
| 14 | + private static final String[] namespaces = new String[]{"Microsoft.Resources", "Microsoft.Network", "Microsoft.Compute", "Microsoft.KeyVault", |
| 15 | + "Microsoft.Storage", "Microsoft.Web", "Microsoft.Authorization", "Microsoft.HDInsight", "Microsoft.DBforMySQL"}; |
| 16 | + |
| 17 | + public static void registerAzureNamespaces(Azure azureInstance) { |
| 18 | + |
| 19 | + try { |
| 20 | + Arrays.stream(namespaces).parallel() |
| 21 | + .map(azureInstance.providers()::getByName) |
| 22 | + .filter(provider -> !StringUtils.equalsIgnoreCase("Registered", provider.registrationState())) |
| 23 | + .forEach(provider -> azureInstance.providers().register(provider.namespace())); |
| 24 | + } catch (Exception ignored) { |
| 25 | + // No need to handle this for now since this functionality will be eventually removed once the Azure SDK |
| 26 | + // something similar |
| 27 | + } |
39 | 28 | } |
40 | | - } |
41 | 29 | } |
0 commit comments