Example usage for org.eclipse.jgit.api PushCommand setForce

List of usage examples for org.eclipse.jgit.api PushCommand setForce

Introduction

In this page you can find the example usage for org.eclipse.jgit.api PushCommand setForce.

Prototype

public PushCommand setForce(boolean force) 

Source Link

Document

Sets the force preference for push operation.

Usage

From source file:com.google.gerrit.acceptance.GitUtil.java

License:Apache License

public static PushResult pushHead(TestRepository<?> testRepo, String ref, boolean pushTags, boolean force)
        throws GitAPIException {
    PushCommand pushCmd = testRepo.git().push();
    pushCmd.setForce(force);
    pushCmd.setRefSpecs(new RefSpec("HEAD:" + ref));
    if (pushTags) {
        pushCmd.setPushTags();//from  w  ww  .  j a va2 s.  com
    }
    Iterable<PushResult> r = pushCmd.call();
    return Iterables.getOnlyElement(r);
}

From source file:com.microsoft.azure.management.appservice.samples.ManageFunctionAppSourceControl.java

License:Open Source License

/**
 * Main function which runs the actual sample.
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 *//* ww w . j a  va2  s.co m*/
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 function app with a new app service plan

        System.out.println("Creating function app " + app1Name + " in resource group " + rgName + "...");

        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);

        //============================================================
        // Deploy to app 1 through FTP

        System.out.println("Deploying a function app to " + app1Name + " through FTP...");

        Utils.uploadFileToFunctionApp(app1.getPublishingProfile(), "host.json",
                ManageFunctionAppSourceControl.class.getResourceAsStream("/square-function-app/host.json"));
        Utils.uploadFileToFunctionApp(app1.getPublishingProfile(), "square/function.json",
                ManageFunctionAppSourceControl.class
                        .getResourceAsStream("/square-function-app/square/function.json"));
        Utils.uploadFileToFunctionApp(app1.getPublishingProfile(), "square/index.js",
                ManageFunctionAppSourceControl.class
                        .getResourceAsStream("/square-function-app/square/index.js"));

        // sync triggers
        app1.syncTriggers();

        System.out.println("Deployment square app to function app " + app1.name() + " completed");
        Utils.print(app1);

        // warm up
        System.out.println("Warming up " + app1Url + "/api/square...");
        post("http://" + app1Url + "/api/square", "625");
        Thread.sleep(5000);
        System.out.println("CURLing " + app1Url + "/api/square...");
        System.out.println("Square of 625 is " + post("http://" + app1Url + "/api/square", "625"));

        //============================================================
        // Create a second function app with local git source control

        System.out
                .println("Creating another function app " + app2Name + " in resource group " + rgName + "...");
        AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
        FunctionApp app2 = azure.appServices().functionApps().define(app2Name).withExistingAppServicePlan(plan)
                .withExistingResourceGroup(rgName).withExistingStorageAccount(app1.storageAccount())
                .withLocalGitSourceControl().create();

        System.out.println("Created function 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(
                        ManageFunctionAppSourceControl.class.getResource("/square-function-app/").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 function app " + app2.name() + " completed");
        Utils.print(app2);

        // warm up
        System.out.println("Warming up " + app2Url + "/api/square...");
        post("http://" + app2Url + "/api/square", "725");
        Thread.sleep(5000);
        System.out.println("CURLing " + app2Url + "/api/square...");
        System.out.println("Square of 725 is " + post("http://" + app2Url + "/api/square", "725"));

        //============================================================
        // Create a 3rd function app with a public GitHub repo in Azure-Samples

        System.out.println("Creating another function app " + app3Name + "...");
        FunctionApp app3 = azure.appServices().functionApps().define(app3Name).withExistingAppServicePlan(plan)
                .withNewResourceGroup(rgName).withExistingStorageAccount(app2.storageAccount())
                .defineSourceControl()
                .withPublicGitRepository("https://github.com/jianghaolu/square-function-app-sample")
                .withBranch("master").attach().create();

        System.out.println("Created function app " + app3.name());
        Utils.print(app3);

        // warm up
        System.out.println("Warming up " + app3Url + "/api/square...");
        post("http://" + app3Url + "/api/square", "825");
        Thread.sleep(5000);
        System.out.println("CURLing " + app3Url + "/api/square...");
        System.out.println("Square of 825 is " + post("http://" + app3Url + "/api/square", "825"));

        //============================================================
        // Create a 4th function app with a personal GitHub repo and turn on continuous integration

        System.out.println("Creating another function app " + app4Name + "...");
        FunctionApp app4 = azure.appServices().functionApps().define(app4Name).withExistingAppServicePlan(plan)
                .withExistingResourceGroup(rgName).withExistingStorageAccount(app3.storageAccount())
                // Uncomment the following lines to turn on 4th scenario
                //.defineSourceControl()
                //    .withContinuouslyIntegratedGitHubRepository("username", "reponame")
                //    .withBranch("master")
                //    .withGitHubAccessToken("YOUR GITHUB PERSONAL TOKEN")
                //    .attach()
                .create();

        System.out.println("Created function 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;
}

From source file:com.microsoft.azure.management.appservice.samples.ManageFunctionAppWithAuthentication.java

License:Open Source License

/**
 * Main function which runs the actual sample.
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 *//*from www .  j  av  a  2s. c  om*/
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 app1Url = app1Name + suffix;
    final String app2Url = app2Name + suffix;
    final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);

    try {

        //============================================================
        // Create a function app with admin level auth

        System.out.println("Creating function app " + app1Name + " in resource group " + rgName
                + " with admin level auth...");

        FunctionApp app1 = azure.appServices().functionApps().define(app1Name).withRegion(Region.US_WEST)
                .withNewResourceGroup(rgName).withLocalGitSourceControl().create();

        System.out.println("Created function app " + app1.name());
        Utils.print(app1);

        //============================================================
        // Create a second function app with function level auth

        System.out.println("Creating another function app " + app2Name + " in resource group " + rgName
                + " with function level auth...");
        AppServicePlan plan = azure.appServices().appServicePlans().getById(app1.appServicePlanId());
        FunctionApp app2 = azure.appServices().functionApps().define(app2Name).withExistingAppServicePlan(plan)
                .withExistingResourceGroup(rgName).withExistingStorageAccount(app1.storageAccount())
                .withLocalGitSourceControl().create();

        System.out.println("Created function app " + app2.name());
        Utils.print(app2);

        //============================================================
        // Deploy to app 1 through Git

        System.out.println("Deploying a local function app to " + app1Name + " through Git...");

        PublishingProfile profile = app1.getPublishingProfile();
        Git git = Git.init().setDirectory(new File(ManageFunctionAppWithAuthentication.class
                .getResource("/square-function-app-admin-auth/").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 function app " + app1.name() + " completed");
        Utils.print(app1);

        // warm up
        System.out.println("Warming up " + app1Url + "/api/square...");
        post("http://" + app1Url + "/api/square", "625");
        Thread.sleep(5000);
        System.out.println("CURLing " + app1Url + "/api/square...");
        System.out.println("Square of 625 is "
                + post("http://" + app1Url + "/api/square?code=" + app1.getMasterKey(), "625"));

        //============================================================
        // Deploy to app 2 through Git

        System.out.println("Deploying a local function app to " + app2Name + " through Git...");

        profile = app2.getPublishingProfile();
        git = Git.init().setDirectory(new File(ManageFunctionAppWithAuthentication.class
                .getResource("/square-function-app-function-auth/").getPath())).call();
        git.add().addFilepattern(".").call();
        git.commit().setMessage("Initial commit").call();
        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 function app " + app2.name() + " completed");
        Utils.print(app2);

        String masterKey = app2.getMasterKey();
        Map<String, String> functionsHeader = new HashMap<>();
        functionsHeader.put("x-functions-key", masterKey);
        String response = curl("http://" + app2Url + "/admin/functions/square/keys", functionsHeader);
        Pattern pattern = Pattern.compile("\"name\":\"default\",\"value\":\"([\\w=/]+)\"");
        Matcher matcher = pattern.matcher(response);
        matcher.find();
        String functionKey = matcher.group(1);

        // warm up
        System.out.println("Warming up " + app2Url + "/api/square...");
        post("http://" + app2Url + "/api/square", "725");
        Thread.sleep(5000);
        System.out.println("CURLing " + app2Url + "/api/square...");
        System.out.println(
                "Square of 725 is " + post("http://" + app2Url + "/api/square?code=" + functionKey, "725"));

        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;
}

From source file:com.microsoft.azure.management.appservice.samples.ManageLinuxWebAppSourceControl.java

License:Open Source License

/**
 * Main function which runs the actual sample.
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 *//*from   w w  w.  j a v a  2 s.  co  m*/
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)
                .withNewLinuxPlan(PricingTier.STANDARD_S1).withPublicDockerHubImage("tomcat:8-jre8")
                .withStartUpCommand(
                        "/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"")
                .withAppSetting("PORT", "8080").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.uploadFileToWebApp(app1.getPublishingProfile(), "helloworld.war",
                ManageLinuxWebAppSourceControl.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).withExistingLinuxPlan(plan)
                .withExistingResourceGroup(rgName).withPublicDockerHubImage("tomcat:8-jre8")
                .withStartUpCommand(
                        "/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"")
                .withAppSetting("PORT", "8080").withLocalGitSourceControl().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(ManageLinuxWebAppSourceControl.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).withExistingLinuxPlan(plan).withNewResourceGroup(rgName)
                .withPublicDockerHubImage("tomcat:8-jre8")
                .withStartUpCommand(
                        "/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"")
                .withAppSetting("PORT", "8080").defineSourceControl()
                .withPublicGitRepository("https://github.com/azure-appservice-samples/java-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).withExistingLinuxPlan(plan)
                .withExistingResourceGroup(rgName).withPublicDockerHubImage("tomcat:8-jre8")
                .withStartUpCommand(
                        "/bin/bash -c \"sed -ie 's/appBase=\\\"webapps\\\"/appBase=\\\"\\\\/home\\\\/site\\\\/wwwroot\\\\/webapps\\\"/g' conf/server.xml && catalina.sh run\"")
                .withAppSetting("PORT", "8080")
                // Uncomment the following lines to turn on 4th scenario
                //.defineSourceControl()
                //    .withContinuouslyIntegratedGitHubRepository("username", "reponame")
                //    .withBranch("master")
                //    .withGitHubAccessToken("YOUR GITHUB PERSONAL TOKEN")
                //    .attach()
                .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;
}

From source file:com.microsoft.azure.management.appservice.samples.ManageWebAppSourceControl.java

License:Open Source License

/**
 * Main function which runs the actual sample.
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 *///  w w  w .j ava 2 s  .  c  om
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 app5Name = SdkContext.randomResourceName("webapp5-", 20);
    final String app6Name = SdkContext.randomResourceName("webapp5-", 20);
    final String app7Name = SdkContext.randomResourceName("webapp7-", 20);
    final String app1Url = app1Name + suffix;
    final String app2Url = app2Name + suffix;
    final String app3Url = app3Name + suffix;
    final String app4Url = app4Name + suffix;
    final String app5Url = app5Name + suffix;
    final String app6Url = app6Name + suffix;
    final String app7Url = app7Name + suffix;
    final String rgName = SdkContext.randomResourceName("rg1NEMV_", 24);
    final String rg7Name = SdkContext.randomResourceName("rg7NEMV_", 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.uploadFileToWebApp(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");
        SdkContext.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");
        SdkContext.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);
        SdkContext.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)
                // Uncomment the following lines to turn on 4th scenario
                //.defineSourceControl()
                //    .withContinuouslyIntegratedGitHubRepository("username", "reponame")
                //    .withBranch("master")
                //    .withGitHubAccessToken("YOUR GITHUB PERSONAL TOKEN")
                //    .attach()
                .create();

        System.out.println("Created web app " + app4.name());
        Utils.print(app4);

        // warm up
        System.out.println("Warming up " + app4Url + "...");
        curl("http://" + app4Url);
        SdkContext.sleep(5000);
        System.out.println("CURLing " + app4Url + "...");
        System.out.println(curl("http://" + app4Url));

        //============================================================
        // Create a 5th web app with the existing app service plan

        System.out.println("Creating web app " + app5Name + " in resource group " + rgName + "...");

        WebApp app5 = azure.webApps().define(app5Name).withExistingWindowsPlan(plan)
                .withExistingResourceGroup(rgName).withJavaVersion(JavaVersion.JAVA_8_NEWEST)
                .withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).create();

        System.out.println("Created web app " + app5.name());
        Utils.print(app5);

        //============================================================
        // Deploy to the 5th web app through web deploy

        System.out.println("Deploying helloworld.war to " + app5Name + " through web deploy...");

        app5.deploy().withPackageUri(
                "https://github.com/Azure/azure-libraries-for-java/raw/master/azure-samples/src/main/resources/helloworld.zip")
                .withExistingDeploymentsDeleted(true).execute();

        System.out.println("Deploying coffeeshop.war to " + app5Name + " through web deploy...");

        app5.deploy().withPackageUri(
                "https://github.com/Azure/azure-libraries-for-java/raw/master/azure-samples/src/main/resources/coffeeshop.zip")
                .withExistingDeploymentsDeleted(false).execute();

        System.out.println("Deployments to web app " + app5.name() + " completed");
        Utils.print(app5);

        // warm up
        System.out.println("Warming up " + app5Url + "/helloworld...");
        curl("http://" + app5Url + "/helloworld");
        SdkContext.sleep(5000);
        System.out.println("CURLing " + app5Url + "/helloworld...");
        System.out.println(curl("http://" + app5Url + "/helloworld"));
        System.out.println("CURLing " + app5Url + "/coffeeshop...");
        System.out.println(curl("http://" + app5Url + "/coffeeshop"));

        //============================================================
        // Create a 6th web app with the existing app service plan

        System.out.println("Creating web app " + app6Name + " in resource group " + rgName + "...");

        WebApp app6 = azure.webApps().define(app6Name).withExistingWindowsPlan(plan)
                .withExistingResourceGroup(rgName).withJavaVersion(JavaVersion.JAVA_8_NEWEST)
                .withWebContainer(WebContainer.TOMCAT_8_0_NEWEST).create();

        System.out.println("Created web app " + app6.name());
        Utils.print(app6);

        //============================================================
        // Deploy to the 6th web app through WAR deploy

        System.out.println("Deploying helloworld.war to " + app6Name + " through WAR deploy...");

        app6.update().withAppSetting("SCM_TARGET_PATH", "webapps/helloworld").apply();
        app6.warDeploy(new File(ManageWebAppSourceControl.class.getResource("/helloworld.war").getPath()));

        System.out.println("Deploying coffeeshop.war to " + app6Name + " through WAR deploy...");

        app6.update().withAppSetting("SCM_TARGET_PATH", "webapps/coffeeshop").apply();
        app6.restart();
        app6.warDeploy(new File(ManageWebAppSourceControl.class.getResource("/coffeeshop.war").getPath()));

        System.out.println("Deployments to web app " + app6.name() + " completed");
        Utils.print(app6);

        // warm up
        System.out.println("Warming up " + app6Url + "/helloworld...");
        curl("http://" + app6Url + "/helloworld");
        SdkContext.sleep(5000);
        System.out.println("CURLing " + app6Url + "/helloworld...");
        System.out.println(curl("http://" + app6Url + "/helloworld"));
        System.out.println("CURLing " + app6Url + "/coffeeshop...");
        System.out.println(curl("http://" + app6Url + "/coffeeshop"));

        //============================================================
        // Create a 7th web app with the existing app service plan

        System.out.println("Creating web app " + app7Name + " in resource group " + rgName + "...");

        WebApp app7 = azure.webApps().define(app7Name).withRegion(Region.US_WEST).withNewResourceGroup(rg7Name)
                .withNewLinuxPlan(PricingTier.STANDARD_S2).withBuiltInImage(RuntimeStack.JAVA_8_JRE8)
                .withAppSetting("JAVA_OPTS", "-Djava.security.egd=file:/dev/./urandom").create();

        System.out.println("Created web app " + app7.name());
        Utils.print(app7);

        //============================================================
        // Deploy to the 7th web app through ZIP deploy

        System.out.println("Deploying app.zip to " + app7Name + " through ZIP deploy...");

        for (int i = 0; i < 5; i++) {
            try {
                app7.zipDeploy(new File(ManageWebAppSourceControl.class.getResource("/app.zip").getPath()));
                break;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        System.out.println("Deployments to web app " + app7.name() + " completed");
        Utils.print(app7);

        // warm up
        System.out.println("Warming up " + app7Url);
        curl("http://" + app7Url);
        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);
            azure.resourceGroups().beginDeleteByName(rg7Name);
            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;
}

From source file:com.microsoft.azure.management.appservice.samples.ManageWebAppSourceControlAsync.java

License:Open Source License

/**
 * Main function which runs the actual sample.
 * @param azure instance of the azure client
 * @return true if sample runs successfully
 *///from  w  ww.j  a  v  a2s.c  o  m
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.uploadFileToWebApp(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)
                                        // Uncomment the following lines to turn on 4th scenario
                                        //.defineSourceControl()
                                        //    .withContinuouslyIntegratedGitHubRepository("username", "reponame")
                                        //    .withBranch("master")
                                        //    .withGitHubAccessToken("YOUR GITHUB PERSONAL TOKEN")
                                        //    .attach()
                                        .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;
}

From source file:com.rimerosolutions.ant.git.tasks.PushTask.java

License:Apache License

@Override
protected void doExecute() {
    try {//from  w ww  .  j a  v a2  s . c  o m
        StoredConfig config = git.getRepository().getConfig();
        List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config);

        if (remoteConfigs.isEmpty()) {
            URIish uri = new URIish(getUri());

            RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME);

            remoteConfig.addURI(uri);
            remoteConfig.addFetchRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING));
            remoteConfig.addPushRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING));
            remoteConfig.update(config);

            config.save();
        }

        String currentBranch = git.getRepository().getBranch();
        List<RefSpec> specs = Arrays.asList(new RefSpec(currentBranch + ":" + currentBranch));

        if (deleteRemoteBranch != null) {
            specs = Arrays.asList(new RefSpec(":" + Constants.R_HEADS + deleteRemoteBranch));
        }

        PushCommand pushCommand = git.push().setPushAll().setRefSpecs(specs).setDryRun(false);

        if (getUri() != null) {
            pushCommand.setRemote(getUri());
        }

        setupCredentials(pushCommand);

        if (includeTags) {
            pushCommand.setPushTags();
        }

        if (getProgressMonitor() != null) {
            pushCommand.setProgressMonitor(getProgressMonitor());
        }

        Iterable<PushResult> pushResults = pushCommand.setForce(true).call();

        for (PushResult pushResult : pushResults) {
            log(pushResult.getMessages());
            GitTaskUtils.validateRemoteRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getRemoteUpdates());
            GitTaskUtils.validateTrackingRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getTrackingRefUpdates());
        }
    } catch (Exception e) {
        if (pushFailedProperty != null) {
            getProject().setProperty(pushFailedProperty, e.getMessage());
        }

        throw new GitBuildException(PUSH_FAILED_MESSAGE, e);
    }
}

