org.cloudfoundry.client.lib.rest
Class CloudControllerClientImpl

java.lang.Object
  extended by org.cloudfoundry.client.lib.rest.CloudControllerClientImpl
All Implemented Interfaces:
CloudControllerClient

public class CloudControllerClientImpl
extends Object
implements CloudControllerClient

Abstract implementation of the CloudControllerClient intended to serve as the base.

Author:
Ramnivas Laddad, A.B.Srinivasan, Jennifer Hickey, Dave Syer, Thomas Risberg

Nested Class Summary
static class CloudControllerClientImpl.CloudFoundryFormHttpMessageConverter
           
 
Field Summary
protected  URL authorizationEndpoint
           
protected  CloudCredentials cloudCredentials
           
protected static org.springframework.http.MediaType JSON_MEDIA_TYPE
           
protected  RestUtil restUtil
           
protected  org.springframework.security.oauth2.common.OAuth2AccessToken token
           
 
Constructor Summary
protected CloudControllerClientImpl()
          Only for unit tests.
  CloudControllerClientImpl(URL cloudControllerUrl, RestUtil restUtil, CloudCredentials cloudCredentials, URL authorizationEndpoint, CloudSpace sessionSpace, HttpProxyConfiguration httpProxyConfiguration)
           
  CloudControllerClientImpl(URL cloudControllerUrl, RestUtil restUtil, CloudCredentials cloudCredentials, URL authorizationEndpoint, String orgName, String spaceName, HttpProxyConfiguration httpProxyConfiguration)
           
 
Method Summary
 void addDomain(String domainName)
           
 void addRoute(String host, String domainName)
           
 void bindService(String appName, String serviceName)
           
protected  void configureCloudFoundryRequestFactory(org.springframework.web.client.RestTemplate restTemplate)
           
 void createApplication(String appName, Staging staging, int memory, List<String> uris, List<String> serviceNames)
           
 void createService(CloudService service)
           
 void debugApplication(String appName, CloudApplication.DebugMode mode)
           
 void deleteAllApplications()
           
 void deleteAllServices()
           
 void deleteApplication(String appName)
           
 void deleteDomain(String domainName)
           
 void deleteRoute(String host, String domainName)
           
 void deleteService(String serviceName)
           
protected  URL determineAuthorizationEndPointToUse(URL authorizationEndpoint, URL cloudControllerUrl)
           
protected  String doGetFile(String urlPath, Object app, int instanceIndex, String filePath, int startPosition, int endPosition)
           
protected  String doGetFile(String urlPath, Object app, String instance, String filePath, int startPosition, int endPosition)
           
protected  Map<String,String> doGetLogs(String urlPath, String appName, String instance)
           
protected  void extractUriInfo(Map<String,UUID> domains, String uri, Map<String,String> uriInfo)
           
 CloudApplication getApplication(String appName)
           
 CloudApplication getApplication(UUID appGuid)
           
 InstancesInfo getApplicationInstances(CloudApplication app)
           
 InstancesInfo getApplicationInstances(String appName)
           
 int[] getApplicationMemoryChoices()
           
 List<CloudApplication> getApplications()
           
 ApplicationStats getApplicationStats(String appName)
           
 URL getCloudControllerUrl()
           
 CrashesInfo getCrashes(String appName)
           
 Map<String,String> getCrashLogs(String appName)
           
 List<CloudDomain> getDomains()
           
 List<CloudDomain> getDomainsForOrg()
           
 String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition)
           
protected  Object getFileAppId(String appName)
           
protected  String getFileUrlPath()
           
 CloudInfo getInfo()
           
 Map<String,String> getLogs(String appName)
           
 List<CloudOrganization> getOrganizations()
           
protected  org.springframework.web.client.RestTemplate getRestTemplate()
           
 List<CloudRoute> getRoutes(String domainName)
           
 CloudService getService(String serviceName)
           
 List<CloudServiceOffering> getServiceOfferings()
           
 List<CloudService> getServices()
           
 List<CloudSpace> getSpaces()
           
 String getStagingLogs(StartingInfo info, int offset)
          Returns null if no further content is available.
protected  String getUrl(String path)
           
 org.springframework.security.oauth2.common.OAuth2AccessToken login()
           
 void logout()
           
 void register(String email, String password)
           
 void registerRestLogListener(RestLogCallback callBack)
           
 void removeDomain(String domainName)
           
 void rename(String appName, String newName)
           
 StartingInfo restartApplication(String appName)
           
 void setResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
           
 StartingInfo startApplication(String appName)
           
 void stopApplication(String appName)
           
 void unbindService(String appName, String serviceName)
           
 void unregister()
           
 void unRegisterRestLogListener(RestLogCallback callBack)
           
 void updateApplicationEnv(String appName, List<String> env)
           
 void updateApplicationEnv(String appName, Map<String,String> env)
           
 void updateApplicationInstances(String appName, int instances)
           
 void updateApplicationMemory(String appName, int memory)
           
 void updateApplicationServices(String appName, List<String> services)
           
 void updateApplicationStaging(String appName, Staging staging)
           
 void updateApplicationUris(String appName, List<String> uris)
           
 void updateHttpProxyConfiguration(HttpProxyConfiguration httpProxyConfiguration)
           
 void updatePassword(CloudCredentials credentials, String newPassword)
           
 void updatePassword(String newPassword)
           
 void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback)
           
 void uploadApplication(String appName, File file, UploadStatusCallback callback)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JSON_MEDIA_TYPE

protected static final org.springframework.http.MediaType JSON_MEDIA_TYPE

restUtil

protected RestUtil restUtil

cloudCredentials

protected CloudCredentials cloudCredentials

authorizationEndpoint

protected URL authorizationEndpoint

token

protected org.springframework.security.oauth2.common.OAuth2AccessToken token
Constructor Detail

CloudControllerClientImpl

public CloudControllerClientImpl(URL cloudControllerUrl,
                                 RestUtil restUtil,
                                 CloudCredentials cloudCredentials,
                                 URL authorizationEndpoint,
                                 CloudSpace sessionSpace,
                                 HttpProxyConfiguration httpProxyConfiguration)

CloudControllerClientImpl

protected CloudControllerClientImpl()
Only for unit tests. This works around the fact that the initialize method is called within the constructor and hence can not be overloaded, making it impossible to write unit tests that don't trigger network calls.


CloudControllerClientImpl

public CloudControllerClientImpl(URL cloudControllerUrl,
                                 RestUtil restUtil,
                                 CloudCredentials cloudCredentials,
                                 URL authorizationEndpoint,
                                 String orgName,
                                 String spaceName,
                                 HttpProxyConfiguration httpProxyConfiguration)
Method Detail

setResponseErrorHandler

public void setResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
Specified by:
setResponseErrorHandler in interface CloudControllerClient

determineAuthorizationEndPointToUse

protected URL determineAuthorizationEndPointToUse(URL authorizationEndpoint,
                                                  URL cloudControllerUrl)

getCloudControllerUrl

public URL getCloudControllerUrl()
Specified by:
getCloudControllerUrl in interface CloudControllerClient

getApplicationMemoryChoices

public int[] getApplicationMemoryChoices()
Specified by:
getApplicationMemoryChoices in interface CloudControllerClient

updatePassword

public void updatePassword(String newPassword)
Specified by:
updatePassword in interface CloudControllerClient

updateHttpProxyConfiguration

public void updateHttpProxyConfiguration(HttpProxyConfiguration httpProxyConfiguration)
Specified by:
updateHttpProxyConfiguration in interface CloudControllerClient

getLogs

public Map<String,String> getLogs(String appName)
Specified by:
getLogs in interface CloudControllerClient

getCrashLogs

public Map<String,String> getCrashLogs(String appName)
Specified by:
getCrashLogs in interface CloudControllerClient

getFile

public String getFile(String appName,
                      int instanceIndex,
                      String filePath,
                      int startPosition,
                      int endPosition)
Specified by:
getFile in interface CloudControllerClient

registerRestLogListener

public void registerRestLogListener(RestLogCallback callBack)
Specified by:
registerRestLogListener in interface CloudControllerClient

unRegisterRestLogListener

public void unRegisterRestLogListener(RestLogCallback callBack)
Specified by:
unRegisterRestLogListener in interface CloudControllerClient

getStagingLogs

public String getStagingLogs(StartingInfo info,
                             int offset)
Returns null if no further content is available. Two errors that will lead to a null value are 404 Bad Request errors, which are handled in the implementation, meaning that no further log file contents are available, or ResourceAccessException, also handled in the implementation, indicating a possible timeout in the server serving the content. Note that any other CloudFoundryException or RestClientException exception not related to the two errors mentioned above may still be thrown (e.g. 500 level errors, Unauthorized or Forbidden exceptions, etc..)

Specified by:
getStagingLogs in interface CloudControllerClient
Returns:
content if available, which may contain multiple lines, or null if no further content is available.

getRestTemplate

protected org.springframework.web.client.RestTemplate getRestTemplate()

getUrl

protected String getUrl(String path)

configureCloudFoundryRequestFactory

protected void configureCloudFoundryRequestFactory(org.springframework.web.client.RestTemplate restTemplate)

doGetLogs

protected Map<String,String> doGetLogs(String urlPath,
                                       String appName,
                                       String instance)

doGetFile

protected String doGetFile(String urlPath,
                           Object app,
                           int instanceIndex,
                           String filePath,
                           int startPosition,
                           int endPosition)

doGetFile

protected String doGetFile(String urlPath,
                           Object app,
                           String instance,
                           String filePath,
                           int startPosition,
                           int endPosition)

getInfo

public CloudInfo getInfo()
Specified by:
getInfo in interface CloudControllerClient

getSpaces

public List<CloudSpace> getSpaces()
Specified by:
getSpaces in interface CloudControllerClient

getOrganizations

public List<CloudOrganization> getOrganizations()
Specified by:
getOrganizations in interface CloudControllerClient

login

public org.springframework.security.oauth2.common.OAuth2AccessToken login()
Specified by:
login in interface CloudControllerClient

logout

public void logout()
Specified by:
logout in interface CloudControllerClient

register

public void register(String email,
                     String password)
Specified by:
register in interface CloudControllerClient

updatePassword

public void updatePassword(CloudCredentials credentials,
                           String newPassword)
Specified by:
updatePassword in interface CloudControllerClient

unregister

public void unregister()
Specified by:
unregister in interface CloudControllerClient

getServices

public List<CloudService> getServices()
Specified by:
getServices in interface CloudControllerClient

createService

public void createService(CloudService service)
Specified by:
createService in interface CloudControllerClient

getService

public CloudService getService(String serviceName)
Specified by:
getService in interface CloudControllerClient

deleteService

public void deleteService(String serviceName)
Specified by:
deleteService in interface CloudControllerClient

deleteAllServices

public void deleteAllServices()
Specified by:
deleteAllServices in interface CloudControllerClient

getServiceOfferings

public List<CloudServiceOffering> getServiceOfferings()
Specified by:
getServiceOfferings in interface CloudControllerClient

getApplications

public List<CloudApplication> getApplications()
Specified by:
getApplications in interface CloudControllerClient

getApplication

public CloudApplication getApplication(String appName)
Specified by:
getApplication in interface CloudControllerClient

getApplication

public CloudApplication getApplication(UUID appGuid)
Specified by:
getApplication in interface CloudControllerClient

getApplicationStats

public ApplicationStats getApplicationStats(String appName)
Specified by:
getApplicationStats in interface CloudControllerClient

createApplication

public void createApplication(String appName,
                              Staging staging,
                              int memory,
                              List<String> uris,
                              List<String> serviceNames)
Specified by:
createApplication in interface CloudControllerClient

extractUriInfo

protected void extractUriInfo(Map<String,UUID> domains,
                              String uri,
                              Map<String,String> uriInfo)

uploadApplication

public void uploadApplication(String appName,
                              File file,
                              UploadStatusCallback callback)
                       throws IOException
