org.cloudfoundry.client.lib.domain.ApplicationLog Java Examples
The following examples show how to use
org.cloudfoundry.client.lib.domain.ApplicationLog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PollExecuteAppStatusExecution.java From multiapps-controller with Apache License 2.0 | 6 votes |
private AppExecutionDetailedStatus getAppExecutionStatus(ApplicationLog log, long startTime, Marker sm, Marker fm, String id) { long time = log.getTimestamp() .getTime(); String sourceName = log.getSourceName() .substring(0, 3); if (time < startTime || !sourceName.equalsIgnoreCase("APP")) return null; MessageType mt = log.getMessageType(); String msg = log.getMessage() .trim(); if (!(id == null || msg.contains(id))) return null; if (mt.equals(sm.messageType) && msg.matches(sm.text)) { return new AppExecutionDetailedStatus(AppExecutionStatus.SUCCEEDED); } else if (mt.equals(fm.messageType) && msg.matches(fm.text)) { return new AppExecutionDetailedStatus(AppExecutionStatus.FAILED, msg); } return null; }
Example #2
Source File: LoggregatorSourceTests.java From spring-cloud-stream-app-starters with Apache License 2.0 | 6 votes |
@Bean public CloudFoundryClient cloudFoundryClient() { CloudFoundryClient mockClient = mock(CloudFoundryClient.class); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { ApplicationLogListener listener = invocation.getArgumentAt(1, ApplicationLogListener.class); listener.onMessage(new ApplicationLog("foo", "hello", new Date(1), ApplicationLog.MessageType.STDOUT, "srcN", "srcID")); listener.onComplete(); return null; } }).when(mockClient).streamLogs(eq("foo"), any(ApplicationLogListener.class)); return mockClient; }
Example #3
Source File: LoggregatorSourceTests.java From spring-cloud-stream-app-starters with Apache License 2.0 | 6 votes |
@Test public void testLogReceipt() throws Exception { Message<?> received = this.messageCollector.forChannel(this.channels.output()).poll(10, TimeUnit.SECONDS); assertNotNull(received); assertThat((String) received.getPayload(), is(equalTo("hello"))); assertThat( (String) received.getHeaders() .get(LoggregatorMessageSource.LoggregatorHeaders.APPLICATION_ID.asHeader()), is(equalTo("foo"))); assertThat((Date) received.getHeaders().get(LoggregatorMessageSource.LoggregatorHeaders.TIMESTAMP.asHeader()), is(equalTo(new Date(1)))); assertThat( (ApplicationLog.MessageType) received.getHeaders() .get(LoggregatorMessageSource.LoggregatorHeaders.MESSAGE_TYPE.asHeader()), is(equalTo(ApplicationLog.MessageType.STDOUT))); assertThat( (String) received.getHeaders().get(LoggregatorMessageSource.LoggregatorHeaders.SOURCE_NAME.asHeader()), is(equalTo("srcN"))); assertThat((String) received.getHeaders().get(LoggregatorMessageSource.LoggregatorHeaders.SOURCE_ID.asHeader()), is(equalTo("srcID"))); }
Example #4
Source File: PollExecuteAppStatusExecutionTest.java From multiapps-controller with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource public void testStep(ApplicationLog applicationLog, String successMarker, String failureMarker, boolean shouldStopApp, AsyncExecutionState expectedExecutionState) { CloudApplicationExtended application = buildApplication(successMarker, failureMarker, shouldStopApp); prepareContext(application); prepareRecentLogsRetriever(applicationLog); prepareStepLogger(); prepareClientProvider(); AsyncExecutionState resultState = step.execute(context); assertEquals(expectedExecutionState, resultState); if (shouldStopApp) { verify(client).stopApplication(application.getName()); return; } verify(client, never()).stopApplication(application.getName()); }
Example #5
Source File: CloudControllerRestClientImpl.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
@Override public List<ApplicationLog> getRecentLogs(UUID applicationGuid) { RecentLogsRequest request = RecentLogsRequest.builder() .applicationId(applicationGuid.toString()) .build(); return fetchFlux(() -> dopplerClient.recentLogs(request), ImmutableRawApplicationLog::of).collectSortedList(Comparator.comparing(ApplicationLog::getTimestamp)) .block(); }
Example #6
Source File: RawApplicationLog.java From cf-java-client-sap with Apache License 2.0 | 5 votes |
@Override public ApplicationLog derive() { Envelope envelope = getEnvelope(); LogMessage logMessage = envelope.getLogMessage(); return ImmutableApplicationLog.builder() .applicationGuid(logMessage.getApplicationId()) .message(logMessage.getMessage()) .timestamp(fromLogTimestamp(logMessage)) .messageType(fromLogMessageType(logMessage)) .sourceId(logMessage.getSourceInstance()) .sourceName(logMessage.getSourceType()) .build(); }
Example #7
Source File: LoggregatorMessageSource.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Override public void onMessage(ApplicationLog applicationLog) { Map<String, Object> headers = new HashMap<>(); headers.put(APPLICATION_ID.asHeader(), applicationLog.getAppId()); headers.put(SOURCE_ID.asHeader(), applicationLog.getSourceId()); headers.put(MESSAGE_TYPE.asHeader(), applicationLog.getMessageType()); headers.put(SOURCE_NAME.asHeader(), applicationLog.getSourceName()); headers.put(TIMESTAMP.asHeader(), applicationLog.getTimestamp()); sendMessage(MessageBuilder.withPayload(applicationLog.getMessage()) .copyHeaders(headers) .build()); }
Example #8
Source File: RecentLogsRetrieverTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private ApplicationLog createAppLog(int milis, String message) { Calendar cal = (Calendar) TIMESTAMP.clone(); cal.add(Calendar.MILLISECOND, milis); return ImmutableApplicationLog.builder() .sourceId("") .sourceName("") .messageType(ApplicationLog.MessageType.STDOUT) .message(message) .applicationGuid("") .timestamp(cal.getTime()) .build(); }
Example #9
Source File: StepsUtil.java From multiapps-controller with Apache License 2.0 | 5 votes |
static void saveAppLogs(DelegateExecution execution, CloudControllerClient client, RecentLogsRetriever recentLogsRetriever, CloudApplication app, Logger logger, ProcessLoggerProvider processLoggerProvider) { LogsOffset offset = getLogOffset(execution); List<ApplicationLog> recentLogs = recentLogsRetriever.getRecentLogsSafely(client, app.getName(), offset); if (recentLogs.isEmpty()) { return; } ProcessLogger processLogger = processLoggerProvider.getLogger(execution, app.getName()); for (ApplicationLog log : recentLogs) { saveAppLog(processLogger, app.getName(), log.toString(), logger); } setLogOffset(recentLogs.get(recentLogs.size() - 1), execution); }
Example #10
Source File: StepsUtil.java From multiapps-controller with Apache License 2.0 | 5 votes |
static void setLogOffset(ApplicationLog lastLog, DelegateExecution execution) { LogsOffset newOffset = ImmutableLogsOffset.builder() .timestamp(lastLog.getTimestamp()) .message(lastLog.getMessage()) .build(); execution.setVariable(com.sap.cloud.lm.sl.cf.core.Constants.LOGS_OFFSET, newOffset); }
Example #11
Source File: PollExecuteAppStatusExecution.java From multiapps-controller with Apache License 2.0 | 5 votes |
private AppExecutionDetailedStatus getAppExecutionStatus(ProcessContext context, CloudControllerClient client, ApplicationAttributes appAttributes, CloudApplication app) { long startTime = context.getVariable(Variables.START_TIME); Marker sm = getMarker(appAttributes, SupportedParameters.SUCCESS_MARKER, DEFAULT_SUCCESS_MARKER); Marker fm = getMarker(appAttributes, SupportedParameters.FAILURE_MARKER, DEFAULT_FAILURE_MARKER); boolean checkDeployId = appAttributes.get(SupportedParameters.CHECK_DEPLOY_ID, Boolean.class, Boolean.FALSE); String deployId = checkDeployId ? (StepsUtil.DEPLOY_ID_PREFIX + context.getVariable(Variables.CORRELATION_ID)) : null; List<ApplicationLog> recentLogs = recentLogsRetriever.getRecentLogs(client, app.getName(), null); return recentLogs.stream() .map(log -> getAppExecutionStatus(log, startTime, sm, fm, deployId)) .filter(Objects::nonNull) .reduce(new AppExecutionDetailedStatus(AppExecutionStatus.EXECUTING), (a, b) -> b); }
Example #12
Source File: RecentLogsRetriever.java From multiapps-controller with Apache License 2.0 | 5 votes |
private boolean isLogNew(ApplicationLog log, LogsOffset offset) { if (log.getTimestamp() .compareTo(offset.getTimestamp()) > 0) { return true; } return log.getTimestamp() .equals(offset.getTimestamp()) && !log.getMessage() .equals(offset.getMessage()); }
Example #13
Source File: RecentLogsRetriever.java From multiapps-controller with Apache License 2.0 | 5 votes |
public List<ApplicationLog> getRecentLogs(CloudControllerClient client, String appName, LogsOffset offset) { List<ApplicationLog> appLogs = client.getRecentLogs(appName); if (offset == null) { return appLogs; } return appLogs.stream() .filter(appLog -> isLogNew(appLog, offset)) .collect(Collectors.toList()); }
Example #14
Source File: RecentLogsRetriever.java From multiapps-controller with Apache License 2.0 | 5 votes |
public List<ApplicationLog> getRecentLogsSafely(CloudControllerClient client, String appName, LogsOffset offset) { try { return getRecentLogs(client, appName, offset); } catch (RuntimeException e) { return Collections.emptyList(); } }
Example #15
Source File: PollExecuteAppStatusExecutionTest.java From multiapps-controller with Apache License 2.0 | 5 votes |
private static ApplicationLog createAppLog(String message, MessageType messageType, String sourceName) { return ImmutableApplicationLog.builder() .applicationGuid(PollExecuteAppStatusExecutionTest.APPLICATION_GUID) .message(message) .timestamp(PollExecuteAppStatusExecutionTest.LOG_TIMESTAMP) .messageType(messageType) .sourceId(PollExecuteAppStatusExecutionTest.SOURCE_ID) .sourceName(sourceName) .build(); }
Example #16
Source File: LoggingCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public List<ApplicationLog> getRecentLogs(UUID applicationGuid) { logger.debug(Messages.GETTING_RECENT_LOGS_OF_APPLICATION_0, applicationGuid); return delegate.getRecentLogs(applicationGuid); }
Example #17
Source File: ResilientCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public List<ApplicationLog> getRecentLogs(UUID applicationGuid) { return executeWithRetry(() -> delegate.getRecentLogs(applicationGuid), HttpStatus.NOT_FOUND); }
Example #18
Source File: ResilientCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public List<ApplicationLog> getRecentLogs(String applicationName) { return executeWithRetry(() -> delegate.getRecentLogs(applicationName), HttpStatus.NOT_FOUND); }
Example #19
Source File: PollExecuteAppStatusExecutionTest.java From multiapps-controller with Apache License 2.0 | 4 votes |
private void prepareRecentLogsRetriever(ApplicationLog applicationLog) { when(recentLogsRetriever.getRecentLogs(any(), any(), any())).thenReturn(Arrays.asList(applicationLog)); }
Example #20
Source File: RawApplicationLog.java From cf-java-client-sap with Apache License 2.0 | 4 votes |
private static ApplicationLog.MessageType fromLogMessageType(LogMessage logMessage) { return logMessage.getMessageType() == MessageType.OUT ? ApplicationLog.MessageType.STDOUT : ApplicationLog.MessageType.STDERR; }
Example #21
Source File: CloudControllerRestClientImpl.java From cf-java-client-sap with Apache License 2.0 | 4 votes |
@Override public List<ApplicationLog> getRecentLogs(String applicationName) { UUID appGuid = getRequiredApplicationGuid(applicationName); return getRecentLogs(appGuid); }
Example #22
Source File: LoggingCloudControllerClient.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public List<ApplicationLog> getRecentLogs(String applicationName) { logger.debug(Messages.GETTING_RECENT_LOGS_OF_APPLICATION_0, applicationName); return delegate.getRecentLogs(applicationName); }
Example #23
Source File: CloudControllerClientImpl.java From cf-java-client-sap with Apache License 2.0 | 4 votes |
@Override public List<ApplicationLog> getRecentLogs(UUID applicationGuid) { return handleExceptions(() -> delegate.getRecentLogs(applicationGuid)); }
Example #24
Source File: CloudControllerClientImpl.java From cf-java-client-sap with Apache License 2.0 | 4 votes |
@Override public List<ApplicationLog> getRecentLogs(String applicationName) { return handleExceptions(() -> delegate.getRecentLogs(applicationName)); }
Example #25
Source File: CloudControllerClient.java From cf-java-client-sap with Apache License 2.0 | 2 votes |
/** * Stream recent log entries. * * Stream logs that were recently produced for an app. * * @param applicationName the name of the application * @return the list of recent log entries */ List<ApplicationLog> getRecentLogs(String applicationName);
Example #26
Source File: CloudControllerClient.java From cf-java-client-sap with Apache License 2.0 | 2 votes |
/** * Get recent log entries. * * Get logs that were recently produced for an app. * * @param applicationGuid the guid of the application * @return the list of recent log entries */ List<ApplicationLog> getRecentLogs(UUID applicationGuid);
Example #27
Source File: ApplicationLogListener.java From cf-java-client-sap with Apache License 2.0 | votes |
void onMessage(ApplicationLog log);
Example #28
Source File: CloudControllerRestClient.java From cf-java-client-sap with Apache License 2.0 | votes |
List<ApplicationLog> getRecentLogs(UUID applicationGuid);
Example #29
Source File: CloudControllerRestClient.java From cf-java-client-sap with Apache License 2.0 | votes |
List<ApplicationLog> getRecentLogs(String applicationName);