From source file:ezbake.deployer.publishers.openShift.RhcApplication.java

License:Apache License

/**
 * Updates the OpenShift application with the changes locally applied. (git commit, git Push)
 * This will cause the new app to be deployed to openshift.  After this the new version should be visible.
 *
 * @throws DeploymentException On any error deploying the application.
 *///from   w w  w.  jav a2s . c om
public void publishChanges() throws DeploymentException {

    try {
        RevCommit commit = gitRepo.commit().setMessage("RhcApplication: publishing newest version")
                .setAuthor(applicationDomain.getUser().getRhlogin(), applicationDomain.getUser().getRhlogin())
                .call();

        log.info("[" + getApplicationName() + "][GIT-COMMIT] committed changes to local git repo. "
                + commit.toString());
        PushCommand pushCommand = gitRepo.push();
        if (gitCredentialsProvider != null)
            pushCommand.setCredentialsProvider(gitCredentialsProvider);
        for (PushResult result : pushCommand.setForce(true).setTimeout(100000).call()) {
            if (!result.getMessages().isEmpty())
                log.info("[" + getApplicationName() + "][GIT-PUSH] " + result.getMessages());
            log.info("[" + getApplicationName() + "][GIT-PUSH] Successfully pushed application.");
        }
    } catch (GitAPIException e) {
        log.error("[" + getApplicationName() + "] Error adding updated files to deployment git repo", e);
        throw new DeploymentException(e.getMessage());
    }
}

