Skip to content

Commit f07ea85

Browse files
committed
Implement test scenarios using persistent test scenarioold test provider and change user impl will be removed in following commit
1 parent b994c5c commit f07ea85

11 files changed

Lines changed: 279 additions & 22 deletions

File tree

framework-cloud/framework-cloud-api/src/main/java/org/kie/cloud/api/scenario/WorkbenchKieServerScenario.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ public interface WorkbenchKieServerScenario extends KieDeploymentScenario<Workbe
5050
*/
5151
default Optional<PrometheusDeployment> getPrometheusDeployment() {
5252
return Optional.empty();
53-
};
53+
}
54+
55+
void changeUsernameAndPassword(String username, String password);
5456
}

framework-cloud/framework-cloud-common/src/main/java/org/kie/cloud/common/provider/KieServerClientProvider.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ public static KieServicesClient getKieServerClient(KieServerDeployment kieServer
6666
kieServerDeployment.getUrl().toString() + "/services/rest/server", kieServerDeployment.getUsername(),
6767
kieServerDeployment.getPassword(), clientTimeout);
6868
configuration.addExtraClasses(extraClasses);
69-
KieServicesClient kieServerClient = KieServicesFactory.newKieServicesClient(configuration);
70-
return kieServerClient;
69+
return KieServicesFactory.newKieServicesClient(configuration);
70+
}
71+
72+
public static KieServicesClient getKieServerClient(String url, String username, String password) {
73+
KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(
74+
url + "/services/rest/server", username, password, KIE_SERVER_TIMEOUT);
75+
return KieServicesFactory.newKieServicesClient(configuration);
7176
}
7277

7378
public static KieServicesClient getKieServerJmsClient(URL amqHost) {
@@ -139,8 +144,7 @@ public static KieServicesClient getSmartRouterClient(SmartRouterDeployment smart
139144
KieServerConstants.CAPABILITY_CASE,
140145
KieServerConstants.CAPABILITY_DMN);
141146
configuration.setCapabilities(capabilities);
142-
KieServicesClient kieServerClient = KieServicesFactory.newKieServicesClient(configuration);
143-
return kieServerClient;
147+
return KieServicesFactory.newKieServicesClient(configuration);
144148
}
145149

