Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -2,6 +2,7 @@

import java.util.List;

import jakarta.servlet.http.HttpServletRequest;
import org.cloudfoundry.multiapps.controller.api.model.Log;
import org.cloudfoundry.multiapps.controller.api.model.Operation;
import org.springframework.http.ResponseEntity;
Expand All @@ -20,6 +21,6 @@ public interface OperationsApiService {

ResponseEntity<String> getOperationLogContent(String spaceGuid, String operationId, String logId);

ResponseEntity<Operation> startOperation(String spaceGuid, Operation operation);
ResponseEntity<Operation> startOperation(String spaceGuid, Operation operation, HttpServletRequest httpServletRequest);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
import jakarta.inject.Inject;
import jakarta.servlet.http.HttpServletRequest;
import org.cloudfoundry.multiapps.controller.api.Constants.Endpoints;
import org.cloudfoundry.multiapps.controller.api.Constants.PathVariables;
import org.cloudfoundry.multiapps.controller.api.Constants.QueryVariables;
Expand Down Expand Up @@ -114,8 +115,8 @@ public ResponseEntity<List<String>> getOperationActions(@PathVariable(PathVariab
}) }, tags = {})
@ApiResponses(value = { @ApiResponse(code = 202, message = "Accepted") })
public ResponseEntity<Operation> startOperation(@PathVariable(PathVariables.SPACE_GUID) String spaceGuid,
@RequestBody Operation operation) {
return delegate.startOperation(spaceGuid, operation);
@RequestBody Operation operation, HttpServletRequest httpServletRequest) {
return delegate.startOperation(spaceGuid, operation, httpServletRequest);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Constants {
public static final String TRIPLE_APPENDED_STRING = "%s%s%s";
public static final String SECURE_EXTENSION_DESCRIPTOR_ID = "__mta.secure";
public static final String STRING_SEPARATOR = "-";
public static final String DEPRECATED_ROUTE_MARKER = "cfapps";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to changeto: ".cfapps."


public static final Long UNSET_LAST_LOG_TIMESTAMP_MS = 0L;
public static final int LOG_STALLED_TASK_MINUTE_INTERVAL = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public class Messages {
// Progress messages
public static final String OPERATION_ID = "Operation ID: {0}";
public static final String MTA_SCHEMA_VERSION_DETECTED_AS = "Detected MTA schema version: \"{0}\"";
public static final String LEGACY_ROUTE_DEPLOY_SERVICE_DEPRECATED = "You are using legacy route https://deploy-service.cfapps.<domain> of SAP Cloud Deployment service. It will be deprecated and removed in the end of 2026. To avoid issues in the future, update all workflows to use the proper SAP Cloud Deployment route https://deploy-service.cf.<domain> (replace \"cfapps\" with \"cf\"). More information: https://me.sap.com/notes/3695458";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this message is quite related to SAP. I'd suggest to move it in the internal project. Override the step and print the message there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks :)

public static final String DEPLOYING_IN_ORG_0_AND_SPACE_1 = "Deploying in org \"{0}\" and space \"{1}\"";
public static final String NO_DEPLOYED_MTA_DETECTED = "No deployed MTA detected - this is initial deployment of MTA with ID \"{0}\"";
public static final String NO_DEPLOYED_MTA_DETECTED_WITH_NAMESPACE = "No deployed MTA detected - this is initial deployment of MTA with ID \"{0}\" and namespace \"{1}\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public static OperationMetadata getMetadata() {
.type(ParameterType.BOOLEAN)
.defaultValue(false)
.build())
.addParameter(ImmutableParameterMetadata.builder()
.id(Variables.API_REQUEST_PATH.getName())
.type(ParameterType.STRING)
.build())

// Special blue green deploy parameters:
.addParameter(ImmutableParameterMetadata.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public static OperationMetadata getMetadata() {
.type(ParameterType.BOOLEAN)
.defaultValue(false)
.build())
.addParameter(ImmutableParameterMetadata.builder()
.id(Variables.API_REQUEST_PATH.getName())
.type(ParameterType.STRING)
.build())

// Special CTS+ parameters:
.addParameter(ImmutableParameterMetadata.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public static OperationMetadata getMetadata() {
.type(ParameterType.BOOLEAN)
.defaultValue(false)
.build())
.addParameter(ImmutableParameterMetadata.builder()
.id(Variables.API_REQUEST_PATH.getName())
.type(ParameterType.STRING)
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import jakarta.inject.Named;
import org.cloudfoundry.multiapps.common.SLException;
import org.cloudfoundry.multiapps.controller.process.Constants;
import org.cloudfoundry.multiapps.controller.process.Messages;
import org.cloudfoundry.multiapps.controller.process.variables.Variables;
import org.cloudfoundry.multiapps.mta.handlers.SchemaVersionDetector;
Expand Down Expand Up @@ -38,6 +39,7 @@ protected StepPhase executeStep(ProcessContext context) {
context.setVariable(Variables.MTA_MAJOR_SCHEMA_VERSION, schemaVersion.getMajor());

getStepLogger().info(Messages.MTA_SCHEMA_VERSION_DETECTED_AS, schemaVersion.getMajor());
printLegacyDeployServiceRouteWarning(context);

return StepPhase.DONE;
}
Expand All @@ -47,4 +49,17 @@ protected String getStepErrorMessage(ProcessContext context) {
return Messages.ERROR_DETECTING_MTA_MAJOR_SCHEMA_VERSION;
}

private void printLegacyDeployServiceRouteWarning(ProcessContext context) {
boolean isUsedRouteDeprecated = false;

if (context.getVariable(Variables.API_REQUEST_PATH) != null) {
isUsedRouteDeprecated = context.getVariable(Variables.API_REQUEST_PATH)
.contains(Constants.DEPRECATED_ROUTE_MARKER);
}

if (isUsedRouteDeprecated) {
getStepLogger().warn(Messages.LEGACY_ROUTE_DEPLOY_SERVICE_DEPRECATED);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public interface Variables {
Variable<String> DEPLOY_URI = ImmutableSimpleVariable.<String> builder()
.name("deployUri")
.build();
Variable<String> API_REQUEST_PATH = ImmutableSimpleVariable.<String> builder()
.name("apiRequestPath")
.build();
Variable<String> CTS_USERNAME = ImmutableSimpleVariable.<String> builder()
.name("userId")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ protected String[] getParametersIds() {
Variables.STOP_ORDER_IS_DEPENDENCY_AWARE.getName(),
Variables.IS_SECURITY_ENABLED.getName(),
Variables.DISPOSABLE_USER_PROVIDED_SERVICE_NAME.getName(),
Variables.IS_DISPOSABLE_USER_PROVIDED_SERVICE_ENABLED.getName()
Variables.IS_DISPOSABLE_USER_PROVIDED_SERVICE_ENABLED.getName(),
Variables.API_REQUEST_PATH.getName()
// @formatter:on
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ protected String[] getParametersIds() {
Variables.SKIP_APP_DIGEST_CALCULATION.getName(),
Variables.IS_SECURITY_ENABLED.getName(),
Variables.DISPOSABLE_USER_PROVIDED_SERVICE_NAME.getName(),
Variables.IS_DISPOSABLE_USER_PROVIDED_SERVICE_ENABLED.getName()
Variables.IS_DISPOSABLE_USER_PROVIDED_SERVICE_ENABLED.getName(),
Variables.API_REQUEST_PATH.getName()
// @formatter:on
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ protected String[] getParametersIds() {
Variables.SKIP_APP_DIGEST_CALCULATION.getName(),
Variables.IS_SECURITY_ENABLED.getName(),
Variables.DISPOSABLE_USER_PROVIDED_SERVICE_NAME.getName(),
Variables.IS_DISPOSABLE_USER_PROVIDED_SERVICE_ENABLED.getName()
Variables.IS_DISPOSABLE_USER_PROVIDED_SERVICE_ENABLED.getName(),
Variables.API_REQUEST_PATH.getName()
// @formatter:on
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.persistence.NoResultException;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.collections4.ListUtils;
import org.cloudfoundry.multiapps.common.ContentException;
import org.cloudfoundry.multiapps.common.NotFoundException;
Expand Down Expand Up @@ -148,13 +149,13 @@ public ResponseEntity<String> getOperationLogContent(String spaceGuid, String op
}

@Override
public ResponseEntity<Operation> startOperation(String spaceGuid, Operation operation) {
public ResponseEntity<Operation> startOperation(String spaceGuid, Operation operation, HttpServletRequest httpServletRequest) {
operationsApiServiceAuditLog.logStartOperation(SecurityContextUtil.getUsername(), spaceGuid, operation);
UserInfo authenticatedUser = getAuthenticatedUser();
String processDefinitionKey = operationsHelper.getProcessDefinitionKey(operation);
Set<ParameterMetadata> predefinedParameters = operationMetadataMapper.getOperationMetadata(operation.getProcessType())
.getParameters();
operation = addServiceParameters(operation, spaceGuid, authenticatedUser.getName(), authenticatedUser.getId());
operation = addServiceParameters(operation, spaceGuid, authenticatedUser.getName(), authenticatedUser.getId(), httpServletRequest);
operation = addParameterValues(operation, predefinedParameters);
ensureRequiredParametersSet(operation, predefinedParameters);
ProcessInstance processInstance = flowableFacade.startProcess(processDefinitionKey, operation.getParameters());
Expand Down Expand Up @@ -246,7 +247,8 @@ private List<String> getAvailableActions(Operation operation) {
throw new IllegalStateException(MessageFormat.format("State \"{0}\" not recognized!", operation.getState()));
}

private Operation addServiceParameters(Operation operation, String spaceGuid, String user, String userGuid) {
private Operation addServiceParameters(Operation operation, String spaceGuid, String user, String userGuid,
HttpServletRequest httpServletRequest) {
Map<String, Object> parameters = new HashMap<>(operation.getParameters());

CloudSpaceClient client = getSpaceClient();
Expand All @@ -265,6 +267,8 @@ private Operation addServiceParameters(Operation operation, String spaceGuid, St
.toString());
parameters.put(Variables.TIMESTAMP.getName(), DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
.format(ZonedDateTime.now()));
parameters.put(Variables.API_REQUEST_PATH.getName(), httpServletRequest.getRequestURL()
.toString());
String namespace = operation.getNamespace();
if (namespace != null) {
parameters.put(Variables.MTA_NAMESPACE.getName(), namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ void testStartOperation() {
Operation operation = createOperation(null, null, parameters);
Mockito.when(operationsHelper.getProcessDefinitionKey(operation))
.thenReturn("deploy");
operationsApiService.startOperation(SPACE_GUID, operation);
HttpServletRequest httpServletRequestMock = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequestMock.getRequestURL())
.thenReturn(new StringBuffer("test/api/path"));
operationsApiService.startOperation(SPACE_GUID, operation, httpServletRequestMock);
Mockito.verify(flowableFacade)
.startProcess(Mockito.any(), Mockito.anyMap());
}
Expand All @@ -210,12 +213,15 @@ void testStartOperationWithInvalidParametersForTheProcess() {
Mockito.when(operationsHelper.getProcessDefinitionKey(operation))
.thenReturn("deploy");

operationsApiService.startOperation(SPACE_GUID, operation);
HttpServletRequest httpServletRequestMock = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequestMock.getRequestURL())
.thenReturn(new StringBuffer("test/api/path"));
operationsApiService.startOperation(SPACE_GUID, operation, httpServletRequestMock);

Mockito.verify(flowableFacade)
.startProcess(ArgumentMatchers.eq("deploy"), ArgumentMatchers.argThat(
map -> map.containsKey(Variables.MTA_ID.getName()) && map.containsKey(Variables.EXT_DESCRIPTOR_FILE_ID.getName())
&& !map.containsKey(Variables.CTS_PROCESS_ID.getName()) && !map.containsKey(Variables.DEPLOY_URI.getName())));
&& !map.containsKey(Variables.CTS_PROCESS_ID.getName()) && !map.containsKey(Variables.CTS_PASSWORD.getName())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why DEPLOY_URI was removed and replaced with CTS_PASSWORD variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed :)

}

@Test
Expand All @@ -225,8 +231,10 @@ void testStartOperationWithValidParametersForTheProcess() {
Operation operation = createOperation(null, null, parameters);
Mockito.when(operationsHelper.getProcessDefinitionKey(operation))
.thenReturn("deploy");

operationsApiService.startOperation(SPACE_GUID, operation);
HttpServletRequest httpServletRequestMock = Mockito.mock(HttpServletRequest.class);
Mockito.when(httpServletRequestMock.getRequestURL())
.thenReturn(new StringBuffer("test/api/path"));
operationsApiService.startOperation(SPACE_GUID, operation, httpServletRequestMock);

Mockito.verify(flowableFacade)
.startProcess(ArgumentMatchers.eq("deploy"), ArgumentMatchers.argThat(
Expand Down
Loading