Specified by:
uploadApplication in interface CloudControllerClient
Throws:
IOException

uploadApplication

public void uploadApplication(String appName,
                              ApplicationArchive archive,
                              UploadStatusCallback callback)
                       throws IOException
Specified by:
uploadApplication in interface CloudControllerClient
Throws:
IOException

startApplication

public StartingInfo startApplication(String appName)
Specified by:
startApplication in interface CloudControllerClient

debugApplication

public void debugApplication(String appName,
                             CloudApplication.DebugMode mode)
Specified by:
debugApplication in interface CloudControllerClient

stopApplication

public void stopApplication(String appName)
Specified by:
stopApplication in interface CloudControllerClient

restartApplication

public StartingInfo restartApplication(String appName)
Specified by:
restartApplication in interface CloudControllerClient

deleteApplication

public void deleteApplication(String appName)
Specified by:
deleteApplication in interface CloudControllerClient

deleteAllApplications

public void deleteAllApplications()
Specified by:
deleteAllApplications in interface CloudControllerClient

updateApplicationMemory

public void updateApplicationMemory(String appName,
                                    int memory)
Specified by:
updateApplicationMemory in interface CloudControllerClient

updateApplicationInstances

public void updateApplicationInstances(String appName,
                                       int instances)
Specified by:
updateApplicationInstances in interface CloudControllerClient

updateApplicationServices

public void updateApplicationServices(String appName,
                                      List<String> services)
Specified by:
updateApplicationServices in interface CloudControllerClient

updateApplicationStaging

public void updateApplicationStaging(String appName,
                                     Staging staging)
Specified by:
updateApplicationStaging in interface CloudControllerClient

updateApplicationUris

public void updateApplicationUris(String appName,
                                  List<String> uris)
Specified by:
updateApplicationUris in interface CloudControllerClient

updateApplicationEnv

public void updateApplicationEnv(String appName,
                                 Map<String,String> env)
Specified by:
updateApplicationEnv in interface CloudControllerClient

updateApplicationEnv

public void updateApplicationEnv(String appName,
                                 List<String> env)
Specified by:
updateApplicationEnv in interface CloudControllerClient

bindService

public void bindService(String appName,
                        String serviceName)
Specified by:
bindService in interface CloudControllerClient

unbindService

public void unbindService(String appName,
                          String serviceName)
Specified by:
unbindService in interface CloudControllerClient

getApplicationInstances

public InstancesInfo getApplicationInstances(String appName)
Specified by:
getApplicationInstances in interface CloudControllerClient

getApplicationInstances

public InstancesInfo getApplicationInstances(CloudApplication app)
Specified by:
getApplicationInstances in interface CloudControllerClient

getCrashes

public CrashesInfo getCrashes(String appName)
Specified by:
getCrashes in interface CloudControllerClient

rename

public void rename(String appName,
                   String newName)
Specified by:
rename in interface CloudControllerClient

getDomainsForOrg

public List<CloudDomain> getDomainsForOrg()
Specified by:
getDomainsForOrg in interface CloudControllerClient

getDomains

public List<CloudDomain> getDomains()
Specified by:
getDomains in interface CloudControllerClient

addDomain

public void addDomain(String domainName)
Specified by:
addDomain in interface CloudControllerClient

deleteDomain

public void deleteDomain(String domainName)
Specified by:
deleteDomain in interface CloudControllerClient

removeDomain

public void removeDomain(String domainName)
Specified by:
removeDomain in interface CloudControllerClient

getRoutes

public List<CloudRoute> getRoutes(String domainName)
Specified by:
getRoutes in interface CloudControllerClient

addRoute

public void addRoute(String host,
                     String domainName)
Specified by:
addRoute in interface CloudControllerClient

deleteRoute

public void deleteRoute(String host,
                        String domainName)
Specified by:
deleteRoute in interface CloudControllerClient

getFileUrlPath

protected String getFileUrlPath()

getFileAppId

protected Object getFileAppId(String appName)


Copyright © 2013. All rights reserved.