Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

public enum ResourceType {
MANAGED_SERVICE("managed-service", SupportedParameters.SERVICE, SupportedParameters.SERVICE_PLAN), USER_PROVIDED_SERVICE(
"user-provided-service"), EXISTING_SERVICE("existing-service"), EXISTING_SERVICE_KEY("existing-service-key");
"user-provided-service"), EXISTING_SERVICE("existing-service"), EXISTING_SERVICE_KEY(
"existing-service-key"), EXTERNAL_LOGGING_SERVICE(
"external-logging-service", SupportedParameters.SERVICE_KEY_NAME);

private final String name;
private final Set<String> requiredParameters = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.cloudfoundry.multiapps.controller.core.model;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.cloudfoundry.multiapps.common.Nullable;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableExternalLoggingServiceConfiguration.class)
@JsonDeserialize(as = ImmutableExternalLoggingServiceConfiguration.class)
public interface ExternalLoggingServiceConfiguration {

String getServiceInstanceName();

String getServiceKeyName();

@Nullable
String getTargetOrg();

@Nullable
String getTargetSpace();
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ public class SupportedParameters {
SERVICE_KEY_NAME, SERVICE_NAME, SERVICE_PLAN, SERVICE_TAGS, SERVICE_BROKER,
SKIP_SERVICE_UPDATES, TYPE, PROVIDER_ID, PROVIDER_NID, TARGET,
SERVICE_CONFIG_PATH, FILTER, MANAGED, VERSION, PATH, MEMORY,
FAIL_ON_SERVICE_UPDATE, SERVICE_PROVIDER, SERVICE_VERSION);
FAIL_ON_SERVICE_UPDATE, SERVICE_PROVIDER, SERVICE_VERSION,
ORGANIZATION_NAME, SPACE_NAME);
public static final Set<String> GLOBAL_PARAMETERS = Set.of(KEEP_EXISTING_ROUTES, APPS_UPLOAD_TIMEOUT, APPS_TASK_EXECUTION_TIMEOUT,
APPS_START_TIMEOUT, APPS_STAGE_TIMEOUT, APPLY_NAMESPACE,
ENABLE_PARALLEL_DEPLOYMENTS, DEPLOY_MODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static ResourceType getResourceType(Resource resource) {
return ResourceType.get(type);
}

private static String getServiceName(Resource resource) {
public static String getServiceName(Resource resource) {
var serviceName = (String) resource.getParameters()
.get(SupportedParameters.SERVICE_NAME);
return serviceName == null ? resource.getName() : serviceName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.cloudfoundry.multiapps.controller.persistence.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.cloudfoundry.multiapps.common.Nullable;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableExternalOperationLogEntry.class)
@JsonDeserialize(as = ImmutableExternalOperationLogEntry.class)
public interface ExternalOperationLogEntry {

@JsonProperty("msg")
String getMessage();

@JsonProperty("date")
String getTimestamp();

@JsonProperty("correlation_id")
@Nullable
String getCorrelationId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class SqlOperationLogQueryProvider {
private static final String ID_COLUMN_LABEL = "id";
private static final String OPERATION_LOG_COLUMN_LABEL = "operation_log";
private static final String OPERATION_LOG_NAME_COLUMN_LABEL = "operation_log_name";
private static final String SELECT_LOGS_BY_SPACE_ID_OPERATION_ID_AND_OPERATION_LOG_NAME = "SELECT ID, OPERATION_LOG, OPERATION_LOG_NAME FROM %s WHERE SPACE=? AND OPERATION_ID=? AND OPERATION_LOG_NAME=? ORDER BY MODIFIED ASC";
private static final String OPERATION_LOG_MODIFIED_COLUMN_LABEL = "modified";
private static final String SELECT_LOGS_BY_SPACE_ID_OPERATION_ID_AND_OPERATION_LOG_NAME = "SELECT ID, OPERATION_LOG, OPERATION_LOG_NAME, MODIFIED FROM %s WHERE SPACE=? AND OPERATION_ID=? AND OPERATION_LOG_NAME=? ORDER BY MODIFIED ASC";
private static final String SELECT_LOGS_BY_SPACE_ID_AND_NAME = "SELECT DISTINCT ID, OPERATION_LOG, OPERATION_LOG_NAME, MODIFIED FROM %s WHERE SPACE=? AND OPERATION_ID=? ORDER BY MODIFIED ASC";
private final String tableName;


public SqlOperationLogQueryProvider(String tableName) {
this.tableName = tableName;
}
Expand Down Expand Up @@ -115,6 +115,8 @@ private OperationLogEntry getOperationLogEntry(ResultSet resultSet) throws SQLEx
.id(resultSet.getString(ID_COLUMN_LABEL))
.operationLog(resultSet.getString(OPERATION_LOG_COLUMN_LABEL))
.operationLogName(resultSet.getString(OPERATION_LOG_NAME_COLUMN_LABEL))
.modified(resultSet.getTimestamp(OPERATION_LOG_MODIFIED_COLUMN_LABEL)
.toLocalDateTime())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package org.cloudfoundry.multiapps.controller.persistence.services;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import org.cloudfoundry.multiapps.controller.persistence.model.ImmutableOperationLogEntry;
import org.cloudfoundry.multiapps.controller.persistence.model.OperationLogEntry;
import org.springframework.scheduling.annotation.Async;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import org.cloudfoundry.multiapps.controller.persistence.model.ExternalOperationLogEntry;
import org.cloudfoundry.multiapps.controller.persistence.model.ImmutableExternalOperationLogEntry;
import org.cloudfoundry.multiapps.controller.persistence.model.ImmutableOperationLogEntry;
import org.cloudfoundry.multiapps.controller.persistence.model.OperationLogEntry;
import org.springframework.scheduling.annotation.Async;

@Named("processLoggerPersister")
public class ProcessLoggerPersister {

Expand All @@ -29,6 +33,7 @@ public ProcessLoggerPersister(ProcessLoggerProvider processLoggerProvider,
public void persistLogs(String correlationId, String taskId) {
List<ProcessLogger> processLoggers = processLoggerProvider.getExistingLoggers(correlationId, taskId);
Map<String, StringBuilder> processLogsMessages = new HashMap<>();
List<ExternalOperationLogEntry> externalOperationLogEntries = new ArrayList<>();

if (processLoggers.isEmpty()) {
return;
Expand Down Expand Up @@ -61,6 +66,14 @@ public void persistLogs(String correlationId, String taskId) {
.withOperationLog(processLogsMessage.getValue()
.toString())
.withModified(LocalDateTime.now());
externalOperationLogEntries.add(ImmutableExternalOperationLogEntry.builder()
.timestamp(String.valueOf(LocalDateTime.now()
.toEpochSecond(
ZoneOffset.UTC)))
.correlationId(correlationId)
.message(processLogsMessage.getValue()
.toString())
.build());
processLogsPersistenceService.persistLog(operationLogEntry);
}
}
Expand Down
4 changes: 4 additions & 0 deletions multiapps-controller-process/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@

requires static java.compiler;
requires static org.immutables.value;
requires spring.webflux;
requires annotations;
requires reactor.netty.core;
requires reactor.netty.http;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.inject.Inject;
import jakarta.inject.Named;

import org.cloudfoundry.multiapps.controller.api.model.Operation;
import org.cloudfoundry.multiapps.controller.api.model.ProcessType;
import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration;
Expand Down Expand Up @@ -67,4 +66,5 @@ private void publishDynatraceEvent(DelegateExecution execution, ProcessType proc
.build();
dynatracePublisher.publishProcessEvent(finishedEvent, getLogger());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import org.cloudfoundry.multiapps.controller.core.helpers.ModuleToDeployHelper;
import org.cloudfoundry.multiapps.controller.core.model.DeployedMta;
import org.cloudfoundry.multiapps.controller.core.model.DeployedMtaApplication;
import org.cloudfoundry.multiapps.controller.core.model.ExternalLoggingServiceConfiguration;
import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
import org.cloudfoundry.multiapps.controller.core.security.serialization.SecureSerialization;
import org.cloudfoundry.multiapps.controller.core.util.CloudModelBuilderUtil;
import org.cloudfoundry.multiapps.controller.core.util.NameUtil;
import org.cloudfoundry.multiapps.controller.process.Messages;
import org.cloudfoundry.multiapps.controller.process.util.DeprecatedBuildpackChecker;
import org.cloudfoundry.multiapps.controller.process.util.ExternalLoggingServiceConfigurationsCalculator;
import org.cloudfoundry.multiapps.controller.process.util.ProcessTypeParser;
import org.cloudfoundry.multiapps.controller.process.variables.Variables;
import org.cloudfoundry.multiapps.mta.builders.v2.ParametersChainBuilder;
Expand Down Expand Up @@ -130,6 +132,13 @@ protected StepPhase executeStep(ProcessContext context) {
List<List<CloudServiceInstanceExtended>> batchesToProcess = getResourceBatches(context, resourcesForDeployment);
context.setVariable(Variables.BATCHES_TO_PROCESS, batchesToProcess);
getStepLogger().debug(Messages.CALCULATING_RESOURCE_BATCHES_COMPLETE);

List<ExternalLoggingServiceConfiguration> externalLoggingServiceConfigurations = calculateExternalLoggingServiceConfigurations(
context, deploymentDescriptor);
context.setVariable(Variables.EXTERNAL_LOGGING_SERVICE_CONFIGURATIONS, externalLoggingServiceConfigurations);
getStepLogger().debug("External logging service configurations: {0}",
SecureSerialization.toJson(externalLoggingServiceConfigurations));

getStepLogger().debug(Messages.CLOUD_MODEL_BUILT);
return StepPhase.DONE;
}
Expand Down Expand Up @@ -331,4 +340,11 @@ private List<String> getDomainsFromApps(ProcessContext context, DeploymentDescri
return new ArrayList<>(domains);
}

private List<ExternalLoggingServiceConfiguration> calculateExternalLoggingServiceConfigurations(ProcessContext context,
DeploymentDescriptor deploymentDescriptor) {
ExternalLoggingServiceConfigurationsCalculator calculator = new ExternalLoggingServiceConfigurationsCalculator(
context.getControllerClient());
return calculator.calculateExternalLoggingServiceConfigurations(deploymentDescriptor.getResources());
}

}
Loading
Loading