use of com.cosylab.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerImpl method executeCommand.
/**
* @param command
* @return
*/
private Serializable executeCommand(Command command) throws NoResourcesException {
if (prevayler != null && statePersitenceFlag.get()) {
try {
final Serializable retVal;
synchronized (prevayler) {
retVal = prevayler.executeCommand(command);
}
reportPrevaylerState(false, null);
return retVal;
} catch (IOException ioex) {
// filesystem error, prevailey failed
// log, raise alarm and bypass prevayler (do not return here)
reportPrevaylerState(true, ioex);
} catch (Throwable th) {
// most likely command execution error
throw new NoResourcesException("Failed to execute command.", th);
}
}
// bypass prevayler
try {
return command.execute(this);
} catch (Throwable th) {
throw new NoResourcesException("Failed to execute command.", th);
}
}
use of com.cosylab.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerImpl method makeComponentImmortal.
/**
* @see com.cosylab.acs.maci.Manager#makeComponentImmortal(int, java.net.URI, boolean)
*/
public void makeComponentImmortal(int id, URI curl, boolean immortalState) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJBadParameterEx {
// extract name
String name = extractName(curl);
// let same exception flying up
try {
checkCURL(curl);
} catch (AcsJBadParameterEx e) {
throw e;
}
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
/****************************************************************/
int h;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
h = components.first();
while (h != 0) {
componentInfo = (ComponentInfo) components.get(h);
if (componentInfo.getName().equals(name)) {
h = componentInfo.getHandle();
break;
}
h = components.next(h);
}
// component not yet activated check
if (h == 0) {
NoResourcesException af = new NoResourcesException("Component not activated.");
throw af;
}
// if not an owner of the component, check administrator rights
if (!componentInfo.getClients().contains(id)) {
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
}
if (immortalState) {
// finally, add manager as an owner
if (!componentInfo.getClients().contains(this.getHandle())) {
// ACID - !!!
executeCommand(new ComponentCommandClientAdd(componentInfo.getHandle() & HANDLE_MASK, this.getHandle()));
//componentInfo.getClients().add(this.getHandle());
}
logger.log(Level.INFO, "Component " + name + " was made immortal.");
}
} finally {
componentsLock.unlock();
}
// this must be done outside component sync. block
if (!immortalState) {
logger.log(Level.INFO, "Component " + name + " was made mortal.");
// finally, can happen that the manager is the only owner
// so release could be necessary
internalReleaseComponent(this.getHandle(), h, false);
}
/****************************************************************/
}
use of com.cosylab.acs.maci.NoResourcesException 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.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerImpl method setStatePersistence.
@Override
public void setStatePersistence(int id, boolean enable) throws AcsJNoPermissionEx {
// TODO introduce new rights
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
if (prevayler != null) {
synchronized (prevayler) {
// on enable, first take current snapshot to start with clean state
if (enable) {
// already enabled check
if (statePersitenceFlag.get())
return;
try {
synchronized (prevayler) {
statePersitenceFlag.set(true);
((SnapshotPrevayler) prevayler).takeSnapshot();
}
} catch (IOException e) {
// @todo better exception
statePersitenceFlag.set(false);
throw new NoResourcesException("Failed to create current state snapshot: " + e.toString());
}
} else {
statePersitenceFlag.set(false);
}
}
}
}
use of com.cosylab.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerImpl method clientLogin.
/**
* Client specific login method.
* @param name name of the client
* @param reply reply to authenticate method
* @param client client that is logging in
* @return ClientInfo client info. of newly logged client
*/
private ClientInfo clientLogin(String name, AuthenticationData reply, Client client, long timeStamp, long executionId) throws AcsJNoPermissionEx {
assert (name != null);
assert (client != null);
TimerTaskClientInfo clientInfo = null;
synchronized (clients) {
// check if client is already logged in,
// if it is, return existing info
int h = clients.first();
while (h != 0) {
ClientInfo loggedClientInfo = (ClientInfo) clients.get(h);
if (client.equals(loggedClientInfo.getClient()))
return loggedClientInfo;
h = clients.next(h);
}
// check thread resources
int usage = threadsUsedPercentage.get();
if (usage > 90) {
throw new NoResourcesException("Thread usage too high (%" + usage + "), rejecting login.");
}
// allocate new handle
// !!! ACID 2
Integer objHandle = (Integer) executeCommand(new ClientCommandAllocate());
int handle;
//int handle = clients.allocate();
if (objHandle == null || (handle = objHandle.intValue()) == 0) {
NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many clients logged in.");
throw af;
}
// generate external handle
h = handle | CLIENT_MASK;
// add generated key
h |= (random.nextInt(0x100)) << 16;
// create new client info
clientInfo = new TimerTaskClientInfo(h, name, client);
clientInfo.setAccessRights(AccessRights.REGISTER_COMPONENT);
// register client to the heartbeat manager
PingTimerTask task = new PingTimerTask(this, logger, clientInfo, null);
clientInfo.setTask(task);
heartbeatTask.schedule(task, clientPingInterval, clientPingInterval);
// !!! ACID - register AddClientCommand
executeCommand(new ClientCommandSet(handle, clientInfo));
// store info
//clients.set(handle, clientInfo);
}
// notify administrators about the login
notifyClientLogin(clientInfo, timeStamp, executionId);
logger.log(Level.INFO, "Client '" + name + "' logged in.");
return clientInfo;
}
Aggregations