Updated ThreadPool support
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@142689 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
62c36f80b6
commit
7a571eed0b
|
@ -35,6 +35,7 @@ public class AccountingClientDaemon implements Runnable {
|
|||
private volatile boolean running = true;
|
||||
private volatile AccountingCache accountingCache;
|
||||
private ArrayList<TaskInProgress> tasks;
|
||||
private long timeout=Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS;
|
||||
|
||||
public AccountingClientDaemon(ServletContextEvent sce,
|
||||
AccountingCache accountingCache) {
|
||||
|
@ -78,8 +79,8 @@ public class AccountingClientDaemon implements Runnable {
|
|||
TaskStatus result = null;
|
||||
try {
|
||||
result = futureResult
|
||||
.get(Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS,
|
||||
TimeUnit.MINUTES);
|
||||
.get(timeout,
|
||||
TimeUnit.MILLISECONDS);
|
||||
logger.info("AccountingClientTask: " + result);
|
||||
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
|
@ -88,8 +89,8 @@ public class AccountingClientDaemon implements Runnable {
|
|||
+ e.getLocalizedMessage(), e);
|
||||
} catch (TimeoutException e) {
|
||||
logger.error("AccountingClientTask No response after "
|
||||
+ Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS
|
||||
+ " minutes!");
|
||||
+ timeout
|
||||
+ " milliseconds!");
|
||||
futureResult.cancel(true);
|
||||
}
|
||||
dones.add(taskInProgress);
|
||||
|
@ -98,7 +99,7 @@ public class AccountingClientDaemon implements Runnable {
|
|||
long diff = now.getTimeInMillis()
|
||||
- taskInProgress.getStartTime()
|
||||
.getTimeInMillis();
|
||||
if (diff > Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS) {
|
||||
if (diff > timeout) {
|
||||
futureResult.cancel(true);
|
||||
dones.add(taskInProgress);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package org.gcube.portlets.admin.accountingmanager.server.is;
|
||||
|
||||
import org.gcube.portlets.admin.accountingmanager.server.util.ThreadPoolInfo;
|
||||
import org.gcube.portlets.admin.accountingmanager.shared.Constants;
|
||||
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class BuildThreadPoolInfo {
|
||||
|
||||
private static Logger logger = LoggerFactory
|
||||
.getLogger(BuildThreadPoolInfo.class);
|
||||
|
||||
public static ThreadPoolInfo build(String scope) throws ServiceException {
|
||||
ThreadPoolInfo threadPoolInfo=null;
|
||||
|
||||
if (Constants.DEBUG_MODE) {
|
||||
logger.info("AccountingManager use default configuration for threadpool [scope="+scope+"]");
|
||||
threadPoolInfo=new ThreadPoolInfo(Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS);
|
||||
} else {
|
||||
ThreadPoolJAXB threadPoolJAXB=null;
|
||||
try {
|
||||
threadPoolJAXB= InformationSystemUtils
|
||||
.retrieveThreadPoolTimeout(scope);
|
||||
} catch(ServiceException e){
|
||||
logger.info(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
logger.debug("ThreadPool: " + threadPoolJAXB);
|
||||
if (threadPoolJAXB != null && threadPoolJAXB.getTimeout() != null
|
||||
&& !threadPoolJAXB.getTimeout().isEmpty()) {
|
||||
long timeout=0;
|
||||
try {
|
||||
timeout=Long.parseLong(threadPoolJAXB.getTimeout());
|
||||
}catch(NumberFormatException e){
|
||||
logger.error("AccountingManager invalid timeout set in threadpool resource",e);
|
||||
}
|
||||
|
||||
if(timeout==0){
|
||||
logger.info("AccountingManager use default configuration for threadpool [scope="+scope+"]");
|
||||
threadPoolInfo=new ThreadPoolInfo(Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS);
|
||||
} else {
|
||||
logger.info("AccountingManager use timeout="+timeout+" for threadpool [scope="+scope+"]");
|
||||
threadPoolInfo=new ThreadPoolInfo(timeout);
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.info("AccountingManager use default configuration for threadpool [scope="+scope+"]");
|
||||
threadPoolInfo=new ThreadPoolInfo(Constants.SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("ThreadPoolInfo: " + threadPoolInfo);
|
||||
return threadPoolInfo;
|
||||
}
|
||||
|
||||
}
|
|
@ -35,7 +35,9 @@ public class InformationSystemUtils {
|
|||
return null;
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
logger.debug("Retrieve enabletab configuration in scope: "+scope);
|
||||
|
||||
|
||||
SimpleQuery query = ICFactory.queryFor(GenericResource.class);
|
||||
query.addCondition(
|
||||
"$resource/Profile/SecondaryType/text() eq '"
|
||||
|
@ -103,5 +105,87 @@ public class InformationSystemUtils {
|
|||
throw new ServiceException(error, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ThreadPoolJAXB retrieveThreadPoolTimeout(String scope)
|
||||
throws ServiceException {
|
||||
try {
|
||||
|
||||
if (scope == null || scope.length() == 0)
|
||||
return null;
|
||||
logger.debug("Retrieve threadpool configuration in scope: "+scope);
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
SimpleQuery query = ICFactory.queryFor(GenericResource.class);
|
||||
query.addCondition(
|
||||
"$resource/Profile/SecondaryType/text() eq '"
|
||||
+ Constants.ACCOUNTING_CATEGORY + "'")
|
||||
.addCondition(
|
||||
"$resource/Profile/Name/text() eq '"
|
||||
+ Constants.ACCOUNTING_POOL_NAME + "'")
|
||||
.setResult("$resource");
|
||||
|
||||
DiscoveryClient<GenericResource> client = ICFactory
|
||||
.clientFor(GenericResource.class);
|
||||
List<GenericResource> accountingResources = client.submit(query);
|
||||
logger.debug("Resources: " + accountingResources);
|
||||
|
||||
ThreadPoolJAXB threadPool = null;
|
||||
|
||||
for (GenericResource genericResource : accountingResources) {
|
||||
if (genericResource.scopes() != null) {
|
||||
ScopeGroup<String> scopes = genericResource.scopes();
|
||||
Iterator<String> iterator = scopes.iterator();
|
||||
String scopeFound = null;
|
||||
boolean found = false;
|
||||
while (iterator.hasNext() && !found) {
|
||||
scopeFound = iterator.next();
|
||||
if (scopeFound.compareTo(scope) == 0) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
try {
|
||||
JAXBParser<ThreadPoolJAXB> parser = new JAXBParser<ThreadPoolJAXB>(
|
||||
ThreadPoolJAXB.class);
|
||||
logger.debug("Body: "
|
||||
+ genericResource.profile().bodyAsString());
|
||||
threadPool = (ThreadPoolJAXB) parser
|
||||
.parse(genericResource.profile()
|
||||
.bodyAsString());
|
||||
logger.debug("ThreadPool: " + threadPool);
|
||||
} catch (Throwable e) {
|
||||
String error = "Error in discovery Accounting Manager thread pool in scope "+ scope+". "
|
||||
+ "Resource parsing failed!";
|
||||
logger.error(error);
|
||||
logger.error("Error {resource="+ genericResource + ", error="
|
||||
+ e.getLocalizedMessage() + "}");
|
||||
e.printStackTrace();
|
||||
throw new ServiceException(error, e);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return threadPool;
|
||||
|
||||
} catch (ServiceException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
String error = "Error in discovery Accounting Manager thread pool in scope: "
|
||||
+ scope;
|
||||
logger.error(error);
|
||||
logger.error("Error: " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
throw new ServiceException(error, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package org.gcube.portlets.admin.accountingmanager.server.is;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
|
||||
@XmlRootElement(name = "threadpool")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class ThreadPoolJAXB {
|
||||
@XmlElement
|
||||
private String timeout;
|
||||
|
||||
public String getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(String timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ThreadPoolJAXB [timeout=" + timeout + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.gcube.portlets.admin.accountingmanager.server.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi email: <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ThreadPoolInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6955469914102879890L;
|
||||
private long timeout;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param timeout
|
||||
*/
|
||||
public ThreadPoolInfo(long timeout) {
|
||||
super();
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(long timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ThreadPoolInfo [timeout=" + timeout + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -39,6 +39,8 @@ public class Constants {
|
|||
// IS Resource
|
||||
public static final String ACCOUNTING_NAME = "AccountingManager";
|
||||
public static final String ACCOUNTING_CATEGORY = "AccountingProfile";
|
||||
public static final String ACCOUNTING_POOL_NAME = "AccountingManagerTaskPool";
|
||||
|
||||
|
||||
//TimeOut
|
||||
public static final long SERVICE_CLIENT_TIMEOUT_DEFAULT_MILLIS = 1800000;
|
||||
|
|
Loading…
Reference in New Issue