rightsStr = new ArrayList<>();
+// for (AccessRights rights : resource.rights()) {
+// rightsStr.add(rights.toString());
+// }
+// info.append("\n\tRights: ").append(rightsStr);
+// System.out.println(info.toString());
+// }
+//
+// /**
+// * Print event hub namespace recovery pairing auth rule key.
+// *
+// * @param resource event hub namespace disaster recovery pairing auth rule key
+// */
+// public static void print(DisasterRecoveryPairingAuthorizationKey resource) {
+// StringBuilder info = new StringBuilder();
+// info.append("DisasterRecoveryPairing auth key: ")
+// .append("\n\t Alias primary connection string: ").append(resource.aliasPrimaryConnectionString())
+// .append("\n\t Alias secondary connection string: ").append(resource.aliasSecondaryConnectionString())
+// .append("\n\t Primary key: ").append(resource.primaryKey())
+// .append("\n\t Secondary key: ").append(resource.secondaryKey())
+// .append("\n\t Primary connection string: ").append(resource.primaryConnectionString())
+// .append("\n\t Secondary connection string: ").append(resource.secondaryConnectionString());
+// System.out.println(info.toString());
+// }
+//
+// /**
+// * Print event hub consumer group.
+// *
+// * @param resource event hub consumer group
+// */
+// public static void print(EventHubConsumerGroup resource) {
+// StringBuilder info = new StringBuilder();
+// info.append("Event hub consumer group: ").append(resource.id())
+// .append("\n\tName: ").append(resource.name())
+// .append("\n\tNamespace resource group: ").append(resource.namespaceResourceGroupName())
+// .append("\n\tNamespace: ").append(resource.namespaceName())
+// .append("\n\tEvent hub name: ").append(resource.eventHubName())
+// .append("\n\tUser metadata: ").append(resource.userMetadata());
+// System.out.println(info.toString());
+// }
- /**
- * Print Batch AI Job.
- *
- * @param resource batch ai job
- */
- public static void print(BatchAIJob resource) {
- StringBuilder info = new StringBuilder("Batch AI job: ")
- .append("\n\tId: ").append(resource.id())
- .append("\n\tName: ").append(resource.name())
- .append("\n\tCluster Id: ").append(resource.cluster())
- .append("\n\tCreation time: ").append(resource.creationTime())
- .append("\n\tNode count: ").append(resource.nodeCount())
- .append("\n\tPriority: ").append(resource.schedulingPriority())
- .append("\n\tExecution state: ").append(resource.executionState())
- .append("\n\tExecution state transition time: ").append(resource.executionStateTransitionTime())
- .append("\n\tTool type: ").append(resource.toolType())
- .append("\n\tExperiment name: ").append(resource.experiment().name());
- if (resource.mountVolumes() != null) {
- info.append("\n\tMount volumes:");
- if (resource.mountVolumes().azureFileShares() != null) {
- info.append("\n\t\tAzure fileshares:");
- for (AzureFileShareReference share : resource.mountVolumes().azureFileShares()) {
- info.append("\n\t\t\tAccount name:").append(share.accountName())
- .append("\n\t\t\tFile Url:").append(share.azureFileUrl())
- .append("\n\t\t\tDirectory mode:").append(share.directoryMode())
- .append("\n\t\t\tFile mode:").append(share.fileMode())
- .append("\n\t\t\tRelative mount path:").append(share.relativeMountPath());
- }
- }
- }
- System.out.println(info.toString());
- }
/**
* Print Diagnostic Setting.
@@ -3125,32 +3329,209 @@ public static void print(MetricAlert metricAlert) {
}
System.out.println(info.toString());
}
- private static OkHttpClient httpClient;
- /**
- * Ensure the HTTP client is valid.
+// /**
+// * Print spring service settings.
+// *
+// * @param springService spring service instance
+// */
+// public static void print(SpringService springService) {
+// StringBuilder info = new StringBuilder("Spring Service: ")
+// .append("\n\tId: ").append(springService.id())
+// .append("\n\tName: ").append(springService.name())
+// .append("\n\tResource Group: ").append(springService.resourceGroupName())
+// .append("\n\tRegion: ").append(springService.region())
+// .append("\n\tTags: ").append(springService.tags());
+//
+// ConfigServerProperties serverProperties = springService.getServerProperties();
+// if (serverProperties != null && serverProperties.provisioningState() != null
+// && serverProperties.provisioningState().equals(ConfigServerState.SUCCEEDED) && serverProperties.configServer() != null) {
+// info.append("\n\tProperties: ");
+// if (serverProperties.configServer().gitProperty() != null) {
+// info.append("\n\t\tGit: ").append(serverProperties.configServer().gitProperty().uri());
+// }
+// }
+//
+// if (springService.sku() != null) {
+// info.append("\n\tSku: ")
+// .append("\n\t\tName: ").append(springService.sku().name())
+// .append("\n\t\tTier: ").append(springService.sku().tier())
+// .append("\n\t\tCapacity: ").append(springService.sku().capacity());
+// }
+//
+// MonitoringSettingProperties monitoringSettingProperties = springService.getMonitoringSetting();
+// if (monitoringSettingProperties != null && monitoringSettingProperties.provisioningState() != null
+// && monitoringSettingProperties.provisioningState().equals(MonitoringSettingState.SUCCEEDED)) {
+// info.append("\n\tTrace: ")
+// .append("\n\t\tEnabled: ").append(monitoringSettingProperties.traceEnabled())
+// .append("\n\t\tApp Insight Instrumentation Key: ").append(monitoringSettingProperties.appInsightsInstrumentationKey());
+// }
+//
+// System.out.println(info.toString());
+// }
+//
+// /**
+// * Print spring app settings.
+// *
+// * @param springApp spring app instance
+// */
+// public static void print(SpringApp springApp) {
+// StringBuilder info = new StringBuilder("Spring Service: ")
+// .append("\n\tId: ").append(springApp.id())
+// .append("\n\tName: ").append(springApp.name())
+// .append("\n\tCreated Time: ").append(springApp.createdTime())
+// .append("\n\tPublic Endpoint: ").append(springApp.isPublic())
+// .append("\n\tUrl: ").append(springApp.url())
+// .append("\n\tHttps Only: ").append(springApp.isHttpsOnly())
+// .append("\n\tFully Qualified Domain Name: ").append(springApp.fqdn())
+// .append("\n\tActive Deployment Name: ").append(springApp.activeDeploymentName());
+//
+// if (springApp.temporaryDisk() != null) {
+// info.append("\n\tTemporary Disk:")
+// .append("\n\t\tSize In GB: ").append(springApp.temporaryDisk().sizeInGB())
+// .append("\n\t\tMount Path: ").append(springApp.temporaryDisk().mountPath());
+// }
+//
+// if (springApp.persistentDisk() != null) {
+// info.append("\n\tPersistent Disk:")
+// .append("\n\t\tSize In GB: ").append(springApp.persistentDisk().sizeInGB())
+// .append("\n\t\tMount Path: ").append(springApp.persistentDisk().mountPath());
+// }
+//
+// if (springApp.identity() != null) {
+// info.append("\n\tIdentity:")
+// .append("\n\t\tType: ").append(springApp.identity().type())
+// .append("\n\t\tPrincipal Id: ").append(springApp.identity().principalId())
+// .append("\n\t\tTenant Id: ").append(springApp.identity().tenantId());
+// }
+//
+// System.out.println(info.toString());
+// }
+
+ /**
+ * Sends a GET request to target URL.
+ *
+ * Retry logic tuned for AppService.
+ * The method does not handle 301 redirect.
*
+ * @param urlString the target URL.
+ * @return Content of the HTTP response.
*/
- private static OkHttpClient ensureValidHttpClient() {
- if (httpClient == null) {
- httpClient = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build();
- }
+ public static String sendGetRequest(String urlString) {
+ ClientLogger logger = new ClientLogger(Utils.class);
- return httpClient;
+ try {
+ Mono>> response =
+ HTTP_CLIENT.getString(getHost(urlString), getPathAndQuery(urlString))
+ .retryWhen(Retry
+ .fixedDelay(5, Duration.ofSeconds(30))
+ .filter(t -> {
+ boolean retry = false;
+ if (t instanceof TimeoutException) {
+ retry = true;
+ } else if (t instanceof HttpResponseException
+ && ((HttpResponseException) t).getResponse().getStatusCode() == 503) {
+ retry = true;
+ }
+
+ if (retry) {
+ logger.info("retry GET request to {}", urlString);
+ }
+ return retry;
+ }));
+ Response ret = stringResponse(response).block();
+ return ret == null ? null : ret.getValue();
+ } catch (MalformedURLException e) {
+ logger.logThrowableAsError(e);
+ return null;
+ }
}
/**
- * Connect to a specified URL using "curl" like HTTP GET client.
+ * Sends a POST request to target URL.
+ *
+ * Retry logic tuned for AppService.
*
- * @param url URL to be tested
- * @return the HTTP GET response content
- */
- public static String curl(String url) {
- Request request = new Request.Builder().url(url).get().build();
+ * @param urlString the target URL.
+ * @param body the request body.
+ * @return Content of the HTTP response.
+ * */
+ public static String sendPostRequest(String urlString, String body) {
+ ClientLogger logger = new ClientLogger(Utils.class);
+
try {
- return ensureValidHttpClient().newCall(request).execute().body().string();
- } catch (IOException e) {
+ Mono> response =
+ stringResponse(HTTP_CLIENT.postString(getHost(urlString), getPathAndQuery(urlString), body))
+ .retryWhen(Retry
+ .fixedDelay(5, Duration.ofSeconds(30))
+ .filter(t -> {
+ boolean retry = false;
+ if (t instanceof TimeoutException) {
+ retry = true;
+ }
+
+ if (retry) {
+ logger.info("retry POST request to {}", urlString);
+ }
+ return retry;
+ }));
+ Response ret = response.block();
+ return ret == null ? null : ret.getValue();
+ } catch (Exception e) {
+ logger.logThrowableAsError(e);
return null;
}
}
+
+ private static Mono> stringResponse(Mono>> responseMono) {
+ return responseMono.flatMap(response -> FluxUtil.collectBytesInByteBufferStream(response.getValue())
+ .map(bytes -> new String(bytes, StandardCharsets.UTF_8))
+ .map(str -> new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), str)));
+ }
+
+ private static String getHost(String urlString) throws MalformedURLException {
+ URL url = new URL(urlString);
+ String protocol = url.getProtocol();
+ String host = url.getAuthority();
+ return protocol + "://" + host;
+ }
+
+ private static String getPathAndQuery(String urlString) throws MalformedURLException {
+ URL url = new URL(urlString);
+ String path = url.getPath();
+ String query = url.getQuery();
+ if (query != null && !query.isEmpty()) {
+ path = path + "?" + query;
+ }
+ return path;
+ }
+
+ private static final WebAppTestClient HTTP_CLIENT = RestProxy.create(
+ WebAppTestClient.class,
+ new HttpPipelineBuilder()
+ .policies(
+ new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)),
+ new RetryPolicy("Retry-After", ChronoUnit.SECONDS))
+ .build());
+
+ @Host("{$host}")
+ @ServiceInterface(name = "WebAppTestClient")
+ private interface WebAppTestClient {
+ @Get("{path}")
+ @ExpectedResponses({200, 400, 404})
+ Mono>> getString(@HostParam("$host") String host, @PathParam(value = "path", encoded = true) String path);
+
+ @Post("{path}")
+ @ExpectedResponses({200, 400, 404})
+ Mono>> postString(@HostParam("$host") String host, @PathParam(value = "path", encoded = true) String path, @BodyParam("text/plain") String body);
+ }
+
+ public static int getSize(Iterable iterable) {
+ int res = 0;
+ Iterator iterator = iterable.iterator();
+ while (iterator.hasNext()) {
+ iterator.next();
+ }
+ return res;
+ }
}
diff --git a/src/main/java/com/microsoft/azure/management/sql/samples/ManageSqlDatabasesAcrossDifferentDataCenters.java b/src/main/java/com/microsoft/azure/management/sql/samples/ManageSqlDatabasesAcrossDifferentDataCenters.java
index 3645fd9..85c7765 100644
--- a/src/main/java/com/microsoft/azure/management/sql/samples/ManageSqlDatabasesAcrossDifferentDataCenters.java
+++ b/src/main/java/com/microsoft/azure/management/sql/samples/ManageSqlDatabasesAcrossDifferentDataCenters.java
@@ -6,26 +6,25 @@
package com.microsoft.azure.management.sql.samples;
-import com.microsoft.azure.AzureEnvironment;
-import com.microsoft.azure.AzureResponseBuilder;
-import com.microsoft.azure.credentials.ApplicationTokenCredentials;
-import com.microsoft.azure.management.Azure;
-import com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage;
-import com.microsoft.azure.management.compute.VirtualMachine;
-import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;
-import com.microsoft.azure.management.network.Network;
-import com.microsoft.azure.management.network.PublicIPAddress;
-import com.microsoft.azure.management.resources.fluentcore.arm.Region;
-import com.microsoft.azure.management.resources.fluentcore.model.Creatable;
+import com.azure.core.credential.TokenCredential;
+import com.azure.core.http.policy.HttpLogDetailLevel;
+import com.azure.core.management.AzureEnvironment;
+import com.azure.core.management.Region;
+import com.azure.core.management.profile.AzureProfile;
+import com.azure.identity.DefaultAzureCredentialBuilder;
+import com.azure.resourcemanager.AzureResourceManager;
+import com.azure.resourcemanager.compute.models.KnownWindowsVirtualMachineImage;
+import com.azure.resourcemanager.compute.models.VirtualMachine;
+import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
+import com.azure.resourcemanager.network.models.Network;
+import com.azure.resourcemanager.network.models.PublicIpAddress;
+import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
+import com.azure.resourcemanager.sql.models.CreateMode;
+import com.azure.resourcemanager.sql.models.DatabaseEdition;
+import com.azure.resourcemanager.sql.models.SqlDatabase;
+import com.azure.resourcemanager.sql.models.SqlFirewallRule;
+import com.azure.resourcemanager.sql.models.SqlServer;
import com.microsoft.azure.management.samples.Utils;
-import com.microsoft.azure.management.sql.CreateMode;
-import com.microsoft.azure.management.sql.DatabaseEdition;
-import com.microsoft.azure.management.sql.SqlDatabase;
-import com.microsoft.azure.management.sql.SqlFirewallRule;
-import com.microsoft.azure.management.sql.SqlServer;
-import com.microsoft.azure.serializer.AzureJacksonAdapter;
-import com.microsoft.rest.LogLevel;
-import com.microsoft.rest.RestClient;
import java.io.File;
import java.util.ArrayList;
@@ -36,28 +35,30 @@
import java.util.concurrent.TimeUnit;
/**
- * Azure SQL sample for managing SQL Database -
- * - Create 3 SQL Servers in different region.
- * - Create a master database in master SQL Server.
- * - Create 2 more SQL Servers in different azure regions
- * - Create secondary read only databases in these server with source as database in server created in step 1.
- * - Create 5 virtual networks in different regions.
- * - Create one VM in each of the virtual network.
- * - Update all three databases to have firewall rules with range of each of the virtual network.
+ * Azure SQL sample for managing SQL Database - - Create 3 SQL Servers in
+ * different region. - Create a master database in master SQL Server. - Create 2
+ * more SQL Servers in different azure regions - Create secondary read only
+ * databases in these server with source as database in server created in step
+ * 1. - Create 5 virtual networks in different regions. - Create one VM in each
+ * of the virtual network. - Update all three databases to have firewall rules
+ * with range of each of the virtual network.
*/
public final class ManageSqlDatabasesAcrossDifferentDataCenters {
/**
* Main function which runs the actual sample.
- * @param azure instance of the azure client
+ *
+ * @param azureResourceManager instance of the azureResourceManager client
* @return true if sample runs successfully
*/
- public static boolean runSample(Azure azure) {
- final String sqlServerName = Utils.createRandomName("sqlserver");
- final String rgName = Utils.createRandomName("rgRSSDRE");
+ public static boolean runSample(AzureResourceManager azureResourceManager) {
+ final String sqlServerName = Utils.randomResourceName(azureResourceManager, "sqlserver", 15);
+ final String rgName = Utils.randomResourceName(azureResourceManager, "rgRSSDRE", 15);
final String administratorLogin = "sqladmin3423";
- // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
+ // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine",
+ // Justification="Serves as an example, not for deployment. Please change when
+ // using this in your code.")]
final String administratorPassword = "myS3cureP@ssword";
final String slaveSqlServer1Name = "slave1sql";
final String slaveSqlServer2Name = "slave2sql";
@@ -68,12 +69,9 @@ public static boolean runSample(Azure azure) {
// ============================================================
// Create a SQL Server, with 2 firewall rules.
- SqlServer masterSqlServer = azure.sqlServers().define(sqlServerName)
- .withRegion(Region.US_EAST)
- .withNewResourceGroup(rgName)
- .withAdministratorLogin(administratorLogin)
- .withAdministratorPassword(administratorPassword)
- .create();
+ SqlServer masterSqlServer = azureResourceManager.sqlServers().define(sqlServerName)
+ .withRegion(Region.US_EAST).withNewResourceGroup(rgName).withAdministratorLogin(administratorLogin)
+ .withAdministratorPassword(administratorPassword).create();
Utils.print(masterSqlServer);
@@ -81,48 +79,38 @@ public static boolean runSample(Azure azure) {
// Create a Database in master SQL server created above.
System.out.println("Creating a database");
- SqlDatabase masterDatabase = masterSqlServer.databases().define(databaseName)
- .withEdition(DatabaseEdition.BASIC)
- .create();
+ SqlDatabase masterDatabase = masterSqlServer.databases().define(databaseName).withBasicEdition().create();
Utils.print(masterDatabase);
// ============================================================
// Create secondary SQLServer/Database for the master database
System.out.println("Creating server in secondary location for master SQL Server");
- SqlServer sqlServerInSecondaryLocation = azure.sqlServers()
- .define(Utils.createRandomName(slaveSqlServer1Name))
- .withRegion(Region.US_EAST2)
- .withExistingResourceGroup(rgName)
- .withAdministratorLogin(administratorLogin)
- .withAdministratorPassword(administratorPassword)
- .create();
+ SqlServer sqlServerInSecondaryLocation = azureResourceManager.sqlServers()
+ .define(Utils.randomResourceName(azureResourceManager, slaveSqlServer1Name, 15))
+ .withRegion(Region.US_EAST2).withExistingResourceGroup(rgName)
+ .withAdministratorLogin(administratorLogin).withAdministratorPassword(administratorPassword)
+ .create();
Utils.print(sqlServerInSecondaryLocation);
System.out.println("Creating database in slave SQL Server.");
SqlDatabase secondaryDatabase = sqlServerInSecondaryLocation.databases().define(databaseName)
- .withSourceDatabase(masterDatabase)
- .withMode(CreateMode.ONLINE_SECONDARY)
- .create();
+ .withSourceDatabase(masterDatabase).withMode(CreateMode.ONLINE_SECONDARY).create();
Utils.print(secondaryDatabase);
// ============================================================
// Create another slave SQLServer/Database for the master database
System.out.println("Creating server in another location for master SQL Server");
- SqlServer sqlServerInEurope = azure.sqlServers()
- .define(Utils.createRandomName(slaveSqlServer2Name))
- .withRegion(Region.EUROPE_WEST)
- .withExistingResourceGroup(rgName)
- .withAdministratorLogin(administratorLogin)
- .withAdministratorPassword(administratorPassword)
- .create();
+ SqlServer sqlServerInEurope = azureResourceManager.sqlServers()
+ .define(Utils.randomResourceName(azureResourceManager, slaveSqlServer2Name, 15))
+ .withRegion(Region.EUROPE_WEST).withExistingResourceGroup(rgName)
+ .withAdministratorLogin(administratorLogin).withAdministratorPassword(administratorPassword)
+ .create();
Utils.print(sqlServerInEurope);
System.out.println("Creating database in second slave SQL Server.");
SqlDatabase secondaryDatabaseInEurope = sqlServerInEurope.databases().define(databaseName)
- .withSourceDatabase(masterDatabase)
- .withMode(CreateMode.ONLINE_SECONDARY)
- .create();
+ .withSourceDatabase(masterDatabase).withMode(CreateMode.ONLINE_SECONDARY).create();
Utils.print(secondaryDatabaseInEurope);
// ============================================================
@@ -139,25 +127,26 @@ public static boolean runSample(Azure azure) {
System.out.println("Creating virtual networks in different regions.");
- for (Region region: regions) {
- creatableNetworks.add(azure.networks().define(Utils.createRandomName(networkNamePrefix))
- .withRegion(region)
- .withExistingResourceGroup(rgName));
+ for (Region region : regions) {
+ creatableNetworks.add(azureResourceManager.networks()
+ .define(Utils.randomResourceName(azureResourceManager, networkNamePrefix, 15))
+ .withRegion(region).withExistingResourceGroup(rgName));
}
- Collection networks = azure.networks().create(creatableNetworks).values();
+ Collection networks = azureResourceManager.networks().create(creatableNetworks).values();
// ============================================================
// Create virtual machines attached to different virtual networks created above.
List> creatableVirtualMachines = new ArrayList<>();
System.out.println("Creating virtual machines in different regions.");
- for (Network network: networks) {
- String vmName = Utils.createRandomName(virtualMachineNamePrefix);
- Creatable publicIPAddressCreatable = azure.publicIPAddresses().define(vmName)
+ for (Network network : networks) {
+ String vmName = Utils.randomResourceName(azureResourceManager, virtualMachineNamePrefix, 15);
+ Creatable publicIPAddressCreatable = azureResourceManager.publicIpAddresses()
+ .define(vmName)
.withRegion(network.region())
.withExistingResourceGroup(rgName)
.withLeafDomainLabel(vmName);
- creatableVirtualMachines.add(azure.virtualMachines().define(vmName)
+ creatableVirtualMachines.add(azureResourceManager.virtualMachines().define(vmName)
.withRegion(network.region())
.withExistingResourceGroup(rgName)
.withExistingPrimaryNetwork(network)
@@ -171,7 +160,7 @@ public static boolean runSample(Azure azure) {
}
HashMap ipAddresses = new HashMap<>();
- for (VirtualMachine virtualMachine: azure.virtualMachines().create(creatableVirtualMachines).values()) {
+ for (VirtualMachine virtualMachine: azureResourceManager.virtualMachines().create(creatableVirtualMachines).values()) {
ipAddresses.put(virtualMachine.name(), virtualMachine.getPrimaryPublicIPAddress().ipAddress());
}
@@ -184,7 +173,7 @@ public static boolean runSample(Azure azure) {
for (SqlServer sqlServer: sqlServers) {
for (Map.Entry ipAddress: ipAddresses.entrySet()) {
- sqlServer.firewallRules().define(ipAddress.getKey()).withIPAddress(ipAddress.getValue()).create();
+ sqlServer.firewallRules().define(ipAddress.getKey()).withIpAddress(ipAddress.getValue()).create();
}
}
@@ -200,7 +189,7 @@ public static boolean runSample(Azure azure) {
// Delete the SQL Server.
System.out.println("Deleting all Sql Servers");
for (SqlServer sqlServer: sqlServers) {
- azure.sqlServers().deleteById(sqlServer.id());
+ azureResourceManager.sqlServers().deleteById(sqlServer.id());
}
return true;
} catch (Exception f) {
@@ -209,7 +198,7 @@ public static boolean runSample(Azure azure) {
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
- azure.resourceGroups().deleteByName(rgName);
+ azureResourceManager.resourceGroups().deleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
}
catch (Exception e) {
@@ -226,22 +215,17 @@ public static boolean runSample(Azure azure) {
public static void main(String[] args) {
try {
- final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
+ final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
+ final TokenCredential credential = new DefaultAzureCredentialBuilder()
+ .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint()).build();
- ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
- RestClient restClient = new RestClient.Builder()
- .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER)
- .withSerializerAdapter(new AzureJacksonAdapter())
- .withReadTimeout(150, TimeUnit.SECONDS)
- .withLogLevel(LogLevel.BODY)
- .withResponseBuilderFactory(new AzureResponseBuilder.Factory())
- .withCredentials(credentials).build();
- Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
+ AzureResourceManager azureResourceManager = AzureResourceManager.configure()
+ .withLogLevel(HttpLogDetailLevel.BASIC).authenticate(credential, profile).withDefaultSubscription();
// Print selected subscription
- System.out.println("Selected subscription: " + azure.subscriptionId());
+ System.out.println("Selected subscription: " + azureResourceManager.subscriptionId());
- runSample(azure);
+ runSample(azureResourceManager);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();