From source file:fr.treeptik.cloudunit.utils.GitUtils.java

License:Open Source License

/**
 * this method is associate with listGitTagsOfApplication() method
 * which list all tags with index, this is this index which must pass as parammeter of this method
 *
 * @param application//ww w  . j a  v a  2s  .c  om
 * @param indexChosen
 * @param dockerManagerAddress
 * @param containerGitAddress
 * @return
 * @throws InvalidRemoteException
 * @throws TransportException
 * @throws GitAPIException
 * @throws IOException
 */
public static List<String> resetOnChosenGitTag(Application application, int indexChosen,
        String dockerManagerAddress, String containerGitAddress)
        throws InvalidRemoteException, TransportException, GitAPIException, IOException {
    User user = application.getUser();
    String sshPort = application.getServers().get(0).getSshPort();
    String password = user.getPassword();
    String userNameGit = user.getLogin();
    String dockerManagerIP = dockerManagerAddress.substring(0, dockerManagerAddress.length() - 5);
    String remoteRepository = "ssh://" + userNameGit + "@" + dockerManagerIP + ":" + sshPort
            + containerGitAddress;
    File gitworkDir = Files.createTempDirectory("clone").toFile();
    CloneCommand clone = Git.cloneRepository();
    clone.setDirectory(gitworkDir);

    CredentialsProvider credentialsProvider = configCredentialsForGit(userNameGit, password);
    clone.setCredentialsProvider(credentialsProvider);
    clone.setURI(remoteRepository);
    Git git = clone.call();

    ListTagCommand listTagCommand = git.tagList();
    List<Ref> listRefs = listTagCommand.call();

    Ref ref = listRefs.get(indexChosen);

    ResetCommand resetCommand = git.reset();
    resetCommand.setMode(ResetType.HARD);
    resetCommand.setRef(ref.getName());
    resetCommand.call();

    PushCommand pushCommand = git.push();
    pushCommand.setCredentialsProvider(credentialsProvider);
    pushCommand.setForce(true);

    List<PushResult> listPushResults = (List<PushResult>) pushCommand.call();
    List<String> listPushResultsMessages = new ArrayList<>();
    for (PushResult pushResult : listPushResults) {
        listPushResultsMessages.add(pushResult.getMessages());
    }
    FilesUtils.deleteDirectory(gitworkDir);
    return listPushResultsMessages;
}

From source file:org.ajoberstar.gradle.git.tasks.GitPush.java

License:Apache License

/**
 * Pushes changes to a remote repository.
 *///from  w  w  w .j a  va2 s . c o m
@TaskAction
public void push() {
    PushCommand cmd = getGit().push();
    TransportAuthUtil.configure(cmd, this);
    cmd.setRemote(getRemote());
    if (isPushTags()) {
        cmd.setPushTags();
    }
    if (isPushAll()) {
        cmd.setPushAll();
    }
    cmd.setForce(isForce());
    try {
        cmd.call();
    } catch (Exception e) {
        throw new GradleException("Problem pushing to repository.", e);
    }
    //TODO add progress monitor to go to Gradle status bar
}