details: /erp/devel/pi-module-install/rev/04370114620e
changeset: 6470:04370114620e
user: Asier Lostalé <asier.lostale <at> openbravo.com>
date: Mon Feb 22 13:01:24 2010 +0100
summary: Show loading icon when installing modules
details: /erp/devel/pi-module-install/rev/179a803ce69b
changeset: 6471:179a803ce69b
user: Asier Lostalé <asier.lostale <at> openbravo.com>
date: Mon Feb 22 13:08:10 2010 +0100
summary: Improve module installating handling:
-Download obx files to a local folder before start unzipping them
-Check the downloaded size is the expecte one
-Do not delete old version of modules to update till all modules have been
locally saved
-In case of a core update, do not start downloading it till the rest of
modules have been successfully downloaded
-In case of a core update, do not start installing till the rest of modules
have been successfully installed
-In case of a core update, preserve WebContent directory (allowing using the
UI console serving from eclipse)
-Improved rollback handling
-Installation log (log4j) is now more verbose
diffstat:
src/org/openbravo/erpCommon/ad_forms/ModuleManagement_InstallP2.html | 4 +-
src/org/openbravo/erpCommon/modules/ImportModule.java | 555
++++++---
src/org/openbravo/erpCommon/modules/ImportModule_data.xsql | 18 +-
src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java | 51 +-
src/org/openbravo/erpCommon/modules/RemoteModule.java | 52 +
5 files changed, 438 insertions(+), 242 deletions(-)
diffs (truncated from 899 to 300 lines):
diff -r 46957ab44fec -r 179a803ce69b
src/org/openbravo/erpCommon/ad_forms/ModuleManagement_InstallP2.html
--- a/src/org/openbravo/erpCommon/ad_forms/ModuleManagement_InstallP2.html
Mon Feb 22 10:22:54 2010 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/ModuleManagement_InstallP2.html
Mon Feb 22 13:08:10 2010 +0100
@@ -11,7 +11,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SL
- * All portions are Copyright (C) 2008-2009 Openbravo SL
+ * All portions are Copyright (C) 2008-2010 Openbravo SL
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
@@ -325,7 +325,7 @@
<button type="button"
id="buttonContinue"
class="ButtonLink"
- onclick="submitCommandForm('INSTALL3', false, null,
'ModuleManagement.html', '_self', null, false);return false;"
+ onclick="setProcessingMode('popup', true);
submitCommandForm('INSTALL3', false, null, 'ModuleManagement.html', '_self',
null, false);return false;"
onfocus="buttonEvent('onfocus', this);
window.status='Continue'; return true;"
onblur="buttonEvent('onblur', this);"
onkeyup="buttonEvent('onkeyup', this);"
diff -r 46957ab44fec -r 179a803ce69b
src/org/openbravo/erpCommon/modules/ImportModule.java
--- a/src/org/openbravo/erpCommon/modules/ImportModule.java Mon Feb 22
10:22:54 2010 +0100
+++ b/src/org/openbravo/erpCommon/modules/ImportModule.java Mon Feb 22
13:08:10 2010 +0100
@@ -22,9 +22,12 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
+import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
@@ -242,7 +245,27 @@
final ModuleInstallDetail mid = VersionUtility.checkRemote(vars,
installableModules,
updateableModules, errors);
modulesToInstall = mid.getModulesToInstall();
- modulesToUpdate = mid.getModulesToUpdate();
+
+ // In case core is in the list of modules to update, put in at the last
module to update, so it
+ // will be updated only in case the rest of modules were successfully
downloaded and updated.
+ Module[] updateModuleAux = mid.getModulesToUpdate();
+ modulesToUpdate = new Module[updateModuleAux.length];
+ int i = 0;
+ boolean updatingCore = false;
+ Module core = null;
+ for (Module module : updateModuleAux) {
+ if (!module.getModuleID().equals("0")) {
+ modulesToUpdate[i] = module;
+ i++;
+ } else {
+ updatingCore = true;
+ core = module;
+ }
+ }
+ if (updatingCore) {
+ modulesToUpdate[i] = core;
+ }
+
checked = mid.isValidConfiguration();
return checked;
@@ -284,33 +307,16 @@
try {
if (checked || force) {
if (installLocally) {
- initInstallation();
+ for (Module module : modulesToUpdate) {
+ preapreUpdate(module);
+ }
- final String moduleToInstallID = (modulesToInstall != null &&
modulesToInstall.length > 0) ? modulesToInstall[0]
- .getModuleID()
- : modulesToUpdate[0].getModuleID();
-
- final Vector<DynaBean> dynMod = new Vector<DynaBean>();
- final Vector<DynaBean> dynDep = new Vector<DynaBean>();
- final Vector<DynaBean> dynDbPrefix = new Vector<DynaBean>();
-
- installModule(file, moduleToInstallID, dynMod, dynDep, dynDbPrefix);
-
- if (moduleToInstallID.equals("0"))
- Utility.mergeOpenbravoProperties(obDir +
"/config/Openbravo.properties", obDir
- + "/config/Openbravo.properties.template");
-
- final Vector<DynaBean> allModules = new Vector<DynaBean>(); // all
- // modules
- // include
- // install
- // and
- // update
- allModules.addAll(dynModulesToInstall);
- allModules.addAll(dynModulesToUpdate);
- insertDynaModulesInDB(allModules, dependencies, dbprefix);
- insertDBLog();
- addDynaClasspathEntries(dynModulesToInstall);
+ // Just pick the first module, to install/update as the rest of them
are inside the obx
+ // file
+ Module module = (modulesToInstall != null && modulesToInstall.length
> 0) ? modulesToInstall[0]
+ : modulesToUpdate[0];
+ installLocalModule(module, file,
+ (modulesToInstall != null && modulesToInstall.length > 0));
} else { // install remotely
execute();
}
@@ -336,105 +342,211 @@
public void execute() {
// just for remote installation, modules to install and update must be
// initialized
- WebServiceImplServiceLocator loc;
- WebServiceImpl ws = null;
- try {
- loc = new WebServiceImplServiceLocator();
- ws = loc.getWebService();
- } catch (final Exception e) {
- log4j.error(e);
- addLog("@CouldntConnectToWS@", MSG_ERROR);
- try {
- ImportModuleData.insertLog(pool, (vars == null ? "0" :
vars.getUser()), "", "", "",
- "Couldn't contact with webservice server", "E");
- } catch (final ServletException ex) {
- ex.printStackTrace();
- }
- return;
- }
if (checked || force) {
- initInstallation();
if ((modulesToInstall == null || modulesToInstall.length == 0)
&& (modulesToUpdate == null || modulesToUpdate.length == 0)) {
addLog("@ErrorNoModulesToInstall@", MSG_ERROR);
return;
}
+ if (downloadAllModules()) {
+ // if failed downloading, exit installation, no rollback is needed
since no actual sources
+ // were changed
+ installAllModules();
+ }
+ cleanTmp();
+ }
+ }
- if (modulesToInstall != null) {
- for (int i = 0; i < modulesToInstall.length; i++) {
- try {
- // get remote module obx
- InputStream obx = ModuleUtiltiy.getRemoteModule(this,
modulesToInstall[i]
- .getModuleVersionID());
- if (obx == null) {
- return;
- }
+ /**
+ * Removes tmp directory where downloaded obx files are temporary stored
+ */
+ private void cleanTmp() {
+ File tmp = new File(obDir + "/tmp");
+ if (tmp.exists()) {
+ log4j.info("Cleaning " + tmp);
+ Utility.deleteDir(tmp);
+ }
+ }
- final Vector<DynaBean> dynMod = new Vector<DynaBean>();
- final Vector<DynaBean> dynDep = new Vector<DynaBean>();
- final Vector<DynaBean> dynDbPrefix = new Vector<DynaBean>();
- installModule(obx, modulesToInstall[i].getModuleID(), dynMod,
dynDep, dynDbPrefix);
+ /**
+ * Downloads all the modules to install/update in the tmp directory. If any
error occurs during
+ * this process, the process is aborted.
+ */
+ private boolean downloadAllModules() {
+ final File dir = new File(obDir + "/tmp");
+ if (!dir.exists())
+ dir.mkdirs();
- // Add entries in .classpath for eclipse users
- insertDynaModulesInDB(dynMod, dynDep, dynDbPrefix);
- addDynaClasspathEntries(dynMod);
- } catch (final Exception e) {
- log4j.error(e.getMessage(), e);
- if (!(e instanceof PermissionException)) {
- addLog("@ErrorGettingModule@", MSG_ERROR);
- }
- rollback();
- try {
- ImportModuleData.insertLog(pool, (vars == null ? "0" :
vars.getUser()), "", "", "",
- "Error getting module " + modulesToInstall[i].getName() + "
- "
- + modulesToInstall[i].getVersionNo(), "E");
- } catch (final ServletException ex) {
- ex.printStackTrace();
- }
- return;
+ for (Module module : modulesToInstall) {
+ if (!downloadRemoteModule(module)) {
+ return false;
+ }
+ }
+ for (Module module : modulesToUpdate) {
+ if (!downloadRemoteModule(module)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Downloads a remote module in the tmp directory.
+ */
+ private boolean downloadRemoteModule(Module module) {
+ log4j.info("Downloading " + module.getPackageName() + " " +
module.getVersionNo());
+ RemoteModule remoteModule = ModuleUtiltiy.getRemoteModule(this,
module.getModuleVersionID());
+
+ if (remoteModule.isError()) {
+ log4j.error("Error downloading module");
+ return false;
+ }
+
+ InputStream obx = remoteModule.getObx();
+ File file = new File(obDir + "/tmp/" + module.getPackageName() + "-" +
module.getVersionNo()
+ + ".obx");
+ log4j.info("File size " + remoteModule.getSize() + " B. Temporary saving
in " + file);
+ FileOutputStream fout = null;
+ try {
+ fout = new FileOutputStream(file);
+ } catch (FileNotFoundException e1) {
+ log4j.error("Error downloading obx, couldn't create file", e1);
+ addLog(module.getName() + "(" + module.getPackageName() + ")
@CannotDownloadModule@ " + file,
+ MSG_ERROR);
+ return false;
+ }
+ final byte[] buf = new byte[1024];
+ int len;
+ long size = 0;
+ int i = 0;
+ DecimalFormat formatter = new DecimalFormat("###.##");
+ try {
+ // log download, each 10% for big files, each 10K for smaller ones
+ int loopsToLog = 10;
+ if (remoteModule.getSize() != null) {
+ try {
+ loopsToLog = (remoteModule.getSize() / 1024) / 10;
+ if (loopsToLog < 10) {
+ loopsToLog = 10;
+ }
+ } catch (Exception e) {
+ loopsToLog = 10;
+ }
+ }
+ while ((len = obx.read(buf)) > 0) {
+
+ size += len;
+ fout.write(buf, 0, len);
+ if (remoteModule.getSize() != null) {
+ // Print download status log
+ i++;
+ if (i % loopsToLog == 0) {
+ // Do not print for each loop: do it each 30 times (just for big
enough modules)
+ Double percentage = new Double(size) / new
Double(remoteModule.getSize()) * 100;
+ String per = formatter.format(percentage);
+ log4j.info(" ...downloaded " + size + " " + per + "%");
}
}
}
+ fout.close();
+ obx.close();
- if (modulesToUpdate != null) {
- for (int i = 0; i < modulesToUpdate.length; i++) {
- try {
- // get remote module obx
- InputStream obx = ModuleUtiltiy.getRemoteModule(this,
modulesToUpdate[i]
- .getModuleVersionID());
- if (obx == null) {
- return;
- }
+ // Check the obx file has been fully downloaded. This is done now by
just checking the
+ // dowloaded size is the expected one. In future CRC should be done to
guarranty the file is
+ // not corrupt, this would require a new service in CR.
+ if (remoteModule.getSize() == null || remoteModule.getSize() == size) {
+ log4j.info(" Downloaded " + size + " 100% -- OK");
+ return true;
+ } else {
+ addLog(module.getName() + "(" + module.getPackageName() + ")
@IncompleteModuleDownload@ "
+ + remoteModule.getSize() + "/" + size, MSG_ERROR);
+ return false;
+ }
+ } catch (IOException e) {
+ addLog(module.getName() + "(" + module.getPackageName() + ")
@ErrorGettingModule@ "
+ + e.getMessage(), MSG_ERROR);
+ return false;
+ }
- final Vector<DynaBean> dynMod = new Vector<DynaBean>();
- final Vector<DynaBean> dynDep = new Vector<DynaBean>();
- final Vector<DynaBean> dynDBPrefix = new Vector<DynaBean>();
- installModule(obx, modulesToUpdate[i].getModuleID(), dynMod,
dynDep, dynDBPrefix);
+ }
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits