Skip to content

Commit 23318e3

Browse files
committed
Add service operation to retrieve results (#116)
Currently only the main data can be fetched, but a download option to get all the raw data will be offered later. The results are not fetched within the UI yet. The SpotterResult's message field had to be renamed to comply with JSON. Added the report text as a string inside ResultsContainer to have all data in one spot. However, the report text file is written normally like before. Changes in Spotter were only to set the report in the container object. Change-Id: I13b546924b0c0b7c832ee20f6c59f3f5f9244a50 Signed-off-by: Denis Knoepfle <denis.knoepfle@sap.com>
1 parent c057a02 commit 23318e3

File tree

10 files changed

+242
-76
lines changed

10 files changed

+242
-76
lines changed

org.spotter.client/src/org/spotter/client/SpotterServiceClient.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.spotter.shared.configuration.JobDescription;
2626
import org.spotter.shared.configuration.SpotterExtensionType;
2727
import org.spotter.shared.hierarchy.model.XPerformanceProblem;
28+
import org.spotter.shared.result.model.ResultsContainer;
2829
import org.spotter.shared.service.SpotterServiceResponse;
2930
import org.spotter.shared.status.SpotterProgress;
3031

@@ -97,6 +98,29 @@ public long startDiagnosis(JobDescription jobDescription) {
9798

9899
}
99100

101+
/**
102+
* Requests the results of a the run with the given job id.
103+
*
104+
* @param jobId
105+
* the job id of the diagnosis run
106+
* @return the retrieved results container or <code>null</code> if none
107+
*/
108+
public ResultsContainer requestResults(String jobId) {
109+
SpotterServiceResponse<ResultsContainer> response = webResource.path(ConfigKeys.SPOTTER_REST_BASE)
110+
.path(ConfigKeys.SPOTTER_REST_REQU_RESULTS).path(jobId).accept(MediaType.APPLICATION_JSON)
111+
.get(new GenericType<SpotterServiceResponse<ResultsContainer>>() {
112+
});
113+
switch (response.getStatus()) {
114+
case OK:
115+
return response.getPayload();
116+
case SERVER_ERROR:
117+
throw new RuntimeException("Server error: " + response.getErrorMessage());
118+
case INVALID_STATE:
119+
default:
120+
throw new IllegalStateException("Illegal response state!");
121+
}
122+
}
123+
100124
/**
101125
* @return true if Spotter Diagnostics is currently running
102126
*/
@@ -172,8 +196,8 @@ public Set<String> getAvailableExtensions(SpotterExtensionType extType) {
172196
*/
173197
public Set<ConfigParameterDescription> getExtensionConfigParamters(String extName) {
174198
SpotterServiceResponse<Set<ConfigParameterDescription>> response = webResource
175-
.path(ConfigKeys.SPOTTER_REST_BASE).path(ConfigKeys.SPOTTER_REST_EXTENSION_PARAMETERS)
176-
.path(extName.toString()).accept(MediaType.APPLICATION_JSON)
199+
.path(ConfigKeys.SPOTTER_REST_BASE).path(ConfigKeys.SPOTTER_REST_EXTENSION_PARAMETERS).path(extName)
200+
.accept(MediaType.APPLICATION_JSON)
177201
.get(new GenericType<SpotterServiceResponse<Set<ConfigParameterDescription>>>() {
178202
});
179203
switch (response.getStatus()) {

org.spotter.core/src/org/spotter/core/Spotter.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ public synchronized void startDiagnosis(String configurationFile, long timestamp
149149
long durationMillis = ((System.currentTimeMillis() - timestamp));
150150

151151
resultsContainer.setResultsMap(ResultBlackboard.getInstance().getResults());
152-
printResults(durationMillis);
152+
String report = printResults(durationMillis);
153+
resultsContainer.setReport(report);
153154
serializeResults(resultsContainer);
154155
ResultBlackboard.getInstance().reset();
155156
}
@@ -178,12 +179,13 @@ private PerformanceProblem retrieveRootPerformanceProblem(ResultsContainer resul
178179
}
179180

180181
/**
181-
* Writes the Spotter report.
182+
* Writes the Spotter report and returns the text that was printed.
182183
*
183184
* @param durationMillis
184185
* time in milli seconds the diagnostics took
186+
* @return the printed text
185187
*/
186-
private void printResults(long durationMillis) {
188+
private String printResults(long durationMillis) {
187189
StringBuilder builder = new StringBuilder();
188190
builder.append("PPD analysis took ");
189191
builder.append(LpeNumericUtils.formatTimeMillis(durationMillis));
@@ -205,6 +207,7 @@ private void printResults(long durationMillis) {
205207
}
206208

207209
LOGGER.info("Spotter analysis finished! Report is written to the following file: {}", outputFile);
210+
return resultString;
208211
}
209212

210213
/**

org.spotter.eclipse.ui/src/org/spotter/eclipse/ui/ServiceClientWrapper.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.spotter.eclipse.ui;
1717

18+
import java.net.ConnectException;
1819
import java.util.ArrayList;
1920
import java.util.HashMap;
2021
import java.util.List;
@@ -35,6 +36,7 @@
3536
import org.spotter.shared.configuration.SpotterExtensionType;
3637
import org.spotter.shared.hierarchy.model.RawHierarchyFactory;
3738
import org.spotter.shared.hierarchy.model.XPerformanceProblem;
39+
import org.spotter.shared.result.model.ResultsContainer;
3840
import org.spotter.shared.status.SpotterProgress;
3941

4042
import com.sun.jersey.api.client.ClientHandlerException;
@@ -70,6 +72,7 @@ public class ServiceClientWrapper {
7072
private static final String MSG_NO_ACTION = "Action cannot be performed without connection to DynamicSpotter Service. "
7173
+ "Please check connection settings and try again.";
7274
private static final String MSG_START_DIAGNOSIS = "Could not start diagnosis!";
75+
private static final String MSG_REQU_RESULTS = "Could not retrieve diagnosis results!";
7376
private static final String MSG_NO_STATUS = "Could not retrieve status.";
7477
private static final String MSG_NO_CONFIG_PARAMS = "Could not retrieve configuration parameters.";
7578
private static final String MSG_NO_EXTENSIONS = "Could not retrieve list of extensions.";
@@ -240,6 +243,23 @@ public Long startDiagnosis(final JobDescription jobDescription) {
240243
return null;
241244
}
242245

246+
/**
247+
* Requests the results of a the run with the given job id.
248+
*
249+
* @param jobId
250+
* the job id of the diagnosis run
251+
* @return the retrieved results container or <code>null</code> if none
252+
*/
253+
public ResultsContainer requestResults(final String jobId) {
254+
lastException = null;
255+
try {
256+
return client.requestResults(jobId);
257+
} catch (Exception e) {
258+
handleException("requestResults", MSG_REQU_RESULTS, e, false, false);
259+
}
260+
return null;
261+
}
262+
243263
/**
244264
* Returns <code>true</code> if DynamicSpotter diagnostics is currently
245265
* running, otherwise <code>false</code>.
@@ -506,7 +526,12 @@ public Exception getLastException() {
506526
* otherwise
507527
*/
508528
public boolean isConnectionIssue() {
509-
return lastException instanceof ClientHandlerException;
529+
if (lastException instanceof ClientHandlerException) {
530+
if (lastException != null && lastException.getCause() instanceof ConnectException) {
531+
return true;
532+
}
533+
}
534+
return false;
510535
}
511536

512537
/**
@@ -577,6 +602,7 @@ public static void showConnectionProblemMessage(String cause, String host, Strin
577602
private void handleException(String requestName, String requestErrorMsg, Exception exception, boolean silent,
578603
boolean warning) {
579604
lastException = exception;
605+
exception.printStackTrace();
580606
if (warning) {
581607
LOGGER.warn("{} request failed! Cause: {}", requestName, exception.getMessage());
582608
} else {

org.spotter.eclipse.ui/src/org/spotter/eclipse/ui/handlers/RunHandler.java

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
7171

7272
IProject project = selectedProjects.iterator().next();
7373
ServiceClientWrapper client = activator.getClient(project.getName());
74+
7475
String spotterFileName = FileManager.SPOTTER_CONFIG_FILENAME;
7576
IFile spotterFile = project.getFile(spotterFileName);
7677
String spotterFilePath = spotterFile.getLocation().toString();

org.spotter.eclipse.ui/src/org/spotter/eclipse/ui/view/ResultsView.java

+28-41
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class ResultsView extends ViewPart implements ISelectionListener {
111111
private static final String RESULTS_EMPTY_CONTENT_DESC = "None selected.";
112112
private static final String EMPTY_RESULTS = "No results selected.";
113113
private static final String ERR_MSG_IO_ERROR = "An I/O error occured while reading the file '%s'.";
114-
private static final String ERR_MSG_MISSING_REPORT = "Could not find the spotter report file.";
114+
private static final String ERR_MSG_MISSING_REPORT = "Either file is missing or report is not set.";
115115
private static final String ERR_MSG_MISSING_SER_FILE = "Could not find the spotter serialization file.";
116116

117117
private static final String LABEL_NONE_SELECTED = "<none selected>";
@@ -587,6 +587,7 @@ private void updateTabs() {
587587
String contentDescription = String.format(RESULTS_CONTENT_DESC_TEMPLATE, runResultItem.getText(),
588588
runResultItem.getProject().getName());
589589
setContentDescription(contentDescription);
590+
updateResultsContainer();
590591
updateHierarchy();
591592
updateReport();
592593
}
@@ -614,25 +615,22 @@ private void resetReport() {
614615
textReport.setText(EMPTY_RESULTS);
615616
}
616617

617-
private void updateHierarchy() {
618+
private void updateResultsContainer() {
618619
String filename = FileManager.DEFAULT_RESULTS_DIR_NAME + File.separator + runResultItem.getText()
619620
+ File.separator + ResultsLocationConstants.RESULTS_SERIALIZATION_FILE_NAME;
620621
IFile file = runResultItem.getProject().getFile(filename);
621-
ExtensionItem input = null;
622+
resultsContainer = null;
622623
try {
623624
if (!file.isSynchronized(IResource.DEPTH_ZERO)) {
624625
file.refreshLocal(IResource.DEPTH_ZERO, null);
625626
}
626627
BufferedInputStream bufferedInStream = new BufferedInputStream(file.getContents());
627628
ObjectInputStream objectIn = new ObjectInputStream(bufferedInStream);
629+
628630
resultsContainer = (ResultsContainer) objectIn.readObject();
631+
629632
objectIn.close();
630633
bufferedInStream.close();
631-
632-
XPerformanceProblem root = resultsContainer.getRootProblem();
633-
if (root != null) {
634-
input = HierarchyEditor.createPerformanceProblemHierarchy(runResultItem.getProject().getName(), root);
635-
}
636634
} catch (CoreException e) {
637635
resultsContainer = null;
638636
String text = ERR_MSG_MISSING_SER_FILE + " (" + filename + ")";
@@ -643,48 +641,37 @@ private void updateHierarchy() {
643641
String text = String.format(ERR_MSG_IO_ERROR, filename);
644642
LOGGER.error(text + (e.getMessage() != null ? " (" + e.getMessage() + ")" : ""));
645643
DialogUtils.openWarning(RESULTS_VIEW_TITLE, text);
646-
} finally {
647-
imageProvider.setResultsContainer(resultsContainer);
648-
if (input == null) {
649-
input = new ExtensionItem();
644+
}
645+
}
646+
647+
private void updateHierarchy() {
648+
ExtensionItem input = null;
649+
650+
if (resultsContainer != null) {
651+
XPerformanceProblem root = resultsContainer.getRootProblem();
652+
if (root != null) {
653+
input = HierarchyEditor.createPerformanceProblemHierarchy(runResultItem.getProject().getName(), root);
650654
}
651-
hierarchyTreeViewer.setInput(input);
652-
hierarchyTreeViewer.expandAll();
653655
}
656+
657+
imageProvider.setResultsContainer(resultsContainer);
658+
if (input == null) {
659+
input = new ExtensionItem();
660+
}
661+
hierarchyTreeViewer.setInput(input);
662+
hierarchyTreeViewer.expandAll();
654663
}
655664

656665
private void updateReport() {
657-
String filename = FileManager.DEFAULT_RESULTS_DIR_NAME + File.separator + runResultItem.getText()
658-
+ File.separator + ResultsLocationConstants.TXT_REPORT_FILE_NAME;
659-
IFile file = runResultItem.getProject().getFile(filename);
660-
StringBuilder sb = new StringBuilder();
661-
try {
662-
if (!file.isSynchronized(IResource.DEPTH_ZERO)) {
663-
file.refreshLocal(IResource.DEPTH_ZERO, null);
664-
}
665-
BufferedInputStream bufferedInStream = new BufferedInputStream(file.getContents());
666-
int readByte;
667-
while ((readByte = bufferedInStream.read()) != -1) {
668-
sb.append((char) readByte);
669-
}
670-
bufferedInStream.close();
671-
textReport.setText(sb.toString());
672-
} catch (CoreException e) {
673-
String text = ERR_MSG_MISSING_REPORT + " (" + filename + ")";
674-
LOGGER.error(text + (e.getMessage() != null ? " (" + e.getMessage() + ")" : ""));
675-
textReport.setText(text);
676-
DialogUtils.openWarning(RESULTS_VIEW_TITLE, text);
677-
} catch (IOException e) {
678-
String text = String.format(ERR_MSG_IO_ERROR, filename);
679-
LOGGER.error(text + (e.getMessage() != null ? " (" + e.getMessage() + ")" : ""));
680-
textReport.setText(text);
681-
DialogUtils.openWarning(RESULTS_VIEW_TITLE, text);
666+
if (resultsContainer != null && resultsContainer.getReport() != null) {
667+
textReport.setText(resultsContainer.getReport());
668+
} else {
669+
textReport.setText(ERR_MSG_MISSING_REPORT);
682670
}
683671
}
684672

685673
private String getCurrentResourceFolder() {
686-
String projectRelativeRunPath = FileManager.DEFAULT_RESULTS_DIR_NAME + File.separator
687-
+ runResultItem.getText();
674+
String projectRelativeRunPath = FileManager.DEFAULT_RESULTS_DIR_NAME + File.separator + runResultItem.getText();
688675
IFolder folder = runResultItem.getProject().getFolder(projectRelativeRunPath);
689676
String currentRunFolder = folder.getLocation().toString() + "/";
690677
String subDirPath = getSubDirPathForProblem(currentSelectedProblem);

0 commit comments

Comments
 (0)