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