Package org.cloudfoundry.client.lib.domain

Examples of org.cloudfoundry.client.lib.domain.CloudApplication


    connectedClient.addDomain(TEST_DOMAIN);
    List<String> uris = Arrays.asList(TEST_DOMAIN);

    Staging staging =  new Staging();
    connectedClient.createApplication(appName, staging, DEFAULT_MEMORY, uris, null);
    CloudApplication app = connectedClient.getApplication(appName);
    assertNotNull(app);
    assertEquals(appName, app.getName());

    List<String> actualUris = app.getUris();
    assertTrue(actualUris.size() == 1);
    assertEquals(TEST_DOMAIN, actualUris.get(0));
  }
View Full Code Here


  @Test
  public void getApplicationByName() {
    final String serviceName = "test_database";
    String appName = createSpringTravelApp("1", Collections.singletonList(serviceName));
    CloudApplication app = connectedClient.getApplication(appName);
    assertNotNull(app);
    assertEquals(appName, app.getName());

    assertEquals(1, app.getServices().size());
    assertEquals(serviceName, app.getServices().get(0));

    assertEquals(1, app.getInstances());
    assertEquals(DEFAULT_MEMORY, app.getMemory());
    assertEquals(DEFAULT_DISK, app.getDiskQuota());

    assertNull(app.getStaging().getCommand());
    assertNull(app.getStaging().getBuildpackUrl());
    assertNull(app.getStaging().getHealthCheckTimeout());
  }
View Full Code Here

  }

  @Test
  public void getApplicationByGuid() {
    String appName = createSpringTravelApp("3");
    CloudApplication app = connectedClient.getApplication(appName);
    CloudApplication guidApp = connectedClient.getApplication(app.getMeta().getGuid());
    assertEquals(app.getName(), guidApp.getName());
  }
View Full Code Here

    final String serviceName = "test_database";
    String appName = createSpringTravelApp("2", Collections.singletonList(serviceName));
    List<CloudApplication> apps = connectedClient.getApplications();
    assertEquals(1, apps.size());

    CloudApplication app = apps.get(0);
    assertEquals(appName, app.getName());
    assertNotNull(app.getMeta());
    assertNotNull(app.getMeta().getGuid());

    assertEquals(1, app.getServices().size());
    assertEquals(serviceName, app.getServices().get(0));

    createSpringTravelApp("3");
    apps = connectedClient.getApplications();
    assertEquals(2, apps.size());
  }
View Full Code Here

  }

  @Test
  public void startStopApplication() throws IOException {
    String appName = createSpringTravelApp("upload-start-stop");
    CloudApplication app = uploadSpringTravelApp(appName);
    assertNotNull(app);
    assertEquals(CloudApplication.AppState.STOPPED, app.getState());

    String url = computeAppUrlNoProtocol(appName);
    assertEquals(url, app.getUris().get(0));

    StartingInfo info = connectedClient.startApplication(appName);
    app = connectedClient.getApplication(appName);
    assertEquals(CloudApplication.AppState.STARTED, app.getState());
    assertNotNull(info);
    assertNotNull(info.getStagingFile());

    connectedClient.stopApplication(appName);
    app = connectedClient.getApplication(appName);
    assertEquals(CloudApplication.AppState.STOPPED, app.getState());
  }