146150
public static ProcessServicesClient getProcessClient(KieServerDeployment kieServerDeployment) {

framework-cloud/framework-cloud-common/src/main/java/org/kie/cloud/common/provider/KieServerControllerClientProvider.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@
2929
public class KieServerControllerClientProvider {
3030

3131
public static KieServerControllerClient getKieServerControllerClient(WorkbenchDeployment workbenchDeployment) {
32-
KieServerControllerClient kieServerControllerClient = KieServerControllerClientFactory.newRestClient(workbenchDeployment.getUrl().toString() + "/rest/controller",
32+
return KieServerControllerClientFactory.newRestClient(workbenchDeployment.getUrl().toString() + "/rest/controller",
3333
workbenchDeployment.getUsername(), workbenchDeployment.getPassword());
34-
return kieServerControllerClient;
34+
}
35+
36+
public static KieServerControllerClient getKieServerControllerClient(String url, String username, String password) {
37+
return KieServerControllerClientFactory.newRestClient(url + "/rest/controller", username, password);
3538
}
3639

3740
public static KieServerControllerClient getKieServerControllerClient(ControllerDeployment controllerDeployment) {
38-
KieServerControllerClient kieServerControllerClient = KieServerControllerClientFactory.newRestClient(controllerDeployment.getUrl().toString() + "/rest/controller",
41+
return KieServerControllerClientFactory.newRestClient(controllerDeployment.getUrl().toString() + "/rest/controller",
3942
controllerDeployment.getUsername(), controllerDeployment.getPassword());
40-
return kieServerControllerClient;
4143
}
4244

4345
/**

framework-cloud/framework-openshift-apb/src/main/java/org/kie/cloud/openshift/scenario/WorkbenchKieServerPersistentScenarioApb.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,9 @@ public List<SmartRouterDeployment> getSmartRouterDeployments() {
182182
public List<ControllerDeployment> getControllerDeployments() {
183183
return Collections.emptyList();
184184
}
185+
186+
@Override
187+
public void changeUsernameAndPassword(String username, String password) {
188+
throw new UnsupportedOperationException("Not supported.");
189+
}
185190
}

framework-cloud/framework-openshift-apb/src/main/java/org/kie/cloud/openshift/scenario/WorkbenchKieServerScenarioApb.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,9 @@ public List<ControllerDeployment> getControllerDeployments() {
173173
public Optional<PrometheusDeployment> getPrometheusDeployment() {
174174
return Optional.ofNullable(prometheusDeployment);
175175
}
176+
177+
@Override
178+
public void changeUsernameAndPassword(String username, String password) {
179+
throw new UnsupportedOperationException("Not supported.");
180+
}
176181
}

framework-cloud/framework-openshift-operator/src/main/java/org/kie/cloud/openshift/operator/scenario/WorkbenchKieServerPersistentScenarioImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,15 @@ public List<ControllerDeployment> getControllerDeployments() {
169169
public SsoDeployment getSsoDeployment() {
170170
return ssoDeployment;
171171
}
172+
173+
@Override
174+
public void changeUsernameAndPassword(final String username, final String password) {
175+
if(getDeployments().stream().allMatch(Deployment::isReady)) {
176+
kieApp.getSpec().getCommonConfig().setAdminUser(username);
177+
kieApp.getSpec().getCommonConfig().setAdminPassword(password);
178+
deployCustomResource();
179+
} else{
180+
throw new RuntimeException("Application is not ready for Username and password change. Please check first that application is ready.");
181+
}
182+
}
172183
}

framework-cloud/framework-openshift-operator/src/main/java/org/kie/cloud/openshift/operator/scenario/WorkbenchKieServerScenarioImpl.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ public class WorkbenchKieServerScenarioImpl extends OpenShiftOperatorScenario<Wo
4949

5050
private WorkbenchDeploymentImpl workbenchDeployment;
5151
private KieServerDeploymentImpl kieServerDeployment;
52-
private boolean deployPrometheus;
52+
private final boolean deployPrometheus;
5353
private PrometheusDeployment prometheusDeployment;
5454

5555
private static final Logger logger = LoggerFactory.getLogger(WorkbenchKieServerScenarioImpl.class);
5656

57-
public WorkbenchKieServerScenarioImpl(KieApp kieApp, boolean deployPrometheus) {
57+
public WorkbenchKieServerScenarioImpl(final KieApp kieApp, final boolean deployPrometheus) {
5858
super(kieApp);
5959
this.deployPrometheus = deployPrometheus;
6060
}
6161

6262
@Override
6363
protected void deployCustomResource() {
6464
// deploy application
65-
getKieAppClient().create(kieApp);
65+
getKieAppClient().createOrReplace(kieApp);
6666
// Wait until the operator reconciliate the KieApp and add there missing informations
6767
new SupplierWaiter<KieApp>(() -> getKieAppClient().withName(OpenShiftConstants.getKieApplicationName()).get(), kieApp -> kieApp.getStatus() != null).reason("Waiting for reconciliation to initialize all fields.").timeout(TimeUnit.MINUTES,1).waitFor();
6868

@@ -82,7 +82,7 @@ protected void deployCustomResource() {
8282
try {
8383
new SimpleWaiter(() -> workbenchDeployment.isReady()).reason("Waiting for Workbench service to be created.").timeout(TimeUnit.MINUTES, 1).waitFor();
8484
new SimpleWaiter(() -> kieServerDeployment.isReady()).reason("Waiting for Kie server service to be created.").timeout(TimeUnit.MINUTES, 1).waitFor();
85-
} catch (WaiterException e) {
85+
} catch (final WaiterException e) {
8686
throw new RuntimeException("Timeout while deploying application.", e);
8787
}
8888

@@ -119,13 +119,13 @@ public KieServerDeployment getKieServerDeployment() {
119119

120120
@Override
121121
public List<Deployment> getDeployments() {
122-
List<Deployment> deployments = new ArrayList<Deployment>(Arrays.asList(workbenchDeployment, kieServerDeployment));
122+
final List<Deployment> deployments = new ArrayList<Deployment>(Arrays.asList(workbenchDeployment, kieServerDeployment));
123123
deployments.removeAll(Collections.singleton(null));
124124
return deployments;
125125
}
126126

127-
private void storeProjectInfoToPersistentVolume(Deployment deployment, String persistentVolumeMountPath) {
128-
String storeCommand = "echo \"Project " + projectName + ", time " + Instant.now() + "\" > " + persistentVolumeMountPath + "/info.txt";
127+
private void storeProjectInfoToPersistentVolume(final Deployment deployment, final String persistentVolumeMountPath) {
128+
final String storeCommand = "echo \"Project " + projectName + ", time " + Instant.now() + "\" > " + persistentVolumeMountPath + "/info.txt";
129129
workbenchDeployment.getInstances().get(0).runCommand("/bin/bash", "-c", storeCommand);
130130
}
131131

@@ -153,4 +153,15 @@ public List<ControllerDeployment> getControllerDeployments() {
153153
public Optional<PrometheusDeployment> getPrometheusDeployment() {
154154
return Optional.ofNullable(prometheusDeployment);
155155
}
156+
157+
@Override
158+
public void changeUsernameAndPassword(final String username, final String password) {
159+
if(getDeployments().stream().allMatch(Deployment::isReady)) {
160+
kieApp.getSpec().getCommonConfig().setAdminUser(username);
161+
kieApp.getSpec().getCommonConfig().setAdminPassword(password);
162+
deployCustomResource();
163+
} else{
164+
throw new RuntimeException("Application is not ready for Username and password change. Please check first that application is ready.");
165+
}
166+
}
156167
}

framework-cloud/framework-openshift-templates/src/main/java/org/kie/cloud/openshift/scenario/WorkbenchKieServerPersistentScenarioImpl.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.Collections;
22+
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Map;
25+
import java.util.concurrent.TimeUnit;
2426

27+
import cz.xtf.core.waiting.SimpleWaiter;
2528
import org.kie.cloud.api.deployment.ControllerDeployment;
2629
import org.kie.cloud.api.deployment.Deployment;
2730
import org.kie.cloud.api.deployment.KieServerDeployment;
@@ -32,6 +35,7 @@
3235
import org.kie.cloud.api.scenario.WorkbenchKieServerPersistentScenario;
3336
import org.kie.cloud.api.scenario.WorkbenchKieServerScenario;
3437
import org.kie.cloud.common.provider.KieServerControllerClientProvider;
38+
import org.kie.cloud.openshift.constants.OpenShiftConstants;
3539
import org.kie.cloud.openshift.constants.OpenShiftTemplateConstants;
3640
import org.kie.cloud.openshift.constants.ProjectSpecificPropertyNames;
3741
import org.kie.cloud.openshift.deployment.KieServerDeploymentImpl;
@@ -147,4 +151,42 @@ public List<ControllerDeployment> getControllerDeployments() {
147151
public SsoDeployment getSsoDeployment() {
148152
return ssoDeployment;
149153
}
154+
155+
@Override
156+
public void changeUsernameAndPassword(String username, String password) {
157+
if(getDeployments().stream().allMatch(Deployment::isReady)) {
158+
deploySecretAppUser(username,password);
159+
logger.info("Restart the environment to update Workbench deployment.");
160+
getDeployments().parallelStream().forEach(this::scaleToZeroAndBackToReplicas); // if parallel stream make mess because of common fork-join pool use normal stream and adjust scaling (scale all deployments to zero at the same time)
161+
} else{
162+
throw new RuntimeException("Application is not ready for Username and password change. Please check first that application is ready.");
163+
}
164+
165+
}
166+
167+
private void deploySecretAppUser(String user, String password) {
168+
logger.info("Delete old secret '{}'", DeploymentConstants.getAppCredentialsSecretName());
169+
project.getOpenShift().secrets().withName(DeploymentConstants.getAppCredentialsSecretName()).delete();
170+
new SimpleWaiter(() -> project.getOpenShift().getSecret(DeploymentConstants.getAppCredentialsSecretName()) == null).timeout(TimeUnit.MINUTES, 2)
171+
.reason("Waiting for old secret to be deleted.")
172+
.waitFor();
173+
174+
logger.info("Creating user secret '{}'", DeploymentConstants.getAppCredentialsSecretName());
175+
Map<String, String> data = new HashMap<>();
176+
data.put(OpenShiftConstants.KIE_ADMIN_USER, user);
177+
data.put(OpenShiftConstants.KIE_ADMIN_PWD, password);
178+
179+
project.createSecret(DeploymentConstants.getAppCredentialsSecretName(), data);
180+
new SimpleWaiter(() -> project.getOpenShift().getSecret(DeploymentConstants.getAppCredentialsSecretName()) != null).timeout(TimeUnit.MINUTES, 2)
181+
.reason("Waiting for new secret to be created.")
182+
.waitFor();
183+
}
184+
185+
private void scaleToZeroAndBackToReplicas(Deployment deployment) {
186+
int replicas = deployment.getInstances().size();
187+
deployment.scale(0);
188+
deployment.waitForScale();
189+
deployment.scale(replicas);
190+
deployment.waitForScale();
191+
}
150192
}

framework-cloud/framework-openshift-templates/src/main/java/org/kie/cloud/openshift/scenario/WorkbenchKieServerScenarioImpl.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.Collections;
22+
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Map;
2425
import java.util.Optional;
26+
import java.util.concurrent.TimeUnit;
2527

28+
import cz.xtf.core.waiting.SimpleWaiter;
2629
import org.kie.cloud.api.deployment.ControllerDeployment;
2730
import org.kie.cloud.api.deployment.Deployment;
2831
import org.kie.cloud.api.deployment.KieServerDeployment;
@@ -32,6 +35,7 @@
3235
import org.kie.cloud.api.deployment.constants.DeploymentConstants;
3336
import org.kie.cloud.api.scenario.WorkbenchKieServerScenario;
3437
import org.kie.cloud.common.provider.KieServerControllerClientProvider;
38+
import org.kie.cloud.openshift.constants.OpenShiftConstants;
3539
import org.kie.cloud.openshift.constants.OpenShiftTemplateConstants;
3640
import org.kie.cloud.openshift.deployment.KieServerDeploymentImpl;
3741
import org.kie.cloud.openshift.deployment.WorkbenchDeploymentImpl;
@@ -133,4 +137,42 @@ public List<ControllerDeployment> getControllerDeployments() {
133137
public Optional<PrometheusDeployment> getPrometheusDeployment() {
134138
return Optional.ofNullable(prometheusDeployment);
135139
}
140+
141+
@Override
142+
public void changeUsernameAndPassword(String username, String password) {
143+
if(getDeployments().stream().allMatch(Deployment::isReady)) {
144+
deploySecretAppUser(username,password);
145+
logger.info("Restart the environment to update Workbench deployment.");
146+
getDeployments().parallelStream().forEach(this::scaleToZeroAndBackToReplicas); // if parallel stream make mess because of common fork-join pool use normal stream and adjust scaling (scale all deployments to zero at the same time)
147+
} else{
148+
throw new RuntimeException("Application is not ready for Username and password change. Please check first that application is ready.");
149+
}
150+
151+
}
152+
153+
private void deploySecretAppUser(String user, String password) {
154+
logger.info("Delete old secret '{}'", DeploymentConstants.getAppCredentialsSecretName());
155+
project.getOpenShift().secrets().withName(DeploymentConstants.getAppCredentialsSecretName()).delete();
156+
new SimpleWaiter(() -> project.getOpenShift().getSecret(DeploymentConstants.getAppCredentialsSecretName()) == null).timeout(TimeUnit.MINUTES, 2)
157+
.reason("Waiting for old secret to be deleted.")
158+
.waitFor();
159+
160+
logger.info("Creating user secret '{}'", DeploymentConstants.getAppCredentialsSecretName());
161+
Map<String, String> data = new HashMap<>();
162+
data.put(OpenShiftConstants.KIE_ADMIN_USER, user);
163+
data.put(OpenShiftConstants.KIE_ADMIN_PWD, password);
164+
165+
project.createSecret(DeploymentConstants.getAppCredentialsSecretName(), data);
166+
new SimpleWaiter(() -> project.getOpenShift().getSecret(DeploymentConstants.getAppCredentialsSecretName()) != null).timeout(TimeUnit.MINUTES, 2)
167+
.reason("Waiting for new secret to be created.")
168+
.waitFor();
169+
}
170+
171+
private void scaleToZeroAndBackToReplicas(Deployment deployment) {
172+
int replicas = deployment.getInstances().size();
173+
deployment.scale(0);
174+
deployment.waitForScale();
175+
deployment.scale(replicas);
176+
deployment.waitForScale();
177+
}
136178
}

test-cloud/test-cloud-remote/src/test/java/org/kie/cloud/integrationtests/persistence/WorkbenchAdminUserPersistenceIntegrationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
import org.junit.BeforeClass;
1919
import org.junit.Test;
2020
import org.kie.cloud.api.scenario.WorkbenchKieServerScenario;
21-
import org.kie.cloud.integrationtests.testproviders.HttpsWorkbenchTestProvider;
21+
import org.kie.cloud.integrationtests.testproviders.PersistenceTestProvider;
2222
import org.kie.cloud.tests.common.AbstractCloudIntegrationTest;
2323
import org.kie.cloud.tests.common.ScenarioDeployer;
2424

2525
public class WorkbenchAdminUserPersistenceIntegrationTest extends AbstractCloudIntegrationTest {
2626

2727
private static WorkbenchKieServerScenario deploymentScenario;
2828

29-
private static HttpsWorkbenchTestProvider httpsWorkbenchTestProvider;
29+
private static PersistenceTestProvider persistenceTestProvider;
3030

3131
@BeforeClass
3232
public static void initializeDeployment() {
@@ -37,7 +37,7 @@ public static void initializeDeployment() {
3737
ScenarioDeployer.deployScenario(deploymentScenario);
3838

3939
// Setup test providers
40-
httpsWorkbenchTestProvider = HttpsWorkbenchTestProvider.create();
40+
persistenceTestProvider = PersistenceTestProvider.create();
4141
}
4242

4343
@AfterClass
@@ -47,11 +47,11 @@ public static void cleanEnvironment() {
4747

4848
@Test
4949
public void testAdminUserPasswordChange() {
50-
httpsWorkbenchTestProvider.testAdminUserPasswordChange(deploymentScenario.getWorkbenchDeployment());
50+
persistenceTestProvider.testAdminUserPasswordChange(deploymentScenario);
5151
}
5252

5353
@Test
5454
public void testAdminUserNameAndPasswordChange() {
55-
httpsWorkbenchTestProvider.testAdminUserNameAndPasswordChange(deploymentScenario.getWorkbenchDeployment());
55+
persistenceTestProvider.testAdminUserNameAndPasswordChange(deploymentScenario);
5656
}
5757
}

0 commit comments

Comments
 (0)