Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.management.appservice.samples;

import com.azure.core.credential.TokenCredential;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.management.AzureEnvironment;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.management.Azure;
import com.azure.management.resources.fluentcore.profile.AzureProfile;

//
//package com.azure.management.appservice.samples;
//
//import com.azure.core.credential.TokenCredential;
//import com.azure.core.http.policy.HttpLogDetailLevel;
//import com.azure.core.management.AzureEnvironment;
//import com.azure.identity.DefaultAzureCredentialBuilder;
//import com.azure.management.Azure;
//import com.azure.management.resources.fluentcore.profile.AzureProfile;
//
//import com.azure.management.trafficmanager.TrafficManagerProfile;
//import com.azure.management.trafficmanager.TrafficRoutingMethod;


/**
* Azure App Service sample for managing web apps.
* - Create a domain
* - Create a self-signed certificate for the domain
* - Create 3 app service plans in 3 different regions
* - Create 5 web apps under the 3 plans, bound to the domain and the certificate
* - Create a traffic manager in front of the web apps
* - Scale up the app service plans to twice the capacity
*/
public final class ManageLinuxWebAppWithTrafficManager {
//
//
///**
// * Azure App Service sample for managing web apps.
// * - Create a domain
// * - Create a self-signed certificate for the domain
// * - Create 3 app service plans in 3 different regions
// * - Create 5 web apps under the 3 plans, bound to the domain and the certificate
// * - Create a traffic manager in front of the web apps
// * - Scale up the app service plans to twice the capacity
// */
//public final class ManageLinuxWebAppWithTrafficManager {
// private static String rgName;
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
private static final String CERT_PASSWORD = "StrongPass!12";

private static Azure azure;
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
// private static final String CERT_PASSWORD = "StrongPass!12";
//
// private static Azure azure;
// private static AppServiceDomain domain;
// private static String pfxPath;

/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
System.out.println("removed later");
return true;
// /**
// * Main function which runs the actual sample.
// * @param azure instance of the azure client
// * @return true if sample runs successfully
// */
// public static boolean runSample(Azure azure) {
// System.out.println("removed later");
// return true;
// RG_NAME = azure.sdkContext().randomResourceName("rgNEMV_", 24);
//
// if (ManageLinuxWebAppWithTrafficManager.azure == null) {
Expand Down Expand Up @@ -230,38 +230,7 @@ public static boolean runSample(Azure azure) {
// }
//
// return false;
}
/**
* Main entry point.
* @param args the parameters
*/
public static void main(String[] args) {
try {

//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();

Azure azure = Azure
.configure()
.withLogLevel(HttpLogDetailLevel.BASIC)
.authenticate(credential, profile)
.withDefaultSubscription();

// Print selected subscription
System.out.println("Selected subscription: " + azure.subscriptionId());

runSample(azure);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}

//
// private static AppServicePlan createAppServicePlan(String name, Region region) {
// return azure.appServicePlans().define(name)
// .withRegion(region)
Expand All @@ -288,4 +257,4 @@ public static void main(String[] args) {
// .attach()
// .create();
// }
}
//}
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.management.appservice.samples;

import com.azure.core.credential.TokenCredential;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.management.AzureEnvironment;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.management.Azure;
import com.azure.management.resources.fluentcore.profile.AzureProfile;

//
//package com.azure.management.appservice.samples;
//
//import com.azure.core.credential.TokenCredential;
//import com.azure.core.http.policy.HttpLogDetailLevel;
//import com.azure.core.management.AzureEnvironment;
//import com.azure.identity.DefaultAzureCredentialBuilder;
//import com.azure.management.Azure;
//import com.azure.management.resources.fluentcore.profile.AzureProfile;
//
//import com.azure.management.trafficmanager.TrafficManagerProfile;
//import com.azure.management.trafficmanager.TrafficRoutingMethod;


/**
* Azure App Service sample for managing web apps.
* - Create a domain
* - Create a self-signed certificate for the domain
* - Create 3 app service plans in 3 different regions
* - Create 5 web apps under the 3 plans, bound to the domain and the certificate
* - Create a traffic manager in front of the web apps
* - Scale up the app service plans to twice the capacity
*/
public final class ManageWebAppWithTrafficManager {
//
//
///**
// * Azure App Service sample for managing web apps.
// * - Create a domain
// * - Create a self-signed certificate for the domain
// * - Create 3 app service plans in 3 different regions
// * - Create 5 web apps under the 3 plans, bound to the domain and the certificate
// * - Create a traffic manager in front of the web apps
// * - Scale up the app service plans to twice the capacity
// */
//public final class ManageWebAppWithTrafficManager {
// private static String rgName;
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
private static final String CERT_PASSWORD = "StrongPass!12";

private static Azure azure;
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
// private static final String CERT_PASSWORD = "StrongPass!12";
//
// private static Azure azure;
// private static AppServiceDomain domain;
// private static String pfxPath;

/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
System.out.println("removed later");
return true;
//
// /**
// * Main function which runs the actual sample.
// * @param azure instance of the azure client
// * @return true if sample runs successfully
// */
// public static boolean runSample(Azure azure) {
// System.out.println("removed later");
// return true;
// RG_NAME = azure.sdkContext().randomResourceName("rgNEMV_", 24);
//
// if (ManageWebAppWithTrafficManager.azure == null) {
Expand Down Expand Up @@ -230,38 +230,7 @@ public static boolean runSample(Azure azure) {
// }
//
// return false;
}
/**
* Main entry point.
* @param args the parameters
*/
public static void main(String[] args) {
try {

//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();

Azure azure = Azure
.configure()
.withLogLevel(HttpLogDetailLevel.BASIC)
.authenticate(credential, profile)
.withDefaultSubscription();

// Print selected subscription
System.out.println("Selected subscription: " + azure.subscriptionId());

runSample(azure);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}

//
// private static AppServicePlan createAppServicePlan(String name, Region region) {
// return azure.appServicePlans().define(name)
// .withRegion(region)
Expand All @@ -287,4 +256,4 @@ public static void main(String[] args) {
// .attach()
// .create();
// }
}
//}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static boolean runSample(Azure azure) {

System.out.println("Created a new resource group - " + resourceGroup.id());

List<String> publicIpCreatableKeys = new ArrayList<>();
// List<String> publicIpCreatableKeys = new ArrayList<>();
// Prepare a batch of Creatable definitions
//
List<Creatable<VirtualMachine>> creatableVirtualMachines = new ArrayList<>();
Expand Down Expand Up @@ -114,7 +114,7 @@ public static boolean runSample(Azure azure) {
.withExistingResourceGroup(resourceGroup)
.withLeafDomainLabel(azure.sdkContext().randomResourceName("pip", 10));

publicIpCreatableKeys.add(publicIPAddressCreatable.key());
// publicIpCreatableKeys.add(publicIPAddressCreatable.key());

//=============================================================
// Create 1 virtual machine creatable
Expand Down Expand Up @@ -153,12 +153,12 @@ public static boolean runSample(Azure azure) {

System.out.println("Virtual Machines created: (took " + (stopwatch.getTime() / 1000) + " seconds to create) == " + virtualMachines.size() + " == virtual machines");

List<String> publicIpResourceIds = new ArrayList<>();
for (String publicIpCreatableKey : publicIpCreatableKeys) {
PublicIPAddress pip = (PublicIPAddress) virtualMachines.createdRelatedResource(publicIpCreatableKey);
publicIpResourceIds.add(pip.id());
}

// List<String> publicIpResourceIds = new ArrayList<>();
// for (String publicIpCreatableKey : publicIpCreatableKeys) {
// PublicIPAddress pip = (PublicIPAddress) virtualMachines.createdRelatedResource(publicIpCreatableKey);
// publicIpResourceIds.add(pip.id());
// }
//
// //=============================================================
// // Create 1 Traffic Manager Profile
// //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public static boolean runSample(Azure azure) {
} else if (sku.resourceType().equals(ComputeResourceType.SNAPSHOTS)) {
size = sku.diskSkuType().toString();
}
Map<Region, Set<AvailabilityZoneId>> regionZones = sku.zones();
System.out.println(String.format(format, sku.name(), sku.resourceType(), size, regionZoneToString(sku.zones())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static boolean runSample(Azure azure) {
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();

System.out.println("Created VM [with an implicit Managed OS disk and explicit Managed data disk]");
System.out.println("Created VM [with an implicit Managed OS disk and explicit Managed data disk]: " + linuxVM1.id());

// Creation is simplified with implicit creation of managed disks without specifying all the disk details. You will notice that you do not require storage accounts
// ::== Update the VM
Expand Down Expand Up @@ -186,7 +186,7 @@ public static boolean runSample(Azure azure) {
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();

System.out.println("Created VM [from custom image]");
System.out.println("Created VM [from custom image]: " + linuxVM3.id());

// Create a VM from a VHD (Create Virtual Machine Using Specialized VHD)

Expand All @@ -207,7 +207,7 @@ public static boolean runSample(Azure azure) {
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();

System.out.println("Created VM [by attaching un-managed disk]");
System.out.println("Created VM [by attaching un-managed disk]: " + linuxVM4.id());

// Create a Snapshot (Create Virtual Machine using specialized disks from snapshot)

Expand Down Expand Up @@ -292,7 +292,7 @@ public static boolean runSample(Azure azure) {
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();

System.out.println("Created VM [with specialized OS managed disk]");
System.out.println("Created VM [with specialized OS managed disk]: " + linuxVM6.id());

// ::== Migrate a VM to managed disks with a single reboot

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,21 @@ public static boolean runSample(Azure.Authenticated authenticated) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
azure.resourceGroups().beginDeleteByName(rgName);
try {
authenticated.servicePrincipals().deleteById(servicePrincipal.id());
} catch (Exception e) { }
if (azure != null) {
azure.resourceGroups().beginDeleteByName(rgName);
try {
authenticated.servicePrincipals().deleteById(servicePrincipal.id());
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
try {
authenticated.activeDirectoryApplications().deleteById(authenticated.activeDirectoryApplications().getByName(servicePrincipal.applicationId()).id());
} catch (Exception e) { }
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ public static boolean runSample(final Azure azure) {
})
.last().block();

if (virtualMachineScaleSet == null) {
return false;
}

final String pipFqdn = publicIPAddress.fqdn();
//=============================================================
// List virtual machine scale set instance network interfaces and SSH connection string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static boolean runSample(Azure azure) {
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
.create();

System.out.println("Created zone aware virtual machine scale set");
System.out.println("Created zone aware virtual machine scale set: " + virtualMachineScaleSet1.id());

//=============================================================
// Create a zone aware virtual machine scale set
Expand All @@ -208,7 +208,7 @@ public static boolean runSample(Azure azure) {
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
.create();

System.out.println("Created zone aware virtual machine scale set");
System.out.println("Created zone aware virtual machine scale set: " + virtualMachineScaleSet2.id());

return true;
} catch (Exception f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class ManageDns {
public static boolean runSample(Azure azure) {
final String customDomainName = "THE CUSTOM DOMAIN THAT YOU OWN (e.g. contoso.com)";
final String rgName = azure.sdkContext().randomResourceName("rgNEMV_", 24);
final String appServicePlanName = azure.sdkContext().randomResourceName("jplan1_", 15);
final String webAppName = azure.sdkContext().randomResourceName("webapp1-", 20);

try {
Expand Down
Loading