Example usage for org.springframework.ide.eclipse.boot.dash.cloudfoundry.client.v2 CFPushArguments setBuildpack

List of usage examples for org.springframework.ide.eclipse.boot.dash.cloudfoundry.client.v2 CFPushArguments setBuildpack

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.boot.dash.cloudfoundry.client.v2 CFPushArguments setBuildpack.

Prototype

public void setBuildpack(String buildpack) 

Source Link

Usage

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testPushAndBindServices() throws Exception {
    //This test fails occasionally because service binding is 'unreliable'. Had a long discussion
    // with Ben Hale. The gist is errors happen and should be expected in distributed world.
    //They are coming from 'AppDirect' which manages the services. The errors are mediated through cloudfoundry
    // which doesn't knwow how it should handle them. So it passed the buck onto the its callers.
    //In this case.... cf-java-client which does the same thing and passes them to us.
    //All the reasons why they can't handle these errors also apply to us, which means that
    //the operation is simply unreliable and so failure is an expected outcome even when everything
    //works correctly.
    //To avoid this test case from failing too often we retry it a few times.
    RetryUtil.retryTimes("testPushAndBindServices", 4, () -> {

        System.out.println("Executing full test scenario.");
        String service1 = services.createTestService();
        String service2 = services.createTestService();
        String service3 = services.createTestService(); //An extra unused service (makes this a better test).

        String appName = appHarness.randomAppName();
        CFPushArguments params = new CFPushArguments();
        params.setAppName(appName);/*  w  ww  . ja va  2  s .c o m*/
        params.setApplicationData(getTestZip("testapp"));
        params.setBuildpack("staticfile_buildpack");
        params.setServices(ImmutableList.of(service1, service2));
        push(params);

        assertEquals(ImmutableSet.of(service1, service2), getBoundServiceNames(appName));

        client.bindAndUnbindServices(appName, ImmutableList.of(service1)).block();
        assertEquals(ImmutableSet.of(service1), getBoundServiceNames(appName));

        client.bindAndUnbindServices(appName, ImmutableList.of(service2)).block();
        assertEquals(ImmutableSet.of(service2), getBoundServiceNames(appName));

        client.bindAndUnbindServices(appName, ImmutableList.of()).block();
        assertEquals(ImmutableSet.of(), getBoundServiceNames(appName));
    });
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testPushAndBindHostAndDomain() throws Exception {
    String appName = appHarness.randomAppName();

    for (int i = 0; i < 2; i++) {
        //Why this loop? Because there was bug which CF V2 that made second push fail to bind to
        // map a host that was previously mapped.
        if (i > 0) {
            System.out.println("Delete app");
            client.deleteApplication(appName);
        }//ww w . ja  v a2 s.c o  m

        System.out.println("Pushing " + (i + 1));
        CFPushArguments params = new CFPushArguments();
        params.setAppName(appName);
        params.setApplicationData(getTestZip("testapp"));
        params.setBuildpack("staticfile_buildpack");
        params.setRoutes(ImmutableList.of(appName + "." + CFAPPS_IO()));

        push(params);
    }

    System.out.println("Pushing SUCCESS");

    CFApplicationDetail app = client.getApplication(appName);
    assertNotNull("Expected application to exist after push: " + appName, app);

    assertEquals(ImmutableSet.of(appName + "." + CFAPPS_IO()), ImmutableSet.copyOf(app.getUris()));
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testPushAndBindMultipleHosts() throws Exception {
    String[] hostNames = { appHarness.randomAppName(), appHarness.randomAppName() };
    String appName = hostNames[0];

    CFPushArguments params = new CFPushArguments();
    params.setAppName(hostNames[0]);//from  w  w w. j av a 2 s  .  c o m
    params.setApplicationData(getTestZip("testapp"));
    params.setBuildpack("staticfile_buildpack");

    Set<String> routes = ImmutableSet
            .copyOf(Stream.of(hostNames).map((host) -> host + "." + CFAPPS_IO()).collect(Collectors.toList()));
    params.setRoutes(routes);

    push(params);

    System.out.println("Pushing SUCCESS");

    CFApplicationDetail app = client.getApplication(appName);
    assertNotNull("Expected application to exist after push: " + appName, app);

    assertEquals(routes, ImmutableSet.copyOf(app.getUris()));
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testPushAndSetRoutes() throws Exception {
    String[] hostNames = { appHarness.randomAppName(), appHarness.randomAppName() };
    String appName = hostNames[0];

    CFPushArguments params = new CFPushArguments();
    params.setAppName(hostNames[0]);//from  www  .ja v  a2s. com
    params.setApplicationData(getTestZip("testapp"));
    params.setBuildpack("staticfile_buildpack");

    Set<String> routes = ImmutableSet
            .copyOf(Stream.of(hostNames).map((host) -> host + "." + CFAPPS_IO()).collect(Collectors.toList()));
    params.setRoutes(routes);

    push(params);

    System.out.println("Pushing SUCCESS");

    {
        CFApplicationDetail app = client.getApplication(appName);
        assertNotNull("Expected application to exist after push: " + appName, app);
        assertEquals(routes, ImmutableSet.copyOf(app.getUris()));
    }

    doSetRoutesTest(appName, ImmutableSet.of());

    for (String route : routes) {
        doSetRoutesTest(appName, ImmutableSet.of(route));
    }

}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testPushAndSetEnv() throws Exception {
    String appName = appHarness.randomAppName();

    CFPushArguments params = new CFPushArguments();
    params.setAppName(appName);//  w w  w. j av  a  2s.  com
    params.setRoutes(appName + "." + CFAPPS_IO());
    params.setApplicationData(getTestZip("testapp"));
    params.setBuildpack("staticfile_buildpack");
    params.setEnv(ImmutableMap.of("foo", "foo_value", "bar", "bar_value"));
    push(params);

    CFApplicationDetail app = client.getApplication(appName);
    assertNotNull("Expected application to exist after push: " + appName, app);
    ACondition.waitFor("app content to be availabe", 10_000, () -> {
        String content = IOUtils.toString(new URI("http://" + appName + '.' + CFAPPS_IO() + "/test.txt"));
        assertTrue(content.length() > 0);
        assertTrue(content.contains("content"));
    });

    {
        Map<String, String> env = client.getEnv(appName).block();
        assertEquals("foo_value", env.get("foo"));
        assertEquals("bar_value", env.get("bar"));
        assertEquals(2, env.size());
    }

    client.setEnvVars(appName, ImmutableMap.of("other", "value")).block();
    {
        Map<String, String> env = client.getEnv(appName).block();
        assertEquals("value", env.get("other"));
        assertEquals(1, env.size());
    }

    //This last piece is commented because it fails.
    //See: https://www.pivotaltracker.com/story/show/116804259

    // The last var doesn't get removed. Not sure how to fix it.
    // But eventually we won't even be using 'setEnvVars' it will be part of the push.
    // and its not going to be our problem to fix that.
    //      client.updateApplicationEnvironment(appName, ImmutableMap.of()).get();
    //      {
    //         Map<String, Object> env = client.getEnv(appName).get();
    //         assertEquals(0, env.size());
    //      }
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testDeleteApplication() throws Exception {
    String appName = appHarness.randomAppName();

    CFPushArguments params = new CFPushArguments();
    params.setAppName(appName);/*from w  w w .j a  v  a  2 s. co  m*/
    params.setApplicationData(getTestZip("testapp"));
    params.setBuildpack("staticfile_buildpack");
    push(params);

    CFApplicationDetail app = client.getApplication(appName);
    assertTrue(client.applicationExists(appName));
    assertNotNull("Expected application to exist after push: " + appName, app);

    client.deleteApplication(appName);
    app = client.getApplication(appName);
    assertNull("Expected application to be deleted after delete: " + appName, app);
    assertFalse(client.applicationExists(appName));
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testStopApplication() throws Exception {
    String appName = appHarness.randomAppName();

    CFPushArguments params = new CFPushArguments();
    params.setAppName(appName);//  w  w  w  . j  a  va2 s.  c om
    params.setApplicationData(getTestZip("testapp"));
    params.setBuildpack("staticfile_buildpack");
    push(params);

    final CFApplicationDetail runningApp = client.getApplication(appName);
    assertNotNull("Expected application to exist after push: " + appName, runningApp);

    new ACondition("wait for app '" + appName + "'to be RUNNING", APP_DEPLOY_TIMEOUT) {
        public boolean test() throws Exception {
            assertAppRunState(1, runningApp.getRunningInstances(), CFAppState.STARTED, runningApp.getState());
            return true;
        }
    };

    client.stopApplication(appName);
    final CFApplicationDetail stoppedApp = client.getApplication(appName);

    new ACondition("wait for app '" + appName + "'to be STOPPED", APP_DEPLOY_TIMEOUT) {
        public boolean test() throws Exception {
            assertAppRunState(0, stoppedApp.getRunningInstances(), CFAppState.STOPPED, stoppedApp.getState());
            return true;
        }
    };
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testGetBoundServices() throws Exception {
    RetryUtil.retryWhen("testGetBoundServices", 5, FLAKY_SERVICE_BROKER, () -> {
        String service1 = services.createTestService();
        String service2 = services.createTestService();
        String service3 = services.createTestService();

        String appName = appHarness.randomAppName();
        CFPushArguments params = new CFPushArguments();
        params.setAppName(appName);/*from  w  w w. ja  v a  2s .  co m*/
        params.setApplicationData(getTestZip("testapp"));
        params.setBuildpack("staticfile_buildpack");
        params.setServices(ImmutableList.of(service1, service2));
        push(params);

        List<CFApplication> allApps = client.getApplicationsWithBasicInfo();
        CFApplication app = null;
        for (CFApplication a : allApps) {
            if (a.getName().equals(appName)) {
                app = a;
            }
        }
        assertEquals(ImmutableSet.of(service1, service2), ImmutableSet.copyOf(app.getServices()));

        app = client.getApplication(appName);
        assertEquals(ImmutableSet.of(service1, service2), ImmutableSet.copyOf(app.getServices()));
    });
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testApplicationLogConnection() throws Exception {
    client = createClient(CfTestTargetParams.fromEnv());

    String appName = appHarness.randomAppName();
    IApplicationLogConsole listener = mock(IApplicationLogConsole.class);
    Cancellation token = client.streamLogs(appName, listener);
    assertNotNull(token);//from w w w  . j a va 2 s  .c  o  m

    Future<Void> pushResult = doAsync(() -> {
        CFPushArguments params = new CFPushArguments();
        params.setAppName(appName);
        params.setApplicationData(getTestZip("testapp"));
        params.setBuildpack("staticfile_buildpack");
        push(params);
    });

    ACondition.waitFor("push", TimeUnit.MINUTES.toMillis(4), () -> {
        assertTrue(pushResult.isDone());
    });
    pushResult.get();

    BootDashModelTest.waitForJobsToComplete();
    verify(listener, atLeastOnce()).onMessage(any());
}

From source file:org.springframework.ide.eclipse.boot.dash.test.CloudFoundryClientTest.java

@Test
public void testGetApplicationBuildpack() throws Exception {
    String appName = appHarness.randomAppName();

    CFPushArguments params = new CFPushArguments();
    params.setAppName(appName);//from ww  w.  j  a v a2s. c o  m
    params.setApplicationData(getTestZip("testapp"));
    params.setBuildpack("staticfile_buildpack");
    push(params);

    //Note we try to get the app two different ways because retrieving the info in
    // each case is slightly different.

    {
        CFApplicationDetail app = client.getApplication(appName);
        assertEquals("staticfile_buildpack", app.getBuildpackUrl());
    }

    {
        List<CFApplication> allApps = client.getApplicationsWithBasicInfo();
        CFApplication app = null;
        for (CFApplication a : allApps) {
            if (a.getName().equals(appName)) {
                app = a;
            }
        }
        assertEquals("staticfile_buildpack", app.getBuildpackUrl());
    }
}