public static Pair<String, String> getMtaIdAndProvidedDependencyName(String providerId) { String[] providerIdSplitted = providerId.split(PROVIDER_ID_DELIMITER, 2); return new Pair<>(providerIdSplitted[0], providerIdSplitted[1]); }
public Pair<Resource, ProvidedDependency> findDependency(DeploymentDescriptor descriptor, String dependencyName) { Resource resource = findResource(descriptor, dependencyName); if (resource != null) { return new Pair<>(resource, null); } ProvidedDependency providedDependency = findProvidedDependency(descriptor, dependencyName); if (providedDependency != null) { return new Pair<>(null, providedDependency); } return null; }
private Pair<List<ProgressMessage>, List<ProgressMessage>> filterProgressMessages(List<ProgressMessage> allProgressMessagesForProcess, List<String> stepIds) { List<ProgressMessage> relevantProgressMessage = new ArrayList<>(); List<ProgressMessage> nonRelevantProgressMessage = new ArrayList<>(); for (ProgressMessage progressMessage : allProgressMessagesForProcess) { if (contains(stepIds, progressMessage)) { relevantProgressMessage.add(progressMessage); } else { nonRelevantProgressMessage.add(progressMessage); } } return new Pair<List<ProgressMessage>, List<ProgressMessage>>(relevantProgressMessage, nonRelevantProgressMessage); }
private Pair<String, String> readTokenKey() { Map<String, Object> tokenKeyResponse = uaaClient.readTokenKey(); Object value = tokenKeyResponse.get("value"); Object alg = tokenKeyResponse.get("alg"); if (value == null || alg == null) { throw new InternalAuthenticationServiceException("Response from /token_key does not contain a key value or an algorithm"); } return new Pair<>(value.toString(), alg.toString()); }
public static Pair<String, String> getHostAndDomain(String uri) { uri = getUriWithoutScheme(uri); int portIndex = uri.lastIndexOf(DEFAULT_PORT_SEPARATOR); if (portIndex > 0) { int pathIndex = getPathIndexAfter(uri, portIndex); // Port-based route, return (port, domain): return new Pair<>(uri.substring(portIndex + 1, pathIndex), uri.substring(0, portIndex)); } else { // Host-based route, return (host, domain): int domainIndex = uri.indexOf(DEFAULT_HOST_DOMAIN_SEPARATOR); int pathIndex = getPathIndexAfter(uri, domainIndex); if (domainIndex > 0) { return new Pair<>(uri.substring(0, domainIndex), uri.substring(domainIndex + 1, pathIndex)); } return new Pair<>("", uri.substring(0, pathIndex)); } }
private Pair<AppExecutionStatus, String> getAppExecutionStatus(ApplicationLog log, long startTime, Pair<MessageType, String> sm, Pair<MessageType, String> fm, String id) { long time = log.getTimestamp() .getTime(); String sourceName = log.getSourceName(); sourceName = (sourceName.length() >= 3) ? sourceName.substring(0, 3) : sourceName; if (time < startTime || !sourceName.equalsIgnoreCase("APP")) return null; MessageType mt = log.getMessageType(); String msg = log.getMessage() .trim(); if (mt != null && mt.equals(sm._1) && msg.matches(sm._2) && ((id == null) || msg.contains(id))) { return new Pair<>(AppExecutionStatus.SUCCEEDED, null); } else if (mt != null && mt.equals(fm._1) && msg.matches(fm._2) && ((id == null) || msg.contains(id))) { return new Pair<>(AppExecutionStatus.FAILED, msg); } else return null; }
private Pair<AppExecutionStatus, String> getAppExecutionStatus(ApplicationLog log, long startTime, Pair<MessageType, String> sm, Pair<MessageType, String> fm, String id) { long time = log.getTimestamp() .getTime(); String sourceName = log.getSourceName(); sourceName = (sourceName.length() >= 3) ? sourceName.substring(0, 3) : sourceName; if (time < startTime || !sourceName.equalsIgnoreCase("APP")) return null; MessageType mt = log.getMessageType(); String msg = log.getMessage() .trim(); if (mt != null && mt.equals(sm._1) && msg.matches(sm._2) && ((id == null) || msg.contains(id))) { return new Pair<>(AppExecutionStatus.SUCCEEDED, null); } else if (mt != null && mt.equals(fm._1) && msg.matches(fm._2) && ((id == null) || msg.contains(id))) { return new Pair<>(AppExecutionStatus.FAILED, msg); } else return null; }
private static Pair<MessageType, String> getMarker(ApplicationAttributes appAttributes, String attribute, String defaultValue) { MessageType messageType; String text; String attr = appAttributes.get(attribute, String.class, defaultValue); if (attr.startsWith(MessageType.STDERR.toString() + ":")) { messageType = MessageType.STDERR; text = attr.substring(MessageType.STDERR.toString() .length() + 1); } else if (attr.startsWith(MessageType.STDOUT.toString() + ":")) { messageType = MessageType.STDOUT; text = attr.substring(MessageType.STDOUT.toString() .length() + 1); } else { messageType = MessageType.STDOUT; text = attr; } return new Pair<>(messageType, text); }
private static Pair<MessageType, String> getMarker(ApplicationAttributes appAttributes, String attribute, String defaultValue) { MessageType messageType; String text; String attr = appAttributes.get(attribute, String.class, defaultValue); if (attr.startsWith(MessageType.STDERR.toString() + ":")) { messageType = MessageType.STDERR; text = attr.substring(MessageType.STDERR.toString() .length() + 1); } else if (attr.startsWith(MessageType.STDOUT.toString() + ":")) { messageType = MessageType.STDOUT; text = attr.substring(MessageType.STDOUT.toString() .length() + 1); } else { messageType = MessageType.STDOUT; text = attr; } return new Pair<>(messageType, text); }
private Pair<AppExecutionStatus, String> getAppExecutionStatus(DelegateExecution context, CloudControllerClient client, ApplicationAttributes appAttributes, CloudApplication app) { Pair<AppExecutionStatus, String> status = new Pair<>(AppExecutionStatus.EXECUTING, null); long startTime = (Long) context.getVariable(Constants.VAR_START_TIME); Pair<MessageType, String> sm = getMarker(appAttributes, SupportedParameters.SUCCESS_MARKER, DEFAULT_SUCCESS_MARKER); Pair<MessageType, String> fm = getMarker(appAttributes, SupportedParameters.FAILURE_MARKER, DEFAULT_FAILURE_MARKER); boolean checkDeployId = appAttributes.get(SupportedParameters.CHECK_DEPLOY_ID, Boolean.class, false); String deployId = checkDeployId ? (StepsUtil.DEPLOY_ID_PREFIX + StepsUtil.getCorrelationId(context)) : null; List<ApplicationLog> recentLogs = recentLogsRetriever.getRecentLogs(client, app.getName()); if (recentLogs != null) { Optional<Pair<AppExecutionStatus, String>> statusx = recentLogs.stream() .map(log -> getAppExecutionStatus(log, startTime, sm, fm, deployId)) .filter(Objects::nonNull) .reduce((a, b) -> b); if (statusx.isPresent()) { status = statusx.get(); } } return status; }
private Pair<AppExecutionStatus, String> getAppExecutionStatus(DelegateExecution context, CloudControllerClient client, ApplicationAttributes appAttributes, CloudApplication app) { Pair<AppExecutionStatus, String> status = new Pair<>(AppExecutionStatus.EXECUTING, null); long startTime = (Long) context.getVariable(Constants.VAR_START_TIME); Pair<MessageType, String> sm = getMarker(appAttributes, SupportedParameters.SUCCESS_MARKER, DEFAULT_SUCCESS_MARKER); Pair<MessageType, String> fm = getMarker(appAttributes, SupportedParameters.FAILURE_MARKER, DEFAULT_FAILURE_MARKER); boolean checkDeployId = appAttributes.get(SupportedParameters.CHECK_DEPLOY_ID, Boolean.class, false); String deployId = checkDeployId ? (StepsUtil.DEPLOY_ID_PREFIX + StepsUtil.getCorrelationId(context)) : null; List<ApplicationLog> recentLogs = recentLogsRetriever.getRecentLogs(client, app.getName()); if (recentLogs != null) { Optional<Pair<AppExecutionStatus, String>> statusx = recentLogs.stream() .map(log -> getAppExecutionStatus(log, startTime, sm, fm, deployId)) .filter(Objects::nonNull) .reduce((a, b) -> b); if (statusx.isPresent()) { status = statusx.get(); } } return status; }
public Pair<String, String> computeOrgAndSpace(String spaceId) { CloudSpace space = attemptToFindSpace(spaceId); if (space != null) { return new Pair<>(space.getOrganization() .getName(), space.getName()); } return null; }
public static Stream<Arguments> testValidate() { return Stream.of( // @formatter:off // (1) All conditions are true Arguments.of(MapUtil.of(new Pair("vcap-application",true), new Pair("vcap-services",true), new Pair("user-provided",true)), true), // (2) All conditions are false Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services",false), new Pair("user-provided",false)), true), // (3) Test with error value for vcap-application Arguments.of(MapUtil.of(new Pair("vcap-application","foo.bar"), new Pair("vcap-services",false), new Pair("user-provided",false)), false), // (4) Test with error value for vcap-services Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services","foo.bar"), new Pair("user-provided",true)), false), // (5) Test with error value for user-provided Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services",true), new Pair("user-provided","bar.xyz")), false), // (6) Test with not map object Arguments.of(null, false), // (7) Arguments.of(MapUtil.of(new Pair("vcap-application",false), new Pair("vcap-services",true), new Pair("user-provided",false)), true), // (8) Arguments.of(MapUtil.of(new Pair("vcap-application",true), new Pair("vcap-services",true), new Pair("user-provided",false)), true), // (9) Not all parameters set Arguments.of(MapUtil.of(new Pair("vcap-services",false), new Pair("user-provided",true)), true), // (10) Arguments.of(MapUtil.of(new Pair("user-provided",true)), true), // (11) Arguments.of(MapUtil.of(new Pair("vcap-application",false)), true) // @formatter:on ); }
@Override protected Pair<CloudControllerClient, TokenProvider> createClient(CloudCredentials credentials) { CloudControllerRestClientFactory factory = new CloudControllerRestClientFactory(null, configuration.shouldSkipSslValidation()); addTaggingInterceptor(factory.getRestTemplate()); OauthClient oauthClient = createOauthClient(factory.getRestTemplate()); CloudControllerRestClient controllerClient = factory.newCloudController(configuration.getControllerUrl(), credentials, null, oauthClient); return new Pair<>(new ResilientCloudControllerClient(controllerClient), new CloudFoundryTokenProvider(oauthClient)); }
@Override protected Pair<CloudControllerClient, TokenProvider> createClient(CloudCredentials credentials, String org, String space) { CloudControllerRestClientFactory factory = new CloudControllerRestClientFactory(null, configuration.shouldSkipSslValidation()); CloudSpace sessionSpace = getSessionSpace(credentials, org, space); addTaggingInterceptor(factory.getRestTemplate(), org, space); OauthClient oauthClient = createOauthClient(factory.getRestTemplate()); CloudControllerRestClient controllerClient = factory.newCloudController(configuration.getControllerUrl(), credentials, sessionSpace, oauthClient); return new Pair<>(new ResilientCloudControllerClient(controllerClient), new CloudFoundryTokenProvider(oauthClient)); }
protected Pair<CloudControllerClient, TokenProvider> createClient(CloudCredentials credentials, String spaceId) { CloudControllerRestClientFactory factory = new CloudControllerRestClientFactory(null, configuration.shouldSkipSslValidation()); CloudSpace sessionSpace = getSessionSpace(credentials, spaceId); addTaggingInterceptor(factory.getRestTemplate(), sessionSpace.getOrganization() .getName(), sessionSpace.getName()); OauthClient oauthClient = createOauthClient(factory.getRestTemplate()); CloudControllerRestClient controllerClient = factory.newCloudController(configuration.getControllerUrl(), credentials, sessionSpace, oauthClient); return new Pair<>(new ResilientCloudControllerClient(controllerClient), new CloudFoundryTokenProvider(oauthClient)); }