Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cloudfoundry-client-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cloudfoundry</groupId>
<artifactId>cloudfoundry-client-lib</artifactId>
<version>1.1.5.BUILD-15-2018102500</version>
<version>1.1.5.BUILD-16-2018120600</version>
<packaging>jar</packaging>
<name>Cloud Foundry Java Client Library</name>
<description>A Cloud Foundry client library for Java</description>
Expand Down Expand Up @@ -33,6 +33,7 @@
<tomcat.version>8.0.15</tomcat.version>
<jetty.version>8.1.12.v20130726</jetty.version>
<byteman.version>2.1.3</byteman.version>
<version.guava>22.0</version.guava>
</properties>

<profiles>
Expand Down Expand Up @@ -269,6 +270,12 @@
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${version.guava}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.*;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

/**
* Abstract implementation of the CloudControllerClient intended to serve as the base.
Expand All @@ -67,7 +69,11 @@ public class CloudControllerClientImpl implements CloudControllerClient {
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 static final Cache<String, UUID> cachedAppIds =
CacheBuilder.newBuilder().expireAfterAccess(24, TimeUnit.HOURS).build();

private static final Cache<String, CloudSpace> cachedSpaces =
CacheBuilder.newBuilder().expireAfterAccess(24, TimeUnit.HOURS).build();
private OauthClient oauthClient;

private CloudSpace sessionSpace;
Expand Down Expand Up @@ -533,14 +539,20 @@ public void createSpace(String spaceName) {

@Override
public CloudSpace getSpace(String spaceName) {
CloudSpace space = cachedSpaces.getIfPresent(spaceName);
if (space != null) {
return space;
}
String urlPath = "/v2/spaces?inline-relations-depth=1&q=name:{name}";
HashMap<String, Object> spaceRequest = new HashMap<String, Object>();
spaceRequest.put("name", spaceName);
List<Map<String, Object>> resourceList = getAllResources(urlPath, spaceRequest);
CloudSpace space = null;
if (resourceList.size() > 0) {
Map<String, Object> resource = resourceList.get(0);
space = resourceMapper.mapResource(resource, CloudSpace.class);
if (space != null) {
cachedSpaces.put(spaceName, space);
}
}
return space;
}
Expand Down Expand Up @@ -2292,11 +2304,18 @@ private UUID getServiceBindingId(UUID appId, UUID serviceId ) {

@SuppressWarnings("unchecked")
private UUID getAppId(String appName) {
Map<String, Object> resource = findApplicationResource(appName, false);
UUID appId = cachedAppIds.getIfPresent(appName);
if (appId != null) {
return appId;
}
Map<String, Object> resource = findApplicationResource(appName, false, 0);
UUID guid = null;
if (resource != null) {
Map<String, Object> appMeta = (Map<String, Object>) resource.get("metadata");
guid = UUID.fromString(String.valueOf(appMeta.get("guid")));
if (guid != null){
cachedAppIds.put(appName, guid);
}
}
return guid;
}
Expand Down Expand Up @@ -2354,22 +2373,25 @@ private Map<String, Object> findApplicationResource(UUID appGuid, boolean fetchS
return processApplicationResource(JsonUtil.convertJsonToMap(resp), fetchServiceInfo);
}


private Map<String, Object> findApplicationResource(String appName, boolean fetchServiceInfo) {
private Map<String, Object> findApplicationResource(String appName, boolean fetchServiceInfo, int maxDepth) {
Map<String, Object> urlVars = new HashMap<String, Object>();
String urlPath = "/v2";
if (sessionSpace != null) {
urlVars.put("space", sessionSpace.getMeta().getGuid());
urlPath = urlPath + "/spaces/{space}";
}
urlVars.put("q", "name:" + appName);
urlPath = urlPath + "/apps?inline-relations-depth=1&q={q}";
urlPath = urlPath + "/apps?inline-relations-depth=" + maxDepth + "&q={q}";

List<Map<String, Object>> allResources = getAllResources(urlPath, urlVars);
if(!allResources.isEmpty()) {
return processApplicationResource(allResources.get(0), fetchServiceInfo);
}
return null;
}

private Map<String, Object> findApplicationResource(String appName, boolean fetchServiceInfo) {
return findApplicationResource(appName, fetchServiceInfo, 1);
}

private Map<String, Object> processApplicationResource(Map<String, Object> resource, boolean fetchServiceInfo) {
Expand Down