use of com.cosylab.acs.maci.ContainerInfo in project ACS by ACS-Community.
the class ManagerImpl method getClients.
/**
* Get client info. for specified handles of <code>Client</code> or <code>Administrator</code>. For <code>Component</code>
* handles component's <code>Container</code> is returned.
*
* @param excludeHandle handle of client not to be included in the array, can be 0.
* @param handles handles of the clients whose info. should be returned, non-<code>null</code>.
* @param returns requested infos, <code>null</code> if none
*/
private ClientInfo[] getClients(int excludeHandle, int[] handles) {
assert (handles != null);
// array of clients to be notified
ClientInfo[] clients = null;
ArrayList<ClientInfo> list = new ArrayList<ClientInfo>();
for (int i = 0; i < handles.length; i++) if (handles[i] != excludeHandle) {
if ((handles[i] & TYPE_MASK) == COMPONENT_MASK) {
ComponentInfo componentInfo = getComponentInfo(handles[i]);
if (componentInfo != null) {
ContainerInfo containerInfo = getContainerInfo(componentInfo.getContainer());
if (containerInfo != null) {
ClientInfo info = new ClientInfo(containerInfo.getHandle(), containerInfo.getName(), containerInfo.getContainer());
list.add(info);
}
}
} else {
ClientInfo info = getClientInfo(handles[i]);
if (info != null)
list.add(info);
}
}
// copy to array
if (list.size() > 0) {
clients = new ClientInfo[list.size()];
list.toArray(clients);
}
return clients;
}
use of com.cosylab.acs.maci.ContainerInfo in project ACS by ACS-Community.
the class ManagerImpl method startUpContainer.
/**
* Start-up container (if it has a deploy info).
* @param containerName name of the container to start up.
* @return container info of container, <code>null</code> if failed to start.
*/
private ContainerInfo startUpContainer(String containerName) {
// not to mess with same component name
final String LOCK_NAME = "container-" + containerName;
// try to acquire lock
String lockNotAcquiredCause = acquireSynchronizationObject(LOCK_NAME, lockTimeout, "start-up container " + containerName);
if (lockNotAcquiredCause == null) {
try {
// double check pattern
ContainerInfo info = getContainerInfo(containerName);
if (info != null)
return info;
return internalNoSyncStartUpContainer(containerName);
} finally {
releaseSynchronizationObject(LOCK_NAME);
}
} else {
NoResourcesException nre = new NoResourcesException("Failed to obtain synchronization lock for container '" + containerName + "', possible deadlock; locked to '" + lockNotAcquiredCause + "'.");
throw nre;
}
}
use of com.cosylab.acs.maci.ContainerInfo 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.ContainerInfo 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.ContainerInfo in project ACS by ACS-Community.
the class ManagerImpl method getContainerInfo.
/**
* Get container info. for specified id of <code>Container</code>.
*
* @param id handle of the container whose info. should be returned
* @param returns requested info, <code>null</code> if container with requested handle does not exits
*/
private ContainerInfo getContainerInfo(int id) {
// parse handle part
int handle = id & HANDLE_MASK;
// info to be returned
ContainerInfo info = null;
synchronized (containers) {
if (containers.isAllocated(handle))
info = (ContainerInfo) containers.get(handle);
}
return info;
}
Aggregations