Search in sources :

Example 1 with CdnProfile

use of com.microsoft.azure.management.cdn.CdnProfile in project azure-sdk-for-java by Azure.

the class ManageCdn 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 resourceGroupName = Utils.createRandomName("rg");
    final String cdnProfileName = Utils.createRandomName("cdnStandardProfile");
    String[] appNames = new String[8];
    try {
        // ============================================================
        // Create a resource group for holding all the created resources
        azure.resourceGroups().define(resourceGroupName).withRegion(Region.US_CENTRAL).create();
        // Create 8 websites
        for (int i = 0; i < 8; i++) {
            appNames[i] = SdkContext.randomResourceName("webapp" + (i + 1) + "-", 20);
        }
        // 2 in US
        createWebApp(appNames[0], Region.US_WEST, azure, resourceGroupName);
        createWebApp(appNames[1], Region.US_EAST, azure, resourceGroupName);
        // 2 in EU
        createWebApp(appNames[2], Region.EUROPE_WEST, azure, resourceGroupName);
        createWebApp(appNames[3], Region.EUROPE_NORTH, azure, resourceGroupName);
        // 2 in Southeast
        createWebApp(appNames[4], Region.ASIA_SOUTHEAST, azure, resourceGroupName);
        createWebApp(appNames[5], Region.AUSTRALIA_SOUTHEAST, azure, resourceGroupName);
        // 1 in Brazil
        createWebApp(appNames[6], Region.BRAZIL_SOUTH, azure, resourceGroupName);
        // 1 in Japan
        createWebApp(appNames[7], Region.JAPAN_WEST, azure, resourceGroupName);
        // =======================================================================================
        // Create CDN profile using Standard Verizon SKU with endpoints in each region of Web apps.
        System.out.println("Creating a CDN Profile");
        // Create CDN Profile definition object that will let us do a for loop
        // to define all 8 endpoints and then parallelize their creation
        CdnProfile.DefinitionStages.WithStandardCreate profileDefinition = azure.cdnProfiles().define(cdnProfileName).withRegion(Region.US_CENTRAL).withExistingResourceGroup(resourceGroupName).withStandardVerizonSku();
        // Define all the endpoints. We need to keep track of the last creatable stage
        // to be able to call create on the entire Cdn profile deployment definition.
        Creatable<CdnProfile> cdnCreatable = null;
        for (String webSite : appNames) {
            cdnCreatable = profileDefinition.defineNewEndpoint().withOrigin(webSite + SUFFIX).withHostHeader(webSite + SUFFIX).withCompressionEnabled(true).withContentTypeToCompress("application/javascript").withQueryStringCachingBehavior(QueryStringCachingBehavior.IGNORE_QUERY_STRING).attach();
        }
        // Create profile and then all the defined endpoints in parallel
        CdnProfile profile = cdnCreatable.create();
        // =======================================================================================
        // Load some content (referenced by Web Apps) to the CDN endpoints.
        Set<String> contentToLoad = new HashSet<>();
        contentToLoad.add("/server.js");
        contentToLoad.add("/pictures/microsoft_logo.png");
        for (CdnEndpoint endpoint : profile.endpoints().values()) {
            endpoint.loadContent(contentToLoad);
        }
        return true;
    } catch (Exception f) {
        System.out.println(f.getMessage());
        f.printStackTrace();
    } finally {
        if (azure.resourceGroups().getByName(resourceGroupName) != null) {
            System.out.println("Deleting Resource Group: " + resourceGroupName);
            azure.resourceGroups().deleteByName(resourceGroupName);
            System.out.println("Deleted Resource Group: " + resourceGroupName);
        } else {
            System.out.println("Did not create any resources in Azure. No clean up is necessary");
        }
    }
    return false;
}
Also used : CdnProfile(com.microsoft.azure.management.cdn.CdnProfile) CdnEndpoint(com.microsoft.azure.management.cdn.CdnEndpoint) CdnEndpoint(com.microsoft.azure.management.cdn.CdnEndpoint) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with CdnProfile

use of com.microsoft.azure.management.cdn.CdnProfile in project azure-sdk-for-java by Azure.

