Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 8c98169

Browse files
David Turanskimarkpollack
authored andcommitted
Enable configuring different platform types without setting profiles
Fixes #3040
1 parent f5b3234 commit 8c98169

File tree

25 files changed

+1277
-304
lines changed

25 files changed

+1277
-304
lines changed

spring-cloud-dataflow-classic-docs/src/test/resources/rest-docs-config.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ spring:
99
collector:
1010
uri: http://localhost:${fakeMetricsCollector.port}
1111
autoconfigure:
12-
exclude: org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeployerAutoConfiguration,org.springframework.cloud.deployer.spi.kubernetes.KubernetesAutoConfiguration,org.springframework.cloud.dataflow.rest.client.config.DataFlowClientAutoConfiguration,org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,org.springframework.cloud.dataflow.shell.autoconfigure.BaseShellAutoConfiguration
12+
exclude: >-
13+
org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeployerAutoConfiguration,
14+
org.springframework.cloud.deployer.spi.kubernetes.KubernetesAutoConfiguration,
15+
org.springframework.cloud.dataflow.rest.client.config.DataFlowClientAutoConfiguration,
16+
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,
17+
org.springframework.cloud.dataflow.shell.autoconfigure.BaseShellAutoConfiguration,
18+
org.springframework.cloud.dataflow.server.config.cloudfoundry.CloudFoundryTaskPlatformAutoConfiguration,
19+
org.springframework.cloud.dataflow.server.config.kubernetes.KubernetesTaskPlatformAutoConfiguration
1320
maven:
1421
remoteRepositories:
1522
springRepo:
16-
url: https://repo.spring.io/libs-snapshot
23+
url: https://repo.spring.io/libs-snapshot
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.core;
18+
19+
import java.util.LinkedHashMap;
20+
import java.util.Map;
21+
22+
/**
23+
* @author David Turanski
24+
**/
25+
public abstract class AbstractPlatformProperties<P> {
26+
private Map<String, P> accounts = new LinkedHashMap<>();
27+
28+
public Map<String, P> getAccounts() {
29+
return accounts;
30+
}
31+
32+
public void setAccounts(Map<String, P> accounts) {
33+
this.accounts = accounts;
34+
}
35+
36+
public P accountProperties(String account) {
37+
P properties = this.getAccounts().get(account);
38+
if (properties == null) {
39+
throw new IllegalArgumentException("Account " + account + " does not exist");
40+
}
41+
return properties;
42+
}
43+
44+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.core;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
/**
26+
* @author David Turanski
27+
**/
28+
public abstract class AbstractTaskPlatformFactory<P extends AbstractPlatformProperties<?>> implements TaskPlatformFactory {
29+
30+
protected Logger logger = LoggerFactory.getLogger(this.getClass());
31+
32+
protected final P platformProperties;
33+
34+
private final String platformType;
35+
36+
protected AbstractTaskPlatformFactory(P platformProperties, String platformType){
37+
this.platformProperties = platformProperties;
38+
this.platformType = platformType;
39+
}
40+
41+
@Override
42+
public TaskPlatform createTaskPlatform() {
43+
return new TaskPlatform(platformType, createLaunchers());
44+
}
45+
46+
protected List<Launcher> createLaunchers() {
47+
List<Launcher> launchers = new ArrayList<>();
48+
49+
for (String account : platformProperties.getAccounts().keySet()) {
50+
try {
51+
launchers.add(createLauncher(account));
52+
}
53+
catch (Exception e) {
54+
logger.error("{} platform account [{}] could not be registered: {}",
55+
platformType, account, e);
56+
throw new IllegalStateException(e.getMessage(), e);
57+
}
58+
}
59+
60+
return launchers;
61+
}
62+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.core;
18+
19+
/**
20+
* @author David Turanski
21+
**/
22+
public interface TaskPlatformFactory {
23+
TaskPlatform createTaskPlatform();
24+
Launcher createLauncher(String account);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.server.config.cloudfoundry;
18+
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
22+
import org.cloudfoundry.client.CloudFoundryClient;
23+
import org.cloudfoundry.reactor.client.ReactorCloudFoundryClient;
24+
25+
/**
26+
* @author David Turanski
27+
**/
28+
public class CloudFoundryPlatformClientProvider {
29+
30+
private final CloudFoundryPlatformProperties platformProperties;
31+
32+
private final CloudFoundryPlatformConnectionContextProvider connectionContextProvider;
33+
34+
private final CloudFoundryPlatformTokenProvider platformTokenProvider;
35+
36+
private final Map<String, CloudFoundryClient> cloudFoundryClients = new HashMap<>();
37+
38+
CloudFoundryPlatformClientProvider(
39+
CloudFoundryPlatformProperties platformProperties,
40+
CloudFoundryPlatformConnectionContextProvider connectionContextProvider,
41+
CloudFoundryPlatformTokenProvider platformTokenProvider) {
42+
this.platformProperties = platformProperties;
43+
this.connectionContextProvider = connectionContextProvider;
44+
this.platformTokenProvider = platformTokenProvider;
45+
}
46+
47+
public CloudFoundryClient cloudFoundryClient(String account){
48+
cloudFoundryClients.putIfAbsent(account, ReactorCloudFoundryClient.builder()
49+
.connectionContext(connectionContextProvider.connectionContext(account))
50+
.tokenProvider(platformTokenProvider.tokenProvider(account))
51+
.build());
52+
return cloudFoundryClients.get(account);
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.server.config.cloudfoundry;
18+
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
22+
import org.cloudfoundry.reactor.ConnectionContext;
23+
import org.cloudfoundry.reactor.DefaultConnectionContext;
24+
25+
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryConnectionProperties;
26+
27+
/**
28+
* @author David Turanski
29+
**/
30+
public class CloudFoundryPlatformConnectionContextProvider {
31+
32+
private Map<String, ConnectionContext> connectionContexts = new HashMap<>();
33+
34+
private final CloudFoundryPlatformProperties platformProperties;
35+
36+
public CloudFoundryPlatformConnectionContextProvider(
37+
CloudFoundryPlatformProperties platformProperties) {
38+
this.platformProperties = platformProperties;
39+
}
40+
41+
public ConnectionContext connectionContext(String account) {
42+
CloudFoundryConnectionProperties connectionProperties =
43+
this.platformProperties.accountProperties(account).getConnection();
44+
this.connectionContexts.putIfAbsent(account, DefaultConnectionContext.builder()
45+
.apiHost(connectionProperties.getUrl().getHost())
46+
.skipSslValidation(connectionProperties.isSkipSslValidation())
47+
.build());
48+
return connectionContexts.get(account);
49+
}
50+
}

spring-cloud-dataflow-platform-cloudfoundry/src/main/java/org/springframework/cloud/dataflow/server/config/cloudfoundry/CloudFoundryPlatformProperties.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2018-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,32 +16,22 @@
1616

1717
package org.springframework.cloud.dataflow.server.config.cloudfoundry;
1818

19-
import java.util.LinkedHashMap;
20-
import java.util.Map;
21-
2219
import org.springframework.boot.context.properties.ConfigurationProperties;
20+
import org.springframework.cloud.dataflow.core.AbstractPlatformProperties;
21+
import org.springframework.cloud.dataflow.server.config.cloudfoundry.CloudFoundryPlatformProperties.CloudFoundryProperties;
2322
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryConnectionProperties;
2423
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeploymentProperties;
2524

2625
/**
2726
* @author Mark Pollack
2827
* @author Ilayaperumal Gopinathan
2928
* @author Donovan Muller
29+
* @author David Turanski
3030
*
3131
* @since 2.0
3232
*/
3333
@ConfigurationProperties("spring.cloud.dataflow.task.platform.cloudfoundry")
34-
public class CloudFoundryPlatformProperties {
35-
36-
private Map<String, CloudFoundryProperties> accounts = new LinkedHashMap<>();
37-
38-
public Map<String, CloudFoundryProperties> getAccounts() {
39-
return accounts;
40-
}
41-
42-
public void setAccounts(Map<String, CloudFoundryProperties> accounts) {
43-
this.accounts = accounts;
44-
}
34+
public class CloudFoundryPlatformProperties extends AbstractPlatformProperties<CloudFoundryProperties> {
4535

4636
public static class CloudFoundryProperties {
4737

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.server.config.cloudfoundry;
18+
19+
import org.cloudfoundry.reactor.TokenProvider;
20+
import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider;
21+
22+
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryConnectionProperties;
23+
24+
/**
25+
* @author David Turanski
26+
**/
27+
public class CloudFoundryPlatformTokenProvider {
28+
29+
private final CloudFoundryPlatformProperties platformProperties;
30+
31+
public CloudFoundryPlatformTokenProvider(
32+
CloudFoundryPlatformProperties platformProperties) {
33+
this.platformProperties = platformProperties;
34+
}
35+
36+
public TokenProvider tokenProvider(String account) {
37+
CloudFoundryConnectionProperties connectionProperties = platformProperties.accountProperties(account).getConnection();
38+
return PasswordGrantTokenProvider.builder()
39+
.username(connectionProperties.getUsername())
40+
.password(connectionProperties.getPassword()).build();
41+
}
42+
}

0 commit comments

Comments
 (0)