| /** |
| ****************************************************************************** |
| * Copyright © 2018 PTA GmbH. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| ****************************************************************************** |
| */ |
| |
| package org.eclipse.openK.resources; |
| |
| |
| import org.apache.log4j.Logger; |
| import org.eclipse.openK.core.common.JsonGeneratorBase; |
| import org.eclipse.openK.core.controller.DispatchController; |
| import org.hibernate.validator.constraints.NotEmpty; |
| import org.eclipse.openK.api.ServiceRequestEnvelope; |
| import org.eclipse.openK.core.controller.BackendController; |
| import org.eclipse.openK.core.controller.BaseWebService; |
| import org.eclipse.openK.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())); |
| } |
| } |