IDEMPIERE-2771 implement semaphore in internal 2packs to avoid multiple servers applying same 2pack / Fixes for semaphore implementation

This commit is contained in:
Carlos Ruiz 2018-11-10 23:21:17 -02:00
parent bc99a2669c
commit e98698cd89
5 changed files with 45 additions and 33 deletions

View File

@ -43,7 +43,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
protected BundleContext context;
protected ServiceTracker<IDictionaryService, IDictionaryService> serviceTracker;
protected IDictionaryService service;
private String trxName = "";
private String trxName = null;
private ProcessInfo m_processInfo = null;
private IProcessUI m_processUI = null;
@ -54,7 +54,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
service.merge(context, zipfile);
success = true;
} 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;
@ -77,7 +77,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
addLog(Level.SEVERE, "Could not find an IDictionaryService to process the zip files");
}
} else {
addLog(Level.SEVERE, "The file was previously installed: " + zipfile.getName());
addLog(Level.WARNING, "The file was previously installed: " + zipfile.getName());
success = true;
}
@ -107,15 +107,24 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack
while(maxAttempts > 0 && !lockAcquired) {
maxAttempts --;
if (logger.isLoggable(Level.INFO)) logger.log(Level.INFO, "Acquiring lock with timeout " + timeout + " for " + getName() + " / remaining attempts " + maxAttempts);
try {
if (getDBLock(timeout))
lockAcquired = true;
} catch (Exception e) {
// Timeout throws DBException, ignore and try again
releaseLock();
}
}
return lockAcquired;
}
public void releaseLock() {
if (trxName != null) {
Trx.get(trxName, false).close();
trxName = null;
}
}
private boolean getDBLock(int timeout) throws AdempiereSystemError {

View File

@ -60,16 +60,17 @@ public class AdempiereActivator extends AbstractActivator {
if (pkg == null) {
try {
if (getDBLock()) {
System.out.println("Installing " + getName() + " " + version + " ...");
logger.log(Level.WARNING, "Installing " + getName() + " " + version + " ...");
packIn();
install();
releaseLock();
System.out.println(getName() + " " + version + " installed.");
logger.log(Level.WARNING, getName() + " " + version + " installed.");
} 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) {
e.printStackTrace();
} finally {
releaseLock();
}
} else {
if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + version + " was installed: "
@ -121,7 +122,7 @@ public class AdempiereActivator extends AbstractActivator {
// call 2pack
merge(zipfile, getPKVersion());
} catch (Throwable e) {
logger.log(Level.SEVERE, "Pack in failed.", e);
logger.log(Level.WARNING, "Pack in failed.", e);
}
finally{
if (zipstream != null) {

View File

@ -157,7 +157,7 @@ public class Incremental2PackActivator extends AbstractActivator {
}
}
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());
pi.setName(getName());
@ -175,7 +175,7 @@ public class Incremental2PackActivator extends AbstractActivator {
trx.commit(true);
} catch (Exception e) {
trx.rollback();
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
logger.log(Level.WARNING, e.getLocalizedMessage(), e);
} finally {
trx.close();
}
@ -197,12 +197,13 @@ public class Incremental2PackActivator extends AbstractActivator {
}
}
}
releaseLock();
} 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) {
e.printStackTrace();
} finally {
releaseLock();
}
}
@ -220,7 +221,7 @@ public class Incremental2PackActivator extends AbstractActivator {
MSession.get(Env.getCtx(), true);
String path = packout.getPath();
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
System.out.println("Installing " + getName() + " " + path + " ...");
logger.log(Level.WARNING, "Installing " + getName() + " " + path + " ...");
FileOutputStream zipstream = null;
try {
// 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)))
return false;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Pack in failed.", e);
logger.log(Level.WARNING, "Pack in failed.", e);
return false;
} finally{
if (zipstream != null) {
@ -245,7 +246,7 @@ public class Incremental2PackActivator extends AbstractActivator {
} catch (Exception e2) {}
}
}
System.out.println(getName() + " " + packout.getPath() + " installed");
logger.log(Level.WARNING, getName() + " " + packout.getPath() + " installed");
}
return true;
}

View File

@ -167,19 +167,19 @@ public class PackInApplicationActivator extends AbstractActivator {
currentFile = zipFile;
if (!packIn(zipFile)) {
// stop processing further packages if one fail
addLog(Level.SEVERE, "Failed application of " + zipFile);
addLog(Level.WARNING, "Failed application of " + zipFile);
break;
}
addLog(Level.INFO, "Successful application of " + zipFile);
filesToProcess.remove(zipFile);
}
} 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;
}
} catch (AdempiereSystemError e) {
e.printStackTrace();
addLog(Level.SEVERE, e.getLocalizedMessage());
addLog(Level.WARNING, e.getLocalizedMessage());
} finally {
releaseLock();
}
@ -212,7 +212,7 @@ public class PackInApplicationActivator extends AbstractActivator {
seedClientValue = clientValue.split("-")[2];
seedClientIDs = getClientIDs(seedClientValue);
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;
}
}
@ -234,7 +234,7 @@ public class PackInApplicationActivator extends AbstractActivator {
} else {
clientIDs = getClientIDs(clientValue);
if (clientIDs.length == 0) {
logger.log(Level.SEVERE, "Client does not exist: " + clientValue);
logger.log(Level.WARNING, "Client does not exist: " + clientValue);
return false;
}
}
@ -258,7 +258,7 @@ public class PackInApplicationActivator extends AbstractActivator {
}
}
} catch (Throwable e) {
logger.log(Level.SEVERE, "Pack in failed.", e);
logger.log(Level.WARNING, "Pack in failed.", e);
return false;
} finally {
Env.setContext(Env.getCtx(), "#AD_Client_ID", 0);
@ -299,7 +299,7 @@ public class PackInApplicationActivator extends AbstractActivator {
for (String filePath : filePaths) {
File toProcess = new File(filePath.trim());
if (!toProcess.exists()) {
addLog(Level.SEVERE, filePath + " does not exist");
addLog(Level.WARNING, filePath + " does not exist");
continue;
}
@ -326,7 +326,7 @@ public class PackInApplicationActivator extends AbstractActivator {
if (toProcess.getName().toLowerCase().endsWith(".zip"))
filesToProcess.add(toProcess);
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;
}
} else if (toProcess.isDirectory() && toProcess.canRead()) {
@ -350,7 +350,7 @@ public class PackInApplicationActivator extends AbstractActivator {
if (fileToProcess.canRead()) {
filesToProcess.add(fileToProcess);
} 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;
}
} 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");
}
}

View File

@ -169,12 +169,13 @@ public class Version2PackActivator extends AbstractActivator {
break;
}
}
releaseLock();
} 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) {
e.printStackTrace();
} finally {
releaseLock();
}
}
@ -190,7 +191,7 @@ public class Version2PackActivator extends AbstractActivator {
if (packout != null && service != null) {
String path = packout.getPath();
String suffix = "_"+path.substring(path.lastIndexOf("2Pack_"));
System.out.println("Installing " + getName() + " " + path + " ...");
logger.log(Level.WARNING, "Installing " + getName() + " " + path + " ...");
FileOutputStream zipstream = null;
try {
// 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)))
return false;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Pack in failed.", e);
logger.log(Level.WARNING, "Pack in failed.", e);
return false;
} finally{
if (zipstream != null) {
@ -215,7 +216,7 @@ public class Version2PackActivator extends AbstractActivator {
} catch (Exception e2) {}
}
}
System.out.println(getName() + " " + packout.getPath() + " installed");
logger.log(Level.WARNING, getName() + " " + packout.getPath() + " installed");
}
return true;
}