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

Commit 725e54d

Browse files
committed
Adding CloudFoundry support.
For adding PaaS support, a CloudFoundryLocation is added which is based on PaasLocation. This new location contains a API client for CloudFoundry Paas Services, (CloudFoundry Java Client), that allows to use the services of this provider. Extracting ssh behaviour from SoftwareProcessImpl: provisioning flags For adding paas support, SoftwareProcess entities should to be agnostics in order to allows to be deployed on SSH and PaaS locations. So, the machine behaviour and management should be decoupled of the entities and it should be moved to an isolate class. SoftwareProcessImpl contained a pair of method for obtaining the needed flags to create and configure a VM. However as it was mentioned previously, this entity shouldn't contain any ssh (machine) behaviour. Then, this code is moved to an external class, MachineProvisioningLocationFlagsSupplier that is managed in SoftwareProcessImpl as a LocationFlagSupplier interface. Moreover, an equivalent class is added to represent this behaviour (obtain flags location) for PaaS. SoftwareProcessImpl will select a behaviour for obtaining the flags depending on the selected location for deploying the entity. Adding BehaviourFactory for selecting PaaS or SSH behaviour in run time. Following the previous commits, SoftwareProcessImpl entities should select PaaS or SSH behaviour in run time, depending on the target location. An entity know the target location when it is started (calling to start effector), then just when this effector is called the entity will able to know the selected location, so in this moment the entity will able to find the required behaviour, SSH or PaaS. The whole behaviour is composed by several classes, then SoftwareProcessImpl uses a factory (BehaviourFactory) which is selected according to the target location. This factory allows to select in run time all behaviour focus in a location. Adding PaaS support to TomcatServer entity. The drivers for CloudFoundry are added to SoftwareProcess entity and JavaWebAppSoftwareProcess implementation entity. The final PaaS support is added to TomcatServer entity using a new driver which is focused on CloudFoundryPaaSLocation. A new hierarchy of drivers is added to Brooklyn, these new drivers is oriented to PaaS but they follow the hierarchy defined for SSH. For example, AbstractSoftwareProcessDriver, AbstractSoftwareProcessSshDriver allow to SoftwareProcess entities use drivers for location based on machines. Then, to enable the PaaS support for SoftwareProcess entities a set of drivers is added such as AbstractSoftwareProcessCloudFoundryDriver and AbstractApplicationCloudFoundryDriver. Fixing dependency convergence
1 parent d3cefa3 commit 725e54d

File tree

43 files changed

+2459
-352
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

+2459
-352
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.brooklyn.location.paas;
20+
21+
22+
import org.apache.brooklyn.config.ConfigKey;
23+
import org.apache.brooklyn.core.config.ConfigKeys;
24+
import org.apache.brooklyn.util.core.flags.SetFromFlag;
25+
26+
/**
27+
* It contains the parameters needed to configure an PaasLocation. For example, the ConfigKey
28+
* {@link #REQUIRED_MEMORY} allows to specify a initial memory amount used in a location.
29+
*/
30+
public interface PaasLocationConfig {
31+
32+
@SetFromFlag("profile.instances")
33+
ConfigKey<Integer> REQUIRED_INSTANCES = ConfigKeys.newIntegerConfigKey(
34+
"instances", "Required instances to deploy the application", 1);
35+
36+
@SetFromFlag("profile.instances")
37+
ConfigKey<Integer> REQUIRED_MEMORY = ConfigKeys.newIntegerConfigKey(
38+
"memory", "Required memory to deploy the application (MB)", 512);
39+
40+
@SetFromFlag("profile.instances")
41+
ConfigKey<Integer> REQUIRED_DISK = ConfigKeys.newIntegerConfigKey(
42+
"disk", "Required disk to deploy the application (MB)", 1024);
43+
44+
45+
}

locations/cloudfoundry/pom.xml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
<artifactId>brooklyn-locations-cloudfoundry</artifactId>
25+
<packaging>jar</packaging>
26+
<name>Brooklyn CloudFoundry Location Targets</name>
27+
<description>
28+
Support for CloudFoundry PaaS Level services
29+
</description>
30+
31+
<parent>
32+
<artifactId>brooklyn-parent</artifactId>
33+
<groupId>org.apache.brooklyn</groupId>
34+
<version>0.9.0-SNAPSHOT</version>
35+
<relativePath>../../parent/pom.xml</relativePath>
36+
</parent>
37+
38+
<properties>
39+
<cloudfoundry.client.version>1.1.2</cloudfoundry.client.version>
40+
<springframework-webmvn.version>4.0.5.RELEASE</springframework-webmvn.version>
41+
<springframework-security.version>2.0.4.RELEASE</springframework-security.version>
42+
</properties>
43+
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.apache.brooklyn</groupId>
47+
<artifactId>brooklyn-core</artifactId>
48+
<version>${project.version}</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.apache.brooklyn</groupId>
52+
<artifactId>brooklyn-api</artifactId>
53+
<version>${project.version}</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.slf4j</groupId>
57+
<artifactId>slf4j-api</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>com.google.guava</groupId>
61+
<artifactId>guava</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.fasterxml.jackson.core</groupId>
65+
<artifactId>jackson-core</artifactId>
66+
<version>${fasterxml.jackson.version}</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.cloudfoundry</groupId>
70+
<artifactId>cloudfoundry-client-lib</artifactId>
71+
<version>${cloudfoundry.client.version}</version>
72+
<exclusions>
73+
<exclusion>
74+
<groupId>com.fasterxml.jackson.core</groupId>
75+
<artifactId>jackson-core</artifactId>
76+
</exclusion>
77+
<exclusion>
78+
<groupId>org.springframework.security.oauth</groupId>
79+
<artifactId>spring-security-oauth2</artifactId>
80+
</exclusion>
81+
</exclusions>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.springframework</groupId>
85+
<artifactId>spring-webmvc</artifactId>
86+
<version>${springframework-webmvn.version}</version>
87+
<exclusions>
88+
<exclusion>
89+
<groupId>commons-logging</groupId>
90+
<artifactId>commons-logging</artifactId>
91+
</exclusion>
92+
</exclusions>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.springframework.security.oauth</groupId>
96+
<artifactId>spring-security-oauth2</artifactId>
97+
<version>${springframework-security.version}</version>
98+
<exclusions>
99+
<exclusion>
100+
<groupId>org.springframework</groupId>
101+
<artifactId>spring-context</artifactId>
102+
</exclusion>
103+
<exclusion>
104+
<groupId>org.springframework</groupId>
105+
<artifactId>spring-aop</artifactId>
106+
</exclusion>
107+
<exclusion>
108+
<groupId>org.springframework</groupId>
109+
<artifactId>spring-expression</artifactId>
110+
</exclusion>
111+
<exclusion>
112+
<groupId>org.springframework</groupId>
113+
<artifactId>spring-webmvc</artifactId>
114+
</exclusion>
115+
<exclusion>
116+
<groupId>org.springframework</groupId>
117+
<artifactId>spring-beans</artifactId>
118+
</exclusion>
119+
<exclusion>
120+
<groupId>org.springframework</groupId>
121+
<artifactId>spring-web</artifactId>
122+
</exclusion>
123+
<exclusion>
124+
<groupId>org.springframework</groupId>
125+
<artifactId>spring-core</artifactId>
126+
</exclusion>
127+
<exclusion>
128+
<groupId>commons-codec</groupId>
129+
<artifactId>commons-codec</artifactId>
130+
</exclusion>
131+
</exclusions>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.testng</groupId>
135+
<artifactId>testng</artifactId>
136+
<scope>test</scope>
137+
</dependency>
138+
<dependency>
139+
<!-- includes testng and useful logging for tests -->
140+
<groupId>org.apache.brooklyn</groupId>
141+
<artifactId>brooklyn-test-support</artifactId>
142+
<version>${brooklyn.version}</version>
143+
<scope>test</scope>
144+
</dependency>
145+
<dependency>
146+
<groupId>org.apache.brooklyn</groupId>
147+
<artifactId>brooklyn-core</artifactId>
148+
<version>${brooklyn.version}</version>
149+
<classifier>tests</classifier>
150+
<scope>test</scope>
151+
</dependency>
152+
</dependencies>
153+
</project>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.brooklyn.location.cloudfoundry;
20+
21+
22+
import org.apache.brooklyn.config.ConfigKey;
23+
import org.apache.brooklyn.core.config.ConfigKeys;
24+
import org.apache.brooklyn.core.location.AbstractLocation;
25+
import org.apache.brooklyn.location.paas.PaasLocation;
26+
import org.apache.brooklyn.location.paas.PaasLocationConfig;
27+
import org.cloudfoundry.client.lib.CloudCredentials;
28+
import org.cloudfoundry.client.lib.CloudFoundryClient;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
32+
import java.net.MalformedURLException;
33+
import java.net.URI;
34+
import java.net.URL;
35+
36+
public class CloudFoundryPaasLocation extends AbstractLocation
37+
implements PaasLocation, PaasLocationConfig {
38+
39+
public static final Logger LOG = LoggerFactory.getLogger(CloudFoundryPaasLocation.class);
40+
41+
public static ConfigKey<String> CF_USER = ConfigKeys.newStringConfigKey("user");
42+
public static ConfigKey<String> CF_PASSWORD = ConfigKeys.newStringConfigKey("password");
43+
public static ConfigKey<String> CF_ORG = ConfigKeys.newStringConfigKey("org");
44+
public static ConfigKey<String> CF_ENDPOINT = ConfigKeys.newStringConfigKey("endpoint");
45+
public static ConfigKey<String> CF_SPACE = ConfigKeys.newStringConfigKey("space");
46+
47+
CloudFoundryClient client;
48+
49+
public CloudFoundryPaasLocation() {
50+
super();
51+
}
52+
53+
@Override
54+
public void init() {
55+
super.init();
56+
}
57+
58+
public void setUpClient() {
59+
if (client == null) {
60+
CloudCredentials credentials =
61+
new CloudCredentials(getConfig(CF_USER), getConfig(CF_PASSWORD));
62+
client = new CloudFoundryClient(credentials,
63+
getTargetURL(getConfig(CF_ENDPOINT)),
64+
getConfig(CF_ORG), getConfig(CF_SPACE), true);
65+
client.login();
66+
}
67+
}
68+
69+
@Override
70+
public String getPaasProviderName() {
71+
return "CloudFoundry";
72+
}
73+
74+
private static URL getTargetURL(String target) {
75+
try {
76+
return URI.create(target).toURL();
77+
} catch (MalformedURLException e) {
78+
throw new RuntimeException("The target URL is not valid: " + e.getMessage());
79+
}
80+
}
81+
82+
public CloudFoundryClient getCloudFoundryClient() {
83+
return client;
84+
}
85+
86+
87+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.brooklyn.location.cloudfoundry;
20+
21+
22+
import org.apache.brooklyn.api.location.Location;
23+
import org.apache.brooklyn.api.location.LocationRegistry;
24+
import org.apache.brooklyn.api.location.LocationResolver;
25+
import org.apache.brooklyn.api.location.LocationSpec;
26+
import org.apache.brooklyn.api.mgmt.ManagementContext;
27+
import org.apache.brooklyn.core.location.BasicLocationRegistry;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
import java.util.Map;
32+
33+
import static com.google.common.base.Preconditions.checkNotNull;
34+
35+
public class CloudFoundryPaasLocationResolver implements LocationResolver {
36+
37+
public static final Logger log = LoggerFactory
38+
.getLogger(CloudFoundryPaasLocationResolver.class);
39+
40+
public static final String CLOUD_FOUNDRY = "cloudfoundry";
41+
42+
private ManagementContext managementContext;
43+
44+
@Override
45+
public void init(ManagementContext managementContext) {
46+
this.managementContext = checkNotNull(managementContext, "managementContext");
47+
}
48+
49+
@Override
50+
public String getPrefix() {
51+
return CLOUD_FOUNDRY;
52+
}
53+
54+
@Override
55+
public boolean accepts(String spec, LocationRegistry registry) {
56+
return BasicLocationRegistry.isResolverPrefixForSpec(this, spec, true);
57+
}
58+
59+
@Override
60+
@SuppressWarnings("unchecked")
61+
public Location newLocationFromString(Map locationFlags,
62+
String spec,
63+
LocationRegistry registry) {
64+
return managementContext.getLocationManager().createLocation(
65+
LocationSpec.create(locationFlags, CloudFoundryPaasLocation.class));
66+
}
67+
68+
69+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
org.apache.brooklyn.location.cloudfoundry.CloudFoundryPaasLocationResolver

0 commit comments

Comments
 (0)