Search in sources :

Example 6 with AppServicePlan

use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-tools-for-java by Microsoft.

the class AppServiceCreateDialog method fillAppServicePlans.

protected void fillAppServicePlans() {
    int i = comboSubscription.getSelectionIndex();
    if (i < 0) {
        // empty
        System.out.println("No subscription is selected");
        return;
    }
    List<ResourceGroup> rgl = AzureModel.getInstance().getSubscriptionToResourceGroupMap().get(binderSubscriptionDetails.get(i));
    if (rgl == null) {
        System.out.println("rgl is null");
        return;
    }
    comboAppServicePlan.removeAll();
    binderAppServicePlan = new ArrayList<AppServicePlan>();
    for (ResourceGroup rg : rgl) {
        List<AppServicePlan> aspl = AzureModel.getInstance().getResourceGroupToAppServicePlanMap().get(rg);
        for (AppServicePlan asp : aspl) {
            if (asp.pricingTier().toSkuDescription().tier().compareToIgnoreCase("dynamic") == 0) {
                continue;
            }
            binderAppServicePlan.add(asp);
            comboAppServicePlan.add(asp.name());
        }
    }
    if (comboAppServicePlan.getItemCount() > 0) {
        comboAppServicePlan.select(0);
    }
}
Also used : ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan)

Example 7 with AppServicePlan

use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method doFillTable.

private void doFillTable() {
    Map<SubscriptionDetail, List<ResourceGroup>> srgMap = AzureModel.getInstance().getSubscriptionToResourceGroupMap();
    Map<ResourceGroup, List<WebApp>> rgwaMap = AzureModel.getInstance().getResourceGroupToWebAppMap();
    Map<ResourceGroup, List<AppServicePlan>> rgaspMap = AzureModel.getInstance().getResourceGroupToAppServicePlanMap();
    webAppDetailsMap.clear();
    table.removeAll();
    for (SubscriptionDetail sd : srgMap.keySet()) {
        if (!sd.isSelected())
            continue;
        Map<String, WebAppUtils.AspDetails> aspMap = new HashMap<>();
        for (ResourceGroup rg : srgMap.get(sd)) {
            for (AppServicePlan asp : rgaspMap.get(rg)) {
                aspMap.put(asp.id(), new WebAppUtils.AspDetails(asp, rg));
            }
        }
        for (ResourceGroup rg : srgMap.get(sd)) {
            for (WebApp wa : rgwaMap.get(rg)) {
                TableItem item = new TableItem(table, SWT.NULL);
                if (wa.javaVersion() != JavaVersion.OFF) {
                    item.setText(new String[] { wa.name(), wa.javaVersion().toString(), wa.javaContainer() + " " + wa.javaContainerVersion(), wa.resourceGroupName() });
                } else {
                    item.setText(new String[] { wa.name(), "Off", "N/A", wa.resourceGroupName() });
                }
                WebAppDetails webAppDetails = new WebAppDetails();
                webAppDetails.webApp = wa;
                webAppDetails.subscriptionDetail = sd;
                webAppDetails.resourceGroup = rg;
                webAppDetails.appServicePlan = aspMap.get(wa.appServicePlanId()).getAsp();
                webAppDetails.appServicePlanResourceGroup = aspMap.get(wa.appServicePlanId()).getRg();
                webAppDetailsMap.put(wa.name(), webAppDetails);
            }
        }
    }
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) HashMap(java.util.HashMap) TableItem(org.eclipse.swt.widgets.TableItem) WebAppUtils(com.microsoft.azuretools.utils.WebAppUtils) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) List(java.util.List) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 8 with AppServicePlan

use of com.microsoft.azure.management.appservice.AppServicePlan in project azure-sdk-for-java by Azure.

