private String email;
*/
public class CloudCredentials {
<<<<<<< HEAD
private boolean refreshable = true;
private String password;
private String clientId = "cf";
private String clientSecret = "";
private OAuth2AccessToken token;
private String proxyUser;
/**
* Create credentials using email and password.
*
* @param email email to authenticate with
* @param password the password
*/
public CloudCredentials(String email, String password) {
this.email = email;
this.password = password;
}
/**
* Create credentials using email, password, and client ID.
*
* @param email email to authenticate with
* @param password the password
* @param clientId the client ID to use for authorization
*/
public CloudCredentials(String email, String password, String clientId) {
this.email = email;
this.password = password;
this.clientId = clientId;
}
/**
* Create credentials using email, password and client ID.
* @param email email to authenticate with
* @param password the password
* @param clientId the client ID to use for authorization
* @param clientSecret the secret for the given client
*/
public CloudCredentials(String email, String password, String clientId, String clientSecret) {
this.email = email;
this.password = password;
this.clientId = clientId;
this.clientSecret = clientSecret;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
*/
public CloudCredentials(OAuth2AccessToken token) {
this.token = token;
}
/**
* Create credentials using a token and indicates if the token is
* refreshable or not.
*
* @param token token to use for authorization
* @param refreshable indicates if the token can be refreshed or not
*/
public CloudCredentials(OAuth2AccessToken token, boolean refreshable) {
this.token = token;
this.refreshable=refreshable;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
* @param clientId the client ID to use for authorization
*/
public CloudCredentials(OAuth2AccessToken token, String clientId) {
this.token = token;
this.clientId = clientId;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
* @param clientId the client ID to use for authorization
* @param clientSecret the password for the specified client
*/
public CloudCredentials(OAuth2AccessToken token, String clientId, String clientSecret) {
this.token = token;
this.clientId = clientId;
this.clientSecret = clientSecret;
}
/**
* Create proxy credentials.
*
* @param cloudCredentials credentials to use
* @param proxyForUser user to be proxied
*/
public CloudCredentials(CloudCredentials cloudCredentials, String proxyForUser) {
this.email = cloudCredentials.getEmail();
this.password = cloudCredentials.getPassword();
this.clientId = cloudCredentials.getClientId();
this.token = cloudCredentials.getToken();
this.proxyUser = proxyForUser;
}
/**
* Get the email.
*
* @return the email
*/
public String getEmail() {
return email;
}
/**
* Get the password.
*
* @return the password
*/
public String getPassword() {
return password;
}
/**
* Get the token.
*
* @return the token
*/
public OAuth2AccessToken getToken() {
return token;
}
/**
* Get the client ID.
*
* @return the client ID
*/
public String getClientId() {
return clientId;
}
/**
* Get the client secret
*
* @return the client secret
*/
public String getClientSecret() {
return clientSecret;
}
/**
* Get the proxy user.
*
* @return the proxy user
*/
public String getProxyUser() {
return proxyUser;
}
/**
* Is this a proxied set of credentials?
*
* @return whether a proxy user is set
*/
public boolean isProxyUserSet() {
return proxyUser != null;
}
/**
* Run commands as a different user. The authenticated user must be
* privileged to run as this user.
* @param user the user to proxy for
* @return credentials for the proxied user
*/
public CloudCredentials proxyForUser(String user) {
return new CloudCredentials(this, user);
}
/**
* Indicates weather the token stored in the cloud credentials can be
* refreshed or not. This is useful when the token stored in this
* object was obtained via implicit OAuth2 authentication and therefore
* can not be refreshed.
*
* @return weather the token can be refreshed
*/
public boolean isRefreshable() {
return refreshable;
}
=======
private String clientId = "cf";
private String clientSecret = "";
private String email;
private String password;
private String proxyUser;
private OAuth2AccessToken token;
/**
* Create credentials using email and password.
*
* @param email email to authenticate with
* @param password the password
*/
public CloudCredentials(String email, String password) {
this.email = email;
this.password = password;
}
/**
* Create credentials using email, password, and client ID.
*
* @param email email to authenticate with
* @param password the password
* @param clientId the client ID to use for authorization
*/
public CloudCredentials(String email, String password, String clientId) {
this.email = email;
this.password = password;
this.clientId = clientId;
}
/**
* Create credentials using email, password and client ID.
*
* @param email email to authenticate with
* @param password the password
* @param clientId the client ID to use for authorization
* @param clientSecret the secret for the given client
*/
public CloudCredentials(String email, String password, String clientId, String clientSecret) {
this.email = email;
this.password = password;
this.clientId = clientId;
this.clientSecret = clientSecret;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
*/
public CloudCredentials(OAuth2AccessToken token) {
this.token = token;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
* @param clientId the client ID to use for authorization
*/
public CloudCredentials(OAuth2AccessToken token, String clientId) {
this.token = token;
this.clientId = clientId;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
* @param clientId the client ID to use for authorization
* @param clientSecret the password for the specified client
*/
public CloudCredentials(OAuth2AccessToken token, String clientId, String clientSecret) {
this.token = token;
this.clientId = clientId;
this.clientSecret = clientSecret;
}
/**
* Create proxy credentials.
*
* @param cloudCredentials credentials to use
* @param proxyForUser user to be proxied
*/
public CloudCredentials(CloudCredentials cloudCredentials, String proxyForUser) {
this.email = cloudCredentials.getEmail();
this.password = cloudCredentials.getPassword();
this.clientId = cloudCredentials.getClientId();
this.token = cloudCredentials.getToken();
this.proxyUser = proxyForUser;
}
/**
* Get the client ID.
*
* @return the client ID
*/
public String getClientId() {
return clientId;
}
/**
* Get the client secret
*
* @return the client secret
*/
public String getClientSecret() {
return clientSecret;
}
/**
* Get the email.
*
* @return the email
*/
public String getEmail() {
return email;
}
/**
* Get the password.
*
* @return the password
*/
public String getPassword() {
return password;
}
/**
* Get the proxy user.
*
* @return the proxy user
*/
public String getProxyUser() {
return proxyUser;
}
/**
* Get the token.
*
* @return the token
*/
public OAuth2AccessToken getToken() {
return token;
}
/**
* Is this a proxied set of credentials?
*
* @return whether a proxy user is set
*/
public boolean isProxyUserSet() {
return proxyUser != null;
}
/**
* Run commands as a different user. The authenticated user must be privileged to run as this user.
*
* @param user the user to proxy for
* @return credentials for the proxied user
*/
public CloudCredentials proxyForUser(String user) {
return new CloudCredentials(this, user);
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
}
Solution content
*/
public class CloudCredentials {
private String clientId = "cf";
private String clientSecret = "";
private String email;
private String password;
private String proxyUser;
private boolean refreshable = true;
private OAuth2AccessToken token;
/**
* Create credentials using email and password.
*
* @param email email to authenticate with
* @param password the password
*/
public CloudCredentials(String email, String password) {
this.email = email;
this.password = password;
}
/**
* Create credentials using email, password, and client ID.
*
* @param email email to authenticate with
* @param password the password
* @param clientId the client ID to use for authorization
*/
public CloudCredentials(String email, String password, String clientId) {
this.email = email;
this.password = password;
this.clientId = clientId;
}
/**
* Create credentials using email, password and client ID.
*
* @param email email to authenticate with
* @param password the password
* @param clientId the client ID to use for authorization
* @param clientSecret the secret for the given client
*/
public CloudCredentials(String email, String password, String clientId, String clientSecret) {
this.email = email;
this.password = password;
this.clientId = clientId;
this.clientSecret = clientSecret;
/**
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
*/
public CloudCredentials(OAuth2AccessToken token) {
this.token = token;
}
/**
* Create credentials using a token and indicates if the token is refreshable or not.
*
* @param token token to use for authorization
* @param refreshable indicates if the token can be refreshed or not
*/
public CloudCredentials(OAuth2AccessToken token, boolean refreshable) {
this.token = token;
this.refreshable = refreshable;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
* @param clientId the client ID to use for authorization
*/
public CloudCredentials(OAuth2AccessToken token, String clientId) {
this.token = token;
this.clientId = clientId;
}
/**
* Create credentials using a token.
*
* @param token token to use for authorization
* @param clientId the client ID to use for authorization
* @param clientSecret the password for the specified client
*/
public CloudCredentials(OAuth2AccessToken token, String clientId, String clientSecret) {
this.token = token;
this.clientId = clientId;
this.clientSecret = clientSecret;
}
/**
* Create proxy credentials.
*
* @param cloudCredentials credentials to use
* @param proxyForUser user to be proxied
*/
public CloudCredentials(CloudCredentials cloudCredentials, String proxyForUser) {
this.email = cloudCredentials.getEmail();
this.password = cloudCredentials.getPassword();
this.clientId = cloudCredentials.getClientId();
this.token = cloudCredentials.getToken();
this.proxyUser = proxyForUser;
}
/**
* Get the client ID.
*
* @return the client ID
*/
public String getClientId() {
return clientId;
}
/**
* Get the client secret
*
* @return the client secret
*/
public String getClientSecret() {
return clientSecret;
}
/**
* Get the email.
*
* @return the email
*/
public String getEmail() {
return email;
}
/**
* Get the password.
*
* @return the password
*/
public String getPassword() {
return password;
}
/**
* Get the proxy user.
*
* @return the proxy user
*/
public String getProxyUser() {
return proxyUser;
}
/**
* Get the token.
*
* @return the token
*/
public OAuth2AccessToken getToken() {
return token;
}
* Is this a proxied set of credentials?
*
* @return whether a proxy user is set
*/
public boolean isProxyUserSet() {
return proxyUser != null;
}
/**
* Indicates weather the token stored in the cloud credentials can be refreshed or not. This is useful when the
* token stored in this object was obtained via implicit OAuth2 authentication and therefore can not be refreshed.
*
* @return weather the token can be refreshed
*/
public boolean isRefreshable() {
return refreshable;
}
/**
* Run commands as a different user. The authenticated user must be privileged to run as this user.
*
* @param user the user to proxy for
* @return credentials for the proxied user
*/
public CloudCredentials proxyForUser(String user) {
return new CloudCredentials(this, user);
}
}
File
CloudCredentials.java
Developer's decision
Manual
Kind of conflict
Attribute
Comment
Method declaration
Chunk
Conflicting content
}
*/
public class CloudFoundryClient implements CloudFoundryOperations {
<<<<<<< HEAD
private CloudControllerClient cc;
private CloudInfo info;
/**
* Construct client for anonymous user. Useful only to get to the '/info' endpoint.
*/
public CloudFoundryClient(URL cloudControllerUrl) {
this(null, cloudControllerUrl, null, (HttpProxyConfiguration) null, false);
}
public CloudFoundryClient(URL cloudControllerUrl, boolean trustSelfSignedCerts) {
this(null, cloudControllerUrl, null, (HttpProxyConfiguration) null, trustSelfSignedCerts);
}
public CloudFoundryClient(URL cloudControllerUrl, HttpProxyConfiguration httpProxyConfiguration) {
this(null, cloudControllerUrl, null, httpProxyConfiguration, false);
public CloudFoundryClient(URL cloudControllerUrl, HttpProxyConfiguration httpProxyConfiguration,
boolean trustSelfSignedCerts) {
this(null, cloudControllerUrl, null, httpProxyConfiguration, trustSelfSignedCerts);
}
/**
* Construct client without a default org and space.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl) {
this(credentials, cloudControllerUrl, null, (HttpProxyConfiguration) null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, null, (HttpProxyConfiguration) null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, null, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, null, httpProxyConfiguration, trustSelfSignedCerts);
}
/**
* Construct a client with a default CloudSpace.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace) {
this(credentials, cloudControllerUrl, sessionSpace, null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, sessionSpace, null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, sessionSpace, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
return cc.getApplicationEnvironment(appGuid);
}
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
Assert.notNull(cloudControllerUrl, "URL for cloud controller cannot be null");
CloudControllerClientFactory cloudControllerClientFactory =
new CloudControllerClientFactory(httpProxyConfiguration, trustSelfSignedCerts);
this.cc = cloudControllerClientFactory.newCloudController(cloudControllerUrl, credentials, sessionSpace);
}
/**
* Construct a client with a default space name and org name.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName) {
this(credentials, cloudControllerUrl, orgName, spaceName, null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, orgName, spaceName, null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, orgName, spaceName, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
Assert.notNull(cloudControllerUrl, "URL for cloud controller cannot be null");
CloudControllerClientFactory cloudControllerClientFactory =
new CloudControllerClientFactory(httpProxyConfiguration, trustSelfSignedCerts);
this.cc = cloudControllerClientFactory.newCloudController(cloudControllerUrl, credentials, orgName, spaceName);
}
/**
* Construct a client with a pre-configured CloudControllerClient
*/
public CloudFoundryClient(CloudControllerClient cc) {
this.cc = cc;
}
public void setResponseErrorHandler(ResponseErrorHandler errorHandler) {
cc.setResponseErrorHandler(errorHandler);
}
public URL getCloudControllerUrl() {
return cc.getCloudControllerUrl();
}
public CloudInfo getCloudInfo() {
if (info == null) {
info = cc.getInfo();
}
return info;
}
public List getSpaces() {
return cc.getSpaces();
}
public List getOrganizations() {
return cc.getOrganizations();
}
public void register(String email, String password) {
cc.register(email, password);
}
public void updatePassword(String newPassword) {
cc.updatePassword(newPassword);
}
public void updatePassword(CloudCredentials credentials, String newPassword) {
cc.updatePassword(credentials, newPassword);
}
public void unregister() {
cc.unregister();
}
public OAuth2AccessToken login() {
return cc.login();
}
public void logout() {
cc.logout();
}
public List getApplications() {
return cc.getApplications();
}
public CloudApplication getApplication(String appName) {
return cc.getApplication(appName);
}
public CloudApplication getApplication(UUID appGuid) {
return cc.getApplication(appGuid);
}
public Map getApplicationEnvironment(UUID appGuid) {
public Map getApplicationEnvironment(String appName) {
return cc.getApplicationEnvironment(appName);
}
public ApplicationStats getApplicationStats(String appName) {
return cc.getApplicationStats(appName);
}
public void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames) {
cc.createApplication(appName, staging, memory, uris, serviceNames);
}
public void createApplication(String appName, Staging staging, Integer disk, Integer memory, List uris,
List serviceNames) {
cc.createApplication(appName, staging, disk, memory, uris, serviceNames);
}
public void createService(CloudService service) {
cc.createService(service);
}
public void createUserProvidedService(CloudService service, Map credentials) {
cc.createUserProvidedService(service, credentials);
}
public void createUserProvidedService(CloudService service, Map credentials, String syslogDrainUrl) {
cc.createUserProvidedService(service, credentials, syslogDrainUrl);
}
@Override
public List deleteOrphanedRoutes() {
return cc.deleteOrphanedRoutes();
}
public void uploadApplication(String appName, String file) throws IOException {
cc.uploadApplication(appName, new File(file), null);
}
public void uploadApplication(String appName, File file) throws IOException {
cc.uploadApplication(appName, file, null);
}
public void uploadApplication(String appName, File file, UploadStatusCallback callback) throws IOException {
cc.uploadApplication(appName, file, callback);
}
public void uploadApplication(String appName, String fileName, InputStream inputStream) throws IOException {
cc.uploadApplication(appName, fileName, inputStream, null);
}
public void uploadApplication(String appName, String fileName, InputStream inputStream, UploadStatusCallback callback) throws IOException {
cc.uploadApplication(appName, fileName, inputStream, callback);
}
public void uploadApplication(String appName, ApplicationArchive archive) throws IOException {
cc.uploadApplication(appName, archive, null);
}
public void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback) throws IOException {
cc.uploadApplication(appName, archive, callback);
}
public StartingInfo startApplication(String appName) {
return cc.startApplication(appName);
}
public void debugApplication(String appName, DebugMode mode) {
cc.debugApplication(appName, mode);
}
public void stopApplication(String appName) {
cc.stopApplication(appName);
}
public StartingInfo restartApplication(String appName) {
return cc.restartApplication(appName);
}
public void deleteApplication(String appName) {
cc.deleteApplication(appName);
}
public void deleteAllApplications() {
cc.deleteAllApplications();
}
public void deleteAllServices() {
cc.deleteAllServices();
}
public void updateApplicationDiskQuota(String appName, int disk) {
cc.updateApplicationDiskQuota(appName, disk);
}
public void updateApplicationMemory(String appName, int memory) {
cc.updateApplicationMemory(appName, memory);
}
public void updateApplicationInstances(String appName, int instances) {
cc.updateApplicationInstances(appName, instances);
}
public void updateApplicationServices(String appName, List services) {
cc.updateApplicationServices(appName, services);
}
public void updateApplicationStaging(String appName, Staging staging) {
cc.updateApplicationStaging(appName, staging);
}
public void updateApplicationUris(String appName, List uris) {
cc.updateApplicationUris(appName, uris);
}
public void updateApplicationEnv(String appName, Map env) {
cc.updateApplicationEnv(appName, env);
}
public void updateApplicationEnv(String appName, List env) {
cc.updateApplicationEnv(appName, env);
}
public List getEvents() {
return cc.getEvents();
}
public List getApplicationEvents(String appName) {
return cc.getApplicationEvents(appName);
}
/**
* @deprecated use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
public Map getLogs(String appName) {
return cc.getLogs(appName);
}
public StreamingLogToken streamLogs(String appName, ApplicationLogListener listener) {
return cc.streamLogs(appName, listener);
}
public List getRecentLogs(String appName) {
return cc.getRecentLogs(appName);
}
/**
* @deprecated use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
public Map getCrashLogs(String appName) {
return cc.getCrashLogs(appName);
}
public String getStagingLogs(StartingInfo info, int offset) {
return cc.getStagingLogs(info, offset);
}
public String getFile(String appName, int instanceIndex, String filePath) {
return cc.getFile(appName, instanceIndex, filePath, 0, -1);
}
public String getFile(String appName, int instanceIndex, String filePath, int startPosition) {
Assert.isTrue(startPosition >= 0,
startPosition + " is not a valid value for start position, it should be 0 or greater.");
return cc.getFile(appName, instanceIndex, filePath, startPosition, -1);
}
public String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition) {
Assert.isTrue(startPosition >= 0,
startPosition + " is not a valid value for start position, it should be 0 or greater.");
Assert.isTrue(endPosition > startPosition,
endPosition + " is not a valid value for end position, it should be greater than startPosition " +
"which is " + startPosition + ".");
return cc.getFile(appName, instanceIndex, filePath, startPosition, endPosition - 1);
}
public void openFile(String appName, int instanceIndex, String filePath, ClientHttpResponseCallback callback) {
cc.openFile(appName, instanceIndex, filePath, callback);
}
public String getFileTail(String appName, int instanceIndex, String filePath, int length) {
Assert.isTrue(length > 0, length + " is not a valid value for length, it should be 1 or greater.");
return cc.getFile(appName, instanceIndex, filePath, -1, length);
}
// list services, un/provision services, modify instance
public List getServices() {
return cc.getServices();
}
public List getServiceBrokers() {
return cc.getServiceBrokers();
}
public CloudServiceBroker getServiceBroker(String name) {
return cc.getServiceBroker(name);
}
public void createServiceBroker(CloudServiceBroker serviceBroker) {
cc.createServiceBroker(serviceBroker);
}
public void updateServiceBroker(CloudServiceBroker serviceBroker) {
cc.updateServiceBroker(serviceBroker);
}
@Override
public void deleteServiceBroker(String name) {
cc.deleteServiceBroker(name);
}
@Override
public void updateServicePlanVisibilityForBroker(String name, boolean visibility) {
cc.updateServicePlanVisibilityForBroker(name, visibility);
}
public CloudService getService(String service) {
return cc.getService(service);
}
public CloudServiceInstance getServiceInstance(String service) {
return cc.getServiceInstance(service);
}
public void deleteService(String service) {
cc.deleteService(service);
}
=======
private CloudControllerClient cc;
private CloudInfo info;
/**
* Construct client for anonymous user. Useful only to get to the '/info' endpoint.
*/
public CloudFoundryClient(URL cloudControllerUrl) {
this(null, cloudControllerUrl, null, (HttpProxyConfiguration) null, false);
}
public CloudFoundryClient(URL cloudControllerUrl, boolean trustSelfSignedCerts) {
this(null, cloudControllerUrl, null, (HttpProxyConfiguration) null, trustSelfSignedCerts);
}
public CloudFoundryClient(URL cloudControllerUrl, HttpProxyConfiguration httpProxyConfiguration) {
this(null, cloudControllerUrl, null, httpProxyConfiguration, false);
}
public CloudFoundryClient(URL cloudControllerUrl, HttpProxyConfiguration httpProxyConfiguration,
boolean trustSelfSignedCerts) {
this(null, cloudControllerUrl, null, httpProxyConfiguration, trustSelfSignedCerts);
}
/**
* Construct client without a default org and space.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl) {
this(credentials, cloudControllerUrl, null, (HttpProxyConfiguration) null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, null, (HttpProxyConfiguration) null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, null, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, null, httpProxyConfiguration, trustSelfSignedCerts);
}
/**
* Construct a client with a default CloudSpace.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace) {
this(credentials, cloudControllerUrl, sessionSpace, null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, sessionSpace, null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, sessionSpace, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
Assert.notNull(cloudControllerUrl, "URL for cloud controller cannot be null");
CloudControllerClientFactory cloudControllerClientFactory =
new CloudControllerClientFactory(httpProxyConfiguration, trustSelfSignedCerts);
this.cc = cloudControllerClientFactory.newCloudController(cloudControllerUrl, credentials, sessionSpace);
}
/**
* Construct a client with a default space name and org name.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName) {
this(credentials, cloudControllerUrl, orgName, spaceName, null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, orgName, spaceName, null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, orgName, spaceName, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
Assert.notNull(cloudControllerUrl, "URL for cloud controller cannot be null");
CloudControllerClientFactory cloudControllerClientFactory =
new CloudControllerClientFactory(httpProxyConfiguration, trustSelfSignedCerts);
this.cc = cloudControllerClientFactory.newCloudController(cloudControllerUrl, credentials, orgName, spaceName);
}
/**
* Construct a client with a pre-configured CloudControllerClient
*/
public CloudFoundryClient(CloudControllerClient cc) {
this.cc = cc;
}
public void addDomain(String domainName) {
cc.addDomain(domainName);
}
public void addRoute(String host, String domainName) {
cc.addRoute(host, domainName);
}
public void bindService(String appName, String serviceName) {
cc.bindService(appName, serviceName);
}
public void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames) {
cc.createApplication(appName, staging, memory, uris, serviceNames);
}
public void createApplication(String appName, Staging staging, Integer disk, Integer memory, List uris,
List serviceNames) {
cc.createApplication(appName, staging, disk, memory, uris, serviceNames);
}
public void createQuota(CloudQuota quota) {
cc.createQuota(quota);
}
public void createService(CloudService service) {
cc.createService(service);
}
public void createServiceBroker(CloudServiceBroker serviceBroker) {
cc.createServiceBroker(serviceBroker);
}
@Override
public void createSpace(String spaceName) {
cc.createSpace(spaceName);
}
public void createUserProvidedService(CloudService service, Map credentials) {
cc.createUserProvidedService(service, credentials);
}
public void createUserProvidedService(CloudService service, Map credentials, String
syslogDrainUrl) {
cc.createUserProvidedService(service, credentials, syslogDrainUrl);
}
public void debugApplication(String appName, DebugMode mode) {
cc.debugApplication(appName, mode);
}
public void deleteAllApplications() {
cc.deleteAllApplications();
}
public void deleteAllServices() {
cc.deleteAllServices();
}
public void deleteApplication(String appName) {
cc.deleteApplication(appName);
}
public void deleteDomain(String domainName) {
cc.deleteDomain(domainName);
}
@Override
public List deleteOrphanedRoutes() {
return cc.deleteOrphanedRoutes();
}
public void deleteQuota(String quotaName) {
cc.deleteQuota(quotaName);
}
public void deleteRoute(String host, String domainName) {
cc.deleteRoute(host, domainName);
}
public void deleteService(String service) {
cc.deleteService(service);
}
@Override
public void deleteServiceBroker(String name) {
cc.deleteServiceBroker(name);
}
@Override
public void deleteSpace(String spaceName) {
cc.deleteSpace(spaceName);
}
public CloudApplication getApplication(String appName) {
return cc.getApplication(appName);
}
public CloudApplication getApplication(UUID appGuid) {
return cc.getApplication(appGuid);
}
public InstancesInfo getApplicationInstances(String appName) {
return cc.getApplicationInstances(appName);
}
public InstancesInfo getApplicationInstances(CloudApplication app) {
return cc.getApplicationInstances(app);
}
public ApplicationStats getApplicationStats(String appName) {
return cc.getApplicationStats(appName);
}
public List getApplications() {
return cc.getApplications();
}
public URL getCloudControllerUrl() {
return cc.getCloudControllerUrl();
}
public CloudInfo getCloudInfo() {
if (info == null) {
info = cc.getInfo();
}
return info;
}
/**
* @deprecated use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
public Map getCrashLogs(String appName) {
return cc.getCrashLogs(appName);
}
public CrashesInfo getCrashes(String appName) {
return cc.getCrashes(appName);
}
public CloudDomain getDefaultDomain() {
return cc.getDefaultDomain();
}
public List getDomains() {
return cc.getDomains();
}
public List getDomainsForOrg() {
return cc.getDomainsForOrg();
}
public String getFile(String appName, int instanceIndex, String filePath) {
return cc.getFile(appName, instanceIndex, filePath, 0, -1);
}
public String getFile(String appName, int instanceIndex, String filePath, int startPosition) {
Assert.isTrue(startPosition >= 0,
startPosition + " is not a valid value for start position, it should be 0 or greater.");
return cc.getFile(appName, instanceIndex, filePath, startPosition, -1);
}
public String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition) {
Assert.isTrue(startPosition >= 0,
startPosition + " is not a valid value for start position, it should be 0 or greater.");
Assert.isTrue(endPosition > startPosition,
endPosition + " is not a valid value for end position, it should be greater than startPosition " +
"which is " + startPosition + ".");
return cc.getFile(appName, instanceIndex, filePath, startPosition, endPosition - 1);
}
public String getFileTail(String appName, int instanceIndex, String filePath, int length) {
Assert.isTrue(length > 0, length + " is not a valid value for length, it should be 1 or greater.");
return cc.getFile(appName, instanceIndex, filePath, -1, length);
}
/**
* @deprecated use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
public Map getLogs(String appName) {
return cc.getLogs(appName);
}
public CloudOrganization getOrgByName(String orgName, boolean required) {
return cc.getOrgByName(orgName, required);
}
public List getOrganizations() {
return cc.getOrganizations();
}
public List getPrivateDomains() {
return cc.getPrivateDomains();
}
public CloudQuota getQuotaByName(String quotaName, boolean required) {
return cc.getQuotaByName(quotaName, required);
}
public List getQuotas() {
return cc.getQuotas();
}
public List getRecentLogs(String appName) {
return cc.getRecentLogs(appName);
}
public List getRoutes(String domainName) {
return cc.getRoutes(domainName);
}
public CloudService getService(String service) {
return cc.getService(service);
}
public CloudServiceBroker getServiceBroker(String name) {
return cc.getServiceBroker(name);
}
public List getServiceBrokers() {
return cc.getServiceBrokers();
}
public List getServiceOfferings() {
return cc.getServiceOfferings();
}
public List getServices() {
return cc.getServices();
}
public List getSharedDomains() {
return cc.getSharedDomains();
}
// list services, un/provision services, modify instance
@Override
public CloudSpace getSpace(String spaceName) {
return cc.getSpace(spaceName);
}
public List getSpaces() {
return cc.getSpaces();
}
public CloudStack getStack(String name) {
return cc.getStack(name);
}
public List getStacks() {
return cc.getStacks();
}
public String getStagingLogs(StartingInfo info, int offset) {
return cc.getStagingLogs(info, offset);
}
public OAuth2AccessToken login() {
return cc.login();
}
public void logout() {
cc.logout();
}
public void openFile(String appName, int instanceIndex, String filePath, ClientHttpResponseCallback callback) {
cc.openFile(appName, instanceIndex, filePath, callback);
}
public void register(String email, String password) {
cc.register(email, password);
}
public void registerRestLogListener(RestLogCallback callBack) {
cc.registerRestLogListener(callBack);
}
public void removeDomain(String domainName) {
cc.removeDomain(domainName);
}
public void rename(String appName, String newName) {
cc.rename(appName, newName);
}
public StartingInfo restartApplication(String appName) {
return cc.restartApplication(appName);
}
public void setQuotaToOrg(String orgName, String quotaName) {
cc.setQuotaToOrg(orgName, quotaName);
}
public void setResponseErrorHandler(ResponseErrorHandler errorHandler) {
cc.setResponseErrorHandler(errorHandler);
}
public StartingInfo startApplication(String appName) {
return cc.startApplication(appName);
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
public void stopApplication(String appName) {
cc.stopApplication(appName);
Solution content
*/
public class CloudFoundryClient implements CloudFoundryOperations {
private CloudControllerClient cc;
private CloudInfo info;
/**
* Construct client for anonymous user. Useful only to get to the '/info' endpoint.
*/
public CloudFoundryClient(URL cloudControllerUrl) {
this(null, cloudControllerUrl, null, (HttpProxyConfiguration) null, false);
}
public CloudFoundryClient(URL cloudControllerUrl, boolean trustSelfSignedCerts) {
this(null, cloudControllerUrl, null, (HttpProxyConfiguration) null, trustSelfSignedCerts);
}
public CloudFoundryClient(URL cloudControllerUrl, HttpProxyConfiguration httpProxyConfiguration) {
this(null, cloudControllerUrl, null, httpProxyConfiguration, false);
}
public CloudFoundryClient(URL cloudControllerUrl, HttpProxyConfiguration httpProxyConfiguration,
boolean trustSelfSignedCerts) {
this(null, cloudControllerUrl, null, httpProxyConfiguration, trustSelfSignedCerts);
}
/**
* Construct client without a default org and space.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl) {
this(credentials, cloudControllerUrl, null, (HttpProxyConfiguration) null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, null, (HttpProxyConfiguration) null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, null, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, null, httpProxyConfiguration, trustSelfSignedCerts);
}
/**
* Construct a client with a default CloudSpace.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace) {
this(credentials, cloudControllerUrl, sessionSpace, null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, sessionSpace, null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, sessionSpace, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, CloudSpace sessionSpace,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
Assert.notNull(cloudControllerUrl, "URL for cloud controller cannot be null");
CloudControllerClientFactory cloudControllerClientFactory =
new CloudControllerClientFactory(httpProxyConfiguration, trustSelfSignedCerts);
this.cc = cloudControllerClientFactory.newCloudController(cloudControllerUrl, credentials, sessionSpace);
}
/**
* Construct a client with a default space name and org name.
*/
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName) {
this(credentials, cloudControllerUrl, orgName, spaceName, null, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
boolean trustSelfSignedCerts) {
this(credentials, cloudControllerUrl, orgName, spaceName, null, trustSelfSignedCerts);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
HttpProxyConfiguration httpProxyConfiguration) {
this(credentials, cloudControllerUrl, orgName, spaceName, httpProxyConfiguration, false);
}
public CloudFoundryClient(CloudCredentials credentials, URL cloudControllerUrl, String orgName, String spaceName,
HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts) {
Assert.notNull(cloudControllerUrl, "URL for cloud controller cannot be null");
CloudControllerClientFactory cloudControllerClientFactory =
new CloudControllerClientFactory(httpProxyConfiguration, trustSelfSignedCerts);
this.cc = cloudControllerClientFactory.newCloudController(cloudControllerUrl, credentials, orgName, spaceName);
}
/**
* Construct a client with a pre-configured CloudControllerClient
*/
public CloudFoundryClient(CloudControllerClient cc) {
this.cc = cc;
}
public void addDomain(String domainName) {
cc.addDomain(domainName);
}
public void addRoute(String host, String domainName) {
cc.addRoute(host, domainName);
}
@Override
public void associateAuditorWithSpace(String spaceName) {
cc.associateAuditorWithSpace(null, spaceName, null);
}
@Override
public void associateAuditorWithSpace(String orgName, String spaceName) {
cc.associateAuditorWithSpace(orgName, spaceName, null);
}
@Override
public void associateAuditorWithSpace(String orgName, String spaceName, String userGuid) {
cc.associateAuditorWithSpace(orgName, spaceName, userGuid);
}
@Override
public void associateDeveloperWithSpace(String spaceName) {
cc.associateDeveloperWithSpace(null, spaceName, null);
}
@Override
public void associateDeveloperWithSpace(String orgName, String spaceName) {
cc.associateDeveloperWithSpace(orgName, spaceName, null);
}
@Override
public void associateDeveloperWithSpace(String orgName, String spaceName, String userGuid) {
cc.associateDeveloperWithSpace(orgName, spaceName, userGuid);
}
@Override
public void associateManagerWithSpace(String spaceName) {
cc.associateManagerWithSpace(null, spaceName, null);
}
@Override
public void associateManagerWithSpace(String orgName, String spaceName) {
}
cc.associateManagerWithSpace(orgName, spaceName, null);
}
@Override
public void associateManagerWithSpace(String orgName, String spaceName, String userGuid) {
cc.associateManagerWithSpace(orgName, spaceName, userGuid);
}
@Override
public void bindRunningSecurityGroup(String securityGroupName) {
cc.bindRunningSecurityGroup(securityGroupName);
}
@Override
public void bindSecurityGroup(String orgName, String spaceName, String securityGroupName) {
cc.bindSecurityGroup(orgName, spaceName, securityGroupName);
}
public void bindService(String appName, String serviceName) {
cc.bindService(appName, serviceName);
}
@Override
public void bindStagingSecurityGroup(String securityGroupName) {
cc.bindStagingSecurityGroup(securityGroupName);
}
public void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames) {
cc.createApplication(appName, staging, memory, uris, serviceNames);
}
public void createApplication(String appName, Staging staging, Integer disk, Integer memory, List uris,
List serviceNames) {
cc.createApplication(appName, staging, disk, memory, uris, serviceNames);
}
public void createQuota(CloudQuota quota) {
cc.createQuota(quota);
}
@Override
public void createSecurityGroup(CloudSecurityGroup securityGroup) {
cc.createSecurityGroup(securityGroup);
}
@Override
public void createSecurityGroup(String name, InputStream jsonRulesFile) {
cc.createSecurityGroup(name, jsonRulesFile);
}
public void createService(CloudService service) {
cc.createService(service);
}
public void createServiceBroker(CloudServiceBroker serviceBroker) {
cc.createServiceBroker(serviceBroker);
}
@Override
public void createSpace(String spaceName) {
cc.createSpace(spaceName);
}
public void createUserProvidedService(CloudService service, Map credentials) {
cc.createUserProvidedService(service, credentials);
}
public void createUserProvidedService(CloudService service, Map credentials, String
syslogDrainUrl) {
cc.createUserProvidedService(service, credentials, syslogDrainUrl);
}
public void debugApplication(String appName, DebugMode mode) {
cc.debugApplication(appName, mode);
}
public void deleteAllApplications() {
cc.deleteAllApplications();
}
public void deleteAllServices() {
cc.deleteAllServices();
}
public void deleteApplication(String appName) {
cc.deleteApplication(appName);
}
public void deleteDomain(String domainName) {
cc.deleteDomain(domainName);
}
@Override
public List deleteOrphanedRoutes() {
return cc.deleteOrphanedRoutes();
}
public void deleteQuota(String quotaName) {
cc.deleteQuota(quotaName);
}
public void deleteRoute(String host, String domainName) {
cc.deleteRoute(host, domainName);
@Override
public void deleteSecurityGroup(String securityGroupName) {
cc.deleteSecurityGroup(securityGroupName);
}
public void deleteService(String service) {
cc.deleteService(service);
}
@Override
public void deleteServiceBroker(String name) {
cc.deleteServiceBroker(name);
}
@Override
public void deleteSpace(String spaceName) {
cc.deleteSpace(spaceName);
}
public CloudApplication getApplication(String appName) {
return cc.getApplication(appName);
}
public CloudApplication getApplication(UUID appGuid) {
return cc.getApplication(appGuid);
}
public Map getApplicationEnvironment(UUID appGuid) {
return cc.getApplicationEnvironment(appGuid);
}
public Map getApplicationEnvironment(String appName) {
return cc.getApplicationEnvironment(appName);
}
public List getApplicationEvents(String appName) {
return cc.getApplicationEvents(appName);
}
public InstancesInfo getApplicationInstances(String appName) {
return cc.getApplicationInstances(appName);
}
public InstancesInfo getApplicationInstances(CloudApplication app) {
return cc.getApplicationInstances(app);
}
public ApplicationStats getApplicationStats(String appName) {
return cc.getApplicationStats(appName);
}
public List getApplications() {
return cc.getApplications();
}
public URL getCloudControllerUrl() {
return cc.getCloudControllerUrl();
}
public CloudInfo getCloudInfo() {
if (info == null) {
info = cc.getInfo();
}
return info;
}
/**
* @deprecated use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
public Map getCrashLogs(String appName) {
return cc.getCrashLogs(appName);
}
public CrashesInfo getCrashes(String appName) {
return cc.getCrashes(appName);
}
public CloudDomain getDefaultDomain() {
return cc.getDefaultDomain();
}
public List getDomains() {
return cc.getDomains();
}
public List getDomainsForOrg() {
return cc.getDomainsForOrg();
}
public List getEvents() {
return cc.getEvents();
}
public String getFile(String appName, int instanceIndex, String filePath) {
return cc.getFile(appName, instanceIndex, filePath, 0, -1);
}
public String getFile(String appName, int instanceIndex, String filePath, int startPosition) {
Assert.isTrue(startPosition >= 0,
startPosition + " is not a valid value for start position, it should be 0 or greater.");
return cc.getFile(appName, instanceIndex, filePath, startPosition, -1);
}
public String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition) {
Assert.isTrue(startPosition >= 0,
startPosition + " is not a valid value for start position, it should be 0 or greater.");
Assert.isTrue(endPosition > startPosition,
endPosition + " is not a valid value for end position, it should be greater than startPosition " +
"which is " + startPosition + ".");
return cc.getFile(appName, instanceIndex, filePath, startPosition, endPosition - 1);
}
// list services, un/provision services, modify instance
public String getFileTail(String appName, int instanceIndex, String filePath, int length) {
Assert.isTrue(length > 0, length + " is not a valid value for length, it should be 1 or greater.");
return cc.getFile(appName, instanceIndex, filePath, -1, length);
}
/**
* @deprecated use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
public Map getLogs(String appName) {
return cc.getLogs(appName);
}
public CloudOrganization getOrgByName(String orgName, boolean required) {
return cc.getOrgByName(orgName, required);
}
@Override
public Map getOrganizationUsers(String orgName) {
return cc.getOrganizationUsers(orgName);
}
public List getOrganizations() {
return cc.getOrganizations();
}
public List getPrivateDomains() {
return cc.getPrivateDomains();
}
public CloudQuota getQuotaByName(String quotaName, boolean required) {
return cc.getQuotaByName(quotaName, required);
}
public List getQuotas() {
return cc.getQuotas();
}
public List getRecentLogs(String appName) {
return cc.getRecentLogs(appName);
}
public List getRoutes(String domainName) {
return cc.getRoutes(domainName);
}
@Override
public List getRunningSecurityGroups() {
return cc.getRunningSecurityGroups();
}
@Override
public CloudSecurityGroup getSecurityGroup(String securityGroupName) {
return cc.getSecurityGroup(securityGroupName);
}
@Override
public List getSecurityGroups() {
return cc.getSecurityGroups();
}
public CloudService getService(String service) {
return cc.getService(service);
}
public CloudServiceBroker getServiceBroker(String name) {
return cc.getServiceBroker(name);
}
public List getServiceBrokers() {
return cc.getServiceBrokers();
}
public CloudServiceInstance getServiceInstance(String service) {
return cc.getServiceInstance(service);
}
public List getServiceOfferings() {
return cc.getServiceOfferings();
}
public List getServices() {
return cc.getServices();
}
public List getSharedDomains() {
return cc.getSharedDomains();
}
@Override
public CloudSpace getSpace(String spaceName) {
return cc.getSpace(spaceName);
}
@Override
public List getSpaceAuditors(String spaceName) {
return cc.getSpaceAuditors(null, spaceName);
}
@Override
public List getSpaceAuditors(String orgName, String spaceName) {
return cc.getSpaceAuditors(orgName, spaceName);
}
@Override
public List getSpaceDevelopers(String spaceName) {
return cc.getSpaceDevelopers(null, spaceName);
}
@Override
public List getSpaceDevelopers(String orgName, String spaceName) {
return cc.getSpaceDevelopers(orgName, spaceName);
}
@Override
public List getSpaceManagers(String spaceName) {
return cc.getSpaceManagers(null, spaceName);
}
@Override
public List getSpaceManagers(String orgName, String spaceName) {
return cc.getSpaceManagers(orgName, spaceName);
}
public List getSpaces() {
return cc.getSpaces();
}
@Override
public List getSpacesBoundToSecurityGroup(String securityGroupName) {
return cc.getSpacesBoundToSecurityGroup(securityGroupName);
}
public CloudStack getStack(String name) {
return cc.getStack(name);
}
public List getStacks() {
return cc.getStacks();
}
public String getStagingLogs(StartingInfo info, int offset) {
return cc.getStagingLogs(info, offset);
}
@Override
public List getStagingSecurityGroups() {
return cc.getStagingSecurityGroups();
}
public OAuth2AccessToken login() {
return cc.login();
}
public void logout() {
cc.logout();
}
public void openFile(String appName, int instanceIndex, String filePath, ClientHttpResponseCallback callback) {
cc.openFile(appName, instanceIndex, filePath, callback);
}
public void register(String email, String password) {
cc.register(email, password);
}
public void registerRestLogListener(RestLogCallback callBack) {
cc.registerRestLogListener(callBack);
}
public void removeDomain(String domainName) {
cc.removeDomain(domainName);
}
public void rename(String appName, String newName) {
cc.rename(appName, newName);
}
public StartingInfo restartApplication(String appName) {
return cc.restartApplication(appName);
}
public void setQuotaToOrg(String orgName, String quotaName) {
cc.setQuotaToOrg(orgName, quotaName);
}
public void setResponseErrorHandler(ResponseErrorHandler errorHandler) {
cc.setResponseErrorHandler(errorHandler);
}
public StartingInfo startApplication(String appName) {
return cc.startApplication(appName);
}
public void stopApplication(String appName) {
cc.stopApplication(appName);
File
CloudFoundryClient.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
Comment
Method declaration
Chunk
Conflicting content
cc.updateApplicationMemory(appName, memory);
}
<<<<<<< HEAD
public CrashesInfo getCrashes(String appName) {
return cc.getCrashes(appName);
}
public List getStacks() {
return cc.getStacks();
}
public CloudStack getStack(String name) {
return cc.getStack(name);
}
public void rename(String appName, String newName) {
cc.rename(appName, newName);
}
public List getDomainsForOrg() {
return cc.getDomainsForOrg();
}
public List getPrivateDomains() {
return cc.getPrivateDomains();
}
public List getSharedDomains() {
return cc.getSharedDomains();
}
public List getDomains() {
return cc.getDomains();
}
public CloudDomain getDefaultDomain() {
return cc.getDefaultDomain();
}
public void addDomain(String domainName) {
cc.addDomain(domainName);
}
public void deleteDomain(String domainName) {
cc.deleteDomain(domainName);
}
public void removeDomain(String domainName) {
cc.removeDomain(domainName);
}
public List getRoutes(String domainName) {
return cc.getRoutes(domainName);
}
public void addRoute(String host, String domainName) {
cc.addRoute(host, domainName);
}
public void deleteRoute(String host, String domainName) {
cc.deleteRoute(host, domainName);
}
public void registerRestLogListener(RestLogCallback callBack) {
cc.registerRestLogListener(callBack);
}
public void unRegisterRestLogListener(RestLogCallback callBack) {
cc.unRegisterRestLogListener(callBack);
}
public CloudOrganization getOrgByName(String orgName, boolean required){
return cc.getOrgByName(orgName, required);
}
public List getQuotas() {
return cc.getQuotas();
}
public CloudQuota getQuotaByName(String quotaName, boolean required) {
return cc.getQuotaByName(quotaName, required);
}
public void setQuotaToOrg(String orgName, String quotaName) {
cc.setQuotaToOrg(orgName, quotaName);
}
public void createQuota(CloudQuota quota) {
cc.createQuota(quota);
}
public void deleteQuota(String quotaName) {
cc.deleteQuota(quotaName);
}
public void updateQuota(CloudQuota quota, String name) {
cc.updateQuota(quota, name);
}
@Override
public void createSpace(String spaceName) {
cc.createSpace(spaceName);
}
@Override
public void deleteSpace(String spaceName) {
cc.deleteSpace(spaceName);
}
@Override
public CloudSpace getSpace(String spaceName) {
return cc.getSpace(spaceName);
}
@Override
public List getSpaceManagers(String spaceName) {
return cc.getSpaceManagers(null, spaceName);
}
@Override
public List getSpaceDevelopers(String spaceName) {
return cc.getSpaceDevelopers(null, spaceName);
}
@Override
public List getSpaceAuditors(String spaceName) {
return cc.getSpaceAuditors(null, spaceName);
}
@Override
public List getSpaceManagers(String orgName, String spaceName) {
return cc.getSpaceManagers(orgName, spaceName);
}
@Override
public List getSpaceDevelopers(String orgName, String spaceName) {
return cc.getSpaceDevelopers(orgName, spaceName);
}
@Override
public List getSpaceAuditors(String orgName, String spaceName) {
return cc.getSpaceAuditors(orgName, spaceName);
}
@Override
public void associateManagerWithSpace(String spaceName) {
cc.associateManagerWithSpace(null, spaceName, null);
}
@Override
public void associateDeveloperWithSpace(String spaceName) {
cc.associateDeveloperWithSpace(null, spaceName, null);
}
@Override
public void associateAuditorWithSpace(String spaceName) {
cc.associateAuditorWithSpace(null, spaceName, null);
}
@Override
public void associateManagerWithSpace(String orgName, String spaceName) {
cc.associateManagerWithSpace(orgName, spaceName, null);
}
@Override
public void associateDeveloperWithSpace(String orgName, String spaceName) {
cc.associateDeveloperWithSpace(orgName, spaceName, null);
}
@Override
public void associateAuditorWithSpace(String orgName, String spaceName) {
cc.associateAuditorWithSpace(orgName, spaceName, null);
}
@Override
public void associateManagerWithSpace(String orgName, String spaceName, String userGuid) {
cc.associateManagerWithSpace(orgName, spaceName, userGuid);
}
@Override
public void associateDeveloperWithSpace(String orgName, String spaceName, String userGuid) {
cc.associateDeveloperWithSpace(orgName, spaceName, userGuid);
}
@Override
public void associateAuditorWithSpace(String orgName, String spaceName, String userGuid) {
cc.associateAuditorWithSpace(orgName, spaceName, userGuid);
}
@Override
public List getSecurityGroups() {
return cc.getSecurityGroups();
}
@Override
public CloudSecurityGroup getSecurityGroup(String securityGroupName) {
return cc.getSecurityGroup(securityGroupName);
}
@Override
public void createSecurityGroup(CloudSecurityGroup securityGroup){
cc.createSecurityGroup(securityGroup);
}
@Override
public void createSecurityGroup(String name, InputStream jsonRulesFile) {
cc.createSecurityGroup(name, jsonRulesFile);
}
@Override
public void updateSecurityGroup(CloudSecurityGroup securityGroup) {
cc.updateSecurityGroup(securityGroup);
}
@Override
public void updateSecurityGroup(String name, InputStream jsonRulesFile) {
cc.updateSecurityGroup(name, jsonRulesFile);
}
@Override
public void deleteSecurityGroup(String securityGroupName) {
cc.deleteSecurityGroup(securityGroupName);
}
@Override
public List getStagingSecurityGroups() {
return cc.getStagingSecurityGroups();
}
@Override
public void bindStagingSecurityGroup(String securityGroupName) {
cc.bindStagingSecurityGroup(securityGroupName);
}
@Override
public void unbindStagingSecurityGroup(String securityGroupName) {
cc.unbindStagingSecurityGroup(securityGroupName);
}
@Override
public List getRunningSecurityGroups() {
return cc.getRunningSecurityGroups();
}
@Override
public void bindRunningSecurityGroup(String securityGroupName) {
cc.bindRunningSecurityGroup(securityGroupName);
}
@Override
public void unbindRunningSecurityGroup(String securityGroupName) {
cc.unbindRunningSecurityGroup(securityGroupName);
}
@Override
public void bindSecurityGroup(String orgName, String spaceName, String securityGroupName) {
cc.bindSecurityGroup(orgName, spaceName, securityGroupName);
}
@Override
public void unbindSecurityGroup(String orgName, String spaceName, String securityGroupName) {
cc.unbindSecurityGroup(orgName, spaceName, securityGroupName);
}
@Override
public Map getOrganizationUsers(String orgName) {
return cc.getOrganizationUsers(orgName);
}
@Override
public List getSpacesBoundToSecurityGroup(String securityGroupName) {
return cc.getSpacesBoundToSecurityGroup(securityGroupName);
}
=======
public void updateApplicationServices(String appName, List services) {
cc.updateApplicationServices(appName, services);
}
public void updateApplicationStaging(String appName, Staging staging) {
cc.updateApplicationStaging(appName, staging);
}
public void updateApplicationUris(String appName, List uris) {
cc.updateApplicationUris(appName, uris);
}
public void updatePassword(String newPassword) {
cc.updatePassword(newPassword);
}
public void updatePassword(CloudCredentials credentials, String newPassword) {
cc.updatePassword(credentials, newPassword);
}
public void updateQuota(CloudQuota quota, String name) {
cc.updateQuota(quota, name);
}
public void updateServiceBroker(CloudServiceBroker serviceBroker) {
cc.updateServiceBroker(serviceBroker);
}
@Override
public void updateServicePlanVisibilityForBroker(String name, boolean visibility) {
cc.updateServicePlanVisibilityForBroker(name, visibility);
}
public void uploadApplication(String appName, String file) throws IOException {
cc.uploadApplication(appName, new File(file), null);
}
public void uploadApplication(String appName, File file) throws IOException {
cc.uploadApplication(appName, file, null);
}
public void uploadApplication(String appName, File file, UploadStatusCallback callback) throws IOException {
cc.uploadApplication(appName, file, callback);
}
public void uploadApplication(String appName, String fileName, InputStream inputStream) throws IOException {
cc.uploadApplication(appName, fileName, inputStream, null);
}
public void uploadApplication(String appName, String fileName, InputStream inputStream, UploadStatusCallback
callback) throws IOException {
cc.uploadApplication(appName, fileName, inputStream, callback);
}
public void uploadApplication(String appName, ApplicationArchive archive) throws IOException {
cc.uploadApplication(appName, archive, null);
}
public void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback) throws
IOException {
cc.uploadApplication(appName, archive, callback);
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
}
/**
*/
public interface CloudFoundryOperations {
<<<<<<< HEAD
/**
* Override the default REST response error handler with a custom error handler.
*
* @param errorHandler
*/
void setResponseErrorHandler(ResponseErrorHandler errorHandler);
/**
* Get the URL used for the cloud controller.
*
* @return the cloud controller URL
*/
URL getCloudControllerUrl();
/**
* Get CloudInfo for the current cloud.
*
* @return CloudInfo object containing the cloud info
*/
CloudInfo getCloudInfo();
/**
* Get list of CloudSpaces for the current cloud.
*
* @return List of CloudSpace objects containing the space info
*/
List getSpaces();
/**
* Get list of space manager UUID for the space.
*
* @param spaceName name of the space
* @return List of space manager UUID
*/
List getSpaceManagers(String spaceName);
/**
* Get list of space developer UUID for the space.
*
* @param spaceName name of the space
* @return List of space developer UUID
*/
List getSpaceDevelopers(String spaceName);
/**
* Get list of space auditor UUID for the space.
*
* @param spaceName name of the space
* @return List of space auditor UUID
*/
List getSpaceAuditors(String spaceName);
/**
* Get list of space manager UUID for the space.
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @return List of space manager UUID
*/
List getSpaceManagers(String orgName, String spaceName);
/**
* Get list of space developer UUID for the space.
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @return List of space developer UUID
*/
List getSpaceDevelopers(String orgName, String spaceName);
/**
* Get list of space auditor UUID for the space.
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @return List of space auditor UUID
*/
List getSpaceAuditors(String orgName, String spaceName);
/**
* Associate current user to the space auditors role
*
* @param spaceName name of the space
*/
void associateAuditorWithSpace(String spaceName);
/**
* Associate current user to the space developer role
*
* @param spaceName name of the space
*/
void associateDeveloperWithSpace(String spaceName);
/**
* Associate current user to the space managers role
*
* @param spaceName name of the space
*/
void associateManagerWithSpace(String spaceName);
/**
* Associate current user to the space auditors role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
*/
void associateAuditorWithSpace(String orgName, String spaceName);
/**
* Associate current user to the space developer role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
*/
void associateDeveloperWithSpace(String orgName, String spaceName);
/**
* Associate current user to the space managers role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
*/
void associateManagerWithSpace(String orgName, String spaceName);
/**
* Associate a user to the space auditors role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @param userGuid guid of the user. If null, use current user. To retrieve user guid, use {@link #getOrganizationUsers(String) getOrganizationUsers } and search for username
*/
void associateAuditorWithSpace(String orgName, String spaceName, String userGuid);
/**
* Associate a user to the space developer role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @param userGuid guid of the user. If null, use current user. To retrieve user guid, use {@link #getOrganizationUsers(String) getOrganizationUsers } and search for username
*/
void associateDeveloperWithSpace(String orgName, String spaceName, String userGuid);
/**
* Associate a user to the space managers role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @param userGuid guid of the user. If null, use current user. To retrieve user guid, use {@link #getOrganizationUsers(String) getOrganizationUsers } and search for username
*/
void associateManagerWithSpace(String orgName, String spaceName, String userGuid);
/**
* Create a space with the specified name
* @param spaceName
*/
void createSpace(String spaceName);
/**
* Get space name with the specified name.
*
* @param spaceName name of the space
* @return the cloud space
*/
CloudSpace getSpace(String spaceName);
/**
* Delete a space with the specified name
*
* @param spaceName name of the space
*/
void deleteSpace(String spaceName);
/**
* Get list of CloudOrganizations for the current cloud.
*
* @return List of CloudOrganizations objects containing the organization info
*/
List getOrganizations();
/**
* Get the organization with the specified name.
*
* @param orgName name of organization
* @param required if true, and organization is not found, throw an exception
* @return
*/
CloudOrganization getOrgByName(String orgName, boolean required);
/**
* Register new user account with the provided credentials.
*
* @param email the email account
* @param password the password
*/
void register(String email, String password);
/**
* Update the password for the logged in user.
*
* @param newPassword the new password
*/
void updatePassword(String newPassword);
/**
* Update the password for the logged in user using
* the username/old_password provided in the credentials.
*
* @param credentials current credentials
* @param newPassword the new password
*/
void updatePassword(CloudCredentials credentials, String newPassword);
/**
* Unregister and log out the currently logged in user
*/
void unregister();
/**
* Login using the credentials already set for the client.
*
* @return authentication token
*/
OAuth2AccessToken login();
/**
* Logout closing the current session.
*/
void logout();
/**
* Get all cloud applications.
*
* @return list of cloud applications
*/
List getApplications();
/**
* Get cloud application with the specified name.
*
* @param appName name of the app
* @return the cloud application
*/
CloudApplication getApplication(String appName);
/**
* Get cloud application with the specified GUID.
*
* @param guid GUID of the app
* @return the cloud application
*/
CloudApplication getApplication(UUID guid);
/**
* Get application stats for the app with the specified name.
*
* @param appName name of the app
* @return the cloud application stats
*/
ApplicationStats getApplicationStats(String appName);
/**
* Get application environment variables for the app with the specified name.
*
* @param appName name of the app
* @return the cloud application environment variables
*/
Map getApplicationEnvironment(String appName);
/**
* Get application environment variables for the app with the specified GUID.
*
* @param appGuid GUID of the app
* @return the cloud application environment variables
*/
Map getApplicationEnvironment(UUID appGuid);
/**
* Create application.
*
* @param appName application name
* @param staging staging info
* @param memory memory to use in MB
* @param uris list of URIs for the app
* @param serviceNames list of service names to bind to app
*/
void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames);
/**
* Create application.
*
* @param appName application name
* @param staging staging info
* @param disk disk quota to use in MB
* @param memory memory to use in MB
* @param uris list of URIs for the app
* @param serviceNames list of service names to bind to app
*/
public void createApplication(String appName, Staging staging, Integer disk, Integer memory, List uris,
List serviceNames);
/**
* Create a service.
*
* @param service cloud service info
*/
void createService(CloudService service);
/**
* Create a user-provided service.
*
* @param service cloud service info
* @param credentials the user-provided service credentials
*/
void createUserProvidedService(CloudService service, Map credentials);
/**
* Create a user-provided service for logging.
*
* @param service cloud service info
* @param credentials the user-provided service credentials
* @param syslogDrainUrl for a logging service
*/
void createUserProvidedService(CloudService service, Map credentials, String syslogDrainUrl);
/**
* Delete routes that do not have any application which is assigned to them.
*/
List deleteOrphanedRoutes();
/**
* Upload an application to Cloud Foundry.
*
* @param appName application name
* @param file path to the application archive or folder
* @throws java.io.IOException
*/
void uploadApplication(String appName, String file) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param file the application archive or folder
* @throws java.io.IOException
*/
void uploadApplication(String appName, File file) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param file the application archive
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, File file, UploadStatusCallback callback) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* This form of uploadApplication will read the passed InputStream and copy the contents to a
* temporary file for upload.
*
* @param appName the application name
* @param fileName the logical name of the application file
* @param inputStream the InputStream to read from
* @throws java.io.IOException
*/
void uploadApplication(String appName, String fileName, InputStream inputStream) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* This form of uploadApplication will read the passed InputStream and copy the contents to a
* temporary file for upload.
*
* @param appName the application name
* @param fileName the logical name of the application file
* @param inputStream the InputStream to read from
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, String fileName, InputStream inputStream, UploadStatusCallback callback) throws IOException;
/**
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param archive the application archive
* @throws java.io.IOException
*/
void uploadApplication(String appName, ApplicationArchive archive) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param archive the application archive
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback) throws IOException;
/**
* Start application. May return starting info if the response obtained after the start request contains headers.
* If the response does not contain headers, null is returned instead.
*
* @param appName
* name of application
* @return Starting info containing response headers, if headers are present in the response. If there are no headers, return null.
*/
StartingInfo startApplication(String appName);
/**
* Debug application.
*
* @param appName name of application
* @param mode debug mode info
*/
void debugApplication(String appName, CloudApplication.DebugMode mode);
/**
* Stop application.
*
* @param appName name of application
*/
void stopApplication(String appName);
/**
* Restart application.
*
* @param appName name of application
*/
StartingInfo restartApplication(String appName);
/**
* Delete application.
*
* @param appName name of application
*/
void deleteApplication(String appName);
/**
* Delete all applications.
*/
void deleteAllApplications();
/**
* Delete all services.
*/
void deleteAllServices();
/**
* Update application disk quota.
*
* @param appName name of application
* @param disk new disk setting in MB
*/
void updateApplicationDiskQuota(String appName, int disk);
/**
* Update application memory.
*
* @param appName name of application
* @param memory new memory setting in MB
*/
void updateApplicationMemory(String appName, int memory);
/**
* Update application instances.
*
* @param appName name of application
* @param instances number of instances to use
*/
void updateApplicationInstances(String appName, int instances);
/**
* Update application services.
*
* @param appName name of appplication
* @param services list of services that should be bound to app
*/
void updateApplicationServices(String appName, List services);
/**
* Update application staging information.
*
* @param appName name of appplication
* @param staging staging information for the app
*/
void updateApplicationStaging(String appName, Staging staging);
/**
* Update application URIs.
*
* @param appName name of application
* @param uris list of URIs the app should use
*/
void updateApplicationUris(String appName, List uris);
/**
* Update application env using a map where the key specifies the name of the environment variable
* and the value the value of the environment variable..
*
* @param appName name of application
* @param env map of environment settings
*/
void updateApplicationEnv(String appName, Map env);
/**
* Update application env using a list of strings each with one environment setting.
*
* @param appName name of application
* @param env list of environment settings
*/
void updateApplicationEnv(String appName, List env);
/**
* Get system events.
*
* @return all system events
*/
List getEvents();
/**
* Get application events.
*
* @param appName name of application
* @return application events
*/
List getApplicationEvents(String appName);
/**
* Get logs from the deployed application. The logs
* will be returned in a Map keyed by the path of the log file
* (logs/stderr.log, logs/stdout.log).
* @param appName name of the application
* @return a Map containing the logs. The logs will be returned with the path to the log file used as the key and
* the full content of the log file will be returned as a String value for the corresponding key.
* @deprecated Use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
Map getLogs(String appName);
/**
* Stream application logs produced after this method is called.
*
* This method has 'tail'-like behavior. Every time there is a new log entry,
* it notifies the listener.
*
* @param appName the name of the application
* @param listener listener object to be notified
* @return token than can be used to cancel listening for logs
*/
StreamingLogToken streamLogs(String appName, ApplicationLogListener listener);
/**
* Stream recent log entries.
*
* Stream logs that were recently produced for an app.
*
* @param appName the name of the application
* @return the list of recent log entries
*/
List getRecentLogs(String appName);
/**
* Get logs from most recent crash of the deployed application. The logs
* will be returned in a Map keyed by the path of the log file
* (logs/stderr.log, logs/stdout.log).
*
* @param appName name of the application
* @return a Map containing the logs. The logs will be returned with the path to the log file used as the key and
* the full content of the log file will be returned as a String value for the corresponding key.
* @deprecated Use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
Map getCrashLogs(String appName);
/**
* Get the staging log while an application is starting. A null
* value indicates that no further checks for staging logs should occur as
* staging logs are no longer available.
*
* @param info
* starting information containing staging log file URL. Obtained
* after starting an application.
* @param offset
* starting position from where content should be retrieved.
* @return portion of the staging log content starting from the offset. It
* may contain multiple lines. Returns null if no further content is
* available.
*/
String getStagingLogs(StartingInfo info, int offset);
* Get the list of stacks available for staging applications.
*
* @return the list of available stacks
*/
List getStacks();
/**
* Get a stack by name.
*
* @param name the name of the stack to get
* @return the stack, or null if not found
*/
CloudStack getStack(String name);
/**
* Get file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath);
/**
* Get a the content, starting at a specific position, of a file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param startPosition the starting position of the file contents (inclusive)
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath, int startPosition);
/**
* Get a range of content of a file from the deployed application. The range begins at the specified startPosition
* and extends to the character at endPosition - 1.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param startPosition the starting position of the file contents (inclusive)
* @param endPosition the ending position of the file contents (exclusive)
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition);
/**
* Get a the last bytes, with length as specified, of content of a file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param length the length of the file contents to retrieve
*
* @return the contents of the file
*/
String getFileTail(String appName, int instanceIndex, String filePath, int length);
/**
* Provide the content of a file from the deployed application via callbacks.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param clientHttpResponseCallback callback object to receive file contents
*/
void openFile(String appName, int instanceIndex, String filePath, ClientHttpResponseCallback clientHttpResponseCallback);
/**
* Get list of cloud services.
*
* @return list of cloud services
*/
List getServices();
/**
* Get cloud service.
*
* @param service name of service
* @return the cloud service info
*/
CloudService getService(String service);
/**
* Get a service instance.
*
* @param service name of the service instance
* @return the service instance info
*/
CloudServiceInstance getServiceInstance(String service);
/**
* Delete cloud service.
*
* @param service name of service
*/
void deleteService(String service);
/**
* Get all service offerings.
*
* @return list of service offerings
*/
List getServiceOfferings();
/**
* Get all service brokers.
*
* @return
*/
List getServiceBrokers();
/**
* Get a service broker.
*
* @param name the service broker name
* @return the service broker
*/
CloudServiceBroker getServiceBroker(String name);
/**
* Create a service broker.
*
* @param serviceBroker cloud service broker info
*/
void createServiceBroker(CloudServiceBroker serviceBroker);
/**
* Update a service broker (unchanged forces catalog refresh).
*
* @param serviceBroker cloud service broker info
*/
void updateServiceBroker(CloudServiceBroker serviceBroker);
/**
* Delete a service broker.
*
* @param name the service broker name
*/
void deleteServiceBroker(String name);
/**
* Service plans are private by default when a service broker's catalog is
* fetched/updated. This method will update the visibility of all plans for
* a broker to either public or private.
*
* @param name the service broker name
* @param visibility true for public, false for private
*/
void updateServicePlanVisibilityForBroker(String name, boolean visibility);
/**
* Associate (provision) a service with an application.
*
* @param appName the application name
* @param serviceName the service name
*/
void bindService(String appName, String serviceName);
/**
* Un-associate (unprovision) a service from an application.
* @param appName the application name
* @param serviceName the service name
*/
void unbindService(String appName, String serviceName);
/**
* Get application instances info for application.
*
* @param appName name of application.
* @return instances info
*/
InstancesInfo getApplicationInstances(String appName);
/**
* Get application instances info for application.
*
* @param app the application.
* @return instances info
*/
InstancesInfo getApplicationInstances(CloudApplication app);
/**
* Get crashes info for application.
* @param appName name of application
* @return crashes info
*/
CrashesInfo getCrashes(String appName);
/**
* Rename an application.
*
* @param appName the current name
* @param newName the new name
*/
void rename(String appName, String newName);
/**
* Get list of all domain registered for the current organization.
*
* @return list of domains
*/
List getDomainsForOrg();
/**
* Get list of all private domains.
*
* @return list of private domains
*/
List getPrivateDomains();
/**
* Get list of all shared domains.
*
* @return list of shared domains
*/
List getSharedDomains();
/**
* Get list of all domain shared and private domains.
*
* @return list of domains
*/
List getDomains();
/**
* Gets the default domain for the current org, which is the first shared domain.
*
* @return the default domain
*/
CloudDomain getDefaultDomain();
/**
* Add a private domain in the current organization.
*
* @param domainName the domain to add
*/
void addDomain(String domainName);
/**
* Delete a private domain in the current organization.
*
* @param domainName the domain to remove
* @deprecated alias for {@link #deleteDomain}
*/
void removeDomain(String domainName);
/**
* Delete a private domain in the current organization.
*
* @param domainName the domain to delete
*/
void deleteDomain(String domainName);
/**
* Get the info for all routes for a domain.
*
* @param domainName the domain the routes belong to
* @return list of routes
*/
List getRoutes(String domainName);
/**
* Register a new route to the a domain.
*
* @param host the host of the route to register
* @param domainName the domain of the route to register
*/
void addRoute(String host, String domainName);
/**
* Delete a registered route from the space of the current session.
*
* @param host the host of the route to delete
* @param domainName the domain of the route to delete
*/
void deleteRoute(String host, String domainName);
/**
* Register a new RestLogCallback
* @param callBack the callback to be registered
*/
void registerRestLogListener(RestLogCallback callBack);
/**
* Un-register a RestLogCallback
*
* @param callBack the callback to be un-registered
*/
void unRegisterRestLogListener(RestLogCallback callBack);
/**
* Get quota by name
*
* @param quotaName
* @param required
* @return CloudQuota instance
*/
CloudQuota getQuotaByName(String quotaName, boolean required);
/**
* Set quota to organization
*
* @param orgName
* @param quotaName
*/
void setQuotaToOrg(String orgName, String quotaName);
/**
* Create quota
*
* @param quota
*/
void createQuota(CloudQuota quota);
/**
* Delete quota by name
*
* @param quotaName
*/
void deleteQuota(String quotaName);
/**
* Get quota definitions
*
* @return List
*/
List getQuotas();
/**
* Update Quota definition
*
* @param quota
* @param name
*/
void updateQuota(CloudQuota quota, String name);
/**
* Get a List of all application security groups.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @return a list of all the {@link CloudSecurityGroup}s in the system
*/
List getSecurityGroups();
/**
* Get a specific security group by name.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param securityGroupName The name of the security group
* @return the CloudSecurityGroup or null if no security groups exist with the
* given name
*/
CloudSecurityGroup getSecurityGroup(String securityGroupName);
/**
* Create a new CloudSecurityGroup.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param securityGroup
*/
void createSecurityGroup(CloudSecurityGroup securityGroup);
/**
* Create a new CloudSecurityGroup using a JSON rules file. This is equivalent to cf create-security-group SECURITY-GROUP PATH-TO-RULES-FILE
* when using the cf command line. See the Application Security Group documentation for more details.
*
* Example JSON-formatted rules file:
*
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param name the name for the security group
* @param jsonRulesFile An input stream that has a single array with JSON objects inside describing the rules
* @see http://docs.cloudfoundry.org/adminguide/app-sec-groups.html
*/
void createSecurityGroup(String name, InputStream jsonRulesFile);
/**
* Update an existing security group.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param securityGroup
* @throws IllegalArgumentException if a security group does not exist with the name of the given CloudSecurityGroup
*/
void updateSecurityGroup(CloudSecurityGroup securityGroup);
/**
* Updates a existing CloudSecurityGroup using a JSON rules file. This is equivalent to cf update-security-group SECURITY-GROUP PATH-TO-RULES-FILE
* when using the cf command line. See the Application Security Group documentation for more details.
*
* Example JSON-formatted rules file:
*
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param jsonRulesFile An input stream that has a single array with JSON objects inside describing the rules
* @throws IllegalArgumentException if a security group does not exist with the given name
* @see http://docs.cloudfoundry.org/adminguide/app-sec-groups.html
*/
void updateSecurityGroup(String name, InputStream jsonRulesFile);
* Deletes the security group with the given name.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param securityGroupName
* @throws IllegalArgumentException if a security group does not exist with the given name
*/
void deleteSecurityGroup(String securityGroupName);
/**
* Lists security groups in the staging set for applications.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*/
List getStagingSecurityGroups();
/**
* Bind a security group to the list of security groups to be used for staging applications.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*/
void bindStagingSecurityGroup(String securityGroupName);
/**
* Unbind a security group from the set of security groups for staging applications.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*/
void unbindStagingSecurityGroup(String securityGroupName);
/**
* List security groups in the set of security groups for running applications.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*/
List getRunningSecurityGroups();
/**
* Bind a security group to the list of security groups to be used for running applications.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*/
void bindRunningSecurityGroup(String securityGroupName);
/**
* Unbind a security group from the set of security groups for running applications.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*/
void unbindRunningSecurityGroup(String securityGroupName);
/**
* Gets all the spaces that are bound to the given security group.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*/
List getSpacesBoundToSecurityGroup(String securityGroupName);
/**
* Bind a security group to a space.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param orgName The name of the organization that the space is in.
* @param spaceName The name of the space
* @param securityGroupName The name of the security group to bind to the space
* @throws IllegalArgumentException if the org, space, or security group do not exist
*/
void bindSecurityGroup(String orgName, String spaceName, String securityGroupName);
/**
* Unbind a security group from a space.
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param orgName The name of the organization that the space is in.
* @param spaceName The name of the space
* @param securityGroupName The name of the security group to bind to the space
* @throws IllegalArgumentException if the org, space, or security group do not exist
*/
void unbindSecurityGroup(String orgName, String spaceName, String securityGroupName);
/**
* Get all users in the specified organization
*
* @param orgName organization name
* @return a Map CloudUser with username as key
* @throws IllegalArgumentException if the org do not exist
*/
Map getOrganizationUsers(String orgName);
=======
/**
* Add a private domain in the current organization.
*
* @param domainName the domain to add
*/
void addDomain(String domainName);
/**
* Register a new route to the a domain.
*
* @param host the host of the route to register
* @param domainName the domain of the route to register
*/
void addRoute(String host, String domainName);
/**
* Associate (provision) a service with an application.
*
* @param appName the application name
* @param serviceName the service name
*/
void bindService(String appName, String serviceName);
/**
* Create application.
*
* @param appName application name
* @param staging staging info
* @param memory memory to use in MB
* @param uris list of URIs for the app
* @param serviceNames list of service names to bind to app
*/
void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames);
/**
* Create application.
*
* @param appName application name
* @param staging staging info
* @param disk disk quota to use in MB
* @param memory memory to use in MB
* @param uris list of URIs for the app
* @param serviceNames list of service names to bind to app
*/
public void createApplication(String appName, Staging staging, Integer disk, Integer memory, List uris,
List serviceNames);
/**
* Create quota
*
* @param quota
*/
void createQuota(CloudQuota quota);
/**
* Create a service.
*
* @param service cloud service info
*/
void createService(CloudService service);
/**
* Create a service broker.
*
* @param serviceBroker cloud service broker info
*/
void createServiceBroker(CloudServiceBroker serviceBroker);
/**
* Create a space with the specified name
*
* @param spaceName
*/
void createSpace(String spaceName);
/**
* Create a user-provided service.
*
* @param service cloud service info
* @param credentials the user-provided service credentials
*/
void createUserProvidedService(CloudService service, Map credentials);
/**
* Create a user-provided service for logging.
*
* @param service cloud service info
* @param credentials the user-provided service credentials
* @param syslogDrainUrl for a logging service
*/
void createUserProvidedService(CloudService service, Map credentials, String syslogDrainUrl);
/**
* Debug application.
*
* @param appName name of application
* @param mode debug mode info
*/
void debugApplication(String appName, CloudApplication.DebugMode mode);
/**
* Delete all applications.
*/
void deleteAllApplications();
/**
* Delete all services.
*/
void deleteAllServices();
/**
* Delete application.
*
* @param appName name of application
*/
void deleteApplication(String appName);
/**
* Delete a private domain in the current organization.
*
* @param domainName the domain to delete
*/
void deleteDomain(String domainName);
/**
* Delete routes that do not have any application which is assigned to them.
*/
List deleteOrphanedRoutes();
/**
* Delete quota by name
*
* @param quotaName
*/
void deleteQuota(String quotaName);
/**
* Delete a registered route from the space of the current session.
*
* @param host the host of the route to delete
* @param domainName the domain of the route to delete
*/
void deleteRoute(String host, String domainName);
/**
* Delete cloud service.
*
* @param service name of service
*/
void deleteService(String service);
/**
* Delete a service broker.
*
* @param name the service broker name
*/
void deleteServiceBroker(String name);
/**
* Delete a space with the specified name
*
* @param spaceName name of the space
*/
void deleteSpace(String spaceName);
/**
* Get cloud application with the specified name.
*
* @param appName name of the app
* @return the cloud application
*/
CloudApplication getApplication(String appName);
/**
* Get application instances info for application.
*
* @param appName name of application.
* @return instances info
*/
InstancesInfo getApplicationInstances(String appName);
/**
* Get application instances info for application.
*
* @param app the application.
* @return instances info
*/
InstancesInfo getApplicationInstances(CloudApplication app);
/**
* Get application stats for the app with the specified name.
*
* @param appName name of the app
* @return the cloud application stats
*/
ApplicationStats getApplicationStats(String appName);
/**
* Get all cloud applications.
*
* @return list of cloud applications
*/
List getApplications();
/**
* Get the URL used for the cloud controller.
*
* @return the cloud controller URL
*/
URL getCloudControllerUrl();
/**
* Get CloudInfo for the current cloud.
*
* @return CloudInfo object containing the cloud info
*/
CloudInfo getCloudInfo();
/**
* Get logs from most recent crash of the deployed application. The logs will be returned in a Map keyed by the
* path
* of the log file (logs/stderr.log, logs/stdout.log).
*
* @param appName name of the application
/**
* @return a Map containing the logs. The logs will be returned with the path to the log file used as the key and
* the full content of the log file will be returned as a String value for the corresponding key.
* @deprecated Use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
Map getCrashLogs(String appName);
/**
* Get crashes info for application.
*
* @param appName name of application
* @return crashes info
*/
CrashesInfo getCrashes(String appName);
/**
* Gets the default domain for the current org, which is the first shared domain.
*
* @return the default domain
*/
CloudDomain getDefaultDomain();
/**
* Get list of all domain shared and private domains.
*
* @return list of domains
*/
List getDomains();
/**
* Get list of all domain registered for the current organization.
*
* @return list of domains
*/
List getDomainsForOrg();
/**
* Get file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath);
/**
* Get a the content, starting at a specific position, of a file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param startPosition the starting position of the file contents (inclusive)
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath, int startPosition);
/**
* Get a range of content of a file from the deployed application. The range begins at the specified startPosition
* and extends to the character at endPosition - 1.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param startPosition the starting position of the file contents (inclusive)
* @param endPosition the ending position of the file contents (exclusive)
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition);
/**
* Get a the last bytes, with length as specified, of content of a file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param length the length of the file contents to retrieve
* @return the contents of the file
*/
String getFileTail(String appName, int instanceIndex, String filePath, int length);
/**
* Get logs from the deployed application. The logs will be returned in a Map keyed by the path of the log file
* (logs/stderr.log, logs/stdout.log).
*
* @param appName name of the application
* @return a Map containing the logs. The logs will be returned with the path to the log file used as the key and
* the full content of the log file will be returned as a String value for the corresponding key.
* @deprecated Use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
Map getLogs(String appName);
/**
* Get list of CloudOrganizations for the current cloud.
*
List getStacks();
* @return List of CloudOrganizations objects containing the organization info
*/
List getOrganizations();
/**
* Get list of all private domains.
*
* @return list of private domains
*/
List getPrivateDomains();
/**
* Get quota by name
*
* @param quotaName
* @param required
* @return CloudQuota instance
*/
CloudQuota getQuotaByName(String quotaName, boolean required);
/**
* Get quota definitions
*
* @return List
*/
List getQuotas();
/**
* Stream recent log entries.
*
* Stream logs that were recently produced for an app.
*
* @param appName the name of the application
* @return the list of recent log entries
*/
List getRecentLogs(String appName);
/**
* Get the info for all routes for a domain.
*
* @param domainName the domain the routes belong to
* @return list of routes
*/
List getRoutes(String domainName);
/**
* Get cloud service.
*
* @param service name of service
* @return the cloud service info
*/
CloudService getService(String service);
/**
* Get a service broker.
*
* @param name the service broker name
* @return the service broker
*/
CloudServiceBroker getServiceBroker(String name);
/**
* Get all service brokers.
*
* @return
*/
List getServiceBrokers();
/**
* Get all service offerings.
*
* @return list of service offerings
*/
List getServiceOfferings();
/**
* Get list of cloud services.
*
* @return list of cloud services
*/
List getServices();
/**
* Get list of all shared domains.
*
* @return list of shared domains
*/
List getSharedDomains();
/**
* Get space name with the specified name.
*
* @param spaceName name of the space
* @return the cloud space
*/
CloudSpace getSpace(String spaceName);
/**
* Get list of CloudSpaces for the current cloud.
*
* @return List of CloudSpace objects containing the space info
*/
List getSpaces();
/**
* Get a stack by name.
*
* @param name the name of the stack to get
* @return the stack, or null if not found
*/
CloudStack getStack(String name);
/**
* Get the list of stacks available for staging applications.
*
* @return the list of available stacks
*/
* Get the staging log while an application is starting. A null value indicates that no further checks for staging
* logs should occur as staging logs are no longer available.
*
* @param info starting information containing staging log file URL. Obtained after starting an application.
* @param offset starting position from where content should be retrieved.
* @return portion of the staging log content starting from the offset. It may contain multiple lines. Returns null
* if no further content is available.
*/
String getStagingLogs(StartingInfo info, int offset);
/**
* Login using the credentials already set for the client.
*
* @return authentication token
*/
OAuth2AccessToken login();
/**
* Logout closing the current session.
*/
void logout();
/**
* Register new user account with the provided credentials.
*
* @param email the email account
* @param password the password
*/
void register(String email, String password);
/**
* Register a new RestLogCallback
*
* @param callBack the callback to be registered
*/
void registerRestLogListener(RestLogCallback callBack);
/**
* Delete a private domain in the current organization.
*
* @param domainName the domain to remove
* @deprecated alias for {@link #deleteDomain}
*/
void removeDomain(String domainName);
/**
* Rename an application.
*
* @param appName the current name
* @param newName the new name
*/
void rename(String appName, String newName);
/**
* Restart application.
*
* @param appName name of application
*/
StartingInfo restartApplication(String appName);
/**
* Set quota to organization
*
* @param orgName
* @param quotaName
*/
void setQuotaToOrg(String orgName, String quotaName);
/**
* Override the default REST response error handler with a custom error handler.
*
* @param errorHandler
*/
void setResponseErrorHandler(ResponseErrorHandler errorHandler);
/**
* Start application. May return starting info if the response obtained after the start request contains headers
* . If
* the response does not contain headers, null is returned instead.
*
* @param appName name of application
* @return Starting info containing response headers, if headers are present in the response. If there are no
* headers, return null.
*/
StartingInfo startApplication(String appName);
/**
* Stop application.
*
* @param appName name of application
*/
void stopApplication(String appName);
/**
* Stream application logs produced after this method is called.
*
* This method has 'tail'-like behavior. Every time there is a new log entry, it notifies the listener.
*
* @param appName the name of the application
* @param listener listener object to be notified
* @return token than can be used to cancel listening for logs
*/
StreamingLogToken streamLogs(String appName, ApplicationLogListener listener);
/**
* Un-register a RestLogCallback
*
* @param callBack the callback to be un-registered
*/
void unRegisterRestLogListener(RestLogCallback callBack);
/**
* Un-associate (unprovision) a service from an application.
*
* @param appName the application name
* @param serviceName the service name
*/
void unbindService(String appName, String serviceName);
/**
* Unregister and log out the currently logged in user
*/
void unregister();
/**
* Update application disk quota.
*
* @param appName name of application
* @param disk new disk setting in MB
*/
void updateApplicationDiskQuota(String appName, int disk);
/**
* Update application env using a map where the key specifies the name of the environment variable and the value the
* value of the environment variable..
*
* @param appName name of application
* @param env map of environment settings
*/
void updateApplicationEnv(String appName, Map env);
/**
* Update application env using a list of strings each with one environment setting.
*
* @param appName name of application
* @param env list of environment settings
*/
void updateApplicationEnv(String appName, List env);
/**
* Update application instances.
*
* @param appName name of application
* @param instances number of instances to use
*/
void updateApplicationInstances(String appName, int instances);
/**
* Update application memory.
*
* @param appName name of application
* @param memory new memory setting in MB
*/
void updateApplicationMemory(String appName, int memory);
/**
* Update application services.
*
* @param appName name of appplication
* @param services list of services that should be bound to app
*/
void updateApplicationServices(String appName, List services);
/**
* Update application staging information.
*
* @param appName name of appplication
* @param staging staging information for the app
*/
void updateApplicationStaging(String appName, Staging staging);
/**
* Update application URIs.
*
* @param appName name of application
* @param uris list of URIs the app should use
*/
void updateApplicationUris(String appName, List uris);
/**
* Update the password for the logged in user.
*
* @param newPassword the new password
*/
void updatePassword(String newPassword);
/**
* Update the password for the logged in user using the username/old_password provided in the credentials.
*
* @param credentials current credentials
* @param newPassword the new password
*/
void updatePassword(CloudCredentials credentials, String newPassword);
/**
* Update Quota definition
*
* @param quota
* @param name
*/
void updateQuota(CloudQuota quota, String name);
/**
* Update a service broker (unchanged forces catalog refresh).
*
* @param serviceBroker cloud service broker info
*/
void updateServiceBroker(CloudServiceBroker serviceBroker);
/**
* Service plans are private by default when a service broker's catalog is fetched/updated. This method will update
* the visibility of all plans for a broker to either public or private.
*
* @param name the service broker name
* @param visibility true for public, false for private
*/
void updateServicePlanVisibilityForBroker(String name, boolean visibility);
/**
* Upload an application to Cloud Foundry.
*
* @param appName application name
* @param file path to the application archive or folder
* @throws java.io.IOException
*/
void uploadApplication(String appName, String file) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param file the application archive or folder
* @throws java.io.IOException
*/
void uploadApplication(String appName, File file) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param file the application archive
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, File file, UploadStatusCallback callback) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* This form of uploadApplication will read the passed InputStream and copy the contents to a
* temporary file for upload.
*
* @param appName the application name
* @param fileName the logical name of the application file
* @param inputStream the InputStream to read from
* @throws java.io.IOException
*/
void uploadApplication(String appName, String fileName, InputStream inputStream) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* This form of uploadApplication will read the passed InputStream and copy the contents to a
* temporary file for upload.
*
* @param appName the application name
* @param fileName the logical name of the application file
* @param inputStream the InputStream to read from
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, String fileName, InputStream inputStream, UploadStatusCallback callback)
throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param archive the application archive
* @throws java.io.IOException
*/
void uploadApplication(String appName, ApplicationArchive archive) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param archive the application archive
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback) throws
IOException;
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
}
Solution content
*/
public interface CloudFoundryOperations {
/**
* Add a private domain in the current organization.
*
* @param domainName the domain to add
*/
void addDomain(String domainName);
/**
* Register a new route to the a domain.
*
* @param host the host of the route to register
* @param domainName the domain of the route to register
*/
void addRoute(String host, String domainName);
/**
* Associate current user to the space auditors role
*
* @param spaceName name of the space
*/
void associateAuditorWithSpace(String spaceName);
/**
* Associate current user to the space auditors role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
*/
void associateAuditorWithSpace(String orgName, String spaceName);
/**
* Associate a user to the space auditors role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @param userGuid guid of the user. If null, use current user. To retrieve user guid, use {@link
* #getOrganizationUsers(String) getOrganizationUsers } and search for username
*/
void associateAuditorWithSpace(String orgName, String spaceName, String userGuid);
/**
* Associate current user to the space developer role
*
* @param spaceName name of the space
*/
void associateDeveloperWithSpace(String spaceName);
/**
* Associate current user to the space developer role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
*/
void associateDeveloperWithSpace(String orgName, String spaceName);
/**
* Associate a user to the space developer role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @param userGuid guid of the user. If null, use current user. To retrieve user guid, use {@link
* #getOrganizationUsers(String) getOrganizationUsers } and search for username
*/
void associateDeveloperWithSpace(String orgName, String spaceName, String userGuid);
/**
* Associate current user to the space managers role
*
* @param spaceName name of the space
*/
void associateManagerWithSpace(String spaceName);
/**
* Associate current user to the space managers role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
*/
void associateManagerWithSpace(String orgName, String spaceName);
/**
* Associate a user to the space managers role
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @param userGuid guid of the user. If null, use current user. To retrieve user guid, use {@link
* #getOrganizationUsers(String) getOrganizationUsers } and search for username
*/
void associateManagerWithSpace(String orgName, String spaceName, String userGuid);
/**
* Bind a security group to the list of security groups to be used for running applications. This method
* requires the logged in user to have admin permissions in the cloud controller.
*/
void bindRunningSecurityGroup(String securityGroupName);
/**
* Bind a security group to a space. This method requires the logged in user to have admin permissions in the
* cloud controller.
*
* @param orgName The name of the organization that the space is in.
* @param spaceName The name of the space
* @param securityGroupName The name of the security group to bind to the space
* @throws IllegalArgumentException if the org, space, or security group do not exist
*/
void bindSecurityGroup(String orgName, String spaceName, String securityGroupName);
/**
* Associate (provision) a service with an application.
*
* @param appName the application name
* @param serviceName the service name
*/
void bindService(String appName, String serviceName);
/**
/**
* Bind a security group to the list of security groups to be used for staging applications. This method
* requires the logged in user to have admin permissions in the cloud controller.
*/
void bindStagingSecurityGroup(String securityGroupName);
/**
* Create application.
*
* @param appName application name
* @param staging staging info
* @param memory memory to use in MB
* @param uris list of URIs for the app
* @param serviceNames list of service names to bind to app
*/
void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames);
/**
* Create application.
*
* @param appName application name
* @param staging staging info
* @param disk disk quota to use in MB
* @param memory memory to use in MB
* @param uris list of URIs for the app
* @param serviceNames list of service names to bind to app
*/
public void createApplication(String appName, Staging staging, Integer disk, Integer memory, List uris,
List serviceNames);
/**
* Create quota
*
* @param quota
*/
void createQuota(CloudQuota quota);
/**
* Create a new CloudSecurityGroup. This method requires the logged in user to have admin permissions in the
* cloud controller.
*
* @param securityGroup
*/
void createSecurityGroup(CloudSecurityGroup securityGroup);
/**
* Create a new CloudSecurityGroup using a JSON rules file. This is equivalent to cf create-security-group
* SECURITY-GROUP PATH-TO-RULES-FILE when using the cf command line. See the Application Security Group
* documentation for more details. Example JSON-formatted rules file:
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param name the name for the security group
* @param jsonRulesFile An input stream that has a single array with JSON objects inside describing the rules
* @see http://docs.cloudfoundry.org/adminguide/app-sec-groups.html
*/
void createSecurityGroup(String name, InputStream jsonRulesFile);
/**
* Create a service.
*
* @param service cloud service info
*/
void createService(CloudService service);
/**
* Create a service broker.
*
* @param serviceBroker cloud service broker info
*/
void createServiceBroker(CloudServiceBroker serviceBroker);
/**
* Create a space with the specified name
*
* @param spaceName
*/
void createSpace(String spaceName);
/**
* Create a user-provided service.
*
* @param service cloud service info
* @param credentials the user-provided service credentials
*/
void createUserProvidedService(CloudService service, Map credentials);
* Create a user-provided service for logging.
*
* @param service cloud service info
* @param credentials the user-provided service credentials
* @param syslogDrainUrl for a logging service
*/
void createUserProvidedService(CloudService service, Map credentials, String syslogDrainUrl);
/**
* Debug application.
*
* @param appName name of application
* @param mode debug mode info
*/
void debugApplication(String appName, CloudApplication.DebugMode mode);
/**
* Delete all applications.
*/
void deleteAllApplications();
/**
* Delete all services.
*/
void deleteAllServices();
/**
* Delete application.
*
* @param appName name of application
*/
void deleteApplication(String appName);
/**
* Delete a private domain in the current organization.
*
* @param domainName the domain to delete
*/
void deleteDomain(String domainName);
/**
* Delete routes that do not have any application which is assigned to them.
*/
List deleteOrphanedRoutes();
/**
* Delete quota by name
*
* @param quotaName
*/
void deleteQuota(String quotaName);
/**
* Delete a registered route from the space of the current session.
*
* @param host the host of the route to delete
* @param domainName the domain of the route to delete
*/
void deleteRoute(String host, String domainName);
/**
* Deletes the security group with the given name. This method requires the logged in user to have admin
* permissions in the cloud controller.
*
* @param securityGroupName
* @throws IllegalArgumentException if a security group does not exist with the given name
*/
void deleteSecurityGroup(String securityGroupName);
/**
* Delete cloud service.
*
* @param service name of service
*/
void deleteService(String service);
/**
* Delete a service broker.
*
* @param name the service broker name
*/
void deleteServiceBroker(String name);
/**
* Delete a space with the specified name
*
* @param spaceName name of the space
*/
void deleteSpace(String spaceName);
/**
* Get cloud application with the specified name.
*
* @param appName name of the app
* @return the cloud application
*/
CloudApplication getApplication(String appName);
/**
* Get cloud application with the specified GUID.
*
* @param guid GUID of the app
* @return the cloud application
*/
CloudApplication getApplication(UUID guid);
/**
* Get application environment variables for the app with the specified name.
*
* @param appName name of the app
* @return the cloud application environment variables
*/
Map getApplicationEnvironment(String appName);
/**
* Get application environment variables for the app with the specified GUID.
*
* @param appGuid GUID of the app
* @return the cloud application environment variables
*/
Map getApplicationEnvironment(UUID appGuid);
/**
* Get application events.
*
* @param appName name of application
* @return application events
*/
List getApplicationEvents(String appName);
/**
* Get application instances info for application.
*
* @param appName name of application.
* @return instances info
*/
InstancesInfo getApplicationInstances(String appName);
/**
* Get application instances info for application.
*
* @param app the application.
* @return instances info
*/
InstancesInfo getApplicationInstances(CloudApplication app);
/**
* Get application stats for the app with the specified name.
*
* @param appName name of the app
* @return the cloud application stats
*/
ApplicationStats getApplicationStats(String appName);
/**
* Get all cloud applications.
*
* @return list of cloud applications
*/
List getApplications();
/**
* Get the URL used for the cloud controller.
*
* @return the cloud controller URL
*/
URL getCloudControllerUrl();
/**
* Get CloudInfo for the current cloud.
*
* @return CloudInfo object containing the cloud info
*/
CloudInfo getCloudInfo();
/**
* Get logs from most recent crash of the deployed application. The logs will be returned in a Map keyed by the path
* of the log file (logs/stderr.log, logs/stdout.log).
*
* @param appName name of the application
* @return a Map containing the logs. The logs will be returned with the path to the log file used as the key and
* the full content of the log file will be returned as a String value for the corresponding key.
* @deprecated Use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
Map getCrashLogs(String appName);
/**
* Get crashes info for application.
*
* @param appName name of application
* @return crashes info
*/
CrashesInfo getCrashes(String appName);
/**
* Gets the default domain for the current org, which is the first shared domain.
*
* @return the default domain
*/
CloudDomain getDefaultDomain();
/**
* Get list of all domain shared and private domains.
*
* @return list of domains
*/
List getDomains();
/**
* Get list of all domain registered for the current organization.
*
* @return list of domains
*/
List getDomainsForOrg();
/**
* Get system events.
*
* @return all system events
*/
List getEvents();
/**
* Get file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath);
/**
* Get a the content, starting at a specific position, of a file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param startPosition the starting position of the file contents (inclusive)
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath, int startPosition);
/**
* Get a range of content of a file from the deployed application. The range begins at the specified startPosition
* and extends to the character at endPosition - 1.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param startPosition the starting position of the file contents (inclusive)
* @param endPosition the ending position of the file contents (exclusive)
* @return the contents of the file
*/
String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition);
/**
* Get a the last bytes, with length as specified, of content of a file from the deployed application.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param length the length of the file contents to retrieve
* @return the contents of the file
*/
String getFileTail(String appName, int instanceIndex, String filePath, int length);
/**
* Get logs from the deployed application. The logs will be returned in a Map keyed by the path of the log file
* (logs/stderr.log, logs/stdout.log).
*
* @param appName name of the application
* @return a Map containing the logs. The logs will be returned with the path to the log file used as the key and
* the full content of the log file will be returned as a String value for the corresponding key.
* @deprecated Use {@link #streamLogs(String, ApplicationLogListener)} or {@link #getRecentLogs(String)}
*/
Map getLogs(String appName);
/**
* Get the organization with the specified name.
*
* @param orgName name of organization
* @param required if true, and organization is not found, throw an exception
* @return
*/
CloudOrganization getOrgByName(String orgName, boolean required);
/**
* Get all users in the specified organization
*
* @param orgName organization name
* @return a Map CloudUser with username as key
* @throws IllegalArgumentException if the org do not exist
*/
Map getOrganizationUsers(String orgName);
/**
* Get list of CloudOrganizations for the current cloud.
*
* @return List of CloudOrganizations objects containing the organization info
*/
List getOrganizations();
/**
* Get list of all private domains.
*
* @return list of private domains
*/
List getPrivateDomains();
/**
* Get quota by name
*
* @param quotaName
* @param required
* @return CloudQuota instance
*/
CloudQuota getQuotaByName(String quotaName, boolean required);
/**
* Get quota definitions
*
* @return List
*/
List getQuotas();
/**
* Stream recent log entries.
*
* Stream logs that were recently produced for an app.
*
* @param appName the name of the application
* @return the list of recent log entries
*/
List getRecentLogs(String appName);
/**
* Get the info for all routes for a domain.
*
* @param domainName the domain the routes belong to
* @return list of routes
*/
List getRoutes(String domainName);
/**
* List security groups in the set of security groups for running applications. This method requires the logged
* in user to have admin permissions in the cloud controller.
*/
List getRunningSecurityGroups();
/**
* Get a specific security group by name. This method requires the logged in user to have admin permissions in
* the cloud controller.
*
* @param securityGroupName The name of the security group
* @return the CloudSecurityGroup or null if no security groups exist with the given name
*/
CloudSecurityGroup getSecurityGroup(String securityGroupName);
/**
* Get a List of all application security groups. This method requires the logged in user to have admin
* permissions in the cloud controller.
*
* @return a list of all the {@link CloudSecurityGroup}s in the system
*/
List getSecurityGroups();
/**
* Get cloud service.
*
* @param service name of service
* @return the cloud service info
*/
CloudService getService(String service);
/**
* Get a service broker.
*
* @param name the service broker name
* @return the service broker
*/
CloudServiceBroker getServiceBroker(String name);
/**
* Get all service brokers.
*
* @return
*/
List getServiceBrokers();
/**
* Get a service instance.
*
* @param service name of the service instance
* @return the service instance info
*/
CloudServiceInstance getServiceInstance(String service);
/**
* Get all service offerings.
*
* @return list of service offerings
*/
List getServiceOfferings();
/**
* Get list of cloud services.
*
* @return list of cloud services
*/
List getServices();
/**
* Get list of all shared domains.
*
* @return list of shared domains
*/
List getSharedDomains();
/**
* Get space name with the specified name.
*
* @param spaceName name of the space
* @return the cloud space
*/
CloudSpace getSpace(String spaceName);
/**
* Get list of space auditor UUID for the space.
*
* @param spaceName name of the space
* @return List of space auditor UUID
*/
List getSpaceAuditors(String spaceName);
/**
* Get list of space auditor UUID for the space.
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @return List of space auditor UUID
*/
List getSpaceAuditors(String orgName, String spaceName);
/**
* Get list of space developer UUID for the space.
*
* @param spaceName name of the space
* @return List of space developer UUID
*/
List getSpaceDevelopers(String spaceName);
/**
* Get list of space developer UUID for the space.
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @return List of space developer UUID
*/
List getSpaceDevelopers(String orgName, String spaceName);
/**
* Get list of space manager UUID for the space.
*
* @param spaceName name of the space
* @return List of space manager UUID
*/
List getSpaceManagers(String spaceName);
/**
* Get list of space manager UUID for the space.
*
* @param orgName name of the organization containing the space
* @param spaceName name of the space
* @return List of space manager UUID
*/
List getSpaceManagers(String orgName, String spaceName);
/**
* Get list of CloudSpaces for the current cloud.
*
* @return List of CloudSpace objects containing the space info
*/
List getSpaces();
/**
* Gets all the spaces that are bound to the given security group. This method requires the logged in user to
* have admin permissions in the cloud controller.
*/
List getSpacesBoundToSecurityGroup(String securityGroupName);
/**
* Get a stack by name.
*
* @param name the name of the stack to get
* @return the stack, or null if not found
*/
CloudStack getStack(String name);
/**
* Get the list of stacks available for staging applications.
*
* @return the list of available stacks
*/
List getStacks();
/**
* Get the staging log while an application is starting. A null value indicates that no further checks for staging
* logs should occur as staging logs are no longer available.
*
* @param info starting information containing staging log file URL. Obtained after starting an application.
* @param offset starting position from where content should be retrieved.
* @return portion of the staging log content starting from the offset. It may contain multiple lines. Returns null
* if no further content is available.
*/
String getStagingLogs(StartingInfo info, int offset);
/**
* Lists security groups in the staging set for applications. This method requires the logged in user to have
* admin permissions in the cloud controller.
*/
List getStagingSecurityGroups();
/**
* Login using the credentials already set for the client.
*
* @return authentication token
*/
OAuth2AccessToken login();
/**
* Logout closing the current session.
*/
void logout();
/**
* Provide the content of a file from the deployed application via callbacks.
*
* @param appName name of the application
* @param instanceIndex instance index
* @param filePath path to the file
* @param clientHttpResponseCallback callback object to receive file contents
*/
void openFile(String appName, int instanceIndex, String filePath, ClientHttpResponseCallback
clientHttpResponseCallback);
/**
* Register new user account with the provided credentials.
*
* @param email the email account
* @param password the password
*/
void register(String email, String password);
/**
* Register a new RestLogCallback
*
* @param callBack the callback to be registered
*/
void registerRestLogListener(RestLogCallback callBack);
/**
* Delete a private domain in the current organization.
*
* @param domainName the domain to remove
* @deprecated alias for {@link #deleteDomain}
*/
void removeDomain(String domainName);
/**
* Rename an application.
*
* @param appName the current name
* @param newName the new name
*/
void rename(String appName, String newName);
/**
* Restart application.
*
* @param appName name of application
*/
StartingInfo restartApplication(String appName);
/**
* Set quota to organization
*
* @param orgName
* @param quotaName
*/
void setQuotaToOrg(String orgName, String quotaName);
/**
* Override the default REST response error handler with a custom error handler.
*
* @param errorHandler
*/
void setResponseErrorHandler(ResponseErrorHandler errorHandler);
/**
* Start application. May return starting info if the response obtained after the start request contains headers .
* If the response does not contain headers, null is returned instead.
*
* @param appName name of application
* @return Starting info containing response headers, if headers are present in the response. If there are no
* headers, return null.
*/
StartingInfo startApplication(String appName);
/**
* Stop application.
*
* @param appName name of application
*/
void stopApplication(String appName);
/**
* Stream application logs produced after this method is called.
*
* This method has 'tail'-like behavior. Every time there is a new log entry, it notifies the listener.
*
* @param appName the name of the application
* @param listener listener object to be notified
* @return token than can be used to cancel listening for logs
*/
StreamingLogToken streamLogs(String appName, ApplicationLogListener listener);
/**
* Un-register a RestLogCallback
*
* @param callBack the callback to be un-registered
*/
void unRegisterRestLogListener(RestLogCallback callBack);
/**
* Unbind a security group from the set of security groups for running applications. This method requires the
* logged in user to have admin permissions in the cloud controller.
*/
void unbindRunningSecurityGroup(String securityGroupName);
/**
* Unbind a security group from a space. This method requires the logged in user to have admin permissions in
* the cloud controller.
*
* @param orgName The name of the organization that the space is in.
* @param spaceName The name of the space
* @param securityGroupName The name of the security group to bind to the space
* @throws IllegalArgumentException if the org, space, or security group do not exist
*/
void unbindSecurityGroup(String orgName, String spaceName, String securityGroupName);
/**
* Un-associate (unprovision) a service from an application.
*
* @param appName the application name
* @param serviceName the service name
*/
void unbindService(String appName, String serviceName);
/**
* Unbind a security group from the set of security groups for staging applications. This method requires the
* logged in user to have admin permissions in the cloud controller.
*/
void unbindStagingSecurityGroup(String securityGroupName);
/**
* Unregister and log out the currently logged in user
*/
void unregister();
/**
* Update application disk quota.
*
* @param appName name of application
* @param disk new disk setting in MB
*/
void updateApplicationDiskQuota(String appName, int disk);
/**
* Update application env using a map where the key specifies the name of the environment variable and the value the
* value of the environment variable..
*
* @param appName name of application
* @param env map of environment settings
*/
void updateApplicationEnv(String appName, Map env);
/**
* Update application env using a list of strings each with one environment setting.
*
* @param appName name of application
* @param env list of environment settings
*/
void updateApplicationEnv(String appName, List env);
/**
* Update application instances.
*
* @param appName name of application
* @param instances number of instances to use
*/
void updateApplicationInstances(String appName, int instances);
/**
* Update application memory.
*
* @param appName name of application
* @param memory new memory setting in MB
*/
void updateApplicationMemory(String appName, int memory);
/**
* Update application services.
*
* @param appName name of appplication
* @param services list of services that should be bound to app
*/
void updateApplicationServices(String appName, List services);
/**
* Update application staging information.
*
* @param appName name of appplication
* @param staging staging information for the app
*/
void updateApplicationStaging(String appName, Staging staging);
/**
* Update application URIs.
*
* @param appName name of application
* @param uris list of URIs the app should use
*/
void updateApplicationUris(String appName, List uris);
/**
* Update the password for the logged in user.
*
* @param newPassword the new password
*/
void updatePassword(String newPassword);
/**
* Update the password for the logged in user using the username/old_password provided in the credentials.
*
* @param credentials current credentials
* @param newPassword the new password
*/
void updatePassword(CloudCredentials credentials, String newPassword);
/**
* Update Quota definition
*
* @param quota
* @param name
*/
void updateQuota(CloudQuota quota, String name);
/**
* Update an existing security group. This method requires the logged in user to have admin permissions in the
* cloud controller.
*
* @param securityGroup
* @throws IllegalArgumentException if a security group does not exist with the name of the given
* CloudSecurityGroup
*/
void updateSecurityGroup(CloudSecurityGroup securityGroup);
/**
* Updates a existing CloudSecurityGroup using a JSON rules file. This is equivalent to cf
* update-security-group SECURITY-GROUP PATH-TO-RULES-FILE when using the cf command line. See the
* Application Security Group documentation for more details. Example JSON-formatted rules file:
*
* This method requires the logged in user to have admin permissions in the cloud controller.
*
* @param jsonRulesFile An input stream that has a single array with JSON objects inside describing the rules
* @throws IllegalArgumentException if a security group does not exist with the given name
* @see http://docs.cloudfoundry.org/adminguide/app-sec-groups.html
*/
void updateSecurityGroup(String name, InputStream jsonRulesFile);
/**
* Update a service broker (unchanged forces catalog refresh).
*
* @param serviceBroker cloud service broker info
*/
void updateServiceBroker(CloudServiceBroker serviceBroker);
/**
* Service plans are private by default when a service broker's catalog is fetched/updated. This method will update
* the visibility of all plans for a broker to either public or private.
*
* @param name the service broker name
* @param visibility true for public, false for private
*/
void updateServicePlanVisibilityForBroker(String name, boolean visibility);
/**
* Upload an application to Cloud Foundry.
*
* @param appName application name
* @param file path to the application archive or folder
* @throws java.io.IOException
*/
void uploadApplication(String appName, String file) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param file the application archive or folder
* @throws java.io.IOException
*/
void uploadApplication(String appName, File file) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param file the application archive
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, File file, UploadStatusCallback callback) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* This form of uploadApplication will read the passed InputStream and copy the contents to a
* temporary file for upload.
*
* @param appName the application name
* @param fileName the logical name of the application file
* @param inputStream the InputStream to read from
* @throws java.io.IOException
*/
void uploadApplication(String appName, String fileName, InputStream inputStream) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* This form of uploadApplication will read the passed InputStream and copy the contents to a
* temporary file for upload.
*
* @param appName the application name
* @param fileName the logical name of the application file
* @param inputStream the InputStream to read from
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, String fileName, InputStream inputStream, UploadStatusCallback callback)
throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param archive the application archive
* @throws java.io.IOException
*/
void uploadApplication(String appName, ApplicationArchive archive) throws IOException;
/**
* Upload an application to Cloud Foundry.
*
* @param appName the application name
* @param archive the application archive
* @param callback a callback interface used to provide progress information or null
* @throws java.io.IOException
*/
void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback) throws
IOException;
}
File
CloudFoundryOperations.java
Developer's decision
Manual
Kind of conflict
Comment
Method interface
Chunk
Conflicting content
.NONE)
public class CloudApplication extends CloudEntity {
<<<<<<< HEAD
private static final String COMMAND_KEY = "command";
private static final String BUILDPACK_URL_KEY = "buildpack";
private static final String DETECTED_BUILDPACK_KEY = "detected_buildpack";
private static final String MEMORY_KEY = "memory";
private static final String DISK_KEY = "disk_quota";
private CloudSpace space;
private Staging staging;
private int instances;
private int memory;
private int diskQuota;
private List uris;
private List services;
private AppState state;
private DebugMode debug;
private int runningInstances;
private List env = new ArrayList();
public CloudApplication(Meta meta, String name) {
super(meta, name);
}
public CloudApplication(String name, String command, String buildpackUrl, int memory, int instances,
List uris, List serviceNames,
AppState state) {
super(CloudEntity.Meta.defaultMeta(), name);
this.staging = new Staging(command, buildpackUrl);
this.memory = memory;
this.instances = instances;
this.uris = uris;
this.services = serviceNames;
this.state = state;
}
@SuppressWarnings("unchecked")
public CloudApplication(Map attributes) {
super(CloudEntity.Meta.defaultMeta(), parse(attributes.get("name")));
instances = (Integer)attributes.get("instances");
Integer runningInstancesAttribute = (Integer) attributes.get("runningInstances");
if (runningInstancesAttribute != null) {
runningInstances = runningInstancesAttribute;
}
uris = (List)attributes.get("uris");
services = (List)attributes.get("services");
state = AppState.valueOf((String) attributes.get("state"));
if (attributes.containsKey("memory")) {
memory = (Integer) attributes.get("memory");
}
if (attributes.containsKey("disk_quota")) {
diskQuota = (Integer) attributes.get("disk_quota");
}
env = (List) attributes.get("env");
Map metaValue = parse(Map.class,
attributes.get("meta"));
if (metaValue != null) {
String debugAttribute = (String) metaValue.get("debug");
if (debugAttribute != null) {
debug = DebugMode.valueOf(debugAttribute);
}
long created = parse(Long.class, metaValue.get("created"));
Date createdDate = created != 0 ? new Date(created * 1000) : null;
setMeta(new Meta(null, createdDate, null));
String command = null;
if (metaValue.containsKey(COMMAND_KEY)) {
command = (String) metaValue.get(COMMAND_KEY);
}
String buildpackUrl = null;
if (metaValue.containsKey(BUILDPACK_URL_KEY)) {
buildpackUrl = (String) metaValue.get(BUILDPACK_URL_KEY);
}
String detectedBuildpack = null;
if (metaValue.containsKey(DETECTED_BUILDPACK_KEY)) {
detectedBuildpack = (String) metaValue.get(DETECTED_BUILDPACK_KEY);
}
setStaging(new Staging(command, buildpackUrl, detectedBuildpack));
}
}
public CloudSpace getSpace() {
return space;
}
public void setSpace(CloudSpace space) {
this.space = space;
}
public enum AppState {
UPDATING, STARTED, STOPPED
}
public enum DebugMode {
run,
suspend
}
public Staging getStaging() {
return staging;
}
public void setStaging(Staging staging) {
this.staging = staging;
}
// for backward compatibility
public Map getResources() {
Map resources = new HashMap();
resources.put(MEMORY_KEY, memory);
resources.put(DISK_KEY, diskQuota);
return resources;
}
public int getInstances() {
return instances;
}
public void setInstances(int instances) {
this.instances = instances;
}
public int getDiskQuota() {
return diskQuota;
}
public void setDiskQuota(int diskQuota) {
this.diskQuota = diskQuota;
}
public int getMemory() {
return memory;
}
public void setMemory(int memory) {
this.memory = memory;
}
public List getUris() {
return uris;
}
public void setUris(List uris) {
this.uris = uris;
}
public AppState getState() {
return state;
}
public void setState(AppState state) {
this.state = state;
}
public DebugMode getDebug() {
return debug;
}
public void setDebug(DebugMode debug) {
this.debug = debug;
}
public List getServices() {
return services;
}
public void setServices(List services) {
this.services = services;
}
public int getRunningInstances() {
return runningInstances;
}
public void setRunningInstances(int runningInstances) {
this.runningInstances = runningInstances;
}
public Map getEnvAsMap() {
Map envMap = new HashMap();
for (String nameAndValue : env) {
String[] parts = nameAndValue.split("=", 2);
envMap.put(parts[0], parts.length == 2 && parts[1].length() > 0 ? parts[1] : null);
}
return envMap;
}
public List getEnv() {
return env;
}
public void setEnv(Map
Solution content
.NONE)
public class CloudApplication extends CloudEntity {
private static final String BUILDPACK_URL_KEY = "buildpack";
private static final String COMMAND_KEY = "command";
private static final String DETECTED_BUILDPACK_KEY = "detected_buildpack";
private static final String DISK_KEY = "disk_quota";
private static final String MEMORY_KEY = "memory";
private DebugMode debug;
private int diskQuota;
private List env = new ArrayList();
private int instances;
private int memory;
private int runningInstances;
private List services;
private CloudSpace space;
private Staging staging;
private AppState state;
private List uris;
public CloudApplication(Meta meta, String name) {
super(meta, name);
}
public CloudApplication(String name, String command, String buildpackUrl, int memory, int instances,
List uris, List serviceNames,
AppState state) {
super(CloudEntity.Meta.defaultMeta(), name);
this.staging = new Staging(command, buildpackUrl);
this.memory = memory;
this.instances = instances;
this.uris = uris;
this.services = serviceNames;
this.state = state;
}
@SuppressWarnings("unchecked")
public CloudApplication(Map attributes) {
super(CloudEntity.Meta.defaultMeta(), parse(attributes.get("name")));
instances = (Integer) attributes.get("instances");
Integer runningInstancesAttribute = (Integer) attributes.get("runningInstances");
if (runningInstancesAttribute != null) {
runningInstances = runningInstancesAttribute;
}
uris = (List) attributes.get("uris");
services = (List) attributes.get("services");
state = AppState.valueOf((String) attributes.get("state"));
if (attributes.containsKey("memory")) {
memory = (Integer) attributes.get("memory");
}
if (attributes.containsKey("disk_quota")) {
diskQuota = (Integer) attributes.get("disk_quota");
}
env = (List) attributes.get("env");
Map metaValue = parse(Map.class,
attributes.get("meta"));
if (metaValue != null) {
String debugAttribute = (String) metaValue.get("debug");
if (debugAttribute != null) {
debug = DebugMode.valueOf(debugAttribute);
}
long created = parse(Long.class, metaValue.get("created"));
Date createdDate = created != 0 ? new Date(created * 1000) : null;
setMeta(new Meta(null, createdDate, null));
String command = null;
if (metaValue.containsKey(COMMAND_KEY)) {
command = (String) metaValue.get(COMMAND_KEY);
}
String buildpackUrl = null;
if (metaValue.containsKey(BUILDPACK_URL_KEY)) {
buildpackUrl = (String) metaValue.get(BUILDPACK_URL_KEY);
}
String detectedBuildpack = null;
if (metaValue.containsKey(DETECTED_BUILDPACK_KEY)) {
detectedBuildpack = (String) metaValue.get(DETECTED_BUILDPACK_KEY);
}
setStaging(new Staging(command, buildpackUrl, detectedBuildpack));
}
}
public DebugMode getDebug() {
return debug;
}
public void setDebug(DebugMode debug) {
this.debug = debug;
}
public int getDiskQuota() {
return diskQuota;
}
public void setDiskQuota(int diskQuota) {
this.diskQuota = diskQuota;
}
public List getEnv() {
return env;
}
public void setEnv(Map env) {
List joined = new ArrayList();
for (Map.Entry entry : env.entrySet()) {
// skip this environment variable if the key is null
if (null == entry.getKey()) {
continue;
}
String value;
// check that there is a value. If it is null, the value should be an empty string
if (null == entry.getValue()) {
value = "";
} else {
value = entry.getValue().toString();
}
joined.add(entry.getKey().toString() + '=' + value);
}
this.env = joined;
}
public Map getEnvAsMap() {
Map envMap = new HashMap();
for (String nameAndValue : env) {
String[] parts = nameAndValue.split("=", 2);
envMap.put(parts[0], parts.length == 2 && parts[1].length() > 0 ? parts[1] : null);
}
return envMap;
}
public int getInstances() {
return instances;
}
public void setInstances(int instances) {
this.instances = instances;
}
public int getMemory() {
return memory;
}
public void setMemory(int memory) {
this.memory = memory;
}
// for backward compatibility
public Map getResources() {
Map resources = new HashMap();
resources.put(MEMORY_KEY, memory);
resources.put(DISK_KEY, diskQuota);
return resources;
}
public int getRunningInstances() {
return runningInstances;
}
public void setRunningInstances(int runningInstances) {
this.runningInstances = runningInstances;
}
public List getServices() {
return services;
}
public void setServices(List services) {
this.services = services;
}
public CloudSpace getSpace() {
return space;
}
public void setSpace(CloudSpace space) {
this.space = space;
}
public Staging getStaging() {
return staging;
}
public void setStaging(Staging staging) {
this.staging = staging;
}
public AppState getState() {
return state;
}
public void setState(AppState state) {
this.state = state;
}
public List getUris() {
return uris;
}
public void setUris(List uris) {
this.uris = uris;
}
@Override
public String toString() {
return "CloudApplication [staging=" + staging + ", instances="
+ instances + ", name=" + getName()
+ ", memory=" + memory + ", diskQuota=" + diskQuota
+ ", state=" + state + ", debug=" + debug + ", uris=" + uris + ", services=" + services
+ ", env=" + env + ", space=" + space.getName() + "]";
}
public enum AppState {
UPDATING, STARTED, STOPPED
}
public enum DebugMode {
run,
suspend
}
}
File
CloudApplication.java
Developer's decision
Combination
Kind of conflict
Annotation
Attribute
Comment
Enum declaration
Method declaration
Method invocation
Chunk
Conflicting content
public void setName(String name) {
*/
public class CloudEntity {
<<<<<<< HEAD
@JsonIgnore
private Meta meta;
private String name;
public CloudEntity() {
}
public CloudEntity(Meta meta) {
this(meta, null);
}
public CloudEntity(Meta meta, String name) {
if (meta != null) {
this.meta = meta;
}
else {
this.meta = Meta.defaultMeta();
}
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Meta getMeta() {
return meta;
}
public void setMeta(Meta meta) {
this.meta = meta;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + ": (" +
(meta == null || meta.getGuid() == null ? "-" : meta.getGuid()) + ") " +
getName();
}
public static class Meta {
private UUID guid;
private Date created;
private Date updated;
private String url;
public Meta(UUID guid, Date created, Date updated) {
this.guid = guid;
this.created = created;
this.updated = updated;
}
public Meta(UUID guid, Date created, Date updated, String url) {
this.guid = guid;
this.created = created;
this.updated = updated;
this.url = url;
}
public UUID getGuid() {
return guid;
}
public Date getCreated() {
return created;
}
public Date getUpdated() {
return updated;
}
public String getUrl() {
return url;
}
public static Meta defaultMeta() {
return new Meta(null, null, null);
}
}
=======
@JsonIgnore
private Meta meta;
private String name;
public CloudEntity() {
}
public CloudEntity(Meta meta, String name) {
if (meta != null) {
this.meta = meta;
} else {
this.meta = Meta.defaultMeta();
}
this.name = name;
}
public Meta getMeta() {
return meta;
}
public void setMeta(Meta meta) {
this.meta = meta;
}
public String getName() {
return name;
}
this.name = name;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + ": (" +
(meta == null || meta.getGuid() == null ? "-" : meta.getGuid()) + ") " +
getName();
}
public static class Meta {
private Date created;
private UUID guid;
private Date updated;
public Meta(UUID guid, Date created, Date updated) {
this.guid = guid;
this.created = created;
this.updated = updated;
}
public static Meta defaultMeta() {
return new Meta(null, null, null);
}
public Date getCreated() {
return created;
}
public UUID getGuid() {
return guid;
}
public Date getUpdated() {
return updated;
}
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
}
Solution content
*/
public class CloudEntity {
@JsonIgnore
private Meta meta;
private String name;
public CloudEntity() {
}
public CloudEntity(Meta meta) {
this(meta, null);
}
public CloudEntity(Meta meta, String name) {
if (meta != null) {
this.meta = meta;
} else {
this.meta = Meta.defaultMeta();
}
this.name = name;
}
public Meta getMeta() {
return meta;
}
public void setMeta(Meta meta) {
this.meta = meta;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + ": (" +
(meta == null || meta.getGuid() == null ? "-" : meta.getGuid()) + ") " +
getName();
}
public static class Meta {
private Date created;
private UUID guid;
private Date updated;
private String url;
public Meta(UUID guid, Date created, Date updated) {
this.guid = guid;
this.created = created;
this.updated = updated;
}
public Meta(UUID guid, Date created, Date updated, String url) {
this.guid = guid;
this.created = created;
this.updated = updated;
this.url = url;
}
public static Meta defaultMeta() {
return new Meta(null, null, null);
}
public Date getCreated() {
return created;
}
public UUID getGuid() {
return guid;
}
public Date getUpdated() {
return updated;
}
public String getUrl() {
return url;
}
}
}
package org.cloudfoundry.client.lib.domain;
<<<<<<< HEAD
public class CloudStack extends CloudEntity {
private String description;
public CloudStack(Meta meta, String name, String description) {
super(meta, name);
this.description = description;
}
public String getDescription() {
return description;
}
=======
public class CloudStack extends CloudEntity {
private String description;
public CloudStack(Meta meta, String name, String description) {
setMeta(meta);
setName(name);
this.description = description;
}
public String getDescription() {
return description;
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
}
Solution content
package org.cloudfoundry.client.lib.domain;
public class CloudStack extends CloudEntity {
private String description;
public CloudStack(Meta meta, String name, String description) {
super(meta, name);
this.description = description;
}
public String getDescription() {
return description;
}
}
File
CloudStack.java
Developer's decision
Version 1
Kind of conflict
Attribute
Class signature
Method declaration
Chunk
Conflicting content
}
public class InstanceStats {
<<<<<<< HEAD
public static class Usage {
private double cpu;
private long disk;
private long mem;
private Date time;
public Usage(Map attributes) {
this.time = parseDate(parse(String.class, attributes.get("time")));
this.cpu = parse(Double.class, attributes.get("cpu"));
this.disk = parse(Long.class, attributes.get("disk"));
this.mem = parse(Long.class, attributes.get("mem"));
}
public double getCpu() {
return cpu;
}
public long getDisk() {
return disk;
}
public long getMem() {
return mem;
}
public Date getTime() {
return time;
}
}
private int cores;
private long diskQuota;
private int fdsQuota;
private String host;
private String id;
private long memQuota;
private String name;
private int port;
private InstanceState state;
private double uptime;
private List uris;
private Usage usage;
@SuppressWarnings("unchecked")
public InstanceStats(String id, Map attributes) {
this.id = id;
String instanceState = parse(String.class, attributes.get("state"));
this.state = InstanceState.valueOfWithDefault(instanceState);
Map stats = parse(Map.class, attributes.get("stats"));
if (stats != null) {
this.cores = parse(Integer.class, stats.get("cores"));
this.name = parse(String.class, stats.get("name"));
Map usageValue = parse(Map.class,
stats.get("usage"));
if (usageValue != null) {
this.usage = new Usage(usageValue);
}
this.diskQuota = parse(Long.class, stats.get("disk_quota"));
this.port = parse(Integer.class, stats.get("port"));
this.memQuota = parse(Long.class, stats.get("mem_quota"));
List statsValue = parse(List.class, stats.get("uris"));
if (statsValue != null) {
this.uris = Collections.unmodifiableList(statsValue);
}
this.fdsQuota = parse(Integer.class, stats.get("fds_quota"));
this.host = parse(String.class, stats.get("host"));
this.uptime = parse(Double.class, stats.get("uptime"));
}
}
private static Date parseDate(String date) {
// dates will be of the form 2011-04-07 09:11:50 +0000
try {
return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ZZZZZ").parse(date);
}
catch (ParseException e) {
// TODO - not sure how best to handle this error
return null;
}
}
public int getCores() {
return cores;
}
public long getDiskQuota() {
return diskQuota;
}
public int getFdsQuota() {
return fdsQuota;
}
public String getHost() {
return host;
}
public String getId() {
return id;
public long getMemQuota() {
return memQuota;
}
public String getName() {
return name;
}
public int getPort() {
return port;
}
public InstanceState getState() {
return state;
}
public double getUptime() {
return uptime;
}
public List getUris() {
return uris;
}
public Usage getUsage() {
return usage;
}
=======
private int cores;
private long diskQuota;
private int fdsQuota;
private String host;
private String id;
private long memQuota;
private String name;
private int port;
private InstanceState state;
private double uptime;
private List uris;
private Usage usage;
@SuppressWarnings("unchecked")
public InstanceStats(String id, Map attributes) {
this.id = id;
String instanceState = parse(String.class, attributes.get("state"));
public Date getTime() {
this.state = InstanceState.valueOfWithDefault(instanceState);
Map stats = parse(Map.class, attributes.get("stats"));
if (stats != null) {
this.cores = parse(Integer.class, stats.get("cores"));
this.name = parse(String.class, stats.get("name"));
Map usageValue = parse(Map.class,
stats.get("usage"));
if (usageValue != null) {
this.usage = new Usage(usageValue);
}
this.diskQuota = parse(Long.class, stats.get("disk_quota"));
this.port = parse(Integer.class, stats.get("port"));
this.memQuota = parse(Long.class, stats.get("mem_quota"));
List statsValue = parse(List.class, stats.get("uris"));
if (statsValue != null) {
this.uris = Collections.unmodifiableList(statsValue);
}
this.fdsQuota = parse(Integer.class, stats.get("fds_quota"));
this.host = parse(String.class, stats.get("host"));
this.uptime = parse(Double.class, stats.get("uptime"));
}
}
private static Date parseDate(String date) {
// dates will be of the form 2011-04-07 09:11:50 +0000
try {
return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ZZZZZ").parse(date);
} catch (ParseException e) {
// TODO - not sure how best to handle this error
return null;
}
}
public int getCores() {
return cores;
}
public long getDiskQuota() {
return diskQuota;
}
public int getFdsQuota() {
return fdsQuota;
}
public String getHost() {
return host;
}
public String getId() {
return id;
}
public long getMemQuota() {
return memQuota;
}
public String getName() {
return name;
}
public int getPort() {
return port;
}
public InstanceState getState() {
return state;
}
public double getUptime() {
return uptime;
}
public List getUris() {
return uris;
}
public Usage getUsage() {
return usage;
}
public static class Usage {
private double cpu;
private int disk;
private int mem;
private Date time;
public Usage(Map attributes) {
this.time = parseDate(parse(String.class, attributes.get("time")));
this.cpu = parse(Double.class, attributes.get("cpu"));
this.disk = parse(Integer.class, attributes.get("disk"));
this.mem = parse(Integer.class, attributes.get("mem"));
}
public double getCpu() {
return cpu;
}
public int getDisk() {
return disk;
}
public int getMem() {
return mem;
}
return time;
}
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
}
Solution content
public class InstanceStats {
private int cores;
private long diskQuota;
private int fdsQuota;
private String host;
private String id;
private long memQuota;
private String name;
private int port;
private InstanceState state;
private double uptime;
private List uris;
private Usage usage;
@SuppressWarnings("unchecked")
public InstanceStats(String id, Map attributes) {
this.id = id;
String instanceState = parse(String.class, attributes.get("state"));
this.state = InstanceState.valueOfWithDefault(instanceState);
Map stats = parse(Map.class, attributes.get("stats"));
if (stats != null) {
this.cores = parse(Integer.class, stats.get("cores"));
this.name = parse(String.class, stats.get("name"));
Map usageValue = parse(Map.class,
stats.get("usage"));
if (usageValue != null) {
this.usage = new Usage(usageValue);
}
this.diskQuota = parse(Long.class, stats.get("disk_quota"));
this.port = parse(Integer.class, stats.get("port"));
this.memQuota = parse(Long.class, stats.get("mem_quota"));
List statsValue = parse(List.class, stats.get("uris"));
if (statsValue != null) {
this.uris = Collections.unmodifiableList(statsValue);
}
this.fdsQuota = parse(Integer.class, stats.get("fds_quota"));
this.host = parse(String.class, stats.get("host"));
this.uptime = parse(Double.class, stats.get("uptime"));
}
}
private static Date parseDate(String date) {
// dates will be of the form 2011-04-07 09:11:50 +0000
try {
return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ZZZZZ").parse(date);
} catch (ParseException e) {
// TODO - not sure how best to handle this error
return null;
}
}
public int getCores() {
return cores;
}
public long getDiskQuota() {
return diskQuota;
}
public int getFdsQuota() {
return fdsQuota;
}
public String getHost() {
return host;
}
public String getId() {
return id;
}
public long getMemQuota() {
return memQuota;
}
public String getName() {
return name;
}
public int getPort() {
return port;
}
public InstanceState getState() {
return state;
}
public double getUptime() {
return uptime;
}
public List getUris() {
return uris;
}
public Usage getUsage() {
return usage;
}
public static class Usage {
private double cpu;
private long disk;
private long mem;
private Date time;
public Usage(Map attributes) {
this.time = parseDate(parse(String.class, attributes.get("time")));
this.cpu = parse(Double.class, attributes.get("cpu"));
this.disk = parse(Long.class, attributes.get("disk"));
this.mem = parse(Long.class, attributes.get("mem"));
}
public double getCpu() {
return cpu;
}
public long getDisk() {
return disk;
}
public long getMem() {
return mem;
}
public Date getTime() {
return time;
}
}
}
File
InstanceStats.java
Developer's decision
Combination
Kind of conflict
Annotation
Attribute
Class declaration
Method declaration
Chunk
Conflicting content
* @author Scott Frederick
*/
public class Staging {
<<<<<<< HEAD
private String command;
private String buildpackUrl;
private String detectedBuildpack;
private String stack;
private Integer healthCheckTimeout;
/**
* Default staging: No command, default buildpack
*/
public Staging() {
}
/**
*
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may be null
*/
public Staging(String command, String buildpackUrl) {
this.command = command;
this.buildpackUrl = buildpackUrl;
}
/**
*
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may be null
* @param detectedBuildpack raw, free-form information regarding a detected buildpack. It is a read-only property, and should not be set except when parsing a response. May be null.
*/
public Staging(String command, String buildpackUrl, String detectedBuildpack) {
this(command, buildpackUrl);
this.detectedBuildpack = detectedBuildpack;
}
/**
*
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may be null
* @param stack the stack to use when staging the application; may be null
* @param healthCheckTimeout the amount of time the platform should wait when verifying that an app started; may be null
*/
public Staging(String command, String buildpackUrl, String stack, Integer healthCheckTimeout) {
this(command, buildpackUrl);
this.stack = stack;
this.healthCheckTimeout = healthCheckTimeout;
}
/**
*
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may be null
* @param stack the stack to use when staging the application; may be null
* @param healthCheckTimeout the amount of time the platform should wait when verifying that an app started; may be null
* @param detectedBuildpack raw, free-form information regarding a detected buildpack. It is a read-only property, and should not be set except when parsing a response. May be null.
*/
public Staging(String command, String buildpackUrl, String stack, Integer healthCheckTimeout, String detectedBuildpack) {
this(command, buildpackUrl, stack, healthCheckTimeout);
this.detectedBuildpack = detectedBuildpack;
}
=======
private String buildpackUrl;
private String command;
private Integer healthCheckTimeout;
private String stack;
/**
* Default staging: No command, default buildpack
*/
public Staging() {
}
/**
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may be
* null
*/
public Staging(String command, String buildpackUrl) {
this.command = command;
this.buildpackUrl = buildpackUrl;
}
/**
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may
* be null
* @param stack the stack to use when staging the application; may be null
* @param healthCheckTimeout the amount of time the platform should wait when verifying that an app started; may be
* null
*/
public Staging(String command, String buildpackUrl, String stack, Integer healthCheckTimeout) {
this(command, buildpackUrl);
this.stack = stack;
this.healthCheckTimeout = healthCheckTimeout;
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
/**
* @return The buildpack url, or null to use the default buildpack detected based on application content
Solution content
* @author Scott Frederick
*/
public class Staging {
private String buildpackUrl;
private String command;
private String detectedBuildpack;
private Integer healthCheckTimeout;
private String stack;
/**
* Default staging: No command, default buildpack
*/
public Staging() {
}
/**
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may be
* null
*/
public Staging(String command, String buildpackUrl) {
this.command = command;
this.buildpackUrl = buildpackUrl;
}
/**
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may be
* null
* @param detectedBuildpack raw, free-form information regarding a detected buildpack. It is a read-only property,
* and should not be set except when parsing a response. May be null.
*/
public Staging(String command, String buildpackUrl, String detectedBuildpack) {
this(command, buildpackUrl);
this.detectedBuildpack = detectedBuildpack;
}
/**
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may
* be null
* @param stack the stack to use when staging the application; may be null
* @param healthCheckTimeout the amount of time the platform should wait when verifying that an app started; may be
* null
*/
public Staging(String command, String buildpackUrl, String stack, Integer healthCheckTimeout) {
this(command, buildpackUrl);
this.stack = stack;
this.healthCheckTimeout = healthCheckTimeout;
}
/**
* @param command the application command; may be null
* @param buildpackUrl a custom buildpack url (e.g. https://github.com/cloudfoundry/java-buildpack.git); may
* be null
* @param stack the stack to use when staging the application; may be null
* @param healthCheckTimeout the amount of time the platform should wait when verifying that an app started; may be
* null
* @param detectedBuildpack raw, free-form information regarding a detected buildpack. It is a read-only property,
* and should not be set except when parsing a response. May be null.
*/
public Staging(String command, String buildpackUrl, String stack, Integer healthCheckTimeout, String
detectedBuildpack) {
this(command, buildpackUrl, stack, healthCheckTimeout);
this.detectedBuildpack = detectedBuildpack;
}
/**
* @return The buildpack url, or null to use the default buildpack detected based on application content
File
Staging.java
Developer's decision
Manual
Kind of conflict
Attribute
Comment
Method declaration
Chunk
Conflicting content
return command;
}
<<<<<<< HEAD
/**
*
* @return Raw, free-form information regarding a detected buildpack, or
* null if no detected buildpack was resolved. For example, if the
* application is stopped, the detected buildpack may be null.
*/
public String getDetectedBuildpack() {
return detectedBuildpack;
}
/**
*
* @return the stack to use when staging the application, or null to use the default stack
*/
public String getStack() {
return stack;
}
=======
/**
* @return the health check timeout value
*/
public Integer getHealthCheckTimeout() {
return healthCheckTimeout;
}
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
/**
* @return the stack to use when staging the application, or null to use the default stack
Solution content
return command;
}
/**
* @return Raw, free-form information regarding a detected buildpack, or null if no detected buildpack was resolved.
* For example, if the application is stopped, the detected buildpack may be null.
*/
public String getDetectedBuildpack() {
return detectedBuildpack;
}
/**
* @return the health check timeout value
*/
public Integer getHealthCheckTimeout() {
return healthCheckTimeout;
}
/**
* @return the stack to use when staging the application, or null to use the default stack
void deleteDomain(String domainName);
<<<<<<< HEAD
CloudServiceInstance getServiceInstance(String serviceName);
void deleteService(String service);
=======
List deleteOrphanedRoutes();
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
void deleteQuota(String quotaName);
Solution content
void deleteDomain(String domainName);
List deleteOrphanedRoutes();
void deleteQuota(String quotaName);
File
CloudControllerClient.java
Developer's decision
Version 2
Kind of conflict
Method interface
Chunk
Conflicting content
InstancesInfo getApplicationInstances(CloudApplication app);
<<<<<<< HEAD
CloudApplication getApplication(String appName);
CloudApplication getApplication(UUID appGuid);
=======
ApplicationStats getApplicationStats(String appName);
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
List getApplications();
Solution content
List getApplicationEvents(String appName);
InstancesInfo getApplicationInstances(String appName);
InstancesInfo getApplicationInstances(CloudApplication app);
ApplicationStats getApplicationStats(String appName);
List getApplications();
File
CloudControllerClient.java
Developer's decision
Manual
Kind of conflict
Method interface
Chunk
Conflicting content
List getApplications();
<<<<<<< HEAD
Map getApplicationEnvironment(UUID appGuid);
Map getApplicationEnvironment(String appName);
void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames);
=======
URL getCloudControllerUrl();
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
Map getCrashLogs(String appName);
Solution content
List getApplications();
URL getCloudControllerUrl();
Map getCrashLogs(String appName);
File
CloudControllerClient.java
Developer's decision
Version 2
Kind of conflict
Method interface
Chunk
Conflicting content
List getSharedDomains();
<<<<<<< HEAD
List getEvents();
List getApplicationEvents(String appName);
Map getLogs(String appName);
=======
CloudSpace getSpace(String spaceName);
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
List getSpaces();
Solution content
List getSharedDomains();
// Space management
CloudSpace getSpace(String spaceName);
List getSpaceAuditors(String orgName, String spaceName);
List getSpaceDevelopers(String orgName, String spaceName);
// Domains and routes management
List getSpaceManagers(String orgName, String spaceName);
List getSpaces();
*/
public class CloudControllerClientImpl implements CloudControllerClient {
<<<<<<< HEAD
private static final String AUTHORIZATION_HEADER_KEY = "Authorization";
private static final String PROXY_USER_HEADER_KEY = "Proxy-User";
private static final String LOGS_LOCATION = "logs";
private static final long JOB_POLLING_PERIOD = TimeUnit.SECONDS.toMillis(5);
private static final long JOB_TIMEOUT = TimeUnit.MINUTES.toMillis(3);
private OauthClient oauthClient;
private CloudSpace sessionSpace;
private CloudEntityResourceMapper resourceMapper = new CloudEntityResourceMapper();
private RestTemplate restTemplate;
private URL cloudControllerUrl;
private LoggregatorClient loggregatorClient;
protected CloudCredentials cloudCredentials;
private final Log logger;
/**
* 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.
*/
protected CloudControllerClientImpl() {
logger = LogFactory.getLog(getClass().getName());
}
public CloudControllerClientImpl(URL cloudControllerUrl, RestTemplate restTemplate,
OauthClient oauthClient, LoggregatorClient loggregatorClient,
CloudCredentials cloudCredentials, CloudSpace sessionSpace) {
logger = LogFactory.getLog(getClass().getName());
initialize(cloudControllerUrl, restTemplate, oauthClient, loggregatorClient, cloudCredentials);
this.sessionSpace = sessionSpace;
}
public CloudControllerClientImpl(URL cloudControllerUrl, RestTemplate restTemplate,
OauthClient oauthClient, LoggregatorClient loggregatorClient,
CloudCredentials cloudCredentials, String orgName, String spaceName) {
logger = LogFactory.getLog(getClass().getName());
CloudControllerClientImpl tempClient =
new CloudControllerClientImpl(cloudControllerUrl, restTemplate,
oauthClient, loggregatorClient, cloudCredentials, null);
initialize(cloudControllerUrl, restTemplate, oauthClient, loggregatorClient, cloudCredentials);
this.sessionSpace = validateSpaceAndOrg(spaceName, orgName, tempClient);
}
private void initialize(URL cloudControllerUrl, RestTemplate restTemplate, OauthClient oauthClient,
LoggregatorClient loggregatorClient, CloudCredentials cloudCredentials) {
Assert.notNull(cloudControllerUrl, "CloudControllerUrl cannot be null");
Assert.notNull(restTemplate, "RestTemplate cannot be null");
Assert.notNull(oauthClient, "OauthClient cannot be null");
oauthClient.init(cloudCredentials);
=======
private static final String AUTHORIZATION_HEADER_KEY = "Authorization";
>>>>>>> 9ca6e8ba6103e1de4352e24f14510352244eb67d
private static final int JOB_POLLING_PERIOD = 5000; // matches that of gcf
Solution content
*/
public class CloudControllerClientImpl implements CloudControllerClient {
private static final String AUTHORIZATION_HEADER_KEY = "Authorization";
private static final long JOB_POLLING_PERIOD = TimeUnit.SECONDS.toMillis(5);
private static final long JOB_TIMEOUT = TimeUnit.MINUTES.toMillis(3);
File
CloudControllerClientImpl.java
Developer's decision
Combination
Kind of conflict
Attribute
Comment
Method declaration
Method invocation
Method signature
Chunk
Conflicting content
private URL cloudControllerUrl;
<<<<<<< HEAD
for (CloudSpace space : spaces) {
if (space.getName().equals(spaceName)) {
CloudOrganization org = space.getOrganization();
if (orgName == null || org.getName().equals(orgName)) {
return space;
}
}
}
throw new IllegalArgumentException("No matching organization and space found for org: " + orgName + " space: " + spaceName);
}
@Override
public void setResponseErrorHandler(ResponseErrorHandler errorHandler) {
this.restTemplate.setErrorHandler(errorHandler);
}
@Override
public URL getCloudControllerUrl() {
return this.cloudControllerUrl;
}
@Override
public void updatePassword(String newPassword) {
updatePassword(cloudCredentials, newPassword);
}
@Override
public Map getLogs(String appName) {
String urlPath = getFileUrlPath();
String instance = String.valueOf(0);
return doGetLogs(urlPath, appName, instance);
}
@Override
public List getRecentLogs(String appName) {
UUID appId = getAppId(appName);
String endpoint = getInfo().getLoggregatorEndpoint();
String uri = loggregatorClient.getRecentHttpEndpoint(endpoint);
ApplicationLogs logs = getRestTemplate().getForObject(uri + "?app={guid}", ApplicationLogs.class, appId);
Collections.sort(logs);
return logs;
}
@Override
public StreamingLogToken streamLogs(String appName, ApplicationLogListener listener) {
return streamLoggregatorLogs(appName, listener, false);
}
@Override
public Map getCrashLogs(String appName) {
String urlPath = getFileUrlPath();
CrashesInfo crashes = getCrashes(appName);
if (crashes.getCrashes().isEmpty()) {
return Collections.emptyMap();
}
TreeMap crashInstances = new TreeMap();
for (CrashInfo crash : crashes.getCrashes()) {
crashInstances.put(crash.getSince(), crash.getInstance());
}
String instance = crashInstances.get(crashInstances.lastKey());
return doGetLogs(urlPath, appName, instance);
}
@Override
public String getFile(String appName, int instanceIndex, String filePath, int startPosition, int endPosition) {
String urlPath = getFileUrlPath();
Object appId = getFileAppId(appName);
return doGetFile(urlPath, appId, instanceIndex, filePath, startPosition, endPosition);
}
@Override
public void openFile(String appName, int instanceIndex, String filePath, ClientHttpResponseCallback callback) {
String urlPath = getFileUrlPath();
Object appId = getFileAppId(appName);
doOpenFile(urlPath, appId, instanceIndex, filePath, callback);
}
@Override
public void registerRestLogListener(RestLogCallback callBack) {
if (getRestTemplate() instanceof LoggingRestTemplate) {
((LoggingRestTemplate)getRestTemplate()).registerRestLogListener(callBack);
}
}
@Override
public void unRegisterRestLogListener(RestLogCallback callBack) {
if (getRestTemplate() instanceof LoggingRestTemplate) {
((LoggingRestTemplate)getRestTemplate()).unRegisterRestLogListener(callBack);
}
}
/**
* 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..)
*
* @return content if available, which may contain multiple lines, or null
* if no further content is available.
*
*/
@Override
public String getStagingLogs(StartingInfo info, int offset) {
String stagingFile = info.getStagingFile();
if (stagingFile != null) {
CloudFoundryClientHttpRequestFactory cfRequestFactory = null;
try {
HashMap logsRequest = new HashMap();
logsRequest.put("offset", offset);
cfRequestFactory = getRestTemplate().getRequestFactory() instanceof CloudFoundryClientHttpRequestFactory ? (CloudFoundryClientHttpRequestFactory) getRestTemplate()
.getRequestFactory() : null;
if (cfRequestFactory != null) {
cfRequestFactory
.increaseReadTimeoutForStreamedTailedLogs(5 * 60 * 1000);
}
return getRestTemplate().getForObject(
stagingFile + "&tail&tail_offset={offset}",
String.class, logsRequest);
} catch (CloudFoundryException e) {
if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
// Content is no longer available
return null;
} else {
throw e;
}
} catch (ResourceAccessException e) {
// Likely read timeout, the directory server won't serve
// the content again
logger.debug("Caught exception while fetching staging logs. Aborting. Caught:" + e,
e);
} finally {
if (cfRequestFactory != null) {
cfRequestFactory
.increaseReadTimeoutForStreamedTailedLogs(-1);
}
}
}
return null;
}
protected RestTemplate getRestTemplate() {
return this.restTemplate;
}
protected String getUrl(String path) {
return cloudControllerUrl + (path.startsWith("/") ? path : "/" + path);
}
protected void configureCloudFoundryRequestFactory(RestTemplate restTemplate) {
ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
if (!(requestFactory instanceof CloudFoundryClientHttpRequestFactory)) {
restTemplate.setRequestFactory(
new CloudFoundryClientHttpRequestFactory(requestFactory));
}
}
private class CloudFoundryClientHttpRequestFactory implements ClientHttpRequestFactory {
private ClientHttpRequestFactory delegate;
private Integer defaultSocketTimeout = 0;
public CloudFoundryClientHttpRequestFactory(ClientHttpRequestFactory delegate) {
this.delegate = delegate;
captureDefaultReadTimeout();
}
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
ClientHttpRequest request = delegate.createRequest(uri, httpMethod);
String authorizationHeader = oauthClient.getAuthorizationHeader();
if (authorizationHeader != null) {
request.getHeaders().add(AUTHORIZATION_HEADER_KEY, authorizationHeader);
}
if (cloudCredentials != null && cloudCredentials.getProxyUser() != null) {
request.getHeaders().add(PROXY_USER_HEADER_KEY, cloudCredentials.getProxyUser());
}
return request;
}
private void captureDefaultReadTimeout() {
// As of HttpClient 4.3.x, obtaining the default parameters is deprecated and removed,
// so we fallback to java.net.Socket.
if (defaultSocketTimeout == null) {
try {
defaultSocketTimeout = new Socket().getSoTimeout();
} catch (SocketException e) {
defaultSocketTimeout = 0;
}
}
}
public void increaseReadTimeoutForStreamedTailedLogs(int timeout) {
// May temporary increase read timeout on other unrelated concurrent
// threads, but per-request read timeout don't seem easily
// accessible
if (delegate instanceof HttpComponentsClientHttpRequestFactory) {
HttpComponentsClientHttpRequestFactory httpRequestFactory =
(HttpComponentsClientHttpRequestFactory) delegate;
if (timeout > 0) {
httpRequestFactory.setReadTimeout(timeout);
} else {
httpRequestFactory
.setReadTimeout(defaultSocketTimeout);
}
}
}
}
protected Map doGetLogs(String urlPath, String appName, String instance) {
Object appId = getFileAppId(appName);
String logFiles = doGetFile(urlPath, appId, instance, LOGS_LOCATION, -1, -1);
String[] lines = logFiles.split("\n");
List fileNames = new ArrayList();
for (String line : lines) {
String[] parts = line.split("\\s");
if (parts.length > 0 && parts[0] != null) {
fileNames.add(parts[0]);
}
}
Map logs = new HashMap(fileNames.size());
for(String fileName : fileNames) {
String logFile = LOGS_LOCATION + "/" + fileName;
logs.put(logFile, doGetFile(urlPath, appId, instance, logFile, -1, -1));
}
return logs;
}
@SuppressWarnings("unchecked")
protected void doOpenFile(String urlPath, Object app, int instanceIndex, String filePath,
ClientHttpResponseCallback callback) {
getRestTemplate().execute(getUrl(urlPath), HttpMethod.GET, null, new ResponseExtractorWrapper(callback), app,
String.valueOf(instanceIndex), filePath);
}
protected String doGetFile(String urlPath, Object app, int instanceIndex, String filePath, int startPosition, int endPosition) {
return doGetFile(urlPath, app, String.valueOf(instanceIndex), filePath, startPosition, endPosition);
}
protected String doGetFile(String urlPath, Object app, String instance, String filePath, int startPosition, int endPosition) {
Assert.isTrue(startPosition >= -1, "Invalid start position value: " + startPosition);
Assert.isTrue(endPosition >= -1, "Invalid end position value: " + endPosition);
Assert.isTrue(startPosition < 0 || endPosition < 0 || endPosition >= startPosition,
"The end position (" + endPosition + ") can't be less than the start position (" + startPosition + ")");
int start, end;
if (startPosition == -1 && endPosition == -1) {
start = 0;
end = -1;
} else {
start = startPosition;
end = endPosition;
}
final String range =
"bytes=" + (start == -1 ? "" : start) + "-" + (end == -1 ? "" : end);
return doGetFileByRange(urlPath, app, instance, filePath, start, end, range);
}
private String doGetFileByRange(String urlPath, Object app, String instance, String filePath, int start, int end,
String range) {
boolean supportsRanges;
try {
supportsRanges = getRestTemplate().execute(getUrl(urlPath),
HttpMethod.HEAD,
new RequestCallback() {
public void doWithRequest(ClientHttpRequest request) throws IOException {
request.getHeaders().set("Range", "bytes=0-");
}
},
new ResponseExtractor() {
public Boolean extractData(ClientHttpResponse response) throws IOException {
return response.getStatusCode().equals(HttpStatus.PARTIAL_CONTENT);
}
},
app, instance, filePath);
} catch (CloudFoundryException e) {
if (e.getStatusCode().equals(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE)) {
// must be a 0 byte file
return "";
} else {
throw e;
}
}
HttpHeaders headers = new HttpHeaders();
if (supportsRanges) {
headers.set("Range", range);
}
HttpEntity requestEntity = new HttpEntity(headers);
ResponseEntity responseEntity = getRestTemplate().exchange(getUrl(urlPath),
HttpMethod.GET, requestEntity, String.class, app, instance, filePath);
String response = responseEntity.getBody();
boolean partialFile = false;
if (responseEntity.getStatusCode().equals(HttpStatus.PARTIAL_CONTENT)) {
partialFile = true;
}
if (!partialFile && response != null) {
if (start == -1) {
return response.substring(response.length() - end);
} else {
if (start >= response.length()) {
if (response.length() == 0) {
return "";
}
throw new CloudFoundryException(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE,
"The starting position " + start + " is past the end of the file content.");
}
if (end != -1) {
if (end >= response.length()) {
end = response.length() - 1;
}
return response.substring(start, end + 1);
} else {
return response.substring(start);
}
}
}
return response;
}
@SuppressWarnings("unchecked")
@Override
public CloudInfo getInfo() {
// info comes from two end points: /info and /v2/info
String infoV2Json = getRestTemplate().getForObject(getUrl("/v2/info"), String.class);
Map infoV2Map = JsonUtil.convertJsonToMap(infoV2Json);
Map userMap = getUserInfo((String) infoV2Map.get("user"));
String infoJson = getRestTemplate().getForObject(getUrl("/info"), String.class);
Map infoMap = JsonUtil.convertJsonToMap(infoJson);
Map limitMap = (Map) infoMap.get("limits");
Map usageMap = (Map) infoMap.get("usage");
String name = CloudUtil.parse(String.class, infoV2Map.get("name"));
String support = CloudUtil.parse(String.class, infoV2Map.get("support"));
String authorizationEndpoint = CloudUtil.parse(String.class, infoV2Map.get("authorization_endpoint"));
String build = CloudUtil.parse(String.class, infoV2Map.get("build"));
String version = "" + CloudUtil.parse(Number.class, infoV2Map.get("version"));
String description = CloudUtil.parse(String.class, infoV2Map.get("description"));
CloudInfo.Limits limits = null;
CloudInfo.Usage usage = null;
boolean debug = false;
if (oauthClient.getToken() != null) {
limits = new CloudInfo.Limits(limitMap);
usage = new CloudInfo.Usage(usageMap);
debug = CloudUtil.parse(Boolean.class, infoMap.get("allow_debug"));
}
String loggregatorEndpoint = CloudUtil.parse(String.class, infoV2Map.get("logging_endpoint"));
return new CloudInfo(name, support, authorizationEndpoint, build, version, (String)userMap.get("user_name"),
description, limits, usage, debug, loggregatorEndpoint);
}
@Override
public void createSpace(String spaceName) {
assertSpaceProvided("create a new space");
UUID orgGuid = sessionSpace.getOrganization().getMeta().getGuid();
UUID spaceGuid = getSpaceGuid(spaceName, orgGuid);
if (spaceGuid == null) {
doCreateSpace(spaceName, orgGuid);
}
}
@Override
public CloudSpace getSpace(String spaceName) {
String urlPath = "/v2/spaces?inline-relations-depth=1&q=name:{name}";
HashMap spaceRequest = new HashMap();
spaceRequest.put("name", spaceName);
List> resourceList = getAllResources(urlPath, spaceRequest);
CloudSpace space = null;
if (resourceList.size() > 0) {
Map resource = resourceList.get(0);
space = resourceMapper.mapResource(resource, CloudSpace.class);
}
return space;
}
@Override
public void deleteSpace(String spaceName) {
assertSpaceProvided("delete a space");
UUID orgGuid = sessionSpace.getOrganization().getMeta().getGuid();
UUID spaceGuid = getSpaceGuid(spaceName, orgGuid);
if (spaceGuid != null) {
doDeleteSpace(spaceGuid);
}
}
private UUID doCreateSpace(String spaceName, UUID orgGuid) {
String urlPath = "/v2/spaces";
HashMap spaceRequest = new HashMap();
spaceRequest.put("organization_guid", orgGuid);
spaceRequest.put("name", spaceName);
String resp = getRestTemplate().postForObject(getUrl(urlPath), spaceRequest, String.class);
Map respMap = JsonUtil.convertJsonToMap(resp);
return resourceMapper.getGuidOfResource(respMap);
}
private UUID getSpaceGuid(String spaceName, UUID orgGuid) {
Map urlVars = new HashMap();
String urlPath = "/v2/organizations/{orgGuid}/spaces?inline-relations-depth=1&q=name:{name}";
urlVars.put("orgGuid", orgGuid);
urlVars.put("name", spaceName);
List> resourceList = getAllResources(urlPath, urlVars);
if (resourceList.size() > 0) {
Map resource = resourceList.get(0);
return resourceMapper.getGuidOfResource(resource);
}
return null;
}
private UUID getSpaceGuid(String orgName, String spaceName) {
CloudOrganization org = getOrgByName(orgName, true);
return getSpaceGuid(spaceName, org.getMeta().getGuid());
}
private void doDeleteSpace(UUID spaceGuid) {
getRestTemplate().delete(getUrl("/v2/spaces/{guid}?async=false"), spaceGuid);
}
@Override
public List getSpaces() {
String urlPath = "/v2/spaces?inline-relations-depth=1";
List> resourceList = getAllResources(urlPath, null);
List spaces = new ArrayList();
for (Map resource : resourceList) {
spaces.add(resourceMapper.mapResource(resource, CloudSpace.class));
}
return spaces;
}
@Override
public List getSpaceManagers(String orgName, String spaceName) {
String urlPath = "/v2/spaces/{guid}/managers";
return getSpaceUserGuids(orgName, spaceName, urlPath);
}
@Override
public List getSpaceDevelopers(String orgName, String spaceName) {
String urlPath = "/v2/spaces/{guid}/developers";
return getSpaceUserGuids(orgName, spaceName, urlPath);
}
@Override
public List getSpaceAuditors(String orgName, String spaceName) {
String urlPath = "/v2/spaces/{guid}/auditors";
return getSpaceUserGuids(orgName, spaceName, urlPath);
}
private List getSpaceUserGuids(String orgName, String spaceName, String urlPath) {
if (orgName == null || spaceName == null) {
assertSpaceProvided("get space users");
}
UUID spaceGuid;
if (spaceName == null) {
spaceGuid = sessionSpace.getMeta().getGuid();
} else {
CloudOrganization organization = (orgName == null ? sessionSpace.getOrganization() : getOrgByName(orgName, true));
spaceGuid = getSpaceGuid(spaceName, organization.getMeta().getGuid());
}
Map urlVars = new HashMap();
urlVars.put("guid", spaceGuid);
List managersGuid = new ArrayList();
List> resourceList = getAllResources(urlPath, urlVars);
for (Map resource : resourceList) {
UUID userGuid = resourceMapper.getGuidOfResource(resource);
managersGuid.add(userGuid);
}
return managersGuid;
}
@Override
public void associateManagerWithSpace(String orgName, String spaceName, String userGuid) {
String urlPath = "/v2/spaces/{guid}/managers/{userGuid}";
associateRoleWithSpace(orgName, spaceName, userGuid, urlPath);
}
@Override
public void associateDeveloperWithSpace(String orgName, String spaceName, String userGuid) {
String urlPath = "/v2/spaces/{guid}/developers/{userGuid}";
associateRoleWithSpace(orgName, spaceName, userGuid, urlPath);
}
@Override
public void associateAuditorWithSpace(String orgName, String spaceName, String userGuid) {
String urlPath = "/v2/spaces/{guid}/auditors/{userGuid}";
associateRoleWithSpace(orgName, spaceName, userGuid, urlPath);
}
private void associateRoleWithSpace(String orgName, String spaceName, String userGuid, String urlPath) {
assertSpaceProvided("associate roles");
CloudOrganization organization = (orgName == null ? sessionSpace.getOrganization() : getOrgByName(orgName, true));
UUID orgGuid = organization.getMeta().getGuid();
UUID spaceGuid = getSpaceGuid(spaceName, orgGuid);
HashMap spaceRequest = new HashMap();
spaceRequest.put("guid", spaceGuid);
String userId = (userGuid==null?getCurrentUserId():userGuid);
getRestTemplate().put(getUrl(urlPath), spaceRequest, spaceGuid, userId);
}
private String getCurrentUserId() {
String username = getInfo().getUser();
Map userMap = getUserInfo(username);
String userId= (String) userMap.get("user_id");
return userId;
}
@Override
public Map getOrganizationUsers(String orgName) {
String urlPath = "/v2/organizations/{guid}/users";
CloudOrganization organization = getOrgByName(orgName, true);
UUID orgGuid=organization.getMeta().getGuid();
Map urlVars = new HashMap();
urlVars.put("guid", orgGuid);
List> resourceList = getAllResources(urlPath, urlVars);
Map orgUsers = new HashMap();
for (Map resource : resourceList) {
CloudUser user = resourceMapper.mapResource(resource, CloudUser.class);
orgUsers.put(user.getUsername(),user);
}
return orgUsers;
}
@Override
public List getOrganizations() {
String urlPath = "/v2/organizations?inline-relations-depth=0";
List> resourceList = getAllResources(urlPath, null);
List orgs = new ArrayList();
for (Map resource : resourceList) {
orgs.add(resourceMapper.mapResource(resource, CloudOrganization.class));
}
return orgs;
}
@Override
public OAuth2AccessToken login() {
oauthClient.init(cloudCredentials);
return oauthClient.getToken();
}
@Override
public void logout() {
oauthClient.clear();
}
@Override
public void register(String email, String password) {
throw new UnsupportedOperationException("Feature is not yet implemented.");
}
@Override
public void updatePassword(CloudCredentials credentials, String newPassword) {
oauthClient.changePassword(credentials.getPassword(), newPassword);
CloudCredentials newCloudCredentials = new CloudCredentials(credentials.getEmail(), newPassword);
if (cloudCredentials.getProxyUser() != null) {
cloudCredentials = newCloudCredentials.proxyForUser(cloudCredentials.getProxyUser());
} else {
cloudCredentials = newCloudCredentials;
}
}
@Override
public void unregister() {
throw new UnsupportedOperationException("Feature is not yet implemented.");
}
@Override
public List getServices() {
Map urlVars = new HashMap();
String urlPath = "/v2";
if (sessionSpace != null) {
urlVars.put("space", sessionSpace.getMeta().getGuid());
urlPath = urlPath + "/spaces/{space}";
}
urlPath = urlPath + "/service_instances?inline-relations-depth=1&return_user_provided_service_instances=true";
List> resourceList = getAllResources(urlPath, urlVars);
List services = new ArrayList();
for (Map resource : resourceList) {
if (hasEmbeddedResource(resource, "service_plan")) {
fillInEmbeddedResource(resource, "service_plan", "service");
}
services.add(resourceMapper.mapResource(resource, CloudService.class));
}
return services;
}
@Override
public void createService(CloudService service) {
assertSpaceProvided("create service");
Assert.notNull(service, "Service must not be null");
Assert.notNull(service.getName(), "Service name must not be null");
Assert.notNull(service.getLabel(), "Service label must not be null");
Assert.notNull(service.getPlan(), "Service plan must not be null");
CloudServicePlan cloudServicePlan = findPlanForService(service);
HashMap serviceRequest = new HashMap();
serviceRequest.put("space_guid", sessionSpace.getMeta().getGuid());
serviceRequest.put("name", service.getName());
serviceRequest.put("service_plan_guid", cloudServicePlan.getMeta().getGuid());
getRestTemplate().postForObject(getUrl("/v2/service_instances"), serviceRequest, String.class);
}
private CloudServicePlan findPlanForService(CloudService service) {
List offerings = getServiceOfferings(service.getLabel());
for (CloudServiceOffering offering : offerings) {
if (service.getVersion() == null || service.getVersion().equals(offering.getVersion())) {
for (CloudServicePlan plan : offering.getCloudServicePlans()) {
if (service.getPlan() != null && service.getPlan().equals(plan.getName())) {
return plan;
}
}
}
}
throw new IllegalArgumentException("Service plan " + service.getPlan() + " not found");
}
@Override
public void createUserProvidedService(CloudService service, Map credentials) {
createUserProvidedServiceDelegate(service, credentials, "");
}
@Override
public void createUserProvidedService(CloudService service, Map credentials, String syslogDrainUrl) {
createUserProvidedServiceDelegate(service, credentials, syslogDrainUrl);
}
private void createUserProvidedServiceDelegate(CloudService service, Map credentials, String syslogDrainUrl) {
assertSpaceProvided("create service");
Assert.notNull(credentials, "Service credentials must not be null");
Assert.notNull(service, "Service must not be null");
Assert.notNull(service.getName(), "Service name must not be null");
Assert.isNull(service.getLabel(), "Service label is not valid for user-provided services");
Assert.isNull(service.getProvider(), "Service provider is not valid for user-provided services");
Assert.isNull(service.getVersion(), "Service version is not valid for user-provided services");
Assert.isNull(service.getPlan(), "Service plan is not valid for user-provided services");
HashMap serviceRequest = new HashMap<>();
serviceRequest.put("space_guid", sessionSpace.getMeta().getGuid());
serviceRequest.put("name", service.getName());
serviceRequest.put("credentials", credentials);
if (syslogDrainUrl != null && !syslogDrainUrl.equals("")) {
serviceRequest.put("syslog_drain_url", syslogDrainUrl);
}
getRestTemplate().postForObject(getUrl("/v2/user_provided_service_instances"), serviceRequest, String.class);
}
@Override
public CloudService getService(String serviceName) {
Map resource = doGetServiceInstance(serviceName, 0);
if (resource == null) {
return null;
}
return resourceMapper.mapResource(resource, CloudService.class);
}
@Override
public CloudServiceInstance getServiceInstance(String serviceName) {
Map resource = doGetServiceInstance(serviceName, 1);
if (resource == null) {
return null;
}
return resourceMapper.mapResource(resource, CloudServiceInstance.class);
}
private Map doGetServiceInstance(String serviceName, int inlineDepth) {
String urlPath = "/v2";
Map urlVars = new HashMap();
if (sessionSpace != null) {
urlVars.put("space", sessionSpace.getMeta().getGuid());
urlPath = urlPath + "/spaces/{space}";
}
urlVars.put("q", "name:" + serviceName);
urlPath = urlPath + "/service_instances?q={q}&return_user_provided_service_instances=true";
if (inlineDepth > 0) {
urlPath = urlPath + "&inline-relations-depth=" + inlineDepth;
}
List> resources = getAllResources(urlPath, urlVars);
if (resources.size() > 0) {
Map serviceResource = resources.get(0);
if (hasEmbeddedResource(serviceResource, "service_plan")) {
fillInEmbeddedResource(serviceResource, "service_plan", "service");
}
return serviceResource;
}
return null;
}
@Override
public void deleteService(String serviceName) {
CloudService cloudService = getService(serviceName);
doDeleteService(cloudService);
}
@Override
public void deleteAllServices() {
List cloudServices = getServices();
for (CloudService cloudService : cloudServices) {
doDeleteService(cloudService);
}
}
@Override
public List getServiceOfferings() {
String urlPath = "/v2/services?inline-relations-depth=1";
List> resourceList = getAllResources(urlPath, null);
List serviceOfferings = new ArrayList();
for (Map resource : resourceList) {
CloudServiceOffering serviceOffering = resourceMapper.mapResource(resource, CloudServiceOffering.class);
serviceOfferings.add(serviceOffering);
}
return serviceOfferings;
}
@Override
public List getServiceBrokers() {
String urlPath = "/v2/service_brokers?inline-relations-depth=1";
List> resourceList = getAllResources(urlPath, null);
List serviceBrokers = new ArrayList();
for (Map resource : resourceList) {
CloudServiceBroker broker = resourceMapper.mapResource(resource, CloudServiceBroker.class);
serviceBrokers.add(broker);
}
return serviceBrokers;
}
@Override
public CloudServiceBroker getServiceBroker(String name) {
String urlPath = "/v2/service_brokers?q={q}";
Map urlVars = new HashMap<>();
urlVars.put("q", "name:" + name);
List> resourceList = getAllResources(urlPath, urlVars);
CloudServiceBroker serviceBroker = null;
if (resourceList.size() > 0) {
final Map resource = resourceList.get(0);
serviceBroker = resourceMapper.mapResource(resource, CloudServiceBroker.class);
}
return serviceBroker;
}
@Override
public void createServiceBroker(CloudServiceBroker serviceBroker) {
Assert.notNull(serviceBroker, "Service Broker must not be null");
Assert.notNull(serviceBroker.getName(), "Service Broker name must not be null");
Assert.notNull(serviceBroker.getUrl(), "Service Broker URL must not be null");
Assert.notNull(serviceBroker.getUsername(), "Service Broker username must not be null");
Assert.notNull(serviceBroker.getPassword(), "Service Broker password must not be null");
HashMap serviceRequest = new HashMap<>();
serviceRequest.put("name", serviceBroker.getName());
serviceRequest.put("broker_url", serviceBroker.getUrl());
serviceRequest.put("auth_username", serviceBroker.getUsername());
serviceRequest.put("auth_password", serviceBroker.getPassword());
getRestTemplate().postForObject(getUrl("/v2/service_brokers"), serviceRequest, String.class);
}
@Override
public void updateServiceBroker(CloudServiceBroker serviceBroker) {
Assert.notNull(serviceBroker, "Service Broker must not be null");
Assert.notNull(serviceBroker.getName(), "Service Broker name must not be null");
Assert.notNull(serviceBroker.getUrl(), "Service Broker URL must not be null");
Assert.notNull(serviceBroker.getUsername(), "Service Broker username must not be null");
Assert.notNull(serviceBroker.getPassword(), "Service Broker password must not be null");
CloudServiceBroker existingBroker = getServiceBroker(serviceBroker.getName());
Assert.notNull(existingBroker, "Cannot update broker if it does not first exist");
HashMap serviceRequest = new HashMap<>();
serviceRequest.put("name", serviceBroker.getName());
serviceRequest.put("broker_url", serviceBroker.getUrl());
serviceRequest.put("auth_username", serviceBroker.getUsername());
serviceRequest.put("auth_password", serviceBroker.getPassword());
getRestTemplate().put(getUrl("/v2/service_brokers/{guid}"), serviceRequest, existingBroker.getMeta().getGuid());
}
@Override
public void deleteServiceBroker(String name) {
CloudServiceBroker existingBroker = getServiceBroker(name);
@SuppressWarnings("unchecked")
Assert.notNull(existingBroker, "Cannot update broker if it does not first exist");
getRestTemplate().delete(getUrl("/v2/service_brokers/{guid}"), existingBroker.getMeta().getGuid());
}
@Override
public void updateServicePlanVisibilityForBroker(String name, boolean visibility) {
CloudServiceBroker broker = getServiceBroker(name);
String urlPath = "/v2/services?q={q}";
Map urlVars = new HashMap<>();
urlVars.put("q", "service_broker_guid:" + broker.getMeta().getGuid());
List> serviceResourceList = getAllResources(urlPath, urlVars);
for (Map serviceResource : serviceResourceList) {
Map metadata = (Map) serviceResource.get("metadata");
String serviceGuid = (String) metadata.get("guid");
urlPath = "/v2/service_plans?q={q}";
urlVars = new HashMap<>();
urlVars.put("q", "service_guid:" + serviceGuid);
List> planResourceList = getAllResources(urlPath, urlVars);
for (Map planResource : planResourceList) {
metadata = (Map) planResource.get("metadata");
String planGuid = (String) metadata.get("guid");
HashMap planUpdateRequest = new HashMap<>();
planUpdateRequest.put("public", visibility);
getRestTemplate().put(getUrl("/v2/service_plans/{guid}"), planUpdateRequest, planGuid);
}
}
}
@Override
public List getApplications() {
Map urlVars = new HashMap();
String urlPath = "/v2";
if (sessionSpace != null) {
urlVars.put("space", sessionSpace.getMeta().getGuid());
urlPath = urlPath + "/spaces/{space}";
}
urlPath = urlPath + "/apps?inline-relations-depth=1";
List> resourceList = getAllResources(urlPath, urlVars);
List apps = new ArrayList();
for (Map resource : resourceList) {
processApplicationResource(resource, true);
apps.add(mapCloudApplication(resource));
}
return apps;
}
@Override
public CloudApplication getApplication(String appName) {
Map resource = findApplicationResource(appName, true);
if (resource == null) {
throw new CloudFoundryException(HttpStatus.NOT_FOUND, "Not Found", "Application not found");
}
return mapCloudApplication(resource);
}
@Override
public CloudApplication getApplication(UUID appGuid) {
Map resource = findApplicationResource(appGuid, true);
if (resource == null) {
throw new CloudFoundryException(HttpStatus.NOT_FOUND, "Not Found", "Application not found");
}
return mapCloudApplication(resource);
}
@Override
public Map getApplicationEnvironment(UUID appGuid) {
String url = getUrl("/v2/apps/{guid}/env");
Map urlVars = new HashMap();
urlVars.put("guid", appGuid);
String resp = restTemplate.getForObject(url, String.class, urlVars);
return JsonUtil.convertJsonToMap(resp);
}
@Override
public Map getApplicationEnvironment(String appName) {
UUID appId = getAppId(appName);
return getApplicationEnvironment(appId);
}
@SuppressWarnings("unchecked")
private CloudApplication mapCloudApplication(Map 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)resource.get("entity")).put("running_instances", running);
cloudApp = resourceMapper.mapResource(resource, CloudApplication.class);
cloudApp.setUris(findApplicationUris(cloudApp.getMeta().getGuid()));
}
return cloudApp;
}
private int getRunningInstances(UUID appId, CloudApplication.AppState appState) {
int running = 0;
ApplicationStats appStats = doGetApplicationStats(appId, appState);
if (appStats != null && appStats.getRecords() != null) {
for (InstanceStats inst : appStats.getRecords()) {
if (InstanceState.RUNNING == inst.getState()){
running++;
}
}
}
return running;
}
@Override
public ApplicationStats getApplicationStats(String appName) {
CloudApplication app = getApplication(appName);
return doGetApplicationStats(app.getMeta().getGuid(), app.getState());
}
@SuppressWarnings("unchecked")
private ApplicationStats doGetApplicationStats(UUID appId, CloudApplication.AppState appState) {
List instanceList = new ArrayList();
if (appState.equals(CloudApplication.AppState.STARTED)) {
Map respMap = getInstanceInfoForApp(appId, "stats");
for (String instanceId : respMap.keySet()) {
InstanceStats instanceStats =
new InstanceStats(instanceId, (Map) respMap.get(instanceId));
instanceList.add(instanceStats);
}
}
return new ApplicationStats(instanceList);
}
private Map getInstanceInfoForApp(UUID appId, String path) {
String url = getUrl("/v2/apps/{guid}/" + path);
Map urlVars = new HashMap();
urlVars.put("guid", appId);
String resp = getRestTemplate().getForObject(url, String.class, urlVars);
return JsonUtil.convertJsonToMap(resp);
}
@Override
public void createApplication(String appName, Staging staging, Integer memory, List uris,
List serviceNames) {
createApplication(appName, staging, null, memory, uris, serviceNames);
}
@Override
public void createApplication(String appName, Staging staging, Integer disk, Integer memory,
List uris, List serviceNames) {
HashMap appRequest = new HashMap();
appRequest.put("space_guid", sessionSpace.getMeta().getGuid());
appRequest.put("name", appName);
appRequest.put("memory", memory);
if (disk != null) {
appRequest.put("disk_quota", disk);
}
appRequest.put("instances", 1);
addStagingToRequest(staging, appRequest);
appRequest.put("state", CloudApplication.AppState.STOPPED);
String appResp = getRestTemplate().postForObject(getUrl("/v2/apps"), appRequest, String.class);
Map appEntity = JsonUtil.convertJsonToMap(appResp);
UUID newAppGuid = CloudEntityResourceMapper.getMeta(appEntity).getGuid();
if (serviceNames != null && serviceNames.size() > 0) {
updateApplicationServices(appName, serviceNames);
}
if (uris != null && uris.size() > 0) {
addUris(uris, newAppGuid);
}
}
private void addStagingToRequest(Staging staging, HashMap appRequest) {
if (staging.getBuildpackUrl() != null) {
appRequest.put("buildpack", staging.getBuildpackUrl());
}
if (staging.getCommand() != null) {
appRequest.put("command", staging.getCommand());
}
if (staging.getStack() != null) {
appRequest.put("stack_guid", getStack(staging.getStack()).getMeta().getGuid());
}
if (staging.getHealthCheckTimeout() != null) {
appRequest.put("health_check_timeout", staging.getHealthCheckTimeout());
}
}
private List> getAllResources(String urlPath, Map urlVars) {
List> allResources = new ArrayList>();
String resp;
if (urlVars != null) {
resp = getRestTemplate().getForObject(getUrl(urlPath), String.class, urlVars);
} else {
resp = getRestTemplate().getForObject(getUrl(urlPath), String.class);
}
Map respMap = JsonUtil.convertJsonToMap(resp);
List> newResources = (List>) respMap.get("resources");
if (newResources != null && newResources.size() > 0) {
allResources.addAll(newResources);
}
String nextUrl = (String) respMap.get("next_url");
while (nextUrl != null && nextUrl.length() > 0) {
nextUrl = addPageOfResources(nextUrl, allResources);
}
return allResources;
}
@SuppressWarnings("unchecked")
private String addPageOfResources(String nextUrl, List> allResources) {
String resp = getRestTemplate().getForObject(getUrl(nextUrl), String.class);
Map respMap = JsonUtil.convertJsonToMap(resp);
List> newResources = (List>) respMap.get("resources");
if (newResources != null && newResources.size() > 0) {
allResources.addAll(newResources);
}
return (String) respMap.get("next_url");
}
private void addUris(List uris, UUID appGuid) {
Map domains = getDomainGuids();
for (String uri : uris) {
Map uriInfo = new HashMap(2);
extractUriInfo(domains, uri, uriInfo);
UUID domainGuid = domains.get(uriInfo.get("domainName"));
bindRoute(uriInfo.get("host"), domainGuid, appGuid);
}
}
private void removeUris(List uris, UUID appGuid) {
Map domains = getDomainGuids();
for (String uri : uris) {
Map uriInfo = new HashMap(2);
extractUriInfo(domains, uri, uriInfo);
UUID domainGuid = domains.get(uriInfo.get("domainName"));
unbindRoute(uriInfo.get("host"), domainGuid, appGuid);
}
}
protected void extractUriInfo(Map domains, String uri, Map uriInfo) {
URI newUri = URI.create(uri);
String host = newUri.getScheme() != null ? newUri.getHost(): newUri.getPath();
for (String domain : domains.keySet()) {
if (host != null && host.endsWith(domain)) {
String previousDomain = uriInfo.get("domainName");
if (previousDomain == null || domain.length() > previousDomain.length()) {
//Favor most specific subdomains
uriInfo.put("domainName", domain);
if (domain.length() < host.length()) {
uriInfo.put("host", host.substring(0, host.indexOf(domain) - 1));
} else if (domain.length() == host.length()) {
uriInfo.put("host", "");
}
}
}
}
if (uriInfo.get("domainName") == null) {
throw new IllegalArgumentException("Domain not found for URI " + uri);
}
if (uriInfo.get("host") == null) {
throw new IllegalArgumentException("Invalid URI " + uri +
" -- host not specified for domain " + uriInfo.get("domainName"));
}
}
private Map getDomainGuids() {
Map urlVars = new HashMap();
String urlPath = "/v2";
if (sessionSpace != null) {
urlVars.put("space", sessionSpace.getMeta().getGuid());
urlPath = urlPath + "/spaces/{space}";
}
String domainPath = urlPath + "/domains?inline-relations-depth=1";
List> resourceList = getAllResources(domainPath, urlVars);
Map domains = new HashMap(resourceList.size());
for (Map d : resourceList) {
domains.put(
CloudEntityResourceMapper.getEntityAttribute(d, "name", String.class),
return file;
CloudEntityResourceMapper.getMeta(d).getGuid());
}
return domains;
}
private UUID getDomainGuid(String domainName, boolean required) {
Map urlVars = new HashMap();
String urlPath = "/v2/domains?inline-relations-depth=1&q=name:{name}";
urlVars.put("name", domainName);
List> resourceList = getAllResources(urlPath, urlVars);
UUID domainGuid = null;
if (resourceList.size() > 0) {
Map resource = resourceList.get(0);
domainGuid = resourceMapper.getGuidOfResource(resource);
}
if (domainGuid == null && required) {
throw new IllegalArgumentException("Domain '" + domainName + "' not found.");
}
return domainGuid;
}
private void bindRoute(String host, UUID domainGuid, UUID appGuid) {
UUID routeGuid = getRouteGuid(host, domainGuid);
if (routeGuid == null) {
routeGuid = doAddRoute(host, domainGuid);
}
String bindPath = "/v2/apps/{app}/routes/{route}";
Map bindVars = new HashMap();
bindVars.put("app", appGuid);
bindVars.put("route", routeGuid);
HashMap bindRequest = new HashMap();
getRestTemplate().put(getUrl(bindPath), bindRequest, bindVars);
}
private void unbindRoute(String host, UUID domainGuid, UUID appGuid) {
UUID routeGuid = getRouteGuid(host, domainGuid);
if (routeGuid != null) {
String bindPath = "/v2/apps/{app}/routes/{route}";
Map bindVars = new HashMap();
bindVars.put("app", appGuid);
bindVars.put("route", routeGuid);
getRestTemplate().delete(getUrl(bindPath), bindVars);
}
}
private UUID getRouteGuid(String host, UUID domainGuid) {
Map urlVars = new HashMap();
String urlPath = "/v2";
urlPath = urlPath + "/routes?inline-relations-depth=0&q=host:{host}";
urlVars.put("host", host);
List> allRoutes = getAllResources(urlPath, urlVars);
UUID routeGuid = null;
for (Map route : allRoutes) {
UUID routeSpace = CloudEntityResourceMapper.getEntityAttribute(route, "space_guid", UUID.class);
UUID routeDomain = CloudEntityResourceMapper.getEntityAttribute(route, "domain_guid", UUID.class);
if (sessionSpace.getMeta().getGuid().equals(routeSpace) &&
domainGuid.equals(routeDomain)) {
routeGuid = CloudEntityResourceMapper.getMeta(route).getGuid();
}
}
return routeGuid;
}
private UUID doAddRoute(String host, UUID domainGuid) {
assertSpaceProvided("add route");
HashMap routeRequest = new HashMap();
routeRequest.put("host", host);
routeRequest.put("domain_guid", domainGuid);
routeRequest.put("space_guid", sessionSpace.getMeta().getGuid());
String routeResp = getRestTemplate().postForObject(getUrl("/v2/routes"), routeRequest, String.class);
Map routeEntity = JsonUtil.convertJsonToMap(routeResp);
return CloudEntityResourceMapper.getMeta(routeEntity).getGuid();
}
@Override
public void uploadApplication(String appName, File file, UploadStatusCallback callback) throws IOException {
Assert.notNull(file, "File must not be null");
if (file.isDirectory()) {
ApplicationArchive archive = new DirectoryApplicationArchive(file);
uploadApplication(appName, archive, callback);
} else {
try (ZipFile zipFile = new ZipFile(file)) {
ApplicationArchive archive = new ZipApplicationArchive(zipFile);
uploadApplication(appName, archive, callback);
}
}
}
@Override
public void uploadApplication(String appName, String fileName, InputStream inputStream, UploadStatusCallback callback) throws IOException {
Assert.notNull(fileName, "FileName must not be null");
Assert.notNull(inputStream, "InputStream must not be null");
File file = createTemporaryUploadFile(inputStream);
try (ZipFile zipFile = new ZipFile(file)) {
ApplicationArchive archive = new ZipApplicationArchive(zipFile);
uploadApplication(appName, archive, callback);
}
file.delete();
}
@Override
public void uploadApplication(String appName, ApplicationArchive archive, UploadStatusCallback callback)
throws IOException {
Assert.notNull(appName, "AppName must not be null");
Assert.notNull(archive, "Archive must not be null");
UUID appId = getAppId(appName);
if (callback == null) {
callback = UploadStatusCallback.NONE;
}
CloudResources knownRemoteResources = getKnownRemoteResources(archive);
callback.onCheckResources();
callback.onMatchedFileNames(knownRemoteResources.getFilenames());
UploadApplicationPayload payload = new UploadApplicationPayload(archive, knownRemoteResources);
callback.onProcessMatchedResources(payload.getTotalUncompressedSize());
HttpEntity> entity = generatePartialResourceRequest(payload, knownRemoteResources);
ResponseEntity> responseEntity =
getRestTemplate().exchange(getUrl("/v2/apps/{guid}/bits?async=true"),
HttpMethod.PUT, entity,
new ParameterizedTypeReference>() {}, appId);
processAsyncJob(responseEntity.getBody(), callback);
}
private void processAsyncJob(Map jobResource, UploadStatusCallback callback) {
CloudJob job = resourceMapper.mapResource(jobResource, CloudJob.class);
do {
boolean unsubscribe = callback.onProgress(job.getStatus().toString());
if (unsubscribe) {
return;
}
if (job.getStatus() == CloudJob.Status.FAILED) {
return;
}
try {
Thread.sleep(JOB_POLLING_PERIOD);
} catch (InterruptedException ex) {
return;
}
ResponseEntity> jobProgressEntity =
getRestTemplate().exchange(getUrl(job.getMeta().getUrl()),
HttpMethod.GET, HttpEntity.EMPTY,
new ParameterizedTypeReference>() {});
job = resourceMapper.mapResource(jobProgressEntity.getBody(), CloudJob.class);
} while (job.getStatus() != CloudJob.Status.FINISHED);
}
private CloudResources getKnownRemoteResources(ApplicationArchive archive) throws IOException {
CloudResources archiveResources = new CloudResources(archive);
String json = JsonUtil.convertToJson(archiveResources);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(JsonUtil.JSON_MEDIA_TYPE);
HttpEntity requestEntity = new HttpEntity(json, headers);
ResponseEntity responseEntity =
getRestTemplate().exchange(getUrl("/v2/resource_match"), HttpMethod.PUT, requestEntity, String.class);
List cloudResources = JsonUtil.convertJsonToCloudResourceList(responseEntity.getBody());
return new CloudResources(cloudResources);
}
private HttpEntity> generatePartialResourceRequest(UploadApplicationPayload application,
CloudResources knownRemoteResources) throws IOException {
MultiValueMap body = new LinkedMultiValueMap(2);
body.add("application", application);
ObjectMapper mapper = new ObjectMapper();
String knownRemoteResourcesPayload = mapper.writeValueAsString(knownRemoteResources);
body.add("resources", knownRemoteResourcesPayload);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
return new HttpEntity>(body, headers);
}
private File createTemporaryUploadFile(InputStream inputStream) throws IOException {
File file = File.createTempFile("cfjava", null);
FileOutputStream outputStream = new FileOutputStream(file);
FileCopyUtils.copy(inputStream, outputStream);
outputStream.close();
}
@Override
public StartingInfo startApplication(String appName) {
CloudApplication app = getApplication(appName);
if (app.getState() != CloudApplication.AppState.STARTED) {
HashMap appRequest = new HashMap();
appRequest.put("state", CloudApplication.AppState.STARTED);
HttpEntity requestEntity = new HttpEntity(
appRequest);
ResponseEntity 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
// if there are headers in the response, null otherwise.
if (headers != null && !headers.isEmpty()) {
String stagingFile = headers.getFirst("x-app-staging-log");
if (stagingFile != null) {
try {
stagingFile = URLDecoder.decode(stagingFile, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("unexpected inability to UTF-8 decode", e);
}
}
// Return the starting info even if decoding failed or staging file is null
return new StartingInfo(stagingFile);
}
}
return null;
}
@Override
public void debugApplication(String appName, CloudApplication.DebugMode mode) {
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 appRequest = new HashMap();
appRequest.put("state", CloudApplication.AppState.STOPPED);
getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, app.getMeta().getGuid());
}
}
@Override
public StartingInfo restartApplication(String appName) {
stopApplication(appName);
return startApplication(appName);
}
@Override
public void deleteApplication(String appName) {
UUID appId = getAppId(appName);
doDeleteApplication(appId);
}
@Override
public void deleteAllApplications() {
List cloudApps = getApplications();
for (CloudApplication cloudApp : cloudApps) {
deleteApplication(cloudApp.getName());
}
}
@Override
public void updateApplicationDiskQuota(String appName, int disk) {
UUID appId = getAppId(appName);
HashMap appRequest = new HashMap();
appRequest.put("disk_quota", disk);
getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, appId);
}
@Override
public void updateApplicationMemory(String appName, int memory) {
UUID appId = getAppId(appName);
HashMap appRequest = new HashMap();
appRequest.put("memory", memory);
getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, appId);
}
@Override
public void updateApplicationInstances(String appName, int instances) {
UUID appId = getAppId(appName);
HashMap appRequest = new HashMap();
appRequest.put("instances", instances);
getRestTemplate().put(getUrl("/v2/apps/{guid}"), appRequest, appId);
}
@Override
public void updateApplicationServices(String appName, List services) {
CloudApplication app = getApplication(appName);
List addServices = new ArrayList();
List deleteServices = new ArrayList();
// 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);
}
}
public List getQuotas() {
String urlPath = "/v2/quota_definitions";
List> resourceList = getAllResources(urlPath, null);
List quotas = new ArrayList();
for (Map resource : resourceList) {
quotas.add(resourceMapper.mapResource(resource, CloudQuota.class));
}
return quotas;
}
/**
* Create quota from a CloudQuota instance (Quota Plan)
*
* @param quota
*/
public void createQuota(CloudQuota quota) {
String setPath = "/v2/quota_definitions";
HashMap setRequest = new HashMap();
setRequest.put("name", quota.getName());
setRequest.put("memory_limit", quota.getMemoryLimit());
setRequest.put("total_routes", quota.getTotalRoutes());
setRequest.put("total_services", quota.getTotalServices());
setRequest.put("non_basic_services_allowed", quota.isNonBasicServicesAllowed());
getRestTemplate().postForObject(getUrl(setPath), setRequest, String.class);
}
public void updateQuota(CloudQuota quota, String name) {
CloudQuota oldQuota = this.getQuotaByName(name, true);
String setPath = "/v2/quota_definitions/{quotaGuid}";
Map setVars = new HashMap();
setVars.put("quotaGuid", oldQuota.getMeta().getGuid());
HashMap