use of it.geosolutions.geoserver.rest.GeoServerRESTReader in project coastal-hazards by USGS-CIDA.
the class HealthResource method healthCheck.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response healthCheck() {
Response response;
boolean overallHealth = true;
Map<String, Object> componentCheckMap = new TreeMap<>();
try {
EntityManagerFactory emf = JPAHelper.getEntityManagerFactory();
boolean open = emf.isOpen();
componentCheckMap.put("EntityManagerFactory", open);
overallHealth = open && overallHealth;
} catch (Exception e) {
LOG.warn("Exception occurred while checking health", e);
componentCheckMap.put("EntityManagerFactory", false);
overallHealth = false;
}
try {
Gson defaultGson = GsonUtil.getDefault();
boolean ok = (defaultGson != null);
componentCheckMap.put("DefaultGson", ok);
overallHealth = ok && overallHealth;
} catch (Exception e) {
LOG.warn("Exception occurred while checking health", e);
componentCheckMap.put("DefaultGson", false);
overallHealth = false;
}
try {
Gson idGson = GsonUtil.getIdOnlyGson();
boolean ok = (idGson != null);
componentCheckMap.put("NonSubtreeGson", ok);
overallHealth = ok && overallHealth;
} catch (Exception e) {
LOG.warn("Exception occurred while checking health", e);
componentCheckMap.put("NonSubtreeGson", false);
overallHealth = false;
}
try {
Gson subtreeGson = GsonUtil.getSubtreeGson();
boolean ok = (subtreeGson != null);
componentCheckMap.put("SubtreeGson", ok);
overallHealth = ok && overallHealth;
} catch (Exception e) {
LOG.warn("Exception occurred while checking health", e);
componentCheckMap.put("SubtreeGson", false);
overallHealth = false;
}
try (ItemManager im = new ItemManager()) {
Item uber = im.load("uber");
boolean ok = (uber != null && uber.isEnabled());
componentCheckMap.put("ItemManager", ok);
overallHealth = ok && overallHealth;
} catch (Exception e) {
LOG.warn("Exception occurred while checking health", e);
componentCheckMap.put("ItemManager", false);
overallHealth = false;
}
try {
Map<String, Boolean> geoserverStatus = new HashMap<>();
GeoServerRESTReader rest = new GeoServerRESTReader(geoserverEndpoint, geoserverUser, geoserverPass);
boolean existGeoserver = rest.existGeoserver();
boolean workspacesConfigured = rest.getWorkspaceNames().contains("proxied");
// TODO may want to add some more checks
geoserverStatus.put("up", existGeoserver);
geoserverStatus.put("configured", workspacesConfigured);
componentCheckMap.put("Geoserver", geoserverStatus);
overallHealth = overallHealth && existGeoserver && workspacesConfigured;
} catch (Exception e) {
LOG.warn("Exception occurred while checking health", e);
componentCheckMap.put("Geoserver", false);
overallHealth = false;
}
try {
// health check add for pycsw Jira cchs-306
boolean hasCswGetCapabilities = false;
Map<String, Boolean> pyCswStatus = new HashMap<>();
String endpointTest = pycswEndpoint + "?service=CSW&request=GetCapabilities&version=" + pycswVersion;
HttpGet httpGet = new HttpGet(endpointTest);
HttpClient httpclient = new DefaultHttpClient();
// Create a custom response handler
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
@Override
public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
}
};
// close anonymous inner class
String resp = httpclient.execute(httpGet, responseHandler);
hasCswGetCapabilities = resp != null;
pyCswStatus.put("getCapabilities", hasCswGetCapabilities);
componentCheckMap.put("PyCsw", pyCswStatus);
overallHealth = overallHealth && hasCswGetCapabilities;
} catch (Exception e) {
LOG.warn("Exception occurred while checking csw health", e);
componentCheckMap.put("Pycsw", false);
overallHealth = false;
}
try (StatusManager statusMan = new StatusManager()) {
// NOTE this does not effect the overall health
boolean staleCache = false;
Map<Status.StatusName, Status> statuses = statusMan.loadAll();
Status itemLastUpdate = statuses.get(StatusName.ITEM_UPDATE);
Status structureLastUpdate = statuses.get(StatusName.STRUCTURE_UPDATE);
Status cacheClearedDate = statuses.get(StatusName.CACHE_CLEAR);
Date itemOrStructureUpdate = null;
if (itemLastUpdate != null) {
itemOrStructureUpdate = itemLastUpdate.getLastUpdate();
}
if (structureLastUpdate != null) {
Date structureDate = structureLastUpdate.getLastUpdate();
if (structureDate != null && itemOrStructureUpdate != null && structureDate.after(itemOrStructureUpdate)) {
itemOrStructureUpdate = structureDate;
}
}
if (cacheClearedDate != null) {
Date cacheDate = cacheClearedDate.getLastUpdate();
if (cacheDate != null && itemOrStructureUpdate != null && cacheDate.before(itemOrStructureUpdate)) {
staleCache = true;
}
}
componentCheckMap.put("TileCacheStale", staleCache);
}
Gson gson = GsonUtil.getDefault();
String json = gson.toJson(componentCheckMap);
if (overallHealth) {
response = Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build();
} else {
response = Response.serverError().entity(json).build();
}
return response;
}
use of it.geosolutions.geoserver.rest.GeoServerRESTReader in project sldeditor by robward-scisys.
the class GeoServerClient method uploadNewStyle.
/**
* Upload new style.
*
* @param sldBody the sld body
* @param workspaceName the workspace name
* @param styleName the style name
* @param manager the manager
* @param publisher the publisher
* @return true, if successful
*/
private boolean uploadNewStyle(String sldBody, String workspaceName, String styleName, GeoServerRESTManager manager, GeoServerRESTPublisher publisher) {
boolean result;
if (isDefaultWorkspace(workspaceName)) {
result = publisher.publishStyle(sldBody, styleName, true);
} else {
GeoServerRESTReader reader = manager.getReader();
if (reader != null) {
if (!reader.existsWorkspace(workspaceName) && !publisher.createWorkspace(workspaceName)) {
ConsoleManager.getInstance().error(this, Localisation.getField(GeoServerClient.class, "GeoServerClient.failedToCreateWorkspace") + workspaceName);
return false;
}
} else {
return false;
}
result = publisher.publishStyleInWorkspace(workspaceName, sldBody, styleName);
}
return result;
}
use of it.geosolutions.geoserver.rest.GeoServerRESTReader in project sldeditor by robward-scisys.
the class GeoServerClient method getWorkspaceList.
/**
* Gets the workspace list.
*
* @return the workspace list
*/
@Override
public List<String> getWorkspaceList() {
List<String> workspaceList = null;
GeoServerRESTManager manager = GeoServerRESTManagerFactory.getManager(connection);
if (manager != null) {
GeoServerRESTReader reader = manager.getReader();
if (reader != null) {
workspaceList = reader.getWorkspaceNames();
}
}
if (workspaceList == null) {
workspaceList = new ArrayList<>();
}
return workspaceList;
}
use of it.geosolutions.geoserver.rest.GeoServerRESTReader in project sldeditor by robward-scisys.
the class GeoServerClient method styleExists.
/**
* Check to see if style exists.
*
* @param workspaceName the workspace name
* @param styleName the style name
* @return true, if successful
*/
private boolean styleExists(String workspaceName, String styleName) {
GeoServerRESTManager manager = GeoServerRESTManagerFactory.getManager(connection);
GeoServerRESTReader reader = manager.getReader();
if (reader != null) {
if (isDefaultWorkspace(workspaceName)) {
return reader.existsStyle(styleName, true);
} else {
// Check workspace exists first
if (reader.existsWorkspace(workspaceName)) {
return reader.existsStyle(workspaceName, styleName);
}
}
}
return false;
}
use of it.geosolutions.geoserver.rest.GeoServerRESTReader in project sldeditor by robward-scisys.
the class GeoServerClient method retrieveData.
/**
* Retrieve data from GeoServer.
*/
@Override
public void retrieveData() {
GeoServerRESTManager manager = GeoServerRESTManagerFactory.getManager(connection);
if (manager != null) {
GeoServerRESTReader reader = manager.getReader();
if (reader != null) {
if (parentObj != null) {
parentObj.startPopulating(connection);
}
List<String> localWorkspaceList = getWorkspaceList();
parseStyleList(reader, localWorkspaceList);
parseLayerList(reader, localWorkspaceList, null);
}
}
}
Aggregations