use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-sdk-for-java by Azure.
the class ManageWebAppWithAuthentication method runSample.
/**
* 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) {
// New resources
final String suffix = ".azurewebsites.net";
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
final String app4Name = SdkContext.randomResourceName("webapp4-", 20);
final String app1Url = app1Name + suffix;
final String app2Url = app2Name + suffix;
final String app3Url = app3Name + suffix;
final String app4Url = app4Name + suffix;
final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
try {
//============================================================
// Create a web app with a new app service plan
System.out.println("Creating web app " + app1Name + " in resource group " + rgName + "...");
WebApp app1 = azure.webApps().define(app1Name).withRegion(Region.US_WEST).withNewResourceGroup(rgName).withNewWindowsPlan(PricingTier.STANDARD_S1).withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).create();
System.out.println("Created web app " + app1.name());
Utils.print(app1);
//============================================================
// Set up active directory authentication
System.out.println("Please create an AD application with redirect URL " + app1Url);
System.out.print("Application ID is:");
Console console = System.console();
String applicationId = console.readLine();
System.out.print("Tenant ID is:");
String tenantId = console.readLine();
System.out.println("Updating web app " + app1Name + " to use active directory login...");
app1.update().defineAuthentication().withDefaultAuthenticationProvider(BuiltInAuthenticationProvider.AZURE_ACTIVE_DIRECTORY).withActiveDirectory(applicationId, "https://sts.windows.net/" + tenantId).attach().apply();
System.out.println("Added active directory login to " + app1.name());
Utils.print(app1);
//============================================================
// Create a second web app
System.out.println("Creating another web app " + app2Name + " in resource group " + rgName + "...");
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
WebApp app2 = azure.webApps().define(app2Name).withExistingWindowsPlan(plan).withExistingResourceGroup(rgName).withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).create();
System.out.println("Created web app " + app2.name());
Utils.print(app2);
//============================================================
// Set up Facebook authentication
System.out.println("Please create a Facebook developer application with whitelisted URL " + app2Url);
System.out.print("App ID is:");
String fbAppId = console.readLine();
System.out.print("App secret is:");
String fbAppSecret = console.readLine();
System.out.println("Updating web app " + app2Name + " to use Facebook login...");
app2.update().defineAuthentication().withDefaultAuthenticationProvider(BuiltInAuthenticationProvider.FACEBOOK).withFacebook(fbAppId, fbAppSecret).attach().apply();
System.out.println("Added Facebook login to " + app2.name());
Utils.print(app2);
//============================================================
// Create a 3rd web app with a public GitHub repo in Azure-Samples
System.out.println("Creating another web app " + app3Name + "...");
WebApp app3 = azure.webApps().define(app3Name).withExistingWindowsPlan(plan).withNewResourceGroup(rgName).defineSourceControl().withPublicGitRepository("https://github.com/Azure-Samples/app-service-web-dotnet-get-started").withBranch("master").attach().create();
System.out.println("Created web app " + app3.name());
Utils.print(app3);
//============================================================
// Set up Google authentication
System.out.println("Please create a Google developer application with redirect URL " + app3Url);
System.out.print("Client ID is:");
String gClientId = console.readLine();
System.out.print("Client secret is:");
String gClientSecret = console.readLine();
System.out.println("Updating web app " + app3Name + " to use Google login...");
app3.update().defineAuthentication().withDefaultAuthenticationProvider(BuiltInAuthenticationProvider.GOOGLE).withGoogle(gClientId, gClientSecret).attach().apply();
System.out.println("Added Google login to " + app3.name());
Utils.print(app3);
//============================================================
// Create a 4th web app
System.out.println("Creating another web app " + app4Name + "...");
WebApp app4 = azure.webApps().define(app4Name).withExistingWindowsPlan(plan).withExistingResourceGroup(rgName).create();
System.out.println("Created web app " + app4.name());
Utils.print(app4);
//============================================================
// Set up Google authentication
System.out.println("Please create a Microsoft developer application with redirect URL " + app4Url);
System.out.print("Client ID is:");
String clientId = console.readLine();
System.out.print("Client secret is:");
String clientSecret = console.readLine();
System.out.println("Updating web app " + app3Name + " to use Microsoft login...");
app4.update().defineAuthentication().withDefaultAuthenticationProvider(BuiltInAuthenticationProvider.MICROSOFT_ACCOUNT).withMicrosoft(clientId, clientSecret).attach().apply();
System.out.println("Added Microsoft login to " + app4.name());
Utils.print(app4);
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-sdk-for-java by Azure.
the class ManageWebAppWithDomainSsl method runSample.
/**
* 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) {
// New resources
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String rgName = SdkContext.randomResourceName("rgNEMV_", 24);
final String domainName = SdkContext.randomResourceName("jsdkdemo-", 20) + ".com";
final String certPassword = "StrongPass!12";
try {
//============================================================
// Create a web app with a new app service plan
System.out.println("Creating web app " + app1Name + "...");
WebApp app1 = azure.webApps().define(app1Name).withRegion(Region.US_WEST).withNewResourceGroup(rgName).withNewWindowsPlan(PricingTier.STANDARD_S1).create();
System.out.println("Created web app " + app1.name());
Utils.print(app1);
//============================================================
// Create a second web app with the same app service plan
System.out.println("Creating another web app " + app2Name + "...");
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
WebApp app2 = azure.webApps().define(app2Name).withExistingWindowsPlan(plan).withExistingResourceGroup(rgName).create();
System.out.println("Created web app " + app2.name());
Utils.print(app2);
//============================================================
// Purchase a domain (will be canceled for a full refund)
System.out.println("Purchasing a domain " + domainName + "...");
AppServiceDomain domain = azure.appServices().domains().define(domainName).withExistingResourceGroup(rgName).defineRegistrantContact().withFirstName("Jon").withLastName("Doe").withEmail("jondoe@contoso.com").withAddressLine1("123 4th Ave").withCity("Redmond").withStateOrProvince("WA").withCountry(CountryIsoCode.UNITED_STATES).withPostalCode("98052").withPhoneCountryCode(CountryPhoneCode.UNITED_STATES).withPhoneNumber("4258828080").attach().withDomainPrivacyEnabled(true).withAutoRenewEnabled(false).create();
System.out.println("Purchased domain " + domain.name());
Utils.print(domain);
//============================================================
// Bind domain to web app 1
System.out.println("Binding http://" + app1Name + "." + domainName + " to web app " + app1Name + "...");
app1 = app1.update().defineHostnameBinding().withAzureManagedDomain(domain).withSubDomain(app1Name).withDnsRecordType(CustomHostNameDnsRecordType.CNAME).attach().apply();
System.out.println("Finished binding http://" + app1Name + "." + domainName + " to web app " + app1Name);
Utils.print(app1);
//============================================================
// Create a self-singed SSL certificate
String pfxPath = ManageWebAppWithDomainSsl.class.getResource("/").getPath() + app2Name + "." + domainName + ".pfx";
String cerPath = ManageWebAppWithDomainSsl.class.getResource("/").getPath() + app2Name + "." + domainName + ".cer";
System.out.println("Creating a self-signed certificate " + pfxPath + "...");
Utils.createCertificate(cerPath, pfxPath, domainName, certPassword, "*." + domainName);
System.out.println("Created self-signed certificate " + pfxPath);
//============================================================
// Bind domain to web app 2 and turn on wild card SSL for both
System.out.println("Binding https://" + app1Name + "." + domainName + " to web app " + app1Name + "...");
app1 = app1.update().withManagedHostnameBindings(domain, app1Name).defineSslBinding().forHostname(app1Name + "." + domainName).withPfxCertificateToUpload(new File(pfxPath), certPassword).withSniBasedSsl().attach().apply();
System.out.println("Finished binding http://" + app1Name + "." + domainName + " to web app " + app1Name);
Utils.print(app1);
System.out.println("Binding https://" + app2Name + "." + domainName + " to web app " + app2Name + "...");
app2 = app2.update().withManagedHostnameBindings(domain, app2Name).defineSslBinding().forHostname(app2Name + "." + domainName).withPfxCertificateToUpload(new File(pfxPath), certPassword).withSniBasedSsl().attach().apply();
System.out.println("Finished binding http://" + app2Name + "." + domainName + " to web app " + app2Name);
Utils.print(app2);
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().deleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-sdk-for-java by Azure.
the class ManageWebAppWithTrafficManager method runSample.
/**
* 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) {
if (ManageWebAppWithTrafficManager.azure == null) {
ManageWebAppWithTrafficManager.azure = azure;
}
// New resources
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
final String app4Name = SdkContext.randomResourceName("webapp4-", 20);
final String app5Name = SdkContext.randomResourceName("webapp5-", 20);
final String plan1Name = SdkContext.randomResourceName("jplan1_", 15);
final String plan2Name = SdkContext.randomResourceName("jplan2_", 15);
final String plan3Name = SdkContext.randomResourceName("jplan3_", 15);
final String domainName = SdkContext.randomResourceName("jsdkdemo-", 20) + ".com";
final String tmName = SdkContext.randomResourceName("jsdktm-", 20);
try {
//============================================================
// Purchase a domain (will be canceled for a full refund)
System.out.println("Purchasing a domain " + domainName + "...");
azure.resourceGroups().define(RG_NAME).withRegion(Region.US_WEST).create();
domain = azure.appServices().domains().define(domainName).withExistingResourceGroup(RG_NAME).defineRegistrantContact().withFirstName("Jon").withLastName("Doe").withEmail("jondoe@contoso.com").withAddressLine1("123 4th Ave").withCity("Redmond").withStateOrProvince("WA").withCountry(CountryIsoCode.UNITED_STATES).withPostalCode("98052").withPhoneCountryCode(CountryPhoneCode.UNITED_STATES).withPhoneNumber("4258828080").attach().withDomainPrivacyEnabled(true).withAutoRenewEnabled(false).create();
System.out.println("Purchased domain " + domain.name());
Utils.print(domain);
//============================================================
// Create a self-singed SSL certificate
pfxPath = ManageWebAppWithTrafficManager.class.getResource("/").getPath() + app2Name + "." + domainName + ".pfx";
String cerPath = ManageWebAppWithTrafficManager.class.getResource("/").getPath() + app2Name + "." + domainName + ".cer";
System.out.println("Creating a self-signed certificate " + pfxPath + "...");
Utils.createCertificate(cerPath, pfxPath, domainName, CERT_PASSWORD, "*." + domainName);
//============================================================
// Create 3 app service plans in 3 regions
System.out.println("Creating app service plan " + plan1Name + " in US West...");
AppServicePlan plan1 = createAppServicePlan(plan1Name, Region.US_WEST);
System.out.println("Created app service plan " + plan1.name());
Utils.print(plan1);
System.out.println("Creating app service plan " + plan2Name + " in Europe West...");
AppServicePlan plan2 = createAppServicePlan(plan2Name, Region.EUROPE_WEST);
System.out.println("Created app service plan " + plan2.name());
Utils.print(plan1);
System.out.println("Creating app service plan " + plan3Name + " in Asia East...");
AppServicePlan plan3 = createAppServicePlan(plan3Name, Region.ASIA_EAST);
System.out.println("Created app service plan " + plan2.name());
Utils.print(plan1);
//============================================================
// Create 5 web apps under these 3 app service plans
System.out.println("Creating web app " + app1Name + "...");
WebApp app1 = createWebApp(app1Name, plan1);
System.out.println("Created web app " + app1.name());
Utils.print(app1);
System.out.println("Creating another web app " + app2Name + "...");
WebApp app2 = createWebApp(app2Name, plan2);
System.out.println("Created web app " + app2.name());
Utils.print(app2);
System.out.println("Creating another web app " + app3Name + "...");
WebApp app3 = createWebApp(app3Name, plan3);
System.out.println("Created web app " + app3.name());
Utils.print(app3);
System.out.println("Creating another web app " + app3Name + "...");
WebApp app4 = createWebApp(app4Name, plan1);
System.out.println("Created web app " + app4.name());
Utils.print(app4);
System.out.println("Creating another web app " + app3Name + "...");
WebApp app5 = createWebApp(app5Name, plan1);
System.out.println("Created web app " + app5.name());
Utils.print(app5);
//============================================================
// Create a traffic manager
System.out.println("Creating a traffic manager " + tmName + " for the web apps...");
TrafficManagerProfile trafficManager = azure.trafficManagerProfiles().define(tmName).withExistingResourceGroup(RG_NAME).withLeafDomainLabel(tmName).withTrafficRoutingMethod(TrafficRoutingMethod.PRIORITY).defineAzureTargetEndpoint("endpoint1").toResourceId(app1.id()).withRoutingPriority(1).attach().defineAzureTargetEndpoint("endpoint2").toResourceId(app2.id()).withRoutingPriority(2).attach().defineAzureTargetEndpoint("endpoint3").toResourceId(app3.id()).withRoutingPriority(3).attach().create();
System.out.println("Created traffic manager " + trafficManager.name());
Utils.print(trafficManager);
//============================================================
// Scale up the app service plans
System.out.println("Scaling up app service plan " + plan1Name + "...");
plan1.update().withCapacity(plan1.capacity() * 2).apply();
System.out.println("Scaled up app service plan " + plan1Name);
Utils.print(plan1);
System.out.println("Scaling up app service plan " + plan2Name + "...");
plan2.update().withCapacity(plan2.capacity() * 2).apply();
System.out.println("Scaled up app service plan " + plan2Name);
Utils.print(plan2);
System.out.println("Scaling up app service plan " + plan3Name + "...");
plan3.update().withCapacity(plan3.capacity() * 2).apply();
System.out.println("Scaled up app service plan " + plan3Name);
Utils.print(plan3);
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + RG_NAME);
azure.resourceGroups().beginDeleteByName(RG_NAME);
System.out.println("Deleted Resource Group: " + RG_NAME);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-sdk-for-java by Azure.
the class ManageWebAppSourceControl method runSample.
/**
* 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) {
// New resources
final String suffix = ".azurewebsites.net";
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
final String app4Name = SdkContext.randomResourceName("webapp4-", 20);
final String app1Url = app1Name + suffix;
final String app2Url = app2Name + suffix;
final String app3Url = app3Name + suffix;
final String app4Url = app4Name + suffix;
final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
try {
//============================================================
// Create a web app with a new app service plan
System.out.println("Creating web app " + app1Name + " in resource group " + rgName + "...");
WebApp app1 = azure.webApps().define(app1Name).withRegion(Region.US_WEST).withNewResourceGroup(rgName).withNewWindowsPlan(PricingTier.STANDARD_S1).withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).create();
System.out.println("Created web app " + app1.name());
Utils.print(app1);
//============================================================
// Deploy to app 1 through FTP
System.out.println("Deploying helloworld.war to " + app1Name + " through FTP...");
Utils.uploadFileToFtp(app1.getPublishingProfile(), "helloworld.war", ManageWebAppSourceControl.class.getResourceAsStream("/helloworld.war"));
System.out.println("Deployment helloworld.war to web app " + app1.name() + " completed");
Utils.print(app1);
// warm up
System.out.println("Warming up " + app1Url + "/helloworld...");
curl("http://" + app1Url + "/helloworld");
Thread.sleep(5000);
System.out.println("CURLing " + app1Url + "/helloworld...");
System.out.println(curl("http://" + app1Url + "/helloworld"));
//============================================================
// Create a second web app with local git source control
System.out.println("Creating another web app " + app2Name + " in resource group " + rgName + "...");
AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
WebApp app2 = azure.webApps().define(app2Name).withExistingWindowsPlan(plan).withExistingResourceGroup(rgName).withLocalGitSourceControl().withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).create();
System.out.println("Created web app " + app2.name());
Utils.print(app2);
//============================================================
// Deploy to app 2 through local Git
System.out.println("Deploying a local Tomcat source to " + app2Name + " through Git...");
PublishingProfile profile = app2.getPublishingProfile();
Git git = Git.init().setDirectory(new File(ManageWebAppSourceControl.class.getResource("/azure-samples-appservice-helloworld/").getPath())).call();
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
PushCommand command = git.push();
command.setRemote(profile.gitUrl());
command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(profile.gitUsername(), profile.gitPassword()));
command.setRefSpecs(new RefSpec("master:master"));
command.setForce(true);
command.call();
System.out.println("Deployment to web app " + app2.name() + " completed");
Utils.print(app2);
// warm up
System.out.println("Warming up " + app2Url + "/helloworld...");
curl("http://" + app2Url + "/helloworld");
Thread.sleep(5000);
System.out.println("CURLing " + app2Url + "/helloworld...");
System.out.println(curl("http://" + app2Url + "/helloworld"));
//============================================================
// Create a 3rd web app with a public GitHub repo in Azure-Samples
System.out.println("Creating another web app " + app3Name + "...");
WebApp app3 = azure.webApps().define(app3Name).withExistingWindowsPlan(plan).withNewResourceGroup(rgName).defineSourceControl().withPublicGitRepository("https://github.com/Azure-Samples/app-service-web-dotnet-get-started").withBranch("master").attach().create();
System.out.println("Created web app " + app3.name());
Utils.print(app3);
// warm up
System.out.println("Warming up " + app3Url + "...");
curl("http://" + app3Url);
Thread.sleep(5000);
System.out.println("CURLing " + app3Url + "...");
System.out.println(curl("http://" + app3Url));
//============================================================
// Create a 4th web app with a personal GitHub repo and turn on continuous integration
System.out.println("Creating another web app " + app4Name + "...");
WebApp app4 = azure.webApps().define(app4Name).withExistingWindowsPlan(plan).withExistingResourceGroup(rgName).create();
System.out.println("Created web app " + app4.name());
Utils.print(app4);
// warm up
System.out.println("Warming up " + app4Url + "...");
curl("http://" + app4Url);
Thread.sleep(5000);
System.out.println("CURLing " + app4Url + "...");
System.out.println(curl("http://" + app4Url));
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-sdk-for-java by Azure.
the class ManageWebAppSourceControlAsync method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(final Azure azure) {
// New resources
final String suffix = ".azurewebsites.net";
final String app1Name = SdkContext.randomResourceName("webapp1-", 20);
final String app2Name = SdkContext.randomResourceName("webapp2-", 20);
final String app3Name = SdkContext.randomResourceName("webapp3-", 20);
final String app4Name = SdkContext.randomResourceName("webapp4-", 20);
final String app1Url = app1Name + suffix;
final String app2Url = app2Name + suffix;
final String app3Url = app3Name + suffix;
final String app4Url = app4Name + suffix;
final String planName = SdkContext.randomResourceName("jplan_", 15);
final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
try {
//============================================================
// Create a web app with a new app service plan
System.out.println("Creating web app " + app1Name + " in resource group " + rgName + "...");
Observable<?> app1Observable = azure.webApps().define(app1Name).withRegion(Region.US_WEST).withNewResourceGroup(rgName).withNewWindowsPlan(PricingTier.STANDARD_S1).withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).createAsync().flatMap(new Func1<Indexable, Observable<?>>() {
@Override
public Observable<?> call(Indexable indexable) {
if (indexable instanceof WebApp) {
WebApp app = (WebApp) indexable;
System.out.println("Created web app " + app.name());
return Observable.merge(Observable.just(indexable), app.getPublishingProfileAsync().map(new Func1<PublishingProfile, PublishingProfile>() {
@Override
public PublishingProfile call(PublishingProfile publishingProfile) {
System.out.println("Deploying helloworld.war to " + app1Name + " through FTP...");
Utils.uploadFileToFtp(publishingProfile, "helloworld.war", ManageWebAppSourceControlAsync.class.getResourceAsStream("/helloworld.war"));
System.out.println("Deployment helloworld.war to web app " + app1Name + " completed");
return publishingProfile;
}
}));
}
return Observable.just(indexable);
}
});
System.out.println("Creating another web app " + app2Name + " in resource group " + rgName + "...");
System.out.println("Creating another web app " + app3Name + "...");
System.out.println("Creating another web app " + app4Name + "...");
Observable<?> app234Observable = azure.appServices().appServicePlans().getByResourceGroupAsync(rgName, planName).flatMap(new Func1<AppServicePlan, Observable<Indexable>>() {
@Override
public Observable<Indexable> call(AppServicePlan plan) {
return Observable.merge(azure.webApps().define(app2Name).withExistingWindowsPlan(plan).withExistingResourceGroup(rgName).withLocalGitSourceControl().withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).createAsync(), azure.webApps().define(app3Name).withExistingWindowsPlan(plan).withNewResourceGroup(rgName).defineSourceControl().withPublicGitRepository("https://github.com/Azure-Samples/app-service-web-dotnet-get-started").withBranch("master").attach().createAsync(), azure.webApps().define(app4Name).withExistingWindowsPlan(plan).withExistingResourceGroup(rgName).createAsync());
}
}).flatMap(new Func1<Indexable, Observable<?>>() {
@Override
public Observable<?> call(Indexable indexable) {
if (indexable instanceof WebApp) {
WebApp app = (WebApp) indexable;
System.out.println("Created web app " + app.name());
if (!app.name().equals(app2Name)) {
return Observable.just(indexable);
}
// for the second web app Deploy a local Tomcat
return app.getPublishingProfileAsync().map(new Func1<PublishingProfile, PublishingProfile>() {
@Override
public PublishingProfile call(PublishingProfile profile) {
System.out.println("Deploying a local Tomcat source to " + app2Name + " through Git...");
Git git = null;
try {
git = Git.init().setDirectory(new File(ManageWebAppSourceControlAsync.class.getResource("/azure-samples-appservice-helloworld/").getPath())).call();
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
PushCommand command = git.push();
command.setRemote(profile.gitUrl());
command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(profile.gitUsername(), profile.gitPassword()));
command.setRefSpecs(new RefSpec("master:master"));
command.setForce(true);
command.call();
} catch (GitAPIException e) {
e.printStackTrace();
}
System.out.println("Deployment to web app " + app2Name + " completed");
return profile;
}
});
}
return Observable.just(indexable);
}
});
Observable.merge(app1Observable, app234Observable).toBlocking().subscribe();
// warm up
System.out.println("Warming up " + app1Url + "/helloworld...");
curl("http://" + app1Url + "/helloworld");
System.out.println("Warming up " + app2Url + "/helloworld...");
curl("http://" + app2Url + "/helloworld");
System.out.println("Warming up " + app3Url + "...");
curl("http://" + app3Url);
System.out.println("Warming up " + app4Url + "...");
curl("http://" + app4Url);
Thread.sleep(5000);
System.out.println("CURLing " + app1Url + "/helloworld...");
System.out.println(curl("http://" + app1Url + "/helloworld"));
System.out.println("CURLing " + app2Url + "/helloworld...");
System.out.println(curl("http://" + app2Url + "/helloworld"));
System.out.println("CURLing " + app3Url + "...");
System.out.println(curl("http://" + app3Url));
System.out.println("CURLing " + app4Url + "...");
System.out.println(curl("http://" + app4Url));
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByNameAsync(rgName).toBlocking().subscribe();
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
Aggregations