use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalReleaseComponent.
/**
* Internal method for releasing components.
*
* @param owner owner of the component, if manager's own handle then deactivation will be forced
* @param curl CURL of the component to be released.
* @param force force deactivate, if still has owners then component will be made unavailable.
* @return Number of clients that are still using the component after the operation completed.
*/
private ReleaseComponentResult internalReleaseComponent(int owner, URI curl, boolean force) throws AcsJNoPermissionEx, AcsJBadParameterEx {
// resolve handle from curl
int h = 0;
String name = extractName(curl);
componentsLock.lock();
try {
h = components.first();
while (h != 0) {
ComponentInfo componentInfo = (ComponentInfo) components.get(h);
if (componentInfo.getName().equals(name)) {
h = componentInfo.getHandle();
break;
}
h = components.next(h);
}
} finally {
componentsLock.unlock();
}
// if found, delegate operation, otherwise do nothing
if (h != 0)
return internalReleaseComponent(owner, h, force);
else
return new ReleaseComponentResult(0, null);
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncReleaseComponent.
/**
* Internal method for releasing components.
*
* @param owner owner of the component.
* @param h handle of the component to be released.
* @param force force deactivate, if still has owners then component will be made unavailable.
* @return Number of clients that are still using the component after the operation completed.
*/
private ReleaseComponentResult internalNoSyncReleaseComponent(int owner, int h, boolean force) throws AcsJNoPermissionEx {
int handle = h & HANDLE_MASK;
int owners = 0;
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)) {
if (!force) {
// not an owner
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Unregistering component that client does not own.");
npe.setID(HandleHelper.toString(owner));
npe.setProtectedResource(componentInfo.getName());
throw npe;
}
} else {
// ACID - !!!
// remove client/component as an owner
executeCommand(new ComponentCommandClientRemove(componentInfo.getHandle() & HANDLE_MASK, owner));
// remove component from client component list
if (owner != this.getHandle())
removeComponentOwner(componentInfo.getHandle(), owner);
}
owners = componentInfo.getClients().size();
if (owners == 0) {
// there is not owner to be unavailable for
synchronized (unavailableComponents) {
if (unavailableComponents.containsKey(componentInfo.getName())) {
// !!! ACID
executeCommand(new UnavailableComponentCommandRemove(componentInfo.getName()));
//unavailableComponents.remove(componentInfo.getName());
}
}
}
} finally {
componentsLock.unlock();
}
/****************** component deactivation ******************/
ReleaseComponentResult result = new ReleaseComponentResult(owners, null);
// there is no owners of the component, deactivate it
if (force) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (owners == 0) {
int keepAliveTime = RELEASE_IMMEDIATELY;
String name = componentInfo.getName();
boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
if (!isOtherDomainComponent) {
keepAliveTime = componentInfo.getKeepAliveTime();
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
// when info is passed from the container
DAOProxy dao = getComponentsDAOProxy();
if (dao != null)
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
else
keepAliveTime = RELEASE_IMMEDIATELY;
}
}
if (keepAliveTime == 0) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (keepAliveTime > 0)
delayedDeactivationTask.schedule(new DeactivateComponentTask(name), keepAliveTime * 1000);
// negative means immortal, however this could not happen since immortal
// components have manager as an owner
}
/// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
// notify administrators about the release request
notifyComponentReleased(new int[] { owner }, new int[] { h }, System.currentTimeMillis());
logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") released.");
// component deactivated
if (owners == 0 || force) {
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
} else if ((owner & TYPE_MASK) == COMPONENT_MASK) {
// component dependency changed...
// notify about the change (only if on the same container)...
// on complete system shutdown sort will be done anyway
ComponentInfo ownerComponentInfo = getComponentInfo(owner);
if (ownerComponentInfo != null && ownerComponentInfo.getContainerName() != null && ownerComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
}
return result;
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method shutdownContainer.
/**
* @see com.cosylab.acs.maci.Manager#shutdownContainer(int, java.lang.String, int)
*/
public void shutdownContainer(int id, String containerName, int action) throws AcsJNoPermissionEx {
// check if null
if (containerName == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'containerName' expected.");
throw af;
}
/****************************************************************/
// the caller must have SHUTDOWN_SYSTEM access rights,
securityCheck(id, AccessRights.SHUTDOWN_SYSTEM);
Container container;
ContainerInfo containerInfo = getContainerInfo(containerName);
if (containerInfo == null || (container = containerInfo.getContainer()) == null) {
// NO_RESOURCES
NoResourcesException nre = new NoResourcesException("Container '" + containerName + "' not logged in.");
throw nre;
}
pendingContainerShutdown.add(containerInfo.getName());
try {
// release components
try {
// get shutdown order
ComponentInfo[] infos = topologySortManager.getComponentShutdownOrder(containerInfo);
releaseComponents(infos);
} catch (Throwable th) {
CoreException ce = new CoreException("Failed to release components on container '" + containerName + "'.", th);
reportException(ce);
}
// shutdown (or disconnect)
try {
if (action == 0)
container.disconnect();
else
container.shutdown(action);
} catch (Throwable th) {
// NO_RESOURCES
NoResourcesException nre = new NoResourcesException("Failed to shutdown container '" + containerName + "'.", th);
throw nre;
}
} finally {
pendingContainerShutdown.remove(containerInfo.getName());
}
/****************************************************************/
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalRequestDefaultComponent.
/**
* Internal method for requesting default components.
* @param requestor requestor of the component.
* @param typr type of the component
* @return componentInfo <code>ComponentInfo</code> of requested default component.
*/
private ComponentInfo internalRequestDefaultComponent(int requestor, String type) throws NoDefaultComponentException {
String defaultComponentName = null;
ComponentInfo defaultComponentInfo = null;
// first check default components table
synchronized (defaultComponents) {
defaultComponentInfo = defaultComponents.get(type);
}
if (defaultComponentInfo != null)
defaultComponentName = defaultComponentInfo.getName();
// if not found, search for the default component in the CDB
if (defaultComponentName == null) {
DAOProxy componentsDAO = getComponentsDAOProxy();
if (componentsDAO != null) {
try {
// get names of all components
// @todo here to check if CDB is available
componentsDAO.get_field_data("");
/*String[] ids =*/
String[] ids = getComponentsList();
// test names
for (int i = 0; i < ids.length; i++) {
// read name
//readStringCharacteristics(componentsDAO, ids[i]+"/Name");
String name = ids[i];
if (name == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + ids[i] + "' defined.");
continue;
}
// do not search dynamic components (they cannot be marked as default in CDB anyway)
if (!name.equals(ComponentSpec.COMPSPEC_ANY)) {
// read type
String componentType = readStringCharacteristics(componentsDAO, ids[i] + "/Type");
if (type == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + name + "' defined.");
continue;
}
// test type
final String TRUE_STRING = "true";
if (type.equals(componentType)) {
// check if it is default, read silently
String isDefault = readStringCharacteristics(componentsDAO, ids[i] + "/Default", true);
if (isDefault == null || !isDefault.equalsIgnoreCase(TRUE_STRING))
continue;
// got the match
defaultComponentName = name;
break;
}
}
}
} catch (Throwable ex) {
CoreException ce = new CoreException("Failed to obtain component data from the CDB.", ex);
reportException(ce);
}
}
}
// if found get the component
if (defaultComponentInfo != null) {
try {
StatusHolder status = new StatusHolder();
ContainerInfo containerInfo = getContainerInfo(defaultComponentInfo.getContainer());
if (containerInfo == null) {
CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "', container with '" + HandleHelper.toString(defaultComponentInfo.getContainer()) + "' not logged in.");
reportException(huse);
return null;
}
ComponentInfo componentInfo = internalRequestComponent(requestor, defaultComponentInfo.getName(), defaultComponentInfo.getType(), defaultComponentInfo.getCode(), containerInfo.getName(), RELEASE_IMMEDIATELY, status, true);
if (componentInfo == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
reportException(huse);
// no error handling...
return null;
}
return componentInfo;
} catch (Throwable t) {
CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
reportException(huse);
return null;
}
} else if (defaultComponentName != null) {
// create CURL
URI curl = null;
try {
curl = CURLHelper.createURI(defaultComponentName);
} catch (URISyntaxException use) {
CoreException huse = new CoreException("Failed to create CURL from default component name: '" + defaultComponentName + "'.", use);
reportException(huse);
return null;
}
try {
// request for component
StatusHolder status = new StatusHolder();
Component component = internalRequestComponent(requestor, curl, status, true);
if (component == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
reportException(huse);
return null;
}
// return component info
ComponentInfo[] componentInfo = getComponentInfo(requestor, new int[0], defaultComponentName, type, true);
if (componentInfo == null || componentInfo.length != 1) {
CoreException huse = new CoreException("Failed to obtain activated default component ComponentInfo: '" + defaultComponentName + "'.");
reportException(huse);
return null;
} else
return componentInfo[0];
} catch (Throwable t) {
CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
reportException(huse);
return null;
}
}
// not found
NoDefaultComponentException ndce = new NoDefaultComponentException("No default component for type '" + type + "' found.");
throw ndce;
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ComponentInfoTopologicalSort method markImmortalChain.
/**
* DSF algrithm to generate immortal chain.
* @param immortalChainMap set of components (immportal or components which clients are immortal components).
* @param dataStore <code>ComponentInfo</code> handle data store instance to sort.
* @param marker handle of the object which identifies member of immortal chain.
*/
private void markImmortalChain(HashSet immortalChainMap, HandleDataStore dataStore, int marker) {
for (int h = dataStore.first(); h != 0; h = dataStore.next(h)) {
ComponentInfo componentInfo = (ComponentInfo) dataStore.get(h);
int[] clients = componentInfo.getClients().toArray();
for (int i = 0; i < clients.length; i++) {
if (clients[i] == marker && !immortalChainMap.contains(componentInfo)) {
immortalChainMap.add(componentInfo);
markImmortalChain(immortalChainMap, dataStore, componentInfo.getHandle());
}
}
}
}
Aggregations