Skip to content

Commit

Permalink
[JBPM-8732] Simplify HealthChecks (#1899)
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
  • Loading branch information
ruromero authored and MarianMacik committed Aug 26, 2019
1 parent 1753048 commit 4068000
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 104 deletions.
2 changes: 1 addition & 1 deletion process-migration-service/pom.xml
Expand Up @@ -46,7 +46,7 @@

<!-- PIM service configuration -->
<pim.server.http.rest>http://${container.hostname}:8180/rest</pim.server.http.rest>
<pim.server.http.health>${pim.server.http.rest}/health/readiness</pim.server.http.health>
<pim.server.http.health>${pim.server.http.rest}/health</pim.server.http.health>
<pim.username>kermit</pim.username>
<pim.password>thefrog</pim.password>

Expand Down
Expand Up @@ -14,13 +14,19 @@
* limitations under the License.
*/

package org.kie.processmigration.service;
package org.kie.processmigration.model;

import org.kie.processmigration.model.Status;
public class Health {

public interface StatusService {
public static final Health UP = new Health("UP");

Status getStatus();
private final String status;

String getHealth();
private Health(String status) {
this.status = status;
}

public String getStatus() {
return status;
}
}
Expand Up @@ -24,6 +24,7 @@

public class KieServerConfig {

private static final String UNKNOWN_STATUS = "UNKNOWN";
private String id;

private String host;
Expand Down Expand Up @@ -83,12 +84,12 @@ public KieServerConfig setClient(KieServicesClient client) {

public String getStatus() {
if (client == null) {
return Status.UNKNOWN;
return UNKNOWN_STATUS;
}
try {
return client.getServerInfo().getType().name();
} catch (Exception e) {
return Status.UNKNOWN;
return UNKNOWN_STATUS;
}
}

Expand Down

This file was deleted.

Expand Up @@ -16,33 +16,22 @@

package org.kie.processmigration.rest;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.microprofile.health.Health;
import org.kie.processmigration.service.StatusService;
import org.kie.processmigration.model.Health;

@Path("/health")
@Produces(MediaType.APPLICATION_JSON)
public class HealthStatusResource {

@Inject
private StatusService statusService;
private static final Response UP = Response.ok(Health.UP).build();

@GET
@Path("/readiness")
@Health
public Response checkReadiness() {
return Response.ok(statusService.getHealth()).build();
}

@GET
@Path("/status")
public Response getStatus() {
return Response.ok(statusService.getStatus()).build();
public Response getUpStatus() {
return UP;
}
}
Expand Up @@ -48,7 +48,6 @@
import org.kie.server.api.marshalling.MarshallingFormat;
import org.kie.server.api.model.KieContainerResourceList;
import org.kie.server.api.model.ServiceResponse;
import org.kie.server.api.model.definition.NodeDefinition;
import org.kie.server.api.model.definition.ProcessDefinition;
import org.kie.server.api.model.instance.ProcessInstance;
import org.kie.server.client.CredentialsProvider;
Expand Down

This file was deleted.

Expand Up @@ -11,6 +11,7 @@ thorntail:
- url-pattern: /*
roles: [ admin ]
- url-pattern: /health/*
- url-pattern: /rest/health/*
datasources:
data-sources:
pimDS:
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.util.List;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -37,6 +38,7 @@
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
Expand All @@ -63,6 +65,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

public class ProcessMigrationIntegrationTest {

Expand Down Expand Up @@ -92,6 +95,13 @@ public void init() throws IOException {
client = HttpClientBuilder.create().setDefaultCredentialsProvider(getBasicAuth()).build();
}

@Test
public void testHealthCheck() throws IOException {
HttpGet get = new HttpGet(PIM_ENDPOINT + "/health");
HttpResponse response = client.execute(get);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusLine().getStatusCode());
}

@Test
public void testMigration() throws IOException, JAXBException {
// Given
Expand Down

0 comments on commit 4068000

Please sign in to comment.