|
48 | 48 | import org.springframework.cloud.dataflow.registry.service.AppRegistryService; |
49 | 49 | import org.springframework.cloud.dataflow.rest.SkipperStream; |
50 | 50 | import org.springframework.cloud.dataflow.server.controller.NoSuchAppException; |
| 51 | +import org.springframework.cloud.dataflow.server.controller.support.InvalidStreamDefinitionException; |
51 | 52 | import org.springframework.cloud.dataflow.server.repository.NoSuchStreamDefinitionException; |
52 | 53 | import org.springframework.cloud.dataflow.server.repository.StreamDefinitionRepository; |
53 | 54 | import org.springframework.cloud.deployer.spi.app.AppInstanceStatus; |
@@ -98,6 +99,9 @@ public class SkipperStreamDeployer implements StreamDeployer { |
98 | 99 |
|
99 | 100 | private static Log logger = LogFactory.getLog(SkipperStreamDeployer.class); |
100 | 101 |
|
| 102 | + //Assume version suffix added by skipper is 5 chars. |
| 103 | + private static final int MAX_APPNAME_LENGTH = 63-5; |
| 104 | + |
101 | 105 | private final SkipperClient skipperClient; |
102 | 106 |
|
103 | 107 | private final StreamDefinitionRepository streamDefinitionRepository; |
@@ -200,7 +204,7 @@ private boolean streamDefinitionExists(String streamName) { |
200 | 204 | } |
201 | 205 |
|
202 | 206 | public Release deployStream(StreamDeploymentRequest streamDeploymentRequest) { |
203 | | - validateAllAppsRegistered(streamDeploymentRequest); |
| 207 | + validateStreamDeploymentRequest(streamDeploymentRequest); |
204 | 208 | Map<String, String> streamDeployerProperties = streamDeploymentRequest.getStreamDeployerProperties(); |
205 | 209 | String packageVersion = streamDeployerProperties.get(SkipperStream.SKIPPER_PACKAGE_VERSION); |
206 | 210 | Assert.isTrue(StringUtils.hasText(packageVersion), "Package Version must be set"); |
@@ -283,21 +287,32 @@ private String determinePlatformName(final String platformName) { |
283 | 287 | } |
284 | 288 | } |
285 | 289 |
|
286 | | - private void validateAllAppsRegistered(StreamDeploymentRequest streamDeploymentRequest) { |
| 290 | + private void validateStreamDeploymentRequest(StreamDeploymentRequest streamDeploymentRequest) { |
287 | 291 | if (streamDeploymentRequest.getAppDeploymentRequests() == null |
288 | 292 | || streamDeploymentRequest.getAppDeploymentRequests().isEmpty()) { |
289 | 293 | // nothing to validate. |
290 | 294 | return; |
291 | 295 | } |
292 | | - |
| 296 | + String streamName = streamDeploymentRequest.getStreamName(); |
293 | 297 | // throw as at this point we should have definition |
294 | 298 | StreamDefinition streamDefinition = this.streamDefinitionRepository |
295 | | - .findById(streamDeploymentRequest.getStreamName()) |
| 299 | + .findById(streamName) |
296 | 300 | .orElseThrow(() -> new NoSuchStreamDefinitionException(streamDeploymentRequest.getStreamName())); |
297 | 301 |
|
298 | 302 | for (AppDeploymentRequest adr : streamDeploymentRequest.getAppDeploymentRequests()) { |
| 303 | + String registeredAppName = getRegisteredName(streamDefinition, adr.getDefinition().getName()); |
| 304 | + String appName = String.format("%s-%s-v", streamName, registeredAppName); |
| 305 | + if (appName.length() > 40) { |
| 306 | + logger.warn("The stream name plus application name [" + appName + "] is longer than 40 characters." + |
| 307 | + " This can not exceed " + MAX_APPNAME_LENGTH + " in length."); |
| 308 | + } |
| 309 | + if (appName.length() > MAX_APPNAME_LENGTH) { |
| 310 | + throw new InvalidStreamDefinitionException( |
| 311 | + String.format("The runtime application name for the app %s in the stream %s " |
| 312 | + + "should not exceed %s in length. The runtime application name is: %s", registeredAppName, streamName, MAX_APPNAME_LENGTH, appName)); |
| 313 | + } |
299 | 314 | String version = this.appRegistryService.getResourceVersion(adr.getResource()); |
300 | | - validateAppVersionIsRegistered(getRegisteredName(streamDefinition, adr.getDefinition().getName()), adr, version); |
| 315 | + validateAppVersionIsRegistered(registeredAppName, adr, version); |
301 | 316 | } |
302 | 317 | } |
303 | 318 |
|
|
0 commit comments