use of psiprobe.model.ApplicationResource in project psi-probe by psi-probe.
the class ApplicationUtils method getApplicationDataSourceUsageScores.
/**
* Gets the application data source usage scores.
*
* @param context the context
* @param resolver the resolver
* @param containerWrapper the container wrapper
* @return the application data source usage scores
*/
public static int[] getApplicationDataSourceUsageScores(Context context, ResourceResolver resolver, ContainerWrapperBean containerWrapper) {
logger.debug("Calculating datasource usage score");
int[] scores = new int[] { 0, 0 };
List<ApplicationResource> appResources;
try {
appResources = resolver.getApplicationResources(context, containerWrapper);
} catch (NamingException e) {
throw new RuntimeException(e);
}
for (ApplicationResource appResource : appResources) {
if (appResource.getDataSourceInfo() != null) {
scores[0] = Math.max(scores[0], appResource.getDataSourceInfo().getBusyScore());
scores[1] = Math.max(scores[1], appResource.getDataSourceInfo().getEstablishedScore());
}
}
return scores;
}
use of psiprobe.model.ApplicationResource in project psi-probe by psi-probe.
the class BaseTomcatAvailabilityController method handleRequestInternal.
@Override
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
final long start = System.currentTimeMillis();
TomcatTestReport tomcatTestReport = new TomcatTestReport();
// check datasource status
tomcatTestReport.setDatasourceUsageScore(0);
boolean allContextsAvailable = true;
if (getContainerWrapper().getResourceResolver().supportsPrivateResources()) {
for (Context appContext : getContainerWrapper().getTomcatContainer().findContexts()) {
allContextsAvailable = allContextsAvailable && getContainerWrapper().getTomcatContainer().getAvailable(appContext);
List<ApplicationResource> applicationResources = getContainerWrapper().getResourceResolver().getApplicationResources(appContext, getContainerWrapper());
for (ApplicationResource appResource : applicationResources) {
DataSourceInfo dsi = appResource.getDataSourceInfo();
if (dsi != null && dsi.getBusyScore() > tomcatTestReport.getDatasourceUsageScore()) {
tomcatTestReport.setContextName(appContext.getName());
tomcatTestReport.setDatasourceUsageScore(dsi.getBusyScore());
tomcatTestReport.setDataSourceName(appResource.getName());
}
}
}
tomcatTestReport.setWebappAvailabilityTest(allContextsAvailable ? TomcatTestReport.TEST_PASSED : TomcatTestReport.TEST_FAILED);
} else {
List<ApplicationResource> resources = getContainerWrapper().getResourceResolver().getApplicationResources();
for (ApplicationResource resource : resources) {
DataSourceInfo dsi = resource.getDataSourceInfo();
if (dsi != null && dsi.getBusyScore() > tomcatTestReport.getDatasourceUsageScore()) {
tomcatTestReport.setDatasourceUsageScore(dsi.getBusyScore());
tomcatTestReport.setDataSourceName(resource.getName());
}
}
}
tomcatTestReport.setDatasourceTest(TomcatTestReport.TEST_PASSED);
// try to allocate some memory
String word = "hello";
int count = TomcatTestReport.DEFAULT_MEMORY_SIZE / word.length();
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for (; count > 0; count--) {
bos.write(word.getBytes(StandardCharsets.UTF_8));
}
tomcatTestReport.setMemoryTest(TomcatTestReport.TEST_PASSED);
} catch (IOException e) {
tomcatTestReport.setMemoryTest(TomcatTestReport.TEST_FAILED);
logger.trace("", e);
}
// try to open some files
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
int fileCount = tomcatTestReport.getDefaultFileCount();
List<File> files = new ArrayList<>();
List<OutputStream> fileStreams = new ArrayList<>();
try {
for (; fileCount > 0; fileCount--) {
File file = new File(tmpDir, "tctest_" + fileCount);
try (OutputStream fos = Files.newOutputStream(file.toPath())) {
files.add(file);
fileStreams.add(fos);
fos.write("this is a test".getBytes(StandardCharsets.UTF_8));
}
}
tomcatTestReport.setFileTest(TomcatTestReport.TEST_PASSED);
} catch (IOException e) {
tomcatTestReport.setFileTest(TomcatTestReport.TEST_FAILED);
logger.trace("", e);
} finally {
for (OutputStream fileStream : fileStreams) {
try {
fileStream.close();
} catch (IOException e) {
logger.trace("", e);
}
}
for (File file : files) {
Files.delete(file.toPath());
}
}
tomcatTestReport.setTestDuration(System.currentTimeMillis() - start);
long maxServiceTime = 0;
// TODO JWL 12/11/2016 - Why is this commented out? If not needed, delete it.
// check the maximum execution time
// List<ThreadPool> pools = containerListenerBean.getThreadPools();
// for (int iPool = 0; iPool < pools.size(); iPool++) {
// ThreadPool threadPool = (ThreadPool) pools.get(iPool);
// List<RequestProcessor> threads = threadPool.getRequestProcessors();
// for (int iThread = 0; iThread < threads.size(); iThread++) {
// RequestProcessor rp = (RequestProcessor) threads.get(iThread);
// if (rp.getStage() == 3) {
// // the request processor is in SERVICE state
// maxServiceTime = Math.max(maxServiceTime, rp.getProcessingTime());
// }
// }
// }
tomcatTestReport.setMaxServiceTime(maxServiceTime);
return new ModelAndView(getViewName(), "testReport", tomcatTestReport);
}
Aggregations