use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class ItemManager method findVisibleAncestors.
private List<Item> findVisibleAncestors(Item item) {
List<Item> items = new ArrayList<>();
List<String> idList = findVisibleAncestorIds(item);
for (String result : idList) {
Item ancestor = load(result);
if (ancestor != null) {
items.add(ancestor);
}
}
return items;
}
use of gov.usgs.cida.coastalhazards.model.Item 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 gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class PcoiTest method testGenerateSLD.
@Test
public void testGenerateSLD() {
Item item = new Item();
item.setAttr("PCOL1");
item.setId("abcde");
item.setType(Item.Type.storms);
List<Service> services = new LinkedList<>();
Service wmsService = new Service();
wmsService.setEndpoint("http://test");
wmsService.setServiceParameter("0");
wmsService.setType(ServiceType.source_wms);
services.add(wmsService);
item.setServices(services);
Summary summary = new Summary();
Tiny tiny = new Tiny();
tiny.setText("Pcoi");
summary.setTiny(tiny);
item.setSummary(summary);
SLDGenerator pcoi = new SLDGenerator(item, item.getId(), null, Pcoi.pcoi);
Response response = pcoi.generateSLD();
// TODO?
Viewable sld = (Viewable) response.getEntity();
}
use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class PcoiTest method testGenerateSLDInfo.
/**
* Test of generateSLDInfo method, of class Pcoi.
*/
@Test
public void testGenerateSLDInfo() {
Item item = new Item();
item.setAttr("PCOL1");
item.setId("abcde");
item.setType(Item.Type.storms);
List<Service> services = new LinkedList<>();
Service wmsService = new Service();
wmsService.setEndpoint("http://test");
wmsService.setServiceParameter("0");
wmsService.setType(ServiceType.source_wms);
services.add(wmsService);
item.setServices(services);
Summary summary = new Summary();
Tiny tiny = new Tiny();
tiny.setText("Pcoi");
summary.setTiny(tiny);
item.setSummary(summary);
SLDGenerator pcoi = new SLDGenerator(item, item.getId(), null, Pcoi.pcoi);
Response response = pcoi.generateSLDInfo();
String json = (String) response.getEntity();
Map<String, Object> sldInfo = new Gson().fromJson(json, HashMap.class);
List<Object> bins = (List) sldInfo.get("bins");
Map<String, Object> bin = (Map) bins.get(0);
Double lowerBound = (Double) bin.get("lowerBound");
String color = (String) bin.get("color");
assertEquals(lowerBound, 0.0f, 0.01f);
assertEquals(color, "#FFFFFE");
}
use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class RasterTest method testGenerateSLD.
@Test
public void testGenerateSLD() {
Item item = new Item();
// for rasters, this will stay the same. We may need a way to manage the type for a raster(ramp, intervals) etc as that is the volatile piece of data.
item.setAttr("GRAY_INDEX");
// may want h
item.setId("EHr6oLT5");
item.setType(Item.Type.vulnerability);
List<Service> services = new LinkedList<>();
Service wmsService = new Service();
wmsService.setEndpoint("http://test");
wmsService.setServiceParameter("0");
wmsService.setType(Service.ServiceType.source_wms);
services.add(wmsService);
item.setServices(services);
Summary summary = new Summary();
Tiny tiny = new Tiny();
tiny.setText("Coastal response to Sea Level");
summary.setTiny(tiny);
item.setSummary(summary);
SLDGenerator raster = new SLDGenerator(item, item.getId(), null, RasterAE.rasterConfig);
Response response = raster.generateSLD();
Viewable sld = (Viewable) response.getEntity();
}
Aggregations