blob: ee69d320dabcbc9782ec8a7a97431e0507421f2f [file] [log] [blame]
package pta.de.resources;
import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;
import pta.de.api.ServiceRequestEnvelope;
import pta.de.core.common.JsonGeneratorBase;
import pta.de.core.controller.BackendController;
import pta.de.core.controller.BaseWebService;
import pta.de.core.controller.DispatchController;
import pta.de.core.exceptions.HttpStatusException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/mics/central")
@Produces(MediaType.APPLICATION_JSON)
public class MicsCentralResource extends BaseWebService{
private static Logger logger = Logger.getLogger(MicsCentralResource.class.getName());
public MicsCentralResource() {
super(logger);
}
@GET
@Path("/serviceDistribution/{clustername}")
public Response getServiceDistribution(@PathParam("clustername") @NotEmpty String clustername) {
return invokeRunnable(() -> new BackendController().readServerDistribution(clustername));
}
@GET
@Path("/serviceHealthState/{clustername}/{servicename}")
public Response getClusterHealthState(@PathParam("clustername") @NotEmpty String clustername,
@PathParam("servicename") @NotEmpty String servicename) {
return invokeRunnable(() -> new BackendController().getServiceHealthState(clustername, servicename));
}
@POST
@Path("/dispatch/{clustername}")
public Response dispatch(String envelope,
@PathParam("clustername") @NotEmpty String clustername) {
ServiceRequestEnvelope envObj = JsonGeneratorBase.getGson().fromJson(envelope, ServiceRequestEnvelope.class);
try {
return new DispatchController().dispatch(clustername, envObj);
} catch (HttpStatusException hse) {
logger.error(hse);
return Response.status(hse.getHttpStatus()).build();
}
}
@GET
@Path("/versionInfo")
public Response getVersionInfo() {
return invokeRunnable(() -> new BackendController().getVersionInfo(getVersionString()));
}
}