View Full Code Here

    return new CloudRoute(getMeta(resource), host, domain, apps.size());
  }

  @SuppressWarnings({ "unchecked", "rawtypes" })
  private CloudApplication mapApplicationResource(Map<String, Object> resource) {
    CloudApplication app = new CloudApplication(
        getMeta(resource),
        getNameOfResource(resource));
    app.setInstances(getEntityAttribute(resource, "instances", Integer.class));
    app.setServices(new ArrayList<String>());
    app.setState(CloudApplication.AppState.valueOf(getEntityAttribute(resource, "state", String.class)));
    //TODO: debug
    app.setDebug(null);

    Integer runningInstancesAttribute = getEntityAttribute(resource, "running_instances", Integer.class);
    if (runningInstancesAttribute != null) {
      app.setRunningInstances(runningInstancesAttribute);
    }
    String command = getEntityAttribute(resource, "command", String.class);
    String buildpack = getEntityAttribute(resource, "buildpack", String.class);
    Map<String, Object> stackResource = getEmbeddedResource(resource, "stack");
    CloudStack stack = mapStackResource(stackResource);
    Integer healthCheckTimeout = getEntityAttribute(resource, "health_check_timeout", Integer.class);
    Staging staging = new Staging(command, buildpack, stack.getName(), healthCheckTimeout);
    app.setStaging(staging);

    Map envMap = getEntityAttribute(resource, "environment_json", Map.class);
    if (envMap.size() > 0) {
      app.setEnv(envMap);
    }
    app.setMemory(getEntityAttribute(resource, "memory", Integer.class));
    app.setDiskQuota(getEntityAttribute(resource, "disk_quota", Integer.class));
    List<Map<String, Object>> serviceBindings = getEntityAttribute(resource, "service_bindings", List.class);
    List<String> serviceList = new ArrayList<String>();
    for (Map<String, Object> binding : serviceBindings) {
      Map<String, Object> service = getEntityAttribute(binding, "service_instance", Map.class);
      String serviceName = getNameOfResource(service);
      if (serviceName != null) {
        serviceList.add(serviceName);
      }
    }
    app.setServices(serviceList);
    return app;
  }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  private CloudApplication mapCloudApplication(Map<String, Object> resource) {
    UUID appId = resourceMapper.getGuidOfResource(resource);
    CloudApplication cloudApp = null;
    if (resource != null) {
      int running = getRunningInstances(appId,
          CloudApplication.AppState.valueOf(
              CloudEntityResourceMapper.getEntityAttribute(resource, "state", String.class)));
      ((Map<String, Object>)resource.get("entity")).put("running_instances", running);
      cloudApp = resourceMapper.mapResource(resource, CloudApplication.class);
      cloudApp.setUris(findApplicationUris(cloudApp.getMeta().getGuid()));
    }
    return cloudApp;
  }
View Full Code Here

    return running;
  }

  @Override
  public ApplicationStats getApplicationStats(String appName) {
    CloudApplication app = getApplication(appName);
    return doGetApplicationStats(app.getMeta().getGuid(), app.getState());
  }
View Full Code Here

    return new HttpEntity<MultiValueMap<String, ?>>(body, headers);
  }

  @Override
  public StartingInfo startApplication(String appName) {
    CloudApplication app = getApplication(appName);
    if (app.getState() != CloudApplication.AppState.STARTED) {
      HashMap<String, Object> appRequest = new HashMap<String, Object>();
      appRequest.put("state", CloudApplication.AppState.STARTED);

      HttpEntity<Object> requestEntity = new HttpEntity<Object>(
          appRequest);
      ResponseEntity<String> entity = getRestTemplate().exchange(
          getUrl("/v2/apps/{guid}?stage_async=true"), HttpMethod.PUT, requestEntity,
          String.class, app.getMeta().getGuid());

      HttpHeaders headers = entity.getHeaders();

      // Return a starting info, even with a null staging log value, as a non-null starting info
      // indicates that the response entity did have headers. The API contract is to return starting info
View Full Code Here

    throw new UnsupportedOperationException("Feature is not yet implemented.");
  }

  @Override
  public void stopApplication(String appName) {
    CloudApplication app = getApplication(appName);
    if (app.getState() != CloudApplication.AppState.STOPPED) {
      HashMap<String, Object> appRequest = new HashMap<String, Object>();
      appRequest.put("state", CloudApplication.AppState.STOPPED);
      getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, app.getMeta().getGuid());
    }
  }
View Full Code Here

TOP

Related Classes of org.cloudfoundry.client.lib.domain.CloudApplication

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.