From a597c2d24f80621c529c7656f1f993556e33b52e Mon Sep 17 00:00:00 2001 From: Keith Uplinger Date: Fri, 3 May 2013 15:37:49 +0000 Subject: [PATCH] Changes to the rpc api that gets more details for the results and applications. Used in the task pull down. --- .../boinc/adapter/TasksListAdapter.java | 11 ++- .../edu/berkeley/boinc/client/Monitor.java | 13 ++-- .../BOINC/src/edu/berkeley/boinc/rpc/App.java | 10 +++ .../edu/berkeley/boinc/rpc/AppVersion.java | 10 +++ .../edu/berkeley/boinc/rpc/AppsParser.java | 3 + .../src/edu/berkeley/boinc/rpc/CcState.java | 68 +++++++++++++++++++ .../edu/berkeley/boinc/rpc/CcStateParser.java | 59 ++++++++++++++-- .../src/edu/berkeley/boinc/rpc/Project.java | 13 ++++ .../src/edu/berkeley/boinc/rpc/Result.java | 5 ++ .../src/edu/berkeley/boinc/rpc/RpcClient.java | 4 +- .../src/edu/berkeley/boinc/rpc/Workunit.java | 3 + 11 files changed, 182 insertions(+), 17 deletions(-) diff --git a/android/BOINC/src/edu/berkeley/boinc/adapter/TasksListAdapter.java b/android/BOINC/src/edu/berkeley/boinc/adapter/TasksListAdapter.java index 3213f1fa90..c3967caf4d 100644 --- a/android/BOINC/src/edu/berkeley/boinc/adapter/TasksListAdapter.java +++ b/android/BOINC/src/edu/berkeley/boinc/adapter/TasksListAdapter.java @@ -98,8 +98,15 @@ public class TasksListAdapter extends ArrayAdapter{ String deadline = (String) DateFormat.format("E d MMM yyyy hh:mm:ss aa", new Date(listItem.result.report_deadline*1000)); ((TextView) v.findViewById(R.id.deadline)).setText("Deadline: " + deadline); // set project name - ((TextView) v.findViewById(R.id.projectName)).setText("Project name: " + listItem.result.project_url); - // TODO: set application friendly name + String tempProjectName = listItem.result.project_url; + if(listItem.result.project != null) { + tempProjectName = listItem.result.project.getName(); + } + ((TextView) v.findViewById(R.id.projectName)).setText("Project name: " + tempProjectName); + // set application friendly name + if(listItem.result.app != null) { + ((TextView) v.findViewById(R.id.friendlyAppName)).setText("App Name: " + listItem.result.app.getName()); + } ImageView suspendResume = (ImageView) v.findViewById(R.id.suspendResumeTask); if (listItem.currentRunState == listItem.nextRunState) { diff --git a/android/BOINC/src/edu/berkeley/boinc/client/Monitor.java b/android/BOINC/src/edu/berkeley/boinc/client/Monitor.java index fed3ed954a..611acbfb7f 100644 --- a/android/BOINC/src/edu/berkeley/boinc/client/Monitor.java +++ b/android/BOINC/src/edu/berkeley/boinc/client/Monitor.java @@ -45,6 +45,7 @@ import edu.berkeley.boinc.AppPreferences; import edu.berkeley.boinc.R; import edu.berkeley.boinc.rpc.AccountIn; import edu.berkeley.boinc.rpc.AccountOut; +import edu.berkeley.boinc.rpc.CcState; import edu.berkeley.boinc.rpc.CcStatus; import edu.berkeley.boinc.rpc.GlobalPreferences; import edu.berkeley.boinc.rpc.Message; @@ -945,19 +946,15 @@ public class Monitor extends Service { } else { if(showRpcCommands) Log.d(TAG, "getCcStatus"); CcStatus status = rpc.getCcStatus(); - /* + if(showRpcCommands) Log.d(TAG, "getState"); CcState state = rpc.getState(); - */ - if(showRpcCommands) Log.d(TAG, "getResults"); - ArrayList results = rpc.getResults(); - if(showRpcCommands) Log.d(TAG, "getProjects"); - ArrayList projects = rpc.getProjectStatus(); + if(showRpcCommands) Log.d(TAG, "getTransers"); ArrayList transfers = rpc.getFileTransfers(); - if( (status != null) && (results != null) && (projects != null) && (transfers != null)) { - Monitor.getClientStatus().setClientStatus(status, results, projects, transfers); + if( (status != null) && (state.results != null) && (state.projects != null) && (transfers != null)) { + Monitor.getClientStatus().setClientStatus(status, state.results, state.projects, transfers); // Update status bar notification ClientNotification.getInstance().update(getApplicationContext(), getClientStatus()); } else { diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/App.java b/android/BOINC/src/edu/berkeley/boinc/rpc/App.java index 5ee8c294cd..c30b6b3c6d 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/App.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/App.java @@ -22,6 +22,16 @@ package edu.berkeley.boinc.rpc; public class App { public String name = ""; public String user_friendly_name = ""; + public int non_cpu_intensive = 0; + public Project project; + + public boolean compare(App myapp) { + //Check if name is the same + if(!this.name.equalsIgnoreCase(myapp.name)) { + return false; + } + return true; + } public final String getName() { return user_friendly_name.equals("") ? name : user_friendly_name; diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/AppVersion.java b/android/BOINC/src/edu/berkeley/boinc/rpc/AppVersion.java index 52e1d66748..bf6e068256 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/AppVersion.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/AppVersion.java @@ -22,4 +22,14 @@ package edu.berkeley.boinc.rpc; public class AppVersion { public String app_name; public int version_num; + public String platform; + public String plan_class; + public String api_version; + public double avg_ncpus; + public double max_ncpus; + + public double gpu_ram; + + App app; + Project project; } diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/AppsParser.java b/android/BOINC/src/edu/berkeley/boinc/rpc/AppsParser.java index 0d0e5ef64b..5a40b4c736 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/AppsParser.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/AppsParser.java @@ -100,6 +100,9 @@ public class AppsParser extends BaseParser { else if (localName.equalsIgnoreCase("user_friendly_name")) { mApp.user_friendly_name = mCurrentElement.toString(); } + else if (localName.equalsIgnoreCase("non_cpu_intensive")) { + mApp.non_cpu_intensive = Integer.parseInt(mCurrentElement.toString()); + } } } mElementStarted = false; diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/CcState.java b/android/BOINC/src/edu/berkeley/boinc/rpc/CcState.java index af1f226eba..98ccb1284b 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/CcState.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/CcState.java @@ -21,6 +21,8 @@ package edu.berkeley.boinc.rpc; import java.util.ArrayList; +import android.util.Log; + public class CcState{ public VersionInfo version_info; public HostInfo host_info; @@ -31,4 +33,70 @@ public class CcState{ public ArrayList results = new ArrayList(); public boolean have_ati; public boolean have_cuda; + + public void clearArrays() { + projects.clear(); + apps.clear(); + app_versions.clear(); + workunits.clear(); + results.clear(); + } + + public Project lookup_project(String testUrl) { + int i = 0; + for(i = 0; i < projects.size(); i++) { + if(projects.get(i).master_url.equalsIgnoreCase(testUrl)) { + return projects.get(i); + } + } + return null; + } + + public App lookup_app(Project project, String appname) { + for(int i = 0; i < apps.size(); i++) { + if(!apps.get(i).project.compare(project)) { + continue; + } + if(apps.get(i).name.equalsIgnoreCase(appname)) { + return apps.get(i); + } + } + return null; + } + + public Workunit lookup_wu(Project project, String wu_name) { + for(int i = 0; i < workunits.size(); i++) { + if(!workunits.get(i).project.compare(project)) { + Log.d("Workunit", "Projects Do not compare"); + continue; + } + if(workunits.get(i).name.equalsIgnoreCase(wu_name)) { + return workunits.get(i); + } + } + return null; + } + + public AppVersion lookup_app_version(Project project, App app, int version_num, String plan_class) { + for(int i = 0; i < app_versions.size(); i++) { + //Check if projects match... + if(!app_versions.get(i).project.compare(project)) { + continue; + } + //Check if app matches + if(!app_versions.get(i).app.compare(app)) { + continue; + } + //checks version_num + if(app_versions.get(i).version_num != version_num) { + continue; + } + //Checks plan class + if(!app_versions.get(i).plan_class.equalsIgnoreCase(plan_class)) { + continue; + } + return app_versions.get(i); + } + return null; + } } diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/CcStateParser.java b/android/BOINC/src/edu/berkeley/boinc/rpc/CcStateParser.java index 5d72e49a4c..e58ac3f66e 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/CcStateParser.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/CcStateParser.java @@ -35,14 +35,19 @@ public class CcStateParser extends BaseParser { private boolean mInHostInfo = false; private ProjectsParser mProjectsParser = new ProjectsParser(); private boolean mInProject = false; + private Project myProject = new Project(); private AppsParser mAppsParser = new AppsParser(); private boolean mInApp = false; + private App myApp = new App(); private AppVersionsParser mAppVersionsParser = new AppVersionsParser(); private boolean mInAppVersion = false; + private AppVersion myAppVersion = new AppVersion(); private WorkunitsParser mWorkunitsParser = new WorkunitsParser(); private boolean mInWorkunit = false; + private Workunit myWorkunit = new Workunit(); private ResultsParser mResultsParser = new ResultsParser(); private boolean mInResult = false; + private Result myResult = new Result(); public final CcState getCcState() { return mCcState; @@ -55,6 +60,13 @@ public class CcStateParser extends BaseParser { */ public static CcState parse(String rpcResult) { try { + String tmp = rpcResult; + while(tmp.length() > 4000) { + Log.d(TAG, "WCG: " + tmp.substring(0, 4000)); + tmp = tmp.substring(4000); + } + Log.d(TAG, "WCG: " + tmp); + CcStateParser parser = new CcStateParser(); Xml.parse(rpcResult, parser); return parser.getCcState(); @@ -72,16 +84,20 @@ public class CcStateParser extends BaseParser { // Commit sub-parsers data to resulting CcState mCcState.version_info = mVersionInfo; mCcState.host_info = mHostInfoParser.getHostInfo(); - mCcState.projects = mProjectsParser.getProjects(); - mCcState.apps = mAppsParser.getApps(); - mCcState.app_versions = mAppVersionsParser.getAppVersions(); - mCcState.workunits = mWorkunitsParser.getWorkunits(); - mCcState.results = mResultsParser.getResults(); + //mCcState.projects = mProjectsParser.getProjects(); + //mCcState.apps = mAppsParser.getApps(); + //mCcState.app_versions = mAppVersionsParser.getAppVersions(); + //mCcState.workunits = mWorkunitsParser.getWorkunits(); + //mCcState.results = mResultsParser.getResults(); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); + if (localName.equalsIgnoreCase("client_state")) { + //Starting the query, clear mCcState + mCcState.clearArrays(); + } if (localName.equalsIgnoreCase("host_info")) { // Just stepped inside mInHostInfo = true; @@ -185,6 +201,10 @@ public class CcStateParser extends BaseParser { if (localName.equalsIgnoreCase("project")) { // Closing tag of mInProject = false; + if(mProjectsParser.getProjects().size() > 0) { + myProject = mProjectsParser.getProjects().get(mProjectsParser.getProjects().size() - 1); + mCcState.projects.add(myProject); + } } } if (mInApp) { @@ -194,6 +214,11 @@ public class CcStateParser extends BaseParser { if (localName.equalsIgnoreCase("app")) { // Closing tag of mInApp = false; + if(mAppsParser.getApps().size() > 0) { + myApp = mAppsParser.getApps().get(mAppsParser.getApps().size() - 1); + myApp.project = myProject; + mCcState.apps.add(myApp); + } } } if (mInAppVersion) { @@ -203,6 +228,12 @@ public class CcStateParser extends BaseParser { if (localName.equalsIgnoreCase("app_version")) { // Closing tag of mInAppVersion = false; + if(mAppVersionsParser.getAppVersions().size() > 0) { + myAppVersion = mAppVersionsParser.getAppVersions().get(mAppVersionsParser.getAppVersions().size() - 1); + myAppVersion.project = myProject; + myAppVersion.app = mCcState.lookup_app(myProject, myAppVersion.app_name); + mCcState.app_versions.add(myAppVersion); + } } } if (mInWorkunit) { @@ -212,6 +243,12 @@ public class CcStateParser extends BaseParser { if (localName.equalsIgnoreCase("workunit")) { // Closing tag of mInWorkunit = false; + if(mWorkunitsParser.getWorkunits().size() > 0) { + myWorkunit = mWorkunitsParser.getWorkunits().get(mWorkunitsParser.getWorkunits().size() - 1); + myWorkunit.project = myProject; + myWorkunit.app = mCcState.lookup_app(myProject, myWorkunit.app_name); + mCcState.workunits.add(myWorkunit); + } } } if (mInResult) { @@ -221,6 +258,18 @@ public class CcStateParser extends BaseParser { if (localName.equalsIgnoreCase("result")) { // Closing tag of mInResult = false; + + if(mResultsParser.getResults().size() > 0) { + myResult = mResultsParser.getResults().get(mResultsParser.getResults().size() - 1); + myResult.project = myProject; + myResult.wup = mCcState.lookup_wu(myProject, myResult.wu_name); + if(myResult.wup != null) { + myResult.app = myResult.wup.app; + myResult.avp = mCcState.lookup_app_version(myProject, myResult.app, myResult.version_num, myResult.plan_class); + + } + mCcState.results.add(myResult); + } } } if (mElementStarted) { diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/Project.java b/android/BOINC/src/edu/berkeley/boinc/rpc/Project.java index b251932506..c688fe01eb 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/Project.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/Project.java @@ -92,4 +92,17 @@ public class Project { public final String getName() { return project_name.equals("") ? master_url : project_name; } + + public boolean compare(Project proj) { + //Test that master_url's match... + if(!this.master_url.equalsIgnoreCase(proj.master_url)) { + return false; + } + + //Test if user_name matches + if(!this.user_name.equalsIgnoreCase(proj.user_name)) { + return false; + } + return true; + } } diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/Result.java b/android/BOINC/src/edu/berkeley/boinc/rpc/Result.java index a0fe013768..6c2b83b362 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/Result.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/Result.java @@ -65,5 +65,10 @@ public class Result { public String slot_path; public String resources = null; + + public Project project; + public AppVersion avp; + public App app; + public Workunit wup; } diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/RpcClient.java b/android/BOINC/src/edu/berkeley/boinc/rpc/RpcClient.java index 9a4887cf2e..79cc3a210d 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/RpcClient.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/RpcClient.java @@ -1103,7 +1103,7 @@ public class RpcClient { return false; } } - + /** * Triggers operation on task in BOINC core client * @param operation operation to be triggered @@ -1139,7 +1139,7 @@ public class RpcClient { mRequest.append(opTag); mRequest.append(">\n"); sendRequest(mRequest.toString()); - + SimpleReplyParser parser = SimpleReplyParser.parse(receiveReply()); if (parser == null) return false; diff --git a/android/BOINC/src/edu/berkeley/boinc/rpc/Workunit.java b/android/BOINC/src/edu/berkeley/boinc/rpc/Workunit.java index 56bf023872..38fb750311 100644 --- a/android/BOINC/src/edu/berkeley/boinc/rpc/Workunit.java +++ b/android/BOINC/src/edu/berkeley/boinc/rpc/Workunit.java @@ -27,4 +27,7 @@ public class Workunit { public double rsc_fpops_bound; public double rsc_memory_bound; public double rsc_disk_bound; + + public Project project; + public App app; }