the class ManageTrafficManager 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) {
    final String rgName = SdkContext.randomResourceName("rgNEMV_", 24);
    final String domainName = SdkContext.randomResourceName("jsdkdemo-", 20) + ".com";
    final String certPassword = "StrongPass!12";
    final String appServicePlanNamePrefix = SdkContext.randomResourceName("jplan1_", 15);
    final String webAppNamePrefix = SdkContext.randomResourceName("webapp1-", 20);
    final String tmName = SdkContext.randomResourceName("jsdktm-", 20);
    final List<Region> regions = new ArrayList<>();
    // The regions in which web app needs to be created
    //
    regions.add(Region.US_WEST2);
    regions.add(Region.US_EAST2);
    regions.add(Region.ASIA_EAST);
    regions.add(Region.INDIA_WEST);
    regions.add(Region.US_CENTRAL);
    try {
        azure.resourceGroups().define(rgName).withRegion(Region.US_WEST).create();
        //============================================================
        // 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);
        //============================================================
        // Create a self-singed SSL certificate
        String pfxPath = ManageTrafficManager.class.getResource("/").getPath() + webAppNamePrefix + "." + domainName + ".pfx";
        String cerPath = ManageTrafficManager.class.getResource("/").getPath() + webAppNamePrefix + "." + domainName + ".cer";
        System.out.println("Creating a self-signed certificate " + pfxPath + "...");
        Utils.createCertificate(cerPath, pfxPath, domainName, certPassword, "*." + domainName);
        //============================================================
        // Creates app service in 5 different region
        List<AppServicePlan> appServicePlans = new ArrayList<>();
        int id = 0;
        for (Region region : regions) {
            String planName = appServicePlanNamePrefix + id;
            System.out.println("Creating an app service plan " + planName + " in region " + region + "...");
            AppServicePlan appServicePlan = azure.appServices().appServicePlans().define(planName).withRegion(region).withExistingResourceGroup(rgName).withPricingTier(PricingTier.BASIC_B1).withOperatingSystem(OperatingSystem.WINDOWS).create();
            System.out.println("Created app service plan " + planName);
            Utils.print(appServicePlan);
            appServicePlans.add(appServicePlan);
            id++;
        }
        //============================================================
        // Creates websites using previously created plan
        List<WebApp> webApps = new ArrayList<>();
        id = 0;
        for (AppServicePlan appServicePlan : appServicePlans) {
            String webAppName = webAppNamePrefix + id;
            System.out.println("Creating a web app " + webAppName + " using the plan " + appServicePlan.name() + "...");
            WebApp webApp = azure.webApps().define(webAppName).withExistingWindowsPlan(appServicePlan).withExistingResourceGroup(rgName).withManagedHostnameBindings(domain, webAppName).defineSslBinding().forHostname(webAppName + "." + domain.name()).withPfxCertificateToUpload(new File(pfxPath), certPassword).withSniBasedSsl().attach().defineSourceControl().withPublicGitRepository("https://github.com/jianghaolu/azure-site-test").withBranch("master").attach().create();
            System.out.println("Created web app " + webAppName);
            Utils.print(webApp);
            webApps.add(webApp);
            id++;
        }
        //============================================================
        // Creates a traffic manager profile
        System.out.println("Creating a traffic manager profile " + tmName + " for the web apps...");
        TrafficManagerProfile.DefinitionStages.WithEndpoint tmDefinition = azure.trafficManagerProfiles().define(tmName).withExistingResourceGroup(rgName).withLeafDomainLabel(tmName).withPriorityBasedRouting();
        Creatable<TrafficManagerProfile> tmCreatable = null;
        int priority = 1;
        for (WebApp webApp : webApps) {
            tmCreatable = tmDefinition.defineAzureTargetEndpoint("endpoint-" + priority).toResourceId(webApp.id()).withRoutingPriority(priority).attach();
            priority++;
        }
        TrafficManagerProfile trafficManagerProfile = tmCreatable.create();
        System.out.println("Created traffic manager " + trafficManagerProfile.name());
        Utils.print(trafficManagerProfile);
        //============================================================
        // Disables one endpoint and removes another endpoint
        System.out.println("Disabling and removing endpoint...");
        trafficManagerProfile = trafficManagerProfile.update().updateAzureTargetEndpoint("endpoint-1").withTrafficDisabled().parent().withoutEndpoint("endpoint-2").apply();
        System.out.println("Endpoints updated");
        //============================================================
        // Enables an endpoint
        System.out.println("Enabling endpoint...");
        trafficManagerProfile = trafficManagerProfile.update().updateAzureTargetEndpoint("endpoint-1").withTrafficEnabled().parent().apply();
        System.out.println("Endpoint updated");
        Utils.print(trafficManagerProfile);
        //============================================================
        // Change/configure traffic manager routing method
        System.out.println("Changing traffic manager profile routing method...");
        trafficManagerProfile = trafficManagerProfile.update().withPerformanceBasedRouting().apply();
        System.out.println("Changed traffic manager profile routing method");
        //============================================================
        // Disables the traffic manager profile
        System.out.println("Disabling traffic manager profile...");
        trafficManagerProfile.update().withProfileStatusDisabled().apply();
        System.out.println("Traffic manager profile disabled");
        //============================================================
        // Enables the traffic manager profile
        System.out.println("Enabling traffic manager profile...");
        trafficManagerProfile.update().withProfileStatusDisabled().apply();
        System.out.println("Traffic manager profile enabled");
        //============================================================
        // Deletes the traffic manager profile
        System.out.println("Deleting the traffic manger profile...");
        azure.trafficManagerProfiles().deleteById(trafficManagerProfile.id());
        System.out.println("Traffic manager profile deleted");
        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;
}
Also used : TrafficManagerProfile(com.microsoft.azure.management.trafficmanager.TrafficManagerProfile) ArrayList(java.util.ArrayList) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) File(java.io.File) AppServiceDomain(com.microsoft.azure.management.appservice.AppServiceDomain) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 9 with AppServicePlan

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;
}
Also used : Console(java.io.Console) IOException(java.io.IOException) WebApp(com.microsoft.azure.management.appservice.WebApp) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan)

Example 10 with AppServicePlan

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;
}
Also used : File(java.io.File) WebApp(com.microsoft.azure.management.appservice.WebApp) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan) AppServiceDomain(com.microsoft.azure.management.appservice.AppServiceDomain)

Aggregations

AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)24 WebApp (com.microsoft.azure.management.appservice.WebApp)15 File (java.io.File)8 IOException (java.io.IOException)8 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)7 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)6 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)5 Git (org.eclipse.jgit.api.Git)5 PushCommand (org.eclipse.jgit.api.PushCommand)5 RefSpec (org.eclipse.jgit.transport.RefSpec)5 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)5 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)4 AppServiceDomain (com.microsoft.azure.management.appservice.AppServiceDomain)3 FunctionApp (com.microsoft.azure.management.appservice.FunctionApp)3 TrafficManagerProfile (com.microsoft.azure.management.trafficmanager.TrafficManagerProfile)3 HashMap (java.util.HashMap)3 WebAppUtils (com.microsoft.azuretools.utils.WebAppUtils)2 List (java.util.List)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1