use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method getDefaultComponent.
/*****************************************************************************/
/*********************** [ Dynamic (de)activation ] **************************/
/*****************************************************************************/
/**
* @see com.cosylab.acs.maci.Manager#getDefaultComponent(int, java.lang.String)
*/
// @todo MF not supported
public ComponentInfo getDefaultComponent(int id, String type) throws AcsJNoPermissionEx, NoDefaultComponentException {
if (type == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'type' expected.");
throw af;
}
/****************************************************************/
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
logger.log(Level.INFO, "Getting default component for type '" + type + "'.");
ComponentInfo componentInfo = internalRequestDefaultComponent(id, type);
return componentInfo;
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncRestartComponent.
/**
* Internal method for restarting components.
*
* @param owner owner of the component.
* @param h handle of the component to be restarting.
* @return Newly restarted component, <code>null</code> if failed.
*/
// @todo MF not supported
private Component internalNoSyncRestartComponent(int owner, int h) throws AcsJNoPermissionEx {
int handle = h & HANDLE_MASK;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
if (components.isAllocated(handle))
componentInfo = (ComponentInfo) components.get(handle);
if (componentInfo == null || componentInfo.getHandle() != h) {
// invalid component handle
BadParametersException af = new BadParametersException("Invalid component handle.");
throw af;
}
// remove ownership of the component
if (!componentInfo.getClients().contains(owner)) {
// not an owner
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Restarting component that client does not own.");
npe.setID(HandleHelper.toString(owner));
npe.setProtectedResource(componentInfo.getName());
throw npe;
}
} finally {
componentsLock.unlock();
}
/****************** restart component ******************/
//
// get container
//
// search for container by its name
Container container = null;
ContainerInfo containerInfo = null;
int containerHandle = componentInfo.getContainer();
// if containerHandle equals 0, we have unavailable or registered component
if (containerHandle != 0) {
containerInfo = getContainerInfo(containerHandle);
if (containerInfo != null) {
checkContainerShutdownState(containerInfo);
container = containerInfo.getContainer();
}
// required container is not logged in
if (container == null) {
// then simply do not do the restart
String containerName;
if (containerInfo != null)
containerName = containerInfo.getName();
else
containerName = HandleHelper.toString(componentInfo.getContainer());
logger.log(Level.WARNING, "Container '" + containerName + "' required by component '" + componentInfo.getName() + "' is not logged in.");
}
}
// return value
Component component = null;
if (container != null) {
// restart component
try {
component = container.restart_component(componentInfo.getHandle());
if (component == null) {
RemoteException re = new RemoteException("Failed to restart component '" + componentInfo.getName() + "', 'null' returned.");
throw re;
}
// @todo what about notifying clients, marking component as available, updating reference...
} catch (Throwable ex) {
RemoteException re = new RemoteException("Failed to restart component '" + componentInfo.getName() + "' on container '" + containerInfo.getName() + "'.", ex);
logger.log(Level.SEVERE, re.getMessage(), re);
}
}
logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' restarted.");
return component;
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ComponentInfoTopologicalSortManager method run.
/**
* (Sync is clean since activationPendingRWLock is acquired and all
* notify request is issued only from its reader lock).
* @see java.lang.Runnable#run()
*/
public void run() {
while (!destroyed) {
synchronized (this) {
int dirtyContainersCount;
synchronized (dirtyContainerMap) {
dirtyContainersCount = dirtyContainerMap.size();
}
if (dirtyContainersCount == 0) {
try {
this.wait();
} catch (InterruptedException e) {
return;
}
}
}
if (destroyed)
return;
// aquire writer lock to prevent activation/deactivation
activationPendingRWLock.writeLock().lock();
try {
Integer[] conts;
synchronized (dirtyContainerMap) {
conts = new Integer[dirtyContainerMap.size()];
dirtyContainerMap.toArray(conts);
dirtyContainerMap.clear();
}
ComponentInfo[] orderedList;
synchronized (components) {
List list = ComponentInfoTopologicalSort.sort(components);
orderedList = new ComponentInfo[list.size()];
list.toArray(orderedList);
}
synchronized (listLock) {
currentTSList = orderedList;
}
for (int i = 0; i < conts.length; i++) {
int handle = conts[i].intValue() & HandleConstants.HANDLE_MASK;
ContainerInfo containerInfo = null;
synchronized (containers) {
if (containers.isAllocated(handle))
containerInfo = (ContainerInfo) containers.get(handle);
}
if (containerInfo == null || containerInfo.getName() == null)
break;
String containerName = containerInfo.getName();
// check if shutdown state
if (pendingContainerShutdown.contains(containerName))
break;
IntArray containerOrderdList = new IntArray(10);
for (int j = 0; j < orderedList.length; j++) {
// if component already deactivated, skip it
if (orderedList[j].getContainer() == 0)
continue;
// this is null proof
if (containerName.equals(orderedList[j].getContainerName())) {
containerOrderdList.add(orderedList[j].getHandle());
}
}
// optimization
if (containerOrderdList.size() > 1)
notifyContainerShutdownOrder(containerInfo, containerOrderdList.toArray());
}
} finally {
activationPendingRWLock.writeLock().unlock();
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
logger.log(Level.WARNING, "Exception caught while waiting in run() method");
ex.printStackTrace();
}
}
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method getRequestorName.
/*****************************************************************************/
/*************************** [ Utility methods ] *****************************/
/*****************************************************************************/
/**
* Returns human-readable and meaningful name of handle.
*
* @param id handle to stringifys
* @return human-readable and meaningful name of handle.
*/
private String getRequestorName(int id) {
// parse handle part
int reqHandle = id & HANDLE_MASK;
boolean invalidHandle = true;
StringBuffer name = new StringBuffer(30);
switch(id & TYPE_MASK) {
case CONTAINER_MASK:
//name.append("Container ");
synchronized (containers) {
if (containers.isAllocated(reqHandle)) {
ContainerInfo info = (ContainerInfo) containers.get(reqHandle);
if (info.getHandle() == id) {
invalidHandle = false;
name.append(info.getName());
}
}
}
break;
case CLIENT_MASK:
//name.append("Client ");
synchronized (clients) {
if (clients.isAllocated(reqHandle)) {
ClientInfo info = (ClientInfo) clients.get(reqHandle);
if (info.getHandle() == id) {
invalidHandle = false;
name.append(info.getName());
}
}
}
break;
case ADMINISTRATOR_MASK:
//name.append("Administrator ");
synchronized (administrators) {
if (administrators.isAllocated(reqHandle)) {
ClientInfo info = (ClientInfo) administrators.get(reqHandle);
if (info.getHandle() == id) {
invalidHandle = false;
name.append(info.getName());
}
}
}
break;
case COMPONENT_MASK:
//name.append("Component ");
componentsLock.lock();
try {
if (components.isAllocated(reqHandle)) {
ComponentInfo info = (ComponentInfo) components.get(reqHandle);
// do additional preallocation check
if (info != null && info.getHandle() == id) {
invalidHandle = false;
name.append(info.getName());
}
}
} finally {
componentsLock.unlock();
}
break;
case MANAGER_MASK:
//name.append("Manager ");
name.append("Manager");
invalidHandle = false;
break;
}
if (invalidHandle)
name.append("<unknown>");
return name.toString();
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method getDynamicComponent.
/**
* @see com.cosylab.acs.maci.Manager#getDynamicComponent(int, com.cosylab.acs.maci.ComponentSpec, boolean)
*/
// TODO MF not supported
public ComponentInfo getDynamicComponent(int id, ComponentSpec componentSpec, boolean markAsDefault) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJIncompleteComponentSpecEx, AcsJInvalidComponentSpecEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
try {
// check if null
if (componentSpec == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec");
throw ex;
}
// check componentSpec components are null
if (componentSpec.getName() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Name");
throw ex;
}
if (componentSpec.getType() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Type");
throw ex;
}
if (componentSpec.getCode() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Code");
throw ex;
}
if (componentSpec.getContainer() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Container");
throw ex;
}
// check for empty componentSpec.name
if (componentSpec.getName().length() == 0) {
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("componentSpec.Name");
ex.setParameterValue("EMPTY");
ex.setReason("Non empty Component Name expected");
throw ex;
}
} catch (AcsJNullPointerEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
} catch (AcsJBadParameterEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
}
// check handle and NONE permissions
// Throws AcsJNoPermissionEx that is let flying up
securityCheck(id, AccessRights.NONE);
/****************************************************************/
// Same exceptions fly up
ComponentInfo componentInfo = null;
try {
componentInfo = internalRequestDynamicComponent(id, componentSpec);
} catch (AcsJSyncLockFailedEx e) {
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
ex.setReason("Failed to get Synchronisation lock");
throw ex;
}
// update default components table
if (componentInfo != null && markAsDefault) {
synchronized (defaultComponents) {
// !!! ACID 3
executeCommand(new DefaultComponentCommandPut(componentInfo.getType(), componentInfo));
//defaultComponents.put(componentInfo.getType(), componentInfo.getName());
}
logger.log(Level.INFO, "'" + componentInfo.getName() + "' has been marked as a default component of type '" + componentInfo.getType() + "'.");
}
if (componentInfo == null) {
/**
* @todo Is it OK to get here? Always?
* This is a place where we have to check carefully.
*/
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
throw ex;
}
return componentInfo;
}
Aggregations