@Override public List<ApplicationLog> getRecentLogs(String appName) { UUID appId = getApplicationId(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; }
private String getCurrentUserId() { String username = getInfo().getUser(); Map<String, Object> userMap = getUserInfo(username); String userId = (String) userMap.get("user_id"); return userId; }
/** * Determine if server supports debug mode, if necessary by sending a * request to the server. The information is cached for quicker, subsequent * checks. * */ protected synchronized void requestAllowDebug(CloudFoundryOperations client) throws CoreException { // Check the debug support of the server once per working copy of server if (isDebugModeSupported == DebugSupportCheck.UNCHECKED) { isDebugModeSupported = client.getCloudInfo().getAllowDebug() ? DebugSupportCheck.SUPPORTED : DebugSupportCheck.UNSUPPORTED; } }
public void saveToken(URI target, OAuth2AccessToken token, CloudInfo cloudInfo, CloudSpace space) { TargetInfos targetInfos = getTokensFromFile(); if (targetInfos == null) { targetInfos = new TargetInfos(); } HashMap<String, String> targetInfo = targetInfos.get(target); if (targetInfo == null) { targetInfo = new LinkedHashMap<String, String>(); } targetInfos.putToken(targetInfo, token); targetInfos.putRefreshToken(targetInfo, token.getRefreshToken()); targetInfos.putVersion(targetInfo, cloudInfo.getVersion()); targetInfos.putSpace(targetInfo, space.getMeta().getGuid().toString()); targetInfos.putOrganization(targetInfo, space.getOrganization().getMeta().getGuid().toString()); targetInfos.put(target, targetInfo); saveTokensToFile(targetInfos); }
@Override public CloudInfo getInfo() { String infoV2Json = getRestTemplate().getForObject(getUrl("/v2/info"), String.class); Map<String, Object> infoV2Map = JsonUtil.convertJsonToMap(infoV2Json); Map<String, Object> userMap = getUserInfo((String) infoV2Map.get("user")); 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; 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); }
private SystemParametersBuilder createParametersBuilder(DelegateExecution context, CloudControllerClient client, PortAllocator portAllocator, boolean portBasedRouting, String defaultDomainName, boolean reserveTemporaryRoute) { DeployedMta deployedMta = StepsUtil.getDeployedMta(context); boolean useNamespacesForServices = (boolean) context.getVariable(Constants.PARAM_USE_NAMESPACES_FOR_SERVICES); boolean useNamespaces = (boolean) context.getVariable(Constants.PARAM_USE_NAMESPACES); String authorizationEndpoint = client.getCloudInfo() .getAuthorizationEndpoint(); int routerPort = configuration.getRouterPort(); String user = (String) context.getVariable(Constants.VAR_USER); URL controllerUrl = configuration.getControllerUrl(); String deployServiceUrl = getDeployServiceUrl(client); Map<String, Object> xsPlaceholderReplacementValues = buildXsPlaceholderReplacementValues(defaultDomainName, authorizationEndpoint, deployServiceUrl, routerPort, controllerUrl.toString(), controllerUrl.getProtocol()); StepsUtil.setXsPlaceholderReplacementValues(context, xsPlaceholderReplacementValues); boolean areXsPlaceholdersSupported = configuration.areXsPlaceholdersSupported(); return new SystemParametersBuilder(StepsUtil.getOrg(context), StepsUtil.getSpace(context), user, defaultDomainName, configuration.getPlatformType(), controllerUrl, authorizationEndpoint, deployServiceUrl, routerPort, portBasedRouting, reserveTemporaryRoute, portAllocator, useNamespaces, useNamespacesForServices, deployedMta, credentialsGeneratorSupplier.get(), areXsPlaceholdersSupported, timestampSupplier); }
public void saveToken(URI target, OAuth2AccessToken token, CloudInfo cloudInfo, CloudSpace space) { TargetInfos targetInfos = getTokensFromFile(); if (targetInfos == null) { targetInfos = new TargetInfos(); } HashMap<String, String> targetInfo = targetInfos.get(target); if (targetInfo == null) { targetInfo = new LinkedHashMap<String, String>(); } targetInfos.putToken(targetInfo, token); targetInfos.putRefreshToken(targetInfo, token.getRefreshToken()); targetInfos.putVersion(targetInfo, cloudInfo.getVersion()); targetInfos.putSpace(targetInfo, space.getMeta() .getGuid() .toString()); targetInfos.putOrganization(targetInfo, space.getOrganization() .getMeta() .getGuid() .toString()); targetInfos.put(target, targetInfo); saveTokensToFile(targetInfos); }
@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<String, Object> infoV2Map = JsonUtil.convertJsonToMap(infoV2Json); Map<String, Object> userMap = getUserInfo((String) infoV2Map.get("user")); String infoJson = getRestTemplate().getForObject(getUrl("/info"), String.class); Map<String, Object> infoMap = JsonUtil.convertJsonToMap(infoJson); Map<String, Object> limitMap = (Map<String, Object>) infoMap.get("limits"); Map<String, Object> usageMap = (Map<String, Object>) 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); }
private SystemParametersBuilder createParametersBuilder(DelegateExecution context, CloudControllerClient client, PortAllocator portAllocator, boolean portBasedRouting, String defaultDomainName, boolean reserveTemporaryRoute) { DeployedMta deployedMta = StepsUtil.getDeployedMta(context); boolean useNamespacesForServices = (boolean) context.getVariable(Constants.PARAM_USE_NAMESPACES_FOR_SERVICES); boolean useNamespaces = (boolean) context.getVariable(Constants.PARAM_USE_NAMESPACES); String authorizationEndpoint = client.getCloudInfo() .getAuthorizationEndpoint(); int routerPort = configuration.getRouterPort(); String user = (String) context.getVariable(Constants.VAR_USER); URL controllerUrl = configuration.getControllerUrl(); String deployServiceUrl = getDeployServiceUrl(client); Map<String, Object> xsPlaceholderReplacementValues = buildXsPlaceholderReplacementValues(defaultDomainName, authorizationEndpoint, deployServiceUrl, routerPort, controllerUrl.toString(), controllerUrl.getProtocol()); StepsUtil.setXsPlaceholderReplacementValues(context, xsPlaceholderReplacementValues); boolean areXsPlaceholdersSupported = configuration.areXsPlaceholdersSupported(); return new SystemParametersBuilder(StepsUtil.getOrg(context), StepsUtil.getSpace(context), user, defaultDomainName, configuration.getPlatformType(), controllerUrl, authorizationEndpoint, deployServiceUrl, routerPort, portBasedRouting, reserveTemporaryRoute, portAllocator, useNamespaces, useNamespacesForServices, deployedMta, credentialsGeneratorSupplier.get(), areXsPlaceholdersSupported, timestampSupplier); }
@Override public List<ApplicationLog> 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; }
private String getCurrentUserId() { String username = getInfo().getUser(); Map<String, Object> userMap = getUserInfo(username); String userId= (String) userMap.get("user_id"); return userId; }
private StreamingLogToken streamLoggregatorLogs(String appName, ApplicationLogListener listener, boolean recent) { ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() { @Override public void beforeRequest(Map<String, List<String>> headers) { String authorizationHeader = oauthClient.getAuthorizationHeader(); if (authorizationHeader != null) { headers.put(AUTHORIZATION_HEADER_KEY, Arrays.asList(authorizationHeader)); } } }; String endpoint = getInfo().getLoggregatorEndpoint(); String mode = recent ? "dump" : "tail"; UUID appId = getApplicationId(appName); return loggregatorClient.connectToLoggregator(endpoint, mode, appId, listener, configurator); }
private StreamingLogToken streamLoggregatorLogs(String appName, ApplicationLogListener listener, boolean recent) { ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() { public void beforeRequest(Map<String, List<String>> headers) { String authorizationHeader = oauthClient.getAuthorizationHeader(); if (authorizationHeader != null) { headers.put(AUTHORIZATION_HEADER_KEY, Arrays.asList(authorizationHeader)); } } }; String endpoint = getInfo().getLoggregatorEndpoint(); String mode = recent ? "dump" : "tail"; UUID appId = getAppId(appName); return loggregatorClient.connectToLoggregator(endpoint, mode, appId, listener, configurator); }