IDEMPIERE-2771 implement semaphore in internal 2packs to avoid multiple servers applying same 2pack / Fixes for semaphore implementation
This commit is contained in:
parent
bc99a2669c
commit
e98698cd89
|
@ -43,7 +43,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
|
||||||
protected BundleContext context;
|
protected BundleContext context;
|
||||||
protected ServiceTracker<IDictionaryService, IDictionaryService> serviceTracker;
|
protected ServiceTracker<IDictionaryService, IDictionaryService> serviceTracker;
|
||||||
protected IDictionaryService service;
|
protected IDictionaryService service;
|
||||||
private String trxName = "";
|
private String trxName = null;
|
||||||
private ProcessInfo m_processInfo = null;
|
private ProcessInfo m_processInfo = null;
|
||||||
private IProcessUI m_processUI = null;
|
private IProcessUI m_processUI = null;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
|
||||||
service.merge(context, zipfile);
|
service.merge(context, zipfile);
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.SEVERE, "The file was previously installed: " + zipfile.getName());
|
logger.log(Level.WARNING, "The file was previously installed: " + zipfile.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -77,7 +77,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
|
||||||
addLog(Level.SEVERE, "Could not find an IDictionaryService to process the zip files");
|
addLog(Level.SEVERE, "Could not find an IDictionaryService to process the zip files");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addLog(Level.SEVERE, "The file was previously installed: " + zipfile.getName());
|
addLog(Level.WARNING, "The file was previously installed: " + zipfile.getName());
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,15 +107,24 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
|
||||||
|
|
||||||
while(maxAttempts > 0 && !lockAcquired) {
|
while(maxAttempts > 0 && !lockAcquired) {
|
||||||
maxAttempts --;
|
maxAttempts --;
|
||||||
if (getDBLock(timeout))
|
if (logger.isLoggable(Level.INFO)) logger.log(Level.INFO, "Acquiring lock with timeout " + timeout + " for " + getName() + " / remaining attempts " + maxAttempts);
|
||||||
lockAcquired = true;
|
try {
|
||||||
|
if (getDBLock(timeout))
|
||||||
|
lockAcquired = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Timeout throws DBException, ignore and try again
|
||||||
|
releaseLock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lockAcquired;
|
return lockAcquired;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseLock() {
|
public void releaseLock() {
|
||||||
Trx.get(trxName, false).close();
|
if (trxName != null) {
|
||||||
|
Trx.get(trxName, false).close();
|
||||||
|
trxName = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getDBLock(int timeout) throws AdempiereSystemError {
|
private boolean getDBLock(int timeout) throws AdempiereSystemError {
|
||||||
|
|
|
@ -60,16 +60,17 @@ public class AdempiereActivator extends AbstractActivator {
|
||||||
if (pkg == null) {
|
if (pkg == null) {
|
||||||
try {
|
try {
|
||||||
if (getDBLock()) {
|
if (getDBLock()) {
|
||||||
System.out.println("Installing " + getName() + " " + version + " ...");
|
logger.log(Level.WARNING, "Installing " + getName() + " " + version + " ...");
|
||||||
packIn();
|
packIn();
|
||||||
install();
|
install();
|
||||||
releaseLock();
|
logger.log(Level.WARNING, getName() + " " + version + " installed.");
|
||||||
System.out.println(getName() + " " + version + " installed.");
|
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.SEVERE, "Could not acquire the DB lock to install:" + getName());
|
logger.log(Level.WARNING, "Could not acquire the DB lock to install:" + getName());
|
||||||
}
|
}
|
||||||
} catch (AdempiereSystemError e) {
|
} catch (AdempiereSystemError e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
releaseLock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + version + " was installed: "
|
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + version + " was installed: "
|
||||||
|
@ -121,7 +122,7 @@ public class AdempiereActivator extends AbstractActivator {
|
||||||
// call 2pack
|
// call 2pack
|
||||||
merge(zipfile, getPKVersion());
|
merge(zipfile, getPKVersion());
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.log(Level.SEVERE, "Pack in failed.", e);
|
logger.log(Level.WARNING, "Pack in failed.", e);
|
||||||
}
|
}
|
||||||
finally{
|
finally{
|
||||||
if (zipstream != null) {
|
if (zipstream != null) {
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class Incremental2PackActivator extends AbstractActivator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (patch) {
|
if (patch) {
|
||||||
System.out.println("Patch Meta Data for " + getName() + " " + entry.version + " ...");
|
logger.log(Level.WARNING, "Patch Meta Data for " + getName() + " " + entry.version + " ...");
|
||||||
|
|
||||||
X_AD_Package_Imp pi = new X_AD_Package_Imp(Env.getCtx(), 0, trx.getTrxName());
|
X_AD_Package_Imp pi = new X_AD_Package_Imp(Env.getCtx(), 0, trx.getTrxName());
|
||||||
pi.setName(getName());
|
pi.setName(getName());
|
||||||
|
@ -175,7 +175,7 @@ public class Incremental2PackActivator extends AbstractActivator {
|
||||||
trx.commit(true);
|
trx.commit(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
trx.rollback();
|
trx.rollback();
|
||||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
logger.log(Level.WARNING, e.getLocalizedMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
trx.close();
|
trx.close();
|
||||||
}
|
}
|
||||||
|
@ -197,12 +197,13 @@ public class Incremental2PackActivator extends AbstractActivator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
releaseLock();
|
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.SEVERE, "Could not acquire the DB lock to install:" + getName());
|
logger.log(Level.WARNING, "Could not acquire the DB lock to install:" + getName());
|
||||||
}
|
}
|
||||||
} catch (AdempiereSystemError e) {
|
} catch (AdempiereSystemError e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
releaseLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +221,7 @@ public class Incremental2PackActivator extends AbstractActivator {
|
||||||
MSession.get(Env.getCtx(), true);
|
MSession.get(Env.getCtx(), true);
|
||||||
String path = packout.getPath();
|
String path = packout.getPath();
|
||||||
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
|
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
|
||||||
System.out.println("Installing " + getName() + " " + path + " ...");
|
logger.log(Level.WARNING, "Installing " + getName() + " " + path + " ...");
|
||||||
FileOutputStream zipstream = null;
|
FileOutputStream zipstream = null;
|
||||||
try {
|
try {
|
||||||
// copy the resource to a temporary file to process it with 2pack
|
// copy the resource to a temporary file to process it with 2pack
|
||||||
|
@ -236,7 +237,7 @@ public class Incremental2PackActivator extends AbstractActivator {
|
||||||
if (!merge(zipfile, extractVersionString(packout)))
|
if (!merge(zipfile, extractVersionString(packout)))
|
||||||
return false;
|
return false;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.log(Level.SEVERE, "Pack in failed.", e);
|
logger.log(Level.WARNING, "Pack in failed.", e);
|
||||||
return false;
|
return false;
|
||||||
} finally{
|
} finally{
|
||||||
if (zipstream != null) {
|
if (zipstream != null) {
|
||||||
|
@ -245,7 +246,7 @@ public class Incremental2PackActivator extends AbstractActivator {
|
||||||
} catch (Exception e2) {}
|
} catch (Exception e2) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(getName() + " " + packout.getPath() + " installed");
|
logger.log(Level.WARNING, getName() + " " + packout.getPath() + " installed");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,19 +167,19 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
currentFile = zipFile;
|
currentFile = zipFile;
|
||||||
if (!packIn(zipFile)) {
|
if (!packIn(zipFile)) {
|
||||||
// stop processing further packages if one fail
|
// stop processing further packages if one fail
|
||||||
addLog(Level.SEVERE, "Failed application of " + zipFile);
|
addLog(Level.WARNING, "Failed application of " + zipFile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
addLog(Level.INFO, "Successful application of " + zipFile);
|
addLog(Level.INFO, "Successful application of " + zipFile);
|
||||||
filesToProcess.remove(zipFile);
|
filesToProcess.remove(zipFile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addLog(Level.SEVERE, "Could not acquire the DB lock to automatically install the packins");
|
addLog(Level.WARNING, "Could not acquire the DB lock to automatically install the packins");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (AdempiereSystemError e) {
|
} catch (AdempiereSystemError e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
addLog(Level.SEVERE, e.getLocalizedMessage());
|
addLog(Level.WARNING, e.getLocalizedMessage());
|
||||||
} finally {
|
} finally {
|
||||||
releaseLock();
|
releaseLock();
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
seedClientValue = clientValue.split("-")[2];
|
seedClientValue = clientValue.split("-")[2];
|
||||||
seedClientIDs = getClientIDs(seedClientValue);
|
seedClientIDs = getClientIDs(seedClientValue);
|
||||||
if (seedClientIDs.length == 0) {
|
if (seedClientIDs.length == 0) {
|
||||||
logger.log(Level.SEVERE, "Seed client does not exist: " + seedClientValue);
|
logger.log(Level.WARNING, "Seed client does not exist: " + seedClientValue);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
} else {
|
} else {
|
||||||
clientIDs = getClientIDs(clientValue);
|
clientIDs = getClientIDs(clientValue);
|
||||||
if (clientIDs.length == 0) {
|
if (clientIDs.length == 0) {
|
||||||
logger.log(Level.SEVERE, "Client does not exist: " + clientValue);
|
logger.log(Level.WARNING, "Client does not exist: " + clientValue);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.log(Level.SEVERE, "Pack in failed.", e);
|
logger.log(Level.WARNING, "Pack in failed.", e);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
Env.setContext(Env.getCtx(), "#AD_Client_ID", 0);
|
Env.setContext(Env.getCtx(), "#AD_Client_ID", 0);
|
||||||
|
@ -299,7 +299,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
for (String filePath : filePaths) {
|
for (String filePath : filePaths) {
|
||||||
File toProcess = new File(filePath.trim());
|
File toProcess = new File(filePath.trim());
|
||||||
if (!toProcess.exists()) {
|
if (!toProcess.exists()) {
|
||||||
addLog(Level.SEVERE, filePath + " does not exist");
|
addLog(Level.WARNING, filePath + " does not exist");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
if (toProcess.getName().toLowerCase().endsWith(".zip"))
|
if (toProcess.getName().toLowerCase().endsWith(".zip"))
|
||||||
filesToProcess.add(toProcess);
|
filesToProcess.add(toProcess);
|
||||||
else {
|
else {
|
||||||
logger.log(Level.SEVERE, toProcess.getName() + " is not a valid .zip file");
|
logger.log(Level.WARNING, toProcess.getName() + " is not a valid .zip file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (toProcess.isDirectory() && toProcess.canRead()) {
|
} else if (toProcess.isDirectory() && toProcess.canRead()) {
|
||||||
|
@ -350,7 +350,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
if (fileToProcess.canRead()) {
|
if (fileToProcess.canRead()) {
|
||||||
filesToProcess.add(fileToProcess);
|
filesToProcess.add(fileToProcess);
|
||||||
} else {
|
} else {
|
||||||
addLog(Level.SEVERE, fileToProcess.getName() + " not readable");
|
addLog(Level.WARNING, fileToProcess.getName() + " not readable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,7 +359,7 @@ public class PackInApplicationActivator extends AbstractActivator {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addLog(Level.SEVERE, toProcess.getName() + " not a file or folder or not readable");
|
addLog(Level.WARNING, toProcess.getName() + " not a file or folder or not readable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,12 +169,13 @@ public class Version2PackActivator extends AbstractActivator {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
releaseLock();
|
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.SEVERE, "Could not acquire the DB lock to install:" + getName());
|
logger.log(Level.WARNING, "Could not acquire the DB lock to install:" + getName());
|
||||||
}
|
}
|
||||||
} catch (AdempiereSystemError e) {
|
} catch (AdempiereSystemError e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
releaseLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +191,7 @@ public class Version2PackActivator extends AbstractActivator {
|
||||||
if (packout != null && service != null) {
|
if (packout != null && service != null) {
|
||||||
String path = packout.getPath();
|
String path = packout.getPath();
|
||||||
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
|
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
|
||||||
System.out.println("Installing " + getName() + " " + path + " ...");
|
logger.log(Level.WARNING, "Installing " + getName() + " " + path + " ...");
|
||||||
FileOutputStream zipstream = null;
|
FileOutputStream zipstream = null;
|
||||||
try {
|
try {
|
||||||
// copy the resource to a temporary file to process it with 2pack
|
// copy the resource to a temporary file to process it with 2pack
|
||||||
|
@ -206,7 +207,7 @@ public class Version2PackActivator extends AbstractActivator {
|
||||||
if (!merge(zipfile, extractVersionString(packout)))
|
if (!merge(zipfile, extractVersionString(packout)))
|
||||||
return false;
|
return false;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.log(Level.SEVERE, "Pack in failed.", e);
|
logger.log(Level.WARNING, "Pack in failed.", e);
|
||||||
return false;
|
return false;
|
||||||
} finally{
|
} finally{
|
||||||
if (zipstream != null) {
|
if (zipstream != null) {
|
||||||
|
@ -215,7 +216,7 @@ public class Version2PackActivator extends AbstractActivator {
|
||||||
} catch (Exception e2) {}
|
} catch (Exception e2) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(getName() + " " + packout.getPath() + " installed");
|
logger.log(Level.WARNING, getName() + " " + packout.getPath() + " installed");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue