Skip to content

Commit ea804d3

Browse files
committed
Added new parameters for namespaces
1 parent 8c9298a commit ea804d3

File tree

43 files changed

+702
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+702
-207
lines changed

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/Messages.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ public final class Messages {
194194
public static final String LIST_OPERATION_ACTIONS_AUDIT_LOG_MESSAGE = "List operation action in space with id: {0}";
195195
public static final String EXECUTE_OPERATION_AUDIT_LOG_MESSAGE = "Execute operation in space with id: {0}";
196196
public static final String GET_OPERATION_LOGS_AUDIT_LOG_MESSAGE = "Get operation logs in space with id: {0}";
197-
public static final String GET_OPERATION_LOG_CONTENT_AUDIT_LOG_MESSAGE = "Get operation log content in space with id: {0}";
197+
public static final String GET_OPERATION_LOG_CONTENT_AUDIT_LOG_MESSAGE = "Get operation log content in space with id: {0}";
198198
public static final String START_OPERATION_AUDIT_LOG_MESSAGE = "Start {0} operation in space with id: {1}";
199199
public static final String GET_INFO_FOR_OPERATION = "Get info for operation in space with id: {0}";
200200

201-
public static final String LIST_MTA_AUDIT_LOG_MESSAGE = "List MTA in space with id: {0}";
201+
public static final String LIST_MTA_AUDIT_LOG_MESSAGE = "List MTA in space with id: {0}";
202202
public static final String GET_MTA_AUDIT_LOG_MESSAGE = "Get MTA in space with id: {0}";
203203

204204
public static final String GET_INFO_FOR_API_AUDIT_LOG_CONFIG = "Get information for api";
@@ -207,7 +207,6 @@ public final class Messages {
207207

208208
public static final String FETCH_TOKEN_AUDIT_LOG_CONFIG = "Access token fetch";
209209

210-
211210
// Audit log configuration
212211
public static final String GET_CSRF_TOKEN_AUDIT_LOG_CONFIG = "CSRF token get ";
213212

@@ -227,10 +226,12 @@ public final class Messages {
227226
public static final String START_OPERATION_AUDIT_LOG_CONFIG = "Operation start";
228227
public static final String GET_OPERATION_INFO_AUDIT_LOG_CONFIG = "Operation info";
229228

230-
public static final String MTA_INFO_AUDIT_LOG_CONFIG= "MTA info";
229+
public static final String MTA_INFO_AUDIT_LOG_CONFIG = "MTA info";
231230
public static final String MTA_LIST_AUDIT_LOG_CONFIG = "MTA list";
232231

233-
public static final String API_INFO_AUDIT_LOG_CONFIG= "Api info";
232+
public static final String API_INFO_AUDIT_LOG_CONFIG = "Api info";
233+
public static final String IGNORING_NAMESPACE_PARAMETERS = "Ignoring parameter \"{0}\" , as the MTA is not deployed with namespace!";
234+
public static final String NAMESPACE_PARSING_ERROR_MESSAGE = "Cannot parse \"{0}\" flag - expected a boolean format.";
234235

235236
private Messages() {
236237
}

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/helpers/MtaDescriptorPropertiesResolver.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ public MtaDescriptorPropertiesResolver(MtaDescriptorPropertiesResolverContext co
4444
}
4545

4646
public List<ParameterValidator> getValidatorsList() {
47-
return List.of(new HostValidator(), new DomainValidator(), new RoutesValidator(context.getNamespace(), context.applyNamespace()),
48-
new IdleRoutesValidator(context.getNamespace(), context.applyNamespace()), new TasksValidator(),
49-
new VisibilityValidator(), new RestartOnEnvChangeValidator());
47+
return List.of(new HostValidator(), new DomainValidator(),
48+
new RoutesValidator(context.getNamespace(),
49+
context.applyNamespaceAppRoutesGlobalLevel(),
50+
context.applyNamespaceAppRoutesProcessVariable()),
51+
new IdleRoutesValidator(context.getNamespace(),
52+
context.applyNamespaceAppRoutesGlobalLevel(),
53+
context.applyNamespaceAppRoutesProcessVariable()),
54+
new TasksValidator(), new VisibilityValidator(), new RestartOnEnvChangeValidator());
5055
}
5156

5257
public DeploymentDescriptor resolve(DeploymentDescriptor descriptor) {
@@ -113,8 +118,12 @@ private void unescapeEscapedReferences(DeploymentDescriptor descriptor) {
113118
}
114119

115120
private DeploymentDescriptor correctEntityNames(DeploymentDescriptor descriptor) {
116-
List<ParameterValidator> correctors = Arrays.asList(new ApplicationNameValidator(context.getNamespace(), context.applyNamespace()),
117-
new ServiceNameValidator(context.getNamespace(), context.applyNamespace()));
121+
List<ParameterValidator> correctors = Arrays.asList(new ApplicationNameValidator(context.getNamespace(),
122+
context.applyNamespaceAppNamesGlobalLevel(),
123+
context.applyNamespaceAppNamesProcessVariable()),
124+
new ServiceNameValidator(context.getNamespace(),
125+
context.applyNamespaceServiceNamesGlobalLevel(),
126+
context.applyNamespaceServiceNamesProcessVariable()));
118127
return context.getHandlerFactory()
119128
.getDescriptorParametersValidator(descriptor, correctors)
120129
.validate();
@@ -128,7 +137,7 @@ private void editRoutesSetTemporaryPlaceholders(DeploymentDescriptor descriptor)
128137

129138
for (Map<String, Object> routeMap : routes) {
130139
Object routeValue = routeMap.get(SupportedParameters.ROUTE);
131-
boolean noHostname = MapUtil.parseBooleanFlag(routeMap, SupportedParameters.NO_HOSTNAME, false);
140+
Boolean noHostname = MapUtil.parseBooleanFlag(routeMap, SupportedParameters.NO_HOSTNAME, false);
132141
String protocol = (String) routeMap.get(SupportedParameters.ROUTE_PROTOCOL);
133142
if (routeValue instanceof String) {
134143
routeMap.put(SupportedParameters.ROUTE, replacePartsWithIdlePlaceholders((String) routeValue, noHostname, protocol));

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/model/MtaDescriptorPropertiesResolverContext.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,20 @@ public interface MtaDescriptorPropertiesResolverContext {
2828
@Nullable
2929
String getNamespace();
3030

31-
boolean applyNamespace();
31+
boolean applyNamespaceAppNamesGlobalLevel();
32+
33+
boolean applyNamespaceServiceNamesGlobalLevel();
34+
35+
boolean applyNamespaceAppRoutesGlobalLevel();
36+
37+
@Nullable
38+
Boolean applyNamespaceAppNamesProcessVariable();
39+
40+
@Nullable
41+
Boolean applyNamespaceServiceNamesProcessVariable();
42+
43+
@Nullable
44+
Boolean applyNamespaceAppRoutesProcessVariable();
3245

3346
boolean shouldReserveTemporaryRoute();
3447
}

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/model/SupportedParameters.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class SupportedParameters {
3333
public static final String APPLY_NAMESPACE = "apply-namespace";
3434
public static final String MTA_VERSION = "mta-version";
3535
public static final String MTA_ID = "mta-id";
36+
public static final String APPLY_NAMESPACE_APPS = "app-names";
37+
public static final String APPLY_NAMESPACE_SERVICES = "service-names";
38+
public static final String APPLY_NAMESPACE_ROUTES = "app-routes";
3639

3740
// Module / module type parameters:
3841
public static final String APP_NAME = "app-name";

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/parser/IdleRouteParametersParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public CloudRoute parseIdleRouteMap(Map<String, Object> routeMap) {
5858
if (routeString == null) {
5959
return null;
6060
}
61-
boolean noHostname = MapUtil.parseBooleanFlag(routeMap, SupportedParameters.NO_HOSTNAME, false);
61+
Boolean noHostname = MapUtil.parseBooleanFlag(routeMap, SupportedParameters.NO_HOSTNAME, false);
6262
String protocol = (String) routeMap.get(SupportedParameters.ROUTE_PROTOCOL);
6363
return new ApplicationURI(routeString, noHostname, protocol).toCloudRoute();
6464
}

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/parser/RouteParametersParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public CloudRoute parseRouteMap(Map<String, Object> routeMap) {
137137
if (routeString == null) {
138138
return null;
139139
}
140-
boolean noHostname = MapUtil.parseBooleanFlag(routeMap, SupportedParameters.NO_HOSTNAME, false);
140+
Boolean noHostname = MapUtil.parseBooleanFlag(routeMap, SupportedParameters.NO_HOSTNAME, false);
141141
String protocol = (String) routeMap.get(SupportedParameters.ROUTE_PROTOCOL);
142142
return new ApplicationURI(routeString, noHostname, protocol).toCloudRoute();
143143
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.cloudfoundry.multiapps.controller.core.util;
2+
3+
import org.cloudfoundry.multiapps.common.util.MapUtil;
4+
import org.cloudfoundry.multiapps.controller.core.Messages;
5+
import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.util.Map;
10+
import java.util.Objects;
11+
12+
import static java.text.MessageFormat.format;
13+
14+
public class NamespaceValidationUtil {
15+
private static final Logger LOGGER = LoggerFactory.getLogger(NamespaceValidationUtil.class);
16+
private String namespace;
17+
private boolean applyNamespaceGlobalLevel;
18+
private Boolean applyNamespaceProcessVariable;
19+
20+
public NamespaceValidationUtil() {
21+
}
22+
23+
public NamespaceValidationUtil(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
24+
this.namespace = namespace;
25+
this.applyNamespaceGlobalLevel = applyNamespaceGlobalLevel;
26+
this.applyNamespaceProcessVariable = applyNamespaceProcessVariable;
27+
}
28+
29+
public String getNamespace() {
30+
return namespace;
31+
}
32+
33+
public boolean shouldApplyNamespaceResultValue(final Map<String, Object> relatedParameters) {
34+
Boolean applyNamespaceModuleLevel = MapUtil.parseBooleanFlag(relatedParameters, SupportedParameters.APPLY_NAMESPACE, null);
35+
boolean applyNamespaceResult = Objects.requireNonNullElse(applyNamespaceProcessVariable,
36+
Objects.requireNonNullElse(applyNamespaceModuleLevel,
37+
applyNamespaceGlobalLevel));
38+
if (namespace == null && applyNamespaceResult) {
39+
LOGGER.warn(format(Messages.IGNORING_NAMESPACE_PARAMETERS, SupportedParameters.NAMESPACE));
40+
}
41+
return applyNamespaceResult;
42+
}
43+
}

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/ApplicationNameValidator.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@
55
import java.util.Set;
66

77
import org.cloudfoundry.multiapps.common.ContentException;
8-
import org.cloudfoundry.multiapps.common.util.MapUtil;
98
import org.cloudfoundry.multiapps.controller.core.Messages;
109
import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
1110
import org.cloudfoundry.multiapps.controller.core.util.NameUtil;
11+
import org.cloudfoundry.multiapps.controller.core.util.NamespaceValidationUtil;
1212
import org.cloudfoundry.multiapps.mta.model.Module;
1313

14-
public class ApplicationNameValidator implements ParameterValidator {
14+
public class ApplicationNameValidator extends NamespaceValidationUtil implements ParameterValidator {
1515

16-
private final String namespace;
17-
private final boolean applyNamespaceGlobal;
18-
19-
public ApplicationNameValidator(String namespace, boolean applyNamespace) {
20-
this.namespace = namespace;
21-
this.applyNamespaceGlobal = applyNamespace;
16+
public ApplicationNameValidator(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
17+
super(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
2218
}
2319

2420
@Override
@@ -47,11 +43,8 @@ public Object attemptToCorrect(Object applicationName, final Map<String, Object>
4743
if (!(applicationName instanceof String)) {
4844
throw new ContentException(Messages.COULD_NOT_CREATE_VALID_APPLICATION_NAME_FROM_0, applicationName);
4945
}
50-
51-
boolean applyNamespaceLocal = MapUtil.parseBooleanFlag(relatedParameters, SupportedParameters.APPLY_NAMESPACE, true);
52-
boolean applyNamespace = applyNamespaceGlobal && applyNamespaceLocal;
53-
54-
return NameUtil.computeValidApplicationName((String) applicationName, namespace, applyNamespace);
46+
boolean applyNamespaceResult = shouldApplyNamespaceResultValue(relatedParameters);
47+
return NameUtil.computeValidApplicationName((String) applicationName, getNamespace(), applyNamespaceResult);
5548
}
5649

5750
@Override

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/HostValidator.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,26 @@
44
import java.util.Map;
55
import java.util.Set;
66

7-
import org.cloudfoundry.multiapps.common.util.MapUtil;
87
import org.cloudfoundry.multiapps.controller.core.Messages;
98
import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
109
import org.cloudfoundry.multiapps.controller.core.util.NameUtil;
1110

1211
public class HostValidator extends RoutePartValidator {
13-
14-
private final String namespace;
15-
private final boolean applyNamespaceGlobal;
16-
1712
public HostValidator() {
18-
this.namespace = null;
19-
this.applyNamespaceGlobal = false;
13+
super(null, false, false);
2014
}
2115

22-
public HostValidator(String namespace, boolean applyNamespaceGlobal) {
23-
this.namespace = namespace;
24-
this.applyNamespaceGlobal = applyNamespaceGlobal;
16+
public HostValidator(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
17+
super(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
2518
}
2619

2720
@Override
2821
public boolean isValid(Object routePart, final Map<String, Object> context) {
2922
if (!super.isValid(routePart, context)) {
3023
return false;
3124
}
32-
if (shouldApplyNamespace(context)) {
33-
return ((String) routePart).startsWith(namespace);
25+
if (shouldApplyNamespace(context) && getNamespace() != null) {
26+
return ((String) routePart).startsWith(getNamespace());
3427
}
3528
return true;
3629
}
@@ -62,12 +55,11 @@ protected String getRoutePartPattern() {
6255

6356
@Override
6457
protected String modifyAndShortenRoutePart(String routePart, Map<String, Object> context) {
65-
return NameUtil.computeNamespacedNameWithLength(routePart, namespace, shouldApplyNamespace(context), getRoutePartMaxLength());
58+
return NameUtil.computeNamespacedNameWithLength(routePart, getNamespace(), shouldApplyNamespace(context), getRoutePartMaxLength());
6659
}
6760

6861
private boolean shouldApplyNamespace(Map<String, Object> context) {
69-
boolean applyNamespaceLocal = MapUtil.parseBooleanFlag(context, SupportedParameters.APPLY_NAMESPACE, true);
70-
return applyNamespaceGlobal && applyNamespaceLocal;
62+
return shouldApplyNamespaceResultValue(context);
7163
}
7264

7365
@Override

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/IdleRouteValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
public class IdleRouteValidator extends RouteValidator {
66

7-
public IdleRouteValidator(String namespace, boolean applyNamespaceGlobal) {
8-
super(namespace, applyNamespaceGlobal);
7+
public IdleRouteValidator(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
8+
super(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
99
}
1010

1111
@Override

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/IdleRoutesValidator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
public class IdleRoutesValidator extends RoutesValidator {
88

9-
public IdleRoutesValidator(String namespace, boolean applyNamespaceGlobal) {
10-
super(namespace, applyNamespaceGlobal);
9+
public IdleRoutesValidator(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
10+
super(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
1111
}
1212

1313
@Override
14-
protected void initRoutesValidators(String namespace, boolean applyNamespaceGlobal) {
15-
ParameterValidator idleRouteValidator = new IdleRouteValidator(namespace, applyNamespaceGlobal);
14+
protected void initRoutesValidators(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
15+
ParameterValidator idleRouteValidator = new IdleRouteValidator(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
1616
this.validators = Map.of(idleRouteValidator.getParameterName(), idleRouteValidator);
1717
}
1818

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/RoutePartValidator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55

66
import org.cloudfoundry.multiapps.common.SLException;
77
import org.cloudfoundry.multiapps.controller.core.util.NameUtil;
8+
import org.cloudfoundry.multiapps.controller.core.util.NamespaceValidationUtil;
89
import org.cloudfoundry.multiapps.mta.model.Module;
910

10-
public abstract class RoutePartValidator implements ParameterValidator {
11+
public abstract class RoutePartValidator extends NamespaceValidationUtil implements ParameterValidator {
12+
protected RoutePartValidator() {
13+
}
14+
15+
protected RoutePartValidator(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
16+
super(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
17+
}
1118

1219
@Override
1320
public String attemptToCorrect(Object routePart, final Map<String, Object> context) {

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/RouteValidator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public class RouteValidator implements ParameterValidator {
1616

1717
private final List<ParameterValidator> validators;
1818

19-
public RouteValidator(String namespace, boolean applyNamespaceGlobal) {
20-
this.validators = List.of(new HostValidator(namespace, applyNamespaceGlobal), new DomainValidator());
19+
public RouteValidator(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
20+
this.validators = List.of(new HostValidator(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable),
21+
new DomainValidator());
2122
}
2223

2324
@Override
@@ -26,7 +27,7 @@ public String attemptToCorrect(Object route, final Map<String, Object> context)
2627
throw new SLException(Messages.COULD_NOT_CREATE_VALID_ROUTE, route);
2728
}
2829
String routeString = (String) route;
29-
boolean noHostname = MapUtil.parseBooleanFlag(context, SupportedParameters.NO_HOSTNAME, false);
30+
Boolean noHostname = MapUtil.parseBooleanFlag(context, SupportedParameters.NO_HOSTNAME, false);
3031
String protocol = (String) context.get(SupportedParameters.ROUTE_PROTOCOL);
3132
ApplicationURI uri = new ApplicationURI(routeString, noHostname, protocol);
3233
try {
@@ -71,7 +72,7 @@ public boolean isValid(Object route, final Map<String, Object> context) {
7172
return false;
7273
}
7374

74-
boolean noHostname = MapUtil.parseBooleanFlag(context, SupportedParameters.NO_HOSTNAME, false);
75+
Boolean noHostname = MapUtil.parseBooleanFlag(context, SupportedParameters.NO_HOSTNAME, false);
7576
String protocol = (String) context.get(SupportedParameters.ROUTE_PROTOCOL);
7677
ApplicationURI uri = new ApplicationURI(routeString, noHostname, protocol);
7778
Map<String, Object> uriParts = uri.getURIParts();

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/validators/parameters/RoutesValidator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public class RoutesValidator implements ParameterValidator {
2020

2121
protected Map<String, ParameterValidator> validators;
2222

23-
public RoutesValidator(String namespace, boolean applyNamespaceGlobal) {
24-
initRoutesValidators(namespace, applyNamespaceGlobal);
23+
public RoutesValidator(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
24+
initRoutesValidators(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
2525
}
2626

27-
protected void initRoutesValidators(String namespace, boolean applyNamespaceGlobal) {
28-
ParameterValidator routeValidator = new RouteValidator(namespace, applyNamespaceGlobal);
27+
protected void initRoutesValidators(String namespace, boolean applyNamespaceGlobalLevel, Boolean applyNamespaceProcessVariable) {
28+
ParameterValidator routeValidator = new RouteValidator(namespace, applyNamespaceGlobalLevel, applyNamespaceProcessVariable);
2929
this.validators = Map.of(routeValidator.getParameterName(), routeValidator);
3030
}
3131

0 commit comments

Comments
 (0)