-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from fabiobrz/add.pgsql-template-prov
[issue 114] - Adding the PostgreSql template provisioner (for legacy …
- Loading branch information
Showing
10 changed files
with
224 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...java/org/jboss/intersmash/tools/application/openshift/DBTemplateOpenShiftApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.jboss.intersmash.tools.application.openshift; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.jboss.intersmash.tools.provision.openshift.template.OpenShiftTemplate; | ||
|
||
/** | ||
* This interface is not supposed to be implemented by user Applications. See the "Mapping of implemented provisioners" | ||
* section of Appsint README.md file for the up-to-date list of supported end users Applications. | ||
*/ | ||
public interface DBTemplateOpenShiftApplication<TT extends OpenShiftTemplate> | ||
extends TemplateApplication<TT> { | ||
|
||
@Override | ||
default Map<String, String> getParameters() { | ||
return Collections.emptyMap(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../jboss/intersmash/tools/application/openshift/PostgreSQLTemplateOpenShiftApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jboss.intersmash.tools.application.openshift; | ||
|
||
import org.jboss.intersmash.tools.application.openshift.template.PostgreSQLTemplate; | ||
|
||
/** | ||
* End user Application interface which presents PostgreSQL template application on OpenShift Container Platform. | ||
* | ||
* See {@link PostgreSQLTemplate} for available templates the | ||
* application can represent. | ||
* | ||
* The application will be deployed by: | ||
* <ul> | ||
* <li>{@link org.jboss.intersmash.tools.provision.openshift.PostgreSQLTemplateOpenShiftProvisioner}</li> | ||
* </ul> | ||
*/ | ||
public interface PostgreSQLTemplateOpenShiftApplication extends DBTemplateOpenShiftApplication<PostgreSQLTemplate> { | ||
|
||
default String getName() { | ||
return "postgresql"; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...in/java/org/jboss/intersmash/tools/application/openshift/template/PostgreSQLTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.jboss.intersmash.tools.application.openshift.template; | ||
|
||
import org.jboss.intersmash.tools.provision.openshift.template.OpenShiftTemplate; | ||
|
||
/** | ||
* OpenShift templates for PostgreSQL. | ||
* | ||
* These are build in {@code openshift} namespace by default. | ||
*/ | ||
public enum PostgreSQLTemplate implements OpenShiftTemplate { | ||
POSTGRESQL_EPHEMERAL("postgresql-ephemeral"), | ||
POSTGRESQL_PERSISTENT("postgresql-persistent"); | ||
|
||
private String name; | ||
|
||
PostgreSQLTemplate(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getLabel() { | ||
return name; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
...rg/jboss/intersmash/tools/provision/openshift/PostgreSQLTemplateOpenShiftProvisioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.jboss.intersmash.tools.provision.openshift; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.jboss.intersmash.tools.application.openshift.PostgreSQLTemplateOpenShiftApplication; | ||
import org.jboss.intersmash.tools.provision.openshift.template.OpenShiftTemplate; | ||
import org.slf4j.event.Level; | ||
|
||
import cz.xtf.core.event.helpers.EventHelper; | ||
import cz.xtf.core.openshift.OpenShiftWaiters; | ||
import cz.xtf.core.openshift.OpenShifts; | ||
import cz.xtf.core.waiting.failfast.FailFastCheck; | ||
import io.fabric8.kubernetes.api.model.KubernetesList; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.openshift.api.model.Template; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Provisions PostgreSql on OpenShift via PostgreSql template available on OpenShift and based on a | ||
* {@link PostgreSQLTemplateOpenShiftApplication} concrete implementation. | ||
* | ||
*/ | ||
@Slf4j | ||
public class PostgreSQLTemplateOpenShiftProvisioner implements OpenShiftProvisioner<PostgreSQLTemplateOpenShiftApplication> { | ||
private FailFastCheck ffCheck = () -> false; | ||
private final PostgreSQLTemplateOpenShiftApplication postgreSQLApplication; | ||
private final OpenShiftTemplate postgreSQLTemplate; | ||
private KubernetesList kubernetesList; | ||
|
||
public PostgreSQLTemplateOpenShiftProvisioner(PostgreSQLTemplateOpenShiftApplication postgreSQLApplication) { | ||
this.postgreSQLApplication = postgreSQLApplication; | ||
this.postgreSQLTemplate = postgreSQLApplication.getTemplate(); | ||
} | ||
|
||
@Override | ||
public PostgreSQLTemplateOpenShiftApplication getApplication() { | ||
return postgreSQLApplication; | ||
} | ||
|
||
@Override | ||
public void deploy() { | ||
ffCheck = FailFastUtils.getFailFastCheck(EventHelper.timeOfLastEventBMOrTestNamespaceOrEpoch(), | ||
postgreSQLApplication.getName()); | ||
|
||
Map<String, String> parameters = new HashMap<>(postgreSQLApplication.getParameters()); | ||
// DATABASE_SERVICE_NAME parameter has to be aligned with the getName() in case that default is not used | ||
if (!postgreSQLApplication.getName().equals("postgresql") || parameters.containsKey("DATABASE_SERVICE_NAME")) { | ||
String dbServiceName = parameters.getOrDefault("DATABASE_SERVICE_NAME", ""); | ||
if (!dbServiceName.equals(postgreSQLApplication.getName())) { | ||
log.warn("DATABASE_SERVICE_NAME has to be aligned with the application name, setting it according to name: {}.", | ||
postgreSQLApplication.getName()); | ||
parameters.put("DATABASE_SERVICE_NAME", postgreSQLApplication.getName()); | ||
} | ||
} | ||
// Get the template from the openshift namespace, recreate it into test namespace and deploy | ||
Template template = OpenShifts.master("openshift") | ||
.getTemplate(postgreSQLApplication.getTemplate().getLabel()); | ||
template.getMetadata().setNamespace(openShift.getNamespace()); | ||
template.getMetadata().setResourceVersion(null); | ||
openShift.createTemplate(template); | ||
kubernetesList = openShift.processAndDeployTemplate(template.getMetadata().getName(), parameters); | ||
OpenShiftWaiters.get(openShift, ffCheck).isDcReady(postgreSQLApplication.getName()).waitFor(); | ||
} | ||
|
||
@Override | ||
public void undeploy() { | ||
openShift.deleteResources(kubernetesList); | ||
openShift.deleteTemplate(postgreSQLApplication.getTemplate().getLabel()); | ||
} | ||
|
||
@Override | ||
public List<Pod> getPods() { | ||
return openShift.getPods(getApplication().getName()); | ||
} | ||
|
||
@Override | ||
public void scale(int replicas, boolean wait) { | ||
openShift.scale(postgreSQLApplication.getName(), replicas); | ||
if (wait) { | ||
OpenShiftWaiters.get(openShift, ffCheck).areExactlyNPodsReady(replicas, "name", postgreSQLTemplate.getLabel()) | ||
.level(Level.DEBUG).waitFor(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getUrl(String routeName, boolean secure) { | ||
throw new UnsupportedOperationException("Route is not created for DB applications."); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...s/intersmash/tools/provision/openshift/PostgreSQLTemplateOpenShiftProvisionerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jboss.intersmash.tools.provision.openshift; | ||
|
||
import org.jboss.intersmash.tools.application.Application; | ||
import org.jboss.intersmash.tools.application.openshift.PostgreSQLTemplateOpenShiftApplication; | ||
import org.jboss.intersmash.tools.provision.ProvisionerFactory; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Provides logic to obtain a {@link PostgreSQLTemplateOpenShiftProvisioner} instance that is initialized with a | ||
* given {@link PostgreSQLTemplateOpenShiftApplication} instance. | ||
*/ | ||
@Slf4j | ||
public class PostgreSQLTemplateOpenShiftProvisionerFactory | ||
implements ProvisionerFactory<PostgreSQLTemplateOpenShiftProvisioner> { | ||
|
||
@Override | ||
public PostgreSQLTemplateOpenShiftProvisioner getProvisioner(Application application) { | ||
if (PostgreSQLTemplateOpenShiftApplication.class.isAssignableFrom(application.getClass())) | ||
return new PostgreSQLTemplateOpenShiftProvisioner((PostgreSQLTemplateOpenShiftApplication) application); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters