use of org.apache.deltaspike.core.api.jmx.JmxManaged in project datawave by NationalSecurityAgency.
the class ModificationCacheBean method reloadMutableFieldCache.
/**
* @return datawave.webservice.result.VoidResponse
* @RequestHeader X-ProxiedEntitiesChain use when proxying request for user
* @RequestHeader X-ProxiedIssuersChain required when using X-ProxiedEntitiesChain, specify one issuer DN per subject DN listed in X-ProxiedEntitiesChain
* @ResponseHeader query-session-id this header and value will be in the Set-Cookie header, subsequent calls for this session will need to supply the
* query-session-id header in the request in a Cookie header or as a query parameter
* @ResponseHeader X-OperationTimeInMS time spent on the server performing the operation, does not account for network or result serialization
* @HTTP 200 success
* @HTTP 202 if asynch is true - see Location response header for the job URI location
* @HTTP 400 invalid or missing parameter
* @HTTP 500 internal server error
*/
@GET
@Produces({ "application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff" })
@Path("/reloadCache")
@GZIP
@JmxManaged
public VoidResponse reloadMutableFieldCache() {
this.clearCache();
log.trace("cleared cache");
final VoidResponse resp = new VoidResponse();
Connector con = null;
BatchScanner s = null;
try {
Map<String, String> trackingMap = connectionFactory.getTrackingMap(Thread.currentThread().getStackTrace());
log.trace("getting mutable list from table " + this.modificationConfiguration.getTableName());
log.trace("modificationConfiguration.getPoolName() = " + modificationConfiguration.getPoolName());
con = connectionFactory.getConnection(modificationConfiguration.getPoolName(), Priority.ADMIN, trackingMap);
log.trace("got connection");
s = ScannerHelper.createBatchScanner(con, this.modificationConfiguration.getTableName(), Collections.singleton(con.securityOperations().getUserAuthorizations(con.whoami())), 8);
s.setRanges(Collections.singleton(new Range()));
s.fetchColumnFamily(MODIFICATION_COLUMN);
for (Entry<Key, Value> e : s) {
// Field name is in the row and datatype is in the colq.
String datatype = e.getKey().getColumnQualifier().toString();
log.trace("datatype = " + datatype);
String fieldName = e.getKey().getRow().toString();
log.trace("fieldname = " + fieldName);
if (null == cache.get(datatype))
cache.put(datatype, new HashSet<>());
cache.get(datatype).add(fieldName);
}
log.trace("cache size = " + cache.size());
for (Entry<String, Set<String>> e : cache.entrySet()) {
log.trace("datatype = " + e.getKey() + ", fieldcount = " + e.getValue().size());
}
} catch (Exception e) {
log.error("Error during initialization of ModificationCacheBean", e);
throw new EJBException("Error during initialization of ModificationCacheBean", e);
} finally {
if (null != s)
s.close();
try {
connectionFactory.returnConnection(con);
} catch (Exception e) {
log.error("Error returning connection to pool", e);
}
}
return resp;
}
use of org.apache.deltaspike.core.api.jmx.JmxManaged in project datawave by NationalSecurityAgency.
the class HealthBean method waitForQueryCompletion.
/**
* This method initiates a shutdown. This will set internal state such that the {@link #health()} method will return a {@link Status#SERVICE_UNAVAILABLE}
* error to prevent new queries from coming in. After that, it will wait up to {@code timeoutMinutes} for queries to complete before initiating a shutdown
* of the web server.
*
* <strong>NOTE:</strong> This method is restricted to users calling from the local host, or via the JMX interface.
*
* TODO: Is there a way to "cancel" any requests that are waiting for an Accumulo connection? It would be nice if such requests could be rejected somehow
* and the load balancer could automatically redirect to a different web server.
*
* @param timeoutMinutes
* the number of minutes to wait for queries to complete before continuing with the shutdown operation anyway
* @return a message indicating whether or not shutdown was attempted
*/
@GET
@Path("/shutdown")
@JmxManaged
public Response waitForQueryCompletion(@QueryParam("timeoutMinutes") @DefaultValue("75") int timeoutMinutes, @Context HttpServletRequest request) {
GenericResponse<String> response = new GenericResponse<>();
// We're only allowed to call shutdown from the loopback interface.
if (!"127.0.0.1".equals(request.getRemoteAddr())) {
LOG.error("Shutdown requested from {}. Denying access since the request was not from localhost.", request.getRemoteAddr());
response.setResult("Shutdown calls must be made on the local host.");
return Response.status(Status.FORBIDDEN).entity(response).build();
}
LOG.warn("Shutdown requested from {}. Waiting up to {} minutes for queries to complete.", request.getRemoteAddr(), timeoutMinutes);
// Wait for queries to complete
long timeoutMillis = TimeUnit.MINUTES.toMillis(timeoutMinutes);
shutdownInProgress = true;
status = "drain";
long startTime = System.currentTimeMillis();
int connectionUsage;
while ((connectionUsage = accumuloConnectionFactoryBean.getConnectionUsagePercent()) > 0) {
long delta = System.currentTimeMillis() - startTime;
if (delta > timeoutMillis) {
LOG.warn("Timeout of {} minutes exceeded while waiting for queries to complete. Shutting down anyway.", timeoutMinutes);
break;
}
LOG.info("Connection usage is {}%. Waiting for queries to complete.", connectionUsage);
try {
Thread.sleep(queryCompletionWaitIntervalMillis);
} catch (InterruptedException e) {
LOG.warn("Interrupted while waiting for queries to complete.");
}
}
if (connectionUsage <= 0) {
response.setResult("All queries completed. Shutting down.");
} else {
response.setResult("Gave up waiting for queries to complete. Shutting down with pool usage percentage of " + connectionUsage + ".");
}
// Initiate a server shutdown using the management JMX bean
try {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("jboss.as:management-root=server");
mBeanServer.invoke(objectName, "shutdown", new Object[] { false, 0, 0 }, new String[] { boolean.class.getName(), int.class.getName(), int.class.getName() });
} catch (MalformedObjectNameException | ReflectionException | InstanceNotFoundException | MBeanException e) {
LOG.warn("Error shutting down: {}", e);
}
return Response.ok().entity(response).build();
}
use of org.apache.deltaspike.core.api.jmx.JmxManaged in project datawave by NationalSecurityAgency.
the class AccumuloConnectionFactoryBean method getConnectionUsagePercent.
@PermitAll
@JmxManaged
public int getConnectionUsagePercent() {
double maxPercentage = 0.0;
for (Entry<String, Map<Priority, AccumuloConnectionPool>> entry : pools.entrySet()) {
for (Entry<Priority, AccumuloConnectionPool> poolEntry : entry.getValue().entrySet()) {
// Don't include ADMIN priority connections when computing a usage percentage
if (Priority.ADMIN.equals(poolEntry.getKey()))
continue;
MutableInt maxActive = new MutableInt();
MutableInt numActive = new MutableInt();
MutableInt numWaiting = new MutableInt();
MutableInt unused = new MutableInt();
poolEntry.getValue().getConnectionPoolStats(maxActive, numActive, unused, unused, numWaiting);
double percentage = (numActive.doubleValue() + numWaiting.doubleValue()) / maxActive.doubleValue();
if (percentage > maxPercentage) {
maxPercentage = percentage;
}
}
}
return (int) (maxPercentage * 100);
}
Aggregations