Search in sources :

Example 6 with WebApp

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

the class OpenWebappAction method actionPerformed.

@Override
public void actionPerformed(NodeActionEvent e) {
    WebApp webApp = webappNode.getWebApp();
    try {
        //            if (webapp.getWebSitePublishSettings() == null) {
        //                webapp.setWebSitePublishSettings(AzureManagerImpl.getManager(webappNode.getProject()).
        //                        getWebSitePublishSettings(webapp.getSubscriptionId(), webapp.getWebSpaceName(), webapp.getName()));
        //            }
        //            WebSitePublishSettings.PublishProfile profile = webapp.getWebSitePublishSettings().getPublishProfileList().get(0);
        //            if (profile != null) {
        //                String url = profile.getDestinationAppUrl();
        //            if (!chkBoxDeployRoot.isSelected()) {
        //                url = url + "/" + artifactDescriptor.getName();
        //            }
        //        }
        String appServiceLink = "https://" + webApp.defaultHostName();
        Desktop.getDesktop().browse(URI.create(appServiceLink));
    //            } else {
    //                PluginUtil.displayErrorDialog("No publish profile", "No publish profile found");
    //            }
    } catch (IOException e1) {
        PluginUtil.displayErrorDialogAndLog(message("error"), message("error"), e1);
    }
}
Also used : IOException(java.io.IOException) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 7 with WebApp

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

the class RemoteDebugAction method actionPerformed.

@Override
public void actionPerformed(NodeActionEvent e) {
    WebApp webApp = webappNode.getWebApp();
    try {
        // TODO
        RemoteDebuggingClientDialog d = new RemoteDebuggingClientDialog((Project) webappNode.getProject(), webApp);
        d.show();
    } catch (Exception ex) {
        PluginUtil.displayErrorDialogAndLog(message("error"), message("error"), ex);
    }
}
Also used : RemoteDebuggingClientDialog(com.microsoft.azuretools.ijidea.ui.RemoteDebuggingClientDialog) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 8 with WebApp

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

the class ManageCdn method createWebApp.

private static WebApp createWebApp(String appName, Region region, Azure azure, String resourceGroupName) {
    final String appUrl = appName + SUFFIX;
    System.out.println("Creating web app " + appName + " with master branch...");
    WebApp app = azure.webApps().define(appName).withRegion(region).withExistingResourceGroup(resourceGroupName).withNewWindowsPlan(PricingTier.STANDARD_S1).withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).defineSourceControl().withPublicGitRepository("https://github.com/jianghaolu/azure-site-test.git").withBranch("master").attach().create();
    System.out.println("Created web app " + app.name());
    Utils.print(app);
    System.out.println("CURLing " + appUrl + "...");
    System.out.println(curl("http://" + appUrl));
    return app;
}
Also used : WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 9 with WebApp

use of com.microsoft.azure.management.appservice.WebApp 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 10 with WebApp

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

Aggregations

WebApp (com.microsoft.azure.management.appservice.WebApp)32 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)15 IOException (java.io.IOException)12 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)6 File (java.io.File)6 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)5 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)5 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)5 AppServiceDomain (com.microsoft.azure.management.appservice.AppServiceDomain)3 TrafficManagerProfile (com.microsoft.azure.management.trafficmanager.TrafficManagerProfile)3 HashMap (java.util.HashMap)3 List (java.util.List)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 Git (org.eclipse.jgit.api.Git)3 SqlDatabase (com.microsoft.azure.management.sql.SqlDatabase)2 SqlServer (com.microsoft.azure.management.sql.SqlServer)2 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)2 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)2 StorageException (com.microsoft.azure.storage.StorageException)2 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)2