use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.
the class ManagerImpl method isServiceComponent.
/**
* Checks if component name is a service component name, list of names is defined in the CDB.
*
* @param name name to be checked, non-<code>null</code>
* @returns <code>true</code> if component name is service component name, <code>false</code> otherwise
*/
public boolean isServiceComponent(String name) {
assert (name != null);
boolean retVal = false;
// get CDB access dao
DAOProxy dao = getManagerDAOProxy();
if (dao != null) {
try {
// query
String[] names = dao.get_string_seq("ServiceComponents");
// find it
for (int i = 0; i < names.length; i++) if (name.equals(names[i])) {
retVal = true;
break;
}
} catch (Throwable ex) {
CoreException ce = new CoreException("Failed to retrieve list of service components.", ex);
logger.log(Level.FINE, ce.getMessage(), ce);
}
}
return retVal;
}
use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.
the class ManagerImpl method conditionalShutdownContainer.
/**
* Conditionally (if has no components and is not immortal container) shutdown container.
* @param containerInfo container to shutdown.
*/
private void conditionalShutdownContainer(ContainerInfo containerInfo) {
int componentsCount;
synchronized (containerInfo.getComponents()) {
componentsCount = containerInfo.getComponents().size();
}
// noop if there are components activated by this container
if (componentsCount > 0)
return;
// obtain keepAliveTime
int keepAliveTime = RELEASE_NEVER;
DAOProxy dao = getContainersDAOProxy();
if (dao != null) {
// defaults to RELEASE_NEVER
keepAliveTime = readLongCharacteristics(dao, containerInfo.getName() + "/DeployInfo/KeepAliveTime", keepAliveTime, true);
}
// always do shutdown in separate thread
if (keepAliveTime >= 0)
delayedDeactivationTask.schedule(new ShutdownContainerTask(containerInfo.getName()), keepAliveTime * 1000);
// negative means immortal
}
use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.
the class ManagerImpl method getComponentsDAOProxy.
/**
* Returns, if necessary also creates, components DAO (CDB access).
*
* @return DAOProxy components DAO (CDB access), otherwise <code>null</code>
*/
private synchronized DAOProxy getComponentsDAOProxy() {
if (System.getProperties().containsKey(NAME_CDB_DISABLE))
return null;
if (componentsDAO == null) {
componentsDAO = createDAO("MACI/Components");
if (componentsDAO != null) {
// initial refresh
componentListCache = refreshComponentsList(componentsDAO);
// ... and install link listener (to refresh after reconnect)
componentsDAO.addConnectionListener(new DAOProxyConnectionListener() {
public void connected(DAOProxy proxy) {
componentListCache = refreshComponentsList(proxy);
}
public void disconnected(DAOProxy proxy) {
/* noop */
}
});
}
}
return componentsDAO;
}
use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.
the class ManagerImpl method containerLogin.
/*****************************************************************************/
/**************************** [ Login methods ] ******************************/
/*****************************************************************************/
/**
* Container specific login method.
* @param name name of the container, non-<code>null</code>.
* @param reply reply to authenticate method, non-<code>null</code>.
* @param container container that is logging in, non-<code>null</code>.
* @return ClientInfo client info. of newly logged container
*/
private ClientInfo containerLogin(String name, AuthenticationData reply, Container container, long timeStamp, long executionId) throws AcsJNoPermissionEx {
assert (name != null);
assert (reply != null);
assert (container != null);
TimerTaskContainerInfo containerInfo = null;
ClientInfo clientInfo = null;
boolean existingLogin = false;
synchronized (containers) {
// check if container is already logged in,
// if it is, return existing info
int h = containers.first();
while (h != 0) {
ContainerInfo loggedContainerInfo = (ContainerInfo) containers.get(h);
//if (container.equals(loggedContainerInfo.getContainer()))
if (name.equals(loggedContainerInfo.getName())) {
Container loggedContainer = loggedContainerInfo.getContainer();
if (loggedContainer != null) {
// if same instance simply recover, if not...
if (!loggedContainer.equals(container)) {
// check if logged container is alive, if it is reject him
boolean alive = false;
try {
int lh = loggedContainer.get_handle();
if (lh != 0 && lh == loggedContainerInfo.getHandle())
alive = true;
} catch (Throwable th) {
// noop
}
if (alive) {
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
String address = "";
try {
address = " " + loggedContainer.getRemoteLocation();
} catch (Throwable th) {
/* noop */
}
npe.setReason("Rejecting container login, container with name '" + name + "'" + address + " already logged in.");
npe.setID(HandleHelper.toString(loggedContainerInfo.getHandle()));
npe.setProtectedResource(name);
throw npe;
} else
logger.log(Level.FINER, "Container '" + name + "' is no longer functional, new container is taking over.");
}
}
// !!! ACID 2
// new reference is considered as better
executeCommand(new ContainerCommandUpdate(h, container));
//loggedContainerInfo.setContainer(container);
existingLogin = true;
// generate ClientInfo
containerInfo = (TimerTaskContainerInfo) loggedContainerInfo;
clientInfo = containerInfo.createClientInfo();
break;
}
h = containers.next(h);
}
// new container
if (h == 0) {
long pingInterval = 0;
DAOProxy dao = getContainersDAOProxy();
if (dao != null) {
String impLang = readStringCharacteristics(dao, name + "/ImplLang", true);
ImplLang configuredImplLang = ImplLang.fromString(impLang);
if (configuredImplLang != ImplLang.not_specified && configuredImplLang != reply.getImplLang()) {
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Rejecting container login, container reported '" + reply.getImplLang() + "' implementation language, but configured '" + configuredImplLang + "'.");
npe.setProtectedResource(name);
throw npe;
}
pingInterval = readLongCharacteristics(dao, name + "/PingInterval", -1, true) * 1000;
}
// allocate new handle
// !!! ACID 2
Integer objHandle = (Integer) executeCommand(new ContainerCommandAllocate());
int handle;
if (objHandle == null || (handle = objHandle.intValue()) == 0) {
NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many containers logged in.");
throw af;
}
// generate external handle
h = handle | CONTAINER_MASK;
// add generated key
h |= (random.nextInt(0x100)) << 16;
// create new container info
containerInfo = new TimerTaskContainerInfo(h, name, container, containerPingInterval);
containerInfo.setImplLang(reply.getImplLang());
if (// safety limit
pingInterval >= 1000)
containerInfo.setPingInterval(pingInterval);
clientInfo = containerInfo.createClientInfo();
// register container to the heartbeat manager
PingTimerTask task = new PingTimerTask(this, logger, clientInfo, alarmSource);
containerInfo.setTask(task);
heartbeatTask.schedule(task, containerInfo.getPingInterval(), containerInfo.getPingInterval());
// !!! ACID - register AddContainerCommand
executeCommand(new ContainerCommandSet(handle, containerInfo));
// store info
//containers.set(handle, containerInfo);
}
}
// cancel all "old" container async request
AcsJCannotGetComponentEx acgcex = new AcsJCannotGetComponentEx();
acgcex.setReason("Request canceled due to container re-login.");
cancelPendingContainerAsyncRequestWithException(containerInfo.getName(), acgcex);
final boolean recoverContainer = reply.isRecover();
if (existingLogin) {
// merge container's and manager's internal state
containerInternalStateMerge(containerInfo, recoverContainer);
}
// notify administrators about the login
notifyContainerLogin(containerInfo, timeStamp, executionId);
// do container post login activation in separate thread
final ContainerInfo finalInfo = containerInfo;
threadPool.execute(new Runnable() {
public void run() {
containerPostLoginActivation(finalInfo, recoverContainer);
}
});
logger.log(Level.INFO, "Container '" + name + "' logged in.");
return clientInfo;
}
use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.
the class ManagerImpl method hasCDBEntry.
/**
* Search for CDB entry of given component.
* @param componentInfo component info of CDB entry to be found, non-<code>null</code>.
* @return if CDB entry of has been found <code>true</code>, or if it does not exist or
* there is no CDB available <code>false</code>.
*/
private boolean hasCDBEntry(ComponentInfo componentInfo) {
assert (componentInfo != null);
try {
// check component entry
DAOProxy dao = getComponentsDAOProxy();
if (dao == null || readStringCharacteristics(dao, componentInfo.getName(), true) == null)
return false;
// check type
String type = readStringCharacteristics(dao, componentInfo.getName() + "/Type", true);
if (type == null || !type.equals(componentInfo.getType()))
return false;
// check code
String code = readStringCharacteristics(dao, componentInfo.getName() + "/Code", true);
if (code == null || !code.equals(componentInfo.getCode()))
return false;
// check container
String container = readStringCharacteristics(dao, componentInfo.getName() + "/Container", true);
if (container == null)
return false;
else {
// dynamic component case
if (componentInfo.isDynamic()) {
if (componentInfo.getDynamicContainerName() != null && !container.equals(componentInfo.getDynamicContainerName()))
return false;
} else // static component case
{
ContainerInfo containerInfo = (ContainerInfo) getContainerInfo(componentInfo.getContainer());
if (containerInfo != null && !containerInfo.getName().equals(container))
return false;
}
}
// there is an entry in CDB
return true;
} catch (Throwable t) {
return false;
}
}
Aggregations