Search in sources :

Example 1 with AppServiceDomain

use of com.microsoft.azure.management.appservice.AppServiceDomain 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)

Example 2 with AppServiceDomain

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

the class ManageLinuxWebAppWithDomainSsl 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).withNewLinuxPlan(PricingTier.STANDARD_S1).withBuiltInImage(RuntimeStack.NODEJS_6_9_3).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).withExistingLinuxPlan(plan).withExistingResourceGroup(rgName).withBuiltInImage(RuntimeStack.NODEJS_6_9_3).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 = ManageLinuxWebAppWithDomainSsl.class.getResource("/").getPath() + app2Name + "." + domainName + ".pfx";
        String cerPath = ManageLinuxWebAppWithDomainSsl.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).withExistingCertificate(app1.hostNameSslStates().get(app1Name + "." + domainName).thumbprint()).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)

Example 3 with AppServiceDomain

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

the class ManageFunctionAppWithDomainSsl 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 function app with a new app service plan
        System.out.println("Creating function app " + app1Name + "...");
        FunctionApp app1 = azure.appServices().functionApps().define(app1Name).withRegion(Region.US_WEST).withNewResourceGroup(rgName).create();
        System.out.println("Created function app " + app1.name());
        Utils.print(app1);
        //============================================================
        // Create a second function app with the same app service plan
        System.out.println("Creating another function app " + app2Name + "...");
        FunctionApp app2 = azure.appServices().functionApps().define(app2Name).withRegion(Region.US_WEST).withExistingResourceGroup(rgName).create();
        System.out.println("Created function 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 function app 1
        System.out.println("Binding http://" + app1Name + "." + domainName + " to function app " + app1Name + "...");
        app1 = app1.update().defineHostnameBinding().withAzureManagedDomain(domain).withSubDomain(app1Name).withDnsRecordType(CustomHostNameDnsRecordType.CNAME).attach().apply();
        System.out.println("Finished binding http://" + app1Name + "." + domainName + " to function app " + app1Name);
        Utils.print(app1);
        //============================================================
        // Create a self-singed SSL certificate
        String pfxPath = ManageFunctionAppWithDomainSsl.class.getResource("/").getPath() + app2Name + "." + domainName + ".pfx";
        String cerPath = ManageFunctionAppWithDomainSsl.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 function app 2 and turn on wild card SSL for both
        System.out.println("Binding https://" + app1Name + "." + domainName + " to function 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 function app " + app1Name);
        Utils.print(app1);
        System.out.println("Binding https://" + app2Name + "." + domainName + " to function 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 function 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 : FunctionApp(com.microsoft.azure.management.appservice.FunctionApp) File(java.io.File) AppServiceDomain(com.microsoft.azure.management.appservice.AppServiceDomain)

Example 4 with AppServiceDomain

use of com.microsoft.azure.management.appservice.AppServiceDomain 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)

Aggregations

AppServiceDomain (com.microsoft.azure.management.appservice.AppServiceDomain)4 File (java.io.File)4 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)3 WebApp (com.microsoft.azure.management.appservice.WebApp)3 FunctionApp (com.microsoft.azure.management.appservice.FunctionApp)1 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1 TrafficManagerProfile (com.microsoft.azure.management.trafficmanager.TrafficManagerProfile)1 ArrayList (java.util.ArrayList)1