the class TestCdnCrud method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    final String cdnStandardProfileName = TestCdnCrud.createRandomName("cdnStandardProfile");
    final String cdnPremiumProfileName = TestCdnCrud.createRandomName("cdnPremiumProfile");
    final String cdnEndpointName = "endpoint-f3757d2a3e10";
    final String cdnPremiumEndpointName = "premiumVerizonEndpointFluentTest";
    final String rgName = TestCdnCrud.createRandomName("rgRCCDN");
    try {
        final File credFile = new File("D:/my.azureauth");
        Azure azure = Azure.configure().withLogLevel(LogLevel.BASIC).authenticate(credFile).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        try {
            // ============================================================
            // Create a Cdn profile
            System.out.println("Creating a CDN Profile");
            CdnProfile standardProfile = azure.cdnProfiles().define(cdnStandardProfileName).withRegion(Region.US_CENTRAL).withNewResourceGroup(rgName).withStandardAkamaiSku().withNewEndpoint("supername.cloudapp.net").defineNewEndpoint("akamiEndpointWithoutMuchProperties").withOrigin("originSuperName", "storageforazdevextest.blob.core.windows.net").attach().defineNewEndpoint(cdnEndpointName, "mylinuxapp.azurewebsites.net").withContentTypeToCompress("powershell/pain").withGeoFilter("/path/videos", GeoFilterActions.BLOCK, CountryIsoCode.ARGENTINA).withGeoFilter("/path/images", GeoFilterActions.BLOCK, CountryIsoCode.BELGIUM).withContentTypeToCompress("text/plain").withCompressionEnabled(true).withQueryStringCachingBehavior(QueryStringCachingBehavior.BYPASS_CACHING).withHttpsAllowed(true).withHttpsPort(444).withHttpAllowed(true).withHttpPort(85).withCustomDomain("sdk-1-f3757d2a3e10.azureedge-test.net").withCustomDomain("sdk-2-f3757d2a3e10.azureedge-test.net").attach().create();
            CdnProfile premiumProfile = azure.cdnProfiles().define(cdnPremiumProfileName).withRegion(Region.US_CENTRAL).withNewResourceGroup(rgName).withPremiumVerizonSku().withNewPremiumEndpoint("someweirdname.blob.core.windows.net").defineNewPremiumEndpoint("supermuperep1").withPremiumOrigin("originPremium", "xplattestvmss1sto0575014.blob.core.windows.net").attach().defineNewPremiumEndpoint(cdnPremiumEndpointName).withPremiumOrigin("supername.cloudapp.net").withHttpAllowed(true).withHttpsAllowed(true).withHttpsPort(12).withHttpPort(123).attach().create();
            CdnProfile profileRead = standardProfile.refresh();
            profileRead = azure.cdnProfiles().getById(standardProfile.id());
            if (profileRead.endpoints().size() != 3 || profileRead.endpoints().get(cdnEndpointName).customDomains().size() != 2) {
                System.out.println("cdnProfiles().getById should retrieve endpoints and custom domains as well.");
            }
            for (CdnEndpoint endpoint : profileRead.endpoints().values()) {
                System.out.println("CDN Endpoint: " + endpoint.name());
                System.out.println("EP Hostname: " + endpoint.hostName());
                System.out.println("EP Origin hostname: " + endpoint.originHostName());
                System.out.println("EP optimization type: " + endpoint.optimizationType());
                System.out.println("EP Origin host header: " + endpoint.originHostHeader());
                System.out.println("EP Origin path: " + endpoint.originPath());
                for (String customDomain : endpoint.customDomains()) {
                    System.out.println("EP custom domain: " + customDomain);
                }
            }
            if (!standardProfile.isPremiumVerizon()) {
                standardProfile.update().withTag("provider", "Akamai").withNewEndpoint("www.somewebsite.com").defineNewEndpoint("somenewnamefortheendpoint").withOrigin("www.someotherwebsite.com").withGeoFilter("/path/music", GeoFilterActions.BLOCK, CountryIsoCode.ESTONIA).attach().updateEndpoint(cdnEndpointName).withoutGeoFilters().withHttpAllowed(true).withHttpPort(1111).withoutCustomDomain("sdk-2-f3757d2a3e10.azureedge-test.net").parent().apply();
            }
            premiumProfile.update().withTag("provider", "Verizon").withNewPremiumEndpoint("xplattestvmss1sto0575014.blob.core.windows.net").defineNewPremiumEndpoint("supermuperep3").withPremiumOrigin("xplattestvmss1sto0575014.blob.core.windows.net").attach().updatePremiumEndpoint(cdnPremiumEndpointName).withHttpsAllowed(true).withHttpsPort(1111).parent().withoutEndpoint("supermuperep1").apply();
            String ssoUri = premiumProfile.generateSsoUri();
            System.out.println("Standard Akamai Endpoints: " + standardProfile.endpoints().size());
            CdnEndpoint standardEp = standardProfile.endpoints().get(cdnEndpointName);
            CustomDomainValidationResult validationResult = standardEp.validateCustomDomain("sdk-2-f3757d2a3e10.azureedge-test.net");
            standardProfile.stopEndpoint(standardEp.name());
            standardEp.start();
        } catch (Exception f) {
            System.out.println(f.getMessage());
            f.printStackTrace();
        } finally {
            if (azure.resourceGroups().getByName(rgName) != null) {
                System.out.println("Deleting Resource Group: " + rgName);
                azure.resourceGroups().deleteByName(rgName);
                System.out.println("Deleted Resource Group: " + rgName);
            } else {
                System.out.println("Did not create any resources in Azure. No clean up is necessary");
            }
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : CdnProfile(com.microsoft.azure.management.cdn.CdnProfile) CdnEndpoint(com.microsoft.azure.management.cdn.CdnEndpoint) CustomDomainValidationResult(com.microsoft.azure.management.cdn.CustomDomainValidationResult) File(java.io.File)

Example 3 with CdnProfile

use of com.microsoft.azure.management.cdn.CdnProfile in project azure-sdk-for-java by Azure.

the class TestCdn method createResource.

@Override
public CdnProfile createResource(CdnProfiles profiles) throws Exception {
    final Region region = Region.US_EAST;
    final String groupName = "rg" + this.testId;
    final String cdnProfileName = "cdnProfile" + this.testId;
    final String cdnEndpointName = "cdnEndpoint" + this.testId;
    final String cdnOriginHostName = "mylinuxapp.azurewebsites.net";
    CdnProfile cdnProfile = profiles.define(cdnProfileName).withRegion(region).withNewResourceGroup(groupName).withStandardAkamaiSku().defineNewEndpoint(cdnEndpointName).withOrigin(cdnOriginHostName).withGeoFilter("/path/videos", GeoFilterActions.BLOCK, CountryIsoCode.ARGENTINA).withGeoFilter("/path/images", GeoFilterActions.BLOCK, CountryIsoCode.BELGIUM).withContentTypeToCompress("text/plain").withCompressionEnabled(true).withQueryStringCachingBehavior(QueryStringCachingBehavior.BYPASS_CACHING).withHttpsAllowed(true).withHttpsPort(444).withHttpAllowed(false).withHttpPort(85).attach().create();
    Assert.assertTrue(cdnProfile.sku().name().equals(SkuName.STANDARD_AKAMAI));
    Assert.assertNotNull(cdnProfile.endpoints());
    Assert.assertEquals(1, cdnProfile.endpoints().size());
    CdnEndpoint endpoint = cdnProfile.endpoints().get(cdnEndpointName);
    Assert.assertNotNull(endpoint);
    Assert.assertEquals(cdnOriginHostName, endpoint.originHostName());
    Assert.assertEquals(444, endpoint.httpsPort());
    Assert.assertEquals(85, endpoint.httpPort());
    Assert.assertFalse(endpoint.isHttpAllowed());
    Assert.assertTrue(endpoint.isHttpsAllowed());
    Assert.assertTrue(endpoint.isCompressionEnabled());
    Assert.assertEquals(QueryStringCachingBehavior.BYPASS_CACHING, endpoint.queryStringCachingBehavior());
    Assert.assertNotNull(endpoint.geoFilters());
    Assert.assertEquals(QueryStringCachingBehavior.BYPASS_CACHING, endpoint.queryStringCachingBehavior());
    for (ResourceUsage usage : profiles.listResourceUsage()) {
        Assert.assertNotNull(usage);
        Assert.assertEquals("profile", usage.resourceType());
    }
    for (EdgeNode node : profiles.listEdgeNodes()) {
        Assert.assertNotNull(node);
    }
    for (ResourceUsage usage : cdnProfile.listResourceUsage()) {
        Assert.assertNotNull(usage);
        Assert.assertEquals("endpoint", usage.resourceType());
    }
    for (CdnEndpoint ep : cdnProfile.endpoints().values()) {
        for (ResourceUsage usage : ep.listResourceUsage()) {
            Assert.assertNotNull(usage);
            Assert.assertTrue("customdomain".equals(usage.resourceType()) || "geofilter".equals(usage.resourceType()));
        }
    }
    return cdnProfile;
}
Also used : CdnProfile(com.microsoft.azure.management.cdn.CdnProfile) CdnEndpoint(com.microsoft.azure.management.cdn.CdnEndpoint) ResourceUsage(com.microsoft.azure.management.cdn.ResourceUsage) EdgeNode(com.microsoft.azure.management.cdn.EdgeNode) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region)

Aggregations

CdnEndpoint (com.microsoft.azure.management.cdn.CdnEndpoint)3 CdnProfile (com.microsoft.azure.management.cdn.CdnProfile)3 CustomDomainValidationResult (com.microsoft.azure.management.cdn.CustomDomainValidationResult)1 EdgeNode (com.microsoft.azure.management.cdn.EdgeNode)1 ResourceUsage (com.microsoft.azure.management.cdn.ResourceUsage)1 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1