getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, appId);
}
@Override
public void updateApplicationServices(String appName, List<String> services) {
CloudApplication app = getApplication(appName);
List<UUID> addServices = new ArrayList<UUID>();
List<UUID> deleteServices = new ArrayList<UUID>();
// services to add
for (String serviceName : services) {
if (!app.getServices().contains(serviceName)) {
CloudService cloudService = getService(serviceName);
if (cloudService != null) {
addServices.add(cloudService.getMeta().getGuid());
}
else {
throw new CloudFoundryException(HttpStatus.NOT_FOUND, "Service with name " + serviceName +
" not found in current space " + sessionSpace.getName());
}
}
}
// services to delete
for (String serviceName : app.getServices()) {
if (!services.contains(serviceName)) {
CloudService cloudService = getService(serviceName);
if (cloudService != null) {
deleteServices.add(cloudService.getMeta().getGuid());
}
}
}
for (UUID serviceId : addServices) {
doBindService(app.getMeta().getGuid(), serviceId);
}
for (UUID serviceId : deleteServices) {
doUnbindService(app.getMeta().getGuid(), serviceId);
}
}